Rizin
unix-like reverse engineering framework and cli tools
analysis_ppc_cs.c File Reference
#include <rz_analysis.h>
#include <rz_lib.h>
#include <capstone/capstone.h>
#include <capstone/ppc.h>
#include "../../asm/arch/ppc/libvle/vle.h"

Go to the source code of this file.

Classes

struct  Getarg
 

Macros

#define SPR_HID0   0x3f0 /* Hardware Implementation Register 0 */
 
#define SPR_HID1   0x3f1 /* Hardware Implementation Register 1 */
 
#define SPR_HID2   0x3f3 /* Hardware Implementation Register 2 */
 
#define SPR_HID4   0x3f4 /* Hardware Implementation Register 4 */
 
#define SPR_HID5   0x3f6 /* Hardware Implementation Register 5 */
 
#define SPR_HID6   0x3f9 /* Hardware Implementation Register 6 */
 
#define INSOPS   insn->detail->ppc.op_count
 
#define INSOP(n)   insn->detail->ppc.operands[n]
 
#define IMM(x)   (ut64)(insn->detail->ppc.operands[x].imm)
 
#define PFMT32x   "lx"
 
#define PPCSPR(n)   getspr(&gop, n)
 
#define ARG(n)   getarg2(&gop, n, "")
 
#define ARG2(n, m)   getarg2(&gop, n, m)
 
#define KW(d, ds, m, ms)   rz_list_append(l, rz_search_keyword_new((const ut8 *)d, ds, (const ut8 *)m, ms, NULL))
 

Functions

static ut64 mask64 (ut64 mb, ut64 me)
 
static ut32 mask32 (ut32 mb, ut32 me)
 
static const char * cmask64 (const char *mb_c, const char *me_c)
 
static const char * cmask32 (const char *mb_c, const char *me_c)
 
static char * getarg2 (struct Getarg *gop, int n, const char *setstr)
 
static ut64 getarg (struct Getarg *gop, int n)
 
static const char * getspr (struct Getarg *gop, int n)
 
static void opex (RzStrBuf *buf, csh handle, cs_insn *insn)
 
static char * get_reg_profile (RzAnalysis *analysis)
 
static int analop_vle (RzAnalysis *a, RzAnalysisOp *op, ut64 addr, const ut8 *buf, int len, RzAnalysisOpMask mask)
 
static int parse_reg_name (RzRegItem *reg, csh handle, cs_insn *insn, int reg_num)
 
static void create_src_dst (RzAnalysisOp *op)
 
static void set_src_dst (RzAnalysisValue *val, csh *handle, cs_insn *insn, int x)
 
static void op_fillval (RzAnalysisOp *op, csh handle, cs_insn *insn)
 
static char * shrink (char *op)
 
static int analop (RzAnalysis *a, RzAnalysisOp *op, ut64 addr, const ut8 *buf, int len, RzAnalysisOpMask mask)
 
static int archinfo (RzAnalysis *a, int q)
 
static RzListanalysis_preludes (RzAnalysis *analysis)
 

Variables

static RzRegItem base_regs [4]
 
RzAnalysisPlugin rz_analysis_plugin_ppc_cs
 
RZ_API RzLibStruct rizin_plugin
 

Macro Definition Documentation

◆ ARG

#define ARG (   n)    getarg2(&gop, n, "")

Definition at line 207 of file analysis_ppc_cs.c.

◆ ARG2

#define ARG2 (   n,
 
)    getarg2(&gop, n, m)

Definition at line 208 of file analysis_ppc_cs.c.

◆ IMM

#define IMM (   x)    (ut64)(insn->detail->ppc.operands[x].imm)

Definition at line 25 of file analysis_ppc_cs.c.

◆ INSOP

#define INSOP (   n)    insn->detail->ppc.operands[n]

Definition at line 24 of file analysis_ppc_cs.c.

◆ INSOPS

#define INSOPS   insn->detail->ppc.op_count

Definition at line 23 of file analysis_ppc_cs.c.

◆ KW

#define KW (   d,
  ds,
  m,
  ms 
)    rz_list_append(l, rz_search_keyword_new((const ut8 *)d, ds, (const ut8 *)m, ms, NULL))

◆ PFMT32x

#define PFMT32x   "lx"

Definition at line 28 of file analysis_ppc_cs.c.

◆ PPCSPR

#define PPCSPR (   n)    getspr(&gop, n)

Definition at line 206 of file analysis_ppc_cs.c.

◆ SPR_HID0

#define SPR_HID0   0x3f0 /* Hardware Implementation Register 0 */

Definition at line 10 of file analysis_ppc_cs.c.

◆ SPR_HID1

#define SPR_HID1   0x3f1 /* Hardware Implementation Register 1 */

Definition at line 11 of file analysis_ppc_cs.c.

◆ SPR_HID2

#define SPR_HID2   0x3f3 /* Hardware Implementation Register 2 */

Definition at line 12 of file analysis_ppc_cs.c.

◆ SPR_HID4

#define SPR_HID4   0x3f4 /* Hardware Implementation Register 4 */

Definition at line 13 of file analysis_ppc_cs.c.

◆ SPR_HID5

#define SPR_HID5   0x3f6 /* Hardware Implementation Register 5 */

Definition at line 14 of file analysis_ppc_cs.c.

◆ SPR_HID6

#define SPR_HID6   0x3f9 /* Hardware Implementation Register 6 */

Definition at line 15 of file analysis_ppc_cs.c.

Function Documentation

◆ analop()

static int analop ( RzAnalysis a,
RzAnalysisOp op,
ut64  addr,
const ut8 buf,
int  len,
RzAnalysisOpMask  mask 
)
static

Definition at line 601 of file analysis_ppc_cs.c.

