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 


Delphi - Tfilestream buffered Search Replace

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

Joined: 11 Dec 2013
Posts: 78

PostPosted: Mon May 19, 2014 12:54 pm    Post subject: Delphi - Tfilestream buffered Search Replace Reply with quote

Now, I can easily program this to load the entire file into memory. That's all well and good for small files. But with large files... they have to be loaded and written in chunks with a buffer.

The issue then is the boundaries between buffers.

Let's say we are searching for ABCD.

And our string is

XXXXXABCD

But, in this simplified buffer, let's say only 8 chars (remember, chars are equivalent to bytes) are loaded at a time.

XXXXXABC

Now, D is placed in the next buffer update. And my search will not find ABCD anymore. I've had a look around online, and there seems to be a lot of confusion about how best to tackle this issue.

So, any recommendations?
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: Mon May 19, 2014 1:22 pm    Post subject: Reply with quote

Read a buffer from the file
Then scan it
When done decrease the read pointer by 7 and read another buffer (that will deal with the overlap)
Repeat till the end of the file is reached

Also, i recommend you look into filemapping
Back to top
View user's profile Send private message MSN Messenger
dlpb
Advanced Cheater
Reputation: 0

Joined: 11 Dec 2013
Posts: 78

PostPosted: Mon May 19, 2014 1:45 pm    Post subject: Reply with quote

I thought about doing that before, but wouldn't there be some issues if:

The change made, let's say, is AA to AAB...

Then...

when it goes back 7 places, the overlap may end up going over this change again, and replacing AAB (which it now is) with AABB. In other words, going back over the same part introduces another issue?
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: Mon May 19, 2014 2:12 pm    Post subject: Reply with quote

The file you're reading from should not be the same file as you're writing to. So you are reading the unmodified file

But since your intent is to have the ability to change the filesize (I really hope it's not binary as that often will mess things up) then make a list of locations to change, and when done scanning write the file with the modifications at the proper locations. (you can only have a file open for either writing or reading anyhow)

_________________
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
dlpb
Advanced Cheater
Reputation: 0

Joined: 11 Dec 2013
Posts: 78

PostPosted: Mon May 19, 2014 2:17 pm    Post subject: Reply with quote

Yeah, I'm just giving people the freedom to edit any file. I will have 2 main functions... if the search and replace lengths are the same, it can be handled much easier. And of course, a file like an executable would always be equal length replacements.

I'll to use fmcreate when filesize changes.

There are times when you do want to change an exe length... like once, when I wanted to single out only bytes that Ascii text uses... but generally, no one will have any use for that.

I like doing things completely...

Anyway, cheers for that. Adding change indexes may just do it.
Back to top
View user's profile Send private message
dlpb
Advanced Cheater
Reputation: 0

Joined: 11 Dec 2013
Posts: 78

PostPosted: Mon May 26, 2014 4:51 pm    Post subject: Reply with quote

Ok, rather than open a new thread, I am wondering if there is an easy way to do the following:

convert 4 chars to hex. Therefore

ÿÿÿÿ

would equal 4294967295

Because ÿ ansi value is 255.

Would I have to process each char (which I have done already in my own function), or is there a nifty delphi trick?
Back to top
View user's profile Send private message
justa_dude
Grandmaster Cheater
Reputation: 23

Joined: 29 Jun 2010
Posts: 893

PostPosted: Mon May 26, 2014 7:01 pm    Post subject: Reply with quote

dlpb wrote:
Ok, rather than open a new thread, I am wondering if there is an easy way to do the following:

convert 4 chars to hex. Therefore

ÿÿÿÿ

would equal 4294967295

Because ÿ ansi value is 255.

Would I have to process each char (which I have done already in my own function), or is there a nifty delphi trick?


You can use Ord and long multiplication or iterate over the bytes in a dword, but modern Pascal supports casts doesn't it?

_________________
A nagy kapu mellett, mindig van egy kis kapu.
----------------------
Come on...
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: Tue May 27, 2014 3:38 am    Post subject: Reply with quote

Just use a pointer of a specific type like a pdword

You can also typecast on the fly from an incompatible type like a char array
E.g.
Code:

pdword(@bytearray[123])^

_________________
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
dlpb
Advanced Cheater
Reputation: 0

Joined: 11 Dec 2013
Posts: 78

PostPosted: Tue May 27, 2014 12:22 pm    Post subject: Reply with quote

you know, Dark Byte, I REALLY need to start paying attention to pointers... I guess it's easy to forgo their use for most things, and then forget how valuable they can be (Delphi does a lot of it for you so).

Thanks again Smile
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