tags:

views:

644

answers:

4

I need to change some text values inside an after effect project file that I assume it's a binary file. You cannot edit this file with a text editor, if you do next time you open it you will encounter the error message about corrupted project file.

So i need to for example change "TextArea1" to "Some new text" so as you see the length of the new text is not the same as the original one. should i use BinaryReader or something? how can i find the original String in Byte[] Array i get from this command...

As I'm a newbie in this field please tell me what should I do in this matter.

A: 

Have you got visual studio? If so, do:

  1. File->Open and select the file.
  2. On the open button, press the drop down arrow.
  3. Choose "Open With..."
  4. Select: Binary Editor.

At least you can see what's in the file. This is at least a good starting point. It will show you the byte values, and any character value for the byte on the right-hand side.

As for how to edit the text, it all depends on what the format of the data is. I know you say it's binary, but that isn't a format, saying something is binary just means you don't actually know what the format is. It might be that before a string (text) value, the previous byte gives the length of the text, so you could insert some more text and then increase this value. It might be that the length is stored in two or more bytes (because a byte can only hold values up to 256, and they might use two bytes for the format if they expect they might want text longer than 256). The format might after a piece of text have a byte that has the value 0 to mark the end of the text. Also, text may often be stored with one character in 1 byte, or 1 character in 2 bytes, or for some characters (mandarin etc), the number of bytes per characters can vary.

Good luck! The best advice is to try and track down someone who knows what the files format is. Tell us more about the file, what type is it? Has it got an extension.

Scott Langham
Thank you scott for your answer. yes i have VS but i need to do this programmatically
EBAGHAKI
My file is a simple psd file!This is from visual Studio hex editor: this is where my text is hidding. replacing it is okay but i cannot insert any character probably the length is hiding somewhere.TextObjects [ << /Model << /Text (þÿTHIS IS A TEST MESSAGE)
EBAGHAKI
A: 

I don't know that file structure, but you may not be able to change the length of the text strings. As a test, if you just replaced characters byte for byte, then it would probably not be corrupted.

kenny
A: 

The simplest way to edit is to do:

byte[] data = File.ReadAllBytes("C:\theFileName");
// modify data here
File.WriteAllBytes("C:\theFileName", data);
Scott Langham
A: 

Assuming that the file structure doesn't have any pointers in it indicating field x should be at this byte offset from the start of the file, field y should begin at this other byte offset, etc., you're going to need to something like this:

  1. Read the file in as bytes.
  2. Locate where the change needs to be made.
  3. Write out the bytes before the change.
  4. Write out the bytes of the new text.
  5. Write out the bytes of the file from after the old text.

You didn't say if the text are single-byte, double-byte, or multi-byte which could somewhat complicate step 2 if all the bytes are in a byte area (for instance) but you need to search for text in double- or multi-byte format.

Otis