voodoo programming

develop
Petr Mrázek 2009-10-26 03:14:34 +00:00
parent 2c5c1f3a32
commit 1ec85dd611
5 changed files with 38 additions and 23 deletions

@ -43,6 +43,12 @@ using namespace std;
#include <sys/types.h>
#include <sys/ptrace.h>
#include <dirent.h>
#define __USE_FILE_OFFSET64
#define _FILE_OFFSET_BITS 64
#include <unistd.h>
#include <sys/stat.h>
#include <fcntl.h>
#else
#define WINVER 0x0500 // OpenThread(), PSAPI, Toolhelp32
#define WIN32_LEAN_AND_MEAN

@ -92,7 +92,7 @@ bool Process::attach()
// HACK: Set the global process variables
g_pProcess = this;
g_ProcessHandle = my_handle;
g_ProcessMemFile = fopen(memFile.c_str(),"rb");
g_ProcessMemFile = open(memFile.c_str(),O_RDONLY);
return true; // we are attached
}
@ -105,8 +105,8 @@ bool Process::detach()
g_pProcess = NULL;
g_ProcessHandle = 0;
fclose(g_ProcessMemFile);// close /proc/PID/mem
g_ProcessMemFile = NULL;
close(g_ProcessMemFile);// close /proc/PID/mem
g_ProcessMemFile = -1;
return true;
}

@ -37,7 +37,7 @@ distribution.
/// HACK: global variables (only one process can be attached at the same time.)
Process * g_pProcess; ///< current process. non-NULL when picked
ProcessHandle g_ProcessHandle; ///< cache of handle to current process. used for speed reasons
FILE * g_ProcessMemFile; ///< opened /proc/PID/mem, valid when attached
int g_ProcessMemFile; ///< opened /proc/PID/mem, valid when attached
#ifdef LINUX_BUILD

@ -41,7 +41,7 @@ class Process;
*/
extern Process * g_pProcess; ///< current process. non-NULL when picked
extern ProcessHandle g_ProcessHandle; ///< cache of handle to current process. used for speed reasons
extern FILE * g_ProcessMemFile; ///< opened /proc/PID/mem, valid when attached
extern int g_ProcessMemFile; ///< opened /proc/PID/mem, valid when attached
class Process
{

@ -31,70 +31,79 @@ inline
uint8_t MreadByte (const uint32_t &offset)
{
uint8_t val;
fseek(g_ProcessMemFile, offset,SEEK_SET);
fread ( &val, sizeof(uint8_t), 1, g_ProcessMemFile );
//fseek(g_ProcessMemFile, offset,SEEK_SET);
//fread ( &val, sizeof(uint8_t), 1, g_ProcessMemFile );
pread(g_ProcessMemFile, &val,1,offset);
return val;
}
inline
void MreadByte (const uint32_t &offset, uint8_t &val )
{
fseek(g_ProcessMemFile, offset,SEEK_SET);
fread ( &val, sizeof(uint8_t), 1, g_ProcessMemFile );
//fseek(g_ProcessMemFile, offset,SEEK_SET);
//fread ( &val, sizeof(uint8_t), 1, g_ProcessMemFile );
pread(g_ProcessMemFile, &val,1,offset);
}
inline
uint16_t MreadWord (const uint32_t &offset)
{
uint16_t val;
fseek(g_ProcessMemFile, offset,SEEK_SET);
fread ( &val, sizeof(uint16_t), 1, g_ProcessMemFile );
//fseek(g_ProcessMemFile, offset,SEEK_SET);
//fread ( &val, sizeof(uint16_t), 1, g_ProcessMemFile );
pread(g_ProcessMemFile, &val,2,offset);
return val;
}
inline
void MreadWord (const uint32_t &offset, uint16_t &val)
{
fseek(g_ProcessMemFile, offset,SEEK_SET);
fread ( &val, sizeof(uint16_t), 1, g_ProcessMemFile );
//fseek(g_ProcessMemFile, offset,SEEK_SET);
//fread ( &val, sizeof(uint16_t), 1, g_ProcessMemFile );
pread(g_ProcessMemFile, &val,2,offset);
}
inline
uint32_t MreadDWord (const uint32_t &offset)
{
uint32_t val;
fseek(g_ProcessMemFile, offset,SEEK_SET);
fread ( &val, sizeof(uint32_t), 1, g_ProcessMemFile );
//fseek(g_ProcessMemFile, offset,SEEK_SET);
//fread ( &val, sizeof(uint32_t), 1, g_ProcessMemFile );
pread(g_ProcessMemFile, &val,4,offset);
return val;
}
inline
void MreadDWord (const uint32_t &offset, uint32_t &val)
{
fseek(g_ProcessMemFile, offset,SEEK_SET);
fread ( &val, sizeof(uint32_t), 1, g_ProcessMemFile );
//fseek(g_ProcessMemFile, offset,SEEK_SET);
//fread ( &val, sizeof(uint32_t), 1, g_ProcessMemFile );
pread(g_ProcessMemFile, &val,4,offset);
}
inline
uint64_t MreadQuad (const uint32_t &offset)
{
uint64_t val;
fseek(g_ProcessMemFile, offset,SEEK_SET);
fread ( &val, sizeof(uint32_t), 1, g_ProcessMemFile );
//fseek(g_ProcessMemFile, offset,SEEK_SET);
//fread ( &val, sizeof(uint32_t), 1, g_ProcessMemFile );
pread(g_ProcessMemFile, &val,8,offset);
return val;
}
inline
void MreadQuad (const uint32_t &offset, uint64_t &val)
{
fseek(g_ProcessMemFile, offset,SEEK_SET);
fread ( &val, sizeof(uint32_t), 1, g_ProcessMemFile );
//fseek(g_ProcessMemFile, offset,SEEK_SET);
//fread ( &val, sizeof(uint32_t), 1, g_ProcessMemFile );
pread(g_ProcessMemFile, &val,8,offset);
}
inline
void Mread (const uint32_t &offset, const uint32_t &size, uint8_t *target)
{
fseek(g_ProcessMemFile, offset,SEEK_SET);
fread ( target, 1, size, g_ProcessMemFile );
//fseek(g_ProcessMemFile, offset,SEEK_SET);
//fread ( target, 1, size, g_ProcessMemFile );
pread(g_ProcessMemFile, target,size,offset);
}
inline