static int format_att_mnemonic( x86_insn_t *insn, char *buf, int len) { int size = 0; char *suffix; if (! insn || ! buf || ! len ) return(0); memset( buf, 0, len ); /* do long jump/call prefix */ if ( insn->type == insn_jmp || insn->type == insn_call ) { if (! is_imm_jmp( x86_operand_1st(insn) ) || (x86_operand_1st(insn))->datatype != op_byte ) { /* far jump/call, use "l" prefix */ STRNCAT( buf, "l", len ); } STRNCAT( buf, insn->mnemonic, len ); return ( strlen( buf ) ); } /* do mnemonic */ STRNCAT( buf, insn->mnemonic, len ); /* do suffixes for memory operands */ if (!(insn->note & insn_note_nosuffix) && (insn->group == insn_arithmetic || insn->group == insn_logic || insn->group == insn_move || insn->group == insn_stack || insn->group == insn_string || insn->group == insn_comparison || insn->type == insn_in || insn->type == insn_out )) { if ( x86_operand_count( insn, op_explicit ) > 0 && is_memory_op( x86_operand_1st(insn) ) ){ size = x86_operand_size( x86_operand_1st( insn ) ); } else if ( x86_operand_count( insn, op_explicit ) > 1 && is_memory_op( x86_operand_2nd(insn) ) ){ size = x86_operand_size( x86_operand_2nd( insn ) ); } } if ( size == 1 ) suffix = "b"; else if ( size == 2 ) suffix = "w"; else if ( size == 4 ) suffix = "l"; else if ( size == 8 ) suffix = "q"; else suffix = ""; STRNCAT( buf, suffix, len ); return ( strlen( buf ) ); }
static int format_att_mnemonic( x86_insn_t *insn, char *buf, int len) { int size = 0; char *suffix; if (! insn || ! buf || ! len ) return(0); memset( buf, 0, len ); /* intel callf/call far is always an lcall */ if (! strcmp( "callf", insn->mnemonic ) ) { STRNCAT( buf, "lcall", len ); return ( strlen( buf ) ); } /* do long jump/call prefix */ if ( insn->type == insn_jmp || insn->type == insn_call ) { if (! is_imm_jmp( x86_operand_1st(insn) ) || (x86_operand_1st(insn))->datatype != op_byte ) { /* far jump/call, use "l" prefix */ STRNCAT( buf, "l", len ); } STRNCAT( buf, insn->mnemonic, len ); return ( strlen( buf ) ); } /* do mnemonic */ STRNCAT( buf, insn->mnemonic, len ); /* do suffixes for memory operands */ if ( x86_operand_count( insn, op_explicit ) > 0 && is_memory_op( x86_operand_1st(insn) ) ) { size = x86_operand_size( x86_operand_1st( insn ) ); } else if ( x86_operand_count( insn, op_explicit ) > 1 && is_memory_op( x86_operand_2nd(insn) ) ) { size = x86_operand_size( x86_operand_2nd( insn ) ); } if ( size == 1 ) suffix = "b"; else if ( size == 2 ) suffix = "w"; else if ( size == 4 ) suffix = "l"; else if ( size == 8 ) suffix = "q"; else suffix = ""; STRNCAT( buf, suffix, len ); return ( strlen( buf ) ); }
bool X86RTLGenerator::parseInsn(x86_insn_t &aInsn, RTLOp &aRTLOp) { size_t uOpCount = x86_operand_count(&aInsn, op_explicit); unsigned uExpectedOpCount = 0xFFFFFFFF; switch(aInsn.type) { case insn_add: aRTLOp.setType(RTLOp::OP_ADD); uExpectedOpCount = 2; break; case insn_call: aRTLOp.setType(RTLOp::OP_CALL); break; case insn_jcc: aRTLOp.setType(RTLOp::OP_JUMP); break; case insn_jmp: aRTLOp.setType(RTLOp::OP_JUMP); break; case insn_mov: aRTLOp.setType(RTLOp::OP_ASSIGN); break; case insn_return: aRTLOp.setType(RTLOp::OP_RETURN); break; case insn_sub: aRTLOp.setType(RTLOp::OP_SUBTRACT); break; case insn_test: aRTLOp.setType(RTLOp::OP_COMPARE); break; case insn_push: case insn_pop: aRTLOp.setType(RTLOp::OP_NOP); break; default: return false; } if((uOpCount >= 1) && (!parseArgument(x86_operand_1st(&aInsn), aRTLOp.getArg1()))) { return false; } if((uOpCount >= 2) && (!parseArgument(x86_operand_2nd(&aInsn), aRTLOp.getArg2()))) { return false; } if((uOpCount >= 3) && (!parseArgument(x86_operand_3rd(&aInsn), aRTLOp.getArg3()))) { return false; } return true; }