-
Notifications
You must be signed in to change notification settings - Fork 4
/
emu.cpp
215 lines (205 loc) · 4.92 KB
/
emu.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
/*
IDA Pro Processor Module for CR16C Instruction Set
Copyright (C) 2011
Andreas Schuler <[email protected]>
Based on Simple Python Byte Code Module (Chris Eagle <[email protected]>)
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License version 2 as published
by the Free Software Foundation.
This program is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
more details.
You should have received a copy of the GNU General Public License along with
this program; if not, write to the Free Software Foundation, Inc., 59 Temple
Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include <ida.hpp>
#include <frame.hpp>
#include "cr16c.hpp"
/*
short stack_delta[256] = {
0, // STOP_CODE
1, // POP_TOP
0, // ROT_TWO
0, // ROT_THREE
-1, // DUP_TOP
0, // ROT_FOUR
0, // NULL
0, // NULL
0, // NULL
0, // NOP
0, // UNARY_POSITIVE
0, // UNARY_NEGATIVE
0, // UNARY_NOT
0, // UNARY_CONVERT
0, // NULL
0, // UNARY_INVERT
0, // NULL
0, // NULL
2, // LIST_APPEND
1, // BINARY_POWER
1, // BINARY_MULTIPLY
1, // BINARY_DIVIDE
1, // BINARY_MODULO
1, // BINARY_ADD
1, // BINARY_SUBTRACT
1, // BINARY_SUBSCR
1, // BINARY_FLOOR_DIVIDE
1, // BINARY_TRUE_DIVIDE
1, // INPLACE_FLOOR_DIVIDE
1, // INPLACE_TRUE_DIVIDE
0, // SLICE
1, // SLICE+1
1, // SLICE+2
2, // SLICE+3
0, // NULL
0, // NULL
0, // NULL
0, // NULL
0, // NULL
0, // NULL
2, // STORE_SLICE
3, // STORE_SLICE+1
3, // STORE_SLICE+2
4, // STORE_SLICE+3
0, // NULL
0, // NULL
0, // NULL
0, // NULL
0, // NULL
0, // NULL
1, // DELETE_SLICE
2, // DELETE_SLICE+1
2, // DELETE_SLICE+2
3, // DELETE_SLICE+3
0, // NULL
1, // INPLACE_ADD
1, // INPLACE_SUBTRACT
1, // INPLACE_MULTIPLY
1, // INPLACE_DIVIDE
1, // INPLACE_MODULO
3, // STORE_SUBSCR
2, // DELETE_SUBSCR
1, // BINARY_LSHIFT
1, // BINARY_RSHIFT
1, // BINARY_AND
1, // BINARY_XOR
1, // BINARY_OR
1, // INPLACE_POWER
0, // GET_ITER
0, // NULL
1, // PRINT_EXPR
1, // PRINT_ITEM
0, // PRINT_NEWLINE
2, // PRINT_ITEM_TO
1, // PRINT_NEWLINE_TO
1, // INPLACE_LSHIFT
1, // INPLACE_RSHIFT
1, // INPLACE_AND
1, // INPLACE_XOR
1, // INPLACE_OR
0, // BREAK_LOOP
0, // NULL
-1, // LOAD_LOCALS
1, // RETURN_VALUE
1, // IMPORT_STAR
3, // EXEC_STMT
1, // YIELD_VALUE
0, // POP_BLOCK
0, // END_FINALLY
2, // BUILD_CLASS
1, // STORE_NAME
0, // DELETE_NAME
128, // UNPACK_SEQUENCE
-1, // FOR_ITER
0, // NULL
2, // STORE_ATTR
1, // DELETE_ATTR
0, // STORE_GLOBAL
0, // DELETE_GLOBAL
128, // DUP_TOPX
-1, // LOAD_CONST
-1, // LOAD_NAME
128, // BUILD_TUPLE
128, // BUILD_LIST
-1, // BUILD_MAP
0, // LOAD_ATTR
1, // COMPARE_OP
-1, // IMPORT_NAME
0, // IMPORT_FROM
0, // NULL
0, // JUMP_FORWARD
0, // JUMP_IF_FALSE
0, // JUMP_IF_TRUE
0, // JUMP_ABSOLUTE
0, // NULL
0, // NULL
-1, // LOAD_GLOBAL
0, // NULL
0, // NULL
0, // CONTINUE_LOOP
0, // SETUP_LOOP
0, // SETUP_EXCEPT
0, // SETUP_FINALLY
0, // NULL
-1, // LOAD_FAST
1, // STORE_FAST
0, // DELETE_FAST
0, // NULL
0, // NULL
0, // NULL
128, // RAISE_VARARGS
128, // CALL_FUNCTION
-1, // MAKE_FUNCTION
128, // BUILD_SLICE
128, // MAKE_CLOSURE
-1, // LOAD_CLOSURE
-1, // LOAD_DEREF
1, // STORE_DEREF
0, // NULL
0, // NULL
128, // CALL_FUNCTION_VAR
128, // CALL_FUNCTION_KW
128, // CALL_FUNCTION_VAR_KW
0 // EXTENDED_ARG
};
*/
//----------------------------------------------------------------------
int idaapi cr16c_emu(void)
{
ulong feature=cmd.get_canon_feature();
if(cmd.itype==CR16C_bal)
{
for(int i=0;i<3;i++)
{
if(cmd.Operands[i].type==o_displ)
{
ua_add_cref(0,cmd.Operands[i].value,fl_CF);
break;
}
}
}
if(feature&CF_JUMP)
{
for(int i=0;i<3;i++)
{
if(cmd.Operands[i].type==o_displ)
{
ua_add_cref(0,cmd.Operands[i].value,fl_JF);
break;
}
}
}
/* //We can only resolve target addresses for relative jumps
if (cmd.auxpref & HAS_JREL) {
ua_add_cref(cmd.Op1.offb, cmd.Op1.addr, fl_JN);
}*/
//Add the sequential flow as long as CF_STOP is not set
//if((cmd.get_canon_feature() & CF_STOP) == 0) {
//cmd.ea + cmd.size computes the address of the next instruction
if((cmd.get_canon_feature() & CF_STOP) == 0)
ua_add_cref(0, cmd.ea + cmd.size, fl_F);
//}
return 1;
}