Jump to content
Tuts 4 You

Search n Replace byte VB.net


andrextrap

Recommended Posts

i will make patch with vb.net


but i dont know how read or write sepecific bytes


ex:


 


&HF7, &HD8, &H1B, &HC0, &H40, &H89, &H45, &HE0


 


i want to change  &H1B to &H33 and &H40 to &H90 but skip other byte


 


( Skip(HF7),Skip(HD8), patch(H1B),Skip(HC0), Patch(H40), skip skip skip) like in uPPP


 


search : F7 D8 1B C0 40 89 45 E0


Replace ..     ..  33  ..   90  ..    .. ..



Private Shared ReadOnly PatchFind As Byte() = {&HF7, &HD8, &H1B, &HC0, &H40, &H89, &H45, &HE0}
Private Shared ReadOnly PatchReplace As Byte() = {&HF7, &HD8, &H33, &HC0, &H90, &H89, &H45, &HE0}
<MethodImpl(MethodImplOptions.AggressiveInlining)>
Private Shared Function DetectPatch(sequence As Byte(), position As Integer) As Boolean
If position + PatchFind.Length > sequence.Length Then
Return False
End If
For p As Integer = 0 To PatchFind.Length - 1
If PatchFind(p) <> sequence(position + p) Then
Return False
End If
Next
Return True
End Function Private Shared Sub PatchFile(originalFile As String, patchedFile As String)
' Ensure target directory exists.
Dim targetDirectory = Path.GetDirectoryName(patchedFile)
If targetDirectory Is Nothing Then
Return
End If
Directory.CreateDirectory(targetDirectory) ' Read file bytes.
Dim fileContent As Byte() = File.ReadAllBytes(originalFile) ' Detect and patch file.
For p As Integer = 0 To fileContent.Length - 1
If Not DetectPatch(fileContent, p) Then
Continue For
End If For w As Integer = 0 To PatchFind.Length - 1 fileContent(p + w) = PatchReplace(w)
Next
Next ' Save it to another location.
File.WriteAllBytes(patchedFile, fileContent)
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
PatchFile("C:\App.exe", "C:\App_patch.exe")
End Sub

thx before


 


sorry my english is bad


Edited by andrextrap
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...