Showing the hexadecimal from an offset and endian swapping
Posted: Tue Jun 13, 2006 4:24 pm
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
Visit remnantmods.com for more information
http://www.halomods.info/
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
Code: Select all
indexLbl.Text = SwapLong(br.ReadBytes(2))
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
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