最新消息:20210816 当前crifan.com域名已被污染,为防止失联,请关注(页面右下角的)公众号

【无法解决】用Procyon导出某个jar包中指定的包名的代码

导出 crifan 3227浏览 0评论
折腾:
【已解决】用Procyon命令行去从jar包导出java源代码
期间,再继续研究看看,如何直接导出指定的类:
即,希望从此处的:
com.huili.readingclub8825612-dex2jar.jar
能导出,其中指定的类:
com.huili.readingclub
-》而无需导出其他无用的,Android自带的库的代码了。
-》以便于提高导出速度。
继续参考:
mstrobel / Procyon / wiki / Java Decompiler — Bitbucket
看看help
➜  v3.4.8 java -jar  /Users/crifan/dev/dev_tool/android/reverse_engineering/Procyon/procyon-decompiler-0.5.34.jar -?
Usage: <main class> [options] <type names or class/jar files>
  Options:
    -b, --bytecode-ast
       Output Bytecode AST instead of Java.
       Default: false
    -ci, --collapse-imports
       Collapse multiple imports from the same package into a single wildcard
       import.
       Default: false
    -cp, --constant-pool
       Includes the constant pool when displaying raw bytecode (unnecessary with
       -v).
       Default: false
    -dl, --debug-line-numbers
       For debugging, show Java line numbers as inline comments (implies -ln;
       requires -o).
       Default: false
        --disable-foreach
       Disable 'for each' loop transforms.
       Default: false
    -eml, --eager-method-loading
       Enable eager loading of method bodies (may speed up decompilation of
       larger archives).
       Default: false
    -ent, --exclude-nested
       Exclude nested types when decompiling their enclosing types.
       Default: false
    -ei, --explicit-imports
       [DEPRECATED] Explicit imports are now enabled by default.  This option
       will be removed in a future release.
       Default: false
    -eta, --explicit-type-arguments
       Always print type arguments to generic methods.
       Default: false
    -fsb, --flatten-switch-blocks
       Drop the braces statements around switch sections when possible.
       Default: false
    -fq, --force-qualified-references
       Force fully qualified type and member references in Java output.
       Default: false
    -?, --help
       Display this usage information and exit.
       Default: false
    -jar, --jar-file
       [DEPRECATED] Decompile all classes in the specified jar file (disables
       -ent and -s).
    -lc, --light
       Use a color scheme designed for consoles with light background colors.
       Default: false
    -lv, --local-variables
       Includes the local variable tables when displaying raw bytecode
       (unnecessary with -v).
       Default: false
    -ll, --log-level
       Set the level of log verbosity (0-3).  Level 0 disables logging.
       Default: 0
    -mv, --merge-variables
       Attempt to merge as many variables as possible.  This may lead to fewer
       declarations, but at the expense of inlining and useful naming.  This feature is
       experimental and may be removed or become the standard behavior in future releases.
       Default: false
    -o, --output-directory
       Write decompiled results to specified directory instead of the console.
    -r, --raw-bytecode
       Output Raw Bytecode instead of Java (to control the level of detail, see:
       -cp, -lv, -ta, -v).
       Default: false
    -ec, --retain-explicit-casts
       Do not remove redundant explicit casts.
       Default: false
    -ps, --retain-pointless-switches
       Do not lift the contents of switches having only a default label.
       Default: false
    -ss, --show-synthetic
       Show synthetic (compiler-generated) members.
       Default: false
    -sm, --simplify-member-references
       Simplify type-qualified member references in Java output [EXPERIMENTAL].
       Default: false
    -sl, --stretch-lines
       Stretch Java lines to match original line numbers (only in combination
       with -o) [EXPERIMENTAL].
       Default: false
    -ta, --type-attributes
       Includes type attributes when displaying raw bytecode (unnecessary with
       -v).
       Default: false
        --unicode
       Enable Unicode output (printable non-ASCII characters will not be
       escaped).
       Default: false
    -u, --unoptimized
       Show unoptimized code (only in combination with -b).
       Default: false
    -v, --verbose
       Includes more detailed output depending on the output language (currently
       only supported for raw bytecode).
       Default: false
        --version
       Display the decompiler version and exit.
       Default: false
    -ln, --with-line-numbers
       Include line numbers in raw bytecode mode; supports Java mode with -o
       only.
       Default: false
