Skip to content

Commit

Permalink
Выводятся родители нормально теперь
Browse files Browse the repository at this point in the history
  • Loading branch information
klimov-andre committed Mar 20, 2019
1 parent 009202d commit 017222d
Showing 1 changed file with 49 additions and 27 deletions.
76 changes: 49 additions & 27 deletions WinSecurity/WinSecurity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@
#include <aclapi.h>


#include <map>
#include <algorithm>
#include <string>

#define CONSOLE
#define PROCESS_CNT 512
#define BUF_LEN 512
Expand All @@ -36,7 +40,42 @@ DWORD GetOwnerNamenSID(DWORD PID, LPWSTR wstrName, DWORD dwNameLen, LPSTR* strSI
BOOL SetPrivilege(HANDLE hToken, LPCTSTR lpszPrivilege, BOOL bEnablePrivilege);
DWORD PrintProcessIntegrity(DWORD PID);
DWORD ShowProcessPrivilages(DWORD PID);
DWORD PrintFileIntegrity(LPSTR path);


// МАПА ПИД -> ИМЯ для быстрого узнавания родителя
std::map <DWORD, std::wstring> g_Processes;


// Заполняет структуру с именами и ПИДами
VOID InitializeProcesses()
{
HANDLE hProcessSnap;
PROCESSENTRY32 pe32;

pe32.dwSize = sizeof(PROCESSENTRY32);
hProcessSnap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);

if (!Process32First(hProcessSnap, &pe32))
{
PRINT_STR_CONSOLE("Error: Process32First");
CloseHandle(hProcessSnap);
return;
}

do
{
g_Processes.insert(std::pair<DWORD, std::wstring>(pe32.th32ProcessID, std::wstring(pe32.szExeFile)));
}while (Process32Next(hProcessSnap, &pe32));

CloseHandle(hProcessSnap);
}


// Тупо вывод бати
VOID PrintParentProcName(DWORD ParentPID)
{
std::wcout << g_Processes[ParentPID];
}


INT Is_64(DWORD PID)
Expand Down Expand Up @@ -81,6 +120,8 @@ BOOL GetProcessList()
DWORD dwCopiedBufLen;
WCHAR wstrExePath[MAX_PATH];

InitializeProcesses();

pe32.dwSize = sizeof(PROCESSENTRY32);

/*
Expand Down Expand Up @@ -133,28 +174,8 @@ BOOL GetProcessList()
////PID РОДИТЕЛЯ
//wprintf(L" %d", pe32.th32ParentProcessID);

////ИМЯ РОДИТЕЛЯ
//hParentProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, pe32.th32ParentProcessID);
//if (hParentProcess == INVALID_HANDLE_VALUE)
//{
// wprintf(L" N/a\n");
//}
//else
//{
// HMODULE hMod;
// DWORD dwLen;
// DWORD dwRes;
// CHAR szProcessName[MAX_PATH];
// dwRes = GetProcessImageFileNameA(hParentProcess, szProcessName, MAX_PATH);
// if (dwRes > 0)
// {
// printf(" %s \n",szProcessName);
// }
// else
// {
// printf(" N/a\n");
// }
//}
//ИМЯ РОДИТЕЛЯ
PrintParentProcName(pe32.th32ParentProcessID);

//// МОДУЛИ
//ListProcessModules(pe32.th32ProcessID);
Expand Down Expand Up @@ -213,7 +234,7 @@ BOOL GetProcessList()

//// УРОВЕНЬ ЦЕЛОСТНОСТИ
// printf("%lu\n", PrintProcessIntegrity(pe32.th32ProcessID));
ShowProcessPrivilages(pe32.th32ProcessID);
//ShowProcessPrivilages(pe32.th32ProcessID);

//PrintFileIntegrity((LPWSTR)L"C:\\Virtual\\ddd.txt");

Expand Down Expand Up @@ -948,9 +969,10 @@ DWORD SetFileIntegrity(LPWSTR path, LPSTR strIntegrity)
int main()
{
setlocale(LC_ALL, "Rus");
PrintFileIntegrity((LPWSTR)L"C:\\Virtual\\ddd.txt");
SetFileIntegrity((LPWSTR)L"C:\\Virtual\\ddd.txt", (LPSTR)"Low");
PrintFileIntegrity((LPWSTR)L"C:\\Virtual\\ddd.txt");
GetProcessList();
//PrintFileIntegrity((LPWSTR)L"C:\\Virtual\\ddd.txt");
//SetFileIntegrity((LPWSTR)L"C:\\Virtual\\ddd.txt", (LPSTR)"Low");
//PrintFileIntegrity((LPWSTR)L"C:\\Virtual\\ddd.txt");

}

0 comments on commit 017222d

Please sign in to comment.