Editing Files

murrayf1

Member
Joined
May 5, 2006
Messages
21
Programming Experience
1-3
Hi I want to write a program to automatically edit some files.

Basically the files are encoded and the only way we can understand them in in hex

This is our hex strings nicly formatted.
We need to read:-
{ } { }{ }
28 000200 000001FF 04 6400 E9AB0DFE E044B866 903C3E9A 00000000
28 000200 0000100D 10 6400 00000000 00000000 F5D52A45 00000000

Each block of data is 27 bytes long and need to repeat this search for every 27 byte block until the end of the file and change the block to somthing else eg E9AB0DFE = 001.00.00 00000000 000.00.01 ect

Does anyone have any ideas on how we can do this. the data in its raw unformatted form with header is below:- the data always starts at 000200
5472615820332E3830204461746166696C652E0A436F707972696768742045444320422E562E20313939352D323030322C204D6F6F726472656368742E1A202053797374656D6E722E3A20333035332020204EE45D8ACB964C02BF7440579CBE1E6CBC2430CC9E0FED8E17536F1788910A4113B94AC80414985D1B43AE553B88764D12F236B00884A5A65C13F506A3F4560E674DDB9231D49C17EA18ABB4AB1AC853CA1DA7EE9EB650807BCFC74066C05ADA2B2AA56523B6F97B7677F66F30E402F5BF52AB4A64E366F72BB1B58AC8495A2331276A47086201EDE028770C7822B5B4B38C9604C11907EC0623BD2F2CA9416D2E610CBF80469ECF3D38409A97D023195111E4EE8428FA4B8FD805FC57C89C3FBE3E9CE48A967293810187B10DB82EB02A653567E4AAB00135CCD7547E52A8306C6E4F579555BFA88F22AF6EBA706312B65C534B80053F074D44A61239BB49D9A3E48735724672902C824278F04BFBDB5A1234015E62675E0FC915A1884102DFB7DFC62F5DFB1CCC0D53EAFA636CD3B961E4F07AECB58F159F33E0F5D4E709EEE8E5C076F7CBF7EEC20B85AF31BB7057F782C92F05B7C9370F9AFB8BF07D36B65FC547C84DD2EB89D36A15D4D9EBFD6C3ED82E21E4EDCBDF4D65776214950CF627935B6400000186510007179D098900000000000000000000000000000000000000000000000000000000000050280002000000100D1064000000000000000000F5D52A4500000000
 
I find your question a little confusing but basically I would do this:

Set up a byte array of length 27 containing the bytes you want to find
Set up another byte array containing the bytes to replace
Read the file in (either completely or in parts if it too big and:

Starting from the offset, examine the first byte
If it is the same as the Find-Array's first byte, embark upon a subroutine to compare the remaining 26 bytes
If the subroutine determines a match then write the destination byte array out to the file starting at the offset
If the first bytes dont match, or the subroutine determines no match, advance the offset by 27 bytes and loop to the top of this algorithm


That way you can compare your whole file in 27 byte jumps, it should be 27 times faster than doing byte-by-byte because you state that your blocks are 27 bytes long - so a block either is or is not a candidate for match based on the first byte. If no match, then you can safely skip 27 bytes.

If I have misinterpreted your requirement, I'm sure you can adjust the algoithm accordingly
 
Back
Top