Skip to content

Commit

Permalink
Merge pull request #70 from RadWolfie/detect-xbe-type
Browse files Browse the repository at this point in the history
Detect xbe Type
  • Loading branch information
PatrickvL authored May 20, 2019
2 parents d58fc07 + 77a2855 commit 56fbf92
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
27 changes: 26 additions & 1 deletion XbSymbolDatabase.c
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,24 @@ xb_output_message output_verbose_level = XB_OUTPUT_MESSAGE_INFO;
bool bOneTimeScan = true;
bool bScanFirstDetect = false;

// ported from Dxbx's XbeExplorer
static xb_xbe_type GetXbeType(const xbe_header *pXbeHeader)
{
// Detect if the XBE is for Chihiro (Untested!) :
// This is based on https://github.com/radare/radare2/blob/7ffe2599a192bf5b9333560345f80dd97f096277/libr/bin/p/bin_xbe.c#L29
if ((pXbeHeader->dwEntryAddr & 0xf0000000) == 0x40000000) {
return XB_XBE_TYPE_CHIHIRO;
}

// Check for Debug XBE, using high bit of the kernel thunk address :
// (DO NOT test like https://github.com/radare/radare2/blob/7ffe2599a192bf5b9333560345f80dd97f096277/libr/bin/p/bin_xbe.c#L33 !)
if ((pXbeHeader->dwKernelImageThunkAddr & 0x80000000) > 0) {
return XB_XBE_TYPE_DEBUG;
}

// Otherwise, the XBE is a Retail build :
return XB_XBE_TYPE_RETAIL;
}

// ******************************************************************
// * API functions to use with other projects.
Expand Down Expand Up @@ -703,6 +721,7 @@ bool XbSymbolScanSection(uint32_t xbe_base_address,

bool XbSymbolInit(const void* xb_header_addr,
xb_symbol_register_t register_func,
xb_xbe_type* xbe_type,
bool* pbDSoundLibHeader)
{
if (xb_header_addr == NULL || register_func == NULL) {
Expand Down Expand Up @@ -757,6 +776,9 @@ bool XbSymbolInit(const void* xb_header_addr,
break;
}
}

// Detect xbe type
*xbe_type = GetXbeType(pXbeHeader);
}
return 1;
}
Expand Down Expand Up @@ -1336,11 +1358,14 @@ bool XbSymbolScan(const void* xb_header_addr,
{

bool bDSoundLibHeader;
xb_xbe_type xbe_type;

if (!XbSymbolInit(xb_header_addr, register_func, &bDSoundLibHeader)) {
if (!XbSymbolInit(xb_header_addr, register_func, &xbe_type, &bDSoundLibHeader)) {
return 0;
}

XbSymbolOutputMessageFormat(XB_OUTPUT_MESSAGE_DEBUG, "xbe type is %s", xbe_type_str[xbe_type]);

const xbe_header* pXbeHeader = xb_header_addr;
memptr_t xb_start_addr = (memptr_t)xb_header_addr - pXbeHeader->dwBaseAddr;
memptr_t xb_start_virt_addr = xb_start_addr;
Expand Down
14 changes: 14 additions & 0 deletions XbSymbolDatabase.h
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,20 @@ typedef enum _xb_output_message {
XB_OUTPUT_MESSAGE_MAX
} xb_output_message;

typedef enum _xb_xbe_type {
XB_XBE_TYPE_RETAIL=0,
XB_XBE_TYPE_DEBUG,
XB_XBE_TYPE_CHIHIRO,
// Only for internal usage.
XB_XBE_TYPE_MAX
} xb_xbe_type;

static const char* xbe_type_str[XB_XBE_TYPE_MAX] = {
"RETAIL",
"DEBUG",
"CHIHIRO"
};

#ifndef xbaddr
typedef uint32_t xbaddr;
#endif
Expand Down

0 comments on commit 56fbf92

Please sign in to comment.