<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[VirtualAlloc(), bringt nur den Zugriff auf eine unzulässige addresse. wieso?]]></title><description><![CDATA[<p>hi, es waer toll wenn ich euch mal diesen code anschauen wuerded, speziel die aller letzte funktion.</p>
<pre><code class="language-cpp">/*******************************************************************************

    Author  : Tobias Stein
    Date    : 9th July '07
    Project : Kill PAGE_GUARD
    File    : KillPG2.cpp
    Remark  : Many memory addresses will protected by PAGE_GUARD, if you want to
              manipulate or read an address, PAGE_GUARD cause an exception, so
              you got no access.
              This application should turn off the fucking PAGE_GUARD.

    All Rights Reserved!

*******************************************************************************/

//--- Includes -----------------------------------------------------------------

#include &lt;windows.h&gt;
#include &lt;fstream.h&gt;
#include &lt;commctrl.h&gt;

//--- Globals ------------------------------------------------------------------

#define ID_BUTTON_TURNOFF               1000
#define ID_PROGRESSBAR_STATUS           1001

char szAppName[ ] = &quot;Kick the fucking PAGE_GUARD&quot;;
char szAppTitle[ ] = &quot;Turn off the fucking PAGE_GUARD&quot;;

//--- Prototype ----------------------------------------------------------------

LRESULT CALLBACK WinProc( HWND, UINT, WPARAM, LPARAM );
void lasterror( );
void EnableDebugPrivilege( );
bool turnItOff( HWND );

//--- Main ---------------------------------------------------------------------

WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow ) {

    HWND hWnd;
    WNDCLASS wc;
    MSG msg;

    wc.style = CS_VREDRAW | CS_HREDRAW;
    wc.lpfnWndProc = WinProc;
    wc.cbClsExtra = 0;
    wc.cbWndExtra = 0;
    wc.hInstance = hInstance;
    wc.hIcon = LoadIcon( 0, IDI_APPLICATION );
    wc.hCursor = LoadCursor( 0, IDC_ARROW );
    wc.hbrBackground = reinterpret_cast&lt; HBRUSH &gt;( GetStockObject( BLACK_BRUSH ) );
    wc.lpszMenuName = 0;
    wc.lpszClassName = szAppName;

    if( !( RegisterClass( &amp;wc ) ) ) {

        MessageBox( 0, &quot;Couldn't register window by windows!&quot;, &quot;Shutdown error!&quot;, MB_OK | MB_ICONERROR );
        return 0;
    }

    hWnd = CreateWindowEx( 0,
                           szAppName, szAppTitle,
                           WS_SYSMENU | WS_MINIMIZEBOX,
                           CW_USEDEFAULT, CW_USEDEFAULT, 320, 220,
                           0,
                           0,
                           hInstance,
                           0 );

    if( !hWnd ) {

        MessageBox( 0, &quot;Couldn't create the window!&quot;, &quot;Shutdown error!&quot;, MB_OK | MB_ICONERROR );
        return 0;
    }

    ShowWindow( hWnd, nCmdShow );
    UpdateWindow( hWnd );

    while( GetMessage( &amp;msg, 0, 0, 0 ) ) {

        TranslateMessage( &amp;msg );
        DispatchMessage( &amp;msg );
    }

    return( msg.wParam );
}

//--- Windowprocedur -----------------------------------------------------------

LRESULT CALLBACK WinProc( HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam ) {

    HINSTANCE hInst;
    static RECT wndRect;
    static HWND hButton_to;
    static HWND hProgressBar;

    switch( message ) {

        case WM_CREATE: {

            hInst = ( (LPCREATESTRUCT)lParam )-&gt;hInstance;
            InitCommonControls( );

            hButton_to = CreateWindowEx( 0, &quot;BUTTON&quot;, &quot;KickIT&quot;, WS_CHILD | WS_VISIBLE,
                                         107, 110, 100, 30, hWnd, (HMENU)ID_BUTTON_TURNOFF,
                                         hInst, 0 );

            hProgressBar = CreateWindowEx( WS_EX_CLIENTEDGE, PROGRESS_CLASS, 0,
                                           WS_CHILD | WS_VISIBLE | WS_BORDER,
                                           0, 0, 0, 0, hWnd, (HMENU)ID_PROGRESSBAR_STATUS,
                                           hInst, 0 );

            SendMessage( hProgressBar, PBM_SETRANGE32, 0, 524256 );
            SendMessage( hProgressBar, PBM_SETSTEP, 1, 0 );
            return 0;
        }

        case WM_SIZE: {

            GetClientRect( hWnd, &amp;wndRect );
            MoveWindow( hProgressBar, wndRect.left, wndRect.bottom - 20, wndRect.right, 20, true );
            return 0;
        }

        case WM_COMMAND: {

            switch( LOWORD( wParam ) ) {

                case ID_BUTTON_TURNOFF: {

                    switch( HIWORD( wParam ) ) {

                        case BN_CLICKED: {

                            turnItOff( hProgressBar );
                            break;
                        }
                    }
                    break;
                }
            }
            return 0;
        }

        case WM_DESTROY: {

            PostQuitMessage( 0 );
            return 0;
        }
    }
    return( DefWindowProc( hWnd, message, wParam, lParam ) );
}

//--- Definitions --------------------------------------------------------------

void lasterror( ) {

    LPVOID lpMsgBuf;

    FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
                   0,
                   GetLastError(),
                   MAKELANGID( LANG_NEUTRAL, SUBLANG_DEFAULT ), // Default language
                   (LPTSTR) &amp;lpMsgBuf,
                   0,
                   NULL );

    // Display the string.
    MessageBox( NULL, (char*)lpMsgBuf, &quot;GetLastError&quot;, MB_OK | MB_ICONINFORMATION );
    // Free the buffer.
    LocalFree( lpMsgBuf );
}

void EnableDebugPrivilege( ) {

    TOKEN_PRIVILEGES priv;
	HANDLE hThis, hToken;
	LUID luid;

	hThis = GetCurrentProcess();

	OpenProcessToken( hThis, TOKEN_ADJUST_PRIVILEGES, &amp;hToken );

	LookupPrivilegeValue( 0, &quot;seDebugPrivilege&quot;, &amp;luid );

	priv.PrivilegeCount = 1;
	priv.Privileges[ 0 ].Luid = luid;
	priv.Privileges[ 0 ].Attributes = SE_PRIVILEGE_ENABLED;

	AdjustTokenPrivileges( hToken, false, &amp;priv, 0, 0, 0 );

	CloseHandle( hToken );
	CloseHandle( hThis );
}

bool turnItOff( HWND hProgressBar ) {

    SYSTEM_INFO si;
    MEMORY_BASIC_INFORMATION mbi;
    DWORD dwOldProtect;
    LPVOID lpAddress;
    DWORD dwCurrentPage;

    EnableDebugPrivilege( );
    memset( &amp;si, 0, sizeof( SYSTEM_INFO ) );
    memset( &amp;mbi, 0, sizeof( MEMORY_BASIC_INFORMATION ) );

    GetSystemInfo( &amp;si );
    dwCurrentPage = (DWORD)si.lpMinimumApplicationAddress;

   do {

        VirtualQuery( (LPVOID)dwCurrentPage, &amp;mbi, sizeof( MEMORY_BASIC_INFORMATION ) );
        lpAddress = VirtualAlloc( mbi.BaseAddress, mbi.RegionSize, MEM_COMMIT, PAGE_READWRITE );

        if( !( VirtualProtect( mbi.BaseAddress, mbi.RegionSize, PAGE_READWRITE, &amp;dwOldProtect ) ) ) {

            lasterror( );
            return false;
        }

        VirtualFree( lpAddress, mbi.RegionSize, MEM_DECOMMIT );
        lpAddress = 0;
        SendMessage( hProgressBar, PBM_STEPIT, 0, 0 );
        dwCurrentPage += ( si.dwPageSize );

    } while( dwCurrentPage &lt; (DWORD)si.lpMaximumApplicationAddress );

    return true;
}

//--- EXIT ---------------------------------------------------------------------
</code></pre>
<p>ich will doch nur den speicher durchlaufen und alles speicherpages auf read/write setzen... wieso aber gibt er mir immer nur nen error wieder?</p>
<p>Gruß Tobi.</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/186514/virtualalloc-bringt-nur-den-zugriff-auf-eine-unzulässige-addresse-wieso</link><generator>RSS for Node</generator><lastBuildDate>Sun, 05 Jul 2026 01:36:43 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/186514.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 09 Jul 2007 18:26:29 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to VirtualAlloc(), bringt nur den Zugriff auf eine unzulässige addresse. wieso? on Mon, 09 Jul 2007 18:28:46 GMT]]></title><description><![CDATA[<p>hi, es waer toll wenn ich euch mal diesen code anschauen wuerded, speziel die aller letzte funktion.</p>
<pre><code class="language-cpp">/*******************************************************************************

    Author  : Tobias Stein
    Date    : 9th July '07
    Project : Kill PAGE_GUARD
    File    : KillPG2.cpp
    Remark  : Many memory addresses will protected by PAGE_GUARD, if you want to
              manipulate or read an address, PAGE_GUARD cause an exception, so
              you got no access.
              This application should turn off the fucking PAGE_GUARD.

    All Rights Reserved!

*******************************************************************************/

//--- Includes -----------------------------------------------------------------

#include &lt;windows.h&gt;
#include &lt;fstream.h&gt;
#include &lt;commctrl.h&gt;

//--- Globals ------------------------------------------------------------------

#define ID_BUTTON_TURNOFF               1000
#define ID_PROGRESSBAR_STATUS           1001

char szAppName[ ] = &quot;Kick the fucking PAGE_GUARD&quot;;
char szAppTitle[ ] = &quot;Turn off the fucking PAGE_GUARD&quot;;

//--- Prototype ----------------------------------------------------------------

LRESULT CALLBACK WinProc( HWND, UINT, WPARAM, LPARAM );
void lasterror( );
void EnableDebugPrivilege( );
bool turnItOff( HWND );

//--- Main ---------------------------------------------------------------------

WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow ) {

    HWND hWnd;
    WNDCLASS wc;
    MSG msg;

    wc.style = CS_VREDRAW | CS_HREDRAW;
    wc.lpfnWndProc = WinProc;
    wc.cbClsExtra = 0;
    wc.cbWndExtra = 0;
    wc.hInstance = hInstance;
    wc.hIcon = LoadIcon( 0, IDI_APPLICATION );
    wc.hCursor = LoadCursor( 0, IDC_ARROW );
    wc.hbrBackground = reinterpret_cast&lt; HBRUSH &gt;( GetStockObject( BLACK_BRUSH ) );
    wc.lpszMenuName = 0;
    wc.lpszClassName = szAppName;

    if( !( RegisterClass( &amp;wc ) ) ) {

        MessageBox( 0, &quot;Couldn't register window by windows!&quot;, &quot;Shutdown error!&quot;, MB_OK | MB_ICONERROR );
        return 0;
    }

    hWnd = CreateWindowEx( 0,
                           szAppName, szAppTitle,
                           WS_SYSMENU | WS_MINIMIZEBOX,
                           CW_USEDEFAULT, CW_USEDEFAULT, 320, 220,
                           0,
                           0,
                           hInstance,
                           0 );

    if( !hWnd ) {

        MessageBox( 0, &quot;Couldn't create the window!&quot;, &quot;Shutdown error!&quot;, MB_OK | MB_ICONERROR );
        return 0;
    }

    ShowWindow( hWnd, nCmdShow );
    UpdateWindow( hWnd );

    while( GetMessage( &amp;msg, 0, 0, 0 ) ) {

        TranslateMessage( &amp;msg );
        DispatchMessage( &amp;msg );
    }

    return( msg.wParam );
}

//--- Windowprocedur -----------------------------------------------------------

LRESULT CALLBACK WinProc( HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam ) {

    HINSTANCE hInst;
    static RECT wndRect;
    static HWND hButton_to;
    static HWND hProgressBar;

    switch( message ) {

        case WM_CREATE: {

            hInst = ( (LPCREATESTRUCT)lParam )-&gt;hInstance;
            InitCommonControls( );

            hButton_to = CreateWindowEx( 0, &quot;BUTTON&quot;, &quot;KickIT&quot;, WS_CHILD | WS_VISIBLE,
                                         107, 110, 100, 30, hWnd, (HMENU)ID_BUTTON_TURNOFF,
                                         hInst, 0 );

            hProgressBar = CreateWindowEx( WS_EX_CLIENTEDGE, PROGRESS_CLASS, 0,
                                           WS_CHILD | WS_VISIBLE | WS_BORDER,
                                           0, 0, 0, 0, hWnd, (HMENU)ID_PROGRESSBAR_STATUS,
                                           hInst, 0 );

            SendMessage( hProgressBar, PBM_SETRANGE32, 0, 524256 );
            SendMessage( hProgressBar, PBM_SETSTEP, 1, 0 );
            return 0;
        }

        case WM_SIZE: {

            GetClientRect( hWnd, &amp;wndRect );
            MoveWindow( hProgressBar, wndRect.left, wndRect.bottom - 20, wndRect.right, 20, true );
            return 0;
        }

        case WM_COMMAND: {

            switch( LOWORD( wParam ) ) {

                case ID_BUTTON_TURNOFF: {

                    switch( HIWORD( wParam ) ) {

                        case BN_CLICKED: {

                            turnItOff( hProgressBar );
                            break;
                        }
                    }
                    break;
                }
            }
            return 0;
        }

        case WM_DESTROY: {

            PostQuitMessage( 0 );
            return 0;
        }
    }
    return( DefWindowProc( hWnd, message, wParam, lParam ) );
}

//--- Definitions --------------------------------------------------------------

void lasterror( ) {

    LPVOID lpMsgBuf;

    FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
                   0,
                   GetLastError(),
                   MAKELANGID( LANG_NEUTRAL, SUBLANG_DEFAULT ), // Default language
                   (LPTSTR) &amp;lpMsgBuf,
                   0,
                   NULL );

    // Display the string.
    MessageBox( NULL, (char*)lpMsgBuf, &quot;GetLastError&quot;, MB_OK | MB_ICONINFORMATION );
    // Free the buffer.
    LocalFree( lpMsgBuf );
}

void EnableDebugPrivilege( ) {

    TOKEN_PRIVILEGES priv;
	HANDLE hThis, hToken;
	LUID luid;

	hThis = GetCurrentProcess();

	OpenProcessToken( hThis, TOKEN_ADJUST_PRIVILEGES, &amp;hToken );

	LookupPrivilegeValue( 0, &quot;seDebugPrivilege&quot;, &amp;luid );

	priv.PrivilegeCount = 1;
	priv.Privileges[ 0 ].Luid = luid;
	priv.Privileges[ 0 ].Attributes = SE_PRIVILEGE_ENABLED;

	AdjustTokenPrivileges( hToken, false, &amp;priv, 0, 0, 0 );

	CloseHandle( hToken );
	CloseHandle( hThis );
}

bool turnItOff( HWND hProgressBar ) {

    SYSTEM_INFO si;
    MEMORY_BASIC_INFORMATION mbi;
    DWORD dwOldProtect;
    LPVOID lpAddress;
    DWORD dwCurrentPage;

    EnableDebugPrivilege( );
    memset( &amp;si, 0, sizeof( SYSTEM_INFO ) );
    memset( &amp;mbi, 0, sizeof( MEMORY_BASIC_INFORMATION ) );

    GetSystemInfo( &amp;si );
    dwCurrentPage = (DWORD)si.lpMinimumApplicationAddress;

   do {

        VirtualQuery( (LPVOID)dwCurrentPage, &amp;mbi, sizeof( MEMORY_BASIC_INFORMATION ) );
        lpAddress = VirtualAlloc( mbi.BaseAddress, mbi.RegionSize, MEM_COMMIT, PAGE_READWRITE );

        if( !( VirtualProtect( mbi.BaseAddress, mbi.RegionSize, PAGE_READWRITE, &amp;dwOldProtect ) ) ) {

            lasterror( );
            return false;
        }

        VirtualFree( lpAddress, mbi.RegionSize, MEM_DECOMMIT );
        lpAddress = 0;
        SendMessage( hProgressBar, PBM_STEPIT, 0, 0 );
        dwCurrentPage += ( si.dwPageSize );

    } while( dwCurrentPage &lt; (DWORD)si.lpMaximumApplicationAddress );

    return true;
}

//--- EXIT ---------------------------------------------------------------------
</code></pre>
<p>ich will doch nur den speicher durchlaufen und alles speicherpages auf read/write setzen... wieso aber gibt er mir immer nur nen error wieder?</p>
<p>Gruß Tobi.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1321775</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1321775</guid><dc:creator><![CDATA[T0bi]]></dc:creator><pubDate>Mon, 09 Jul 2007 18:28:46 GMT</pubDate></item><item><title><![CDATA[Reply to VirtualAlloc(), bringt nur den Zugriff auf eine unzulässige addresse. wieso? on Mon, 09 Jul 2007 21:24:28 GMT]]></title><description><![CDATA[<p>Eventuell das Ziel nochmal überdenken.</p>
<p>Alle Seiten auf read/write gesetzt bedeutet auch, dass kein Code ausgeführt wird / werden kann.</p>
<p>*edit* Nachtrag :</p>
<p>Wenn eine Seite nicht gelesen werden kann, heisst es nicht unbedingt, dass sie durch PAGE_GUARD geschützt ist.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1321848</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1321848</guid><dc:creator><![CDATA[[[global:guest]]]]></dc:creator><pubDate>Mon, 09 Jul 2007 21:24:28 GMT</pubDate></item><item><title><![CDATA[Reply to VirtualAlloc(), bringt nur den Zugriff auf eine unzulässige addresse. wieso? on Mon, 09 Jul 2007 21:34:36 GMT]]></title><description><![CDATA[<blockquote>
<p>Alle Seiten auf read/write gesetzt bedeutet auch, dass kein Code ausgeführt wird / werden kann.</p>
</blockquote>
<p>versteh ich jetzt net? abber soll das net gerade das bewirken das man vollen zugriff auf alle addressen hat?<br />
meinst du ich sollte noch vor alloc mit mbi.State auf free prüfen und schaun ob überhaup PG hat? und fals net continue machen?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1321856</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1321856</guid><dc:creator><![CDATA[T0bi]]></dc:creator><pubDate>Mon, 09 Jul 2007 21:34:36 GMT</pubDate></item><item><title><![CDATA[Reply to VirtualAlloc(), bringt nur den Zugriff auf eine unzulässige addresse. wieso? on Tue, 10 Jul 2007 08:23:30 GMT]]></title><description><![CDATA[<p>mir ist mal aufgefallen das ich irgendwie nur die aller erste seite allocieren kann( also 0x00010000 - 0x00011000 ), wenn ueberhaupt, getlasterror meint immer &quot;Unbekannte prozedur&quot; oder so in der art. jetzt wollte ich mal versuchen die naechste seite( also 0x00011000 - 0x00012000 ) zu allozieren, aber da kam sofort wieder die Meldung, dass es ein Zugriff auf eine unzulässige Addresse ist. hm wieso denn ? -.-</p>
<p>Gruß Tobi.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1322033</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1322033</guid><dc:creator><![CDATA[T0bi]]></dc:creator><pubDate>Tue, 10 Jul 2007 08:23:30 GMT</pubDate></item><item><title><![CDATA[Reply to VirtualAlloc(), bringt nur den Zugriff auf eine unzulässige addresse. wieso? on Tue, 10 Jul 2007 09:03:12 GMT]]></title><description><![CDATA[<p>Mal ganz grundsätzlich: Was bezweckst Du mit diesem Code?<br />
Was meinst Du mit &quot;fucking&quot; PAGE_GUARD?</p>
<p>Ist Dir eigentlich klar, das:<br />
1. Page guards haben nichts mit geschützen Seiten zu tun (siehe Anmerkung von merker)<br />
2. Page Guards notwendig sind damit Dein Stack wachsen kann.<br />
3. Read only Seiten Deinen Exe Code schützen.<br />
4. Daten geschützt mit einem Read only Attribute auf der Seite damit diese wirklich konstant sind?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1322064</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1322064</guid><dc:creator><![CDATA[Martin Richter]]></dc:creator><pubDate>Tue, 10 Jul 2007 09:03:12 GMT</pubDate></item></channel></rss>