Skip to content

Commit 7924f16

Browse files
authored
Merge pull request #21 from mcbegamerxx954/main
Reverted fixes
2 parents ece7a0e + 97e66e3 commit 7924f16

File tree

2 files changed

+17
-55
lines changed

2 files changed

+17
-55
lines changed

src/Loader.cpp

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include "Util.h"
1111
#include "material.h"
1212

13+
1314
//==========================================================================================================================================
1415

1516
typedef struct _LoaderInvocationListener LoaderInvocationListener;
@@ -42,7 +43,7 @@ struct InvocationState {
4243
std::string* retstr;
4344
};
4445

45-
46+
GumAddress minecraftpeBaseAddr;
4647
GumAddress ResourcePackManager_ResourcePackManager;
4748
GumAddress AppPlatform_readAssetFile;
4849

@@ -58,14 +59,14 @@ void __attribute__((constructor)) init() {
5859

5960
gum_init();
6061

61-
ModuleRange minecraftpeDetails = get_module_range();
62-
if (minecraftpeDetails.addr == 0 || minecraftpeDetails.len == 0) {
63-
// Failed initialization
64-
return;
65-
}
62+
minecraftpeBaseAddr = gum_module_find_base_address("libminecraftpe.so");
63+
64+
GumModuleMap* moduleMap = gum_module_map_new();
65+
const GumModuleDetails* minecraftpeDetails = gum_module_map_find(moduleMap, minecraftpeBaseAddr);
66+
6667
#if __arm__
6768
//ResourcePackManager::ResourcePackManager
68-
ResourcePackManager_ResourcePackManager = FindSignatures(&minecraftpeDetails,
69+
ResourcePackManager_ResourcePackManager = FindSignatures(minecraftpeDetails,
6970
//1.20.50-1.20.81
7071
//"F0 B5 03 AF 2D E9 00 07 90 B0 05 46 AD 48 98 46 92 46 78 44 00 68 00 68 0F 90 08 69",
7172
//1.21.0-1.21.31
@@ -81,7 +82,7 @@ void __attribute__((constructor)) init() {
8182
);
8283

8384
//AppPlatform::readAssetFile
84-
AppPlatform_readAssetFile = FindSignatures(&minecraftpeDetails,
85+
AppPlatform_readAssetFile = FindSignatures(minecraftpeDetails,
8586
//1.20.50.21preview
8687
//"F0 B5 03 AF 4D F8 04 8D 9C B0 04 46 6E 48 78 44 00 68 00 68 1B 90 00 20 CD E9 08 00",
8788
//1.20.50-1.20.73
@@ -102,15 +103,15 @@ void __attribute__((constructor)) init() {
102103
}
103104
#elif __aarch64__
104105
//ResourcePackManager::ResourcePackManager
105-
ResourcePackManager_ResourcePackManager = FindSignatures(&minecraftpeDetails,
106+
ResourcePackManager_ResourcePackManager = FindSignatures(minecraftpeDetails,
106107
//1.20.50-1.21.50
107108
"FF 03 03 D1 FD 7B 07 A9 FD C3 01 91 F9 43 00 F9 F8 5F 09 A9 F6 57 0A A9 F4 4F 0B A9 59 D0 3B D5 F6 03 03 2A 28 17 40 F9 F5 03 02 AA F3 03 00 AA A8 83 1F F8 28 10 40 F9",
108109
//1.21.60.21preview
109110
"FF 83 02 D1 FD 7B 06 A9 FD 83 01 91 F8 5F 07 A9 F6 57 08 A9 F4 4F 09 A9 58 D0 3B D5 F6 03 03 2A 08 17 40 F9 F5 03 02 AA F3 03 00 AA A8 83 1F F8 28 10 40 F9 28 01 00 B4"
110111
);
111112

112113
//AppPlatform::readAssetFile
113-
AppPlatform_readAssetFile = FindSignatures(&minecraftpeDetails,
114+
AppPlatform_readAssetFile = FindSignatures(minecraftpeDetails,
114115
//1.20.50-1.20.73
115116
"FF 03 04 D1 FD 7B 0C A9 FD 03 03 91 FC 5F 0D A9 F6 57 0E A9 F4 4F 0F A9 57 D0 3B D5 F3 03 08 AA E8 16 40 F9 A8 83 1F F8 FF 7F 02 A9",
116117
//1.20.80-1.21.50
@@ -128,6 +129,8 @@ void __attribute__((constructor)) init() {
128129
printf("AppPlatform::readAssetFile not found\n");
129130
}
130131
#endif
132+
133+
g_object_unref(moduleMap);
131134

132135
interceptor = gum_interceptor_obtain();
133136
listener = (GumInvocationListener*) g_object_new(LOADER_TYPE_INVOCATION_LISTENER, NULL);

src/Util.h

Lines changed: 4 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -4,54 +4,13 @@
44
#include <vector>
55
#include <string>
66
#include "frida-gum.h"
7-
#include <stddef.h>
8-
#include <stdint.h>
9-
#include <link.h>
10-
#include <string.h>
117

128
#define FindSignature FindSig
139
#define FindSignatures(moduleInfo, ...) FindSigs(moduleInfo, {__VA_ARGS__})
1410

15-
16-
struct ModuleRange {
17-
uintptr_t addr;
18-
size_t len;
19-
};
20-
21-
int callback(struct dl_phdr_info* dl_info, size_t _size, void* data) {
22-
// Skip if module is not minecraftpe
23-
if (strstr(dl_info->dlpi_name, "libminecraftpe") == NULL) {
24-
return 0;
25-
}
26-
27-
for (size_t i = 0; i < dl_info->dlpi_phnum; i++) {
28-
const ElfW(Phdr) phdr = dl_info->dlpi_phdr[i];
29-
// Im so sorry
30-
#define PF_X 0x1
31-
// Check if we found a loadable and executable section
32-
// should be where the code is at
33-
if (phdr.p_type == PT_LOAD && phdr.p_flags & PF_X) {
34-
// Retrieve ModuleRange
35-
struct ModuleRange* mod_range = (struct ModuleRange*) data;
36-
mod_range->addr = dl_info->dlpi_addr + phdr.p_paddr;
37-
mod_range->len = phdr.p_memsz;
38-
// Stop dl_iterate_phdr
39-
return -1;
40-
}
41-
}
42-
return 0;
43-
}
44-
45-
/// Get module range of minecraftpe
46-
struct ModuleRange get_module_range() {
47-
struct ModuleRange mod_range = {0,0};
48-
dl_iterate_phdr(callback,(void*) &mod_range);
49-
return mod_range;
50-
}
51-
52-
inline uintptr_t FindSig(const ModuleRange* moduleInfo, const std::string& signature) {
53-
uintptr_t moduleBase = moduleInfo->addr;
54-
size_t moduleSize = moduleInfo->len;
11+
inline uintptr_t FindSig(const GumModuleDetails* moduleInfo, const std::string& signature) {
12+
uintptr_t moduleBase = (uintptr_t)moduleInfo->range->base_address;
13+
size_t moduleSize = moduleInfo->range->size;
5514

5615
std::vector<uint16_t> pattern;
5716
for (int i = 0; i < signature.size(); i++) {
@@ -94,7 +53,7 @@ inline uintptr_t FindSig(const ModuleRange* moduleInfo, const std::string& signa
9453
return 0;
9554
}
9655

97-
inline uintptr_t FindSigs(const ModuleRange* moduleInfo, const std::initializer_list<std::string>& signatures) {
56+
inline uintptr_t FindSigs(const GumModuleDetails* moduleInfo, const std::initializer_list<std::string>& signatures) {
9857
uintptr_t ptr = 0;
9958
for (auto& sig : signatures) {
10059
if ((ptr = FindSig(moduleInfo, sig))) {

0 commit comments

Comments
 (0)