• 0

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


Question

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)

  • 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.

  • 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

  • 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.

  • 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.

  • 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})

  • 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.

  • 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

  • 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

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

    • No registered users viewing this page.
  • Posts

    • I do trust Apple probably more than these other companies with certain data, but I also do think (and it has been demonstrated that) Apple pulls a lot of shenanigans and always has for a long time.
    • Does your iPhone support the latest iOS version? Here's the iOS 27 compatibility list by Aditya Tiwari It's that time of year when we get to know about the latest operating system updates for Apple devices. For iPhone, Apple previewed the iOS 27 update at WWDC 2026, where the company finally introduced an upgraded version of Siri. Apple typically supports iPhone models for up to five years. But it has been making exceptions in recent years (read iPhone 11). If you're wondering whether your iPhone is compatible with the iOS 27 update, here is the official list of devices: iPhone 17 Pro Max, iPhone 17 Pro, iPhone 17, iPhone 17e, iPhone Air iPhone 16 Pro Max, iPhone 16 Pro, iPhone 16, iPhone 16 Plus, iPhone 16e iPhone 15 Pro Max, iPhone 15 Pro, iPhone 15 Plus, iPhone 15 iPhone 14 Pro Max, iPhone 14 Pro, iPhone 14 Plus, iPhone 14 iPhone 13 Pro Max, iPhone 13 Pro, iPhone 13, iPhone 13 mini iPhone 12 Pro Max, iPhone 12 Pro, iPhone 12, iPhone 12 mini iPhone 11 Pro Max, iPhone 11 Pro, iPhone 11 iPhone SE (2nd generation), iPhone SE (3rd generation) So, you can download the iOS 27 developer beta on up to 31 different iPhone models. There has been no change to the list of supported iPhones since iOS 26. However, it will expand to include more devices when the iPhone 18 series arrives later this year. To download the developer beta on your iPhone, go to Settings > General > Software Update > Beta Updates. Here, select "iOS 27 Developer Beta" from the list of choices to get the new update. In addition to iOS 27, you can try the developer beta versions of macOS 27, iPadOS 27, watchOS 27, tvOS 27, and HomePod software 27 on your supported devices. iOS 27 comes with improved Liquid Glass, which you can adjust using a new transparency slider. Apple said during the keynote that iPhone apps now launch up to 30% faster, new photos appear in the Photos app up to 70% faster, and AirDrop transfers work up to 80% faster. The new update promises to improve performance on older iPhones by introducing a new CPU Scheduler that supports devices all the way back to the iPhone 11. While iOS 27 is supported on older iPhones, it goes without saying that they'll lack several features due to hardware differences. For instance, iPhone 14/14 Plus and older models come with a notch instead of the Dynamic Island. Similarly, Apple Intelligence features are supported on iPhone 15 Pro/Pro Max and later models.
    • The Radeon RX 9070 XT is right up there with the GeForce RTX 5070 Ti
    • I don't know why someone said useless, but it does have that pesky kernel driver bundled, and it's in perennial turmoil. When it goes bad, it goes very bad, and it's impossible to predict when it will due to system differences. I know that they're in the middle of development for a major new version that will include a completely new driver, one that they expect will largely solve the problem, but that's a ways out and it's unproven at this point.
    • doesn't AdGuard let ads through that pay to be let through?
  • Recent Achievements

    • Reacting Well
      Sir_Timbit earned a badge
      Reacting Well
    • Week One Done
      rubentuben8 earned a badge
      Week One Done
    • Week One Done
      ARaclen earned a badge
      Week One Done
    • Week One Done
      jojodbn earned a badge
      Week One Done
    • One Year In
      jojodbn earned a badge
      One Year In
  • Popular Contributors

    1. 1
      +primortal
      523
    2. 2
      PsYcHoKiLLa
      232
    3. 3
      +Edouard
      132
    4. 4
      ATLien_0
      88
    5. 5
      Steven P.
      83
  • Tell a friend

    Love Neowin? Tell a friend!