@@ -2068,24 +2068,45 @@ ProcInfos findMyProc(const char *procname, HANDLE hSnapshot) {
20682068}
20692069// 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.
20702070// Thanks!
2071+
2072+ std::vector<std::string> normalizeArgs (std::vector<std::string>& args) {
2073+ // flags could be -, --, or /. heck,
2074+ for i in args.size () {
2075+ if (args.[i].at (0 ) == " /" ) {
2076+ args[i].erase (0 , 1 ); } else {
2077+ if (args[i].at (0 ) == " -" ) {
2078+ if (args[i].at (1 ) == " -" ) // i could've done stats_with ("--") too but i feel like it takes more performance
2079+ // all this arg stuff probably steals milliseconds unfortunately
2080+ {
2081+ args[i].erase (0 , 2 );
2082+ } else {
2083+ args[i].erase (0 , 1 );
2084+ }
2085+ }
2086+ }
2087+
2088+
2089+ }
2090+
20712091
20722092
20732093int main (int argc, char * argv[]) {
20742094 SetConsoleOutputCP (CP_UTF8);
20752095 virtualTerminalEnabled = IsVirtualTerminalModeEnabled ();
20762096 std::vector<std::string> arguments (argv, argv + argc);
20772097 for (size_t i = 0 ; i < arguments.size (); ++i) {
2078- std::string arg = arguments[i];
2098+ std::vector<std::string> args = normalizeArgs (arguments);
2099+
20792100
20802101
2081- if (i == 0 && arguments .size () > 1 ) {
2102+ if (i == 0 && args .size () > 1 ) {
20822103 continue ;
20832104 }
20842105
20852106
20862107
20872108
2088- if (arguments .size () == 1 || arguments [1 ] == " - h" || arguments [1 ] == " -- help" ) {
2109+ if (args .size () == 1 || args [1 ] == " h" || args [1 ] == " help" ) {
20892110 if (!forkAuthor.empty ()) {
20902111 std::cout << " \n win-witr - Why is this running? Windows version by supervoidcoder. Fork by " << forkAuthor << std::endl;
20912112 } else {
@@ -2126,15 +2147,15 @@ int main(int argc, char* argv[]) {
21262147 }
21272148
21282149
2129- if (arg == " - v" || arg == " -- version" ) {
2150+ if (args[ 2 ] == " v" || args[ 2 ] == " version" ) {
21302151 std::cout << " \n win-witr " << version << std::endl;
21312152 return 0 ;
21322153 }
21332154
2134- if (arg == " -- pid" ) {
2135- if (i + 1 < arguments .size ()) {
2155+ if (args[ 2 ] == " pid" ) {
2156+ if (i + 1 < args .size ()) {
21362157
2137- std::string pidStr = arguments [i + 1 ]; // never increment the actual variable unless you're actually trying to find the next argument, otherwise
2158+ std::string pidStr = args [i + 1 ]; // never increment the actual variable unless you're actually trying to find the next argument, otherwise
21382159 // skipping arguments will happen and can crash if there is, in fact, no next argument.
21392160
21402161 int pid = 0 ;
@@ -2189,7 +2210,7 @@ int main(int argc, char* argv[]) {
21892210 return 0 ;
21902211 }
21912212 // check for process name if no recognized flags
2192- else if (arg[ 0 ] != ' - ' ) { // if it doesn't start with -- or -
2213+ else {
21932214 std::string procName = arg;
21942215 HANDLE hshot = CreateToolhelp32Snapshot (TH32CS_SNAPPROCESS, 0 );
21952216 if (INVALID_HANDLE_VALUE == hshot) {return 1 ;}
0 commit comments