3
3
//
4
4
#pragma once
5
5
6
+ #include < sys/stat.h>
7
+
8
+ #include < lsplt.hpp>
9
+
6
10
#include < string>
7
11
#include " elf_util.h"
8
12
#include " logging.h"
@@ -13,10 +17,12 @@ namespace SoList {
13
17
#ifdef __LP64__
14
18
inline static size_t solist_size_offset = 0x18 ;
15
19
inline static size_t solist_next_offset = 0x28 ;
20
+ inline static size_t solist_base_offset = 0x10 ;
16
21
constexpr static size_t solist_realpath_offset = 0x1a8 ;
17
22
#else
18
23
inline static size_t solist_size_offset = 0x90 ;
19
24
inline static size_t solist_next_offset = 0xa4 ;
25
+ inline static size_t solist_base_offset = 0x86 ;
20
26
constexpr static size_t solist_realpath_offset = 0x174 ;
21
27
#endif
22
28
@@ -32,6 +38,10 @@ namespace SoList {
32
38
return *(size_t *) ((uintptr_t ) this + solist_size_offset);
33
39
}
34
40
41
+ inline ElfW (Addr) get_base() {
42
+ return *(ElfW (Addr) *) ((uintptr_t ) this + solist_base_offset);
43
+ }
44
+
35
45
inline const char *get_path () {
36
46
if (get_realpath_sym) return get_realpath_sym (this );
37
47
@@ -214,4 +224,43 @@ namespace SoList {
214
224
215
225
return true ;
216
226
}
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
+ }
217
266
}
0 commit comments