2013-12-07 06:57:16 +00:00
|
|
|
/**
|
|
|
|
******************************************************************************
|
|
|
|
* Xenia : Xbox 360 Emulator Research Project *
|
|
|
|
******************************************************************************
|
|
|
|
* Copyright 2013 Ben Vanik. All rights reserved. *
|
|
|
|
* Released under the BSD license - see LICENSE in the root for more details. *
|
|
|
|
******************************************************************************
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef XENIA_CPU_XEX_MODULE_H_
|
|
|
|
#define XENIA_CPU_XEX_MODULE_H_
|
|
|
|
|
2014-07-14 04:15:37 +00:00
|
|
|
#include <string>
|
|
|
|
|
2015-03-24 15:25:58 +00:00
|
|
|
#include "xenia/cpu/module.h"
|
2015-02-01 06:49:47 +00:00
|
|
|
#include "xenia/kernel/util/xex2.h"
|
2015-06-29 05:48:24 +00:00
|
|
|
#include "xenia/kernel/util/xex2_info.h"
|
2013-12-07 06:57:16 +00:00
|
|
|
|
|
|
|
namespace xe {
|
2015-05-18 06:31:59 +00:00
|
|
|
|
|
|
|
// KernelState forward decl.
|
2015-06-23 05:26:51 +00:00
|
|
|
namespace kernel {
|
|
|
|
class KernelState;
|
|
|
|
}
|
2015-05-18 06:31:59 +00:00
|
|
|
|
2013-12-07 06:57:16 +00:00
|
|
|
namespace cpu {
|
|
|
|
|
2015-03-24 15:25:58 +00:00
|
|
|
class Runtime;
|
2013-12-07 06:57:16 +00:00
|
|
|
|
2015-03-24 15:25:58 +00:00
|
|
|
class XexModule : public xe::cpu::Module {
|
2015-03-25 02:41:29 +00:00
|
|
|
public:
|
2015-05-31 23:58:12 +00:00
|
|
|
XexModule(Processor* processor, kernel::KernelState* kernel_state);
|
2013-12-07 06:57:16 +00:00
|
|
|
virtual ~XexModule();
|
|
|
|
|
2013-12-25 01:25:29 +00:00
|
|
|
xe_xex2_ref xex() const { return xex_; }
|
2015-07-06 15:40:35 +00:00
|
|
|
bool loaded() const { return loaded_; }
|
2015-07-07 00:45:10 +00:00
|
|
|
const xex2_header* xex_header() const {
|
|
|
|
return reinterpret_cast<const xex2_header*>(xex_header_mem_.data());
|
|
|
|
}
|
2015-07-03 02:58:47 +00:00
|
|
|
const xex2_security_info* xex_security_info() const {
|
2015-07-07 00:45:10 +00:00
|
|
|
return GetSecurityInfo(xex_header());
|
2015-07-03 02:58:47 +00:00
|
|
|
}
|
2013-12-25 01:25:29 +00:00
|
|
|
|
2015-06-29 05:48:24 +00:00
|
|
|
// Gets an optional header. Returns NULL if not found.
|
|
|
|
// Special case: if key & 0xFF == 0x00, this function will return the value,
|
2015-07-03 15:41:43 +00:00
|
|
|
// not a pointer! This assumes out_ptr points to uint32_t.
|
2015-06-29 05:48:24 +00:00
|
|
|
static bool GetOptHeader(const xex2_header* header, xe_xex2_header_keys key,
|
|
|
|
void** out_ptr);
|
2015-06-29 06:39:07 +00:00
|
|
|
bool GetOptHeader(xe_xex2_header_keys key, void** out_ptr) const;
|
|
|
|
|
2015-07-03 02:58:47 +00:00
|
|
|
// Ultra-cool templated version
|
|
|
|
// Special case: if key & 0xFF == 0x00, this function will return the value,
|
2015-07-03 15:41:43 +00:00
|
|
|
// not a pointer! This assumes out_ptr points to uint32_t.
|
2015-07-03 02:58:47 +00:00
|
|
|
template <typename T>
|
|
|
|
static bool GetOptHeader(const xex2_header* header, xe_xex2_header_keys key,
|
|
|
|
T* out_ptr) {
|
|
|
|
return GetOptHeader(header, key, reinterpret_cast<void**>(out_ptr));
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
bool GetOptHeader(xe_xex2_header_keys key, T* out_ptr) const {
|
|
|
|
return GetOptHeader(key, reinterpret_cast<void**>(out_ptr));
|
|
|
|
}
|
|
|
|
|
|
|
|
static const xex2_security_info* GetSecurityInfo(const xex2_header* header);
|
|
|
|
|
2015-06-29 06:39:07 +00:00
|
|
|
uint32_t GetProcAddress(uint16_t ordinal) const;
|
|
|
|
uint32_t GetProcAddress(const char* name) const;
|
2015-06-29 05:48:24 +00:00
|
|
|
|
|
|
|
bool ApplyPatch(XexModule* module);
|
|
|
|
bool Load(const std::string& name, const std::string& path,
|
|
|
|
const void* xex_addr, size_t xex_length);
|
2015-05-06 00:21:08 +00:00
|
|
|
bool Load(const std::string& name, const std::string& path, xe_xex2_ref xex);
|
2015-07-05 19:03:00 +00:00
|
|
|
bool Unload();
|
2013-12-07 06:57:16 +00:00
|
|
|
|
2014-07-14 04:15:37 +00:00
|
|
|
const std::string& name() const override { return name_; }
|
2013-12-07 06:57:16 +00:00
|
|
|
|
2015-03-25 02:41:29 +00:00
|
|
|
bool ContainsAddress(uint32_t address) override;
|
2013-12-07 06:57:16 +00:00
|
|
|
|
2015-03-25 02:41:29 +00:00
|
|
|
private:
|
2015-07-03 02:58:47 +00:00
|
|
|
bool SetupLibraryImports(const char* name,
|
|
|
|
const xex2_import_library* library);
|
2015-05-06 00:21:08 +00:00
|
|
|
bool FindSaveRest();
|
2013-12-07 06:57:16 +00:00
|
|
|
|
2015-03-25 02:41:29 +00:00
|
|
|
private:
|
2015-05-04 05:28:25 +00:00
|
|
|
Processor* processor_;
|
2015-05-18 06:31:59 +00:00
|
|
|
kernel::KernelState* kernel_state_;
|
2015-03-25 02:41:29 +00:00
|
|
|
std::string name_;
|
|
|
|
std::string path_;
|
|
|
|
xe_xex2_ref xex_;
|
2015-07-07 00:45:10 +00:00
|
|
|
std::vector<uint8_t> xex_header_mem_; // Holds the xex header
|
|
|
|
bool loaded_; // Loaded into memory?
|
2013-12-07 06:57:16 +00:00
|
|
|
|
2015-03-25 02:41:29 +00:00
|
|
|
uint32_t base_address_;
|
|
|
|
uint32_t low_address_;
|
|
|
|
uint32_t high_address_;
|
2013-12-07 06:57:16 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace cpu
|
|
|
|
} // namespace xe
|
|
|
|
|
|
|
|
#endif // XENIA_CPU_XEX_MODULE_H_
|