601  {
602  static csh handle = 0;
603  static int omode = -1, obits = -1;
604  int n, ret;
605  cs_insn *insn;
606  char *op1;
607  int mode = (a->bits == 64) ? CS_MODE_64 : (a->bits == 32) ? CS_MODE_32
608  : 0;
609  mode |= a->big_endian ? CS_MODE_BIG_ENDIAN : CS_MODE_LITTLE_ENDIAN;
610 
611  if (a->cpu && strncmp(a->cpu, "vle", 3) == 0) {
612  // vle is big-endian only
613  if (!a->big_endian) {
614  return -1;
615  }
616  ret = analop_vle(a, op, addr, buf, len, mask);
617  if (ret >= 0) {
618  return op->size;
619  }
620  }
621 
622  if (mode != omode || a->bits != obits) {
623  cs_close(&handle);
624  handle = 0;
625  omode = mode;
626  obits = a->bits;
627  }
628  if (handle == 0) {
629  ret = cs_open(CS_ARCH_PPC, mode, &handle);
630  if (ret != CS_ERR_OK) {
631  return -1;
632  }
634  }
635  op->size = 4;
636 
637  // capstone-next
638  n = cs_disasm(handle, (const ut8 *)buf, len, addr, 1, &insn);
639  if (n < 1) {
640  op->type = RZ_ANALYSIS_OP_TYPE_ILL;
641  } else {
643  op->mnemonic = strdup(insn->mnemonic);
644  }
646  opex(&op->opex, handle, insn);
647  }
648  struct Getarg gop = {
649  .handle = handle,
650  .insn = insn,
651  .bits = a->bits
652  };
653  op->size = insn->size;
654  op->id = insn->id;
655  switch (insn->id) {
656 #if CS_API_MAJOR >= 4
657  case PPC_INS_CMPB:
658 #endif
659  case PPC_INS_CMPD:
660  case PPC_INS_CMPDI:
661  case PPC_INS_CMPLD:
662  case PPC_INS_CMPLDI:
663  case PPC_INS_CMPLW:
664  case PPC_INS_CMPLWI:
665  case PPC_INS_CMPW:
666  case PPC_INS_CMPWI:
667 #if CS_API_MAJOR > 4
668  case PPC_INS_CMP:
669  case PPC_INS_CMPI:
670 #endif
671  op->type = RZ_ANALYSIS_OP_TYPE_CMP;
672  op->sign = true;
673  if (ARG(2)[0] == '\0') {
674  esilprintf(op, "%s,%s,-,0xff,&,cr0,=", ARG(1), ARG(0));
675  } else {
676  esilprintf(op, "%s,%s,-,0xff,&,%s,=", ARG(2), ARG(1), ARG(0));
677  }
678  break;
679  case PPC_INS_MFLR:
680  op->type = RZ_ANALYSIS_OP_TYPE_MOV;
681  esilprintf(op, "lr,%s,=", ARG(0));
682  break;
683  case PPC_INS_MTLR:
684  op->type = RZ_ANALYSIS_OP_TYPE_MOV;
685  esilprintf(op, "%s,lr,=", ARG(0));
686  break;
687  case PPC_INS_MR:
688  case PPC_INS_LI:
689  op->type = RZ_ANALYSIS_OP_TYPE_MOV;
690  op->val = IMM(1);
691  esilprintf(op, "%s,%s,=", ARG(1), ARG(0));
692  break;
693  case PPC_INS_LIS:
694  op->type = RZ_ANALYSIS_OP_TYPE_MOV;
695  op->val = IMM(1);
696  op->val <<= 16;
697  esilprintf(op, "%s0000,%s,=", ARG(1), ARG(0));
698  break;
699  case PPC_INS_CLRLWI:
700  op->type = RZ_ANALYSIS_OP_TYPE_AND;
701  esilprintf(op, "%s,%s,&,%s,=", ARG(1), cmask32(ARG(2), "0x1F"), ARG(0));
702  break;
703  case PPC_INS_RLWINM:
704  op->type = RZ_ANALYSIS_OP_TYPE_ROL;
705  esilprintf(op, "%s,%s,<<<,%s,&,%s,=", ARG(2), ARG(1), cmask32(ARG(3), ARG(4)), ARG(0));
706  break;
707  case PPC_INS_SC:
708  op->type = RZ_ANALYSIS_OP_TYPE_SWI;
709  esilprintf(op, "0,$");
710  break;
711  case PPC_INS_EXTSB:
712  op->sign = true;
713  op->type = RZ_ANALYSIS_OP_TYPE_MOV;
714  if (a->bits == 64) {
715  esilprintf(op, "%s,0x80,&,?{,0xFFFFFFFFFFFFFF00,%s,|,%s,=,}", ARG(1), ARG(1), ARG(0));
716  } else {
717  esilprintf(op, "%s,0x80,&,?{,0xFFFFFF00,%s,|,%s,=,}", ARG(1), ARG(1), ARG(0));
718  }
719  break;
720  case PPC_INS_EXTSH:
721  op->sign = true;
722  if (a->bits == 64) {
723  esilprintf(op, "%s,0x8000,&,?{,0xFFFFFFFFFFFF0000,%s,|,%s,=,}", ARG(1), ARG(1), ARG(0));
724  } else {
725  esilprintf(op, "%s,0x8000,&,?{,0xFFFF0000,%s,|,%s,=,}", ARG(1), ARG(1), ARG(0));
726  }
727  break;
728  case PPC_INS_EXTSW:
729  op->sign = true;
730  esilprintf(op, "%s,0x80000000,&,?{,0xFFFFFFFF00000000,%s,|,%s,=,}", ARG(1), ARG(1), ARG(0));
731  break;
732  case PPC_INS_SYNC:
733  case PPC_INS_ISYNC:
734  case PPC_INS_LWSYNC:
735  case PPC_INS_MSYNC:
736  case PPC_INS_PTESYNC:
737  case PPC_INS_TLBSYNC:
738  case PPC_INS_SLBIA:
739  case PPC_INS_SLBIE:
740  case PPC_INS_SLBMFEE:
741  case PPC_INS_SLBMTE:
742  case PPC_INS_EIEIO:
743  case PPC_INS_NOP:
744  op->type = RZ_ANALYSIS_OP_TYPE_NOP;
745  esilprintf(op, ",");
746  break;
747  case PPC_INS_STW:
748  case PPC_INS_STWUX:
749  case PPC_INS_STWX:
750  case PPC_INS_STWCX:
752  esilprintf(op, "%s,%s", ARG(0), ARG2(1, "=[4]"));
753  break;
754  case PPC_INS_STWU:
756  op1 = shrink(ARG(1));
757  if (!op1) {
758  break;
759  }
760  esilprintf(op, "%s,%s,=[4],%s=", ARG(0), op1, op1);
761  if (strstr(op1, "r1")) {
762  op->stackop = RZ_ANALYSIS_STACK_INC;
763  op->stackptr = -atoi(op1);
764  }
765  break;
766  case PPC_INS_STWBRX:
768  break;
769  case PPC_INS_STB:
771  esilprintf(op, "%s,%s", ARG(0), ARG2(1, "=[1]"));
772  break;
773  case PPC_INS_STBU:
775  op1 = shrink(ARG(1));
776  if (!op1) {
777  break;
778  }
779  esilprintf(op, "%s,%s,=[1],%s=", ARG(0), op1, op1);
780  break;
781  case PPC_INS_STH:
783  esilprintf(op, "%s,%s", ARG(0), ARG2(1, "=[2]"));
784  break;
785  case PPC_INS_STHU:
787  op1 = shrink(ARG(1));
788  if (!op1) {
789  break;
790  }
791  esilprintf(op, "%s,%s,=[2],%s=", ARG(0), op1, op1);
792  break;
793  case PPC_INS_STD:
795  esilprintf(op, "%s,%s", ARG(0), ARG2(1, "=[8]"));
796  break;
797  case PPC_INS_STDU:
799  op1 = shrink(ARG(1));
800  if (!op1) {
801  break;
802  }
803  esilprintf(op, "%s,%s,=[8],%s=", ARG(0), op1, op1);
804  break;
805  case PPC_INS_LBZ:
806 #if CS_API_MAJOR >= 4
807  case PPC_INS_LBZCIX:
808 #endif
809  case PPC_INS_LBZU:
810  case PPC_INS_LBZUX:
812  op1 = shrink(ARG(1));
813  if (!op1) {
814  break;
815  }
816  esilprintf(op, "%s,[1],%s,=,%s=", op1, ARG(0), op1);
817  break;
818  case PPC_INS_LBZX:
820  esilprintf(op, "%s,%s,=", ARG2(1, "[1]"), ARG(0));
821  break;
822  case PPC_INS_LD:
823  case PPC_INS_LDARX:
824 #if CS_API_MAJOR >= 4
825  case PPC_INS_LDCIX:
826 #endif
827  case PPC_INS_LDU:
828  case PPC_INS_LDUX:
830  op1 = shrink(ARG(1));
831  if (!op1) {
832  break;
833  }
834  esilprintf(op, "%s,[8],%s,=,%s=", op1, ARG(0), op1);
835  break;
836  case PPC_INS_LDX:
838  esilprintf(op, "%s,%s,=", ARG2(1, "[8]"), ARG(0));
839  break;
840  case PPC_INS_LDBRX:
842  break;
843  case PPC_INS_LFD:
844  case PPC_INS_LFDU:
845  case PPC_INS_LFDUX:
846  case PPC_INS_LFDX:
847  case PPC_INS_LFIWAX:
848  case PPC_INS_LFIWZX:
849  case PPC_INS_LFS:
850  case PPC_INS_LFSU:
851  case PPC_INS_LFSUX:
852  case PPC_INS_LFSX:
854  esilprintf(op, "%s,%s,=", ARG2(1, "[4]"), ARG(0));
855  break;
856  case PPC_INS_LHA:
857  case PPC_INS_LHAU:
858  case PPC_INS_LHAUX:
859  case PPC_INS_LHAX:
860  case PPC_INS_LHZ:
861  case PPC_INS_LHZU:
863  op1 = shrink(ARG(1));
864  if (!op1) {
865  break;
866  }
867  esilprintf(op, "%s,[2],%s,=,%s=", op1, ARG(0), op1);
868  break;
869  case PPC_INS_LHBRX:
871  break;
872  case PPC_INS_LWA:
873  case PPC_INS_LWARX:
874  case PPC_INS_LWAUX:
875  case PPC_INS_LWAX:
876  case PPC_INS_LWZ:
877 #if CS_API_MAJOR >= 4
878  case PPC_INS_LWZCIX:
879 #endif
880  case PPC_INS_LWZX:
882  esilprintf(op, "%s,%s,=", ARG2(1, "[4]"), ARG(0));
883  break;
884  case PPC_INS_LWZU:
885  case PPC_INS_LWZUX:
887  op1 = shrink(ARG(1));
888  if (!op1) {
889  break;
890  }
891  esilprintf(op, "%s,[4],%s,=,%s=", op1, ARG(0), op1);
892  break;
893  case PPC_INS_LWBRX:
895  break;
896  case PPC_INS_SLW:
897  case PPC_INS_SLWI:
898  op->type = RZ_ANALYSIS_OP_TYPE_SHL;
899  esilprintf(op, "%s,%s,<<,%s,=", ARG(2), ARG(1), ARG(0));
900  break;
901  case PPC_INS_SRW:
902  case PPC_INS_SRWI:
903  op->type = RZ_ANALYSIS_OP_TYPE_SHR;
904  esilprintf(op, "%s,%s,>>,%s,=", ARG(2), ARG(1), ARG(0));
905  break;
906  case PPC_INS_MULLI:
907  op->sign = true;
908  // fallthrough
909  case PPC_INS_MULLW:
910  case PPC_INS_MULLD:
911  op->type = RZ_ANALYSIS_OP_TYPE_MUL;
912  esilprintf(op, "%s,%s,*,%s,=", ARG(2), ARG(1), ARG(0));
913  break;
914  case PPC_INS_SUB:
915  case PPC_INS_SUBC:
916  case PPC_INS_SUBF:
917  case PPC_INS_SUBFIC:
918  case PPC_INS_SUBFZE:
919  op->type = RZ_ANALYSIS_OP_TYPE_SUB;
920  esilprintf(op, "%s,%s,-,%s,=", ARG(1), ARG(2), ARG(0));
921  break;
922  case PPC_INS_ADDI:
923  op->val = ((st16)IMM(2));
924  // fallthrough
925  case PPC_INS_ADD:
926  op->sign = true;
927  op->type = RZ_ANALYSIS_OP_TYPE_ADD;
928  esilprintf(op, "%s,%s,+,%s,=", ARG(2), ARG(1), ARG(0));
929  break;
930  case PPC_INS_CRCLR:
931  case PPC_INS_CRSET:
932  case PPC_INS_CRMOVE:
933  case PPC_INS_CRXOR:
934  case PPC_INS_CRNOR:
935  case PPC_INS_CRNOT:
936  // reset conditional bits
937  op->type = RZ_ANALYSIS_OP_TYPE_MOV;
938  break;
939  case PPC_INS_ADDC:
940  case PPC_INS_ADDIC:
941  op->type = RZ_ANALYSIS_OP_TYPE_ADD;
942  esilprintf(op, "%s,%s,+,%s,=", ARG(2), ARG(1), ARG(0));
943  break;
944  case PPC_INS_ADDE:
945  case PPC_INS_ADDIS:
946  case PPC_INS_ADDME:
947  case PPC_INS_ADDZE:
948  op->type = RZ_ANALYSIS_OP_TYPE_ADD;
949  esilprintf(op, "%s,%s,+,%s,=", ARG(2), ARG(1), ARG(0));
950  break;
951  case PPC_INS_MTSPR:
952  op->type = RZ_ANALYSIS_OP_TYPE_MOV;
953  esilprintf(op, "%s,%s,=", ARG(1), PPCSPR(0));
954  break;
955  case PPC_INS_BCTR: // switch table here
957  esilprintf(op, "ctr,pc,=");
958  break;
959  case PPC_INS_BCTRL: // switch table here
961  esilprintf(op, "pc,lr,=,ctr,pc,=");
962  break;
963  case PPC_INS_B:
964  case PPC_INS_BC:
965  case PPC_INS_BA:
967  op->jump = ARG(1)[0] == '\0' ? IMM(0) : IMM(1);
968  op->fail = addr + op->size;
969  switch (insn->detail->ppc.bc) {
970  case PPC_BC_LT:
971  if (ARG(1)[0] == '\0') {
972  esilprintf(op, "0x80,cr0,&,!,!,?{,%s,pc,=,},", ARG(0));
973  } else {
974  esilprintf(op, "0x80,%s,&,!,!,?{,%s,pc,=,},", ARG(0), ARG(1));
975  }
976  break;
977  case PPC_BC_LE:
978  if (ARG(1)[0] == '\0') {
979  esilprintf(op, "0x80,cr0,&,!,!,cr0,!,|,?{,%s,pc,=,},", ARG(0));
980  } else {
981  esilprintf(op, "0x80,%s,&,!,!,0,%s,!,|,?{,%s,pc,=,},", ARG(0), ARG(0), ARG(1));
982  }
983  break;
984  case PPC_BC_EQ:
985  if (ARG(1)[0] == '\0') {
986  esilprintf(op, "cr0,!,?{,%s,pc,=,},", ARG(0));
987  } else {
988  esilprintf(op, "%s,!,?{,%s,pc,=,},", ARG(0), ARG(1));
989  }
990  break;
991  case PPC_BC_GE:
992  if (ARG(1)[0] == '\0') {
993  esilprintf(op, "0x80,cr0,&,!,cr0,!,|,?{,%s,pc,=,},", ARG(0));
994  } else {
995  esilprintf(op, "0x80,%s,&,!,%s,!,|,?{,%s,pc,=,},", ARG(0), ARG(0), ARG(1));
996  }
997  break;
998  case PPC_BC_GT:
999  if (ARG(1)[0] == '\0') {
1000  esilprintf(op, "0x80,cr0,&,!,?{,%s,pc,=,},", ARG(0));
1001  } else {
1002  esilprintf(op, "0x80,%s,&,!,?{,%s,pc,=,},", ARG(0), ARG(1));
1003  }
1004  break;
1005  case PPC_BC_NE:
1006  if (ARG(1)[0] == '\0') {
1007  esilprintf(op, "cr0,!,!,?{,%s,pc,=,},", ARG(0));
1008  } else {
1009  esilprintf(op, "%s,!,!,?{,%s,pc,=,},", ARG(0), ARG(1));
1010  }
1011  break;
1012  case PPC_BC_INVALID:
1013  op->type = RZ_ANALYSIS_OP_TYPE_JMP;
1014  esilprintf(op, "%s,pc,=", ARG(0));
1015  case PPC_BC_UN: // unordered
1016  case PPC_BC_NU: // not unordered
1017  case PPC_BC_SO: // summary overflow
1018  case PPC_BC_NS: // not summary overflow
1019  default:
1020  break;
1021  }
1022  break;
1023  case PPC_INS_BT:
1024  case PPC_INS_BF:
1025  switch (insn->detail->ppc.operands[0].type) {
1026  case PPC_OP_CRX:
1027  op->type = RZ_ANALYSIS_OP_TYPE_CJMP;
1028  op->fail = addr + op->size;
1029  break;
1030  case PPC_OP_REG:
1031  if (op->type == RZ_ANALYSIS_OP_TYPE_CJMP) {
1032  op->type = RZ_ANALYSIS_OP_TYPE_UCJMP;
1033  } else {
1034  op->type = RZ_ANALYSIS_OP_TYPE_CJMP;
1035  }
1036  op->jump = IMM(1);
1037  op->fail = addr + op->size;
1038  // op->type = RZ_ANALYSIS_OP_TYPE_UJMP;
1039  default:
1040  break;
1041  }
1042  break;
1043  case PPC_INS_BDNZ:
1044  op->type = RZ_ANALYSIS_OP_TYPE_CJMP;
1045  op->jump = IMM(0);
1046  op->fail = addr + op->size;
1047  esilprintf(op, "1,ctr,-=,$z,!,?{,%s,pc,=,}", ARG(0));
1048  break;
1049  case PPC_INS_BDNZA:
1050  op->type = RZ_ANALYSIS_OP_TYPE_CJMP;
1051  op->jump = IMM(0);
1052  op->fail = addr + op->size;
1053  break;
1054  case PPC_INS_BDNZL:
1055  op->type = RZ_ANALYSIS_OP_TYPE_CJMP;
1056  op->jump = IMM(0);
1057  op->fail = addr + op->size;
1058  break;
1059  case PPC_INS_BDNZLA:
1060  op->type = RZ_ANALYSIS_OP_TYPE_CJMP;
1061  op->jump = IMM(0);
1062  op->fail = addr + op->size;
1063  break;
1064  case PPC_INS_BDNZLR:
1065  op->type = RZ_ANALYSIS_OP_TYPE_CJMP;
1066  op->fail = addr + op->size;
1067  esilprintf(op, "1,ctr,-=,$z,!,?{,lr,pc,=,},");
1068  break;
1069  case PPC_INS_BDNZLRL:
1070  op->fail = addr + op->size;
1071  op->type = RZ_ANALYSIS_OP_TYPE_CJMP;
1072  break;
1073  case PPC_INS_BDZ:
1074  op->type = RZ_ANALYSIS_OP_TYPE_CJMP;
1075  op->jump = IMM(0);
1076  op->fail = addr + op->size;
1077  esilprintf(op, "1,ctr,-=,$z,?{,%s,pc,=,}", ARG(0));
1078  break;
1079  case PPC_INS_BDZA:
1080  op->type = RZ_ANALYSIS_OP_TYPE_CJMP;
1081  op->jump = IMM(0);
1082  op->fail = addr + op->size;
1083  break;
1084  case PPC_INS_BDZL:
1085  op->type = RZ_ANALYSIS_OP_TYPE_CJMP;
1086  op->jump = IMM(0);
1087  op->fail = addr + op->size;
1088  break;
1089  case PPC_INS_BDZLA:
1090  op->type = RZ_ANALYSIS_OP_TYPE_CJMP;
1091  op->jump = IMM(0);
1092  op->fail = addr + op->size;
1093  break;
1094  case PPC_INS_BDZLR:
1095  op->type = RZ_ANALYSIS_OP_TYPE_CJMP;
1096  op->fail = addr + op->size;
1097  esilprintf(op, "1,ctr,-=,$z,?{,lr,pc,=,}");
1098  break;
1099  case PPC_INS_BDZLRL:
1100  op->type = RZ_ANALYSIS_OP_TYPE_CJMP;
1101  op->fail = addr + op->size;
1102  break;
1103  case PPC_INS_BLR:
1104  case PPC_INS_BLRL:
1105  case PPC_INS_BCLR:
1106  case PPC_INS_BCLRL:
1107  op->type = RZ_ANALYSIS_OP_TYPE_CRET;
1108  op->fail = addr + op->size;
1109  switch (insn->detail->ppc.bc) {
1110  case PPC_BC_INVALID:
1111  op->type = RZ_ANALYSIS_OP_TYPE_RET;
1112  esilprintf(op, "lr,pc,=");
1113  break;
1114  case PPC_BC_LT:
1115  if (ARG(1)[0] == '\0') {
1116  esilprintf(op, "0x80,cr0,&,!,!,?{,lr,pc,=,},");
1117  } else {
1118  esilprintf(op, "0x80,%s,&,!,!,?{,lr,pc,=,},", ARG(0));
1119  }
1120  break;
1121  case PPC_BC_LE:
1122  if (ARG(1)[0] == '\0') {
1123  esilprintf(op, "0x80,cr0,&,!,!,cr0,!,|,?{,lr,pc,=,},");
1124  } else {
1125  esilprintf(op, "0x80,%s,&,!,!,0,%s,!,|,?{,lr,pc,=,},", ARG(0), ARG(0));
1126  }
1127  break;
1128  case PPC_BC_EQ:
1129  if (ARG(1)[0] == '\0') {
1130  esilprintf(op, "cr0,!,?{,lr,pc,=,},");
1131  } else {
1132  esilprintf(op, "%s,!,?{,lr,pc,=,},", ARG(0));
1133  }
1134  break;
1135  case PPC_BC_GE:
1136  if (ARG(1)[0] == '\0') {
1137  esilprintf(op, "0x80,cr0,&,!,cr0,!,|,?{,lr,pc,=,},");
1138  } else {
1139  esilprintf(op, "0x80,%s,&,!,%s,!,|,?{,lr,pc,=,},", ARG(0), ARG(0));
1140  }
1141  break;
1142  case PPC_BC_GT:
1143  if (ARG(1)[0] == '\0') {
1144  esilprintf(op, "0x80,cr0,&,!,?{,lr,pc,=,},");
1145  } else {
1146  esilprintf(op, "0x80,%s,&,!,?{,lr,pc,=,},", ARG(0));
1147  }
1148  break;
1149  case PPC_BC_NE:
1150  if (ARG(1)[0] == '\0') {
1151  esilprintf(op, "cr0,!,!,?{,lr,pc,=,},");
1152  } else {
1153  esilprintf(op, "%s,!,!,?{,lr,pc,=,},", ARG(0));
1154  }
1155  break;
1156  case PPC_BC_UN: // unordered
1157  case PPC_BC_NU: // not unordered
1158  case PPC_BC_SO: // summary overflow
1159  case PPC_BC_NS: // not summary overflow
1160  default:
1161  break;
1162  }
1163  break;
1164  case PPC_INS_NOR:
1165  op->type = RZ_ANALYSIS_OP_TYPE_NOR;
1166  esilprintf(op, "%s,%s,|,!,%s,=", ARG(2), ARG(1), ARG(0));
1167  break;
1168  case PPC_INS_XOR:
1169  case PPC_INS_XORI:
1170  op->type = RZ_ANALYSIS_OP_TYPE_XOR;
1171  esilprintf(op, "%s,%s,^,%s,=", ARG(2), ARG(1), ARG(0));
1172  break;
1173  case PPC_INS_XORIS:
1174  op->type = RZ_ANALYSIS_OP_TYPE_XOR;
1175  esilprintf(op, "16,%s,<<,%s,^,%s,=", ARG(2), ARG(1), ARG(0));
1176  break;
1177  case PPC_INS_DIVD:
1178  case PPC_INS_DIVW:
1179  op->sign = true;
1180  op->type = RZ_ANALYSIS_OP_TYPE_DIV;
1181  esilprintf(op, "%s,%s,/,%s,=", ARG(2), ARG(1), ARG(0));
1182  break;
1183  case PPC_INS_DIVDU:
1184  case PPC_INS_DIVWU:
1185  op->type = RZ_ANALYSIS_OP_TYPE_DIV;
1186  esilprintf(op, "%s,%s,/,%s,=", ARG(2), ARG(1), ARG(0));
1187  break;
1188  case PPC_INS_BL:
1189  case PPC_INS_BLA:
1190  op->type = RZ_ANALYSIS_OP_TYPE_CALL;
1191  op->jump = IMM(0);
1192  op->fail = addr + op->size;
1193  esilprintf(op, "pc,lr,=,%s,pc,=", ARG(0));
1194  break;
1195  case PPC_INS_TRAP:
1196  op->sign = true;
1197  op->type = RZ_ANALYSIS_OP_TYPE_TRAP;
1198  break;
1199  case PPC_INS_AND:
1200  case PPC_INS_NAND:
1201  case PPC_INS_ANDI:
1202  op->type = RZ_ANALYSIS_OP_TYPE_AND;
1203  esilprintf(op, "%s,%s,&,%s,=", ARG(2), ARG(1), ARG(0));
1204  break;
1205  case PPC_INS_ANDIS:
1206  op->type = RZ_ANALYSIS_OP_TYPE_AND;
1207  esilprintf(op, "16,%s,<<,%s,&,%s,=", ARG(2), ARG(1), ARG(0));
1208  break;
1209  case PPC_INS_OR:
1210  case PPC_INS_ORI:
1211  op->type = RZ_ANALYSIS_OP_TYPE_OR;
1212  esilprintf(op, "%s,%s,|,%s,=", ARG(2), ARG(1), ARG(0));
1213  break;
1214  case PPC_INS_ORIS:
1215  op->type = RZ_ANALYSIS_OP_TYPE_OR;
1216  esilprintf(op, "16,%s,<<,%s,|,%s,=", ARG(2), ARG(1), ARG(0));
1217  break;
1218  case PPC_INS_MFPVR:
1219  op->type = RZ_ANALYSIS_OP_TYPE_MOV;
1220  esilprintf(op, "pvr,%s,=", ARG(0));
1221  break;
1222  case PPC_INS_MFSPR:
1223  op->type = RZ_ANALYSIS_OP_TYPE_MOV;
1224  esilprintf(op, "%s,%s,=", PPCSPR(1), ARG(0));
1225  break;
1226  case PPC_INS_MFCTR:
1227  op->type = RZ_ANALYSIS_OP_TYPE_MOV;
1228  esilprintf(op, "ctr,%s,=", ARG(0));
1229  break;
1230  case PPC_INS_MFDCCR:
1231  op->type = RZ_ANALYSIS_OP_TYPE_MOV;
1232  esilprintf(op, "dccr,%s,=", ARG(0));
1233  break;
1234  case PPC_INS_MFICCR:
1235  op->type = RZ_ANALYSIS_OP_TYPE_MOV;
1236  esilprintf(op, "iccr,%s,=", ARG(0));
1237  break;
1238  case PPC_INS_MFDEAR:
1239  op->type = RZ_ANALYSIS_OP_TYPE_MOV;
1240  esilprintf(op, "dear,%s,=", ARG(0));
1241  break;
1242  case PPC_INS_MFMSR:
1243  op->type = RZ_ANALYSIS_OP_TYPE_MOV;
1244  esilprintf(op, "msr,%s,=", ARG(0));
1245  break;
1246  case PPC_INS_MTCTR:
1247  op->type = RZ_ANALYSIS_OP_TYPE_MOV;
1248  esilprintf(op, "%s,ctr,=", ARG(0));
1249  break;
1250  case PPC_INS_MTDCCR:
1251  op->type = RZ_ANALYSIS_OP_TYPE_MOV;
1252  esilprintf(op, "%s,dccr,=", ARG(0));
1253  break;
1254  case PPC_INS_MTICCR:
1255  op->type = RZ_ANALYSIS_OP_TYPE_MOV;
1256  esilprintf(op, "%s,iccr,=", ARG(0));
1257  break;
1258  case PPC_INS_MTDEAR:
1259  op->type = RZ_ANALYSIS_OP_TYPE_MOV;
1260  esilprintf(op, "%s,dear,=", ARG(0));
1261  break;
1262  case PPC_INS_MTMSR:
1263  case PPC_INS_MTMSRD:
1264  op->type = RZ_ANALYSIS_OP_TYPE_MOV;
1265  esilprintf(op, "%s,msr,=", ARG(0));
1266  break;
1267  // Data Cache Block Zero
1268  case PPC_INS_DCBZ:
1269  op->type = RZ_ANALYSIS_OP_TYPE_STORE;
1270  esilprintf(op, "%s,%s", ARG(0), ARG2(1, ",=[128]"));
1271  break;
1272  case PPC_INS_CLRLDI:
1273  op->type = RZ_ANALYSIS_OP_TYPE_AND;
1274  esilprintf(op, "%s,%s,&,%s,=", ARG(1), cmask64(ARG(2), "0x3F"), ARG(0));
1275  break;
1276  case PPC_INS_ROTLDI:
1277  op->type = RZ_ANALYSIS_OP_TYPE_ROL;
1278  esilprintf(op, "%s,%s,<<<,%s,=", ARG(2), ARG(1), ARG(0));
1279  break;
1280  case PPC_INS_RLDCL:
1281  case PPC_INS_RLDICL:
1282  op->type = RZ_ANALYSIS_OP_TYPE_ROL;
1283  esilprintf(op, "%s,%s,<<<,%s,&,%s,=", ARG(2), ARG(1), cmask64(ARG(3), "0x3F"), ARG(0));
1284  break;
1285  case PPC_INS_RLDCR:
1286  case PPC_INS_RLDICR:
1287  op->type = RZ_ANALYSIS_OP_TYPE_ROL;
1288  esilprintf(op, "%s,%s,<<<,%s,&,%s,=", ARG(2), ARG(1), cmask64(0, ARG(3)), ARG(0));
1289  break;
1290  }
1291  if (mask & RZ_ANALYSIS_OP_MASK_VAL) {
1292  op_fillval(op, handle, insn);
1293  }
1294  if (!(mask & RZ_ANALYSIS_OP_MASK_ESIL)) {
1295  rz_strbuf_fini(&op->esil);
1296  }
1297  cs_free(insn, n);
1298  // cs_close (&handle);
1299  }
1300  return op->size;
1301 }
size_t len
Definition: 6502dis.c:15
#define mask()
#define ARG2(n, m)
static int analop_vle(RzAnalysis *a, RzAnalysisOp *op, ut64 addr, const ut8 *buf, int len, RzAnalysisOpMask mask)
static const char * cmask64(const char *mb_c, const char *me_c)
static void opex(RzStrBuf *buf, csh handle, cs_insn *insn)
#define IMM(x)
#define ARG(n)
static char * shrink(char *op)
static const char * cmask32(const char *mb_c, const char *me_c)
#define PPCSPR(n)
static void op_fillval(RzAnalysisOp *op, csh handle, cs_insn *insn)
static mcore_handle handle
Definition: asm_mcore.c:8
@ CS_ARCH_PPC
PowerPC architecture.
Definition: capstone.h:79
@ CS_MODE_64
64-bit mode (X86, PPC)
Definition: capstone.h:107
@ CS_MODE_32
32-bit mode (X86)
Definition: capstone.h:106
@ CS_MODE_BIG_ENDIAN
big-endian mode
Definition: capstone.h:123
@ CS_MODE_LITTLE_ENDIAN
little-endian mode (default mode)
Definition: capstone.h:103
@ CS_OPT_DETAIL
Break down instruction structure into details.
Definition: capstone.h:171
size_t csh
Definition: capstone.h:71
@ CS_OPT_ON
Turn ON an option (CS_OPT_DETAIL, CS_OPT_SKIPDATA).
Definition: capstone.h:183
CAPSTONE_EXPORT size_t CAPSTONE_API cs_disasm(csh ud, const uint8_t *buffer, size_t size, uint64_t offset, size_t count, cs_insn **insn)
Definition: cs.c:798
CAPSTONE_EXPORT cs_err CAPSTONE_API cs_open(cs_arch arch, cs_mode mode, csh *handle)
Definition: cs.c:453
CAPSTONE_EXPORT void CAPSTONE_API cs_free(cs_insn *insn, size_t count)
Definition: cs.c:1017
CAPSTONE_EXPORT cs_err CAPSTONE_API cs_close(csh *handle)
Definition: cs.c:501
CAPSTONE_EXPORT cs_err CAPSTONE_API cs_option(csh ud, cs_opt_type type, size_t value)
Definition: cs.c:646
const char int mode
Definition: ioapi.h:137
voidpf void * buf
Definition: ioapi.h:138
uint8_t ut8
Definition: lh5801.h:11
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")
int n
Definition: mipsasm.c:19
int CS_ERR_OK
Definition: __init__.py:235
#define esilprintf(op, fmt,...)
Definition: rz_analysis.h:29
@ RZ_ANALYSIS_STACK_INC
Definition: rz_analysis.h:457
@ RZ_ANALYSIS_OP_MASK_DISASM
Definition: rz_analysis.h:445
@ RZ_ANALYSIS_OP_MASK_VAL
Definition: rz_analysis.h:442
@ RZ_ANALYSIS_OP_MASK_OPEX
Definition: rz_analysis.h:444
@ RZ_ANALYSIS_OP_MASK_ESIL
Definition: rz_analysis.h:441
@ RZ_ANALYSIS_OP_TYPE_CMP
Definition: rz_analysis.h:399
@ RZ_ANALYSIS_OP_TYPE_SUB
Definition: rz_analysis.h:402
@ RZ_ANALYSIS_OP_TYPE_LOAD
Definition: rz_analysis.h:416
@ RZ_ANALYSIS_OP_TYPE_MUL
Definition: rz_analysis.h:404
@ RZ_ANALYSIS_OP_TYPE_ROL
Definition: rz_analysis.h:420
@ RZ_ANALYSIS_OP_TYPE_JMP
Definition: rz_analysis.h:368
@ RZ_ANALYSIS_OP_TYPE_AND
Definition: rz_analysis.h:411
@ RZ_ANALYSIS_OP_TYPE_UJMP
Definition: rz_analysis.h:369
@ RZ_ANALYSIS_OP_TYPE_NOR
Definition: rz_analysis.h:413
@ RZ_ANALYSIS_OP_TYPE_SWI
Definition: rz_analysis.h:393
@ RZ_ANALYSIS_OP_TYPE_TRAP
Definition: rz_analysis.h:392
@ RZ_ANALYSIS_OP_TYPE_CALL
Definition: rz_analysis.h:378
@ RZ_ANALYSIS_OP_TYPE_ADD
Definition: rz_analysis.h:401
@ RZ_ANALYSIS_OP_TYPE_OR
Definition: rz_analysis.h:410
@ RZ_ANALYSIS_OP_TYPE_STORE
Definition: rz_analysis.h:415
@ RZ_ANALYSIS_OP_TYPE_CRET
Definition: rz_analysis.h:386
@ RZ_ANALYSIS_OP_TYPE_SHR
Definition: rz_analysis.h:406
@ RZ_ANALYSIS_OP_TYPE_CJMP
Definition: rz_analysis.h:373
@ RZ_ANALYSIS_OP_TYPE_DIV
Definition: rz_analysis.h:405
@ RZ_ANALYSIS_OP_TYPE_UCJMP
Definition: rz_analysis.h:377
@ RZ_ANALYSIS_OP_TYPE_MOV
Definition: rz_analysis.h:390
@ RZ_ANALYSIS_OP_TYPE_SHL
Definition: rz_analysis.h:407
@ RZ_ANALYSIS_OP_TYPE_ILL
Definition: rz_analysis.h:387
@ RZ_ANALYSIS_OP_TYPE_RET
Definition: rz_analysis.h:385
@ RZ_ANALYSIS_OP_TYPE_NOP
Definition: rz_analysis.h:389
@ RZ_ANALYSIS_OP_TYPE_XOR
Definition: rz_analysis.h:412
RZ_API void rz_strbuf_fini(RzStrBuf *sb)
Definition: strbuf.c:365
#define st16
Definition: rz_types_base.h:14
#define a(i)
Definition: sha256.c:41
cs_insn * insn
@ PPC_OP_REG
= CS_OP_REG (Register operand).
Definition: ppc.h:44
@ PPC_OP_CRX
Condition Register field.
Definition: ppc.h:47
@ PPC_BC_LE
Definition: ppc.h:21
@ PPC_BC_EQ
Definition: ppc.h:22
@ PPC_BC_SO
summary overflow
Definition: ppc.h:30
@ PPC_BC_UN
Definition: ppc.h:26
@ PPC_BC_NE
Definition: ppc.h:25
@ PPC_BC_GT
Definition: ppc.h:24
@ PPC_BC_NU
Definition: ppc.h:27
@ PPC_BC_NS
not summary overflow
Definition: ppc.h:31
@ PPC_BC_LT
Definition: ppc.h:20
@ PPC_BC_INVALID
Definition: ppc.h:19
@ PPC_BC_GE
Definition: ppc.h:23
@ PPC_INS_BDZ
Definition: ppc.h:344
@ PPC_INS_CRCLR
Definition: ppc.h:1256
@ PPC_INS_LBZU
Definition: ppc.h:621
@ PPC_INS_CLRLDI
Definition: ppc.h:1327
@ PPC_INS_AND
Definition: ppc.h:322
@ PPC_INS_MTDEAR
Definition: ppc.h:1319
@ PPC_INS_LDU
Definition: ppc.h:628
@ PPC_INS_EXTSB
Definition: ppc.h:565
@ PPC_INS_STWCX
Definition: ppc.h:906
@ PPC_INS_CMPB
Definition: ppc.h:355
@ PPC_INS_CMPDI
Definition: ppc.h:357
@ PPC_INS_MFMSR
Definition: ppc.h:684
@ PPC_INS_SUBF
Definition: ppc.h:913
@ PPC_INS_CMPWI
Definition: ppc.h:363
@ PPC_INS_SLBMFEE
Definition: ppc.h:859
@ PPC_INS_XOR
Definition: ppc.h:1109
@ PPC_INS_LFSU
Definition: ppc.h:638
@ PPC_INS_BT
Definition: ppc.h:1376
@ PPC_INS_SUBFIC
Definition: ppc.h:916
@ PPC_INS_DIVD
Definition: ppc.h:383
@ PPC_INS_LWZ
Definition: ppc.h:667
@ PPC_INS_LWAUX
Definition: ppc.h:664
@ PPC_INS_BLRL
Definition: ppc.h:353
@ PPC_INS_MR
Definition: ppc.h:1324
@ PPC_INS_LWSYNC
Definition: ppc.h:1333
@ PPC_INS_ADDZE
Definition: ppc.h:321
@ PPC_INS_MTICCR
Definition: ppc.h:1318
@ PPC_INS_LFDX
Definition: ppc.h:634
@ PPC_INS_LWZX
Definition: ppc.h:671
@ PPC_INS_MFLR
Definition: ppc.h:683
@ PPC_INS_LBZX
Definition: ppc.h:623
@ PPC_INS_MTSPR
Definition: ppc.h:703
@ PPC_INS_ADDE
Definition: ppc.h:316
@ PPC_INS_MULLW
Definition: ppc.h:713
@ PPC_INS_LHZ
Definition: ppc.h:646
@ PPC_INS_STBU
Definition: ppc.h:871
@ PPC_INS_LDARX
Definition: ppc.h:625
@ PPC_INS_STDU
Definition: ppc.h:878
@ PPC_INS_MTMSR
Definition: ppc.h:700
@ PPC_INS_EXTSW
Definition: ppc.h:567
@ PPC_INS_MFPVR
Definition: ppc.h:1289
@ PPC_INS_BDZL
Definition: ppc.h:346
@ PPC_INS_ANDIS
Definition: ppc.h:324
@ PPC_INS_LDUX
Definition: ppc.h:629
@ PPC_INS_CRMOVE
Definition: ppc.h:1255
@ PPC_INS_BA
Definition: ppc.h:328
@ PPC_INS_BCLRL
Definition: ppc.h:334
@ PPC_INS_OR
Definition: ppc.h:719
@ PPC_INS_LWZU
Definition: ppc.h:669
@ PPC_INS_B
Definition: ppc.h:327
@ PPC_INS_BDZLRL
Definition: ppc.h:349
@ PPC_INS_SLBIA
Definition: ppc.h:857
@ PPC_INS_RLDICL
Definition: ppc.h:850
@ PPC_INS_BDNZLA
Definition: ppc.h:341
@ PPC_INS_BCTR
Definition: ppc.h:335
@ PPC_INS_BCTRL
Definition: ppc.h:336
@ PPC_INS_CRNOT
Definition: ppc.h:1254
@ PPC_INS_BDNZA
Definition: ppc.h:339
@ PPC_INS_SRWI
Definition: ppc.h:1249
@ PPC_INS_LFIWAX
Definition: ppc.h:635
@ PPC_INS_RLWINM
Definition: ppc.h:854
@ PPC_INS_ADDI
Definition: ppc.h:317
@ PPC_INS_BCLR
Definition: ppc.h:333
@ PPC_INS_STW
Definition: ppc.h:903
@ PPC_INS_LWZCIX
Definition: ppc.h:668
@ PPC_INS_BF
Definition: ppc.h:1377
@ PPC_INS_LFSUX
Definition: ppc.h:639
@ PPC_INS_LFIWZX
Definition: ppc.h:636
@ PPC_INS_RLDCR
Definition: ppc.h:848
@ PPC_INS_EIEIO
Definition: ppc.h:568
@ PPC_INS_MTLR
Definition: ppc.h:699
@ PPC_INS_BDNZLRL
Definition: ppc.h:343
@ PPC_INS_SUB
Definition: ppc.h:1331
@ PPC_INS_MTDCCR
Definition: ppc.h:1317
@ PPC_INS_LWZUX
Definition: ppc.h:670
@ PPC_INS_TRAP
Definition: ppc.h:932
@ PPC_INS_STWBRX
Definition: ppc.h:904
@ PPC_INS_BLA
Definition: ppc.h:351
@ PPC_INS_BL
Definition: ppc.h:350
@ PPC_INS_LWARX
Definition: ppc.h:663
@ PPC_INS_LDBRX
Definition: ppc.h:626
@ PPC_INS_LI
Definition: ppc.h:651
@ PPC_INS_BDNZLR
Definition: ppc.h:342
@ PPC_INS_MTMSRD
Definition: ppc.h:701
@ PPC_INS_LFDUX
Definition: ppc.h:633
@ PPC_INS_MSYNC
Definition: ppc.h:691
@ PPC_INS_LBZ
Definition: ppc.h:619
@ PPC_INS_ORI
Definition: ppc.h:717
@ PPC_INS_XORI
Definition: ppc.h:1110
@ PPC_INS_SLBMTE
Definition: ppc.h:860
@ PPC_INS_LIS
Definition: ppc.h:652
@ PPC_INS_SC
Definition: ppc.h:856
@ PPC_INS_ADDIS
Definition: ppc.h:319
@ PPC_INS_LD
Definition: ppc.h:624
@ PPC_INS_MULLD
Definition: ppc.h:711
@ PPC_INS_ADDC
Definition: ppc.h:315
@ PPC_INS_MFDCCR
Definition: ppc.h:1282
@ PPC_INS_BDNZL
Definition: ppc.h:340
@ PPC_INS_NAND
Definition: ppc.h:714
@ PPC_INS_MULLI
Definition: ppc.h:712
@ PPC_INS_CRXOR
Definition: ppc.h:367
@ PPC_INS_LDX
Definition: ppc.h:630
@ PPC_INS_ANDI
Definition: ppc.h:325
@ PPC_INS_SLWI
Definition: ppc.h:1248
@ PPC_INS_LFSX
Definition: ppc.h:640
@ PPC_INS_SUBC
Definition: ppc.h:1332
@ PPC_INS_BC
Definition: ppc.h:329
@ PPC_INS_CMPW
Definition: ppc.h:362
@ PPC_INS_MFSPR
Definition: ppc.h:686
@ PPC_INS_CMPLD
Definition: ppc.h:358
@ PPC_INS_LBZUX
Definition: ppc.h:622
@ PPC_INS_ISYNC
Definition: ppc.h:617
@ PPC_INS_NOP
Definition: ppc.h:716
@ PPC_INS_MFICCR
Definition: ppc.h:1283
@ PPC_INS_SUBFZE
Definition: ppc.h:918
@ PPC_INS_LDCIX
Definition: ppc.h:627
@ PPC_INS_DIVWU
Definition: ppc.h:386
@ PPC_INS_STWUX
Definition: ppc.h:908
@ PPC_INS_STWU
Definition: ppc.h:907
@ PPC_INS_EXTSH
Definition: ppc.h:566
@ PPC_INS_TLBSYNC
Definition: ppc.h:930
@ PPC_INS_MFCTR
Definition: ppc.h:680
@ PPC_INS_SLBIE
Definition: ppc.h:858
@ PPC_INS_LHAU
Definition: ppc.h:642
@ PPC_INS_STH
Definition: ppc.h:890
@ PPC_INS_RLDICR
Definition: ppc.h:851
@ PPC_INS_BDZA
Definition: ppc.h:345
@ PPC_INS_SLW
Definition: ppc.h:862
@ PPC_INS_DIVW
Definition: ppc.h:385
@ PPC_INS_LHA
Definition: ppc.h:641
@ PPC_INS_CMPLDI
Definition: ppc.h:359
@ PPC_INS_STHU
Definition: ppc.h:893
@ PPC_INS_CMPD
Definition: ppc.h:356
@ PPC_INS_ROTLDI
Definition: ppc.h:1326
@ PPC_INS_PTESYNC
Definition: ppc.h:1334
@ PPC_INS_XORIS
Definition: ppc.h:1111
@ PPC_INS_LBZCIX
Definition: ppc.h:620
@ PPC_INS_ORIS
Definition: ppc.h:721
@ PPC_INS_LWA
Definition: ppc.h:662
@ PPC_INS_CRNOR
Definition: ppc.h:371
@ PPC_INS_LHAX
Definition: ppc.h:644
@ PPC_INS_BDNZ
Definition: ppc.h:338
@ PPC_INS_MTCTR
Definition: ppc.h:693
@ PPC_INS_STD
Definition: ppc.h:874
@ PPC_INS_ADD
Definition: ppc.h:314
@ PPC_INS_LFS
Definition: ppc.h:637
@ PPC_INS_CMPLW
Definition: ppc.h:360
@ PPC_INS_CRSET
Definition: ppc.h:1253
@ PPC_INS_RLDCL
Definition: ppc.h:847
@ PPC_INS_LWAX
Definition: ppc.h:665
@ PPC_INS_LHAUX
Definition: ppc.h:643
@ PPC_INS_LFDU
Definition: ppc.h:632
@ PPC_INS_BLR
Definition: ppc.h:352
@ PPC_INS_LHZU
Definition: ppc.h:648
@ PPC_INS_LHBRX
Definition: ppc.h:645
@ PPC_INS_DIVDU
Definition: ppc.h:384
@ PPC_INS_BDZLR
Definition: ppc.h:348
@ PPC_INS_STB
Definition: ppc.h:869
@ PPC_INS_CMPLWI
Definition: ppc.h:361
@ PPC_INS_NOR
Definition: ppc.h:718
@ PPC_INS_ADDME
Definition: ppc.h:320
@ PPC_INS_MFDEAR
Definition: ppc.h:1284
@ PPC_INS_LFD
Definition: ppc.h:631
@ PPC_INS_SYNC
Definition: ppc.h:919
@ PPC_INS_STWX
Definition: ppc.h:909
@ PPC_INS_CLRLWI
Definition: ppc.h:1329
@ PPC_INS_SRW
Definition: ppc.h:868
@ PPC_INS_ADDIC
Definition: ppc.h:318
@ PPC_INS_DCBZ
Definition: ppc.h:380
@ PPC_INS_BDZLA
Definition: ppc.h:347
@ PPC_INS_LWBRX
Definition: ppc.h:666
Definition: dis.c:32
static int addr
Definition: z80asm.c:58