以及:
procyon(1) — procyon-decompiler — Debian stretch — Debian Manpages
可见:
    -jar, --jar-file
       [DEPRECATED] Decompile all classes in the specified jar file (disables
       -ent and -s).
已经废弃这种语法了。
➜  v3.4.8 ll
total 47304
-rw-------   1 crifan  staff   9.5M  3 21 10:00 com.huili.readingclub.jar
drwxr-xr-x  13 crifan  staff   416B  4  1 17:41 com.huili.readingclub8825612
-rw-------   1 crifan  staff   9.5M  3 21 10:00 com.huili.readingclub8825612-dex2jar.jar
-rw-r--r--   1 crifan  staff   4.0M  4  1 17:24 decompiled-com.huili.readingclub8825612-dex2jar.zip
➜  v3.4.8 java -jar  /Users/crifan/dev/dev_tool/android/reverse_engineering/Procyon/procyon-decompiler-0.5.34.jar com.huili.readingclub
!!! ERROR: Failed to load class com.huili.readingclub.
不行。
暂时搞不定。
看到:
https://manpages.debian.org/stretch/procyon-decompiler/procyon.1.en.html
“Decompile a single class from a jar:
$ CLASSPATH=myJar.jar procyon com.example.Foo”
试试
➜  v3.4.8 CLASSPATH=/Users/crifan/dev/dev_root/company/xxx/projects/crawl_data/小花生app/xiaohuasheng/exported_jar_sourcecode/luyten/v3.4.8/com.huili.readingclub8825612-dex2jar.jar java -jar  /Users/crifan/dev/dev_tool/android/reverse_engineering/Procyon/procyon-decompiler-0.5.34.jar com.huili.readingclub
!!! ERROR: Failed to load class com.huili.readingclub.
加上CLASSPATH:
➜  v3.4.8 CLASSPATH=/Users/crifan/dev/dev_root/company/xxx/projects/crawl_data/小花生app/xiaohuasheng/exported_jar_sourcecode/luyten/v3.4.8/com.huili.readingclub8825612-dex2jar.jar ./procyon-decompiler-0.5.34.jar com.huili.readingclub
zsh: no such file or directory: ./procyon-decompiler-0.5.34.jar
还是不行。
➜  v3.4.8 brew install procyon
Updating Homebrew...
Error: No available formula with the name "procyon"
==> Searching for a previously deleted formula (in the last month)...
Warning: homebrew/core is shallow clone. To get complete history run:
  git -C "$(brew --repo homebrew/core)" fetch --unshallow


Error: No previously deleted formula found.
==> Searching for similarly named formulae...
This similarly named formula was found:
procyon-decompiler
To install it, run:
  brew install procyon-decompiler
==> Searching taps...
==> Searching taps on GitHub...
Error: No formulae found in taps.
mac的brew中没有。
试试
➜  v3.4.8 brew install procyon-decompiler


