Skip to content

Instantly share code, notes, and snippets.

@adventurist
Created July 7, 2020 18:53
Show Gist options
  • Save adventurist/7b2c99f54b9185041f50d1cc7c039d65 to your computer and use it in GitHub Desktop.
Save adventurist/7b2c99f54b9185041f50d1cc7c039d65 to your computer and use it in GitHub Desktop.
Decoder returns vector (asm)
Decoder::Decoder() [base object constructor]:
push rbp
push rbx
mov rbx, rdi
sub rsp, 24
mov QWORD PTR [rdi], 0
mov QWORD PTR [rdi+8], 0
mov QWORD PTR [rdi+16], 0
mov edi, 4990
call operator new(unsigned long)
mov rdi, QWORD PTR [rbx]
test rdi, rdi
je .L2
mov QWORD PTR [rsp+8], rax
call operator delete(void*)
mov rax, QWORD PTR [rsp+8]
.L2:
mov QWORD PTR [rbx+8], rax
mov QWORD PTR [rbx], rax
add rax, 4990
mov QWORD PTR [rbx+16], rax
add rsp, 24
pop rbx
pop rbp
ret
mov rdi, QWORD PTR [rbx]
mov rbp, rax
test rdi, rdi
je .L4
call operator delete(void*)
.L4:
mov rdi, rbp
call _Unwind_Resume
.LC0:
.string "vector::_M_range_insert"
void std::vector<unsigned char, std::allocator<unsigned char> >::_M_range_insert<unsigned char*>(__gnu_cxx::__normal_iterator<unsigned char*, std::vector<unsigned char, std::allocator<unsigned char> > >, unsigned char*, unsigned char*, std::forward_iterator_tag):
push r15
push r14
push r13
push r12
mov r12, rdx
push rbp
push rbx
sub rsp, 24
cmp rdx, rcx
je .L15
mov r8, QWORD PTR [rdi+8]
mov rax, QWORD PTR [rdi+16]
mov rbp, rcx
sub rbp, rdx
mov rbx, rdi
mov r13, rsi
sub rax, r8
cmp rbp, rax
ja .L18
mov r14, r8
sub r14, rsi
cmp rbp, r14
jb .L61
lea r15, [rdx+r14]
mov rdi, r8
sub rcx, r15
mov rdx, rcx
jne .L62
.L23:
sub rbp, r14
add rdi, rbp
test r14, r14
mov QWORD PTR [rbx+8], rdi
jne .L63
.L24:
mov rdx, r15
add rdi, r14
sub rdx, r12
mov QWORD PTR [rbx+8], rdi
jne .L60
.L15:
add rsp, 24
pop rbx
pop rbp
pop r12
pop r13
pop r14
pop r15
ret
.L61:
mov r14, r8
mov rdx, r8
mov rax, r8
sub r14, rbp
sub rdx, r14
jne .L64
.L20:
mov rdx, r14
add rax, rbp
sub rdx, r13
mov QWORD PTR [rbx+8], rax
jne .L65
test rbp, rbp
mov rdx, rbp
je .L15
.L60:
add rsp, 24
mov rsi, r12
mov rdi, r13
pop rbx
pop rbp
pop r12
pop r13
pop r14
pop r15
jmp memmove
.L18:
mov rdx, QWORD PTR [rdi]
sub r8, rdx
mov rax, r8
not rax
cmp rbp, rax
ja .L66
cmp rbp, r8
mov rax, r8
mov r14, -1
cmovnb rax, rbp
add r8, rax
jnc .L67
.L26:
mov rdi, r14
call operator new(unsigned long)
mov rsi, QWORD PTR [rbx]
mov r15, rax
mov rdx, rsi
.L27:
mov r8, r13
xor ecx, ecx
sub r8, rdx
jne .L68
.L28:
add rcx, r15
test rbp, rbp
jne .L69
.L29:
mov r12, QWORD PTR [rbx+8]
add rbp, rcx
xor eax, eax
sub r12, r13
jne .L70
.L30:
mov rdi, QWORD PTR [rbx]
add rbp, rax
test rdi, rdi
je .L31
call operator delete(void*)
.L31:
add r14, r15
mov QWORD PTR [rbx], r15
mov QWORD PTR [rbx+8], rbp
mov QWORD PTR [rbx+16], r14
add rsp, 24
pop rbx
pop rbp
pop r12
pop r13
pop r14
pop r15
ret
.L65:
mov rdi, r8
mov rsi, r13
sub rdi, rdx
call memmove
test rbp, rbp
mov rdx, rbp
je .L15
jmp .L60
.L67:
test r8, r8
jne .L71
mov rsi, rdx
xor r14d, r14d
xor r15d, r15d
jmp .L27
.L62:
mov rsi, r15
call memmove
mov rdi, QWORD PTR [rbx+8]
jmp .L23
.L64:
mov rdi, r8
mov rsi, r14
call memmove
mov r8, rax
mov rax, QWORD PTR [rbx+8]
jmp .L20
.L63:
mov rdx, r14
mov rsi, r13
call memmove
mov rdi, QWORD PTR [rbx+8]
jmp .L24
.L70:
mov rdx, r12
mov rsi, r13
mov rdi, rbp
call memmove
mov rax, r12
jmp .L30
.L69:
mov rdi, rcx
mov rdx, rbp
mov rsi, r12
call memmove
mov rcx, rax
jmp .L29
.L68:
mov rdx, r8
mov rdi, r15
mov QWORD PTR [rsp+8], r8
call memmove
mov r8, QWORD PTR [rsp+8]
mov rcx, r8
jmp .L28
.L66:
mov edi, OFFSET FLAT:.LC0
call std::__throw_length_error(char const*)
.L71:
mov r14, r8
jmp .L26
Link::process(bool):
push r14
push r13
push r12
push rbp
push rbx
mov rbx, rdi
sub rsp, 16
test sil, sil
je .L73
mov rsi, QWORD PTR [rdi+8]
mov ecx, OFFSET FLAT:big_data+10
mov BYTE PTR [rsp], 0
mov edx, OFFSET FLAT:big_data
call void std::vector<unsigned char, std::allocator<unsigned char> >::_M_range_insert<unsigned char*>(__gnu_cxx::__normal_iterator<unsigned char*, std::vector<unsigned char, std::allocator<unsigned char> > >, unsigned char*, unsigned char*, std::forward_iterator_tag)
mov rdi, QWORD PTR [rbx+8]
sub rdi, QWORD PTR [rbx]
jne .L107
.L72:
add rsp, 16
pop rbx
pop rbp
pop r12
pop r13
pop r14
ret
.L73:
mov rbp, QWORD PTR [rdi+8]
mov rax, QWORD PTR [rdi+16]
sub rax, rbp
cmp rax, 3
jbe .L78
mov rdi, rbp
mov edx, 4
mov esi, OFFSET FLAT:small_data
call memmove
add QWORD PTR [rbx+8], 4
add rsp, 16
pop rbx
pop rbp
pop r12
pop r13
pop r14
ret
.L107:
call operator new(unsigned long)
mov rsi, QWORD PTR [rbx]
mov rdx, QWORD PTR [rbx+8]
mov rcx, rax
sub rdx, rsi
je .L75
mov rdi, rax
call memmove
mov rcx, rax
.L75:
test rcx, rcx
je .L72
add rsp, 16
mov rdi, rcx
pop rbx
pop rbp
pop r12
pop r13
pop r14
jmp operator delete(void*)
.L78:
mov rsi, QWORD PTR [rdi]
mov rdx, rbp
sub rdx, rsi
cmp rdx, -5
ja .L108
cmp rdx, 4
mov eax, 4
mov r13, -1
cmovnb rax, rdx
add rax, rdx
jnc .L109
.L82:
mov rdi, r13
call operator new(unsigned long)
mov rsi, QWORD PTR [rbx]
mov rdx, rbp
mov r12, rax
sub rdx, rsi
mov r14, rdx
.L83:
test rdx, rdx
jne .L110
.L84:
lea rcx, [r12+r14]
mov edx, 4
mov esi, OFFSET FLAT:small_data
mov rdi, rcx
call memmove
mov r14, QWORD PTR [rbx+8]
mov rcx, rax
xor eax, eax
add rcx, 4
sub r14, rbp
jne .L111
.L85:
mov rdi, QWORD PTR [rbx]
lea rbp, [rcx+rax]
test rdi, rdi
je .L86
call operator delete(void*)
.L86:
mov QWORD PTR [rbx], r12
add r12, r13
mov QWORD PTR [rbx+8], rbp
mov QWORD PTR [rbx+16], r12
add rsp, 16
pop rbx
pop rbp
pop r12
pop r13
pop r14
ret
.L109:
test rax, rax
jne .L112
mov r14, rdx
xor r13d, r13d
xor r12d, r12d
jmp .L83
.L111:
mov rdi, rcx
mov rdx, r14
mov rsi, rbp
call memmove
mov rcx, rax
mov rax, r14
jmp .L85
.L110:
mov rdx, r14
mov rdi, r12
call memmove
jmp .L84
.L108:
mov edi, OFFSET FLAT:.LC0
call std::__throw_length_error(char const*)
.L112:
mov r13, rax
jmp .L82
main:
push rbx
sub rsp, 64
mov rdi, rsp
call Decoder::Decoder() [complete object constructor]
lea rdi, [rsp+32]
mov QWORD PTR [rsp+32], 0
mov QWORD PTR [rsp+40], 0
mov QWORD PTR [rsp+48], 0
call Decoder::Decoder() [complete object constructor]
lea rdi, [rsp+32]
xor esi, esi
call Link::process(bool)
lea rdi, [rsp+32]
xor esi, esi
call Link::process(bool)
lea rdi, [rsp+32]
xor esi, esi
call Link::process(bool)
lea rdi, [rsp+32]
xor esi, esi
call Link::process(bool)
lea rdi, [rsp+32]
xor esi, esi
call Link::process(bool)
lea rdi, [rsp+32]
mov esi, 1
call Link::process(bool)
mov rdi, QWORD PTR [rsp+32]
test rdi, rdi
je .L114
call operator delete(void*)
.L114:
mov rdi, QWORD PTR [rsp]
test rdi, rdi
je .L126
call operator delete(void*)
.L126:
add rsp, 64
xor eax, eax
pop rbx
ret
mov rbx, rax
.L118:
mov rdi, QWORD PTR [rsp]
test rdi, rdi
je .L119
call operator delete(void*)
.L119:
mov rdi, rbx
call _Unwind_Resume
mov rdi, QWORD PTR [rsp+32]
mov rbx, rax
test rdi, rdi
je .L118
call operator delete(void*)
jmp .L118
small_data:
.byte 4
.zero 4
big_data:
.byte 5
.zero 9
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment