Skip to content

Instantly share code, notes, and snippets.

@kirbyUK

kirbyUK/hints.c Secret

Created September 9, 2016 18:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kirbyUK/9d7d85bfa695cce84c5a620b2a623e3e to your computer and use it in GitHub Desktop.
Save kirbyUK/9d7d85bfa695cce84c5a620b2a623e3e to your computer and use it in GitHub Desktop.
Extracts loading hints from a running Shrek SuperSlam process
#include <Windows.h>
#include <stdio.h>
#include <stdlib.h>
const LPCTSTR WINDOW_NAME = "Shrek SuperSlam";
const unsigned char* START_ADDRESS = 0x0A6725A0;
const unsigned char* END_ADDRESS = 0x0A674D00;
struct Hint {
char name[16];
char garbage[16];
char hint[128];
};
DWORD GetPid()
{
HWND hwnd = FindWindowA(NULL, WINDOW_NAME);
DWORD pid = 0;
GetWindowThreadProcessId(hwnd, &pid);
return pid;
}
HANDLE GetHandle(DWORD pid)
{
return OpenProcess(
PROCESS_VM_READ,
FALSE,
pid
);
}
struct Hint* ReadHint(HANDLE handle, unsigned char** addr)
{
int len = 0;
struct Hint* hint = (struct Hint*)malloc(sizeof(struct Hint));
char buffer[16] = {
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
};
if (ReadProcessMemory(handle, (LPVOID)*addr, hint->name, 16, 0) == FALSE)
{
free(hint);
printf("Error reading memory!\n");
return NULL;
}
*addr += 16;
if (ReadProcessMemory(handle, (LPVOID)*addr, hint->garbage, 16, 0) == FALSE)
{
free(hint);
printf("Error reading memory!\n");
return NULL;
}
*addr += 16;
while (buffer[15] != 0x00)
{
if (ReadProcessMemory(handle, (LPVOID)*addr, buffer, 16, 0) == FALSE)
{
free(hint);
printf("Error reading memory!\n");
return NULL;
}
for (int i = 0; i < 16; i++)
hint->hint[i + len] = buffer[i];
*addr += 16;
len += 16;
}
return hint;
}
int main()
{
DWORD pid = GetPid();
if (pid == NULL)
{
printf("Couldn't get PID!\n");
return 1;
}
HANDLE handle = GetHandle(pid);
if ((handle == INVALID_HANDLE_VALUE) || (handle == NULL))
{
printf("Couldn't get handle!\n");
return 1;
}
for (unsigned char* addr = START_ADDRESS; addr < END_ADDRESS; addr)
{
struct Hint* hint = ReadHint(handle, &addr);
if (hint == NULL)
return 1;
printf("%s: %s\n", hint->name, hint->hint);
free(hint);
}
CloseHandle(handle);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment