trying to use system commands?

Hey,

I am trying to make a brute force password cracker for an old zip file. (unzipping with PKUNZIP ver 1.1....its really old) I can already put together the code to try every possible letter and number combination.

I think I can make the system call to PKUNZIP well enough. But here are my questions:

First, since PKUNZIP is not actually part of system, but rather a stand alone program controlled at the command line, is system even the way to call it? DO you have to include pkunzip.exe somehow in the code? That is, how do I reference it?

Second, how do I deal with output coming back at the command line....Most of the time I am guessing that the output will be a string saying that the password is incorrect. Hopefully, eventually, the right password will be hit on and the output should be an unpacked file (or files). Or would the output just be a string that lists the files that were output? I am confused on this point.

Basically, I am looking for some pointers in the right direction or even better a code sample where someone makes command line calls to some program and deals with this sort of issue. Thanks.
mw
closed account (1yR4jE8b)
I've never really had to use the system() function, but I do know that int returns an integer which is the exit code of the program. So, assuming pkunzip returns 0 when it completes succesfully then you'll just need to store the exit code and exit the loop when the stored value is 0.
That makes sense. I will give that a try. THanks.
mw
You can also include redirections in the system() command:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include <cstdlib>
#include <iostream>
using namespace std;

int main()
  {
  if (system( "dir /ad/on/b > dir.txt 2> nul" ) == 0)
    {
    cout << "Yeah! The file \"dir.txt\" now contains the subdirectories in this directory.\n";
    }
  else
    {
    cout << "Fooey! Something went wrong.\n";
    }
  return 0;
  }

The "> dir.txt" puts standard output in the file "dir.txt".
The "2> nul" puts standard error in the special file "nul", which makes things disappear.
You can change either as you prefer.

Hope this helps.
Last edited on
closed account (1yR4jE8b)
If you are in windows, than redirecting to nul is ok but in *nix it should be /dev/null, just saying
About system

The system function is basically a function to call a Batch command or a cmd command or a command line command or whatever you want to call it with in the %windir%\system32 (C:\windows\system32\) I only know how to do this in windows.
If you included iostream, int main, return 0, ect. you could pretty much make a whole batch file with in c++ using the system ("command") function line after line. the system function is very slow because it has to (i think) send info from your program to windows to tell the os to call the command and call it back to your prog. Some one tell me if i am wrong about any of this. Um also I dont know what punkzip is, but if you put the exe (If it is a exe) into system32 and modify its name to something shorter say:
pnkzip or even PUNKZIP and not PUNKZIP ver 1.1 (so it will be easier to call) you can call it by
putting system ("pnkzip"); because if i remember right, the second you put the exe into sys32 it will become a bat file command. I just tested it. but it may not run right with only its exe and not its dlls. And It is going to take longer as in, The system command has to do its thing and call it. But then the program also has to open. also with what you are trying to do...
as far as i know system will only open it, it wont do any thing else



only works in windows
Last edited on
it's (pk)unzip it's a zip program much like winzip, 7zip, unzip.


I usually do this for my .bashrc in Linux, this way it doesn't matter what kind of archive it is, I just type extract file

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# Extract Program.
function extract()      
{
     if [ -f $1 ] ; then
         case $1 in
             *.tar.bz2)   tar xvjf $1     ;;
             *.tar.gz)    tar xvzf $1     ;;
             *.bz2)       bunzip2 $1      ;;
             *.rar)       unrar x $1      ;;
             *.gz)        gunzip $1       ;;
             *.tar)       tar xvf $1      ;;
             *.tbz2)      tar xvjf $1     ;;
             *.tgz)       tar xvzf $1     ;;
             *.zip)       unzip $1        ;;
             *.Z)         uncompress $1   ;;
             *.7z)        7z x $1         ;;
             *)           echo "'$1' cannot be extracted via >extract<" ;;
         esac
     else
         echo "'$1' is not a valid file"
     fi
}
Last edited on
Topic archived. No new replies allowed.