1- Imports System.Security.Cryptography
2- Imports System.Text
3- Imports System.IO
1+ Imports System.IO
42
53Public Class Form1
64
7- Private VALID_CRC As New Dictionary( Of String , Integer )
5+ Private Const PATTERN As String = "85 C0 75 ? ? 0D 03 15 86"
86
97 Private Sub CreateBackup( ByVal path As String )
10-
11- Dim pathOnly As String = System.IO.Path.GetDirectoryName(path)
12-
13- File.Delete(pathOnly + "\ImagingEngine.dll.bak" )
14- File.Copy(path, pathOnly + "\ImagingEngine.dll.bak" )
15-
8+ File.Copy(path, $"{System.IO.Path.GetDirectoryName(path)}\ImagingEngine.dll.bak" , True )
169 End Sub
1710
1811 Private Sub PatchFile( ByVal path As String , ByVal offset As Integer )
1912
2013 CreateBackup(path)
2114
22- Dim sr As FileStream = New FileStream(path, FileMode.Open, FileAccess.ReadWrite)
23- sr.Seek(offset, SeekOrigin.Begin)
24-
25- Dim currentByte As Byte = sr.ReadByte()
26- If currentByte = &H75 Then
27- sr.Seek(offset, SeekOrigin.Begin)
28- sr.WriteByte( &HEB )
29- Else
30- MsgBox( "Invalid byte at offset, unsupported dll version?" )
31- Environment.Exit( 1 )
32- End If
33- sr.Close()
34-
35- End Sub
36-
37- ' --- INIT ---
38-
39- Private Sub Form1_Load(sender As Object , e As EventArgs) Handles MyBase .Load
40- ' Init dictionaries
41-
42- ' --- Windows 10 Pro Version 1903 Build 18362.356 ---
43-
44- ' x86
45- VALID_CRC.Add( "3F43D403517A4889856CFFAC7AB579545E9FFE0F022F3BF0262890EC4EC269EF" , &HC93DE )
46- ' x64
47- VALID_CRC.Add( "A532AE68CCC53DFDC190BB447AE9175A86C072DD99A374151F1D23EDABFCC1A2" , &H9E56D )
48-
49- ' --- Windows 10 Version 22H2 Build 19045.2486 ---
50-
51- ' x86
52- VALID_CRC.Add( "1160360F25D5D1E263C7EADF03240B251B1DCB4263CB2AFCF431619A08346D0E" , &HC88AD )
53- ' x64
54- VALID_CRC.Add( "994476041A9AF3E546706B016A8890B7830FD94FF9C766DD18FF36530E456987" , &HA07DC )
55-
56- ' --- Windows 7 Enterprise Version 6.1.7601 Service Pack 1 Build 7601 ---
57-
58- ' x86
59- VALID_CRC.Add( "F732F0530A7FFD6C67FF774760174B8E01377DC1085942215870C85235F11C61" , &HCAA9E )
15+ Using fs As New FileStream(path, FileMode.Open, FileAccess.ReadWrite)
16+ fs.Seek(offset, SeekOrigin.Begin)
6017
61- ' --- Windows 11 Pro 10.0.22000 build 22000 ---
62-
63- ' x64
64- VALID_CRC.Add( "5176E7C7AD8C8C62D4B78C3300067758DA380EF85CED7DF150B50BB4DD981A84" , &HC4D17 )
65- ' x86
66- VALID_CRC.Add( "806BD2FF9DDBE08E1E230FE4CA048312CEB88ACF0EEEDF3597938014FA496D48" , &HCCAA0 )
67-
68-
69-
70- End Sub
71-
72- ' --- UTILS ---
73- Private Function BytesToHexString( ByVal bytes_Input As Byte ()) As String
74-
75- ' https://social.msdn.microsoft.com/Forums/vstudio/en-US/fa53ce74-fd53-4d2a-bc05-619Fb9d32481/convert-Byte-array-To-hex-String?forum=vbgeneral
76-
77- Dim strTemp As New StringBuilder(bytes_Input.Length * 2 )
78-
79- For Each b As Byte In bytes_Input
80-
81- ' HACK: My calculated hash has zeros in front of single digits
82- Dim hexTMP As String = Conversion.Hex(b)
83- If hexTMP.Length = 1 Then
84- hexTMP = "0" + hexTMP
18+ If fs.ReadByte() = &H75 Then
19+ fs.Seek(offset, SeekOrigin.Begin)
20+ fs.WriteByte( &HEB )
21+ Else
22+ MsgBox( "Invalid byte at offset, unsupported dll version?" )
23+ Environment.Exit( 1 )
8524 End If
25+ End Using
8626
87- strTemp.Append(hexTMP)
88- Next
89-
90- Return strTemp.ToString()
91-
92- End Function
93-
94- Private Function GetOffset( ByVal path As String )
95-
96- Dim sha256 As SHA256 = SHA256Managed.Create()
97- Dim fileStream As Stream = New StreamReader(path).BaseStream
98- Dim hash As Byte () = sha256.ComputeHash(fileStream)
99- Dim hexString As String = BytesToHexString(hash)
100-
101- fileStream.Close()
102-
103- If VALID_CRC.Keys.Contains(hexString) Then
104- Return VALID_CRC(hexString)
105- Else
106- Return Nothing
107- End If
108-
109- End Function
27+ End Sub
11028
11129 ' --- EVENTS ---
11230
@@ -131,56 +49,45 @@ Public Class Form1
13149 pathToFile = txtPath.Text
13250 End If
13351
134- Dim offset As Integer = GetOffset(pathToFile)
135- If IsNothing(offset) Then
136- If MessageBox.Show( "Unknown ImagingEngine.dll version, do you want to try anyway?" , "" , MessageBoxButtons.YesNo, MessageBoxIcon.Question) = DialogResult.No Then
137- Environment.Exit( 1 )
138- Else
139- PatchFile(pathToFile, offset)
140- End If
141- Else
142- PatchFile(pathToFile, offset)
143- End If
52+ Dim j As Integer , firstFound As Integer = 0
53+ Dim patternSplit As String () = PATTERN.Split( " " )
14454
145- MsgBox( "Done." )
146-
147- End Sub
55+ Dim fileBytes As Byte () = File.ReadAllBytes(pathToFile)
56+ For i = 0 To fileBytes.Count - 1 Step 1
14857
149- Private Sub btnPatchSigScan_Click(sender As Object , e As EventArgs) Handles btnPatchSigScan.Click
58+ If patternSplit(j) = "?" Then
59+ j += 1
60+ If firstFound = 0 Then
61+ firstFound = i
62+ End If
63+ Continue For
64+ End If
15065
151- Dim pathToFile As String = ""
152- Dim pathToFileSig As String = ""
66+ If fileBytes(i) = CByte ( $"&H{patternSplit(j)}" ) Then
67+ j += 1
68+ If firstFound = 0 Then
69+ firstFound = i
70+ End If
71+ Else
72+ firstFound = 0
73+ j = 0
74+ End If
15375
154- If txtPathSigScanner.Text = "" Then
155- MsgBox( "Please insert path for SigScanner.exe or Browse. Usually under ""Program files\Windows PhotoViewer""" )
156- Environment.Exit( 1 )
157- Else
158- pathToFileSig = txtPathSigScanner.Text
159- End If
76+ If j >= patternSplit.Count Then
77+ Exit For
78+ End If
79+ Next
16080
161- If txtPath.Text = "" Then
162- MsgBox( "Please insert path for ImagingEngine.dll or Browse. Usually under ""Program files\Windows PhotoViewer""" )
163- Environment.Exit( 1 )
81+ If firstFound > 0 Then
82+ PatchFile(pathToFile, (firstFound + &H2 ) )
83+ MsgBox( "Done" )
16484 Else
165- pathToFile = txtPath.Text
85+ MsgBox( "Could not find byte to patch. Already patched?" )
86+ Return
16687 End If
16788
168- Dim p As New Process()
169- p.StartInfo.FileName = pathToFileSig
170- p.StartInfo.Arguments = pathToFile + " " + pathToFile.Replace( "ImagingEngine.dll" , "ImagingEngine.dll.bak" )
171- p.Start()
172-
17389 End Sub
17490
175- Private Sub btnBrowseSig_Click(sender As Object , e As EventArgs) Handles btnBrowseSig.Click
176-
177- Dim a As New OpenFileDialog() With {.Filter = "SigScanner executable|SigScanner.exe" }
178-
179- If a.ShowDialog() = DialogResult.OK Then
180- txtPathSigScanner.Text = a.FileName
181- End If
182-
183- End Sub
18491End Class
18592
18693
0 commit comments