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

📄 cplus-dem.c

📁 功能较全面的反汇编器:反汇编器ht-2.0.15.tar.gz
💻 C
📖 第 1 页 / 共 5 页
字号:
static void remember_Ktype (struct work_stuff *, const char *, int);static void forget_types (struct work_stuff *);static void forget_B_and_K_types (struct work_stuff *);static void string_prepends (string *, string *);static intdemangle_template_value_parm (struct work_stuff*, const char**,                              string*, type_kind_t);static intdo_hpacc_template_const_value (struct work_stuff *, const char **, string *);static intdo_hpacc_template_literal (struct work_stuff *, const char **, string *);static int snarf_numeric_literal (const char **, string *);/* There is a TYPE_QUAL value for each type qualifier.  They can be   combined by bitwise-or to form the complete set of qualifiers for a   type.  */#define TYPE_UNQUALIFIED   0x0#define TYPE_QUAL_CONST    0x1#define TYPE_QUAL_VOLATILE 0x2#define TYPE_QUAL_RESTRICT 0x4static int code_for_qualifier (int);static const char* qualifier_string (int);static const char* demangle_qualifier (int);static int demangle_expression (struct work_stuff *, const char **, string *,                                 type_kind_t);static intdemangle_integral_value (struct work_stuff *, const char **, string *);static intdemangle_real_value (struct work_stuff *, const char **, string *);static voiddemangle_arm_hp_template (struct work_stuff *, const char **, int, string *);static voidrecursively_demangle (struct work_stuff *, const char **, string *, int);static void grow_vect (char **, size_t *, size_t, int);/* Translate count to integer, consuming tokens in the process.   Conversion terminates on the first non-digit character.   Trying to consume something that isn't a count results in no   consumption of input and a return of -1.   Overflow consumes the rest of the digits, and returns -1.  */static intconsume_count (const char **type){  int count = 0;  if (! ISDIGIT ((unsigned char)**type))    return -1;  while (ISDIGIT ((unsigned char)**type))    {      count *= 10;      /* Check for overflow.	 We assume that count is represented using two's-complement;	 no power of two is divisible by ten, so if an overflow occurs	 when multiplying by ten, the result will not be a multiple of	 ten.  */      if ((count % 10) != 0)	{	  while (ISDIGIT ((unsigned char) **type))	    (*type)++;	  return -1;	}      count += **type - '0';      (*type)++;    }  if (count < 0)    count = -1;  return (count);}/* Like consume_count, but for counts that are preceded and followed   by '_' if they are greater than 10.  Also, -1 is returned for   failure, since 0 can be a valid value.  */static intconsume_count_with_underscores (const char **mangled){  int idx;  if (**mangled == '_')    {      (*mangled)++;      if (!ISDIGIT ((unsigned char)**mangled))	return -1;      idx = consume_count (mangled);      if (**mangled != '_')	/* The trailing underscore was missing. */	return -1;      (*mangled)++;    }  else    {      if (**mangled < '0' || **mangled > '9')	return -1;      idx = **mangled - '0';      (*mangled)++;    }  return idx;}/* C is the code for a type-qualifier.  Return the TYPE_QUAL   corresponding to this qualifier.  */static intcode_for_qualifier (int c){  switch (c)    {    case 'C':      return TYPE_QUAL_CONST;    case 'V':      return TYPE_QUAL_VOLATILE;    case 'u':      return TYPE_QUAL_RESTRICT;    default:      break;    }  /* C was an invalid qualifier.  */  abort ();}/* Return the string corresponding to the qualifiers given by   TYPE_QUALS.  */static const char*qualifier_string (int type_quals){  switch (type_quals)    {    case TYPE_UNQUALIFIED:      return "";    case TYPE_QUAL_CONST:      return "const";    case TYPE_QUAL_VOLATILE:      return "volatile";    case TYPE_QUAL_RESTRICT:      return "__restrict";    case TYPE_QUAL_CONST | TYPE_QUAL_VOLATILE:      return "const volatile";    case TYPE_QUAL_CONST | TYPE_QUAL_RESTRICT:      return "const __restrict";    case TYPE_QUAL_VOLATILE | TYPE_QUAL_RESTRICT:      return "volatile __restrict";    case TYPE_QUAL_CONST | TYPE_QUAL_VOLATILE | TYPE_QUAL_RESTRICT:      return "const volatile __restrict";    default:      break;    }  /* TYPE_QUALS was an invalid qualifier set.  */  abort ();}/* C is the code for a type-qualifier.  Return the string   corresponding to this qualifier.  This function should only be   called with a valid qualifier code.  */static const char*demangle_qualifier (int c){  return qualifier_string (code_for_qualifier (c));}intcplus_demangle_opname (const char *opname, char *result, int options){  int len, len1, ret;  string type;  struct work_stuff work[1];  const char *tem;  len = strlen(opname);  result[0] = '\0';  ret = 0;  memset ((char *) work, 0, sizeof (work));  work->options = options;  if (opname[0] == '_' && opname[1] == '_'      && opname[2] == 'o' && opname[3] == 'p')    {      /* ANSI.  */      /* type conversion operator.  */      tem = opname + 4;      if (do_type (work, &tem, &type))	{	  strcat (result, "operator ");	  strncat (result, type.b, type.p - type.b);	  string_delete (&type);	  ret = 1;	}    }  else if (opname[0] == '_' && opname[1] == '_'	   && ISLOWER((unsigned char)opname[2])	   && ISLOWER((unsigned char)opname[3]))    {      if (opname[4] == '\0')	{	  /* Operator.  */	  size_t i;	  for (i = 0; i < ARRAY_SIZE (optable); i++)	    {	      if (strlen (optable[i].in) == 2		  && memcmp (optable[i].in, opname + 2, 2) == 0)		{		  strcat (result, "operator");		  strcat (result, optable[i].out);		  ret = 1;		  break;		}	    }	}      else	{	  if (opname[2] == 'a' && opname[5] == '\0')	    {	      /* Assignment.  */	      size_t i;	      for (i = 0; i < ARRAY_SIZE (optable); i++)		{		  if (strlen (optable[i].in) == 3		      && memcmp (optable[i].in, opname + 2, 3) == 0)		    {		      strcat (result, "operator");		      strcat (result, optable[i].out);		      ret = 1;		      break;		    }		}	    }	}    }  else if (len >= 3	   && opname[0] == 'o'	   && opname[1] == 'p'	   && strchr (cplus_markers, opname[2]) != NULL)    {      /* see if it's an assignment expression */      if (len >= 10 /* op$assign_ */	  && memcmp (opname + 3, "assign_", 7) == 0)	{	  size_t i;	  for (i = 0; i < ARRAY_SIZE (optable); i++)	    {	      len1 = len - 10;	      if ((int) strlen (optable[i].in) == len1		  && memcmp (optable[i].in, opname + 10, len1) == 0)		{		  strcat (result, "operator");		  strcat (result, optable[i].out);		  strcat (result, "=");		  ret = 1;		  break;		}	    }	}      else	{	  size_t i;	  for (i = 0; i < ARRAY_SIZE (optable); i++)	    {	      len1 = len - 3;	      if ((int) strlen (optable[i].in) == len1		  && memcmp (optable[i].in, opname + 3, len1) == 0)		{		  strcat (result, "operator");		  strcat (result, optable[i].out);		  ret = 1;		  break;		}	    }	}    }  else if (len >= 5 && memcmp (opname, "type", 4) == 0	   && strchr (cplus_markers, opname[4]) != NULL)    {      /* type conversion operator */      tem = opname + 5;      if (do_type (work, &tem, &type))	{	  strcat (result, "operator ");	  strncat (result, type.b, type.p - type.b);	  string_delete (&type);	  ret = 1;	}    }  squangle_mop_up (work);  return ret;}/* Takes operator name as e.g. "++" and returns mangled   operator name (e.g. "postincrement_expr"), or NULL if not found.   If OPTIONS & DMGL_ANSI == 1, return the ANSI name;   if OPTIONS & DMGL_ANSI == 0, return the old GNU name.  */const char *cplus_mangle_opname (const char *opname, int options){  size_t i;  int len;  len = strlen (opname);  for (i = 0; i < ARRAY_SIZE (optable); i++)    {      if ((int) strlen (optable[i].out) == len	  && (options & DMGL_ANSI) == (optable[i].flags & DMGL_ANSI)	  && memcmp (optable[i].out, opname, len) == 0)	return optable[i].in;    }  return (0);}/* Add a routine to set the demangling style to be sure it is valid and   allow for any demangler initialization that maybe necessary. */enum demangling_stylescplus_demangle_set_style (enum demangling_styles style){  const struct demangler_engine *demangler = libiberty_demanglers;   for (; demangler->demangling_style != unknown_demangling; ++demangler)    if (style == demangler->demangling_style)      {	current_demangling_style = style;	return current_demangling_style;      }  return unknown_demangling;}/* Do string name to style translation */enum demangling_stylescplus_demangle_name_to_style (const char *name){  const struct demangler_engine *demangler = libiberty_demanglers;   for (; demangler->demangling_style != unknown_demangling; ++demangler)    if (strcmp (name, demangler->demangling_style_name) == 0)      return demangler->demangling_style;  return unknown_demangling;}/* char *cplus_demangle (const char *mangled, int options)   If MANGLED is a mangled function name produced by GNU C++, then   a pointer to a @code{malloc}ed string giving a C++ representation   of the name will be returned; otherwise NULL will be returned.   It is the caller's responsibility to free the string which   is returned.   The OPTIONS arg may contain one or more of the following bits:   	DMGL_ANSI	ANSI qualifiers such as `const' and `void' are			included.	DMGL_PARAMS	Function parameters are included.   For example,   cplus_demangle ("foo__1Ai", DMGL_PARAMS)		=> "A::foo(int)"   cplus_demangle ("foo__1Ai", DMGL_PARAMS | DMGL_ANSI)	=> "A::foo(int)"   cplus_demangle ("foo__1Ai", 0)			=> "A::foo"   cplus_demangle ("foo__1Afe", DMGL_PARAMS)		=> "A::foo(float,...)"   cplus_demangle ("foo__1Afe", DMGL_PARAMS | DMGL_ANSI)=> "A::foo(float,...)"   cplus_demangle ("foo__1Afe", 0)			=> "A::foo"   Note that any leading underscores, or other such characters prepended by   the compilation system, are presumed to have already been stripped from   MANGLED.  */char *cplus_demangle (const char *mangled, int options){  char *ret;  struct work_stuff work[1];  if (current_demangling_style == no_demangling)    return xstrdup (mangled);  memset ((char *) work, 0, sizeof (work));  work->options = options;  if ((work->options & DMGL_STYLE_MASK) == 0)    work->options |= (int) current_demangling_style & DMGL_STYLE_MASK;  /* The V3 ABI demangling is implemented elsewhere.  */  if (GNU_V3_DEMANGLING || AUTO_DEMANGLING)    {      ret = cplus_demangle_v3 (mangled, work->options);      if (ret || GNU_V3_DEMANGLING)	return ret;    }  if (JAVA_DEMANGLING)    {      ret = java_demangle_v3 (mangled);      if (ret)        return ret;    }  if (GNAT_DEMANGLING)    return ada_demangle(mangled,options);  ret = internal_cplus_demangle (work, mangled);  squangle_mop_up (work);  return (ret);}/* Assuming *OLD_VECT points to an array of *SIZE objects of size   ELEMENT_SIZE, grow it to contain at least MIN_SIZE objects,   updating *OLD_VECT and *SIZE as necessary.  */static voidgrow_vect (char **old_vect, size_t *size, size_t min_size, int element_size){  if (*size < min_size)    {      *size *= 2;      if (*size < min_size)	*size = min_size;      *old_vect = XRESIZEVAR (char, *old_vect, *size * element_size);    }}/* Demangle ada names:   1. Discard final __{DIGIT}+ or ${DIGIT}+   2. Convert other instances of embedded "__" to `.'.   3. Discard leading _ada_.   4. Remove everything after first ___ if it is followed by 'X'.   5. Put symbols that should be suppressed in <...> brackets.   The resulting string is valid until the next call of ada_demangle.  */static char *ada_demangle (const char *mangled, int option ATTRIBUTE_UNUSED){  int i, j;  int len0;  const char* p;  char *demangled = NULL;  int changed;  size_t demangled_size = 0;    changed = 0;  if (strncmp (mangled, "_ada_", 5) == 0)    {      mangled += 5;      changed = 1;    }

⌨️ 快捷键说明

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