Hi,
I wan to create simple hex editor because later want to add function to read memory from comm port. I want to make it able read byte by byte and can edit byte by byte too.
So far I do have below code. I edit it from a code found it somewhere on the net.
Now I do have binar as a byte array contain the byte data of the file. With above code, it will display the hex value as string in the textbox.
My question is can I display the byte array in richtextbox as a hexdump without convert it to string? I want to do something like HxD editor where we can select certain byte and when we change it only the pair ascii will change too.
I think this something like manipulate the byte array on the richtextbox but I'm no idea how I can do that.
Thanks in advance.
I wan to create simple hex editor because later want to add function to read memory from comm port. I want to make it able read byte by byte and can edit byte by byte too.
So far I do have below code. I edit it from a code found it somewhere on the net.
Code:
Function BinarF(ByVal FilePath As String) As Byte()
Dim f As System.IO.FileStream = System.IO.File.OpenRead(FilePath)
f.Seek(0, System.IO.SeekOrigin.Begin)
Dim j As Integer = 1024 * 500
If f.Length - 1 < 1024 * 500 Then
j = CInt(f.Length - 1)
Else
MsgBox("The file will not load completely: just 512KB")
End If
Dim binar(j) As Byte, i As Integer = 0
For i = 0 To j
binar(i) = CByte(f.ReadByte())
Next
Return binar
End Function
Private Sub OpenToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OpenToolStripMenuItem.Click
Dim ofd1 As New OpenFileDialog, path As String = ""
If ofd1.ShowDialog = Windows.Forms.DialogResult.OK Then
Dim binf As Byte() = BinarF(ofd1.FileName)
Dim i As Integer = 0, j As Integer = binf.Length - 1, x As Byte = 0
Dim a As String = "", buffer1 As String = ""
Dim strplus As String = "", buffer2 As String = ""
'var with start values
For i = 0 To j
x = binf(i)
If x < 16 Then
buffer1 += "0" + Hex(x)
Else
buffer1 += Hex(x)
End If
Select Case x
Case 0, 13, 10, 9, 12, 11 : strplus += "." 'also 12 asd 11 if richtextbox
Case Else : strplus += Chr(x)
End Select
If strplus.Length = 8 Then
buffer1 += " "
End If
If strplus.Length = 16 Then
buffer2 += buffer1 + " " + strplus + Chr(13) + Chr(10)
buffer1 = ""
strplus = ""
Else
buffer1 += ChrW(32)
End If
If buffer2.Length > 4096 Then
a += buffer2
buffer2 = ""
End If
Next
While buffer1.Length < 48
buffer1 += " "
End While
a += buffer2 + buffer1 + " " + strplus
TextBox1.Text = a
End If
End Sub
My question is can I display the byte array in richtextbox as a hexdump without convert it to string? I want to do something like HxD editor where we can select certain byte and when we change it only the pair ascii will change too.
I think this something like manipulate the byte array on the richtextbox but I'm no idea how I can do that.
Thanks in advance.