Exemplo n.º 1
0
int main(int argc, char* argv[]) {

  bool all = false;
  bool string = false;
  bool stringdata = false;
  bool type = false;
  bool proto = false;
  bool field = false;
  bool meth = false;
  bool clsdef = false;
  bool clsdata = false;
  bool code = false;
  bool enarr = false;
  bool anno = false;
  bool debug = false;
  uint32_t ddebug_offset = 0;

  char c;
  static const struct option options[] = {
    { "all", no_argument, nullptr, 'a' },
    { "string", no_argument, nullptr, 's' },
    { "stringdata", no_argument, nullptr, 'S' },
    { "type", no_argument, nullptr, 't' },
    { "proto", no_argument, nullptr, 'p' },
    { "field", no_argument, nullptr, 'f' },
    { "meth", no_argument, nullptr, 'm' },
    { "clsdef", no_argument, nullptr, 'c' },
    { "clsdata", no_argument, nullptr, 'C' },
    { "code", no_argument, nullptr, 'x' },
    { "enarr", no_argument, nullptr, 'e' },
    { "anno", no_argument, nullptr, 'A' },
    { "debug", no_argument, nullptr, 'd' },
    { "ddebug", required_argument, nullptr, 'D' },
    { "clean", no_argument, (int*)&clean, 1 },
    { "help", no_argument, nullptr, 'h' },
    { nullptr, 0, nullptr, 0 },
  };

  while ((c = getopt_long(
            argc,
            argv,
            "asStpfmcCxeAdDh",
            &options[0],
            nullptr)) != -1) {
    switch (c) {
      case 'a':
        all = true;
        break;
      case 's':
        string = true;
        break;
      case 'S':
        stringdata = true;
        break;
      case 't':
        type = true;
        break;
      case 'p':
        proto = true;
        break;
      case 'f':
        field = true;
        break;
      case 'm':
        meth = true;
        break;
      case 'c':
        clsdef = true;
        break;
      case 'C':
        clsdata = true;
        break;
      case 'x':
        code = true;
        break;
      case 'e':
        enarr = true;
        break;
      case 'A':
        anno = true;
        break;
      case 'd':
        debug = true;
        break;
      case 'D':
        sscanf(optarg, "%x", &ddebug_offset);
        break;
      case 'h':
        puts(ddump_usage_string);
        return 0;
      case '?':
        return 1; // getopt_long has printed an error
      case 0:
        // we're handling a long-only option
        break;
      default:
        abort();
    }
  }

  if (optind == argc) {
    fprintf(stderr, "%s: no dex files given; use -h for help\n", argv[0]);
    return 1;
  }

  while (optind < argc) {
    const char* dexfile = argv[optind++];
    ddump_data rd;
    open_dex_file(dexfile, &rd);
    redump(format_map(&rd).c_str());
    if (string || all) {
      dump_strings(&rd);
    }
    if (stringdata || all) {
      dump_stringdata(&rd);
    }
    if (type || all) {
      dump_types(&rd);
    }
    if (proto || all) {
      dump_protos(&rd);
    }
    if (field || all) {
      dump_fields(&rd);
    }
    if (meth || all) {
      dump_methods(&rd);
    }
    if (clsdef || all) {
      dump_clsdefs(&rd);
    }
    if (clsdata || all) {
      dump_clsdata(&rd);
    }
    if (code || all) {
      dump_code(&rd);
    }
    if (enarr || all) {
      dump_enarr(&rd);
    }
    if (anno || all) {
      dump_anno(&rd);
    }
    if (debug || all) {
      dump_debug(&rd);
    }
    if (ddebug_offset != 0) {
      disassemble_debug(&rd, ddebug_offset);
    }
    fprintf(stdout, "\n");
    fflush(stdout);
  }

  return 0;
}
Exemplo n.º 2
0
/*
 * dump_module_info - dump module info
 */
static void dump_module_info( section_dbg_header *sdh )
/*****************************************************/
{
    unsigned_32 bytes_read;
    mod_info    *mi;
    unsigned_32 total_bytes;
    long        cpos;
    char        name[256];
    unsigned_16 index;
    mod_info    *tmi;

    total_bytes = sdh->gbl_offset - sdh->mod_offset;
    print_info_title( "Module" );

    bytes_read = 0;
    mi = (mod_info *) Wbuff;
    tmi = alloca( sizeof( mod_info ) + 255 );
    if( tmi == NULL ) {
        Wdputslc( "Error! Not enough stack.\n" );
        longjmp( Se_env, 1 );
    }
    cpos = Curr_sectoff + sdh->mod_offset;
    index = 0;
    while( bytes_read < total_bytes ) {
        Wlseek( cpos );
        Wread( Wbuff, sizeof( mod_info ) + 255 );
        bytes_read += sizeof( mod_info ) + mi->name[0];
        cpos += sizeof( mod_info ) + mi->name[0];
        get_len_prefix_string( name, mi->name );
        Putdecl( index, 3 );
        Wdputs( ") Name:   ");
        Wdputs( name );
        Wdputslc( "\n" );
        Wdputs( "     Language is " );
        Wdputs( &Lang_lst[ mi->language ] );
        Wdputslc( "\n" );
        Wdputs( "     Locals: num = " );
        Putdec( mi->di[DMND_LOCALS].u.entries );
        Wdputs( ", offset = " );
        Puthex( mi->di[DMND_LOCALS].info_off, 8 );
        Wdputslc( "H\n" );
        Wdputs( "     Types:  num = " );
        Putdec( mi->di[DMND_TYPES].u.entries );
        Wdputs( ", offset = " );
        Puthex( mi->di[DMND_TYPES].info_off, 8 );
        Wdputslc( "H\n" );
        Wdputs( "     Lines:  num = " );
        Putdec( mi->di[DMND_LINES].u.entries );
        Wdputs( ", offset = " );
        Puthex( mi->di[DMND_LINES].info_off, 8 );
        Wdputslc( "H\n" );
        memcpy( tmi, mi, sizeof( mod_info ) + mi->name[0] );
        if( Debug_options & LOCALS ) {
            dump_locals( tmi );
        }
        if( Debug_options & LINE_NUMS ) {
            dump_line_numbers( tmi );
        }
        if( Debug_options & TYPES ) {
            dump_types( tmi );
        }
        Wdputslc( "\n" );
        index++;
    }
} /* dump_module_info */