Jump to content
Tuts 4 You

[C++] PatternFind (Pattern Find + Search & Replace)


mrexodia

Recommended Posts

Posted

Hello everyone,

For x64_dbg I had to create a pattern finder and mudlord asked me to extend it with a pattern search & replace ability.

Example of usage:

#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;}
Output:
found: main+0000002668 00 01 00 0068 01 11 21 23
Feel free to use it wherever you like, credit (link to http://x64dbg.com) is appreciated, but not required.

Attached the full source (only ~150 lines)

Greetings,

Mr. eXoDia

PatternFindUpdate.rar

  • Like 7
  • 5 weeks later...
newbie_newbe
Posted (edited)

Mr. eXoDia


How to compile this source code, sory newbie.


Edited by newbie_newbe
Posted

@newbie_newbe: just add the .cpp and .h file to your coding project and include the .h file.

This is not useful if you want some GUI or anything, just for coding projects that require a pattern searcher.

Greetings

newbie_newbe
Posted

Ooooh..... Ok Thank you


  • 1 month later...
  • 1 month later...
Posted (edited)

thanks, it's nicer than the code i use.  i wrote a little tool that uses BeaEngine to hook anywhere in code, and i use a few different pattern matching algorithms to find my hook targets.


Edited by electroglyph

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...