Created
February 12, 2019 11:28
-
-
Save ccentauri/b0b0cc4f722f6ad2db906d8cfef772a3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const char *security_check::IntegrityHashSecurityChecker::getBaseApkAbsolutePath() { | |
jobject jAppInfoObject = getApplicationInfo(); | |
jclass jAppInfoClass = env->FindClass("android/content/pm/ApplicationInfo"); | |
jfieldID jSourceDirField = env->GetFieldID(jAppInfoClass, "sourceDir", "Ljava/lang/String;"); | |
jstring jSourceDirString = (jstring) env->GetObjectField(jAppInfoObject, jSourceDirField); | |
const char *sourceApkPath = env->GetStringUTFChars(jSourceDirString, 0); | |
env->ReleaseStringUTFChars(jSourceDirString, sourceApkPath); | |
return sourceApkPath; | |
} | |
std::string security_check::IntegrityHashSecurityChecker::getCodeIntegrityHash() { | |
int err = 0; | |
zip *z = zip_open(getBaseApkAbsolutePath(), 0, &err); | |
const char *name = "classes.dex"; | |
struct zip_stat st; | |
zip_stat_init(&st); | |
zip_stat(z, name, 0, &st); | |
char *contents = new char[st.size]; | |
//Read the compressed file | |
zip_file *f = zip_fopen(z, name, 0); | |
zip_fread(f, contents, st.size); | |
std::ofstream stream; | |
stream.open("/sdcard/extr/classes.dex", std::ofstream::out); | |
stream.write(contents, st.size); | |
LOG(getBaseApkAbsolutePath()); | |
zip_fclose(f); | |
zip_close(z); | |
return ""; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment