rewrite 6xE4 logic

This commit is contained in:
Martin Michelsen
2025-06-08 16:18:29 -07:00
parent 54acd931da
commit 6999694f89
10 changed files with 728 additions and 539 deletions
@@ -1,56 +1,57 @@
start:
.include VersionDetectWithPatchFunctionsXB
xor eax, eax
cmp edx, 0
jne can_patch
.include GetVersionInfoXB
test eax, eax
jnz can_patch
ret
can_patch:
push esi
push edi
push ebx
mov edi, edx # edi = ptr to useful kernel function ptrs
jmp get_patch_data_ptr
can_patch:
push esi
push edi
push ebx
mov edi, eax # edi = ptr to version info struct
jmp get_patch_data_ptr
get_patch_data_ptr_ret:
pop ebx # ebx = patch header
pop ebx # ebx = patch header
apply_next_patch:
cmp dword [ebx + 4], 0
jne copy_code_and_apply_again
pop ebx
pop edi
pop esi
mov eax, 1
cmp dword [ebx + 4], 0
jne copy_code_and_apply_again
pop ebx
pop edi
pop esi
mov eax, 1
ret
copy_code_and_apply_again:
push dword [ebx] # dest addr
call [edi + 4] # MmQueryAddressProtect
mov esi, eax # esi = prev protection flags
push dword [ebx] # dest addr
mov ecx, [edi + 0x0C]
call [ecx] # MmQueryAddressProtect
mov esi, eax # esi = prev protection flags
push 4 # new protection flags
push dword [ebx + 4] # size
push dword [ebx] # base address
call [edi] # MmSetAddressProtect
push 4 # new protection flags
push dword [ebx + 4] # size
push dword [ebx] # base address
mov ecx, [edi + 0x08]
call [ecx] # MmSetAddressProtect
xor ecx, ecx # ecx = offset
mov edx, [ebx] # edx = dest addr
xor ecx, ecx # ecx = offset
mov edx, [ebx] # edx = dest addr
copy_next_byte:
mov al, [ebx + ecx + 8] # copy one byte to dest
mov [edx + ecx], al
inc ecx # offset++
cmp [ebx + 4], ecx # check if all bytes have been copied
jne copy_next_byte
mov al, [ebx + ecx + 8] # copy one byte to dest
mov [edx + ecx], al
inc ecx # offset++
cmp [ebx + 4], ecx # check if all bytes have been copied
jne copy_next_byte
push esi # new protection flags
push dword [ebx + 4] # size
push dword [ebx] # base address
lea ebx, [ebx + ecx + 8] # advance to next block
call [edi] # MmSetAddressProtect
jmp apply_next_patch
push esi # new protection flags
push dword [ebx + 4] # size
push dword [ebx] # base address
lea ebx, [ebx + ecx + 8] # advance to next block
mov ecx, [edi + 0x08]
call [ecx] # MmSetAddressProtect
jmp apply_next_patch
get_patch_data_ptr:
call get_patch_data_ptr_ret
call get_patch_data_ptr_ret
first_patch_header: