Results 1 to 5 of 5
  1. #1
    Void's Avatar
    Join Date
    Sep 2009
    Gender
    male
    Location
    Inline.
    Posts
    3,198
    Reputation
    205
    Thanks
    1,445
    My Mood
    Mellow

    Scanning strings.

    Hello.

    This might be a pretty choob-ish thread, but I can't figure this out. What I'm trying to do it scan a directory of all it's files, then scan each file for a string. I've got the directory/file part down. The part I'm having troubles with is breaking at each character and comparing the strings.

    This is what I've got so far:
    [PHP]
    #include <windows.h>
    #include <iostream>
    #include <string>

    using namespace std;

    char* DirectoryPath = "C:\\Documents and Settings\\David\\My Documents\\TestFolder";
    char* Search = "david";

    int main()
    {
    FILE* File;
    string FileList[MAX_PATH];
    int num = 0;

    WIN32_FIND_DATA FileData;
    char Path[MAX_PATH];
    sprintf(Path,"%s\\*",DirectoryPath);

    HANDLE FoundFile = FindFirstFile(Path,&FileData);
    if(FoundFile != INVALID_HANDLE_VALUE)
    {
    do{
    if(!(FileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY))
    {
    FileList[num] = FileData.cFileName;
    num++;
    }
    }while(FindNextFile(FoundFile,&FileData));
    }

    for(int i=0;i<num;i++){
    string CurrentLine;
    static char FilePath[MAX_PATH];
    sprintf(FilePath,"%s\\%s",DirectoryPath,FileList[i].c_str());
    File = fopen(FilePath,"rb");
    if(!File){ cout <<"File could not be open."; cin.get(); return 0; }
    fseek(File,0,SEEK_END);
    long Size = ftell(File);
    rewind(File);

    char* Buffer;
    Buffer = (char*)malloc(Size);
    fread(Buffer,1,Size,File);
    char* Ptr = strpbrk(Buffer,Search);
    do
    {
    char temp[MAX_PATH] = {0};
    for(int i=0;i<strlen(Search);i++)
    {
    temp[i] = *(Ptr+i);
    }
    if(strcmp(temp,Search)==0)
    {
    cout << "String found in: "<< FilePath <<"\n\n";
    } else {
    Ptr = strpbrk(Ptr+1,Search[0]);
    }
    }while(Ptr != NULL);
    fclose(File);
    }
    cin.get();
    }
    [/PHP]

    Right now, it will only output "String found in: this file" if the first occurance of the character is the correct one. For example. I have this in a text file:
    Code:
    dddddd david
    And I search "david" using my method, it will break at the first 'd', check if the preceding 4 letters are 'avid' and if it isn't. It just stops. I don't know how to keep reading from where it stops. As you can see I've tried breaking starting from where the first character starts +1, so that it skips the character it broke at earlier. It doesn't seem to work.

    Yeah.. if any of you has an easier way to scan strings or buffers, let me know. This method seems a little over complicated.

    Thanks.

  2. #2
    why06's Avatar
    Join Date
    Jul 2009
    Gender
    male
    Location
    IBM
    Posts
    4,304
    Reputation
    170
    Thanks
    2,203
    My Mood
    Flirty
    Not a very in-depth solution, but I would use strcmp instead. strpbrk really isn't helping you at all. Just iterate through the file string and when str1[0] = str2[0] start keep going through so that once you finish looping through all chars and they're all the same you return the file handle or whatever.

    "Every gun that is made, every warship launched, every rocket fired signifies, in the final sense, a theft from those who hunger and are not fed, those who are cold and are not clothed. This world in arms is not spending money alone. It is spending the sweat of its laborers, the genius of its scientists, the hopes of its children. The cost of one modern heavy bomber is this: a modern brick school in more than 30 cities. It is two electric power plants, each serving a town of 60,000 population. It is two fine, fully equipped hospitals. It is some fifty miles of concrete pavement. We pay for a single fighter plane with a half million bushels of wheat. We pay for a single destroyer with new homes that could have housed more than 8,000 people. This is, I repeat, the best way of life to be found on the road the world has been taking. This is not a way of life at all, in any true sense. Under the cloud of threatening war, it is humanity hanging from a cross of iron."
    - Dwight D. Eisenhower

  3. #3
    Retoxified's Avatar
    Join Date
    Feb 2010
    Gender
    male
    Posts
    148
    Reputation
    8
    Thanks
    171
    Anyone thought of strstr?
    StrStr Function (Windows)

    Just read in line by line, use strstr and check if the return is not NULL(which means string was found) and either use break to get out of the scanloop or let it continue to find multiple occurances.

    With that you can go as detailed as line number and character offset from the start of the string

  4. The Following 2 Users Say Thank You to Retoxified For This Useful Post:

    Void (04-04-2010),why06 (04-04-2010)

  5. #4
    why06's Avatar
    Join Date
    Jul 2009
    Gender
    male
    Location
    IBM
    Posts
    4,304
    Reputation
    170
    Thanks
    2,203
    My Mood
    Flirty
    Well that sure makes life easier. =/

    "Every gun that is made, every warship launched, every rocket fired signifies, in the final sense, a theft from those who hunger and are not fed, those who are cold and are not clothed. This world in arms is not spending money alone. It is spending the sweat of its laborers, the genius of its scientists, the hopes of its children. The cost of one modern heavy bomber is this: a modern brick school in more than 30 cities. It is two electric power plants, each serving a town of 60,000 population. It is two fine, fully equipped hospitals. It is some fifty miles of concrete pavement. We pay for a single fighter plane with a half million bushels of wheat. We pay for a single destroyer with new homes that could have housed more than 8,000 people. This is, I repeat, the best way of life to be found on the road the world has been taking. This is not a way of life at all, in any true sense. Under the cloud of threatening war, it is humanity hanging from a cross of iron."
    - Dwight D. Eisenhower

  6. #5
    Void's Avatar
    Join Date
    Sep 2009
    Gender
    male
    Location
    Inline.
    Posts
    3,198
    Reputation
    205
    Thanks
    1,445
    My Mood
    Mellow
    Didn't know that existed.

Similar Threads

  1. File Scan here
    By Neogaidenx in forum Spammers Corner
    Replies: 4
    Last Post: 08-14-2008, 11:30 AM
  2. Scan Site?
    By Hispiforce in forum WarRock - International Hacks
    Replies: 5
    Last Post: 06-02-2007, 05:30 PM
  3. k2 scan
    By Jeckels in forum WarRock - International Hacks
    Replies: 6
    Last Post: 05-30-2007, 07:26 PM
  4. String Theory
    By arunforce in forum General
    Replies: 8
    Last Post: 01-14-2007, 09:49 AM
  5. CE SCANS TAKING 4ever
    By A7X Oblivian in forum WarRock - International Hacks
    Replies: 3
    Last Post: 06-03-2006, 07:45 AM