Skip to content

Commit

Permalink
add process and module display fields
Browse files Browse the repository at this point in the history
  • Loading branch information
BlackINT3 committed Jun 15, 2019
1 parent 552ba24 commit 048255d
Show file tree
Hide file tree
Showing 7 changed files with 88 additions and 39 deletions.
5 changes: 1 addition & 4 deletions src/OpenArk/cmds/cmds.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -493,10 +493,7 @@ Q_INVOKABLE void Cmds::CmdProcessInfo(QStringList argv)

Q_INVOKABLE void Cmds::CmdProcessTree(QStringList argv)
{
UNONE::LogCallback routine;
bool regok = UNONE::InterCurrentLogger(routine);
if (regok) UNONE::InterRegisterLogger([&](const std::wstring &) {});
ON_SCOPE_EXIT([&] {if (regok) UNONE::InterUnregisterLogger();});
DISABLE_RECOVER();

int level = 0;
std::wstring prefix;
Expand Down
33 changes: 28 additions & 5 deletions src/OpenArk/common/cache/cache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ static struct {
QMap<unsigned int, ProcInfo> d;
} proc_info;


ProcInfo CacheGetProcInfo(unsigned int pid, ProcInfo& info)
{
QMutexLocker locker(&proc_info.lck);
Expand All @@ -34,11 +35,11 @@ ProcInfo CacheGetProcInfo(unsigned int pid, ProcInfo& info)
if (info.ppid == -1) info.ppid = UNONE::PsGetParentPid(pid);
auto &&path = UNONE::PsGetProcessPathW(pid);
info.path = WStrToQ(path);
std::wstring company, descript;
UNONE::FsGetFileInfoW(path, L"CompanyName", company);
UNONE::FsGetFileInfoW(path, L"FileDescription", descript);
info.corp = WStrToQ(company);
info.desc = WStrToQ(descript);
std::wstring corp, desc;
UNONE::FsGetFileInfoW(path, L"CompanyName", corp);
UNONE::FsGetFileInfoW(path, L"FileDescription", desc);
info.corp = WStrToQ(corp);
info.desc = WStrToQ(desc);
if (info.name.isEmpty()) info.name = WStrToQ(UNONE::FsPathToNameW(path));
info.ctime = WStrToQ(ProcessCreateTime(pid));
if (is_os64 && !UNONE::PsIsX64(pid)) info.name.append(" *32");
Expand Down Expand Up @@ -89,4 +90,26 @@ UNONE::PROCESS_BASE_INFOW CacheGetProcessBaseInfo(DWORD pid)
UNONE::PsGetProcessInfoW(pid, info);
proc_baseinfo.d.insert(pid, info);
return info;
}

static struct {
QMutex lck;
QMap<QString, FileBaseInfo> d;
} filebase_info;

FileBaseInfo CacheGetFileBaseInfo(QString path)
{
QMutexLocker locker(&filebase_info.lck);
if (filebase_info.d.contains(path)) {
auto it = filebase_info.d.find(path);
return it.value();
}
std::wstring corp, desc, ver;
auto w_path = path.toStdWString();
UNONE::FsGetFileInfoW(w_path, L"CompanyName", corp);
UNONE::FsGetFileInfoW(w_path, L"FileDescription", desc);
UNONE::FsGetFileVersionW(w_path, ver);
auto info = FileBaseInfo{ path, WStrToQ(desc), WStrToQ(ver), WStrToQ(corp) };
filebase_info.d.insert(path, info);
return info;
}
7 changes: 7 additions & 0 deletions src/OpenArk/common/cache/cache.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,10 @@ void CacheRefreshProcInfo();

UNONE::PROCESS_BASE_INFOW CacheGetProcessBaseInfo(DWORD pid);

struct FileBaseInfo {
QString path;
QString desc;
QString ver;
QString corp;
};
FileBaseInfo CacheGetFileBaseInfo(QString path);
7 changes: 7 additions & 0 deletions src/OpenArk/common/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,10 @@ __inline QString AppBdTime()
QString stamp = StrToQ(UNONE::TmFormatUnixTimeA(UNONE::PeGetTimeStamp((CHAR*)GetModuleHandleW(NULL)), "YMDHW"));
return stamp;
}

