XexModule keep track of whether it's loaded into memory or not

This commit is contained in:
Dr. Chat 2015-07-06 10:40:35 -05:00
parent 6ddd0b4700
commit 93f24d2047
2 changed files with 12 additions and 1 deletions

View File

@ -44,7 +44,8 @@ XexModule::XexModule(Processor* processor, KernelState* kernel_state)
xex_header_(nullptr), xex_header_(nullptr),
base_address_(0), base_address_(0),
low_address_(0), low_address_(0),
high_address_(0) {} high_address_(0),
loaded_(false) {}
XexModule::~XexModule() { XexModule::~XexModule() {
xe_xex2_dealloc(xex_); xe_xex2_dealloc(xex_);
@ -215,7 +216,10 @@ bool XexModule::Load(const std::string& name, const std::string& path,
bool XexModule::Load(const std::string& name, const std::string& path, bool XexModule::Load(const std::string& name, const std::string& path,
xe_xex2_ref xex) { xe_xex2_ref xex) {
assert_false(loaded_);
loaded_ = true;
xex_ = xex; xex_ = xex;
auto header = xex_header_; auto header = xex_header_;
auto old_header = xe_xex2_get_header(xex_); auto old_header = xe_xex2_get_header(xex_);
@ -296,6 +300,11 @@ bool XexModule::Load(const std::string& name, const std::string& path,
} }
bool XexModule::Unload() { bool XexModule::Unload() {
if (!loaded_) {
return true;
}
loaded_ = false;
// Just deallocate the memory occupied by the exe // Just deallocate the memory occupied by the exe
xe::be<uint32_t>* exe_address = 0; xe::be<uint32_t>* exe_address = 0;
GetOptHeader(XEX_HEADER_IMAGE_BASE_ADDRESS, &exe_address); GetOptHeader(XEX_HEADER_IMAGE_BASE_ADDRESS, &exe_address);

View File

@ -33,6 +33,7 @@ class XexModule : public xe::cpu::Module {
virtual ~XexModule(); virtual ~XexModule();
xe_xex2_ref xex() const { return xex_; } xe_xex2_ref xex() const { return xex_; }
bool loaded() const { return loaded_; }
const xex2_header* xex_header() const { return xex_header_; } const xex2_header* xex_header() const { return xex_header_; }
const xex2_security_info* xex_security_info() const { const xex2_security_info* xex_security_info() const {
return GetSecurityInfo(xex_header_); return GetSecurityInfo(xex_header_);
@ -86,6 +87,7 @@ class XexModule : public xe::cpu::Module {
std::string path_; std::string path_;
xe_xex2_ref xex_; xe_xex2_ref xex_;
xex2_header* xex_header_; xex2_header* xex_header_;
bool loaded_; // Loaded into memory?
uint32_t base_address_; uint32_t base_address_;
uint32_t low_address_; uint32_t low_address_;