Skip to content

Commit 5b3bb46

Browse files
committed
improve: MapInfo structure filling
This commit improves how "MapInfo" structured is filled, by using SoInfo rather than maps scanning.
1 parent b9ea635 commit 5b3bb46

File tree

2 files changed

+50
-4
lines changed

2 files changed

+50
-4
lines changed

loader/src/include/solist.hpp

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
//
44
#pragma once
55

6+
#include <sys/stat.h>
7+
8+
#include <lsplt.hpp>
9+
610
#include <string>
711
#include "elf_util.h"
812
#include "logging.h"
@@ -13,10 +17,12 @@ namespace SoList {
1317
#ifdef __LP64__
1418
inline static size_t solist_size_offset = 0x18;
1519
inline static size_t solist_next_offset = 0x28;
20+
inline static size_t solist_base_offset = 0x10;
1621
constexpr static size_t solist_realpath_offset = 0x1a8;
1722
#else
1823
inline static size_t solist_size_offset = 0x90;
1924
inline static size_t solist_next_offset = 0xa4;
25+
inline static size_t solist_base_offset = 0x86;
2026
constexpr static size_t solist_realpath_offset = 0x174;
2127
#endif
2228

@@ -32,6 +38,10 @@ namespace SoList {
3238
return *(size_t *) ((uintptr_t) this + solist_size_offset);
3339
}
3440

41+
inline ElfW(Addr) get_base() {
42+
return *(ElfW(Addr) *) ((uintptr_t) this + solist_base_offset);
43+
}
44+
3545
inline const char *get_path() {
3646
if (get_realpath_sym) return get_realpath_sym(this);
3747

@@ -214,4 +224,43 @@ namespace SoList {
214224

215225
return true;
216226
}
227+
228+
static std::vector<lsplt::MapInfo> FillLSPltMaps() {
229+
if (solist == NULL && !Initialize()) {
230+
LOGE("Failed to initialize solist");
231+
232+
return {};
233+
}
234+
235+
std::vector<lsplt::MapInfo> maps;
236+
237+
for (SoInfo *iter = solist; iter; iter = iter->get_next()) {
238+
if (iter->get_path() == NULL || iter->get_name() == NULL || iter->get_path()[0] == '[')
239+
continue;
240+
241+
struct stat st;
242+
if (stat(iter->get_path(), &st) == -1) {
243+
LOGE("Failed to stat %s", iter->get_path());
244+
245+
continue;
246+
}
247+
248+
uintptr_t start = (uintptr_t)iter->get_base();
249+
size_t sz = iter->get_size();
250+
251+
maps.emplace_back(lsplt::MapInfo {
252+
.start = start,
253+
.end = (uintptr_t)(start + sz),
254+
.perms = PROT_READ | PROT_WRITE | PROT_EXEC, /* INFO: Not important, just spoof them. */
255+
.is_private = true,
256+
.offset = 0,
257+
/* INFO: May need fix as it seems to get compiler errors even though type is correct. */
258+
.dev = (dev_t)st.st_dev,
259+
.inode = (ino_t)st.st_ino,
260+
.path = iter->get_path()
261+
});
262+
}
263+
264+
return maps;
265+
}
217266
}

loader/src/injector/hook.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -783,11 +783,8 @@ void hook_functions() {
783783

784784
ino_t android_runtime_inode = 0;
785785
dev_t android_runtime_dev = 0;
786-
/* TODO by ThePedroo: Implement injection via native bridge */
787-
// ino_t native_bridge_inode = 0;
788-
// dev_t native_bridge_dev = 0;
789786

790-
cached_map_infos = lsplt::MapInfo::Scan();
787+
cached_map_infos = SoList::FillLSPltMaps();
791788
for (auto &map : cached_map_infos) {
792789
if (map.path.ends_with("libandroid_runtime.so")) {
793790
android_runtime_inode = map.inode;

0 commit comments

Comments
 (0)