• 0

Help me.. Making A Patch (vb.net)


Question

i am use VB2010...

'Sample'

Dim XX As String = "D:\Test.dll"

Patch(XX, &H7129DB, &H90,&H7D,&H7C)

Patch(XX, &H7129AB, &H90,&H7D,&H7A,&H8A,&H90)

Patch(XX, &H3189CA, &H90,&H80)

Link to comment
Share on other sites

17 answers to this question

Recommended Posts

  • 0

Private Sub Patch(ByVal TargetFile As String, ByVal FileOffset As Long, ByVal NewValue As Byte)

Dim br As BinaryReader = New BinaryReader(File.Open(TargetFile, FileMode.Open))

br.BaseStream.Position = FileOffset

br.BaseStream.WriteByte(NewValue)

br.Close()

End Sub

i want to patch multi byte

'''Simple'''

Dim XX As String = "D:\Test.dll"

Patch(XX, &H3189CA, &H90)

Patch(XX, &H7129DB, &H90,&H7D,&H7C)

Patch(XX, &H7129AB, &H90,&H7D,&H7A,&H8A,&H90)

Link to comment
Share on other sites

  • 0

I'm not sure I understand what you want. You want to know how to write the "Patch" function so that your above code will work? If so, can you explain what it's supposed to do, what the arguments represent?

Link to comment
Share on other sites

  • 0

I think that's what he wants to know.

Basically it's

Private Sub Patch(ByVal TargetFile As String, ByVal FileOffset As Long, ByVal NewValue As Byte)

Target File = .exe to patch

FileOffset = Where to enter the byte

NewValue = What the old byte at that offset (+ 1) is replaced with

You want to do a multi-byte system so it would be

Private Sub Patch(ByVal TargetFile As String, ByVal FileOffset As Long, ByVal NewValue As Byte[])

Though, this doesn't make sense to me in such that.. you aren't replacing so much as overwriting, I would of thought you had to specify what you were replacing with what. Like how many bytes it is you need to replace. You may have a group of 2 bytes you need to turn into 3. So wouldn't you have to let it know that 2 is becoming 3, 4, etc?

There is a bit more logic that needs to be done.. but I guess for sake of making your thing work (my VB is very very rusty).. could do

Private Sub Patch(ByVal TargetFile As String, ByVal FileOffset As Long, ByVal NewValue As Byte[])

Dim br As BinaryReader = New BinaryReader(File.Open(TargetFile, FileMode.Open))
     br.BaseStream.Position = FileOffset

   foreach (byteB in NewValue)
           if (byteB != nill)    then
               br.BaseStream.WriteByte(b)
            else
                  break
            end if
         end loop 'I dont know if thats right or not'

     br.Close()


Then it would be called with 

Patch("app.exe", &H3189CA, new byte[] {&H90})
Patch("app.exe", &H3189CB, new byte[] {&H90,&H95,&H40})
Patch("app.exe", &H3189CF, new byte[] {&H96})

My VB is rusty for some of that stuff, so I used the closest thing with C# that I could write, but I hope it's enough to make sense of what I think it is you want. I know for a fact this

code will not run, but it's enough that you should understand what to do.

Link to comment
Share on other sites

  • 0

Private Sub Patch(ByVal TargetFile As String, ByVal FileOffset As Long, ByVal NewValue As Byte())

        Dim br As BinaryReader = New BinaryReader(File.Open(TargetFile, FileMode.Open))
        br.BaseStream.Position = FileOffset
        For Each  byteB In NewValue     [color="#FF0000"]'Problem'[/color]

            If (byteB() <> null) Then
                br.BaseStream.WriteByte(b)
            Else
                break()
            End If

        Next
        br.Close()
    End Sub

How i should be fix for code working help me

Link to comment
Share on other sites

  • 0

I'm not sure I understand what you want. You want to know how to write the "Patch" function so that your above code will work? If so, can you explain what it's supposed to do, what the arguments represent?

i want to patch file Multibyte help me

Link to comment
Share on other sites

  • 0

What is the error? Is it a compile or run time error?

Try adding:

Dim byteB as Byte[/CODE]

before the For loop. I have no idea if that is required in VB.NET (it might create it automatically?) as I've not used VB.NET ever and haven't used Basic since 1995. Just guessing.

Link to comment
Share on other sites

  • 0

This has a better chance of doing what you want:

    Sub Patch(ByVal TargetFile As String, ByVal FileOffset As Integer, ByVal ParamArray NewValue As Byte())

        Using bw = New BinaryWriter(File.Open(TargetFile, FileMode.Open))
            bw.Seek(FileOffset, SeekOrigin.Begin)
            For Each byteB In NewValue
                bw.Write(byteB)
            Next
        End Using

    End Sub

... but it might not, because you don't really explain what you expect the function to do. I've assumed that:

Patch(XX, &H7129DB, &H90,&H7D,&H7C)

Means: "Open file 'XX', go to offset &H7129DB, and starting from there, write the bytes &H90,&H7D and &H7C". Only you can tell whether that's what you want or not.

Link to comment
Share on other sites

  • 0

This has a better chance of doing what you want:

    Sub Patch(ByVal TargetFile As String, ByVal FileOffset As Integer, ByVal ParamArray NewValue As Byte())

        Using bw = New BinaryWriter(File.Open(TargetFile, FileMode.Open))
            bw.Seek(FileOffset, SeekOrigin.Begin)

            For Each byteB In NewValue    ......  [color="#2E8B57"](it Problem)[/color]

                bw.Write(byteB)
            Next
        End Using

    End Sub

... but it might not, because you don't really explain what you expect the function to do. I've assumed that:

Patch(XX, &H7129DB, &H90,&H7D,&H7C)

Means: "Open file 'XX', go to offset &H7129DB, and starting from there, write the bytes &H90,&H7D and &H7C". Only you can tell whether that's what you want or not.

yes patch file address bla bla.. and multibyte

' sample '

Patch("app.exe", &H3189CA, new byte[] {&H90})

Patch("app.exe", &H3189CB, new byte[] {&H90,&H95,&H40,&H1,&H70,,&H90,&H99})

Patch("app.exe", &H3189CF, new byte[] {&H96,&H71})

Link to comment
Share on other sites

  • 0

I am writing up a quick copy in vb.net 2005. It will be quickly thrown together and not the nicest interface in the world. But I THINK it will do what you want. If not it will at least give you something to build on.

Link to comment
Share on other sites

  • 0

Well here it is. I tried to comment as much as I can so it's easy to understand. It's not a difficult program by any means. I added both the ability to dynamically (during run time) set position, bytes, etc. As well as a sample of hard coded (using your examples) example of how to do that. I also wrote a few ideas in the code as well in the comments.

It was a quick do-up I am sure it could be re-written almost entirely and there will be bugs and crashes and such, but I wasn't going to spend the time error handling everything. It does what it's supposed to.

Remember with this though, when you are entering the values, enter the plain hex value, no need for &h in front as I handle all that in the code.

PatchApp.zip

Link to comment
Share on other sites

  • 0

Well here it is. I tried to comment as much as I can so it's easy to understand. It's not a difficult program by any means. I added both the ability to dynamically (during run time) set position, bytes, etc. As well as a sample of hard coded (using your examples) example of how to do that. I also wrote a few ideas in the code as well in the comments.

It was a quick do-up I am sure it could be re-written almost entirely and there will be bugs and crashes and such, but I wasn't going to spend the time error handling everything. It does what it's supposed to.

Remember with this though, when you are entering the values, enter the plain hex value, no need for &h in front as I handle all that in the code.

code the patch fail code you sure ? help me

Link to comment
Share on other sites

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.