accessing APK contents from the code on android device
I need to access contents of my application APK from the code of this same application running on device. I wrote this code that works perferctly well and return the datа on my 2.2 and 2.3.3 devices.
But Is it a legal way and will it work on all versions starting from 2.1 to any future or existing version?
The main reason is to detect apk original signature or repacked apk.
Here is my code of accessing META-INF/CERT.RSA:
String path = this.getApplication().getPackageCodePath();
try
{
ZipFile zfile = new ZipFile(path);
ZipEntry zentry = zfile.getEntry("META-INF/CERT.RSA");
long siz = zentry.getSize();
byte[] buf=new byte[(int) siz];
InputStream istream = zfile.getInputStream(zentry);
int ret = istream.read(buf);
istream.close();
}
catch (IOException e)
{
// TODO Auto-开发者_如何学Pythongenerated catch block
e.printStackTrace();
}
Thank you in advance
Yes, this will work.
At present it works up to latest Android 3.2, and no method from this approach is marked as deprecated.
精彩评论