MCPcopy Create free account
hub / github.com/cinit/TMoe / lookupFileLogLogsEnabled

Function lookupFileLogLogsEnabled

app/src/main/cpp/tmoe_core/TMoeJNI.cpp:38–90  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

36static void *pFileLogLogsEnabled = nullptr;
37
38static void *lookupFileLogLogsEnabled() {
39 void *p = pFileLogLogsEnabled;
40 if (p != nullptr) {
41 return p;
42 }
43 // prefer dlfcn if available
44 if (auto* handle = GetLoadedTMessageLibHandle()) {
45 p = dlsym(handle, "LOGS_ENABLED");
46 if (p != nullptr) {
47 LOGD("LOGS_ENABLED: %p", p);
48 pFileLogLogsEnabled = p;
49 return p;
50 }
51 }
52 // lookup
53 elfsym::ProcessView self;
54 int err = self.readProcess(getpid());
55 if (err != 0) {
56 LOGE("readProcess self failed, err: %d", err);
57 }
58 std::optional<elfsym::ProcessView::Module> libtmsg;
59 for (const auto &module: self.getModules()) {
60 if (module.name.find("libtmessages.") != std::string::npos) {
61 libtmsg = module;
62 break;
63 }
64 }
65 if (!libtmsg.has_value()) {
66 LOGE("libtmessages.*.so not found");
67 return nullptr;
68 }
69 std::string soanme = libtmsg->name;
70 std::string path = libtmsg->path;
71 uintptr_t baseAddress = libtmsg->baseAddress;
72 LOGD("libtmsg: %s, baseAddress: %p", soanme.c_str(), (void *) baseAddress);
73 FileMemMap fileMemMap;
74 err = fileMemMap.mapFilePath(path.c_str());
75 if (err != 0) {
76 LOGE("mapFilePath failed, err: %d", err);
77 return nullptr;
78 }
79 elfsym::ElfView elfView;
80 elfView.attachFileMemMapping(Rva(fileMemMap.getAddress(), fileMemMap.getLength()));
81 int offset = elfView.getSymbolAddress("LOGS_ENABLED");
82 if (offset == 0) {
83 LOGE("getSymbolAddress LOGS_ENABLED failed");
84 return nullptr;
85 }
86 uintptr_t addr = baseAddress + offset;
87 LOGD("LOGS_ENABLED: %p", (void *) addr);
88 pFileLogLogsEnabled = reinterpret_cast<void *>(addr);
89 return pFileLogLogsEnabled;
90}
91
92extern "C" JNIEXPORT jint JNICALL
93Java_cc_ioctl_tmoe_hook_func_TgnetLogController_getCurrentTgnetLogStatus(JNIEnv *env, jclass clazz) {

Calls 9

RvaClass · 0.85
readProcessMethod · 0.80
getModulesMethod · 0.80
mapFilePathMethod · 0.80
attachFileMemMappingMethod · 0.80
getAddressMethod · 0.80
getLengthMethod · 0.80
getSymbolAddressMethod · 0.80

Tested by

no test coverage detected