GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — feat: Pro版本更新4.5.3,修复一些问题。 · pigadmin/SKRoot-linuxKernelRoot@82e6066

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • Pro(众测开放中)/src/testModule/module_TEESimulatorRS
    • android_packages_list_utils.h
    • module_TEESimulatorRS.cpp
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎Pro(众测开放中)/src/testModule/module_TEESimulatorRS/android_packages_list_utils.h‎

Copy file name to clipboardExpand all lines: Pro(众测开放中)/src/testModule/module_TEESimulatorRS/android_packages_list_utils.h
+198-4Lines changed: 198 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,23 @@
11
#pragma once
2+
3+
#include <atomic>
4+
#include <cerrno>
5+
#include <cctype>
6+
#include <cstddef>
7+
#include <cstdint>
8+
#include <fstream>
9+
#include <functional>
10+
#include <limits>
11+
#include <poll.h>
12+
#include <sstream>
213
#include <string>
314
#include <string_view>
4-
#include <vector>
15+
#include <sys/inotify.h>
516
#include <unordered_map>
617
#include <unordered_set>
7-
#include <fstream>
8-
#include <sstream>
9-
#include <cctype>
18+
#include <unistd.h>
19+
#include <utility>
20+
#include <vector>
1021

1122
namespace android_pkgmap {
1223

@@ -55,6 +66,20 @@ namespace detail {
5566
return true;
5667
}
5768

69+
inline bool split_path(const std::string& path,
70+
std::string& out_directory,
71+
std::string& out_filename) {
72+
const std::size_t slash = path.find_last_of('/');
73+
74+
if (slash == std::string::npos || slash + 1 >= path.size()) {
75+
return false;
76+
}
77+
78+
out_directory = slash == 0 ? "/" : path.substr(0, slash);
79+
out_filename = path.substr(slash + 1);
80+
81+
return !out_filename.empty();
82+
}
5883
}
5984