==> Downloading 
https://bitbucket.org/mstrobel/procyon/downloads/procyon-decompiler-0.5.30.jar
==> Downloading from 
https://bbuseruploads.s3.amazonaws.com/313ed3f9-beaa-4b00-add2-b6925c0382a5/downloads/8ce7a87e-1bfb-4f5b-b09e-853a417d1a3e/procyon-deco
######################################################################## 100.0%
🍺  /usr/local/Cellar/procyon-decompiler/0.5.30: 4 files, 1.7MB, built in 16 seconds
==> `brew cleanup` has not been run in 30 days, running now...
Removing: /Users/crifan/Library/Caches/Homebrew/cairo--1.14.12.high_sierra.bottle.tar.gz... (1.6MB)
Removing: /Users/crifan/Library/Caches/Homebrew/fdk-aac--0.1.6.high_sierra.bottle.tar.gz... (866KB)
Removing: /usr/local/Cellar/ffmpeg/3.4.2... (248 files, 50.9MB)
Removing: /Users/crifan/Library/Caches/Homebrew/ffmpeg--4.0.2.tar.xz... (8.3MB)
Removing: /Users/crifan/Library/Caches/Homebrew/ffmpeg--4.0.2.high_sierra.bottle.tar.gz... (19.7MB)
Removing: /Users/crifan/Library/Caches/Homebrew/fontconfig--2.13.1.high_sierra.bottle.tar.gz... (1.2MB)
Removing: /Users/crifan/Library/Caches/Homebrew/freetype--2.9.1.high_sierra.bottle.tar.gz... (876.8KB)
Removing: /Users/crifan/Library/Caches/Homebrew/fribidi--1.0.5.high_sierra.bottle.tar.gz... (123.8KB)
Removing: /Users/crifan/Library/Caches/Homebrew/glib--2.58.1.high_sierra.bottle.tar.gz... (5.5MB)
Removing: /Users/crifan/Library/Caches/Homebrew/harfbuzz--1.9.0.high_sierra.bottle.tar.gz... (1.6MB)
Removing: /usr/local/Cellar/icu4c/60.2... (249 files, 67MB)
Removing: /Users/crifan/Library/Caches/Homebrew/icu4c--62.1.high_sierra.bottle.tar.gz... (25.5MB)
Removing: /Users/crifan/Library/Caches/Homebrew/libass--0.14.0_1.high_sierra.bottle.tar.gz... (210.4KB)
Removing: /Users/crifan/Library/Caches/Homebrew/libffi--3.2.1.high_sierra.bottle.tar.gz... (97.2KB)
Removing: /Users/crifan/Library/Caches/Homebrew/libogg--1.3.3.high_sierra.bottle.tar.gz... (203.2KB)
Removing: /Users/crifan/Library/Caches/Homebrew/libpng--1.6.35.high_sierra.bottle.tar.gz... (445.3KB)
Removing: /Users/crifan/Library/Caches/Homebrew/libvorbis--1.3.6.high_sierra.bottle.tar.gz... (564.8KB)
Removing: /Users/crifan/Library/Caches/Homebrew/nasm--2.13.03.high_sierra.bottle.tar.gz... (499.4KB)
Removing: /usr/local/Cellar/openssl/1.0.2o... (1,792 files, 12.3MB)
Removing: /Users/crifan/Library/Caches/Homebrew/opus--1.2.1.high_sierra.bottle.tar.gz... (403.8KB)
Removing: /Users/crifan/Library/Caches/Homebrew/pixman--0.34.0_1.high_sierra.bottle.tar.gz... (497.9KB)
Removing: /Users/crifan/Library/Caches/Homebrew/rsync--3.1.3_1.high_sierra.bottle.tar.gz... (332.2KB)
Removing: /Users/crifan/Library/Caches/Homebrew/texi2html--5.0.high_sierra.bottle.1.tar.gz... (942.9KB)
Removing: /Users/crifan/Library/Caches/Homebrew/x265--2.9.high_sierra.bottle.tar.gz... (4.8MB)
Removing: /Users/crifan/Library/Caches/Homebrew/icu4c-60.2.high_sierra.bottle.tar.gz... (25.3MB)
Removing: /Users/crifan/Library/Caches/Homebrew/python-3.6.4_4.high_sierra.bottle.1.tar.gz... (21.6MB)
Removing: /Users/crifan/Library/Caches/Homebrew/sqlite-3.22.0.high_sierra.bottle.tar.gz... (1.4MB)
Removing: /Users/crifan/Library/Caches/Homebrew/libidn2-2.0.4.high_sierra.bottle.tar.gz... (190.4KB)
Removing: /Users/crifan/Library/Caches/Homebrew/tree-1.7.0.high_sierra.bottle.1.tar.gz... (48.3KB)
Error: Calling needs :cxx11 is disabled! There is no replacement.
Please report this to the homebrew/core tap:
  /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core/Formula/boost.rb:37


If reporting this issue please do so at (not Homebrew/brew or Homebrew/core):
  
