Example #1
0
static int format_operand_att( x86_op_t *op, x86_insn_t *insn, char *buf,
                               int len) {

    char str[MAX_OP_STRING];

    memset (str, 0, sizeof str);

    switch ( op->type ) {
    case op_register:
        STRNCATF( buf, "%%%s", op->data.reg.name, len );
        break;

    case op_immediate:
        get_operand_data_str( op, str, sizeof str );
        STRNCATF( buf, "$%s", str, len );
        break;

    case op_relative_near:
        STRNCATF( buf, "0x%08X",
                  (unsigned int)(op->data.sbyte +
                                 insn->addr + insn->size), len );
        break;

    case op_relative_far:
        if (op->datatype == op_word) {
            STRNCATF( buf, "0x%08X",
                      (unsigned int)(op->data.sword +
                                     insn->addr + insn->size), len );
        } else {
            STRNCATF( buf, "0x%08X",
                      (unsigned int)(op->data.sdword +
                                     insn->addr + insn->size), len );
        }
        break;

    case op_absolute:
    case op_offset:
        /* ATT requires a '*' before absolute JMP/CALL ops */
        if (insn->type == insn_jmp || insn->type == insn_call)
            STRNCAT( buf, "*", len );

        len -= format_seg( op, buf, len, att_syntax );
        STRNCATF( buf, "0x%08lX", op->data.sdword, len );
        break;

    case op_expression:
        len -= format_seg( op, buf, len, att_syntax );
        len -= format_expr( &op->data.expression, buf, len,
                            att_syntax );
        break;
    case op_unused:
    case op_unknown:
        /* return 0-truncated buffer */
        break;
    }

    return ( strlen( buf ) );
}
Example #2
0
static int format_operand_native( x86_op_t *op, x86_insn_t *insn, char *buf,
                                  int len) {

    char str[MAX_OP_STRING];

    switch (op->type) {
    case op_register:
        STRNCAT( buf, op->data.reg.name, len );
        break;

    case op_immediate:
        get_operand_data_str( op, str, sizeof str );
        STRNCAT( buf, str, len );
        break;

    case op_relative_near:
        STRNCATF( buf, "0x%08X",
                  (unsigned int)(op->data.sbyte +
                                 insn->addr + insn->size), len );
        break;

    case op_relative_far:
        if ( op->datatype == op_word ) {
            STRNCATF( buf, "0x%08X",
                      (unsigned int)(op->data.sword +
                                     insn->addr + insn->size), len );
            break;
        } else {
            STRNCATF( buf, "0x%08lX", op->data.sdword +
                      insn->addr + insn->size, len );
        }
        break;

    case op_absolute:
    case op_offset:
        len -= format_seg( op, buf, len, native_syntax );
        STRNCATF( buf, "0x%08lX", op->data.sdword, len );
        break;

    case op_expression:
        len -= format_seg( op, buf, len, native_syntax );
        len -= format_expr( &op->data.expression, buf, len,
                            native_syntax );
        break;
    case op_unused:
    case op_unknown:
        /* return 0-truncated buffer */
        break;
    }

    return( strlen( buf ) );
}
static int format_operand_raw( x86_op_t *op, x86_insn_t *insn, char *buf,
                               int len){

        char str[MAX_OP_RAW_STRING];
	char *datatype = get_operand_datatype_str(op);

        switch (op->type) {
                case op_register:

                        get_operand_regtype_str( op->data.reg.type, str,
                                                 sizeof str );

                        STRNCAT( buf, "reg|", len );
                        STRNCATF( buf, "%s|", datatype, len );
                        STRNCATF( buf, "%s:", op->data.reg.name, len );
                        STRNCATF( buf, "%s:", str, len );
                        STRNCATF( buf, "%d|", op->data.reg.size, len );
                        break;

                case op_immediate:

                        get_operand_data_str( op, str, sizeof str );

                        STRNCAT( buf, "immediate|", len );
                        STRNCATF( buf, "%s|", datatype, len );
                        STRNCATF( buf, "%s|", str, len );
                        break;

                case op_relative_near:
			/* NOTE: in raw format, we print the
			 * relative offset, not the actual
			 * address of the jump target */

                        STRNCAT( buf, "relative|", len );
                        STRNCATF( buf, "%s|", datatype, len );
                        STRNCATF( buf, "%hhd|", op->data.sbyte, len );
                        break;

                case op_relative_far:

                        STRNCAT( buf, "relative|", len );
                        STRNCATF( buf, "%s|", datatype, len );

                        if (op->datatype == op_word) {
                                STRNCATF( buf, "%hd|", op->data.sword, len);
                                break;
                        } else {
                        	STRNCATF( buf, "%d|", op->data.sdword, len );
			}
                        break;

                case op_absolute:

                        STRNCAT( buf, "absolute_address|", len );
                        STRNCATF( buf, "%s|", datatype, len );

                        STRNCATF( buf, "$0x%04hX:", op->data.absolute.segment,
				len );
			if (op->datatype == op_descr16) {
                        	STRNCATF( buf, "0x%04hX|", 
					op->data.absolute.offset.off16, len );
			} else {
                        	STRNCATF( buf, "0x%08X|", 
					op->data.absolute.offset.off32, len );
			}

                        break;

                case op_expression:

                        STRNCAT( buf, "address_expression|", len );
                        STRNCATF( buf, "%s|", datatype, len );

                        len -= format_seg( op, buf, len, native_syntax );
                        len -= format_expr( &op->data.expression, buf, len,
                                     raw_syntax );

                        STRNCAT( buf, "|", len );
                        break;

                case op_offset:

                        STRNCAT( buf, "segment_offset|", len );
                        STRNCATF( buf, "%s|", datatype, len );

                        len -= format_seg( op, buf, len, xml_syntax );

                        STRNCATF( buf, "%08X|", op->data.sdword, len );
                        break;

                case op_unused:
                case op_unknown:
                        /* return 0-truncated buffer */
                        break;
        }

        return( strlen( buf ) );
}
static int format_operand_xml( x86_op_t *op, x86_insn_t *insn, char *buf,
                               int len){

        char str[MAX_OP_STRING] = "\0";

        switch (op->type) {
                case op_register:

                        get_operand_regtype_str( op->data.reg.type, str,
                                                 sizeof str );

                        STRNCAT( buf, "\t\t<register ", len );
                        STRNCATF( buf, "name=\"%s\" ", op->data.reg.name, len );
                        STRNCATF( buf, "type=\"%s\" ", str, len );
                        STRNCATF( buf, "size=%d/>\n", op->data.reg.size, len );
                        break;

                case op_immediate:

                        get_operand_data_str( op, str, sizeof str );

                        STRNCAT( buf, "\t\t<immediate ", len );
                        STRNCATF( buf, "type=\"%s\" ",
                                  get_operand_datatype_str (op), len );
                        STRNCATF( buf, "value=\"%s\"/>\n", str, len );
                        break;

                case op_relative_near:
                        STRNCAT( buf, "\t\t<relative_offset ", len );

                        STRNCATF( buf, "value=\"0x%08X\"/>\n",
                                  (unsigned int)(op->data.sbyte +
                                  insn->addr + insn->size), len );
                        break;

                case op_relative_far:
                        STRNCAT( buf, "\t\t<relative_offset ", len );

                        if (op->datatype == op_word) {
                                STRNCATF( buf, "value=\"0x%08X\"/>\n",
                                          (unsigned int)(op->data.sword +
                                          insn->addr + insn->size), len);
                                break;
                        } else {

                        	STRNCATF( buf, "value=\"0x%08X\"/>\n",
                                      op->data.sdword + insn->addr + insn->size,
                                      len );
			}
                        break;

                case op_absolute:

                        STRNCATF( buf, 
				"\t\t<absolute_address segment=\"0x%04hX\"",
                        	op->data.absolute.segment, len );

			if (op->datatype == op_descr16) {
                        	STRNCATF( buf, "offset=\"0x%04hX\">", 
					op->data.absolute.offset.off16, len );
			} else {
                        	STRNCATF( buf, "offset=\"0x%08X\">", 
					op->data.absolute.offset.off32, len );
			}

                        STRNCAT( buf, "\t\t</absolute_address>\n", len );
                        break;

                case op_expression:
			

                        STRNCAT( buf, "\t\t<address_expression>\n", len );

                        len -= format_seg( op, buf, len, xml_syntax );
                        len -= format_expr( &op->data.expression, buf, len,
                                     xml_syntax );

                        STRNCAT( buf, "\t\t</address_expression>\n", len );
                        break;

                case op_offset:

                        STRNCAT( buf, "\t\t<segment_offset>\n", len );

                        len -= format_seg( op, buf, len, xml_syntax );

                        STRNCAT( buf, "\t\t\t<address ", len);
                        STRNCATF( buf, "value=\"0x%08X\"/>\n",
                                          op->data.sdword, len );
                        STRNCAT( buf, "\t\t</segment_offset>\n", len );
                        break;

                case op_unused:
                case op_unknown:
                        /* return 0-truncated buffer */
                        break;
        }

        return( strlen( buf ) );
}
Example #5
0
static int format_operand_raw( x86_op_t *op, x86_insn_t *insn, char *buf,
                               int len) {

    char str[MAX_OP_RAW_STRING];
    char *datatype = get_operand_datatype_str(op);

    switch (op->type) {
    case op_register:

        get_operand_regtype_str( op->data.reg.type, str,
                                 sizeof str );

        STRNCAT( buf, "reg|", len );
        STRNCATF( buf, "%s|", datatype, len );
        STRNCATF( buf, "%s:", op->data.reg.name, len );
        STRNCATF( buf, "%s:", str, len );
        STRNCATF( buf, "%d|", op->data.reg.size, len );
        break;

    case op_immediate:

        get_operand_data_str( op, str, sizeof str );

        STRNCAT( buf, "immediate|", len );
        STRNCATF( buf, "%s|", datatype, len );
        STRNCATF( buf, "%s|", str, len );
        break;

    case op_relative_near:

        STRNCAT( buf, "relative|", len );
        STRNCATF( buf, "%s|", datatype, len );
        STRNCATF( buf, "%08X|",
                  (unsigned int)(op->data.sbyte +
                                 insn->addr + insn->size), len );
        break;

    case op_relative_far:

        STRNCAT( buf, "relative|", len );
        STRNCATF( buf, "%s|", datatype, len );

        if (op->datatype == op_word) {
            STRNCATF( buf, "%08X",
                      (unsigned int)(op->data.sword +
                                     insn->addr + insn->size), len);
            break;
        } else {
            STRNCATF( buf, "%08lX|",
                      op->data.sdword + insn->addr + insn->size,
                      len );
        }
        break;

    case op_absolute:

        STRNCAT( buf, "absolute_address|", len );
        STRNCATF( buf, "%s|", datatype, len );

        len -= format_seg( op, buf, len, native_syntax );

        STRNCATF( buf, "%08lX|", op->data.sdword, len );

        break;

    case op_expression:

        STRNCAT( buf, "address_expression|", len );
        STRNCATF( buf, "%s|", datatype, len );

        len -= format_seg( op, buf, len, native_syntax );
        len -= format_expr( &op->data.expression, buf, len,
                            raw_syntax );

        STRNCAT( buf, "|", len );
        break;

    case op_offset:

        STRNCAT( buf, "segment_offset|", len );
        STRNCATF( buf, "%s|", datatype, len );

        len -= format_seg( op, buf, len, xml_syntax );

        STRNCATF( buf, "%08lX|", op->data.sdword, len );
        break;

    case op_unused:
    case op_unknown:
        /* return 0-truncated buffer */
        break;
    }

    return( strlen( buf ) );
}