Posted February 25, 201510 yr i will make patch with vb.netbut i dont know how read or write sepecific bytesex: &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 E0Replace .. .. 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 Subthx before sorry my english is bad Edited February 25, 201510 yr by andrextrap
Create an account or sign in to comment