woody-woodpacker/assets/xor.s

58 lines
1.1 KiB
ArmAsm
Raw Normal View History

2024-09-03 20:14:18 +00:00
bits 64
global _start
_start:
push rax
push rcx
push rdx
push rsi
push rdi
2024-09-06 13:02:02 +00:00
lea rdi, [rel _start]
sub rdi, qword [rel load_ptr]
mov rsi, qword [rel load_size]
2024-09-03 21:57:33 +00:00
mov rdx, qword [rel private_key]
2024-09-03 20:14:18 +00:00
2024-09-03 21:57:33 +00:00
decrypt_last_block:
2024-09-06 13:02:02 +00:00
; rcx = 8 * (8 - load_size % 8)
2024-09-03 21:57:33 +00:00
; Then crop the private key by rcx bits
; That's to decrypt the end of the section in case the section size
; isn't a multiple of 64 bits
2024-09-06 13:02:02 +00:00
mov rcx, rsi
2024-09-03 21:57:33 +00:00
not rcx
and rcx, 7
inc rcx
shl rcx, 3
mov rax, rdx
shl rax, cl
shr rax, cl
; make section size a multiple of 64bits with this and
2024-09-06 13:02:02 +00:00
and rsi, 0xfffffffffffffff8
xor [rdi + rsi], rax
2024-09-03 20:14:18 +00:00
2024-09-03 21:57:33 +00:00
decrypt_whole_blocks:
2024-09-06 13:02:02 +00:00
sub rsi, 8
cmp rsi, -8
2024-09-03 21:57:33 +00:00
je end_decrypt
2024-09-06 13:02:02 +00:00
xor [rdi + rsi], rdx
2024-09-03 21:57:33 +00:00
jmp decrypt_whole_blocks
2024-09-03 20:14:18 +00:00
end_decrypt:
2024-09-06 13:02:02 +00:00
lea rsi, [rel msg]
2024-09-03 21:57:33 +00:00
mov rdi, 1
2024-09-03 20:14:18 +00:00
mov rdx, 14
mov rax, 1
syscall
pop rdi
pop rsi
pop rdx
pop rcx
pop rax
jmp 0xdadadada ; this needs to be just before that
msg db "....WOODY....",10 ; that needs to be just after this
2024-09-06 13:02:02 +00:00
load_ptr dq 0xbabababababababa
load_size dq 0xcacacacacacacaca
2024-09-03 20:14:18 +00:00
private_key dq 0xabcdefabcdefabcd