References a, addr, analop_vle(), ARG, ARG2, cmask32(), cmask64(), CS_ARCH_PPC, cs_close(), cs_disasm(), capstone::CS_ERR_OK, cs_free(), CS_MODE_32, CS_MODE_64, CS_MODE_BIG_ENDIAN, CS_MODE_LITTLE_ENDIAN, cs_open(), CS_OPT_DETAIL, CS_OPT_ON, cs_option(), esilprintf, Getarg::handle, handle, IMM, Getarg::insn, len, mask, n, op_fillval(), opex(), PPC_BC_EQ, PPC_BC_GE, PPC_BC_GT, PPC_BC_INVALID, PPC_BC_LE, PPC_BC_LT, PPC_BC_NE, PPC_BC_NS, PPC_BC_NU, PPC_BC_SO, PPC_BC_UN, PPC_INS_ADD, PPC_INS_ADDC, PPC_INS_ADDE, PPC_INS_ADDI, PPC_INS_ADDIC, PPC_INS_ADDIS, PPC_INS_ADDME, PPC_INS_ADDZE, PPC_INS_AND, PPC_INS_ANDI, PPC_INS_ANDIS, PPC_INS_B, PPC_INS_BA, PPC_INS_BC, PPC_INS_BCLR, PPC_INS_BCLRL, PPC_INS_BCTR, PPC_INS_BCTRL, PPC_INS_BDNZ, PPC_INS_BDNZA, PPC_INS_BDNZL, PPC_INS_BDNZLA, PPC_INS_BDNZLR, PPC_INS_BDNZLRL, PPC_INS_BDZ, PPC_INS_BDZA, PPC_INS_BDZL, PPC_INS_BDZLA, PPC_INS_BDZLR, PPC_INS_BDZLRL, PPC_INS_BF, PPC_INS_BL, PPC_INS_BLA, PPC_INS_BLR, PPC_INS_BLRL, PPC_INS_BT, PPC_INS_CLRLDI, PPC_INS_CLRLWI, PPC_INS_CMPB, PPC_INS_CMPD, PPC_INS_CMPDI, PPC_INS_CMPLD, PPC_INS_CMPLDI, PPC_INS_CMPLW, PPC_INS_CMPLWI, PPC_INS_CMPW, PPC_INS_CMPWI, PPC_INS_CRCLR, PPC_INS_CRMOVE, PPC_INS_CRNOR, PPC_INS_CRNOT, PPC_INS_CRSET, PPC_INS_CRXOR, PPC_INS_DCBZ, PPC_INS_DIVD, PPC_INS_DIVDU, PPC_INS_DIVW, PPC_INS_DIVWU, PPC_INS_EIEIO, PPC_INS_EXTSB, PPC_INS_EXTSH, PPC_INS_EXTSW, PPC_INS_ISYNC, PPC_INS_LBZ, PPC_INS_LBZCIX, PPC_INS_LBZU, PPC_INS_LBZUX, PPC_INS_LBZX, PPC_INS_LD, PPC_INS_LDARX, PPC_INS_LDBRX, PPC_INS_LDCIX, PPC_INS_LDU, PPC_INS_LDUX, PPC_INS_LDX, PPC_INS_LFD, PPC_INS_LFDU, PPC_INS_LFDUX, PPC_INS_LFDX, PPC_INS_LFIWAX, PPC_INS_LFIWZX, PPC_INS_LFS, PPC_INS_LFSU, PPC_INS_LFSUX, PPC_INS_LFSX, PPC_INS_LHA, PPC_INS_LHAU, PPC_INS_LHAUX, PPC_INS_LHAX, PPC_INS_LHBRX, PPC_INS_LHZ, PPC_INS_LHZU, PPC_INS_LI, PPC_INS_LIS, PPC_INS_LWA, PPC_INS_LWARX, PPC_INS_LWAUX, PPC_INS_LWAX, PPC_INS_LWBRX, PPC_INS_LWSYNC, PPC_INS_LWZ, PPC_INS_LWZCIX, PPC_INS_LWZU, PPC_INS_LWZUX, PPC_INS_LWZX, PPC_INS_MFCTR, PPC_INS_MFDCCR, PPC_INS_MFDEAR, PPC_INS_MFICCR, PPC_INS_MFLR, PPC_INS_MFMSR, PPC_INS_MFPVR, PPC_INS_MFSPR, PPC_INS_MR, PPC_INS_MSYNC, PPC_INS_MTCTR, PPC_INS_MTDCCR, PPC_INS_MTDEAR, PPC_INS_MTICCR, PPC_INS_MTLR, PPC_INS_MTMSR, PPC_INS_MTMSRD, PPC_INS_MTSPR, PPC_INS_MULLD, PPC_INS_MULLI, PPC_INS_MULLW, PPC_INS_NAND, PPC_INS_NOP, PPC_INS_NOR, PPC_INS_OR, PPC_INS_ORI, PPC_INS_ORIS, PPC_INS_PTESYNC, PPC_INS_RLDCL, PPC_INS_RLDCR, PPC_INS_RLDICL, PPC_INS_RLDICR, PPC_INS_RLWINM, PPC_INS_ROTLDI, PPC_INS_SC, PPC_INS_SLBIA, PPC_INS_SLBIE, PPC_INS_SLBMFEE, PPC_INS_SLBMTE, PPC_INS_SLW, PPC_INS_SLWI, PPC_INS_SRW, PPC_INS_SRWI, PPC_INS_STB, PPC_INS_STBU, PPC_INS_STD, PPC_INS_STDU, PPC_INS_STH, PPC_INS_STHU, PPC_INS_STW, PPC_INS_STWBRX, PPC_INS_STWCX, PPC_INS_STWU, PPC_INS_STWUX, PPC_INS_STWX, PPC_INS_SUB, PPC_INS_SUBC, PPC_INS_SUBF, PPC_INS_SUBFIC, PPC_INS_SUBFZE, PPC_INS_SYNC, PPC_INS_TLBSYNC, PPC_INS_TRAP, PPC_INS_XOR, PPC_INS_XORI, PPC_INS_XORIS, PPC_OP_CRX, PPC_OP_REG, PPCSPR, RZ_ANALYSIS_OP_MASK_DISASM, RZ_ANALYSIS_OP_MASK_ESIL, RZ_ANALYSIS_OP_MASK_OPEX, RZ_ANALYSIS_OP_MASK_VAL, RZ_ANALYSIS_OP_TYPE_ADD, RZ_ANALYSIS_OP_TYPE_AND, RZ_ANALYSIS_OP_TYPE_CALL, RZ_ANALYSIS_OP_TYPE_CJMP, RZ_ANALYSIS_OP_TYPE_CMP, RZ_ANALYSIS_OP_TYPE_CRET, RZ_ANALYSIS_OP_TYPE_DIV, RZ_ANALYSIS_OP_TYPE_ILL, RZ_ANALYSIS_OP_TYPE_JMP, RZ_ANALYSIS_OP_TYPE_LOAD, RZ_ANALYSIS_OP_TYPE_MOV, RZ_ANALYSIS_OP_TYPE_MUL, RZ_ANALYSIS_OP_TYPE_NOP, RZ_ANALYSIS_OP_TYPE_NOR, RZ_ANALYSIS_OP_TYPE_OR, RZ_ANALYSIS_OP_TYPE_RET, RZ_ANALYSIS_OP_TYPE_ROL, RZ_ANALYSIS_OP_TYPE_SHL, RZ_ANALYSIS_OP_TYPE_SHR, RZ_ANALYSIS_OP_TYPE_STORE, RZ_ANALYSIS_OP_TYPE_SUB, RZ_ANALYSIS_OP_TYPE_SWI, RZ_ANALYSIS_OP_TYPE_TRAP, RZ_ANALYSIS_OP_TYPE_UCJMP, RZ_ANALYSIS_OP_TYPE_UJMP, RZ_ANALYSIS_OP_TYPE_XOR, RZ_ANALYSIS_STACK_INC, rz_strbuf_fini(), shrink(), st16, and strdup().

