Skip to content

Instantly share code, notes, and snippets.

@ChrisLane
Created December 7, 2016 18:24
Show Gist options
  • Save ChrisLane/c183b3644a625a2d91fabbd81928d0a8 to your computer and use it in GitHub Desktop.
Save ChrisLane/c183b3644a625a2d91fabbd81928d0a8 to your computer and use it in GitHub Desktop.
.LC0:
.string "%d\n"
.globl print
.type print, @function
print:
pushq %rbp
movq %rsp, %rbp
subq $16, %rsp
movl %edi, -4(%rbp)
movl -4(%rbp), %eax
movl %eax, %esi
leaq .LC0(%rip), %rdi
movl $0, %eax
call printf@PLT
leave
ret
// Begin injected program
.globl f
.type f, @function
f:
pushq %rbp
movq %rsp, %rbp
subq $16, %rsp
pushq %rdi
// begin application
// arguments to registers
// begin operator
// begin deref
// begin identifier
//offset 1
movq -24(%rbp), %rax
pushq %rax
// end identifier
popq %rbx
movq (%rbx), %rax
pushq %rax
// end deref
// begin const
pushq $1
// end const
popq %rbx
popq %rax
subq %rbx, %rax
pushq %rax
// end operator
popq %rdi
// arguments to the stack
// begin operator
// begin deref
// begin identifier
//offset 1
movq -24(%rbp), %rax
pushq %rax
// end identifier
popq %rbx
movq (%rbx), %rax
pushq %rax
// end deref
// begin const
pushq $1
// end const
popq %rbx
popq %rax
subq %rbx, %rax
pushq %rax
// end operator
// call the function
call f
pushq %rax
// end application
popq %rax
leave
ret
.globl main
.type main, @function
main:
pushq %rbp
movq %rsp, %rbp
subq $16, %rsp
// begin new
pushq $10
leaq -24(%rbp), %rax
pushq %rax
// begin print
// begin application
// arguments to registers
//offset 2
movq -32(%rbp), %rax
pushq %rax
popq %rdi
// arguments to stack
//offset 2
movq -32(%rbp), %rax
pushq %rax
// call the function
call f
pushq %rax
// end application
popq %rdi
call print
pushq $0
// end print
// strip the stack down
popq %rax
popq %rbx
pushq %rax
// end new
// End injected program
movl $0, %edi
call exit@PLT
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment