Patch tool needed

  • Thread starter Thread starter Paul
  • Start date Start date
P

Paul

Looking for a small program that will allow me to patch a single byte (same
byte) in over 300 binary files via command line. Any suggestions?

Thanks!
Paul
 
Use a vb script to patch. A=ts.read(num) where num is the bytes into the file. In the example I am patching the second byte (with a space, makes it into a faulty com file). Also B=ts.read(BytesToRead-2) the -2 part needs to be set to your offset. The two is Read(1) + Skip(1). So A holds the the part of the file before your insertion and B after your insertion. The actual byte being changed isn't read at all (the skip). You may wish to read it though and check it before writing the byte. You may also want to backup the file.

'On Error Resume Next
Set objShell = CreateObject("Shell.Application")
Set fso = CreateObject("Scripting.FileSystemObject")
Set Ag=Wscript.Arguments
FName=Ag(0)
Set objFile=fso.GetFile(FName)
BytesToRead=objFile.Size
Set ts = fso.OpenTextFile(FName, 1, vbtrue)
A=ts.read(1)
ts.skip(1)
B=ts.read(BytesToRead-2)
ts.close
Set ts = fso.OpenTextFile(FName, 2, vbtrue)
ts.write A & Chr(32) & B


Then use the for command or something to run on each file.
 
David,

This worked great.

Thanks!
Paul

Use a vb script to patch. A=ts.read(num) where num is the bytes into the
file. In the example I am patching the second byte (with a space, makes it
into a faulty com file). Also B=ts.read(BytesToRead-2) the -2 part needs to
be set to your offset. The two is Read(1) + Skip(1). So A holds the the part
of the file before your insertion and B after your insertion. The actual
byte being changed isn't read at all (the skip). You may wish to read it
though and check it before writing the byte. You may also want to backup the
file.

'On Error Resume Next
Set objShell = CreateObject("Shell.Application")
Set fso = CreateObject("Scripting.FileSystemObject")
Set Ag=Wscript.Arguments
FName=Ag(0)
Set objFile=fso.GetFile(FName)
BytesToRead=objFile.Size
Set ts = fso.OpenTextFile(FName, 1, vbtrue)
A=ts.read(1)
ts.skip(1)
B=ts.read(BytesToRead-2)
ts.close
Set ts = fso.OpenTextFile(FName, 2, vbtrue)
ts.write A & Chr(32) & B


Then use the for command or something to run on each file.
 
Back
Top