Use HMODULE instead of handles for xex modules

This commit is contained in:
Dr. Chat
2015-06-27 22:00:58 -05:00
parent 1289e7ad22
commit 7372dd4d8d
5 changed files with 126 additions and 41 deletions

View File

@@ -20,7 +20,8 @@ XModule::XModule(KernelState* kernel_state, ModuleType module_type,
: XObject(kernel_state, kTypeModule),
module_type_(module_type),
path_(path),
processor_module_(nullptr) {
processor_module_(nullptr),
hmodule_ptr_(0) {
auto last_slash = path.find_last_of('/');
if (last_slash == path.npos) {
last_slash = path.find_last_of('\\');
@@ -34,9 +35,22 @@ XModule::XModule(KernelState* kernel_state, ModuleType module_type,
if (dot != name_.npos) {
name_ = name_.substr(0, dot);
}
// Loader data (HMODULE)
hmodule_ptr_ = memory()->SystemHeapAlloc(sizeof(X_LDR_DATA_TABLE_ENTRY));
// Hijack the checksum field to store our kernel object handle.
auto ldr_data =
memory()->TranslateVirtual<X_LDR_DATA_TABLE_ENTRY*>(hmodule_ptr_);
ldr_data->checksum = handle();
}
XModule::~XModule() { kernel_state_->UnregisterModule(this); }
XModule::~XModule() {
kernel_state_->UnregisterModule(this);
// Destroy the loader data.
memory()->SystemHeapFree(hmodule_ptr_);
}
bool XModule::Matches(const std::string& name) const {
if (strcasecmp(xe::find_name_from_path(path_).c_str(), name.c_str()) == 0) {
@@ -58,5 +72,17 @@ X_STATUS XModule::GetSection(const char* name, uint32_t* out_section_data,
return X_STATUS_UNSUCCESSFUL;
}
object_ref<XModule> XModule::GetFromHModule(KernelState* kernel_state,
void* hmodule) {
// Grab the object from our stashed kernel handle
return kernel_state->object_table()->LookupObject<XModule>(
GetHandleFromHModule(hmodule));
}
uint32_t XModule::GetHandleFromHModule(void* hmodule) {
auto ldr_data = reinterpret_cast<X_LDR_DATA_TABLE_ENTRY*>(hmodule);
return ldr_data->checksum;
}
} // namespace kernel
} // namespace xe