◆ analop_vle()

static int analop_vle ( RzAnalysis a,
RzAnalysisOp op,
ut64  addr,
const ut8 buf,
int  len,
RzAnalysisOpMask  mask 
)
static

Definition at line 417 of file analysis_ppc_cs.c.

417  {
418  vle_t *instr = NULL;
419  vle_handle handle = { 0 };
420  op->size = 2;
421  if (len > 1 && !vle_init(&handle, buf, len) && (instr = vle_next(&handle))) {
422  op->size = instr->size;
423  op->type = instr->analysis_op;
424  // op->id = instr->type;
425 
427  op->mnemonic = strdup(instr->name);
428  }
429  switch (op->type) {
431  break;
433  break;
435  break;
437  op->jump = addr + instr->fields[instr->n - 1].value;
438  op->fail = addr + op->size;
439  break;
441  op->eob = true;
442  op->jump = addr + instr->fields[instr->n - 1].value;
443  op->fail = addr + op->size;
444  break;
446  op->cond = instr->cond; // RZ_TYPE_COND_NE;
447  op->eob = true;
448  op->jump = addr + instr->fields[instr->n - 1].value;
449  op->fail = addr + op->size;
450  break;
452  break;
454  op->jump = addr + instr->fields[instr->n - 1].value;
455  break;
457  break;
459  break;
461  break;
463  break;
465  break;
467  break;
469  break;
471  op->eob = true;
472  break;
474  op->eob = true;
475  break;
477  break;
479  break;
481  break;
483  break;
485  break;
487  break;
489  break;
491  break;
493  break;
494  default:
495  // RZ_LOG_ERROR("Missing an RZ_ANALYSIS_OP_TYPE (%"PFMT64u")\n", op->type);
496  break;
497  }
498  vle_free(instr);
499  return op->size;
500  }
501  return -1;
502 }
#define NULL
Definition: cris-opc.c:27
@ RZ_ANALYSIS_OP_TYPE_SYNC
Definition: rz_analysis.h:431
@ RZ_ANALYSIS_OP_TYPE_ROR
Definition: rz_analysis.h:419
@ RZ_ANALYSIS_OP_TYPE_CCALL
Definition: rz_analysis.h:383
@ RZ_ANALYSIS_OP_TYPE_RJMP
Definition: rz_analysis.h:370
@ RZ_ANALYSIS_OP_TYPE_NOT
Definition: rz_analysis.h:414
@ RZ_ANALYSIS_OP_TYPE_RCALL
Definition: rz_analysis.h:380
ut32 value
Definition: vle.h:26
Definition: vle.h:18
Definition: vle.h:30
const char * name
Definition: vle.h:31
vle_field_t fields[10]
Definition: vle.h:32
ut16 size
Definition: vle.h:34
ut16 n
Definition: vle.h:33
int cond
Definition: vle.h:36
ut32 analysis_op
Definition: vle.h:35
vle_t * vle_next(vle_handle *handle)
Definition: vle.c:889
int vle_init(vle_handle *handle, const ut8 *buffer, const ut32 size)
Definition: vle.c:870
void vle_free(vle_t *instr)
Definition: vle.c:911

