• 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
  On 29/08/2011 at 18:32, Dr_Asik said:

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

  • 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
  On 30/08/2011 at 05:15, Dr_Asik said:

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.zipFetching info...

  • 0
  On 30/08/2011 at 15:13, firey said:

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

    • Isn't the CPU used to calculate the parity for the RAID? If so, the combination of SSDs and 10GBe might make the CPU more important
    • yeah GSMA began working to enable end to end encryption between android and iphone last year and apparently a new standard was developed. apple has said that they would implement this in "future software updates" but i haven't heard anything since march, the time this was all reported on. shortly after, i read on forbes that the FBI suggests not sending texts between iphone and android because they're unencrypted. i use signal to chat with my wife but i'd rather just use messages tbh (she has an iphone), i'm not really a 3rd party guy haha
    • Well, I did not like the trailer for the project he went to work on also, but why do you think he should waste time with this… did you love the season 2? Maybe I am missing out after the crap I saw in first season ep1-3? I love the first last of us game… while not the BEST it was one of the games that I will remember for the EXPERIENCE it game me… last of us 2 was not on the same level at all and the show🤔 complete miss in my experience of the first few level
    • They're likely moving all resources to other things. Clearly Windows is not important to them.
    • Image Uploader 1.4.3 Build 5352 by Razvan Serea Image Uploader is a free and open-source program for Windows that that allows you to effortlessly upload images, screenshots, and various files to a wide array of hosting services. With its capability to capture selected screen areas, it promptly uploads content to image hosting services, while also offering the convenience of automatically copying the URL to your clipboard. Key Features of Image Uploader: Upload to Multiple Hosting Services Image Uploader supports uploading images and files to over 30 popular hosting services. Additionally, it can upload directly to your own FTP, SFTP, or WebDAV server. After upload, the tool automatically generates sharing codes in HTML, BBCode, and Markdown, with support for custom output templates tailored to your needs. Video Frame Grabbing and Screenshot Tools You can extract multiple frames from video files in a wide range of formats including AVI, MP4, MKV, WMV, and more. It supports both system-installed codecs and built-in ones. The extracted frames can be uploaded individually or compiled into a single mosaic image. It also includes screenshot capabilities for the full screen or selected regions, along with a simple image editor for annotations, highlights, and blurring. Advanced Integration and Usability Image Uploader supports drag-and-drop, clipboard monitoring, and can be accessed via Windows Explorer’s context menu. It also features URL shortening, multi-account support, reuploading, and the ability to upload images embedded in text while retaining formatting. The app is available in several languages, including English, Russian, Turkish, Korean, Arabic, and more. Image Uploader 1.4.3 Build 5352 changelog: New Features Screen Recording: Added two powerful capture methods: DirectX (Desktop Duplication API) FFmpeg-based recording Expanded Hosting Services: Added support for new file hosting platforms: TeleBox (linkbox.to) take-me-to.space ranoz.gg webshare.cz lobfile.com imgpx.com freeimghost.net radikal.cloud anonpic.org fotozavr.ru imgtr.ee thumbsnap.com 8upload.com filemail.com Others Video Uploads: Added Flickr.com support for video uploads Localization: New French translation added Context Menu: Added "File Information" option to video file context menus DPI Support: Improved support for: Screen DPI changes Mixed-DPI multi-monitor setups Improvements Disabled application window animations during screenshot/screen recording initiation Updated API and documentation Improved overall stability Bug Fixes Fixed network client error that could cause application crashes Resolved unauthorized startup registration issue Fixed upload functionality for pixeldrain.com Restored tray icon balloon notifications visibility Various minor bug fixes Download: Image Uploader 64-bit | Portable 64-bit | ~16.0 MB | (Open Source) Download: Image Uploader 32-bit | Portable 32-bit | ~15.0 MB Download: Image Uploader ARM64 | Portable ARM64 | ~11.0 MB Links: Image Uploader Home Page | Screenshot | GitHub Get alerted to all of our Software updates on Twitter at @NeowinSoftware
  • Recent Achievements

    • Reacting Well
      SteveJaye earned a badge
      Reacting Well
    • One Month Later
      MadMung0 earned a badge
      One Month Later
    • One Month Later
      Uranus_enjoyer earned a badge
      One Month Later
    • Week One Done
      Philsl earned a badge
      Week One Done
    • Week One Done
      Jaclidio hoy earned a badge
      Week One Done
  • Popular Contributors

    1. 1
      +primortal
      429
    2. 2
      ATLien_0
      156
    3. 3
      +FloatingFatMan
      149
    4. 4
      Nick H.
      64
    5. 5
      +thexfile
      62
  • Tell a friend

    Love Neowin? Tell a friend!