push work on reader
This commit is contained in:
parent
9b4f02903e
commit
257dbc1c22
142
board/bpreader.c
142
board/bpreader.c
@ -2,16 +2,152 @@
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#include "hook/iobuf.h"
|
||||
#include "hook/iohook.h"
|
||||
|
||||
#include "hooklib/uart.h"
|
||||
#include "hooklib/fdshark.h"
|
||||
|
||||
#include "util/dprintf.h"
|
||||
#include "util/dump.h"
|
||||
|
||||
#include "board/bpreader.h"
|
||||
|
||||
static struct bpreader_config config;
|
||||
static HRESULT bp_handle_irp(struct irp *irp);
|
||||
static HRESULT bp_handle_irp_locked(struct irp *irp);
|
||||
|
||||
HRESULT bpreader_init(uint16_t port)
|
||||
static struct bpreader_config *config;
|
||||
static struct uart bp_uart;
|
||||
static CRITICAL_SECTION bp_lock;
|
||||
static uint8_t bp_written_bytes[520];
|
||||
static uint8_t bp_readable_bytes[520];
|
||||
static uint8_t last_cmd = 0;
|
||||
static uint16_t write_ct = 0;
|
||||
|
||||
HRESULT bpreader_init(struct bpreader_config *cfg, uint16_t port)
|
||||
{
|
||||
config = cfg;
|
||||
if (!config->enable) {
|
||||
return S_OK;
|
||||
}
|
||||
if (cfg->port < 0) {
|
||||
port = cfg->port;
|
||||
}
|
||||
|
||||
uart_init(&bp_uart, port);
|
||||
bp_uart.written.bytes = bp_written_bytes;
|
||||
bp_uart.written.nbytes = sizeof(bp_written_bytes);
|
||||
bp_uart.readable.bytes = bp_readable_bytes;
|
||||
bp_uart.readable.nbytes = sizeof(bp_readable_bytes);
|
||||
InitializeCriticalSection(&bp_lock);
|
||||
|
||||
dprintf("Reader: Init\n");
|
||||
return iohook_push_handler(bp_handle_irp);
|
||||
}
|
||||
|
||||
void bpreader_congif_init(struct bpreader_config *cfg)
|
||||
void bpreader_congif_load(struct bpreader_config *cfg, const wchar_t *filename)
|
||||
{
|
||||
assert(cfg != NULL);
|
||||
assert(filename != NULL);
|
||||
|
||||
cfg->enable = GetPrivateProfileIntW(L"reader", L"enable", 1, filename);
|
||||
cfg->port = GetPrivateProfileIntW(L"reader", L"port", 0, filename);
|
||||
GetPrivateProfileStringW(
|
||||
L"reader",
|
||||
L"access_code",
|
||||
L"",
|
||||
cfg->access_code,
|
||||
_countof(cfg->access_code),
|
||||
filename);
|
||||
}
|
||||
|
||||
static HRESULT bp_handle_irp(struct irp *irp)
|
||||
{
|
||||
HRESULT hr;
|
||||
|
||||
assert(irp != NULL);
|
||||
|
||||
if (uart_match_irp(&bp_uart, irp)) {
|
||||
EnterCriticalSection(&bp_lock);
|
||||
hr = bp_handle_irp_locked(irp);
|
||||
LeaveCriticalSection(&bp_lock);
|
||||
}
|
||||
else {
|
||||
return iohook_invoke_next(irp);
|
||||
}
|
||||
|
||||
return hr;
|
||||
}
|
||||
|
||||
static HRESULT bp_handle_irp_locked(struct irp *irp)
|
||||
{
|
||||
HRESULT hr;
|
||||
if (irp->op == IRP_OP_OPEN) {
|
||||
dprintf("BNG Reader: Starting backend\n");
|
||||
dprintf("Reader: Baudrate %ld\n", bp_uart.baud.BaudRate);
|
||||
}
|
||||
|
||||
hr = uart_handle_irp(&bp_uart, irp);
|
||||
if (FAILED(hr)) {
|
||||
return hr;
|
||||
}
|
||||
#if 0
|
||||
if (irp->op == IRP_OP_WRITE) {
|
||||
dprintf("WRITE:\n");
|
||||
dump_iobuf(&bp_uart.written);
|
||||
}
|
||||
if (irp->op == IRP_OP_READ) {
|
||||
dprintf("READ:\n");
|
||||
dump_iobuf(&bp_uart.readable);
|
||||
}
|
||||
#endif
|
||||
if (irp->op == IRP_OP_WRITE) {
|
||||
write_ct = 0;
|
||||
if (bp_uart.written.bytes[0] == 0x55) {
|
||||
dprintf("Reader: Hello\n");
|
||||
return hr;
|
||||
}
|
||||
else if (bp_uart.written.bytes[3] == 0x00) {
|
||||
dprintf("Reader: Wait Next Cmd\n");
|
||||
last_cmd = 0x00;
|
||||
return hr;
|
||||
}
|
||||
else {
|
||||
last_cmd = bp_uart.written.bytes[3];
|
||||
dump_iobuf(&bp_uart.written);
|
||||
return hr;
|
||||
}
|
||||
}
|
||||
if (irp->op == IRP_OP_READ) {
|
||||
dprintf("Reader: last_cmd %d write_ct %d\n", last_cmd, write_ct);
|
||||
switch (last_cmd) {
|
||||
case 0x03:
|
||||
dprintf("Reader: Initalize Reader\n");
|
||||
uint8_t buff_init[] = { 00, 00, 0xFF, 00, 0xFF, 00, 00, 00, 0xFF, 0x02, 0xFE, 0xD5, 0x19, 0x12, 0x00};
|
||||
iobuf_write(&bp_uart.readable, buff_init, sizeof(buff_init));
|
||||
bp_uart.written.pos = 0;
|
||||
break;
|
||||
|
||||
case 0x06:
|
||||
dprintf("Reader: Unknown 0x06\n");
|
||||
uint8_t buff_unk6_r1[] = { 00, 00, 0xff, 00, 0xff, 00, 00, 00 };
|
||||
uint8_t buff_unk6_r2[] = {0xFF, 02, 0xFE, 0xd5, 0x33, 0xf8, 0x00};
|
||||
|
||||
if (!write_ct)
|
||||
iobuf_write(&bp_uart.readable, buff_unk6_r1, sizeof(buff_unk6_r1));
|
||||
else
|
||||
iobuf_write(&bp_uart.readable, buff_unk6_r2, sizeof(buff_unk6_r2));
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
dprintf("Reader: Unknown Command %02X\n", last_cmd);
|
||||
dump_iobuf(&bp_uart.written);
|
||||
break;
|
||||
}
|
||||
write_ct++;
|
||||
}
|
||||
|
||||
bp_uart.written.pos = 0;
|
||||
return hr;
|
||||
}
|
@ -5,8 +5,9 @@
|
||||
|
||||
struct bpreader_config {
|
||||
bool enable;
|
||||
char access_code[21];
|
||||
uint16_t port;
|
||||
wchar_t access_code[21];
|
||||
};
|
||||
|
||||
HRESULT bpreader_init(uint16_t port);
|
||||
void bpreader_congif_init(struct bpreader_config *cfg);
|
||||
HRESULT bpreader_init(struct bpreader_config *cfg, uint16_t port);
|
||||
void bpreader_congif_load(struct bpreader_config *cfg, const wchar_t *filename);
|
4
dist/ferrum/bananatools.ini
vendored
4
dist/ferrum/bananatools.ini
vendored
@ -36,6 +36,10 @@ server_host=localhost
|
||||
[xinput]
|
||||
enable=1
|
||||
|
||||
[reader]
|
||||
enable=1
|
||||
access_code=00000000000000000000
|
||||
|
||||
; JVS config
|
||||
[jvs]
|
||||
enable=1
|
||||
|
4
dist/taiko/bananatools.ini
vendored
4
dist/taiko/bananatools.ini
vendored
@ -21,6 +21,10 @@ windowed=1
|
||||
framed=0
|
||||
monitor=0
|
||||
|
||||
[reader]
|
||||
enable=1
|
||||
access_code=00000000000000000000
|
||||
|
||||
; Control the AMCUS replacement class
|
||||
[amcus]
|
||||
enable=1
|
||||
|
@ -31,16 +31,6 @@ void ferrum_xinput_config_load(
|
||||
cfg->enable = GetPrivateProfileIntW(L"xinput", L"enable", 1, filename);
|
||||
}
|
||||
|
||||
void ferrum_network_config_load(
|
||||
struct ferrum_network_config *cfg,
|
||||
const wchar_t *filename)
|
||||
{
|
||||
assert(cfg != NULL);
|
||||
assert(filename != NULL);
|
||||
|
||||
cfg->enable = GetPrivateProfileIntW(L"network", L"enable", 1, filename);
|
||||
}
|
||||
|
||||
|
||||
void ferrum_hook_config_load(
|
||||
struct ferrum_hook_config *cfg,
|
||||
@ -53,5 +43,5 @@ void ferrum_hook_config_load(
|
||||
ferrum_dll_config_load(&cfg->dll, filename);
|
||||
ferrum_xinput_config_load(&cfg->xinput, filename);
|
||||
gfx_config_load(&cfg->gfx, filename);
|
||||
ferrum_network_config_load(&cfg->network, filename);
|
||||
bpreader_congif_load(&cfg->reader, filename);
|
||||
}
|
||||
|
@ -5,7 +5,7 @@
|
||||
#include "ferrumhook/ferrum-dll.h"
|
||||
#include "ferrumhook/xinput.h"
|
||||
#include "ferrumhook/jvs.h"
|
||||
#include "ferrumhook/network.h"
|
||||
#include "board/bpreader.h"
|
||||
|
||||
#include "platform/config.h"
|
||||
#include "gfxhook/config.h"
|
||||
@ -17,7 +17,7 @@ struct ferrum_hook_config {
|
||||
struct ferrum_xinput_config xinput;
|
||||
struct gfx_config gfx;
|
||||
struct amcus_config amcus;
|
||||
struct ferrum_network_config network;
|
||||
struct bpreader_config reader;
|
||||
};
|
||||
|
||||
void ferrum_dll_config_load(
|
||||
@ -28,10 +28,6 @@ void ferrum_xinput_config_load(
|
||||
struct ferrum_xinput_config *cfg,
|
||||
const wchar_t *filename);
|
||||
|
||||
void ferrum_network_config_load(
|
||||
struct ferrum_network_config *cfg,
|
||||
const wchar_t *filename);
|
||||
|
||||
void ferrum_hook_config_load(
|
||||
struct ferrum_hook_config *cfg,
|
||||
const wchar_t *filename);
|
||||
|
@ -5,7 +5,6 @@
|
||||
#include "ferrumhook/ferrum-dll.h"
|
||||
#include "ferrumhook/xinput.h"
|
||||
#include "ferrumhook/jvs.h"
|
||||
#include "ferrumhook/network.h"
|
||||
|
||||
#include "amcus/amcus.h"
|
||||
|
||||
@ -18,6 +17,7 @@
|
||||
#include "gfxhook/gfx.h"
|
||||
#include "gfxhook/dxgi.h"
|
||||
#include "gfxhook/d3d11.h"
|
||||
#include "board/bpreader.h"
|
||||
|
||||
#include "util/dprintf.h"
|
||||
|
||||
@ -65,7 +65,7 @@ static DWORD CALLBACK ferrum_pre_startup(void)
|
||||
ExitProcess(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
hr = network_hook_init(&ferrum_hook_cfg.network);
|
||||
hr = bpreader_init(&ferrum_hook_cfg.reader, 4);
|
||||
|
||||
if (FAILED(hr)) {
|
||||
ExitProcess(EXIT_FAILURE);
|
||||
|
@ -18,6 +18,7 @@ shared_library(
|
||||
hooklib_lib,
|
||||
gfxhook_lib,
|
||||
jvs_lib,
|
||||
board_lib,
|
||||
],
|
||||
sources : [
|
||||
'dllmain.c',
|
||||
@ -29,7 +30,5 @@ shared_library(
|
||||
'xinput.h',
|
||||
'jvs.c',
|
||||
'jvs.h',
|
||||
'network.c',
|
||||
'network.h',
|
||||
],
|
||||
)
|
||||
|
@ -1,66 +0,0 @@
|
||||
#include <windows.h>
|
||||
|
||||
#include "taikohook/network.h"
|
||||
|
||||
#include "hook/table.h"
|
||||
|
||||
#include "util/dprintf.h"
|
||||
|
||||
void network_insert_hooks(HMODULE target);
|
||||
|
||||
static uint64_t my_TLSv1_method();
|
||||
static uint64_t my_SSL_CTX_new(void *method);
|
||||
static uint64_t (*next_TLSv1_2_method)();
|
||||
static uint64_t (*next_TLSv1_method)();
|
||||
static uint64_t (*next_SSL_CTX_new)(void *method);
|
||||
|
||||
static const struct hook_symbol nethook_syms[] = {
|
||||
{
|
||||
.link = (void *) &next_TLSv1_2_method,
|
||||
.ordinal = 350
|
||||
},
|
||||
{
|
||||
.patch = my_TLSv1_method,
|
||||
.link = (void *) &next_TLSv1_method,
|
||||
.ordinal = 170
|
||||
},
|
||||
{
|
||||
.patch = my_SSL_CTX_new,
|
||||
.link = (void *) &next_SSL_CTX_new,
|
||||
.ordinal = 12
|
||||
},
|
||||
};
|
||||
|
||||
HRESULT network_hook_init(const struct ferrum_network_config *cfg)
|
||||
{
|
||||
if (!cfg->enable) {
|
||||
return S_FALSE;
|
||||
}
|
||||
|
||||
dprintf("Nethook: Init\n");
|
||||
network_insert_hooks(NULL);
|
||||
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
void network_insert_hooks(HMODULE target)
|
||||
{
|
||||
hook_table_apply(
|
||||
target,
|
||||
"ssleay32.dll",
|
||||
nethook_syms,
|
||||
_countof(nethook_syms)
|
||||
);
|
||||
}
|
||||
|
||||
static uint64_t my_TLSv1_method()
|
||||
{
|
||||
dprintf("Nethook: Redirect TLS v1.0 to v1.2\n");
|
||||
return next_TLSv1_2_method();
|
||||
}
|
||||
|
||||
static uint64_t my_SSL_CTX_new(void *method)
|
||||
{
|
||||
dprintf("Nethook: my_SSL_CTX_new\n");
|
||||
return next_SSL_CTX_new(method);
|
||||
}
|
@ -1,10 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <windows.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
struct ferrum_network_config {
|
||||
bool enable;
|
||||
};
|
||||
|
||||
HRESULT network_hook_init(const struct ferrum_network_config *cfg);
|
@ -23,8 +23,8 @@ static HRESULT jvs_handle_irp_locked(struct irp *irp);
|
||||
|
||||
static struct uart jvs_uart;
|
||||
static CRITICAL_SECTION jvs_lock;
|
||||
static uint8_t jvs_written_bytes[520];
|
||||
static uint8_t jvs_readable_bytes[520];
|
||||
static uint8_t bp_written_bytes[520];
|
||||
static uint8_t bp_readable_bytes[520];
|
||||
|
||||
static struct jvs_node *jvs_root;
|
||||
static jvs_provider_t jvs_provider;
|
||||
@ -40,10 +40,10 @@ HRESULT jvs_hook_init(const struct jvs_config *cfg, jvs_provider_t provider)
|
||||
dprintf("JVS I/O: init\n");
|
||||
|
||||
uart_init(&jvs_uart, cfg->port);
|
||||
jvs_uart.written.bytes = jvs_written_bytes;
|
||||
jvs_uart.written.nbytes = sizeof(jvs_written_bytes);
|
||||
jvs_uart.readable.bytes = jvs_readable_bytes;
|
||||
jvs_uart.readable.nbytes = sizeof(jvs_readable_bytes);
|
||||
jvs_uart.written.bytes = bp_written_bytes;
|
||||
jvs_uart.written.nbytes = sizeof(bp_written_bytes);
|
||||
jvs_uart.readable.bytes = bp_readable_bytes;
|
||||
jvs_uart.readable.nbytes = sizeof(bp_readable_bytes);
|
||||
|
||||
jvs_provider = provider;
|
||||
|
||||
|
0
taikohook/bngrw.c
Normal file
0
taikohook/bngrw.c
Normal file
0
taikohook/bngrw.h
Normal file
0
taikohook/bngrw.h
Normal file
@ -64,4 +64,5 @@ void taiko_hook_config_load(
|
||||
gfx_config_load(&cfg->gfx, filename);
|
||||
qr_config_load(&cfg->qr, filename);
|
||||
network_config_load(&cfg->network, filename);
|
||||
bpreader_congif_load(&cfg->reader, filename);
|
||||
}
|
||||
|
@ -10,6 +10,7 @@
|
||||
#include "platform/config.h"
|
||||
#include "gfxhook/config.h"
|
||||
#include "amcus/config.h"
|
||||
#include "board/bpreader.h"
|
||||
|
||||
struct taiko_hook_config {
|
||||
struct platform_config platform;
|
||||
@ -19,6 +20,7 @@ struct taiko_hook_config {
|
||||
struct amcus_config amcus;
|
||||
struct qr_config qr;
|
||||
struct ferrum_network_config network;
|
||||
struct bpreader_config reader;
|
||||
};
|
||||
|
||||
void taiko_dll_config_load(
|
||||
|
@ -18,6 +18,7 @@ shared_library(
|
||||
hooklib_lib,
|
||||
gfxhook_lib,
|
||||
jvs_lib,
|
||||
board_lib
|
||||
],
|
||||
sources : [
|
||||
'dllmain.c',
|
||||
@ -33,5 +34,7 @@ shared_library(
|
||||
'qr.h',
|
||||
'network.c',
|
||||
'network.h',
|
||||
'bngrw.c',
|
||||
'bngrw.h',
|
||||
],
|
||||
)
|
||||
|
Loading…
Reference in New Issue
Block a user