Jump to content
Tuts 4 You

Help With Making A Patch (vb.net)


cegy

Recommended Posts

Hi, is it possible to make a patch in vb.net am using 2008 of it atm. i do know how a patch works in vb6 but not in .net so i thought to ask.

could somone show me a simple example please.

many thanks :biggrin:

Link to comment
Imports System.IOPublic Class Form1	Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load		Patch("C:\Grandma's_Online_Banking.exe", 666, &H90)	End Sub	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 SubEnd Class

Good luck with the rest :biggrin:

Link to comment

i could userstand soem of it but not all erm..

Patch("C:\Grandma's_Online_Banking.exe", 666, &H90) is to open the file and patch it with the offset of &H90

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

br.BaseStream.Position = FileOffset

br.BaseStream.WriteByte(NewValue)

br.Close()

mean that its gonna open the file and write the file offset patch to it and then close it.

could u tell me abit more about this bit?

Patch("C:\Grandma's_Online_Banking.exe", 666, &H90)

and also to show like a 4 byte patching if it possible than just 1 bye patching?

many thanks

Edited by cegy
Link to comment
could u tell me abit more about this bit?

Patch("C:\Grandma's_Online_Banking.exe", 666, &H90)

and also to show like a 4 byte patching if it possible than just 1 bye patching?

Ofc it's a simple and useless example.. written in a min.

I dunno what you expected. U're really asking about the utter basics !

Do at least 'something', show it and get help.

Sry, but pls don't be that lazy and expect full projects :geek:

Link to comment

Patch("C:\Grandma's_Online_Banking.exe", 666, &H90)

that IS 1 byte patch at offset 666, patching a nop into the executable.... jesus, if you cant figure that out from the code, im worried about any potential code you make...

Edited by evlncrn8
Link to comment
could u tell me abit more about this bit?

Patch("C:\Grandma's_Online_Banking.exe", 666, &H90)

and also to show like a 4 byte patching if it possible than just 1 bye patching?

Perhaps:

(no specific language!)

global nrPatches.l=4

dim Offset.l (global nrPatches)

Dim Patchdata.b(global nrPatches)

Offset(0)=666

Offset(1)=766

Offset(2)=866

Offset(3)=966

Patchdata(0)=$43

Patchdata(1)=$4f

Patchdata(2)=$4f

Patchdata(3)=$4c

for i=0 to NrPatches-1

Patch("C:\Grandma's_Online_Banking.exe", Offset(i), Patchdata(i))

next

yu can all do dynamically, its just a fast idea to given answer!

Edited by hmi222
Link to comment

He's suggesting you use a loop for patching multiple offsets.

Perhaps you should start by coding some simple projects first - this is the absolute basic of programming in any language.

Link to comment

yup, its simple binary file access... it should be one of the first things you learn apart from hello world...

running before you can run isn't good... you'll trip, land on your head and get bloody... though you do have the vb/.net 'bandage' of it hiding things from you...

Link to comment
Patrickssj6

This is a module I created a long time ago...

Public Class PatchModule	Public Structure PEPatch
'Public Variables - Vital
Public eFilePath As String
'Prvate Variables - NotVital
Private eBytes As Array 'Use Functions
Public Function FileExistance() As Boolean
If IO.File.Exists(eFilePath) = True Then
Return (True)
Else
Return (False)
End If
End Function
Public Function CompareFileSize(ByRef TotalBytes As Integer) As Boolean
eBytes = IO.File.ReadAllBytes(eFilePath)
If eBytes.Length = TotalBytes Then
Return (True)
Else
Return (False)
End If
End Function Public Function GetFileSize() As Long
eBytes = IO.File.ReadAllBytes(eFilePath)
Return (eBytes.Length)
End Function
Public Function ReadBytes(ByRef pOffset As Long, Optional ByRef pLength As Integer = 4) As String
Dim BR As IO.BinaryReader = New IO.BinaryReader(New IO.FileStream(eFilePath, IO.FileMode.OpenOrCreate))
BR.BaseStream.Position = pOffset
eBytes = BR.ReadBytes(pLength)
ReadBytes = BitConverter.ToString(eBytes, 0, pLength)
BR.Close()
End Function
Public Sub WriteBytes(ByRef pOffset As Long, ByRef pBytes As Byte)
Dim BW As IO.BinaryWriter = New IO.BinaryWriter(New IO.FileStream(eFilePath, IO.FileMode.OpenOrCreate))
BW.BaseStream.Position = pOffset
BW.Write(pBytes)
BW.Close()
End Sub
Public Function CheckPatched(ByRef pOffset As Long, ByRef pOriginalByte As Byte) As Boolean
Dim BR As IO.BinaryReader = New IO.BinaryReader(New IO.FileStream(eFilePath, IO.FileMode.OpenOrCreate))
BR.BaseStream.Position = pOffset
eBytes = BR.ReadBytes(1)
BR.Close()
If BitConverter.ToString(eBytes, 0, 1) = BitConverter.ToString(BitConverter.GetBytes(pOriginalByte), 0, 1) Then
Return (False) 'Not Patched
Else
Return (True) 'Patched
End If End Function
End StructureEnd Class

Put that inside a new class then....

Declare to use the new class

Public Patcher As PatchModule.PEPatch

Then do whatever you want....this example NOPs out 2 jumps (each 2 bytes) to bypass an ASCII check:

Patcher.eFilePath = FilePath
'ASCII Overwrites
For i = 0 To 1
Patcher.WriteBytes(&HCDF79 + i, &H90)
Patcher.WriteBytes(&HCDF8B + i, &H90)
Next
TextBox2.Paste("Patching ASCII Overwrite...DONE!" & vbNewLine)
Edited by Patrickssj6
Link to comment
  • 3 weeks later...

I think he means write multiple bytes to 1 address instead of single byte to multiple address's, im not 100% sure how vb.net works but can you make an array of bytes to patch to single address like you would with other programming languages?

maybe this type of example he is looking for

Uf0 -Pu55y example code:

Imports System.IO

Public Class Form1	Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load		Patch("C:\Grandma's_Online_Banking.exe", 666, &H90)	End Sub

now im not sure the following would work but give it a try for multiple bytes on single address, I have no idea how vb.net works but I going by how vb.net might declare an array of bytes.

Imports System.IOPublic Class Form1	Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim Patch() as Byte = {&H90,&H90,&H90,&H90} Patch("C:\Grandma's_Online_Banking.exe", 666, Patch) End Sub

And the anwser to your question about " Patch("C:\Grandma's_Online_Banking.exe", 666, &H90) "

Patch = Call the Sub that writes the bytes to address

"C:\Grandma's_Online_Banking.exe" = the Path to application

666 = the offset address

&H90 = the byte, Now you might not relize that &H mean that its a byte, and ofcause you already know that 90 = nop so to tell vb.net that its an actuall byte you need &H then 90 so it will be &H90

I hope this helps you with understanding what &H is... and im not 100% sure that "Dim Patch() as Byte = {&H90,&H90,&H90,&H90}" will work but if it does it it could be used to nop out 4 bytes from a single starting address.

Good luck

Edited by Departure
Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...