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 


Function not working locating a base address

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

Joined: 24 May 2007
Posts: 215

PostPosted: Sat Nov 01, 2014 5:51 am    Post subject: Function not working locating a base address Reply with quote

Code:

DWORD GetBaseAddr(DWORD pid,char* modName)
{
HANDLE snapshot = CreateToolhelp32Snapshot(TH32CS_SNAPALL,pid);

MODULEENTRY32 modEnt;

modEnt.dwSize = sizeof(MODULEENTRY32);

Module32First(snapshot,&modEnt);
do {
if(strcmp( modEnt.szModule,modName) == 0)
{
return (DWORD)modEnt.modBaseAddr;
}
} while(Module32Next(snapshot,&modEnt));

return 0;
}

Not working on 64 bit process, any help? works 100% on 32 bit
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 470

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

PostPosted: Sat Nov 01, 2014 7:02 am    Post subject: Reply with quote

You need to strip the path from szModule and i recommend stricmp because the charcase could be different
_________________
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
shakib187
Expert Cheater
Reputation: 0

Joined: 24 May 2007
Posts: 215

PostPosted: Sat Nov 01, 2014 5:32 pm    Post subject: Reply with quote

Alright after some investagating, I found out the process name was too long for me to read, I tried googling for the problem but came up with nothing. Any help would be appreciated!
Back to top
View user's profile Send private message
atom0s
Moderator
Reputation: 205

Joined: 25 Jan 2006
Posts: 8585
Location: 127.0.0.1

PostPosted: Sat Nov 01, 2014 5:57 pm    Post subject: Reply with quote

Some notes about your function:
- The name you pass to the function can be const char* instead of just char*.
- You are opening a handle and never closing it.
- You should check the return of Module32First to ensure it didn't fail.
- strcmp is case-sensitive, check out strnicmp instead.

Also if you are looking for a specific module, there is no reason to use 'TH32CS_SNAPALL'. Instead, you should use TH32CS_SNAPMODULE or TH32CS_SNAPMODULE32 specifically.

_________________
- Retired.
Back to top
View user's profile Send private message Visit poster's website
shakib187
Expert Cheater
Reputation: 0

Joined: 24 May 2007
Posts: 215

PostPosted: Sat Nov 01, 2014 7:06 pm    Post subject: Reply with quote

Hey atom0s thanks for replying, I have edited my code and took your advice. I dont understand why I cant get the process module, I can get the processID just fine with my other function

Code:

DWORD GetPID(char* procName)
{
HANDLE handle = CreateToolhelp32Snapshot(TH32CS_SNAPALL,0);
PROCESSENTRY32 procEnt;
procEnt.dwSize = sizeof( PROCESSENTRY32 );

Process32First(handle,&procEnt);
do {
if( strcmp(procEnt.szExeFile,procName) == 0 )
{
return procEnt.th32ProcessID;
}
}while( Process32Next(handle,&procEnt) );
CloseHandle(handle);
return 0;
}


But for some reason this game only, I cannot get the module. I never have run into this problem which is why I'm so confused. I mean it seems to me that the strcmp is not the problem because it can get the PID but I dont know Neutral

In cheat engine the pointer shows up just fine
Back to top
View user's profile Send private message
atom0s
Moderator
Reputation: 205

Joined: 25 Jan 2006
Posts: 8585
Location: 127.0.0.1

PostPosted: Sat Nov 01, 2014 9:54 pm    Post subject: Reply with quote

Is the process you are targeting 64bit?
_________________
- Retired.
Back to top
View user's profile Send private message Visit poster's website
shakib187
Expert Cheater
Reputation: 0

Joined: 24 May 2007
Posts: 215

PostPosted: Sat Nov 01, 2014 10:37 pm    Post subject: Reply with quote

atom0s wrote:
Is the process you are targeting 64bit?


yes
Code:

DWORD base = GetBaseAddr(pid,"launcher64.exe");

HANDLE handle = OpenProcess(PROCESS_ALL_ACCESS, FALSE,
pid);   

Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 470

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

PostPosted: Sun Nov 02, 2014 12:18 am    Post subject: Reply with quote

is your code compiled as a 64-bit process as well? If not, it won't be able to target that process
_________________
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
shakib187
Expert Cheater
Reputation: 0

Joined: 24 May 2007
Posts: 215

PostPosted: Sun Nov 02, 2014 9:33 am    Post subject: Reply with quote

Dark Byte wrote:
is your code compiled as a 64-bit process as well? If not, it won't be able to target that process


Okay I finally got my application to 64 bit
Back to top
View user's profile Send private message
shakib187
Expert Cheater
Reputation: 0

Joined: 24 May 2007
Posts: 215

PostPosted: Mon Nov 03, 2014 2:09 am    Post subject: Reply with quote

I did it, thank you guys for your help, especially DB.
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