-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'improve-stack-analysis' into 'main'
Improvements in stack def-use and value analysis See merge request rewriting/ddisasm!1180
- Loading branch information
Showing
15 changed files
with
732 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
.PHONY: all clean check | ||
all: out.txt | ||
|
||
out.txt: ex | ||
@./$^ > $@ | ||
ex: src.s | ||
gcc $^ -o $@ | ||
|
||
clean: | ||
rm -f ex out.txt | ||
check: | ||
./ex > /tmp/res.txt | ||
@ diff out.txt /tmp/res.txt && echo TEST OK |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
|
||
# Patterns for moving values through the stack | ||
|
||
.align 16 | ||
.globl main | ||
.type main, @function | ||
main: | ||
push_pop: | ||
pushq %rbp | ||
movq %rsp, %rbp | ||
leaq .hello_ptr(%rip), %rdx | ||
push %rdx | ||
xor %rdx, %rdx | ||
pop %rdx | ||
movq (%rdx), %rdi | ||
call puts@PLT | ||
|
||
# Push several immediates to the stack | ||
# and pop them later | ||
|
||
nested_push_imm: | ||
leaq .aaa(%rip), %rdx | ||
pushw $2 | ||
pushq $4 | ||
pushq %rdx | ||
xor %rdx, %rdx | ||
|
||
popq %rdi | ||
pop_4: | ||
popq %rsi | ||
movb $0x42, (%rsi,%rdi) | ||
call puts@PLT | ||
|
||
leaq .aaa(%rip), %rdi | ||
xor %rax,%rax | ||
pop_2: | ||
popw %ax | ||
movb $0x43, (%rdi,%rax) | ||
call puts@PLT | ||
|
||
# Push several immediates to the stack | ||
# and read them later without popping them | ||
|
||
push_load: | ||
|
||
leaq .aaa(%rip), %rdx | ||
pushq $2 | ||
pushw $4 | ||
pushq %rdx | ||
xor %rdx, %rdx | ||
|
||
movq (%rsp),%rdi | ||
xor %rsi,%rsi | ||
read_4: | ||
movw 8(%rsp),%si | ||
movb $0x44, (%rsi,%rdi) | ||
call puts@PLT | ||
|
||
leaq .aaa(%rip), %rdi | ||
read_2: | ||
movq 10(%rsp),%rsi | ||
movb $0x45, (%rsi,%rdi) | ||
call puts@PLT | ||
|
||
add $18, %rsp | ||
|
||
# Push some registers to the stack | ||
# and read them later | ||
|
||
push_regs: | ||
leaq .aaa(%rip), %rdx | ||
mov $1, %rax | ||
pushq %rax | ||
mov $3, %ax | ||
pushw %ax | ||
pushq %rdx | ||
xor %rdx, %rdx | ||
|
||
movq (%rsp),%rdi | ||
xor %rsi,%rsi | ||
read_3: | ||
movw 8(%rsp),%si | ||
movb $0x44, (%rsi,%rdi) | ||
call puts@PLT | ||
|
||
leaq .aaa(%rip), %rdi | ||
read_1: | ||
movq 10(%rsp),%rsi | ||
movb $0x45, (%rsi,%rdi) | ||
call puts@PLT | ||
|
||
add $18, %rsp | ||
xor %rax,%rax | ||
popq %rbp | ||
ret | ||
|
||
|
||
|
||
.data | ||
|
||
.hello_ptr: | ||
.quad .hello | ||
.hello: | ||
.string "hello\n" | ||
.aaa: | ||
.string "AAAAAAAAAAAAAA\n" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
.PHONY: all clean check | ||
all: out.txt | ||
|
||
out.txt: ex | ||
@./$^ > $@ | ||
ex: src.s | ||
gcc $^ -pie -m32 -o $@ | ||
|
||
clean: | ||
rm -f ex out.txt | ||
check: | ||
./ex > /tmp/res.txt | ||
@ diff out.txt /tmp/res.txt && echo TEST OK |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
|
||
# Patterns for moving values through the stack | ||
|
||
.align 16 | ||
.globl main | ||
.type main, @function | ||
main: | ||
pushl %ebp | ||
movl %esp, %ebp | ||
|
||
|
||
call __x86.get_pc_thunk.bx | ||
addl $_GLOBAL_OFFSET_TABLE_, %ebx | ||
leal .hello_ptr@GOTOFF(%ebx), %edx | ||
push %edx | ||
xor %edx, %edx | ||
pop %edx | ||
movl (%edx), %edi | ||
|
||
sub $12, %esp | ||
push %edi | ||
call puts@PLT | ||
add $16, %esp | ||
|
||
# Push several immediates to the stack | ||
# and pop them later | ||
|
||
nested_push_imm: | ||
leal .aaa@GOTOFF(%ebx), %edx | ||
pushw $2 | ||
pushl $4 | ||
pushl %edx | ||
xor %edx, %edx | ||
|
||
popl %edi | ||
pop_4: | ||
popl %esi | ||
movb $0x42, (%esi,%edi) | ||
|
||
push %edi | ||
call puts@PLT | ||
add $4, %esp | ||
|
||
leal .aaa@GOTOFF(%ebx), %edi | ||
xor %eax,%eax | ||
pop_2: | ||
popw %ax | ||
movb $0x43, (%edi,%eax) | ||
|
||
push %edi | ||
call puts@PLT | ||
add $4, %esp | ||
|
||
# Push several immediates to the stack | ||
# and read them later without popping them | ||
|
||
push_load: | ||
|
||
leal .aaa@GOTOFF(%ebx), %edx | ||
pushl $2 | ||
pushw $4 | ||
pushl %edx | ||
xor %edx, %edx | ||
|
||
movl (%esp),%edi | ||
xor %esi,%esi | ||
read_4: | ||
movw 4(%esp),%si | ||
movb $0x44, (%esi,%edi) | ||
|
||
push %edi | ||
call puts@PLT | ||
add $4, %esp | ||
|
||
leal .aaa@GOTOFF(%ebx), %edi | ||
read_2: | ||
movl 6(%esp),%esi | ||
movb $0x45, (%esi,%edi) | ||
|
||
|
||
push %edi | ||
call puts@PLT | ||
add $4, %esp | ||
|
||
add $10, %esp | ||
|
||
# Push some registers to the stack | ||
# and read them later | ||
|
||
push_regs: | ||
leal .aaa@GOTOFF(%ebx), %edx | ||
mov $1, %eax | ||
pushl %eax | ||
mov $3, %ax | ||
pushw %ax | ||
pushl %edx | ||
xor %edx, %edx | ||
|
||
movl (%esp),%edi | ||
xor %esi,%esi | ||
read_3: | ||
movw 4(%esp),%si | ||
movb $0x44, (%esi,%edi) | ||
|
||
push %edi | ||
call puts@PLT | ||
add $4, %esp | ||
|
||
leal .aaa@GOTOFF(%ebx), %edi | ||
read_1: | ||
movl 6(%esp),%esi | ||
movb $0x45, (%esi,%edi) | ||
|
||
push %edi | ||
call puts@PLT | ||
add $4, %esp | ||
|
||
add $10, %esp | ||
xor %eax,%eax | ||
|
||
popl %ebp | ||
end: | ||
ret | ||
|
||
|
||
|
||
.data | ||
|
||
.hello_ptr: | ||
.long .hello | ||
.hello: | ||
.string "hello\n" | ||
.aaa: | ||
.string "AAAAAAAAAAAAAA\n" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.