Shrinking alloy memory interface so that alloy-sandbox doesn't need xe.

This commit is contained in:
Ben Vanik
2014-08-19 21:02:15 -07:00
parent 76d524b655
commit 48a0e5c601
23 changed files with 230 additions and 192 deletions

View File

@@ -21,14 +21,14 @@
#include <third_party/mspack/mspack.h>
#include <third_party/pe/pe_image.h>
using namespace alloy;
// using namespace alloy;
DEFINE_bool(xex_dev_key, false, "Use the devkit key.");
typedef struct xe_xex2 {
xe_ref_t ref;
Memory *memory;
xe::Memory *memory;
xe_xex2_header_t header;
@@ -44,13 +44,13 @@ int xe_xex2_read_header(const uint8_t *addr, const size_t length,
xe_xex2_header_t *header);
int xe_xex2_decrypt_key(xe_xex2_header_t *header);
int xe_xex2_read_image(xe_xex2_ref xex, const uint8_t *xex_addr,
const size_t xex_length, Memory *memory);
const size_t xex_length, xe::Memory *memory);
int xe_xex2_load_pe(xe_xex2_ref xex);
int xe_xex2_find_import_infos(xe_xex2_ref xex,
const xe_xex2_import_library_t *library);
xe_xex2_ref xe_xex2_load(Memory *memory, const void *addr, const size_t length,
xe_xex2_options_t options) {
xe_xex2_ref xe_xex2_load(xe::Memory *memory, const void *addr,
const size_t length, xe_xex2_options_t options) {
xe_xex2_ref xex = (xe_xex2_ref)xe_calloc(sizeof(xe_xex2));
xe_ref_init((xe_ref)xex);
@@ -542,12 +542,13 @@ void xe_xex2_decrypt_buffer(const uint8_t *session_key,
int xe_xex2_read_image_uncompressed(const xe_xex2_header_t *header,
const uint8_t *xex_addr,
const size_t xex_length, Memory *memory) {
const size_t xex_length,
xe::Memory *memory) {
// Allocate in-place the XEX memory.
const size_t exe_length = xex_length - header->exe_offset;
size_t uncompressed_size = exe_length;
uint32_t alloc_result = (uint32_t)memory->HeapAlloc(
header->exe_address, uncompressed_size, MEMORY_FLAG_ZERO);
header->exe_address, uncompressed_size, xe::MEMORY_FLAG_ZERO);
if (!alloc_result) {
XELOGE("Unable to allocate XEX memory at %.8X-%.8X.", header->exe_address,
uncompressed_size);
@@ -575,7 +576,7 @@ int xe_xex2_read_image_uncompressed(const xe_xex2_header_t *header,
int xe_xex2_read_image_basic_compressed(const xe_xex2_header_t *header,
const uint8_t *xex_addr,
const size_t xex_length,
Memory *memory) {
xe::Memory *memory) {
const size_t exe_length = xex_length - header->exe_offset;
const uint8_t *source_buffer = (const uint8_t *)xex_addr + header->exe_offset;
const uint8_t *p = source_buffer;
@@ -592,7 +593,7 @@ int xe_xex2_read_image_basic_compressed(const xe_xex2_header_t *header,
// Allocate in-place the XEX memory.
uint32_t alloc_result = (uint32_t)memory->HeapAlloc(
header->exe_address, uncompressed_size, MEMORY_FLAG_ZERO);
header->exe_address, uncompressed_size, xe::MEMORY_FLAG_ZERO);
if (!alloc_result) {
XELOGE("Unable to allocate XEX memory at %.8X-%.8X.", header->exe_address,
uncompressed_size);
@@ -645,7 +646,7 @@ XECLEANUP:
int xe_xex2_read_image_compressed(const xe_xex2_header_t *header,
const uint8_t *xex_addr,
const size_t xex_length, Memory *memory) {
const size_t xex_length, xe::Memory *memory) {
const size_t exe_length = xex_length - header->exe_offset;
const uint8_t *exe_buffer = (const uint8_t *)xex_addr + header->exe_offset;
@@ -726,7 +727,7 @@ int xe_xex2_read_image_compressed(const xe_xex2_header_t *header,
// Allocate in-place the XEX memory.
uint32_t alloc_result = (uint32_t)memory->HeapAlloc(
header->exe_address, uncompressed_size, MEMORY_FLAG_ZERO);
header->exe_address, uncompressed_size, xe::MEMORY_FLAG_ZERO);
if (!alloc_result) {
XELOGE("Unable to allocate XEX memory at %.8X-%.8X.", header->exe_address,
uncompressed_size);
@@ -778,7 +779,7 @@ XECLEANUP:
}
int xe_xex2_read_image(xe_xex2_ref xex, const uint8_t *xex_addr,
const size_t xex_length, Memory *memory) {
const size_t xex_length, xe::Memory *memory) {
const xe_xex2_header_t *header = &xex->header;
switch (header->file_format_info.compression_type) {
case XEX_COMPRESSION_NONE: