/*****************************************************************
 *                                                               *
 * PIRPASS.C by EXE-Gency                                        *
 * A program to search the current directory for the any pirch   *
 * passwords. (Pirch is a program that can be used for accessing *
 * IRC.) Password is normally stored in PIRCH98.INI but PIRPASS  *
 * supports wildcards to you can use GETPIRCH *.INI as well as   *
 * GETPIRCH PIRCH98.INI. The decryption algorithm is taken from  *
 * a file by Daemon0/Underground Periodical.                     *
 *                                                               *
 * If you want to compile the source code yourself you'll need a *
 * copy of DJGPP:                                                *
 *                                                               *
 * GCC -O PIRPASS.EXE PIRPASS.C                                  *
 *                                                               *
 *****************************************************************/

#include "stdio.h"
#include "dir.h"
#include "string.h"
#include "process.h"

int main(int Argc, char *Argv[]) {
    FILE         *PasswordFile;
    struct ffblk FileSearch;
    unsigned int SearchResult, SearchCount;
    char         String[100], *Ptr;

    if(Argc!=2) {
        printf("PIRPASS v1.0 by EXE-Gency\n");
        printf("Syntax: PIRPASS [filename]\n");
        printf("E.G:    PIRPASS PIRCH98.INI\n");
        exit(1);
    }

    printf("PIRPASS v1.0 by EXE-Gency. Program to get pirch password.\n");

    SearchCount=0;

    SearchResult=findfirst(Argv[1], &FileSearch, 0);
    while(!SearchResult) {
        SearchCount++;
        if((PasswordFile=fopen(FileSearch.ff_name, "r"))==NULL) {
            printf("Cannot open file [%s] for reading!\n", FileSearch.ff_name);
        } else {
            while(!feof(PasswordFile)) {
                fgets(String, 99, PasswordFile);
                Ptr=strstr(String, "Pw=");
                if(Ptr) {
                    Ptr+=3;
                    printf("Found password [");
                    while(*Ptr!=10) {
                        printf("%c", (*Ptr)-127);
                        Ptr++;
                    }
                    printf("] in file [%s]\n", FileSearch.ff_name);
                }
            }
            fclose(PasswordFile);
        }
        SearchResult=findnext(&FileSearch);
    }
    printf("Finished! %u files scanned.", SearchCount);
    return 0;
}
