473,509 Members | 2,863 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Read/Write Values at a Given Hex Address Offset

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
Nov 21 '05 #1
4 4980
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

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Nov 21 '05 #2
Thanks for your help, I'll try it out.

"Mattias Sjögren" <ma********************@mvps.org> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
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

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.

Nov 21 '05 #3
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

"Dave" <no****@yahoo.com> wrote in message news:en**************@TK2MSFTNGP10.phx.gbl...
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

Nov 21 '05 #4
Forgot one little thing :-)

Dim a as Object

I always forget something!!
(over th hill and gaining speed)
james
"james" <jjames700ReMoVeMe at earthlink dot net> wrote in message news:ud**************@TK2MSFTNGP15.phx.gbl...
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

Nov 21 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
6378
by: Brian | last post by:
I'm having intermittent trouble with a call to the Read method of the HttpWebResponse object. I get an ArumentOutOfRangeException claiming that deep down inside of the Read method, the count...
4
2931
by: Prowler | last post by:
In the application we are currently building, we need to write positioning code on-the-fly, based upon the screen offset of the element in the AS/400 application which drives the Web app. The 400,...
1
4520
by: news | last post by:
OP wrote: }in order to justify learning another language I'd first need to be }convinced that python could easily do the following:- } }ReadSectors2Bufr(hdx, StartSectr, SectrCnt, Bufr); <-- like...
19
2681
by: Holger Hasselbach | last post by:
- The value of the object allocated by the malloc function is used (7.20.3.3). - The value of any bytes in a new object allocated by the realloc function beyond the size of the old object are used...
8
7242
by: james | last post by:
I am trying to use Filestream to read a file ( .DAT) that contains values in HEX that I want to convert to text. I know the different offset addresses for each portion of the data I am trying to...
35
11335
by: RyanS09 | last post by:
Hello- I am trying to write a snippet which will open a text file with an integer on each line. I would like to read the last integer in the file. I am currently using: file = fopen("f.txt",...
6
5911
by: Urs Thuermann | last post by:
With offsetof() I can get the offset of a member in a struct. AFAICS, it is portable and clean to use this offset to access that member. I need to do something like this struct foo { struct...
3
8874
by: sam | last post by:
same as subject?
0
7237
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7137
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7347
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7416
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7073
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7506
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
3218
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3207
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
779
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.