-
Notifications
You must be signed in to change notification settings - Fork 0
/
CustomColoursPatch.asm
301 lines (227 loc) · 6.82 KB
/
CustomColoursPatch.asm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
alloc(newmem0,2048)
label(returnhere0)
label(originalcode0)
label(exit0)
alloc(newmem1,2048)
label(returnhere1)
label(originalcode1)
label(exit1)
// --------------------------------------------------------------
// Code to choose between custom colours and legacy colours
// --------------------------------------------------------------
newmem0:
pushad
mov cl, byte ptr [ebx]
cmp cl, 'c'
je enableCustomColours
jmp disableCustomColours
enableCustomColours:
mov dword ptr [shouldUseCustomColours], 1
jmp doneSettingCustomColours
disableCustomColours:
mov dword ptr [shouldUseCustomColours], 0
doneSettingCustomColours:
popad
originalcode0:
push ebx
call "THUGPro.exe"+20E0
exit0:
jmp returnhere0
// --------------------------------------------------------------
// Code to set the colour
// --------------------------------------------------------------
newmem1:
pushad
sub ebx, 2
mov eax, [shouldUseCustomColours]
cmp eax, 0
je dontUseCustomColours
xor eax, eax
mov al, byte ptr [ebx+1] // Use legacy colours if end of string is reached
cmp al, 0
je dontUseCustomColours
mov al, byte ptr [ebx+2]
push eax
call _isValidDigit
test eax, eax
jz dontUseCustomColours
mov al, byte ptr [ebx+3]
push eax
call _isValidDigit
test eax, eax
jz dontUseCustomColours
mov al, byte ptr [ebx+4]
push eax
call _isValidDigit
test eax, eax
jz dontUseCustomColours
mov al, byte ptr [ebx+5]
push eax
call _isValidDigit
test eax, eax
jz dontUseCustomColours
jmp useCustomColours
dontUseCustomColours:
popad
jmp originalcode1
useCustomColours:
sub ebx, 1
push ebx
call _customColourTextToInt
mov dword ptr [customColour], eax
popad
// Original block of code from exe with slight modifications
mov edx, dword ptr [edi+14]
mov eax, dword ptr [edx+eax*4+134]
mov ecx, eax
shr ecx, 10
mov edx, eax
movzx ecx, cl
and edx, ff
shl edx, 10
mov [esp+6c], eax
or ecx, edx
and eax, FF00FF00
or ecx, eax
mov ecx, dword ptr [customColour] // <-- injected this line to load the custom colour
mov dword ptr [esp+58], ecx
add ebx, 4 // <-- injected this line to skip past the colour digits (so they don't render)
jmp 004CFFFA
shouldUseCustomColours:
dd 0
customColour:
dd 12345678
originalcode1:
mov edx,[edi+14]
mov eax,[edx+eax*4+134]
exit1:
jmp returnhere1
// --------------------------------------------------------------
// Untested functions
// --------------------------------------------------------------
_isValidDigit:
push ebp
mov ebp, esp
mov ecx, [ebp+8] // ecx = character
cmp ecx, 30 // ecx < '0': invalid
jl digitIsInvalid
cmp ecx, 39 // ecx <= '9': valid (decimal)
jle digitIsValid
cmp ecx, 41 // ecx < 'A': invalid
jl digitIsInvalid
cmp ecx, 46 // ecx <= 'F': valid (uppercase hex)
jle digitIsValid
cmp ecx, 61 // ecx < 'a': invalid
jl digitIsInvalid
cmp ecx, 66 // ecx <= 'f': valid (lowercase hex)
jle digitIsValid
jmp digitIsInvalid // else : invalid
digitIsValid:
mov eax, 1
jmp doneCheckingValidity
digitIsInvalid:
mov eax, 0
jmp doneCheckingValidity
doneCheckingValidity:
pop ebp
ret 4
// --------------------------------------------------------------
// Unit tested functions
// --------------------------------------------------------------
_customColourTextToInt:
push ebp
mov ebp, esp
sub esp, 10
mov dword ptr [ebp-4], 0 // int red
mov dword ptr [ebp-8], 0 // int green
mov dword ptr [ebp-C], 0 // int blue
mov dword ptr [ebp-10], 0 // int alpha
mov ecx, [ebp+8] // ecx = text
xor ebx, ebx // get red byte...
mov bl, byte ptr [ecx+3]
push ebx
call _colourDigitToByte
mov dword ptr [ebp-4], eax
xor ebx, ebx // get green byte...
mov bl, byte ptr [ecx+4]
push ebx
call _colourDigitToByte
mov dword ptr [ebp-8], eax
xor ebx, ebx // get blue byte...
mov bl, byte ptr [ecx+5]
push ebx
call _colourDigitToByte
mov dword ptr [ebp-C], eax
xor ebx, ebx // get alpha byte...
mov bl, byte ptr [ecx+6]
push ebx
call _colourDigitToByte
mov dword ptr [ebp-10], eax
mov eax, dword ptr [ebp-10] // argb = alpha
mov ebx, eax // t = argb
shl ebx, 8 // t <<= 8
add ebx, dword ptr [ebp-4] // t += red
mov eax, ebx // argb = t
mov ebx, eax // t = argb
shl ebx, 8 // t <<= 8
add ebx, dword ptr [ebp-8] // t += green
mov eax, ebx // argb = t
mov ebx, eax // t = argb
shl ebx, 8 // t <<= 8
add ebx, dword ptr [ebp-C] // t += blue
mov eax, ebx // argb = t
add esp, 10
pop ebp
ret 4
_colourDigitToByte:
push ebp
mov ebp, esp
sub esp, C
mov dword ptr [ebp-4], 0xF // int maxTypedValue = 0xF
mov dword ptr [ebp-8], 0xFF // int maxEncodedValue = 0xFF
mov dword ptr [ebp-C], 0 // DWORD temp
mov ebx, dword ptr [ebp+8] // char ebx = typedValue
cmp ebx, 61 // if (ebx >= 'a') {
jge isLowerCaseHex // treat as lowercase hex
cmp ebx, 41 // } else if (ebx >= 'A') {
jge isUpperCaseHex // treat as uppercase hex
// } else {
jmp isDecimal // treat as decimal
// }
isLowerCaseHex:
sub ebx, 61 // ebx = 10 + (ebx - 'a')
add ebx, A
jmp doneConvertingFromAscii
isUpperCaseHex:
sub ebx, 41 // ebx = 10 + (ebx - 'A')
add ebx, A
jmp doneConvertingFromAscii
isDecimal:
sub ebx, 30 // ebx = ebx - '0'
jmp doneConvertingFromAscii
doneConvertingFromAscii:
mov dword ptr [ebp+8], ebx
finit
fild dword ptr [ebp+8] // fpu <- typedValue
fidiv dword ptr [ebp-4] // st(0) /= maxTypedValue
fimul dword ptr [ebp-8] // st(0) *= maxEncodedValue
fisttp dword ptr [ebp-C] // fpu -> temp
mov eax, dword ptr [ebp-C] // return temp
add esp, C
pop ebp
ret 4
// --------------------------------------------------------------
// Code Injection Points
// --------------------------------------------------------------
"THUGPro.exe"+CFE68:
jmp newmem0
nop
returnhere0:
"THUGPro.exe"+CFE7D:
jmp newmem1
nop
nop
nop
nop
nop
returnhere1: