Help[C++ & ASM] Write value in ASM dosn't work

Posts 1–11 of 11 · Page 1 of 1
[C++ & ASM] Write BYTE in ASM, Howto Write / Read BYTE by Read/WriteProcessMemory?
Hello MPGH Com,

 
Old Problem -> Solved
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
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
}
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
}
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
Weird. Works perfectly fine for me.
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
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.
"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
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.

http://msdn.microsoft.com/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)
}
why not writing it like that?:

Code:
*(BYTE*)(ADDRESS) = 0x90; // byte "0x90" (nop) is just an example
Posts 1–11 of 11 · Page 1 of 1

Post a Reply

Similar Threads

Tags for this Thread

None

Talk with us