Click here to Skip to main content
15,895,142 members
Articles / Programming Languages / C++

Detect Driver

,
Rate me:
Please Sign up or sign in to vote.
5.00/5 (46 votes)
10 Mar 2010CPOL12 min read 110.5K   9.1K   155  
This article is the continue of the previously posted article Hide Driver. Some methods to detect hidden files and processes are described in it
#include "stdafx.h"
#include "GUIApp.h"
#include "ProcessList.h"

#include "tlhelp32.h" // for CreateToolhelp32Snapshot

#include "HandleGuard.h" // utils

// ProcessList dialog

IMPLEMENT_DYNAMIC(ProcessList, CDialog)
ProcessList::ProcessList(CWnd* pParent /*=NULL*/)
    : CDialog(ProcessList::IDD, pParent)
{
}

ProcessList::~ProcessList()
{
}

void ProcessList::DoDataExchange(CDataExchange* pDX)
{
    CDialog::DoDataExchange(pDX);
    DDX_Control(pDX, IDC_LIST_USERS, processList_);
}


BEGIN_MESSAGE_MAP(ProcessList, CDialog)

    ON_BN_CLICKED(IDC_BUTTON_OK, OnBnClickedButtonOk)
    ON_BN_CLICKED(IDC_BUTTON_CANCEL, OnBnClickedButtonCancel)
END_MESSAGE_MAP()


// ProcessList message handlers

BOOL ProcessList::OnInitDialog()
{
    CDialog::OnInitDialog();
    SetWindowText(_T("Local Processes"));

    processList_.InsertColumn(0,_T("Image Name"),LVCFMT_LEFT,100,0);
    processList_.InsertColumn(1,_T("PID"),LVCFMT_LEFT,100,1);


    DWORD dwExStyle_f=processList_.GetExtendedStyle();
    dwExStyle_f= (LVS_EX_FULLROWSELECT|LVS_EX_GRIDLINES);
    processList_.SetExtendedStyle(dwExStyle_f);

    UpdateProcessList();

    return TRUE;  // return TRUE unless you set the focus to a control
    // EXCEPTION: OCX Property Pages should return FALSE
}
void ProcessList::UpdateProcessList(void)
{
    CString str;
    int nIndex = processList_.GetItemCount();

    HANDLE hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPALL,NULL);
    if(hSnapshot == INVALID_HANDLE_VALUE ) 
        return ;

    utils::HandleGuard guard(hSnapshot);

    PROCESSENTRY32 pe = {sizeof(pe)}; 
    BOOL fOK = Process32First(hSnapshot,&pe); // FirstProcess always ignored
    while(Process32Next(hSnapshot,&pe))
    {
        // Process Name
        str.Format(_T("%ws"),pe.szExeFile);
        processList_.InsertItem(nIndex,str);
        // Process PID
        str.Format(_T("%d"),pe.th32ProcessID);
        processList_.SetItemText(nIndex,1,str);

        ++nIndex;
    }
    
}
void ProcessList::OnOK()
{
	OnBnClickedButtonOk();
}
void ProcessList::OnBnClickedButtonOk()
{
    selectedProcesses_.clear();
    POSITION pos = processList_.GetFirstSelectedItemPosition();
    if (pos == NULL)
    {
        CDialog::OnOK();
        return;
    }

    while (pos)
    {
        int nItem = processList_.GetNextSelectedItem(pos);
        CString ProcessName = processList_.GetItemText(nItem,0);

        PWCHAR str = (PWCHAR)ProcessName.GetString();

        if(!selectedProcesses_.empty())
            selectedProcesses_+=L',';

        selectedProcesses_+=str;
    }
    CDialog::OnOK();
}

void ProcessList::OnBnClickedButtonCancel()
{
    CDialog::OnCancel();
}
const std::wstring& ProcessList::GetSelectedProcesses()const
{
	return selectedProcesses_;
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Chief Technology Officer Apriorit Inc.
United States United States
ApriorIT is a software research and development company specializing in cybersecurity and data management technology engineering. We work for a broad range of clients from Fortune 500 technology leaders to small innovative startups building unique solutions.

As Apriorit offers integrated research&development services for the software projects in such areas as endpoint security, network security, data security, embedded Systems, and virtualization, we have strong kernel and driver development skills, huge system programming expertise, and are reals fans of research projects.

Our specialty is reverse engineering, we apply it for security testing and security-related projects.

A separate department of Apriorit works on large-scale business SaaS solutions, handling tasks from business analysis, data architecture design, and web development to performance optimization and DevOps.

Official site: https://www.apriorit.com
Clutch profile: https://clutch.co/profile/apriorit
This is a Organisation

33 members

Written By
Software Developer Codedgers Inc
Ukraine Ukraine
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions