All pastes #490074 Raw Edit

Chao7

public text v1 · immutable
·published 2007-05-15 20:44 UTC
rendered paste body

[BITS 32]
[CPU PRESCOTT]
xrLUA_ISZ          equ 0x005CC104
szluaopen_base     equ xrLUA_ISZ +  12; 0x005CC110
szluaopen_package  equ xrLUA_ISZ +  27; 0x005CC11F
szluaopen_table    equ xrLUA_ISZ +  45; 0x005CC131
szluaopen_io       equ xrLUA_ISZ +  61; 0x005CC141
szluaopen_os       equ xrLUA_ISZ +  74; 0x005CC14E
szluaopen_string   equ xrLUA_ISZ +  87; 0x005CC15B
szluaopen_math     equ xrLUA_ISZ + 104; 0x005CC16C
szluaopen_debug    equ xrLUA_ISZ + 119; 0x005CC17B
szluaopen_jit      equ xrLUA_ISZ + 135; 0x005CC18B
szluaopen_coco     equ xrLUA_ISZ + 149; 0x005CC199
szlua_pushcclosure equ xrLUA_ISZ + 164; 0x005CC1A8
szlua_pushstring   equ xrLUA_ISZ + 183; 0x005CC1BB
szlua_call         equ xrLUA_ISZ + 200; 0x005CC1CC

szbase             equ szluaopen_base + 8 ; "base"
sz_                equ szbase + 4 ; ""
szpackage          equ szluaopen_package + 8 ; "package"
sztable            equ szluaopen_table + 8 ; "package"
szio               equ szluaopen_io + 8 ; "package"
szos               equ szluaopen_os + 8 ; "package"
szstring           equ szluaopen_string + 8 ; "package"
szmath             equ szluaopen_math + 8 ; "package"
szdebug            equ szluaopen_debug + 8 ; "package"
szjit              equ szluaopen_jit + 8 ; "package"
szcoco             equ szluaopen_coco + 8 ; "package"

xrLUA_IAT          equ 0x005CC1D5
luaopen_base       equ xrLUA_IAT + ( 4 *  0 ) ; 0x005CC1D5
luaopen_package    equ xrLUA_IAT + ( 4 *  1 ) ; 0x005CC1D9
luaopen_table      equ xrLUA_IAT + ( 4 *  2 ) ; 0x005CC1DD
luaopen_io         equ xrLUA_IAT + ( 4 *  3 ) ; 0x005CC1E1
luaopen_os         equ xrLUA_IAT + ( 4 *  4 ) ; 0x005CC1E5
luaopen_string     equ xrLUA_IAT + ( 4 *  5 ) ; 0x005CC1E9
luaopen_math       equ xrLUA_IAT + ( 4 *  6 ) ; 0x005CC1ED
luaopen_debug      equ xrLUA_IAT + ( 4 *  7 ) ; 0x005CC1F2
luaopen_jit        equ xrLUA_IAT + ( 4 *  8 ) ; 0x005CC1F6
luaopen_coco       equ xrLUA_IAT + ( 4 *  9 ) ; 0x005CC1F9
lua_pushcclosure   equ xrLUA_IAT + ( 4 * 10 ) ; 0x005CC1FD
lua_pushstring     equ xrLUA_IAT + ( 4 * 11 ) ; 0x005CC201
lua_call           equ xrLUA_IAT + ( 4 * 12 ) ; 0x005CC205

luahack_load:

; eax is state ptr
push ebx ; func ptr
push esi ; str ptr
push edx ; edx is relocated base image ptr, becomes state ptr
push edi ; call func

call luahack_eip_offset
luahack_eip_offset:
pop ecx
sub ecx, byte luahack_eip_offset ; get func base

mov ebx, edx
mov esi, edx
mov edi, edx

add ebx, luaopen_base
add esi, szluaopen_base
add edi, lua_pushcclosure

xchg edx, eax ; grab state ptr passed thru eax

; base
add esi, sz_ - szluaopen_base ; 12

add eax, luahack_postreg ; return to after luahack_reg hack
push eax

luahack_reg:
push ebx
push edx
call [ edi ]
add esp, 4*2
push esi
push edx
call [ edi + 4 ]
add esp, 4*2
push dword 0x00000000
push dword 0x00000001
push edx
call [ edi + 8 ]
add esp, 4*3
ret

luahack_postreg:

; package
add esi, szpackage - sz_ ; 11
add ebx, luaopen_package - luaopen_base ; 4
call near luahack_reg

; table
add esi, sztable - szpackage; 18
add ebx, luaopen_table - luaopen_package ; 4
call near luahack_reg

; io
add esi, szio - sztable ; 16
add ebx, luaopen_io - luaopen_table ; 4
call near luahack_reg

; os
add esi, szos - szio ; 13
add ebx, luaopen_os - luaopen_io ; 4
call near luahack_reg

; string
add esi, szstring - szos ; 13
add ebx, luaopen_string - luaopen_os ; 4
call near luahack_reg

; math
add esi, szmath - szstring ; 17
add ebx, luaopen_math - luaopen_string ; 4
call near luahack_reg

; debug
add esi, szdebug - szmath ; 15
add ebx, luaopen_debug - luaopen_math ; 4
call near luahack_reg

; jit
add esi, szjit - szdebug ; 16
add ebx, luaopen_jit - luaopen_debug ; 4
call near luahack_reg

; coco
add esi, szcoco - szjit ; 14
add ebx, luaopen_coco - luaopen_jit ; 4
call near luahack_reg

xchg eax, edx ; return luaState pointer

pop edi ; call func
pop edx ; edx is base reloc ptr, becomes state ptr - passed by eax
pop esi ; str ptr
pop ebx ; func ptr

ret