E
extream87
Guest
Hello, i need to read/write 13bytes from a file without knowing the offset. Get the offset is not the problem the main problem is i only know the 1st 4bytes and the last 4bytes so are 5bytes value missing.
4bytes - Known value
5bytes - Unknown value
4bytes - Known value
Total: 13 bytes
In my project i've 2 textbox's.
Textbox1 = 1st 4bytes
????5bytes
Textbox2 = last 4bytes
I want to know if is possible search for this 13bytes in a file and get offset position of first byte and read the 13bytes only knowing 8bytes.
Thanks
Note:
To read bytes i usually use:
Dim littleEndian As Long
Using fs As New IO.FileStream(FileLocPC, IO.FileMode.Open), br As New IO.BinaryReader(fs, beBOM)
fs.Position = position
Dim startIdx As Integer = 0
Dim b() As Byte = br.ReadBytes(4)
littleEndian = BitConverter.ToInt32(b, startIdx)
fs.Close()
fs.Dispose()
End Using
To write:
Dim bytes = Enumerable.Range(0, finalhex.Length \ 2 - 0).Select(Function Convert.ToByte(finalhex.Substring(n * 2, 2), 16)).ToArray()
Dim fs As New IO.FileStream(FileLocPC, FileMode.Open, FileAccess.ReadWrite)
fs.Position = position
fs.Write(bytes, 0, bytes.Length)
fs.Close() : fs.Dispose() : Check()
Continue reading...
4bytes - Known value
5bytes - Unknown value
4bytes - Known value
Total: 13 bytes
In my project i've 2 textbox's.
Textbox1 = 1st 4bytes
????5bytes
Textbox2 = last 4bytes
I want to know if is possible search for this 13bytes in a file and get offset position of first byte and read the 13bytes only knowing 8bytes.
Thanks
Note:
To read bytes i usually use:
Dim littleEndian As Long
Using fs As New IO.FileStream(FileLocPC, IO.FileMode.Open), br As New IO.BinaryReader(fs, beBOM)
fs.Position = position
Dim startIdx As Integer = 0
Dim b() As Byte = br.ReadBytes(4)
littleEndian = BitConverter.ToInt32(b, startIdx)
fs.Close()
fs.Dispose()
End Using
To write:
Dim bytes = Enumerable.Range(0, finalhex.Length \ 2 - 0).Select(Function Convert.ToByte(finalhex.Substring(n * 2, 2), 16)).ToArray()
Dim fs As New IO.FileStream(FileLocPC, FileMode.Open, FileAccess.ReadWrite)
fs.Position = position
fs.Write(bytes, 0, bytes.Length)
fs.Close() : fs.Dispose() : Check()
Continue reading...