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

JVS: add g_pPINS(A|B) variables support #188

Merged
merged 4 commits into from
Feb 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions include/xref/jvs.def
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ XREF_SYMBOL(JvsScReceiveRs323c_String)
XREF_SYMBOL(JvsScSendMidi_String)
XREF_SYMBOL(JvsScSendRs323c_String)

// derived variables
XREF_SYMBOL(JVS_g_pPINSA)
XREF_SYMBOL(JVS_g_pPINSB)

// functions
XREF_SYMBOL(JVS_SendCommand)
XREF_SYMBOL(JvsBACKUP_Read)
Expand Down
62 changes: 58 additions & 4 deletions src/OOVPADatabase/JVS/4831.inl
Original file line number Diff line number Diff line change
Expand Up @@ -275,23 +275,35 @@ OOVPA_SIG_MATCH(
// ******************************************************************
OOVPA_SIG_HEADER_XREF(JVS_SendCommand,
4831,
XRefOne)
XRefThree)
OOVPA_SIG_MATCH(
XREF_ENTRY(0x250, XREF_JVS_SendCommand_String),
XREF_ENTRY(0x2A0, XREF_JVS_g_pPINSA), // Derived
XREF_ENTRY(0x2A8, XREF_JVS_g_pPINSB), // Derived

// sub esp,0x?
OV_MATCH(0x00, 0x81, 0xEC),

// mov e??, [e?? + param_4]
OV_MATCH(0x0A, 0xB4, 0x00),

// test ebp,ebp
OV_MATCH(0x0E, 0x85, 0xED),

// push esi
// push edi
OV_MATCH(0x10, 0x56, 0x57),

// mov esi,[e?? + 0x?]
OV_MATCH(0x31, 0x8B, 0xB4),

// jz +?
OV_MATCH(0x90, 0x0F),

// test al,0x??
OV_MATCH(0x96, 0xA8),

// and eax,0x3
OV_MATCH(0x2A4, 0x83, 0xE0, 0x03),
//
);

Expand All @@ -301,29 +313,71 @@ OOVPA_SIG_MATCH(
// ******************************************************************
OOVPA_SIG_HEADER_XREF(JVS_SendCommand2,
4831,
XRefOne)
XRefThree)
OOVPA_SIG_MATCH(
XREF_ENTRY(0x2C0, XREF_JVS_SendCommand_String),
XREF_ENTRY(0x312, XREF_JVS_g_pPINSA), // Derived
XREF_ENTRY(0x31B, XREF_JVS_g_pPINSB), // Derived

// sub esp,0x58
// push ebx
OV_MATCH(0x00, 0x83, 0xEC, 0x58, 0x53),

// mov [esp + 0x70],al
OV_MATCH(0x86, 0x88, 0x44, 0x24, 0x70),

// and edx,0x3
OV_MATCH(0x316, 0x83, 0xE2, 0x03),
//
);

// ******************************************************************
// * JVS_SendCommand3
// * Variation of JVS_SendCommand
// ******************************************************************
// TODO: Set this signature as revision 1
OOVPA_SIG_HEADER_XREF(JVS_SendCommand3,
4831,
XRefOne)
XRefThree)
OOVPA_SIG_MATCH(
XREF_ENTRY(0x28B, XREF_JVS_SendCommand_String),
XREF_ENTRY(0x302, XREF_JVS_g_pPINSA), // Derived
XREF_ENTRY(0x30B, XREF_JVS_g_pPINSB), // Derived

// sub esp,0x58
// push ebx
OV_MATCH(0x00, 0x83, 0xEC, 0x58, 0x53),

// mov [esp + 0x70],al
OV_MATCH(0x86, 0x88, 0x44, 0x24, 0x70),

// and edx,0x3
OV_MATCH(0x306, 0x83, 0xE2, 0x03),
//
);

