Skip to content

Commit

Permalink
Add parser for intel syntax
Browse files Browse the repository at this point in the history
I DO NOT LIKE AT&T SYNTAX AT ALL
  • Loading branch information
hidva committed Jan 4, 2020
0 parents commit a35e8f9
Show file tree
Hide file tree
Showing 15 changed files with 3,322 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
parser/as2cfg.y.go
/as2cfg.out
/y.output
11 changes: 11 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
as2cfg.out: parser/as2cfg.l.go parser/as2cfg.y.go virtualall
go build -o as2cfg.out github.com/hidva/as2cfg/as2cfg

parser/as2cfg.l.go: parser/as2cfg.l
golex -o parser/as2cfg.l.go parser/as2cfg.l
parser/as2cfg.y.go: parser/as2cfg.y
goyacc -o parser/as2cfg.y.go parser/as2cfg.y

.PHONY: virtualall
virtualall:
@echo ""
44 changes: 44 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
AS2CFG, a utility from converting the assembly code output by GDB disassembler to CFG(Control Flow Graph).

Currently, the usage is very simple, just type:

```
gdb --batch -ex 'disas MyAtoI' atoi.out | grep -F 0x | as2cfg | dot -Tsvg > atoi.cfg.svg
```

`atoi.out` is compiled from:

```c
int MyAtoI(const char *input) {
int res = 0;
int sign = 1;

while (*input == ' ' || *input == '\t')
++input;

if (*input == '-') {
sign = -1;
++input;
} else if (*input == '+') {
++input;
}

for (; *input != '\0'; ++input) {
if (*input >= '0' && *input <= '9') {
res = res * 10 + *input - '0';
} else {
break;
}
}

return sign * res;
}
```
And `atoi.cfg.svg` looks like:
![atoi.cfg.svg](https://github.com/hidva/as2cfg/blob/master/atoi.cfg.svg)
The operand in instruction is represented by its SSA name, it means that if two operands in the same block have the same SSA name, they are the same operand.
And we will attempt to generate more meanful expression for edge constructed by Jcc(JE, JNE, etc.) instruction, such as that the expression for the edge constructed by the 'je(0x400590)' after 'cmp(dl_1,0x9)' is `dl_1 == 0x9` and `dl_1 != 0x9`, not just `ZF = 1` and `ZF = 0`.
Loading

0 comments on commit a35e8f9

Please sign in to comment.