private byte getHeaderByteValue(FileHeaderField a_fileHeaderField) { byte bValue = 0; bValue |= a_fileHeaderField.m_data[0]; return(bValue); }
/// <summary> /// This method consumes the file header and returns a new FileHeaderField each /// time it is called until all fields has been consumed. If the last field has been /// read a FileHeaderField with ID=0xFF is returned. /// </summary> /// <param name="a_fileStream">The FileStream to read from.</param> /// <returns>A FileHeaderField.</returns> private FileHeaderField readField(FileStream a_fileStream) { FileHeaderField fhf = new FileHeaderField(); a_fileStream.Position -= 1; fhf.m_fieldLength = (byte)a_fileStream.ReadByte(); a_fileStream.Position -= 2; fhf.m_fieldID = (byte)a_fileStream.ReadByte(); if (fhf.m_fieldID == 0xFF) { return(fhf); } for (int i = 0; i < fhf.m_fieldLength; i++) { try { a_fileStream.Position -= 2; fhf.m_data[i] = (byte)a_fileStream.ReadByte(); } catch (Exception E) { logger.Debug("Failed to read header field: " + E.Message); } } a_fileStream.Position -= 1; return(fhf); }
/// <summary> /// This method tranforms the data of a FileheaderField to a string. /// </summary> /// <param name="a_fileHeaderField">The FileHeaderField.</param> /// <returns>A string representing the information in the FileHeaderField.</returns> private string getHeaderString(FileHeaderField a_fileHeaderField) { Encoding ascii = Encoding.ASCII; ascii.GetChars(a_fileHeaderField.m_data, 0, a_fileHeaderField.m_fieldLength); return(ascii.GetString(a_fileHeaderField.m_data, 0, a_fileHeaderField.m_fieldLength)); }
private int getHeaderSmallIntValue(FileHeaderField a_fileHeaderField) { int intValue = 0; intValue |= a_fileHeaderField.m_data[0]; intValue <<= 8; intValue |= a_fileHeaderField.m_data[1]; return(intValue); }
/// <summary> /// This method sets the information in a four byte field to represent a integer value. /// </summary> /// <param name="a_fileHeaderField">The FileHeaderField.</param> /// <param name="a_value">The value that the field should contain.</param> private void setHeaderIntValue(FileHeaderField a_fileHeaderField, int a_value) { a_fileHeaderField.m_data[3] = (byte)a_value; a_value >>= 8; a_fileHeaderField.m_data[2] = (byte)a_value; a_value >>= 8; a_fileHeaderField.m_data[1] = (byte)a_value; a_value >>= 8; a_fileHeaderField.m_data[0] = (byte)a_value; }
/// <summary> /// This method writes a FileHeaderField to the file header. /// </summary> /// <param name="a_fileStream">The FileStream to write to.</param> /// <param name="a_fhf">The FileHeaderField.</param> private void writeField(FileStream a_fileStream, FileHeaderField a_fhf) { a_fileStream.Position -= 3; // Skip ID and length for (int i = 0; i < a_fhf.m_fieldLength; i++) { a_fileStream.WriteByte(a_fhf.m_data[i]); a_fileStream.Position -= 2; } a_fileStream.Position += 1; }
private void writeFieldIncludingDetails(FileStream a_fileStream, FileHeaderField a_fhf) { a_fileStream.Position -= 1; // write length a_fileStream.WriteByte(a_fhf.m_fieldLength); a_fileStream.Position -= 2; // write ID a_fileStream.WriteByte(a_fhf.m_fieldID); a_fileStream.Position -= 2; // Skip ID and length for (int i = 0; i < a_fhf.m_fieldLength; i++) { a_fileStream.WriteByte(a_fhf.m_data[i]); a_fileStream.Position -= 2; } a_fileStream.Position += 1; }
/// <summary> /// This method consumes the file header and returns a new FileHeaderField each /// time it is called until all fields has been consumed. If the last field has been /// read a FileHeaderField with ID=0xFF is returned. /// </summary> /// <param name="a_fileStream">The FileStream to read from.</param> /// <returns>A FileHeaderField.</returns> private FileHeaderField readField(FileStream a_fileStream) { FileHeaderField fhf = new FileHeaderField(); a_fileStream.Position -= 1; fhf.m_fieldLength = (byte)a_fileStream.ReadByte(); a_fileStream.Position -= 2; fhf.m_fieldID = (byte)a_fileStream.ReadByte(); if (fhf.m_fieldID == 0xFF) { return(fhf); } for (int i = 0; i < fhf.m_fieldLength; i++) { a_fileStream.Position -= 2; fhf.m_data[i] = (byte)a_fileStream.ReadByte(); } a_fileStream.Position -= 1; return(fhf); }
private byte getHeaderByteValue(FileHeaderField a_fileHeaderField) { byte bValue = 0; bValue |= a_fileHeaderField.m_data[0]; return bValue; }
private void writeFieldIncludingDetails(FileStream a_fileStream, FileHeaderField a_fhf) { a_fileStream.Position -= 1; // write length a_fileStream.WriteByte(a_fhf.m_fieldLength); a_fileStream.Position -= 2; // write ID a_fileStream.WriteByte(a_fhf.m_fieldID); a_fileStream.Position -= 2; // Skip ID and length for (int i = 0; i < a_fhf.m_fieldLength; i++) { a_fileStream.WriteByte(a_fhf.m_data[i]); a_fileStream.Position -= 2; } a_fileStream.Position += 1; }
private int getHeaderSmallIntValue(FileHeaderField a_fileHeaderField) { int intValue = 0; intValue |= a_fileHeaderField.m_data[0]; intValue <<= 8; intValue |= a_fileHeaderField.m_data[1]; return intValue; }
private byte[] getHeaderDateValue(FileHeaderField a_fileHeaderField) { byte[] value = new byte[5]; value = a_fileHeaderField.m_data; return value; }
private byte[] getHeaderDateValue(FileHeaderField a_fileHeaderField) { byte[] value = new byte[5]; value = a_fileHeaderField.m_data; return(value); }
private void setHeaderDateValue(FileHeaderField a_fileHeaderField, byte[] a_value) { a_fileHeaderField.m_data = a_value; }
/// <summary> /// This method consumes the file header and returns a new FileHeaderField each /// time it is called until all fields has been consumed. If the last field has been /// read a FileHeaderField with ID=0xFF is returned. /// </summary> /// <param name="a_fileStream">The FileStream to read from.</param> /// <returns>A FileHeaderField.</returns> private FileHeaderField readField(FileStream a_fileStream) { FileHeaderField fhf = new FileHeaderField(); a_fileStream.Position -= 1; fhf.m_fieldLength = (byte) a_fileStream.ReadByte(); a_fileStream.Position -= 2; fhf.m_fieldID = (byte) a_fileStream.ReadByte(); if (fhf.m_fieldID == 0xFF) return fhf; for (int i = 0; i < fhf.m_fieldLength; i++) { a_fileStream.Position -= 2; fhf.m_data[i] = (byte)a_fileStream.ReadByte(); } a_fileStream.Position -= 1; return fhf; }
/// <summary> /// This method tranforms the data of a FileheaderField to a string. /// </summary> /// <param name="a_fileHeaderField">The FileHeaderField.</param> /// <returns>A string representing the information in the FileHeaderField.</returns> private string getHeaderString(FileHeaderField a_fileHeaderField) { Encoding ascii = Encoding.ASCII; ascii.GetChars(a_fileHeaderField.m_data, 0, a_fileHeaderField.m_fieldLength); return ascii.GetString(a_fileHeaderField.m_data, 0, a_fileHeaderField.m_fieldLength); }
private void setHeaderDateValue(FileHeaderField a_fileHeaderField, byte[] a_value) { a_fileHeaderField.m_data = a_value; }
/// <summary> /// This method sets the data in a FileHeaderField to the values given by a string. /// </summary> /// <param name="a_fileHeaderField">The FileHeaderField.</param> /// <param name="a_string">The string to set.</param> private void setHeaderString(FileHeaderField a_fileHeaderField, string a_string) { System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding(); byte[] bytes = encoding.GetBytes(a_string); a_fileHeaderField.m_data = bytes; }
private void CreateNewFooter(string a_filename, bool create9B, bool create9C, bool createF2) { if (!File.Exists(a_filename)) { return; } FileStream fs = new FileStream(a_filename, FileMode.Open, FileAccess.ReadWrite); fs.Seek(0, SeekOrigin.End); long writePos; fileLength = fs.Position; writePos = fs.Position; FileHeaderField fhf = new FileHeaderField(); fhf.m_fieldID = (byte)0x91; fhf.m_fieldLength = (byte)m_vehicleidnr.Length; setHeaderString(fhf, m_vehicleidnr); writeFieldIncludingDetails(fs, fhf); // fs.Position = writePos; fhf.m_fieldID = (byte)0x94; fhf.m_fieldLength = (byte)m_partNumber.Length; setHeaderString(fhf, m_partNumber); writeFieldIncludingDetails(fs, fhf); //fs.Position = writePos; fhf.m_fieldID = (byte)0x95; fhf.m_fieldLength = (byte)m_softwareVersion.Length; setHeaderString(fhf, m_softwareVersion); writeFieldIncludingDetails(fs, fhf); //fs.Position = writePos; fhf.m_fieldID = (byte)0x97; fhf.m_fieldLength = (byte)m_carDescription.Length; setHeaderString(fhf, m_carDescription); writeFieldIncludingDetails(fs, fhf); //fs.Position = writePos; fhf.m_fieldID = (byte)0x9A; fhf.m_fieldLength = (byte)m_datemodified.Length; setHeaderString(fhf, m_datemodified); writeFieldIncludingDetails(fs, fhf); //fs.Position = writePos; if (create9C) { fhf.m_fieldID = (byte)0x9C; fhf.m_fieldLength = 4; setHeaderIntValue(fhf, m_9cvalue); writeFieldIncludingDetails(fs, fhf); } //fs.Position = writePos; if (create9B) { fhf.m_fieldID = (byte)0x9B; fhf.m_fieldLength = 4; setHeaderIntValue(fhf, m_symboltableaddress); writeFieldIncludingDetails(fs, fhf); } //fs.Position = writePos; if (createF2) { fhf.m_fieldID = (byte)0xF2; fhf.m_fieldLength = 4; setHeaderIntValue(fhf, m_checksumF2); writeFieldIncludingDetails(fs, fhf); } //fs.Position = writePos; fhf.m_fieldID = (byte)0xFB; fhf.m_fieldLength = 4; setHeaderIntValue(fhf, m_checksumFB); writeFieldIncludingDetails(fs, fhf); //fs.Position = writePos; fhf.m_fieldID = (byte)0xFC; fhf.m_fieldLength = 4; setHeaderIntValue(fhf, m_bottomOfFlash); writeFieldIncludingDetails(fs, fhf); //fs.Position = writePos; fhf.m_fieldID = (byte)0xFD; fhf.m_fieldLength = 4; setHeaderIntValue(fhf, m_romChecksumType); writeFieldIncludingDetails(fs, fhf); //fs.Position = writePos; fhf.m_fieldID = (byte)0xFE; fhf.m_fieldLength = 4; setHeaderIntValue(fhf, m_fwLength); writeFieldIncludingDetails(fs, fhf); //fs.Position = writePos; fhf.m_fieldID = (byte)0xFA; fhf.m_fieldLength = (byte)5; setHeaderDateValue(fhf, m_LastModifiedBy); writeFieldIncludingDetails(fs, fhf); //fs.Position = writePos; fhf.m_fieldID = (byte)0x92; fhf.m_fieldLength = (byte)m_immobilizerID.Length; setHeaderString(fhf, m_immobilizerID); writeFieldIncludingDetails(fs, fhf); //fs.Position = writePos; fhf.m_fieldID = (byte)0x93; fhf.m_fieldLength = (byte)m_ecuhardwarenr.Length; setHeaderString(fhf, m_ecuhardwarenr); writeFieldIncludingDetails(fs, fhf); //fs.Position = writePos; fhf.m_fieldID = (byte)0xF8; fhf.m_fieldLength = 2; setHeaderSmallIntValue(fhf, m_valueF8); writeFieldIncludingDetails(fs, fhf); //fs.Position = writePos; fhf.m_fieldID = (byte)0xF7; fhf.m_fieldLength = 2; setHeaderSmallIntValue(fhf, m_valueF7); writeFieldIncludingDetails(fs, fhf); //fs.Position = writePos; fhf.m_fieldID = (byte)0xF6; fhf.m_fieldLength = 2; setHeaderSmallIntValue(fhf, m_valueF6); writeFieldIncludingDetails(fs, fhf); //fs.Position = writePos; fhf.m_fieldID = (byte)0xF5; fhf.m_fieldLength = 2; setHeaderSmallIntValue(fhf, m_valueF5); writeFieldIncludingDetails(fs, fhf); //fs.Position = writePos; fhf.m_fieldID = (byte)0x90; fhf.m_fieldLength = (byte)m_chassisID.Length; setHeaderString(fhf, m_chassisID); writeFieldIncludingDetails(fs, fhf); //fs.Position = writePos; fhf.m_fieldID = (byte)0x99; fhf.m_fieldLength = (byte)m_testserialnr.Length; setHeaderString(fhf, m_testserialnr); writeFieldIncludingDetails(fs, fhf); //fs.Position = writePos; fhf.m_fieldID = (byte)0x98; fhf.m_fieldLength = (byte)m_enginetype.Length; setHeaderString(fhf, m_enginetype); writeFieldIncludingDetails(fs, fhf); //fs.Position = writePos; fhf.m_fieldID = (byte)0xF9; fhf.m_fieldLength = 1; fhf.m_data = new byte[1]; fhf.m_data.SetValue(m_RomChecksumError, 0); writeFieldIncludingDetails(fs, fhf); //fs.Position = writePos; fs.Close(); logger.Debug("New header created"); }
private void CreateNewFooter(string a_filename, bool create9B, bool create9C, bool createF2) { if (!File.Exists(a_filename)) return; FileStream fs = new FileStream(a_filename, FileMode.Open, FileAccess.ReadWrite); fs.Seek(0, SeekOrigin.End); long writePos; fileLength = fs.Position; writePos = fs.Position; FileHeaderField fhf = new FileHeaderField(); fhf.m_fieldID = (byte)0x91; fhf.m_fieldLength = (byte)m_vehicleidnr.Length; setHeaderString(fhf, m_vehicleidnr); writeFieldIncludingDetails(fs, fhf); // fs.Position = writePos; fhf.m_fieldID = (byte)0x94; fhf.m_fieldLength = (byte)m_partNumber.Length; setHeaderString(fhf, m_partNumber); writeFieldIncludingDetails(fs, fhf); //fs.Position = writePos; fhf.m_fieldID = (byte)0x95; fhf.m_fieldLength = (byte)m_softwareVersion.Length; setHeaderString(fhf, m_softwareVersion); writeFieldIncludingDetails(fs, fhf); //fs.Position = writePos; fhf.m_fieldID = (byte)0x97; fhf.m_fieldLength = (byte)m_carDescription.Length; setHeaderString(fhf, m_carDescription); writeFieldIncludingDetails(fs, fhf); //fs.Position = writePos; fhf.m_fieldID = (byte)0x9A; fhf.m_fieldLength = (byte)m_datemodified.Length; setHeaderString(fhf, m_datemodified); writeFieldIncludingDetails(fs, fhf); //fs.Position = writePos; if (create9C) { fhf.m_fieldID = (byte)0x9C; fhf.m_fieldLength = 4; setHeaderIntValue(fhf, m_9cvalue); writeFieldIncludingDetails(fs, fhf); } //fs.Position = writePos; if (create9B) { fhf.m_fieldID = (byte)0x9B; fhf.m_fieldLength = 4; setHeaderIntValue(fhf, m_symboltableaddress); writeFieldIncludingDetails(fs, fhf); } //fs.Position = writePos; if (createF2) { fhf.m_fieldID = (byte)0xF2; fhf.m_fieldLength = 4; setHeaderIntValue(fhf, m_checksumF2); writeFieldIncludingDetails(fs, fhf); } //fs.Position = writePos; fhf.m_fieldID = (byte)0xFB; fhf.m_fieldLength = 4; setHeaderIntValue(fhf, m_checksumFB); writeFieldIncludingDetails(fs, fhf); //fs.Position = writePos; fhf.m_fieldID = (byte)0xFC; fhf.m_fieldLength = 4; setHeaderIntValue(fhf, m_bottomOfFlash); writeFieldIncludingDetails(fs, fhf); //fs.Position = writePos; fhf.m_fieldID = (byte)0xFD; fhf.m_fieldLength = 4; setHeaderIntValue(fhf, m_romChecksumType); writeFieldIncludingDetails(fs, fhf); //fs.Position = writePos; fhf.m_fieldID = (byte)0xFE; fhf.m_fieldLength = 4; setHeaderIntValue(fhf, m_fwLength); writeFieldIncludingDetails(fs, fhf); //fs.Position = writePos; fhf.m_fieldID = (byte)0xFA; fhf.m_fieldLength = (byte)5; setHeaderDateValue(fhf, m_LastModifiedBy); writeFieldIncludingDetails(fs, fhf); //fs.Position = writePos; fhf.m_fieldID = (byte)0x92; fhf.m_fieldLength = (byte)m_immobilizerID.Length; setHeaderString(fhf, m_immobilizerID); writeFieldIncludingDetails(fs, fhf); //fs.Position = writePos; fhf.m_fieldID = (byte)0x93; fhf.m_fieldLength = (byte)m_ecuhardwarenr.Length; setHeaderString(fhf, m_ecuhardwarenr); writeFieldIncludingDetails(fs, fhf); //fs.Position = writePos; fhf.m_fieldID = (byte)0xF8; fhf.m_fieldLength = 2; setHeaderSmallIntValue(fhf, m_valueF8); writeFieldIncludingDetails(fs, fhf); //fs.Position = writePos; fhf.m_fieldID = (byte)0xF7; fhf.m_fieldLength = 2; setHeaderSmallIntValue(fhf, m_valueF7); writeFieldIncludingDetails(fs, fhf); //fs.Position = writePos; fhf.m_fieldID = (byte)0xF6; fhf.m_fieldLength = 2; setHeaderSmallIntValue(fhf, m_valueF6); writeFieldIncludingDetails(fs, fhf); //fs.Position = writePos; fhf.m_fieldID = (byte)0xF5; fhf.m_fieldLength = 2; setHeaderSmallIntValue(fhf, m_valueF5); writeFieldIncludingDetails(fs, fhf); //fs.Position = writePos; fhf.m_fieldID = (byte)0x90; fhf.m_fieldLength = (byte)m_chassisID.Length; setHeaderString(fhf, m_chassisID); writeFieldIncludingDetails(fs, fhf); //fs.Position = writePos; fhf.m_fieldID = (byte)0x99; fhf.m_fieldLength = (byte)m_testserialnr.Length; setHeaderString(fhf, m_testserialnr); writeFieldIncludingDetails(fs, fhf); //fs.Position = writePos; fhf.m_fieldID = (byte)0x98; fhf.m_fieldLength = (byte)m_enginetype.Length; setHeaderString(fhf, m_enginetype); writeFieldIncludingDetails(fs, fhf); //fs.Position = writePos; fhf.m_fieldID = (byte)0xF9; fhf.m_fieldLength = 1; fhf.m_data = new byte[1]; fhf.m_data.SetValue(m_RomChecksumError, 0); writeFieldIncludingDetails(fs, fhf); //fs.Position = writePos; fs.Close(); Console.WriteLine("New header created"); }
/// <summary> /// This method writes a FileHeaderField to the file header. /// </summary> /// <param name="a_fileStream">The FileStream to write to.</param> /// <param name="a_fhf">The FileHeaderField.</param> private void writeField(FileStream a_fileStream, FileHeaderField a_fhf) { a_fileStream.Position -= 3; // Skip ID and length for (int i = 0; i < a_fhf.m_fieldLength; i++) { a_fileStream.WriteByte(a_fhf.m_data[i]); a_fileStream.Position -= 2; } a_fileStream.Position += 1; }
/// <summary> /// This method sets the data in a FileHeaderField to the values given by a string. /// </summary> /// <param name="a_fileHeaderField">The FileHeaderField.</param> /// <param name="a_string">The string to set.</param> private void setHeaderString(FileHeaderField a_fileHeaderField, string a_string) { System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding(); byte[] bytes = encoding.GetBytes(a_string); a_fileHeaderField.m_data = bytes; }
/// <summary> /// This method sets the information in a four byte field to represent a integer value. /// </summary> /// <param name="a_fileHeaderField">The FileHeaderField.</param> /// <param name="a_value">The value that the field should contain.</param> private void setHeaderSmallIntValue(FileHeaderField a_fileHeaderField, int a_value) { a_fileHeaderField.m_data[1] = (byte)a_value; a_value >>= 8; a_fileHeaderField.m_data[0] = (byte)a_value; }