(Link to AcmlmWiki) Offline: thank ||bass
Register | Login
Views: 13,040,846
Main | Memberlist | Active users | Calendar | Chat | Online users
Ranks | FAQ | ACS | Stats | Color Chart | Search | Photo album
06-02-24 04:15 AM
0 users currently in Programming.
Acmlm's Board - I3 Archive - Programming - VB6 Hex Editing
  
User name:
Password:
Reply:
 
Options: - -
Quik-Attach:
Preview for more options

Max size 1.00 MB, types: png, gif, jpg, txt, zip, rar, tar, gz, 7z, ace, mp3, ogg, mid, ips, bz2, lzh, psd

UserPost
HyperHacker
Posts: 1740/5072
That OpenFile() function reads the entire file into memory. It's good for some things, but in many cases just seek/get/put is better. For example, if you're making a level editor, having the entire file in memory means having a very large array (the size of the ROM) when most of it is data you're not going to be doing anything with. Also, if you write it all back to the file at once, it makes it impossible to have two different programs editing the same file at the same time. Plus, it's slower.
interdpth
Posts: 89/362
I've never see these methods before

I usually just go
dim byte1 as byte
dim thisinteger as integer
dim thatlong as long
dim thisfile as string
ThisFile = "somedir"
open thisfile for binary as #1

seek #1, offset + 1
get #1, ,byte
get #1,, thisinteger
get #1, , thatlong

close #1

But ya'lls method is cooler. I might start using them myself
Mega-Dog
Posts: 30/72
ok here is some new code

Option Explicit

dim FileStuff() as Byte

Private Sub OpenFile(byval Filename as String)
  Open Filename for Binary as #1
  ReDim FileStuff(lof(1)-1)
  Get #1, , FileStuff
  Close #1
End Sub


Now how you get the hex of an offset of the file just address FileStuff(address) so an example would be:

hexat120A = Hex(FileStuff(&H120A&))


Oh and Dan I do use functions at times so that way I can have zeros leading in front of my hex codes.
Dan
Posts: 120/219
KeiChi Tsuu:

You have to use the Open function to open the file, then use the Put method for setting the value, (or Get if you want to retrieve a value), then you close the file. The important thing to remember is to use the correct data type! I believe in VB the size of a data type when using the Get/Put functions is extremely important.

Megadog:

Both of those functions seem like a complete waste of time. They call the in-built VB functions, so why not just call those functions directly instead of adding another completely un-necessary step?
Mega-Dog
Posts: 29/72
Option Explicit

Private Function Ascii2Hex(ByVal Ascii as Byte) as String
  Ascii2Hex = Hex(Ascii)
End Function


this function will turn any Ascii Character into a Hex String. Hex in VB is always in String format. here would be how to turn it back:


Private Function Hex2Ascii(ByVal HexCode as String) as Byte
  Hex2Ascii = AscW(HexCode)
End Function


this code will only convert codes prob 00-FF for like rom hacking. to make it support higher hex just use Double or Long instead of Byte.
KeiiChi Kun
Posts: 31/190
I know this is a rather broad, and perhaps stupid question, but what is the best way to edit the hexadecimal values of a certain offset of a file in Visual Basic 6?
Acmlm's Board - I3 Archive - Programming - VB6 Hex Editing


ABII

Acmlmboard 1.92.999, 9/17/2006
©2000-2006 Acmlm, Emuz, Blades, Xkeeper

Page rendered in 0.011 seconds; used 350.59 kB (max 389.11 kB)