// scanner.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。 // #include #include #include #include #include "../../common/log_util.h" #include "scanner.h" static bool found_proc(uint64_t pid, const char* path, void* param) { uint32_t* cnt = (uint32_t*)param; printf("%d - %ld: %s\n", ++cnt[0], pid, path); return true; } static bool found_modules(const char* path, bool is_dir, void* param) { uint32_t* cnt = (uint32_t*)param; printf("%d - %s\n", ++cnt[0], path); return true; } static bool found_modules_norepeat(const char* path, bool is_dir, void* param) { struct { uint32_t cnt; std::vector modules; }*data = nullptr; *(void**)&data = param; if (std::find(data->modules.begin(), data->modules.end(), path) == data->modules.end()) { printf("%d - %s\n", ++data->cnt, path); data->modules.push_back(path); } return true; } static bool on_found_thread(uint64_t tid, void* start_addr, void* param) { uint32_t* cnt = (uint32_t*)param; printf("%d - %p(%u): starting at %p\n", ++cnt[0], tid, tid, start_addr); return true; } static bool on_stack(uint64_t off, const char* module, void* param) { uint32_t* cnt = (uint32_t*)param; printf("%d - %s + %p\n", ++cnt[0], module, off); return true; } int32_t main(int32_t argc, char *argv[]) { // uint32_t cnt = 0, err = 0; // // if(argc >= 2) // { // if(strcmp(argv[1], "-h") == 0 || strcmp(argv[1], "-?") == 0 || strcmp(argv[1], "-help") == 0) // { // printf("usage: proc - no options, to enum all processes\n\ // -?/-h/-help: to show this message\n\ // [-nrp], to enum process(pid) modules, '-nrp' do not print repeating modules\n\ // <-t pid> [tid], to enum threads or print callstack of given thread\ // "); // } // else if(argc >= 3) // { // if(strcmp(argv[1], "-t") == 0) // { // uint32_t pid = atoi(argv[2]); // if(argc >= 4) // err = sys_util::get_thread_callstack(pid, atoi(argv[3]), on_stack, &cnt); // else // err = sys_util::enum_threads(pid, on_found_thread, &cnt); // } // else if(strcmp(argv[2], "-nrp") == 0) // { // struct // { // uint32_t cnt = 0; // std::vector modules; // }data; // err = sys_util::enum_modules(found_modules_norepeat, &data, atoi(argv[1])); // } // } // else // err = sys_util::enum_modules(found_modules, &cnt, atoi(argv[1])); // } // else // { // err = sys_util::enum_processes(found_proc, &cnt); // } // if(err) // printf("error = %d (%s)\n", err, strerror(err));EINVAL; // // return 0; char *oper = argc > 1 ? argv[1] : nullptr; log_cls::initialize(nullptr); log_cls::log(LOG_LEVEL_DEBUG, "----starting...----\n"); if (oper) { scanner* scnr = nullptr; int ret = 0; std::string id(sys_util::get_module_path() + ":0:104857600"); scnr = new scanner(id.c_str()); // ("/usr/bin/idtransponder:0:104857600"); ret = scnr->run(); scnr->release(); log_cls::log(LOG_LEVEL_DEBUG, "----stopped with: %s----\n", strerror(ret)); } log_cls::log(LOG_LEVEL_DEBUG, "----stopped.----\n"); return 0; }