Skip to content
This repository was archived by the owner on Nov 26, 2022. It is now read-only.

Commit

Permalink
Add a basic hex viewer for mono
Browse files Browse the repository at this point in the history
  • Loading branch information
pleonex committed Feb 28, 2016
1 parent 5419a24 commit 581845a
Show file tree
Hide file tree
Showing 6 changed files with 340 additions and 17 deletions.
21 changes: 12 additions & 9 deletions Tinke/Sistema.cs
Original file line number Diff line number Diff line change
Expand Up @@ -874,10 +874,7 @@ private void treeSystem_AfterSelect(object sender, TreeViewEventArgs e)
listFile.Items[6].SubItems.Add(accion.Get_RelativePath(selectFile.id, "", accion.Root));
toolStripOpenAs.Enabled = true;

if (isMono)
btnHex.Enabled = false;
else
btnHex.Enabled = true;
btnHex.Enabled = true;

if (selectFile.format != Format.Unknown)
btnSee.Enabled = true;
Expand Down Expand Up @@ -1045,17 +1042,23 @@ private void Recursive_ReadFile(sFolder currFolder)
private void btnHex_Click(object sender, EventArgs e)
{
sFile file = accion.Selected_File();
VisorHex hex = new VisorHex(accion.Save_File(file), file.id,
file.name == "rom.nds" ? false : true);
string filePath = accion.Save_File(file);
Form hex;

if (!isMono) {
hex = new VisorHex(filePath, file.id, file.name != "rom.nds");
hex.FormClosed += hex_FormClosed;
} else {
hex = new VisorHexBasic(filePath, 0, file.size);
}

hex.Text += " - " + file.name;
hex.Show();
hex.FormClosed += new FormClosedEventHandler(hex_FormClosed);
}
void hex_FormClosed(object sender, FormClosedEventArgs e)
{
VisorHex hex = (VisorHex)sender;
if (hex.Edited)
VisorHex hex = sender as VisorHex;
if (sender != null && hex.Edited)
accion.Change_File(hex.FileID, hex.NewFile);
}

Expand Down
13 changes: 11 additions & 2 deletions Tinke/Tinke.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,15 @@
<DependentUpon>Settings.settings</DependentUpon>
<DesignTimeSharedInput>True</DesignTimeSharedInput>
</Compile>
<Compile Include="VisorHexBasic.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="VisorHexBasic.Designer.cs">
<DependentUpon>VisorHexBasic.cs</DependentUpon>
</Compile>
<EmbeddedResource Include="VisorHexBasic.resx">
<DependentUpon>VisorHexBasic.cs</DependentUpon>
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Be.Windows.Forms.HexBox\Be.Windows.Forms.HexBox.csproj">
Expand Down Expand Up @@ -391,11 +400,11 @@
</ItemGroup>
<ItemGroup />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>
</Project>
80 changes: 80 additions & 0 deletions Tinke/VisorHexBasic.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