// ******************************************************************
// * JVS_SendCommand3
// * Variation of JVS_SendCommand
// ******************************************************************
// TODO: Set this signature as revision 2
OOVPA_SIG_HEADER_XREF(JVS_SendCommand3,
4832,
XRefThree)
OOVPA_SIG_MATCH(
XREF_ENTRY(0x28B, XREF_JVS_SendCommand_String),
XREF_ENTRY(0x307, XREF_JVS_g_pPINSA), // Derived
XREF_ENTRY(0x313, XREF_JVS_g_pPINSB), // Derived

// sub esp,0x58
// push ebx
OV_MATCH(0x00, 0x83, 0xEC, 0x58, 0x53),

// mov [esp + 0x70],al
OV_MATCH(0x86, 0x88, 0x44, 0x24, 0x70),

// and edx,0x3
OV_MATCH(0x30B, 0x83, 0xE2, 0x03),
//
);

Expand Down
2 changes: 1 addition & 1 deletion src/OOVPADatabase/JVS_OOVPA.inl
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ OOVPATable JVSLIB_OOVPA[] = {
// Chihiro/JVS (Functions)
REGISTER_OOVPAS(JVS_SendCommand, 4831),
REGISTER_OOVPAS_BIND_XREF(JVS_SendCommand2, JVS_SendCommand, 4831),
REGISTER_OOVPAS_BIND_XREF(JVS_SendCommand3, JVS_SendCommand, 4831),
REGISTER_OOVPAS_BIND_XREF(JVS_SendCommand3, JVS_SendCommand, 4831, 4832),
REGISTER_OOVPAS(JvsBACKUP_Read, 4831),
REGISTER_OOVPAS_BIND_XREF(JvsBACKUP_Read2, JvsBACKUP_Read, 4831),
REGISTER_OOVPAS_BIND_XREF(JvsBACKUP_Read3, JvsBACKUP_Read, 4831),
Expand Down
19 changes: 14 additions & 5 deletions src/lib/libXbSymbolDatabase.c
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,9 @@ const char* XbSymbolDatabase_LibraryToString(uint32_t library_flag)
case XbSymbolLib_DSOUND: {
return Lib_DSOUND;
}
case XbSymbolLib_JVS: {
return Lib_JVS;
}
case XbSymbolLib_XACTENG: {
return Lib_XACTENG;
}
Expand Down Expand Up @@ -400,6 +403,9 @@ uint32_t XbSymbolDatabase_LibraryToFlag(const char* library_name)
if (strncmp(library_name, Lib_DSOUND, 8) == 0) {
return XbSymbolLib_DSOUND;
}
if (strncmp(library_name, Lib_JVS, 8) == 0) {
return XbSymbolLib_JVS;
}
if (strncmp(library_name, Lib_XACTENG, 8) == 0) {
return XbSymbolLib_XACTENG;
}
Expand Down Expand Up @@ -518,16 +524,16 @@ uint32_t XbSymbolDatabase_GenerateLibraryFilter(const void* xb_header_addr, XbSD

library_flag = XbSymbolDatabase_LibraryToFlag(xb_library_versions[library_index].szName);

// If library is unknown to the database, skip it.
if (library_flag == 0) {
continue;
}

// Keep the highest build version for manual checklist.
if (build_version < xb_library_versions[library_index].wBuildVersion) {
build_version = xb_library_versions[library_index].wBuildVersion;
}

// If library is unknown to the database, skip it.
if (library_flag == 0) {
continue;
}

// If found DSOUND library, then skip the manual check.
if (library_flag == XbSymbolLib_DSOUND) {
if (!has_dsound_library) {
Expand Down Expand Up @@ -838,6 +844,9 @@ bool XbSymbolDatabase_CreateXbSymbolContext(XbSymbolContextHandle* ppHandle,
pContext->xref_database[XREF_OFFSET_D3DDevice__m_VBlankCallback] = XREF_ADDR_UNDETERMINED; //In use // Manual check only.
#endif //
pContext->xref_database[XREF_OFFSET_D3DDevice__m_VertexShader] = XREF_ADDR_DERIVE; //In use
// JVS //
pContext->xref_database[XREF_JVS_g_pPINSA] = XREF_ADDR_DERIVE; //In use
pContext->xref_database[XREF_JVS_g_pPINSB] = 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
Expand Down
2 changes: 2 additions & 0 deletions src/lib/manual_custom.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
// Each include is base on library requirement to do by hand
#include "manual_d3d8__ltcg.h"
#include "manual_dsound.h"
#include "manual_jvs.h"
#include "manual_xapilib.h"

static bool manual_scan_library_custom(iXbSymbolContext* pContext,
Expand Down Expand Up @@ -76,5 +77,6 @@ static bool manual_scan_library_custom(iXbSymbolContext* pContext,
static inline void manual_register_symbols(iXbSymbolContext* pContext)
{
manual_register_d3d8__ltcg(pContext);
manual_register_jvs(pContext);
manual_register_xapilib(pContext);
}
29 changes: 29 additions & 0 deletions src/lib/manual_jvs.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// This is an open source non-commercial project. Dear PVS-Studio, please check it.
// PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
// ******************************************************************
// *
// * XbSymbolDatabase is free software; you can redistribute them
// * and/or modify them under the terms of the GNU General Public
// * License as published by the Free Software Foundation; either
// * version 2 of the license, or (at your option) any later version.
// *
// * This program is distributed in the hope that it will be useful,
// * but WITHOUT ANY WARRANTY; without even the implied warranty of
// * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// * GNU General Public License for more details.
// *
// * You should have recieved a copy of the GNU General Public License
// * along with this program; see the file COPYING.
// * If not, write to the Free Software Foundation, Inc.,
// * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
// *
// * All rights reserved
// *
// ******************************************************************
#pragma once

static inline void manual_register_jvs(iXbSymbolContext* pContext)
{
internal_RegisterValidXRefAddr_M(pContext, Lib_JVS, XbSymbolLib_JVS, XREF_JVS_g_pPINSA, 4831, "JVS_g_pPINSA");
internal_RegisterValidXRefAddr_M(pContext, Lib_JVS, XbSymbolLib_JVS, XREF_JVS_g_pPINSB, 4831, "JVS_g_pPINSB");
}
8 changes: 6 additions & 2 deletions src/lib/manual_xapilib.h
Original file line number Diff line number Diff line change
Expand Up @@ -194,15 +194,15 @@ static bool internal_xapi_find_device_types(iXbSymbolContext* pContext,
&pOOVPARevision);
}

// If either GetTypeInformation overload is found, start look up in DeviceTypeInfo table's entires.
// If either GetTypeInformation overload is found, start look up in DeviceTypeInfo table's entries.
if (xXbAddr) {
internal_RegisterSymbol(pContext, pLibrarySession, pSymbol, pOOVPARevision->Version, xXbAddr);

uint32_t* table_i = (uint32_t*)internal_section_VirtToHostAddress(pContext, pContext->xref_database[XREF_g_DeviceTypeInfoTableBegin]);
uint32_t* table_end = (uint32_t*)internal_section_VirtToHostAddress(pContext, pContext->xref_database[XREF_g_DeviceTypeInfoTableEnd]);
size_t type_description_table_count = ((memptr_t)table_end - (memptr_t)table_i) / sizeof(uint32_t);

output_message_format(&pContext->output, XB_OUTPUT_MESSAGE_DEBUG, "DeviceTypeInfoTable Entires: %u", type_description_table_count);
output_message_format(&pContext->output, XB_OUTPUT_MESSAGE_DEBUG, "DeviceTypeInfoTable Entries: %u", type_description_table_count);

// Partial extracted for ucType and XppType fields needed to get specific device type named.
typedef struct _XID_TYPE_INFORMATION {
Expand All @@ -216,6 +216,10 @@ static bool internal_xapi_find_device_types(iXbSymbolContext* pContext,
int i = 0;
for (; table_i < table_end; table_i++, i++) {
PXID_TYPE_INFORMATION DeviceTypeInfo = (PXID_TYPE_INFORMATION)internal_section_VirtToHostAddress(pContext, *table_i);
if (!DeviceTypeInfo) {
// if address is nullptr, then skip it.
continue;
}
switch (DeviceTypeInfo->ucType) {
case 1: // Gamepad (Generic)
pContext->xref_database[XREF_g_DeviceType_Gamepad] = DeviceTypeInfo->XppType;
Expand Down
18 changes: 13 additions & 5 deletions src/test/libverify/JVS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@

#include "unittest.hpp"

static const library_list database_opt = {
REGISTER_SYMBOL_INLINE(JvsRTC_Write_String, VER_RANGE(4831, VER_MAX, VER_NONE, VER_NONE)),
REGISTER_SYMBOLS(JvsRTC_Write,
REGISTER_SYMBOL(JvsRTC_Write, VER_RANGE(4831, VER_MAX, VER_NONE, VER_NONE)),
REGISTER_SYMBOL(JvsRTC_Write2, VER_RANGE(4831, VER_MAX, VER_NONE, VER_NONE))),
};

static const library_list database_min = {
REGISTER_SYMBOL_INLINE(JVS_SendCommand_String, VER_RANGE(4831, VER_MAX, VER_NONE, VER_NONE)),
REGISTER_SYMBOL_INLINE(JvsBACKUP_Read_String, VER_RANGE(4831, VER_MAX, VER_NONE, VER_NONE)),
Expand All @@ -13,7 +20,6 @@ static const library_list database_min = {
REGISTER_SYMBOL_INLINE(JvsNodeReceivePacket_String, VER_RANGE(4831, VER_MAX, VER_NONE, VER_NONE)),
REGISTER_SYMBOL_INLINE(JvsNodeSendPacket_String, VER_RANGE(4831, VER_MAX, VER_NONE, VER_NONE)),
REGISTER_SYMBOL_INLINE(JvsRTC_Read_String, VER_RANGE(4831, VER_MAX, VER_NONE, VER_NONE)),
REGISTER_SYMBOL_INLINE(JvsRTC_Write_String, VER_RANGE(4831, VER_MAX, VER_NONE, VER_NONE)),
REGISTER_SYMBOL_INLINE(JvsScFirmwareDownload_String, VER_RANGE(4831, VER_MAX, VER_NONE, VER_NONE)),
REGISTER_SYMBOL_INLINE(JvsScFirmwareUpload_String, VER_RANGE(4831, VER_MAX, VER_NONE, VER_NONE)),
REGISTER_SYMBOL_INLINE(JvsScReceiveMidi_String, VER_RANGE(4831, VER_MAX, VER_NONE, VER_NONE)),
Expand All @@ -23,6 +29,11 @@ static const library_list database_min = {
};

static const library_list database_full = {
// vars
REGISTER_SYMBOL_INLINE(JVS_g_pPINSA, VER_RANGE(4831, VER_MAX, VER_NONE, VER_NONE)),
REGISTER_SYMBOL_INLINE(JVS_g_pPINSB, VER_RANGE(4831, VER_MAX, VER_NONE, VER_NONE)),

// functions
REGISTER_SYMBOLS(JVS_SendCommand,
REGISTER_SYMBOL(JVS_SendCommand, VER_RANGE(4831, VER_MAX, VER_NONE, VER_NONE)),
REGISTER_SYMBOL(JVS_SendCommand2, VER_RANGE(4831, VER_MAX, VER_NONE, VER_NONE)),
Expand Down Expand Up @@ -62,9 +73,6 @@ static const library_list database_full = {
REGISTER_SYMBOL(JvsRTC_Read, VER_RANGE(4831, VER_MAX, VER_NONE, VER_NONE)),
REGISTER_SYMBOL(JvsRTC_Read2, VER_RANGE(4831, VER_MAX, VER_NONE, VER_NONE)),
REGISTER_SYMBOL(JvsRTC_Read3, VER_RANGE(4831, VER_MAX, VER_NONE, VER_NONE))),
REGISTER_SYMBOLS(JvsRTC_Write,
REGISTER_SYMBOL(JvsRTC_Write, VER_RANGE(4831, VER_MAX, VER_NONE, VER_NONE)),
REGISTER_SYMBOL(JvsRTC_Write2, VER_RANGE(4831, VER_MAX, VER_NONE, VER_NONE))),
REGISTER_SYMBOLS(JvsScFirmwareDownload,
REGISTER_SYMBOL(JvsScFirmwareDownload, VER_RANGE(4831, VER_MAX, VER_NONE, VER_NONE)),
REGISTER_SYMBOL(JvsScFirmwareDownload2, VER_RANGE(4831, VER_MAX, VER_NONE, VER_NONE)),
Expand Down Expand Up @@ -106,7 +114,7 @@ static_assert(XREF_OFFSET == 0);

static const subcategory_db jvs_db = {
.name = "general",
.optional = nullptr,
.optional = &database_opt,
.min = &database_min,
.full = &database_full,
};
Expand Down