Skip to content

Commit

Permalink
Handle stos and movs
Browse files Browse the repository at this point in the history
  • Loading branch information
zyedidia committed Jun 5, 2024
1 parent c88450e commit 49bc004
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
28 changes: 28 additions & 0 deletions lfi-leg/lfi-amd64.leg
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ Insn = INDENT Label? (
FnDirective
| Directive
| Lea
| Stos
| Movs
| Lock
| ModSP
| Triple1
Expand Down Expand Up @@ -141,6 +143,32 @@ REMAINDER = < (!(EOL | ';') .)* > { $$ = (Transform) { .val = strndup(yytext, yy

# --- loads and stores ---

Stos = s:STOS r:REG COMMA '%es:(%rdi)' - {
mkdirective(".p2align 4\n");
mkinsn("movl %%edi, %%edi\n");
mkinsn("orq %%r14, %%rdi\n");
mkinsn("%s %s, %%es:(%%rdi)\n", s.val, r.val);
tfree(r);
}

STOS = < ('rep' -)? 'stos' - > {
$$ = (Transform) { .val = strndup(yytext, yyleng) }
}

Movs = m:MOVS '%ds:(%rsi)' - COMMA '%es:(%rdi)' - {
mkdirective(".p2align 4\n");
mkinsn("movl %%esi, %%esi\n");
mkinsn("movl %%edi, %%edi\n");
mkinsn("orq %%r14, %%rsi\n");
mkinsn("orq %%r14, %%rdi\n");
mkinsn("%s %%ds:(%%rsi), %%es:(%%rdi)\n", m.val);
tfree(m);
}

MOVS = < ('rep' -)? 'movs' [qlb] - > {
$$ = (Transform) { .val = strndup(yytext, yyleng) }
}

Lea = l:LEA a:AddrNoMod COMMA r:REG {
mkinsn("%s %s, %s\n", l.val, a.val, r.val);
tfree(l); tfree(a); tfree(r);
Expand Down
4 changes: 4 additions & 0 deletions lfi-leg/test/amd64/test.s
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,7 @@ add $0xc0, %rsp
lock ; cmpxchg

call *32+output(%rip)

rep stos %eax, %es:(%rdi)

rep movsq %ds:(%rsi), %es:(%rdi)

0 comments on commit 49bc004

Please sign in to comment.