Articles   Members Online:
-Article/Tip Search
-News Group Search over 21 Million news group articles.
-Delphi/Pascal
-CBuilder/C++
-C#Builder/C#
-JBuilder/Java
-Kylix
Member Area
-Home
-Account Center
-Top 10 NEW!!
-Submit Article/Tip
-Forums Upgraded!!
-My Articles
-Edit Information
-Login/Logout
-Become a Member
-Why sign up!
-Newsletter
-Chat Online!
-Indexes NEW!!
Employment
-Build your resume
-Find a job
-Post a job
-Resume Search
Contacts
-Contacts
-Feedbacks
-Link to us
-Privacy/Disclaimer
Embarcadero
Visit Embarcadero
Embarcadero Community
JEDI
Links
How to patch binary files Turn on/off line numbers in source code. Switch to Orginial background IDE or DSP color Comment or reply to this aritlce/tip for discussion. Bookmark this article to my favorite article(s). Print this article
26-Mar-04
Category
Files Operation
Language
Delphi 3.x
Views
182
User Rating
No Votes
# Votes
0
Replies
0
Publisher:
DSP, Administrator
Reference URL:
DKB
			Author: Arthur Young

How to patch binary files? 

Answer:

Replaces a string in a file with new string. 

1   procedure TForm1.Button1Click(Sender: TObject);
2   var
3     f: file;
4     l: Longint;
5     FileName, oldstring, newstring, s: string;
6   begin
7     oldstring := 'old string';
8     newstring := 'new string';
9     FileName := 'c:\YourFileName.xyz';
10  
11    s := oldstring;
12    AssignFile(f, FileName);
13    Reset(f, 1);
14    for l := 0 to FileSize(f) - Length(oldstring) - 1 do
15    begin
16      Application.ProcessMessages;
17      Seek(f, l);
18      BlockRead(f, oldstring[1], Length(oldstring));
19      if oldstring = s then
20      begin
21        Seek(f, l);
22        BlockWrite(f, newstring[1], Length(newstring));
23        ShowMessage('String successfully replaced!');
24      end;
25      Application.ProcessMessages;
26    end;
27    CloseFile(f);
28  end;


			
Vote: How useful do you find this Article/Tip?
Bad Excellent
1 2 3 4 5 6 7 8 9 10

 

Advertisement
Share this page
Advertisement
Download from Google

Copyright © Mendozi Enterprises LLC