I try to build an application using a builder and a stub but i fail
My builder code :
File.Copy(AppDomain.CurrentDomain.BaseDirectory + @"\Camstub.exe", filepath);
string split = "|";
string info = split + CName.Text + split + Link.Text + split;
FileStream fs = new FileStream(filepath, FileMode.Open, FileAccess.ReadWrite, FileShare.None);
BinaryWriter bw = new BinaryWriter(fs);
fs.Position = fs.Length + 1;
bw.Write(info);
bw.Close();
MessageBox.Show(info);
My stub code :
public MainWindow()
{
InitializeComponent();
StreamReader sr = new StreamReader(System.Windows.Forms.Application.ExecutablePath);
BinaryReader br = new BinaryReader(sr.BaseStream);
byte[] fileData = br.ReadBytes(Convert.ToInt32(sr.BaseStream.Length));
br.Close();
sr.Close();
ASCIIEncoding Enc = new ASCIIEncoding();
string split = "|";
string Message = Enc.GetString(fileData);
MessageBox.Show(Message);
The messagebox in the builder show me:
The application is sucessfully build but the messagebox when i execute it show me:
So, I expect the same messagebox in both.
Any idea ?
Thanks in advance ;)
Based on the information given in the comments, you want to read the |CName|Link| data from the end of the file. The |CName|Link| data can be of variable length.
To deal with variable length data you somehow need to indicate the byte length of the data. In the given scenario here, a simple and suitable solution would be to store the byte length as a 2-byte or 4-byte number at the end of the file after the |CName|Link| data. A 2-byte number (i.e., ushort or UInt16) allows to specify a length of up to 65536 and should likely be sufficient for your purpose. (If the data can be more than 64KB, then use 4 bytes to store the length.)
Thus, the builder should do the following:
The stub should do something like this: