View Single Post
  #1  
Old 05-19-2014, 06:32
mr.exodia mr.exodia is offline
Retired Moderator
 
Join Date: Nov 2011
Posts: 783
Rept. Given: 490
Rept. Rcvd 1,123 Times in 305 Posts
Thanks Given: 89
Thanks Rcvd at 716 Times in 333 Posts
mr.exodia Reputation: 1100-1299 mr.exodia Reputation: 1100-1299 mr.exodia Reputation: 1100-1299 mr.exodia Reputation: 1100-1299 mr.exodia Reputation: 1100-1299 mr.exodia Reputation: 1100-1299 mr.exodia Reputation: 1100-1299 mr.exodia Reputation: 1100-1299 mr.exodia Reputation: 1100-1299
mudlord asked me to update this to include a pattern search & replace engine.

Example of full usage:
Code:
#include "patternfind.h"

int main(int argc, char* argv[])
{
    unsigned char data[0x100];
    memcpy(data, main, sizeof(data));

    //find pattern offset
    size_t found = patternfind(data, sizeof(data), "68 ?? ?1 0? 00");

    printf("found: main+%p\n", found);
    if(found==-1) //not found
        return 0;

    //print current data
    for(int i=0; i<5; i++)
        printf("%.2X ", data[found+i]);
    puts("");

    //search & replace
    if(!patternsnr(data, sizeof(data), "68 ?? ?1 0? 00", "?? ?1 1? 21 23"))
        return 0; //search & replace failed

    //print replaced data
    for(int i=0; i<5; i++)
        printf("%.2X ", data[found+i]);
    puts("");

    return 0;
}
Prints:
Code:
found: main+00000026
68 00 01 00 00
68 01 11 21 23
New patternfind.cpp attached.

Greetings,

Mr. eXoDia

Last edited by mr.exodia; 10-28-2015 at 09:13.
Reply With Quote
The Following 11 Users Gave Reputation+1 to mr.exodia For This Useful Post:
besoeso (05-19-2014), bilbo (05-26-2014), chessgod101 (05-19-2014), Computer_Angel (05-19-2014), Dreamer (05-19-2014), Git (05-19-2014), Insid3Code (05-20-2014), nikkapedd (05-24-2014), nulli (05-27-2014), ontryit (05-19-2014), zeuscane (05-19-2014)