#ifndef ENV_MODULE_H
#define ENV_MODULE_H
#include <QDateTime>
#include <QString>
namespace env
{
struct HandleCloser
{
using pointer = HANDLE;
void operator()(HANDLE h)
{
if (h != INVALID_HANDLE_VALUE) {
::CloseHandle(h);
}
}
};
using HandlePtr = std::unique_ptr<HANDLE, HandleCloser>;
class Module
{
public:
Module(QString path, std::size_t fileSize);
const QString& path() const;
QString displayPath() const;
std::size_t fileSize() const;
const QString& version() const;
const QString& versionString() const;
const QDateTime& timestamp() const;
const QString& md5() const;
QString timestampString() const;
bool interesting() const;
QString toString() const;
private:
struct FileInfo
{
VS_FIXEDFILEINFO ffi;
QString fileDescription;
};
QString m_path;
std::size_t m_fileSize;
QString m_version;
QDateTime m_timestamp;
QString m_versionString;
QString m_md5;
FileInfo getFileInfo() const;
QString getVersion(const VS_FIXEDFILEINFO& fi) const;
QDateTime getTimestamp(const VS_FIXEDFILEINFO& fi) const;
QString getMD5() const;
VS_FIXEDFILEINFO getFixedFileInfo(std::byte* buffer) const;
QString getFileDescription(std::byte* buffer) const;
};
class Process
{
public:
Process();
explicit Process(HANDLE h);
Process(DWORD pid, DWORD ppid, QString name);
bool isValid() const;
DWORD pid() const;
DWORD ppid() const;
const QString& name() const;
HandlePtr openHandleForWait() const;
bool canAccess() const;
void addChild(Process p);
std::vector<Process>& children();
const std::vector<Process>& children() const;
private:
DWORD m_pid;
mutable std::optional<DWORD> m_ppid;
mutable std::optional<QString> m_name;
std::vector<Process> m_children;
};
std::vector<Process> getRunningProcesses();
std::vector<Module> getLoadedModules();
Process getProcessTree(HANDLE h);
QString getProcessName(DWORD pid);
QString getProcessName(HANDLE process);
DWORD getProcessParentID(DWORD pid);
DWORD getProcessParentID(HANDLE handle);
}
#endif