Skip to content

Commit

Permalink
Add wrapper checks for parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
szapp committed Jan 1, 2021
1 parent 07b7085 commit 478c08a
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 5 deletions.
39 changes: 37 additions & 2 deletions src/exec/parse.asm
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,19 @@
global parser_check_func
parser_check_func:
resetStackoffset 0xA4
xor eax, eax
mov ecx, DWORD [zCParser__enableParsing] ; Check if wrapped by Ninja
cmp ecx, 0x2A
jnz .back

lea ecx, [esp+stackoffset-0x7C]
push ecx
lea ecx, [esi+0x10]
call zCPar_SymbolTable__GetSymbol_str
addStack 4
verifyStackoffset 0xA4

; Jump back
.back:
test eax, eax
mov ebp, eax
jnz g1g2(0x6F4980,0x79E1D1)
Expand All @@ -33,6 +38,11 @@ linker_replace_func:
push edi
push ecx ; symbol
push eax ; Calculated stack position

mov eax, DWORD [zCParser__enableParsing] ; Check if wrapped by Ninja
cmp eax, 0x2A
jnz .rf_back

mov eax, [ecx+zCPar_Symbol_content_offset]
test eax, eax
verifyStackoffset g1g2(0xA8,0xE4) + 0xC
Expand Down Expand Up @@ -110,6 +120,11 @@ linker_replace_func:
global parser_check_var
parser_check_var:
resetStackoffset g1g2(0x394,0x3EC)
xor g1g2(edi,ebp), g1g2(edi,ebp)
mov eax, DWORD [zCParser__enableParsing] ; Check if wrapped by Ninja
cmp eax, 0x2A
jnz .check_sym

mov eax, DWORD [esi+zCParser_in_func_offset] ; parser->in_func->name
test eax, eax
jnz .sub_var
Expand Down Expand Up @@ -170,6 +185,10 @@ parser_check_class:
%if GOTHIC_BASE_VERSION == 2
pop ecx
%endif
mov ecx, DWORD [zCParser__enableParsing] ; Check if wrapped by Ninja
cmp ecx, 0x2A
jnz .pcc_new

lea ecx, [esp+stackoffset-0x34]
push ecx
lea ecx, [esi+0x10]
Expand All @@ -189,6 +208,8 @@ parser_check_class:
jmp 0x6F2B26
%elif GOTHIC_BASE_VERSION == 2
jnz 0x79C452

.pcc_new:
push 0x3C
call operator_new
jmp 0x79C437
Expand All @@ -198,15 +219,21 @@ parser_check_class:
global parser_check_prototype
parser_check_prototype:
resetStackoffset 0xB8
xor eax, eax
mov ecx, DWORD [zCParser__enableParsing] ; Check if wrapped by Ninja
cmp ecx, 0x2A
jnz .back

lea ecx, [esp+stackoffset-0x90]
push ecx
lea ecx, [esi+0x10]
call zCPar_SymbolTable__GetSymbol_str
addStack 4

.back:
test eax, eax
verifyStackoffset 0xB8

; Jump back
%if GOTHIC_BASE_VERSION == 1
jnz 0x6F36E6
push 0x4DF
Expand All @@ -226,6 +253,10 @@ parser_verify_ikarus_version:
push eax
push ebx

mov ecx, DWORD [zCParser__enableParsing] ; Check if wrapped by Ninja
cmp ecx, 0x2A
jnz .backClean

mov ecx, [esi+zCParser_mergemode_offset]
test ecx, ecx
verifyStackoffset g1g2(0x398,0x3F0) + 0x8
Expand Down Expand Up @@ -401,6 +432,10 @@ parser_verify_lego_version:
push edx
push ebx

mov ecx, DWORD [zCParser__enableParsing] ; Check if wrapped by Ninja
cmp ecx, 0x2A
jnz .back

mov ecx, [esi+zCParser_mergemode_offset]
test ecx, ecx
verifyStackoffset g1g2(0x394,0x3EC) + 0xC
Expand Down
5 changes: 3 additions & 2 deletions src/func/allowRedefine.asm
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ ninja_allowRedefine:
xor ebx, ebx
mov ecx, [esp+stackoffset+arg_1]
mov esi, [ecx+zCParser_datsave_offset]
add esi, DWORD [zCParser__enableParsing] ; Check if wrapped by Ninja
mov eax, char_redefinedIdentifier
test esi, esi
cmp ecx, 0x2A
jnz .createString
mov eax, NINJA_OVERWRITING

Expand All @@ -28,7 +29,7 @@ ninja_allowRedefine:
push DWORD [esp+stackoffset+arg_2]
call zSTRING__operator_plusEq
addStack 4
test esi, esi
cmp esi, 0x2A
jz .noteOnly
push ebx
push eax
Expand Down
2 changes: 1 addition & 1 deletion src/func/armParser.asm
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ ninja_armParser:
mov [esi], eax ; parser->datsave = 0
mov [esi-zCParser_datsave_offset+zCParser_lastsym_offset], eax ; parser->lastsym = 0

inc eax
mov eax, 0x2A
mov DWORD [zCParser__enableParsing], eax

mov ecx, DWORD [zCPar_SymbolTable__cur_table]
Expand Down

0 comments on commit 478c08a

Please sign in to comment.