private void mInsertOnClick(object sender, EventArgs ea) { //insert file OpenFileDialog ofd = new OpenFileDialog(); ofd.Title = "Select file"; ofd.Filter = "All Files (*.*)|*.*|Dll Files (*.dll)|*.dll"; if (ofd.ShowDialog() == DialogResult.OK) { Cursor.Current = Cursors.WaitCursor; FileInfo fi = new FileInfo(ofd.FileName); ListViewFileItem lvi = new ListViewFileItem(); lvi.Text = Path.GetFileName(ofd.FileName); lvi.SubItems.Add("Yes"); lvi.SubItems.Add("No"); lvi.SubItems.Add("No"); lvi.SubItems.Add(fi.Length.ToString("n0")); lvi.Offset = 0; lvi.Size = (int)fi.Length; lvi.SubItems.Add(Path.GetFullPath(ofd.FileName)); if (contents.SelectedItems.Count == 0) { //no items selected so add at bottom contents.Items.Add(lvi); } else { //insert before first selected item contents.Items.Insert(contents.SelectedItems[0].Index, lvi); } //check for _virtual.dat if (lvi.Text == "_virtual.dat") { //get display settings from _virtual.dat FileStream fsIn = null; BinaryReader brIn = null; try { fsIn = new FileStream(ofd.FileName, FileMode.Open); brIn = new BinaryReader(fsIn); displayMode = brIn.ReadInt32(); displayWidth = brIn.ReadInt32(); displayHeight = brIn.ReadInt32(); displayDepth = brIn.ReadInt32(); contents.ContextMenu.MenuItems[0].Text = proExe.getDisplayString(displayWidth, displayHeight, displayDepth, displayMode); contents.ContextMenu.MenuItems[0].Enabled = true; } catch (Exception ex) { MessageBox.Show(ex.ToString(), "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error); } finally { brIn.Close(); fsIn.Close(); } } Cursor.Current = Cursors.Default; } ofd.Dispose(); //enable menu items if (contents.Items.Count > 0) { contents.ContextMenu.MenuItems[2].Enabled = true; //save contents.ContextMenu.MenuItems[11].MenuItems[0].Enabled = true; //decompress } }
public static void ExtractFile(ListViewFileItem lvi, string exeName, string outName) { //extract file in ListViewFileItem FileStream fsIn = null; BinaryReader brIn = null; FileStream fsOut = null; BinaryWriter bwOut = null; try { fsIn = new FileStream(exeName, FileMode.Open); brIn = new BinaryReader(fsIn); fsOut = new FileStream(outName, FileMode.Create); bwOut = new BinaryWriter(fsOut); fsIn.Seek(lvi.Offset, SeekOrigin.Begin); bwOut.Write(brIn.ReadBytes(lvi.Size)); } catch (Exception ex) { MessageBox.Show(ex.ToString(), "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error); } finally { if (brIn != null) brIn.Close(); if (fsIn != null) fsIn.Close(); if (bwOut != null) bwOut.Close(); if (fsOut != null) fsOut.Close(); } }
private void InsertFile(string fileName, string name, bool upx, bool nullString) { //insert file FileInfo fi = new FileInfo(fileName); ListViewFileItem lvi = new ListViewFileItem(); lvi.SubItems[(int)ListViewOrder.Name].Text = name; lvi.SubItems[(int)ListViewOrder.FileType].Text = ListViewStrings.Yes; lvi.SubItems[(int)ListViewOrder.Upx].Text = ListViewStrings.No; lvi.SubItems[(int)ListViewOrder.NullString].Text = ListViewStrings.No; lvi.SubItems[(int)ListViewOrder.FileSize].Text = fi.Length.ToString("n0"); lvi.SubItems[(int)ListViewOrder.Location].Text = fileName; lvi.Offset = 0; lvi.Size = (int)fi.Length; lvi.SubItems.Add(Path.GetFullPath(fileName)); if (contents.SelectedItems.Count == 0) { //no items selected so add at bottom contents.Items.Add(lvi); } else { //insert before first selected item contents.Items.Insert(contents.SelectedItems[0].Index, lvi); } updateAlternatingColours(); //check for _virtual.dat if (lvi.Text == ListViewStrings.VirtualDat) { //get display settings from _virtual.dat FileStream fsIn = null; BinaryReader brIn = null; try { fsIn = new FileStream(fileName, FileMode.Open); brIn = new BinaryReader(fsIn); displaySettings.Mode = (DisplayMode) brIn.ReadInt32(); displaySettings.Width = brIn.ReadInt32(); displaySettings.Height = brIn.ReadInt32(); displaySettings.Depth = brIn.ReadInt32(); contents.ContextMenu.MenuItems[MENU_DISPLAY].Text = proExe.getDisplayString(displaySettings); contents.ContextMenu.MenuItems[MENU_DISPLAY].Enabled = true; } catch (Exception ex) { MessageBox.Show(ex.ToString(), "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error); } finally { brIn.Close(); fsIn.Close(); } } }
private void auto_Click(object sender, EventArgs e) { //auto build patch analyseDialog ad = new analyseDialog(); if (ad.ShowDialog() == DialogResult.OK) { foreach (ListViewFileItem lvi in ad.newExe.Items) { if (lvi.SubItems[1].Text == "Yes") { //changed item so add to files ListViewFileItem item = new ListViewFileItem(); item.Text = lvi.Text; item.SubItems.Add("Add/Replace"); item.SubItems.Add(ad.newExeName); item.Size = lvi.Size; item.Offset = lvi.Offset; files.Items.Add(item); } } } }
private void load_Click(object sender, EventArgs e) { //load OpenFileDialog dlg = new OpenFileDialog(); dlg.Title = "Load"; dlg.Filter = "Builder settings files (*.bsf)|*.bsf|All Files (*.*)|*.*"; if (dlg.ShowDialog() == DialogResult.OK) { FileStream fs = null; BinaryReader br = null; //clear items name.Text = ""; filename.Text = ""; checksum.Text = ""; info.Text = ""; files.Items.Clear(); try { fs = new FileStream(dlg.FileName,FileMode.Open); br = new BinaryReader(fs); name.Text = br.ReadString(); filename.Text = br.ReadString(); checksum.Text = br.ReadString(); info.Text = br.ReadString(); //files ListViewFileItem itm; while (fs.Position != fs.Length) { itm = new ListViewFileItem(); itm.Text = br.ReadString(); itm.SubItems.Add(br.ReadString()); itm.SubItems.Add(br.ReadString()); itm.Offset = br.ReadInt32(); itm.Size = br.ReadInt32(); files.Items.Add(itm); } } catch (Exception ex) { MessageBox.Show(ex.ToString(),"Error",MessageBoxButtons.OK,MessageBoxIcon.Error); } finally { br.Close(); fs.Close(); } //enable build and save buttons build.Enabled = true; save.Enabled = true; } dlg.Dispose(); }
private static void WriteData(FileStream fsIn, BinaryReader brIn, ListViewFileItem lvi, BinaryWriter bwOut) { //writes filedata to file after modifing it if required (upx, string table null, etc) if (lvi.SubItems[2].Text == "Yes") { //upx MessageBox.Show("Sorry Upx support is not done yet"); } else if (lvi.SubItems[3].Text == "Yes") { //str table null MessageBox.Show("Sorry null string tables not done yet."); } else { if (lvi.SubItems[1].Text == "Yes") { //data size bwOut.Write(lvi.Size); } //data fsIn.Seek(lvi.Offset, SeekOrigin.Begin); bwOut.Write(brIn.ReadBytes(lvi.Size)); } }
public static void LoadExe(ListView contents, string fileName, window win) { FileStream fs = null; BinaryReader br = null; try { fs = new FileStream(fileName, FileMode.Open); br = new BinaryReader(fs); ListViewFileItem lvi; //check exe signiture if (Encoding.ASCII.GetString(br.ReadBytes(2)) == "MZ") { SkipExeSection(fs, br); //add exe to listview lvi = new ListViewFileItem(); lvi.Text = "Exe section"; lvi.Offset = 0; lvi.Size = (int)fs.Position; lvi.SubItems.Add("No"); lvi.SubItems.Add("No"); lvi.SubItems.Add("No"); lvi.SubItems.Add(lvi.Size.ToString("n0")); lvi.SubItems.Add("<exe>"); contents.Items.Add(lvi); //Check for exe with no attached data if (lvi.Size == (int)fs.Length) return; } else { //it's a pck file so files start at begining of file fs.Seek(0, SeekOrigin.Begin); } //add attached files int nameLength = 1; while (nameLength > 0 && nameLength < 50 && fs.Position < fs.Length) { lvi = new ListViewFileItem(); nameLength = br.ReadInt32(); //MessageBox.Show(nameLength.ToString()); if (nameLength > 0 && nameLength < 50) { //file lvi.Text = Encoding.ASCII.GetString(br.ReadBytes(nameLength)); lvi.Size = br.ReadInt32(); lvi.Offset = (int)fs.Position; //check for _virtual.dat if (lvi.Text == "_virtual.dat") { //get display settings win.displayMode = br.ReadInt32(); int Width = br.ReadInt32(); int Height = br.ReadInt32(); int Depth = br.ReadInt32(); win.displayWidth = Width; win.displayHeight = Height; win.displayDepth = Depth; contents.ContextMenu.MenuItems[0].Text = proExe.getDisplayString(Width, Height, Depth, win.displayMode); contents.ContextMenu.MenuItems[0].Enabled = true; fs.Seek(-16, SeekOrigin.Current); } fs.Seek(lvi.Size, SeekOrigin.Current); lvi.SubItems.Add("Yes"); lvi.SubItems.Add("No"); lvi.SubItems.Add("No"); lvi.SubItems.Add(lvi.Size.ToString("n0")); lvi.SubItems.Add("<exe>"); } else { //compressed or extra data lvi.Text = "Compressed or extra data"; lvi.Offset = (int)fs.Position - 4; lvi.Size = (int)(fs.Length - (fs.Position - 4)); lvi.SubItems.Add("No"); lvi.SubItems.Add("No"); lvi.SubItems.Add("No"); lvi.SubItems.Add(lvi.Size.ToString("n0")); lvi.SubItems.Add("<exe>"); } contents.Items.Add(lvi); } } catch (Exception ex) { MessageBox.Show(ex.ToString(), "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error); } finally { if (br != null) br.Close(); if (fs != null) fs.Close(); } }
private static int WriteData(FileStream fsIn, BinaryReader brIn, ListViewFileItem lvi, BinaryWriter bwOut) { //writes filedata to file after modifing it if required (upx, string table null, etc) string tempFile; FileStream fsTemp = null; BinaryWriter bwTemp = null; BinaryReader brTemp = null; if (lvi.SubItems[(int)ListViewOrder.Upx].Text != ListViewStrings.No || lvi.SubItems[(int)ListViewOrder.NullString].Text == ListViewStrings.Yes) { //upx or null string table if (lvi.SubItems[(int)ListViewOrder.Upx].Text == ListViewStrings.Yes) { //check for upx.exe if (File.Exists(Application.StartupPath + Path.DirectorySeparatorChar + "upx.exe") == false) { MessageBox.Show("upx.exe not found in program directory.", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error); return 0; } } tempFile = Path.GetTempFileName(); try { //write temp file fsTemp = new FileStream(tempFile, FileMode.Create); bwTemp = new BinaryWriter(fsTemp); bwTemp.Write(brIn.ReadBytes(lvi.Size)); bwTemp.Close(); bwTemp = null; fsTemp.Close(); fsTemp = null; if (lvi.SubItems[(int)ListViewOrder.Upx].Text != ListViewStrings.No) { //compress with upx Process upx = new Process(); upx.StartInfo.CreateNoWindow = true; upx.StartInfo.UseShellExecute = false; upx.StartInfo.RedirectStandardOutput = true; upx.StartInfo.RedirectStandardError = true; upx.StartInfo.FileName = Application.StartupPath + Path.DirectorySeparatorChar + "upx.exe"; //use lzma compression? if (lvi.SubItems[(int)ListViewOrder.Upx].Text == ListViewStrings.UpxLzma) upx.StartInfo.Arguments += "--lzma " + tempFile; else upx.StartInfo.Arguments = tempFile; upx.Start(); upx.WaitForExit(); if (upx.StandardOutput.ReadToEnd().IndexOf("Packed 1 file.") == -1) { //upx failed if (MessageBox.Show("Upx failed to compress " + lvi.SubItems[(int)ListViewOrder.Name].Text + "\n See upx error?", "Error!", MessageBoxButtons.YesNo, MessageBoxIcon.Error) == DialogResult.Yes) { //show upx output MessageBox.Show(upx.StandardError.ReadToEnd()); } } } else if(lvi.SubItems[(int)ListViewOrder.NullString].Text == ListViewStrings.Yes) { //null string table } //write modified file fsTemp = new FileStream(tempFile, FileMode.Open); brTemp = new BinaryReader(fsTemp); if (lvi.SubItems[(int)ListViewOrder.FileType].Text == ListViewStrings.Yes) { //attached file so writedata size bwOut.Write((int)fsTemp.Length); } bwOut.Write(brTemp.ReadBytes((int)fsTemp.Length)); return (int)fsTemp.Length; } catch (Exception ex) { MessageBox.Show(ex.ToString(), "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error); } finally { if (bwTemp != null) bwTemp.Close(); if (brTemp != null) brTemp.Close(); if (fsTemp != null) fsTemp.Close(); if (File.Exists(tempFile)) File.Delete(tempFile); } } //unmodified file data if (lvi.SubItems[(int)ListViewOrder.FileType].Text == ListViewStrings.Yes) { //attached file so writedata size bwOut.Write(lvi.Size); } //write data fsIn.Seek(lvi.Offset, SeekOrigin.Begin); bwOut.Write(brIn.ReadBytes(lvi.Size)); //return ammount of data written return lvi.Size; }
public static void LoadExe(ListView contents, string fileName, window win) { //debugLog.StartSection("LoadExe"); int exeSectionSize = 0, extraDataSize = 0; FileStream fs = null; BinaryReader br = null; try { fs = new FileStream(fileName, FileMode.Open); br = new BinaryReader(fs); ListViewFileItem lvi; //debugLog.Log("Loading " + Path.GetFileName(fileName)); //check exe signiture if (Encoding.ASCII.GetString(br.ReadBytes(2)) == "MZ") { //debugLog.Log("Found exe signiture"); SkipExeSection(fs, br); //add exe to listview lvi = new ListViewFileItem(); lvi.SubItems[(int)ListViewOrder.Name].Text = ListViewStrings.ExeSection; lvi.Offset = 0; lvi.Size = (int)fs.Position; exeSectionSize = lvi.Size; lvi.SubItems[(int)ListViewOrder.FileType].Text = ListViewStrings.No; lvi.SubItems[(int)ListViewOrder.Upx].Text = ListViewStrings.No; lvi.SubItems[(int)ListViewOrder.NullString].Text = ListViewStrings.No; lvi.SubItems[(int)ListViewOrder.FileSize].Text = lvi.Size.ToString("n0"); lvi.SubItems[(int)ListViewOrder.Location].Text = ListViewStrings.LocationExe; contents.Items.Add(lvi); //debugLog.Log("Exe section size = " + lvi.Size.ToString("n0")); //Check for exe with no attached data if (lvi.Size == (int)fs.Length) { //debugLog.Log("Exe has no appended data"); return; } } else { //it's a pck file so files start at begining of file //debugLog.Log("Exe signiture not found, assuming .pck"); fs.Seek(0, SeekOrigin.Begin); } //add attached files int nameLength = 1; while (nameLength > 0 && nameLength < 500 && fs.Position < fs.Length) { lvi = new ListViewFileItem(); nameLength = br.ReadInt32(); //MessageBox.Show(nameLength.ToString()); if (nameLength > 0 && nameLength < 500) { //file lvi.SubItems[(int)ListViewOrder.Name].Text = Encoding.ASCII.GetString(br.ReadBytes(nameLength)); lvi.Size = br.ReadInt32(); lvi.Offset = (int)fs.Position; //debugLog.Log(DbcRemoveNull(lvi.Text).PadRight(26, ' ') + " Size :" + lvi.Size.ToString("n0").PadRight(10, ' ') + // " Offset :" + lvi.Offset.ToString("n0")); //check for _virtual.dat if (lvi.SubItems[(int)ListViewOrder.Name].Text == ListViewStrings.VirtualDat) { //get display settings win.displayMode = br.ReadInt32(); int Width = br.ReadInt32(); int Height = br.ReadInt32(); int Depth = br.ReadInt32(); win.displayWidth = Width; win.displayHeight = Height; win.displayDepth = Depth; contents.ContextMenu.MenuItems[window.MENU_DISPLAY].Text = proExe.getDisplayString(Width, Height, Depth, win.displayMode); contents.ContextMenu.MenuItems[window.MENU_DISPLAY].Enabled = true; fs.Seek(-16, SeekOrigin.Current); } fs.Seek(lvi.Size, SeekOrigin.Current); lvi.SubItems[(int)ListViewOrder.FileType].Text = ListViewStrings.Yes; lvi.SubItems[(int)ListViewOrder.Upx].Text = ListViewStrings.No; lvi.SubItems[(int)ListViewOrder.NullString].Text = ListViewStrings.No; lvi.SubItems[(int)ListViewOrder.FileSize].Text = lvi.Size.ToString("n0"); lvi.SubItems[(int)ListViewOrder.Location].Text = ListViewStrings.LocationExe; } else { //compressed or extra data lvi.SubItems[(int)ListViewOrder.Name].Text = ListViewStrings.ExtraData; lvi.Offset = (int)fs.Position - 4; lvi.Size = (int)(fs.Length - (fs.Position - 4)); lvi.SubItems[(int)ListViewOrder.FileType].Text = ListViewStrings.No; lvi.SubItems[(int)ListViewOrder.Upx].Text = ListViewStrings.No; lvi.SubItems[(int)ListViewOrder.NullString].Text = ListViewStrings.No; lvi.SubItems[(int)ListViewOrder.FileSize].Text = lvi.Size.ToString("n0"); lvi.SubItems[(int)ListViewOrder.Location].Text = ListViewStrings.LocationExe; fs.Seek(-4, SeekOrigin.End); extraDataSize = br.ReadInt32(); //debugLog.Log("Extra data size :" + lvi.Size.ToString("n0") + " reported exe section size :" + // extraDataSize.ToString("n0")); //if (extraDataSize != exeSectionSize) // debugLog.Log("Warning exe section size reported in extra data does not match actual exe section size"); } contents.Items.Add(lvi); } } catch (Exception ex) { MessageBox.Show(ex.ToString(), "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error); } finally { if (br != null) br.Close(); if (fs != null) fs.Close(); } //debugLog.StopSection(); }
public static void LoadExe(ListView contents, string fileName) { FileStream fs = null; BinaryReader br = null; try { fs = new FileStream(fileName, FileMode.Open); br = new BinaryReader(fs); //skip exe section SkipExeSection(fs, br); //add exe to listview ListViewFileItem lvi = new ListViewFileItem(); lvi.Text = "<Standard Head>"; lvi.Offset = 0; lvi.Size = (int) fs.Position; //lvi.SubItems.Add("No"); //lvi.SubItems.Add(lvi.Size.ToString()); lvi.SubItems.Add("<exe>"); contents.Items.Add(lvi); //Check for exe with no attached data if (lvi.Size == (int)fs.Length) return; //add attached files int nameLength = 1; while (nameLength > 0 && nameLength < 50) { lvi = new ListViewFileItem(); nameLength = br.ReadInt32(); //MessageBox.Show(nameLength.ToString()); if (nameLength > 0 && nameLength < 50) { //file lvi.Text = Encoding.ASCII.GetString(br.ReadBytes(nameLength)); lvi.Size = br.ReadInt32(); lvi.Offset = (int)fs.Position; fs.Seek(lvi.Size, SeekOrigin.Current); //lvi.SubItems.Add("Yes"); //lvi.SubItems.Add(lvi.Size.ToString()); lvi.SubItems.Add("<exe>"); } else { //compressed or extra data lvi.Text = "<Extra Data>"; lvi.Offset = (int)fs.Position - 4; lvi.Size = (int)(fs.Length - (fs.Position - 4)); //lvi.SubItems.Add("No"); //lvi.SubItems.Add(lvi.Size.ToString()); lvi.SubItems.Add("<exe>"); } contents.Items.Add(lvi); } } catch (Exception ex) { MessageBox.Show(ex.ToString(), "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error); } finally { if (br != null) br.Close(); if (fs != null) fs.Close(); } }
private void setCheckBoxValue(ListViewFileItem lvi, int subItem, CheckState state) { //set the text for a subitem determined by a checkbox if (state != CheckState.Indeterminate) { if (state == CheckState.Checked) { lvi.SubItems[subItem].Text = ListViewStrings.Yes; } else { lvi.SubItems[subItem].Text = ListViewStrings.No; } } }
//Extern menu stuff private void mExternAddOnClick(object obj, EventArgs ea) { //add item addFilesDialog dlg = new addFilesDialog("",""); if (dlg.ShowDialog() == DialogResult.OK) { if (dlg.name != "") { ListViewFileItem itm = new ListViewFileItem(); itm.Text = dlg.name; itm.SubItems.Add(dlg.location); Extern.Items.Add(itm); } } }
private void mAddOnClick(object obj, EventArgs ea) { //add item addFilesDialog dlg = new addFilesDialog("","",0); if (dlg.ShowDialog() == DialogResult.OK) { if (dlg.name != "") { ListViewFileItem itm = new ListViewFileItem(); itm.Text = dlg.name; itm.SubItems.Add(dlg.action); itm.SubItems.Add(dlg.location); //set offset and size to -1 so whole file added to patch itm.Offset = -1; itm.Size = -1; files.Items.Add(itm); } } }
private static int WriteData(FileStream fsIn, BinaryReader brIn, ListViewFileItem lvi, BinaryWriter bwOut) { //writes filedata to file after modifing it if required (upx, string table null, etc) if (lvi.SubItems[(int)ListViewOrder.Upx].Text == ListViewStrings.Yes) { //upx MessageBox.Show("Sorry Upx support is not done yet"); return 0; } else if (lvi.SubItems[(int)ListViewOrder.NullString].Text == ListViewStrings.Yes) { //str table null MessageBox.Show("Sorry null string tables not done yet."); return 0; } if (lvi.SubItems[(int)ListViewOrder.FileType].Text == ListViewStrings.Yes) { //attached file so writedata size bwOut.Write(lvi.Size); } //data fsIn.Seek(lvi.Offset, SeekOrigin.Begin); bwOut.Write(brIn.ReadBytes(lvi.Size)); //return ammount of data written return lvi.Size; }
private void InsertFile(string fileName, string name, bool upx, bool nullString) { //insert file FileInfo fi = new FileInfo(fileName); ListViewFileItem lvi = new ListViewFileItem(); lvi.Text = name; lvi.SubItems.Add("Yes"); lvi.SubItems.Add("No"); lvi.SubItems.Add("No"); lvi.SubItems.Add(fi.Length.ToString("n0")); lvi.Offset = 0; lvi.Size = (int)fi.Length; lvi.SubItems.Add(Path.GetFullPath(fileName)); if (contents.SelectedItems.Count == 0) { //no items selected so add at bottom contents.Items.Add(lvi); } else { //insert before first selected item contents.Items.Insert(contents.SelectedItems[0].Index, lvi); } //check for _virtual.dat if (lvi.Text == "_virtual.dat") { //get display settings from _virtual.dat FileStream fsIn = null; BinaryReader brIn = null; try { fsIn = new FileStream(fileName, FileMode.Open); brIn = new BinaryReader(fsIn); displayMode = brIn.ReadInt32(); displayWidth = brIn.ReadInt32(); displayHeight = brIn.ReadInt32(); displayDepth = brIn.ReadInt32(); contents.ContextMenu.MenuItems[0].Text = proExe.getDisplayString(displayWidth, displayHeight, displayDepth, displayMode); contents.ContextMenu.MenuItems[0].Enabled = true; } catch (Exception ex) { MessageBox.Show(ex.ToString(), "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error); } finally { brIn.Close(); fsIn.Close(); } } }
public static void LoadExe(ListView contents, bool hasChangedColumn, string fileName) { FileStream fs = null; BinaryReader br = null; try { fs = new FileStream(fileName, FileMode.Open); br = new BinaryReader(fs); //find size of exe header //skip dos stub fs.Seek(60, SeekOrigin.Current); int e_lfanew = br.ReadInt32(); //MessageBox.Show(e_lfanew.ToString()); fs.Seek(e_lfanew + 4, SeekOrigin.Begin); //IMAGE_FILE_HEADER fs.Seek(2, SeekOrigin.Current); int NumberOfSections = br.ReadInt16(); fs.Seek(16, SeekOrigin.Current); //end of IMAGE_FILE_HEADER //IMAGE_OPTIONAL_HEADER fs.Seek(224, SeekOrigin.Current); //end of IMAGE_OPTIONAL_HEADER //section directories int Size = 0; // size of section int Pos = 0; // position of section for (int i=0; i<NumberOfSections; i++) { fs.Seek(16, SeekOrigin.Current); Size = br.ReadInt32(); Pos = br.ReadInt32(); fs.Seek(16, SeekOrigin.Current); } //end of section directories fs.Seek(Pos+Size, SeekOrigin.Begin); //add exe to listview ListViewFileItem lvi = new ListViewFileItem(); lvi.Text = "Exe section"; lvi.Offset = 0; lvi.Size = Pos + Size; if (hasChangedColumn == true) lvi.SubItems.Add(""); //get hash lvi.SubItems.Add(getHash(fs, br, lvi.Offset, lvi.Size)); lvi.SubItems.Add("No"); contents.Items.Add(lvi); //Check for exe with no attached data if (lvi.Size == (int)fs.Length) return; //add attached files int nameLength = 1; while (nameLength > 0 && nameLength < 50) { lvi = new ListViewFileItem(); nameLength = br.ReadInt32(); //MessageBox.Show(nameLength.ToString()); if (nameLength > 0 && nameLength < 50) { //file lvi.Text = Encoding.ASCII.GetString(br.ReadBytes(nameLength)); lvi.Size = br.ReadInt32(); lvi.Offset = (int)fs.Position; fs.Seek(lvi.Size, SeekOrigin.Current); if (hasChangedColumn == true) lvi.SubItems.Add(""); //get hash lvi.SubItems.Add(getHash(fs, br, lvi.Offset, lvi.Size)); lvi.SubItems.Add("Yes"); } else { //compressed or extra data lvi.Text = "Compressed or extra data"; lvi.Offset = (int)fs.Position - 4; lvi.Size = (int)(fs.Length - (fs.Position - 4)); if (hasChangedColumn == true) lvi.SubItems.Add(""); //get hash lvi.SubItems.Add(getHash(fs, br, lvi.Offset, lvi.Size)); lvi.SubItems.Add("No"); } contents.Items.Add(lvi); } } catch (Exception ex) { MessageBox.Show(ex.ToString(), "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error); } finally { if (br != null) br.Close(); if (fs != null) fs.Close(); } }