// disable logger, exit recover
#define DISABLE_RECOVER() \
UNONE::LogCallback routine;\
bool regok = UNONE::InterCurrentLogger(routine);\
if (regok) UNONE::InterRegisterLogger([&](const std::wstring &) {});\
ON_SCOPE_EXIT([&] {if (regok) UNONE::InterUnregisterLogger(); });
2 changes: 1 addition & 1 deletion src/OpenArk/common/cpp-wrapper/cpp-wrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,4 @@ class ScopeGuard

#define SCOPEGUARD_LINENAME_CAT(name, line) name##line
#define SCOPEGUARD_LINENAME(name, line) SCOPEGUARD_LINENAME_CAT(name, line)
#define ON_SCOPE_EXIT(callback) ScopeGuard SCOPEGUARD_LINENAME(EXIT, __LINE__)(callback)
#define ON_SCOPE_EXIT(callback) ScopeGuard SCOPEGUARD_LINENAME(EXIT, __LINE__)(callback)
71 changes: 43 additions & 28 deletions src/OpenArk/process-mgr/process-mgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,14 @@ struct {

// ModulesView's header index
struct {
int name = 0;
int base = 1;
int size = 2;
int path = 3;
int desc = 4;
int ver = 5;
int corp = 6;
int s = 0;
int name = s++;
int base = s++;
int size = s++;
int path = s++;
int desc = s++;
int ver = s++;
int corp = s++;
} MDX;

ProcSortFilterProxyModel::ProcSortFilterProxyModel(QWidget *parent)
Expand Down Expand Up @@ -120,15 +121,15 @@ ProcessMgr::ProcessMgr(QWidget* parent) :
pview->setColumnWidth(PDX.path, 440);
pview->setColumnWidth(PDX.desc, 190);
pview->setColumnWidth(PDX.corp, 155);
ShowProcessTree();
ShowProcess();

mod_menu_ = new QMenu();
mod_menu_->addAction(tr("Refresh"), this, SLOT(onRefresh()));
mod_menu_->addAction(tr("Explore File"), this, SLOT(onExploreFile()));
mod_menu_->addAction(tr("Sento Scanner"), this, SLOT(onSendtoScanner()));
mod_model_ = new QStandardItemModel;
QTreeView *mview = ui.moduleView;
mod_model_->setHorizontalHeaderLabels(QStringList() << tr("Name") << tr("Base") << tr("Size") << tr("Path"));
mod_model_->setHorizontalHeaderLabels(QStringList() << tr("Name") << tr("Base") << tr("Size") << tr("Path") << tr("Description") << tr("Version") << tr("Company Name"));
SetDefaultTreeViewStyle(mview, mod_model_);
mview->header()->setSortIndicator(-1, Qt::AscendingOrder);
mview->viewport()->installEventFilter(this);
Expand Down Expand Up @@ -222,17 +223,15 @@ void ProcessMgr::onRefresh()
{
auto sender = QObject::sender();
if (IsContainAction(proc_menu_, sender)) {
if (proc_header_idx_ == 0) ShowProcessTree();
else ShowProcessList();
ShowProcess();
return;
}
if (IsContainAction(mod_menu_, sender)) {
onShowModules();
return;
}
if (sender == nullptr) {
if (proc_header_idx_ == 0) ShowProcessTree();
else ShowProcessList();
ShowProcess();
return;
}
}
Expand Down Expand Up @@ -407,36 +406,45 @@ void ProcessMgr::onShowProperties()

void ProcessMgr::onShowModules()
{
DISABLE_RECOVER();
ClearItemModelData(mod_model_, 0);
DWORD pid = ProcCurPid();
UNONE::PsEnumModule(pid, [&](MODULEENTRY32W& entry)->bool{
QString modname = WCharsToQ(entry.szModule);
QString modpath = WCharsToQ(entry.szExePath);
ULONG64 modbase = (ULONG64)entry.modBaseAddr;
ULONG64 modsize = entry.modBaseSize;
QStandardItem *item0 = new QStandardItem(LoadIcon(modpath), modname);
QStandardItem *item1 = new QStandardItem(WStrToQ(UNONE::StrFormatW(L"0x%llX", modbase)));
QStandardItem *item2 = new QStandardItem(WStrToQ(UNONE::StrFormatW(L"0x%llX", modsize)));
QStandardItem *item3 = new QStandardItem(modpath);
auto count = mod_model_->rowCount();
for (int i = 0; i < count; i++) {
auto base = mod_model_->data(mod_model_->index(i, MDX.base)).toString().toStdWString();
if (UNONE::StrToHex64W(base) == modbase) {
return true;
}
}
mod_model_->setItem(count, MDX.name, item0);
mod_model_->setItem(count, MDX.base, item1);
mod_model_->setItem(count, MDX.size, item2);
mod_model_->setItem(count, MDX.path, item3);
auto info = CacheGetFileBaseInfo(modpath);
QStandardItem *name_item = new QStandardItem(LoadIcon(modpath), modname);
QStandardItem *base_item = new QStandardItem(WStrToQ(UNONE::StrFormatW(L"0x%llX", modbase)));
QStandardItem *size_item = new QStandardItem(WStrToQ(UNONE::StrFormatW(L"0x%llX", modsize)));
QStandardItem *path_item = new QStandardItem(modpath);
QStandardItem *desc_item = new QStandardItem(info.desc);
QStandardItem *ver_item = new QStandardItem(info.ver);
QStandardItem *corp_item = new QStandardItem(info.corp);
mod_model_->setItem(count, MDX.name, name_item);
mod_model_->setItem(count, MDX.base, base_item);
mod_model_->setItem(count, MDX.size, size_item);
mod_model_->setItem(count, MDX.path, path_item);
mod_model_->setItem(count, MDX.desc, desc_item);
mod_model_->setItem(count, MDX.ver, ver_item);
mod_model_->setItem(count, MDX.corp, corp_item);
return true;
});

auto view = ui.moduleView;
view->setColumnWidth(MDX.name, 180);
view->setColumnWidth(MDX.name, 150);
view->resizeColumnToContents(MDX.base);
view->resizeColumnToContents(MDX.size);
view->setColumnWidth(MDX.path, 180);
view->setColumnWidth(MDX.path, 425);
view->setColumnWidth(MDX.desc, 200);
}

void ProcessMgr::onProcSectionClicked(int idx)
Expand All @@ -446,15 +454,15 @@ void ProcessMgr::onProcSectionClicked(int idx)
switch (proc_header_idx_) {
case 3:
ui.processView->header()->setSortIndicator(-1, Qt::AscendingOrder);
ShowProcessTree();
ShowProcess();
proc_header_idx_ = 0;
break;
case 1:
ShowProcessList();
ShowProcess();
}
} else {
if (proc_header_idx_ == 0) {
ShowProcessList();
ShowProcess();
proc_header_idx_ = 1;
}
}
Expand Down Expand Up @@ -532,11 +540,18 @@ void ProcessMgr::ShowProperties(DWORD pid, int tab)
properties->show();
}

