@@ -7,20 +7,20 @@ Module Program
77
88 Public Sub Main()
99 Console.ForegroundColor = ConsoleColor.DarkYellow
10- Console .Write(vbLf & " UPX-Patcher (" )
10+ StdOut .Write(vbLf & " UPX-Patcher (" , False )
1111
1212 Console.ForegroundColor = ConsoleColor.DarkCyan
13- Console .Write("https://github.com/DosX-dev/UPX-Patcher" )
13+ StdOut .Write("https://github.com/DosX-dev/UPX-Patcher" , False )
1414
1515 Console.ForegroundColor = ConsoleColor.DarkYellow
16- Console.WriteLine (")" & vbLf)
16+ StdOut.Write (")" & vbLf, True )
1717
1818 Console.ResetColor()
1919
2020 Dim args = Environment.GetCommandLineArgs()
2121
2222 If args.Length = 1 Then
23- Console.WriteLine ("Usage: {0} <file_path>" , AppDomain.CurrentDomain.FriendlyName)
23+ StdOut.Write ("Usage: " & AppDomain.CurrentDomain.FriendlyName & " <file_path>" , True )
2424 Environment.Exit( 0 )
2525 End If
2626
@@ -52,7 +52,7 @@ Module Program
5252 End If
5353
5454
55- Console.WriteLine ("Sections confusing..." )
55+ StdOut.Log ("Sections confusing..." )
5656
5757 bytesReplacer.PatchBytes(fileName, { &H55 , &H50 , ' #0
5858 &H58 , &H30 ,
@@ -69,7 +69,7 @@ Module Program
6969 &H0 },
7070 Encoding.ASCII.GetBytes( ".code" ))
7171
72- Console.WriteLine ("Version block confusing..." )
72+ StdOut.Log ("Version block confusing..." )
7373
7474
7575 Dim offset As Long = bytesReplacer.FindStringOffset(fileName, "UPX!" ) ' version identifier
@@ -104,31 +104,68 @@ Module Program
104104 ''''''''''''''''''''''''''''''''''''''''''''''''
105105
106106
107- Console.WriteLine( "Adding fake version block..." )
107+ ' StdOut.Log("Adding fake version block...")
108+ '
109+ '
110+ ' bytesReplacer.PatchBytes(fileName,
111+ ' {
112+ ' &H0, &H0, &H0, &H0, &H0, &H0, &H0, &H0, &H0, &H0, ' padding
113+ ' &H0, &H0, &H0, &H0, ' 00 00 00 00 -> "DosX"
114+ ' &H0, ' version separator
115+ ' &H0, &H0, &H0, ' 00 00 00 -> "UPX"
116+ ' &H0, ' 00 -> "!"
117+ ' &H0 ' padding
118+ ' }, {
119+ ' &H0, &H0, &H0, &H0, &H0, &H0, &H0, &H0, &H0, &H0, ' padding
120+ ' &H44, &H6F, &H73, &H58, ' "DosX"
121+ ' &H0, ' version separator
122+ ' &H55, &H50, &H58, ' "UPX"
123+ ' &H21, ' "!"
124+ ' &H0 ' padding
125+ ' }
126+ ' )
127+
128+ StdOut.Log( "Replacing standart DOS Stub message..." )
108129
130+ bytesReplacer.PatchBytes(fileName, Encoding.ASCII.GetBytes( "This program cannot be run in DOS mode." ),
131+ Encoding.ASCII.GetBytes( "https://github.com/DosX-dev/UPX-Patcher" ))
109132
110- bytesReplacer.PatchBytes(fileName,
111- {
112- &H0 , &H0 , &H0 , &H0 , &H0 , &H0 , &H0 , &H0 , &H0 , &H0 , ' padding
113- &H0 , &H0 , &H0 , &H0 , ' 00 00 00 00 -> "DosX"
114- &H0 , ' version separator
115- &H0 , &H0 , &H0 , ' 00 00 00 -> "UPX"
116- &H0 , ' 00 -> "!"
117- &H0 ' padding
118- }, {
119- &H0 , &H0 , &H0 , &H0 , &H0 , &H0 , &H0 , &H0 , &H0 , &H0 , ' padding
120- &H44 , &H6F , &H73 , &H58 , ' "DosX"
121- &H0 , ' version separator
122- &H55 , &H50 , &H58 , ' "UPX"
123- &H21 , ' "!"
124- &H0 ' padding
125- }
126- )
133+ StdOut.Log( "WinAPI changing..." )
127134
128- Console.WriteLine( "Replacing standart DOS Stub message..." )
135+ bytesReplacer.PatchBytes(fileName, Encoding.ASCII.GetBytes( "ExitProcess" ), ' function name size is 11 bytes
136+ Encoding.ASCII.GetBytes( "CopyContext" ))
129137
130- bytesReplacer.PatchBytes(fileName, Encoding.ASCII.GetBytes( "This program cannot be run in DOS mode." ),
131- Encoding.ASCII.GetBytes( "https://github.com/DosX-dev/UPX-Patcher" ))
138+ StdOut.Log( "EntryPoint patching..." )
139+
140+ Dim isBuild64 As Boolean = PE.Is64(fileName)
141+
142+ If isBuild64 Then
143+ bytesReplacer.PatchBytes(fileName, ' x86_64
144+ {
145+ &H0 , ' db 0
146+ &H53 , ' pushal
147+ &H56 ' mov esi
148+ },
149+ {
150+ &H0 , ' db 0
151+ &H55 , ' push ebp
152+ &H56 ' mov esi
153+ }
154+ )
155+ Else
156+ bytesReplacer.PatchBytes(fileName, ' i386
157+ {
158+ &H0 , ' db 0
159+ &H60 , ' pushal
160+ &HBE ' mov esi
161+ },
162+ {
163+ &H0 , ' db 0
164+ &H55 , ' push ebp
165+ &HBE ' mov esi
166+ }
167+ )
168+ End If
132169
133170 Catch ex As Exception
134171 Console.ForegroundColor = ConsoleColor.Red
@@ -137,8 +174,7 @@ Module Program
137174 Environment.Exit( 1 )
138175 End Try
139176
140- Console.WriteLine( "Done !")
177+ StdOut.Log( "Successfully patched !")
141178 End If
142179 End Sub
143-
144180End Module
0 commit comments