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 


[C++] Read the BaseAddress of an .dll file.

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
Tomi20
How do I cheat?
Reputation: 0

Joined: 17 Jul 2013
Posts: 6
Location: Poland

PostPosted: Wed Jul 17, 2013 8:59 am    Post subject: [C++] Read the BaseAddress of an .dll file. Reply with quote

Hello!
I'm trying to write a console application that will display my current position in minecraft. I have three memory addresses like: OpenAL64.dll+2FD00 (the addresses are pointers), and now my question in CE the addresses are displayed and when I write only the "OpenAL64.dll" in the add memory window displays a memory address, but when i Do it in Visual Studio 2012 in C++ there is a too big value or this value equals 0.

This Code displays 0 to the console...
Code:
   hWnd = FindWindow("SunAwtFrame", NULL);
   GetWindowThreadProcessId(hWnd, &dwID);
   DWORD address = (DWORD)GetModuleHandle("OpenAL64.dll");
   printf("%x", address);


I searched up google over two days and I found nothing..
Please help me Embarassed

Thanks in advance.
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 471

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

PostPosted: Wed Jul 17, 2013 9:21 am    Post subject: Reply with quote

CreateToolhelp32Snapshot and Module32First/module32next is one of the easiest methods to find the base address of a module
_________________
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
Tomi20
How do I cheat?
Reputation: 0

Joined: 17 Jul 2013
Posts: 6
Location: Poland

PostPosted: Wed Jul 17, 2013 10:28 am    Post subject: Reply with quote

Ok, nice I see an address.. i Think the address isn't valid..

Screen Shot:
http\//db.tt/ErWR31rm
replace \ with : Smile

And my code:
Code:

   MODULEENTRY32 mModule;

   hWnd = FindWindow("SunAwtFrame", NULL);
   GetWindowThreadProcessId(hWnd, &dwID);

   HANDLE hTool = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE, dwID);
   bool isSuccess = Module32First(hTool, &mModule);

   printf(" Is success? %d, address : %x, name : %s \n", isSuccess, mModule.modBaseAddr, mModule.szModule);


Whan I'm Doing wrong Question
Back to top
View user's profile Send private message
atom0s
Moderator
Reputation: 205

Joined: 25 Jan 2006
Posts: 8587
Location: 127.0.0.1

PostPosted: Wed Jul 17, 2013 11:00 am    Post subject: Reply with quote

You must set the dwSize member inside of MODULEENTRY32 before you can call Module32First for it to work properly.

mModule.dwSize = sizeof( MODULEENTRY32 );
bool isSuccess = Module32First(hTool, &mModule);

Along with that you need to loop Module32Next afterward to keep stepping through the snapshot to find the specific module you are looking for.

_________________
- Retired.
Back to top
View user's profile Send private message Visit poster's website
Tomi20
How do I cheat?
Reputation: 0

Joined: 17 Jul 2013
Posts: 6
Location: Poland

PostPosted: Wed Jul 17, 2013 11:36 am    Post subject: Reply with quote

I changed my code, and now i have the address of OpenAL64.dll, but the address is still wrong.. CE has got an other value.

That's my code:
Code:
   MODULEENTRY32 mModule;
   
   hWnd = FindWindow("SunAwtFrame", NULL);
   GetWindowThreadProcessId(hWnd, &dwID);

   HANDLE hTool = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE, dwID);
   mModule.dwSize = sizeof( MODULEENTRY32 );

   Module32First(hTool, &mModule);
   do{
      printf("Address : %x, name : %s \n", mModule.modBaseAddr, mModule.szModule);
   }while(Module32Next(hTool, &mModule));


In my console application the address of OpenAL64.dll is EDE20000 and in CE "OpenAL64.dll" -> 300905A4D

Do I'm everything wrong? Crying or Very sad
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 471

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

PostPosted: Wed Jul 17, 2013 12:09 pm    Post subject: Reply with quote

Yes

In cheat engine open the memory view window , press ctrl+g and fill in OpenAL64.dl, that will bring you to the address of the module start

_________________
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
Tomi20
How do I cheat?
Reputation: 0

Joined: 17 Jul 2013
Posts: 6
Location: Poland

PostPosted: Wed Jul 17, 2013 12:37 pm    Post subject: Reply with quote

Aha, alright!
But why In C++ from the left in hex are three letters skipped?
CE Memory Viewer -> 7FEEDE20000
C++ -> EDE20000

That's why I can't read the memory!

@Edit: How can I get the whole address?
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 471

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

PostPosted: Wed Jul 17, 2013 1:33 pm    Post subject: Reply with quote

Multiple reasons
1: %x doesn't do 64-bit values, use %llx
2: you store the address in a DWORD instead of d a QWORD or PTR_UINT

_________________
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
Tomi20
How do I cheat?
Reputation: 0

Joined: 17 Jul 2013
Posts: 6
Location: Poland

PostPosted: Wed Jul 17, 2013 1:44 pm    Post subject: Reply with quote

Thanks!! You're a genius!

Topic can be closed.
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