void ProcessMgr::ShowProcessList()
void ProcessMgr::ShowProcess()
{
DISABLE_RECOVER();
ClearItemModelData(proc_model_);
CacheRefreshProcInfo();
if (proc_header_idx_ == 0) ShowProcessTree();
else ShowProcessList();
AjustProcessStyle();
}

void ProcessMgr::ShowProcessList()
{
std::vector<ProcInfo> pis;
UNONE::PsEnumProcess([&pis](PROCESSENTRY32W& entry)->bool {
ProcInfo info;
Expand All @@ -553,11 +568,11 @@ void ProcessMgr::ShowProcessList()
AppendProcessItem(nullptr, name_item, pi, proc_model_->rowCount());
}

AjustProcessStyle();
}

void ProcessMgr::ShowProcessTree()
{
DISABLE_RECOVER();
ClearItemModelData(proc_model_);
CacheRefreshProcInfo();

Expand Down
2 changes: 1 addition & 1 deletion src/OpenArk/process-mgr/process-mgr.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ private slots:

private:
void ShowProperties(DWORD pid, int tab);

void ShowProcess();
void ShowProcessList();
void ShowProcessTree();
void AppendProcessItem(QStandardItem *parent, QStandardItem *name_item, ProcInfo info, int seq);
Expand Down

0 comments on commit 048255d

Please sign in to comment.