Remove duplicate code implementing readInt.

Implement one version in terms of the other.
develop
Tom Prince 2011-02-23 01:50:21 -05:00
parent 9964dbac72
commit 9b854be327
7 changed files with 43 additions and 256 deletions

@ -627,16 +627,6 @@ void SHMProcess::read (uint32_t src_address, uint32_t size, uint8_t *target_buff
} }
} }
uint8_t SHMProcess::readByte (const uint32_t offset)
{
if(!d->locked) throw Error::MemoryAccessDenied();
D_SHMHDR->address = offset;
gcc_barrier
d->SetAndWait(CORE_READ_BYTE);
return D_SHMHDR->value;
}
void SHMProcess::readByte (const uint32_t offset, uint8_t &val ) void SHMProcess::readByte (const uint32_t offset, uint8_t &val )
{ {
if(!d->locked) throw Error::MemoryAccessDenied(); if(!d->locked) throw Error::MemoryAccessDenied();
@ -647,16 +637,6 @@ void SHMProcess::readByte (const uint32_t offset, uint8_t &val )
val = D_SHMHDR->value; val = D_SHMHDR->value;
} }
uint16_t SHMProcess::readWord (const uint32_t offset)
{
if(!d->locked) throw Error::MemoryAccessDenied();
D_SHMHDR->address = offset;
gcc_barrier
d->SetAndWait(CORE_READ_WORD);
return D_SHMHDR->value;
}
void SHMProcess::readWord (const uint32_t offset, uint16_t &val) void SHMProcess::readWord (const uint32_t offset, uint16_t &val)
{ {
if(!d->locked) throw Error::MemoryAccessDenied(); if(!d->locked) throw Error::MemoryAccessDenied();
@ -667,15 +647,6 @@ void SHMProcess::readWord (const uint32_t offset, uint16_t &val)
val = D_SHMHDR->value; val = D_SHMHDR->value;
} }
uint32_t SHMProcess::readDWord (const uint32_t offset)
{
if(!d->locked) throw Error::MemoryAccessDenied();
D_SHMHDR->address = offset;
gcc_barrier
d->SetAndWait(CORE_READ_DWORD);
return D_SHMHDR->value;
}
void SHMProcess::readDWord (const uint32_t offset, uint32_t &val) void SHMProcess::readDWord (const uint32_t offset, uint32_t &val)
{ {
if(!d->locked) throw Error::MemoryAccessDenied(); if(!d->locked) throw Error::MemoryAccessDenied();
@ -686,15 +657,6 @@ void SHMProcess::readDWord (const uint32_t offset, uint32_t &val)
val = D_SHMHDR->value; val = D_SHMHDR->value;
} }
uint64_t SHMProcess::readQuad (const uint32_t offset)
{
if(!d->locked) throw Error::MemoryAccessDenied();
D_SHMHDR->address = offset;
gcc_barrier
d->SetAndWait(CORE_READ_QUAD);
return D_SHMHDR->Qvalue;
}
void SHMProcess::readQuad (const uint32_t offset, uint64_t &val) void SHMProcess::readQuad (const uint32_t offset, uint64_t &val)
{ {
if(!d->locked) throw Error::MemoryAccessDenied(); if(!d->locked) throw Error::MemoryAccessDenied();
@ -705,15 +667,6 @@ void SHMProcess::readQuad (const uint32_t offset, uint64_t &val)
val = D_SHMHDR->Qvalue; val = D_SHMHDR->Qvalue;
} }
float SHMProcess::readFloat (const uint32_t offset)
{
if(!d->locked) throw Error::MemoryAccessDenied();
D_SHMHDR->address = offset;
gcc_barrier
d->SetAndWait(CORE_READ_DWORD);
return reinterpret_cast<float&> (D_SHMHDR->value);
}
void SHMProcess::readFloat (const uint32_t offset, float &val) void SHMProcess::readFloat (const uint32_t offset, float &val)
{ {
if(!d->locked) throw Error::MemoryAccessDenied(); if(!d->locked) throw Error::MemoryAccessDenied();
@ -817,7 +770,7 @@ const std::string SHMProcess::readCString (uint32_t offset)
char r; char r;
do do
{ {
r = readByte(offset+counter); r = Process::readByte(offset+counter);
temp_c[counter] = r; temp_c[counter] = r;
counter++; counter++;
} while (r && counter < 255); } while (r && counter < 255);
@ -864,8 +817,8 @@ string SHMProcess::readClassName (uint32_t vptr)
{ {
if(!d->locked) throw Error::MemoryAccessDenied(); if(!d->locked) throw Error::MemoryAccessDenied();
int typeinfo = readDWord(vptr - 0x4); int typeinfo = Process::readDWord(vptr - 0x4);
int typestring = readDWord(typeinfo + 0x4); int typestring = Process::readDWord(typeinfo + 0x4);
string raw = readCString(typestring); string raw = readCString(typestring);
size_t start = raw.find_first_of("abcdefghijklmnopqrstuvwxyz");// trim numbers size_t start = raw.find_first_of("abcdefghijklmnopqrstuvwxyz");// trim numbers
size_t end = raw.length(); size_t end = raw.length();

@ -395,47 +395,21 @@ void WineProcess::read (const uint32_t offset, const uint32_t size, uint8_t *tar
} }
} }
uint8_t WineProcess::readByte (const uint32_t offset)
{
uint8_t val;
read(offset, 1, &val);
return val;
}
void WineProcess::readByte (const uint32_t offset, uint8_t &val ) void WineProcess::readByte (const uint32_t offset, uint8_t &val )
{ {
read(offset, 1, &val); read(offset, 1, &val);
} }
uint16_t WineProcess::readWord (const uint32_t offset)
{
uint16_t val;
read(offset, 2, (uint8_t *) &val);
return val;
}
void WineProcess::readWord (const uint32_t offset, uint16_t &val) void WineProcess::readWord (const uint32_t offset, uint16_t &val)
{ {
read(offset, 2, (uint8_t *) &val); read(offset, 2, (uint8_t *) &val);
} }
uint32_t WineProcess::readDWord (const uint32_t offset)
{
uint32_t val;
read(offset, 4, (uint8_t *) &val);
return val;
}
void WineProcess::readDWord (const uint32_t offset, uint32_t &val) void WineProcess::readDWord (const uint32_t offset, uint32_t &val)
{ {
read(offset, 4, (uint8_t *) &val); read(offset, 4, (uint8_t *) &val);
} }
float WineProcess::readFloat (const uint32_t offset)
{
float val;
read(offset, 4, (uint8_t *) &val);
return val;
}
void WineProcess::readFloat (const uint32_t offset, float &val) void WineProcess::readFloat (const uint32_t offset, float &val)
{ {
read(offset, 4, (uint8_t *) &val); read(offset, 4, (uint8_t *) &val);
@ -446,13 +420,6 @@ void WineProcess::readQuad (const uint32_t offset, uint64_t &val)
read(offset, 8, (uint8_t *) &val); read(offset, 8, (uint8_t *) &val);
} }
uint64_t WineProcess::readQuad (const uint32_t offset)
{
uint64_t val;
read(offset, 8, (uint8_t *) &val);
return val;
}
/* /*
* WRITING * WRITING
*/ */
@ -470,7 +437,7 @@ void WineProcess::writeQuad (uint32_t offset, const uint64_t data)
void WineProcess::writeDWord (uint32_t offset, uint32_t data) void WineProcess::writeDWord (uint32_t offset, uint32_t data)
{ {
#ifdef HAVE_64_BIT #ifdef HAVE_64_BIT
uint64_t orig = readQuad(offset); uint64_t orig = Process::readQuad(offset);
orig &= 0xFFFFFFFF00000000; orig &= 0xFFFFFFFF00000000;
orig |= data; orig |= data;
ptrace(PTRACE_POKEDATA,d->my_handle, offset, orig); ptrace(PTRACE_POKEDATA,d->my_handle, offset, orig);
@ -483,7 +450,7 @@ void WineProcess::writeDWord (uint32_t offset, uint32_t data)
void WineProcess::writeWord (uint32_t offset, uint16_t data) void WineProcess::writeWord (uint32_t offset, uint16_t data)
{ {
#ifdef HAVE_64_BIT #ifdef HAVE_64_BIT
uint64_t orig = readQuad(offset); uint64_t orig = Process::readQuad(offset);
orig &= 0xFFFFFFFFFFFF0000; orig &= 0xFFFFFFFFFFFF0000;
orig |= data; orig |= data;
ptrace(PTRACE_POKEDATA,d->my_handle, offset, orig); ptrace(PTRACE_POKEDATA,d->my_handle, offset, orig);
@ -498,7 +465,7 @@ void WineProcess::writeWord (uint32_t offset, uint16_t data)
void WineProcess::writeByte (uint32_t offset, uint8_t data) void WineProcess::writeByte (uint32_t offset, uint8_t data)
{ {
#ifdef HAVE_64_BIT #ifdef HAVE_64_BIT
uint64_t orig = readQuad(offset); uint64_t orig = Process::readQuad(offset);
orig &= 0xFFFFFFFFFFFFFF00; orig &= 0xFFFFFFFFFFFFFF00;
orig |= data; orig |= data;
ptrace(PTRACE_POKEDATA,d->my_handle, offset, orig); ptrace(PTRACE_POKEDATA,d->my_handle, offset, orig);
@ -560,7 +527,7 @@ const std::string WineProcess::readCString (uint32_t offset)
char r; char r;
do do
{ {
r = readByte(offset+counter); r = Process::readByte(offset+counter);
temp_c[counter] = r; temp_c[counter] = r;
counter++; counter++;
} while (r && counter < 255); } while (r && counter < 255);
@ -572,8 +539,8 @@ const std::string WineProcess::readCString (uint32_t offset)
size_t WineProcess::readSTLString (uint32_t offset, char * buffer, size_t bufcapacity) size_t WineProcess::readSTLString (uint32_t offset, char * buffer, size_t bufcapacity)
{ {
uint32_t start_offset = offset + d->STLSTR_buf_off; uint32_t start_offset = offset + d->STLSTR_buf_off;
size_t length = readDWord(offset + d->STLSTR_size_off); size_t length = Process::readDWord(offset + d->STLSTR_size_off);
size_t capacity = readDWord(offset + d->STLSTR_cap_off); size_t capacity = Process::readDWord(offset + d->STLSTR_cap_off);
size_t read_real = min(length, bufcapacity-1);// keep space for null termination size_t read_real = min(length, bufcapacity-1);// keep space for null termination
@ -584,7 +551,7 @@ size_t WineProcess::readSTLString (uint32_t offset, char * buffer, size_t bufcap
} }
else // read data from what the offset + 4 dword points to else // read data from what the offset + 4 dword points to
{ {
start_offset = readDWord(start_offset);// dereference the start offset start_offset = Process::readDWord(start_offset);// dereference the start offset
read(start_offset, read_real, (uint8_t *)buffer); read(start_offset, read_real, (uint8_t *)buffer);
} }
@ -595,8 +562,8 @@ size_t WineProcess::readSTLString (uint32_t offset, char * buffer, size_t bufcap
const string WineProcess::readSTLString (uint32_t offset) const string WineProcess::readSTLString (uint32_t offset)
{ {
uint32_t start_offset = offset + d->STLSTR_buf_off; uint32_t start_offset = offset + d->STLSTR_buf_off;
size_t length = readDWord(offset + d->STLSTR_size_off); size_t length = Process::readDWord(offset + d->STLSTR_size_off);
size_t capacity = readDWord(offset + d->STLSTR_cap_off); size_t capacity = Process::readDWord(offset + d->STLSTR_cap_off);
char * temp = new char[capacity+1]; char * temp = new char[capacity+1];
@ -607,7 +574,7 @@ const string WineProcess::readSTLString (uint32_t offset)
} }
else // read data from what the offset + 4 dword points to else // read data from what the offset + 4 dword points to
{ {
start_offset = readDWord(start_offset);// dereference the start offset start_offset = Process::readDWord(start_offset);// dereference the start offset
read(start_offset, capacity, (uint8_t *)temp); read(start_offset, capacity, (uint8_t *)temp);
} }
@ -619,8 +586,8 @@ const string WineProcess::readSTLString (uint32_t offset)
string WineProcess::readClassName (uint32_t vptr) string WineProcess::readClassName (uint32_t vptr)
{ {
int rtti = readDWord(vptr - 0x4); int rtti = Process::readDWord(vptr - 0x4);
int typeinfo = readDWord(rtti + 0xC); int typeinfo = Process::readDWord(rtti + 0xC);
string raw = readCString(typeinfo + 0xC); // skips the .?AV string raw = readCString(typeinfo + 0xC); // skips the .?AV
raw.resize(raw.length() - 2);// trim @@ from end raw.resize(raw.length() - 2);// trim @@ from end
return raw; return raw;

@ -373,58 +373,26 @@ void NormalProcess::read (const uint32_t offset, const uint32_t size, uint8_t *t
} }
} }
uint8_t NormalProcess::readByte (const uint32_t offset)
{
uint8_t val;
read(offset, 1, &val);
return val;
}
void NormalProcess::readByte (const uint32_t offset, uint8_t &val ) void NormalProcess::readByte (const uint32_t offset, uint8_t &val )
{ {
read(offset, 1, &val); read(offset, 1, &val);
} }
uint16_t NormalProcess::readWord (const uint32_t offset)
{
uint16_t val;
read(offset, 2, (uint8_t *) &val);
return val;
}
void NormalProcess::readWord (const uint32_t offset, uint16_t &val) void NormalProcess::readWord (const uint32_t offset, uint16_t &val)
{ {
read(offset, 2, (uint8_t *) &val); read(offset, 2, (uint8_t *) &val);
} }
uint32_t NormalProcess::readDWord (const uint32_t offset)
{
uint32_t val;
read(offset, 4, (uint8_t *) &val);
return val;
}
void NormalProcess::readDWord (const uint32_t offset, uint32_t &val) void NormalProcess::readDWord (const uint32_t offset, uint32_t &val)
{ {
read(offset, 4, (uint8_t *) &val); read(offset, 4, (uint8_t *) &val);
} }
float NormalProcess::readFloat (const uint32_t offset)
{
float val;
read(offset, 4, (uint8_t *) &val);
return val;
}
void NormalProcess::readFloat (const uint32_t offset, float &val) void NormalProcess::readFloat (const uint32_t offset, float &val)
{ {
read(offset, 4, (uint8_t *) &val); read(offset, 4, (uint8_t *) &val);
} }
uint64_t NormalProcess::readQuad (const uint32_t offset)
{
uint64_t val;
read(offset, 8, (uint8_t *) &val);
return val;
}
void NormalProcess::readQuad (const uint32_t offset, uint64_t &val) void NormalProcess::readQuad (const uint32_t offset, uint64_t &val)
{ {
read(offset, 8, (uint8_t *) &val); read(offset, 8, (uint8_t *) &val);
@ -446,7 +414,7 @@ void NormalProcess::writeQuad (uint32_t offset, const uint64_t data)
void NormalProcess::writeDWord (uint32_t offset, uint32_t data) void NormalProcess::writeDWord (uint32_t offset, uint32_t data)
{ {
#ifdef HAVE_64_BIT #ifdef HAVE_64_BIT
uint64_t orig = readQuad(offset); uint64_t orig = Process::readQuad(offset);
orig &= 0xFFFFFFFF00000000; orig &= 0xFFFFFFFF00000000;
orig |= data; orig |= data;
ptrace(PTRACE_POKEDATA,d->my_handle, offset, orig); ptrace(PTRACE_POKEDATA,d->my_handle, offset, orig);
@ -459,7 +427,7 @@ void NormalProcess::writeDWord (uint32_t offset, uint32_t data)
void NormalProcess::writeWord (uint32_t offset, uint16_t data) void NormalProcess::writeWord (uint32_t offset, uint16_t data)
{ {
#ifdef HAVE_64_BIT #ifdef HAVE_64_BIT
uint64_t orig = readQuad(offset); uint64_t orig = Process::readQuad(offset);
orig &= 0xFFFFFFFFFFFF0000; orig &= 0xFFFFFFFFFFFF0000;
orig |= data; orig |= data;
ptrace(PTRACE_POKEDATA,d->my_handle, offset, orig); ptrace(PTRACE_POKEDATA,d->my_handle, offset, orig);
@ -474,7 +442,7 @@ void NormalProcess::writeWord (uint32_t offset, uint16_t data)
void NormalProcess::writeByte (uint32_t offset, uint8_t data) void NormalProcess::writeByte (uint32_t offset, uint8_t data)
{ {
#ifdef HAVE_64_BIT #ifdef HAVE_64_BIT
uint64_t orig = readQuad(offset); uint64_t orig = Process::readQuad(offset);
orig &= 0xFFFFFFFFFFFFFF00; orig &= 0xFFFFFFFFFFFFFF00;
orig |= data; orig |= data;
ptrace(PTRACE_POKEDATA,d->my_handle, offset, orig); ptrace(PTRACE_POKEDATA,d->my_handle, offset, orig);
@ -536,7 +504,7 @@ const std::string NormalProcess::readCString (uint32_t offset)
char r; char r;
do do
{ {
r = readByte(offset+counter); r = Process::readByte(offset+counter);
temp_c[counter] = r; temp_c[counter] = r;
counter++; counter++;
} while (r && counter < 255); } while (r && counter < 255);
@ -555,7 +523,7 @@ struct _Rep_base
size_t NormalProcess::readSTLString (uint32_t offset, char * buffer, size_t bufcapacity) size_t NormalProcess::readSTLString (uint32_t offset, char * buffer, size_t bufcapacity)
{ {
_Rep_base header; _Rep_base header;
offset = readDWord(offset); offset = Process::readDWord(offset);
read(offset - sizeof(_Rep_base),sizeof(_Rep_base),(uint8_t *)&header); read(offset - sizeof(_Rep_base),sizeof(_Rep_base),(uint8_t *)&header);
size_t read_real = min((size_t)header._M_length, bufcapacity-1);// keep space for null termination size_t read_real = min((size_t)header._M_length, bufcapacity-1);// keep space for null termination
read(offset,read_real,(uint8_t * )buffer); read(offset,read_real,(uint8_t * )buffer);
@ -567,7 +535,7 @@ const string NormalProcess::readSTLString (uint32_t offset)
{ {
_Rep_base header; _Rep_base header;
offset = readDWord(offset); offset = Process::readDWord(offset);
read(offset - sizeof(_Rep_base),sizeof(_Rep_base),(uint8_t *)&header); read(offset - sizeof(_Rep_base),sizeof(_Rep_base),(uint8_t *)&header);
// FIXME: use char* everywhere, avoid string // FIXME: use char* everywhere, avoid string
@ -580,8 +548,8 @@ const string NormalProcess::readSTLString (uint32_t offset)
string NormalProcess::readClassName (uint32_t vptr) string NormalProcess::readClassName (uint32_t vptr)
{ {
int typeinfo = readDWord(vptr - 0x4); int typeinfo = Process::readDWord(vptr - 0x4);
int typestring = readDWord(typeinfo + 0x4); int typestring = Process::readDWord(typeinfo + 0x4);
string raw = readCString(typestring); string raw = readCString(typestring);
size_t start = raw.find_first_of("abcdefghijklmnopqrstuvwxyz");// trim numbers size_t start = raw.find_first_of("abcdefghijklmnopqrstuvwxyz");// trim numbers
size_t end = raw.length(); size_t end = raw.length();

@ -340,7 +340,7 @@ bool SHMProcess::Private::validate(vector <VersionInfo *> & known_versions)
uint32_t base = (uint32_t)hmod; uint32_t base = (uint32_t)hmod;
// read from this process // read from this process
uint32_t pe_offset = self->readDWord(base+0x3C); uint32_t pe_offset = self->Process::readDWord(base+0x3C);
self->read(base + pe_offset , sizeof(pe_header), (uint8_t *)&pe_header); self->read(base + pe_offset , sizeof(pe_header), (uint8_t *)&pe_header);
self->read(base + pe_offset+ sizeof(pe_header), sizeof(sections) , (uint8_t *)&sections ); self->read(base + pe_offset+ sizeof(pe_header), sizeof(sections) , (uint8_t *)&sections );
@ -436,7 +436,7 @@ void SHMProcess::getMemRanges( vector<t_memrange> & ranges )
t_memrange temp; t_memrange temp;
uint32_t base = d->memdescriptor->getBase(); uint32_t base = d->memdescriptor->getBase();
temp.start = base + 0x1000; // more fakery. temp.start = base + 0x1000; // more fakery.
temp.end = base + readDWord(base+readDWord(base+0x3C)+0x50)-1; // yay for magic. temp.end = base + Process::readDWord(base+readDWord(base+0x3C)+0x50)-1; // yay for magic.
temp.read = 1; temp.read = 1;
temp.write = 1; temp.write = 1;
temp.execute = 0; // fake temp.execute = 0; // fake
@ -688,16 +688,6 @@ void SHMProcess::read (uint32_t src_address, uint32_t size, uint8_t *target_buff
} }
} }
uint8_t SHMProcess::readByte (const uint32_t offset)
{
if(!d->locked) throw Error::MemoryAccessDenied();
D_SHMHDR->address = offset;
full_barrier
d->SetAndWait(CORE_READ_BYTE);
return D_SHMHDR->value;
}
void SHMProcess::readByte (const uint32_t offset, uint8_t &val ) void SHMProcess::readByte (const uint32_t offset, uint8_t &val )
{ {
if(!d->locked) throw Error::MemoryAccessDenied(); if(!d->locked) throw Error::MemoryAccessDenied();
@ -708,16 +698,6 @@ void SHMProcess::readByte (const uint32_t offset, uint8_t &val )
val = D_SHMHDR->value; val = D_SHMHDR->value;
} }
uint16_t SHMProcess::readWord (const uint32_t offset)
{
if(!d->locked) throw Error::MemoryAccessDenied();
D_SHMHDR->address = offset;
full_barrier
d->SetAndWait(CORE_READ_WORD);
return D_SHMHDR->value;
}
void SHMProcess::readWord (const uint32_t offset, uint16_t &val) void SHMProcess::readWord (const uint32_t offset, uint16_t &val)
{ {
if(!d->locked) throw Error::MemoryAccessDenied(); if(!d->locked) throw Error::MemoryAccessDenied();
@ -728,15 +708,6 @@ void SHMProcess::readWord (const uint32_t offset, uint16_t &val)
val = D_SHMHDR->value; val = D_SHMHDR->value;
} }
uint32_t SHMProcess::readDWord (const uint32_t offset)
{
if(!d->locked) throw Error::MemoryAccessDenied();
D_SHMHDR->address = offset;
full_barrier
d->SetAndWait(CORE_READ_DWORD);
return D_SHMHDR->value;
}
void SHMProcess::readDWord (const uint32_t offset, uint32_t &val) void SHMProcess::readDWord (const uint32_t offset, uint32_t &val)
{ {
if(!d->locked) throw Error::MemoryAccessDenied(); if(!d->locked) throw Error::MemoryAccessDenied();
@ -747,15 +718,6 @@ void SHMProcess::readDWord (const uint32_t offset, uint32_t &val)
val = D_SHMHDR->value; val = D_SHMHDR->value;
} }
float SHMProcess::readFloat (const uint32_t offset)
{
if(!d->locked) throw Error::MemoryAccessDenied();
D_SHMHDR->address = offset;
full_barrier
d->SetAndWait(CORE_READ_DWORD);
return reinterpret_cast<float&> (D_SHMHDR->value);
}
void SHMProcess::readFloat (const uint32_t offset, float &val) void SHMProcess::readFloat (const uint32_t offset, float &val)
{ {
if(!d->locked) throw Error::MemoryAccessDenied(); if(!d->locked) throw Error::MemoryAccessDenied();
@ -765,15 +727,7 @@ void SHMProcess::readFloat (const uint32_t offset, float &val)
d->SetAndWait(CORE_READ_DWORD); d->SetAndWait(CORE_READ_DWORD);
val = reinterpret_cast<float&> (D_SHMHDR->value); val = reinterpret_cast<float&> (D_SHMHDR->value);
} }
uint64_t SHMProcess::readQuad (const uint32_t offset)
{
if(!d->locked) throw Error::MemoryAccessDenied();
D_SHMHDR->address = offset;
full_barrier
d->SetAndWait(CORE_READ_QUAD);
return D_SHMHDR->Qvalue;
}
void SHMProcess::readQuad (const uint32_t offset, uint64_t &val) void SHMProcess::readQuad (const uint32_t offset, uint64_t &val)
{ {
if(!d->locked) throw Error::MemoryAccessDenied(); if(!d->locked) throw Error::MemoryAccessDenied();
@ -878,7 +832,7 @@ const std::string SHMProcess::readCString (uint32_t offset)
char r; char r;
do do
{ {
r = readByte(offset+counter); r = Process::readByte(offset+counter);
temp_c[counter] = r; temp_c[counter] = r;
counter++; counter++;
} while (r && counter < 255); } while (r && counter < 255);
@ -923,8 +877,8 @@ void SHMProcess::writeSTLString(const uint32_t address, const std::string writeS
string SHMProcess::readClassName (uint32_t vptr) string SHMProcess::readClassName (uint32_t vptr)
{ {
int rtti = readDWord(vptr - 0x4); int rtti = Process::readDWord(vptr - 0x4);
int typeinfo = readDWord(rtti + 0xC); int typeinfo = Process::readDWord(rtti + 0xC);
string raw = readCString(typeinfo + 0xC); // skips the .?AV string raw = readCString(typeinfo + 0xC); // skips the .?AV
raw.resize(raw.length() - 2);// trim @@ from end raw.resize(raw.length() - 2);// trim @@ from end
return raw; return raw;

@ -90,7 +90,7 @@ NormalProcess::NormalProcess(uint32_t pid, vector <VersionInfo *> & known_versio
// read from this process // read from this process
try try
{ {
uint32_t pe_offset = readDWord(d->base+0x3C); uint32_t pe_offset = Process::readDWord(d->base+0x3C);
read(d->base + pe_offset , sizeof(d->pe_header), (uint8_t *)&d->pe_header); read(d->base + pe_offset , sizeof(d->pe_header), (uint8_t *)&d->pe_header);
const size_t sectionsSize = sizeof(IMAGE_SECTION_HEADER) * d->pe_header.FileHeader.NumberOfSections; const size_t sectionsSize = sizeof(IMAGE_SECTION_HEADER) * d->pe_header.FileHeader.NumberOfSections;
d->sections = (IMAGE_SECTION_HEADER *) malloc(sectionsSize); d->sections = (IMAGE_SECTION_HEADER *) malloc(sectionsSize);
@ -417,70 +417,30 @@ void NormalProcess::getMemRanges( vector<t_memrange> & ranges )
} }
} }
uint8_t NormalProcess::readByte (const uint32_t offset)
{
uint8_t result;
if(!ReadProcessMemory(d->my_handle, (int*) offset, &result, sizeof(uint8_t), NULL))
throw Error::MemoryAccessDenied();
return result;
}
void NormalProcess::readByte (const uint32_t offset,uint8_t &result) void NormalProcess::readByte (const uint32_t offset,uint8_t &result)
{ {
if(!ReadProcessMemory(d->my_handle, (int*) offset, &result, sizeof(uint8_t), NULL)) if(!ReadProcessMemory(d->my_handle, (int*) offset, &result, sizeof(uint8_t), NULL))
throw Error::MemoryAccessDenied(); throw Error::MemoryAccessDenied();
} }
uint16_t NormalProcess::readWord (const uint32_t offset)
{
uint16_t result;
if(!ReadProcessMemory(d->my_handle, (int*) offset, &result, sizeof(uint16_t), NULL))
throw Error::MemoryAccessDenied();
return result;
}
void NormalProcess::readWord (const uint32_t offset, uint16_t &result) void NormalProcess::readWord (const uint32_t offset, uint16_t &result)
{ {
if(!ReadProcessMemory(d->my_handle, (int*) offset, &result, sizeof(uint16_t), NULL)) if(!ReadProcessMemory(d->my_handle, (int*) offset, &result, sizeof(uint16_t), NULL))
throw Error::MemoryAccessDenied(); throw Error::MemoryAccessDenied();
} }
uint32_t NormalProcess::readDWord (const uint32_t offset)
{
uint32_t result;
if(!ReadProcessMemory(d->my_handle, (int*) offset, &result, sizeof(uint32_t), NULL))
throw Error::MemoryAccessDenied();
return result;
}
void NormalProcess::readDWord (const uint32_t offset, uint32_t &result) void NormalProcess::readDWord (const uint32_t offset, uint32_t &result)
{ {
if(!ReadProcessMemory(d->my_handle, (int*) offset, &result, sizeof(uint32_t), NULL)) if(!ReadProcessMemory(d->my_handle, (int*) offset, &result, sizeof(uint32_t), NULL))
throw Error::MemoryAccessDenied(); throw Error::MemoryAccessDenied();
} }
uint64_t NormalProcess::readQuad (const uint32_t offset)
{
uint64_t result;
if(!ReadProcessMemory(d->my_handle, (int*) offset, &result, sizeof(uint64_t), NULL))
throw Error::MemoryAccessDenied();
return result;
}
void NormalProcess::readQuad (const uint32_t offset, uint64_t &result) void NormalProcess::readQuad (const uint32_t offset, uint64_t &result)
{ {
if(!ReadProcessMemory(d->my_handle, (int*) offset, &result, sizeof(uint64_t), NULL)) if(!ReadProcessMemory(d->my_handle, (int*) offset, &result, sizeof(uint64_t), NULL))
throw Error::MemoryAccessDenied(); throw Error::MemoryAccessDenied();
} }
float NormalProcess::readFloat (const uint32_t offset)
{
float result;
if(!ReadProcessMemory(d->my_handle, (int*) offset, &result, sizeof(float), NULL))
throw Error::MemoryAccessDenied();
return result;
}
void NormalProcess::readFloat (const uint32_t offset, float &result) void NormalProcess::readFloat (const uint32_t offset, float &result)
{ {
if(!ReadProcessMemory(d->my_handle, (int*) offset, &result, sizeof(float), NULL)) if(!ReadProcessMemory(d->my_handle, (int*) offset, &result, sizeof(float), NULL))
@ -544,8 +504,8 @@ const string NormalProcess::readCString (const uint32_t offset)
size_t NormalProcess::readSTLString (uint32_t offset, char * buffer, size_t bufcapacity) size_t NormalProcess::readSTLString (uint32_t offset, char * buffer, size_t bufcapacity)
{ {
uint32_t start_offset = offset + d->STLSTR_buf_off; uint32_t start_offset = offset + d->STLSTR_buf_off;
size_t length = readDWord(offset + d->STLSTR_size_off); size_t length = Process::readDWord(offset + d->STLSTR_size_off);
size_t capacity = readDWord(offset + d->STLSTR_cap_off); size_t capacity = Process::readDWord(offset + d->STLSTR_cap_off);
size_t read_real = min(length, bufcapacity-1);// keep space for null termination size_t read_real = min(length, bufcapacity-1);// keep space for null termination
// read data from inside the string structure // read data from inside the string structure
@ -555,7 +515,7 @@ size_t NormalProcess::readSTLString (uint32_t offset, char * buffer, size_t bufc
} }
else // read data from what the offset + 4 dword points to else // read data from what the offset + 4 dword points to
{ {
start_offset = readDWord(start_offset);// dereference the start offset start_offset = Process::readDWord(start_offset);// dereference the start offset
read(start_offset, read_real, (uint8_t *)buffer); read(start_offset, read_real, (uint8_t *)buffer);
} }
@ -566,8 +526,8 @@ size_t NormalProcess::readSTLString (uint32_t offset, char * buffer, size_t bufc
const string NormalProcess::readSTLString (uint32_t offset) const string NormalProcess::readSTLString (uint32_t offset)
{ {
uint32_t start_offset = offset + d->STLSTR_buf_off; uint32_t start_offset = offset + d->STLSTR_buf_off;
size_t length = readDWord(offset + d->STLSTR_size_off); size_t length = Process::readDWord(offset + d->STLSTR_size_off);
size_t capacity = readDWord(offset + d->STLSTR_cap_off); size_t capacity = Process::readDWord(offset + d->STLSTR_cap_off);
char * temp = new char[capacity+1]; char * temp = new char[capacity+1];
// read data from inside the string structure // read data from inside the string structure
@ -577,7 +537,7 @@ const string NormalProcess::readSTLString (uint32_t offset)
} }
else // read data from what the offset + 4 dword points to else // read data from what the offset + 4 dword points to
{ {
start_offset = readDWord(start_offset);// dereference the start offset start_offset = Process::readDWord(start_offset);// dereference the start offset
read(start_offset, capacity, (uint8_t *)temp); read(start_offset, capacity, (uint8_t *)temp);
} }
@ -589,8 +549,8 @@ const string NormalProcess::readSTLString (uint32_t offset)
string NormalProcess::readClassName (uint32_t vptr) string NormalProcess::readClassName (uint32_t vptr)
{ {
int rtti = readDWord(vptr - 0x4); int rtti = Process::readDWord(vptr - 0x4);
int typeinfo = readDWord(rtti + 0xC); int typeinfo = Process::readDWord(rtti + 0xC);
string raw = readCString(typeinfo + 0xC); // skips the .?AV string raw = readCString(typeinfo + 0xC); // skips the .?AV
raw.resize(raw.length() - 2);// trim @@ from end raw.resize(raw.length() - 2);// trim @@ from end
return raw; return raw;

@ -99,33 +99,33 @@ namespace DFHack
virtual bool forceresume() = 0; virtual bool forceresume() = 0;
/// read a 8-byte integer /// read a 8-byte integer
virtual uint64_t readQuad(const uint32_t address) = 0; uint64_t readQuad(const uint32_t address) { uint64_t result; readQuad(address, result); return result; }
/// read a 8-byte integer /// read a 8-byte integer
virtual void readQuad(const uint32_t address, uint64_t & value) = 0; virtual void readQuad(const uint32_t address, uint64_t & value) = 0;
/// write a 8-byte integer /// write a 8-byte integer
virtual void writeQuad(const uint32_t address, const uint64_t value) = 0; virtual void writeQuad(const uint32_t address, const uint64_t value) = 0;
/// read a 4-byte integer /// read a 4-byte integer
virtual uint32_t readDWord(const uint32_t address) = 0; uint32_t readDWord(const uint32_t address) { uint32_t result; readDWord(address, result); return result; }
/// read a 4-byte integer /// read a 4-byte integer
virtual void readDWord(const uint32_t address, uint32_t & value) = 0; virtual void readDWord(const uint32_t address, uint32_t & value) = 0;
/// write a 4-byte integer /// write a 4-byte integer
virtual void writeDWord(const uint32_t address, const uint32_t value) = 0; virtual void writeDWord(const uint32_t address, const uint32_t value) = 0;
/// read a float /// read a float
virtual float readFloat(const uint32_t address) = 0; float readFloat(const uint32_t address) { float result; readFloat(address, result); return result; }
/// write a float /// write a float
virtual void readFloat(const uint32_t address, float & value) = 0; virtual void readFloat(const uint32_t address, float & value) = 0;
/// read a 2-byte integer /// read a 2-byte integer
virtual uint16_t readWord(const uint32_t address) = 0; uint16_t readWord(const uint32_t address) { uint16_t result; readWord(address, result); return result; }
/// read a 2-byte integer /// read a 2-byte integer
virtual void readWord(const uint32_t address, uint16_t & value) = 0; virtual void readWord(const uint32_t address, uint16_t & value) = 0;
/// write a 2-byte integer /// write a 2-byte integer
virtual void writeWord(const uint32_t address, const uint16_t value) = 0; virtual void writeWord(const uint32_t address, const uint16_t value) = 0;
/// read a byte /// read a byte
virtual uint8_t readByte(const uint32_t address) = 0; uint8_t readByte(const uint32_t address) { uint8_t result; readByte(address, result); return result; }
/// read a byte /// read a byte
virtual void readByte(const uint32_t address, uint8_t & value) = 0; virtual void readByte(const uint32_t address, uint8_t & value) = 0;
/// write a byte /// write a byte

@ -50,22 +50,17 @@ namespace DFHack
bool resume(); bool resume();
bool forceresume(); bool forceresume();
uint64_t readQuad(const uint32_t address);
void readQuad(const uint32_t address, uint64_t & value); void readQuad(const uint32_t address, uint64_t & value);
void writeQuad(const uint32_t address, const uint64_t value); void writeQuad(const uint32_t address, const uint64_t value);
uint32_t readDWord(const uint32_t address);
void readDWord(const uint32_t address, uint32_t & value); void readDWord(const uint32_t address, uint32_t & value);
void writeDWord(const uint32_t address, const uint32_t value); void writeDWord(const uint32_t address, const uint32_t value);
float readFloat(const uint32_t address);
void readFloat(const uint32_t address, float & value); void readFloat(const uint32_t address, float & value);
uint16_t readWord(const uint32_t address);
void readWord(const uint32_t address, uint16_t & value); void readWord(const uint32_t address, uint16_t & value);
void writeWord(const uint32_t address, const uint16_t value); void writeWord(const uint32_t address, const uint16_t value);
uint8_t readByte(const uint32_t address);
void readByte(const uint32_t address, uint8_t & value); void readByte(const uint32_t address, uint8_t & value);
void writeByte(const uint32_t address, const uint8_t value); void writeByte(const uint32_t address, const uint8_t value);
@ -116,22 +111,17 @@ namespace DFHack
bool resume(); bool resume();
bool forceresume(); bool forceresume();
uint64_t readQuad(const uint32_t address);
void readQuad(const uint32_t address, uint64_t & value); void readQuad(const uint32_t address, uint64_t & value);
void writeQuad(const uint32_t address, const uint64_t value); void writeQuad(const uint32_t address, const uint64_t value);
uint32_t readDWord(const uint32_t address);
void readDWord(const uint32_t address, uint32_t & value); void readDWord(const uint32_t address, uint32_t & value);
void writeDWord(const uint32_t address, const uint32_t value); void writeDWord(const uint32_t address, const uint32_t value);
float readFloat(const uint32_t address);
void readFloat(const uint32_t address, float & value); void readFloat(const uint32_t address, float & value);
uint16_t readWord(const uint32_t address);
void readWord(const uint32_t address, uint16_t & value); void readWord(const uint32_t address, uint16_t & value);
void writeWord(const uint32_t address, const uint16_t value); void writeWord(const uint32_t address, const uint16_t value);
uint8_t readByte(const uint32_t address);
void readByte(const uint32_t address, uint8_t & value); void readByte(const uint32_t address, uint8_t & value);
void writeByte(const uint32_t address, const uint8_t value); void writeByte(const uint32_t address, const uint8_t value);
@ -181,22 +171,17 @@ namespace DFHack
bool resume(); bool resume();
bool forceresume(); bool forceresume();
uint64_t readQuad(const uint32_t address);
void readQuad(const uint32_t address, uint64_t & value); void readQuad(const uint32_t address, uint64_t & value);
void writeQuad(const uint32_t address, const uint64_t value); void writeQuad(const uint32_t address, const uint64_t value);
uint32_t readDWord(const uint32_t address);
void readDWord(const uint32_t address, uint32_t & value); void readDWord(const uint32_t address, uint32_t & value);
void writeDWord(const uint32_t address, const uint32_t value); void writeDWord(const uint32_t address, const uint32_t value);
float readFloat(const uint32_t address);
void readFloat(const uint32_t address, float & value); void readFloat(const uint32_t address, float & value);
uint16_t readWord(const uint32_t address);
void readWord(const uint32_t address, uint16_t & value); void readWord(const uint32_t address, uint16_t & value);
void writeWord(const uint32_t address, const uint16_t value); void writeWord(const uint32_t address, const uint16_t value);
uint8_t readByte(const uint32_t address);
void readByte(const uint32_t address, uint8_t & value); void readByte(const uint32_t address, uint8_t & value);
void writeByte(const uint32_t address, const uint8_t value); void writeByte(const uint32_t address, const uint8_t value);