xoreaxeaxeax / movfuscator

The single instruction C compiler
Other
9.39k stars 396 forks source link

--no-mov-flow doesn't work #19

Closed Smertig closed 5 years ago

Smertig commented 7 years ago

Hello!

Option --no-mov-flow seems not to work. I got these output:

M/o/Vfuscation complete.

/tmp/lcc61831.s: Assembler messages:
/tmp/lcc61831.s:1254: Error: too many memory references for `cmp'
/tmp/lcc61831.s:3293: Error: too many memory references for `cmp'
/tmp/lcc61831.s:5042: Error: too many memory references for `cmp'
/tmp/lcc61831.s:6292: Error: too many memory references for `cmp'
/tmp/lcc61831.s:9089: Error: too many memory references for `cmp'
/tmp/lcc61831.s:10983: Error: too many memory references for `cmp'
/tmp/lcc61831.s:12366: Error: too many memory references for `cmp'

To reproduce this bug, you can simply add -Wf--no-mov-flow at the end of 22nd line of check.sh

GregoryMorse commented 7 years ago

Change all the lines with: print("cmpl "); emit_kid(p,1,nt); print(", "); emit_kid(p,0,nt); print("\n"); To: print("movl "); emit_kid(p,0,nt); print(", %%eax\n"); print("cmpl "); emit_kid(p,1,nt); print(", %%eax\n");

jump+v does not work either as print("jmp "); emit_kid(p,0,nt); print("\n"); Should be: if (p->kids[0]->syms[0]) { print("jmp %s\n", p->kids[0]->syms[0]->x.name); } else { print("movl "); emit_kid(p,0,nt); print(", %%eax\n"); print("jmp *%%eax\n"); }

"cmpl (%s), 1\n" should be changed to "cmpl $1, (%s)\n" also in cc_branch. Almost certain this code was sketched out only and never tested...

Secondly, unfortunately the C libraries are precompiled when you build movfuscator. emit_start is called in each build, but the result discarded. The library version is what is used. But unfortunately that is using the mov_flow flag, the default. This is one way to do the job by changing default in c code, or much better is to change build.sh to pass --no-mov-flow to the libraries when they are precompiled. static int mov_flow= 0; Better approach in build.sh: "$BUILDDIR/movcc" movfuscator/crt.c -o "$BUILDDIR/crt.c" -c -Wf--crt -Wf--q -Wf--no-mov-flow where is 0, f and d.

After all of this, it works flawlessly though :). Hope the author will commit these changes. I can submit a pull request if need be.

xoreaxeaxeax commented 6 years ago

Thanks for the fixes, I'll get this committed shortly. That flag worked at one point, but seems to have broken along the way.

MrAureliusR commented 5 years ago

Any chance this will get fixed at some point? Having the same problem still.

xoreaxeaxeax commented 5 years ago

Fixed with 6342ae76b580c174eb35e612ec9fc0013be7859d. Thanks @GregoryMorse for the change suggestions.