JFrame实现批量获取Android安装包安全证书MD5
今天遇到一个需求。获取全部apk的签名的MD5。以下是我使用Java SE实现的一个工具。贴出核心源码。希望给有须要的朋友有所帮助。
界面例如以下:
仅仅须要制定.apk文件所在的文件夹就可以,核心代码例如以下:
public class ReadCmdLine {
private static MD5Window window;
private static String inputPath;
public static void main(String args[]) {
window = new MD5Window();
window.setVisible(true);
initWindow();
}
private static void initWindow() {
// 文件文件夹文本框
window.getFilePathButton().addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
JFileChooser jfc = new JFileChooser();
jfc.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
jfc.showDialog(new JLabel(), "选择");
File file = jfc.getSelectedFile();
notDirectoryExcute(file);
}
});
// 開始运行button
window.getBeginButton().addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
inputPath = window.getJTextFiled();
if (inputPath != null && !"".equals(inputPath.trim())) {
notDirectoryExcute(new File(inputPath));
}
}
});
// 清空结果button
window.getClearButton().addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
window.setTextArea("");
}
});
}
/**
* 推断是否是文件夹,假设不是则运行
*
* @param file
*/
public static void notDirectoryExcute(File file) {
if (file.isDirectory()) {
inputPath = file.getAbsolutePath();
window.setJTextFiled(inputPath);
File[] fiels = file.listFiles();
for (int i = 0; i < fiels.length; i++) {
String absPath = fiels[i].getAbsolutePath();
if (absPath.contains(".apk")) {
excute(absPath);
}
}
} else {
JOptionPane.showMessageDialog(window, "请选择文件夹");
}
}
/**
* 核心逻辑
*
* @param absPath
*/
public static void excute(String absPath) {
// 1、从.apk中读取CERT.RSA文件
String appName = absPath.substring(absPath.lastIndexOf("_") + 1,
absPath.lastIndexOf("."));
try {
if (absPath != null) {
readZipFile(absPath);
}
} catch (Exception e) {
e.printStackTrace();
}
// 2、运行 keytool命令获取MD5
Process process = null;
List<String> processList = new ArrayList<String>();
try {
process = Runtime.getRuntime().exec(
"keytool -printcert -file D:/test/CERT.RSA");
BufferedReader input = new BufferedReader(new InputStreamReader(
process.getInputStream()));
String line = "";
while ((line = input.readLine()) != null) {
processList.add(line);
}
input.close();
} catch (IOException e) {
e.printStackTrace();
}
// 过滤内容
for (String line : processList) {
if (line.contains("MD5")) {
window.setTextArea(window.getTextArea()
+ String.format("%-30s", appName) + line.trim() + "\n");
}
}
}
/**
* 读取压缩文件内容
*
* @param file 压缩文件的路径
* @throws Exception
*/
public static void readZipFile(String file) throws Exception {
ZipFile zf = new ZipFile(file);
InputStream in = new BufferedInputStream(new FileInputStream(file));
ZipInputStream zin = new ZipInputStream(in);
File outFile = new File("D:\\test\\CERT.RSA");
OutputStream out = new FileOutputStream(outFile);
InputStream rsaStream = zf.getInputStream(zf
.getEntry("META-INF/CERT.RSA"));
byte[] buf1 = new byte[1024];
int len;
while ((len = rsaStream.read(buf1)) > 0) {
out.write(buf1, 0, len);
}
rsaStream.close();
out.close();
in.close();
zin.closeEntry();
}
}
JFrame实现批量获取Android安装包安全证书MD5的更多相关文章
- 技术|Android安装包优化
版权声明 1.本文版权归原作者所有,转载需注明作者信息及原文出处. 2.本文作者:赵裕(vimerzhao),永久链接:https://github.com/vimerzhao/vimerzhao.g ...
- 技术|Android安装包极限优化
版权声明 1.本文版权归原作者所有,转载需注明作者信息及原文出处. 2.本文作者:赵裕(vimerzhao),永久链接:https://github.com/vimerzhao/vimerzhao.g ...
- Android安装包相关知识汇总 (编译过程图给力)
转自: https://mp.weixin.qq.com/s?__biz=MzAwNDY1ODY2OQ==&mid=208008519&idx=1&sn=278b7793699 ...
- android 安装包签名问题探究
1.首先先科普一下,android为什么需要给安装包签名: 所有的Android应用程序在发布之前都要求开发人员用一个证书进行数字签名,anroid系统不会安装没有进行签名的由于程序. 平时我们 ...
- Android安装包apk文件在某些版本操作系统上安装解析包出错问题的解决办法
当我们将Android升级功能的中的下载新版本apk文件存放在data/data/xxx.apk位置时,在有的些版本的手机中安装可能会出现安装包解析出错的问题,对于该问题的解决方案是提升该文件的权限. ...
- Mac下获取AppStore安装包文件路径
通过远在大洋彼岸的苹果服务器下载东西,确实有够慢啊!AppStore更甚:甚至都经常提示连不上服务器,而有些软件呢,还必须从AppStore下载安装,所以没办法,谁让上了苹果的贼船呢!公司的网速更是不 ...
- Mac下获取AppStore安装包文件路径-取出安装包
问题描述:我们通过AppStore下载软件的时候想要把安装包保存下来,但是AppStore安装好之后会自动删除安装包,而且安装路径也很难找到. 解决方案: 一.打开活动监视器 二.找storedown ...
- unity 导出 android安装包配置方案
原地址:http://blog.csdn.net/u012085988/article/details/17393111 1.jdk本人安装的是win32版的(虽然系统是64位的.但听说装64位的导出 ...
- [原]获取openstack-pike安装包
linux version: CentOS 7.5.1804 #进入仓库配置目录 cd /etc/yum.repo.d/ #批量重命名所有文件 for files in `ls *`; do mv $ ...
随机推荐
- select多选
1.css <style> .divBox{ width:400px; margin:100px auto; } .divBox span{ vertical-align:top; dis ...
- 232 Implement Queue using Stacks 用栈来实现队列
使用栈来实现队列的如下操作: push(x) -- 将一个元素放入队列的尾部.pop() -- 从队列首部移除元素.peek() -- 返回队列首部的元素.empty() -- 返回队列是否为空.注意 ...
- [ NOI 2001 ] 方程的解数
\(\\\) \(Description\) 已知一个 \(N\) 元高次方程: \[ k_1x_1^{p_1}+k_2x_2^{p_2}+...+k_nx_n^{p_n}=0 \] 要求所有的 \( ...
- Js上传图片并生成缩略图
Js上传图片并显示缩略图的流程为 Js选择文件->Jquery上传图片->服务器接收图片流->存储图片->返回结果到Js端->显示缩略图 本文上传图片所用的Js库是aja ...
- Assembly之instruction之JC
JC Jump if carry setJHS Jump if higher or same Syntax JC label JHS label Operation If C = 1: PC + 2 ...
- HDU_6016_(Bestcoder round #92 1002)_(dfs)(暴力)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6016 题意:给定男羊和女羊的朋友关系,即给定一个图,问从任意一只羊开始连续数四只不相同的羊的方法数. ...
- Masonry 原理与使用说明
原理: 1)约束生成:MASConstraintMaker: 2)缺省补齐: - (void)setSecondViewAttribute:(id)secondViewAttribute { if ( ...
- ThinkPHP---插件highcharts
[一]概论 (1)介绍 基于jquery开发的国外图标插件,统计图,折线图,饼状图等常常用到. 国内也有一款类似插件echarts,由百度开发. (2)官网:www.highcharts.com ...
- HDU5834 Magic boy Bi Luo with his excited tree (树形DP)
题意:一棵树有点权和边权 从每个点出发 走过一条边要花费边权同时可以获得点权 边走几次就算几次花费 点权最多算一次 问每个点能获得的最大价值 题解:好吧 这才叫树形DP入门题 dp[i][0]表示从i ...
- wpf 自定义单选按钮 RadioButton
新建RadioButtonEx.cs public class RadioButtonEx : RadioButton { public Geometry SelectIcon { get { ret ...