Results 1 to 11 of 11
  1. #1
    Benhero's Avatar
    Join Date
    Jun 2011
    Gender
    male
    Posts
    9
    Reputation
    10
    Thanks
    1

    [C++ & ASM] Write BYTE in ASM, Howto Write / Read BYTE by Read/WriteProcessMemory?

    Hello MPGH Com,

     
    I have a Problem with ASM.
    I try to Write a Value to a Adress with ASM.
    Code:
    int rubish;
    DWORD aRubish = 0x421F7C;
    ReadProcessMemory(cHandle, (void*)aRubish, &rubish, sizeof(rubish), 0);
    Sleep(250);
    cout << endl << "Adress: " << aRubish << endl << "Rubish Left: " << rubish << endl;
    __asm{
    	MOV dword ptr [aRubish], 0
    	CALL endSeqence
    }
    ReadProcessMemory(cHandle, (void*)aRubish, &rubish, sizeof(rubish), 0);
    cout << "Adress: " << aRubish << endl << "Rubish Left: " << rubish << endl;
    This is what i get:
    Code:
    Adress:4333436
    Rubish Left: 15
    Adress: 0
    Rubish Left: 15
    At second i try to Override a Sub statement.
    So i was try to chance
    Code:
    SUB edx,01
    to
    Code:
    SUB edx,00
    I try different ways but i don't found a way to do it..

    Hop you unterstand me... <.< I know my english are not the best...


    New Problem:


    I try to write 1 BYTE with your Method.. but it crash again ._.

    Code:
    DWORD aTime = 0x421908;
    DWORD aTimeSub = 0x40508D;
    __asm
    {
    	mov eax, dword ptr ds : [aTime];
    	mov dword ptr ds : [eax], 1;
    	mov eax, ds : [aTimeSub];
    	mov byte ptr[eax], 0x00;
    }
    Cheat Engine:
    Code:
    fessie.exe+508B - 83 EA 01              - sub edx,01
    fessie.exe+508B = 0040508B what means 01 is on 0040508D?
    Or am I wrong?

    #EDIT:
    I try to read just 1 Byte with

    Code:
    DWORD aTimeSub = 0x40508D;
    int timeSub;
    ReadProcessMemory(cHandle, (void*)aTimeSub, &timeSub, sizeof(BYTE), 0);
    But i get This Value: -858993663

    I think this is biger then just 1 Byte

    I wan't to get the Value as Integer. In this case i need the number 1.
    Same at WriteProcessMemory()... how to write 1 Byte.

    Greatz

    Greatz Benhero
    Last edited by Benhero; 12-11-2014 at 09:29 AM. Reason: New Text Title

  2. #2
    殺す必要がある唯一のものは殺されるために準備され人 々である。
    Premium Member
    Hitokiri~'s Avatar
    Join Date
    Oct 2012
    Gender
    female
    Location
    Cancer.
    Posts
    1,201
    Reputation
    24
    Thanks
    937
    My Mood
    Bitchy
    Several things are wrong with your code:

    1.) You're using an external process ( I assume that it's an external process since you're using ReadProcessMemory() ) and trying to use assembly to edit that process.
    2.) Your code to modify the address only modifies the actual value passed ( In this case, "DWORD aRubish" ) in the local process.

    Assuming you're using an external process, you cannot simply use:
    Code:
    mov xxx, yyy
    I'll show you how to do it either way:
    External Method
    Code:
    static DWORD dwAddress = 0x421F7C;
    
    void __cdecl DoCrap( HANDLE hProc )
    {
        DWORD dwCallAddr = DWORD( GetProcAddress( HMODULE( GetModuleHandleA( "kernel32.dll" ) ), "WriteProcessMemory" ) );
        DWORD dwValue = 0; DWORD dwSizeOfValue = sizeof( dwValue );
        __asm
        {
              push 0; // lpNumberOfBytesWritten
              push dword ptr ds:[ dwSizeOfValue ]; // nSize
              lea eax, dword ptr ds:[ dwValue ];
              push eax; // lpBuffer
              push dword ptr ds:[ dwAddress ]; // lpBaseAddress
              push [ esp+8 ]; // hProcess
              call dword ptr ds:[ dwCallAddr ];
        }
    }
    Internal ( DLL ) version:
    Code:
    static DWORD dwAddress = 0x421F7C;
    
    __asm
    {
         mov eax, dword ptr ds:[ dwAddress ];
         mov dword ptr ds:[ eax ], 0; // Value
    }

  3. The Following User Says Thank You to Hitokiri~ For This Useful Post:

    Benhero (12-10-2014)

  4. #3
    Benhero's Avatar
    Join Date
    Jun 2011
    Gender
    male
    Posts
    9
    Reputation
    10
    Thanks
    1
    Sry^^... i forgot to say i use an DLL. So i inject the code.

    and.. It Works!!! o.o Thanks a lot..

    Now i only have the Second Problem...

    .. I try this. But my Game Crashes.
    Code:
    DWORD aTime = 0x421908;
    DWORD aTimeSub = 0x40508D;
    __asm{
    	mov eax, dword ptr ds : [aTime];
    	mov dword ptr ds : [eax], 99;
    	mov eax, dword ptr ds : [aTimeSub]
    	mov byte ptr ds : [eax], 0
    }
    I think my fail was that eax is a to big register... so i don't know what i should use..
    AX or maybe AH/AL..

    Greatz
    Last edited by Benhero; 12-10-2014 at 12:59 PM.

  5. #4
    Mayion's Avatar
    Join Date
    Oct 2012
    Gender
    male
    Location
    Bed
    Posts
    13,498
    Reputation
    4018
    Thanks
    8,377
    My Mood
    Twisted
    @ @Benhero Do I close the thread & mark it as solved?
    I do not use any type of messenger outside of MPGH.
    Inactive but you can reach me through VM/PM.










     

    Donator - 30 August 2013
    Battlefield Minion - 26 October 2013

    Blackshot Minion - 14 January 2014/16 September 2014
    Minecraft Minion - 7 February 2014/16 September 2014
    WarRock Minion - 23 February 2014
    League of Legends Minion - 21 March 2014

    Minion+ - 15 May 2014
    Other Semi-Popular First Person Shooter Minion - 8 August 2014
    CrossFire Minion - 23 October 2014
    Programming Section Minion - 13 November 2014
    Marketplace Minion - 7 December 2014

    Official Middleman - 7 December 2014 - 27 June 2015
    Moderator - 29 December 2014
    Project Blackout Minion - 10 January 2015
    News Force Interviewer - January 2015
    Steam Games Minion - 21 March 2015
    Dragon Nest Minion - 31 March 2015
    Publicist - April 2015 - 21 September 2015
    Global Moderator - 25 August 2015
    Super User - 13 August 2016



  6. The Following User Says Thank You to Mayion For This Useful Post:

    Benhero (12-10-2014)

  7. #5
    Benhero's Avatar
    Join Date
    Jun 2011
    Gender
    male
    Posts
    9
    Reputation
    10
    Thanks
    1
    No, please don't jet. because the second problem are not resolved..
    I can't write a single byte at adress 0xXXXXXX.

    Visual Studio give me the error:
    Code:
    error C2408: Unzulässiger Typ in Verbindung mit dem Operator PTR in 'Erster Operand'
    if i use this code to write 1 Byte.
    Code:
    __asm{
    	mov eax, dword ptr ds : [aTime];
    	mov dword ptr ds : [eax], 99
    	mov eax, dword ptr ds : [aTimeSub];
    	mov byte ptr ds : [eax], 99
    }

  8. The Following User Says Thank You to Benhero For This Useful Post:

    [MPGH]Mayion (12-10-2014)

  9. #6
    殺す必要がある唯一のものは殺されるために準備され人 々である。
    Premium Member
    Hitokiri~'s Avatar
    Join Date
    Oct 2012
    Gender
    female
    Location
    Cancer.
    Posts
    1,201
    Reputation
    24
    Thanks
    937
    My Mood
    Bitchy
    Weird. Works perfectly fine for me.

  10. The Following User Says Thank You to Hitokiri~ For This Useful Post:

    Benhero (12-11-2014)

  11. #7
    Benhero's Avatar
    Join Date
    Jun 2011
    Gender
    male
    Posts
    9
    Reputation
    10
    Thanks
    1
    I try.. but it crash again ._.

    Code:
    Code:
    DWORD aTime = 0x421908;
    DWORD aTimeSub = 0x40508D;
    __asm
    {
    	mov eax, dword ptr ds : [aTime];
    	mov dword ptr ds : [eax], 1;
    	mov eax, ds : [aTimeSub];
    	mov byte ptr[eax], 0x00;
    }
    Cheat Engine:
    Code:
    fessie.exe+508B - 83 EA 01              - sub edx,01
    fessie.exe+508B = 0040508B what means 01 is on 0040508D?
    Or am I wrong?

    #EDIT
    The error is located.. but i don't know how to fix it..
    It is a Access Violation..
    Code:
    Access violation writing at position 0x4050D8

    Greatz
    Last edited by Benhero; 12-11-2014 at 03:02 PM. Reason: Access violation

  12. #8
    0xB4DF00D's Avatar
    Join Date
    Mar 2012
    Gender
    male
    Posts
    46
    Reputation
    10
    Thanks
    28
    My Mood
    Bored
    Quote Originally Posted by Benhero View Post
    I try.. but it crash again ._.

    Code:
    Code:
    DWORD aTime = 0x421908;
    DWORD aTimeSub = 0x40508D;
    __asm
    {
    	mov eax, dword ptr ds : [aTime];
    	mov dword ptr ds : [eax], 1;
    	mov eax, ds : [aTimeSub];
    	mov byte ptr[eax], 0x00;
    }
    Cheat Engine:
    Code:
    fessie.exe+508B - 83 EA 01              - sub edx,01
    fessie.exe+508B = 0040508B what means 01 is on 0040508D?
    Or am I wrong?

    #EDIT
    The error is located.. but i don't know how to fix it..
    It is a Access Violation..
    Code:
    Access violation writing at position 0x4050D8

    Greatz
    Trying to write at .code section without setting the write flag.
    Use VirtualProtect or just use WPM.

  13. #9
    Benhero's Avatar
    Join Date
    Jun 2011
    Gender
    male
    Posts
    9
    Reputation
    10
    Thanks
    1
    "fessie.exe+508B" is the same as "0040508B". What did you mean with Write flag?
    I din't ever use VirtualProtect. I'll try it.. But i don't wanna use WMP.

    Greatz

  14. #10
    0xB4DF00D's Avatar
    Join Date
    Mar 2012
    Gender
    male
    Posts
    46
    Reputation
    10
    Thanks
    28
    My Mood
    Bored
    Quote Originally Posted by Benhero View Post
    "fessie.exe+508B" is the same as "0040508B". What did you mean with Write flag?
    I din't ever use VirtualProtect. I'll try it.. But i don't wanna use WMP.

    Greatz
    0040508B is part of the .code/.text section, and for standards the code section has only PAGE_EXECUTE_READ flag, so you can't write at the code section without changing the memory page flags.

    https://msdn.microsof*****m/en-us/libr...(v=vs.85).aspx

    You have to change the page protection to PAGE_EXECUTE_READWRITE

    Code:
    DWORD old;
    DWORD aTime = 0x421908;
    DWORD aTimeSub = 0x40508D;
    if(VirtualProtect((void*)aTimeSub,0x2000,PAGE_EXECUTE_READWRITE,&old))
    {
    __asm
    {
    	mov eax, dword ptr ds : [aTime];
    	mov dword ptr ds : [eax], 1;
    	mov eax, ds : [aTimeSub];
    	mov byte ptr[eax], 0x00;
    }
    VirtualProtect((void*)aTimeSub,0x2000,old,&old)
    }

  15. #11
    I'm not lazy, I just really enjoy doing nothing.
    Donator
    _PuRe.LucK*'s Avatar
    Join Date
    Apr 2013
    Gender
    male
    Location
    idk bruh.
    Posts
    521
    Reputation
    71
    Thanks
    5,654
    My Mood
    Bored
    why not writing it like that?:

    Code:
    *(BYTE*)(ADDRESS) = 0x90; // byte "0x90" (nop) is just an example

Similar Threads

  1. [Help] How do i write values greater then 255 in VB.NET?
    By ikillindreams in forum Call of Duty Modern Warfare 3 Coding, Programming & Source Code
    Replies: 4
    Last Post: 12-01-2012, 11:32 AM
  2. Warrock dosn't Work !
    By Sn0wn00b in forum WarRock Discussions
    Replies: 16
    Last Post: 09-03-2010, 03:32 AM
  3. My Mombot dosn't work (error)
    By hanzie69 in forum Call of Duty 4 - Modern Warfare (MW) Hacks
    Replies: 0
    Last Post: 02-06-2009, 08:14 AM
  4. [Help] How to write value NOP
    By jaqq3000 in forum Visual Basic Programming
    Replies: 9
    Last Post: 12-02-2007, 11:46 AM
  5. How to write value "NOP"
    By w00t? in forum Visual Basic Programming
    Replies: 2
    Last Post: 10-10-2007, 12:32 PM