Read/Write Values at a Given Hex Address Offset

D

Dave

Greetings,

How do I read the hex value of a binary file at a given offset? i.e., how
can I find out, via code, what the 2-digit hex code is at, say, offset
132ea. Then, how would I write over that value?

Thanks,

-Dave
 
M

Mattias Sjögren

How do I read the hex value of a binary file at a given offset? i.e., how
can I find out, via code, what the 2-digit hex code is at, say, offset
132ea. Then, how would I write over that value?

Open a FileStream, Seek() to offset &H132ea and then read/write from
there (using for example a BinaryReader/BinaryWriter).



Mattias
 
D

Dave

Thanks for your help, I'll try it out.

Mattias Sjögren said:
Open a FileStream, Seek() to offset &H132ea and then read/write from
there (using for example a BinaryReader/BinaryWriter).



Mattias
 
J

james

Dim MyAddress as Short = &H132
' assumes that you are using the OpenFileDialog to get the path & Filename
Dim filename As String = OpenFileDialog1.FileName

Dim fs As FileStream = New FileStream(filename, FileMode.Open)

Dim br As BinaryReader = New BinaryReader(fs)

Dim sz As Integer = fs.Length' you don't neccessarily need this, I use this in my app. toset the size an Array.



br.BaseStream.Seek(MyAddress, SeekOrigin.Begin)'moves to the address you want

a = br.ReadInt32() 'reads Both Bytes (characters you want)

ListBox1.Items.Add("My Address Data: " + (a).ToString()) 'Adds the data to a listbox

br.Close()'close the Binary Reader

fs.Close()' close the FileStream



To overwrite the character(s) just do the reverse and use the Binary Writer. (make sure you don't write more than the number of
characters (Bytes) you need to or you will overwrite (corrupt) data you don't intend to.

james
 
J

james

Forgot one little thing :)

Dim a as Object

I always forget something!!
(over th hill and gaining speed)
james
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top