44 res = (
val >> 10) & 1;
47 fprintf(stderr,
"Invalid token %s\n", ins);
58 ut32 ins_len,
ut32 magic_value,
int *err_code) {
65 return get_q_bits(magic_value, ins, ins_len, err_code);
68 op_str =
ins_str[1 + hash_code * 4];
72 for (
i = 0;
i < ins_len;
i++) {
73 aux = strchr(&op_str[
x], ins[
i]);
75 aux = strchr(op_str, ins[
i]);
77 fprintf(stderr,
"Invalid token %s\n", ins);
83 len = (
unsigned int)(aux - op_str);
89 res = (res * 2) | ((op_b >> ((1023 -
len) % 8)) & 1);
96 printf(
"INS_BITS => 0x%x\n", res);
106 if ((ins_bits <= 31) | (ins_bits >= 128 && ins_bits < 160)) {
108 }
else if (ins_bits >= 32 && ins_bits <= 252) {
111 fprintf(stderr,
"Invalid arg: %u\n", ins_bits);
119 ut32 *ret_ins_bits,
int *err_code) {
131 ((ins_bits & 1) << 6));
135 fprintf(stderr,
"invalid register! %s\n", reg_arg);
146 fprintf(stderr,
"invalid register! %s\n", reg_arg);
166 if (hash_code == 0xDF || hash_code == 0xE0) {
167 *ret_ins_bits = ins_bits;
224 ut32 *reg_len_dec,
ut32 *ret_ins_bits,
ut32 magic_value,
ut8 two_ins,
int *err_code) {
230 char *res_decode =
NULL;
236 ins =
ins_str[1 + 2 + hash_code * 4];
238 fprintf(stderr,
"Invalid instruction hash %x\n", hash_code);
242 if (hash_code == 0x19C) {
244 reg_len_dec, magic_value, ins_pos + ins_off, ins_len, two_ins, err_code);
251 printf(
"PSEUDO INS %s\n", ins);
256 *ins_len_dec = ins_len;
261 aux = strchr(
pos,
'`');
262 if (!aux ||
pos == aux) {
263 fprintf(stderr,
"Invalid instruction %s\n", ins);
270 fprintf(stderr,
"Invalid length token %d\n",
len);
277 token_aux[
len] =
'\0';
281 printf(
"TOKEN AUX: %s\n", token_aux);
285 for (
i = 0;
i <
len;
i++) {
286 if (token_aux[
i] ==
',') {
287 len = (
unsigned int)(
size_t)(&token_aux[
i] - token_aux);
288 reg = &token_aux[
i + 1];
298 reg_len_dec, magic_value, ins_pos + ins_off, ins_len, two_ins, err_code);
304 printf(
"RET TOKEN %s\n", res_decode);
309 res_decode =
strcat_dup(res_decode, token_aux, 1);
315 printf(
"RESULT DECODE: %s\n", res_decode);
356 *magic_value |= 0x10;
359 *magic_value |= 0x20;
362 *magic_value |= 0x40;
365 *magic_value |= 0x80;
368 *magic_value |= 0x100;
371 *magic_value |= 0x200;
374 *magic_value |= 0x400;
377 fprintf(stderr,
"invalid hash code 0x%x for magic value 0x%x\n", hash_code, *magic_value);
383 st32 *ins_hash_code,
int *err_code) {
384 st32 hash_code, hash_aux;
385 ut32 reg_len_dec, ins_len_dec, ret_ins_bits;
386 char *ins_res =
NULL, *ins_aux =
NULL;
387 ut32 magic_value = 0x800;
397 hash_aux = hash_code;
409 if (ins_hash_code !=
NULL) {
410 *ins_hash_code = hash_code;
414 printf(
"MAGIC VALUE 0x%x\n", 0x800);
417 if (hash_aux == 0x1E1 || hash_aux == 0x1E2) {
418 ins_aux =
decode_ins(hash_aux, ins_pos, ins_off, &ins_len_dec, ®_len_dec,
419 &ret_ins_bits, magic_value, two_ins, err_code);
426 if (hash_code == 0x223) {
430 *next_ins_pos = *next_ins_pos + 1;
433 ins_aux =
decode_ins(hash_code, ins_pos, ins_off, &ins_len_dec,
434 ®_len_dec, &ret_ins_bits, magic_value, two_ins, err_code);
442 *next_ins_pos += ins_len_dec;
449 ut8 opcode, two_ins = 0;
450 ut32 next_ins1_pos, next_ins2_pos;
452 char *ins1, *ins2, *aux, *ins_res;
462 if ((opcode & 0xF0) == 0x30) {
463 two_ins = opcode & 0x0F;
473 ins1 =
do_decode(1, ins_pos, two_ins, &next_ins1_pos, &hash_code, &err_code);
478 ins2 =
do_decode(next_ins1_pos + 1, ins_pos, two_ins, &next_ins2_pos,
NULL, &err_code);
484 *next_ins_pos = next_ins2_pos;
486 if (hash_code == 0xF0 || hash_code == 0xF1) {
495 *next_ins_pos = next_ins1_pos + next_ins2_pos + 1;
496 if (*next_ins_pos != two_ins) {
503 ins_res =
do_decode(0, ins_pos, two_ins, &next_ins1_pos, &hash_code, &err_code);
508 *next_ins_pos = next_ins1_pos;
516 op = (ins_bits >> 6) | 16 * (ins_bits & 3);
517 op2 = (ins_bits >> 2) & 0xF;
519 return (
op == 26 ||
op == 30 || (op3 > 7 && op3 != 15));
523 char *reg_arg,
ut32 *ret_ins_bits,
ut32 *ret_reg_len,
ut32 magic_value,
524 ut32 ins_pos,
ut32 ins_len,
ut8 two_ins,
int *err_code) {
525 ut32 tok_op, ins_bits;
529 ut32 ret_len = 0, flag;
534 ins_bits =
get_ins_bits(hash_code, ins_pos, ins_token, ins_token_len, magic_value, err_code);
538 tok_op = *ins_token - 0x23;
541 printf(
"WAY ins_bits: OP = %d 0x%x %s %d %d\n", tok_op, ins_bits, ins_token, ins_token_len, ins_pos);
555 if (!reg_arg || *reg_arg ==
'\0') {
556 res =
strdup(
"<register>");
559 res =
decode_regis(reg_arg, hash_code, ins_bits, ret_ins_bits, err_code);
564 case 35: res = ins_bits ?
strdup(
" || far()") :
NULL;
break;
565 case 36: res = ins_bits ?
strdup(
" || local()") :
NULL;
break;
566 case 37: res =
get_opers(ins_bits);
break;
568 res = ins_bits ?
"lo" :
"hi";
574 sprintf(buff_aux,
"#0x%x", (ins_bits << (32 - ins_token_len) >> (32 - ins_token_len)));
581 if (*reg_arg ==
'!') {
589 if (hash_code == 0xDF || hash_code == 0xE0) {
590 *ret_ins_bits = ins_bits;
592 if (!reg_arg || *reg_arg !=
'-') {
593 sprintf(buff_aux,
"#0x%lx", (
long unsigned int)ins_bits);
595 sprintf(buff_aux,
"-#0x%lx", (
long unsigned int)ins_bits);
598 if (!reg_arg || *reg_arg !=
'm') {
605 if (magic_value & 0xC0) {
608 }
else if (magic_value & 0x30) {
615 if ((reg_arg && *reg_arg ==
'L') || hash_code == 105 || hash_code == 7) {
617 fprintf(stderr,
"Ooops!!! look up address in sections!! %d", hash_code);
620 if (reg_arg && *reg_arg ==
'L') {
621 ins_bits = ins_bits << (32 - ins_token_len) >> (32 - ins_token_len);
623 if (reg_arg && *reg_arg ==
'i') {
626 sprintf(buff_aux,
"#0x%06lx", (
long unsigned int)ins_bits);
632 if (reg_arg && *reg_arg ==
'3') {
634 ins_bits = ins_bits >> 1;
637 if (magic_value & 1) {
639 }
else if (reg_arg) {
653 if (magic_value & 1) {
662 }
else if (magic_value & 2) {
665 }
else if (reg_arg) {
666 if (((magic_value & 0x10) && strchr(reg_arg,
'r')) ||
667 ((magic_value & 0x20) && strchr(reg_arg,
'w'))) {
672 ((magic_value & 0x40) && strchr(reg_arg,
'r')) ||
673 ((magic_value & 0x80000000) && strchr(reg_arg,
'w'))) {
684 *ret_reg_len = ret_len;
695 if (*reg_arg ==
'1') {
697 }
else if (*reg_arg ==
'2') {
713 if (*reg_arg ==
'H') {
715 }
else if (*reg_arg ==
'L') {
717 }
else if (*reg_arg ==
'd') {
719 }
else if (*reg_arg ==
')') {
733 if (reg_arg && *reg_arg ==
'3') {
735 ins_bits = ins_bits >> 1;
739 tok_op = ins_bits & 0xF;
740 if (magic_value & 4) {
741 if (tok_op <= 7 || tok_op == 0xF) {
745 }
else if (magic_value & 8) {
746 if (tok_op <= 7 || tok_op == 0xF) {
750 }
else if (magic_value & 2) {
753 }
else if (reg_arg) {
755 ((magic_value & 0x10) && *ins_token ==
'X' && strchr(reg_arg,
'r')) ||
756 ((magic_value & 0x20) && *ins_token ==
'Y' && strchr(reg_arg,
'w'))) {
761 ((magic_value & 0x40) && *ins_token ==
'X' && strchr(reg_arg,
'r')) ||
762 ((magic_value & 0x80000000) && *ins_token ==
'Y' && strchr(reg_arg,
'w'))
769 res = flag ?
strcat_dup(
"t3 = ", aux, 2) : aux;
779 if (*reg_arg ==
'(') {
781 }
else if (*reg_arg ==
')') {
796 if (*reg_arg ==
'(') {
798 }
else if (*reg_arg ==
')') {
813 if (*reg_arg ==
'(') {
815 }
else if (*reg_arg ==
')') {
817 }
else if (*reg_arg ==
'a') {
832 if (*reg_arg ==
'(') {
834 }
else if (*reg_arg ==
')') {
843 res = (ins_bits != 0) ?
strdup(
"t3 = ") :
NULL;
852 if (*reg_arg ==
'(') {
854 }
else if (*reg_arg ==
')') {
864 res = ins_bits ?
"s" :
NULL;
866 res = ins_bits ?
".cr" :
NULL;
868 res = ins_bits ?
".lr" :
NULL;
870 fprintf(stderr,
"Invalid instruction %s\n!", ins_token);
876 printf(
"OP(78): TOKEN=%s\n", res);
885 printf(
"RES = %s\n", (res) ? res :
"NULL");
ut32 get_ins_len(ut8 opcode)
static bool is_hash(st32 hash_code)
static char * decode_ins(st32 hash_code, ut32 ins_pos, ut32 ins_off, ut32 *ins_len_dec, ut32 *reg_len_dec, ut32 *ret_ins_bits, ut32 magic_value, ut8 two_ins, int *err_code)
static char * do_decode(ut32 ins_off, ut32 ins_pos, ut32 two_ins, ut32 *next_ins_pos, st32 *ins_hash_code, int *err_code)
static bool check_arg(ut32 ins_bits, int *err_code)
void set_magic_value(ut32 *magic_value, st32 hash_code, int *err_code)
static ut32 get_ins_bits(ut32 hash_code, ut32 ins_pos, char *ins, ut32 ins_len, ut32 magic_value, int *err_code)
char * c55plus_decode(ut32 ins_pos, ut32 *next_ins_pos)
static bool is_linear_circular(ut32 ins_bits)
static char * decode_regis(char *reg_arg, st32 hash_code, ut32 ins_bits, ut32 *ret_ins_bits, int *err_code)
static ut32 get_q_bits(ut32 val, char *ins, ut32 ins_len, int *err_code)
static char * get_token_decoded(st32 hash_code, char *ins_token, ut32 ins_token_len, char *reg_arg, ut32 *ret_ins_bits, ut32 *ret_reg_len, ut32 magic_value, ut32 ins_pos, ut32 ins_len, ut8 two_ins, int *err_code)
_Use_decl_annotations_ int __cdecl printf(const char *const _Format,...)
char * get_opers(ut8 oper_byte)
char * get_reg_name_2(ut32 idx)
char * get_AR_regs_class1(ut32 ins_bits)
char * get_sim_reg(char *reg_arg, ut32 ins_bits)
char * get_cmp_op(ut32 idx)
char * get_tc2_tc1(ut32 ins_bits)
char * get_trans_reg(ut32 ins_bits)
char * get_reg_pair(ut32 idx)
char * get_status_regs_and_bits(char *reg_arg, int reg_bit)
char * get_AR_regs_class2(ut32 ins_bits, ut32 *ret_len, ut32 ins_pos, ut32 idx)
char * get_reg_name_1(ut32 idx)
char * get_reg_name_3(ut32 idx)
st32 get_hash_code(ut32 ins_pos)
RZ_API void Ht_() free(HtName_(Ht) *ht)
ut32 get_ins_part(ut32 pos, ut32 len)
memcpy(mem, inblock.get(), min(CONTAINING_RECORD(inblock.get(), MEMBLOCK, data) ->size, size))
char * strcat_dup(char *s1, char *s2, st32 n_free)
char * get_hex_str(ut32 hex_num)
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")
RZ_API int rz_str_ncasecmp(const char *dst, const char *orig, size_t n)