Reading android MANIFEST.MF file

前端 未结 2 1205
后悔当初
后悔当初 2021-01-15 09:04

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 e

2条回答
  •  情深已故
    2021-01-15 09:18

    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 map = mf.getEntries();
    
    Attributes a = map.get("classes.dex");
    String sha1 = (String)a.getValue("SHA1-Digest");
    

提交回复
热议问题