Shadow security reinforcement
Overview of Shadow Security Reinforcement and Shelling Process
Shadow security reinforcement, not my original creation, thank you for sharing! ! !
name: yingan-unpack
description: >-
Ying'an (yingP / sspya / Kuaishou Keling guard) reinforced APK shelling and repair. Trigger characteristics: dexdump reports Bad checksum; a large number of dex instructions unused-73/unused-e9/unused-e5; exists abcd/libabcd.enc, assets/libabcdProtect_a64.so, libabcd.so, libArkSafe.so, libArkvm.so, API-ying'an; exists lib/arm64-v8a/libcom_kwai_kling_shellservice_dex.so; the class name contains com.yingP.runtime.、Epic.Jni.Hooker、llIIIllllIl. Contains real dex positioning, checksum repair, shell pile completion, card secret and pop-up window removal, and minimized repackaging.
Shadow Security Reinforcement Shelling and Repair
0 core conclusions
Ying'an does not hide dex, it destroys dex usability: the entire method body instruction is replaced by Dalvik undefined opcode (0x73/0xe9/0xe5/0xe3/0xe8), the structure is complete but VerifyError occurs as soon as ART is executed; the checksum of the header is changed, and dexdump/baksmali/jadx cannot be opened; the real unencrypted dex lies there In lib/arm64-v8a/libcom_kwai_kling_shellservice_dex.so, the .so is actually ZIP.
Therefore, there is no need for dynamic dump, no need for frida, and no need to restore VM bytecode. Just extract the classes.dex in the ZIP.
1 identification
unzip -l target.apk | grep -E "abcd/|Protect|ArkSafe|Arkvm|toolChecker|shellservice_dex|API-影安"
dexdump -f classes.dex 2>&1 | grep -E "checksum|Bad"
dexdump -d classes.dex 2>/dev/null | grep -c "unused-"
| feature | meaning |
|---|---|
| API-Ying'an (root directory ~145B) | Shell factory watermark sspya.com |
| abcd/libabcd.enc (tens of MB high entropy) | Encrypted payload, usually a dead file |
| assets/libabcdProtect_a64.so | Shell loaders, most of which are dead files |
| libabcd.so / libArkSafe.so / libArkvm.so / libtoolChecker.so | shell runtime |
| libcom_kwai_kling_shellservice_dex.so | The real thing is here, ZIP |
| com.yingP.runtime.* / Epic.* / *llIIIlllIl | Shell Java layer |
2 process
2.1 Get the real dex
mkdir -p work && cd work
unzip -o -q target.apk "classes.dex" "classes2.dex" "lib/arm64-v8a/libcom_kwai_kling_shellservice_dex.so"
unzip -o libcom_kwai_kling_shellservice_dex.so -d real
dexdump -f real/classes.dex 2>&1 | head -6
dexdump -d real/classes.dex 2>/dev/null | grep -c "unused-"
magic should be dex\n038, unused- count must be 0. If it is not 0, it means that there is also an encrypted version in so, and a dynamic solution is adopted.
2.2 app_process verification (don’t skip it)
Write a minimal smali loader Class.forName key class:
CLASSPATH=loader.dex:real/classes.dex app_process /system/bin Loader
Successfully output OK Application / OK Activity; failure to output the complete stack. This is the only place where you can get ART errors (Android 15's logcat is often cut off by ROM, and logcat reports Failed to wait for logd.ready).
2.3 Repair checksum (required only when using the dex of the original APK)
# dexdump 报的实际值就是该写回的值
printf "\x8a\x05\xb2\x30" | dd of=classes.dex bs=1 seek=8 conv=notrunc
Changing checksum does not affect signature (SHA1 covers 32..EOF, checksum is not included in 8..11).
2.4 Replacement and replacement of piles
There are two shell references in the manifest that must be supplemented, otherwise ClassNotFoundException:
android:name="v.m.p"
android:appComponentFactory="com.mt.mtxx.mtxx.llIIIlllIl"
v/m/p.smali (Do not inherit PUBLIC FINAL classes, ART will reject Superclass is final)
.class public Lv/m/p;
.super Lx/Bu;
.method public constructor <init>()V
.registers 2
invoke-direct {p0}, Lx/Bu;-><init>()V
return-void
.end method
com/mt/mtxx/mtxx/llIIIlllIl.smali
.class public Lcom/mt/mtxx/mtxx/llIIIlllIl;
.super Landroid/app/AppComponentFactory;
.method public constructor <init>()V
.registers 1
invoke-direct {p0}, Landroid/app/AppComponentFactory;-><init>()V
return-void
.end method
smali_assemble(smaliDir=桩目录, outDex=patch.dex)
apk_tool replace entry=classes.dex source=real/classes.dex
apk_tool delete entry=classes2.dex
apk_tool replace entry=classes2.dex source=patch.dex
apk_tool sign
2.5 Catch crashes
A global exception is raised in the constructor of v.m.p, and the stack is written to /data/user/0/<pkg>/files/crash.txt:
.method public constructor <init>()V
.registers 2
invoke-direct {p0}, Lx/Bu;-><init>()V
:try_start_0
new-instance v0, Lv/CrashHandler;
invoke-direct {v0}, Lv/CrashHandler;-><init>()V
invoke-static {v0}, Ljava/lang/Thread;->setDefaultUncaughtExceptionHandler(Ljava/lang/Thread$UncaughtExceptionHandler;)V
:try_end_0
.catch Ljava/lang/Throwable; {:try_start_0 .. :try_end_0} :catch_0
return-void
:catch_0
move-exception v0
return-void
.end method
CrashHandler.uncaughtException using FileOutputStream plus printStackTrace. More reliable than logcat, any ROM can be used.
3 Business layer (card secret and pop-up window)
Unpacking only solves the problem of being able to install it. The card password and anti-piracy prompt are business codes, and the obfuscated name is x/*:
| Target | Find a way |
|---|---|
| Card secret status enumeration | Enum class clinit calls Lx/ii;->a9([B[B)String, which after decryption is NONE/VALID/EXPIRED/INVALID |
| Login status determination | Find the static method that returns Z, internally read the status class timestamp and token |
| Pop-up window | grep -r "Landroid/app/Dialog;->show" |
| Announcement text | TextView's setText call point, or resource id textLicenseNotice |
| String decryptor | Full database search ([B[B)Ljava/lang/String; |
String decryption: Ying'anzao Lx/ii;->a9([B[B)String, the first array is the ciphertext, and the second is the 8-byte key. Don’t calculate the algorithm, write the smali loader and adjust it directly:
const/4 v0, 0x4
new-array v0, v0, [B
fill-array-data v0, :array_d
const/16 v1, 0x8
new-array v1, v1, [B
fill-array-data v1, :array_k
invoke-static {v0, v1}, Lx/ii;->a9([B[B)Ljava/lang/String;
Common patch points:
x/Cf 枚举 a1 = VALID
x/Df 状态构造,把 Cf.a2/a3 的引用全换成 Cf.a1
x/Bf a0(Bf)Z 是 isLoggedIn,改成 const/4 v0,0x1; return v0
x/gi f2(Z)V 是 notice 拉取,改成 return-void
x/gi Dialog.show() 调用直接删行(v0 与 v4 各一处)
x/gi 公告 setText 入参改 const-string v1, ""
4 pits
- After smali_assemble is successfully assembled, part of .smali will be lost (1871 changed to 1552). After each modification, re-export the entire file through baksmali, and assemble it immediately after importing.
- jadx_decompile OOMs on 2.7 MB dex. Use dexdump -d > x.txt and then grep, 46 MB of text is enough.
- When baksmali encounters encrypted dex, it reports clinit truncated. It is not that the dex is damaged, but that the opcode is illegal. The same goes for repairing the checksum.
- logcat is not available on containers or streamlined ROMs, don't fix logd, just use 2.5's CrashHandler.
- AlertDialogLayout's measure infinite loop will cause ANR under 720x1280. For testing, use wm size 1080x1920 plus wm density 420.
- assets/Epic_so/ is usually missing in the distribution package, and it will not affect it as long as the startup path does not pass through Epic.Jni.Hooker.init.
- Do not inherit the PUBLIC FINAL class as a stub, ART reports that Superclass is final.
- The apk_tool and so tools can usually only access the app private directory. If the path is unavailable, they will be copied to /data/user/0/<tool package name>/files/ first.
5 Clean up
Delete after confirming zero references (grep -r for each filename, hits must be 0):
abcd/libabcd.enc, abcd/libabcd2.enc, abcd/cfg/*, abcd/dexopt/*
assets/libabcdProtect*, assets/Epic_so/*, API-影安
integrity.properties, core-common.properties
lib/arm64-v8a/libabcd.so, libArkSafe.so, libArkvm.so, libtoolChecker.so
lib/arm64-v8a/libcom_kwai_kling_shellservice_dex.so
Must be retained (grab /proc/<pid>/maps to verify):
libcom_kwai_kling_guard_jni.so license 签名校验
libcom_kwai_kling_qnn_native_jni.so QNN 推理
libcom_kwai_kling_touch_probe_jni.so libopsvc.so libtim9.so
libopencv_java4.so libtensorflowlite*.so libLiteRt*.so libQnn*.so
Typical gain: 173 MB down to 127 MB.
6 Self-test
- dexdump -d classes.dex has unused- count of 0
- dexdump -f classes.dex None Bad checksum
- There is no abcd|Ark|Protect|ying'an|shellservice|Epic in unzip -l out.apk
- The post-installation process survives for more than 30 seconds, mCurrentFocus is the target Activity
- The business in /proc/<pid>/maps is complete
- crash.txt does not exist
please Log in or Register an account Participate in discussions, download exclusive add-ons or unlock level posts.