private void button1_Click(object sender, EventArgs e) { FileDataNode node = treeView1.SelectedNode as FileDataNode; if (node != null) { IDataSurrogate dataSurrogate = node.SurrogateObject as IDataSurrogate; int offset = node.GetFileOffset() + node.GetHeaderSize(); ShowHexData(dataSurrogate, offset); } button1.Visible = false; }
private void ShowHexPanel(IDataSurrogate surrogate, int offset) { toolStripButton1.Visible = true; pageControl1.SelectedTab = tabPage1; if (surrogate.DataSize < 0x10000) { ShowHexData(surrogate, offset); } else { button1.Visible = true; } }
private void ShowHexData(IDataSurrogate surrogate, int offset) { byte[] data = surrogate.BufferedData; string hexView = ""; string hexData = ""; string asciiData = ""; for (int i = 0; i < data.Length; i++) { if (i % 2 == 1) { hexData += string.Format("{0:X2} ", data[i]); } else { hexData += string.Format("{0:X2}", data[i]); } if (char.IsControl((char)data[i])) { asciiData += '.'; } else { asciiData += (char)data[i]; } if ((i + 1) % 0x10 == 0 || i == data.Length - 1) { string line = string.Format("{0:X8}: ", offset); line += hexData; line = line.PadRight(59); line += asciiData; line += Environment.NewLine; hexView += line; offset += 0x10; hexData = ""; asciiData = ""; } } textBox1.Text = hexView; }