Skip to content

Instantly share code, notes, and snippets.

@fvrmatteo
Created December 5, 2017 11:27
Show Gist options
  • Select an option

  • Save fvrmatteo/69e973a3c17acd45f33cad92aed8b45d to your computer and use it in GitHub Desktop.

Select an option

Save fvrmatteo/69e973a3c17acd45f33cad92aed8b45d to your computer and use it in GitHub Desktop.
package com.qihoo.util;
import android.app.Application;
import android.content.Context;
import android.os.Build;
import android.util.Log;
import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.RandomAccessFile;
import java.lang.reflect.Method;
public class StubApp1868252644 extends Application {
private static Context context;
public static Application newApp = null;
public static Application runApp = null;
private static String soName = "libjiagu";
public static String strEntryApplication = "com.qihoo360.crypt.entryRunApplication";
public static native void interface5(Application application);
public static native String interface6(String str);
public static native boolean interface7(Application application, Context context);
public static native boolean interface8(Application application, Context context);
public static native void mark();
public static native int n0111();
public static native long n01112(boolean z);
public static native long n0112();
public static native void n01120(long j);
public static native long n01122(long j);
public static native void n011230(long j, Object obj);
public static native float n011231(long j, Object obj);
public static native void n0112310(long j, Object obj, float f);
public static native void n01123110(long j, Object obj, int i, boolean z);
public static native void n011231110(long j, Object obj, int i, int i2, int i3);
public static native long n0112312(long j, Object obj, int i);
public static native long n011232(long j, Object obj);
public static native void n0112322323230(long j, Object obj, long j2, long j3, Object obj2, long j4, Object obj3, long j5, Object obj4);
public static native void n01123230(long j, Object obj, long j2, Object obj2);
public static native boolean n01123231(long j, Object obj, long j2, Object obj2);
public static native void n011232310(long j, Object obj, long j2, Object obj2, int i);
public static native void n0112332310(long j, Object obj, Object obj2, long j2, Object obj3, boolean z);
public static native void n01123330(long j, Object obj, Object obj2, Object obj3);
public static native boolean n0112333111(long j, Object obj, Object obj2, Object obj3, int i, int i2);
public static native int n011311131(Object obj, int i, int i2, int i3, Object obj2);
public static native void n01131130(Object obj, int i, int i2, Object obj2);
public static native boolean n0113311(Object obj, Object obj2, int i);
public static native boolean n01133111(Object obj, Object obj2, int i, boolean z);
public static native boolean n01133331(Object obj, Object obj2, Object obj3, Object obj4);
public native Object n1113113(Object obj, int i, float f);
public native Object n111313(Object obj, int i);
public native Object n111313113(Object obj, int i, Object obj2, int i2, int i3);
public native Object n111323(Object obj, long j);
public native Object n11133(Object obj);
public native boolean n111331(Object obj, Object obj2);
public static Context getAppContext() {
return context;
}
public static Application getNewAppInstance(Context context) {
try {
if (newApp == null) {
ClassLoader classLoader = context.getClassLoader();
if (classLoader != null) {
Class loadClass = classLoader.loadClass(strEntryApplication);
if (loadClass != null) {
newApp = (Application) loadClass.newInstance();
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
return newApp;
}
public static void ChangeTopApplication() {
try {
interface7(newApp, runApp.getBaseContext());
} catch (Exception e) {
e.printStackTrace();
}
}
public void onCreate() {
super.onCreate();
if (Configuration.ENABLE_CRASH_REPORT) {
prepareInitCrashReport();
}
ChangeTopApplication();
if (newApp != null) {
interface5(newApp);
newApp.onCreate();
}
if (Configuration.ENABLE_CRASH_REPORT) {
initCrashReport();
}
}
private void prepareInitCrashReport() {
try {
Class.forName("com.qihoo.bugreport.CrashReport").getDeclaredMethod("prepareInit", new Class[0]).invoke(null, new Object[0]);
} catch (Throwable th) {
Log.e("CRASH_REPORT", "Failed to reflect prepareInit method of Class CrashReport.");
}
}
private void initCrashReport() {
try {
Class.forName("com.qihoo.bugreport.CrashReport").getDeclaredMethod("init", new Class[]{Context.class}).invoke(null, new Object[]{getApplicationContext()});
} catch (Throwable th) {
Log.e("CRASH_REPORT", "Failed to reflect init method of Class CrashReport.");
}
}
public static Boolean isX86Arch() {
try {
for (String contains : Build.SUPPORTED_32_BIT_ABIS) {
if (contains.contains("x86")) {
return Boolean.valueOf(true);
}
}
} catch (NoSuchFieldError e) {
if (Build.CPU_ABI.contains("x86") || Build.CPU_ABI2.contains("x86")) {
return Boolean.valueOf(true);
}
try {
RandomAccessFile randomAccessFile = new RandomAccessFile("/system/build.prop", "r");
String readLine = randomAccessFile.readLine();
while (readLine != null) {
if (readLine.contains("ro.product.cpu.abi") && readLine.contains("x86")) {
return Boolean.valueOf(true);
}
readLine = randomAccessFile.readLine();
}
} catch (FileNotFoundException e2) {
e2.printStackTrace();
} catch (IOException e3) {
e3.printStackTrace();
}
}
return Boolean.valueOf(false);
}
private void initAssetForNative() {
try {
Class.forName("com.qihoo.dexjiagu.TransitMgr").getMethod("initAssetForNative", new Class[]{Context.class}).invoke(null, new Object[]{this});
} catch (Exception e) {
}
}
protected void attachBaseContext(Context context) {
super.attachBaseContext(context);
context = context;
if (newApp == null) {
String absolutePath = context.getFilesDir().getAbsolutePath();
Boolean isX86Arch = isX86Arch();
Boolean valueOf = Boolean.valueOf(false);
if (Build.CPU_ABI.contains("64") || Build.CPU_ABI2.contains("64")) {
valueOf = Boolean.valueOf(true);
}
if (isX86Arch.booleanValue()) {
copy(context, soName + "_x86.so", absolutePath, soName + ".so");
} else {
copy(context, soName + ".so", absolutePath, soName + ".so");
}
if (valueOf.booleanValue()) {
if (isX86Arch.booleanValue()) {
copy(context, soName + "_x64.so", absolutePath, soName + "_64.so");
} else {
copy(context, soName + "_a64.so", absolutePath, soName + "_64.so");
}
System.load(absolutePath + "/" + soName + "_64.so");
} else {
System.load(absolutePath + "/" + soName + ".so");
}
}
if (runApp == null) {
runApp = this;
}
newApp = getNewAppInstance(context);
if (newApp != null) {
try {
Method declaredMethod = Application.class.getDeclaredMethod("attach", new Class[]{Context.class});
if (declaredMethod != null) {
declaredMethod.setAccessible(true);
declaredMethod.invoke(newApp, new Object[]{context});
}
} catch (Exception e) {
e.printStackTrace();
}
}
interface8(newApp, context);
initAssetForNative();
}
public static boolean copy(Context context, String str, String str2, String str3) {
String str4 = str2 + "/" + str3;
File file = new File(str2);
if (!file.exists()) {
file.mkdir();
}
try {
file = new File(str4);
if (file.exists()) {
boolean z;
InputStream open = context.getResources().getAssets().open(str);
InputStream fileInputStream = new FileInputStream(file);
BufferedInputStream bufferedInputStream = new BufferedInputStream(open);
BufferedInputStream bufferedInputStream2 = new BufferedInputStream(fileInputStream);
if (isSameFile(bufferedInputStream, bufferedInputStream2)) {
z = true;
} else {
z = false;
}
open.close();
fileInputStream.close();
bufferedInputStream.close();
bufferedInputStream2.close();
if (z) {
return z;
}
}
InputStream open2 = context.getResources().getAssets().open(str);
FileOutputStream fileOutputStream = new FileOutputStream(str4);
byte[] bArr = new byte[7168];
while (true) {
int read = open2.read(bArr);
if (read <= 0) {
break;
}
fileOutputStream.write(bArr, 0, read);
}
fileOutputStream.close();
open2.close();
try {
Runtime.getRuntime().exec("chmod 755 " + str4);
} catch (Exception e) {
}
return true;
} catch (Exception e2) {
e2.printStackTrace();
return false;
}
}
public static boolean isSameFile(BufferedInputStream bufferedInputStream, BufferedInputStream bufferedInputStream2) {
try {
int available = bufferedInputStream.available();
int available2 = bufferedInputStream2.available();
if (available != available2) {
return false;
}
byte[] bArr = new byte[available];
byte[] bArr2 = new byte[available2];
bufferedInputStream.read(bArr);
bufferedInputStream2.read(bArr2);
for (available2 = 0; available2 < available; available2++) {
if (bArr[available2] != bArr2[available2]) {
return false;
}
}
return true;
} catch (FileNotFoundException e) {
e.printStackTrace();
return false;
} catch (IOException e2) {
e2.printStackTrace();
return false;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment