From 9b854be3278124b7761a6b983a7211204e6fc85f Mon Sep 17 00:00:00 2001 From: Tom Prince Date: Wed, 23 Feb 2011 01:50:21 -0500 Subject: [PATCH] Remove duplicate code implementing readInt. Implement one version in terms of the other. --- library/DFProcess-linux-SHM.cpp | 53 ++------------------------ library/DFProcess-linux-wine.cpp | 57 ++++++---------------------- library/DFProcess-linux.cpp | 48 ++++-------------------- library/DFProcess-windows-SHM.cpp | 56 +++------------------------- library/DFProcess-windows.cpp | 60 +++++------------------------- library/include/dfhack/DFProcess.h | 10 ++--- library/private/ProcessInternal.h | 15 -------- 7 files changed, 43 insertions(+), 256 deletions(-) diff --git a/library/DFProcess-linux-SHM.cpp b/library/DFProcess-linux-SHM.cpp index db161bc4e..9fe3684a5 100644 --- a/library/DFProcess-linux-SHM.cpp +++ b/library/DFProcess-linux-SHM.cpp @@ -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 ) { if(!d->locked) throw Error::MemoryAccessDenied(); @@ -647,16 +637,6 @@ void SHMProcess::readByte (const uint32_t offset, uint8_t &val ) 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) { if(!d->locked) throw Error::MemoryAccessDenied(); @@ -667,15 +647,6 @@ void SHMProcess::readWord (const uint32_t offset, uint16_t &val) 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) { if(!d->locked) throw Error::MemoryAccessDenied(); @@ -686,15 +657,6 @@ void SHMProcess::readDWord (const uint32_t offset, uint32_t &val) 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) { if(!d->locked) throw Error::MemoryAccessDenied(); @@ -705,15 +667,6 @@ void SHMProcess::readQuad (const uint32_t offset, uint64_t &val) 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 (D_SHMHDR->value); -} void SHMProcess::readFloat (const uint32_t offset, float &val) { if(!d->locked) throw Error::MemoryAccessDenied(); @@ -817,7 +770,7 @@ const std::string SHMProcess::readCString (uint32_t offset) char r; do { - r = readByte(offset+counter); + r = Process::readByte(offset+counter); temp_c[counter] = r; counter++; } while (r && counter < 255); @@ -864,8 +817,8 @@ string SHMProcess::readClassName (uint32_t vptr) { if(!d->locked) throw Error::MemoryAccessDenied(); - int typeinfo = readDWord(vptr - 0x4); - int typestring = readDWord(typeinfo + 0x4); + int typeinfo = Process::readDWord(vptr - 0x4); + int typestring = Process::readDWord(typeinfo + 0x4); string raw = readCString(typestring); size_t start = raw.find_first_of("abcdefghijklmnopqrstuvwxyz");// trim numbers size_t end = raw.length(); diff --git a/library/DFProcess-linux-wine.cpp b/library/DFProcess-linux-wine.cpp index e3b40502f..7f880afbb 100644 --- a/library/DFProcess-linux-wine.cpp +++ b/library/DFProcess-linux-wine.cpp @@ -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 ) { 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) { 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) { 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) { 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); } -uint64_t WineProcess::readQuad (const uint32_t offset) -{ - uint64_t val; - read(offset, 8, (uint8_t *) &val); - return val; -} - /* * WRITING */ @@ -470,7 +437,7 @@ void WineProcess::writeQuad (uint32_t offset, const uint64_t data) void WineProcess::writeDWord (uint32_t offset, uint32_t data) { #ifdef HAVE_64_BIT - uint64_t orig = readQuad(offset); + uint64_t orig = Process::readQuad(offset); orig &= 0xFFFFFFFF00000000; orig |= data; 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) { #ifdef HAVE_64_BIT - uint64_t orig = readQuad(offset); + uint64_t orig = Process::readQuad(offset); orig &= 0xFFFFFFFFFFFF0000; orig |= data; 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) { #ifdef HAVE_64_BIT - uint64_t orig = readQuad(offset); + uint64_t orig = Process::readQuad(offset); orig &= 0xFFFFFFFFFFFFFF00; orig |= data; ptrace(PTRACE_POKEDATA,d->my_handle, offset, orig); @@ -560,7 +527,7 @@ const std::string WineProcess::readCString (uint32_t offset) char r; do { - r = readByte(offset+counter); + r = Process::readByte(offset+counter); temp_c[counter] = r; counter++; } 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) { uint32_t start_offset = offset + d->STLSTR_buf_off; - size_t length = readDWord(offset + d->STLSTR_size_off); - size_t capacity = readDWord(offset + d->STLSTR_cap_off); + size_t length = Process::readDWord(offset + d->STLSTR_size_off); + size_t capacity = Process::readDWord(offset + d->STLSTR_cap_off); 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 { - 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); } @@ -595,8 +562,8 @@ size_t WineProcess::readSTLString (uint32_t offset, char * buffer, size_t bufcap const string WineProcess::readSTLString (uint32_t offset) { uint32_t start_offset = offset + d->STLSTR_buf_off; - size_t length = readDWord(offset + d->STLSTR_size_off); - size_t capacity = readDWord(offset + d->STLSTR_cap_off); + size_t length = Process::readDWord(offset + d->STLSTR_size_off); + size_t capacity = Process::readDWord(offset + d->STLSTR_cap_off); 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 { - 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); } @@ -619,8 +586,8 @@ const string WineProcess::readSTLString (uint32_t offset) string WineProcess::readClassName (uint32_t vptr) { - int rtti = readDWord(vptr - 0x4); - int typeinfo = readDWord(rtti + 0xC); + int rtti = Process::readDWord(vptr - 0x4); + int typeinfo = Process::readDWord(rtti + 0xC); string raw = readCString(typeinfo + 0xC); // skips the .?AV raw.resize(raw.length() - 2);// trim @@ from end return raw; diff --git a/library/DFProcess-linux.cpp b/library/DFProcess-linux.cpp index 860f4ee16..284bb2dc2 100644 --- a/library/DFProcess-linux.cpp +++ b/library/DFProcess-linux.cpp @@ -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 ) { 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) { 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) { 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) { 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) { 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) { #ifdef HAVE_64_BIT - uint64_t orig = readQuad(offset); + uint64_t orig = Process::readQuad(offset); orig &= 0xFFFFFFFF00000000; orig |= data; 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) { #ifdef HAVE_64_BIT - uint64_t orig = readQuad(offset); + uint64_t orig = Process::readQuad(offset); orig &= 0xFFFFFFFFFFFF0000; orig |= data; 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) { #ifdef HAVE_64_BIT - uint64_t orig = readQuad(offset); + uint64_t orig = Process::readQuad(offset); orig &= 0xFFFFFFFFFFFFFF00; orig |= data; ptrace(PTRACE_POKEDATA,d->my_handle, offset, orig); @@ -536,7 +504,7 @@ const std::string NormalProcess::readCString (uint32_t offset) char r; do { - r = readByte(offset+counter); + r = Process::readByte(offset+counter); temp_c[counter] = r; counter++; } while (r && counter < 255); @@ -555,7 +523,7 @@ struct _Rep_base size_t NormalProcess::readSTLString (uint32_t offset, char * buffer, size_t bufcapacity) { _Rep_base header; - offset = readDWord(offset); + offset = Process::readDWord(offset); 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 read(offset,read_real,(uint8_t * )buffer); @@ -567,7 +535,7 @@ const string NormalProcess::readSTLString (uint32_t offset) { _Rep_base header; - offset = readDWord(offset); + offset = Process::readDWord(offset); read(offset - sizeof(_Rep_base),sizeof(_Rep_base),(uint8_t *)&header); // FIXME: use char* everywhere, avoid string @@ -580,8 +548,8 @@ const string NormalProcess::readSTLString (uint32_t offset) string NormalProcess::readClassName (uint32_t vptr) { - int typeinfo = readDWord(vptr - 0x4); - int typestring = readDWord(typeinfo + 0x4); + int typeinfo = Process::readDWord(vptr - 0x4); + int typestring = Process::readDWord(typeinfo + 0x4); string raw = readCString(typestring); size_t start = raw.find_first_of("abcdefghijklmnopqrstuvwxyz");// trim numbers size_t end = raw.length(); diff --git a/library/DFProcess-windows-SHM.cpp b/library/DFProcess-windows-SHM.cpp index d01de5c01..4d23d8837 100644 --- a/library/DFProcess-windows-SHM.cpp +++ b/library/DFProcess-windows-SHM.cpp @@ -340,7 +340,7 @@ bool SHMProcess::Private::validate(vector & known_versions) uint32_t base = (uint32_t)hmod; // 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), sizeof(sections) , (uint8_t *)§ions ); @@ -436,7 +436,7 @@ void SHMProcess::getMemRanges( vector & ranges ) t_memrange temp; uint32_t base = d->memdescriptor->getBase(); 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.write = 1; 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 ) { if(!d->locked) throw Error::MemoryAccessDenied(); @@ -708,16 +698,6 @@ void SHMProcess::readByte (const uint32_t offset, uint8_t &val ) 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) { if(!d->locked) throw Error::MemoryAccessDenied(); @@ -728,15 +708,6 @@ void SHMProcess::readWord (const uint32_t offset, uint16_t &val) 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) { if(!d->locked) throw Error::MemoryAccessDenied(); @@ -747,15 +718,6 @@ void SHMProcess::readDWord (const uint32_t offset, uint32_t &val) 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 (D_SHMHDR->value); -} void SHMProcess::readFloat (const uint32_t offset, float &val) { if(!d->locked) throw Error::MemoryAccessDenied(); @@ -765,15 +727,7 @@ void SHMProcess::readFloat (const uint32_t offset, float &val) d->SetAndWait(CORE_READ_DWORD); val = reinterpret_cast (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) { if(!d->locked) throw Error::MemoryAccessDenied(); @@ -878,7 +832,7 @@ const std::string SHMProcess::readCString (uint32_t offset) char r; do { - r = readByte(offset+counter); + r = Process::readByte(offset+counter); temp_c[counter] = r; counter++; } 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) { - int rtti = readDWord(vptr - 0x4); - int typeinfo = readDWord(rtti + 0xC); + int rtti = Process::readDWord(vptr - 0x4); + int typeinfo = Process::readDWord(rtti + 0xC); string raw = readCString(typeinfo + 0xC); // skips the .?AV raw.resize(raw.length() - 2);// trim @@ from end return raw; diff --git a/library/DFProcess-windows.cpp b/library/DFProcess-windows.cpp index 72940dd43..0d7d32f8c 100644 --- a/library/DFProcess-windows.cpp +++ b/library/DFProcess-windows.cpp @@ -90,7 +90,7 @@ NormalProcess::NormalProcess(uint32_t pid, vector & known_versio // read from this process 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); const size_t sectionsSize = sizeof(IMAGE_SECTION_HEADER) * d->pe_header.FileHeader.NumberOfSections; d->sections = (IMAGE_SECTION_HEADER *) malloc(sectionsSize); @@ -417,70 +417,30 @@ void NormalProcess::getMemRanges( vector & 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) { if(!ReadProcessMemory(d->my_handle, (int*) offset, &result, sizeof(uint8_t), NULL)) 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) { if(!ReadProcessMemory(d->my_handle, (int*) offset, &result, sizeof(uint16_t), NULL)) 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) { if(!ReadProcessMemory(d->my_handle, (int*) offset, &result, sizeof(uint32_t), NULL)) 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) { if(!ReadProcessMemory(d->my_handle, (int*) offset, &result, sizeof(uint64_t), NULL)) 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) { 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) { uint32_t start_offset = offset + d->STLSTR_buf_off; - size_t length = readDWord(offset + d->STLSTR_size_off); - size_t capacity = readDWord(offset + d->STLSTR_cap_off); + size_t length = Process::readDWord(offset + d->STLSTR_size_off); + size_t capacity = Process::readDWord(offset + d->STLSTR_cap_off); size_t read_real = min(length, bufcapacity-1);// keep space for null termination // 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 { - 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); } @@ -566,8 +526,8 @@ size_t NormalProcess::readSTLString (uint32_t offset, char * buffer, size_t bufc const string NormalProcess::readSTLString (uint32_t offset) { uint32_t start_offset = offset + d->STLSTR_buf_off; - size_t length = readDWord(offset + d->STLSTR_size_off); - size_t capacity = readDWord(offset + d->STLSTR_cap_off); + size_t length = Process::readDWord(offset + d->STLSTR_size_off); + size_t capacity = Process::readDWord(offset + d->STLSTR_cap_off); char * temp = new char[capacity+1]; // 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 { - 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); } @@ -589,8 +549,8 @@ const string NormalProcess::readSTLString (uint32_t offset) string NormalProcess::readClassName (uint32_t vptr) { - int rtti = readDWord(vptr - 0x4); - int typeinfo = readDWord(rtti + 0xC); + int rtti = Process::readDWord(vptr - 0x4); + int typeinfo = Process::readDWord(rtti + 0xC); string raw = readCString(typeinfo + 0xC); // skips the .?AV raw.resize(raw.length() - 2);// trim @@ from end return raw; @@ -604,4 +564,4 @@ string NormalProcess::getPath() GetModuleFileNameEx(d->my_handle,hmod,String,sizeof(String)); //get the filename from the module string out(String); return(out.substr(0,out.find_last_of("\\"))); -} \ No newline at end of file +} diff --git a/library/include/dfhack/DFProcess.h b/library/include/dfhack/DFProcess.h index d0159cce4..7e81a94de 100644 --- a/library/include/dfhack/DFProcess.h +++ b/library/include/dfhack/DFProcess.h @@ -99,33 +99,33 @@ namespace DFHack virtual bool forceresume() = 0; /// 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 virtual void readQuad(const uint32_t address, uint64_t & value) = 0; /// write a 8-byte integer virtual void writeQuad(const uint32_t address, const uint64_t value) = 0; /// 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 virtual void readDWord(const uint32_t address, uint32_t & value) = 0; /// write a 4-byte integer virtual void writeDWord(const uint32_t address, const uint32_t value) = 0; /// 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 virtual void readFloat(const uint32_t address, float & value) = 0; /// 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 virtual void readWord(const uint32_t address, uint16_t & value) = 0; /// write a 2-byte integer virtual void writeWord(const uint32_t address, const uint16_t value) = 0; /// 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 virtual void readByte(const uint32_t address, uint8_t & value) = 0; /// write a byte diff --git a/library/private/ProcessInternal.h b/library/private/ProcessInternal.h index 9e048bc7b..0bca44d54 100644 --- a/library/private/ProcessInternal.h +++ b/library/private/ProcessInternal.h @@ -50,22 +50,17 @@ namespace DFHack bool resume(); bool forceresume(); - uint64_t readQuad(const uint32_t address); void readQuad(const uint32_t address, 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 writeDWord(const uint32_t address, const uint32_t value); - float readFloat(const uint32_t address); 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 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 writeByte(const uint32_t address, const uint8_t value); @@ -116,22 +111,17 @@ namespace DFHack bool resume(); bool forceresume(); - uint64_t readQuad(const uint32_t address); void readQuad(const uint32_t address, 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 writeDWord(const uint32_t address, const uint32_t value); - float readFloat(const uint32_t address); 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 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 writeByte(const uint32_t address, const uint8_t value); @@ -181,22 +171,17 @@ namespace DFHack bool resume(); bool forceresume(); - uint64_t readQuad(const uint32_t address); void readQuad(const uint32_t address, 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 writeDWord(const uint32_t address, const uint32_t value); - float readFloat(const uint32_t address); 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 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 writeByte(const uint32_t address, const uint8_t value);