An example I did that creates a binary from predefined hex strings.
Code:
public void CreateFile()
{
GenKey(textBox1.Text, textBox1.Text.Length);
padArray(textBox1.Text);
shiftInt = Convert.ToUInt32(outPut);
prevInt = shiftInt;
for (int n = 0; n < newarrStr.Length; n++)
{
Gen(n, textBox1.Text.Length);
}
middleBit += myOut;
string path = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
using (FileStream stream = new FileStream(path + "\\key-test-alpha.exe", FileMode.Create))
{
using (BinaryWriter writer = new BinaryWriter(stream))
{
writer.Write(StringToByteArray(headerBit1));
writer.Write(StringToByteArray(headerBit2));
writer.Write(StringToByteArray(headerBit3));
writer.Write(StringToByteArray(middleBit));
writer.Write(StringToByteArray(footerBit1));
writer.Write(StringToByteArray(footerBit2));
writer.Write(StringToByteArray(footerBit3));
writer.Write(StringToByteArray(footerBit4));
writer.Write(StringToByteArray(footerBit5));
writer.Write(StringToByteArray(footerBit6));
writer.Write(5);
writer.Close();
}
}
MessageBox.Show("File has been written to your Desktop", "Thank You For Playing", MessageBoxButtons.OK);
}
Project was abandoned due to the binary being digitally signed thats why there are so many different headers and footers written to the file. It was only after I had gotten this far that I realized it was a signature. Still though you get the idea. _________________
<Wiccaan> Bah that was supposed to say 'not saying its dead' lol. Fixing >.>
Joined: 25 Jan 2006 Posts: 8587 Location: 127.0.0.1
Posted: Wed Apr 06, 2011 5:21 pm Post subject:
Look into serialization if you need to handle a large amount of data. It will be in your best interest to serialize a class into a file rather then writing/reading line by line and so on. _________________
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You can download files in this forum