why06 (01-28-2010)
Well here is a simple memory patcher, takes a block of memory and searches for a string pattern that you pass and applies a patch to it, super simple.
Hope this helps people learning C++ in any way!Code://Give a memory string 'search' of size 'len' to find in a memory block //of'look_size' starting at addr 'begin' returns the beggining of the memory //of the found memory or null on fail void *ELFindMemory( void *begin, unsigned int look_size, unsigned char *search, unsigned int len ) { if begin == NULL || look_size == 0 || search == NULL || len == 0 ) return NULL; //begin search bool isFound = false; for( unsigned int i = 0; i < look_size; i++ ) { if( *(unsigned char *)(begin + i ) == search[0] ) { for( unsigned int j = 1; j < len; j++ ) { if( *(unsigned char *)(begin + i + j ) == search[j] ) isFound = true; else isFound = false; } } if( isFound == true ) return (void *)( begin + i ); } return NULL; } //Takes the found addr 'memory' and writes the 'patch' of length 'patch_len' with a filler if the //patch is less then the original memory contents 'filler' int ELPatchMemory( void *memory, int orig_size, unsigned char *patch, int patch_len, unsigned char filler ) { if( puid == 0 || memory == NULL || orig_size == 0 || patch == NULL || patch_len == 0 ) return -1; if( orig_size < patch_size ) return -10; for( unsigned int i = 0; i < patch_len ) { *(unsigned char *)( memory + i ) = *(unsigned char *)(patch + i ); } if( orig_size > patch_len ) { orig_size -= patch_len; for( unsigned int i = 0; i < orig_size; i++ ) { *(unsigned char *)( memory + patch_len + i + 1 ) = filler; } } return 0; }
why06 (01-28-2010)
Very nice!
The patch memory function reminds me exactly of WriteProcessMemory(), and good error checking by the way. There were a few syntax errors, in other words, you can't just stick this into a compiler w/o getting a few errors.
This part is missing an incrementor. Unless ofcourse the incrementor is implied, I dunno all the shortcuts for for loops.Code:for( unsigned int i = 0; i < patch_len ) { *(unsigned char *)( memory + i ) = *(unsigned char *)(patch + i ); }
But there was something important... oh yeh!
Your memory searcher only checks the first and last character, and the length. Which might work, but what if you run into something like "dop" when u were lookin for "dip"?
Oh and filler needs to be assigned a value. perhaps NOP 0x90?
Someone correct me about anything if Im mistaken, but I assume *(unsigned char*) meant the value of a char*....
"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
the incrementer is implied for this source code. thanks for the comments
why06 (01-28-2010)
I is never incremented, so thats pretty much an infinite loopOriginally Posted by Justin
Ah we-a blaze the fyah, make it bun dem!
"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