Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


making my own PostMessage bypass .dll in Delphi

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
Anden100
Grandmaster Cheater
Reputation: 0

Joined: 20 Apr 2007
Posts: 668

PostPosted: Mon Apr 14, 2008 7:20 am    Post subject: making my own PostMessage bypass .dll in Delphi Reply with quote

Im not much of a programmer, but i decided to give it a shot

i've been trying to "convert" a C++ source i found (ty 4ng3licDew):

Code:
// myHookHop.cpp : Defines the entry point for the DLL application.
//

#include "stdafx.h"

HINSTANCE hInst; // Instance of user32 DLL
DWORD DLLFunc;

BOOL APIENTRY DllMain( HANDLE hModule,
                       DWORD  ul_reason_for_call,
                       LPVOID lpReserved
                )
{
   if (ul_reason_for_call == DLL_PROCESS_ATTACH) {

      hInst = LoadLibrary("user32.dll");

      DLLFunc = NULL;
      if (hInst != NULL) {
         DLLFunc = (DWORD)GetProcAddress(hInst, "PostMessageA") + 5;
      }

   } else if (ul_reason_for_call == DLL_PROCESS_DETACH) {
       
      if (hInst != NULL) {
         // Un-Load DLL
         ::FreeLibrary(hInst);
         hInst = NULL;
      }   
   }

    return TRUE;
}

__declspec(naked) BOOL WINAPI myPostMessageA(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
{
   __asm
   {
      mov  edi, edi
      push ebp
      mov  ebp, esp
      jmp dword ptr ds:[DLLFunc]

   }
}


But im a little confused about the main procedure, so far this is what i got:

Code:
library Project1;

{ Important note about DLL memory management: ShareMem must be the
  first unit in your library's USES clause AND your project's (select
  Project-View Source) USES clause if your DLL exports any procedures or
  functions that pass strings as parameters or function results. This
  applies to all strings passed to and from your DLL--even those that
  are nested in records and classes. ShareMem is the interface unit to
  the BORLNDMM.DLL shared memory manager, which must be deployed along
  with your DLL. To avoid using BORLNDMM.DLL, pass string information
  using PChar or ShortString parameters. }

uses
  SysUtils,
  Classes,
  windows;

{$R *.res}

var
  hInst1: hInst;
  DLLFunc: DWord;

procedure DllMain(HANDLE: hModule; ul_reason_for_call: DWord);
begin
  hInst1 := LoadLibrary('user32.dll');

  DLLFunc:= 0;
  if hInst1 <> 0 then
  begin
    DLLFunc := (DWORD(GetProcAddress(hInst1, 'PostMessageA'))) + 5;
  end

  else if (ul_reason_for_call = DLL_PROCESS_DETACH) then
  begin
      if (hInst1 <> 0) then
      begin
         FreeLibrary(hInst1);
         hInst1 := 0;
      end;
  end;
end;

function myPostMessageA(hWnd: HWND;Msg: UINT; wParam: WPARAM; lParam: LPARAM): BOOL; stdcall
begin
   asm
      mov  edi, edi
      push ebp
      mov  ebp, esp
      jmp dword ptr ds:[DLLFunc]
   end;
end;

exports
myPostMessageA;

end.


Could any1 please tell me, how i do the DllMain procedure in delphi?
Back to top
View user's profile Send private message
4ng3licDew
Cheater
Reputation: 0

Joined: 14 Feb 2008
Posts: 28

PostPosted: Mon Apr 14, 2008 7:50 am    Post subject: Reply with quote

I use google and look for: Dll delphi

Code:

procedure DllMain(reason: integer) ;
begin
   case reason of
     DLL_PROCESS_ATTACH:
     begin
       // Load Library
     end;
     DLL_PROCESS_DETACH
     begin
       // Unload Library
     end;
   end;
end; (*DllMain*)

.
.
.


begin
   DllProc := @DllMain;
   DllProc(DLL_PROCESS_ATTACH) ;
end.
Back to top
View user's profile Send private message
Anden100
Grandmaster Cheater
Reputation: 0

Joined: 20 Apr 2007
Posts: 668

PostPosted: Mon Apr 14, 2008 7:56 am    Post subject: Reply with quote

I know that one, but still all the variables in the DLLMain procedure, is it possible to get rid of them?[/code]
Back to top
View user's profile Send private message
4ng3licDew
Cheater
Reputation: 0

Joined: 14 Feb 2008
Posts: 28

PostPosted: Mon Apr 14, 2008 8:26 am    Post subject: Reply with quote

Check out topic: [Help] Delphi+API hooks (user32)
forum(dot)cheatengine(dot)org/viewtopic.php?p=1958331

I copy this code from Rot1's and modified it. This is just an idea. I have not tested it:
Code:

.
.
.
uses
  SysUtils,
  Classes,
  windows;

{$R *.res}

var
    DblWord: DWORD;
    hHandle: THandle;

procedure DllMain(reason: integer) ;
begin
   case reason of
      DLL_PROCESS_ATTACH:
      begin
         hHandle:=LoadLibrary('user32.dll');
         DblWord:=DWORD(GetProcAddress(hHandle,'PostMessageA'))+5;
      end;
      DLL_PROCESS_DETACH
      begin
         FreeLibrary(hHandle);
      end;
   end;
end; (*DllMain*)

function myPostMessageA(hWnd:HWND; MSG:UINT; WPARAM:wParam; LPARAM:lParam):BOOL;stdcall; export;
begin
   asm
      mov edi,edi
      push ebp
      mov esp,ebp
      jmp [DblWord]
   end;
end;

exports myPostMessageA;

begin
   DllProc := @DllMain;
   DllProc(DLL_PROCESS_ATTACH) ;
end.
Back to top
View user's profile Send private message
Anden100
Grandmaster Cheater
Reputation: 0

Joined: 20 Apr 2007
Posts: 668

PostPosted: Mon Apr 14, 2008 9:11 am    Post subject: Reply with quote

Omg ty, thats awesome, ill take a look at that one!

Ty! it works perfectly!

Found out, that a big part, of what was in the main procedure, were actually unnessesary (how do you spell that?), after removing big parts of it, it got it to work even better Razz

Dammit: "Sorry, but you will have to wait 34696 seconds before you can give rep"
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites