Acmlm's Board - I2 Archive - Programming - Editing a specific hex value in a file using Visual Basic 6.00
User | Post |
Sukasa
Posts: 632/1981 |
well, what I am trying to do should be simple enough. I'm going to check a file's header that will be in the file type to be edited already, and compare it to an internal checksum. If they match, the program will allow editing, if not, it won't and will not open the file in the first place. Thanks a ton guys
...for those who were wondering, the program is SMWOE. I had a thread on it a week or two ago in the SMW hacking forum. |
HyperLamer
Posts: 4557/8210 |
If you're just planning to blindly write the value, the get statement isn't necessary, but it's a good idea to make sure the value you're changing is right (to ensure the user opened the right file). Simple examples of using Get and Put in Binary mode:
Get #nFileNum, &h1234, X -Reads from file offset 0x1233 (since VB starts at 1) in file #nFileNum into X. Number of bytes read is however many X is. (Byte = 1, Integer = 2, Long = 4.)
Put #nFileNum, &h1234, X -Writes X to file offset 0x1233 in file #nFileNum. Again, number of bytes is size of X.
The seek doesn't even seem necessary, since Get and Put take direct addresses anyway. It might be possible to use them without to do sequential reading and writing, but I generally just use a local variable and increment it for that. |
Sukasa
Posts: 628/1981 |
Originally posted by interdpth It's more of open "a.hex" for binary as #1 seek #1, &H6 get #1, ,a get #1, 7, b put #1, 0x533, c close #1
Okay, I do know a bit, but I am at a loss with the seek statement, as well as a little mislead by the get statements. could you please help out a bit more with this? |
HyperLamer
Posts: 4537/8210 |
I don't recall having to use seek for that. Been a while since I did VB but IIRC, just something like put #1, SomeOffset, SomeValue would work. You should use variable file numbers though:
Dim nFileNum as Integer nFileNum = FreeFile Open "file.bla" For Binary as #nFileNum This way you don't need to worry about whether you already have a file open as #1 or what have you. FreeFile will always be a free file number. |
interdpth
Posts: 462/527 |
It's more of open "a.hex" for binary as #1 seek #1, &H6 get #1, ,a get #1, 7, b put #1, 0x533, c close #1 |
Squash Monster
Posts: 578/677 |
I'm going to assume that you've already learned VB's version of sequential and random files.
Open the file the same as you would with one of those, except open it for Binary instead of Random, Append, Input, or Output, or whatever they called them.
Use Get and Put like you would with Random, but instead of giving it a record number, give it an offset. They'll both put as many bytes as whatever variable type you use with them takes, so you probably want to only use the byte type.
And VB numbers offsets starting with 1 instead of 0, so keep that in mind. |
Sukasa
Posts: 621/1981 |
Hey! I am trying to put together a project at school for extra marks, and I am wondering how to edit a specific offset. I kinda mean something like "gosub editthedamnhex (addresstoedit, newvalue)", and "gosub getthedamnhex" with a global value. Could anyone help me, please? |
|