Search code examples
javaidedecompiling

Find method or symbol call in hundreds of compiled jars


I spent the last hour looking for an easy way to find symbol and method calls within hundreds of compiled jars. I tried to load them them all in the ide to use the search symbol feature but the ide does only index the ones set on public and not the calls. Can you think of an easy way which does not include decompiling one jar after another. I kinda have to do this quite often with different sets of jars each time.

I would appreciate any ideas that could bring me a step further. Thanks for your time.


Solution

  • Run javap against every class in every jar.

    I would use the unix "find" command to apply a complex unzip-pipeline-into-javap against every jar file in a given directory:

    find -iname \*.jar -execdir bash -c "
    
      unzip -qql {}       | # -l to list zip contents, and -qq to keep quiet.
        sed 's/  */ /g'   | # convert groups of spaces to a single space
        cut -d ' ' -f 5   | # pull out 5th field of each unzip output line
        grep '.class$'    | # each line must end in ".class"
        sed 's/.class$//' | # convert to java class name: remove trailing ".class"
        tr '/' '.'        | # convert to java class name: convert '/' to '.'
        sort              | # sort classnames
      #
      # And, finally, call 'javap' against each class, with most options enabled:
      #
      xargs /opt/java/jdk1.8.0_25/bin/javap -s -p -v -l -c  -cp {}
    
    " \; | gzip > every-jar-decompiled.txt.gz
    

    The output was so significant in my test (over 1GB for 100MB of jars) that I gzipped it. Use "zcat" or "zgrep" to examine the results.

    If you're on windows you can probably use cygwin to run this command.