Showing the hexadecimal from an offset and endian swapping
- LuxuriousMeat
- Posts: 824
- Joined: Thu Nov 03, 2005 6:43 pm
- Location: zzzzzzzzzzzzzzzz
- Contact:
Showing the hexadecimal from an offset and endian swapping
im using vb 2005 and i need to know how to show 2 bytes of the hexadecimal in a textbox and then endian swap it does anybdy nwo how to do that

Code: Select all
Dim BR As BinaryReader(New FileStream(Junk Here))
BR.BaseStream.Position = Dec(Hex Offset Here)
TextBox1.Text = SwapShort(BR.ReadBytes(2))
TextBox2.Text = SwapLong(BR.ReadBytes(2))
TextBox3.Text = SwapInteger(BR.ReadBytes(2))
Public Function Dec(ByVal HexString As String)
Return ("&H" & HexString)
End Function
Public Function SwapShort(ByVal IntIn As Short) As Short
Dim BytesIn(1) As Byte
Dim BytesOut(1) As Byte
Dim X As Integer
BytesIn = BitConverter.GetBytes(IntIn)
For X = 0 To 1
BytesOut(X) = BytesIn(1 - X)
Next X
SwapShort = BitConverter.ToInt32(BytesOut, 0)
End Function
Public Function SwapInteger(ByVal IntIn As Integer) As Integer
Dim BytesIn(3) As Byte
Dim BytesOut(3) As Byte
Dim X As Integer
BytesIn = BitConverter.GetBytes(IntIn)
For X = 0 To 3
BytesOut(X) = BytesIn(3 - X)
Next X
SwapInteger = BitConverter.ToInt32(BytesOut, 0)
End Function
Public Function SwapLong(ByVal IntIn As Integer) As Long
Dim BytesIn(7) As Byte
Dim BytesOut(7) As Byte
Dim X As Integer
BytesIn = BitConverter.GetBytes(IntIn)
For X = 0 To 7
BytesOut(X) = BytesIn(7 - X)
Next X
SwapLong = BitConverter.ToInt32(BytesOut, 0)
End Function
http://pscode.com/vb/scripts/ShowCode.a ... &lngWId=10
- LuxuriousMeat
- Posts: 824
- Joined: Thu Nov 03, 2005 6:43 pm
- Location: zzzzzzzzzzzzzzzz
- Contact:
they all give me errors like this
i get this error
Value of type :I-dimensional array of Byte' cannot be converted to 'Integer'.
Code: Select all
indexLbl.Text = SwapLong(br.ReadBytes(2))
Value of type :I-dimensional array of Byte' cannot be converted to 'Integer'.

Im not to sure on what SwapEndian really is but I searched and someone said it was where you reverse the bytes/string. So here is what I came up with:
If it doesnt work, try changing Input, Char1, Str1 as integers.
Good luck!
Code: Select all
Public Function SwapEndian(ByVal Input As String)
Dim Char1 As String = Nothing
Dim Str1 As String = Nothing
For i As Short = Len(Input) To 1 Step -1
Char1 = Mid(Input, i, 1)
Str1 &= Char1
Next
Return Str1
End Function
Good luck!
- LuxuriousMeat
- Posts: 824
- Joined: Thu Nov 03, 2005 6:43 pm
- Location: zzzzzzzzzzzzzzzz
- Contact:
Code: Select all
Public Function SwapEndian(Hexstr As String) As String
Dim Tmp As String
For i As Integer = 0 To (HexStr.Length/2)-1
Tmp = HexStr.Substring(i*2,2) & Tmp
Next
Return Tmp
End Function
Public Function DecToHex(DecVal As Long) As String
Return DecVal.ToString("X")
End Function
Public Function HexToDex(HexStr As String) As Long
Return Convert.ToInt64(HexStr,16)
End Function
There damn
Sig breaks rules, read the rules before reposting.