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 


[6.3+ bug]Scans on files cause crashs or corrupted results

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine
View previous topic :: View next topic  
Author Message
Gniarf
Grandmaster Cheater Supreme
Reputation: 43

Joined: 12 Mar 2012
Posts: 1285

PostPosted: Sun Oct 27, 2013 5:54 pm    Post subject: [6.3+ bug]Scans on files cause crashs or corrupted results Reply with quote

I'm looking for bits that are =1 in the attached config0.dat and that are =0 in both other files, so:
1-I open config0.dat in CE x86 and do a first binary scan for bits that are set.
2-Then open config1.dat and do a next scan for bits that are =0. Yet the result window shows some offsets that are still =1 in config1.dat.
3-If do a second rescan on config1.dat for bits that are =0, I get 0 results, even if some results were shown as =0 on the previous scan.

If I do the same thing on CE x64, CE crashes or silently closes on step 2.

Note1: I'm always using the "bits" mode instead of "decimal".
Note2: It's not cpu affinity this time Wink.

Seen on CE r2192.

I've tried to reproduce that behavior on files that are in the cheat engine directory, but failed, that's why I'm posting the files I'm working on.

Sample affected files: http://www.mediafire.com/?od09tq1sjs0ep3j

EDIT: It's not specific to the binary datatype, I also get corrupted results and crashs with the byte datatype.

_________________
DO NOT PM me if you want help on making/fixing/using a hack.
Back to top
View user's profile Send private message
Gniarf
Grandmaster Cheater Supreme
Reputation: 43

Joined: 12 Mar 2012
Posts: 1285

PostPosted: Fri Nov 01, 2013 12:04 am    Post subject: Reply with quote

Ok, I decided to go ahead and fix the bug myself. Basically there were 2 array overflow issues in TScanner.nextnextscanmembinary:
1-j could go past maxindex.
2-maxindex was 1 byte too big.

All in all I suggest the following fix:
Code:
TScanner.nextnextscanmembinary
...
begin
  i:=0;
  //maxindex:=chunksize;
  maxindex:=chunksize-1; //ex: if you have 1 byte chunk, max index should be 0.
  vsize:=variablesize;
  alist:=addresslist;
  currentbase:=0;
  phandle:=processhandle;

  while i<maxindex do
  begin
   j:=i+1;
             
    currentbase:=alist[i].address and qword($FFFFFFFFFFFFF000);
    //while j<=maxindex do //if j=maxindex and the if below is true, then j becomes maxindex+1.
    while j<maxindex do 
    begin
      if (currentbase)=(qword(alist[j].address+vsize-1) and qword($fffffffffffff000)) then
        inc(j)
      else
      begin
        dec(j);
        break;
      end;
    end;



Obviously that doesn't fix the problem for scans with the byte datatype, I'll look at it later but in the meantime the exact scenario is:
1-open config0.dat in ce x64, scan for a byte an unknown initial value.
2-open config1.dat, filter with unchanged value.
3-filter again with unchanged value -> crash.

_________________
DO NOT PM me if you want help on making/fixing/using a hack.
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 471

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

PostPosted: Fri Nov 01, 2013 4:43 am    Post subject: Reply with quote

Thanks, i hadn't had time to look into it yet (i did look over the file access when making the big endian file scanner but didn't see anything wrong there)

actually, it's a little bit more complex

it's fixed in the svn now

_________________
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
Gniarf
Grandmaster Cheater Supreme
Reputation: 43

Joined: 12 Mar 2012
Posts: 1285

PostPosted: Fri Nov 01, 2013 11:24 am    Post subject: Reply with quote

Got up in the middle of the night thinking "Oh Sh*** what if found=1 -> chunksize=1 -> maxindex=0 -> no while looping ?!"... Well looks like you found it first, sorry for screwing up.

Anyway, doing some tests around this bug I created a file that contains db 01,01, and guess what, if I scan for "1", type binary, CE will only find one result. After some investigation it boils down to variablesize being = 2 because getBytecountBinaryString (from memscan.pas) thinks that "1" takes 2 bytes, so you'd need a special handler incase result mod 8=1 (since 9 bits always take 2 bytes).

...But that'd only partly solve the problem, since I could redo my experiment with a file containing db 03,03 and scanning for "11". There the problem is that the scanning loop in TScanner.FirstScanmem/TScanner.FirstNextScanmem should be stopped at N bits from the end instead of a given number of bytes when scanning for binary strings.

_________________
DO NOT PM me if you want help on making/fixing/using a hack.
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 471

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

PostPosted: Fri Nov 01, 2013 2:56 pm    Post subject: Reply with quote

check the svn. there was one more situation where next scan would bork out
_________________
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
Gniarf
Grandmaster Cheater Supreme
Reputation: 43

Joined: 12 Mar 2012
Posts: 1285

PostPosted: Fri Nov 01, 2013 4:05 pm    Post subject: Reply with quote

About the fix in getBytecountBinaryString, if you do it that way you get result=2+N for a 8*N+1 bit string (except when N=0) which gives 3 bytes for 9 bits. Correct me if I'm wrong but such string can only spread over 1+N bytes. So i'd go for:
Code:
if (result mod 8<2) then //8*N bits spread over up to N+1 bytes
  result:=1+result div 8  //8*N+1 always spread over N+1 bytes
else
  result:=2+(result div 8);//8*N+(2 to 7) spread over up to N+2 bytes



-------------------------------------
Just a some random bit of code I felt like dumping there, doesn't add or fix anything but looks cleaner to me:
Code:
j:=i;
//finds the last alist element that is entierely on the same page as alist[i]
while (j<maxindex) and ( (currentbase)=(qword(alist[j+1].address+vsize-1) and qword($fffffffffffff000)) ) do
begin
  inc(j)
end;



EDIT: apparently the x64 crash seems to have gone away with r2198.

_________________
DO NOT PM me if you want help on making/fixing/using a hack.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine 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