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 


Lazarus GetModuleBaseAddress

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

Joined: 23 Jan 2010
Posts: 42
Location: Germany

PostPosted: Thu Jun 02, 2016 11:59 pm    Post subject: Lazarus GetModuleBaseAddress Reply with quote

I recently starting using lazarus and I almost got the GetModuleBaseAddress
function to work except for this line:

Code:

GetModuleInformation(PHandle, Modules[i], @ModuleInfo, SizeOf(ModuleInfo));



Code:

unit1.pas(81,62) Error: Call by var for arg no. 3 has to match exactly: Got "Pointer" expected "_MODULEINFO"


I'm not very experienced so maybe I'm missing something really obvious.
Back to top
View user's profile Send private message
hhhuut
Grandmaster Cheater
Reputation: 6

Joined: 08 Feb 2015
Posts: 607

PostPosted: Fri Jun 03, 2016 1:51 am    Post subject: Reply with quote

Try removing the "@" character from "@ModuleInfo".
Back to top
View user's profile Send private message
aeree
Cheater
Reputation: 3

Joined: 23 Jan 2010
Posts: 42
Location: Germany

PostPosted: Fri Jun 03, 2016 2:00 am    Post subject: Reply with quote

hhhuut wrote:
Try removing the "@" character from "@ModuleInfo".


I tried that but then GetModuleBaseAddress just returns 0
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 470

Joined: 09 May 2003
Posts: 25807
Location: The netherlands

PostPosted: Fri Jun 03, 2016 2:59 am    Post subject: Reply with quote

perhaps there is something else in the code wrong
_________________
Do not ask me about online cheats. I don't know any and wont help finding them.

Like my help? Join me on Patreon so i can keep helping
Back to top
View user's profile Send private message MSN Messenger
aeree
Cheater
Reputation: 3

Joined: 23 Jan 2010
Posts: 42
Location: Germany

PostPosted: Fri Jun 03, 2016 9:52 am    Post subject: Reply with quote

Dark Byte wrote:
perhaps there is something else in the code wrong



Possible. I wrote a little test program to check. I removed the '@' character as hhhuut suggested. Still doesn't work though.


Code:


program Memhacktest;

uses SysUtils, Windows, jwapsapi;

var hwindow:HWND;
    hprocess:HANDLE;
    procid:DWORD;
    value:SINGLE;
    modbase:^DWORD;


    function GetModuleBaseAddress(ProcessID: Cardinal; MName: String): Pointer;
    var
      Modules         : Array of HMODULE;
      cbNeeded, i     : Cardinal;
      ModuleInfo      : TModuleInfo;
      ModuleName      : Array[0..MAX_PATH] of Char;
      PHandle         : THandle;
    begin
      Result := nil;
      SetLength(Modules, 1024);
      PHandle := OpenProcess(PROCESS_QUERY_INFORMATION + PROCESS_VM_READ, False, ProcessID);
      if (PHandle <> 0) then
      begin
        EnumProcessModules(PHandle, @Modules[0], 1024 * SizeOf(HMODULE), cbNeeded); //Getting the enumeration of modules
        SetLength(Modules, cbNeeded div SizeOf(HMODULE)); //Setting the number of modules
        for i := 0 to Length(Modules) - 1 do //Start the loop
        begin
          GetModuleBaseName(PHandle, Modules[i], ModuleName, SizeOf(ModuleName)); //Getting the name of module
          if AnsiCompareText(MName, ModuleName) = 0 then //If the module name matches with the name of module we are looking for...
          begin
            GetModuleInformation(PHandle, Modules[i], ModuleInfo, SizeOf(ModuleInfo)); //Get the information of module
            Result := ModuleInfo.lpBaseOfDll; //Return the information we want (The image base address)
            CloseHandle(PHandle);
            Exit;
          end;
        end;
      end;
    end;




begin
  hwindow:=FindWindow(nil,'Half-Life'); //Works fine
  GetWindowThreadProcessId(hwindow, @procid); //same
  hprocess:=OpenProcess(PROCESS_ALL_ACCESS,FALSE,procid); //nothing yet
  modbase:= GetModuleBaseAddress(procid,'hw.dll'); //fuck


  writeln('HWND: ' + inttostr(hwindow));
  writeln('ProcessID: ' + inttostr(procid));
  writeln('hProcess: ' + inttostr(hprocess));
  writeln('modbase: 0x' + inttohex(dword(modbase),10));
  readln();
end.




Output:
Back to top
View user's profile Send private message
aeree
Cheater
Reputation: 3

Joined: 23 Jan 2010
Posts: 42
Location: Germany

PostPosted: Sat Jun 04, 2016 2:22 am    Post subject: Reply with quote

I solved the problem by compiling it in 32bit.
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 470

Joined: 09 May 2003
Posts: 25807
Location: The netherlands

PostPosted: Sat Jun 04, 2016 2:47 am    Post subject: Reply with quote

if there are more than 1024 modules it will fail (after reallocating you don't call
EnumProcessModules again)

and you may want to define TModuleInfo yourself, as the jwa* units in lazarus don't do alignment properly.
Usually just copy pasting it to your own unit will fix it

_________________
Do not ask me about online cheats. I don't know any and wont help finding them.

Like my help? Join me on Patreon so i can keep helping
Back to top
View user's profile Send private message MSN Messenger
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