读取android MANIFEST.MF文件 [英] Reading android MANIFEST.MF file

查看:466
本文介绍了读取android MANIFEST.MF文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以使用Android API读取当前正在运行的应用程序的META-INF \ MANIFEST.MF文件?

Is there a way to read META-INF\MANIFEST.MF file of the currently running application using Android API?

我想读取classes.dex文件的SHA1并将其用作我的资产之一的加密密钥.

I want to read SHA1 for classes.dex file and use it as an encrpytion key to one of my assets.

我无法对.apk文件使用签名,因为每次创建新的APK时,我都需要重新加密资产并将其放入需要重新签名.apk的apk文件中,这变成了鸡与蛋的问题.

I cannot use the signature for .apk file because everytime I create a new apk I need to re-encrpyte my asset and put in to apk file which requires re-signing the .apk and it becomes a chicken and egg problem.

推荐答案

我找到了一种方法.我将.apk文件选择为JarFile,然后可以访问.apk中的单个文件.我相信这仅适用于运行此代码的.apk文件.

I have found a way to do it. I opne the .apk file as a JarFile and then I can access individual files inside .apk. I believe this will only work for the .apk file that is running this code.

这里是:

// Get Package Name
String packageName = ctx.getPackageName();

// Get classes.dex file signature
ApplicationInfo ai = ctx.getApplicationInfo();
String source = ai.sourceDir;

JarFile jar = new JarFile(source);
Manifest mf = jar.getManifest();

Map<String, Attributes> map = mf.getEntries();

Attributes a = map.get("classes.dex");
String sha1 = (String)a.getValue("SHA1-Digest");

这篇关于读取android MANIFEST.MF文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