Merge branch 'master' of https://github.com/tomprince/dfhack into tomprince-master
commit
d26f9ee4a4
@ -0,0 +1,96 @@
|
||||
/*
|
||||
www.sourceforge.net/projects/dfhack
|
||||
Copyright (c) 2009 Petr Mrázek (peterix), Kenneth Ferland (Impaler[WrG]), dorf
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any
|
||||
damages arising from the use of this software.
|
||||
|
||||
Permission is granted to anyone to use this software for any
|
||||
purpose, including commercial applications, and to alter it and
|
||||
redistribute it freely, subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must
|
||||
not claim that you wrote the original software. If you use this
|
||||
software in a product, an acknowledgment in the product documentation
|
||||
would be appreciated but is not required.
|
||||
|
||||
2. Altered source versions must be plainly marked as such, and
|
||||
must not be misrepresented as being the original software.
|
||||
|
||||
3. This notice may not be removed or altered from any source
|
||||
distribution.
|
||||
*/
|
||||
|
||||
#include "Internal.h"
|
||||
#include "MicrosoftSTL.h"
|
||||
#include "dfhack/DFProcess.h"
|
||||
#include "dfhack/VersionInfo.h"
|
||||
#include <string>
|
||||
using namespace DFHack;
|
||||
|
||||
void MicrosoftSTL::init(Process* self)
|
||||
{
|
||||
p = self;
|
||||
OffsetGroup * strGrp = p->getDescriptor()->getGroup("string")->getGroup("MSVC");
|
||||
STLSTR_buf_off = strGrp->getOffset("buffer");
|
||||
STLSTR_size_off = strGrp->getOffset("size");
|
||||
STLSTR_cap_off = strGrp->getOffset("capacity");
|
||||
}
|
||||
|
||||
size_t MicrosoftSTL::readSTLString (uint32_t offset, char * buffer, size_t bufcapacity)
|
||||
{
|
||||
uint32_t start_offset = offset + STLSTR_buf_off;
|
||||
size_t length = p->readDWord(offset + STLSTR_size_off);
|
||||
size_t capacity = p->readDWord(offset + STLSTR_cap_off);
|
||||
|
||||
size_t read_real = min(length, bufcapacity-1);// keep space for null termination
|
||||
|
||||
// read data from inside the string structure
|
||||
if(capacity < 16)
|
||||
{
|
||||
p->read(start_offset, read_real , (uint8_t *)buffer);
|
||||
}
|
||||
else // read data from what the offset + 4 dword points to
|
||||
{
|
||||
start_offset = p->readDWord(start_offset);// dereference the start offset
|
||||
p->read(start_offset, read_real, (uint8_t *)buffer);
|
||||
}
|
||||
|
||||
buffer[read_real] = 0;
|
||||
return read_real;
|
||||
}
|
||||
|
||||
const string MicrosoftSTL::readSTLString (uint32_t offset)
|
||||
{
|
||||
uint32_t start_offset = offset + STLSTR_buf_off;
|
||||
size_t length = p->readDWord(offset + STLSTR_size_off);
|
||||
size_t capacity = p->readDWord(offset + STLSTR_cap_off);
|
||||
|
||||
char * temp = new char[capacity+1];
|
||||
|
||||
// read data from inside the string structure
|
||||
if(capacity < 16)
|
||||
{
|
||||
p->read(start_offset, capacity, (uint8_t *)temp);
|
||||
}
|
||||
else // read data from what the offset + 4 dword points to
|
||||
{
|
||||
start_offset = p->readDWord(start_offset);// dereference the start offset
|
||||
p->read(start_offset, capacity, (uint8_t *)temp);
|
||||
}
|
||||
|
||||
temp[length] = 0;
|
||||
string ret = temp;
|
||||
delete temp;
|
||||
return ret;
|
||||
}
|
||||
|
||||
string MicrosoftSTL::readClassName (uint32_t vptr)
|
||||
{
|
||||
int rtti = p->readDWord(vptr - 0x4);
|
||||
int typeinfo = p->readDWord(rtti + 0xC);
|
||||
string raw = p->readCString(typeinfo + 0xC); // skips the .?AV
|
||||
raw.resize(raw.length() - 2);// trim @@ from end
|
||||
return raw;
|
||||
}
|
@ -0,0 +1,46 @@
|
||||
/*
|
||||
www.sourceforge.net/projects/dfhack
|
||||
Copyright (c) 2009 Petr Mrázek (peterix), Kenneth Ferland (Impaler[WrG]), dorf
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any
|
||||
damages arising from the use of this software.
|
||||
|
||||
Permission is granted to anyone to use this software for any
|
||||
purpose, including commercial applications, and to alter it and
|
||||
redistribute it freely, subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must
|
||||
not claim that you wrote the original software. If you use this
|
||||
software in a product, an acknowledgment in the product documentation
|
||||
would be appreciated but is not required.
|
||||
|
||||
2. Altered source versions must be plainly marked as such, and
|
||||
must not be misrepresented as being the original software.
|
||||
|
||||
3. This notice may not be removed or altered from any source
|
||||
distribution.
|
||||
*/
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace DFHack {
|
||||
class Process;
|
||||
class MicrosoftSTL
|
||||
{
|
||||
private:
|
||||
uint32_t STLSTR_buf_off;
|
||||
uint32_t STLSTR_size_off;
|
||||
uint32_t STLSTR_cap_off;
|
||||
|
||||
Process* p;
|
||||
public:
|
||||
void init(Process* p);
|
||||
|
||||
const std::string readSTLString (uint32_t offset);
|
||||
size_t readSTLString (uint32_t offset, char * buffer, size_t bufcapacity);
|
||||
void writeSTLString(const uint32_t address, const std::string writeString){};
|
||||
// get class name of an object with rtti/type info
|
||||
std::string readClassName(uint32_t vptr);
|
||||
};
|
||||
}
|
@ -1,93 +0,0 @@
|
||||
/*
|
||||
www.sourceforge.net/projects/dfhack
|
||||
Copyright (c) 2009 Petr Mrázek (peterix), Kenneth Ferland (Impaler[WrG]), dorf
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any
|
||||
damages arising from the use of this software.
|
||||
|
||||
Permission is granted to anyone to use this software for any
|
||||
purpose, including commercial applications, and to alter it and
|
||||
redistribute it freely, subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must
|
||||
not claim that you wrote the original software. If you use this
|
||||
software in a product, an acknowledgment in the product documentation
|
||||
would be appreciated but is not required.
|
||||
|
||||
2. Altered source versions must be plainly marked as such, and
|
||||
must not be misrepresented as being the original software.
|
||||
|
||||
3. This notice may not be removed or altered from any source
|
||||
distribution.
|
||||
*/
|
||||
|
||||
#ifndef WINDOWS_PROCESS_H_INCLUDED
|
||||
#define WINDOWS_PROCESS_H_INCLUDED
|
||||
#ifndef LINUX_BUILD
|
||||
|
||||
#include "dfhack/DFProcess.h"
|
||||
|
||||
namespace DFHack
|
||||
{
|
||||
class NormalProcess : public Process
|
||||
{
|
||||
class Private;
|
||||
private:
|
||||
Private * const d;
|
||||
public:
|
||||
NormalProcess(uint32_t pid, std::vector <VersionInfo *> & known_versions);
|
||||
~NormalProcess();
|
||||
bool attach();
|
||||
bool detach();
|
||||
|
||||
bool suspend();
|
||||
bool asyncSuspend();
|
||||
bool resume();
|
||||
bool forceresume();
|
||||
|
||||
void readQuad(const uint32_t address, uint64_t & value);
|
||||
void writeQuad(const uint32_t address, const uint64_t value);
|
||||
|
||||
void readDWord(const uint32_t address, uint32_t & value);
|
||||
void writeDWord(const uint32_t address, const uint32_t value);
|
||||
|
||||
void readFloat(const uint32_t address, float & value);
|
||||
|
||||
void readWord(const uint32_t address, uint16_t & value);
|
||||
void writeWord(const uint32_t address, const uint16_t value);
|
||||
|
||||
void readByte(const uint32_t address, uint8_t & value);
|
||||
void writeByte(const uint32_t address, const uint8_t value);
|
||||
|
||||
void read( uint32_t address, uint32_t length, uint8_t* buffer);
|
||||
void write(uint32_t address, uint32_t length, uint8_t* buffer);
|
||||
|
||||
const std::string readSTLString (uint32_t offset);
|
||||
size_t readSTLString (uint32_t offset, char * buffer, size_t bufcapacity);
|
||||
void writeSTLString(const uint32_t address, const std::string writeString){};
|
||||
// get class name of an object with rtti/type info
|
||||
std::string readClassName(uint32_t vptr);
|
||||
|
||||
const std::string readCString (uint32_t offset);
|
||||
|
||||
bool isSuspended();
|
||||
bool isAttached();
|
||||
bool isIdentified();
|
||||
|
||||
bool getThreadIDs(std::vector<uint32_t> & threads );
|
||||
void getMemRanges(std::vector<t_memrange> & ranges );
|
||||
VersionInfo *getDescriptor();
|
||||
int getPID();
|
||||
std::string getPath();
|
||||
// get module index by name and version. bool 1 = error
|
||||
bool getModuleIndex (const char * name, const uint32_t version, uint32_t & OUTPUT) { OUTPUT=0; return false;};
|
||||
// get the SHM start if available
|
||||
char * getSHMStart (void){return 0;};
|
||||
// set a SHM command and wait for a response
|
||||
bool SetAndWait (uint32_t state){return false;};
|
||||
};
|
||||
|
||||
}
|
||||
#endif
|
||||
#endif
|
Loading…
Reference in New Issue