diff --git a/library/Process-darwin.cpp b/library/Process-darwin.cpp index d6988d5d6..69defbf92 100644 --- a/library/Process-darwin.cpp +++ b/library/Process-darwin.cpp @@ -41,6 +41,7 @@ using namespace std; #include #include "MemAccess.h" +#include "Memory.h" #include "VersionInfoFactory.h" #include "VersionInfo.h" #include "Error.h" @@ -241,7 +242,7 @@ void Process::getMemRanges( vector & ranges ) uintptr_t Process::getBase() { - return 0x1000; + return DEFAULT_BASE_ADDR; // Memory.h } int Process::adjustOffset(int offset, bool /*to_file*/) diff --git a/library/Process-linux.cpp b/library/Process-linux.cpp index 14c70a802..7a72171ca 100644 --- a/library/Process-linux.cpp +++ b/library/Process-linux.cpp @@ -39,6 +39,7 @@ using namespace std; #include #include "MemAccess.h" +#include "Memory.h" #include "VersionInfoFactory.h" #include "VersionInfo.h" #include "Error.h" @@ -167,7 +168,7 @@ void Process::getMemRanges( vector & ranges ) uintptr_t Process::getBase() { - return 0x8048000; + return DEFAULT_BASE_ADDR; // Memory.h } int Process::adjustOffset(int offset, bool /*to_file*/) diff --git a/library/Process-windows.cpp b/library/Process-windows.cpp index 5474d7cfb..b9e58462b 100644 --- a/library/Process-windows.cpp +++ b/library/Process-windows.cpp @@ -43,6 +43,7 @@ using namespace std; #include "VersionInfoFactory.h" #include "Error.h" #include "MemAccess.h" +#include "Memory.h" using namespace DFHack; namespace DFHack { @@ -306,7 +307,7 @@ uintptr_t Process::getBase() { if(d) return (uintptr_t) d->base; - return 0x400000; + return DEFAULT_BASE_ADDR; // Memory.h } int Process::adjustOffset(int offset, bool to_file) diff --git a/library/VersionInfoFactory.cpp b/library/VersionInfoFactory.cpp index 02dac568c..672f5a9c8 100644 --- a/library/VersionInfoFactory.cpp +++ b/library/VersionInfoFactory.cpp @@ -34,6 +34,7 @@ using namespace std; #include "VersionInfoFactory.h" #include "VersionInfo.h" #include "Error.h" +#include "Memory.h" using namespace DFHack; #include @@ -98,25 +99,20 @@ void VersionInfoFactory::ParseVersion (TiXmlElement* entry, VersionInfo* mem) if(os == "windows") { mem->setOS(OS_WINDOWS); - // set default image base. this is fixed for base relocation later - mem->setBase(0x400000); } else if(os == "linux") { mem->setOS(OS_LINUX); - // this is wrong... I'm not going to do base image relocation on linux though. - mem->setBase(0x8048000); } else if(os == "darwin") { mem->setOS(OS_APPLE); - // this is wrong... I'm not going to do base image relocation on linux though. - mem->setBase(0x1000); } else { return; // ignore it if it's invalid } + mem->setBase(DEFAULT_BASE_ADDR); // Memory.h // process additional entries //cout << "Entry " << cstr_version << " " << cstr_os << endl; diff --git a/library/include/Memory.h b/library/include/Memory.h new file mode 100644 index 000000000..1016f2966 --- /dev/null +++ b/library/include/Memory.h @@ -0,0 +1,22 @@ +// Default base address +#if defined(_WIN32) + #ifdef DFHACK64 + #define DEFAULT_BASE_ADDR 0x140000000 + #else + #define DEFAULT_BASE_ADDR 0x400000 + #endif +#elif defined(_DARWIN) + #ifdef DFHACK64 + #define DEFAULT_BASE_ADDR 0x1000 + #else + #define DEFAULT_BASE_ADDR 0x1000 + #endif +#elif defined(_LINUX) + #ifdef DFHACK64 + #define DEFAULT_BASE_ADDR 0x8048000 + #else + #define DEFAULT_BASE_ADDR 0x8048000 + #endif +#else + #error Unknown OS +#endif