KittyMemoryEx 1.0.0
Dedicated library for runtime code patching, memory scanning, tracing, injection and some more useful memory utilities. works for both Android and Linux
Loading...
Searching...
No Matches
KittyScanner.hpp
1#pragma once
2
3#include <link.h>
4
5#include <cstddef>
6#include <cstdint>
7#include <mutex>
8#include <unordered_map>
9#include <functional>
10#include <utility>
11#include <vector>
12#include <string>
13#include <algorithm>
14
15#include "KittyUtils.hpp"
16#include "KittyMemoryEx.hpp"
17#include "KittyMemOp.hpp"
18
19#define KT_SCANNER_CHUNK_SIZE ((size_t)(1024 * 1024))
20
24class KittyScannerMgr
25{
26private:
27 IKittyMemOp *_pMem;
28
29public:
30 KittyScannerMgr() : _pMem(nullptr)
31 {
32 }
33
39 KittyScannerMgr(IKittyMemOp *pMem) : _pMem(pMem)
40 {
41 }
42
53 std::vector<uintptr_t> findBytesAll(uintptr_t start,
54 uintptr_t end,
55 const char *bytes,
56 const std::string &mask) const;
57
68 uintptr_t findBytesFirst(uintptr_t start, uintptr_t end, const char *bytes, const std::string &mask) const;
69
80 std::vector<uintptr_t> findHexAll(uintptr_t start, uintptr_t end, std::string hex, const std::string &mask) const;
81
92 uintptr_t findHexFirst(uintptr_t start, uintptr_t end, std::string hex, const std::string &mask) const;
93
103 std::vector<uintptr_t> findIdaPatternAll(uintptr_t start, uintptr_t end, const std::string &pattern) const;
104
114 uintptr_t findIdaPatternFirst(uintptr_t start, uintptr_t end, const std::string &pattern) const;
115
126 std::vector<uintptr_t> findDataAll(uintptr_t start, uintptr_t end, const void *data, size_t size) const;
127
138 uintptr_t findDataFirst(uintptr_t start, uintptr_t end, const void *data, size_t size) const;
139};
140
141#ifdef __ANDROID__
142
143#define KT_SOINFO_BUFFER_SZ 0x250
144
149{
150 uintptr_t ptr = 0;
151 uintptr_t base = 0;
152 size_t size = 0;
153 uintptr_t phdr = 0;
154 size_t phnum = 0;
155 uintptr_t dyn = 0;
156 uintptr_t strtab = 0;
157 uintptr_t symtab = 0;
158 size_t strsz = 0;
159 uintptr_t bias = 0;
160 uintptr_t next = 0;
161 uint16_t e_machine = 0;
162 std::string path;
163 std::string realpath;
164};
165
169enum class EScanElfType : uint32_t
170{
171 Any,
172 Native,
173 Emulated,
174};
175
179enum class EScanElfFilter : uint32_t
180{
181 Any,
182 System,
183 App,
184};
185
186#endif
187
192class ElfScanner
193{
194 friend class ElfScannerMgr;
195 friend class LinkerScannerMgr;
196 friend class NativeBeidgeScannerMgr;
197
198protected:
199 IKittyMemOp *_pMem;
200 uintptr_t _elfBase;
201 KT_ElfW(Ehdr) _ehdr;
202 uintptr_t _phdr;
203 std::vector<KT_ElfW(Phdr)> _phdrs;
204 int _loads;
205 uintptr_t _loadBias, _loadSize;
206 uintptr_t _dynamic;
207 std::vector<KT_ElfW(Dyn)> _dynamics;
208 uintptr_t _stringTable, _symbolTable, _elfHashTable, _gnuHashTable;
209 size_t _strsz, _syment;
210 bool _fixedBySoInfo;
211 KittyMemoryEx::ProcMap _baseSegment;
212 std::vector<KittyMemoryEx::ProcMap> _segments;
213 std::vector<KittyMemoryEx::ProcMap> _bssSegments;
214 std::string _filepath;
215 std::string _realpath;
216 bool _dsymbols_init;
217 std::unordered_map<std::string, uintptr_t> _dsymbolsMap;
218
219public:
220 ElfScanner()
221 : _pMem(nullptr), _elfBase(0), _phdr(0), _loads(0), _loadBias(0), _loadSize(0), _dynamic(0), _stringTable(0),
222 _symbolTable(0), _elfHashTable(0), _gnuHashTable(0), _strsz(0), _syment(0), _fixedBySoInfo(false),
223 _dsymbols_init(false)
224 {
225 }
226
235 ElfScanner(IKittyMemOp *pMem, uintptr_t elfBase, const std::vector<KittyMemoryEx::ProcMap> &maps);
236
245 ElfScanner(IKittyMemOp *pMem, uintptr_t elfBase)
246 : ElfScanner(pMem,
247 elfBase,
248 (pMem ? KittyMemoryEx::getAllMaps(pMem->processID()) : std::vector<KittyMemoryEx::ProcMap>()))
249 {
250 }
251
252#ifdef __ANDROID__
261 ElfScanner(IKittyMemOp *pMem, const kitty_soinfo_t &soinfo, const std::vector<KittyMemoryEx::ProcMap> &maps);
262
272 : ElfScanner(pMem,
273 soinfo,
274 (pMem ? KittyMemoryEx::getAllMaps(pMem->processID()) : std::vector<KittyMemoryEx::ProcMap>()))
275 {
276 }
277#endif
278
282 inline bool isValid() const
283 {
284 return _elfBase && _loadSize && _phdr && _loadBias;
285 }
286
292 inline bool isFixedBySoInfo() const
293 {
294 return _fixedBySoInfo;
295 }
296
300 inline uintptr_t base() const
301 {
302 return _elfBase;
303 }
304
308 inline uintptr_t end() const
309 {
310 return _elfBase + _loadSize;
311 }
312
316 inline KT_ElfW(Ehdr) header() const
317 {
318 return _ehdr;
319 }
320
324 inline uintptr_t phdr() const
325 {
326 return _phdr;
327 }
328
332 inline std::vector<KT_ElfW(Phdr)> programHeaders() const
333 {
334 return _phdrs;
335 }
336
340 inline int loads() const
341 {
342 return _loads;
343 }
344
348 inline uintptr_t loadBias() const
349 {
350 return _loadBias;
351 }
352
356 inline uintptr_t loadSize() const
357 {
358 return _loadSize;
359 }
360
364 inline uintptr_t dynamic() const
365 {
366 return _dynamic;
367 }
368
372 inline std::vector<KT_ElfW(Dyn)> dynamics() const
373 {
374 return _dynamics;
375 }
376
380 inline uintptr_t stringTable() const
381 {
382 return _stringTable;
383 }
384
388 inline uintptr_t symbolTable() const
389 {
390 return _symbolTable;
391 }
392
396 inline size_t stringTableSize() const
397 {
398 return _strsz;
399 }
400
404 inline size_t symbolEntrySize() const
405 {
406 return _syment;
407 }
408
412 inline uintptr_t elfHashTable() const
413 {
414 return _elfHashTable;
415 }
416
420 inline uintptr_t gnuHashTable() const
421 {
422 return _gnuHashTable;
423 }
424
429 std::unordered_map<std::string, uintptr_t> dsymbols();
430
437 uintptr_t findSymbol(const std::string &symbolName) const;
438
445 uintptr_t findDebugSymbol(const std::string &symbolName);
446
451 {
452 return _baseSegment;
453 }
454
458 std::vector<KittyMemoryEx::ProcMap> segments() const
459 {
460 return _segments;
461 }
462
466 std::vector<KittyMemoryEx::ProcMap> bssSegments() const
467 {
468 return _bssSegments;
469 }
470
474 inline std::string filePath() const
475 {
476 return _filepath;
477 }
478
483 inline std::string realPath() const
484 {
485 return _realpath;
486 }
487
491 inline bool isZipped() const
492 {
493 return _baseSegment.offset != 0;
494 }
495
501 inline bool find_r_debug(r_debug *out) const
502 {
503 for (auto &it : _dynamics)
504 {
505 if (it.d_tag == DT_DEBUG && it.d_un.d_val)
506 {
507 if (out)
508 _pMem->Read(it.d_un.d_val, out, sizeof(r_debug));
509
510 return true;
511 }
512 }
513 return false;
514 }
515};
516
520class ElfScannerMgr
521{
522 friend class NativeBeidgeScannerMgr;
523
524protected:
525 IKittyMemOp *_pMem;
526 ElfScanner _programElf;
527 std::unordered_map<uintptr_t, ElfScanner> _cached_elfs;
528
529public:
530 ElfScannerMgr() : _pMem(nullptr)
531 {
532 }
533
538 ElfScannerMgr(IKittyMemOp *pMem) : _pMem(pMem)
539 {
540 }
541
547 inline ElfScanner createWithBase(uintptr_t elfBase) const
548 {
549 return !_pMem ? ElfScanner() : ElfScanner(_pMem, elfBase);
550 }
551
558 {
559 return !_pMem ? ElfScanner() : ElfScanner(_pMem, map.startAddress);
560 }
561#ifdef __ANDROID__
567 inline ElfScanner createWithSoInfo(const kitty_soinfo_t &soinfo) const
568 {
569 return !_pMem ? ElfScanner() : ElfScanner(_pMem, soinfo);
570 }
571#endif
572
577 bool isValidELF(uintptr_t elfBase) const;
578
584 inline bool isElfNative(const ElfScanner &elf)
585 {
586 int a = getProgramElf().header().e_machine, b = elf.header().e_machine;
587 return a != 0 && b != 0 && a == b;
588 }
589
595 inline bool isElfEmulated(const ElfScanner &elf)
596 {
597 int a = getProgramElf().header().e_machine, b = elf.header().e_machine;
598 return a != 0 && b != 0 && a != b;
599 }
600
605
606#ifdef __ANDROID__
613 std::vector<ElfScanner> getAllELFs(EScanElfType type = EScanElfType::Any,
614 EScanElfFilter filter = EScanElfFilter::Any);
615
626 ElfScanner findElf(const std::string &path,
627 EScanElfType type = EScanElfType::Any,
628 EScanElfFilter filter = EScanElfFilter::Any);
629
637 std::vector<std::pair<uintptr_t, ElfScanner>> findSymbolAll(const std::string &symbolName,
638 EScanElfType type = EScanElfType::Any,
639 EScanElfFilter filter = EScanElfFilter::Any);
640#else
645 std::vector<ElfScanner> getAllELFs();
646
655 ElfScanner findElf(const std::string &path);
656
662 std::vector<std::pair<uintptr_t, ElfScanner>> findSymbolAll(const std::string &symbolName);
663#endif
664
674 uintptr_t findRemoteSymbol(const std::string &local_sym_name, uintptr_t local_sym_addr);
675};
676
677#ifdef __ANDROID__
678
683{
684 uintptr_t solist = 0;
685 uintptr_t somain = 0;
686 uintptr_t sonext = 0;
687};
688
693{
698 static constexpr uintptr_t noff = uintptr_t(-1);
699
700 uintptr_t base = noff;
701 uintptr_t size = noff;
702 uintptr_t phdr = noff;
703 uintptr_t phnum = noff;
704 uintptr_t dyn = noff;
705 uintptr_t strtab = noff;
706 uintptr_t symtab = noff;
707 uintptr_t strsz = noff;
708 uintptr_t bias = noff;
709 uintptr_t next = noff;
710
715 inline bool isValid() const
716 {
717 return phdr != noff && phnum != noff && base != noff && size != noff && dyn != noff && strtab != noff &&
718 symtab != noff && bias != noff && next != noff;
719 }
720};
721
727class LinkerScannerMgr : public ElfScanner
728{
729private:
730 kitty_linker_syms_t _linker_syms;
731 kitty_soinfo_offsets_t _soinfo_offsets;
732 bool _init;
733
734public:
735 LinkerScannerMgr() : ElfScanner(), _init(false)
736 {
737 memset(&_linker_syms, 0, sizeof(_linker_syms));
738 memset(&_soinfo_offsets, 0, sizeof(_soinfo_offsets));
739 }
740
746 LinkerScannerMgr(IKittyMemOp *pMem, const ElfScanner &linkerElf);
747
753 LinkerScannerMgr(IKittyMemOp *pMem, uintptr_t linkerBase);
754
759 bool init();
760
764 inline bool isInitialized() const
765 {
766 return isValid() && _init;
767 }
768
773 inline ElfScanner *asELF() const
774 {
775 return (ElfScanner *)this;
776 }
777
782 {
783 return _linker_syms;
784 }
785
790 {
791 return _soinfo_offsets;
792 }
793
797 inline uintptr_t solist() const
798 {
799 if (!isValid() || !_linker_syms.solist)
800 return 0;
801
802 uintptr_t value = 0;
803 return _pMem->Read(_linker_syms.solist, &value, sizeof(uintptr_t)) == sizeof(uintptr_t) ? value : 0;
804 }
805
809 inline uintptr_t somain() const
810 {
811 if (!isValid() || !_linker_syms.somain)
812 return 0;
813
814 uintptr_t value = 0;
815 return _pMem->Read(_linker_syms.somain, &value, sizeof(uintptr_t)) == sizeof(uintptr_t) ? value : 0;
816 }
817
821 inline uintptr_t sonext() const
822 {
823 if (!isValid() || !_linker_syms.sonext)
824 return 0;
825
826 uintptr_t value = 0;
827 return _pMem->Read(_linker_syms.sonext, &value, sizeof(uintptr_t)) == sizeof(uintptr_t) ? value : 0;
828 }
829
834 {
835 if (!isValid() || !_linker_syms.somain)
836 return {};
837
838 return infoFromSoInfo_(somain(), KittyMemoryEx::getAllMaps(_pMem->processID()));
839 }
840
845 {
846 if (!isValid())
847 return {};
848
849 return infoFromSoInfo_(sonext(), KittyMemoryEx::getAllMaps(_pMem->processID()));
850 }
851
855 std::vector<kitty_soinfo_t> allSoInfo() const;
856
862 kitty_soinfo_t findSoInfo(const std::string &name) const;
863
864private:
865 kitty_soinfo_t infoFromSoInfo_(uintptr_t si, const std::vector<KittyMemoryEx::ProcMap> &maps) const;
866};
867
868enum KT_JNICallType
869{
870 KT_JNICallTypeRegular = 1,
871 KT_JNICallTypeCriticalNative = 2,
872};
873
874enum KT_NativeBridgeImplementationVersion
875{
876 // first version, not used.
877 KT_NB_DEFAULT_VERSION = 1,
878 // The version which signal semantic is introduced.
879 KT_NB_SIGNAL_VERSION = 2,
880 // The version which namespace semantic is introduced.
881 KT_NB_NAMESPACE_VERSION = 3,
882 // The version with vendor namespaces
883 KT_NB_VENDOR_NAMESPACE_VERSION = 4,
884 // The version with runtime namespaces
885 KT_NB_RUNTIME_NAMESPACE_VERSION = 5,
886 // The version with pre-zygote-fork hook to support app-zygotes.
887 KT_NB_PRE_ZYGOTE_FORK_VERSION = 6,
888 // The version with critical_native support
889 KT_NB_CRITICAL_NATIVE_SUPPORT_VERSION = 7,
890 // The version with native bridge detection fallback for function pointers
891 KT_NB_IDENTIFY_NATIVELY_BRIDGED_FUNCTION_POINTERS_VERSION = 8,
892};
893
897struct nbItf_data_t
898{
899 inline nbItf_data_t()
900 {
901 memset(this, 0, sizeof(nbItf_data_t));
902 }
903
904 int version;
905#ifdef __LP64__
906 uint32_t pad1;
907#endif
908 bool (*initialize)(const void *runtime_cbs, const char *private_dir, const char *instruction_set);
909 void *(*loadLibrary)(const char *libpath, int flag);
910 void *(*getTrampoline)(void *handle, const char *name, const char *shorty, uint32_t len);
911 bool (*isSupported)(const char *libpath);
912 const void *(*getAppEnv)(const char *instruction_set);
913 bool (*isCompatibleWith)(uint32_t bridge_version);
914 void *(*getSignalHandler)(int signal);
915 int (*unloadLibrary)(void *handle);
916 const char *(*getError)();
917 bool (*isPathSupported)(const char *library_path);
918 bool (*initAnonymousNamespace)(const char *public_ns_sonames, const char *anon_ns_library_path);
919 void *(*createNamespace)(const char *name,
920 const char *ld_library_path,
921 const char *default_library_path,
922 uint64_t type,
923 const char *permitted_when_isolated_path,
924 void *parent_ns);
925 bool (*linkNamespaces)(void *from, void *to, const char *shared_libs_sonames);
926 void *(*loadLibraryExt)(const char *libpath, int flag, void *ns);
927 void *(*getVendorNamespace)();
928 void *(*getExportedNamespace)(const char *name);
929 void (*preZygoteFork)();
930 void *(*getTrampolineWithJNICallType)(void *handle,
931 const char *name,
932 const char *shorty,
933 uint32_t len,
934 enum KT_JNICallType jni_call_type);
935 void *(*getTrampolineForFunctionPointer)(const void *method,
936 const char *shorty,
937 uint32_t len,
938 enum KT_JNICallType jni_call_type);
939 bool (*isNativeBridgeFunctionPointer)(const void *method);
940
941 inline static size_t GetStructSize(int version)
942 {
943 switch (version)
944 {
945 case KT_NB_SIGNAL_VERSION:
946 return sizeof(uintptr_t) * 8;
947 case KT_NB_NAMESPACE_VERSION:
948 return sizeof(uintptr_t) * 15;
949 case KT_NB_VENDOR_NAMESPACE_VERSION:
950 return sizeof(uintptr_t) * 16;
951 case KT_NB_RUNTIME_NAMESPACE_VERSION:
952 return sizeof(uintptr_t) * 17;
953 case KT_NB_PRE_ZYGOTE_FORK_VERSION:
954 return sizeof(uintptr_t) * 18;
955 case KT_NB_CRITICAL_NATIVE_SUPPORT_VERSION:
956 return sizeof(uintptr_t) * 19;
957 case KT_NB_IDENTIFY_NATIVELY_BRIDGED_FUNCTION_POINTERS_VERSION:
958 return sizeof(uintptr_t) * 21;
959 }
960 return 0;
961 }
962};
963
967class NativeBridgeScannerMgr
968{
969private:
970 IKittyMemOp *_pMem;
971 KittyScannerMgr *_memScanner;
972 ElfScannerMgr *_elfScanner;
973 ElfScanner _nbElf, _nbImplElf, _soheadElf;
974 uintptr_t _sohead;
975 kitty_soinfo_offsets_t _soinfo_offsets;
976 bool _init;
977 bool _isHoudini;
978
979 uintptr_t _nbItf;
980 size_t _nbItf_data_size;
981 nbItf_data_t _nbItf_data;
982
983public:
984 bool (*fnNativeBridgeInitialized)();
985
986 NativeBridgeScannerMgr()
987 : _pMem(nullptr), _memScanner(nullptr), _elfScanner(nullptr), _sohead(0), _init(false), _isHoudini(false),
988 _nbItf(0), _nbItf_data_size(0), fnNativeBridgeInitialized(nullptr)
989 {
990 memset(&_nbItf_data, 0, sizeof(_nbItf_data));
991 memset(&_soinfo_offsets, 0, sizeof(_soinfo_offsets));
992 }
993
1001
1006 bool init();
1007
1011 inline bool isValid() const
1012 {
1013 return _init;
1014 }
1015
1020 {
1021 return _soinfo_offsets;
1022 }
1023
1028 {
1029 return _nbElf;
1030 }
1031
1036 {
1037 return _nbImplElf;
1038 }
1039
1044 {
1045 return _soheadElf;
1046 }
1047
1051 inline bool isHoudini() const
1052 {
1053 return _isHoudini;
1054 }
1055
1059 inline uintptr_t sohead() const
1060 {
1061 return _sohead;
1062 }
1063
1068 {
1069 if (!_pMem || !_sohead)
1070 return {};
1071
1072 return infoFromSoInfo_(_sohead, KittyMemoryEx::getAllMaps(_pMem->processID()));
1073 }
1074
1078 std::vector<kitty_soinfo_t> allSoInfo() const;
1079
1085 kitty_soinfo_t findSoInfo(const std::string &name) const;
1086
1090 inline size_t nbItfDataSize() const
1091 {
1092 return _nbItf_data_size;
1093 }
1094
1099 {
1100 return _nbItf_data;
1101 }
1102
1103private:
1104 kitty_soinfo_t infoFromSoInfo_(uintptr_t si, const std::vector<KittyMemoryEx::ProcMap> &maps) const;
1105};
1106
1107#endif // __ANDROID__
Manager class for ELF scanners.
Definition KittyScanner.hpp:521
std::vector< std::pair< uintptr_t, ElfScanner > > findSymbolAll(const std::string &symbolName, EScanElfType type=EScanElfType::Any, EScanElfFilter filter=EScanElfFilter::Any)
Lookup dynamic symbol name in all loaded ELFs.
ElfScanner createWithBase(uintptr_t elfBase) const
Constructs ElfScanner class with the given ELF base address.
Definition KittyScanner.hpp:547
ElfScannerMgr(IKittyMemOp *pMem)
Constructor for ElfScannerMgr.
Definition KittyScanner.hpp:538
bool isElfEmulated(const ElfScanner &elf)
Checks if the memory-mapped ELF file is emulated to the Android device.
Definition KittyScanner.hpp:595
std::vector< ElfScanner > getAllELFs(EScanElfType type=EScanElfType::Any, EScanElfFilter filter=EScanElfFilter::Any)
Fetches all memory mapped ELFs.
uintptr_t findRemoteSymbol(const std::string &local_sym_name, uintptr_t local_sym_addr)
Finds the remote address of a local symbol.
bool isValidELF(uintptr_t elfBase) const
Checks if provided base address is an Elf.
ElfScanner createWithMap(const KittyMemoryEx::ProcMap &map) const
Constructs ElfScanner class with the given process memory map info.
Definition KittyScanner.hpp:557
ElfScanner findElf(const std::string &path, EScanElfType type=EScanElfType::Any, EScanElfFilter filter=EScanElfFilter::Any)
Searches for a memory mapped ELF file based on the given path, type, and filter.
ElfScanner & getProgramElf()
Returns the program ELF.
bool isElfNative(const ElfScanner &elf)
Checks if the memory-mapped ELF file is native to the Android device.
Definition KittyScanner.hpp:584
ElfScanner createWithSoInfo(const kitty_soinfo_t &soinfo) const
Constructs ElfScanner class with the given soinfo.
Definition KittyScanner.hpp:567
Represents a scanner for memory ELF files. This class is used to scan ELF files from memory and extra...
Definition KittyScanner.hpp:193
uintptr_t loadSize() const
Elf's load size.
Definition KittyScanner.hpp:356
KT_ElfW(Ehdr) header() const
Elf's header.
Definition KittyScanner.hpp:316
uintptr_t stringTable() const
Elf's dynamic string table address in memory.
Definition KittyScanner.hpp:380
std::string realPath() const
Returns the real path of the memory mapped Elf file (e.g, incase if it's inside a zip,...
Definition KittyScanner.hpp:483
ElfScanner(IKittyMemOp *pMem, const kitty_soinfo_t &soinfo, const std::vector< KittyMemoryEx::ProcMap > &maps)
Constructor for ElfScanner class. This constructor initializes the ElfScanner class with the given so...
uintptr_t end() const
Elf's end address in memory.
Definition KittyScanner.hpp:308
size_t stringTableSize() const
Elf's dynamic string table size.
Definition KittyScanner.hpp:396
std::vector< KittyMemoryEx::ProcMap > segments() const
Returns all of Elf's memory maps info.
Definition KittyScanner.hpp:458
uintptr_t base() const
Elf's Base address in memory.
Definition KittyScanner.hpp:300
uintptr_t elfHashTable() const
Elf's ELF hash table address in memory (DT_HASH), zero if not present.
Definition KittyScanner.hpp:412
std::vector< KT_ElfW(Phdr)> programHeaders() const
Vector of Elf's program headers.
Definition KittyScanner.hpp:332
bool isValid() const
Checks if the ElfScanner class is valid.
Definition KittyScanner.hpp:282
bool isZipped() const
Returns if the memory mapped Elf file was loaded from zip file.
Definition KittyScanner.hpp:491
size_t symbolEntrySize() const
Elf's symbol entry size.
Definition KittyScanner.hpp:404
uintptr_t dynamic() const
Elf's dynamic section address in memory.
Definition KittyScanner.hpp:364
KittyMemoryEx::ProcMap baseSegment() const
Elf's base memory map info.
Definition KittyScanner.hpp:450
uintptr_t phdr() const
Elf's program header address in memory.
Definition KittyScanner.hpp:324
std::string filePath() const
Returns the file path of the memory mapped Elf file.
Definition KittyScanner.hpp:474
std::vector< KittyMemoryEx::ProcMap > bssSegments() const
Returns all of Elf's BSS memory maps.
Definition KittyScanner.hpp:466
uintptr_t findSymbol(const std::string &symbolName) const
Finds a symbol from the dynamic symbol table by name.
std::unordered_map< std::string, uintptr_t > dsymbols()
Returns a map of symbols from the symbol table (SHT_SYMTAB) on disk.
std::vector< KT_ElfW(Dyn)> dynamics() const
Vector of Elf's dynamic sections.
Definition KittyScanner.hpp:372
ElfScanner(IKittyMemOp *pMem, uintptr_t elfBase)
Constructor for ElfScanner class. This constructor initializes the ElfScanner class with the given EL...
Definition KittyScanner.hpp:245
bool isFixedBySoInfo() const
Checks if the ELF file is fixed by soinfo. Some Elf headers are obfuscated or removed,...
Definition KittyScanner.hpp:292
ElfScanner(IKittyMemOp *pMem, const kitty_soinfo_t &soinfo)
Constructor for ElfScanner class. This constructor initializes the ElfScanner class with the given so...
Definition KittyScanner.hpp:271
uintptr_t findDebugSymbol(const std::string &symbolName)
Finds a symbol from the symbol table (SHT_SYMTAB) on disk by name.
uintptr_t loadBias() const
Elf's load bias address in memory.
Definition KittyScanner.hpp:348
int loads() const
Elf's number of loads.
Definition KittyScanner.hpp:340
ElfScanner(IKittyMemOp *pMem, uintptr_t elfBase, const std::vector< KittyMemoryEx::ProcMap > &maps)
Constructor for ElfScanner class. This constructor initializes the ElfScanner class with the given EL...
uintptr_t symbolTable() const
Elf's dynamic symbol table address in memory.
Definition KittyScanner.hpp:388
bool find_r_debug(r_debug *out) const
Finds the r_debug structure in the process.
Definition KittyScanner.hpp:501
uintptr_t gnuHashTable() const
Elf's GNU hash table address in memory (DT_GNU_HASH), zero if not present.
Definition KittyScanner.hpp:420
Interface class for memory operations.
Definition KittyMemOp.hpp:46
Represents a mapping of a memory region.
Definition KittyMemoryEx.hpp:15
Manager class for pattern scanning operations.
Definition KittyScanner.hpp:25
std::vector< uintptr_t > findDataAll(uintptr_t start, uintptr_t end, const void *data, size_t size) const
Searches for data within a remote memory range and returns all results.
uintptr_t findHexFirst(uintptr_t start, uintptr_t end, std::string hex, const std::string &mask) const
Searches for hex within a remote memory range and returns the first result.
std::vector< uintptr_t > findBytesAll(uintptr_t start, uintptr_t end, const char *bytes, const std::string &mask) const
Searches for bytes within a remote memory range and returns all results.
KittyScannerMgr(IKittyMemOp *pMem)
Constructor for KittyScannerMgr.
Definition KittyScanner.hpp:39
std::vector< uintptr_t > findIdaPatternAll(uintptr_t start, uintptr_t end, const std::string &pattern) const
Searches for a pattern within a remote memory range using the IDA pattern syntax and returns all resu...
uintptr_t findDataFirst(uintptr_t start, uintptr_t end, const void *data, size_t size) const
Searches for data within a remote memory range and returns the first result.
std::vector< uintptr_t > findHexAll(uintptr_t start, uintptr_t end, std::string hex, const std::string &mask) const
Searches for hex within a remote memory range and returns all results.
uintptr_t findBytesFirst(uintptr_t start, uintptr_t end, const char *bytes, const std::string &mask) const
Searches for bytes within a remote memory range and returns the first result.
uintptr_t findIdaPatternFirst(uintptr_t start, uintptr_t end, const std::string &pattern) const
Searches for a pattern within a remote memory range using the IDA pattern syntax and returns the firs...
LinkerScannerMgr(IKittyMemOp *pMem, uintptr_t linkerBase)
Constructor for LinkerScannerMgr with the linker ElfScanner object.
kitty_soinfo_offsets_t soinfo_offsets() const
Returns the soinfo offsets.
Definition KittyScanner.hpp:789
kitty_linker_syms_t linker_offsets() const
Returns the linker symbols offsets.
Definition KittyScanner.hpp:781
ElfScanner * asELF() const
Converts the LinkerScannerMgr object to an ElfScanner pointer.
Definition KittyScanner.hpp:773
uintptr_t solist() const
Returns the linker solist head address.
Definition KittyScanner.hpp:797
uintptr_t somain() const
Returns the linker somain address.
Definition KittyScanner.hpp:809
bool isInitialized() const
Returns true if initialized, false otherwise.
Definition KittyScanner.hpp:764
bool init()
Initializes the linker scanner.
kitty_soinfo_t sonextInfo() const
Returns the linker solist tail info.
Definition KittyScanner.hpp:844
LinkerScannerMgr(IKittyMemOp *pMem, const ElfScanner &linkerElf)
Constructor for LinkerScannerMgr with a linker base address.
std::vector< kitty_soinfo_t > allSoInfo() const
Returns all linker's soinfo.
kitty_soinfo_t findSoInfo(const std::string &name) const
Finds a soinfo by name.
kitty_soinfo_t somainInfo() const
Returns the linker somain info.
Definition KittyScanner.hpp:833
uintptr_t sonext() const
Returns the linker solist tail address.
Definition KittyScanner.hpp:821
bool isValid() const
Returns true if initialized, false otherwise.
Definition KittyScanner.hpp:1011
ElfScanner & nbImplElf()
Getter for the native bridge implementaion Elf (e.g, 'libhoudini.so' or 'libndk_translation....
Definition KittyScanner.hpp:1035
std::vector< kitty_soinfo_t > allSoInfo() const
Returns all emulated soinfo.
bool isHoudini() const
Check if the native bridge implementaion is Houdini.
Definition KittyScanner.hpp:1051
kitty_soinfo_t soheadInfo() const
Returns the first loaded emulated soinfo.
Definition KittyScanner.hpp:1067
bool init()
Initializes the native bridge scanner.
uintptr_t sohead() const
Returns the first loaded emulated so address.
Definition KittyScanner.hpp:1059
NativeBridgeScannerMgr(IKittyMemOp *pMem, KittyScannerMgr *memScanner, ElfScannerMgr *elfScanner)
Constructor for NativeBridgeScannerMgr.
ElfScanner & soheadElf()
Getter for the first loaded emulated so Elf.
Definition KittyScanner.hpp:1043
kitty_soinfo_offsets_t soinfo_offsets() const
Returns the soinfo offsets.
Definition KittyScanner.hpp:1019
nbItf_data_t nbItfData() const
Returns native bridge callbacks data.
Definition KittyScanner.hpp:1098
kitty_soinfo_t findSoInfo(const std::string &name) const
Finds a soinfo by name.
ElfScanner & nbElf()
Getter for 'libnativebridge.so' Elf.
Definition KittyScanner.hpp:1027
size_t nbItfDataSize() const
Returns native bridge callbacks data size.
Definition KittyScanner.hpp:1090
Represents a mapping of a memory region.
Definition KittyMemoryEx.hpp:15
Provides utility functions for process memory.
Definition KittyMemoryEx.hpp:10
std::vector< ProcMap > getAllMaps(pid_t pid)
Retrieves information about all memory maps in a remote process.
Structure to hold info of linker symbols.
Definition KittyScanner.hpp:683
Structure to hold info of linker soinfo offsets.
Definition KittyScanner.hpp:693
static constexpr uintptr_t noff
Sentinel used for "offset not found yet", so a legitimately discovered offset of 0 can't be confused ...
Definition KittyScanner.hpp:698
bool isValid() const
Returns true if all offsets required to walk/parse soinfo structures were found.
Definition KittyScanner.hpp:715
Structure to hold info of linker soinfo.
Definition KittyScanner.hpp:149
Structure to hold info of native bridge callbacks data.
Definition KittyScanner.hpp:898