I have never used Asm before, so I've had a little bit of trouble trying to write a Hook in Asm for a process. I've also had trouble with the function FlushInstructionCache. Here is my problematic code snippet ( the real project is 1,000+ lines, but the rest of the code executes with no problems ).
( The code I posted below begins at line 627 )
Code:
Newmem = VirtualAllocEx( RobloxHandle, NULL, 32, MEM_COMMIT | MEM_RESERVE, PAGE_EXECUTE_READWRITE );
if ( Newmem == NULL )
{
return;
} else
{
__asm
{
Newmem
movss xmm3,[edx]
addss xmm3,xmm3
addss xmm3,xmm3
ret
"MyProcess.exe"+0x3BC6AE
call Newmem
ret
};
if ( FlushInstructionCache( ProcessHandle, NULL, NULL) == 0 )
{
return;
}
}
Here was what I wanted the above code to do :
Overall goal : Create a hook in MyProcess.exe and let the application be able to call the memory I allocated for execution.
Step 1 : Allocate code in memory
Step 2 : Return to main if the Allocation failed ( and exit )
Step 3 : If the allocation did not fail, do the following :
- Put the code in the asm bracket after Newmem at Newmem's address
- Overwrite the code at the offset of "MyProcess.exe"+0x3BC6AE with a call to the allocated memory's address and return back.
- Use FlushInstructionCache() to insure the above code was added and executed properly, and return to main if the function fails ( and exit )
Appendage : Newmem is declared as a void *
Of course, this code executes with 2 warnings and errors which are listed below :
Code:
|In function 'input_loop':|
|635|error: expected '(' before '{' token|
|637|warning: statement with no effect|
|637|error: expected ';' before 'movss'|
|647|warning: passing argument 3 of 'FlushInstructionCache' makes integer from pointer without a cast|
include\winbase.h|1382|note: expected 'DWORD' but argument is of type 'void *'|
||=== Build finished: 2 errors, 2 warnings ===|
Please help me get the code written properly.