int main(void) { test_reg(); test_rm(); test_mm(); test_big(0xffffffff); test_big(0x1fff); test_big(0xff); return 0; }
int main (int argc, char **argv) { unsigned int insn; FILE *fas; int aline = 0; char s[81], *name; if (argc < 3) { printf ("usage: %s itbl asm.s\n", argv[0]); exit (0); } if (itbl_parse (argv[1]) != 0) { printf ("failed to parse itbl\n"); exit (0); } fas = fopen (argv[2], "r"); if (fas == 0) { printf ("failed to open asm file %s\n", argv[2]); exit (0); } while (fgets (s, 80, fas)) { char *p; aline++; if (p = strchr (s, ';'), p) /* strip comments */ *p = 0; if (p = strchr (s, '#'), p) /* strip comments */ *p = 0; p = s + strlen (s) - 1; while (p >= s && (*p == ' ' || *p == '\t' || *p == '\n')) /* strip trailing spaces */ p--; *(p + 1) = 0; p = s; while (*p && (*p == ' ' || *p == '\t' || *p == '\n')) /* strip leading spaces */ p++; if (!*p) continue; name = itbl_get_field (&p); insn = itbl_assemble (name, p); if (insn == 0) printf ("line %d: Invalid instruction (%s)\n", aline, s); else { char buf[128]; printf ("line %d: insn(%s) = 0x%x)\n", aline, s, insn); if (!itbl_disassemble (buf, insn)) printf ("line %d: Can't disassemble instruction " "(0x%x)\n", aline, insn); else printf ("line %d: disasm(0x%x) = %s)\n", aline, insn, buf); } } test_reg (1, e_dreg, "d1", 1); test_reg (3, e_creg, "c2", 22); test_reg (3, e_dreg, "d3", 3); fclose (fas); return 0; }
/** * Parse the parameters following an opcode. * @param paramCount * @return True if successful, false if parameters are invalid or incomplete. */ bool parseParam(uint8_t paramCount) { uint16_t pointer = regPC + 1; uint16_t pointer_imm; uint16_t pointer_reg; uint16_t pointer_immPtr; uint16_t pointer_regPtr; paramType_t pTypeX; pIdentity_t idX; uint8_t i; for (i = 1; i <= paramCount; i++) { // Select the right parameter blocks to modify for this iteration of the parsing loop switch (i) { case 1: pTypeX = pTypeA; idX = A; break; case 2: pTypeX = pTypeB; idX = B; break; case 3: pTypeX = pTypeC; idX = C; break; case 4: pTypeX = pTypeD; idX = D; break; } // Test for immediate values pointer_imm = test_imm(pTypeX, idX, pointer); if (pointer_imm) { pointer = pointer_imm; break; } // Test for registers pointer_reg = test_reg(pTypeX, idX, pointer); if (pointer_reg) { pointer = pointer_reg; break; } // Test for immediate 16-bit addresses pointer_immPtr = test_immPtr(pTypeX, idX, pointer); if (pointer_immPtr) { pointer = pointer_immPtr; break; } // Test for 16-bit pointer registers pointer_regPtr = test_regPtr(pTypeX, idX, pointer); if (pointer_regPtr) { pointer = pointer_regPtr; break; } // No valid parameters found, so fail. return false; } // All parameters found are valid, so update regPC and pass. regPC = pointer; return true; }
int main(int argc, char **argv) { debug_init(stdout); save_fx(fx_orig); memcpy(&fx_orig[240], scratch_orig, 4*sizeof(long)); memcpy(&fx_orig[256], taint_orig, 8*sizeof(long)); offset = (long)taintmem_test - (long)mem_test; codeexec(NULL, 0, (long *)regs_orig); init_threads(); test_reg2(taint_copy_reg32_to_reg32, ref_copy_reg32_to_reg32); test_reg2(taint_copy_reg16_to_reg16, ref_copy_reg16_to_reg16); test_reg2(taint_copy_reg8_to_reg8, ref_copy_reg8_to_reg8); test_mem(taint_copy_mem32_to_reg32, ref_copy_mem32_to_reg32); test_mem(taint_copy_mem16_to_reg16, ref_copy_mem16_to_reg16); test_mem(taint_copy_mem8_to_reg8, ref_copy_mem8_to_reg8); test_mem(taint_copy_reg32_to_mem32, ref_copy_reg32_to_mem32); test_mem(taint_copy_reg16_to_mem16, ref_copy_reg16_to_mem16); test_mem(taint_copy_reg8_to_mem8, ref_copy_reg8_to_mem8); test_stackop(taint_copy_push_reg32, ref_copy_push_reg32); test_stackop(taint_copy_push_reg16, ref_copy_push_reg16); test_mem(taint_copy_push_mem32, ref_copy_push_mem32); test_mem(taint_copy_push_mem16, ref_copy_push_mem16); test_stackop(taint_copy_pop_reg32, ref_copy_pop_reg32); test_stackop(taint_copy_pop_reg16, ref_copy_pop_reg16); test_mem(taint_copy_pop_mem32, ref_copy_pop_mem32); test_mem(taint_copy_pop_mem16, ref_copy_pop_mem16); test_addr(taint_copy_eax_to_addr32, ref_copy_eax_to_addr32); test_addr(taint_copy_ax_to_addr16, ref_copy_ax_to_addr16); test_addr(taint_copy_al_to_addr8, ref_copy_al_to_addr8); test_addr(taint_copy_addr32_to_eax, ref_copy_addr32_to_eax); test_addr(taint_copy_addr16_to_ax, ref_copy_addr16_to_ax); test_addr(taint_copy_addr8_to_al, ref_copy_addr8_to_al); test_impl(taint_copy_eax_to_str32, ref_copy_eax_to_str32); test_impl(taint_copy_ax_to_str16, ref_copy_ax_to_str16); test_impl(taint_copy_al_to_str8, ref_copy_al_to_str8); test_impl(taint_copy_str32_to_eax, ref_copy_str32_to_eax); test_impl(taint_copy_str16_to_ax, ref_copy_str16_to_ax); test_impl(taint_copy_str8_to_al, ref_copy_str8_to_al); test_impl(taint_copy_str32_to_str32, ref_copy_str32_to_str32); test_impl(taint_copy_str16_to_str16, ref_copy_str16_to_str16); test_impl(taint_copy_str8_to_str8, ref_copy_str8_to_str8); test_reg(taint_erase_reg32, ref_erase_reg32); test_reg(taint_erase_reg16, ref_erase_reg16); test_reg(taint_erase_reg8, ref_erase_reg8); test_mem(taint_erase_mem32, ref_erase_mem32); test_mem(taint_erase_mem16, ref_erase_mem16); test_mem(taint_erase_mem8, ref_erase_mem8); test_reg(taint_erase_hireg16, ref_erase_hireg16); test_impl(taint_erase_push32, ref_erase_push32); test_impl(taint_erase_push16, ref_erase_push16); test_reg2(taint_or_reg32_to_reg32, ref_or_reg32_to_reg32); test_reg2(taint_or_reg16_to_reg16, ref_or_reg16_to_reg16); test_reg2(taint_or_reg8_to_reg8, ref_or_reg8_to_reg8); test_mem(taint_or_reg32_to_mem32, ref_or_reg32_to_mem32); test_mem(taint_or_reg16_to_mem16, ref_or_reg16_to_mem16); test_mem(taint_or_reg8_to_mem8, ref_or_reg8_to_mem8); test_mem(taint_or_mem32_to_reg32, ref_or_mem32_to_reg32); test_mem(taint_or_mem16_to_reg16, ref_or_mem16_to_reg16); test_mem(taint_or_mem8_to_reg8, ref_or_mem8_to_reg8); test_mem(taint_xor_reg32_to_mem32, ref_xor_reg32_to_mem32); test_mem(taint_xor_reg16_to_mem16, ref_xor_reg16_to_mem16); test_mem(taint_xor_reg8_to_mem8, ref_xor_reg8_to_mem8); test_mem(taint_xor_mem32_to_reg32, ref_xor_mem32_to_reg32); test_mem(taint_xor_mem16_to_reg16, ref_xor_mem16_to_reg16); test_mem(taint_xor_mem8_to_reg8, ref_xor_mem8_to_reg8); test_reg2(taint_swap_reg32_reg32, ref_swap_reg32_reg32); test_reg2(taint_swap_reg16_reg16, ref_swap_reg16_reg16); test_reg2(taint_swap_reg8_reg8, ref_swap_reg8_reg8); test_mem(taint_swap_reg32_mem32, ref_swap_reg32_mem32); test_mem(taint_swap_reg16_mem16, ref_swap_reg16_mem16); test_mem(taint_swap_reg8_mem8, ref_swap_reg8_mem8); test_reg2(taint_copy_reg16_to_reg32, ref_copy_reg16_to_reg32); test_reg2(taint_copy_reg8_to_reg32, ref_copy_reg8_to_reg32); test_reg2(taint_copy_reg8_to_reg16, ref_copy_reg8_to_reg16); test_mem(taint_copy_mem16_to_reg32, ref_copy_mem16_to_reg32); test_mem(taint_copy_mem8_to_reg32, ref_copy_mem8_to_reg32); test_mem(taint_copy_mem8_to_reg16, ref_copy_mem8_to_reg16); test_impl2(taint_erase_eax_edx, ref_erase_eax_edx); test_impl2(taint_erase_ax_dx, ref_erase_ax_dx); test_impl2(taint_erase_eax, ref_erase_eax); test_impl2(taint_erase_ax, ref_erase_ax); test_impl2(taint_erase_al, ref_erase_al); test_pushpop(taint_copy_popa32, ref_copy_popa32, (long)mem_test); test_pushpop(taint_copy_popa16, ref_copy_popa16, (long)mem_test); test_pushpop(taint_copy_pusha32, ref_copy_pusha32, 32+(long)mem_test); test_pushpop(taint_copy_pusha16, ref_copy_pusha16, 32+(long)mem_test); test_impl(taint_leave32, ref_leave32); test_impl(taint_leave16, ref_leave16); test_cmpxchg(taint_cmpxchg8_pre, taint_cmpxchg8_post, ref_cmpxchg8); test_cmpxchg(taint_cmpxchg16_pre, taint_cmpxchg16_post, ref_cmpxchg16); test_cmpxchg(taint_cmpxchg32_pre, taint_cmpxchg32_post, ref_cmpxchg32); test_cmpxchg(taint_cmpxchg8b_pre, taint_cmpxchg8b_post, ref_cmpxchg8b); mrm_generator(test_lea); exit(err); }