my problem is the following. I have 2 functions, one that calls WriteProcessMemory and returns it's result and another that sends the buffer to the first one.
If i send a static variable as the buffer from the 2nd to the 1st no problem, but vice-versa it crashes.
Here's the source for the 1st:
void WriteMem(LPVOID addr, LPCVOID *buffer,size_t size){
int i = WriteProcessMemory(hProc, addr, buffer, size, NULL);
if(i)
printf("Success\n");
else
printf("Fail\n");
}
Source for the 2nd:
Segmentation fault:
void EditCards(BYTE victim){
BYTE cardsDrawn = 23;
puts("Choose the cards:");
scanf("%hhu",&cardsDrawn);
if(cardsDrawn > 40)
cardsDrawn = 40;
cardsDrawn = 40 - cardsDrawn;//If the enemy has 5 cards then 45 have been drawn :P
WriteMem( victim ? Y_ENEMY_CARDS : Y_PLAYER_CARDS, &cardsDrawn, sizeof(BYTE));
}
Works fine:
void EditCards(BYTE victim){
static BYTE cardsDrawn = 23;
puts("Choose the cards:");
scanf("%hhu",&cardsDrawn);
if(cardsDrawn > 40)
cardsDrawn = 40;
cardsDrawn = 40 - cardsDrawn;//If the enemy has 5 cards then 45 have been drawn :P
WriteMem( victim ? Y_ENEMY_CARDS : Y_PLAYER_CARDS, &cardsDrawn, sizeof(BYTE));
}
The space alocated for cardsDrawn
afaik is still allocated when passed to next WriteMem
why fail?
EDIT:
No i'm editing the memory of another process. If you want to know it's ePSXe.exe
hProc is a global variable
assigned in the main function. It's an handle for the process i'm editing its memory.
Here's what is requested:
#define Y_PLAYER_CARDS ((LPVOID)0x0B76510)
#define Y_ENEMY_CARDS (LPVOID)(Y_PLAYER_CARDS + 0x20)