References addr, vle_t::analysis_op, vle_t::cond, vle_t::fields, handle, len, mask, vle_t::n, vle_t::name, NULL, RZ_ANALYSIS_OP_MASK_DISASM, RZ_ANALYSIS_OP_TYPE_ADD, RZ_ANALYSIS_OP_TYPE_AND, RZ_ANALYSIS_OP_TYPE_CALL, RZ_ANALYSIS_OP_TYPE_CCALL, RZ_ANALYSIS_OP_TYPE_CJMP, RZ_ANALYSIS_OP_TYPE_CMP, RZ_ANALYSIS_OP_TYPE_ILL, RZ_ANALYSIS_OP_TYPE_JMP, RZ_ANALYSIS_OP_TYPE_LOAD, RZ_ANALYSIS_OP_TYPE_MOV, RZ_ANALYSIS_OP_TYPE_MUL, RZ_ANALYSIS_OP_TYPE_NOT, RZ_ANALYSIS_OP_TYPE_OR, RZ_ANALYSIS_OP_TYPE_RCALL, RZ_ANALYSIS_OP_TYPE_RET, RZ_ANALYSIS_OP_TYPE_RJMP, RZ_ANALYSIS_OP_TYPE_ROL, RZ_ANALYSIS_OP_TYPE_ROR, RZ_ANALYSIS_OP_TYPE_SHL, RZ_ANALYSIS_OP_TYPE_SHR, RZ_ANALYSIS_OP_TYPE_STORE, RZ_ANALYSIS_OP_TYPE_SUB, RZ_ANALYSIS_OP_TYPE_SWI, RZ_ANALYSIS_OP_TYPE_SYNC, RZ_ANALYSIS_OP_TYPE_TRAP, RZ_ANALYSIS_OP_TYPE_XOR, vle_t::size, strdup(), vle_field_t::value, vle_free(), vle_init(), and vle_next().

Referenced by analop().

◆ analysis_preludes()

static RzList* analysis_preludes ( RzAnalysis analysis)
static

Definition at line 1310 of file analysis_ppc_cs.c.

1310  {
1311 #define KW(d, ds, m, ms) rz_list_append(l, rz_search_keyword_new((const ut8 *)d, ds, (const ut8 *)m, ms, NULL))
1313  KW("\x7c\x08\x02\xa6", 4, NULL, 0);
1314  return l;
1315 }
#define KW(d, ds, m, ms)
RZ_API void rz_search_keyword_free(RzSearchKeyword *kw)
Definition: keyword.c:49
RZ_API RZ_OWN RzList * rz_list_newf(RzListFree f)
Returns a new initialized RzList pointer and sets the free method.
Definition: list.c:248
void(* RzListFree)(void *ptr)
Definition: rz_list.h:11

References KW, NULL, rz_list_newf(), and rz_search_keyword_free().

◆ archinfo()

static int archinfo ( RzAnalysis a,
int  q 
)
static

Definition at line 1303 of file analysis_ppc_cs.c.

1303  {
1304  if (a->cpu && !strncmp(a->cpu, "vle", 3)) {
1305  return 2;
1306  }
1307  return 4;
1308 }

References a.

◆ cmask32()

static const char* cmask32 ( const char *  mb_c,
const char *  me_c 
)
static

Definition at line 57 of file analysis_ppc_cs.c.

57  {
58  static char cmask[32];
59  ut32 mb = 0;
60  ut32 me = 0;
61  if (mb_c) {
62  mb = strtol(mb_c, NULL, 16);
63  }
64  if (me_c) {
65  me = strtol(me_c, NULL, 16);
66  }
67  snprintf(cmask, sizeof(cmask), "0x%" PFMT32x "", mask32(mb, me));
68  return cmask;
69 }
#define PFMT32x
static ut32 mask32(ut32 mb, ut32 me)
uint32_t ut32
snprintf
Definition: kernel.h:364

References mask32(), NULL, PFMT32x, and snprintf.

Referenced by analop().

◆ cmask64()

static const char* cmask64 ( const char *  mb_c,
const char *  me_c 
)
static

Definition at line 43 of file analysis_ppc_cs.c.

43  {
44  static char cmask[32];
45  ut64 mb = 0;
46  ut64 me = 0;
47  if (mb_c) {
48  mb = strtol(mb_c, NULL, 16);
49  }
50  if (me_c) {
51  me = strtol(me_c, NULL, 16);
52  }
53  snprintf(cmask, sizeof(cmask), "0x%" PFMT64x "", mask64(mb, me));
54  return cmask;
55 }
static ut64 mask64(ut64 mb, ut64 me)
#define PFMT64x
Definition: rz_types.h:393
ut64(WINAPI *w32_GetEnabledXStateFeatures)()

References mask64(), NULL, PFMT64x, snprintf, and ut64().

Referenced by analop().

◆ create_src_dst()

static void create_src_dst ( RzAnalysisOp op)
static

Definition at line 525 of file analysis_ppc_cs.c.

525  {
526  op->src[0] = rz_analysis_value_new();
527  op->src[1] = rz_analysis_value_new();
528  op->src[2] = rz_analysis_value_new();
529  op->dst = rz_analysis_value_new();
530  ZERO_FILL(base_regs[0]);
531  ZERO_FILL(base_regs[1]);
532  ZERO_FILL(base_regs[2]);
533  ZERO_FILL(base_regs[3]);
534 }
RZ_API RzAnalysisValue * rz_analysis_value_new(void)
Definition: value.c:6
static RzRegItem base_regs[4]
#define ZERO_FILL(x)
Definition: rz_types.h:281

References base_regs, rz_analysis_value_new(), and ZERO_FILL.

Referenced by op_fillval().

◆ get_reg_profile()

static char* get_reg_profile ( RzAnalysis analysis)
static

Definition at line 210 of file analysis_ppc_cs.c.

210  {
211  const char *p = NULL;
212  if (analysis->bits == 32) {
213  p =
214  "=PC pc\n"
215  "=SP r1\n"
216  "=BP r31\n"
217  "=SR srr1\n" // status register ??
218  "=SN r3\n" // also for ret
219  "=A0 r3\n" // also for ret
220  "=A1 r4\n"
221  "=A2 r5\n"
222  "=A3 r6\n"
223  "=A4 r7\n"
224  "=A5 r8\n"
225  "=A6 r6\n"
226  "gpr srr0 .32 0 0\n"
227  "gpr srr1 .32 4 0\n"
228  "gpr r0 .32 8 0\n"
229  "gpr r1 .32 12 0\n"
230  "gpr r2 .32 16 0\n"
231  "gpr r3 .32 20 0\n"
232  "gpr r4 .32 24 0\n"
233  "gpr r5 .32 28 0\n"
234  "gpr r6 .32 32 0\n"
235  "gpr r7 .32 36 0\n"
236  "gpr r8 .32 40 0\n"
237  "gpr r9 .32 44 0\n"
238  "gpr r10 .32 48 0\n"
239  "gpr r11 .32 52 0\n"
240  "gpr r12 .32 56 0\n"
241  "gpr r13 .32 60 0\n"
242  "gpr r14 .32 64 0\n"
243  "gpr r15 .32 68 0\n"
244  "gpr r16 .32 72 0\n"
245  "gpr r17 .32 76 0\n"
246  "gpr r18 .32 80 0\n"
247  "gpr r19 .32 84 0\n"
248  "gpr r20 .32 88 0\n"
249  "gpr r21 .32 92 0\n"
250  "gpr r22 .32 96 0\n"
251  "gpr r23 .32 100 0\n"
252  "gpr r24 .32 104 0\n"
253  "gpr r25 .32 108 0\n"
254  "gpr r26 .32 112 0\n"
255  "gpr r27 .32 116 0\n"
256  "gpr r28 .32 120 0\n"
257  "gpr r29 .32 124 0\n"
258  "gpr r30 .32 128 0\n"
259  "gpr r31 .32 132 0\n"
260  "gpr lr .32 136 0\n"
261  "gpr ctr .32 140 0\n"
262  "gpr msr .32 144 0\n"
263  "gpr pc .32 148 0\n"
264  "gpr cr .64 152 0\n"
265  "gpr cr0 .8 152 0\n"
266  "gpr cr1 .8 153 0\n"
267  "gpr cr2 .8 154 0\n"
268  "gpr cr3 .8 155 0\n"
269  "gpr cr4 .8 156 0\n"
270  "gpr cr5 .8 157 0\n"
271  "gpr cr6 .8 158 0\n"
272  "gpr cr7 .8 159 0\n"
273  "gpr xer .32 160 0\n"
274  "gpr mq .32 164 0\n"
275  "gpr fpscr .32 168 0\n"
276  "gpr vrsave .32 172 0\n"
277  "gpr pvr .32 176 0\n"
278  "gpr dccr .32 180 0\n"
279  "gpr iccr .32 184 0\n"
280  "gpr dear .32 188 0\n"
281  "gpr hid0 .32 192 0\n"
282  "gpr hid1 .32 196 0\n"
283  "gpr hid2 .32 200 0\n"
284  "gpr hid3 .32 204 0\n"
285  "gpr hid4 .32 208 0\n"
286  "gpr hid5 .32 212 0\n"
287  "gpr hid6 .32 216 0\n"
288  "gpr ibat0 .64 220 0\n"
289  "gpr ibat1 .64 228 0\n"
290  "gpr ibat2 .64 236 0\n"
291  "gpr ibat3 .64 244 0\n"
292  "gpr ibat0l .32 220 0\n"
293  "gpr ibat1l .32 228 0\n"
294  "gpr ibat2l .32 236 0\n"
295  "gpr ibat3l .32 244 0\n"
296  "gpr ibat0u .32 224 0\n"
297  "gpr ibat1u .32 232 0\n"
298  "gpr ibat2u .32 240 0\n"
299  "gpr ibat3u .32 248 0\n"
300  "gpr dbat0 .64 256 0\n"
301  "gpr dbat1 .64 264 0\n"
302  "gpr dbat2 .64 272 0\n"
303  "gpr dbat3 .64 280 0\n"
304  "gpr dbat0l .32 256 0\n"
305  "gpr dbat1l .32 264 0\n"
306  "gpr dbat2l .32 272 0\n"
307  "gpr dbat3l .32 280 0\n"
308  "gpr dbat0u .32 260 0\n"
309  "gpr dbat1u .32 268 0\n"
310  "gpr dbat2u .32 276 0\n"
311  "gpr dbat3u .32 284 0\n"
312  "gpr mask .32 288 0\n";
313  } else {
314  p =
315  "=PC pc\n"
316  "=SP r1\n"
317  "=SR srr1\n" // status register ??
318  "=SN r0\n" // also for ret
319  "=A0 r3\n" // also for ret
320  "=A1 r4\n"
321  "=A2 r5\n"
322  "=A3 r6\n"
323  "=A4 r7\n"
324  "=A5 r8\n"
325  "=A6 r6\n"
326  "gpr srr0 .64 0 0\n"
327  "gpr srr1 .64 8 0\n"
328  "gpr r0 .64 16 0\n"
329  "gpr r1 .64 24 0\n"
330  "gpr r2 .64 32 0\n"
331  "gpr r3 .64 40 0\n"
332  "gpr r4 .64 48 0\n"
333  "gpr r5 .64 56 0\n"
334  "gpr r6 .64 64 0\n"
335  "gpr r7 .64 72 0\n"
336  "gpr r8 .64 80 0\n"
337  "gpr r9 .64 88 0\n"
338  "gpr r10 .64 96 0\n"
339  "gpr r11 .64 104 0\n"
340  "gpr r12 .64 112 0\n"
341  "gpr r13 .64 120 0\n"
342  "gpr r14 .64 128 0\n"
343  "gpr r15 .64 136 0\n"
344  "gpr r16 .64 144 0\n"
345  "gpr r17 .64 152 0\n"
346  "gpr r18 .64 160 0\n"
347  "gpr r19 .64 168 0\n"
348  "gpr r20 .64 176 0\n"
349  "gpr r21 .64 184 0\n"
350  "gpr r22 .64 192 0\n"
351  "gpr r23 .64 200 0\n"
352  "gpr r24 .64 208 0\n"
353  "gpr r25 .64 216 0\n"
354  "gpr r26 .64 224 0\n"
355  "gpr r27 .64 232 0\n"
356  "gpr r28 .64 240 0\n"
357  "gpr r29 .64 248 0\n"
358  "gpr r30 .64 256 0\n"
359  "gpr r31 .64 264 0\n"
360  "gpr lr .64 272 0\n"
361  "gpr ctr .64 280 0\n"
362  "gpr msr .64 288 0\n"
363  "gpr pc .64 296 0\n"
364  "gpr cr .64 304 0\n"
365  "gpr cr0 .8 304 0\n"
366  "gpr cr1 .8 305 0\n"
367  "gpr cr2 .8 306 0\n"
368  "gpr cr3 .8 307 0\n"
369  "gpr cr4 .8 308 0\n"
370  "gpr cr5 .8 309 0\n"
371  "gpr cr6 .8 310 0\n"
372  "gpr cr7 .8 311 0\n"
373  "gpr xer .64 312 0\n"
374  "gpr mq .64 320 0\n"
375  "gpr fpscr .64 328 0\n"
376  "gpr vrsave .64 336 0\n"
377  "gpr pvr .64 344 0\n"
378  "gpr dccr .32 352 0\n"
379  "gpr iccr .32 356 0\n"
380  "gpr dear .32 360 0\n"
381  "gpr hid0 .64 364 0\n"
382  "gpr hid1 .64 372 0\n"
383  "gpr hid2 .64 380 0\n"
384  "gpr hid3 .64 388 0\n"
385  "gpr hid4 .64 396 0\n"
386  "gpr hid5 .64 404 0\n"
387  "gpr hid6 .64 412 0\n"
388  "gpr ibat0 .64 420 0\n"
389  "gpr ibat1 .64 428 0\n"
390  "gpr ibat2 .64 436 0\n"
391  "gpr ibat3 .64 444 0\n"
392  "gpr ibat0l .32 420 0\n"
393  "gpr ibat1l .32 428 0\n"
394  "gpr ibat2l .32 436 0\n"
395  "gpr ibat3l .32 444 0\n"
396  "gpr ibat0u .32 424 0\n"
397  "gpr ibat1u .32 432 0\n"
398  "gpr ibat2u .32 440 0\n"
399  "gpr ibat3u .32 448 0\n"
400  "gpr dbat0 .64 456 0\n"
401  "gpr dbat1 .64 464 0\n"
402  "gpr dbat2 .64 472 0\n"
403  "gpr dbat3 .64 480 0\n"
404  "gpr dbat0l .32 456 0\n"
405  "gpr dbat1l .32 464 0\n"
406  "gpr dbat2l .32 472 0\n"
407  "gpr dbat3l .32 480 0\n"
408  "gpr dbat0u .32 460 0\n"
409  "gpr dbat1u .32 468 0\n"
410  "gpr dbat2u .32 476 0\n"
411  "gpr dbat3u .32 484 0\n"
412  "gpr mask .64 488 0\n"; // not a real register used on complex functions
413  }
414  return strdup(p);
415 }
void * p
Definition: libc.cpp:67

References rz_analysis_t::bits, NULL, p, and strdup().

◆ getarg()

static ut64 getarg ( struct Getarg gop,
int  n 
)
static

Definition at line 108 of file analysis_ppc_cs.c.

108  {
109  ut64 value = 0;
110  cs_insn *insn = gop->insn;
111  cs_ppc_op op;
112 
113  if (n < 0 || n >= 8) {
114  return 0;
115  }
116 
117  op = INSOP(n);
118  switch (op.type) {
119  case PPC_OP_INVALID:
120  break;
121  case PPC_OP_REG:
122  value = op.reg;
123  break;
124  case PPC_OP_IMM:
125  value = (ut64)op.imm;
126  break;
127  case PPC_OP_MEM:
128  value = op.mem.disp + op.mem.base;
129  break;
130  case PPC_OP_CRX: // Condition Register field
131  value = (ut64)op.imm;
132  break;
133  }
134  return value;
135 }
ut8 op
Definition: 6502dis.c:13
#define INSOP(n)
static int value
Definition: cmd_api.c:93
Instruction operand.
Definition: ppc.h:283
@ PPC_OP_IMM
= CS_OP_IMM (Immediate operand).
Definition: ppc.h:45
@ PPC_OP_MEM
= CS_OP_MEM (Memory operand).
Definition: ppc.h:46
@ PPC_OP_INVALID
= CS_OP_INVALID (Uninitialized).
Definition: ppc.h:43

References Getarg::insn, INSOP, n, op, PPC_OP_CRX, PPC_OP_IMM, PPC_OP_INVALID, PPC_OP_MEM, PPC_OP_REG, ut64(), and value.

Referenced by getspr().

◆ getarg2()

static char* getarg2 ( struct Getarg gop,
int  n,
const char *  setstr 
)
static

Definition at line 71 of file analysis_ppc_cs.c.

71  {
72  cs_insn *insn = gop->insn;
73  csh handle = gop->handle;
74  static char words[8][64];
75  cs_ppc_op op;
76 
77  if (n < 0 || n >= 8) {
78  return NULL;
79  }
80  op = INSOP(n);
81  switch (op.type) {
82  case PPC_OP_INVALID:
83  words[n][0] = '\0';
84  // strcpy (words[n], "invalid");
85  break;
86  case PPC_OP_REG:
87  snprintf(words[n], sizeof(words[n]),
88  "%s%s", cs_reg_name(handle, op.reg), setstr);
89  break;
90  case PPC_OP_IMM:
91  snprintf(words[n], sizeof(words[n]),
92  "0x%" PFMT64x "%s", (ut64)op.imm, setstr);
93  break;
94  case PPC_OP_MEM:
95  snprintf(words[n], sizeof(words[n]),
96  "%" PFMT64d ",%s,+,%s",
97  (ut64)op.mem.disp,
98  cs_reg_name(handle, op.mem.base), setstr);
99  break;
100  case PPC_OP_CRX: // Condition Register field
101  snprintf(words[n], sizeof(words[n]),
102  "%" PFMT64d "%s", (ut64)op.imm, setstr);
103  break;
104  }
105  return words[n];
106 }
CAPSTONE_EXPORT const char *CAPSTONE_API cs_reg_name(csh ud, unsigned int reg)
Definition: cs.c:1154
#define PFMT64d
Definition: rz_types.h:394

References cs_reg_name(), Getarg::handle, handle, Getarg::insn, INSOP, n, NULL, op, PFMT64d, PFMT64x, PPC_OP_CRX, PPC_OP_IMM, PPC_OP_INVALID, PPC_OP_MEM, PPC_OP_REG, snprintf, and ut64().

◆ getspr()

static const char* getspr ( struct Getarg gop,
int  n 
)
static

