RAM



  • Also habe es jetzt so:
    Testprogramm:

    #include <stdio.h>
    
    int main()
    {
        int x=666;
        printf("Adresse von x: %x", &x);
        printf("%d", x);
        getchar();
    
        printf("%d", x);
        getchar();
        return 0;
    }
    

    Dort will ich versuchen an den Wert 666 zu kommen mit diesem Programm:

    #include <stdio.h>
    #include <windows.h>
    
    #define BLOCKSIZE                       32
    
    void print(char *szText)
    {
        for(unsigned int i=0; i<strlen(szText); i++)
            printf("%c", szText[i]);
    
    }
    
    int main()
    {
        HWND                                            hWnd;
      HANDLE                                        hProc;
      DWORD                                         dwProcID;
      DWORD                                         dwRw = 0;  
      unsigned                                  adrStart    = 0x00000000;
      unsigned                                  adrEnd      = 0x80000000;
      unsigned char                         buffer[BLOCKSIZE];
      unsigned                                  b;
      unsigned long                         iBytesRead=0;
      MEMORY_BASIC_INFORMATION  mbi;
    
      // find notepad
      hWnd = FindWindow(0, "C:\\Dokumente und Einstellungen\\Administrator\\Desktop\\demo.exe");
      if(!hWnd)
        return 0;
    
        // get process id
        GetWindowThreadProcessId(hWnd, &dwProcID);
    
        // open process
        hProc = OpenProcess(PROCESS_ALL_ACCESS, FALSE, dwProcID);
    
        // start stopping
      DWORD st=GetTickCount();
    
      // begin
        for(; adrStart<adrEnd; adrStart+=BLOCKSIZE){         
            // get some info
            VirtualQueryEx(hProc, (LPCVOID)adrStart,    &mbi,   BLOCKSIZE);
    
            if(mbi.State==MEM_COMMIT){
                b=1;
                unsigned c=adrStart;
            printf("%X - %X   ", adrStart, adrStart+BLOCKSIZE);
                while(c<adrStart+BLOCKSIZE){
                    if(ReadProcessMemory(hProc,(LPCVOID)c,&b, sizeof(b),&dwProcID)){
                        // state
                        iBytesRead+=BLOCKSIZE;
    
                        printf("%c", b);
                        c++;
                    }
                }           
                getchar();
            }
    
        }
    
        // stop stopping
        printf("\n\nFinihed! %d MiliSek.\n%d,%d MBytes searched", (GetTickCount()-st), iBytesRead/(1024*1024), iBytesRead%(1024*1024));
    
        // close handle
        CloseHandle(hProc);//<-- Wichtig!
    
        // quit
        fflush(stdin);
        getchar();
      return 0;
    }
    

    Die Ausgabe des Programms lautet:

    10000 - 10020   A L L U S E R S P R O F I L E =
    10020 - 10040   C : \ D o k u m e n t e   u n d
    10040 - 10060     E i n s t e l l u n g e n \ A
    10060 - 10080   l l   U s e r s   A P P D A T A
    10080 - 100A0   = C : \ D o k u m e n t e   u n
    100A0 - 100C0   d   E i n s t e l l u n g e n \
    100C0 - 100E0   A d m i n i s t r a t o r \ A n
    100E0 - 10100   w e n d u n g s d a t e n   B a
    10100 - 10120   s e m a k e = C : \ P r o g r a
    10120 - 10140   m m e \ M i c r o s o f t   S D
    10140 - 10160   K \ I n c l u d e \ B K O f f i
    10160 - 10180   c e . M a k   B k o f f i c e =
    10180 - 101A0   C : \ P r o g r a m m e \ M i c
    101A0 - 101C0   r o s o f t   S D K \ .   C o m
    101C0 - 101E0   m o n P r o g r a m F i l e s =
    101E0 - 10200   C : \ P r o g r a m m e \ G e m
    10200 - 10220   e i n s a m e   D a t e i e n
    10220 - 10240   C O M P U T E R N A M E = P A R
    10240 - 10260   A N O I A C   C o m S p e c = C
    10260 - 10280   : \ W I N N T \ s y s t e m 3 2
    10280 - 102A0   \ c m d . e x e   C O R P A T H
    102A0 - 102C0   = C : \ W I N N T \ M i c r o s
    102C0 - 102E0   o f t . N E T \ F r a m e w o r
    102E0 - 10300   k \ v 1 . 0 . 2 2 0 4 \   H O M
    10300 - 10320   E D R I V E = C :   H O M E P A
    10320 - 10340   T H = \   I N C L U D E = C : \
    10340 - 10360   P r o g r a m m e \ M i c r o s
    10360 - 10380   o f t . N e t \ F r a m e w o r
    10380 - 103A0   k S D K \ i n c l u d e \ ; C :
    103A0 - 103C0   \ P r o g r a m m e \ M i c r o
    103C0 - 103E0   s o f t   S D K \ I n c l u d e
    103E0 - 10400   \ . ; C : \ P r o g r a m m e \
    10400 - 10420   M i c r o s o f t   V i s u a l
    10420 - 10440     S t u d i o \ V C 9 8 \ a t l
    10440 - 10460   \ i n c l u d e ; C : \ P r o g
    10460 - 10480   r a m m e \ M i c r o s o f t
    10480 - 104A0   V i s u a l   S t u d i o \ V C
    104A0 - 104C0   9 8 \ m f c \ i n c l u d e ; C
    104C0 - 104E0   : \ P r o g r a m m e \ M i c r
    104E0 - 10500   o s o f t   V i s u a l   S t u
    10500 - 10520   d i o \ V C 9 8 \ i n c l u d e
    10520 - 10540     I N E T S D K = C : \ P r o g
    10540 - 10560   r a m m e \ M i c r o s o f t
    10560 - 10580   S D K \ .   L I B = C : \ P r o
    10580 - 105A0   g r a m m e \ M i c r o s o f t
    105A0 - 105C0   . N e t \ F r a m e w o r k S D
    105C0 - 105E0   K \ L i b \ ; C : \ P r o g r a
    105E0 - 10600   m m e \ M i c r o s o f t   S D
    10600 - 10620   K \ L i b \ . ; C : \ P r o g r
    10620 - 10640   a m m e \ M i c r o s o f t   V
    10640 - 10660   i s u a l   S t u d i o \ V C 9
    10660 - 10680   8 \ m f c \ l i b ; C : \ P r o
    10680 - 106A0   g r a m m e \ M i c r o s o f t
    106A0 - 106C0     V i s u a l   S t u d i o \ V
    106C0 - 106E0   C 9 8 \ l i b   L O G O N S E R
    106E0 - 10700   V E R = \ \ P A R A N O I A C
    10700 - 10720   M S D e v D i r = C : \ P r o g
    10720 - 10740   r a m m e \ M i c r o s o f t
    10740 - 10760   V i s u a l   S t u d i o \ C o
    10760 - 10780   m m o n \ M S D e v 9 8   M S S
    10780 - 107A0   d k = C : \ P r o g r a m m e \
    107A0 - 107C0   M i c r o s o f t   S D K \ .
    107C0 - 107E0   M s t o o l s = C : \ P r o g r
    107E0 - 10800   a m m e \ M i c r o s o f t   S
    10800 - 10820   D K \ .   N U M B E R _ O F _ P
    10820 - 10840   R O C E S S O R S = 1   O S = W
    10840 - 10860   i n d o w s _ N T   O s 2 L i b
    10860 - 10880   P a t h = C : \ W I N N T \ s y
    10880 - 108A0   s t e m 3 2 \ o s 2 \ d l l ;
    108A0 - 108C0   P a t h = C : \ P r o g r a m m
    108C0 - 108E0   e \ D e v - C p p \ B i n ; C :
    108E0 - 10900   \ P r o g r a m m e \ D e v - C
    10900 - 10920   p p \ l i b \ g c c - l i b \ m
    10920 - 10940   i n g w 3 2 \ 2 . 9 5 . 3 - 6 ;
    10940 - 10960   C : \ P r o g r a m m e \ M i c
    10960 - 10980   r o s o f t . N e t \ F r a m e
    10980 - 109A0   w o r k S D K \ B i n \ ; C : \
    109A0 - 109C0   W I N N T \ M i c r o s o f t .
    109C0 - 109E0   N E T \ F r a m e w o r k \ v 1
    109E0 - 10A00   . 0 . 2 2 0 4 \ ; C : \ W I N N
    10A00 - 10A20   T \ s y s t e m 3 2 ; C : \ W I
    10A20 - 10A40   N N T ; C : \ W I N N T \ S y s
    10A40 - 10A60   t e m 3 2 \ W b e m ; C : \ P r
    10A60 - 10A80   o g r a m m e \ M i c r o s o f
    10A80 - 10AA0   t   S D K \ B i n \ . ; C : \ P
    10AA0 - 10AC0   r o g r a m m e \ M i c r o s o
    10AC0 - 10AE0   f t   S D K \ B i n \ W i n N T
    10AE0 - 10B00   \ . ; C : \ P R O G R A ~ 1 \ U
    10B00 - 10B20   L T R A E ~ 1 ; c : \ P R O G R
    10B20 - 10B40   A ~ 1 \ O m n i H t t p \ p h p
    10B40 - 10B60   ; C : \ P r o g r a m m e \ M i
    10B60 - 10B80   c r o s o f t   V i s u a l   S
    10B80 - 10BA0   t u d i o \ C o m m o n \ T o o
    10BA0 - 10BC0   l s \ W i n N T ; C : \ P r o g
    10BC0 - 10BE0   r a m m e \ M i c r o s o f t
    10BE0 - 10C00   V i s u a l   S t u d i o \ C o
    10C00 - 10C20   m m o n \ M S D e v 9 8 \ B i n
    10C20 - 10C40   ; C : \ P r o g r a m m e \ M i
    10C40 - 10C60   c r o s o f t   V i s u a l   S
    10C60 - 10C80   t u d i o \ C o m m o n \ T o o
    10C80 - 10CA0   l s ; C : \ P r o g r a m m e \
    10CA0 - 10CC0   M i c r o s o f t   V i s u a l
    10CC0 - 10CE0     S t u d i o \ V C 9 8 \ b i n
    10CE0 - 10D00   ; C : \ P r o g r a m m e \ M i
    10D00 - 10D20   c r o s o f t   S D K \ B i n \
    10D20 - 10D40   . ; C : \ P r o g r a m m e \ M
    10D40 - 10D60   i c r o s o f t   S D K \ B i n
    10D60 - 10D80   \ W i n N T \ .   P A T H E X T
    10D80 - 10DA0   = . C O M ; . E X E ; . B A T ;
    10DA0 - 10DC0   . C M D ; . V B S ; . V B E ; .
    10DC0 - 10DE0   J S ; . J S E ; . W S F ; . W S
    10DE0 - 10E00   H ; . V B S   P R O C E S S O R
    10E00 - 10E20   _ A R C H I T E C T U R E = x 8
    10E20 - 10E40   6   P R O C E S S O R _ I D E N
    10E40 - 10E60   T I F I E R = x 8 6   F a m i l
    10E60 - 10E80   y   6   M o d e l   6   S t e p
    10E80 - 10EA0   p i n g   2 ,   A u t h e n t i
    10EA0 - 10EC0   c A M D   P R O C E S S O R _ L
    10EC0 - 10EE0   E V E L = 6   P R O C E S S O R
    10EE0 - 10F00   _ R E V I S I O N = 0 6 0 2   P
    10F00 - 10F20   r o g r a m F i l e s = C : \ P
    10F20 - 10F40   r o g r a m m e   S y s t e m D
    10F40 - 10F60   r i v e = C :   S y s t e m R o
    10F60 - 10F80   o t = C : \ W I N N T   T E M P
    10F80 - 10FA0   = C : \ D O K U M E ~ 1 \ A D M
    10FA0 - 10FC0   I N I ~ 1 \ L O K A L E ~ 1 \ T
    10FC0 - 10FE0   e m p   T M P = C : \ D O K U M
    10FE0 - 11000   E ~ 1 \ A D M I N I ~ 1 \ L O K
    11000 - 11020   A L E ~ 1 \ T e m p   U S E R D
    11020 - 11040   O M A I N = P A R A N O I A C
    11040 - 11060   U S E R N A M E = A d m i n i s
    11060 - 11080   t r a t o r   U S E R P R O F I
    11080 - 110A0   L E = C : \ D o k u m e n t e
    110A0 - 110C0   u n d   E i n s t e l l u n g e
    110C0 - 110E0   n \ A d m i n i s t r a t o r
    110E0 - 11100   w i n d i r = C : \ W I N N T
    11100 - 11120
    11120 - 11140
    11140 - 11160
    11160 - 11180
    11180 - 111A0
    ...
    ...
    ...
    

    Also irgentwie scheint es ja zu klappen, aber es will nicht so richtig. Normalerweise müsste auch unten noch die Anzeige kommen wielange das Program benötigt hat und wieviel Bytes es verarbeitet hat, aber diese wird nie erreicht.

    Wo ist mein Fehler?
    DAnke!

    cu para
    😃



  • Also falls es jemand interessiert, ich habs geschafft, Strings in anderern Anwendungen zu ändern, die sich im Speicher befanden.
    Man startet mein Program, gibt den Fenstertitle des Programs ein, dann noch den zu suchenden String, dann den String durch den der String ersetzt werden soll. OK - Fertig

    Hier der Code:

    #include <stdio.h>
    #include <stdlib.h>
    #include <windows.h>
    
    #define BLOCKSIZE                       4096
    
    int main()
    {
        // memory
        HWND                                            hWnd;
      HANDLE                                        hProc;
      DWORD                                         dwProcID;
      DWORD                                         dwRw = 0;  
      unsigned                                  adrStart    = 0x00000000;
      unsigned                                  adrEnd      = 0x80000000;
      unsigned char                         buffer[BLOCKSIZE];
      unsigned                                  c;
      unsigned long                         iBytesRead=0;
      MEMORY_BASIC_INFORMATION  mbi;
    
      // string
      char                                          szWindow[MAX_PATH];
      char                                          szWanted[MAX_PATH];
      char                                          szChangeTo[MAX_PATH];
      char                                          *szReadBuffer;
      int                                               iWantedSize;
    
      // get the window to cheat
      printf("Windowname: ");
      scanf("%s", &szWindow);
    
      // find the window
      //strcpy(szWindow, "C:\\Dokumente und Einstellungen\\Administrator\\Desktop\\demo.exe"); // test
      hWnd = FindWindow(0, szWindow);
    
      // no window found
      if(!hWnd){
        printf("window not found!");
        fflush(stdin);
        getchar();
        return 0;   
        }
    
        // get the variable to find
        printf("Variable  : ");
        scanf("%s", &szWanted);
    
        // get the variable to change in
        printf("Change to : ");
        scanf("%s", &szChangeTo);
    
        // allocate space for readbuffer
        iWantedSize = strlen(szWanted);
        szReadBuffer = new char[iWantedSize];
    
        // get process id
        GetWindowThreadProcessId(hWnd, &dwProcID);
    
        // open process
        hProc = OpenProcess(PROCESS_ALL_ACCESS, FALSE, dwProcID);
    
        // start stopping
      DWORD st=GetTickCount();
    
      // begin
        for(; adrStart<adrEnd; adrStart+=BLOCKSIZE){         
            // get some info
            VirtualQueryEx(hProc, (LPCVOID)adrStart,    &mbi,   BLOCKSIZE);
    
            // found accessable memory, inspect it
            if(mbi.State==MEM_COMMIT && mbi.Protect==PAGE_READWRITE ){
                // examine this block
                for(int c=0; c<BLOCKSIZE; c+=iWantedSize){
                    ReadProcessMemory(hProc, (LPCVOID)(adrStart+c), (LPVOID)szReadBuffer, iWantedSize, 0);  
    
                    //printf("%s", szReadBuffer);
    
                    // compare memo with string to find                 
                    if(strcmp(szReadBuffer, szWanted)==0){
                        // yes! found
                        printf("Address of %s is => %x\n", szWanted, adrStart+c);
    
                        // ok, let it change
                        if(WriteProcessMemory(hProc, (LPVOID)(adrStart+c), (LPVOID)szChangeTo, strlen(szChangeTo), 0)==0)
                            printf("writing error!\n");
                    }
    
                    // bytes read
    
                }
    
            }
    
        }
    
        // stop stopping
        printf("\n\nFinihed! %d MiliSek.\n%d,%d MBytes searched", (GetTickCount()-st), iBytesRead/(1024*1024), iBytesRead%(1024*1024));
    
        // close handle
        CloseHandle(hProc);//<-- Wichtig!
    
        // quit
        fflush(stdin);
        getchar();
      return 0;
    }
    

    So dann hätt ich aber noch ne Frage. Das Programm funzt wenn es heisst:

    char szA[]="HALLO";
    

    und ich lasse "HALLO" durch "HOHOH" ersetzen. Alles kein Problem, aber wie kann ich einen Integer (int x=9) finden und ändern?

    cu para
    😃



  • Schickschick, aber ifndet dein Programm auch Strings die auf der Grenze zwischen zwei Pages liegen? 😉

    zu den Integers...du musst halt nu jede Stelle mit dem gesuchten Int vergelichen, ich würde aber davon abraten, sofern du nicht explizit darauf achtest, keine execute-pages zu untersuchen, weil die chance dass du nen programmteil killst doch ziemlich groß ist.


Anmelden zum Antworten