Closed wrlu closed 1 year ago
PackageLoadedParam.getAppInfo()
should have provided enough information?
OK you are right, but ApplicationInfo
does not directly provide the information about is memory dex or not. So please add isMemoryDex()
API if possible?
And another thing is the API named isFirstPackage()
may be confused, because many applications use split apk or user will hook the system_server itself.
This is an example to check if a dex is a base apk or a hotfix binary in my hook framework project.
#define FS_DATA_PATH "/data"
#define FS_STORAGE_PATH "/storage"
#define FS_DATA_APP_PATH "/data/app"
bool isHotfixDexPath(const char *sourceName) {
if (sourceName == nullptr) {
return false;
}
// Dex file in read-only partition should not be a hot patch.
if (!( strstart(sourceName, FS_DATA_PATH)
|| strstart(sourceName, FS_STORAGE_PATH) )) {
return false;
}
// Dex file in system default apk path should not be a hot patch.
// TODO: On some Android system apk can be installed to sdcard.
if (strstart(sourceName, FS_DATA_APP_PATH)) {
return false;
}
// Otherwise should be a hot patch (like /data/user/0, /data/data, /sdcard or /storage/emulated/0).
return true;
}
What is isMemoryDex
used for? Could you provide a valid scenario?
When hooking system_server
, you won't get isFirstPackage
because you will get a SystemServerLoadedParam
, which does not have isFirstPackage
.
I think isMemoryDex()
or isHotfixDexPath()
can be used for app protection hooking.
Aha, I got you. But unfortunately, those hotfixes won't trigger OnPackageLoaded
.
抱歉没有仔细阅读过Xposed实现的原理,我目前做了一个项目就是通过插桩dalvik_system_DexFile.cc
这里去抓取一些动态加载的dex。所以说OnPackageLoaded这个是只针对于主包才会调用的嘛?对于动态加载的dex或者内存dex没有回调?
Basically, OnPackageLoaded
is for a package. Hotfixes are not even a package. Technically, OnPackageLoaded
only triggers whenever a LoadedApk creates its ClassLoader
.
Ok I got it.
Sometimes developers want to know the apk/dex path when loading, like
/data/app/xxxxxx/base.apk
or/data/user/0/xxxxx/files/dymload.dex
, or it is a memory dex. So could you please add some new methods to PackageLoadedParam class in LSPosed new API, such asgetDexPath()
andisMemoryDex
?P.S. We can get this information from
DexFile_openDexFileNative
andDexFile_openInMemoryDexFilesNative
function indalvik_system_DexFile.cc
.