Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

search and overwrite binary files data

Posted on 2003-10-23
6
Medium Priority
?
191 Views
Last Modified: 2010-04-05
how i can replace a string into binary files BUT the 2 two strings haven't same length?

eg. old string = "Hi"
new string = "Hello"

example??

bye , tia86

125 points for the correct answer
0
Comment
Question by:Tia86
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 

Author Comment

by:Tia86
ID: 9608134
i have found this code

procedure TForm1.Button1Click(Sender: TObject);
var
  f: file;
  l: Longint;
  FileName, oldstring, newstring, s: string;
begin
  oldstring := 'old_string';
  newstring := 'new_string';
  FileName  := 'file.xyz';
   
  s := oldstring;
  AssignFile(f, FileName);
  Reset(f, 1);
  for l := 0 to FileSize(f) - Length(oldstring) - 1 do
  begin
    Application.ProcessMessages;
    Seek(f, l);
    BlockRead(f, oldstring[1], Length(oldstring));
    if oldstring = s then
    begin
      Seek(f, l);
      BlockWrite(f, newstring[1], Length(newstring));
      ShowMessage('String successfully replaced!');
    end;
    Application.ProcessMessages;
  end;
  CloseFile(f);
end;


but don't work if the 2 strings haven't same lenght...

help me!
0
 
LVL 3

Accepted Solution

by:
BJThomsen earned 172 total points
ID: 9608453
Simply copy the file from one file to another when you get to the string write the new string then the rest of the file.

This could result in corrupt data though. Not sure what the binary data is, but any positional references within the file could now be incorrect. If it was part of a structure the new format may not correctly read ect.

0
 
LVL 17

Assisted Solution

by:Wim ten Brink
Wim ten Brink earned 164 total points
ID: 9613446
Be very careful! Some binary formats depend on string values having a fixed length! There could be a length byte in front of the 'Hi' string or the system expects a fixed length and will consider 'llo' as part of some new data element instead as part of your 'Hello' string value. Especially executables are very sensitive about this. (And some executables maintain a checksum that will invalidate the exe if you modify data inside them.)
0
 
LVL 1

Assisted Solution

by:ttd
ttd earned 164 total points
ID: 9640460
Hi Tia86,

The answer is simply: No way!

Do you want to make your shin-bone 2 inches longer without "modifying" your leg? So modifying things is simple, but to keep the modified things working is not so simple unless you have a full knowledge about the thing that is being modified.

Regards,

ttd
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Suggested Courses

604 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question