Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

XAPI: Add Device types Manual Scan #165

Merged
merged 11 commits into from
Sep 28, 2022
Merged
2 changes: 2 additions & 0 deletions include/libXbSymbolDatabase.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,9 @@ extern "C" {
#define Lib_XACTENG "XACTENG"
#define Sec_XACTENG Lib_XACTENG
#define Lib_XAPILIB "XAPILIB"
#define Sec_XID ".XID"
#define Sec_XPP "XPP"
#define Sec_XPPDat ".XPP&Dat"
#define Lib_XGRAPHC "XGRAPHC"
#define Sec_XGRPH "XGRPH"
#define Lib_XNET "XNET"
Expand Down
6 changes: 6 additions & 0 deletions include/xref/xapilib.def
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,13 @@
// Variables
XREF_SYMBOL(XAPI__tls_array) // initially set to XREF_ADDR_DERIVE
XREF_SYMBOL(XAPI__tls_index) // initially set to XREF_ADDR_DERIVE
XREF_SYMBOL(g_DeviceType_Gamepad) //
XREF_SYMBOL(g_DeviceType_IRDongle) //
XREF_SYMBOL(g_DeviceType_Keyboard) //
XREF_SYMBOL(g_DeviceType_MU) // initially set to XREF_ADDR_DERIVE
XREF_SYMBOL(g_DeviceType_SBC) //
XREF_SYMBOL(g_DeviceTypeInfoTableBegin) // initially set to XREF_ADDR_DERIVE
XREF_SYMBOL(g_DeviceTypeInfoTableEnd) // initially set to XREF_ADDR_DERIVE
XREF_SYMBOL(g_XapiCurrentTopLevelFilter) // initially set to XREF_ADDR_DERIVE
XREF_SYMBOL(g_XapiMountedMUs) // initially set to XREF_ADDR_DERIVE

Expand Down
40 changes: 22 additions & 18 deletions src/OOVPADatabase/Xapi/3911.inl
Original file line number Diff line number Diff line change
Expand Up @@ -374,30 +374,34 @@ OOVPA_SIG_MATCH(
// ******************************************************************
// * XInputOpen
// ******************************************************************
OOVPA_SIG_HEADER_NO_XREF(XInputOpen,
3911)
OOVPA_SIG_HEADER_XREF(XInputOpen,
3911,
XRefThree)
OOVPA_SIG_MATCH(

// XInputOpen+0x20 : jmp +0x0B
{ 0x20, 0xEB },
{ 0x21, 0x0B },
// cmp dword [ebp + 0x08],g_DeviceType_Gamepad
XREF_ENTRY(0x0B, XREF_g_DeviceType_Gamepad), // derived

// cmp dword [ebp + 0x08],g_DeviceType_Keyboard
XREF_ENTRY(0x18, XREF_g_DeviceType_Keyboard), // derived

// cmp dword [ebp + 0x08],g_DeviceType_IRDongle
XREF_ENTRY(0x25, XREF_g_DeviceType_IRDongle), // derived

// jmp +0x0B
OV_MATCH(0x20, 0xEB, 0x0B),

// XInputOpen+0x29 : jnz +0x3D
{ 0x29, 0x75 },
{ 0x2A, 0x3D },
// jnz +0x3D
OV_MATCH(0x29, 0x75, 0x3D),

// XInputOpen+0x4A : add edx, 0x10
{ 0x4A, 0x83 },
{ 0x4B, 0xC2 },
{ 0x4C, 0x10 },
// add edx,0x10
OV_MATCH(0x4A, 0x83, 0xC2, 0x10),

// XInputOpen+0x66 : jmp +0x09
{ 0x66, 0xEB },
{ 0x67, 0x09 },
// jmp +0x09
OV_MATCH(0x66, 0xEB, 0x09),

// XInputOpen+0x68 : push 0x57
{ 0x68, 0x6A },
{ 0x69, 0x57 },
// push 0x57
OV_MATCH(0x68, 0x6A, 0x57),
//
);

Expand Down
34 changes: 0 additions & 34 deletions src/OOVPADatabase/Xapi/4134.inl
Original file line number Diff line number Diff line change
Expand Up @@ -64,37 +64,3 @@ OOVPA_SIG_MATCH(
{ 0x13, 0xC2 },
//
);

// ******************************************************************
// * GetTypeInformation
// ******************************************************************
OOVPA_SIG_HEADER_NO_XREF(GetTypeInformation,
4134)
OOVPA_SIG_MATCH(

{ 0x00, 0xB8 },
{ 0x05, 0x56 },
{ 0x06, 0x8B },
{ 0x07, 0xD0 },
{ 0x08, 0xBE },
{ 0x0D, 0x3B },
{ 0x0E, 0xD6 },
{ 0x0F, 0x73 },
{ 0x10, 0x12 },
{ 0x11, 0x8B },
{ 0x12, 0x10 },
{ 0x13, 0x85 },
{ 0x14, 0xD2 },
{ 0x15, 0x74 },
{ 0x16, 0x05 },
{ 0x17, 0x39 },
{ 0x18, 0x4A },
{ 0x19, 0x04 },
{ 0x1A, 0x74 },
{ 0x1B, 0x0B },
{ 0x1C, 0x83 },
{ 0x1D, 0xC0 },
{ 0x1E, 0x04 },
{ 0x1F, 0x3B },
//
);
87 changes: 67 additions & 20 deletions src/OOVPADatabase/Xapi/4242.inl
Original file line number Diff line number Diff line change
Expand Up @@ -26,33 +26,35 @@
// ******************************************************************
// * XInputOpen
// ******************************************************************
OOVPA_SIG_HEADER_NO_XREF(XInputOpen,
4242)
// Generic OOVPA as of 4242 and newer.
OOVPA_SIG_HEADER_XREF(XInputOpen,
4242,
XRefTwo)
OOVPA_SIG_MATCH(

// XInputOpen+0x14 : push 0x57
{ 0x14, 0x6A },
{ 0x15, 0x57 },
// call GetTypeInformation
XREF_ENTRY(0x0C, XREF_XAPI_GetTypeInformation),

// XInputOpen+0x1D : jmp +0x33
{ 0x1D, 0xEB },
{ 0x1E, 0x33 },
// call SetLastError
XREF_ENTRY(0x17, XREF_XAPI_SetLastError),

// XInputOpen+0x33 : add edx, 0x10
{ 0x33, 0x83 },
{ 0x34, 0xC2 },
{ 0x35, 0x10 },
// push 0x57
OV_MATCH(0x14, 0x6A, 0x57),

// XInputOpen+0x47 : jmp +0x06
{ 0x47, 0x75 },
{ 0x48, 0x06 },
// jmp +0x33
OV_MATCH(0x1D, 0xEB, 0x33),

// XInputOpen+0x52 : leave
{ 0x52, 0xC9 },
// add edx, 0x10
OV_MATCH(0x33, 0x83, 0xC2, 0x10),

// XInputOpen+0x53 : retn 0x10
{ 0x53, 0xC2 },
{ 0x54, 0x10 },
// jmp +0x06
OV_MATCH(0x47, 0x75, 0x06),

// leave
OV_MATCH(0x52, 0xC9),

// retn 0x10
OV_MATCH(0x53, 0xC2, 0x10),
//
);

Expand Down Expand Up @@ -272,3 +274,48 @@ OOVPA_SIG_MATCH(
OV_MATCH(0x51, 0x66, 0xC7, 0x45, 0xF2, 0x3E, 0x00),
//
);

// ******************************************************************
// * GetTypeInformation
// ******************************************************************
// Generic OOVPA as of 4242 and newer.
OOVPA_SIG_HEADER_XREF(GetTypeInformation,
4242,
XRefTwo)
OOVPA_SIG_MATCH(

// mov eax,g_DeviceTypeInfoTableBegin
XREF_ENTRY(0x01, XREF_g_DeviceTypeInfoTableBegin), // derived

// mov esi,g_DeviceTypeInfoTableEnd
XREF_ENTRY(0x09, XREF_g_DeviceTypeInfoTableEnd), // derived

// mov eax,g_DeviceTypeInfoTableBegin
OV_MATCH(0x00, 0xB8),
// push esi
// mov edx,eax
// mov esi,g_DeviceTypeInfoTableEnd
OV_MATCH(0x05, 0x56, 0x8B, 0xD0, 0xBE),
// cmp edx,esi
OV_MATCH(0x0D, 0x3B, 0xD6),
// jnc +0x12
OV_MATCH(0x0F, 0x73, 0x12),
// mov edx,dword [eax]
OV_MATCH(0x11, 0x8B, 0x10),
// test edx,edx
OV_MATCH(0x13, 0x85, 0xD2),

// cmp dword [edx + 0x04],ecx
OV_MATCH(0x17, 0x39, 0x4A, 0x04),
// JZ +0x0B
OV_MATCH(0x1A, 0x74, 0x0B),
// add eax,0x04
OV_MATCH(0x1C, 0x83, 0xC0, 0x04),

// ret
OV_MATCH(0x26, 0xC3),

// ret
OV_MATCH(0x2A, 0xC3),
//
);
5 changes: 2 additions & 3 deletions src/OOVPADatabase/Xapi_OOVPA.inl
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@
// * GetOverlappedResult (4034)
// * GetThreadPriority (4034)
// * GetTimeZoneInformation (4034)
// * GetTypeInformation (4134)
// * MoveFileA (4034)
// * QueueUserAPC (4034)
// * SetThreadPriority (4034)
Expand Down Expand Up @@ -449,7 +448,7 @@ OOVPATable XAPILIB_OOVPA[] = {
REGISTER_OOVPAS_XAPI(GetOverlappedResult, 3911),
REGISTER_OOVPAS_XAPI(GetThreadPriority, 3911),
REGISTER_OOVPAS_XAPI(GetTimeZoneInformation, 3911),
REGISTER_OOVPAS_XAPI(GetTypeInformation, 4134), // TODO: Actually introduced in some unknown XDK between 4134 and 4361
REGISTER_OOVPAS_M_PREFIX(GetTypeInformation, XAPI, 4242), // Final generic OOVPA: 4242; Removed: 0
REGISTER_OOVPAS_M(MU_Init, 3911, 4242, 5233),
REGISTER_OOVPAS_XAPI(OutputDebugStringA, 3911), // Final generic OOVPA: 3911; Removed: 0
REGISTER_OOVPAS_XAPI(OutputDebugStringW, 3911), // Final generic OOVPA: 3911; Removed: 0
Expand All @@ -473,7 +472,7 @@ OOVPATable XAPILIB_OOVPA[] = {
REGISTER_OOVPAS(XInputGetCapabilities, 3911, 4831), // Final generic OOVPA: 4831; Removed: 0
REGISTER_OOVPAS(XInputGetDeviceDescription, 4831),
REGISTER_OOVPAS(XInputGetState, 3911, 4242, 5455),
REGISTER_OOVPAS(XInputOpen, 3911, 4242),
REGISTER_OOVPAS_C(XInputOpen, 3911, 4242), // Final generic OOVPA: 4242; Removed: 0
REGISTER_OOVPAS(XInputPoll, 3911),
REGISTER_OOVPAS(XInputSetLightgunCalibration, 4831),
REGISTER_OOVPAS(XInputSetState, 3911, 4242, 4831),
Expand Down
28 changes: 28 additions & 0 deletions src/lib/internal_functions.h
Original file line number Diff line number Diff line change
Expand Up @@ -621,3 +621,31 @@ static void internal_SetLibraryTypeEnd(iXbSymbolContext* pContext, eLibraryType

iXbSymbolContext_Unlock(pContext);
}

static memptr_t internal_section_VirtToHostAddress(iXbSymbolContext* pContext, xbaddr virt_addr)
{
memptr_t host_addr = NULL;
XbSDBSection* section_filter = pContext->section_input.filters;
for (unsigned i = 0; i < pContext->section_input.count; i++, section_filter++) {
// Check if virt_addr match within specific section range, then convert to host address.
if (section_filter->xb_virt_addr <= virt_addr && virt_addr <= section_filter->xb_virt_addr + section_filter->buffer_size) {
host_addr = (memptr_t)section_filter->buffer_lower - section_filter->xb_virt_addr + virt_addr;
break;
}
}
return host_addr;
}

static xbaddr internal_section_HostToVirtAddress(iXbSymbolContext* pContext, memptr_t host_addr)
{
xbaddr virt_addr = 0;
XbSDBSection* section_filter = pContext->section_input.filters;
for (unsigned i = 0; i < pContext->section_input.count; i++, section_filter++) {
// Check if host_addr match within specific section range, then convert to virtual address.
if ((memptr_t)section_filter->buffer_lower <= host_addr && host_addr <= (memptr_t)section_filter->buffer_lower + section_filter->buffer_size) {
virt_addr = (xbaddr)(host_addr - (memptr_t)section_filter->buffer_lower + section_filter->xb_virt_addr);
break;
}
}
return virt_addr;
}
7 changes: 7 additions & 0 deletions src/lib/libXbSymbolDatabase.c
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,9 @@ const char SectionList[][8] = {
Sec_D3DX,
Sec_DSOUND,
Sec_XACTENG,
Sec_XID,
Sec_XPP,
Sec_XPPDat,
Sec_XGRPH,
Sec_XONLINE,
Sec_XNET
Expand Down Expand Up @@ -823,6 +825,11 @@ bool XbSymbolDatabase_CreateXbSymbolContext(XbSymbolContextHandle* ppHandle,
pContext->xref_database[XREF_OFFSET_D3DDevice__m_VertexShader] = XREF_ADDR_DERIVE; //In use
// XAPILIB //
pContext->xref_database[XREF_g_XapiCurrentTopLevelFilter] = XREF_ADDR_DERIVE; //In use
pContext->xref_database[XREF_g_DeviceType_Gamepad] = XREF_ADDR_DERIVE; //In use
pContext->xref_database[XREF_g_DeviceType_Keyboard] = XREF_ADDR_DERIVE; //In use
pContext->xref_database[XREF_g_DeviceType_IRDongle] = XREF_ADDR_DERIVE; //In use
pContext->xref_database[XREF_g_DeviceTypeInfoTableBegin] = XREF_ADDR_DERIVE; //In use
pContext->xref_database[XREF_g_DeviceTypeInfoTableEnd] = XREF_ADDR_DERIVE; //In use
pContext->xref_database[XREF_g_XapiMountedMUs] = XREF_ADDR_DERIVE; //In use
pContext->xref_database[XREF_OFFSET_XapiCurrentFiber] = XREF_ADDR_DERIVE; //In use
pContext->xref_database[XREF_OFFSET_XapiLastErrorCode] = XREF_ADDR_DERIVE; //In use
Expand Down
Loading