@@ -7,20 +7,20 @@ Module Program
7
7
8
8
Public Sub Main()
9
9
Console.ForegroundColor = ConsoleColor.DarkYellow
10
- Console .Write(vbLf & " UPX-Patcher (" )
10
+ StdOut .Write(vbLf & " UPX-Patcher (" , False )
11
11
12
12
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 )
14
14
15
15
Console.ForegroundColor = ConsoleColor.DarkYellow
16
- Console.WriteLine (")" & vbLf)
16
+ StdOut.Write (")" & vbLf, True )
17
17
18
18
Console.ResetColor()
19
19
20
20
Dim args = Environment.GetCommandLineArgs()
21
21
22
22
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 )
24
24
Environment.Exit( 0 )
25
25
End If
26
26
@@ -52,7 +52,7 @@ Module Program
52
52
End If
53
53
54
54
55
- Console.WriteLine ("Sections confusing..." )
55
+ StdOut.Log ("Sections confusing..." )
56
56
57
57
bytesReplacer.PatchBytes(fileName, { &H55 , &H50 , ' #0
58
58
&H58 , &H30 ,
@@ -69,7 +69,7 @@ Module Program
69
69
&H0 },
70
70
Encoding.ASCII.GetBytes( ".code" ))
71
71
72
- Console.WriteLine ("Version block confusing..." )
72
+ StdOut.Log ("Version block confusing..." )
73
73
74
74
75
75
Dim offset As Long = bytesReplacer.FindStringOffset(fileName, "UPX!" ) ' version identifier
@@ -104,31 +104,68 @@ Module Program
104
104
''''''''''''''''''''''''''''''''''''''''''''''''
105
105
106
106
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..." )
108
129
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" ))
109
132
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..." )
127
134
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" ))
129
137
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
132
169
133
170
Catch ex As Exception
134
171
Console.ForegroundColor = ConsoleColor.Red
@@ -137,8 +174,7 @@ Module Program
137
174
Environment.Exit( 1 )
138
175
End Try
139
176
140
- Console.WriteLine( "Done !")
177
+ StdOut.Log( "Successfully patched !")
141
178
End If
142
179
End Sub
143
-
144
180
End Module
0 commit comments