Example #1
0
int main(int argc, char **argv)
{
    ClassFile cf;

    memset(&cf, 0, sizeof (cf));

    if(argc != 2) {
        printf("Use: %s <class_file.class>\n", argv[0]);
        return -1;
    }

    RC_ReadClassFile(argv[1], &cf);
    RC_DumpClassFile(&cf);

    return 0;
}
Example #2
0
int main(int argc, char **argv) {

    int opt;
    int option_index;
    ClassFile cf;
    utf8 str;

    static char *s_ops = "hd::lp::Df";

    static struct option l_ops[] = {
        {"help",             no_argument,       0, 'h'},
        {"dump-method-code", optional_argument, 0, 'd'},
        {"list-methods",     no_argument,       0, 'l'},
        {"dump-cpool",       optional_argument, 0, 'p'},
        {"dump-all",         no_argument,       0, 'D'},
        {0,                  0,                 0, 0  }        
    };
    
    if(argc < 2) {
        usage(argv[0]);
        return -1;
    }

    optind = 1;
    while((opt = getopt_long(argc, argv, s_ops, l_ops, &option_index)) != -1) {
        if(opt == 'h') {
            help(argv[0]);
            return 0;
        }

        if(opt == '?') {
            help(argv[0]);
            return -1;            
        }
    }

    if(RC_ReadClassFile(argv[argc-1], &cf) != CF_OK) {
        printf("Impossible to open file %s. "
               "Are you sure this is a java class?\n" , argv[argc-1]);
        
        return -1;
    }

    optind = 1;
    while((opt = getopt_long(argc, argv, s_ops, l_ops, &option_index)) != -1) {
        switch(opt) {
            case 'd':
                if(optarg != 0) {
                    str.length = strlen(optarg);
                    str.str = optarg;
                    dump_method_code(&cf, &str);
                } else {
                    dump_method_code(&cf, NULL);
                }

            break;

            case 'l':
                list_methods(&cf);
            break;

            case 'p':
            break;

            case 'D':
                RC_DumpClassFile(&cf);
            break;

            case '?':
            break;
            
        }
        
        
    }
    
    return 0;
}