6085
/**
@@ -162,4 +187,173 @@ inline uint32_t get_uid_for_package(const std::string& pkg,
162187
return 0;
163188
}
164189

190+
/**
191+
* 最小化监听 packages.list 是否发生变化。
192+
*
193+
* 这里只负责通知“包列表发生过变化”,不读取文件、不比较内容,
194+
* 也不区分安装、卸载、更新或 UID 变化。
195+
*
196+
* 监听目录而不是直接监听 packages.list,是因为 Android 通常先写
197+
* 临时文件,再通过 rename 覆盖 packages.list。直接监听文件 inode
198+
* 在文件被替换后可能失效。
199+
*
200+
* 监听事件:
201+
* IN_MOVED_TO 临时文件 rename 为 packages.list
202+
* IN_CLOSE_WRITE 某些厂商直接写 packages.list 后关闭
203+
*
204+
* @param callback 检测到变化时调用
205+
* @param stop_requested 外部停止标志
206+
* @param path packages.list 完整路径
207+
* @param stop_poll_ms 检查停止标志的最长间隔,默认 500ms
208+
*
209+
* @return 正常停止返回 true;初始化或监听失败返回 false。
210+
*/
211+
inline bool watch_packages_list_changed(
212+
const std::function<void()>& callback,
213+
const std::atomic_bool& stop_requested,
214+
const std::string& path = "/data/system/packages.list",
215+
int stop_poll_ms = 500) {
216+
if (!callback) {
217+
return false;
218+
}
219+
220+
std::string directory;
221+
std::string filename;
222+
223+
if (!detail::split_path(path, directory, filename)) {
224+
return false;
225+
}
226+
227+
const int inotify_fd =
228+
::inotify_init1(IN_NONBLOCK | IN_CLOEXEC);
229+
230+
if (inotify_fd < 0) {
231+
return false;
232+
}
233+
234+
constexpr std::uint32_t kWatchMask =
235+
IN_MOVED_TO |
236+
IN_CLOSE_WRITE;
237+
238+
const int watch_descriptor =
239+
::inotify_add_watch(
240+
inotify_fd,
241+
directory.c_str(),
242+
kWatchMask);
243+
244+
if (watch_descriptor < 0) {
245+
::close(inotify_fd);
246+
return false;
247+
}
248+
249+
if (stop_poll_ms < 1) {
250+
stop_poll_ms = 1;
251+
}
252+
253+
pollfd poll_fd{
254+
.fd = inotify_fd,
255+
.events = POLLIN,
256+
.revents = 0,
257+
};
258+
259+
alignas(inotify_event) char buffer[4096];
260+
bool success = true;
261+
262+
while (!stop_requested.load(std::memory_order_relaxed)) {
263+
poll_fd.revents = 0;
264+
265+
const int poll_result =
266+
::poll(&poll_fd, 1, stop_poll_ms);
267+
268+
if (poll_result < 0) {
269+
if (errno == EINTR) {
270+
continue;
271+
}
272+
273+
success = false;
274+
break;
275+
}
276+
277+
if (poll_result == 0) {
278+
continue;
279+
}
280+
281+
if ((poll_fd.revents &
282+
(POLLERR | POLLHUP | POLLNVAL)) != 0) {
283+
success = false;
284+
break;
285+
}
286+
287+
if ((poll_fd.revents & POLLIN) == 0) {
288+
continue;
289+
}
290+
291+
for (;;) {
292+
const ssize_t bytes_read =
293+
::read(inotify_fd, buffer, sizeof(buffer));
294+
295+
if (bytes_read < 0) {
296+
if (errno == EINTR) {
297+
continue;
298+
}
299+
300+
if (errno == EAGAIN || errno == EWOULDBLOCK) {
301+
break;
302+
}
303+
304+
success = false;
305+
break;
306+
}
307+
308+
if (bytes_read == 0) {
309+
success = false;
310+
break;
311+
}
312+
313+
std::size_t offset = 0;
314+
315+
while (offset + sizeof(inotify_event) <=
316+
static_cast<std::size_t>(bytes_read)) {
317+
const auto* event =
318+
reinterpret_cast<const inotify_event*>(
319+
buffer + offset);
320+
321+
const std::size_t event_size =
322+
sizeof(inotify_event) + event->len;
323+
324+
if (offset + event_size >
325+
static_cast<std::size_t>(bytes_read)) {
326+
success = false;
327+
break;
328+
}
329+
330+
bool changed = false;
331+
332+
if ((event->mask & IN_Q_OVERFLOW) != 0) {
333+
changed = true;
334+
} else if (event->len > 0 &&
335+
std::string_view(event->name) == filename &&
336+
(event->mask &
337+
(IN_MOVED_TO | IN_CLOSE_WRITE)) != 0) {
338+
changed = true;
339+
}
340+
341+
if (changed) {
342+
callback();
343+
}
344+
345+
offset += event_size;
346+
}
347+
348+
if (!success) {
349+
break;
350+
}
351+
}
352+
}
353+
354+
::inotify_rm_watch(inotify_fd, watch_descriptor);
355+
::close(inotify_fd);
356+
357+
return success;
358+
}
165359
} // namespace android_pkgmap
Collapse file

‎Pro(众测开放中)/src/testModule/module_TEESimulatorRS/module_TEESimulatorRS.cpp‎

Copy file name to clipboardExpand all lines: Pro(众测开放中)/src/testModule/module_TEESimulatorRS/module_TEESimulatorRS.cpp
+14-1Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#include <iostream>
22
#include <unistd.h>
33
#include <algorithm>
4+
#include <atomic>
5+
#include <thread>
46
#include <sys/wait.h>
57
#include <sys/syscall.h>
68
#include "module_TEESimulatorRS.h"
@@ -11,7 +13,7 @@
1113
#include "android_packages_list_utils.h"
1214
#include "android_system_property_utils.h"
1315

14-
#define MOD_VER "6.0.1-r1"
16+
#define MOD_VER "6.0.1-r2"
1517

1618
#define CONFIG_DIR "/data/adb/tricky_store"
1719
#define TARGET_TXT "/data/adb/tricky_store/target.txt"
@@ -142,6 +144,17 @@ int skroot_module_main(const char* root_key, const char* module_private_dir) {
142144
if (auto_third_app_toggle) {
143145
bool ok = write_target_txt_applist();
144146
printf("write target.txt applist: %s\n", ok ? "success" : "failed");
147+
pid_t pid = ::fork();
148+
if (pid == 0) {
149+
sleep(7);
150+
static std::atomic_bool stop_watcher{false};
151+
android_pkgmap::watch_packages_list_changed([] {
152+
printf("app list has changed!\n");
153+
bool ok = write_target_txt_applist();
154+
printf("write target.txt applist: %s\n", ok ? "success" : "failed");
155+
}, stop_watcher);
156+
_exit(127);
157+
}
145158
}
146159

147160
pid_t pid = ::fork();

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.