Support Forums

Full Version: Offsets and Hex Value Trouble
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I have this program I am working on and So far it does everything but write the hex values to the offset in the file. I am having trouble with it since, the hex values I want to replace are in 3 different consecutive offsets. I wonder if there is a way to do it so it would take the code for instance
Code:
65B710
and separate it into 3 bytes so it would be written into the 3 offsets as 65 B7 10.

Here is my code so far.



Code:
Imports System.IO
Imports System.IO.FileStream
Imports System.IO.BinaryWriter
Public Class Form1
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    End Sub
    Private Sub Hex()
        Dim decValue As Integer = TextBox2.Text
        Dim hexValue As String = decValue.ToString("X")
        TextBox3.Text = hexValue
    End Sub
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Hex()
    End Sub
    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdOpen.Click
        OFD1.ShowDialog()
        TextBox1.Text = OFD1.FileName
    End Sub
    Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged

    End Sub

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdMod.Click
        Dim OpenMe As New OpenFileDialog
        Dim fs As System.IO.FileStream
        Dim bw As System.IO.BinaryWriter
        fs = New System.IO.FileStream(OFD1.FileName, IO.FileMode.OpenOrCreate) 'Uses the file you just opened
        bw = New System.IO.BinaryWriter(fs) 'tells the binary writer to write to the file you opened

        fs.Position = &H7B6805 And &H7BA805 'offset to write (i told it to start at the beginning of the file.)
        bw.Write(TextBox3.Text) 'value to write. if you want to write a hex value, make sure you have "&H" before it.

        fs.Close()
        bw.Close()

        MsgBox("Injected", MsgBoxStyle.Information, "Success")
    End Sub

    Private Sub OpenFileDialog1_FileOk(ByVal sender As System.Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles OFD1.FileOk

    End Sub
End Class
It's quite easy to do.

Store the value in a string eg.

Code:
string hexValue = "65B710";

Use a for loop to loop through the string and get the start index (move it by 2 each time), and use Substring() and have the length parameter 2 (and startIndex parameter would be the for loop variable).
Have the same problem here :/