コード例 #1
0
ファイル: snesdis.c プロジェクト: P4N74/radare2
static int snesDisass(int M_flag, int X_flag, ut64 pc, RAsmOp *op, const ut8 *buf, int len){
	snes_op_t *s_op = &snes_op[buf[0]];
	int op_len = snes_op_get_size(M_flag, X_flag, s_op);
	if (len < op_len)
		return 0;
	switch (s_op->len) {
	case SNES_OP_8BIT:
		strncpy (op->buf_asm, s_op->name, sizeof (op->buf_asm) - 1);
		break;
	case SNES_OP_16BIT:
		if (*buf % 0x20 == 0x10 || *buf == 0x80) { // relative branch
			snprintf (op->buf_asm, sizeof (op->buf_asm), s_op->name, pc + 2 + (st8)buf[1]);
		} else {
			snprintf (op->buf_asm, sizeof (op->buf_asm), s_op->name, buf[1]);
		}
		break;
	case SNES_OP_24BIT:
		if (*buf == 0x44 || *buf == 0x54) { // mvp and mvn
			snprintf (op->buf_asm, sizeof (op->buf_asm), s_op->name, buf[1], buf[2]);
		} else if (*buf == 0x82) { // brl
			snprintf (op->buf_asm, sizeof (op->buf_asm), s_op->name, pc + 3 + (st16)ut8p_bw(buf+1));
		} else {
			snprintf (op->buf_asm, sizeof (op->buf_asm), s_op->name, ut8p_bw(buf+1));
		}
		break;
	case SNES_OP_32BIT:
		snprintf (op->buf_asm, sizeof (op->buf_asm), s_op->name, buf[1]|buf[2]<<8|buf[3]<<16);
		break;
	case SNES_OP_IMM_M:
		if (M_flag) {
			snprintf (op->buf_asm, sizeof (op->buf_asm), "%s #0x%02x",
				s_op->name, buf[1]);
		} else {
			snprintf (op->buf_asm, sizeof (op->buf_asm), "%s #0x%04x",
				s_op->name, ut8p_bw (buf+1));
		}
		break;
	case SNES_OP_IMM_X:
		if (X_flag) {
			snprintf (op->buf_asm, sizeof (op->buf_asm), "%s #0x%02x",
				s_op->name, buf[1]);
		} else {
			snprintf (op->buf_asm, sizeof (op->buf_asm), "%s #0x%04x",
				s_op->name, ut8p_bw (buf+1));
		}
		break;
	}
	return op_len;
}
コード例 #2
0
ファイル: bin_omf.c プロジェクト: 13572293130/radare2
static int check_bytes(const ut8 *buf, ut64 length) {
	if ((*buf != 0x80 && *buf != 0x82) || length < 4)
		return false;

	ut16 rec_size = ut8p_bw (buf + 1);
	ut8 str_size = *(buf + 3);
	if (str_size + 2 != rec_size || length < rec_size + 3)
		return false;

	// check that the string is ASCII
	int i;
	for (i = 4; i < str_size + 4; ++i)
		if (buf[i] > 0x7f)
			return false;

	return r_bin_checksum_omf_ok((char *)buf, length);
}