86 changes: 86 additions & 0 deletions Tinke/VisorHexBasic.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace Tinke
{
public partial class VisorHexBasic : Form
{
string file;
UInt32 offset;
UInt32 size;

public VisorHexBasic(string file, UInt32 offset, UInt32 size)
{
InitializeComponent();
this.Text = Tools.Helper.GetTranslation("Sistema", "S41");

this.file = file;
this.offset = offset;
this.size = size;

vScrollBar1.Maximum = (int)size / 0x10;
Show_Hex(0);

txtHex.Select(0, 0);
txtHex.HideSelection = false;
this.Resize += new System.EventHandler(this.VisorHex_Resize);
}

public void Clear()
{
txtHex.Text = "";
}

private void vScrollBar1_Scroll(object sender, ScrollEventArgs e)
{
Show_Hex(e.NewValue);
}

private void Show_Hex(int pos)
{
BinaryReader br = new BinaryReader(File.OpenRead(file));
br.BaseStream.Position = offset + pos * 16;

txtHex.ReadOnly = true;
txtHex.Text = "Offset 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F\r\n\r\n";

for (int i = 0; i < txtHex.Height / 17; i++)
{
if (br.BaseStream.Length == br.BaseStream.Position ||
br.BaseStream.Position >= offset + size)
break;

string text, ascii; text = ascii = "";

for (int j = 0; j < 0x10; j++)
{
if (br.BaseStream.Position == offset + size)
break;

byte value = br.ReadByte();
string c = String.Format("{0:X}", value);
text += (c.Length == 2 ? c : '0' + c) + ' ';
ascii += (value > 0x1F && value < 0x7F ? Char.ConvertFromUtf32(value).ToString() + ' ' : ". ");
}
txtHex.Text += "0x" + String.Format("{0:X}", (i + pos) * 16).PadLeft(8, '0') + " " + text.PadRight(52, ' ') + ascii + "\r\n";
text = "";
ascii = "";
}

br.Close();
}

private void VisorHex_Resize(object sender, EventArgs e)
{
txtHex.Width = this.Width - 30;
Show_Hex(vScrollBar1.Value);
}
}
}
145 changes: 145 additions & 0 deletions Tinke/VisorHexBasic.resx
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<assembly alias="System.Drawing" name="System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<data name="$this.Icon" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>
AAABAAEAEBAAAAAAIABoBAAAFgAAACgAAAAQAAAAIAAAAAEAIAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAA
AAD///8A////ALtqNGu6ZTC8u2Yx7bpmMPe6ZjD3umYw97plMPe6ZS/3uWUu97llLve5ZC73uWQu77di
LL23Yi5j////AP///wC8aTPe+PHq8vfs3/32697/9ure//bq3P/26tz/+vPr//rz6//68ur//Pfz//z4
9P3+/v3wt2Aq1f///wD///8Av3E49fXr3/79v2j//L1n//u+Zf/8vmT//L5k//y9Yv/7vWP/+7xh//y+
YP/8vGL//fv4/blkLfP///8A////AMF4PPf37eP//cJu///YoP//157//9ab///XmP//1pb//9aV///V
lP//1JP/+75l//v39P+7ZzH3Qj042UhCPNlLPjH+WFRP/7aGQv89MCD/QTUk/zcrG/87LBX/97NS//ez
Uv/3slH/97JP//eyT//8+fX/v28292NbVP+nmo3/cGde/0U/Ov+tnJH/XFVO/5aKf/9mXlb/GxkY//zk
0f/84s7//OLM//vgyf/74cj//fr3/8F2O/dxaF//wbar/3lwZv9iXFb/uqmc/25mXf+9saX/fnRq/zMu
K//95dP//OTR//zizf/74cv/++HJ//v38v/FfD/3dWxj+MS5r/+nmo3/gHpz/9bDtP9sY1z/u6+k/6aY
i/9TTUb//eXT//vk0P/748z/+t/H//rfxv/68ur/xoBC92ZeVu9pYVj/Vk9I/01JRv+MgHf/QDs3/0ZC
PP89ODP/LCgl//zk0f/74cz/+uDH//ndw//43ML/+vTt/8aCRfc+OTSFW1RN/7CgkP9pXVH/hnRl/2NY
Tv+qmIj/WlFK/4V5bv/74cz/+t/H//jcwv/22r3/9ti7//r07//Gg0b3lYl9HWZeVvOFeG//SkE7/5WG
ev9WSkD/koN0/09HQP/kz7v/+uDI//jcwv/11rv/89S1//HSs//49PD/xIJG93VsYw+YjICPnI+D/1JM
R//Lt6f/VE1H/5CFef+ajH//9d3G//ndxP/22bz/9Onf//fy7P/79/P/9e/p/8J+Rfv///8Akod7Endt
Yv91bWX/3ci1/29mXv9sYln/++LL//ngyP/43ML/9da6//37+P/85s3/+uXJ/+K2hP+/eUKm////AP//
/wDFiEvq+vby/Prgx//74cn/++LJ//vgyP/538X/+NvB//TWuP//+/j/9ti0/+Gwff/bkmT2tGs+B///
/wD///8AxIVJw/fy7Oz49O78+PTt//jz7f/48+3/+PPt//jy7P/38uz/8ubX/+Kyff/blGX1s2g7B///
/wD///8A////AMF9RGDIi027yIxP7siMT/bIjE/3yIxP98iNT/fJjE/3x4tP98WJS9TEdjuRs2g8Bv//
/wD///8AwAAAAMAAAADAAAAAwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAgAAAAMAA
AADAAQAAwAMAAA==
</value>
</data>
</root>
Loading

0 comments on commit 581845a

Please sign in to comment.