Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: cl.exe build active file",
"label": "Build win-witr.exe",
"command": "cl.exe",
"args": [
"/Zi",
"/O2",
"/std:c++20",
"/EHsc",
"/nologo",
"/std:c++20",
"/Fe${fileDirname}\\${fileBasenameNoExtension}.exe",
"${file}"
"main.cpp",
"/DUNICODE",
"/D_UNICODE",
"/Fe:win-witr.exe"
],
"options": {
"cwd": "${fileDirname}"
Expand Down
80 changes: 64 additions & 16 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,10 @@ std::unordered_map<int, std::string> errorHints = {

};

struct Statuses {
bool verbose;
// will probably add more later
};

bool EnableDebugPrivilege() {
HANDLE hToken;
Expand Down Expand Up @@ -1745,7 +1749,8 @@ void FindProcessPorts(DWORD targetPid) {



void PIDinspect(const std::vector<DWORD>& pids, const std::vector<std::string>& names, HANDLE hshot) { // ooh guys look i'm in the void
void PIDinspect(const std::vector<DWORD>& pids, const std::vector<std::string>& names, HANDLE hshot, Statuses stats, int related ) {
//^^^ ooh guys look i'm in the void
DWORD pid = pids[0];
std::unordered_map<DWORD, PROCESSENTRY32> pidMap;
PROCESSENTRY32 pe32{};
Expand Down Expand Up @@ -2067,23 +2072,48 @@ ProcInfos findMyProc(const char *procname, HANDLE hSnapshot) {
}
// The above function is taken from https://cocomelonc.github.io/pentest/2021/09/29/findmyprocess.html, modified simply to use WideToString for the process name comparison among other things.
// Thanks!


std::vector<std::string> normalizeArgs(std::vector<std::string>& args) {
// this function can seem a little obfuscated so let me help
for (size_t i = 0; i < args.size(); i++) {
if (args[i].at(0) == '/') { // if it starts with a /
args[i].at(0) = '-'; // then set it to - to normalize the argument, so /help turns into -help
} else if (args[i].at(0) == '-') { // if it starts with a -
if (args[i].at(1) == '-') { // then check if the person put another - like --help
args[i].erase(0, 1); // if so then delete first char and it turns into -help
} else {
// do nothing
}
}
}
return args;
}

bool contains(const std::vector<std::string>& v, const std::string& value) {
return std::find(v.begin(), v.end(), value) != v.end();
}
// contains function that checks if the stringy vector contains the thing its self explanatory

int main(int argc, char* argv[]) {
SetConsoleOutputCP(CP_UTF8);
virtualTerminalEnabled = IsVirtualTerminalModeEnabled();
for (int i = 0; i < argc; ++i) {
std::string arg = argv[i];
std::vector<std::string> arguments(argv, argv + argc);
Statuses s;

s.verbose = false; // for now this don't do anything
for (size_t i = 0; i < arguments.size(); ++i) {
std::vector<std::string> args = normalizeArgs(arguments);



if (i == 0 && argc > 1) {
if (i == 0 && args.size() > 1) {
continue;
}




if (argc == 1 || std::string(argv[1]) == "-h" || std::string(argv[1]) == "--help") {
if (args.size() == 1 || args[1] == "-h" || args[1] == "-help") {
if (!forkAuthor.empty()) {
std::cout << "\nwin-witr - Why is this running? Windows version by supervoidcoder. Fork by " << forkAuthor << std::endl;
} else {
Expand Down Expand Up @@ -2123,16 +2153,24 @@ int main(int argc, char* argv[]) {
return 0; // exit after printing help because it might try to process -help as a process name otherwise
}


if (arg == "-v" || arg == "--version") {
// at this point, if help exists but is not the first argument we can assume the user is asking about a specific flag
bool help = contains(args, "-help");

if (args[1] == "-v" || args[1] == "-version") {
if (!help) {
std::cout << "\nwin-witr " << version << std::endl;
} else {
std::cout << "Shows the version number of win-witr. If it says \"dev-build\", it means you compiled it yourself without a version number compiler environment variable.\n";

}
return 0;
}

if (arg == "--pid") {
if (i + 1 < argc) {
if (args[1] == "-pid") {
if (!help) {
if (i + 1 < args.size()) {

std::string pidStr = argv[i + 1]; // never increment the actual variable unless you're actually trying to find the next argument, otherwise
std::string pidStr = args[i + 1]; // never increment the actual variable unless you're actually trying to find the next argument, otherwise
// skipping arguments will happen and can crash if there is, in fact, no next argument.

int pid = 0;
Expand Down Expand Up @@ -2170,7 +2208,8 @@ int main(int argc, char* argv[]) {

HANDLE hshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
if (INVALID_HANDLE_VALUE == hshot) {return 1;}
PIDinspect(pids, trash, hshot);

PIDinspect(pids, trash, hshot, s, 0);
CloseHandle(hshot);
} else {
if (virtualTerminalEnabled) { // ugh i have to do this EVERY SINGLE TIME
Expand All @@ -2185,16 +2224,21 @@ int main(int argc, char* argv[]) {
return 1;
}
return 0;
}
}
else {
std::cout << "Looks up a specific process based on the Process ID (PID) and returns information such as RAM usage, process ancestry, listening ports, and more.\n";

}}
// check for process name if no recognized flags
else if (arg[0] != '-') { // if it doesn't start with -- or -
std::string procName = arg;
else {
if (!help) {
std::string procName = args[1];
HANDLE hshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
if (INVALID_HANDLE_VALUE == hshot) {return 1;}
ProcInfos r = findMyProc(procName.c_str(), hshot);
if (!r.pids.empty()) {
std::vector<DWORD> dwPids(r.pids.begin(), r.pids.end());
PIDinspect(dwPids, r.names, hshot);
PIDinspect(dwPids, r.names, hshot, s, 0);
CloseHandle(hshot);
} else {
if (virtualTerminalEnabled) {
Expand All @@ -2204,6 +2248,10 @@ int main(int argc, char* argv[]) {
}
}
}
} else {
std::cout << "Looks up a process based on the name. The search is case-insensitive, and you do not need to type the .exe extension. If there are multiple processes with similar names, it will show them to you under \"Related Processes\" along with their PIDs so you can manually search up each one using the --pid flag.\n";

}
}
return 0;

Expand Down
Loading