簡體   English   中英

在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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM