⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 i386-pinsn.c

📁 早期freebsd实现
💻 C
📖 第 1 页 / 共 3 页
字号:
  /* d9_5  2 */  {    "fld1","fldl2t","fldl2e","fldpi","fldlg2","fldln2","fldz","(bad)",  },  /* d9_6  3 */  {    "f2xm1","fyl2x","fptan","fpatan","fxtract","fprem1","fdecstp","fincstp",  },  /* d9_7  4 */  {    "fprem","fyl2xp1","fsqrt","fsincos","frndint","fscale","fsin","fcos",  },  /* da_5  5 */  {    "(bad)","fucompp","(bad)","(bad)","(bad)","(bad)","(bad)","(bad)",  },  /* db_4  6 */  {    "feni(287 only)","fdisi(287 only)","fNclex","fNinit",    "fNsetpm(287 only)","(bad)","(bad)","(bad)",  },  /* de_3  7 */  {    "(bad)","fcompp","(bad)","(bad)","(bad)","(bad)","(bad)","(bad)",  },  /* df_4  8 */  {    "fNstsw","(bad)","(bad)","(bad)","(bad)","(bad)","(bad)","(bad)",  },};static voiddofloat (){  struct dis386 *dp;  unsigned char floatop;    floatop = codep[-1];    if (mod != 3)    {      putop (float_mem[(floatop - 0xd8) * 8 + reg]);      obufp = op1out;      OP_E (v_mode);      return;    }  codep++;    dp = &float_reg[floatop - 0xd8][reg];  if (dp->name == NULL)    {      putop (fgrps[dp->bytemode1][rm]);      /* instruction fnstsw is only one with strange arg */      if (floatop == 0xdf && *codep == 0xe0)	strcpy (op1out, "%eax");    }  else    {      putop (dp->name);      obufp = op1out;      if (dp->op1)	(*dp->op1)(dp->bytemode1);      obufp = op2out;      if (dp->op2)	(*dp->op2)(dp->bytemode2);    }}/* ARGSUSED */intOP_ST (ignore)     int ignore;{  oappend ("%st");  return (0);}/* ARGSUSED */intOP_STi (ignore)     int ignore;{  sprintf (scratchbuf, "%%st(%d)", rm);  oappend (scratchbuf);  return (0);}/* capital letters in template are macros */static voidputop (template)     char *template;{  char *p;    for (p = template; *p; p++)    {      switch (*p)	{	default:	  *obufp++ = *p;	  break;	case 'C':		/* For jcxz/jecxz */	  if (aflag == 0)	    *obufp++ = 'e';	  break;	case 'N':	  if ((prefixes & PREFIX_FWAIT) == 0)	    *obufp++ = 'n';	  break;	case 'S':	  /* operand size flag */	  if (dflag)	    *obufp++ = 'l';	  else	    *obufp++ = 'w';	  break;	}    }  *obufp = 0;}static voidoappend (s)     char *s;{  strcpy (obufp, s);  obufp += strlen (s);  *obufp = 0;}static voidappend_prefix (){  if (prefixes & PREFIX_CS)    oappend ("%cs:");  if (prefixes & PREFIX_DS)    oappend ("%ds:");  if (prefixes & PREFIX_SS)    oappend ("%ss:");  if (prefixes & PREFIX_ES)    oappend ("%es:");  if (prefixes & PREFIX_FS)    oappend ("%fs:");  if (prefixes & PREFIX_GS)    oappend ("%gs:");}intOP_indirE (bytemode)     int bytemode;{  oappend ("*");  OP_E (bytemode);  return (0);}intOP_E (bytemode)     int bytemode;{  int disp;  int havesib;  int base;  int index;  int scale;  int havebase;    /* skip mod/rm byte */  codep++;    havesib = 0;  havebase = 0;  disp = 0;    if (mod == 3)    {      switch (bytemode)	{	case b_mode:	  oappend (names8[rm]);	  break;	case w_mode:	  oappend (names16[rm]);	  break;	case v_mode:	  if (dflag)	    oappend (names32[rm]);	  else	    oappend (names16[rm]);	  break;	default:	  oappend ("<bad dis table>");	  break;	}      return (0);    }    append_prefix ();  if (rm == 4)    {      havesib = 1;      havebase = 1;      scale = (*codep >> 6) & 3;      index = (*codep >> 3) & 7;      base = *codep & 7;      codep++;    }    switch (mod)    {    case 0:      switch (rm)	{	case 4:	  /* implies havesib and havebase */	  if (base == 5) {	    havebase = 0;	    disp = get32 ();	  }	  break;	case 5:	  disp = get32 ();	  break;	default:	  havebase = 1;	  base = rm;	  break;	}      break;    case 1:      disp = *(char *)codep++;      if (rm != 4)	{	  havebase = 1;	  base = rm;	}      break;    case 2:      disp = get32 ();      if (rm != 4)	{	  havebase = 1;	  base = rm;	}      break;    }    if (mod != 0 || rm == 5 || (havesib && base == 5))    {      sprintf (scratchbuf, "0x%x", disp);      oappend (scratchbuf);    }    if (havebase || havesib)     {      oappend ("(");      if (havebase)	oappend (names32[base]);      if (havesib) 	{	  if (index != 4) 	    {	      sprintf (scratchbuf, ",%s", names32[index]);	      oappend (scratchbuf);	    }	  sprintf (scratchbuf, ",%d", 1 << scale);	  oappend (scratchbuf);	}      oappend (")");    }  return (0);}intOP_G (bytemode)     int bytemode;{  switch (bytemode)     {    case b_mode:      oappend (names8[reg]);      break;    case w_mode:      oappend (names16[reg]);      break;    case d_mode:      oappend (names32[reg]);      break;    case v_mode:      if (dflag)	oappend (names32[reg]);      else	oappend (names16[reg]);      break;    default:      oappend ("<internal disassembler error>");      break;    }  return (0);}static intget32 (){  int x = 0;    x = *codep++ & 0xff;  x |= (*codep++ & 0xff) << 8;  x |= (*codep++ & 0xff) << 16;  x |= (*codep++ & 0xff) << 24;  return (x);}static intget16 (){  int x = 0;    x = *codep++ & 0xff;  x |= (*codep++ & 0xff) << 8;  return (x);}static voidset_op (op)     int op;{  op_index[op_ad] = op_ad;  op_address[op_ad] = op;}intOP_REG (code)     int code;{  char *s;    switch (code)     {    case indir_dx_reg: s = "(%dx)"; break;	case ax_reg: case cx_reg: case dx_reg: case bx_reg:	case sp_reg: case bp_reg: case si_reg: case di_reg:		s = names16[code - ax_reg];		break;	case es_reg: case ss_reg: case cs_reg:	case ds_reg: case fs_reg: case gs_reg:		s = names_seg[code - es_reg];		break;	case al_reg: case ah_reg: case cl_reg: case ch_reg:	case dl_reg: case dh_reg: case bl_reg: case bh_reg:		s = names8[code - al_reg];		break;	case eAX_reg: case eCX_reg: case eDX_reg: case eBX_reg:	case eSP_reg: case eBP_reg: case eSI_reg: case eDI_reg:      if (dflag)	s = names32[code - eAX_reg];      else	s = names16[code - eAX_reg];      break;    default:      s = "<internal disassembler error>";      break;    }  oappend (s);  return (0);}intOP_I (bytemode)     int bytemode;{  int op;    switch (bytemode)     {    case b_mode:      op = *codep++ & 0xff;      break;    case v_mode:      if (dflag)	op = get32 ();      else	op = get16 ();      break;    case w_mode:      op = get16 ();      break;    default:      oappend ("<internal disassembler error>");      return (0);    }  sprintf (scratchbuf, "$0x%x", op);  oappend (scratchbuf);  return (0);}intOP_sI (bytemode)     int bytemode;{  int op;    switch (bytemode)     {    case b_mode:      op = *(char *)codep++;      break;    case v_mode:      if (dflag)	op = get32 ();      else	op = (short)get16();      break;    case w_mode:      op = (short)get16 ();      break;    default:      oappend ("<internal disassembler error>");      return (0);    }  sprintf (scratchbuf, "$0x%x", op);  oappend (scratchbuf);  return (0);}intOP_J (bytemode)     int bytemode;{  int disp;  int mask = -1;    switch (bytemode)     {    case b_mode:      disp = *(char *)codep++;      break;    case v_mode:      if (dflag)	disp = get32 ();      else	{	  disp = (short)get16 ();	  /* for some reason, a data16 prefix on a jump instruction	     means that the pc is masked to 16 bits after the	     displacement is added!  */	  mask = 0xffff;	}      break;    default:      oappend ("<internal disassembler error>");      return (0);    }  disp = (start_pc + codep - start_codep + disp) & mask;  set_op (disp);  sprintf (scratchbuf, "0x%x", disp);  oappend (scratchbuf);  return (0);}/* ARGSUSED */intOP_SEG (dummy)     int dummy;{  static char *sreg[] = {    "%es","%cs","%ss","%ds","%fs","%gs","%?","%?",  };  oappend (sreg[reg]);  return (0);}intOP_DIR (size)     int size;{  int seg, offset;    switch (size)     {    case lptr:      if (aflag) 	{	  offset = get32 ();	  seg = get16 ();	}       else 	{	  offset = get16 ();	  seg = get16 ();	}      sprintf (scratchbuf, "0x%x,0x%x", seg, offset);      oappend (scratchbuf);      break;    case v_mode:      if (aflag)	offset = get32 ();      else	offset = (short)get16 ();            offset = start_pc + codep - start_codep + offset;      set_op (offset);      sprintf (scratchbuf, "0x%x", offset);      oappend (scratchbuf);      break;    default:      oappend ("<internal disassembler error>");      break;    }  return (0);}/* ARGSUSED */intOP_OFF (bytemode)     int bytemode;{  int off;    if (aflag)    off = get32 ();  else    off = get16 ();    sprintf (scratchbuf, "0x%x", off);  oappend (scratchbuf);  return (0);}/* ARGSUSED */intOP_ESDI (dummy)    int dummy;{  oappend ("%es:(");  oappend (aflag ? "%edi" : "%di");  oappend (")");  return (0);}/* ARGSUSED */intOP_DSSI (dummy)    int dummy;{  oappend ("%ds:(");  oappend (aflag ? "%esi" : "%si");  oappend (")");  return (0);}/* ARGSUSED */intOP_ONE (dummy)    int dummy;{  oappend ("1");  return (0);}/* ARGSUSED */intOP_C (dummy)    int dummy;{  codep++; /* skip mod/rm */  sprintf (scratchbuf, "%%cr%d", reg);  oappend (scratchbuf);  return (0);}/* ARGSUSED */intOP_D (dummy)    int dummy;{  codep++; /* skip mod/rm */  sprintf (scratchbuf, "%%db%d", reg);  oappend (scratchbuf);  return (0);}/* ARGSUSED */intOP_T (dummy)     int dummy;{  codep++; /* skip mod/rm */  sprintf (scratchbuf, "%%tr%d", reg);  oappend (scratchbuf);  return (0);}intOP_rm (bytemode)     int bytemode;{  switch (bytemode)     {    case d_mode:      oappend (names32[rm]);      break;    case w_mode:      oappend (names16[rm]);      break;    }  return (0);}	#define MAXLEN 20intprint_insn (memaddr, stream)     CORE_ADDR memaddr;     FILE *stream;{  unsigned char buffer[MAXLEN];    read_memory (memaddr, (char *) buffer, MAXLEN);    return (i386dis ((int)memaddr, buffer, stream));}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -