Use std::vector to hold the xex header instead of new/delete
This commit is contained in:
parent
b2241e3fef
commit
f9977a25af
|
@ -41,20 +41,12 @@ XexModule::XexModule(Processor* processor, KernelState* kernel_state)
|
||||||
processor_(processor),
|
processor_(processor),
|
||||||
kernel_state_(kernel_state),
|
kernel_state_(kernel_state),
|
||||||
xex_(nullptr),
|
xex_(nullptr),
|
||||||
xex_header_(nullptr),
|
|
||||||
base_address_(0),
|
base_address_(0),
|
||||||
low_address_(0),
|
low_address_(0),
|
||||||
high_address_(0),
|
high_address_(0),
|
||||||
loaded_(false) {}
|
loaded_(false) {}
|
||||||
|
|
||||||
XexModule::~XexModule() {
|
XexModule::~XexModule() { xe_xex2_dealloc(xex_); }
|
||||||
xe_xex2_dealloc(xex_);
|
|
||||||
|
|
||||||
if (xex_header_) {
|
|
||||||
delete[] xex_header_;
|
|
||||||
xex_header_ = nullptr;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bool XexModule::GetOptHeader(const xex2_header* header, xe_xex2_header_keys key,
|
bool XexModule::GetOptHeader(const xex2_header* header, xe_xex2_header_keys key,
|
||||||
void** out_ptr) {
|
void** out_ptr) {
|
||||||
|
@ -89,7 +81,7 @@ bool XexModule::GetOptHeader(const xex2_header* header, xe_xex2_header_keys key,
|
||||||
}
|
}
|
||||||
|
|
||||||
bool XexModule::GetOptHeader(xe_xex2_header_keys key, void** out_ptr) const {
|
bool XexModule::GetOptHeader(xe_xex2_header_keys key, void** out_ptr) const {
|
||||||
return XexModule::GetOptHeader(xex_header_, key, out_ptr);
|
return XexModule::GetOptHeader(xex_header(), key, out_ptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
const xex2_security_info* XexModule::GetSecurityInfo(
|
const xex2_security_info* XexModule::GetSecurityInfo(
|
||||||
|
@ -207,9 +199,9 @@ bool XexModule::Load(const std::string& name, const std::string& path,
|
||||||
|
|
||||||
// Make a copy of the xex header.
|
// Make a copy of the xex header.
|
||||||
auto src_header = reinterpret_cast<const xex2_header*>(xex_addr);
|
auto src_header = reinterpret_cast<const xex2_header*>(xex_addr);
|
||||||
xex_header_ = (xex2_header*)new char[src_header->header_size];
|
xex_header_mem_.resize(src_header->header_size);
|
||||||
|
|
||||||
std::memcpy(xex_header_, src_header, src_header->header_size);
|
std::memcpy(xex_header_mem_.data(), src_header, src_header->header_size);
|
||||||
|
|
||||||
return Load(name, path, xex_);
|
return Load(name, path, xex_);
|
||||||
}
|
}
|
||||||
|
@ -220,7 +212,7 @@ bool XexModule::Load(const std::string& name, const std::string& path,
|
||||||
loaded_ = true;
|
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_);
|
||||||
|
|
||||||
// Setup debug info.
|
// Setup debug info.
|
||||||
|
@ -311,10 +303,7 @@ bool XexModule::Unload() {
|
||||||
assert_not_zero(exe_address);
|
assert_not_zero(exe_address);
|
||||||
|
|
||||||
memory()->LookupHeap(*exe_address)->Release(*exe_address);
|
memory()->LookupHeap(*exe_address)->Release(*exe_address);
|
||||||
|
xex_header_mem_.resize(0);
|
||||||
assert_not_null(xex_header_); // Unloading a module that wasn't loaded?
|
|
||||||
delete[] xex_header_;
|
|
||||||
xex_header_ = nullptr;
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,9 +34,11 @@ class XexModule : public xe::cpu::Module {
|
||||||
|
|
||||||
xe_xex2_ref xex() const { return xex_; }
|
xe_xex2_ref xex() const { return xex_; }
|
||||||
bool loaded() const { return loaded_; }
|
bool loaded() const { return loaded_; }
|
||||||
const xex2_header* xex_header() const { return xex_header_; }
|
const xex2_header* xex_header() const {
|
||||||
|
return reinterpret_cast<const xex2_header*>(xex_header_mem_.data());
|
||||||
|
}
|
||||||
const xex2_security_info* xex_security_info() const {
|
const xex2_security_info* xex_security_info() const {
|
||||||
return GetSecurityInfo(xex_header_);
|
return GetSecurityInfo(xex_header());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Gets an optional header. Returns NULL if not found.
|
// Gets an optional header. Returns NULL if not found.
|
||||||
|
@ -86,7 +88,7 @@ class XexModule : public xe::cpu::Module {
|
||||||
std::string name_;
|
std::string name_;
|
||||||
std::string path_;
|
std::string path_;
|
||||||
xe_xex2_ref xex_;
|
xe_xex2_ref xex_;
|
||||||
xex2_header* xex_header_;
|
std::vector<uint8_t> xex_header_mem_; // Holds the xex header
|
||||||
bool loaded_; // Loaded into memory?
|
bool loaded_; // Loaded into memory?
|
||||||
|
|
||||||
uint32_t base_address_;
|
uint32_t base_address_;
|
||||||
|
|
Loading…
Reference in New Issue