https://github.com/Homebrew/homebrew-core/issues
-》很明显:
安装的版本是:稍微旧的:procyon-decompiler-0.5.30
也是从bitbucket去下载的
最后跳转到:bbuseruploads.s3.amazonaws.com去下载的
但是最后失败了。
先不管,去试试能否运行
➜  v3.4.8 which procyon
procyon not found
➜  v3.4.8 which procyon-decompiler
/usr/local/bin/procyon-decompiler
➜  v3.4.8 which procyon-decompiler --version
/usr/local/bin/procyon-decompiler
--version not found
➜  v3.4.8 which procyon-decompiler -version
/usr/local/bin/procyon-decompiler
-version not found
➜  v3.4.8 which procyon-decompiler -V
/usr/local/bin/procyon-decompiler
-V not found
➜  v3.4.8 which procyon-decompiler -?
/usr/local/bin/procyon-decompiler
-? not found
➜  v3.4.8 which procyon-decompiler -
➜  v3.4.8 ll /usr/local/bin/procyon-decompiler
lrwxr-xr-x  1 crifan  admin    58B  4  1 18:17 /usr/local/bin/procyon-decompiler -> ../Cellar/procyon-decompiler/0.5.30/bin/procyon-decompiler
➜  v3.4.8 procyon-decompiler -?
Usage: <main class> [options] <type names or class/jar files>
...
    -ln, --with-line-numbers
       Include line numbers in raw bytecode mode; supports Java mode with -o
       only.
       Default: false
