rendered paste body.globl main
main:
sub $0x16, %esp
// our signal handler
// -----------------
// pop %ebp
// add $6, %esp
// inc %eax
// ret
mov %esp, %ebx
//movb $0xb3, (%ebx)
//inc %ebx
//movb $0x01, (%ebx)
//inc %ebx
//movb $0xc3, (%ebx)
movb $0x83, (%ebx)
inc %ebx
movb $0xc4, (%ebx)
inc %ebx
movb $0x40, (%ebx)
inc %ebx
movb $0x8b, (%ebx)
inc %ebx
movb $0x1c, (%ebx)
inc %ebx
movb $0x24, (%ebx)
inc %ebx
movb $0x83, (%ebx)
inc %ebx
movb $0xec, (%ebx)
inc %ebx
movb $0x40, (%ebx)
inc %ebx
movb $0x83, (%ebx)
inc %ebx
movb $0xc3, (%ebx)
inc %ebx
movb $0x04, (%ebx)
inc %ebx
movb $0x53, (%ebx)
inc %ebx
//movb $0xff, (%ebx)
//inc %ebx
//movb $0xe3, (%ebx)
//inc %ebx
movb $0xc3, (%ebx)
// install signal handler
mov %esp, %ecx
xor %eax, %eax
movb $48, %al
xor %ebx, %ebx
movb $11, %bl
int $0x80
// prepare vars for loop and save ebp for later ret
mov %esp, %edi
mov %esp, %edx
mov %esp, %esi
xor %ecx, %ecx
inc %ecx
xor %ebx, %ebx
calculate_stack_start:
cmp %cl, %bl
je calculate_stack_end
inc %edi
mov (%edi), %edx
jmp calculate_stack_start
calculate_stack_end:
// at this point, esi holds the original esp
// and edi holds the start of the stack
// re-install signal handler
mov %esi, %ecx
xor %eax, %eax
movb $48, %al
xor %ebx, %ebx
movb $11, %bl
int $0x80
// reset variables
// mov %esp, %edi
mov %esi, %esp
xor %ebx, %ebx
xor %ecx, %ecx
inc %ecx
// save for later use
push %edi
cse_loop:
cmp %cl, %bl
je munmap_stack
dec %edi
mov (%edi), %edx
jmp cse_loop
munmap_stack:
add $1, %edi
mov %esi, %esp
// restore end of stack
sub $4, %esp
pop %esi
// at this point - edi = end of stack, esi = start of stack
// edi holds the end of the stack
sub %edi, %esi
// we stopped short in our loops by 2 bytes each time
add $2, %esi
// ebx is the memory to munmap
mov %edi, %ebx
// ecx is the size to munmap
mov %esi, %ecx
// perform munmap
xor %eax, %eax
mov $91, %al
int $0x80
calculate_heap_end:
// re-install signal handler
mov %esi, %ecx
xor %eax, %eax
movb $48, %al
xor %ebx, %ebx
movb $11, %bl
int $0x80
// prepare vars for loop and save ebp for later ret
mov %esp, %edi
mov %esp, %edx
mov %esp, %esi
xor %ecx, %ecx
inc %ecx
xor %ebx, %ebx
// get current heap address
che_loop:
cmp %cl, %bl
je calculate_stack_end
inc %edi
mov (%edi), %edx
jmp che_loop
my_exit:
xor %eax, %eax
xor %ebx, %ebx
inc %eax
int $0x80