private bool readFile() { if (File.Exists(this.dfp_txtDFPPath.Text)) { fs = this.openFileDialog1.OpenFile(); byte[] headerSection = new byte[1024 * 4]; int readLen = fs.Read(headerSection, 0, headerSection.Length); if (readLen != headerSection.Length) { MessageBox.Show("文件头长度错误."); return(false); } Encrypt AESDecrypt = new Encrypt(); byte[] decryptHeaderBuff = AESDecrypt.decrypt(headerSection); dfpHeader = new DFPHeader(decryptHeaderBuff); writeLog(dfpHeader); writeLog(" 正在解析配置文件...\r\n"); fs.Seek(0, SeekOrigin.Begin); int length = (int)dfpHeader.ConfigurationOffset + (int)dfpHeader.ConfigurationLength; length = length - length % 256 + length + 256; byte[] cfgbuff = new byte[length]; fs.Read(cfgbuff, 0, length); byte[] decryptCfgBuff = AESDecrypt.decrypt(cfgbuff); dfpHeader.ReadConfigurations(decryptCfgBuff); writeLog(" 解析配置文件完毕!\r\n"); return(true); } return(false); }
private void writeLog(DFPHeader dfp) { DateTime stamp = DateTime.Parse(dfp.Timestamp); this.richTextBox1.AppendText(string.Format(" 文件头Checksum: \t0x{0:X8}\r\n", dfp.HeaderCheckSum)); this.richTextBox1.AppendText(string.Format(" 文件Checksum: \t\t0x{0:X8}\r\n", dfp.FileCheckSum)); this.richTextBox1.AppendText(string.Format(" 发布名称: \t\t{0}\r\n", dfp.DFPReleaseName)); this.richTextBox1.AppendText(string.Format(" 发布版本: \t\t{0:D}\r\n", dfp.DFPReleaseID)); this.richTextBox1.AppendText(string.Format(" 发布时间: \t\t{0}\r\n", stamp.ToString("yyyy/MM/dd HH:mm:ss"))); this.richTextBox1.AppendText(string.Format(" Manifest起始位置: \t{0:D}(0x{0:X8})\r\n", dfp.ManifestOffset)); this.richTextBox1.AppendText(string.Format(" Manifest文件长度: \t{0:D}(0x{0:X8})字节\r\n", dfp.ManifestLength)); this.richTextBox1.AppendText(string.Format(" Manifest文件数: \t{0:D}(0x{0:X8})个\r\n", dfp.ManifestCount)); this.richTextBox1.AppendText(string.Format(" 配置文件起始位置: \t{0:D}(0x{0:X8})\r\n", dfp.ConfigurationOffset)); this.richTextBox1.AppendText(string.Format(" 配置文件长度: \t\t{0:D}(0x{0:X8})字节\r\n", dfp.ConfigurationLength)); this.richTextBox1.AppendText(string.Format(" 配置文件数: \t\t{0:D}(0x{0:X8})个\r\n", dfp.ConfigurationCount)); this.richTextBox1.AppendText(string.Format(" 版本号: \t\t{0}\r\n", dfp.DFPVersion)); }