• Log in or sign up for an account here: https://www.sythe.org/login

Hex Editing Functions

Darthatron

Massive Troll
Joined
May 22, 2006
Sythe Gold
0
Messages
1,612
Age
35
Location
The internet.
Hex Editing Functions
Ok, here are some pretty basic Hex Editing Functions for... Well... Hex Editing. :p I have no idea why anyone here would want to use these functions, except maybe save file editing... Or something.

This is a Function thats get a string of Bytes...
Code:
Public Function ReadHEX(FilePath As String, Start As Long, Length As Long) As String
On Error Resume Next
Dim iFile As Long
Dim bytData As Byte
Dim sHex As String
Dim i As Long
    Start = Start + 1
    iFile = FreeFile
    sHex = ""
    i = 0
    Open FilePath For Binary As iFile
        For i = Start To (Start + Length - 1)
            Get iFile, i, bytData
            sHex = sHex & Right("00" & Hex(bytData), 2)
        Next i
    Close iFile
ReadHEX = sHex
End Function
Example of use:
Code:
strString = ReadHEX("C:\File.bin", 20542, 1)
________________________________________________

This next Function lets you write a single Byte into a file. If you could be bothered you could easily use it to make a 'WriteHEX' Function, but I am far too lazy and have no need for it.
Code:
Public Function Write1Byte(FilePath As String, Start As Long, Data As String)
On Error Resume Next
Dim iFile As Long
Dim bytData As Byte
    Start = Start + 1
    iFile = FreeFile
    Open FilePath For Binary As iFile
        bytData = CInt("&H" & Right("00" & Data, 2))
    Put iFile, Start, bytData
    Close iFile
End Function
Example of use:
Code:
Write1Byte "C:\File.bin",, 20542, "FF"
________________________________________________

The following code flips a HEX string around. Sometimes in Binary Data to 'goto' a location you would put the actual location of the String, reversed. So... For the location &H123456 to 'goto' the location would be &H563412.
Code:
Public Function ReverseHEX(HEXData As String) As String
Dim iNum As Long
Dim HEXHolder As String
    If (Len(HEXData)) <> Int((Len(HEXData)) / 2) * 2 Then HEXData = "0" & HEXData
    
    For iNum = 0 To Len(HEXData) + 1
        If Len(HEXData) <= 1 Then GoTo EndNow
        HEXHolder = HEXHolder & Right(HEXData, 2)
        HEXData = Left(HEXData, Len(HEXData) - 2)
    Next iNum
EndNow:
ReverseHEX = HEXHolder
End Function
Example of use:
Code:
strString = ReverseHEX("123456")

Hell... that's it, I'm too lazy to elaborate anymore. :p Have fun Hex Editing! :D

EDIT: Obviously nobody used these yet, because I used a function that I didn't include... Anyway, fixed it.
 
Hex Editing Functions
not bad.....well im not rlly sure if it is or not cuz i don;t know any of this real well, but it looked like it took a while :)
 
Hex Editing Functions
not bad.....well im not rlly sure if it is or not cuz i don;t know any of this real well, but it looked like it took a while :)

No... they took about 5 minutes each to write, they are pretty basic. :D The hard/annoying part is finding the offsets you want to edit and what they do. :( Thanks for commenting.
 
Runescape Gamblingrunescape gambling
Back
Top