Logo Search packages:      
Sourcecode: cafix version File versions  Download package

hack.c

#include "hack.h"
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <unistd.h>
#include <fcntl.h>


int a, caractere, match, found, file;
long size ;
char *buffer, *nom, *position, *position2, text[8], *occurence;
struct stat buf;
int main(int argc, char *argv[]){
    if(argc==1) {showhelp(); return 0;}
    if (strcmp(argv[1],"--help")==0 || strcmp(argv[1],"-h")==0) {showhelp(); return 0;}
    nom = argv[1];
    if ((file = open(argv[1], O_RDONLY)) < 0) { printf("file doesn't exist!\n"); return; }

    stat(nom, &buf);
    if (buf.st_size>150000) { perror("file is too big, not a backup..."); return 0;}
    printf("file is %li Bytes long\n", buf.st_size);
    buffer = (char*) malloc(buf.st_size);
    read(file, buffer, buf.st_size);

    for(a=0;a<8;a++){
    text[a]=getchar();
    if (text[a]=='\n') { text[a]='\0'; break; }
    }

    if (argv[1]=='\0') { printf("must provide a filename...\n"); return 0; }
    if (strlen(text)>7) { printf("filename is too big...\n"); return 0; }
    if (strlen(text)==0) { printf("must provide a name to lookup...\n"); return 0; }
    position=memchr(buffer, text[0], buf.st_size);
    if (position!=NULL && strlen(text)>1) {match=1; check();}
    if (position!=NULL && strlen(text)==1) {match=1; result();}
    if (match!=strlen(text)) {printf("The whole filename was not found, only the %d first characters\n", match); }
    manyresults();

}

void check(){

    for(a=1;a<strlen(text);a++) {
    if (*(position+a)==text[a]){
    match=match+1; }
    }
//    printf("matched: %d\n", match);
    if (match==strlen(text)) { result(); }

}

void result() {
//    printf("found @ %d in memory %c\n", position, *position);
    for(a=0;a<8;a++){
        if (*(position+a)!=-1){
                printf("%c\n",*(position+a));}
                }
    printf("\n");
    for(a=16;a<24;a++){
        if (*(position+a)!=-1){
                printf("%c",*(position+a)); }
                }
        printf("\n");
}

void manyresults() {
    position2=position;
    while(position!=NULL) {
//    printf("%d %d\n", position, buf.st_size-(position-buffer));
    occurence=position+7;
    size=buf.st_size-(position-buffer);
    position=memchr(occurence, text[0], size);
//    printf("%d %d\n", position, position2);
    if (position==position2) { printf("no more occurence of searched string!\n"); return;}
    if (position==NULL) {return;}
    match=1;
    check();
    }

}


void showhelp() {
        system("clear");
        printf("  Cafix password hacker :) \n\n");
        printf("  Usage: hack [Backup file name]\n\n");
        printf("   You just need to provide a backup, run this prog entering the casio\n");
        printf("   filename (or the first caracters) and it'll search the backup for this\n");
        printf("   string and will return the corresponding password\n\n");
}

Generated by  Doxygen 1.6.0   Back to index