I wanted to make a program to help me find the locations of some double valuse in current process memory.
I found some code snippets to study, but Im failing at the first hurdle.
First let me be clear that I am not the author of the below code, but I am free to use it, as per the authors consent.
My goal was to see how it works, the problem is, my compiler (VS2010) tells me this.
Void* __cdecl malloc(size_t _Size)
Error: a value of type "void*" cannot be used to initialize an entity of of type "MEMBLOCK*"
But when I look at the reference to malloc, I see it defined as "void * malloc ( size_t size );", thats void right? malloc reference
I'd sure appreciate it if someone has the time, knowhow, and inclination to point out my misassumptions.
#include <windows.h>
#include <stdio.h>
#include "StdAfx.h"
#define IS_IN_SEARCH(mb,offset) (mb->searchmask[(offset)/8] & (1<<((offset)%8)))
#define REMOVE_FROM_SEARCH(mb,offset) mb->searchmask[(offset)/8] &= ~(1<<((offset)%8));
typedef struct _MEMBLOCK
{
HANDLE hProc;
unsigned char *addr;
int size;
unsigned char *buffer;
unsigned char *searchmask;
int matches;
int data_size;
struct _MEMBLOCK *next;
} MEMBLOCK;
typedef enum
{
COND_UNCONDITIONAL,
COND_EQUALS,
COND_INCREASED,
COND_DECREASED,
} SEARCH_CONDITION;
MEMBLOCK* create_memblock (HANDLE hProc, MEMORY_BASIC_INFORMATION *meminfo, int data_size)
{
MEMBLOCK *mb = malloc (sizeof(MEMBLOCK)); // error here with malloc
if (mb)
{
mb->hProc = hProc;
mb->addr = meminfo->BaseAddress;
mb->size = meminfo->RegionSize;
mb->buffer = malloc (meminfo->RegionSize);
mb->searchmask = malloc (meminfo->RegionSize/8);
memset (mb->searchmask, 0xff, meminfo->RegionSize/8);
mb->matches = meminfo->RegionSize;
mb->data_size = data_size;
mb->next = NULL;
}
return mb;
}