| 1 |
;# Copyright (c) 2008 Thomas Gaugler <[email protected]> |
| 2 |
;# Copyright (c) 2008-2026 NSIS Contributors |
| 3 |
;# |
| 4 |
;# Permission is hereby granted, free of charge, to any person |
| 5 |
;# obtaining a copy of this software and associated documentation |
| 6 |
;# files (the "Software"), to deal in the Software without |
| 7 |
;# restriction, including without limitation the rights to use, |
| 8 |
;# copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 9 |
;# copies of the Software, and to permit persons to whom the |
| 10 |
;# Software is furnished to do so, subject to the following |
| 11 |
;# conditions: |
| 12 |
;# |
| 13 |
;# The above copyright notice and this permission notice shall be |
| 14 |
;# included in all copies or substantial portions of the Software. |
| 15 |
;# |
| 16 |
;# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
| 17 |
;# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES |
| 18 |
;# OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
| 19 |
;# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT |
| 20 |
;# HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, |
| 21 |
;# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
| 22 |
;# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
| 23 |
;# OTHER DEALINGS IN THE SOFTWARE. |
| 24 |
;# |
| 25 |
;# |
| 26 |
;# Implementation of the functions CallProc, RealCallBack and |
| 27 |
;# CallBack of the System plugin in pure x86 assembly. |
| 28 |
;# |
| 29 |
;# This is a hybrid assembly source file supporting both the |
| 30 |
;# MASM as well as the GNU assembler in one file. |
| 31 |
;# |
| 32 |
;# |
| 33 |
;# MASM: |
| 34 |
;# ml.exe /c /nologo /Fo"call.obj" /W3 /Zi /errorReport:prompt /Ta"call.S" |
| 35 |
;# |
| 36 |
;# For enabling debug support use: |
| 37 |
;# ml.exe /c /nologo /D"SYSTEM_LOG_DEBUG" /Fo"call.obj" /W3 /Zi /errorReport:prompt /Ta"call.S" |
| 38 |
;# |
| 39 |
;# GNU toolchain: |
| 40 |
;# gcc -x assembler-with-cpp -s call.S -c |
| 41 |
;# |
| 42 |
;# For enabling debug support use: |
| 43 |
;# gcc -x assembler-with-cpp -DSYSTEM_LOG_DEBUG -s call.S -c |
| 44 |
;# |
| 45 |
;# |
| 46 |
|
| 47 |
; .if 0 |
| 48 |
;# MASM specific block |
| 49 |
.386 |
| 50 |
.model flat |
| 51 |
OPTION casemap:none |
| 52 |
;# SYSCALL is identical to the C calling convention, |
| 53 |
;# but does not add an underscore prefix to symbols. |
| 54 |
OPTION language:syscall |
| 55 |
|
| 56 |
SECTION_DATA equ .data |
| 57 |
SECTION_CODE equ .code |
| 58 |
|
| 59 |
DATA_SUFFIX equ |
| 60 |
|
| 61 |
ASCII equ DB |
| 62 |
|
| 63 |
TEMP_LABEL equ @@ |
| 64 |
TEMP_LABEL_AHEAD equ @f |
| 65 |
TEMP_LABEL_BACK equ @b |
| 66 |
|
| 67 |
MACRO_DECL equ |
| 68 |
|
| 69 |
FUNC_DECL MACRO name |
| 70 |
name PROC |
| 71 |
ENDM |
| 72 |
|
| 73 |
FUNC_END MACRO name |
| 74 |
name ENDP |
| 75 |
ENDM |
| 76 |
|
| 77 |
;# end of MASM specific block |
| 78 |
IF 0 |
| 79 |
; .else |
| 80 |
;# GNU toolchain specific block |
| 81 |
.intel_syntax noprefix |
| 82 |
.set __GNU__,1 |
| 83 |
|
| 84 |
#ifdef SYSTEM_LOG_DEBUG |
| 85 |
;# Disable further proprocessing of SYSTEM_LOG_DEBUG |
| 86 |
;# and hand it over to the GNU assembler |
| 87 |
#undef SYSTEM_LOG_DEBUG |
| 88 |
.set SYSTEM_LOG_DEBUG,1 |
| 89 |
#endif |
| 90 |
|
| 91 |
#ifdef _UNICODE |
| 92 |
#undef _UNICODE |
| 93 |
.set _UNICODE,1 |
| 94 |
#endif |
| 95 |
|
| 96 |
#define IFDEF .ifdef |
| 97 |
#define ELSE .else |
| 98 |
#define ENDIF .endif |
| 99 |
|
| 100 |
#define EXTERN .extern |
| 101 |
|
| 102 |
#define SECTION_DATA .data |
| 103 |
#define SECTION_CODE .text |
| 104 |
|
| 105 |
#define DATA_SUFFIX : |
| 106 |
#define BYTE .byte |
| 107 |
#define DWORD .int |
| 108 |
#define WORD .word |
| 109 |
#define ASCII .ascii |
| 110 |
|
| 111 |
#define MACRO_DECL .macro |
| 112 |
#define MACRO |
| 113 |
#define ENDM .endm |
| 114 |
|
| 115 |
#define TEMP_LABEL 1 |
| 116 |
#define TEMP_LABEL_AHEAD 1f |
| 117 |
#define TEMP_LABEL_BACK 1b |
| 118 |
|
| 119 |
.macro FUNC_DECL name |
| 120 |
.global \name |
| 121 |
.func \name |
| 122 |
\name: |
| 123 |
.endm |
| 124 |
|
| 125 |
.macro FUNC_END name |
| 126 |
.endfunc |
| 127 |
.endm |
| 128 |
|
| 129 |
;# /* |
| 130 |
;# http://gcc.gnu.org/ml/gcc/2006-11/msg00081.html |
| 131 |
;# _alloca_probe <=> _chkstk <=> _alloca (in libgcc) |
| 132 |
;# */ |
| 133 |
|
| 134 |
#define __alloca_probe __alloca |
| 135 |
|
| 136 |
#define END .end |
| 137 |
|
| 138 |
;# end of GNU toolchain specific block |
| 139 |
ENDIF |
| 140 |
|
| 141 |
IFDEF SYSTEM_LOG_DEBUG |
| 142 |
EXTERN _WriteToLog : PROC |
| 143 |
EXTERN _syslogbuf : DWORD |
| 144 |
ENDIF |
| 145 |
|
| 146 |
EXTERN __alloca_probe : PROC |
| 147 |
|
| 148 |
EXTERN __imp__GlobalFree@4 : PROC |
| 149 |
|
| 150 |
IFDEF _UNICODE |
| 151 |
EXTERN __imp__wsprintfW : PROC |
| 152 |
ELSE |
| 153 |
EXTERN __imp__wsprintfA : PROC |
| 154 |
ENDIF |
| 155 |
|
| 156 |
EXTERN _GlobalCopy : PROC |
| 157 |
|
| 158 |
EXTERN _LastStackPlace : DWORD |
| 159 |
EXTERN _LastStackReal : DWORD |
| 160 |
EXTERN _LastProc : DWORD |
| 161 |
EXTERN _CallbackIndex : DWORD |
| 162 |
|
| 163 |
EXTERN _retexpr : DWORD |
| 164 |
EXTERN _retaddr : PTR |
| 165 |
|
| 166 |
EXTERN _GetNewStackSize : PROC |
| 167 |
EXTERN _GetGenStackOption : PROC |
| 168 |
EXTERN _GetCDeclOption : PROC |
| 169 |
EXTERN _GetProcOffset : PROC |
| 170 |
EXTERN _GetCloneOffset : PROC |
| 171 |
EXTERN _GetProcNameOffset : PROC |
| 172 |
EXTERN _GetArgsSizeOffset : PROC |
| 173 |
EXTERN _GetParamCount : PROC |
| 174 |
EXTERN _GetParamsOffset : PROC |
| 175 |
EXTERN _GetSizeOfProcParam : PROC |
| 176 |
EXTERN _GetSizeOffsetParam : PROC |
| 177 |
EXTERN _GetValueOffsetParam : PROC |
| 178 |
EXTERN _Get_valueOffsetParam : PROC |
| 179 |
EXTERN _SetCloneOption : PROC |
| 180 |
EXTERN _SetCallProcResultValues@12 : PROC |
| 181 |
EXTERN _SetProcResultCallback : PROC |
| 182 |
|
| 183 |
SECTION_DATA |
| 184 |
|
| 185 |
;# Low double word of result |
| 186 |
_z1 DATA_SUFFIX DWORD 0 |
| 187 |
|
| 188 |
;# High double word of result |
| 189 |
_z2 DATA_SUFFIX DWORD 0 |
| 190 |
|
| 191 |
IFDEF SYSTEM_LOG_DEBUG |
| 192 |
|
| 193 |
IFDEF _UNICODE |
| 194 |
LogStack DATA_SUFFIX |
| 195 |
BYTE '%', 0, 's', 0, ' ', 0, ' ', 0, 'E', 0, 'S', 0, 'P', 0, ' ', 0 |
| 196 |
BYTE ' ', 0, '0', 0, 'x', 0, '%', 0, '0', 0, '8', 0, 'X', 0, ' ', 0 |
| 197 |
BYTE 'S', 0, 't', 0, 'a', 0, 'c', 0, 'k', 0, ' ', 0, '=', 0, ' ', 0 |
| 198 |
BYTE 'x', 0, '%', 0, '0', 0, '8', 0, 'X', 0, ' ', 0, ' ', 0, 'R', 0 |
| 199 |
BYTE 'a', 0, 'l', 0, ' ', 0, '=', 0, ' ', 0, '0', 0, 'x', 0, '%', 0 |
| 200 |
BYTE '8', 0, 'X', 0 |
| 201 |
WORD 0 |
| 202 |
|
| 203 |
LogCall DATA_SUFFIX WORD 9,9 |
| 204 |
BYTE 'C', 0, 'a', 0, 'l', 0, 'l', 0, ':', 0 |
| 205 |
WORD 10,0 |
| 206 |
|
| 207 |
LogBeforeCall DATA_SUFFIX WORD 9,9,9 |
| 208 |
BYTE 'B', 0, 'e', 0, 'f', 0, 'o', 0, 'r', 0, 'e', 0, ' ', 0, 'c', 0 |
| 209 |
BYTE 'l', 0, 'l', 0, ' ', 0, ' ', 0, ' ', 0, ' ', 0, ' ', 0, ' ', 0 |
| 210 |
BYTE ' ', 0 |
| 211 |
WORD 0 |
| 212 |
|
| 213 |
LogNearCall DATA_SUFFIX WORD 10,9,9,9 |
| 214 |
BYTE 'N', 0, 'e', 0, 'a', 0, 'r', 0, ' ', 0, 'c', 0, 'a', 0, 'l', 0 |
| 215 |
BYTE ' ', 0, ' ', 0, ' ', 0, ' ', 0, ' ', 0, ' ', 0, ' ', 0, ' ', 0 |
| 216 |
BYTE ' ', 0 |
| 217 |
WORD 0 |
| 218 |
|
| 219 |
LogBackFrom DATA_SUFFIX WORD 9 |
| 220 |
BYTE 'B', 0, 'a', 0, 'c', 0, 'k', 0, ' ', 0, 'f', 0, 'r', 0, 'o', 0 |
| 221 |
BYTE ' ', 0 |
| 222 |
WORD 0 |
| 223 |
|
| 224 |
LogAfterCall DATA_SUFFIX WORD 10,9,9,9 |
| 225 |
BYTE 'A', 0, 'f', 0, 't', 0, 'e', 0, 'r', 0, ' ', 0, 'c', 0, 'a', 0 |
| 226 |
BYTE 'l', 0, ' ', 0, ' ', 0, ' ', 0, ' ', 0, ' ', 0, ' ', 0, ' ', 0 |
| 227 |
BYTE ' ', 0 |
| 228 |
WORD 0 |
| 229 |
|
| 230 |
LogReturnAfter DATA_SUFFIX WORD 10,9,9,9 |
| 231 |
BYTE 'R', 0, 'e', 0, 't', 0, 'u', 0, 'r', 0, 'n', 0, ' ', 0, ' ', 0 |
| 232 |
BYTE ' ', 0, ' ', 0, ' ', 0, ' ', 0, ' ', 0, ' ', 0, ' ', 0, ' ', 0 |
| 233 |
BYTE ' ', 0, ' ', 0, ' ', 0, '0', 0, 'x', 0, '%', 0, '0', 0, '8', 0 |
| 234 |
BYTE ' ', 0, ' ', 0, ' ', 0, ' ', 0, '0', 0, 'x', 0, '%', 0, '0', 0 |
| 235 |
BYTE 'X', 0 |
| 236 |
WORD 0 |
| 237 |
|
| 238 |
LogCalled DATA_SUFFIX |
| 239 |
BYTE 'C', 0, 'a', 0, 'l', 0, 'l', 0, 'e', 0, 'd', 0, ' ', 0, 'c', 0 |
| 240 |
BYTE 'l', 0, 'l', 0, 'b', 0, 'a', 0, 'c', 0, 'k', 0, ' ', 0, 'f', 0 |
| 241 |
BYTE 'o', 0, 'm', 0, ' ', 0 |
| 242 |
WORD 0 |
| 243 |
|
| 244 |
LogShortAfter DATA_SUFFIX WORD 10,9,9,9 |
| 245 |
BYTE 'S', 0, 'h', 0, 'o', 0, 'r', 0, 't', 0, '-', 0, 'A', 0, 'f', 0 |
| 246 |
BYTE 'e', 0, 'r', 0, ' ', 0, 'c', 0, 'a', 0, 'l', 0, 'l', 0, ' ', 0 |
| 247 |
BYTE ' ', 0 |
| 248 |
WORD 0 |
| 249 |
|
| 250 |
LogReturn DATA_SUFFIX WORD 9,9 |
| 251 |
BYTE 'R', 0, 'e', 0, 't', 0, 'u', 0, 'r', 0, 'n', 0, ' ', 0, 'f', 0 |
| 252 |
BYTE 'o', 0, 'm', 0, ' ', 0, 'c', 0, 'a', 0, 'l', 0, 'l', 0, 'b', 0 |
| 253 |
BYTE 'c', 0, 'k', 0, ':', 0 |
| 254 |
WORD 10,0 |
| 255 |
|
| 256 |
LogBefore DATA_SUFFIX WORD 9,9,9 |
| 257 |
BYTE 'B', 0, 'e', 0, 'f', 0, 'o', 0, 'r', 0, 'e', 0, ' ', 0, 'c', 0 |
| 258 |
BYTE 'l', 0, 'l', 0, '-', 0, 'b', 0, 'a', 0, 'c', 0, 'k', 0, ' ', 0 |
| 259 |
BYTE ' ', 0 |
| 260 |
WORD 0 |
| 261 |
|
| 262 |
LogShortBefore DATA_SUFFIX WORD 10,9,9,9 |
| 263 |
BYTE 'S', 0, 'h', 0, '-', 0, 'B', 0, 'e', 0, 'f', 0, 'o', 0, 'r', 0 |
| 264 |
BYTE ' ', 0, 'c', 0, 'a', 0, 'l', 0, 'l', 0, '-', 0, 'b', 0, 'a', 0 |
| 265 |
BYTE 'k', 0 |
| 266 |
WORD 0 |
| 267 |
LogLF DATA_SUFFIX WORD 10,0 |
| 268 |
ELSE |
| 269 |
LogStack DATA_SUFFIX ASCII "%s ESP = 0x%08X Stack = 0x%08X Real = 0x%08X" |
| 270 |
BYTE 0 |
| 271 |
|
| 272 |
LogCall DATA_SUFFIX BYTE 9,9 |
| 273 |
ASCII "Call:" |
| 274 |
BYTE 10,0 |
| 275 |
|
| 276 |
LogBeforeCall DATA_SUFFIX BYTE 9,9,9 |
| 277 |
ASCII "Before call " |
| 278 |
BYTE 0 |
| 279 |
|
| 280 |
LogNearCall DATA_SUFFIX BYTE 10,9,9,9 |
| 281 |
ASCII "Near call " |
| 282 |
BYTE 0 |
| 283 |
|
| 284 |
LogBackFrom DATA_SUFFIX BYTE 9 |
| 285 |
ASCII "Back from " |
| 286 |
BYTE 0 |
| 287 |
|
| 288 |
LogAfterCall DATA_SUFFIX BYTE 10,9,9,9 |
| 289 |
ASCII "After call " |
| 290 |
BYTE 0 |
| 291 |
|
| 292 |
LogReturnAfter DATA_SUFFIX BYTE 10,9,9,9 |
| 293 |
ASCII "Return 0x%08X 0x%08X" |
| 294 |
BYTE 0 |
| 295 |
|
| 296 |
LogCalled DATA_SUFFIX ASCII "Called callback from " |
| 297 |
BYTE 0 |
| 298 |
|
| 299 |
LogShortAfter DATA_SUFFIX BYTE 10,9,9,9 |
| 300 |
ASCII "Short-After call " |
| 301 |
BYTE 0 |
| 302 |
|
| 303 |
LogReturn DATA_SUFFIX BYTE 9,9 |
| 304 |
ASCII "Return from callback:" |
| 305 |
BYTE 10,0 |
| 306 |
|
| 307 |
LogBefore DATA_SUFFIX BYTE 9,9,9 |
| 308 |
ASCII "Before call-back " |
| 309 |
BYTE 0 |
| 310 |
|
| 311 |
LogShortBefore DATA_SUFFIX BYTE 10,9,9,9 |
| 312 |
ASCII "Sh-Before call-back" |
| 313 |
BYTE 0 |
| 314 |
|
| 315 |
LogLF DATA_SUFFIX BYTE 10,0 |
| 316 |
ENDIF |
| 317 |
ENDIF |
| 318 |
|
| 319 |
SECTION_CODE |
| 320 |
|
| 321 |
IFDEF SYSTEM_LOG_DEBUG |
| 322 |
|
| 323 |
;# Sets edi to address of the end of the syslog buffer (terminating zero) |
| 324 |
MACRO_DECL SYSTEM_LOG_INIT MACRO |
| 325 |
mov edi,offset _syslogbuf |
| 326 |
TEMP_LABEL: |
| 327 |
;# End loop if terminating zero of buffer was found otherwise move |
| 328 |
;# to next character and check again |
| 329 |
cmp byte ptr [edi],0 |
| 330 |
je TEMP_LABEL_AHEAD |
| 331 |
inc edi |
| 332 |
jmp TEMP_LABEL_BACK |
| 333 |
TEMP_LABEL: |
| 334 |
ENDM |
| 335 |
|
| 336 |
;# Appends log information and advances edi accordingly. |
| 337 |
;# |
| 338 |
;# edi must point to the address of the log buffer where |
| 339 |
;# the log information should be appended. |
| 340 |
;# |
| 341 |
;# eax returns number of bytes appended to log buffer |
| 342 |
MACRO_DECL SYSTEM_LOG_ADD MACRO arg1,arg2 |
| 343 |
;# Format string |
| 344 |
IFDEF __GNU__ |
| 345 |
push \arg1 \arg2 |
| 346 |
ELSE |
| 347 |
push arg1 arg2 |
| 348 |
ENDIF |
| 349 |
;# Log buffer |
| 350 |
push edi |
| 351 |
IFDEF _UNICODE |
| 352 |
call dword ptr [__imp__wsprintfW] |
| 353 |
ELSE |
| 354 |
call dword ptr [__imp__wsprintfA] |
| 355 |
ENDIF |
| 356 |
;# If wsprintf succeeds then advance edi by number of bytes |
| 357 |
;# written to buffer |
| 358 |
cmp eax,0 |
| 359 |
jl TEMP_LABEL_AHEAD |
| 360 |
add edi,eax |
| 361 |
TEMP_LABEL: |
| 362 |
add esp,8 |
| 363 |
ENDM |
| 364 |
|
| 365 |
;# Writes stackpointer and additional information to log |
| 366 |
;# and advances edi accordingly (terminating zero of buffer). |
| 367 |
;# |
| 368 |
;# edi must point to the address of the log buffer where |
| 369 |
;# the log information should be appended. |
| 370 |
;# |
| 371 |
;# eax returns number of bytes appended to log buffer |
| 372 |
MACRO_DECL SYSTEM_EVENT MACRO arg1,arg2 |
| 373 |
;# Save current stack pointer in eax |
| 374 |
mov eax,esp |
| 375 |
;# Stackpointer information |
| 376 |
push dword ptr [_LastStackReal] |
| 377 |
push dword ptr [_LastStackPlace] |
| 378 |
push eax |
| 379 |
;# Event information |
| 380 |
IFDEF __GNU__ |
| 381 |
push \arg1 \arg2 |
| 382 |
ELSE |
| 383 |
push arg1 arg2 |
| 384 |
ENDIF |
| 385 |
SYSTEM_LOG_ADD offset LogStack |
| 386 |
add esp,16 |
| 387 |
ENDM |
| 388 |
|
| 389 |
;# Flush log information and reset log buffer. |
| 390 |
;# |
| 391 |
;# edi must point to the address of the log buffer where |
| 392 |
;# the log information should be appended. |
| 393 |
;# |
| 394 |
;# eax returns number of bytes appended to log buffer |
| 395 |
MACRO_DECL SYSTEM_LOG_POST MACRO |
| 396 |
;# Append line feed to log information |
| 397 |
SYSTEM_LOG_ADD offset LogLF |
| 398 |
;# Flush log information |
| 399 |
push offset _syslogbuf |
| 400 |
call _WriteToLog |
| 401 |
add esp,4 |
| 402 |
;# Reset log buffer |
| 403 |
mov byte ptr [_syslogbuf],0 |
| 404 |
ENDM |
| 405 |
|
| 406 |
ENDIF |
| 407 |
|
| 408 |
FUNC_DECL _CallProc |
| 409 |
;# Save stack |
| 410 |
push ebp |
| 411 |
mov ebp,esp |
| 412 |
;# Stack space for local variables |
| 413 |
;# ebp-4 = Size of ProcParameter structure |
| 414 |
sub esp,4 |
| 415 |
;# Save all usable registers to free our hands |
| 416 |
push ebx |
| 417 |
push edi |
| 418 |
push esi |
| 419 |
|
| 420 |
IFDEF SYSTEM_LOG_DEBUG |
| 421 |
SYSTEM_LOG_INIT |
| 422 |
SYSTEM_LOG_ADD offset LogCall |
| 423 |
SYSTEM_EVENT offset LogBeforeCall |
| 424 |
ENDIF |
| 425 |
|
| 426 |
;# CallbackIndex != 0 |
| 427 |
cmp dword ptr [_CallbackIndex],0 |
| 428 |
je stack_expand_done |
| 429 |
|
| 430 |
;# proc->Options without POPT_GENSTACK |
| 431 |
push dword ptr [ebp+8] |
| 432 |
call _GetGenStackOption |
| 433 |
cmp eax,0 |
| 434 |
pop eax |
| 435 |
jne stack_expand_done |
| 436 |
|
| 437 |
;# Save previous stack location |
| 438 |
push ebp |
| 439 |
mov dword ptr [_LastStackReal],esp |
| 440 |
cmp dword ptr [_LastStackPlace],0 |
| 441 |
jne stack_adjust |
| 442 |
;# Create new stack |
| 443 |
call _GetNewStackSize |
| 444 |
call __alloca_probe |
| 445 |
mov dword ptr [_LastStackPlace],esp |
| 446 |
jmp stack_expand_done |
| 447 |
stack_adjust: |
| 448 |
;# Move stack pointer |
| 449 |
mov esp,dword ptr [_LastStackPlace] |
| 450 |
|
| 451 |
stack_expand_done: |
| 452 |
;# Push arguments to stack |
| 453 |
;# |
| 454 |
;# Get number of parameters |
| 455 |
push dword ptr [ebp+8] |
| 456 |
call _GetParamCount |
| 457 |
add esp,4 |
| 458 |
|
| 459 |
;# Skip if there are no parameters |
| 460 |
cmp eax,0 |
| 461 |
jle params_loop_done |
| 462 |
|
| 463 |
;# Save number of parameters on stack |
| 464 |
push eax |
| 465 |
|
| 466 |
;# Get offset for element Params of SystemProc structure |
| 467 |
call _GetParamsOffset |
| 468 |
add eax,dword ptr [ebp+8] |
| 469 |
push eax |
| 470 |
|
| 471 |
call _GetSizeOfProcParam |
| 472 |
mov dword ptr [ebp-4],eax |
| 473 |
|
| 474 |
;# Calculate offset for the last Parameter |
| 475 |
pop ebx |
| 476 |
pop ecx |
| 477 |
mul ecx |
| 478 |
add ebx,eax |
| 479 |
|
| 480 |
;# Save offset of last parameter on stack |
| 481 |
push ebx |
| 482 |
;# Save number of parameters on stack |
| 483 |
push ecx |
| 484 |
|
| 485 |
;# Size offset of parameter |
| 486 |
call _GetSizeOffsetParam |
| 487 |
push eax |
| 488 |
|
| 489 |
;# Value offset of parameter |
| 490 |
call _GetValueOffsetParam |
| 491 |
push eax |
| 492 |
|
| 493 |
;# _value offset of parameter |
| 494 |
call _Get_valueOffsetParam |
| 495 |
push eax |
| 496 |
|
| 497 |
;# ebx = _value offset |
| 498 |
pop ebx |
| 499 |
;# edx = Value offset |
| 500 |
pop edx |
| 501 |
;# esi = Size offset |
| 502 |
pop esi |
| 503 |
;# ecx = n-th parameter |
| 504 |
pop ecx |
| 505 |
;# eax = offset of current worked on parameter |
| 506 |
pop eax |
| 507 |
|
| 508 |
params_loop: |
| 509 |
;# Check Size of param |
| 510 |
cmp dword ptr [eax+esi],2 |
| 511 |
jne params_default |
| 512 |
|
| 513 |
;# Long type 'L'/'l' (64-bit) |
| 514 |
push dword ptr [eax+ebx] |
| 515 |
|
| 516 |
params_default: |
| 517 |
;# Default for all types |
| 518 |
push dword ptr [eax+edx] |
| 519 |
|
| 520 |
|
| 521 |
;# Continue with next parameter |
| 522 |
sub eax,dword ptr[ebp-4] |
| 523 |
loop params_loop |
| 524 |
|
| 525 |
params_loop_done: |
| 526 |
;# Save proc |
| 527 |
;# proc->Clone |
| 528 |
call _GetCloneOffset |
| 529 |
mov ecx,dword ptr [ebp+8] |
| 530 |
add eax,ecx |
| 531 |
|
| 532 |
;# proc->Clone = LastProc |
| 533 |
mov edx,dword ptr [_LastProc] |
| 534 |
mov dword ptr [eax],edx |
| 535 |
|
| 536 |
;# LastProc = proc |
| 537 |
mov dword ptr [_LastProc],ecx |
| 538 |
|
| 539 |
IFDEF SYSTEM_LOG_DEBUG |
| 540 |
SYSTEM_EVENT offset LogNearCall |
| 541 |
SYSTEM_LOG_POST |
| 542 |
ENDIF |
| 543 |
|
| 544 |
;# Get address of procedure |
| 545 |
call _GetProcOffset |
| 546 |
mov ecx,dword ptr [ebp+8] |
| 547 |
mov ecx,dword ptr [eax+ecx] |
| 548 |
|
| 549 |
;# /* |
| 550 |
;# workaround for bug #1535007 |
| 551 |
;# http://sf.net/tracker/index.php?func=detail&aid=1535007&group_id=22049&atid=373085 |
| 552 |
;# |
| 553 |
;# If a function returns short and doesn't clear eax in the process, |
| 554 |
;# it will only set 2 bytes of eax, and the other 2 bytes remain |
| 555 |
;# "random". In this case, they'll be part of the proc pointer. |
| 556 |
;# |
| 557 |
;# To avoid this, eax is cleared before the function is called. This |
| 558 |
;# makes sure the value eax will contain is only what the function |
| 559 |
;# actually sets. |
| 560 |
;# */ |
| 561 |
xor eax,eax |
| 562 |
|
| 563 |
;# Call |
| 564 |
call ecx |
| 565 |
|
| 566 |
;# Save return |
| 567 |
mov dword ptr [_z1],eax |
| 568 |
mov dword ptr [_z2],edx |
| 569 |
|
| 570 |
IFDEF SYSTEM_LOG_DEBUG |
| 571 |
SYSTEM_LOG_INIT |
| 572 |
SYSTEM_LOG_ADD offset LogBackFrom |
| 573 |
;# LastProc->ProcName |
| 574 |
call _GetProcNameOffset |
| 575 |
mov ecx,dword ptr [_LastProc] |
| 576 |
add eax,ecx |
| 577 |
SYSTEM_LOG_ADD eax |
| 578 |
SYSTEM_EVENT offset LogShortAfter |
| 579 |
ENDIF |
| 580 |
|
| 581 |
cmp dword ptr [_CallbackIndex],0 |
| 582 |
je stack_restore_done |
| 583 |
mov eax,dword ptr [_LastProc] |
| 584 |
push eax |
| 585 |
call _GetGenStackOption |
| 586 |
cmp eax,0 |
| 587 |
pop eax |
| 588 |
jne stack_restore_done |
| 589 |
|
| 590 |
;# Restore real stack location |
| 591 |
mov dword ptr [_LastStackPlace],esp |
| 592 |
mov esp,dword ptr [_LastStackReal] |
| 593 |
pop ebp |
| 594 |
|
| 595 |
stack_restore_done: |
| 596 |
;# Restore proc |
| 597 |
mov edx,dword ptr [_LastProc] |
| 598 |
mov dword ptr [ebp+8],edx |
| 599 |
|
| 600 |
;# proc->Clone |
| 601 |
call _GetCloneOffset |
| 602 |
add eax,edx |
| 603 |
|
| 604 |
;# LastProc = proc->Clone |
| 605 |
mov eax,dword ptr [eax] |
| 606 |
mov dword ptr [_LastProc],eax |
| 607 |
|
| 608 |
;# In case of cdecl convention we should clear stack |
| 609 |
|
| 610 |
;# if ((proc->Options & POPT_CDECL) != 0) |
| 611 |
push edx |
| 612 |
call _GetCDeclOption |
| 613 |
cmp eax,0 |
| 614 |
pop edx |
| 615 |
je stack_clear_done |
| 616 |
|
| 617 |
;# Get number of parameters |
| 618 |
push edx |
| 619 |
call _GetParamCount |
| 620 |
add esp,4 |
| 621 |
|
| 622 |
;# Skip if there are no parameters |
| 623 |
cmp eax,0 |
| 624 |
jle stack_clear_done |
| 625 |
|
| 626 |
;# Save number of parameters on stack |
| 627 |
push eax |
| 628 |
|
| 629 |
;# Get offset for element Params of SystemProc structure |
| 630 |
call _GetParamsOffset |
| 631 |
add eax,dword ptr [ebp+8] |
| 632 |
|
| 633 |
;# Calculate offset for the Parameter 1 |
| 634 |
add eax,dword ptr [ebp-4] |
| 635 |
|
| 636 |
;# Save offset for the Parameter 1 on stack |
| 637 |
push eax |
| 638 |
|
| 639 |
;# Size offset of parameter |
| 640 |
call _GetSizeOffsetParam |
| 641 |
push eax |
| 642 |
|
| 643 |
;# if ((CallbackIndex > 0) && ((proc->Options & POPT_GENSTACK) == 0)) |
| 644 |
cmp dword ptr [_CallbackIndex],0 |
| 645 |
jle real_stack_cleanup |
| 646 |
push dword ptr [ebp+8] |
| 647 |
call _GetGenStackOption |
| 648 |
cmp eax,0 |
| 649 |
pop eax |
| 650 |
jne real_stack_cleanup |
| 651 |
|
| 652 |
;# In case of temporary stack |
| 653 |
;# |
| 654 |
;# esi = Size offset |
| 655 |
pop esi |
| 656 |
;# eax = offset of current worked on parameter |
| 657 |
pop eax |
| 658 |
;# ecx = n-th parameter |
| 659 |
pop ecx |
| 660 |
|
| 661 |
temp_stack_loop: |
| 662 |
;# LastStackPlace += 4* Size of current parameter; |
| 663 |
mov edx,dword ptr [eax+esi] |
| 664 |
mov ebx,dword ptr [_LastStackPlace] |
| 665 |
lea edx,[ebx+edx*4] |
| 666 |
mov dword ptr [_LastStackPlace],edx |
| 667 |
|
| 668 |
;# Go to next |
| 669 |
add eax,dword ptr [ebp-4] |
| 670 |
loop temp_stack_loop |
| 671 |
|
| 672 |
;# End of stack cleanup |
| 673 |
jmp stack_clear_done |
| 674 |
|
| 675 |
real_stack_cleanup: |
| 676 |
;# In case of real stack |
| 677 |
;# |
| 678 |
;# esi = Size offset |
| 679 |
pop esi |
| 680 |
;# eax = offset of current worked on parameter |
| 681 |
pop eax |
| 682 |
;# ecx = Number of parameters |
| 683 |
pop ecx |
| 684 |
|
| 685 |
real_stack_loop: |
| 686 |
;# Size of current parameter == 2 |
| 687 |
cmp dword ptr [eax+esi],2 |
| 688 |
jne real_stack_default |
| 689 |
;# Long type |
| 690 |
pop edx |
| 691 |
|
| 692 |
real_stack_default: |
| 693 |
;# Default |
| 694 |
pop edx |
| 695 |
add eax,dword ptr [ebp-4] |
| 696 |
loop real_stack_loop |
| 697 |
|
| 698 |
stack_clear_done: |
| 699 |
;# In case of cleared call-proc-queue -> clear allocated stack place (more flexible) |
| 700 |
cmp dword ptr [_LastProc],0 |
| 701 |
jne stack_cleanup_done |
| 702 |
mov dword ptr [_LastStackPlace],0 |
| 703 |
|
| 704 |
stack_cleanup_done: |
| 705 |
|
| 706 |
;# Save return |
| 707 |
push dword ptr [_z2] |
| 708 |
push dword ptr [_z1] |
| 709 |
push dword ptr [ebp+8] |
| 710 |
call _SetCallProcResultValues@12 |
| 711 |
|
| 712 |
IFDEF SYSTEM_LOG_DEBUG |
| 713 |
SYSTEM_EVENT offset LogAfterCall |
| 714 |
|
| 715 |
push dword ptr [_z2] |
| 716 |
push dword ptr [_z1] |
| 717 |
SYSTEM_LOG_ADD offset LogReturnAfter |
| 718 |
add esp,8 |
| 719 |
|
| 720 |
SYSTEM_LOG_POST |
| 721 |
ENDIF |
| 722 |
|
| 723 |
;# Return |
| 724 |
mov eax,dword ptr [ebp+8] |
| 725 |
;# Restore registers |
| 726 |
pop esi |
| 727 |
pop edi |
| 728 |
pop ebx |
| 729 |
;# Restore stack pointer |
| 730 |
mov esp,ebp |
| 731 |
pop ebp |
| 732 |
ret |
| 733 |
FUNC_END _CallProc |
| 734 |
|
| 735 |
|
| 736 |
|
| 737 |
FUNC_DECL _RealCallBack |
| 738 |
;# Save stack |
| 739 |
push ebp |
| 740 |
mov ebp,esp |
| 741 |
|
| 742 |
;# Stack space for local variables |
| 743 |
;# ebp-16 = Size of ProcParameter structure |
| 744 |
;# ebp-12 = ArgsSize |
| 745 |
;# ebp-8 = Arguments pointer |
| 746 |
;# ebp-4 = proc |
| 747 |
sub esp,16 |
| 748 |
|
| 749 |
;# Save all usable registers to free our hands |
| 750 |
push ebx |
| 751 |
push edi |
| 752 |
push esi |
| 753 |
|
| 754 |
;# Arguments pointer |
| 755 |
;# 1-st arg (4 bytes), return (4 bytes) => add 8 bytes |
| 756 |
mov dword ptr [ebp-8],ebp |
| 757 |
add dword ptr [ebp-8],8 |
| 758 |
|
| 759 |
;# Our callback proc is in eax (set by the thunk created in CreateCallback) |
| 760 |
mov dword ptr [ebp-4],eax |
| 761 |
|
| 762 |
IFDEF SYSTEM_LOG_DEBUG |
| 763 |
SYSTEM_LOG_INIT |
| 764 |
SYSTEM_LOG_ADD offset LogCalled |
| 765 |
;# LastProc->ProcName |
| 766 |
call _GetProcNameOffset |
| 767 |
mov ecx,dword ptr [_LastProc] |
| 768 |
add eax,ecx |
| 769 |
SYSTEM_LOG_ADD eax |
| 770 |
SYSTEM_EVENT offset LogShortAfter |
| 771 |
SYSTEM_LOG_POST |
| 772 |
ENDIF |
| 773 |
|
| 774 |
call _GetCloneOffset |
| 775 |
mov edx,eax |
| 776 |
mov ecx,dword ptr [ebp-4] |
| 777 |
|
| 778 |
;# 1. Find last unused clone |
| 779 |
jmp clone_load |
| 780 |
clone_next: |
| 781 |
mov ecx,dword ptr [eax] |
| 782 |
mov dword ptr [ebp-4],ecx |
| 783 |
clone_load: |
| 784 |
lea eax,[ecx+edx] |
| 785 |
cmp dword ptr [eax],0 |
| 786 |
jne clone_next |
| 787 |
|
| 788 |
;# 2. Create new clone |
| 789 |
push edx |
| 790 |
push ecx |
| 791 |
call _GlobalCopy |
| 792 |
pop ecx |
| 793 |
pop edx |
| 794 |
;# proc->Clone = Result of GlobalCopy |
| 795 |
mov ecx,dword ptr [ebp-4] |
| 796 |
mov dword ptr [ecx+edx],eax |
| 797 |
;# proc = proc->Clone |
| 798 |
mov dword ptr [ebp-4],eax |
| 799 |
|
| 800 |
;# 3. Set clone option |
| 801 |
push eax |
| 802 |
call _SetCloneOption |
| 803 |
pop eax |
| 804 |
|
| 805 |
;# proc->ArgsSize = 0 |
| 806 |
mov dword ptr [ebp-12],0 |
| 807 |
|
| 808 |
;# Read Arguments |
| 809 |
|
| 810 |
;# Get number of parameters |
| 811 |
push dword ptr [ebp-4] |
| 812 |
call _GetParamCount |
| 813 |
add esp,4 |
| 814 |
|
| 815 |
;# Skip if there are no parameters |
| 816 |
cmp eax,0 |
| 817 |
jle cb_params_loop_done |
| 818 |
|
| 819 |
;# Save number of parameters on stack |
| 820 |
push eax |
| 821 |
|
| 822 |
;# Get size of ProcParameter structure |
| 823 |
call _GetSizeOfProcParam |
| 824 |
mov dword ptr [ebp-16],eax |
| 825 |
|
| 826 |
;# Get offset for element Params of SystemProc structure |
| 827 |
call _GetParamsOffset |
| 828 |
add eax,dword ptr [ebp-4] |
| 829 |
|
| 830 |
;# Calculate offset for the Parameter 1 |
| 831 |
add eax,dword ptr [ebp-16] |
| 832 |
|
| 833 |
;# Save offset for the Parameter 1 on stack |
| 834 |
push eax |
| 835 |
|
| 836 |
;# Size offset of parameter |
| 837 |
call _GetSizeOffsetParam |
| 838 |
push eax |
| 839 |
|
| 840 |
;# Value offset of parameter |
| 841 |
call _GetValueOffsetParam |
| 842 |
push eax |
| 843 |
|
| 844 |
;# _value offset of parameter |
| 845 |
call _Get_valueOffsetParam |
| 846 |
push eax |
| 847 |
|
| 848 |
;# ebx = _value offset |
| 849 |
pop ebx |
| 850 |
;# edx = Value offset |
| 851 |
pop edx |
| 852 |
;# esi = Size offset |
| 853 |
pop esi |
| 854 |
;# eax = offset of current worked on parameter |
| 855 |
pop eax |
| 856 |
;# ecx = n-th parameter |
| 857 |
pop ecx |
| 858 |
|
| 859 |
cb_params_loop: |
| 860 |
push ecx |
| 861 |
|
| 862 |
;# Default |
| 863 |
mov ecx,dword ptr [ebp-8] |
| 864 |
mov ecx,dword ptr [ecx] |
| 865 |
mov dword ptr [eax+edx],ecx |
| 866 |
;# (Arguments pointer)++ |
| 867 |
add dword ptr [ebp-8],4 |
| 868 |
;# ArgsSize += 4 |
| 869 |
add dword ptr [ebp-12],4 |
| 870 |
|
| 871 |
;# Size of current parameter == 2 |
| 872 |
cmp dword ptr [eax+esi],2 |
| 873 |
jne cb_params_next |
| 874 |
;# Long type |
| 875 |
mov ecx,dword ptr [ebp-8] |
| 876 |
mov ecx,dword ptr [ecx] |
| 877 |
mov dword ptr [eax+ebx],ecx |
| 878 |
;# (Arguments pointer)++ |
| 879 |
add dword ptr [ebp-8],4 |
| 880 |
;# ArgsSize += 4 |
| 881 |
add dword ptr [ebp-12],4 |
| 882 |
|
| 883 |
cb_params_next: |
| 884 |
;# Next parameter |
| 885 |
add eax,dword ptr [ebp-16] |
| 886 |
|
| 887 |
pop ecx |
| 888 |
loop cb_params_loop |
| 889 |
|
| 890 |
cb_params_loop_done: |
| 891 |
;# proc->ArgsSize = ArgsSize |
| 892 |
call _GetArgsSizeOffset |
| 893 |
add eax,dword ptr [ebp-4] |
| 894 |
mov ecx,dword ptr [ebp-12] |
| 895 |
mov dword ptr [eax],ecx |
| 896 |
|
| 897 |
push dword ptr [ebp-4] |
| 898 |
call _SetProcResultCallback |
| 899 |
pop eax |
| 900 |
|
| 901 |
;# Return |
| 902 |
;# eax = proc |
| 903 |
;# Save temporary stack info |
| 904 |
push ebp |
| 905 |
;# Push LastStackPlace |
| 906 |
mov dword ptr [_LastStackPlace],esp |
| 907 |
;# Restore real stack |
| 908 |
mov esp,dword ptr [_LastStackReal] |
| 909 |
;# Pop LastStackReal |
| 910 |
pop ebp |
| 911 |
|
| 912 |
;# Fake return from System::Call |
| 913 |
|
| 914 |
;# Restore registers |
| 915 |
pop esi |
| 916 |
pop edi |
| 917 |
pop ebx |
| 918 |
;# Restore stack pointer |
| 919 |
mov esp,ebp |
| 920 |
pop ebp |
| 921 |
;# Return |
| 922 |
ret |
| 923 |
FUNC_END _RealCallBack |
| 924 |
|
| 925 |
|
| 926 |
|
| 927 |
FUNC_DECL _CallBack |
| 928 |
;# Save stack |
| 929 |
push ebp |
| 930 |
mov ebp,esp |
| 931 |
|
| 932 |
;# Save all usable registers to free our hands |
| 933 |
push ebx |
| 934 |
push edi |
| 935 |
push esi |
| 936 |
|
| 937 |
IFDEF SYSTEM_LOG_DEBUG |
| 938 |
SYSTEM_LOG_INIT |
| 939 |
SYSTEM_LOG_ADD offset LogReturn |
| 940 |
SYSTEM_EVENT offset LogBefore |
| 941 |
SYSTEM_LOG_POST |
| 942 |
ENDIF |
| 943 |
|
| 944 |
;# Get offset for element Params of SystemProc structure |
| 945 |
call _GetParamsOffset |
| 946 |
add eax,dword ptr [ebp+8] |
| 947 |
push eax |
| 948 |
|
| 949 |
;# Value offset |
| 950 |
call _GetValueOffsetParam |
| 951 |
push eax |
| 952 |
|
| 953 |
;# _value offset |
| 954 |
call _Get_valueOffsetParam |
| 955 |
mov edx,eax |
| 956 |
|
| 957 |
;# offset of Value element within SystemProc structure |
| 958 |
pop ecx |
| 959 |
|
| 960 |
;# offset of Params element within SystemProc structure |
| 961 |
pop eax |
| 962 |
|
| 963 |
;# Callback proc result |
| 964 |
push dword ptr [eax+ecx] |
| 965 |
push dword ptr [eax+edx] |
| 966 |
|
| 967 |
;# Adjust return statement |
| 968 |
;# if ((proc->Options & POPT_CDECL) != 0) |
| 969 |
push dword ptr [ebp+8] |
| 970 |
call _GetCDeclOption |
| 971 |
cmp eax,0 |
| 972 |
pop edx |
| 973 |
jne _retexpr_stdcall |
| 974 |
;# retexpr[1] = proc->ArgsSize |
| 975 |
call _GetArgsSizeOffset |
| 976 |
mov ecx,dword ptr [ebp+8] |
| 977 |
mov al,byte ptr [ecx+eax] |
| 978 |
mov byte ptr [_retexpr+1],al |
| 979 |
jmp set_return_addr |
| 980 |
_retexpr_stdcall: |
| 981 |
;# retexpr[1] = 0 |
| 982 |
mov byte ptr [_retexpr+1],0 |
| 983 |
set_return_addr: |
| 984 |
;# Right return statement address |
| 985 |
mov dword ptr [_retaddr],offset _retexpr |
| 986 |
|
| 987 |
;# Remove unneeded callback proc |
| 988 |
push dword ptr [ebp+8] |
| 989 |
call dword ptr [__imp__GlobalFree@4] |
| 990 |
|
| 991 |
;# Prepare return |
| 992 |
;# Callback proc result |
| 993 |
pop edx |
| 994 |
pop eax |
| 995 |
|
| 996 |
;# Restore temporary stack and return |
| 997 |
|
| 998 |
;# Save real stack info |
| 999 |
;# Save previous stack location |
| 1000 |
;# Push _LastStackReal |
| 1001 |
push ebp |
| 1002 |
mov dword ptr [_LastStackReal],esp |
| 1003 |
;# Move stack pointer |
| 1004 |
mov esp,dword ptr [_LastStackPlace] |
| 1005 |
;# Pop _LastStackPlace |
| 1006 |
pop ebp |
| 1007 |
|
| 1008 |
IFDEF SYSTEM_LOG_DEBUG |
| 1009 |
push eax |
| 1010 |
push edx |
| 1011 |
SYSTEM_EVENT offset LogShortBefore |
| 1012 |
SYSTEM_LOG_POST |
| 1013 |
;# Callback proc result |
| 1014 |
pop edx |
| 1015 |
pop eax |
| 1016 |
ENDIF |
| 1017 |
|
| 1018 |
;# Fake return from Callback |
| 1019 |
|
| 1020 |
;# Restore registers |
| 1021 |
pop esi |
| 1022 |
pop edi |
| 1023 |
pop ebx |
| 1024 |
;# Restore stack pointer |
| 1025 |
mov esp,ebp |
| 1026 |
pop ebp |
| 1027 |
;# Return |
| 1028 |
jmp dword ptr [_retaddr] |
| 1029 |
|
| 1030 |
FUNC_END _CallBack |
| 1031 |
|
| 1032 |
END |
| 1033 |
|