Reading android MANIFEST.MF file

送分小仙女□ 提交于 2019-12-02 03:06:59

问题


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

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

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.


回答1:


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.

Here it is:

// 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");



回答2:


Use following way to detect External Jar/SDK MANIFEST.MF Info. We could use this info for detecting Jar version etc. Use http://docs.oracle.com/javase/6/docs/api/java/util/jar/Manifest.html

public void getSDKInfo() {
Package package = Manifest.class.getPackage();
String specTitle = package.getSpecificationTitle();
String vendor = package.getSpecificationVendor();
String virsion = package.getSpecificationVersion();
}


来源:https://stackoverflow.com/questions/3392189/reading-android-manifest-mf-file

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!