29 size_t extract_syscalls(BYTE* pe_buf,
size_t pe_size, std::map<DWORD, std::string>& syscallToName,
size_t startID = 0)
31 std::vector<std::string> names_list;
32 if (!peconv::get_exported_names(pe_buf, names_list)) {
36 std::map<DWORD, std::string> sys_functions;
37 for (
auto itr = names_list.begin(); itr != names_list.end(); ++itr) {
38 std::string funcName = *itr;
40 ULONG_PTR va = (ULONG_PTR)peconv::get_exported_func(pe_buf, funcName.c_str());
44 sys_functions[rva] = funcName;
48 for (
auto itr = sys_functions.begin(); itr != sys_functions.end(); ++itr) {
49 std::string funcName = itr->second;
50 syscallToName[
id++] = funcName;
55 size_t extract_from_dll(IN
const std::string& path,
size_t startSyscallID, OUT std::map<DWORD, std::string>& syscallToName)
58 BYTE* buffer = peconv::load_pe_module(path.c_str(), bufsize,
false,
false);
62 std::cerr <<
"Failed to load the PE: " << path <<
"\n";
67 size_t extracted_count =
extract_syscalls(buffer, bufsize, syscallToName, startSyscallID);
68 peconv::free_pe_buffer(buffer);
70 if (!extracted_count) {
72 std::cerr <<
"No syscalls extracted from: " << path <<
"\n";
75 return extracted_count;
87 std::stringstream outs;
88 size_t extracted_count = 0;
91 ExpandEnvironmentStringsA(
"%SystemRoot%\\system32\\ntdll.dll", ntdll_path,
MAX_PATH);
95 ExpandEnvironmentStringsA(
"%SystemRoot%\\system32\\win32u.dll", win32u_path,
MAX_PATH);
100 if (!extracted_count) {
102 std::cerr <<
"Failed to extract syscalls.\n";
106 return syscallToName.size();