19 #include "../../asm/arch/snes/snes_op_table.h"
20 #include "../../asm/arch/6502/6502_il.inc"
58 switch (data[0] & 0x1f) {
61 imm =
len > 1 ? data[1] : 0;
63 snprintf(esiladdr_out, esiladdr_size,
"0x%02x", (
unsigned int)
imm);
66 _6502_il_immediate(il_out,
imm);
71 imm =
len > 1 ? data[1] : 0;
73 snprintf(esiladdr_out, esiladdr_size,
"0x%02x", (
unsigned int)
imm);
76 _6502_il_addr_absolute(il_out,
imm);
81 imm =
len > 1 ? data[1] : 0;
83 snprintf(esiladdr_out, esiladdr_size,
"x,0x%02x,+", (
unsigned int)
imm);
86 _6502_il_addr_zero_page_reg(il_out,
imm,
"x");
93 snprintf(esiladdr_out, esiladdr_size,
"0x%04x", (
unsigned int)
imm);
96 _6502_il_addr_absolute(il_out,
imm);
104 snprintf(esiladdr_out, esiladdr_size,
"x,0x%04x,+", (
unsigned int)
imm);
107 _6502_il_addr_reg(il_out,
imm,
"x");
115 snprintf(esiladdr_out, esiladdr_size,
"y,0x%04x,+", (
unsigned int)
imm);
118 _6502_il_addr_reg(il_out,
imm,
"y");
125 snprintf(esiladdr_out, esiladdr_size,
"x,0x%02x,+,[2]", (
unsigned int)
imm);
128 _6502_il_addr_indirect_x(il_out,
imm);
134 imm =
len > 1 ? data[1] : 0;
136 snprintf(esiladdr_out, esiladdr_size,
"y,0x%02x,[2],+", (
unsigned int)
imm);
139 _6502_il_addr_indirect_y(il_out,
imm);
147 char *addrbuf,
int addrsize,
const char *
reg,
154 switch (data[0] & 0x1f) {
157 imm = (
len > 1) ? data[1] : 0;
158 snprintf(addrbuf, addrsize,
"0x%02x", (
unsigned int)
imm);
160 _6502_il_immediate(il_out,
imm);
167 _6502_il_accumulator(il_out);
172 imm = (
len > 1) ? data[1] : 0;
173 snprintf(addrbuf, addrsize,
"0x%02x", (
unsigned int)
imm);
175 _6502_il_addr_absolute(il_out,
imm);
180 imm = (
len > 1) ? data[1] : 0;
183 _6502_il_addr_zero_page_reg(il_out,
imm,
reg);
188 imm = (
len > 2) ? data[1] | data[2] << 8 : 0;
191 _6502_il_addr_absolute(il_out,
imm);
196 imm = (
len > 2) ? data[1] | data[2] << 8 : 0;
199 _6502_il_addr_reg(il_out,
imm,
reg);
207 char *addrbuf,
int addrsize,
const char *
reg,
214 switch (data[0] & 0x1f) {
217 imm = (
len > 1) ? data[1] : 0;
220 _6502_il_immediate(il_out,
imm);
227 _6502_il_accumulator(il_out);
232 imm = (
len > 1) ? data[1] : 0;
235 _6502_il_addr_absolute(il_out,
imm);
240 imm = (
len > 1) ? data[1] : 0;
243 _6502_il_addr_zero_page_reg(il_out,
imm,
reg);
248 imm = (
len > 2) ? data[1] | data[2] << 8 : 0;
251 _6502_il_addr_absolute(il_out,
imm);
256 imm = (
len > 2) ? data[1] | data[2] << 8 : 0;
259 _6502_il_addr_reg(il_out,
imm,
reg);
319 const char *
src =
"unk";
320 const char *
dst =
"unk";
361 char *
reg = (data0 == 0x08) ?
"flags" :
"a";
369 char *
reg = (data0 == 0x28) ?
"flags" :
"a";
417 const int buffsize =
sizeof(addrbuf) - 1;
427 _6502ILAddr il_addr = { 0 };
550 rz_strbuf_set(&
op->esil,
",1,I,=,0,D,=,flags,0x10,|,0x100,sp,+,=[1],pc,1,+,0xfe,sp,+,=[2],3,sp,-=,0xfffe,[2],pc,=");
569 op->il_op = _6502_il_op_flag(data[0]);
577 rz_strbuf_setf(&
op->esil,
"%s,[1],0x80,&,!,!,N,=,%s,[1],0x40,&,!,!,V,=,a,%s,[1],&,0xff,&,!,Z,=", addrbuf, addrbuf, addrbuf);
579 op->il_op = _6502_il_op_bit(il_addr_ptr);
595 if (data[0] == 0x69) {
596 rz_strbuf_setf(&
op->esil,
"%s,a,+=,7,$c,C,a,+=,7,$c,|,C,:=", addrbuf);
598 rz_strbuf_setf(&
op->esil,
"%s,[1],a,+=,7,$c,C,a,+=,7,$c,|,C,:=", addrbuf);
604 op->il_op = _6502_il_op_adc(il_addr_ptr);
620 if (data[0] == 0xe9) {
629 op->il_op = _6502_il_op_sbc(il_addr_ptr);
651 op->il_op = _6502_il_op_ora(il_addr_ptr);
674 op->il_op = _6502_il_op_and(il_addr_ptr);
688 if (data[0] == 0x49) {
695 op->il_op = _6502_il_op_eor(il_addr_ptr);
706 if (data[0] == 0x0a) {
707 rz_strbuf_set(&
op->esil,
"1,a,<<=,7,$c,C,:=,a,a,=");
709 rz_strbuf_setf(&
op->esil,
"1,%s,[1],<<,%s,=[1],7,$c,C,:=", addrbuf, addrbuf);
713 op->il_op = _6502_il_op_asl(il_addr_ptr);
724 if (data[0] == 0x4a) {
727 rz_strbuf_setf(&
op->esil,
"1,%s,[1],&,C,=,1,%s,[1],>>,%s,=[1]", addrbuf, addrbuf, addrbuf);
731 op->il_op = _6502_il_op_lsr(il_addr_ptr);
742 if (data[0] == 0x2a) {
743 rz_strbuf_set(&
op->esil,
"1,a,<<,C,|,a,=,7,$c,C,:=,a,a,=");
745 rz_strbuf_setf(&
op->esil,
"1,%s,[1],<<,C,|,%s,=[1],7,$c,C,:=", addrbuf, addrbuf);
749 op->il_op = _6502_il_op_rol(il_addr_ptr);
762 if (data[0] == 0x6a) {
763 rz_strbuf_set(&
op->esil,
"C,N,=,1,a,&,C,=,1,a,>>,7,N,<<,|,a,=");
765 rz_strbuf_setf(&
op->esil,
"C,N,=,1,%s,[1],&,C,=,1,%s,[1],>>,7,N,<<,|,%s,=[1]", addrbuf, addrbuf, addrbuf);
769 op->il_op = _6502_il_op_ror(il_addr_ptr);
782 op->il_op = _6502_il_op_inc(il_addr_ptr,
true);
795 op->il_op = _6502_il_op_inc(il_addr_ptr,
false);
805 op->il_op = _6502_il_op_inc_reg(data[0] == 0xe8 ?
"x" :
"y",
true);
815 op->il_op = _6502_il_op_inc_reg(data[0] == 0xca ?
"x" :
"y",
false);
829 if (data[0] == 0xc9) {
838 op->il_op = _6502_il_op_cmp(
"a", il_addr_ptr);
847 if (data[0] == 0xe0) {
856 op->il_op = _6502_il_op_cmp(
"x", il_addr_ptr);
865 if (data[0] == 0xc0) {
874 op->il_op = _6502_il_op_cmp(
"y", il_addr_ptr);
892 if (data[1] <= 127) {
893 op->jump =
addr + data[1] +
op->size;
895 op->jump =
addr - (256 - data[1]) +
op->size;
905 op->il_op = _6502_il_op_branch(data[0],
op->jump);
912 op->jump = (
len > 2) ? data[1] | data[2] << 8 : 0;
918 rz_strbuf_setf(&
op->esil,
"1,pc,-,0xff,sp,+,=[2],0x%04" PFMT64x ",pc,=,2,sp,-=",
op->jump);
920 op->il_op = _6502_il_op_jsr(
op->jump,
addr);
927 op->jump = (
len > 2) ? data[1] | data[2] << 8 : 0;
930 op->il_op = _6502_il_op_jmp(
op->jump,
false);
936 ut16 imm =
len > 2 ? data[1] | data[2] << 8 : 0;
939 op->il_op = _6502_il_op_jmp(
imm,
true);
952 rz_strbuf_set(&
op->esil,
"0x101,sp,+,[2],pc,=,pc,++=,2,sp,+=");
954 op->il_op = _6502_il_op_rts();
966 rz_strbuf_set(&
op->esil,
"0x101,sp,+,[1],flags,=,0x102,sp,+,[2],pc,=,3,sp,+=");
968 op->il_op = _6502_il_op_rti();
990 if (data[0] == 0xa9) {
997 op->il_op = _6502_il_op_ld(
"a", il_addr_ptr);
1008 if (data[0] == 0xa2) {
1015 op->il_op = _6502_il_op_ld(
"x", il_addr_ptr);
1026 if (data[0] == 0xa0) {
1033 op->il_op = _6502_il_op_ld(
"y", il_addr_ptr);
1048 op->il_op = _6502_il_op_st(
"a", il_addr_ptr);
1059 op->il_op = _6502_il_op_st(
"x", il_addr_ptr);
1070 op->il_op = _6502_il_op_st(
"y", il_addr_ptr);
1082 if (data[0] == 0x08) {
1083 op->il_op = _6502_il_op_php();
1085 op->il_op = _6502_il_op_pha();
1098 if (data[0] == 0x28) {
1099 op->il_op = _6502_il_op_plp();
1101 op->il_op = _6502_il_op_pla();
1114 op->il_op = _6502_il_op_transfer(
1115 data[0] == 0xaa ?
"x" : (data[0] == 0xa8 ?
"y" :
"a"),
1116 data[0] == 0x8a ?
"x" : (data[0] == 0x98 ?
"y" :
"a"),
1128 op->il_op = _6502_il_op_transfer(
"sp",
"x",
false);
1137 op->il_op = _6502_il_op_transfer(
"x",
"sp",
true);
1154 "gpr flags .8 3 0\n"
1195 .desc =
"6502/NES analysis plugin",
1208 #ifndef RZ_PLUGIN_INCORE
static void _6502_analysis_esil_push(RzAnalysisOp *op, ut8 data0)
static void _6502_analysis_esil_get_addr_pattern3(RzAnalysisOp *op, const ut8 *data, size_t len, char *addrbuf, int addrsize, const char *reg, RZ_NULLABLE _6502ILAddr *il_out)
static char * get_reg_profile(RzAnalysis *analysis)
static RzAnalysisILConfig * il_config(RzAnalysis *analysis)
RzAnalysisPlugin rz_analysis_plugin_6502
static void _6502_analysis_esil_get_addr_pattern2(RzAnalysisOp *op, const ut8 *data, size_t len, char *addrbuf, int addrsize, const char *reg, RZ_NULLABLE _6502ILAddr *il_out)
static void _6502_analysis_esil_ccall(RzAnalysisOp *op, ut8 data0)
RZ_API RzLibStruct rizin_plugin
static void _6502_analysis_esil_update_flags(RzAnalysisOp *op, int flags)
static int esil_6502_fini(RzAnalysisEsil *esil)
static int address_bits(RzAnalysis *analysis, int bits)
static void _6502_analysis_esil_get_addr_pattern1(RzAnalysisOp *op, const ut8 *data, size_t len, RZ_NULLABLE char *esiladdr_out, int esiladdr_size, RZ_NULLABLE _6502ILAddr *il_out)
static void _6502_analysis_esil_mov(RzAnalysisOp *op, ut8 data0)
static int _6502_op(RzAnalysis *analysis, RzAnalysisOp *op, ut64 addr, const ut8 *data, int len, RzAnalysisOpMask mask)
static void _6502_analysis_esil_flags(RzAnalysisOp *op, ut8 data0)
static int esil_6502_init(RzAnalysisEsil *esil)
static void _6502_analysis_esil_inc_reg(RzAnalysisOp *op, ut8 data0, char *sign)
static void _6502_analysis_esil_pop(RzAnalysisOp *op, ut8 data0)
RZ_API RZ_OWN RzAnalysisILConfig * rz_analysis_il_config_new(ut32 pc_size, bool big_endian, ut32 mem_key_size)
int bits(struct state *s, int need)
RZ_API RZ_OWN RzILOpEffect * rz_il_op_new_nop()
return strdup("=SP r13\n" "=LR r14\n" "=PC r15\n" "=A0 r0\n" "=A1 r1\n" "=A2 r2\n" "=A3 r3\n" "=ZF zf\n" "=SF nf\n" "=OF vf\n" "=CF cf\n" "=SN or0\n" "gpr lr .32 56 0\n" "gpr pc .32 60 0\n" "gpr cpsr .32 64 0 ____tfiae_________________qvczn\n" "gpr or0 .32 68 0\n" "gpr tf .1 64.5 0 thumb\n" "gpr ef .1 64.9 0 endian\n" "gpr jf .1 64.24 0 java\n" "gpr qf .1 64.27 0 sticky_overflow\n" "gpr vf .1 64.28 0 overflow\n" "gpr cf .1 64.29 0 carry\n" "gpr zf .1 64.30 0 zero\n" "gpr nf .1 64.31 0 negative\n" "gpr itc .4 64.10 0 if_then_count\n" "gpr gef .4 64.16 0 great_or_equal\n" "gpr r0 .32 0 0\n" "gpr r1 .32 4 0\n" "gpr r2 .32 8 0\n" "gpr r3 .32 12 0\n" "gpr r4 .32 16 0\n" "gpr r5 .32 20 0\n" "gpr r6 .32 24 0\n" "gpr r7 .32 28 0\n" "gpr r8 .32 32 0\n" "gpr r9 .32 36 0\n" "gpr r10 .32 40 0\n" "gpr r11 .32 44 0\n" "gpr r12 .32 48 0\n" "gpr r13 .32 52 0\n" "gpr r14 .32 56 0\n" "gpr r15 .32 60 0\n" "gpr r16 .32 64 0\n" "gpr r17 .32 68 0\n")
static int is_immediate(ut32 instr)
RZ_API RzRegItem * rz_reg_get(RzReg *reg, const char *name, int type)
RZ_API bool rz_reg_set_value(RzReg *reg, RzRegItem *item, ut64 value)
@ RZ_ANALYSIS_OP_TYPE_CMP
@ RZ_ANALYSIS_OP_TYPE_SUB
@ RZ_ANALYSIS_OP_TYPE_LOAD
@ RZ_ANALYSIS_OP_TYPE_UNK
@ RZ_ANALYSIS_OP_TYPE_ROL
@ RZ_ANALYSIS_OP_TYPE_JMP
@ RZ_ANALYSIS_OP_TYPE_AND
@ RZ_ANALYSIS_OP_TYPE_UJMP
@ RZ_ANALYSIS_OP_TYPE_ROR
@ RZ_ANALYSIS_OP_TYPE_SWI
@ RZ_ANALYSIS_OP_TYPE_CALL
@ RZ_ANALYSIS_OP_TYPE_ADD
@ RZ_ANALYSIS_OP_TYPE_STORE
@ RZ_ANALYSIS_OP_TYPE_PUSH
@ RZ_ANALYSIS_OP_TYPE_SHR
@ RZ_ANALYSIS_OP_TYPE_POP
@ RZ_ANALYSIS_OP_TYPE_CJMP
@ RZ_ANALYSIS_OP_TYPE_MOV
@ RZ_ANALYSIS_OP_TYPE_SHL
@ RZ_ANALYSIS_OP_TYPE_ILL
@ RZ_ANALYSIS_OP_TYPE_RET
@ RZ_ANALYSIS_OP_TYPE_NOP
@ RZ_ANALYSIS_OP_TYPE_XOR
RZ_API const char * rz_strbuf_set(RzStrBuf *sb, const char *s)
RZ_API bool rz_strbuf_append(RzStrBuf *sb, const char *s)
RZ_API const char * rz_strbuf_setf(RzStrBuf *sb, const char *fmt,...) RZ_PRINTF_CHECK(2
RZ_API void rz_strbuf_init(RzStrBuf *sb)
static struct sockaddr static addrlen static backlog const void static flags void flags
static snes_op_t snes_op[]
static int snes_op_get_size(int M_flag, int X_flag, snes_op_t *op)
Description of the global context of an RzAnalysisILVM.
ut64(WINAPI *w32_GetEnabledXStateFeatures)()