在 VB.net 中的特定偏移处查找十六进制值
Finding HEX value at a specific offset in VB.net
我正在尝试弄清楚如何读取从特定地址(比如 0x2050)开始的一段字节(比如 16)。我想将十六进制值中的 16 位输出放入标签中。
我一直在努力找出 BinaryReader 和 FileStreams,但我不完全确定它们之间的区别是什么,或者我应该使用哪一个。
*我看到很多线程提到文件大小可能是一个问题,我想指出我将检查的一些文件的大小可能高达 4gb。
我试过以下方法:
Dim bytes() As Byte = New Byte(OpenedFile.Length) {}
ListBox1.Items.Add(Conversion.Hex(OpenedFile.Read(bytes, &H2050, 6)))
但这只是将 6 个字节写入文件,我不确定为什么。列表框中没有输出。
像下面这样的东西怎么样?:
Sub Main()
Dim pos As Long = 8272
Dim requiredBytes As Integer = 2
Dim value(0 To requiredBytes - 1) As Byte
Using reader As New BinaryReader(File.Open("File.bin", FileMode.Open))
' Loop through length of file.
Dim fileLength As Long = reader.BaseStream.Length
Dim byteCount As Integer = 0
reader.BaseStream.Seek(pos, SeekOrigin.Begin)
While pos < fileLength And byteCount < requiredBytes
value(byteCount) = reader.ReadByte()
pos += 1
byteCount += 1
End While
End Using
Dim displayValue As String
displayValue = BitConverter.ToString(value)
End Sub
我正在尝试弄清楚如何读取从特定地址(比如 0x2050)开始的一段字节(比如 16)。我想将十六进制值中的 16 位输出放入标签中。
我一直在努力找出 BinaryReader 和 FileStreams,但我不完全确定它们之间的区别是什么,或者我应该使用哪一个。
*我看到很多线程提到文件大小可能是一个问题,我想指出我将检查的一些文件的大小可能高达 4gb。
我试过以下方法:
Dim bytes() As Byte = New Byte(OpenedFile.Length) {}
ListBox1.Items.Add(Conversion.Hex(OpenedFile.Read(bytes, &H2050, 6)))
但这只是将 6 个字节写入文件,我不确定为什么。列表框中没有输出。
像下面这样的东西怎么样?:
Sub Main()
Dim pos As Long = 8272
Dim requiredBytes As Integer = 2
Dim value(0 To requiredBytes - 1) As Byte
Using reader As New BinaryReader(File.Open("File.bin", FileMode.Open))
' Loop through length of file.
Dim fileLength As Long = reader.BaseStream.Length
Dim byteCount As Integer = 0
reader.BaseStream.Seek(pos, SeekOrigin.Begin)
While pos < fileLength And byteCount < requiredBytes
value(byteCount) = reader.ReadByte()
pos += 1
byteCount += 1
End While
End Using
Dim displayValue As String
displayValue = BitConverter.ToString(value)
End Sub