Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

reorganize/tidy Process-*.cpp source units #5138

Merged
merged 2 commits into from
Dec 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 26 additions & 21 deletions library/Process-darwin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,33 +21,44 @@ must not be misrepresented as being the original software.
3. This notice may not be removed or altered from any source
distribution.
*/
#include <cstring>
#include <cstdio>
#include <map>
#include <set>
#include <string>
#include <vector>

#include "Internal.h"
#include <dirent.h>
#include <errno.h>
#include <unistd.h>
#include <sys/mman.h>
#include <sys/time.h>
#include <unistd.h>
#include <string.h>

#include <mach-o/dyld.h>
#include <mach/mach.h>
#include <mach/mach_vm.h>
#include <mach/vm_region.h>
#include <mach/vm_statistics.h>
#include <dlfcn.h>

#include <string>
#include <vector>
#include <map>
#include <set>
#include <cstdio>
#include <cstring>
using namespace std;

#include <md5wrapper.h>
#include "Error.h"
#include "Internal.h"
#include "MemAccess.h"
#include "Memory.h"
#include "VersionInfoFactory.h"
#include "VersionInfo.h"
#include "Error.h"
#include <string.h>
#include "VersionInfoFactory.h"
#include "md5wrapper.h"
using namespace DFHack;

using std::string;
using std::map;
using std::vector;
using std::endl;
using std::cerr;


Process::Process(const VersionInfoFactory& known_versions) : identified(false), my_pe(0)
{
char path[1024];
Expand All @@ -67,8 +78,8 @@ Process::Process(const VersionInfoFactory& known_versions) : identified(false),
auto vinfo = known_versions.getVersionInfoByMD5(my_md5);
if(vinfo)
{
my_descriptor = std::make_shared<VersionInfo>(*vinfo);
identified = true;
my_descriptor = std::make_shared<VersionInfo>(*vinfo);
}
else
{
Expand Down Expand Up @@ -115,17 +126,11 @@ string Process::doReadClassName (void * vptr)
char * typeinfo = Process::readPtr(((char *)vptr - sizeof(void*)));
char * typestring = Process::readPtr(typeinfo + sizeof(void*));
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();
return raw.substr(start,end-start);
}

#include <mach/mach.h>
#include <mach/mach_vm.h>
#include <mach/vm_region.h>
#include <mach/vm_statistics.h>
#include <dlfcn.h>

const char *
inheritance_strings[] = {
"SHARE", "COPY", "NONE", "DONATE_COPY",
Expand Down
23 changes: 15 additions & 8 deletions library/Process-linux.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,30 +22,37 @@ must not be misrepresented as being the original software.
distribution.
*/

#include <cstdio>
#include <cstring>
#include <dirent.h>
#include <errno.h>
#include <cstdio>
#include <cstdlib>
#include <map>
#include <set>
#include <string>
#include <vector>

#include <dirent.h>
#include <errno.h>
#include <sys/mman.h>
#include <sys/time.h>
#include <unistd.h>
#include <vector>

#include "Error.h"
#include "Internal.h"
#include "md5wrapper.h"
#include "MemAccess.h"
#include "Memory.h"
#include "modules/Filesystem.h"
#include "VersionInfo.h"
#include "VersionInfoFactory.h"
#include "modules/Filesystem.h"
#include "md5wrapper.h"

using namespace std;
using namespace DFHack;

using std::string;
using std::map;
using std::vector;
using std::endl;
using std::cerr;

Process::Process(const VersionInfoFactory& known_versions) : identified(false), my_pe(0)
{
const char * exe_link_name = "/proc/self/exe";
Expand All @@ -69,8 +76,8 @@ Process::Process(const VersionInfoFactory& known_versions) : identified(false),
auto vinfo = known_versions.getVersionInfoByMD5(my_md5);
if(vinfo)
{
my_descriptor = std::make_shared<VersionInfo>(*vinfo);
identified = true;
my_descriptor = std::make_shared<VersionInfo>(*vinfo);
}
else
{
Expand Down
83 changes: 49 additions & 34 deletions library/Process-windows.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,29 +22,37 @@ must not be misrepresented as being the original software.
distribution.
*/

#include "Internal.h"

#define _WIN32_WINNT 0x0501
#define WINVER 0x0501

#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <psapi.h>

#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <string>
#include <map>
using namespace std;
#include <set>
#include <string>
#include <vector>

#include "VersionInfo.h"
#include "VersionInfoFactory.h"
#include "Error.h"
#include "Internal.h"
#include "MemAccess.h"
#include "Memory.h"
#include "VersionInfo.h"
#include "VersionInfoFactory.h"

#define _WIN32_WINNT 0x0600
#define WINVER 0x0600

#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <psapi.h>

using namespace DFHack;

using std::string;
using std::map;
using std::vector;
using std::endl;
using std::cerr;


namespace DFHack
{
class PlatformSpecific
Expand All @@ -62,6 +70,7 @@ namespace DFHack
char * base;
};
}

Process::Process(const VersionInfoFactory& factory) : identified(false)
{
HMODULE hmod = NULL;
Expand Down Expand Up @@ -90,7 +99,7 @@ Process::Process(const VersionInfoFactory& factory) : identified(false)
d->sections = (IMAGE_SECTION_HEADER *) malloc(sectionsSize);
read(d->base + pe_offset + sizeof(d->pe_header), sectionsSize, (uint8_t *)(d->sections));
}
catch (exception &)
catch (std::exception &)
{
return;
}
Expand All @@ -117,6 +126,25 @@ Process::~Process()
free(d->sections);
}

string Process::doReadClassName (void * vptr)
{
char * rtti = readPtr((char *)vptr - sizeof(void*));
#ifdef DFHACK64
void *base;
if (!RtlPcToFileHeader(rtti, &base))
return "dummy";
char * typeinfo = (char *)base + readDWord(rtti + 0xC);
string raw = readCString(typeinfo + 0x10+4); // skips the .?AV
#else
char * typeinfo = readPtr(rtti + 0xC);
string raw = readCString(typeinfo + 0xC); // skips the .?AV
#endif
if (!raw.length())
return "dummy";
raw.resize(raw.length() - 2);// trim @@ from end
return raw;
}

/*
typedef struct _MEMORY_BASIC_INFORMATION
{
Expand Down Expand Up @@ -341,25 +369,6 @@ int Process::adjustOffset(int offset, bool to_file)
return -1;
}

string Process::doReadClassName (void * vptr)
{
char * rtti = readPtr((char *)vptr - sizeof(void*));
#ifdef DFHACK64
void *base;
if (!RtlPcToFileHeader(rtti, &base))
return "dummy";
char * typeinfo = (char *)base + readDWord(rtti + 0xC);
string raw = readCString(typeinfo + 0x10+4); // skips the .?AV
#else
char * typeinfo = readPtr(rtti + 0xC);
string raw = readCString(typeinfo + 0xC); // skips the .?AV
#endif
if (!raw.length())
return "dummy";
raw.resize(raw.length() - 2);// trim @@ from end
return raw;
}

uint32_t Process::getTickCount()
{
return GetTickCount();
Expand All @@ -376,6 +385,12 @@ string Process::getPath()
return(out.substr(0,out.find_last_of("\\")));
}

int Process::getPID()
{
return (int) GetCurrentProcessId();
}


bool Process::setPermisions(const t_memrange & range,const t_memrange &trgrange)
{
DWORD newprotect=0;
Expand Down
Loading