是可以的。
那再去试试
➜  v3.4.8 CLASSPATH=/Users/crifan/dev/dev_root/company/xxx/projects/crawl_data/小花生app/xiaohuasheng/exported_jar_sourcecode/luyten/v3.4.8/com.huili.readingclub8825612-dex2jar.jar procyon-decompiler com.huili.readingclub
!!! ERROR: Failed to load class com.huili.readingclub.
问题依旧。
➜  v3.4.8 CLASSPATH=/Users/crifan/dev/dev_root/company/xxx/projects/crawl_data/小花生app/xiaohuasheng/exported_jar_sourcecode/luyten/v3.4.8/com.huili.readingclub8825612-dex2jar.jar procyon-decompiler com.huili
!!! ERROR: Failed to load class com.huili.
设置更深层的类,也不行:
➜  v3.4.8 CLASSPATH=/Users/crifan/dev/dev_root/company/xxx/projects/crawl_data/小花生app/xiaohuasheng/exported_jar_sourcecode/luyten/v3.4.8/com.huili.readingclub8825612-dex2jar.jar procyon-decompiler com.huili.readingclub.model
!!! ERROR: Failed to load class com.huili.readingclub.model.
当前路径:
➜  v3.4.8 CLASSPATH=./com.huili.readingclub.jar procyon-decompiler com.huili.readingclub.model
!!! ERROR: Failed to load class com.huili.readingclub.model.
也不行。
难道版本太低了?
https://bitbucket.org/mstrobel/procyon/downloads/
“procyon-decompiler-0.5.30.jar
1.7 MB
mstrobel
67592
2015-08-30″
0.5.30是2015年的,也是够老旧的版本了。
https://manpages.debian.org/stretch/procyon-decompiler/procyon.1.en.html
的语法是针对于“October 2016 procyon 0.5.32”
或许是版本问题。
那自己手动把
/usr/local/bin/procyon-decompiler -> ../Cellar/procyon-decompiler/0.5.30/bin/procyon-decompiler
换成最新版本?
➜  v3.4.8 ll /usr/local/Cellar/procyon-decompiler/0.5.30
total 8
-rw-r--r--  1 crifan  admin   587B  4  1 18:17 INSTALL_RECEIPT.json
drwxr-xr-x  3 crifan  admin    96B  4  1 18:17 bin
drwxr-xr-x  3 crifan  admin    96B  4  1 18:17 libexec
➜  v3.4.8 cp ./procyon
➜  v3.4.8 cp /Users/crifan/dev/dev_tool/android/reverse_engineering/Procyon/procyon-decompiler-0.5.34.jar
➜  v3.4.8 mkdir /usr/local/Cellar/procyon-decompiler/0.5.34
➜  v3.4.8 cp /Users/crifan/dev/dev_tool/android/reverse_engineering/Procyon/procyon-decompiler-0.5.34.jar /usr/local/Cellar/procyon-decompiler/0.5.34
➜  v3.4.8 cd /usr/local/Cellar/procyon-decompiler/0.5.34
➜  0.5.34 git:(master) ✗ ll
total 3512
-rw-r--r--@ 1 crifan  admin   1.7M  4  1 18:30 procyon-decompiler-0.5.34.jar
➜  0.5.34 git:(master) ✗ mkdir bin
➜  0.5.34 git:(master) ✗ mv procyon-decompiler-0.5.34.jar bin
➜  0.5.34 git:(master) ✗ ll bin
total 3512
-rw-r--r--@ 1 crifan  admin   1.7M  4  1 18:30 procyon-decompiler-0.5.34.jar
➜  0.5.34 git:(master) ✗ ll ../0.5.30/bin/procyon-decompiler
-r-xr-xr-x  1 crifan  admin   115B  4  1 18:17 ../0.5.30/bin/procyon-decompiler
➜  0.5.34 git:(master) ✗ ll
total 0
drwxr-xr-x  3 crifan  admin    96B  4  1 18:30 bin
➜  0.5.34 git:(master) ✗ cd bin
➜  bin git:(master) ✗ ll
total 3512
-rw-r--r--@ 1 crifan  admin   1.7M  4  1 18:30 procyon-decompiler-0.5.34.jar
➜  bin git:(master) ✗ chmod +x procyon-decompiler-0.5.34.jar
➜  bin git:(master) ✗ ll
total 3512
-rwxr-xr-x@ 1 crifan  admin   1.7M  4  1 18:30 procyon-decompiler-0.5.34.jar
➜  bin git:(master) ✗ mv procyon-decompiler-0.5.34.jar procyon-decompiler
➜  bin git:(master) ✗ ll ../../0.5.30/*
-rw-r--r--  1 crifan  admin   587B  4  1 18:17 ../../0.5.30/INSTALL_RECEIPT.json


../../0.5.30/bin:
total 8
-r-xr-xr-x  1 crifan  admin   115B  4  1 18:17 procyon-decompiler


../../0.5.30/libexec:
total 3456
-rw-r--r--  1 crifan  staff   1.7M  8 31  2015 procyon-decompiler-0.5.30.jar
然后看看已有文件后,去看看json:
➜  0.5.30 git:(master) ✗ cat INSTALL_RECEIPT.json
{"homebrew_version":"2.0.6","used_options":[],"unused_options":[],"built_as_bottle":false,"poured_from_bottle":false,"installed_as_dependency":false,"installed_on_request":true,"changed_files":null,"time":1554113860,"source_modified_time":1440952406,"HEAD":"649d1427f5fe41323c436608f5c21513f8f34f71","stdlib":null,"compiler":"clang","aliases":[],"runtime_dependencies":[],"source":{"path":"/usr/local/Homebrew/Library/Taps/homebrew/homebrew-core/Formula/procyon-decompiler.rb","tap":"homebrew/core","spec":"stable","versions":{"stable":"0.5.30","devel":"","head":"","version_scheme":0}}}%
再看看可执行文件:
➜  0.5.30 git:(master) ✗ ll
total 8
-rw-r--r--  1 crifan  admin   587B  4  1 18:17 INSTALL_RECEIPT.json
drwxr-xr-x  3 crifan  admin    96B  4  1 18:17 bin
drwxr-xr-x  3 crifan  admin    96B  4  1 18:17 libexec
➜  0.5.30 git:(master) ✗ cd bin
➜  bin git:(master) ✗ ll
total 8
-r-xr-xr-x  1 crifan  admin   115B  4  1 18:17 procyon-decompiler
➜  bin git:(master) ✗ cat procyon-decompiler
#!/bin/bash
exec java  -jar /usr/local/Cellar/procyon-decompiler/0.5.30/libexec/procyon-decompiler-0.5.30.jar "$@"
看来只是个脚本,可以拷贝过去,用上
➜  bin git:(master) ✗ cp procyon-decompiler ../../0.5.34/bin
➜  bin git:(master) ✗ cd ../../0.5.34
➜  0.5.34 git:(master) ✗ ll
total 0
drwxr-xr-x  3 crifan  admin    96B  4  1 18:31 bin
➜  0.5.34 git:(master) ✗ cd bin
➜  bin git:(master) ✗ ll
total 8
-rwxr-xr-x@ 1 crifan  admin   115B  4  2 10:16 procyon-decompiler
➜  bin git:(master) ✗ vi procyon-decompiler
➜  bin git:(master) ✗ cat procyon-decompiler
#!/bin/bash
exec java  -jar /usr/local/Cellar/procyon-decompiler/0.5.34/libexec/procyon-decompiler-0.5.34.jar "$@"
目前看来,基本没区别了:
➜  procyon-decompiler git:(master) ✗ ll
total 0
drwxr-xr-x  6 crifan  admin   192B  4  1 18:17 0.5.30
drwxr-xr-x  4 crifan  admin   128B  4  2 10:17 0.5.34
➜  procyon-decompiler git:(master) ✗ ll 0.5.30 *
➜  procyon-decompiler git:(master) ✗ cd 0.5.30
➜  0.5.30 git:(master) ✗ ll *
-rw-r--r--  1 crifan  admin   587B  4  1 18:17 INSTALL_RECEIPT.json


bin:
total 8
-r-xr-xr-x  1 crifan  admin   115B  4  1 18:17 procyon-decompiler


libexec:
total 3456
-rw-r--r--  1 crifan  staff   1.7M  8 31  2015 procyon-decompiler-0.5.30.jar
➜  0.5.30 git:(master) ✗ cd ../0.5.34
➜  0.5.34 git:(master) ✗ ll *
bin:
total 8
-rwxr-xr-x@ 1 crifan  admin   115B  4  2 10:16 procyon-decompiler


libexec:
total 3512
-rw-r--r--@ 1 crifan  admin   1.7M  4  2 10:17 procyon-decompiler-0.5.34.jar
然后再去修改软连接
➜  0.5.34 git:(master) ✗ ll /usr/local/bin/procyon-decompiler
lrwxr-xr-x  1 crifan  admin    58B  4  1 18:17 /usr/local/bin/procyon-decompiler -> ../Cellar/procyon-decompiler/0.5.30/bin/procyon-decompiler
➜  0.5.34 git:(master) ✗ ln -s /usr/local/Cellar/procyon-decompiler/0.5.34/bin/procyon-decompiler /usr/local/bin/procyon-decompiler
ln: /usr/local/bin/procyon-decompiler: File exists
➜  0.5.34 git:(master) ✗ rm -f /usr/local/bin/procyon-decompiler
➜  0.5.34 git:(master) ✗ ln -s /usr/local/Cellar/procyon-decompiler/0.5.34/bin/procyon-decompiler /usr/local/bin/procyon-decompiler
➜  0.5.34 git:(master) ✗ ll /usr/local/bin/procyon-decompiler
lrwxr-xr-x  1 crifan  admin    66B  4  2 10:26 /usr/local/bin/procyon-decompiler -> /usr/local/Cellar/procyon-decompiler/0.5.34/bin/procyon-decompiler
然后再去运行看看是否有效果
➜  v3.4.8 CLASSPATH=/Users/crifan/dev/dev_root/company/xxx/projects/crawl_data/小花生app/xiaohuasheng/exported_jar_sourcecode/luyten/v3.4.8/com.huili.readingclub8825612-dex2jar.jar procyon-decompiler com.huili.readingclub
!!! ERROR: Failed to load class com.huili.readingclub.
问题依旧。看来不是版本问题。
【总结】
此处看来是,不论哪个版本
  • mac中brew install出来的0.5.30的
  • 还是最新的直接下载到的jar包0.5.34
的procyon-decompiler,目前都是不支持
procyon(1) — procyon-decompiler — Debian stretch — Debian Manpages
的debian系统的工具procyon的语法
Decompile a single class from a jar:
$ CLASSPATH=myJar.jar procyon com.example.Foo
的。

转载请注明:在路上 » 【无法解决】用Procyon导出某个jar包中指定的包名的代码

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
82 queries in 0.194 seconds, using 22.13MB memory