• 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

    • Dragon's Dogma 2: Dark Arisen expansion to bring snowy region, new updates also coming by Pulasthi Ariyasinghe Capcom had a surprise waiting for Dragon's Dogma fans today in the Nintendo Direct presentation. The company revealed an expansion for the second installment with a name that should be familiar to series veterans. Coming later this year, Dragon's Dogma 2: Dark Arisen is promising a massive new region to explore, new monsters, fresh skills to learn, and more. The studio says players will be heading to the Northern region of the world, named Norgan, to find new secrets about an undying "Fallen Dragon." There will be forgotten relics that the protagonist can find to unlock fresh weapons and skills the expansion is introducing. Players will also be able to find mysterious equipment from a previous Arisen as a part of the expansion, all part of 12 Lost Rites Dungeon Challenges they must complete to gain access. In Neowin's own review, I found Dragon's Dogma 2 to be an impressive RPG when it launched back in 2024, giving the title an 8.5/10 for its class variants, companion system, and immersive exploration. "Once a prosperous region of the kingdom of Vermund, it was abandoned many years ago for reasons unknown," says Capcom about the new region. "Long has it been since any soul traveled its paths. Blanketed in heavy snow, these frigid lands are home to savage hordes and creatures of unbelievable power. Those who are capable of vanquishing such fearsome foes, or those who possess a keen eye for exploration, will find themselves rewarded with powerful relics." Dragon’s Dogma 2: Dark Arisen expansion launches on October 9, 2026, with a $29.99 price tag. Ahead of the expansion release, Capcom is also planning to release two free updates to the base game. The first will land tomorrow, June 10, bringing more accessible fast travel with an Eternal Ferrystone and other quality-of-life adjustments. The second update will land sometime in August, aiming to improve frame rates, add more save slots, and bring even more community-requested adjustments. This expanded Dark Arisen edition is also launching on the Nintendo Switch 2 on the same day the content comes to PC, Xbox Series X|S, and PlayStation 5.
    • Classic themes are just the colors on the bar like the olden days, if you use the image themes, it does fancy transparent backgrounds and it makes the elements of the app look like they are transparent bubbles. This sample image shows what it looks like.  
    • Good point, unfortunately. NextDNS has far more filters and workarounds than uBlock, and it's easy to implement.
    • Windows 10 KB5094127 Patch Tuesday improves File Explorer search and more by Taras Buria The June 2026 Patch Tuesday updates are here, bringing mandatory patches to users with PCs enrolled in the Extended Security Update program for Windows 10. Microsoft is rolling out KB5094127, with build numbers 19045.7417 and 19044.7417. Changelog includes the following: [File Explorer] This update improves File Explorer search, including support for Chinese text, and UTF 8–encoded files without a byte order mark (BOM). Text now displays more clearly and consistently across search results, Content view, and tooltips. [Secure Boot] This update enables dynamic status reporting for Secure Boot states in Windows Security App. This update adds a new policy setting, LimitSecureBootRequiredServiceData, under Computer Configuration > Administrative Templates > Windows Components > Secure Boot. When this setting is enabled, Windows limits the Secure Boot service data it sends by suppressing the event normally sent to Microsoft. This policy is also included in the Windows Restricted Traffic Limited Functionality Baseline package. For information about the policy, see Manage connections from Windows 10 and Windows 11 operating system components to Microsoft services. With this update, Windows quality updates include additional high confidence device targeting data, increasing coverage of devices eligible to automatically receive new Secure Boot certificates. Devices receive the new certificates only after demonstrating sufficient successful update signals, maintaining a controlled and phased rollout. As for known bugs, Microsoft has the following to say: A workaround is available in the official documentation. Today's updates are available for PCs enrolled in the Extended Security Updates program only. If your PC is eligible, you can download the update from Settings > Windows Update or from the Microsoft Update Catalog here.
    • Then the solution is to not let children have easy access to smart phones or internet until they are older, not mass surveillance. Only this would require parents to do actual parenting, most likely, as with any good solution to the problem.
  • Recent Achievements

    • Week One Done
      rubentuben8 earned a badge
      Week One Done
    • Week One Done
      ARaclen earned a badge
      Week One Done
    • One Year In
      jojodbn earned a badge
      One Year In
    • One Month Later
      jojodbn earned a badge
      One Month Later
    • Week One Done
      jojodbn earned a badge
      Week One Done
  • Popular Contributors

    1. 1
      +primortal
      523
    2. 2
      PsYcHoKiLLa
      231
    3. 3
      +Edouard
      124
    4. 4
      ATLien_0
      87
    5. 5
      Steven P.
      83
  • Tell a friend

    Love Neowin? Tell a friend!