Definition at line 137 of file analysis_ppc_cs.c.

137  {
138  static char cspr[16];
139  ut32 spr = 0;
140  if (n < 0 || n >= 8) {
141  return NULL;
142  }
143  spr = getarg(gop, 0);
144  switch (spr) {
145  case SPR_HID0:
146  return "hid0";
147  case SPR_HID1:
148  return "hid1";
149  case SPR_HID2:
150  return "hid2";
151  case SPR_HID4:
152  return "hid4";
153  case SPR_HID5:
154  return "hid5";
155  case SPR_HID6:
156  return "hid6";
157  default:
158  snprintf(cspr, sizeof(cspr), "spr_%u", spr);
159  break;
160  }
161  return cspr;
162 }
#define SPR_HID0
#define SPR_HID2
#define SPR_HID1
#define SPR_HID5
static ut64 getarg(struct Getarg *gop, int n)
#define SPR_HID4
#define SPR_HID6

References getarg(), NULL, snprintf, SPR_HID0, SPR_HID1, SPR_HID2, SPR_HID4, SPR_HID5, and SPR_HID6.

◆ mask32()

static ut32 mask32 ( ut32  mb,
ut32  me 
)
static

Definition at line 37 of file analysis_ppc_cs.c.

37  {
38  ut32 maskmb = UT32_MAX >> mb;
39  ut32 maskme = UT32_MAX << (31 - me);
40  return (mb <= me) ? maskmb & maskme : maskmb | maskme;
41 }
#define UT32_MAX
Definition: rz_types_base.h:99

References UT32_MAX.

Referenced by cmask32().

◆ mask64()

static ut64 mask64 ( ut64  mb,
ut64  me 
)
static

Definition at line 31 of file analysis_ppc_cs.c.

31  {
32  ut64 maskmb = UT64_MAX >> mb;
33  ut64 maskme = UT64_MAX << (63 - me);
34  return (mb <= me) ? maskmb & maskme : maskmb | maskme;
35 }
#define UT64_MAX
Definition: rz_types_base.h:86

References ut64(), and UT64_MAX.

Referenced by cmask64().

◆ op_fillval()

static void op_fillval ( RzAnalysisOp op,
csh  handle,
cs_insn *  insn 
)
static

Definition at line 554 of file analysis_ppc_cs.c.

554  {
556  switch (op->type & RZ_ANALYSIS_OP_TYPE_MASK) {
577  set_src_dst(op->src[2], &handle, insn, 3);
578  set_src_dst(op->src[1], &handle, insn, 2);
579  set_src_dst(op->src[0], &handle, insn, 1);
580  set_src_dst(op->dst, &handle, insn, 0);
581  break;
583  set_src_dst(op->dst, &handle, insn, 1);
584  set_src_dst(op->src[0], &handle, insn, 0);
585  break;
586  }
587 }
static void create_src_dst(RzAnalysisOp *op)
static void set_src_dst(RzAnalysisValue *val, csh *handle, cs_insn *insn, int x)
#define RZ_ANALYSIS_OP_TYPE_MASK
Definition: rz_analysis.h:358
@ RZ_ANALYSIS_OP_TYPE_SAL
Definition: rz_analysis.h:408
@ RZ_ANALYSIS_OP_TYPE_SAR
Definition: rz_analysis.h:409
@ RZ_ANALYSIS_OP_TYPE_CAST
Definition: rz_analysis.h:426
@ RZ_ANALYSIS_OP_TYPE_LEA
Definition: rz_analysis.h:417

References create_src_dst(), handle, RZ_ANALYSIS_OP_TYPE_ADD, RZ_ANALYSIS_OP_TYPE_AND, RZ_ANALYSIS_OP_TYPE_CAST, RZ_ANALYSIS_OP_TYPE_CMP, RZ_ANALYSIS_OP_TYPE_DIV, RZ_ANALYSIS_OP_TYPE_LEA, RZ_ANALYSIS_OP_TYPE_LOAD, RZ_ANALYSIS_OP_TYPE_MASK, RZ_ANALYSIS_OP_TYPE_MOV, RZ_ANALYSIS_OP_TYPE_MUL, RZ_ANALYSIS_OP_TYPE_NOR, RZ_ANALYSIS_OP_TYPE_NOT, RZ_ANALYSIS_OP_TYPE_OR, RZ_ANALYSIS_OP_TYPE_ROL, RZ_ANALYSIS_OP_TYPE_ROR, RZ_ANALYSIS_OP_TYPE_SAL, RZ_ANALYSIS_OP_TYPE_SAR, RZ_ANALYSIS_OP_TYPE_SHL, RZ_ANALYSIS_OP_TYPE_SHR, RZ_ANALYSIS_OP_TYPE_STORE, RZ_ANALYSIS_OP_TYPE_SUB, RZ_ANALYSIS_OP_TYPE_XOR, and set_src_dst().

Referenced by analop().

◆ opex()

static void opex ( RzStrBuf buf,
csh  handle,
cs_insn *  insn 
)
static

Definition at line 164 of file analysis_ppc_cs.c.

164  {
165  int i;
166  PJ *pj = pj_new();
167  if (!pj) {
168  return;
169  }
170  pj_o(pj);
171  pj_ka(pj, "operands");
172  cs_ppc *x = &insn->detail->ppc;
173  for (i = 0; i < x->op_count; i++) {
174  cs_ppc_op *op = x->operands + i;
175  pj_o(pj);
176  switch (op->type) {
177  case PPC_OP_REG:
178  pj_ks(pj, "type", "reg");
179  pj_ks(pj, "value", cs_reg_name(handle, op->reg));
180  break;
181  case PPC_OP_IMM:
182  pj_ks(pj, "type", "imm");
183  pj_kN(pj, "value", op->imm);
184  break;
185  case PPC_OP_MEM:
186  pj_ks(pj, "type", "mem");
187  if (op->mem.base != PPC_REG_INVALID) {
188  pj_ks(pj, "base", cs_reg_name(handle, op->mem.base));
189  }
190  pj_ki(pj, "disp", op->mem.disp);
191  break;
192  default:
193  pj_ks(pj, "type", "invalid");
194  break;
195  }
196  pj_end(pj); /* o operand */
197  }
198  pj_end(pj); /* a operands */
199  pj_end(pj);
200 
203  pj_free(pj);
204 }
lzma_index ** i
Definition: index.h:629
int x
Definition: mipsasm.c:20
RZ_API PJ * pj_ka(PJ *j, const char *k)
Definition: pj.c:163
RZ_API PJ * pj_new(void)
Definition: pj.c:25
RZ_API PJ * pj_ki(PJ *j, const char *k, int d)
Definition: pj.c:149
RZ_API PJ * pj_end(PJ *j)
Definition: pj.c:87
RZ_API const char * pj_string(PJ *pj)
Definition: pj.c:57
RZ_API void pj_free(PJ *j)
Definition: pj.c:34
RZ_API PJ * pj_o(PJ *j)
Definition: pj.c:75
RZ_API PJ * pj_ks(PJ *j, const char *k, const char *v)
Definition: pj.c:170
RZ_API PJ * pj_kN(PJ *j, const char *k, st64 n)
Definition: pj.c:128
RZ_API bool rz_strbuf_append(RzStrBuf *sb, const char *s)
Definition: strbuf.c:222
RZ_API void rz_strbuf_init(RzStrBuf *sb)
Definition: strbuf.c:33
Instruction structure.
Definition: ppc.h:294
Definition: rz_pj.h:12
@ PPC_REG_INVALID
Definition: ppc.h:52

References cs_reg_name(), handle, i, pj_end(), pj_free(), pj_ka(), pj_ki(), pj_kN(), pj_ks(), pj_new(), pj_o(), pj_string(), PPC_OP_IMM, PPC_OP_MEM, PPC_OP_REG, PPC_REG_INVALID, rz_strbuf_append(), rz_strbuf_init(), and x.

Referenced by analop().

◆ parse_reg_name()

static int parse_reg_name ( RzRegItem reg,
csh  handle,
cs_insn *  insn,
int  reg_num 
)
static

Definition at line 504 of file analysis_ppc_cs.c.

504  {
505  if (!reg) {
506  return -1;
507  }
508  switch (INSOP(reg_num).type) {
509  case PPC_OP_REG:
510  reg->name = (char *)cs_reg_name(handle, INSOP(reg_num).reg);
511  break;
512  case PPC_OP_MEM:
513  if (INSOP(reg_num).mem.base != PPC_REG_INVALID) {
514  reg->name = (char *)cs_reg_name(handle, INSOP(reg_num).mem.base);
515  }
516  break;
517  default:
518  break;
519  }
520  return 0;
521 }
#define reg(n)
int type
Definition: mipsasm.c:17

References cs_reg_name(), handle, INSOP, PPC_OP_MEM, PPC_OP_REG, PPC_REG_INVALID, reg, and type.

Referenced by set_src_dst().

◆ set_src_dst()

static void set_src_dst ( RzAnalysisValue val,
csh handle,
cs_insn *  insn,
int  x 
)
static

Definition at line 536 of file analysis_ppc_cs.c.

536  {
537  cs_ppc_op ppcop = INSOP(x);
538  parse_reg_name(&base_regs[x], *handle, insn, x);
539  switch (ppcop.type) {
540  case PPC_OP_REG:
541  break;
542  case PPC_OP_MEM:
543  val->delta = ppcop.mem.disp;
544  break;
545  case PPC_OP_IMM:
546  val->imm = ppcop.imm;
547  break;
548  default:
549  break;
550  }
551  val->reg = &base_regs[x];
552 }
static int parse_reg_name(RzRegItem *reg, csh handle, cs_insn *insn, int reg_num)
ut16 val
Definition: armass64_const.h:6
ppc_op_mem mem
base/disp value for MEM operand
Definition: ppc.h:288
ppc_op_type type
operand type
Definition: ppc.h:284
int64_t imm
immediate value for IMM operand
Definition: ppc.h:287
int32_t disp
displacement/offset value
Definition: ppc.h:273

References base_regs, ppc_op_mem::disp, handle, cs_ppc_op::imm, INSOP, cs_ppc_op::mem, parse_reg_name(), PPC_OP_IMM, PPC_OP_MEM, PPC_OP_REG, cs_ppc_op::type, val, and x.

Referenced by op_fillval().

◆ shrink()

static char* shrink ( char *  op)
static

Definition at line 589 of file analysis_ppc_cs.c.

589  {
590  if (!op) {
591  return NULL;
592  }
593  size_t len = strlen(op);
594  if (!len) {
595  return NULL;
596  }
597  op[len - 1] = 0;
598  return op;
599 }

References len, NULL, and op.

Referenced by analop().

Variable Documentation

◆ base_regs

RzRegItem base_regs[4]
static

Definition at line 523 of file analysis_ppc_cs.c.

Referenced by create_src_dst(), and set_src_dst().

◆ rizin_plugin

RZ_API RzLibStruct rizin_plugin
Initial value:
= {
}
RzAnalysisPlugin rz_analysis_plugin_ppc_cs
@ RZ_LIB_TYPE_ANALYSIS
Definition: rz_lib.h:73
#define RZ_VERSION
Definition: rz_version.h:8
const char * version
Definition: rz_analysis.h:1239

Definition at line 1331 of file analysis_ppc_cs.c.

◆ rz_analysis_plugin_ppc_cs

RzAnalysisPlugin rz_analysis_plugin_ppc_cs
Initial value:
= {
.name = "ppc",
.desc = "Capstone PowerPC analysis",
.license = "BSD",
.esil = true,
.arch = "ppc",
.bits = 32 | 64,
.archinfo = archinfo,
.preludes = analysis_preludes,
.op = &analop,
.get_reg_profile = &get_reg_profile,
}
static char * get_reg_profile(RzAnalysis *analysis)
static int archinfo(RzAnalysis *a, int q)
static int analop(RzAnalysis *a, RzAnalysisOp *op, ut64 addr, const ut8 *buf, int len, RzAnalysisOpMask mask)
static RzList * analysis_preludes(RzAnalysis *analysis)

Definition at line 1317 of file analysis_ppc_cs.c.