• 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

    • Chrome is Google's commercial web browser product; it consists of their proprietary features (Googlified everything including profile sync) plus their chromium project barebones web browser. Google developers control the chromium project. The chromium project is the "core" for the web browser product from other vendors including Microsoft Edge (their own proprietary features), Opera (their own features), Brave (their own features), etc... The "downstream" teams at Microsoft, Opera, Brave, etc., can either integrate their original MV2-supporting code into future builds, or they can integrate chromium wholesale and simply add-on their own features/functionalities -- their 'current' build pipeline, so to speak. THIS is why changes at the chromium project affect so many products besides only Google's commercial Chrome browser. -- Edit to add: The chromium project is open-source, and is the piece that's Google's code contribution to the W3C and world wide web at large; there are no licensing fees for others to use the code in their own products... which is what they do. Other browser engines do exist (Firefox's for example) but it's nearly impossible to have both engines bundled into the same 1 browser product.
    • You're comparing settler colonies to colonized war torn nations. It's easy to become the richest by coming in and stealing other people's land, culture and resources.
    • ABP has become "old news" when MV3 started rolling out. They've gone downhill and is now simply irrelevant..... in my experience.
    • About two years ago, I switched to Brave and haven't looked back.
    • FWIW StatCounter has been trash for over 25+ years! Back in the day (circa 2000 and GeoCities pre-Blogger era), it was useful to paste a number on your webpage indicating how many visitors you had. In the ensuing 25+ years, they've grown in reputation and changed their ways... but their overall consumer value has remained abysmal. Serious marketing agencies only cite StatCounter when there's literally no other sources available to support any marketing claims! They are the absolute lowest threshold serious companies use to push any sort of narrative about this-or-that happening. Besides their credibility being what it is, they are forever subject to quality issues. They're so bad that my DNS-level ad-filter prevents me from even viewing their main website! HA!
  • 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
      531
    2. 2
      PsYcHoKiLLa
      231
    3. 3
      +Edouard
      131
    4. 4
      ATLien_0
      88
    5. 5
      Steven P.
      81
  • Tell a friend

    Love Neowin? Tell a friend!