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

📄 jcf-dump.c

📁 gcc-2.95.3 Linux下最常用的C编译器
💻 C
📖 第 1 页 / 共 3 页
字号:
      if (strcmp (arg, "-o") == 0 && argi + 1 < argc)	output_file = argv[++argi];      else if (strcmp (arg, "-classpath") == 0 && argi + 1 < argc)	jcf_path_classpath_arg (argv[++argi]);      else if (strcmp (arg, "-CLASSPATH") == 0 && argi + 1 < argc)	jcf_path_CLASSPATH_arg (argv[++argi]);      else if (strncmp (arg, "-I", 2) == 0)	jcf_path_include_arg (arg + 2);      else if (strcmp (arg, "-verbose") == 0)	verbose++;      else if (strcmp (arg, "-print-main") == 0)	flag_print_main++;      else if (strcmp (arg, "-c") == 0)	flag_disassemble_methods++;      else if (strcmp (arg, "-javap") == 0)	{	  flag_javap_compatible++;	  flag_print_constant_pool = 0;	}      else	{	  fprintf (stderr, "%s: illegal argument\n", argv[argi]);	  exit (FATAL_EXIT_CODE);	}    }  if (argi == argc)    usage ();  jcf_path_seal ();  if (flag_print_main)    {      flag_print_fields = 0;      flag_print_methods = 0;      flag_print_constant_pool = 0;      flag_print_attributes = 0;      flag_print_class_info = 0;    }  if (output_file)    {      out = fopen (output_file, "w");      if (out)	{	  fprintf (stderr, "Cannot open '%s' for output.\n", output_file);	  exit (FATAL_EXIT_CODE);	}    }  else    out = stdout;  if (argi >= argc)    {      fprintf (out, "Reading .class from <standard input>.\n");#if JCF_USE_STDIO      open_class ("<stdio>", jcf, stdin, NULL);#else      open_class ("<stdio>", jcf, 0, NULL);#endif      process_class (jcf);    }  else    {      for (; argi < argc; argi++)	{	  char *arg = argv[argi];	  char* class_filename = find_class (arg, strlen (arg), jcf, 0);	  if (class_filename == NULL)	    class_filename = find_classfile (arg, jcf, NULL);	  if (class_filename == NULL)	    {	      perror ("Could not find class");	      exit (FATAL_EXIT_CODE);	    }	  JCF_FILL (jcf, 4);	  if (GET_u4 (jcf->read_ptr) == ZIPMAGIC)	    {	      long compressed_size, member_size;	      int compression_method, filename_length, extra_length;	      int general_purpose_bits;	      char *filename;	      int total_length;	      if (flag_print_class_info)		fprintf (out, "Reading classes from archive %s.\n",			 class_filename);	      for (;;)		{		  int skip = 0;		  jcf_filbuf_t save_filbuf = jcf->filbuf;		  long magic = JCF_readu4_le (jcf);		  if (magic == 0x02014b50 || magic == 0x06054b50)		    break;  /* got to central directory */		  if (magic != 0x04034b50) /* ZIPMAGIC (little-endian) */		    {		      fprintf (stderr, "bad format of .zip/.jar archive\n");		      exit (FATAL_EXIT_CODE);		    }		  JCF_FILL (jcf, 26);		  JCF_SKIP (jcf, 2);		  general_purpose_bits = JCF_readu2_le (jcf);		  compression_method = JCF_readu2_le (jcf);		  JCF_SKIP (jcf, 8);		  compressed_size = JCF_readu4_le (jcf);		  member_size = JCF_readu4_le (jcf);		  filename_length = JCF_readu2_le (jcf);		  extra_length = JCF_readu2_le (jcf);		  total_length = filename_length + extra_length		    + compressed_size;		  if (jcf->read_end - jcf->read_ptr < total_length)		    jcf_trim_old_input (jcf);		  JCF_FILL (jcf, total_length);		  filename = jcf->read_ptr;		  JCF_SKIP (jcf, filename_length);		  JCF_SKIP (jcf, extra_length);		  if (filename_length > 0		      && filename[filename_length-1] == '/')		    {		      if (flag_print_class_info)			fprintf (out, "[Skipping directory %.*s]\n",				 filename_length, filename);		      skip = 1;		    }		  else if (compression_method != 0)		    {		      if (flag_print_class_info)			fprintf (out, "[Skipping compressed file %.*s]\n",				 filename_length, filename);		      skip = 1;		    }		  else if (member_size < 4			   || GET_u4 (jcf->read_ptr) != 0xcafebabe)		    {		      if (flag_print_class_info)			fprintf (out, "[Skipping non-.class member %.*s]\n",				 filename_length, filename);		      skip = 1;		    }		  else		    {		      if (flag_print_class_info)			fprintf (out, "Reading class member: %.*s.\n",				 filename_length, filename);		    }		  if (skip)		    {		      JCF_SKIP (jcf, compressed_size);		    }		  else		    {		      unsigned char *save_end;		      jcf->filbuf = jcf_unexpected_eof;		      save_end = jcf->read_end;		      jcf->read_end = jcf->read_ptr + compressed_size;		      process_class (jcf);		      jcf->filbuf = save_filbuf;		      jcf->read_end = save_end;		    }		}	    }	  else	    {	      if (flag_print_class_info)		fprintf (out, "Reading .class from %s.\n", class_filename);	      process_class (jcf);	    }	  JCF_FINISH(jcf);	}    }  exit (SUCCESS_EXIT_CODE);}static voidDEFUN(disassemble_method, (jcf, byte_ops, len),      JCF* jcf AND unsigned char *byte_ops AND int len){#undef AND /* Causes problems with opcodes for iand and land. */#undef PTR  int PC;  int i;  int saw_wide = 0;  if (flag_disassemble_methods == 0)    return;#define BCODE byte_ops  for (PC = 0; PC < len;)    {      int oldpc = PC;      int saw_index;      jint INT_temp;      switch (byte_ops[PC++])	{/* This is the actual code emitted for each of opcodes in javaops.def.   The actual opcode-specific stuff is handled by the OPKIND macro.   I.e. for an opcode whose OPKIND is BINOP, the BINOP will be called.   Those macros are defiend below.  The OPKINDs that do not have any   inline parameters (such as BINOP) and therefore do mot need anything   else to me printed out just use an empty body. */#define JAVAOP(OPNAME, OPCODE, OPKIND, OPERAND_TYPE, OPERAND_VALUE) \        case OPCODE: \	  fprintf (out, "%3d: %s", oldpc, #OPNAME); \	  OPKIND(OPERAND_TYPE, OPERAND_VALUE); \	  fputc ('\n', out); \	  break;#define CONST_INDEX_1 (saw_index = 1, IMMEDIATE_u1)#define CONST_INDEX_2 (saw_index = 1, IMMEDIATE_u2)#define VAR_INDEX_1 (saw_index = 1, IMMEDIATE_u1)#define VAR_INDEX_2 (saw_index = 1, IMMEDIATE_u2)#define CHECK_PC_IN_RANGE(PC) (PC < 0 || PC > len ? \  (fprintf(stderr, "Bad byte codes.\n"), exit(-1)) : 1)/* Print out operand (if not implied by the opcode) for PUSCH opcodes.   These all push a constant onto the opcode stack. */#define PUSHC(OPERAND_TYPE, OPERAND_VALUE) \  saw_index = 0, i = (OPERAND_VALUE); \  if (oldpc+1 == PC) /* nothing */; \  else if (saw_index) fprintf (out, " "), print_constant_ref (out, jcf, i); \  else fprintf (out, " %d", i);/* Print out operand (a local variable index) for LOAD opcodes.   These all push local variable onto the opcode stack. */#define LOAD(OPERAND_TYPE, OPERAND_VALUE) \  INT_temp = saw_wide ? IMMEDIATE_u2 : (OPERAND_VALUE); goto load_store;/* Handle STORE opcodes same as LOAD opcodes.   These all store a value from the opcode stack in a local variable. */#define STORE LOAD/* Handle more kind of opcodes. */#define STACK(OPERAND_TYPE, OPERAND_VALUE) /* nothing */#define UNOP(OPERAND_TYPE, OPERAND_VALUE) /* nothing */#define BINOP(OPERAND_TYPE, OPERAND_VALUE) /* nothing */#define CONVERT(OPERAND_TYPE, OPERAND_VALUE) /* nothing */#define CONVERT2(OPERAND_TYPE, OPERAND_VALUE) /* nothing */#define RETURN(OPERAND_TYPE, OPERAND_VALUE) /* nothing */#define UNKNOWN(OPERAND_TYPE, OPERAND_VALUE) /* nothing *//* Handle putfield and getfield opcodes, with static versions. */#define FIELD(MAYBE_STATIC, PUT_OR_GET) \  fputc (' ', out); print_constant_ref (out, jcf, IMMEDIATE_u2)/* Print operand for invoke opcodes. */#define INVOKE(OPERAND_TYPE, OPERAND_VALUE) \  fputc (' ', out); print_constant_ref (out, jcf, IMMEDIATE_u2);\  if (OPERAND_VALUE) /* for invokeinterface */ \  { int nargs = IMMEDIATE_u1;  PC++; \    fprintf (out, " nargs:%d", nargs); }#define OBJECT(OPERAND_TYPE, OPERAND_VALUE) \  fputc (' ', out); print_constant_ref (out, jcf, IMMEDIATE_u2);#define ARRAY(OPERAND_TYPE, SUBOP) \  ARRAY_##SUBOP(OPERAND_TYPE)/* Handle sub-categories of ARRAY opcodes. */#define ARRAY_LOAD(TYPE) /* nothing */#define ARRAY_STORE(TYPE) /* nothing */#define ARRAY_LENGTH(TYPE) /* nothing */#define ARRAY_NEW(TYPE) ARRAY_NEW_##TYPE#define ARRAY_NEW_NUM \ INT_temp = IMMEDIATE_u1; \ { char *str; \  switch (INT_temp) {  \    case  4: str = "boolean"; break; \    case  5: str = "char"; break; \    case  6: str = "float"; break; \    case  7: str = "double"; break; \    case  8: str = "byte"; break; \    case  9: str = "short"; break; \    case 10: str = "int"; break; \    case 11: str = "long"; break; \    default: str = "<unknown type code %d>"; break; \  } \  fputc (' ', out); fprintf (out, str, INT_temp); }#define ARRAY_NEW_PTR  \  fputc (' ', out); print_constant_ref (out, jcf, IMMEDIATE_u2);#define ARRAY_NEW_MULTI \  fputc (' ', out); print_constant_ref (out, jcf, IMMEDIATE_u2); \  fprintf (out, " %d", IMMEDIATE_u1); /* number of dimensions */#define TEST(OPERAND_TYPE, OPERAND_VALUE) \  fprintf (out, " %d", oldpc + IMMEDIATE_s2)#define BRANCH(OPERAND_TYPE, OPERAND_VALUE) \  saw_index = 0, INT_temp = (OPERAND_VALUE); \  fprintf (out, " %ld", (long) (saw_index ? INT_temp : oldpc + INT_temp))#define JSR(OPERAND_TYPE, OPERAND_VALUE) \  saw_index = 0, INT_temp = (OPERAND_VALUE); \  fprintf (out, " %ld", (long) (saw_index ? INT_temp : oldpc + INT_temp))#undef RET /* Defined by config/i386/i386.h */#define RET(OPERAND_TYPE, OPERAND_VALUE) \  INT_temp = saw_wide ? IMMEDIATE_u2 : (OPERAND_VALUE); \  saw_wide = 0; \  fprintf (out, " %ld", (long) INT_temp);#define SWITCH(OPERAND_TYPE, TABLE_OR_LOOKUP) \  PC = (PC + 3) / 4 * 4; TABLE_OR_LOOKUP##_SWITCH#define LOOKUP_SWITCH \  { jint default_offset = IMMEDIATE_s4;  jint npairs = IMMEDIATE_s4; \    fprintf (out, " npairs=%ld, default=%ld", (long) npairs, (long) default_offset+oldpc); \    while (--npairs >= 0) { \     jint match = IMMEDIATE_s4; jint offset = IMMEDIATE_s4; \     fprintf (out, "\n%10ld: %ld", (long)match, (long)(offset+oldpc)); } \  }#define TABLE_SWITCH \  { jint default_offset = IMMEDIATE_s4; \    jint low = IMMEDIATE_s4; jint high = IMMEDIATE_s4; \    fprintf (out, " low=%ld, high=%ld, default=%ld", \      (long) low, (long) high, (long) default_offset+oldpc); \    for (; low <= high; low++) { \     jint offset = IMMEDIATE_s4; \     fprintf (out, "\n%10ld: %ld", (long)low, (long)(offset+oldpc)); } \  }#define SPECIAL(OPERAND_TYPE, OPERAND_VALUE) \  SPECIAL_##OPERAND_VALUE(OPERAND_TYPE)#define SPECIAL_IINC(OPERAND_TYPE) \  i = saw_wide ? IMMEDIATE_u2 : IMMEDIATE_u1; \  fprintf (out, " %d", i); \  INT_temp = saw_wide ? IMMEDIATE_s2 : IMMEDIATE_s1; \  saw_wide = 0; \  fprintf (out, " %d", i)#define SPECIAL_WIDE(OPERAND_TYPE) \  saw_wide = 1;#define SPECIAL_EXIT(OPERAND_TYPE) /* nothing */#define SPECIAL_ENTER(OPERAND_TYPE) /* nothing */#define SPECIAL_BREAK(OPERAND_TYPE) /* nothing */#define SPECIAL_THROW(OPERAND_TYPE) /* nothing */#define IMPL(OPERAND_TYPE, OPERAND_VALUE) \  fprintf (out, " %d", IMMEDIATE_u##OPERAND_VALUE)#define COND(OPERAND_TYPE, OPERAND_VALUE) \   TEST(OPERAND_TYPE, OPERAND_VALUE)#include "javaop.def"	load_store:	  if (oldpc+1 == PC) /* nothing - local index implied by opcode */;	  else	    {	      saw_wide = 0;	      fprintf (out, " %ld", (long) INT_temp);	    }	  fputc ('\n', out);	  break;	default:	  fprintf (out, "%3d: unknown(%3d)\n", oldpc, byte_ops[PC]);	}    }}

⌨️ 快捷键说明

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