It's an bypass for PostMessageA (For a game) but it's in C++ and I belive C# doesn't have assembler to let me convert it so how could I get this to work with C#? I don't know enought C++ to create DLLs :-(
Code:
DWORD dwPostMessage = (DWORD)GetProcAddress( LoadLibrary( _T("user32.dll") ), "PostMessageA") + 5;
_declspec(dllexport) BOOL WINAPI __PostMessageA( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
{
_asm
{
mov edi,edi
push ebp
mov ebp,esp
jmp dword ptr ds:[dwPostMessage]
}
}
BOOL WINAPI DllMain( HMODULE hModule, DWORD dwReason, LPVOID lpReserved )
{
switch ( dwReason )
{
case DLL_PROCESS_ATTACH:
case DLL_THREAD_ATTACH:
case DLL_THREAD_DETACH:
case DLL_PROCESS_DETACH:
break;
}
}
Loading
Sergio FonsecaPosted Apr 30, 2008, 5:54 PM
I'm starting a project in C++ to test if it really bypasses PostMessageA before spending my time on more work. Thank you xP
AlanPosted Apr 29, 2008, 7:33 PM
After removing DllMain (which didn't seem to be doing anything) and moving the declaration inside __PostMessageA(), I managed to compile the following code as a C dll (which I called sergio.dll):
#include
_declspec(dllexport) BOOL WINAPI __PostMessageA( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
{
DWORD dwPostMessage = (DWORD)GetProcAddress( LoadLibraryA( "user32.dll" ), "PostMessageA") + 5;
_asm
{
mov edi,edi
push ebp
mov ebp,esp
jmp dword ptr ds:[dwPostMessage]
}
}
However, when I tried to call this by changing the P/Invoke signature in the C# program to:
[DllImport("sergio.dll", EntryPoint = "__PostMessageA")]
static extern bool PostMessage(IntPtr hWnd, uint msg, int wParam, int lParam);
I got a System.AccessViolationException :(
I suspect that this is because the frame pointer register 'ebp' is being modified by the inline assembly code because there was a warning to this effect when I compiled the dll. Your chances of getting this to work from C# are not therefore looking too good.
Of course, there's no way of translating this code to C# because it doesn't support inline assembly of native code or, for that matter, MSIL.