Register | Login | |||||
Main
| Memberlist
| Active users
| Calendar
| Chat
| Online users Ranks | FAQ | ACS | Stats | Color Chart | Search | Photo album |
| |
0 users currently in Programming. |
Acmlm's Board - I3 Archive - Programming - VB6 Hex Editing | New poll | | |
Add to favorites | Next newer thread | Next older thread |
User | Post | ||
KeiiChi Kun Leever Learn some manners. Password changed to gibberish and IP banned. Since: 01-01-06 From: Sushi Bar Last post: 6445 days Last view: 6444 days |
| ||
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? | |||
Mega-Dog Since: 11-19-05 From: Minnesota Last post: 6453 days Last view: 6435 days |
| ||
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. |
|||
Dan Purple Leever Since: 11-18-05 Last post: 6441 days Last view: 6431 days |
| ||
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 Since: 11-19-05 From: Minnesota Last post: 6453 days Last view: 6435 days |
| ||
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. |
|||
interdpth Mole MZM rapist Since: 11-18-05 Last post: 6432 days Last view: 6431 days |
| ||
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 |
|||
HyperHacker Star Mario Finally being paid to code in VB! If only I still enjoyed that. <_< Wii #7182 6487 4198 1828 Since: 11-18-05 From: Canada, w00t! My computer's specs, if anyone gives a damn. STOP TRUNCATING THIS >8^( Last post: 6432 days Last view: 6432 days |
| ||
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. (edited by HyperMackerel on 04-20-06 08:47 PM) |
Add to favorites | Next newer thread | Next older thread |
Acmlm's Board - I3 Archive - Programming - VB6 Hex Editing | | |