 |
Cheat Engine The Official Site of Cheat Engine
|
| View previous topic :: View next topic |
| Author |
Message |
Luig Cheater
Reputation: 0
Joined: 24 Sep 2010 Posts: 26
|
Posted: Wed Jun 08, 2011 6:13 pm Post subject: AoB scan function crashes target process. [FreePascal] |
|
|
As the title states.
I am using the following function:
| Code: | function CheckBytes(Address:DWORD; bMask:array of byte; szMask:string):Boolean;
var
TestByte:byte;
i:integer;
begin
i:=0;
Result:=True;
for TestByte in bMask do
begin
if (szMask[i] <> '?') and (TestByte <> (PBYTE(Address+i)^)) then
begin
Result:=False;
break;
end;
i += 1;
end;
end;
function FindPattern(bMask:array of byte; szMask:string; dwOffset:DWORD):DWORD;
var
dwAddress:DWORD;
dwLen:DWORD;
j:Integer;
begin
dwAddress := $00400000;
dwLen := $07FFFFFF;
Result:=$00400000;
try
for j := 0 to dwLen do
begin
if CheckBytes((dwAddress+j), bMask, szMask) then
begin
Result:= (dwAddress+j+dwOffset);
break;
end;
end;
except
On E: EAccessViolation Do
ShowMessage('Error');
end;
end; |
I tried to port it from this function :
| Code: | bool Check(const BYTE* pData, const BYTE* bMask, const char* szMask)
{
for(; *szMask; ++szMask, ++pData, ++bMask)
if(*szMask != '?' && *pData != *bMask )
return false;
return (*szMask) == NULL;
}
DWORD FindPattern(BYTE *bMask, char* szMask, DWORD dwOffset)
{
DWORD dwAddress = 0x00400000;
DWORD dwLen = 0x07FFFFFF;
__try
{
for(DWORD i=0; i < dwLen; i++)
if( Check ((BYTE*)( dwAddress + i ), bMask, szMask) )
return (DWORD)(dwAddress + i + dwOffset);
}
__except(EXCEPTION_EXECUTE_HANDLER)
{
MessageBox(NULL, "Find Pattern Error", "Error", MB_OK);
}
return 0x00400000;
} |
This is of course from an injected .dll
Last edited by Luig on Wed Jun 08, 2011 9:39 pm; edited 2 times in total |
|
| Back to top |
|
 |
Slugsnack Grandmaster Cheater Supreme
Reputation: 71
Joined: 24 Jan 2007 Posts: 1857
|
Posted: Wed Jun 08, 2011 6:28 pm Post subject: |
|
|
| wtf. why is findpattern() just scanning irregardless of what memory is paged..
|
|
| Back to top |
|
 |
Luig Cheater
Reputation: 0
Joined: 24 Sep 2010 Posts: 26
|
Posted: Wed Jun 08, 2011 6:50 pm Post subject: |
|
|
I don't know, it's just C++ functions I found that everyone said works so I decided to attempt to port it to Pascal. Can you refer me to a proper function I can port or is already in Pascal.
Edit:
Never mind. My function was like you said trying to access a memory that was not accessible. I'm currently on a tight deadline here so I set the base scan address at 0x04000000 and that did the trick. Later I'm sure I'll be interested in learning how to get memory page information. It would be nice if you could leave me some hints or tips.
edit2:
Okay I found out that wasn't the best way to do it. There weren't many resources on the topic so from the information that I have gathered I tried to write my own function. For some reason it's still crashing, can someone point me to the right direction?
| Code: | function FindPattern(bMask:array of byte; szMask:string; dwOffset:DWORD):DWORD;
var
dwAddress:DWORD;
dwLen:DWORD;
k:DWORD;
MBI: TMemoryBasicInformation;
begin
dwAddress := $00400000;
dwLen := $07FFFFFF;
Result:=$00400000;
While (dwAddress <= dwLen) and (Result=$00400000) do
begin
if VirtualQuery(Pointer(dwAddress), MBI, SizeOf(MBI)) <> 0 then
begin
if (DWORD(MBI.AllocationBase)>0) and (MBI.RegionSize>0) and (MBI.State=MEM_COMMIT) then
begin
for k := 0 to MBI.RegionSize do
begin
if CheckBytes((dwAddress+k), bMask, szMask) then
begin
Result:= (dwAddress+k+dwOffset);
break;
end;
end;
dwAddress+=MBI.RegionSize;
end else
begin
dwAddress+=1;
end;
end else
begin
dwAddress+=1;
end;
end;
end; |
|
|
| Back to top |
|
 |
|
|
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
|
|