Modify a Binary file(an after effect project file) in c# or c++

Modify a Binary file(an after effect project file) in c# or c++

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.

The Benefits of Using Function Pointers


Is there a best practice for accessing C++ native COM functions to interop from C#?
Have you got visual studio? If so, do: .
How do I use DLLImport with structs as parameters in C#?
  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.

Speed of virtual call in C# vs C++
This is at least a good starting point.

Connect to Exchange - Getting Started Tutorial? [closed]
It will show you the byte values, and any character value for the byte on the right-hand side..
How to find all possible subsets of a given array?
As for how to edit the text, it all depends on what the format of the data is.

“Unable to find an entry point named [function] in dll” (c++ to c# type conversion)
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.

Calling C++ dll function from C#: Of structs, strings and wchar_t arrays
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..


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..


The simplest way to edit is to do:.
byte[] data = File.ReadAllBytes("C:\theFileName"); // modify data here File.WriteAllBytes("C:\theFileName", data); 


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..

61 out of 100 based on 36 user ratings 711 reviews