中山小榄网站建设,长沙网络营销品牌排名,福田公司创始人,自己做的网站链接Rust-CLI实现自动反编译APK Rust提供了比较好的CLI接口,可以快速的编写命令行应用, 用于日常的工具类使用。 分享一个用Rust命令行实现自动反编译Android APK包工具#xff0c;是之前学习Rust写的一个练手小工具#xff0c;可以快速反编译APK#xff0c;同时也学习下用Rust…
Rust-CLI实现自动反编译APK Rust提供了比较好的CLI接口,可以快速的编写命令行应用, 用于日常的工具类使用。 分享一个用Rust命令行实现自动反编译Android APK包工具是之前学习Rust写的一个练手小工具可以快速反编译APK同时也学习下用Rust来写命令行工具的。
核心依赖库准备 反编译APK依赖的必要库
d2j-dex2jar
jd-cli
Apktool
应用该库使用为最新版本如果有不支持兼容的需要确认Java使用的相关版本即可这些可以下载或者从工具源码里获取。 Rust CLI 编写依赖的库
clap
console
execute
indicatif
text2art
这些库的使用方式和说明可在crates.io查到具体的使用或者参见我工程里的源码使用方式。
核心代码解析 编写CLI处理接口 let matches Command::new(Decompile APK).author(lg.jsongmail.com).version(1.0.0).about(ApkDecompiler for Android, create by Spark Coding BU).arg(Arg::new(file).action(ArgAction::Set).short(f).long(file).default_value(-).help(The path to your apk.),).after_help(Longer explanation to appear after the options when \displaying the help information from --help or -h,).get_matches(); Command使用的是clap来创建 通过Arg创建对应的参数和应用可以创建读个arg进行添加。 读取CLI的输入参数 let file_path match matches.get_one::String(file) {Some(it) it,_ return,};let apk_path PathBuf::from(file_path); 开始执行: pub fn start_decompile(self) - Result() {self.show_tools_info()?;self.create_output_dir()?;self.start_dex2jar()?;self.start_decompile_class()?;self.start_decompile_res()?;self.open_output()?;\Ok(())}
开始执行会显示工具对应的信息创建文件输出的地址开始解析对应的包 举例命令行的创建 ///use dex2jar get APKs jar in output_pathpub fn start_dex2jar(self) - Result() {let mut command Command::new(sh);command.arg(self.exe_dir.join(lib/dex2jar/d2j-dex2jar.sh)).arg(-f).arg(self.apk_path).arg(-o).arg(self.output_path.join(app.jar));execute_state(command, dex2jar);Ok(())} 工程注意点
1.使用build.rs在构建前需要把代码依赖的lib库拷到对应的target下这里使用了构建脚本, 具体参见代码工程
2.如何使用cli的执行状态来显示处理过程, 是CLI下常用的工具使用方法 到软件路径下./apkdecompiler -f ./test.apk 一个命令可以自动反编译出包。 _____ _ _____ _ _/ ____| | | | __ \ (_)| |
| (___ _ __ __ _ _ __ | | __ | | | | ___ ___ ___ _ __ ___ _ __ _ | | ___ _ __\___ \ | _ \ / _ || __|| |/ / | | | | / _ \ / __| / _ \ | _ _ \ | _ \ | || | / _ \| __|____) || |_) || (_| || | | | |__| || __/| (__ | (_) || | | | | || |_) || || || __/| |
|_____/ | .__/ \__,_||_| |_|\_\ |_____/ \___| \___| \___/ |_| |_| |_|| .__/ |_||_| \___||_|| | | ||_| |_|
begin del old file...in /Users/developer/apkdecompiler/output
✅ create ouput:/Users/developer/apkdecompiler/output
✅ dex2jar...done
✅ decompile class...done
✅ decompile Resource...done 反编译后的相关代码和资源内容会自动打开对应的文件夹。分享这个工具仅供对练手rust方便反编译Android APK包用户使用任何商业行为均与软件和本人无关。
一些源码实现细节比如rust里文件路径操作、命令行状态实现等没有具体在文中呈现可以通过源码进一步学习。
PS: 也欢迎大家评论和交流~ 更多文章也可关注微信公号良技漫谈 如需源码回复Rust。