Skip to content

Commit 17be07a

Browse files
committed
- Removed force requirement of s_GlobalMetadata & s_GlobalMetadataHeader.
- Added comments support in preset.prop - Updated README.md
1 parent c769e43 commit 17be07a

File tree

4 files changed

+60
-21
lines changed

4 files changed

+60
-21
lines changed

README.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
[![Android CI status](https://github.com/MhmRdd/Il2Dump/actions/workflows/build.yml/badge.svg?branch=master)](https://github.com/MhmRdd/Il2Dump/actions/workflows/build.yml)
33
[![License: CC BY-NC-SA 4.0](https://img.shields.io/badge/License-CC%20BY--NC--SA%204.0-lightgrey.svg)](https://creativecommons.org/licenses/by-nc-sa/4.0/)
44

5-
A Zygisk Module to dump il2cpp/unity games based on `GlobalMetadata` & `GlobalMetadataHeader` & `MetadataRegistration` & `CodeRegistration` offsets.
5+
A Zygisk Module to dump il2cpp/unity games based on `GlobalMetadata` (optional) & `GlobalMetadataHeader` (optional) & `MetadataRegistration` & `CodeRegistration` offsets.
66

77
> [!WARNING]
88
> This module breaks SELinux policy of `untrusted_app` by allowing `write` on `unix_stream_socket` class to `zygote`.<br/>
@@ -20,11 +20,11 @@ A Zygisk Module to dump il2cpp/unity games based on `GlobalMetadata` & `GlobalMe
2020
**All configuration files & folders will take effect immediately.**
2121

2222
## Creating `preset.prop`
23-
All offsets should be filled, format:
23+
format:
2424
```properties
2525
library=libil2cpp.so
26-
s_GlobalMetadata=ABCD0D0
27-
s_GlobalMetadataHeader=ABCD0D0
26+
#s_GlobalMetadata=ABCD0D0
27+
#s_GlobalMetadataHeader=ABCD0D0
2828
s_Il2CppCodeRegistration=ABCD0B0
2929
s_Il2CppMetadataRegistration=ABCD0B8
3030
```
@@ -60,6 +60,8 @@ void MetadataCache::Initialize()
6060
/* ... */
6161
}
6262
```
63+
> [!TIP]
64+
> `s_GlobalMetadata` can be obtained automatically by Il2Dump (if not inputted manually), whereas `s_GlobalMetadataHeader` is set to default (as `s_GlobalMetadata`) when not specified.
6365
6466
## Acknowledgement
6567

build.gradle.kts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ val gitCommitHash = "git rev-parse --verify --short HEAD".execute()
3434
// also the soname
3535
val moduleId by extra("zygisk_il2dump")
3636
val moduleName by extra("Zygisk Il2Dump")
37-
val verName by extra("v1.0.2")
37+
val verName by extra("v1.0.3")
3838
val verCode by extra(gitCommitCount)
3939
val commitHash by extra(gitCommitHash)
4040
val abiList by extra(listOf("arm64-v8a", "armeabi-v7a"))
@@ -53,7 +53,7 @@ tasks.register("Delete", Delete::class) {
5353

5454
fun Project.configureBaseExtension() {
5555
extensions.findByType(AppExtension::class)?.run {
56-
namespace = "io.github.a13e300.zygisk.module.sample"
56+
namespace = "io.github.mhmrdd.zygisk.module.il2dump"
5757
compileSdkVersion(androidCompileSdkVersion)
5858
ndkVersion = androidCompileNdkVersion
5959
buildToolsVersion = androidBuildToolsVersion

module/src/main/cpp/il2dump.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,6 @@ class Il2Dump : public zygisk::ModuleBase {
7676
int fd = -1;
7777

7878
void preSpecialize(const char* process) {
79-
/*if (strcmp(process, "com.activision.callofduty.shooter") != 0) {
80-
api->setOption(zygisk::Option::DLCLOSE_MODULE_LIBRARY);
81-
return;
82-
}*/
8379
fd = api->connectCompanion();
8480
xwrite(fd, process);
8581
auto pstatus = xread<bool>(fd);
@@ -191,6 +187,8 @@ static void Il2Comp(int fd) {
191187
std::string library;
192188
uintptr_t GlobalMetadata = 0, GlobalMetadataHeader = 0, Il2CppCodeRegistration = 0, Il2CppMetadataRegistration = 0;
193189
while (std::getline(presetFile, prop)) {
190+
if (prop.starts_with('#'))
191+
continue;
194192
size_t eqpos = prop.find('=');
195193
if (eqpos == std::string::npos)
196194
continue;
@@ -240,7 +238,9 @@ static void Il2Comp(int fd) {
240238
}
241239
}
242240
}
243-
if (GlobalMetadata && GlobalMetadataHeader && Il2CppCodeRegistration && Il2CppMetadataRegistration) {
241+
if (!GlobalMetadataHeader)
242+
GlobalMetadataHeader = GlobalMetadata;
243+
if (Il2CppCodeRegistration && Il2CppMetadataRegistration) {
244244
status = true;
245245
xwrite(fd, status);
246246
xwrite(fd, library);
@@ -262,7 +262,7 @@ static void Il2Comp(int fd) {
262262
if (dumpPtr) {
263263
dump << *dumpPtr;
264264
} else {
265-
dump << "// [Il2Dump]: Failed to transact vector `" << i << "`!" << std::endl;
265+
dump << std::endl << "// [Il2Dump]: Failed to transact vector[" << i << "]!";
266266
}
267267
}
268268
dump.close();

module/src/main/cpp/utils.cpp

Lines changed: 46 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -564,7 +564,7 @@ std::unique_ptr<uintptr_t> xread<uintptr_t>(int fd) {
564564
return std::make_unique<uintptr_t>(data);
565565
}
566566

567-
bool monitorIl2Addr() {
567+
static bool monitorIl2Addr() {
568568
if (il2Name.empty()) {
569569
LOGE("Invalid library name to dump, abort!");
570570
return false;
@@ -607,6 +607,40 @@ bool monitorIl2Addr() {
607607
return false;
608608
}
609609

610+
static void *getGlobalMetadata() {
611+
if (s_GlobalMetadata)
612+
return (void*) getPointer(il2Addr + (uintptr_t) s_GlobalMetadata);
613+
std::ifstream maps("/proc/self/maps");
614+
std::string line;
615+
if (!maps) {
616+
LOGF("Unable to open `/proc/self/maps`, abort!");
617+
return nullptr;
618+
} else if (!maps.is_open()) {
619+
LOGE("Unable to open `/proc/self/maps`, abort!");
620+
return nullptr;
621+
}
622+
while (std::getline(maps, line)) {
623+
std::istringstream iss(line);
624+
std::string addr_range, perms, offset, dev, inode, path;
625+
uintptr_t start;
626+
if (!(iss >> addr_range >> perms >> offset >> dev >> inode)) continue;
627+
std::getline(iss >> std::ws, path);
628+
if (perms[0] == 'r' || perms[1] == 'w') {
629+
size_t dash = addr_range.find('-');
630+
if (dash == std::string::npos) continue;
631+
start = std::stoul(addr_range.substr(0, dash), nullptr, 16);
632+
if (path.find(il2Package) != std::string::npos &&
633+
path.ends_with("/il2cpp/Metadata/global-metadata.dat")
634+
) {
635+
maps.close();
636+
return (void*) start;
637+
}
638+
}
639+
}
640+
maps.close();
641+
return nullptr;
642+
}
643+
610644
void dumpIl2(int fd, zygisk::Api* api) {
611645
if (!monitorIl2Addr()) {
612646
error:
@@ -620,26 +654,29 @@ void dumpIl2(int fd, zygisk::Api* api) {
620654
}
621655
std::this_thread::sleep_for(std::chrono::seconds(2));
622656
MountGuard rodata((void*) (il2Addr + (uintptr_t) s_GlobalMetadata), PROT_READ);
623-
s_GlobalMetadata = reinterpret_cast<void *>(
624-
getPointer(il2Addr + (uintptr_t) s_GlobalMetadata));
625-
s_GlobalMetadataHeader = ReadPointer<Il2CppGlobalMetadataHeader>(
626-
getPointer(il2Addr + (uintptr_t) s_GlobalMetadataHeader));
627-
s_Il2CppMetadataRegistration = ReadPointer<Il2CppMetadataRegistration>(
628-
getPointer(il2Addr + (uintptr_t) s_Il2CppMetadataRegistration));
629-
s_Il2CppCodeRegistration = ReadPointer<Il2CppCodeRegistration>(
630-
getPointer(il2Addr + (uintptr_t) s_Il2CppCodeRegistration));
657+
s_GlobalMetadata = getGlobalMetadata();
631658
if (!s_GlobalMetadata) {
632659
LOGE("Invalid pointer dereference at `GlobalMetadata`!");
633660
goto error;
634661
}
662+
s_GlobalMetadataHeader = s_GlobalMetadataHeader ?
663+
ReadPointer<Il2CppGlobalMetadataHeader>(
664+
getPointer(il2Addr + (uintptr_t) s_GlobalMetadataHeader)
665+
) : ReadPointer<Il2CppGlobalMetadataHeader>(
666+
(uintptr_t ) s_GlobalMetadata
667+
);
635668
if (!s_GlobalMetadataHeader) {
636669
LOGE("Invalid pointer dereference at `GlobalMetadataHeader`!");
637670
goto error;
638671
}
672+
s_Il2CppMetadataRegistration = ReadPointer<Il2CppMetadataRegistration>(
673+
getPointer(il2Addr + (uintptr_t) s_Il2CppMetadataRegistration));
639674
if (!s_Il2CppMetadataRegistration) {
640675
LOGE("Invalid pointer dereference at `Il2CppMetadataRegistration`!");
641676
goto error;
642677
}
678+
s_Il2CppCodeRegistration = ReadPointer<Il2CppCodeRegistration>(
679+
getPointer(il2Addr + (uintptr_t) s_Il2CppCodeRegistration));
643680
if (!s_Il2CppCodeRegistration) {
644681
LOGE("Invalid pointer dereference at `Il2CppCodeRegistration`!");
645682
goto error;

0 commit comments

Comments
 (0)