Skip to content

Commit ba17996

Browse files
committed
Update & fixes
1 parent 2c213cf commit ba17996

File tree

3 files changed

+17
-20
lines changed

3 files changed

+17
-20
lines changed

AndKittyInjector/src/Injector/KittyInjector.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ injected_info_t KittyInjector::nativeInject(KittyIOFile& lib, int flags, bool us
259259

260260
auto memfd_dlopen = [&]() -> bool
261261
{
262-
std::string memfd_rand = KittyUtils::random_string(KittyUtils::randInt(5, 12));
262+
std::string memfd_rand = KittyUtils::String::Random(KittyUtils::randInt(5, 12));
263263
KITTY_LOGI("nativeInject: memfd_rand(%d) = %s.", int(memfd_rand.length()), memfd_rand.c_str());
264264

265265
uintptr_t rmemfd_name = _remote_syscall.rmmap_str(memfd_rand);
@@ -276,7 +276,7 @@ injected_info_t KittyInjector::nativeInject(KittyIOFile& lib, int flags, bool us
276276
return false;
277277
}
278278

279-
std::string rmemfdPath = KittyUtils::strfmt("/proc/%d/fd/%d", _kMgr->processID(), rmemfd);
279+
std::string rmemfdPath = KittyUtils::String::Fmt("/proc/%d/fd/%d", _kMgr->processID(), rmemfd);
280280
KittyIOFile rmemfdFile(rmemfdPath, O_RDWR);
281281
if (!rmemfdFile.Open())
282282
{
@@ -356,7 +356,7 @@ injected_info_t KittyInjector::emuInject(KittyIOFile& lib, int flags, bool use_d
356356
if (use_dl_memfd)
357357
{
358358
do {
359-
std::string memfd_rand = KittyUtils::random_string(KittyUtils::randInt(5, 12));
359+
std::string memfd_rand = KittyUtils::String::Random(KittyUtils::randInt(5, 12));
360360
memfdName = "/memfd:" + memfd_rand;
361361
KITTY_LOGI("emuInject: memfd_rand(%d) = %s.", int(memfd_rand.length()), memfd_rand.c_str());
362362

@@ -374,7 +374,7 @@ injected_info_t KittyInjector::emuInject(KittyIOFile& lib, int flags, bool use_d
374374
break;
375375
}
376376

377-
std::string rmemfdPath = KittyUtils::strfmt("/proc/%d/fd/%d", _kMgr->processID(), rmemfd);
377+
std::string rmemfdPath = KittyUtils::String::Fmt("/proc/%d/fd/%d", _kMgr->processID(), rmemfd);
378378
KittyIOFile rmemfdFile(rmemfdPath, O_RDWR);
379379
if (!rmemfdFile.Open())
380380
{
@@ -621,7 +621,7 @@ bool KittyInjector::hideSegmentsFromMaps(injected_info_t &injected)
621621
{
622622
if (it.pathname.empty()) continue;
623623

624-
/* if (KittyUtils::string_contains(it.pathname, ".bss]"))
624+
/* if (KittyUtils::String::Contains(it.pathname, ".bss]"))
625625
{
626626
KITTY_LOGI("hideSegments: Spoofing .bss %p - %p", (void*)it.startAddress, (void*)it.endAddress);
627627
uintptr_t rstr = _remote_syscall.rmmap_str("anon:Mem_0x10000004");

AndKittyInjector/src/Injector/SoInfoPatch.hpp

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ class SoInfoPatch
183183
bool check1 = (it.is_rw && it.startAddress >= nb_impl_elf.bss() && it.endAddress <= (nb_impl_elf.bss()+nb_impl_elf.bssSize()));
184184

185185
// search in "[anon:Mem_x]" read-only regions
186-
bool check2 = (it.is_ro && KittyUtils::string_startswith(it.pathname, "[anon:Mem_"));
186+
bool check2 = (it.is_ro && KittyUtils::String::StartsWith(it.pathname, "[anon:Mem_"));
187187

188188
// search in "[anon:linker_alloc]" read-only regions
189189
bool check3 = (it.is_ro && it.pathname == "[anon:linker_alloc]");
@@ -227,13 +227,10 @@ class SoInfoPatch
227227
return results;
228228
}
229229

230-
for (auto& it : maps)
230+
// search in nb implementation rw regions
231+
for (auto& it : nb_impl_elf.segments())
231232
{
232-
if (!it.is_private || it.length < 0xFFFF)
233-
continue;
234-
235-
// search in nb implementation rw regions
236-
if (!(it.is_rw && it.startAddress >= nb_impl_elf.base() && it.endAddress <= nb_impl_elf.end()))
233+
if (!it.is_private || !it.is_rw)
237234
continue;
238235

239236
auto results = _kMgr->memScanner.findDataAll(it.startAddress, it.endAddress, &si, sizeof(si));
@@ -286,14 +283,14 @@ class SoInfoPatch
286283
if (sohead_elf.isValid() && it.startAddress >= sohead_elf.base())
287284
continue;
288285

289-
if (!KittyUtils::string_contains(it.pathname, arch))
286+
if (!KittyUtils::String::Contains(it.pathname, arch))
290287
continue;
291288

292289
auto fileName = KittyUtils::fileNameFromPath(it.pathname);
293290
auto fileExtension = KittyUtils::fileExtension(it.pathname);
294291

295292
bool is_libc = fileName == "libc.so";
296-
bool is_app_process = fileExtension.empty() && KittyUtils::string_startswith(fileName, "app_process");
293+
bool is_app_process = fileExtension.empty() && KittyUtils::String::StartsWith(fileName, "app_process");
297294

298295
if (!is_libc && !is_app_process)
299296
continue;
@@ -307,11 +304,11 @@ class SoInfoPatch
307304
sohead_elf = tmp;
308305
}
309306

310-
// our injected elf is loaded before libc / app_process ?
311-
if (!sohead_elf.isValid() || sohead_elf.base() > elf.base())
307+
// nb libc / app_process not loaded yet.
308+
if (!sohead_elf.isValid())
312309
{
313310
// don't have solution for this yet, increase injection delay for now
314-
KITTY_LOGE("SoInfoPatch: Failed to remove elf(%p) (first in solist).", (void*)elf.base());
311+
KITTY_LOGE("SoInfoPatch: Failed to find sohead ELF.");
315312
return false;
316313
}
317314

@@ -363,7 +360,7 @@ class SoInfoPatch
363360

364361
if (!trav)
365362
{
366-
KITTY_LOGE("SoInfoPatch: elf(%p) is not in solist.", (void*)elf.base());
363+
KITTY_LOGE("SoInfoPatch: elf(%p) is not in solist or was loaded before sohead.", (void*)elf.base());
367364
return false;
368365
}
369366

AndKittyInjector/src/main.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ void watch_proc_inject(const std::string& pkg, const std::string& lib,
317317
}
318318

319319
// inject on any event that isn't related to fd or timer
320-
auto proc_dir = KittyUtils::strfmt("/proc/%d", pid);
320+
auto proc_dir = KittyUtils::String::Fmt("/proc/%d", pid);
321321
int proc_dir_watch = sync_watch_callback(proc_dir, IN_ALL_EVENTS,
322322
[&](int, struct inotify_event* iev) -> bool {
323323

@@ -334,7 +334,7 @@ void watch_proc_inject(const std::string& pkg, const std::string& lib,
334334

335335
// maybe check cmdline if zygote or <preinitalized>
336336
// std::string cmdline;
337-
// KittyIOFile::readFileToString(KittyUtils::strfmt("/proc/%d/cmdline", pid), &cmdline);
337+
// KittyIOFile::readFileToString(KittyUtils::String::Fmt("/proc/%d/cmdline", pid), &cmdline);
338338
// KITTY_LOGI("cmdline %s", cmdline.c_str());
339339

340340
if (proc_dir_watch <= 0) {

0 commit comments

Comments
 (0)