Android Question clasess.dex integrity check

KZero

Active Member
Licensed User
Longtime User
Hi,

is it possible to read Clasess.dex file check-sum ?

i found this code for java

B4X:
private void crcTest() throws IOException {
boolean modified = false;
// required dex crc value stored as a text string.
// it could be any invisible layout element
long dexCrc = Long.parseLong(Main.MyContext.getString(R.string.dex_crc));
ZipFile zf = new ZipFile(Main.MyContext.getPackageCodePath());
ZipEntry ze = zf.getEntry("classes.dex");
if ( ze.getCrc() != dexCrc ) {
  // dex has been modified
  modified = true;
}
else {
  // dex not tampered with
  modified = false;
}
}


thanks in advance
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
You can use this code to get the APK CRC:
B4X:
Sub GetApkCRC As Long
   Dim jo As JavaObject = Activity
   Dim FileName As String = jo.RunMethodJO("getContext", Null).RunMethod("getPackageCodePath", Null)
   Dim zf As JavaObject
   zf.InitializeNewInstance("java.util.zip.ZipFile", Array As Object(FileName))
   Dim ze As JavaObject = zf.RunMethod("getEntry", Array As Object("classes.dex"))
   Return ze.RunMethod("getCrc", Null)
End Sub
 
Upvote 0
Top