I tried to implement a solution of this question: Calling a function through its address in memory in c / c++, but I'm not very familiar with the differences in C and C++. When I try to implement the answer, my compiler throws a weird error message at me:
shellcode/findpattern.c: In function ‘shell_code’:
shellcode/findpattern.c:9:30: error: expected expression before ‘)’ token
memchr* memchr = (memchr*)0xdeadbeef;
^
shellcode/findpattern.c:10:30: error: expected expression before ‘)’ token
memcmp* memcmp = (memcmp*)0xdeadb00f;
^
Here is my code:
//#include "string.h"
#include "stdio.h"
//#include "stdlib.h"
typedef void* memchr(const void* , int , size_t );
typedef int memcmp(const void* , const void* , size_t );
void shell_code(){
memchr* memchr = (memchr*)0xdeadbeef;
memcmp* memcmp = (memcmp*)0xdeadb00f;
unsigned char *current = 0x00400000;
unsigned char *end = 0x015f1000;
int patternlength = 8;
unsigned char pattern[8] = "\x48\x08\x49\x8B\x48\x11\x8B\$
unsigned char *ret;
while(current < end){
ret = memchr(current, pattern[0], end-current);
if (ret != NULL){
if (memcmp(current, &pattern, patternlength) == 0$
return current + patternlength;
}
}
current = ret;
}
}
What am I missing here? As far as I understand this is just a cast, so why does the compiler throw an error here? Is this a C vs C++ thing that I'm unfamiliar with?