Skip to content

Commit

Permalink
chore: add a fallback strategy to get version code when LSPatch set i…
Browse files Browse the repository at this point in the history
…t to 1
  • Loading branch information
cinit committed Aug 7, 2023
1 parent e2a5547 commit cc26685
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
26 changes: 26 additions & 0 deletions app/src/main/java/io/github/qauxv/startup/StartupRoutine.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,37 @@ public static void execPostStartupInit(Context ctx, Object step, String lpwReser
HostInfo.init((Application) ctx);
Initiator.init(ctx.getClassLoader());
Natives.load(ctx);
overrideLSPatchModifiedVersionCodeIfNecessary(ctx);
NativeCoreBridge.initNativeCore(ctx.getPackageName(), Build.VERSION.SDK_INT,
HostInfo.getHostInfo().getVersionName(), HostInfo.getHostInfo().getVersionCode());
MainHook.getInstance().performHook(ctx, step);
}

private static void overrideLSPatchModifiedVersionCodeIfNecessary(Context ctx) {
if (HostInfo.isInHostProcess() && HostInfo.getHostInfo().getVersionCode32() == 1) {
if ("com.tencent.mobileqq".equals(ctx.getPackageName())) {
ClassLoader cl = ctx.getClassLoader();
// try to get version code from Lcooperation/qzone/QUA;->QUA:Ljava/lang/String;
try {
Class<?> kQUA = cl.loadClass("cooperation.qzone.QUA");
Field QUA = kQUA.getDeclaredField("QUA");
QUA.setAccessible(true);
String qua = (String) QUA.get(null);
if (qua != null && qua.startsWith("V1_AND_")) {
// "V1_AND_SQ_8.9.0_3060_YYB_D"
String[] split = qua.split("_");
if (split.length >= 5) {
int versionCode = Integer.parseInt(split[4]);
HostInfo.overrideVersionCodeForLSPatchModified1(versionCode);
}
}
} catch (ReflectiveOperationException | NumberFormatException e) {
io.github.qauxv.util.Log.e("Failed to get version code from Lcooperation/qzone/QUA;->QUA:Ljava/lang/String;", e);
}
}
}
}

private static void ensureHiddenApiAccess() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P && !isHiddenApiAccessible()) {
android.util.Log.w("QAuxv", "Hidden API access not accessible, SDK_INT is " + Build.VERSION.SDK_INT);
Expand Down
13 changes: 13 additions & 0 deletions app/src/main/java/io/github/qauxv/util/HostInfo.kt
Original file line number Diff line number Diff line change
Expand Up @@ -145,3 +145,16 @@ enum class HostSpecies {
QAuxiliary,
Unknown
}

fun overrideVersionCodeForLSPatchModified1(newVersionCode: Int) {
io.github.qauxv.util.Log.w("Overriding version code from ${hostInfo.versionCode32} to $newVersionCode")
hostInfo = HostInfoImpl(
hostInfo.application,
hostInfo.packageName,
hostInfo.hostName,
newVersionCode.toLong(),
newVersionCode,
hostInfo.versionName,
hostInfo.hostSpecies
)
}

0 comments on commit cc26685

Please sign in to comment.