c++ - How to Fix SYSTEM_PROCESS_INFORMATION Errors -
help me fix error
#include <windows.h> #include <stdio.h> #include <psapi.h> td_ntquerysysteminformation ntquerysysteminformation = null; td_ntqueryobject ntqueryobject = null; td_ntduplicateobject ntduplicateobject = null; bool init() { hmodule hntdll = getmodulehandle(text("ntdll.dll")); if(!hntdll) return false; ntquerysysteminformation = (td_ntquerysysteminformation)getprocaddress(hntdll, "ntquerysysteminformation"); ntqueryobject = (td_ntqueryobject)getprocaddress(hntdll, "ntqueryobject"); ntduplicateobject = (td_ntduplicateobject)getprocaddress(hntdll, "ntduplicateobject"); return (ntquerysysteminformation && ntqueryobject && ntduplicateobject); } bool acquiredebugprivilege() { handle htoken = null; if(!openprocesstoken(getcurrentprocess(), token_adjust_privileges, &htoken)) return false; bool bsuccess = false; token_privileges tp; tp.privilegecount = 1; if(lookupprivilegevalue(0, se_debug_name, &tp.privileges[0].luid)) { tp.privileges[0].attributes = se_privilege_enabled; if(adjusttokenprivileges(htoken, 0, &tp, sizeof(tp), 0, 0)) bsuccess = true; } closehandle(htoken); return bsuccess; } bool isprocessfound(dword dwprocessid, psystem_process_information pinfos) { psystem_process_information pcurrent = pinfos; while(true) { if((dword)pcurrent->uniqueprocessid == dwprocessid) return true; if(pcurrent->nextentryoffset == 0) break; pcurrent = (psystem_process_information)((dword_ptr)pcurrent + pcurrent- >nextentryoffset); } return false; } bool detecthiddenprocesses(puint picount) { if(!picount) return false; *picount = 0; // first, retrieve process list (this dirty way) dword dwlen = sizeof(system_process_information); psystem_process_information pprocessinfos = (psystem_process_information)malloc(dwlen); while(pprocessinfos) { ntstatus status = ntquerysysteminformation(systemprocessinformation, pprocessinfos, dwlen, &dwlen); if(nt_success(status)) break; else if(status != status_info_length_mismatch) { free(pprocessinfos); return false; } free(pprocessinfos); pprocessinfos = (psystem_process_information)malloc(dwlen); } if(!pprocessinfos) return false; // secondly, retreive open handle dwlen = sizeof(system_handle_information); psystem_handle_information phandleinfos = (psystem_handle_information)malloc(dwlen); while(phandleinfos) { ntstatus status = ntquerysysteminformation(systemhandleinformation, phandleinfos, dwlen, &dwlen); if(nt_success(status)) break; else if(status != status_info_length_mismatch) { free(phandleinfos); return false; } free(phandleinfos); phandleinfos = (psystem_handle_information)malloc(dwlen); } if(!phandleinfos) return false; // now, find handle process pobject_type_information ptype = (pobject_type_information)malloc(4096); if(!ptype) { free(phandleinfos); free(pprocessinfos); return false; } for(ulong = 0; < phandleinfos->handlecount; i++) { dword dwowner = phandleinfos->handles[i].processid; handle hhandle = (handle)phandleinfos->handles[i].handle; handle howner = openprocess(process_dup_handle, false, dwowner); if(howner == null) continue; // duplicate handle can query handle hhandlelocal = null; ntstatus status = ntduplicateobject(howner, hhandle, getcurrentprocess(), &hhandlelocal, 0, 0, duplicate_same_access | duplicate_same_attributes); if(nt_success(status)) { // query type status = ntqueryobject(hhandlelocal, objecttypeinformation, ptype, 4096, null); if(nt_success(status)) { if(ptype->typename.buffer && wcscmp(ptype->typename.buffer, l"process") == 0) { dword dwprocessid = getprocessid(hhandlelocal); // check if process not hidden if(!isprocessfound(dwprocessid, pprocessinfos)) { // hoho here go wchar_t szprocess[max_path]; if(getprocessimagefilenamew(hhandlelocal, szprocess, max_path) == 0) wcscpy_s(szprocess, l"<unknown>"); printf("[%0.4d] %ws\n", dwprocessid, szprocess); (*picount)++; } } } } closehandle(howner); } free(ptype); free(phandleinfos); free(pprocessinfos); return true; } int main(int argc, char* argv[]) { uint ihiddencount = 0; if(!acquiredebugprivilege()) { printf("unable acquire debug privilege.\n"); return exit_failure; } if(!init()) { printf("initialization failure.\r\n"); return exit_failure; } detecthiddenprocesses(&ihiddencount); printf("found %d hidden process%s.\r\n", ihiddencount, (ihiddencount > 1 ? "es" : "")); return exit_success; }
code
1>------ build started: project: mand, configuration: release win32 ------ 1> main.cpp 1>main.cpp(5): error c2146: syntax error : missing ';' before identifier 'ntquerysysteminformation' 1>main.cpp(5): error c4430: missing type specifier - int assumed. note: c++ not support default-int 1>main.cpp(5): error c4430: missing type specifier - int assumed. note: c++ not support default-int 1>main.cpp(6): error c2146: syntax error : missing ';' before identifier 'ntqueryobject' 1>main.cpp(6): error c4430: missing type specifier - int assumed. note: c++ not support default-int 1>main.cpp(6): error c4430: missing type specifier - int assumed. note: c++ not support default-int 1>main.cpp(7): error c2146: syntax error : missing ';' before identifier 'ntduplicateobject' 1>main.cpp(7): error c4430: missing type specifier - int assumed. note: c++ not support default-int 1>main.cpp(7): error c4430: missing type specifier - int assumed. note: c++ not support default-int 1>main.cpp(14): error c2146: syntax error : missing ';' before identifier 1>main.cpp(15): error c2146: syntax error : missing ';' before identifier 'getprocaddress' 1>main.cpp(16): error c2146: syntax error : missing ';' before identifier 'getprocaddress' 1>main.cpp(41): error c2061: syntax error : identifier 'psystem_process_information' 1>main.cpp(42): error c2065: 'psystem_process_information' : undeclared identifier 1>main.cpp(42): error c2146: syntax error : missing ';' before identifier 'pcurrent' 1>main.cpp(42): error c2065: 'pcurrent' : undeclared identifier 1>main.cpp(42): error c2065: 'pinfos' : undeclared identifier 1>main.cpp(45): error c2065: 'pcurrent' : undeclared identifier 1>main.cpp(45): error c2227: left of '->uniqueprocessid' must point class/struct/union/generic type 1> type ''unknown-type'' 1>main.cpp(48): error c2065: 'pcurrent' : undeclared identifier 1>main.cpp(48): error c2227: left of '->nextentryoffset' must point class/struct/union/generic type 1> type ''unknown-type'' 1>main.cpp(50): error c2065: 'pcurrent' : undeclared identifier 1>main.cpp(50): error c2065: 'psystem_process_information' : undeclared identifier 1>main.cpp(50): error c2065: 'pcurrent' : undeclared identifier 1>main.cpp(50): error c2065: 'pcurrent' : undeclared identifier 1>main.cpp(50): error c2227: left of '->nextentryoffset' must point class/struct/union/generic type 1> type ''unknown-type'' 1>main.cpp(62): error c2065: 'system_process_information' : undeclared identifier 1>main.cpp(62): error c2070: ''unknown-type'': illegal sizeof operand 1>main.cpp(63): error c2065: 'psystem_process_information' : undeclared identifier 1>main.cpp(63): error c2146: syntax error : missing ';' before identifier 'pprocessinfos' 1>main.cpp(63): error c2065: 'pprocessinfos' : undeclared identifier 1>main.cpp(63): error c2065: 'psystem_process_information' : undeclared identifier 1>main.cpp(63): error c2146: syntax error : missing ';' before identifier 'malloc' 1>main.cpp(65): error c2065: 'pprocessinfos' : undeclared identifier 1>main.cpp(66): error c2065: 'systemprocessinformation' : undeclared identifier 1>main.cpp(66): error c2065: 'pprocessinfos' : undeclared identifier 1>main.cpp(67): error c3861: 'nt_success': identifier not found 1>main.cpp(69): error c2065: 'status_info_length_mismatch' : undeclared identifier 1>main.cpp(70): error c2065: 'pprocessinfos' : undeclared identifier 1>main.cpp(74): error c2065: 'pprocessinfos' : undeclared identifier 1>main.cpp(75): error c2065: 'pprocessinfos' : undeclared identifier 1>main.cpp(75): error c2065: 'psystem_process_information' : undeclared identifier 1>main.cpp(75): error c2146: syntax error : missing ';' before identifier 'malloc' 1>main.cpp(78): error c2065: 'pprocessinfos' : undeclared identifier 1>main.cpp(82): error c2065: 'system_handle_information' : undeclared identifier 1>main.cpp(82): error c2070: ''unknown-type'': illegal sizeof operand 1>main.cpp(83): error c2065: 'psystem_handle_information' : undeclared identifier 1>main.cpp(83): error c2146: syntax error : missing ';' before identifier 'phandleinfos' 1>main.cpp(83): error c2065: 'phandleinfos' : undeclared identifier 1>main.cpp(83): error c2065: 'psystem_handle_information' : undeclared identifier 1>main.cpp(83): error c2146: syntax error : missing ';' before identifier 'malloc' 1>main.cpp(85): error c2065: 'phandleinfos' : undeclared identifier 1>main.cpp(86): error c2065: 'systemhandleinformation' : undeclared identifier 1>main.cpp(86): error c2065: 'phandleinfos' : undeclared identifier 1>main.cpp(87): error c3861: 'nt_success': identifier not found 1>main.cpp(89): error c2065: 'status_info_length_mismatch' : undeclared identifier 1>main.cpp(90): error c2065: 'phandleinfos' : undeclared identifier 1>main.cpp(94): error c2065: 'phandleinfos' : undeclared identifier 1>main.cpp(95): error c2065: 'phandleinfos' : undeclared identifier 1>main.cpp(95): error c2065: 'psystem_handle_information' : undeclared identifier 1>main.cpp(95): error c2146: syntax error : missing ';' before identifier 'malloc' 1>main.cpp(98): error c2065: 'phandleinfos' : undeclared identifier 1>main.cpp(102): error c2065: 'pobject_type_information' : undeclared identifier 1>main.cpp(102): error c2146: syntax error : missing ';' before identifier 'ptype' 1>main.cpp(102): error c2065: 'ptype' : undeclared identifier 1>main.cpp(102): error c2065: 'pobject_type_information' : undeclared identifier 1>main.cpp(102): error c2146: syntax error : missing ';' before identifier 'malloc' 1>main.cpp(103): error c2065: 'ptype' : undeclared identifier 1>main.cpp(104): error c2065: 'phandleinfos' : undeclared identifier 1>main.cpp(105): error c2065: 'pprocessinfos' : undeclared identifier 1>main.cpp(109): error c2065: 'phandleinfos' : undeclared identifier 1>main.cpp(109): error c2227: left of '->handlecount' must point class/struct/union/generic type 1> type ''unknown-type'' 1>main.cpp(110): error c2065: 'phandleinfos' : undeclared identifier 1>main.cpp(110): error c2227: left of '->handles' must point class/struct/union/generic type 1>main.cpp(110): error c2228: left of '.processid' must have class/struct/union 1>main.cpp(111): error c2065: 'phandleinfos' : undeclared identifier 1>main.cpp(111): error c2227: left of '->handles' must point class/struct/union/generic type 1> type ''unknown-type'' 1>main.cpp(111): error c2228: left of '.handle' must have class/struct/union 1>main.cpp(119): error c2065: 'duplicate_same_attributes' : undeclared identifier 1>main.cpp(119): error c2064: term not evaluate function taking 7 arguments 1>main.cpp(120): error c3861: 'nt_success': identifier not found 1>main.cpp(122): error c2065: 'objecttypeinformation' : undeclared identifier 1>main.cpp(122): error c2065: 'ptype' : undeclared identifier 1>main.cpp(123): error c3861: 'nt_success': identifier not found 1>main.cpp(124): error c2065: 'ptype' : undeclared identifier 1>main.cpp(124): error c2227: left of '->typename' must point class/struct/union/generic type 1> type ''unknown-type'' 1>main.cpp(124): error c2228: left of '.buffer' must have class/struct/union 1>main.cpp(124): error c2065: 'ptype' : undeclared identifier 1>main.cpp(124): error c2227: left of '->typename' must point class/struct/union/generic type 1> type ''unknown-type'' 1>main.cpp(124): error c2228: left of '.buffer' must have class/struct/union 1>main.cpp(127): error c2065: 'pprocessinfos' : undeclared identifier 1>main.cpp(142): error c2065: 'ptype' : undeclared identifier 1>main.cpp(144): error c2065: 'phandleinfos' : undeclared identifier 1>main.cpp(145): error c2065: 'pprocessinfos' : undeclared identifier ========== build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
these types undefined , therefore unknown compiler:
td_ntquerysysteminformation ntquerysysteminformation = null; td_ntqueryobject ntqueryobject = null; td_ntduplicateobject ntduplicateobject = null;
same psystem_process_information
, pobject_type_information
etc.
you need include definition.
Comments
Post a Comment