| View previous topic :: View next topic | 
	
	
		| Author | Message | 
	
		| aeree Cheater
 
 ![]() Reputation: 3 
 Joined: 23 Jan 2010
 Posts: 42
 Location: Germany
 
 | 
			
				|  Posted: Thu Jun 02, 2016 11:59 pm    Post subject: Lazarus GetModuleBaseAddress |   |  
				| 
 |  
				| 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 |  | 
	
		|  | 
	
		| hhhuut Grandmaster Cheater
 
  Reputation: 6 
 Joined: 08 Feb 2015
 Posts: 607
 
 
 | 
			
				|  Posted: Fri Jun 03, 2016 1:51 am    Post subject: |   |  
				| 
 |  
				| Try removing the "@" character from "@ModuleInfo". |  | 
	
		| Back to top |  | 
	
		|  | 
	
		| aeree Cheater
 
 ![]() Reputation: 3 
 Joined: 23 Jan 2010
 Posts: 42
 Location: Germany
 
 | 
			
				|  Posted: Fri Jun 03, 2016 2:00 am    Post subject: |   |  
				| 
 |  
				|  	  | hhhuut wrote: |  	  | Try removing the "@" character from "@ModuleInfo". | 
 
 I tried that but then GetModuleBaseAddress just returns 0
 |  | 
	
		| Back to top |  | 
	
		|  | 
	
		| Dark Byte Site Admin
 
  Reputation: 470 
 Joined: 09 May 2003
 Posts: 25807
 Location: The netherlands
 
 | 
			
				|  Posted: Fri Jun 03, 2016 2:59 am    Post subject: |   |  
				| 
 |  
				| 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 |  | 
	
		|  | 
	
		| aeree Cheater
 
 ![]() Reputation: 3 
 Joined: 23 Jan 2010
 Posts: 42
 Location: Germany
 
 | 
			
				|  Posted: Fri Jun 03, 2016 9:52 am    Post subject: |   |  
				| 
 |  
				|  	  | 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 |  | 
	
		|  | 
	
		| aeree Cheater
 
 ![]() Reputation: 3 
 Joined: 23 Jan 2010
 Posts: 42
 Location: Germany
 
 | 
			
				|  Posted: Sat Jun 04, 2016 2:22 am    Post subject: |   |  
				| 
 |  
				| I solved the problem by compiling it in 32bit. |  | 
	
		| Back to top |  | 
	
		|  | 
	
		| Dark Byte Site Admin
 
  Reputation: 470 
 Joined: 09 May 2003
 Posts: 25807
 Location: The netherlands
 
 | 
			
				|  Posted: Sat Jun 04, 2016 2:47 am    Post subject: |   |  
				| 
 |  
				| 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 |  | 
	
		|  | 
	
		|  |