Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Offsets and Hex Value Trouble
#1
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
[Image: zbacklash11.png]
Reply
#2
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).
Reply
#3
Have the same problem here :/
[Image: 20r9vh4.jpg]
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  VB.Net Int<>Hex Conversion Tool AceInfinity 5 1,197 08-11-2011, 12:08 PM
Last Post: AceInfinity

Forum Jump:


Users browsing this thread: 1 Guest(s)