From 51b11469d007f0e07b606d3d3c9a5571920455f0 Mon Sep 17 00:00:00 2001 From: Dniel97 Date: Tue, 29 Aug 2023 22:57:04 +0200 Subject: [PATCH] added `aimeGen` as default instead of `feliciaGen` --- aimeio/aimeio.c | 73 +++++++++++++++++++++++++++++++++++++-- dist/chusan/segatools.ini | 1 + dist/cm/segatools.ini | 1 - dist/idac/segatools.ini | 1 - dist/mai2/segatools.ini | 1 + dist/mu3/segatools.ini | 1 - dist/swdc/segatools.ini | 1 - doc/config/common.md | 9 ++++- 8 files changed, 81 insertions(+), 7 deletions(-) diff --git a/aimeio/aimeio.c b/aimeio/aimeio.c index f505aac..fa0db03 100644 --- a/aimeio/aimeio.c +++ b/aimeio/aimeio.c @@ -17,6 +17,7 @@ struct aime_io_config { wchar_t aime_path[MAX_PATH]; wchar_t felica_path[MAX_PATH]; bool felica_gen; + bool aime_gen; uint8_t vk_scan; }; @@ -40,6 +41,11 @@ static HRESULT aime_io_generate_felica( uint8_t *bytes, size_t nbytes); +static HRESULT aime_io_generate_aime( + const wchar_t *path, + uint8_t *bytes, + size_t nbytes); + static void aime_io_config_read( struct aime_io_config *cfg, const wchar_t *filename) @@ -67,6 +73,12 @@ static void aime_io_config_read( cfg->felica_gen = GetPrivateProfileIntW( L"aime", L"felicaGen", + 0, + filename); + + cfg->aime_gen = GetPrivateProfileIntW( + L"aime", + L"aimeGen", 1, filename); @@ -136,7 +148,7 @@ static HRESULT aime_io_generate_felica( srand(time(NULL)); - for (i = 0 ; i < nbytes ; i++) { + for (i = 0; i < nbytes; i++) { bytes[i] = rand(); } @@ -151,7 +163,7 @@ static HRESULT aime_io_generate_felica( return E_FAIL; } - for (i = 0 ; i < nbytes ; i++) { + for (i = 0; i < nbytes; i++) { fprintf(f, "%02X", bytes[i]); } @@ -163,6 +175,47 @@ static HRESULT aime_io_generate_felica( return S_OK; } +static HRESULT aime_io_generate_aime( + const wchar_t *path, + uint8_t *bytes, + size_t nbytes) +{ + size_t i; + FILE *f; + + assert(path != NULL); + assert(bytes != NULL); + assert(nbytes > 0); + + srand(time(NULL)); + + /* AiMe IDs should not start with 3, due to a missing check for BananaPass IDs */ + do { + for (i = 0; i < nbytes; i++) { + bytes[i] = rand() % 10 << 4 | rand() % 10; + } + } while (bytes[0] >> 4 == 3); + + f = _wfopen(path, L"w"); + + if (f == NULL) { + dprintf("AimeIO DLL: %S: fopen failed: %i\n", path, (int) errno); + + return E_FAIL; + } + + for (i = 0; i < nbytes; i++) { + fprintf(f, "%02x", bytes[i]); + } + + fprintf(f, "\n"); + fclose(f); + + dprintf("AimeIO DLL: Generated random AiMe ID\n"); + + return S_OK; +} + uint16_t aime_io_get_api_version(void) { return 0x0100; @@ -210,6 +263,22 @@ HRESULT aime_io_nfc_poll(uint8_t unit_no) return S_OK; } + /* Try generating AiMe IC (if enabled) */ + + if (aime_io_cfg.aime_gen) { + hr = aime_io_generate_aime( + aime_io_cfg.aime_path, + aime_io_aime_id, + sizeof(aime_io_aime_id)); + + if (FAILED(hr)) { + return hr; + } + + aime_io_aime_id_present = true; + return S_OK; + } + /* Try FeliCa IC */ hr = aime_io_read_id_file( diff --git a/dist/chusan/segatools.ini b/dist/chusan/segatools.ini index a2189f9..b1da417 100644 --- a/dist/chusan/segatools.ini +++ b/dist/chusan/segatools.ini @@ -11,6 +11,7 @@ appdata= [aime] ; Enable aime reader emulation. enable=1 +aimePath=DEVICE\aime.txt ; Enable high baud rate. ;highbaud=1 diff --git a/dist/cm/segatools.ini b/dist/cm/segatools.ini index 31e9d96..93b2151 100644 --- a/dist/cm/segatools.ini +++ b/dist/cm/segatools.ini @@ -12,7 +12,6 @@ appdata= ; Enable aime reader emulation. enable=1 aimePath=DEVICE\aime.txt -felicaGen=0 [dns] ; Insert the hostname or IP address of the server you wish to use here. diff --git a/dist/idac/segatools.ini b/dist/idac/segatools.ini index 0994d84..2d8b164 100644 --- a/dist/idac/segatools.ini +++ b/dist/idac/segatools.ini @@ -12,7 +12,6 @@ appdata= ; Controls emulation of the Aime card reader assembly. enable=1 aimePath=DEVICE\aime.txt -felicaGen=0 [dns] ; Insert the hostname or IP address of the server you wish to use here. diff --git a/dist/mai2/segatools.ini b/dist/mai2/segatools.ini index a86bee4..148d852 100644 --- a/dist/mai2/segatools.ini +++ b/dist/mai2/segatools.ini @@ -11,6 +11,7 @@ appdata= [aime] ; Enable aime reader emulation. enable=1 +aimePath=DEVICE\aime.txt [dns] ; Insert the hostname or IP address of the server you wish to use here. diff --git a/dist/mu3/segatools.ini b/dist/mu3/segatools.ini index 9c8f46f..a9f82e1 100644 --- a/dist/mu3/segatools.ini +++ b/dist/mu3/segatools.ini @@ -12,7 +12,6 @@ appdata= ; Controls emulation of the Aime card reader assembly. enable=1 aimePath=DEVICE\aime.txt -felicaGen=0 [dns] ; Insert the hostname or IP address of the server you wish to use here. diff --git a/dist/swdc/segatools.ini b/dist/swdc/segatools.ini index 24cbb8f..5a3493b 100644 --- a/dist/swdc/segatools.ini +++ b/dist/swdc/segatools.ini @@ -12,7 +12,6 @@ appdata= ; Controls emulation of the Aime card reader assembly. enable=1 aimePath=DEVICE\aime.txt -felicaGen=0 [dns] ; Insert the hostname or IP address of the server you wish to use here. diff --git a/doc/config/common.md b/doc/config/common.md index de6f267..0236eaf 100644 --- a/doc/config/common.md +++ b/doc/config/common.md @@ -45,6 +45,13 @@ Default: `DEVICE\aime.txt` Path to a text file containing a classic Aime IC card ID. **This does not currently work**. +### `aimeGen` + +Default: `1` + +Whether to generate a random AiMe ID if the file at `aimePath` does not +exist. + ### `felicaPath` Default: `DEVICE\felica.txt` @@ -53,7 +60,7 @@ Path to a text file containing a FeliCa e-cash card IDm serial number. ### `felicaGen` -Default: `1` +Default: `0` Whether to generate a random FeliCa ID if the file at `felicaPath` does not exist.