Skip to content

Instantly share code, notes, and snippets.

@ryancole
Created June 17, 2012 02:12
Show Gist options
  • Select an option

  • Save ryancole/2943157 to your computer and use it in GitHub Desktop.

Select an option

Save ryancole/2943157 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <Windows.h>
#include "Utilities.h"
#include "MemoryManager.h"
namespace Aspects_Managers {
MemoryManager::MemoryManager() {
/* stub, idk */
}
// initialize the memory manager, enabling debug privileges
MemoryManager::MemoryManager(DWORD diabloProcessId) {
// set diablo process id
m_diabloProcessId = diabloProcessId;
// get diablo process handle
m_diabloProcessHandle = OpenProcess(PROCESS_ALL_ACCESS, FALSE, m_diabloProcessId);
// get diablo access handle
OpenProcessToken(m_diabloProcessHandle, TOKEN_ADJUST_PRIVILEGES, &m_diabloAccessHandle);
// enable debug priv
if (!EnableDebugPrivileges())
printf("Failed to enable debug privileges.");
}
MemoryManager::~MemoryManager() {
CloseHandle(m_diabloProcessHandle);
}
// read the players location from diablo
bool MemoryManager::GetCurrentLocation(LPVOID buffer) {
if (ReadProcessMemory(m_diabloProcessHandle, (LPCVOID)D3_CURRENT_LOCATION, buffer, D3_CURRENT_LOCATION_LENGTH, NULL) > 0)
return true;
PrintError(GetLastError());
return false;
}
// enable debug privileges on the diablo process
bool MemoryManager::EnableDebugPrivileges() {
LUID luid;
TOKEN_PRIVILEGES tp;
if (!LookupPrivilegeValue(NULL, L"SeDebugPrivilege", &luid))
return false;
tp.PrivilegeCount = 1;
tp.Privileges[0].Luid = luid;
tp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
if (!AdjustTokenPrivileges(m_diabloAccessHandle, FALSE, &tp, sizeof(TOKEN_PRIVILEGES), (PTOKEN_PRIVILEGES) NULL, (PDWORD)NULL))
return false;
return true;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment