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 


Need help about a very weird problem?

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

Joined: 24 Jul 2012
Posts: 145

PostPosted: Sun Dec 09, 2012 7:39 am    Post subject: Need help about a very weird problem? Reply with quote

This is about the WINAPI 'SymFromName'.
This is MSDN'S C++ CODE:
Code:
TCHAR szSymbolName[MAX_SYM_NAME];
ULONG64 buffer[(sizeof(SYMBOL_INFO) +
    MAX_SYM_NAME * sizeof(TCHAR) +
    sizeof(ULONG64) - 1) /
    sizeof(ULONG64)];
PSYMBOL_INFO pSymbol = (PSYMBOL_INFO)buffer;

_tcscpy_s(szSymbolName, MAX_SYM_NAME, TEXT("WinMain"));
pSymbol->SizeOfStruct = sizeof(SYMBOL_INFO);
pSymbol->MaxNameLen = MAX_SYM_NAME;

if (SymFromName(hProcess, szSymbolName, pSymbol))
{
    // SymFromName returned success
}
else
{
    // SymFromName failed
    DWORD error = GetLastError();
    _tprintf(TEXT("SymFromName returned error : %d\n"), error);
}



Here is my code(object pascal):
Code:
function GetAddressFromSymbol(phd:Thandle;s:string):ptruint;
const
  BSIZE = (sizeof(SYMBOL_INFO)+MAX_SYM_NAME*SizeOf(TCHAR)+SizeOf(ULONG64)-1) div SizeOf(ULONG64);
var
  buffer:array[0..BSIZE-1]of ULONG64;
  sn:array[0..MAX_SYM_NAME-1] of Char;
  pi:PSYMBOL_INFO;
begin
  if not SymInitialize(phd,nil,true) then
  begin
    MessageBox(0,pchar(SysErrorMessage(GetLastError)),'SymInit Error',MB_OK);
    Exit($00000000);
  end;
  SymSetOptions(SymGetOptions or SYMOPT_CASE_INSENSITIVE);

  ZeroMemory(@sn,SizeOf(sn));
  ZeroMemory(@buffer,SizeOf(buffer));

  sn := s;
  pi := PSYMBOL_INFO(@buffer);

  pi^.SizeOfStruct := SizeOf(SYMBOL_INFO);
  pi^.MaxNameLen := MAX_SYM_NAME;

  if SymFromName(phd,sn,pi) then
  begin
    result:=pi^.Address;
    MessageBox(0,pchar(SysErrorMessage(GetLastError)),'Kidding Me!',MB_OK);
  end else
  begin
    result:=$00000000;
    MessageBox(0,pchar(SysErrorMessage(GetLastError)),'Last Error!',MB_OK);
  end;

  SymCleanup(phd);

end;


The weird thing is that return value of SymFromName is true, but I got error message "The parameter is incorrect!" as the pic showing.At the same time, pi^.address value is $0000000



Capture.PNG
 Description:
 Filesize:  59.01 KB
 Viewed:  3752 Time(s)

Capture.PNG


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

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

PostPosted: Sun Dec 09, 2012 7:22 pm    Post subject: Reply with quote

print out the size of SYMBOL_INFO in both pascal and C , make sure they are the same (for the same architecure)

I often find that the pascal headers aren't always 100% correct due to alignment issues which is why I copy the structures to my own units

http://code.google.com/p/cheat-engine/source/browse/Cheat+Engine+6/symbolhandler.pas?r=818 still uses SymFromName

_________________
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
Alice0725
Expert Cheater
Reputation: 11

Joined: 24 Jul 2012
Posts: 145

PostPosted: Sun Dec 09, 2012 11:00 pm    Post subject: Reply with quote

Dark Byte wrote:
print out the size of SYMBOL_INFO in both pascal and C , make sure they are the same (for the same architecure)

I often find that the pascal headers aren't always 100% correct due to alignment issues which is why I copy the structures to my own units

http://code.google.com/p/cheat-engine/source/browse/Cheat+Engine+6/symbolhandler.pas?r=818 still uses SymFromName



You are right , Dark Byte! The size is different, one is 84, the other one is 88. Thanks! Now, CETack 1.0 finished! Laughing
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