From 31131a32d84bffc128f79a63f82aae5a36a632d2 Mon Sep 17 00:00:00 2001 From: petrs Date: Mon, 9 Jul 2018 22:23:23 +0200 Subject: [PATCH 01/11] improved searching for winscard_rules.txt file + logging --- Winscard/Winscard.cpp | 101 +++++++++++++++++++++++++++++------------- 1 file changed, 70 insertions(+), 31 deletions(-) diff --git a/Winscard/Winscard.cpp b/Winscard/Winscard.cpp index 5ee2e35..e884b52 100644 --- a/Winscard/Winscard.cpp +++ b/Winscard/Winscard.cpp @@ -80,7 +80,10 @@ static SCard \1 (STDCALL *Original_\2) /**/ #pragma warning(disable:4996) -static string_type ENV_WINSCARD_RULES_PATH = _CONV("APDUPLAY"); +static string_type ENV_APDUPLAY_WINSCARD_RULES_PATH = _CONV("APDUPLAY"); +static string_type ENV_APDUPLAY_DEBUG_PATH = _CONV("APDUPLAY_DEBUG"); +static string_type APDUPLAY_DEBUG_FILE = _CONV("c:\\Temp\\apduplay_debug.txt"); + static string_type RULE_FILE = _CONV("winscard_rules.txt"); static string_type WINSCARD_RULES_LOG = _CONV("winscard_rules_log.txt"); static string_type WINSCARD_LOG = _CONV("winscard_log.txt"); @@ -108,6 +111,8 @@ BYTE GET_APDU2[] = { 0xC0, 0xC0, 0x00, 0x00 }; #define VIRTUAL_READERS_LEN strlen(VIRT_READER_NAME) #define REMOTE_READER_PREFIX "Simona" +//#define REMOTE_READER_PREFIX "Generic EMV Smartcard" + #define CMD_APDU "APDU" #define CMD_RESET "RESET" @@ -738,7 +743,7 @@ SCard LONG STDCALL SCardConnect( dwShareMode = SCARD_SHARE_SHARED; } - // Detect remote cards (now only via reader prefix and assign virtual card handle) + // Detect remote cards (now only via reader prefix) and assign virtual card handle string_type readerName = szReader; if (readerName.find(REMOTE_READER_PREFIX) != -1) { theApp.m_nextRemoteCardID++; @@ -2808,7 +2813,7 @@ void GetDesktopPath(char_type* path) string_type stringPath = "/home/"; stringPath += login; stringPath += "/Desktop/APDUPlay/"; - type_copy(path, stringPath.c_str()); + type_copy(rulesFilePath, stringPath.c_str()); #else char_type appData[MAX_PATH]; SHGetFolderPath(NULL, CSIDL_DESKTOPDIRECTORY | CSIDL_FLAG_CREATE, NULL, SHGFP_TYPE_CURRENT, appData); @@ -2822,10 +2827,17 @@ BOOL CWinscardApp::InitInstance() { CWinApp::InitInstance(); + char* debugPath = std::getenv(ENV_APDUPLAY_DEBUG_PATH.c_str()); + if (debugPath != NULL) { + APDUPLAY_DEBUG_FILE = debugPath; + } + srand((int) time(NULL)); + CCommonFnc::File_AppendString(APDUPLAY_DEBUG_FILE, _CONV("InitInstance\n")); // LOAD MODIFICATION RULES LoadRules(); + CCommonFnc::File_AppendString(APDUPLAY_DEBUG_FILE, _CONV("After LoadRules\n")); // CONNECT TO REMOTE SOCKET IF REQUIRED if (m_remoteConfig.bRedirect) { @@ -3486,8 +3498,9 @@ int CWinscardApp::LoadRule(const char_type* section_name, dictionary* dict/*stri int CWinscardApp::LoadRules() { int status = STAT_OK; FILE *file = NULL; - char_type path[256]; - type_copy(path, RULE_FILE.c_str()); + char_type rulesFilePath[256]; + char_type baseDir[256]; // base rulesFilePath for input/output files + type_copy(rulesFilePath, RULE_FILE.c_str()); string_type date_and_time = getCurrentTimeString(); @@ -3498,33 +3511,53 @@ int CWinscardApp::LoadRules() { // Searching for 'winscard_rules.txt' (priority) // 1. Lookup in local directory // 2. Lookup for APDUPLAY environmental variable - // 3. Lookup on user Desktop + // (UNUSED) 3. Lookup on user Desktop if (!file) { // 1. Lookup in local directory - file = fopen(path, "r"); + CCommonFnc::File_AppendString(APDUPLAY_DEBUG_FILE, string_format(_CONV("Going to open %s ... "), rulesFilePath)); + file = fopen(rulesFilePath, "r"); + if (file) { + CCommonFnc::File_AppendString(APDUPLAY_DEBUG_FILE, _CONV("success\n")); + type_copy(baseDir, ""); + } + else { + CCommonFnc::File_AppendString(APDUPLAY_DEBUG_FILE, _CONV("fail\n")); + } } if (!file) { // 2. Lookup for APDUPLAY environmental variable - char* configPath = std::getenv(ENV_WINSCARD_RULES_PATH.c_str()); + char* configPath = std::getenv(ENV_APDUPLAY_WINSCARD_RULES_PATH.c_str()); + CCommonFnc::File_AppendString(APDUPLAY_DEBUG_FILE, string_format(_CONV("Going to query %s env variable ... "), ENV_APDUPLAY_WINSCARD_RULES_PATH)); if (configPath != NULL) { + CCommonFnc::File_AppendString(APDUPLAY_DEBUG_FILE, string_format(_CONV(" defined (%s)\n"), configPath)); // variable detected, try to open string newRuleFile = string_format(_CONV("%s\\%s"), configPath, RULE_FILE.c_str()); + CCommonFnc::File_AppendString(APDUPLAY_DEBUG_FILE, string_format(_CONV("Going to open %s ... "), newRuleFile.c_str())); file = fopen(newRuleFile.c_str(), "r"); if (file) { - type_copy(path, newRuleFile.c_str()); + CCommonFnc::File_AppendString(APDUPLAY_DEBUG_FILE, _CONV("success\n")); + type_copy(rulesFilePath, newRuleFile.c_str()); + type_copy(baseDir, configPath); + } + else { + CCommonFnc::File_AppendString(APDUPLAY_DEBUG_FILE, _CONV("fail\n")); } } + else { + CCommonFnc::File_AppendString(APDUPLAY_DEBUG_FILE, _CONV("not found\n")); + } } +/* if (!file) { // 3. Lookup on user Desktop - GetDesktopPath(path); - type_cat(path, RULE_FILE.c_str()); - file = fopen(path, "r"); // try to open file on desktop + GetDesktopPath(rulesFilePath); + type_cat(rulesFilePath, RULE_FILE.c_str()); + file = fopen(rulesFilePath, "r"); // try to open file on desktop } - +*/ if (file) { fclose(file); - dictionary* dict = iniparser_load(path); + dictionary* dict = iniparser_load(rulesFilePath); int number_of_sections = iniparser_getnsec(dict); @@ -3539,21 +3572,27 @@ int CWinscardApp::LoadRules() { iniparser_freedict(dict); } else { + CCommonFnc::File_AppendString(APDUPLAY_DEBUG_FILE, _CONV("Rules file NOT found\n")); CCommonFnc::File_AppendString(WINSCARD_RULES_LOG, _CONV("Rules file NOT found\n")); } if (!m_winscardConfig.sLOG_BASE_PATH.empty()) { - WINSCARD_RULES_LOG = string_format(_CONV("%s%s"), m_winscardConfig.sLOG_BASE_PATH.c_str(), WINSCARD_RULES_LOG.c_str()); - WINSCARD_LOG = string_format(_CONV("%s%s"), m_winscardConfig.sLOG_BASE_PATH.c_str(), WINSCARD_LOG.c_str()); - INSTRUCTION_FILE = string_format(_CONV("%s%s"), m_winscardConfig.sLOG_BASE_PATH.c_str(), INSTRUCTION_FILE.c_str()); + CCommonFnc::File_AppendString(APDUPLAY_DEBUG_FILE, string_format(_CONV("Logging base path is forced as '%s' (LOG_BASE_PATH)\n"), m_winscardConfig.sLOG_BASE_PATH.c_str())); + + // Use provided directory to store output files + WINSCARD_RULES_LOG = string_format(_CONV("%s\\%s"), m_winscardConfig.sLOG_BASE_PATH.c_str(), WINSCARD_RULES_LOG.c_str()); + WINSCARD_LOG = string_format(_CONV("%s\\%s"), m_winscardConfig.sLOG_BASE_PATH.c_str(), WINSCARD_LOG.c_str()); + INSTRUCTION_FILE = string_format(_CONV("%s\\%s"), m_winscardConfig.sLOG_BASE_PATH.c_str(), INSTRUCTION_FILE.c_str()); } else { - GetDesktopPath(path); - WINSCARD_RULES_LOG = string_format(_CONV("%s%s"), path, WINSCARD_RULES_LOG.c_str()); - WINSCARD_LOG = string_format(_CONV("%s%s"), path, WINSCARD_LOG.c_str()); - INSTRUCTION_FILE = string_format(_CONV("%s%s"), path, INSTRUCTION_FILE.c_str()); + CCommonFnc::File_AppendString(APDUPLAY_DEBUG_FILE, string_format(_CONV("Logging base path not forced, using '%s'\n"), baseDir)); + + // Use base directory to store output files + WINSCARD_RULES_LOG = string_format(_CONV("%s%s"), baseDir, WINSCARD_RULES_LOG.c_str()); + WINSCARD_LOG = string_format(_CONV("%s%s"), baseDir, WINSCARD_LOG.c_str()); + INSTRUCTION_FILE = string_format(_CONV("%s%s"), baseDir, INSTRUCTION_FILE.c_str()); } std::fstream instruction_file; @@ -3564,10 +3603,10 @@ int CWinscardApp::LoadRules() { theApp.m_winscardConfig.bLOG_WRITE_DESCRIPTION = TRUE; instruction_file.close(); CCommonFnc::File_AppendString(WINSCARD_RULES_LOG, _CONV("Instruction file found")); - instructionDict = iniparser_load((const char*)INSTRUCTION_FILE.c_str()); + instructionDict = iniparser_load((const char*) INSTRUCTION_FILE.c_str()); } - return status; + return status; } #endif @@ -3854,19 +3893,19 @@ int CWinscardApp::LoadRules() { memset(buffer, 0, cBuffer); - char_type path[256]; - type_copy(path, RULE_FILE.c_str()); + char_type rulesFilePath[256]; + type_copy(rulesFilePath, RULE_FILE.c_str()); string_type date_and_time = getCurrentTimeString(); WINSCARD_LOG += _CONV("_") + date_and_time + _CONV(".txt"); WINSCARD_RULES_LOG += _CONV("_") + date_and_time + _CONV(".txt"); - if (!(file = type_fopen(path, _CONV("r")))) // try to open file in current directory + if (!(file = type_fopen(rulesFilePath, _CONV("r")))) // try to open file in current directory { - type_copy(path, GetDesktopPath()); - type_cat(path, RULE_FILE.c_str()); - file = type_fopen(path, _CONV("r")); // try to open file on desktop + type_copy(rulesFilePath, GetDesktopPath()); + type_cat(rulesFilePath, RULE_FILE.c_str()); + file = type_fopen(rulesFilePath, _CONV("r")); // try to open file on desktop } if (file) { @@ -3882,13 +3921,13 @@ int CWinscardApp::LoadRules() { CCommonFnc::File_AppendString(WINSCARD_RULES_LOG, message); // OBTAIN SECTION NAMES - if ((cReaded = GetPrivateProfileString(NULL, NULL, _CONV(""), buffer, cBuffer, path)) != 0) { + if ((cReaded = GetPrivateProfileString(NULL, NULL, _CONV(""), buffer, cBuffer, rulesFilePath)) != 0) { // PARSE SECTION NAMES, TRY TO LOAD EACH RULE CCommonFnc::String_ParseNullSeparatedArray(buffer, cBuffer, &valuesList); for (auto iter = valuesList.begin(); iter != valuesList.end(); iter++) { - LoadRule(*iter, path); + LoadRule(*iter, rulesFilePath); } } m_bRulesActive = TRUE; From 6048294bed487feb9a8ccd9510455bf5468b93de Mon Sep 17 00:00:00 2001 From: petrs Date: Mon, 9 Jul 2018 22:35:42 +0200 Subject: [PATCH 02/11] troubleshooting, more details --- README.md | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 58a4d9f..7addfce 100644 --- a/README.md +++ b/README.md @@ -21,18 +21,37 @@ The APDUPlay project is providing following functionality: See more details at https://github.com/petrs/APDUPlay/wiki. ## Installation -1. Find out if your targeted application is 32- or 64-bit [(howto)](https://superuser.com/questions/103071/quick-way-to-tell-if-an-installed-application-is-64-bit-or-32-bit#103073). -1. Copy Winscard.dll from your system folder (c:\Windows\winscard.dll for 32-bit target application or c:\Windows\SysWOW64\winscard.dll for 64-bit application) to the folder with target application and rename it to original32.dll or original64.dll respectively +1. Find out if your targeted application is 32- or 64-bit [(Use Microsoft Sysinternals Sigcheck utility)](https://docs.microsoft.com/en-us/sysinternals/downloads/sigcheck). Run sigcheck.exe targetApp.exe and look for MachineType: 32-bit or 64-bit (works also for dll files) +1. Copy Winscard.dll from your system folder (c:\Windows\System32\winscard.dll for 64-bit target application (if you are running 64-bit OS) or c:\Windows\SysWOW64\winscard.dll for 32-bit application) to the folder with target application and rename it to original32.dll or original64.dll respectively. NOTE: c:\Windows\System32\ will contain either 32-bit or 64-bit version based on your OS. 2. Copy Winscard.dll from APDUPlay project to the folder with target application (the folder should contain winscard.dll binary from APDUPlay project AND originalXX.dll which is original Microsoft's winscard.dll) 3. Run the application and inspect resulting files winscard_log.txt and winscard_rules_log.txt 4. (Optional) Change configuration file winscard_rules.txt to modify default behavior (see below) -## Troubleshooting +## Examples - * If you use (wrongly) 64bit version of library Microsoft's winscard.dll (renamed as original32.dll), it will fail with "The procedure entry point original.g_rgSCardT1Pci could not be located in the dynamic link library WinSCard.dll." - +The localization of correct winscard.dll path can be tedious task for some applications. Here are some examples with increasing difficulty: + 1. Simple application directly using winscard.dll (example.exe) + 2. Application with persistent agent (gpg2.exe --card-edit) + 3. Java-based application: (GlobalPlatformPro gp -l) +## Troubleshooting + + * Problem: After running target application, the following error message is displayed: "The procedure entry point original.g_rgSCardT1Pci could not be located in the dynamic link library WinSCard.dll.". You likely mismatched 64-bit and 32-bit versions of APDUPlay's winscard.dll and Microsoft's original library (renamed as original32.dll). Use [Microsoft Sysinternals Sigcheck utility](https://docs.microsoft.com/en-us/sysinternals/downloads/sigcheck) to verify that both libraries as either 64-bit or 32-bit (based on your target application needs). + + * Problem: Target application is (probably) not loading modified winscard.dll from APDUPlay project, but uses standard Microsoft's one from system folder (no files with logged communication are created). Use [Process Monitor utility]( https://docs.microsoft.com/en-us/sysinternals/downloads/procmon) from Microsoft to find location of loaded libraries (use Filter option to limit results only to target application: CTRL+L -> Process Name is 'targetApp.exe' -> Add). Search for event 'Load Image path_to_folder\Winscard.dll'. The path_to_folder should point to APDUPlay's version of winscard.dll, not Microsoft one. + + * Problem: Logging seems to work, but only for the first of application. When started again, changes done to winscard_rules.txt does not apply. Target application might have persistent component (e.g., GPG have gpg-agent.exe) which loads the dll (and rules from winscard_rules.txt) and runs even when target application is terminated. Try to locate and kill this component, or restart computer (will force component to restart again). + + * Problem: Target application always opens winscard.dll from system folders (either system32 or sysWOW64 folder). +Run cmd as admin, then: +``` +cd target_folder (either system32 or sysWOW64) +takeown /f winscard.dll +cacls winscard.dll /G your_username:F +rename winscard.dll to winscard_MS.dll (winscard.dll might be currently used by some other process so direct copy woudl not be possible) +copy APDUPlay's winscard.dll instead winscard.dll +``` Please, open an issue in case of any bug found. From b8db3bde144d016c21c62f078985260e8454c2a8 Mon Sep 17 00:00:00 2001 From: petrs Date: Mon, 9 Jul 2018 23:30:04 +0200 Subject: [PATCH 03/11] all functions with hCard handle now check for remote card --- Winscard/Winscard.cpp | 105 ++++++++++++++++++++++++++++++++---------- Winscard/Winscard.h | 1 + 2 files changed, 82 insertions(+), 24 deletions(-) diff --git a/Winscard/Winscard.cpp b/Winscard/Winscard.cpp index e884b52..c743b96 100644 --- a/Winscard/Winscard.cpp +++ b/Winscard/Winscard.cpp @@ -246,7 +246,13 @@ SCard LONG STDCALL SCardReconnect( string_type message; message = string_format(_CONV("SCardReconnect(hCard:0x%x) called\n"), hCard); if (theApp.m_winscardConfig.bLOG_FUNCTIONS_CALLS) CCommonFnc::File_AppendString(WINSCARD_RULES_LOG, message); - return (*Original_SCardReconnect)(hCard, dwShareMode, dwPreferredProtocols, dwInitialization, pdwActiveProtocol); + if (theApp.IsRemoteCard(hCard)) { + return SCARD_S_SUCCESS; + *pdwActiveProtocol = SCARD_PROTOCOL_T1; + } + else { + return (*Original_SCardReconnect)(hCard, dwShareMode, dwPreferredProtocols, dwInitialization, pdwActiveProtocol); + } } static SCard LONG(STDCALL *Original_SCardBeginTransaction)( @@ -257,7 +263,12 @@ SCard LONG STDCALL SCardBeginTransaction( IN SCARDHANDLE hCard ) { CCommonFnc::File_AppendString(WINSCARD_RULES_LOG, _CONV("SCardBeginTransaction called\n")); - return (*Original_SCardBeginTransaction)(hCard); + if (theApp.IsRemoteCard(hCard)) { + return SCARD_S_SUCCESS; + } + else { + return (*Original_SCardBeginTransaction)(hCard); + } } @@ -271,7 +282,12 @@ SCard LONG STDCALL SCardEndTransaction( IN DWORD dwDisposition ) { if (theApp.m_winscardConfig.bLOG_FUNCTIONS_CALLS) CCommonFnc::File_AppendString(WINSCARD_RULES_LOG, _CONV("SCardEndTransaction called\n")); - return (*Original_SCardEndTransaction)(hCard, dwDisposition); + if (theApp.IsRemoteCard(hCard)) { + return SCARD_S_SUCCESS; + } + else { + return (*Original_SCardEndTransaction)(hCard, dwDisposition); + } } static SCard LONG(STDCALL *Original_SCardControl)( @@ -294,7 +310,12 @@ SCard LONG STDCALL SCardControl( OUT LPDWORD lpBytesReturned ) { if (theApp.m_winscardConfig.bLOG_FUNCTIONS_CALLS) CCommonFnc::File_AppendString(WINSCARD_RULES_LOG, _CONV("SCardControl called\n")); - return (*Original_SCardControl)(hCard, dwControlCode, lpInBuffer, nInBufferSize, lpOutBuffer, nOutBufferSize, lpBytesReturned); + if (theApp.IsRemoteCard(hCard)) { + return SCARD_S_SUCCESS; + } + else { + return (*Original_SCardControl)(hCard, dwControlCode, lpInBuffer, nInBufferSize, lpOutBuffer, nOutBufferSize, lpBytesReturned); + } } @@ -312,7 +333,12 @@ SCard LONG STDCALL SCardGetAttrib( IN OUT LPDWORD pcbAttrLen ) { if (theApp.m_winscardConfig.bLOG_FUNCTIONS_CALLS) CCommonFnc::File_AppendString(WINSCARD_RULES_LOG, _CONV("SCardGetAttrib called\n")); - return (*Original_SCardGetAttrib)(hCard, dwAttrId, pbAttr, pcbAttrLen); + if (theApp.IsRemoteCard(hCard)) { + return SCARD_S_SUCCESS; + } + else { + return (*Original_SCardGetAttrib)(hCard, dwAttrId, pbAttr, pcbAttrLen); + } } @@ -330,7 +356,12 @@ SCard LONG STDCALL SCardSetAttrib( IN DWORD cbAttrLen ) { if (theApp.m_winscardConfig.bLOG_FUNCTIONS_CALLS) CCommonFnc::File_AppendString(WINSCARD_RULES_LOG, _CONV("SCardSetAttrib called\n")); - return (*Original_SCardSetAttrib)(hCard, dwAttrId, pbAttr, cbAttrLen); + if (theApp.IsRemoteCard(hCard)) { + return SCARD_S_SUCCESS; + } + else { + return (*Original_SCardSetAttrib)(hCard, dwAttrId, pbAttr, cbAttrLen); + } } /* ******************************************************************************* */ @@ -483,8 +514,7 @@ SCard LONG STDCALL SCardDisconnect( if (theApp.m_winscardConfig.bLOG_FUNCTIONS_CALLS) CCommonFnc::File_AppendString(WINSCARD_RULES_LOG, _CONV("SCardDisconnect called\n")); // DISCONNECT FROM CARD - if (hCard == HANDLE_VIRTUAL_CARD) { - // DO NOTHING + if (theApp.IsRemoteCard(hCard)) { return SCARD_S_SUCCESS; } else { @@ -784,8 +814,21 @@ SCard LONG STDCALL SCardStatus( LPBYTE pbAtr, LPDWORD pcbAtrLen) { - if (theApp.m_winscardConfig.bLOG_FUNCTIONS_CALLS) CCommonFnc::File_AppendString(WINSCARD_RULES_LOG, _CONV("SCardStatus called\n")); - return (*Original_SCardStatus)(hCard, szReaderName, pcchReaderLen, pdwState, pdwProtocol, pbAtr, pcbAtrLen); + if (theApp.m_winscardConfig.bLOG_FUNCTIONS_CALLS) { + string_type message = string_format(_CONV("SCardStatus(hCard:0x%x,szReaderName:%s,pcchReaderLen:%d,pcbAtrLen:%d) called\n"), hCard, szReaderName, *pcchReaderLen, *pcbAtrLen); + CCommonFnc::File_AppendString(WINSCARD_RULES_LOG, message); + } + + if (theApp.IsRemoteCard(hCard)) { + // According to https://docs.microsoft.com/en-us/windows/desktop/api/winscard/nf-winscard-scardstatusa + *pdwState = SCARD_SPECIFIC; + *pdwProtocol = SCARD_PROTOCOL_T1; + + return SCARD_S_SUCCESS; + } + else { + return (*Original_SCardStatus)(hCard, szReaderName, pcchReaderLen, pdwState, pdwProtocol, pbAtr, pcbAtrLen); + } } static SCard LONG(STDCALL *Original_SCardListReaders)( @@ -1761,7 +1804,12 @@ SCard LONG STDCALL SCardCancelTransaction( IN SCARDHANDLE hCard ) { if (theApp.m_winscardConfig.bLOG_FUNCTIONS_CALLS) CCommonFnc::File_AppendString(WINSCARD_RULES_LOG, _CONV("SCardCancelTransaction called\n")); - return (*Original_SCardCancelTransaction)(hCard); + if (theApp.IsRemoteCard(hCard)) { + return SCARD_S_SUCCESS; + } + else { + return (*Original_SCardCancelTransaction)(hCard); + } } static SCard LONG(STDCALL *Original_SCardState)( @@ -1782,7 +1830,15 @@ SCard LONG STDCALL SCardState( string_type message; message = string_format(_CONV("SCardState(hCard:0x%x) called\n"), hCard); if (theApp.m_winscardConfig.bLOG_FUNCTIONS_CALLS) CCommonFnc::File_AppendString(WINSCARD_RULES_LOG, message); - return (*Original_SCardState)(hCard, pdwState, pdwProtocol, pbAtr, pcbAtrLen); + if (theApp.IsRemoteCard(hCard)) { + return SCARD_S_SUCCESS; + *pdwState = SCARD_SPECIFIC; + *pdwProtocol = SCARD_PROTOCOL_T1; + // TODO: fill pbAtr + } + else { + return (*Original_SCardState)(hCard, pdwState, pdwProtocol, pbAtr, pcbAtrLen); + } } @@ -1808,7 +1864,15 @@ SCard LONG STDCALL SCardStatusW( string_type message; message = string_format(_CONV("SCardStatusW(hCard:0x%x) called\n"), hCard); if (theApp.m_winscardConfig.bLOG_FUNCTIONS_CALLS) CCommonFnc::File_AppendString(WINSCARD_RULES_LOG, message); - return (*Original_SCardStatusW)(hCard, szReaderName, pcchReaderLen, pdwState, pdwProtocol, pbAtr, pcbAtrLen); + if (theApp.IsRemoteCard(hCard)) { + return SCARD_S_SUCCESS; + *pdwState = SCARD_SPECIFIC; + *pdwProtocol = SCARD_PROTOCOL_T1; + // TODO: fill pbAtr + } + else { + return (*Original_SCardStatusW)(hCard, szReaderName, pcchReaderLen, pdwState, pdwProtocol, pbAtr, pcbAtrLen); + } } static SCard HANDLE(STDCALL *Original_SCardAccessStartedEvent)(void); @@ -1854,13 +1918,6 @@ typedef FARPROC(STDCALL *q) (HMODULE, LPCSTR); static q load_func = GetProcAddress; #endif -/*linux specific funcions: -*SCardConnect -- DONE -*SCardStatus -- DONE -*SCardGetStatusChange -- DONE -*SCardListReaders -- DONE -*SCardListReaderGroups -- DONE -*/ int initialize() { char *error = ""; @@ -2855,11 +2912,11 @@ int CWinscardApp::Remote_Connect(REMOTE_CONFIG* pRemoteConfig) { //pRemoteConfig->pSocket = new SocketClient(sIP, atoi(pRemoteConfig->port.c_str())); try { pRemoteConfig->pSocket = new SocketClient(sIP, type_to_int(pRemoteConfig->port.c_str(), NULL, 10)); - message = string_format(_CONV("\n> Connnecting to remote proxy with IP:port = %s:%s"), pRemoteConfig->IP, pRemoteConfig->port); + message = string_format(_CONV("\n> Connnecting to remote proxy with IP:port = %s:%s\n"), pRemoteConfig->IP, pRemoteConfig->port); CCommonFnc::File_AppendString(WINSCARD_RULES_LOG, message); } catch (std::string error) { - message = string_format(_CONV("\n> Failed to connect to %s:%s (error: %s)"), pRemoteConfig->IP, pRemoteConfig->port, error); + message = string_format(_CONV("\n> Failed to connect to %s:%s (error: %s)\n"), pRemoteConfig->IP, pRemoteConfig->port, error); CCommonFnc::File_AppendString(WINSCARD_RULES_LOG, message); } @@ -3011,7 +3068,7 @@ LONG CWinscardApp::Remote_SCardConnect(REMOTE_CONFIG* pRemoteConfig, string_type string_type response; status = Remote_ParseResponse(l, theApp.m_remoteConfig.nextCommandID, &response); - message = string_format(_CONV("\n::<- %s"), response.c_str()); + message = string_format(_CONV("\n::<- %s\n"), response.c_str()); replace(message.begin(), message.end(), '\n', ' '); CCommonFnc::File_AppendString(WINSCARD_RULES_LOG, message); } @@ -3094,7 +3151,7 @@ LONG CWinscardApp::Remote_SCardTransmit(REMOTE_CONFIG* pRemoteConfig, string_typ string_type response; status = Remote_ParseResponse(l, theApp.m_remoteConfig.nextCommandID, &response); - message = string_format(_CONV("\n::<- %s"), l.c_str()); + message = string_format(_CONV("\n::<- %s\n"), l.c_str()); //message.Replace("\n", " "); replace(message.begin(), message.end(), '\n', ' '); CCommonFnc::File_AppendString(WINSCARD_RULES_LOG, message); diff --git a/Winscard/Winscard.h b/Winscard/Winscard.h index ab0bedd..393adf2 100644 --- a/Winscard/Winscard.h +++ b/Winscard/Winscard.h @@ -38,6 +38,7 @@ class CWinscardApp : public CWinApp unordered_map cardReaderMap; unordered_map remoteReadersMap; DWORD m_nextRemoteCardID = 1; + #if defined (_WIN32) From de0c478747d595043a0e941a1bcb6fed31276521 Mon Sep 17 00:00:00 2001 From: petrs Date: Tue, 10 Jul 2018 20:22:32 +0200 Subject: [PATCH 04/11] removal of multiple virtual readers --- Winscard/Winscard.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Winscard/Winscard.cpp b/Winscard/Winscard.cpp index c743b96..ca2cb70 100644 --- a/Winscard/Winscard.cpp +++ b/Winscard/Winscard.cpp @@ -107,7 +107,7 @@ BYTE GET_APDU1[] = { 0x00, 0xC0, 0x00, 0x00 }; BYTE GET_APDU2[] = { 0xC0, 0xC0, 0x00, 0x00 }; //#define VIRT_READER_NAME "VirtOpenPGP" -#define VIRT_READER_NAME "Simona /111.222.123.033@07\nSimona /111.222.123.033@12\nSimona /111.222.123.033@123" +#define VIRT_READER_NAME "Simona /111.222.123.033@07" #define VIRTUAL_READERS_LEN strlen(VIRT_READER_NAME) #define REMOTE_READER_PREFIX "Simona" @@ -2883,7 +2883,7 @@ void GetDesktopPath(char_type* path) BOOL CWinscardApp::InitInstance() { CWinApp::InitInstance(); - + // Check for user-defined path for debug file char* debugPath = std::getenv(ENV_APDUPLAY_DEBUG_PATH.c_str()); if (debugPath != NULL) { APDUPLAY_DEBUG_FILE = debugPath; From 623736306a155b2e32d696f6a0ad7404fb2952d2 Mon Sep 17 00:00:00 2001 From: petrs Date: Tue, 10 Jul 2018 21:35:36 +0200 Subject: [PATCH 05/11] fixed incorrect linking to original.dll instead of original32/64.dll --- Winscard/Winscard.def | 157 ------------------------------ Winscard/Winscard.vcproj | 3 - Winscard/Winscard.vcxproj | 31 +++--- Winscard/Winscard.vcxproj.filters | 3 - Winscard/Winscard32.def | 157 ++++++++++++++++++++++++++++++ Winscard/Winscard64.def | 157 ++++++++++++++++++++++++++++++ Winscard/original.def | 74 -------------- Winscard/original.lib | Bin 19590 -> 0 bytes 8 files changed, 329 insertions(+), 253 deletions(-) delete mode 100644 Winscard/Winscard.def create mode 100644 Winscard/Winscard32.def create mode 100644 Winscard/Winscard64.def delete mode 100644 Winscard/original.def delete mode 100644 Winscard/original.lib diff --git a/Winscard/Winscard.def b/Winscard/Winscard.def deleted file mode 100644 index 7fc794d..0000000 --- a/Winscard/Winscard.def +++ /dev/null @@ -1,157 +0,0 @@ -; Copyright (c) 2001 Andrew Fernandes . All rights reserved. -; -; This work may be used and distributed under the terms of the GNU Public License, -; as written in the included file "gpl.txt" or online at . -; -LIBRARY "winscard" -EXPORTS -; -; functions to pass transparently -; -;SCardAccessNewReaderEvent=original.SCardAccessNewReaderEvent @1 -;SCardAccessStartedEvent=original.SCardAccessStartedEvent @2 -;SCardAddReaderToGroupA=original.SCardAddReaderToGroupA @6 -;SCardAddReaderToGroupW=original.SCardAddReaderToGroupW @7 -;SCardBeginTransaction=original.SCardBeginTransaction @8 -;SCardCancel=original.SCardCancel @9 -;SCardConnectA=original.SCardConnectA @10 -;SCardConnectW=original.SCardConnectW @11 -;SCardControl=original.SCardControl @12 -;SCardDisconnect=original.SCardDisconnect @13 -;SCardEndTransaction=original.SCardEndTransaction @14 -;SCardEstablishContext=original.SCardEstablishContext @15 -;SCardForgetCardTypeA=original.SCardForgetCardTypeA @16 -;SCardForgetCardTypeW=original.SCardForgetCardTypeW @17 -;SCardForgetReaderA=original.SCardForgetReaderA @18 -;SCardForgetReaderGroupA=original.SCardForgetReaderGroupA @19 -;SCardForgetReaderGroupW=original.SCardForgetReaderGroupW @20 -;SCardForgetReaderW=original.SCardForgetReaderW @21 -;SCardFreeMemory=original.SCardFreeMemory @22 -;SCardGetAttrib=original.SCardGetAttrib @23 -;SCardGetCardTypeProviderNameA=original.SCardGetCardTypeProviderNameA @24 -;SCardGetCardTypeProviderNameW=original.SCardGetCardTypeProviderNameW @25 -;SCardGetProviderIdA=original.SCardGetProviderIdA @26 -;SCardGetProviderIdW=original.SCardGetProviderIdW @27 -;SCardGetStatusChangeA=original.SCardGetStatusChangeA @28 -;SCardGetStatusChangeW=original.SCardGetStatusChangeW @29 -;SCardIntroduceCardTypeA=original.SCardIntroduceCardTypeA @30 -;SCardIntroduceCardTypeW=original.SCardIntroduceCardTypeW @31 -;SCardIntroduceReaderA=original.SCardIntroduceReaderA @32 -;SCardIntroduceReaderGroupA=original.SCardIntroduceReaderGroupA @33 -;SCardIntroduceReaderGroupW=original.SCardIntroduceReaderGroupW @34 -;SCardIntroduceReaderW=original.SCardIntroduceReaderW @35 -;SCardIsValidContext=original.SCardIsValidContext @36 -;SCardListCardsA=original.SCardListCardsA @37 -;SCardListCardsW=original.SCardListCardsW @38 -;SCardListInterfacesA=original.SCardListInterfacesA @39 -;SCardListInterfacesW=original.SCardListInterfacesW @40 -;SCardListReaderGroupsA=original.SCardListReaderGroupsA @41 -;SCardListReaderGroupsW=original.SCardListReaderGroupsW @42 -;SCardListReadersA=original.SCardListReadersA @43 -;SCardListReadersW=original.SCardListReadersW @44 -;SCardLocateCardsA=original.SCardLocateCardsA @45 -;SCardLocateCardsW=original.SCardLocateCardsW @46 -;SCardReconnect=original.SCardReconnect @47 -;SCardReleaseAllEvents=original.SCardReleaseAllEvents @3 -;SCardReleaseContext=original.SCardReleaseContext @48 -;SCardReleaseNewReaderEvent=original.SCardReleaseNewReaderEvent @4 -;SCardReleaseStartedEvent=original.SCardReleaseStartedEvent @5 -;SCardRemoveReaderFromGroupA=original.SCardRemoveReaderFromGroupA @49 -;SCardRemoveReaderFromGroupW=original.SCardRemoveReaderFromGroupW @50 -;SCardSetAttrib=original.SCardSetAttrib @51 -;SCardSetCardTypeProviderNameA=original.SCardSetCardTypeProviderNameA @52 -;SCardSetCardTypeProviderNameW=original.SCardSetCardTypeProviderNameW @53 -;SCardState=original.SCardState @54 -;SCardStatusA=original.SCardStatusA @55 -;SCardStatusW=original.SCardStatusW @56 -; -; initialized shared data symbols -; -;g_rgSCardRawPci=original.g_rgSCardRawPci @58 DATA -;g_rgSCardT0Pci=original.g_rgSCardT0Pci @59 DATA -;g_rgSCardT1Pci=original.g_rgSCardT1Pci @60 DATA -; -; functions to be intercepted -; - -SCardAudit=original.SCardAudit@8 -SCardGetDeviceTypeIdA=original.SCardGetDeviceTypeIdA@12 -SCardGetDeviceTypeIdW=original.SCardGetDeviceTypeIdW@12 -SCardGetReaderDeviceInstanceIdA=original.SCardGetReaderDeviceInstanceIdA@16 -SCardGetReaderDeviceInstanceIdW=original.SCardGetReaderDeviceInstanceIdW@16 -SCardGetReaderIconA=original.SCardGetReaderIconA@16 -SCardGetReaderIconW=original.SCardGetReaderIconW@16 -SCardGetTransmitCount=original.SCardGetTransmitCount@8 -SCardListReadersWithDeviceInstanceIdA=original.SCardListReadersWithDeviceInstanceIdA@16 -SCardListReadersWithDeviceInstanceIdW=original.SCardListReadersWithDeviceInstanceIdW@16 -SCardLocateCardsByATRA=original.SCardLocateCardsByATRA@20 -SCardLocateCardsByATRW=original.SCardLocateCardsByATRW@20 -SCardReadCacheA=original.SCardReadCacheA@24 -SCardReadCacheW=original.SCardReadCacheW@24 -SCardWriteCacheA=original.SCardWriteCacheA@24 -SCardWriteCacheW=original.SCardWriteCacheW@24 - -g_rgSCardRawPci=original.g_rgSCardRawPci DATA -g_rgSCardT0Pci=original.g_rgSCardT0Pci DATA -g_rgSCardT1Pci=original.g_rgSCardT1Pci DATA - -SCardTransmit @57 -SCardConnectW @11 -SCardDisconnect @13 -SCardListReadersA @43 -SCardListReadersW @44 -SCardFreeMemory @22 - -SCardAccessStartedEvent @2 -SCardAddReaderToGroupA @6 -SCardAddReaderToGroupW @7 -SCardBeginTransaction @8 -SCardCancel @9 -SCardConnectA @10 -SCardConnectW @11 -SCardControl @12 -SCardDisconnect @13 -SCardEndTransaction @14 -SCardEstablishContext @15 -SCardForgetCardTypeA @16 -SCardForgetCardTypeW @17 -SCardForgetReaderA @18 -SCardForgetReaderGroupA @19 -SCardForgetReaderGroupW @20 -SCardForgetReaderW @21 -SCardFreeMemory @22 -SCardGetAttrib @23 -SCardGetCardTypeProviderNameA @24 -SCardGetCardTypeProviderNameW @25 -SCardGetProviderIdA @26 -SCardGetProviderIdW @27 -SCardGetStatusChangeA @28 -SCardGetStatusChangeW @29 -SCardIntroduceCardTypeA @30 -SCardIntroduceCardTypeW @31 -SCardIntroduceReaderA @32 -SCardIntroduceReaderGroupA @33 -SCardIntroduceReaderGroupW @34 -SCardIntroduceReaderW @35 -SCardIsValidContext @36 -SCardListCardsA @37 -SCardListCardsW @38 -SCardListInterfacesA @39 -SCardListInterfacesW @40 -SCardListReaderGroupsA @41 -SCardListReaderGroupsW @42 -SCardListReadersA @43 -SCardListReadersW @44 -SCardLocateCardsA @45 -SCardLocateCardsW @46 -SCardReconnect @47 -SCardReleaseContext @48 -SCardReleaseStartedEvent @5 -SCardRemoveReaderFromGroupA @49 -SCardRemoveReaderFromGroupW @50 -SCardSetAttrib @51 -SCardSetCardTypeProviderNameA @52 -SCardSetCardTypeProviderNameW @53 -SCardState @54 -SCardStatusA @55 -SCardStatusW @56 diff --git a/Winscard/Winscard.vcproj b/Winscard/Winscard.vcproj index 0853e80..432e907 100644 --- a/Winscard/Winscard.vcproj +++ b/Winscard/Winscard.vcproj @@ -66,7 +66,6 @@ /> $(IntDir);%(AdditionalIncludeDirectories) - original.lib;%(AdditionalDependencies) - .\Winscard.def + %(AdditionalDependencies) + .\Winscard32.def true Windows MachineX86 @@ -248,7 +248,7 @@ $(IntDir);%(AdditionalIncludeDirectories) - original.lib;%(AdditionalDependencies) + %(AdditionalDependencies) .\Winscard.def true Windows @@ -277,8 +277,8 @@ $(IntDir);%(AdditionalIncludeDirectories) - original.lib;%(AdditionalDependencies) - .\Winscard.def + %(AdditionalDependencies) + .\Winscard64.def true Windows @@ -310,8 +310,8 @@ $(IntDir);%(AdditionalIncludeDirectories) - original.lib;%(AdditionalDependencies) - .\Winscard.def + %(AdditionalDependencies) + .\Winscard32.def true Windows true @@ -344,7 +344,7 @@ $(IntDir);%(AdditionalIncludeDirectories) - original.lib;%(AdditionalDependencies) + %(AdditionalDependencies) .\Winscard.def true Windows @@ -374,8 +374,8 @@ $(IntDir);%(AdditionalIncludeDirectories) - original.lib;%(AdditionalDependencies) - .\Winscard.def + %(AdditionalDependencies) + .\Winscard64.def true Windows true @@ -400,8 +400,8 @@ $(IntDir);%(AdditionalIncludeDirectories) - original.lib;%(AdditionalDependencies) - .\Winscard.def + %(AdditionalDependencies) + .\Winscard32.def true Windows true @@ -427,7 +427,7 @@ $(IntDir);%(AdditionalIncludeDirectories) - original.lib;%(AdditionalDependencies) + %(AdditionalDependencies) .\Winscard.def true Windows @@ -453,8 +453,8 @@ $(IntDir);%(AdditionalIncludeDirectories) - original.lib;%(AdditionalDependencies) - .\Winscard.def + %(AdditionalDependencies) + .\Winscard64.def true Windows true @@ -497,7 +497,6 @@ - diff --git a/Winscard/Winscard.vcxproj.filters b/Winscard/Winscard.vcxproj.filters index 3ebfb47..81fa3fc 100644 --- a/Winscard/Winscard.vcxproj.filters +++ b/Winscard/Winscard.vcxproj.filters @@ -32,9 +32,6 @@ - - Source Files - Resource Files diff --git a/Winscard/Winscard32.def b/Winscard/Winscard32.def new file mode 100644 index 0000000..bd09105 --- /dev/null +++ b/Winscard/Winscard32.def @@ -0,0 +1,157 @@ +; Copyright (c) 2001 Andrew Fernandes . All rights reserved. +; +; This work may be used and distributed under the terms of the GNU Public License, +; as written in the included file "gpl.txt" or online at . +; +LIBRARY "winscard" +EXPORTS +; +; functions to pass transparently +; +;SCardAccessNewReaderEvent=original32.SCardAccessNewReaderEvent @1 +;SCardAccessStartedEvent=original32.SCardAccessStartedEvent @2 +;SCardAddReaderToGroupA=original32.SCardAddReaderToGroupA @6 +;SCardAddReaderToGroupW=original32.SCardAddReaderToGroupW @7 +;SCardBeginTransaction=original32.SCardBeginTransaction @8 +;SCardCancel=original32.SCardCancel @9 +;SCardConnectA=original32.SCardConnectA @10 +;SCardConnectW=original32.SCardConnectW @11 +;SCardControl=original32.SCardControl @12 +;SCardDisconnect=original32.SCardDisconnect @13 +;SCardEndTransaction=original32.SCardEndTransaction @14 +;SCardEstablishContext=original32.SCardEstablishContext @15 +;SCardForgetCardTypeA=original32.SCardForgetCardTypeA @16 +;SCardForgetCardTypeW=original32.SCardForgetCardTypeW @17 +;SCardForgetReaderA=original32.SCardForgetReaderA @18 +;SCardForgetReaderGroupA=original32.SCardForgetReaderGroupA @19 +;SCardForgetReaderGroupW=original32.SCardForgetReaderGroupW @20 +;SCardForgetReaderW=original32.SCardForgetReaderW @21 +;SCardFreeMemory=original32.SCardFreeMemory @22 +;SCardGetAttrib=original32.SCardGetAttrib @23 +;SCardGetCardTypeProviderNameA=original32.SCardGetCardTypeProviderNameA @24 +;SCardGetCardTypeProviderNameW=original32.SCardGetCardTypeProviderNameW @25 +;SCardGetProviderIdA=original32.SCardGetProviderIdA @26 +;SCardGetProviderIdW=original32.SCardGetProviderIdW @27 +;SCardGetStatusChangeA=original32.SCardGetStatusChangeA @28 +;SCardGetStatusChangeW=original32.SCardGetStatusChangeW @29 +;SCardIntroduceCardTypeA=original32.SCardIntroduceCardTypeA @30 +;SCardIntroduceCardTypeW=original32.SCardIntroduceCardTypeW @31 +;SCardIntroduceReaderA=original32.SCardIntroduceReaderA @32 +;SCardIntroduceReaderGroupA=original32.SCardIntroduceReaderGroupA @33 +;SCardIntroduceReaderGroupW=original32.SCardIntroduceReaderGroupW @34 +;SCardIntroduceReaderW=original32.SCardIntroduceReaderW @35 +;SCardIsValidContext=original32.SCardIsValidContext @36 +;SCardListCardsA=original32.SCardListCardsA @37 +;SCardListCardsW=original32.SCardListCardsW @38 +;SCardListInterfacesA=original32.SCardListInterfacesA @39 +;SCardListInterfacesW=original32.SCardListInterfacesW @40 +;SCardListReaderGroupsA=original32.SCardListReaderGroupsA @41 +;SCardListReaderGroupsW=original32.SCardListReaderGroupsW @42 +;SCardListReadersA=original32.SCardListReadersA @43 +;SCardListReadersW=original32.SCardListReadersW @44 +;SCardLocateCardsA=original32.SCardLocateCardsA @45 +;SCardLocateCardsW=original32.SCardLocateCardsW @46 +;SCardReconnect=original32.SCardReconnect @47 +;SCardReleaseAllEvents=original32.SCardReleaseAllEvents @3 +;SCardReleaseContext=original32.SCardReleaseContext @48 +;SCardReleaseNewReaderEvent=original32.SCardReleaseNewReaderEvent @4 +;SCardReleaseStartedEvent=original32.SCardReleaseStartedEvent @5 +;SCardRemoveReaderFromGroupA=original32.SCardRemoveReaderFromGroupA @49 +;SCardRemoveReaderFromGroupW=original32.SCardRemoveReaderFromGroupW @50 +;SCardSetAttrib=original32.SCardSetAttrib @51 +;SCardSetCardTypeProviderNameA=original32.SCardSetCardTypeProviderNameA @52 +;SCardSetCardTypeProviderNameW=original32.SCardSetCardTypeProviderNameW @53 +;SCardState=original32.SCardState @54 +;SCardStatusA=original32.SCardStatusA @55 +;SCardStatusW=original32.SCardStatusW @56 +; +; initialized shared data symbols +; +;g_rgSCardRawPci=original32.g_rgSCardRawPci @58 DATA +;g_rgSCardT0Pci=original32.g_rgSCardT0Pci @59 DATA +;g_rgSCardT1Pci=original32.g_rgSCardT1Pci @60 DATA +; +; functions to be intercepted +; + +SCardAudit=original32.SCardAudit@8 +SCardGetDeviceTypeIdA=original32.SCardGetDeviceTypeIdA@12 +SCardGetDeviceTypeIdW=original32.SCardGetDeviceTypeIdW@12 +SCardGetReaderDeviceInstanceIdA=original32.SCardGetReaderDeviceInstanceIdA@16 +SCardGetReaderDeviceInstanceIdW=original32.SCardGetReaderDeviceInstanceIdW@16 +SCardGetReaderIconA=original32.SCardGetReaderIconA@16 +SCardGetReaderIconW=original32.SCardGetReaderIconW@16 +SCardGetTransmitCount=original32.SCardGetTransmitCount@8 +SCardListReadersWithDeviceInstanceIdA=original32.SCardListReadersWithDeviceInstanceIdA@16 +SCardListReadersWithDeviceInstanceIdW=original32.SCardListReadersWithDeviceInstanceIdW@16 +SCardLocateCardsByATRA=original32.SCardLocateCardsByATRA@20 +SCardLocateCardsByATRW=original32.SCardLocateCardsByATRW@20 +SCardReadCacheA=original32.SCardReadCacheA@24 +SCardReadCacheW=original32.SCardReadCacheW@24 +SCardWriteCacheA=original32.SCardWriteCacheA@24 +SCardWriteCacheW=original32.SCardWriteCacheW@24 + +g_rgSCardRawPci=original32.g_rgSCardRawPci DATA +g_rgSCardT0Pci=original32.g_rgSCardT0Pci DATA +g_rgSCardT1Pci=original32.g_rgSCardT1Pci DATA + +SCardTransmit @57 +SCardConnectW @11 +SCardDisconnect @13 +SCardListReadersA @43 +SCardListReadersW @44 +SCardFreeMemory @22 + +SCardAccessStartedEvent @2 +SCardAddReaderToGroupA @6 +SCardAddReaderToGroupW @7 +SCardBeginTransaction @8 +SCardCancel @9 +SCardConnectA @10 +SCardConnectW @11 +SCardControl @12 +SCardDisconnect @13 +SCardEndTransaction @14 +SCardEstablishContext @15 +SCardForgetCardTypeA @16 +SCardForgetCardTypeW @17 +SCardForgetReaderA @18 +SCardForgetReaderGroupA @19 +SCardForgetReaderGroupW @20 +SCardForgetReaderW @21 +SCardFreeMemory @22 +SCardGetAttrib @23 +SCardGetCardTypeProviderNameA @24 +SCardGetCardTypeProviderNameW @25 +SCardGetProviderIdA @26 +SCardGetProviderIdW @27 +SCardGetStatusChangeA @28 +SCardGetStatusChangeW @29 +SCardIntroduceCardTypeA @30 +SCardIntroduceCardTypeW @31 +SCardIntroduceReaderA @32 +SCardIntroduceReaderGroupA @33 +SCardIntroduceReaderGroupW @34 +SCardIntroduceReaderW @35 +SCardIsValidContext @36 +SCardListCardsA @37 +SCardListCardsW @38 +SCardListInterfacesA @39 +SCardListInterfacesW @40 +SCardListReaderGroupsA @41 +SCardListReaderGroupsW @42 +SCardListReadersA @43 +SCardListReadersW @44 +SCardLocateCardsA @45 +SCardLocateCardsW @46 +SCardReconnect @47 +SCardReleaseContext @48 +SCardReleaseStartedEvent @5 +SCardRemoveReaderFromGroupA @49 +SCardRemoveReaderFromGroupW @50 +SCardSetAttrib @51 +SCardSetCardTypeProviderNameA @52 +SCardSetCardTypeProviderNameW @53 +SCardState @54 +SCardStatusA @55 +SCardStatusW @56 diff --git a/Winscard/Winscard64.def b/Winscard/Winscard64.def new file mode 100644 index 0000000..b945139 --- /dev/null +++ b/Winscard/Winscard64.def @@ -0,0 +1,157 @@ +; Copyright (c) 2001 Andrew Fernandes . All rights reserved. +; +; This work may be used and distributed under the terms of the GNU Public License, +; as written in the included file "gpl.txt" or online at . +; +LIBRARY "winscard" +EXPORTS +; +; functions to pass transparently +; +;SCardAccessNewReaderEvent=original64.SCardAccessNewReaderEvent @1 +;SCardAccessStartedEvent=original64.SCardAccessStartedEvent @2 +;SCardAddReaderToGroupA=original64.SCardAddReaderToGroupA @6 +;SCardAddReaderToGroupW=original64.SCardAddReaderToGroupW @7 +;SCardBeginTransaction=original64.SCardBeginTransaction @8 +;SCardCancel=original64.SCardCancel @9 +;SCardConnectA=original64.SCardConnectA @10 +;SCardConnectW=original64.SCardConnectW @11 +;SCardControl=original64.SCardControl @12 +;SCardDisconnect=original64.SCardDisconnect @13 +;SCardEndTransaction=original64.SCardEndTransaction @14 +;SCardEstablishContext=original64.SCardEstablishContext @15 +;SCardForgetCardTypeA=original64.SCardForgetCardTypeA @16 +;SCardForgetCardTypeW=original64.SCardForgetCardTypeW @17 +;SCardForgetReaderA=original64.SCardForgetReaderA @18 +;SCardForgetReaderGroupA=original64.SCardForgetReaderGroupA @19 +;SCardForgetReaderGroupW=original64.SCardForgetReaderGroupW @20 +;SCardForgetReaderW=original64.SCardForgetReaderW @21 +;SCardFreeMemory=original64.SCardFreeMemory @22 +;SCardGetAttrib=original64.SCardGetAttrib @23 +;SCardGetCardTypeProviderNameA=original64.SCardGetCardTypeProviderNameA @24 +;SCardGetCardTypeProviderNameW=original64.SCardGetCardTypeProviderNameW @25 +;SCardGetProviderIdA=original64.SCardGetProviderIdA @26 +;SCardGetProviderIdW=original64.SCardGetProviderIdW @27 +;SCardGetStatusChangeA=original64.SCardGetStatusChangeA @28 +;SCardGetStatusChangeW=original64.SCardGetStatusChangeW @29 +;SCardIntroduceCardTypeA=original64.SCardIntroduceCardTypeA @30 +;SCardIntroduceCardTypeW=original64.SCardIntroduceCardTypeW @31 +;SCardIntroduceReaderA=original64.SCardIntroduceReaderA @32 +;SCardIntroduceReaderGroupA=original64.SCardIntroduceReaderGroupA @33 +;SCardIntroduceReaderGroupW=original64.SCardIntroduceReaderGroupW @34 +;SCardIntroduceReaderW=original64.SCardIntroduceReaderW @35 +;SCardIsValidContext=original64.SCardIsValidContext @36 +;SCardListCardsA=original64.SCardListCardsA @37 +;SCardListCardsW=original64.SCardListCardsW @38 +;SCardListInterfacesA=original64.SCardListInterfacesA @39 +;SCardListInterfacesW=original64.SCardListInterfacesW @40 +;SCardListReaderGroupsA=original64.SCardListReaderGroupsA @41 +;SCardListReaderGroupsW=original64.SCardListReaderGroupsW @42 +;SCardListReadersA=original64.SCardListReadersA @43 +;SCardListReadersW=original64.SCardListReadersW @44 +;SCardLocateCardsA=original64.SCardLocateCardsA @45 +;SCardLocateCardsW=original64.SCardLocateCardsW @46 +;SCardReconnect=original64.SCardReconnect @47 +;SCardReleaseAllEvents=original64.SCardReleaseAllEvents @3 +;SCardReleaseContext=original64.SCardReleaseContext @48 +;SCardReleaseNewReaderEvent=original64.SCardReleaseNewReaderEvent @4 +;SCardReleaseStartedEvent=original64.SCardReleaseStartedEvent @5 +;SCardRemoveReaderFromGroupA=original64.SCardRemoveReaderFromGroupA @49 +;SCardRemoveReaderFromGroupW=original64.SCardRemoveReaderFromGroupW @50 +;SCardSetAttrib=original64.SCardSetAttrib @51 +;SCardSetCardTypeProviderNameA=original64.SCardSetCardTypeProviderNameA @52 +;SCardSetCardTypeProviderNameW=original64.SCardSetCardTypeProviderNameW @53 +;SCardState=original64.SCardState @54 +;SCardStatusA=original64.SCardStatusA @55 +;SCardStatusW=original64.SCardStatusW @56 +; +; initialized shared data symbols +; +;g_rgSCardRawPci=original64.g_rgSCardRawPci @58 DATA +;g_rgSCardT0Pci=original64.g_rgSCardT0Pci @59 DATA +;g_rgSCardT1Pci=original64.g_rgSCardT1Pci @60 DATA +; +; functions to be intercepted +; + +SCardAudit=original64.SCardAudit@8 +SCardGetDeviceTypeIdA=original64.SCardGetDeviceTypeIdA@12 +SCardGetDeviceTypeIdW=original64.SCardGetDeviceTypeIdW@12 +SCardGetReaderDeviceInstanceIdA=original64.SCardGetReaderDeviceInstanceIdA@16 +SCardGetReaderDeviceInstanceIdW=original64.SCardGetReaderDeviceInstanceIdW@16 +SCardGetReaderIconA=original64.SCardGetReaderIconA@16 +SCardGetReaderIconW=original64.SCardGetReaderIconW@16 +SCardGetTransmitCount=original64.SCardGetTransmitCount@8 +SCardListReadersWithDeviceInstanceIdA=original64.SCardListReadersWithDeviceInstanceIdA@16 +SCardListReadersWithDeviceInstanceIdW=original64.SCardListReadersWithDeviceInstanceIdW@16 +SCardLocateCardsByATRA=original64.SCardLocateCardsByATRA@20 +SCardLocateCardsByATRW=original64.SCardLocateCardsByATRW@20 +SCardReadCacheA=original64.SCardReadCacheA@24 +SCardReadCacheW=original64.SCardReadCacheW@24 +SCardWriteCacheA=original64.SCardWriteCacheA@24 +SCardWriteCacheW=original64.SCardWriteCacheW@24 + +g_rgSCardRawPci=original64.g_rgSCardRawPci DATA +g_rgSCardT0Pci=original64.g_rgSCardT0Pci DATA +g_rgSCardT1Pci=original64.g_rgSCardT1Pci DATA + +SCardTransmit @57 +SCardConnectW @11 +SCardDisconnect @13 +SCardListReadersA @43 +SCardListReadersW @44 +SCardFreeMemory @22 + +SCardAccessStartedEvent @2 +SCardAddReaderToGroupA @6 +SCardAddReaderToGroupW @7 +SCardBeginTransaction @8 +SCardCancel @9 +SCardConnectA @10 +SCardConnectW @11 +SCardControl @12 +SCardDisconnect @13 +SCardEndTransaction @14 +SCardEstablishContext @15 +SCardForgetCardTypeA @16 +SCardForgetCardTypeW @17 +SCardForgetReaderA @18 +SCardForgetReaderGroupA @19 +SCardForgetReaderGroupW @20 +SCardForgetReaderW @21 +SCardFreeMemory @22 +SCardGetAttrib @23 +SCardGetCardTypeProviderNameA @24 +SCardGetCardTypeProviderNameW @25 +SCardGetProviderIdA @26 +SCardGetProviderIdW @27 +SCardGetStatusChangeA @28 +SCardGetStatusChangeW @29 +SCardIntroduceCardTypeA @30 +SCardIntroduceCardTypeW @31 +SCardIntroduceReaderA @32 +SCardIntroduceReaderGroupA @33 +SCardIntroduceReaderGroupW @34 +SCardIntroduceReaderW @35 +SCardIsValidContext @36 +SCardListCardsA @37 +SCardListCardsW @38 +SCardListInterfacesA @39 +SCardListInterfacesW @40 +SCardListReaderGroupsA @41 +SCardListReaderGroupsW @42 +SCardListReadersA @43 +SCardListReadersW @44 +SCardLocateCardsA @45 +SCardLocateCardsW @46 +SCardReconnect @47 +SCardReleaseContext @48 +SCardReleaseStartedEvent @5 +SCardRemoveReaderFromGroupA @49 +SCardRemoveReaderFromGroupW @50 +SCardSetAttrib @51 +SCardSetCardTypeProviderNameA @52 +SCardSetCardTypeProviderNameW @53 +SCardState @54 +SCardStatusA @55 +SCardStatusW @56 diff --git a/Winscard/original.def b/Winscard/original.def deleted file mode 100644 index 7b98f72..0000000 --- a/Winscard/original.def +++ /dev/null @@ -1,74 +0,0 @@ - ?ClassInstall32@@YGKIPAXPAU_SP_DEVINFO_DATA@@@Z (unsigned long __stdcall ClassInstall32(unsigned int,void *,struct _SP_DEVINFO_DATA *)) -_SCardAccessStartedEvent@0 -_SCardAddReaderToGroupA@12 -_SCardAddReaderToGroupW@12 -_SCardAudit@8 -_SCardBeginTransaction@4 -_SCardCancel@4 -_SCardConnectA@24 -_SCardConnectW@24 -_SCardControl@28 -_SCardDisconnect@8 -_SCardEndTransaction@8 -_SCardEstablishContext@16 -_SCardForgetCardTypeA@8 -_SCardForgetCardTypeW@8 -_SCardForgetReaderA@8 -_SCardForgetReaderGroupA@8 -_SCardForgetReaderGroupW@8 -_SCardForgetReaderW@8 -_SCardFreeMemory@8 -_SCardGetAttrib@16 -_SCardGetCardTypeProviderNameA@20 -_SCardGetCardTypeProviderNameW@20 -_SCardGetDeviceTypeIdA@12 -_SCardGetDeviceTypeIdW@12 -_SCardGetProviderIdA@12 -_SCardGetProviderIdW@12 -_SCardGetReaderDeviceInstanceIdA@16 -_SCardGetReaderDeviceInstanceIdW@16 -_SCardGetReaderIconA@16 -_SCardGetReaderIconW@16 -_SCardGetStatusChangeA@16 -_SCardGetStatusChangeW@16 -_SCardGetTransmitCount@8 -_SCardIntroduceCardTypeA@32 -_SCardIntroduceCardTypeW@32 -_SCardIntroduceReaderA@12 -_SCardIntroduceReaderGroupA@8 -_SCardIntroduceReaderGroupW@8 -_SCardIntroduceReaderW@12 -_SCardIsValidContext@4 -_SCardListCardsA@24 -_SCardListCardsW@24 -_SCardListInterfacesA@16 -_SCardListInterfacesW@16 -_SCardListReaderGroupsA@12 -_SCardListReaderGroupsW@12 -_SCardListReadersA@16 -_SCardListReadersW@16 -_SCardListReadersWithDeviceInstanceIdA@16 -_SCardListReadersWithDeviceInstanceIdW@16 -_SCardLocateCardsA@16 -_SCardLocateCardsByATRA@20 -_SCardLocateCardsByATRW@20 -_SCardLocateCardsW@16 -_SCardReadCacheA@24 -_SCardReadCacheW@24 -_SCardReconnect@20 -_SCardReleaseContext@4 -_SCardReleaseStartedEvent@0 -_SCardRemoveReaderFromGroupA@12 -_SCardRemoveReaderFromGroupW@12 -_SCardSetAttrib@16 -_SCardSetCardTypeProviderNameA@16 -_SCardSetCardTypeProviderNameW@16 -_SCardState@20 -_SCardStatusA@28 -_SCardStatusW@28 -_SCardTransmit@28 -_SCardWriteCacheA@24 -_SCardWriteCacheW@24 -_g_rgSCardRawPci -_g_rgSCardT0Pci -_g_rgSCardT1Pci \ No newline at end of file diff --git a/Winscard/original.lib b/Winscard/original.lib deleted file mode 100644 index e2726a0182bb08d3bb8802fa955317973f368b61..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 19590 zcmd5^OK)677CuQJfX9T8gdv2N6Y_pIezonqyW>|nb{xwwn3;{!aW_dzjyvk^WCj+@ zA3!V+V#Ok>S)f@UmMDt|u|jBsMu-)QXjZIPuw;|@s_NFgr=IQ`8)>d|a{JbKeD$tV zr^?xTw$fa_b-wFlkNKSFH^22)U-DyUWN<|Nyxv7bpAsDa9r}jo@b5$?zg09bNhIj( zuZk`V5J~z1Z%}bxLZ9IcI(H+XAMpmAhpwatc!LT*C>ln(putCqhOQF{I`d&d$io>> z|L2MZb`c3WvsKaAd&m!{|FEKgkH7~VTS(}8yg`#g34Mh(==6?+AbT1#bzjk?9wI?~ zXA^>KA83#iUED(?Xbkxibn#80_~LW!27 z=0vMqxv^4j-5P7GwrhWH7yE}{tbY5>QiLxx=W8pqN~@;zh72{ADRs)NcPcCOs$a)t zN}ZW{t36+1X<(j_;Hru1;El8%v$}&}J&ovwO>S(BP)oCOTSE3o| zux2)`hpV+j%WIMp~F`G;h}UXt6Wk7x3%a(2j0~Yn97seJ|fvW~T>Onu_n_H&#r^b2MUw z%gR-%R#j^*H00#t6wEIm(QKAeG{1n)! zO2t8Qlm;YZ9vt4{n%YW2YF`VDUu$-a%Ec_9oaQ_ou%zUqB{dAP$}mT`hwIVu_dabi z>wlBYTI~w@Li2rV8Za3WVWzQMY1f1e&tz}&Yz?O#m^D^*mU{91(!#tm;raz^G^y)M zv9>OoTQQGcYggKLTVuB>t2Z&vTdn5hOH_;Fl+(+Xnq!sK<=RToT$Zy$CDT}4tu42m z)f)~@md+(nCd;6bROwQ3zP7B=>?O!#NZIjvOADLb&}2y2i?y5e)rDqdwN+Ve*Bh%= z$$V_7H?dmfS|*OmlsclZYIgp!#8l?4aC}UQs-0CblS2jhW;5`=rHs`<5-~v`0tsomh5qyM|?! z=hEFOCK0ppt+bm<&6_e83w?9Tb?xD2sr|mx`O4o!@`bULN~M4y3foFn=XG>KTo1JDlz{6;L~5duBe5i9!e3~Yct?_=3b(o5I=c@_m{_s=8*6Eu+d#6`T+C`s0rR3*y@A*pN|rKjdHzvndm#v zZ?IW~{xIx596>tD@(5-492gH!rt?VaDgg^L4*OqB6YZWs9`T-qtxu87D|DJ(rPruT z{dAm8P%n*89}Un`^cL->SLh}BGwq=RG)gbh4jQA2^a5?C37Vu573nA)qj7qZdgx`^ zNxNt_ZKXd^H$6|==oxyJo}(_BqDyp;4$~1jMCa)OousGf482Zo&?(wW`%qCsRG?ux zOXp}4ZT>&Y(F|RtY1)#17|8J!Ss3lz6q{LX76v<}b7fEucKH?bfnsi-)P(OK96q*O zIo^cFB@1{@-k6+($+5d&@@jeT?}L+_C8j$^L9*ChgvAzEs6nzZm8F~Vv9(m|`eoP}0$e2{d=<6InYx(| zqtlh&%l9`vj)~!S2%Igq+OSJ=4v%fNQ=aZG=_s){R-f^4vkqc$S!GA!y~!?CxTrGQ zX*84#Fp&o1Mtn0B&KRu5G9N&eKx~usJYcg}HZxYTuTDW!J+-_Dt+2o2=zBaPZgZ`@ zJKKpX)0qO>Xxl7?Aj+|ZZ!Wbx8_++Y+hWm6fRau6st)!6}Y9k;&@>@^c*j%E=CT>_t+wNJKz2 z2^Y|7DNFOMsEnPht2~hhPu%pR8nYuRzS1&rbG>B@ch%)g?4DxhVV)J3X`5U*2|8Ro zyP7);rKxz?{2EZsR_1_!gKVtQObH7WTdPfmZ#_oGHbWIK;FDA9wrP*A(N6Dz9nN<; z7x>wV?bFV&D}0FS({)#SQ=9XB`g-#5MGDdtS2xVs0sC-J zUiVfj0Fq)vdaO^z?wFR0({!$n!0Jh?%*<2pah%CQ=m6C48Z5<(?bLkc3vds@(q~m7 zd;>Fblv(gZ>5(_3ocI)8!x7J-b9uL9nbV+_O>QgWF<&Dh;EaA2+INseiJAAo%%&Wt z6-`gXP+9v@0>)M-@apwFoY}@J<+QZvr?5N*d=aPG19DCUin+oYY!61)QJ?1Oqo)%) z-S%i$DKZvsoiqlPM7t6fBu$P5%)(byy7VQM-s;MVxR#kz6Hy%Tbn`+TqMh5HL834yo^1&9?7P0>N`1N6Xf@tz z_Z*%-(lb+@MWo4nx{)Llg#kjON&MQ5f1j4WI1F;J+_-%Q+1+=2)27FdHK5QDkI3I< z(xomU3?@=;=@eN$fwV=Z3<((|WHN;;MWpW)|0IvFg5Ue^_rpbWuH`xBOFoByZ7M{+M3SNz1;DTm-L*q)y)ea(L>>+ZRW5 zSH#Rk=!v)mh;jP(F+%Kkx^u@(IX>lX;bGmtR&H=8fL89-K~&#)rUA@9IvJ5M+$|Zd z?{*G{BL1;n+^2%La_Q$#xp9Y*o5MX;J->>2emcWVHrNJK?lvvxrP0DV2&}CsmS^K` z!19kyYIZ1q`WjH5Nm0{y05_kzHq+_cD&d>JdN#viVFm*(e~kvltiXHD#*^OCI`IOd zQp`kM98ceJFyQz{CoNYPNL(qaHhX|3&Zbm^)`+%ni2SWL?8n;=yzUgw3F52|^OPU+ z5HO$5Fk5bH$bik?a{}WYhp%t}b={g#C2@}P$DzIuKouMJb)pvhb^I2}y4^xmyWsVg zG`5bs=*3K9Z$@GHM<-(@hPxw->r`@H+(M*|cY1Lh$ozdcGC%CfFnI)$7t82Xoz!h? zK6)v|GXk6I!W#~ZQCu#-S-u{lfjFp)mm2W7>o=*sCA3E{e~Snm2R1ln87$$L0%7IEH)(ne5U^`mY;S%(8{i_1B_~=d|DC7N$o!*|@uY92+HEXi%STg8^E8lSd#A7bvM(pV$Gu3eeF*}}g zCuUyij%qf7dLn@8PRn^wW4ohX1CwB2k@l3=#L6#l?3g%)rarN&kuY6&Dzub-jbbl z>qRSDXqXbM0}Kw`5n5oj5T|^XQ#2h&aNzQflOg|k$v)ssr+C>lEP3ag7b<^!Mi6H_ zi0(4O;XA6+NPoG4v(u&Y;#hK@j05B@-%w!BEN;cj8ffa8ngN!({bFcWO*HxUq9)q^ E0PUU1Y5)KL From b945ca8bee4170179687c449b9f938db0cec3f17 Mon Sep 17 00:00:00 2001 From: petrs Date: Tue, 10 Jul 2018 22:21:15 +0200 Subject: [PATCH 06/11] added more logging into debug file --- Winscard/Winscard.cpp | 341 ++++++++++++++++++++++-------------------- Winscard/stdafx.h | 3 - 2 files changed, 177 insertions(+), 167 deletions(-) diff --git a/Winscard/Winscard.cpp b/Winscard/Winscard.cpp index ca2cb70..6997532 100644 --- a/Winscard/Winscard.cpp +++ b/Winscard/Winscard.cpp @@ -62,16 +62,6 @@ Please, report any bugs to author #include "wintypes.h" #endif -/* -BOOL bAUTO_REQUEST_DATA = TRUE; // DEFAULT: FALSE, SET TO TRUE IF APPLICATION IS NOT ABLE TO HANDLE GET DATA (00 0c 00 00 lc) COMMAND ON ITS OWN -BOOL bFORCE_CONNECT_SHARED_MODE = TRUE; // DEFAULT: FALSE, SET TO TRUE IF SOME APPLICATION IS BLOCKING CARD -BOOL bFORCE_APDU_NONZERO_INPUT_DATA = TRUE; // DEFAULT: FALSE, SET TO TRUE IF APPLET HAVE PROBLEM TO RETURN DATA (apdu.setOutgoingAndSend()) WHEN NO PREVIOUS setIncomingAndReceive() WAS CALLED. -BOOL bLOG_EXCHANGED_APDU = TRUE; // DEFAULT: FALSE, SET TO TRUE IF LOGGING OF APDU DATA IS REQUIRED -BOOL bMODIFY_APDU_BY_RULES = TRUE; // DEFAULT: FALSE, SET TO TRUE . -BOOL bLOG_FUNCTIONS_CALLS = TRUE; // DEFAULT: FALSE, SET TO TRUE . -/**/ - - /* extern SCard (.*?) STDCALL.*?(SCard.*?)\((.*?)\); static SCard \1 (STDCALL *Original_\2) @@ -80,6 +70,8 @@ static SCard \1 (STDCALL *Original_\2) /**/ #pragma warning(disable:4996) +static string_type LIBRARY_VERSION = _CONV("2.0.1"); + static string_type ENV_APDUPLAY_WINSCARD_RULES_PATH = _CONV("APDUPLAY"); static string_type ENV_APDUPLAY_DEBUG_PATH = _CONV("APDUPLAY_DEBUG"); static string_type APDUPLAY_DEBUG_FILE = _CONV("c:\\Temp\\apduplay_debug.txt"); @@ -138,8 +130,8 @@ int apduCounter = 0; /* The following values variables MUST be defined here, but MUST NOT be referenced in this or any other program module. The DEF file is set to forward their linkage -to the "original.dll". If we need the data that these variables should be pointing -to, we must GetProcAddress on "original.dll" and use the data there. +to the "originalxx.dll". If we need the data that these variables should be pointing +to, we must GetProcAddress on "originalxx.dll" and use the data there. */ #if defined(_WIN32) @@ -159,12 +151,28 @@ const SCARD_IO_REQUEST g_rgSCardT0Pci, g_rgSCardT1Pci, g_rgSCardRawPci; /* ******************************************************************************* */ +void LogDebugString(string_type message, bool bInsertTime = true) { + string_type logLine; + + if (bInsertTime) { + string_type date_and_time = getCurrentTimeString(); + CCommonFnc::File_AppendString(APDUPLAY_DEBUG_FILE, string_format(_CONV("%s: %s"), date_and_time.c_str(), message.c_str())); + } + else { + CCommonFnc::File_AppendString(APDUPLAY_DEBUG_FILE, message); + } +} + +void LogWinscardRules(string_type message) { + LogDebugString(message); + CCommonFnc::File_AppendString(WINSCARD_RULES_LOG, message); +} void DumpMemory(LPCBYTE location, DWORD length) { string_type message; CCommonFnc::BYTE_ConvertFromArrayToHexString((BYTE*)location, length, &message); CCommonFnc::File_AppendString(WINSCARD_LOG, message); - CCommonFnc::File_AppendString(WINSCARD_LOG, _CONV("\r\n")); + CCommonFnc::File_AppendString(WINSCARD_LOG, _CONV("\n")); } static SCard LONG(STDCALL *Original_SCardEstablishContext)( @@ -182,10 +190,10 @@ SCard LONG STDCALL SCardEstablishContext( ) { string_type message; message = string_format(_CONV("SCardEstablishContext() called\n")); - if (theApp.m_winscardConfig.bLOG_FUNCTIONS_CALLS) CCommonFnc::File_AppendString(WINSCARD_RULES_LOG, message); + LogWinscardRules(message); LONG status = (*Original_SCardEstablishContext)(dwScope, pvReserved1, pvReserved2, phContext); message = string_format(_CONV("-> hContext:0x%x\n"), *phContext); - if (theApp.m_winscardConfig.bLOG_FUNCTIONS_CALLS) CCommonFnc::File_AppendString(WINSCARD_RULES_LOG, message); + LogWinscardRules(message); return status; } @@ -199,7 +207,7 @@ SCard LONG STDCALL SCardReleaseContext( ) { string_type message; message = string_format(_CONV("SCardReleaseContext(hContext:0x%x) called\n"), hContext); - if (theApp.m_winscardConfig.bLOG_FUNCTIONS_CALLS) CCommonFnc::File_AppendString(WINSCARD_RULES_LOG, message); + LogWinscardRules(message); return (*Original_SCardReleaseContext)(hContext); } @@ -213,7 +221,7 @@ SCard LONG STDCALL SCardIsValidContext( ) { string_type message; message = string_format(_CONV("SCardIsValidContext(hContext:0x%x) called\n"), hContext); - if (theApp.m_winscardConfig.bLOG_FUNCTIONS_CALLS) CCommonFnc::File_AppendString(WINSCARD_RULES_LOG, message); + LogWinscardRules(message); return (*Original_SCardIsValidContext)(hContext); } @@ -224,7 +232,7 @@ static SCard LONG(STDCALL *Original_SCardCancel)( SCard LONG STDCALL SCardCancel( IN SCARDCONTEXT hContext ) { - if (theApp.m_winscardConfig.bLOG_FUNCTIONS_CALLS) CCommonFnc::File_AppendString(WINSCARD_RULES_LOG, _CONV("SCardCancel called\n")); + LogWinscardRules(_CONV("SCardCancel called\n")); return (*Original_SCardCancel)(hContext); } @@ -245,7 +253,7 @@ SCard LONG STDCALL SCardReconnect( ) { string_type message; message = string_format(_CONV("SCardReconnect(hCard:0x%x) called\n"), hCard); - if (theApp.m_winscardConfig.bLOG_FUNCTIONS_CALLS) CCommonFnc::File_AppendString(WINSCARD_RULES_LOG, message); + LogWinscardRules(message); if (theApp.IsRemoteCard(hCard)) { return SCARD_S_SUCCESS; *pdwActiveProtocol = SCARD_PROTOCOL_T1; @@ -262,7 +270,7 @@ static SCard LONG(STDCALL *Original_SCardBeginTransaction)( SCard LONG STDCALL SCardBeginTransaction( IN SCARDHANDLE hCard ) { - CCommonFnc::File_AppendString(WINSCARD_RULES_LOG, _CONV("SCardBeginTransaction called\n")); + LogWinscardRules(_CONV("SCardBeginTransaction called\n")); if (theApp.IsRemoteCard(hCard)) { return SCARD_S_SUCCESS; } @@ -281,7 +289,7 @@ SCard LONG STDCALL SCardEndTransaction( IN SCARDHANDLE hCard, IN DWORD dwDisposition ) { - if (theApp.m_winscardConfig.bLOG_FUNCTIONS_CALLS) CCommonFnc::File_AppendString(WINSCARD_RULES_LOG, _CONV("SCardEndTransaction called\n")); + LogWinscardRules(_CONV("SCardEndTransaction called\n")); if (theApp.IsRemoteCard(hCard)) { return SCARD_S_SUCCESS; } @@ -309,7 +317,7 @@ SCard LONG STDCALL SCardControl( IN DWORD nOutBufferSize, OUT LPDWORD lpBytesReturned ) { - if (theApp.m_winscardConfig.bLOG_FUNCTIONS_CALLS) CCommonFnc::File_AppendString(WINSCARD_RULES_LOG, _CONV("SCardControl called\n")); + LogWinscardRules(_CONV("SCardControl called\n")); if (theApp.IsRemoteCard(hCard)) { return SCARD_S_SUCCESS; } @@ -332,7 +340,7 @@ SCard LONG STDCALL SCardGetAttrib( OUT LPBYTE pbAttr, IN OUT LPDWORD pcbAttrLen ) { - if (theApp.m_winscardConfig.bLOG_FUNCTIONS_CALLS) CCommonFnc::File_AppendString(WINSCARD_RULES_LOG, _CONV("SCardGetAttrib called\n")); + LogWinscardRules(_CONV("SCardGetAttrib called\n")); if (theApp.IsRemoteCard(hCard)) { return SCARD_S_SUCCESS; } @@ -355,7 +363,7 @@ SCard LONG STDCALL SCardSetAttrib( IN LPCBYTE pbAttr, IN DWORD cbAttrLen ) { - if (theApp.m_winscardConfig.bLOG_FUNCTIONS_CALLS) CCommonFnc::File_AppendString(WINSCARD_RULES_LOG, _CONV("SCardSetAttrib called\n")); + LogWinscardRules(_CONV("SCardSetAttrib called\n")); if (theApp.IsRemoteCard(hCard)) { return SCARD_S_SUCCESS; } @@ -377,7 +385,7 @@ CWinscardApp::~CWinscardApp() FreeLibrary(hOriginal); #endif // Reference to WINSCARD_LOG will fail with access to 0xfeefee (global CString WINSCARD_LOG does not exists at the time of dll release (strange)) - // if (theApp.m_winscardConfig.bLOG_EXCHANGED_APDU) CCommonFnc::File_AppendString(WINSCARD_LOG, "[end]\r\n"); + // if (theApp.m_winscardConfig.bLOG_EXCHANGED_APDU) CCommonFnc::File_AppendString(WINSCARD_LOG, "[end]\n"); #if defined(_WIN32) if (m_remoteConfig.pSocket != NULL) delete m_remoteConfig.pSocket; @@ -469,7 +477,7 @@ SCard LONG STDCALL SCardFreeMemory( { string_type message; message = string_format(_CONV("SCardFreeMemory(hContext:0x%x) called\n"), hContext); - if (theApp.m_winscardConfig.bLOG_FUNCTIONS_CALLS) CCommonFnc::File_AppendString(WINSCARD_RULES_LOG, message); + LogWinscardRules(message); LONG status = SCARD_S_SUCCESS; @@ -511,7 +519,7 @@ SCard LONG STDCALL SCardDisconnect( SCARDHANDLE hCard, DWORD dwDisposition) { - if (theApp.m_winscardConfig.bLOG_FUNCTIONS_CALLS) CCommonFnc::File_AppendString(WINSCARD_RULES_LOG, _CONV("SCardDisconnect called\n")); + LogWinscardRules(_CONV("SCardDisconnect called\n")); // DISCONNECT FROM CARD if (theApp.IsRemoteCard(hCard)) { @@ -542,13 +550,13 @@ SCard LONG STDCALL SCardTransmit( IN OUT LPDWORD pcbRecvLength ) { - if (theApp.m_winscardConfig.bLOG_FUNCTIONS_CALLS) CCommonFnc::File_AppendString(WINSCARD_RULES_LOG, _CONV("SCardTransmit called\n")); + LogWinscardRules(_CONV("SCardTransmit called\n")); LONG result = SCARD_S_SUCCESS; // DWORD written; char_type *txMsg = _CONV("transmitted:"); char_type *rxMsg = _CONV("received:"); - char_type *crlf = _CONV("\r\n"); + char_type *crlf = _CONV("\n"); const int bufferLength = 1024; //char_type buffer[bufferLength]; string_type buffer; @@ -563,16 +571,16 @@ SCard LONG STDCALL SCardTransmit( //elapsedLibrary = -clock(); auto lib_timestamp1 = Clock::now(); if (theApp.m_winscardConfig.bLOG_EXCHANGED_APDU) { - //sprintf(buffer, "SCardTransmit (handle 0x%0.8X)#\r\n", hCard); - buffer = string_format(_CONV("SCardTransmit (handle 0x%0.8X)#\r\n"), hCard); + //sprintf(buffer, "SCardTransmit (handle 0x%0.8X)#\n", hCard); + buffer = string_format(_CONV("SCardTransmit (handle 0x%0.8X)#\n"), hCard); CCommonFnc::File_AppendString(WINSCARD_LOG, buffer); - //sprintf(buffer, "apduCounter:%d#\r\n", apduCounter); - buffer = string_format(_CONV("apduCounter:%d#\r\n"), apduCounter); + //sprintf(buffer, "apduCounter:%d#\n", apduCounter); + buffer = string_format(_CONV("apduCounter:%d#\n"), apduCounter); CCommonFnc::File_AppendString(WINSCARD_LOG, buffer); - //sprintf(buffer, "totalBytesINCounter:%d#\r\n", theApp.m_processedApduByteCounter + 1); - buffer = string_format(_CONV("totalBytesINCounter:%d#\r\n"), theApp.m_processedApduByteCounter + 1); + //sprintf(buffer, "totalBytesINCounter:%d#\n", theApp.m_processedApduByteCounter + 1); + buffer = string_format(_CONV("totalBytesINCounter:%d#\n"), theApp.m_processedApduByteCounter + 1); CCommonFnc::File_AppendString(WINSCARD_LOG, buffer); if(theApp.m_winscardConfig.bLOG_WRITE_DESCRIPTION) @@ -594,11 +602,11 @@ SCard LONG STDCALL SCardTransmit( if (theApp.m_winscardConfig.bMODIFY_APDU_BY_RULES) { message = string_format(_CONV("\nIncoming rules applied for apduCounter %d: \n"), apduCounter); - CCommonFnc::File_AppendString(WINSCARD_RULES_LOG, message); + LogWinscardRules(message); CCommonFnc::BYTE_ConvertFromArrayToHexString((BYTE*)pbSendBuffer, cbSendLength, &message); //message.Insert(0, " "); message += "\n"; message.insert(0, _CONV(" ")); message += _CONV("\n"); - if (theApp.m_winscardConfig.bLOG_EXCHANGED_APDU) CCommonFnc::File_AppendString(WINSCARD_RULES_LOG, message); + if (theApp.m_winscardConfig.bLOG_EXCHANGED_APDU) LogWinscardRules(message); } // COPY INPUT DATA @@ -610,7 +618,7 @@ SCard LONG STDCALL SCardTransmit( CCommonFnc::BYTE_ConvertFromArrayToHexString((BYTE*)sendBuffer, cbSendLength, &message); //message.Insert(0, " "); message += "\n"; message.insert(0, _CONV(" ")); message += _CONV("\n"); - if (theApp.m_winscardConfig.bLOG_EXCHANGED_APDU) CCommonFnc::File_AppendString(WINSCARD_RULES_LOG, message); + if (theApp.m_winscardConfig.bLOG_EXCHANGED_APDU) LogWinscardRules(message); } //elapsedCard = -clock(); @@ -695,12 +703,12 @@ SCard LONG STDCALL SCardTransmit( auto card_timestamp2 = Clock::now(); auto elapsedCard = std::chrono::duration_cast(card_timestamp2 - card_timestamp1).count(); if (theApp.m_winscardConfig.bLOG_EXCHANGED_APDU) { - //sprintf(buffer, "responseTime:%d#\r\n", elapsedCard); - buffer = string_format(_CONV("responseTime:%d#\r\n"), elapsedCard); + //sprintf(buffer, "responseTime:%d#\n", elapsedCard); + buffer = string_format(_CONV("responseTime:%d#\n"), elapsedCard); CCommonFnc::File_AppendString(WINSCARD_LOG, buffer); - //sprintf(buffer, "SCardTransmit result:0x%x#\r\n", result); - buffer = string_format(_CONV("SCardTransmit result:0x%x#\r\n"), result); + //sprintf(buffer, "SCardTransmit result:0x%x#\n", result); + buffer = string_format(_CONV("SCardTransmit result:0x%x#\n"), result); CCommonFnc::File_AppendString(WINSCARD_LOG, buffer); } @@ -722,17 +730,17 @@ SCard LONG STDCALL SCardTransmit( if (theApp.m_winscardConfig.bMODIFY_APDU_BY_RULES) { message = string_format(_CONV("\nOutgoing rules applied for apduCounter %d: \n"), apduCounter); - CCommonFnc::File_AppendString(WINSCARD_RULES_LOG, message); + LogWinscardRules(message); CCommonFnc::BYTE_ConvertFromArrayToHexString(pbRecvBuffer, *pcbRecvLength, &message); //message.Insert(0, " "); message += "\n"; message.insert(0, _CONV(" ")); message += _CONV("\n"); - if (theApp.m_winscardConfig.bLOG_EXCHANGED_APDU) CCommonFnc::File_AppendString(WINSCARD_RULES_LOG, message); + if (theApp.m_winscardConfig.bLOG_EXCHANGED_APDU) LogWinscardRules(message); // APPLY OUTGOING RULES if (theApp.m_winscardConfig.bMODIFY_APDU_BY_RULES) theApp.ApplyRules(pbRecvBuffer, pcbRecvLength, OUTPUT_APDU); CCommonFnc::BYTE_ConvertFromArrayToHexString(pbRecvBuffer, *pcbRecvLength, &message); //message.Insert(0, " "); message += "\n"; message.insert(0, _CONV(" ")); message += _CONV("\n"); - if (theApp.m_winscardConfig.bLOG_EXCHANGED_APDU) CCommonFnc::File_AppendString(WINSCARD_RULES_LOG, message); + if (theApp.m_winscardConfig.bLOG_EXCHANGED_APDU) LogWinscardRules(message); } @@ -743,9 +751,8 @@ SCard LONG STDCALL SCardTransmit( auto lib_timestamp2 = Clock::now(); auto elapsedLibrary = std::chrono::duration_cast(lib_timestamp2 - lib_timestamp1).count(); if (theApp.m_winscardConfig.bLOG_EXCHANGED_APDU) { - message = string_format(_CONV("responseTimeLibrary:%d#\r\n"), elapsedLibrary); - CCommonFnc::File_AppendString(WINSCARD_RULES_LOG, message); - CCommonFnc::File_AppendString(WINSCARD_RULES_LOG, _CONV("...............................................\r\n")); + message = string_format(_CONV("responseTimeLibrary:%d#\n"), elapsedLibrary); + LogWinscardRules(message); } return result; @@ -786,7 +793,7 @@ SCard LONG STDCALL SCardConnect( status = (*Original_SCardConnect)(hContext, szReader, dwShareMode, dwPreferredProtocols, phCard, pdwActiveProtocol); string_type message; message = string_format(_CONV("SCardConnect(hContext:0x%x,%s,hCard:0x%x) called\n"), hContext, szReader, *phCard); - if (theApp.m_winscardConfig.bLOG_FUNCTIONS_CALLS) CCommonFnc::File_AppendString(WINSCARD_RULES_LOG, message); + LogWinscardRules(message); } // Store mapping between card handle and reader (used in card remoting) @@ -814,10 +821,7 @@ SCard LONG STDCALL SCardStatus( LPBYTE pbAtr, LPDWORD pcbAtrLen) { - if (theApp.m_winscardConfig.bLOG_FUNCTIONS_CALLS) { - string_type message = string_format(_CONV("SCardStatus(hCard:0x%x,szReaderName:%s,pcchReaderLen:%d,pcbAtrLen:%d) called\n"), hCard, szReaderName, *pcchReaderLen, *pcbAtrLen); - CCommonFnc::File_AppendString(WINSCARD_RULES_LOG, message); - } + LogWinscardRules(string_format(_CONV("SCardStatus(hCard:0x%x,szReaderName:%s,pcchReaderLen:%d,pcbAtrLen:%d) called\n"), hCard, szReaderName, *pcchReaderLen, *pcbAtrLen)); if (theApp.IsRemoteCard(hCard)) { // According to https://docs.microsoft.com/en-us/windows/desktop/api/winscard/nf-winscard-scardstatusa @@ -844,7 +848,7 @@ SCard LONG STDCALL SCardListReaders( OUT LPSTR mszReaders, IN OUT LPDWORD pcchReaders) { - if (theApp.m_winscardConfig.bLOG_FUNCTIONS_CALLS) CCommonFnc::File_AppendString(WINSCARD_RULES_LOG, _CONV("SCardListReaders called\n")); + LogWinscardRules(_CONV("SCardListReaders called\n")); int status = SCARD_S_SUCCESS; ls readersList; @@ -944,7 +948,7 @@ SCard LONG STDCALL SCardListReaders( availableReaders += ", "; } availableReaders += "\n"; - if (theApp.m_winscardConfig.bLOG_FUNCTIONS_CALLS) CCommonFnc::File_AppendString(WINSCARD_RULES_LOG, availableReaders); + LogWinscardRules(availableReaders); return status; } @@ -960,7 +964,7 @@ SCard LONG STDCALL SCardListReaderGroups( OUT LPSTR mszGroups, IN OUT LPDWORD pcchGroups ) { - if (theApp.m_winscardConfig.bLOG_FUNCTIONS_CALLS) CCommonFnc::File_AppendString(WINSCARD_RULES_LOG, _CONV("SCardListReaderGroups called\n")); + LogWinscardRules(_CONV("SCardListReaderGroups called\n")); return (*Original_SCardListReaderGroups)(hContext, mszGroups, pcchGroups); } @@ -987,7 +991,7 @@ SCard LONG STDCALL SCardConnectW( LONG status = SCARD_S_SUCCESS; string_type message; message = string_format(_CONV("SCardConnectW(hContext:0x%x, %S) called\n"), hContext, szReader); - if (theApp.m_winscardConfig.bLOG_FUNCTIONS_CALLS) CCommonFnc::File_AppendString(WINSCARD_RULES_LOG, message); + LogWinscardRules(message); // RESET APDU IN BYTE COUNTER theApp.m_processedApduByteCounter = 0; @@ -1000,20 +1004,20 @@ SCard LONG STDCALL SCardConnectW( message = string_format(_CONV("\n:: %s"), l.c_str()); //message.Replace("\n", " "); replace(message.begin(), message.end(), '\n', ' '); - CCommonFnc::File_AppendString(WINSCARD_RULES_LOG, message); + LogWinscardRules(message); // PREPARE FOR MEASUREMENT message = string_format(_CONV("get params 1 %d %d"), theApp.m_remoteConfig.measureApduByteCounter, theApp.m_remoteConfig.measureApduByteDelay); theApp.m_remoteConfig.pSocket->SendLine(message); l = theApp.m_remoteConfig.pSocket->ReceiveResponse(REMOTE_SOCKET_ENDSEQ, REMOTE_SOCKET_TIMEOUT); message = string_format(_CONV(":: %s"), l.c_str()); - CCommonFnc::File_AppendString(WINSCARD_RULES_LOG, message); + LogWinscardRules(message); message = string_format(_CONV("post sampling %d"), theApp.m_remoteConfig.numSamples); theApp.m_remoteConfig.pSocket->SendLine(message); l = theApp.m_remoteConfig.pSocket->ReceiveResponse(REMOTE_SOCKET_ENDSEQ, REMOTE_SOCKET_TIMEOUT); message = string_format(_CONV(":: %s"), l.c_str()); - CCommonFnc::File_AppendString(WINSCARD_RULES_LOG, message); + LogWinscardRules(message); // PREPARE FOR MEASUREMENT READING IN FUTURE theApp.m_remoteConfig.sampleReaded = FALSE; @@ -1029,7 +1033,7 @@ SCard LONG STDCALL SCardConnectW( } message = string_format(_CONV("-> hCard:0x%x\n"), *phCard); - CCommonFnc::File_AppendString(WINSCARD_RULES_LOG, message); + LogWinscardRules(message); return status; } @@ -1049,7 +1053,7 @@ SCard LONG STDCALL SCardListReadersW( { string_type message; message = string_format(_CONV("SCardListReadersW(hContext:0x%x) called\n"), hContext); - if (theApp.m_winscardConfig.bLOG_FUNCTIONS_CALLS) CCommonFnc::File_AppendString(WINSCARD_RULES_LOG, message); + LogWinscardRules(message); LONG status = SCARD_S_SUCCESS; lws readersList; @@ -1153,7 +1157,7 @@ SCard LONG STDCALL SCardListReadersW( availableReaders += L", "; } availableReaders += L"\n"; - if (theApp.m_winscardConfig.bLOG_FUNCTIONS_CALLS) CCommonFnc::File_AppendString(WINSCARD_RULES_LOG, availableReaders); + //LogWinscardRules(availableReaders); return status; } @@ -1169,7 +1173,7 @@ SCard LONG STDCALL SCardListReaderGroupsW( OUT LPWSTR mszGroups, IN OUT LPDWORD pcchGroups ) { - if (theApp.m_winscardConfig.bLOG_FUNCTIONS_CALLS) CCommonFnc::File_AppendString(WINSCARD_RULES_LOG, _CONV("SCardListReaderGroupsW called\n")); + LogWinscardRules(_CONV("SCardListReaderGroupsW called\n")); return (*Original_SCardListReaderGroupsW)(hContext, mszGroups, pcchGroups); } @@ -1193,7 +1197,7 @@ SCard LONG STDCALL SCardListCardsA( ) { string_type message; message = string_format(_CONV("SCardListCardsA(hContext:0x%x) called\n"), hContext); - if (theApp.m_winscardConfig.bLOG_FUNCTIONS_CALLS) CCommonFnc::File_AppendString(WINSCARD_RULES_LOG, message); + LogWinscardRules(message); return (*Original_SCardListCardsA)(hContext, pbAtr, rgquidInterfaces, cguidInterfaceCount, mszCards, pcchCards); } @@ -1217,7 +1221,7 @@ SCard LONG STDCALL SCardListCardsW( ) { string_type message; message = string_format(_CONV("SCardListCardsW(hContext:0x%x) called\n"), hContext); - if (theApp.m_winscardConfig.bLOG_FUNCTIONS_CALLS) CCommonFnc::File_AppendString(WINSCARD_RULES_LOG, message); + LogWinscardRules(message); return (*Original_SCardListCardsW)(hContext, pbAtr, rgquidInterfaces, cguidInterfaceCount, mszCards, pcchCards); } @@ -1235,7 +1239,7 @@ SCard LONG STDCALL SCardListInterfacesA( OUT LPGUID pguidInterfaces, IN OUT LPDWORD pcguidInterfaces ) { - if (theApp.m_winscardConfig.bLOG_FUNCTIONS_CALLS) CCommonFnc::File_AppendString(WINSCARD_RULES_LOG, _CONV("SCardListInterfacesA called\n")); + LogWinscardRules(_CONV("SCardListInterfacesA called\n")); return (*Original_SCardListInterfacesA)(hContext, szCard, pguidInterfaces, pcguidInterfaces); } @@ -1253,7 +1257,7 @@ SCard LONG STDCALL SCardListInterfacesW( OUT LPGUID pguidInterfaces, IN OUT LPDWORD pcguidInterfaces ) { - if (theApp.m_winscardConfig.bLOG_FUNCTIONS_CALLS) CCommonFnc::File_AppendString(WINSCARD_RULES_LOG, _CONV("SCardListInterfacesW called\n")); + LogWinscardRules(_CONV("SCardListInterfacesW called\n")); return (*Original_SCardListInterfacesW)(hContext, szCard, pguidInterfaces, pcguidInterfaces); } @@ -1269,7 +1273,7 @@ SCard LONG STDCALL SCardGetProviderIdA( IN LPCSTR szCard, OUT LPGUID pguidProviderId ) { - if (theApp.m_winscardConfig.bLOG_FUNCTIONS_CALLS) CCommonFnc::File_AppendString(WINSCARD_RULES_LOG, _CONV("SCardGetProviderIdA called\n")); + LogWinscardRules(_CONV("SCardGetProviderIdA called\n")); return (*Original_SCardGetProviderIdA)(hContext, szCard, pguidProviderId); } @@ -1285,7 +1289,7 @@ SCard LONG STDCALL SCardGetProviderIdW( IN LPCWSTR szCard, OUT LPGUID pguidProviderId ) { - if (theApp.m_winscardConfig.bLOG_FUNCTIONS_CALLS) CCommonFnc::File_AppendString(WINSCARD_RULES_LOG, _CONV("SCardGetProviderIdW called\n")); + LogWinscardRules(_CONV("SCardGetProviderIdW called\n")); return (*Original_SCardGetProviderIdW)(hContext, szCard, pguidProviderId); } @@ -1305,7 +1309,7 @@ SCard LONG STDCALL SCardGetCardTypeProviderNameA( OUT LPSTR szProvider, IN OUT LPDWORD pcchProvider ) { - if (theApp.m_winscardConfig.bLOG_FUNCTIONS_CALLS) CCommonFnc::File_AppendString(WINSCARD_RULES_LOG, _CONV("SCardGetCardTypeProviderNameA called\n")); + LogWinscardRules(_CONV("SCardGetCardTypeProviderNameA called\n")); return (*Original_SCardGetCardTypeProviderNameA)(hContext, szCardName, dwProviderId, szProvider, pcchProvider); } @@ -1325,7 +1329,7 @@ SCard LONG STDCALL SCardGetCardTypeProviderNameW( OUT LPWSTR szProvider, IN OUT LPDWORD pcchProvider ) { - if (theApp.m_winscardConfig.bLOG_FUNCTIONS_CALLS) CCommonFnc::File_AppendString(WINSCARD_RULES_LOG, _CONV("SCardGetCardTypeProviderNameW called\n")); + LogWinscardRules(_CONV("SCardGetCardTypeProviderNameW called\n")); return (*Original_SCardGetCardTypeProviderNameW)(hContext, szCardName, dwProviderId, szProvider, pcchProvider); } @@ -1339,7 +1343,7 @@ SCard LONG STDCALL SCardIntroduceReaderGroupA( IN SCARDCONTEXT hContext, IN LPCSTR szGroupName ) { - if (theApp.m_winscardConfig.bLOG_FUNCTIONS_CALLS) CCommonFnc::File_AppendString(WINSCARD_RULES_LOG, _CONV("SCardIntroduceReaderGroupA called\n")); + LogWinscardRules(_CONV("SCardIntroduceReaderGroupA called\n")); return (*Original_SCardIntroduceReaderGroupA)(hContext, szGroupName); } @@ -1353,7 +1357,7 @@ SCard LONG STDCALL SCardIntroduceReaderGroupW( IN SCARDCONTEXT hContext, IN LPCWSTR szGroupName ) { - if (theApp.m_winscardConfig.bLOG_FUNCTIONS_CALLS) CCommonFnc::File_AppendString(WINSCARD_RULES_LOG, _CONV("SCardIntroduceReaderGroupW called\n")); + LogWinscardRules(_CONV("SCardIntroduceReaderGroupW called\n")); return (*Original_SCardIntroduceReaderGroupW)(hContext, szGroupName); } @@ -1367,7 +1371,7 @@ SCard LONG STDCALL SCardForgetReaderGroupA( IN SCARDCONTEXT hContext, IN LPCSTR szGroupName ) { - if (theApp.m_winscardConfig.bLOG_FUNCTIONS_CALLS) CCommonFnc::File_AppendString(WINSCARD_RULES_LOG, _CONV("SCardForgetReaderGroupA called\n")); + LogWinscardRules(_CONV("SCardForgetReaderGroupA called\n")); return (*Original_SCardForgetReaderGroupA)(hContext, szGroupName); } @@ -1381,7 +1385,7 @@ SCard LONG STDCALL SCardForgetReaderGroupW( IN SCARDCONTEXT hContext, IN LPCWSTR szGroupName ) { - if (theApp.m_winscardConfig.bLOG_FUNCTIONS_CALLS) CCommonFnc::File_AppendString(WINSCARD_RULES_LOG, _CONV("SCardForgetReaderGroupW called\n")); + LogWinscardRules(_CONV("SCardForgetReaderGroupW called\n")); return (*Original_SCardForgetReaderGroupW)(hContext, szGroupName); } @@ -1397,7 +1401,7 @@ SCard LONG STDCALL SCardIntroduceReaderA( IN LPCSTR szReaderName, IN LPCSTR szDeviceName ) { - if (theApp.m_winscardConfig.bLOG_FUNCTIONS_CALLS) CCommonFnc::File_AppendString(WINSCARD_RULES_LOG, _CONV("SCardIntroduceReaderA called\n")); + LogWinscardRules(_CONV("SCardIntroduceReaderA called\n")); return (*Original_SCardIntroduceReaderA)(hContext, szReaderName, szDeviceName); } @@ -1413,7 +1417,7 @@ SCard LONG STDCALL SCardIntroduceReaderW( IN LPCWSTR szReaderName, IN LPCWSTR szDeviceName ) { - if (theApp.m_winscardConfig.bLOG_FUNCTIONS_CALLS) CCommonFnc::File_AppendString(WINSCARD_RULES_LOG, _CONV("SCardIntroduceReaderW called\n")); + LogWinscardRules(_CONV("SCardIntroduceReaderW called\n")); return (*Original_SCardIntroduceReaderW)(hContext, szReaderName, szDeviceName); } @@ -1427,7 +1431,7 @@ SCard LONG STDCALL SCardForgetReaderA( IN SCARDCONTEXT hContext, IN LPCSTR szReaderName ) { - if (theApp.m_winscardConfig.bLOG_FUNCTIONS_CALLS) CCommonFnc::File_AppendString(WINSCARD_RULES_LOG, _CONV("SCardForgetReaderA called\n")); + LogWinscardRules(_CONV("SCardForgetReaderA called\n")); return (*Original_SCardForgetReaderA)(hContext, szReaderName); } @@ -1441,7 +1445,7 @@ SCard LONG STDCALL SCardForgetReaderW( IN SCARDCONTEXT hContext, IN LPCWSTR szReaderName ) { - if (theApp.m_winscardConfig.bLOG_FUNCTIONS_CALLS) CCommonFnc::File_AppendString(WINSCARD_RULES_LOG, _CONV("SCardForgetReaderW called\n")); + LogWinscardRules(_CONV("SCardForgetReaderW called\n")); return (*Original_SCardForgetReaderW)(hContext, szReaderName); } @@ -1457,7 +1461,7 @@ SCard LONG STDCALL SCardAddReaderToGroupA( IN LPCSTR szReaderName, IN LPCSTR szGroupName ) { - if (theApp.m_winscardConfig.bLOG_FUNCTIONS_CALLS) CCommonFnc::File_AppendString(WINSCARD_RULES_LOG, _CONV("SCardAddReaderToGroupA called\n")); + LogWinscardRules(_CONV("SCardAddReaderToGroupA called\n")); return (*Original_SCardAddReaderToGroupA)(hContext, szReaderName, szGroupName); } @@ -1473,7 +1477,7 @@ SCard LONG STDCALL SCardAddReaderToGroupW( IN LPCWSTR szReaderName, IN LPCWSTR szGroupName ) { - if (theApp.m_winscardConfig.bLOG_FUNCTIONS_CALLS) CCommonFnc::File_AppendString(WINSCARD_RULES_LOG, _CONV("SCardAddReaderToGroupW called\n")); + LogWinscardRules(_CONV("SCardAddReaderToGroupW called\n")); return (*Original_SCardAddReaderToGroupW)(hContext, szReaderName, szGroupName); } @@ -1489,7 +1493,7 @@ SCard LONG STDCALL SCardRemoveReaderFromGroupA( IN LPCSTR szReaderName, IN LPCSTR szGroupName ) { - if (theApp.m_winscardConfig.bLOG_FUNCTIONS_CALLS) CCommonFnc::File_AppendString(WINSCARD_RULES_LOG, _CONV("SCardRemoveReaderFromGroupA called\n")); + LogWinscardRules(_CONV("SCardRemoveReaderFromGroupA called\n")); return (*Original_SCardRemoveReaderFromGroupA)(hContext, szReaderName, szGroupName); } @@ -1505,7 +1509,7 @@ SCard LONG STDCALL SCardRemoveReaderFromGroupW( IN LPCWSTR szReaderName, IN LPCWSTR szGroupName ) { - if (theApp.m_winscardConfig.bLOG_FUNCTIONS_CALLS) CCommonFnc::File_AppendString(WINSCARD_RULES_LOG, _CONV("SCardRemoveReaderFromGroupW called\n")); + LogWinscardRules(_CONV("SCardRemoveReaderFromGroupW called\n")); return (*Original_SCardRemoveReaderFromGroupW)(hContext, szReaderName, szGroupName); } @@ -1531,7 +1535,7 @@ SCard LONG STDCALL SCardIntroduceCardTypeA( IN LPCBYTE pbAtrMask, IN DWORD cbAtrLen ) { - if (theApp.m_winscardConfig.bLOG_FUNCTIONS_CALLS) CCommonFnc::File_AppendString(WINSCARD_RULES_LOG, _CONV("SCardIntroduceCardTypeA called\n")); + LogWinscardRules(_CONV("SCardIntroduceCardTypeA called\n")); return (*Original_SCardIntroduceCardTypeA)(hContext, szCardName, pguidPrimaryProvider, rgguidInterfaces, dwInterfaceCount, pbAtr, pbAtrMask, cbAtrLen); } @@ -1557,7 +1561,7 @@ SCard LONG STDCALL SCardIntroduceCardTypeW( IN LPCBYTE pbAtrMask, IN DWORD cbAtrLen ) { - if (theApp.m_winscardConfig.bLOG_FUNCTIONS_CALLS) CCommonFnc::File_AppendString(WINSCARD_RULES_LOG, _CONV("SCardIntroduceCardTypeW called\n")); + LogWinscardRules(_CONV("SCardIntroduceCardTypeW called\n")); return (*Original_SCardIntroduceCardTypeW)(hContext, szCardName, pguidPrimaryProvider, rgguidInterfaces, dwInterfaceCount, pbAtr, pbAtrMask, cbAtrLen); } @@ -1575,7 +1579,7 @@ SCard LONG STDCALL SCardSetCardTypeProviderNameA( IN DWORD dwProviderId, IN LPCSTR szProvider ) { - if (theApp.m_winscardConfig.bLOG_FUNCTIONS_CALLS) CCommonFnc::File_AppendString(WINSCARD_RULES_LOG, _CONV("SCardSetCardTypeProviderNameA called\n")); + LogWinscardRules(_CONV("SCardSetCardTypeProviderNameA called\n")); return (*Original_SCardSetCardTypeProviderNameA)(hContext, szCardName, dwProviderId, szProvider); } @@ -1593,7 +1597,7 @@ SCard LONG STDCALL SCardSetCardTypeProviderNameW( IN DWORD dwProviderId, IN LPCWSTR szProvider ) { - if (theApp.m_winscardConfig.bLOG_FUNCTIONS_CALLS) CCommonFnc::File_AppendString(WINSCARD_RULES_LOG, _CONV("SCardSetCardTypeProviderNameW called\n")); + LogWinscardRules(_CONV("SCardSetCardTypeProviderNameW called\n")); return (*Original_SCardSetCardTypeProviderNameW)(hContext, szCardName, dwProviderId, szProvider); } @@ -1607,7 +1611,7 @@ SCard LONG STDCALL SCardForgetCardTypeA( IN SCARDCONTEXT hContext, IN LPCSTR szCardName ) { - if (theApp.m_winscardConfig.bLOG_FUNCTIONS_CALLS) CCommonFnc::File_AppendString(WINSCARD_RULES_LOG, _CONV("SCardForgetCardTypeA called\n")); + LogWinscardRules(_CONV("SCardForgetCardTypeA called\n")); return (*Original_SCardForgetCardTypeA)(hContext, szCardName); } @@ -1621,7 +1625,7 @@ SCard LONG STDCALL SCardForgetCardTypeW( IN SCARDCONTEXT hContext, IN LPCWSTR szCardName ) { - if (theApp.m_winscardConfig.bLOG_FUNCTIONS_CALLS) CCommonFnc::File_AppendString(WINSCARD_RULES_LOG, _CONV("SCardForgetCardTypeW called\n")); + LogWinscardRules(_CONV("SCardForgetCardTypeW called\n")); return (*Original_SCardForgetCardTypeW)(hContext, szCardName); } @@ -1640,7 +1644,7 @@ SCard LONG STDCALL SCardLocateCardsA( ) { string_type message; message = string_format(_CONV("SCardLocateCardsA(%s,0x%x) called\n"), mszCards, hContext); - if (theApp.m_winscardConfig.bLOG_FUNCTIONS_CALLS) CCommonFnc::File_AppendString(WINSCARD_RULES_LOG, message); + LogWinscardRules(message); return (*Original_SCardLocateCardsA)(hContext, mszCards, rgReaderStates, cReaders); } @@ -1660,7 +1664,7 @@ SCard LONG STDCALL SCardLocateCardsW( ) { string_type message; message = string_format(_CONV("SCardLocateCardsW(%S,0x%x) called\n"), mszCards, hContext); - if (theApp.m_winscardConfig.bLOG_FUNCTIONS_CALLS) CCommonFnc::File_AppendString(WINSCARD_RULES_LOG, message); + LogWinscardRules(message); return (*Original_SCardLocateCardsW)(hContext, mszCards, rgReaderStates, cReaders); } @@ -1682,7 +1686,7 @@ SCard LONG STDCALL SCardLocateCardsByATRA( ) { string_type message; message = string_format(_CONV("SCardLocateCardsByATRA(hContext:0x%x) called\n"), hContext); - if (theApp.m_winscardConfig.bLOG_FUNCTIONS_CALLS) CCommonFnc::File_AppendString(WINSCARD_RULES_LOG, message); + LogWinscardRules(message); return (*Original_SCardLocateCardsByATRA)(hContext, rgAtrMasks, cAtrs, rgReaderStates, cReaders); } @@ -1704,7 +1708,7 @@ SCard LONG STDCALL SCardLocateCardsByATRW( ) { string_type message; message = string_format(_CONV("SCardLocateCardsByATRW(hContext:0x%x) called\n"), hContext); - if (theApp.m_winscardConfig.bLOG_FUNCTIONS_CALLS) CCommonFnc::File_AppendString(WINSCARD_RULES_LOG, message); + LogWinscardRules(message); return (*Original_SCardLocateCardsByATRW)(hContext, rgAtrMasks, cAtrs, rgReaderStates, cReaders); } @@ -1721,7 +1725,7 @@ SCard LONG STDCALL SCardGetStatusChangeA( IN OUT LPSCARD_READERSTATEA rgReaderStates, IN DWORD cReaders ) { - if (theApp.m_winscardConfig.bLOG_FUNCTIONS_CALLS) CCommonFnc::File_AppendString(WINSCARD_RULES_LOG, _CONV("SCardGetStatusChangeA called\n")); + LogWinscardRules(_CONV("SCardGetStatusChangeA called\n")); return (*Original_SCardGetStatusChangeA)(hContext, dwTimeout, rgReaderStates, cReaders); } @@ -1739,7 +1743,7 @@ SCard LONG STDCALL SCardGetStatusChangeW( IN OUT LPSCARD_READERSTATEW rgReaderStates, IN DWORD cReaders ) { - if (theApp.m_winscardConfig.bLOG_FUNCTIONS_CALLS) CCommonFnc::File_AppendString(WINSCARD_RULES_LOG, _CONV("SCardGetStatusChangeW called\n")); + LogWinscardRules(_CONV("SCardGetStatusChangeW called\n")); return (*Original_SCardGetStatusChangeW)(hContext, dwTimeout, rgReaderStates, cReaders); } @@ -1750,7 +1754,7 @@ static SCard LONG(STDCALL *Original_SCardUIDlgSelectCardA)( SCard LONG STDCALL SCardUIDlgSelectCardA( LPOPENCARDNAMEA_EX a ) { - if (theApp.m_winscardConfig.bLOG_FUNCTIONS_CALLS) CCommonFnc::File_AppendString(WINSCARD_RULES_LOG, _CONV("SCardUIDlgSelectCardA called\n")); + LogWinscardRules(_CONV("SCardUIDlgSelectCardA called\n")); return (*Original_SCardUIDlgSelectCardA)(a); } @@ -1762,7 +1766,7 @@ static SCard LONG(STDCALL *Original_SCardUIDlgSelectCardW)( SCard LONG STDCALL SCardUIDlgSelectCardW( LPOPENCARDNAMEW_EX a ) { - if (theApp.m_winscardConfig.bLOG_FUNCTIONS_CALLS) CCommonFnc::File_AppendString(WINSCARD_RULES_LOG, _CONV("SCardUIDlgSelectCardW called\n")); + LogWinscardRules(_CONV("SCardUIDlgSelectCardW called\n")); return (*Original_SCardUIDlgSelectCardW)(a); } @@ -1773,7 +1777,7 @@ static SCard LONG(STDCALL *Original_GetOpenCardNameA)( SCard LONG STDCALL GetOpenCardNameA( LPOPENCARDNAMEA a ) { - if (theApp.m_winscardConfig.bLOG_FUNCTIONS_CALLS) CCommonFnc::File_AppendString(WINSCARD_RULES_LOG, _CONV("GetOpenCardNameA called\n")); + LogWinscardRules(_CONV("GetOpenCardNameA called\n")); return (*Original_GetOpenCardNameA)(a); } @@ -1784,7 +1788,7 @@ static SCard LONG(STDCALL *Original_GetOpenCardNameW)( SCard LONG STDCALL GetOpenCardNameW( LPOPENCARDNAMEW a ) { - if (theApp.m_winscardConfig.bLOG_FUNCTIONS_CALLS) CCommonFnc::File_AppendString(WINSCARD_RULES_LOG, _CONV("GetOpenCardNameW called\n")); + LogWinscardRules(_CONV("GetOpenCardNameW called\n")); return (*Original_GetOpenCardNameW)(a); } @@ -1792,7 +1796,7 @@ SCard LONG STDCALL GetOpenCardNameW( static SCard LONG(STDCALL *Original_SCardDlgExtendedError)(void); SCard LONG STDCALL SCardDlgExtendedError(void) { - CCommonFnc::File_AppendString(WINSCARD_RULES_LOG, _CONV("SCardDlgExtendedError called\n")); + LogWinscardRules(_CONV("SCardDlgExtendedError called\n")); return (*Original_SCardDlgExtendedError)(); } @@ -1803,7 +1807,7 @@ static SCard LONG(STDCALL *Original_SCardCancelTransaction)( SCard LONG STDCALL SCardCancelTransaction( IN SCARDHANDLE hCard ) { - if (theApp.m_winscardConfig.bLOG_FUNCTIONS_CALLS) CCommonFnc::File_AppendString(WINSCARD_RULES_LOG, _CONV("SCardCancelTransaction called\n")); + LogWinscardRules(_CONV("SCardCancelTransaction called\n")); if (theApp.IsRemoteCard(hCard)) { return SCARD_S_SUCCESS; } @@ -1829,7 +1833,7 @@ SCard LONG STDCALL SCardState( ) { string_type message; message = string_format(_CONV("SCardState(hCard:0x%x) called\n"), hCard); - if (theApp.m_winscardConfig.bLOG_FUNCTIONS_CALLS) CCommonFnc::File_AppendString(WINSCARD_RULES_LOG, message); + LogWinscardRules(message); if (theApp.IsRemoteCard(hCard)) { return SCARD_S_SUCCESS; *pdwState = SCARD_SPECIFIC; @@ -1863,7 +1867,7 @@ SCard LONG STDCALL SCardStatusW( ) { string_type message; message = string_format(_CONV("SCardStatusW(hCard:0x%x) called\n"), hCard); - if (theApp.m_winscardConfig.bLOG_FUNCTIONS_CALLS) CCommonFnc::File_AppendString(WINSCARD_RULES_LOG, message); + LogWinscardRules(message); if (theApp.IsRemoteCard(hCard)) { return SCARD_S_SUCCESS; *pdwState = SCARD_SPECIFIC; @@ -1878,7 +1882,7 @@ SCard LONG STDCALL SCardStatusW( static SCard HANDLE(STDCALL *Original_SCardAccessStartedEvent)(void); SCard HANDLE STDCALL SCardAccessStartedEvent(void) { - if (theApp.m_winscardConfig.bLOG_FUNCTIONS_CALLS) CCommonFnc::File_AppendString(WINSCARD_RULES_LOG, _CONV("SCardAccessStartedEvent called\n")); + LogWinscardRules(_CONV("SCardAccessStartedEvent called\n")); return (*Original_SCardAccessStartedEvent)(); } @@ -1886,7 +1890,7 @@ SCard HANDLE STDCALL SCardAccessStartedEvent(void) { static SCard void(STDCALL *Original_SCardReleaseStartedEvent)(void); SCard void STDCALL SCardReleaseStartedEvent(void) { - if (theApp.m_winscardConfig.bLOG_FUNCTIONS_CALLS) CCommonFnc::File_AppendString(WINSCARD_RULES_LOG, _CONV("SCardReleaseStartedEvent called\n")); + LogWinscardRules(_CONV("SCardReleaseStartedEvent called\n")); return (*Original_SCardReleaseStartedEvent)(); } #endif @@ -1908,7 +1912,7 @@ LONG SCardGetStatusChange( IN OUT SCARD_READERSTATE *rgReaderStates, IN DWORD cReaders ) { - if (theApp.m_winscardConfig.bLOG_FUNCTIONS_CALLS) CCommonFnc::File_AppendString(WINSCARD_RULES_LOG, _CONV("SCardGetStatusChange called\n")); + LogWinscardRules(_CONV("SCardGetStatusChange called\n")); return (*Original_SCardGetStatusChange)(hContext, dwTimeout, rgReaderStates, cReaders); } @@ -2681,7 +2685,7 @@ int initialize() IN SCARDHANDLE hCard)) load_func(hOriginal, "SCardCancelTransaction"); if (!Original_SCardCancelTransaction) { - CCommonFnc::File_AppendString(WINSCARD_RULES_LOG, _CONV("Could not find SCardCancelTransaction procedure address\n")); + LogWinscardRules(_CONV("Could not find SCardCancelTransaction procedure address\n")); } Original_SCardState = @@ -2732,7 +2736,7 @@ int initialize() LPOPENCARDNAMEA_EX)) load_func(hOriginal, "SCardUIDlgSelectCardA"); if (!Original_SCardUIDlgSelectCardA) { - CCommonFnc::File_AppendString(WINSCARD_RULES_LOG, _CONV("Could not find SCardUIDlgSelectCardA procedure address\n")); + LogWinscardRules(_CONV("Could not find SCardUIDlgSelectCardA procedure address\n")); } Original_SCardUIDlgSelectCardW = @@ -2740,28 +2744,28 @@ int initialize() LPOPENCARDNAMEW_EX)) load_func(hOriginal, "SCardUIDlgSelectCardW"); if (!Original_SCardUIDlgSelectCardW) { - CCommonFnc::File_AppendString(WINSCARD_RULES_LOG, _CONV("Could not find SCardUIDlgSelectCardW procedure address\n")); + LogWinscardRules(_CONV("Could not find SCardUIDlgSelectCardW procedure address\n")); } Original_GetOpenCardNameA = (LONG(STDCALL *)(LPOPENCARDNAMEA)) load_func(hOriginal, "GetOpenCardNameA"); if (!Original_GetOpenCardNameA) { - CCommonFnc::File_AppendString(WINSCARD_RULES_LOG, _CONV("Could not find GetOpenCardNameA procedure address\n")); + LogWinscardRules(_CONV("Could not find GetOpenCardNameA procedure address\n")); } Original_GetOpenCardNameW = (LONG(STDCALL *)(LPOPENCARDNAMEW)) load_func(hOriginal, "GetOpenCardNameW"); if (!Original_GetOpenCardNameW) { - CCommonFnc::File_AppendString(WINSCARD_RULES_LOG, _CONV("Could not find GetOpenCardNameW procedure address\n")); + LogWinscardRules(_CONV("Could not find GetOpenCardNameW procedure address\n")); } Original_SCardDlgExtendedError = (LONG(STDCALL *)(void)) load_func(hOriginal, "SCardDlgExtendedError "); if (!Original_SCardDlgExtendedError) { - CCommonFnc::File_AppendString(WINSCARD_RULES_LOG, _CONV("Could not find SCardDlgExtendedError procedure address\n")); + LogWinscardRules(_CONV("Could not find SCardDlgExtendedError procedure address\n")); } #endif @@ -2879,6 +2883,8 @@ void GetDesktopPath(char_type* path) #endif } + + #if defined (_WIN32) BOOL CWinscardApp::InitInstance() { @@ -2890,34 +2896,50 @@ BOOL CWinscardApp::InitInstance() } srand((int) time(NULL)); - CCommonFnc::File_AppendString(APDUPLAY_DEBUG_FILE, _CONV("InitInstance\n")); + LogDebugString(_CONV("#####################################################################################\n"), false); + LogDebugString(_CONV("InitInstance entered\n")); + +#if defined (_WIN32) && !defined(_WIN64) + LogDebugString(string_format(_CONV("APDUPlay winscard.dll v%s (32-bit version)\n"), LIBRARY_VERSION.c_str())); +#endif +#ifdef _WIN64 + LogDebugString(string_format(_CONV("APDUPlay winscard.dll v%s, (64-bit version)\n"), LIBRARY_VERSION.c_str())); +#endif + // LOAD MODIFICATION RULES LoadRules(); - CCommonFnc::File_AppendString(APDUPLAY_DEBUG_FILE, _CONV("After LoadRules\n")); + LogDebugString(_CONV("After LoadRules\n")); // CONNECT TO REMOTE SOCKET IF REQUIRED if (m_remoteConfig.bRedirect) { - Remote_Connect(&m_remoteConfig); + LogDebugString(_CONV("[REMOTE] Redirect = 1 => going to connect to specified socket (make sure socket is opened. If application terminates, try to set Redirect = 0 to disable remote redirecting)\n")); + Remote_Connect(&m_remoteConfig); } - if (theApp.m_winscardConfig.bLOG_EXCHANGED_APDU) CCommonFnc::File_AppendString(WINSCARD_LOG, _CONV("[begin]\r\n")); + if (theApp.m_winscardConfig.bLOG_EXCHANGED_APDU) CCommonFnc::File_AppendString(WINSCARD_LOG, _CONV("[begin]\n")); - return initialize(); + BOOL bStatus = initialize(); + LogDebugString(string_format(_CONV("Finalizing InitInstance with %s\n"), bStatus ? _CONV("true") : _CONV("false"))); + + return bStatus; } int CWinscardApp::Remote_Connect(REMOTE_CONFIG* pRemoteConfig) { string_type message; string_type sIP(pRemoteConfig->IP); - //pRemoteConfig->pSocket = new SocketClient(sIP, atoi(pRemoteConfig->port.c_str())); try { + message = string_format(_CONV("Connnecting to remote proxy with IP:port = %s:%s\n"), pRemoteConfig->IP.c_str(), pRemoteConfig->port.c_str()); + LogWinscardRules(message); pRemoteConfig->pSocket = new SocketClient(sIP, type_to_int(pRemoteConfig->port.c_str(), NULL, 10)); - message = string_format(_CONV("\n> Connnecting to remote proxy with IP:port = %s:%s\n"), pRemoteConfig->IP, pRemoteConfig->port); - CCommonFnc::File_AppendString(WINSCARD_RULES_LOG, message); } catch (std::string error) { - message = string_format(_CONV("\n> Failed to connect to %s:%s (error: %s)\n"), pRemoteConfig->IP, pRemoteConfig->port, error); - CCommonFnc::File_AppendString(WINSCARD_RULES_LOG, message); + message = string_format(_CONV("Failed to connect to %s:%s (error: %s)\n"), pRemoteConfig->IP.c_str(), pRemoteConfig->port.c_str(), error); + LogWinscardRules(message); + } + catch (...) { + message = string_format(_CONV("Failed to connect to %s:%s\n"), pRemoteConfig->IP.c_str(), pRemoteConfig->port.c_str()); + LogWinscardRules(message); } return STAT_OK; @@ -2973,7 +2995,7 @@ int CWinscardApp::ApplyRules(BYTE* pbBuffer, DWORD* pcbLength, int direction) { } } - // NEDETERMINISTIC SLEEP IF REQUIRED + // NONDETERMINISTIC SLEEP IF REQUIRED if (iter->msDelay > 0) { std::this_thread::sleep_for(std::chrono::milliseconds(iter->msDelay)); //_sleep(iter->msDelay); @@ -3057,7 +3079,7 @@ LONG CWinscardApp::Remote_SCardConnect(REMOTE_CONFIG* pRemoteConfig, string_type pRemoteConfig->pSocket->SendLine(l); //message.Insert(0, "\n::-> "); message.insert(0, _CONV("\n::-> ")); - CCommonFnc::File_AppendString(WINSCARD_RULES_LOG, message); + LogWinscardRules(message); _sleep(500); // OBTAIN RESPONSE, PARSE BACK @@ -3070,16 +3092,16 @@ LONG CWinscardApp::Remote_SCardConnect(REMOTE_CONFIG* pRemoteConfig, string_type message = string_format(_CONV("\n::<- %s\n"), response.c_str()); replace(message.begin(), message.end(), '\n', ' '); - CCommonFnc::File_AppendString(WINSCARD_RULES_LOG, message); + LogWinscardRules(message); } catch (const char* s) { - message = string_format(_CONV("Remote_SCardConnect(), SendLine(%s), fail with (%s)"), message, s); - CCommonFnc::File_AppendString(WINSCARD_RULES_LOG, message); + message = string_format(_CONV("Remote_SCardConnect(), SendLine(%s), fail with (%s)"), message.c_str(), s); + LogWinscardRules(message); status = SCARD_F_UNKNOWN_ERROR; } catch (...) { - message = string_format(_CONV("Remote_SCardConnect(), SendLine(%s), fail with (unhandled exception)"), message); - CCommonFnc::File_AppendString(WINSCARD_RULES_LOG, message); + message = string_format(_CONV("Remote_SCardConnect(), SendLine(%s), fail with (unhandled exception)"), message.c_str()); + LogWinscardRules(message); status = SCARD_F_UNKNOWN_ERROR; } } @@ -3098,7 +3120,7 @@ LONG CWinscardApp::Remote_ParseResponse(string_type rawResponse, DWORD expectedC size_t pos = 0; if (rawResponse.at(pos) != '>') { - CCommonFnc::File_AppendString(WINSCARD_RULES_LOG, "'>'was expected at begin"); + LogWinscardRules("'>'was expected at begin"); status = SCARD_F_COMM_ERROR; } pos++; @@ -3107,7 +3129,7 @@ LONG CWinscardApp::Remote_ParseResponse(string_type rawResponse, DWORD expectedC size_t pos2 = rawResponse.find(CMD_SEPARATOR); string_type uniqueCmdID = rawResponse.substr(pos, pos2 - 1); if (expectedCommandID != atoi(uniqueCmdID.c_str())) { - CCommonFnc::File_AppendString(WINSCARD_RULES_LOG, "Unexpected commandID in response"); + LogWinscardRules("Unexpected commandID in response"); status = SCARD_F_COMM_ERROR; } pos = pos2 + 1; @@ -3137,7 +3159,7 @@ LONG CWinscardApp::Remote_SCardTransmit(REMOTE_CONFIG* pRemoteConfig, string_typ pRemoteConfig->pSocket->SendLine(l); //message.Insert(0, "\n::-> "); message.insert(0, _CONV("\n::-> ")); - CCommonFnc::File_AppendString(WINSCARD_RULES_LOG, message); + LogWinscardRules(message); // SLEEP LONGER, IF MORE DATA WILL BE RETURNED BY SYSTEM 00 0c 00 00 xx CALL if (memcmp(pbSendBuffer, GET_APDU1, sizeof(GET_APDU1)) == 0 || memcmp(pbSendBuffer, GET_APDU2, sizeof(GET_APDU2)) == 0) { @@ -3154,7 +3176,7 @@ LONG CWinscardApp::Remote_SCardTransmit(REMOTE_CONFIG* pRemoteConfig, string_typ message = string_format(_CONV("\n::<- %s\n"), l.c_str()); //message.Replace("\n", " "); replace(message.begin(), message.end(), '\n', ' '); - CCommonFnc::File_AppendString(WINSCARD_RULES_LOG, message); + LogWinscardRules(message); if (response.find(CMD_RESPONSE_FAIL) == string_type::npos) { // RESPONSE CORRECT @@ -3171,13 +3193,13 @@ LONG CWinscardApp::Remote_SCardTransmit(REMOTE_CONFIG* pRemoteConfig, string_typ } } catch (const char* s) { - message = string_format(_CONV("\nRemote_SCardTransmit(), SendLine(%s), fail with (%s)"), message, s); - CCommonFnc::File_AppendString(WINSCARD_RULES_LOG, message); + message = string_format(_CONV("\nRemote_SCardTransmit(), SendLine(%s), fail with (%s)"), message.c_str(), s); + LogWinscardRules(message); status = SCARD_F_UNKNOWN_ERROR; } catch (...) { - message = string_format(_CONV("\nRemote_SCardTransmit(), SendLine(%s), fail with (unhandled exception)"), message); - CCommonFnc::File_AppendString(WINSCARD_RULES_LOG, message); + message = string_format(_CONV("\nRemote_SCardTransmit(), SendLine(%s), fail with (unhandled exception)"), message.c_str()); + LogWinscardRules(message); status = SCARD_F_UNKNOWN_ERROR; } } @@ -3241,12 +3263,6 @@ int CWinscardApp::LoadRule(const char_type* section_name, dictionary* dict/*stri m_winscardConfig.bMODIFY_APDU_BY_RULES = value; } - type_copy(sec_and_key, section_name); - if ((value = iniparser_getboolean(dict, type_cat(sec_and_key, _CONV(":LOG_FUNCTIONS_CALLS")), 2)) != 2) - { - m_winscardConfig.bLOG_FUNCTIONS_CALLS = value; - } - type_copy(sec_and_key, section_name); char_value = iniparser_getstring(dict, type_cat(sec_and_key, _CONV(":READER_ORDERED_FIRST")), ""); if (type_length(char_value) != 0) @@ -3571,37 +3587,37 @@ int CWinscardApp::LoadRules() { // (UNUSED) 3. Lookup on user Desktop if (!file) { // 1. Lookup in local directory - CCommonFnc::File_AppendString(APDUPLAY_DEBUG_FILE, string_format(_CONV("Going to open %s ... "), rulesFilePath)); + LogDebugString(string_format(_CONV("Going to open %s ... "), rulesFilePath)); file = fopen(rulesFilePath, "r"); if (file) { - CCommonFnc::File_AppendString(APDUPLAY_DEBUG_FILE, _CONV("success\n")); + LogDebugString(_CONV("success\n"), false); type_copy(baseDir, ""); } else { - CCommonFnc::File_AppendString(APDUPLAY_DEBUG_FILE, _CONV("fail\n")); + LogDebugString(_CONV("fail\n"), false); } } if (!file) { // 2. Lookup for APDUPLAY environmental variable char* configPath = std::getenv(ENV_APDUPLAY_WINSCARD_RULES_PATH.c_str()); - CCommonFnc::File_AppendString(APDUPLAY_DEBUG_FILE, string_format(_CONV("Going to query %s env variable ... "), ENV_APDUPLAY_WINSCARD_RULES_PATH)); + LogDebugString(string_format(_CONV("Going to query %s env variable ... "), ENV_APDUPLAY_WINSCARD_RULES_PATH.c_str())); if (configPath != NULL) { - CCommonFnc::File_AppendString(APDUPLAY_DEBUG_FILE, string_format(_CONV(" defined (%s)\n"), configPath)); + LogDebugString(string_format(_CONV(" defined (%s)\n"), configPath), false); // variable detected, try to open string newRuleFile = string_format(_CONV("%s\\%s"), configPath, RULE_FILE.c_str()); - CCommonFnc::File_AppendString(APDUPLAY_DEBUG_FILE, string_format(_CONV("Going to open %s ... "), newRuleFile.c_str())); + LogDebugString(string_format(_CONV("Going to open %s ... "), newRuleFile.c_str())); file = fopen(newRuleFile.c_str(), "r"); if (file) { - CCommonFnc::File_AppendString(APDUPLAY_DEBUG_FILE, _CONV("success\n")); + LogDebugString(_CONV("success\n"), false); type_copy(rulesFilePath, newRuleFile.c_str()); type_copy(baseDir, configPath); } else { - CCommonFnc::File_AppendString(APDUPLAY_DEBUG_FILE, _CONV("fail\n")); + LogDebugString(_CONV("fail\n"), false); } } else { - CCommonFnc::File_AppendString(APDUPLAY_DEBUG_FILE, _CONV("not found\n")); + LogDebugString(_CONV("not found\n"), false); } } @@ -3629,13 +3645,13 @@ int CWinscardApp::LoadRules() { iniparser_freedict(dict); } else { - CCommonFnc::File_AppendString(APDUPLAY_DEBUG_FILE, _CONV("Rules file NOT found\n")); - CCommonFnc::File_AppendString(WINSCARD_RULES_LOG, _CONV("Rules file NOT found\n")); + LogDebugString(_CONV("Rules file NOT found\n")); + LogWinscardRules(_CONV("Rules file NOT found\n")); } if (!m_winscardConfig.sLOG_BASE_PATH.empty()) { - CCommonFnc::File_AppendString(APDUPLAY_DEBUG_FILE, string_format(_CONV("Logging base path is forced as '%s' (LOG_BASE_PATH)\n"), m_winscardConfig.sLOG_BASE_PATH.c_str())); + LogDebugString(string_format(_CONV("Logging base path is forced as '%s' (LOG_BASE_PATH)\n"), m_winscardConfig.sLOG_BASE_PATH.c_str())); // Use provided directory to store output files WINSCARD_RULES_LOG = string_format(_CONV("%s\\%s"), m_winscardConfig.sLOG_BASE_PATH.c_str(), WINSCARD_RULES_LOG.c_str()); @@ -3644,7 +3660,7 @@ int CWinscardApp::LoadRules() { } else { - CCommonFnc::File_AppendString(APDUPLAY_DEBUG_FILE, string_format(_CONV("Logging base path not forced, using '%s'\n"), baseDir)); + LogDebugString(string_format(_CONV("Logging base path not forced, using '%s'\n"), baseDir)); // Use base directory to store output files WINSCARD_RULES_LOG = string_format(_CONV("%s%s"), baseDir, WINSCARD_RULES_LOG.c_str()); @@ -3659,7 +3675,7 @@ int CWinscardApp::LoadRules() { { theApp.m_winscardConfig.bLOG_WRITE_DESCRIPTION = TRUE; instruction_file.close(); - CCommonFnc::File_AppendString(WINSCARD_RULES_LOG, _CONV("Instruction file found")); + LogWinscardRules(_CONV("Instruction file found")); instructionDict = iniparser_load((const char*) INSTRUCTION_FILE.c_str()); } @@ -3716,9 +3732,6 @@ int CWinscardApp::LoadRule(string_type ruleName, string_type filePath) { if ((GetPrivateProfileString(ruleName.c_str(), _CONV("MODIFY_APDU_BY_RULES"), _CONV(""), buffer, cBuffer, filePath.c_str())) > 0) { m_winscardConfig.bMODIFY_APDU_BY_RULES = (type_to_int(buffer, NULL, 10) == 0) ? FALSE : TRUE; } - if ((GetPrivateProfileString(ruleName.c_str(), _CONV("LOG_FUNCTIONS_CALLS"), _CONV(""), buffer, cBuffer, filePath.c_str())) > 0) { - m_winscardConfig.bLOG_FUNCTIONS_CALLS = (type_to_int(buffer, NULL, 10) == 0) ? FALSE : TRUE; - } if ((GetPrivateProfileString(ruleName.c_str(), _CONV("READER_ORDERED_FIRST"), _CONV(""), buffer, cBuffer, filePath.c_str())) > 0) { m_winscardConfig.sREADER_ORDERED_FIRST = buffer; } @@ -3975,7 +3988,7 @@ int CWinscardApp::LoadRules() { string_type message; message = string_format(_CONV("Rules file found: %s\n"), filePath.c_str()); - CCommonFnc::File_AppendString(WINSCARD_RULES_LOG, message); + LogWinscardRules(message); // OBTAIN SECTION NAMES if ((cReaded = GetPrivateProfileString(NULL, NULL, _CONV(""), buffer, cBuffer, rulesFilePath)) != 0) { @@ -3990,7 +4003,7 @@ int CWinscardApp::LoadRules() { m_bRulesActive = TRUE; } else { - CCommonFnc::File_AppendString(WINSCARD_RULES_LOG, _CONV("Rules file NOT found\n")); + LogWinscardRules(_CONV("Rules file NOT found\n")); } if (!m_winscardConfig.sLOG_BASE_PATH.empty()) @@ -4011,7 +4024,7 @@ int CWinscardApp::LoadRules() { { theApp.m_winscardConfig.bLOG_WRITE_DESCRIPTION = TRUE; instruction_file.close(); - CCommonFnc::File_AppendString(WINSCARD_RULES_LOG, _CONV("Instruction file found")); + LogWinscardRules(_CONV("Instruction file found")); instructionDict = iniparser_load((const char*)INSTRUCTION_FILE.c_str()); } diff --git a/Winscard/stdafx.h b/Winscard/stdafx.h index 2284378..4052ab8 100644 --- a/Winscard/stdafx.h +++ b/Winscard/stdafx.h @@ -213,7 +213,6 @@ typedef struct _WINSCARD_CONFIG { BOOL bFORCE_APDU_NONZERO_INPUT_DATA = FALSE; BOOL bLOG_EXCHANGED_APDU = FALSE; BOOL bMODIFY_APDU_BY_RULES = FALSE; - BOOL bLOG_FUNCTIONS_CALLS = FALSE; BOOL bLOG_WRITE_DESCRIPTION = FALSE; string_type sREADER_ORDERED_FIRST; string_type sLOG_BASE_PATH; @@ -232,7 +231,6 @@ typedef struct _WINSCARD_CONFIG { bFORCE_APDU_NONZERO_INPUT_DATA = FALSE; // DEFAULT: FALSE, SET TO TRUE IF APPLET HAVE PROBLEM TO RETURN DATA (apdu.setOutgoingAndSend()) WHEN NO PREVIOUS setIncomingAndReceive() WAS CALLED. bLOG_EXCHANGED_APDU = TRUE; // DEFAULT: FALSE, SET TO TRUE IF LOGGING OF APDU DATA IS REQUIRED bMODIFY_APDU_BY_RULES = TRUE; // DEFAULT: FALSE, SET TO TRUE . - bLOG_FUNCTIONS_CALLS = TRUE; // DEFAULT: FALSE, SET TO TRUE . sREADER_ORDERED_FIRST = _CONV(""); sLOG_BASE_PATH = _CONV(""); #else @@ -242,7 +240,6 @@ typedef struct _WINSCARD_CONFIG { bFORCE_APDU_NONZERO_INPUT_DATA = FALSE; // DEFAULT: FALSE, SET TO TRUE IF APPLET HAVE PROBLEM TO RETURN DATA (apdu.setOutgoingAndSend()) WHEN NO PREVIOUS setIncomingAndReceive() WAS CALLED. bLOG_EXCHANGED_APDU = FALSE; // DEFAULT: FALSE, SET TO TRUE IF LOGGING OF APDU DATA IS REQUIRED bMODIFY_APDU_BY_RULES = FALSE; // DEFAULT: FALSE, SET TO TRUE . - bLOG_FUNCTIONS_CALLS = FALSE; // DEFAULT: FALSE, SET TO TRUE . sREADER_ORDERED_FIRST = ""; sLOG_BASE_PATH = ""; #endif From c117619086ec3f4e5019f523843db5ebd747feea Mon Sep 17 00:00:00 2001 From: petrs Date: Tue, 10 Jul 2018 22:21:45 +0200 Subject: [PATCH 07/11] change of \r\n to \n --- Winscard/CommonFnc.cpp | 3 +-- Winscard/Winscard.rc | 24 ++++++++++++------------ 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/Winscard/CommonFnc.cpp b/Winscard/CommonFnc.cpp index 4a4ff35..0489001 100644 --- a/Winscard/CommonFnc.cpp +++ b/Winscard/CommonFnc.cpp @@ -224,8 +224,7 @@ int CCommonFnc::File_SaveMatrixInt(string_type filePath, INT_DATA_BLOB* pBlob, s } else { for (i = startOffset; i < endOffset; i++) { - //value.Format("%d\r\n", pBlob->pData[i]); - value = string_format(_CONV("%d\r\n"), pBlob->pData[i]); + value = string_format(_CONV("%d\n"), pBlob->pData[i]); values += value; if ((i % NUM_VALUES_PER_WRITE) == 0) { diff --git a/Winscard/Winscard.rc b/Winscard/Winscard.rc index e8bc4fc..ea83711 100644 --- a/Winscard/Winscard.rc +++ b/Winscard/Winscard.rc @@ -25,25 +25,25 @@ END 2 TEXTINCLUDE BEGIN - "#include ""afxres.h""\r\n" + "#include ""afxres.h""\n" "\0" END 3 TEXTINCLUDE BEGIN - "#define _AFX_NO_SPLITTER_RESOURCES\r\n" - "#define _AFX_NO_OLE_RESOURCES\r\n" - "#define _AFX_NO_TRACKER_RESOURCES\r\n" - "#define _AFX_NO_PROPERTY_RESOURCES\r\n" - "\r\n" - "#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_CSY)\r\n" - "LANGUAGE 5, 1\r\n" - "#pragma code_page(1250)\r\n" - "#include ""res\\Winscard.rc2"" // non-Microsoft Visual C++ edited resources\r\n" + "#define _AFX_NO_SPLITTER_RESOURCES\n" + "#define _AFX_NO_OLE_RESOURCES\n" + "#define _AFX_NO_TRACKER_RESOURCES\n" + "#define _AFX_NO_PROPERTY_RESOURCES\n" + "\n" + "#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_CSY)\n" + "LANGUAGE 5, 1\n" + "#pragma code_page(1250)\n" + "#include ""res\\Winscard.rc2"" // non-Microsoft Visual C++ edited resources\n" #ifndef _AFXDLL - "#include ""afxres.rc"" // Standard components\r\n" + "#include ""afxres.rc"" // Standard components\n" #endif - "#endif\r\n" + "#endif\n" "\0" END From 14ccab00bdbfaa4929a1b5e223cddcb3b78f0cb0 Mon Sep 17 00:00:00 2001 From: petrs Date: Tue, 10 Jul 2018 22:22:07 +0200 Subject: [PATCH 08/11] minor fixed --- Winscard/ReadMe.txt | 2 +- WinscardTests/winscard_rules.txt | 15 --------------- 2 files changed, 1 insertion(+), 16 deletions(-) delete mode 100644 WinscardTests/winscard_rules.txt diff --git a/Winscard/ReadMe.txt b/Winscard/ReadMe.txt index 18ac1fb..e4c2211 100644 --- a/Winscard/ReadMe.txt +++ b/Winscard/ReadMe.txt @@ -34,7 +34,7 @@ res\Winscard.rc2 Visual C++. You should place all resources not editable by the resource editor in this file. -Winscard.def +Winscard32.def or Winscard64.def This file contains information about the DLL that must be provided to run with Microsoft Windows. It defines parameters such as the name and description of the DLL. It also exports diff --git a/WinscardTests/winscard_rules.txt b/WinscardTests/winscard_rules.txt deleted file mode 100644 index 33a387e..0000000 --- a/WinscardTests/winscard_rules.txt +++ /dev/null @@ -1,15 +0,0 @@ -[WINSCARD] -LOG_EXCHANGED_APDU = 1 -MODIFY_APDU_BY_RULES = 1 -LOG_FUNCTIONS_CALLS = 1 -AUTO_REQUEST_DATA = 1 -LOG_BASE_PATH = ./ -[RULE1] -MATCH1=in=1,cla=80,ins=ca,p1=9f,p2=17,data0=90 00, -ACTION=in=1,cla=80,ins=cb,p1=9f,p2=17,data0=97 00, -USAGE = 1 -APDUIN = 1 -[REMOTE] -REDIRECT = 1 -IP = 127.0.0.1 -PORT = 4001 From 82c1670173281823dd2448283cea48312c0f8031 Mon Sep 17 00:00:00 2001 From: petrs Date: Tue, 10 Jul 2018 22:50:33 +0200 Subject: [PATCH 09/11] improved logging (stderr-> debug file) --- Winscard/Winscard.cpp | 145 ++++++++++++++++++++++-------------------- 1 file changed, 75 insertions(+), 70 deletions(-) diff --git a/Winscard/Winscard.cpp b/Winscard/Winscard.cpp index 6997532..a94245a 100644 --- a/Winscard/Winscard.cpp +++ b/Winscard/Winscard.cpp @@ -1944,7 +1944,7 @@ int initialize() #if __linux__ error = dlerror(); #endif - fprintf(stderr, "Failed to load original library%s%s\n", delimeter, error); + LogDebugString(string_format(_CONV("Failed to load original library%s%s\n"), delimeter, error)); return FALSE; } @@ -1971,7 +1971,7 @@ int initialize() #if __linux__ error = dlerror(); #endif - fprintf(stderr, "Could not find SCardTransmit procedure address%s%s\n", delimeter, error); + LogDebugString(string_format(_CONV("Could not find SCardTransmit procedure address%s%s\n"), delimeter, error)); return FALSE; } @@ -1982,7 +1982,7 @@ int initialize() #if __linux__ error = dlerror(); #endif - fprintf(stderr, "Could not find SCardDisconnect procedure address%s%s\n", delimeter, error); + LogDebugString(string_format(_CONV("Could not find SCardDisconnect procedure address%s%s\n"), delimeter, error)); return FALSE; } @@ -1993,7 +1993,7 @@ int initialize() #if __linux__ error = dlerror(); #endif - fprintf(stderr, "Could not find SCardFreeMemory procedure address%s%s\n", delimeter, error); + LogDebugString(string_format(_CONV("Could not find SCardFreeMemory procedure address%s%s\n"), delimeter, error)); return FALSE; } @@ -2007,7 +2007,7 @@ int initialize() #if __linux__ error = dlerror(); #endif - fprintf(stderr, "Could not find SCardEstablishContext procedure address%s%s\n", delimeter, error); + LogDebugString(string_format(_CONV("Could not find SCardEstablishContext procedure address%s%s\n"), delimeter, error)); return FALSE; } @@ -2019,7 +2019,7 @@ int initialize() #if __linux__ error = dlerror(); #endif - fprintf(stderr, "Could not find SCardReleaseContext procedure address%s%s\n", delimeter, error); + LogDebugString(string_format(_CONV("Could not find SCardReleaseContext procedure address%s%s\n"), delimeter, error)); return FALSE; } @@ -2031,7 +2031,7 @@ int initialize() #if __linux__ error = dlerror(); #endif - fprintf(stderr, "Could not find SCardIsValidContext procedure address%s%s\n", delimeter, error); + LogDebugString(string_format(_CONV("Could not find SCardIsValidContext procedure address%s%s\n"), delimeter, error)); return FALSE; } @@ -2044,7 +2044,7 @@ int initialize() #if __linux__ error = dlerror(); #endif - fprintf(stderr, "Could not find SCardFreeMemory procedure address%s%s\n", delimeter, error); + LogDebugString(string_format(_CONV("Could not find SCardFreeMemory procedure address%s%s\n"), delimeter, error)); return FALSE; } @@ -2056,7 +2056,7 @@ int initialize() #if __linux__ error = dlerror(); #endif - fprintf(stderr, "Could not find SCardCancel procedure address%s%s\n", delimeter, error); + LogDebugString(string_format(_CONV("Could not find SCardCancel procedure address%s%s\n"), delimeter, error)); return FALSE; } @@ -2072,7 +2072,7 @@ int initialize() #if __linux__ error = dlerror(); #endif - fprintf(stderr, "Could not find SCardReconnect procedure address%s%s\n", delimeter, error); + LogDebugString(string_format(_CONV("Could not find SCardReconnect procedure address%s%s\n"), delimeter, error)); return FALSE; } @@ -2085,7 +2085,7 @@ int initialize() #if __linux__ error = dlerror(); #endif - fprintf(stderr, "Could not find SCardDisconnect procedure address%s%s\n", delimeter, error); + LogDebugString(string_format(_CONV("Could not find SCardDisconnect procedure address%s%s\n"), delimeter, error)); return FALSE; } @@ -2097,7 +2097,7 @@ int initialize() #if __linux__ error = dlerror(); #endif - fprintf(stderr, "Could not find SCardBeginTransaction procedure address%s%s\n", delimeter, error); + LogDebugString(string_format(_CONV("Could not find SCardBeginTransaction procedure address%s%s\n"), delimeter, error)); return FALSE; } @@ -2110,7 +2110,7 @@ int initialize() #if __linux__ error = dlerror(); #endif - fprintf(stderr, "Could not find SCardEndTransaction procedure address%s%s\n", delimeter, error); + LogDebugString(string_format(_CONV("Could not find SCardEndTransaction procedure address%s%s\n"), delimeter, error)); return FALSE; } @@ -2128,7 +2128,7 @@ int initialize() #if __linux__ error = dlerror(); #endif - fprintf(stderr, "Could not find SCardTransmit procedure address%s%s\n", delimeter, error); + LogDebugString(string_format(_CONV("Could not find SCardTransmit procedure address%s%s\n"), delimeter, error)); return FALSE; } @@ -2146,7 +2146,7 @@ int initialize() #if __linux__ error = dlerror(); #endif - fprintf(stderr, "Could not find SCardControl procedure address%s%s\n", delimeter, error); + LogDebugString(string_format(_CONV("Could not find SCardControl procedure address%s%s\n"), delimeter, error)); return FALSE; } @@ -2161,7 +2161,7 @@ int initialize() #if __linux__ error = dlerror(); #endif - fprintf(stderr, "Could not find SCardGetAttrib procedure address%s%s\n", delimeter, error); + LogDebugString(string_format(_CONV("Could not find SCardGetAttrib procedure address%s%s\n"), delimeter, error)); return FALSE; } @@ -2176,7 +2176,7 @@ int initialize() #if __linux__ error = dlerror(); #endif - fprintf(stderr, "Could not find SCardSetAttrib procedure address%s%s\n", delimeter, error); + LogDebugString(_CONV("Could not find SCardSetAttrib procedure address%s%s\n")); return FALSE; } @@ -2186,7 +2186,7 @@ int initialize() (long(STDCALL *)(SCARDHANDLE hCard, LPSTR szReaderName, LPDWORD pcchReaderLen, LPDWORD pdwState, LPDWORD pdwProtocol, LPBYTE pbAtr, LPDWORD pcbAtrLen)) load_func(hOriginal, "SCardStatusA"); if ((!Original_SCardStatus)) { - fprintf(stderr, "Could not find SCardStatusA procedure address\n"); + LogDebugString(_CONV("Could not find SCardStatusA procedure address\n")); return FALSE; } @@ -2194,7 +2194,7 @@ int initialize() (long(STDCALL *)(SCARDCONTEXT hContext, LPCWSTR szReader, DWORD dwShareMode, DWORD dwPreferredProtocols, LPSCARDHANDLE phCard, LPDWORD pdwActiveProtocol)) load_func(hOriginal, "SCardConnectW"); if ((!Original_SCardConnectW)) { - fprintf(stderr, "Could not find SCardConnectW procedure address\n"); + LogDebugString(_CONV("Could not find SCardConnectW procedure address\n")); return FALSE; } @@ -2202,7 +2202,7 @@ int initialize() (long(STDCALL *)(SCARDCONTEXT hContext, LPCWSTR mszGroups, LPWSTR mszReaders, LPDWORD pcchReaders)) load_func(hOriginal, "SCardListReadersW"); if ((!Original_SCardListReadersW)) { - fprintf(stderr, "Could not find SCardListReadersW procedure address\n"); + LogDebugString(_CONV("Could not find SCardListReadersW procedure address\n")); return FALSE; } @@ -2210,7 +2210,7 @@ int initialize() (long(STDCALL *)(SCARDCONTEXT hContext, LPCSTR mszGroups, LPSTR mszReaders, LPDWORD pcchReaders)) load_func(hOriginal, "SCardListReadersA"); if ((!Original_SCardListReaders)) { - fprintf(stderr, "Could not find SCardListReadersA procedure address\n"); + LogDebugString(_CONV("Could not find SCardListReadersA procedure address\n")); return FALSE; } @@ -2221,7 +2221,7 @@ int initialize() IN OUT LPDWORD pcchGroups)) load_func(hOriginal, "SCardListReaderGroupsA"); if (!Original_SCardListReaderGroups) { - fprintf(stderr, "Could not find SCardListReaderGroupsA procedure address\n"); + LogDebugString(_CONV("Could not find SCardListReaderGroupsA procedure address\n")); return FALSE; } @@ -2232,7 +2232,7 @@ int initialize() IN OUT LPDWORD pcchGroups)) load_func(hOriginal, "SCardListReaderGroupsW"); if (!Original_SCardListReaderGroupsW) { - fprintf(stderr, "Could not find SCardListReaderGroupsW procedure address\n"); + LogDebugString(_CONV("Could not find SCardListReaderGroupsW procedure address\n")); return FALSE; } @@ -2244,7 +2244,7 @@ int initialize() IN OUT LPDWORD pcchReaders)) load_func(hOriginal, "SCardListReadersA"); if (!Original_SCardListReaders) { - fprintf(stderr, "Could not find SCardListReadersA procedure address\n"); + LogDebugString(_CONV("Could not find SCardListReadersA procedure address\n")); return FALSE; } @@ -2256,7 +2256,7 @@ int initialize() IN OUT LPDWORD pcchReaders)) load_func(hOriginal, "SCardListReadersW"); if (!Original_SCardListReadersW) { - fprintf(stderr, "Could not find SCardListReadersW procedure address\n"); + LogDebugString(_CONV("Could not find SCardListReadersW procedure address\n")); return FALSE; } @@ -2270,7 +2270,7 @@ int initialize() IN OUT LPDWORD pcchCards)) load_func(hOriginal, "SCardListCardsA"); if (!Original_SCardListCardsA) { - fprintf(stderr, "Could not find SCardListCardsA procedure address\n"); + LogDebugString(_CONV("Could not find SCardListCardsA procedure address\n")); return FALSE; } @@ -2284,7 +2284,7 @@ int initialize() IN OUT LPDWORD pcchCards)) load_func(hOriginal, "SCardListCardsW"); if (!Original_SCardListCardsW) { - fprintf(stderr, "Could not find SCardListCardsW procedure address\n"); + LogDebugString(_CONV("Could not find SCardListCardsW procedure address\n")); return FALSE; } @@ -2296,7 +2296,7 @@ int initialize() IN OUT LPDWORD pcguidInterfaces)) load_func(hOriginal, "SCardListInterfacesA"); if (!Original_SCardListInterfacesA) { - fprintf(stderr, "Could not find SCardListInterfacesA procedure address\n"); + LogDebugString(_CONV("Could not find SCardListInterfacesA procedure address\n")); return FALSE; } @@ -2308,7 +2308,7 @@ int initialize() IN OUT LPDWORD pcguidInterfaces)) load_func(hOriginal, "SCardListInterfacesW"); if (!Original_SCardListInterfacesW) { - fprintf(stderr, "Could not find SCardListInterfacesW procedure address\n"); + LogDebugString(_CONV("Could not find SCardListInterfacesW procedure address\n")); return FALSE; } @@ -2319,7 +2319,7 @@ int initialize() OUT LPGUID pguidProviderId)) load_func(hOriginal, "SCardGetProviderIdA"); if (!Original_SCardGetProviderIdA) { - fprintf(stderr, "Could not find SCardGetProviderIdA procedure address\n"); + LogDebugString(_CONV("Could not find SCardGetProviderIdA procedure address\n")); return FALSE; } @@ -2330,7 +2330,7 @@ int initialize() OUT LPGUID pguidProviderId)) load_func(hOriginal, "SCardGetProviderIdW"); if (!Original_SCardGetProviderIdW) { - fprintf(stderr, "Could not find SCardGetProviderIdW procedure address\n"); + LogDebugString(_CONV("Could not find SCardGetProviderIdW procedure address\n")); return FALSE; } @@ -2343,7 +2343,7 @@ int initialize() IN OUT LPDWORD pcchProvider)) load_func(hOriginal, "SCardGetCardTypeProviderNameA"); if (!Original_SCardGetCardTypeProviderNameA) { - fprintf(stderr, "Could not find SCardGetCardTypeProviderNameA procedure address\n"); + LogDebugString(_CONV("Could not find SCardGetCardTypeProviderNameA procedure address\n")); return FALSE; } @@ -2356,7 +2356,7 @@ int initialize() IN OUT LPDWORD pcchProvider)) load_func(hOriginal, "SCardGetCardTypeProviderNameW"); if (!Original_SCardGetCardTypeProviderNameW) { - fprintf(stderr, "Could not find SCardGetCardTypeProviderNameW procedure address\n"); + LogDebugString(_CONV("Could not find SCardGetCardTypeProviderNameW procedure address\n")); return FALSE; } @@ -2366,7 +2366,7 @@ int initialize() IN LPCSTR szGroupName)) load_func(hOriginal, "SCardIntroduceReaderGroupA"); if (!Original_SCardIntroduceReaderGroupA) { - fprintf(stderr, "Could not find SCardIntroduceReaderGroupA procedure address\n"); + LogDebugString(_CONV("Could not find SCardIntroduceReaderGroupA procedure address\n")); return FALSE; } @@ -2376,7 +2376,7 @@ int initialize() IN LPCWSTR szGroupName)) load_func(hOriginal, "SCardIntroduceReaderGroupW"); if (!Original_SCardIntroduceReaderGroupW) { - fprintf(stderr, "Could not find SCardIntroduceReaderGroupW procedure address\n"); + LogDebugString(_CONV("Could not find SCardIntroduceReaderGroupW procedure address\n")); return FALSE; } @@ -2386,7 +2386,7 @@ int initialize() IN LPCSTR szGroupName)) load_func(hOriginal, "SCardForgetReaderGroupA"); if (!Original_SCardForgetReaderGroupA) { - fprintf(stderr, "Could not find SCardForgetReaderGroupA procedure address\n"); + LogDebugString(_CONV("Could not find SCardForgetReaderGroupA procedure address\n")); return FALSE; } @@ -2396,7 +2396,7 @@ int initialize() IN LPCWSTR szGroupName)) load_func(hOriginal, "SCardForgetReaderGroupW"); if (!Original_SCardForgetReaderGroupW) { - fprintf(stderr, "Could not find SCardForgetReaderGroupW procedure address\n"); + LogDebugString(_CONV("Could not find SCardForgetReaderGroupW procedure address\n")); return FALSE; } @@ -2407,7 +2407,7 @@ int initialize() IN LPCSTR szDeviceName)) load_func(hOriginal, "SCardIntroduceReaderA"); if (!Original_SCardIntroduceReaderA) { - fprintf(stderr, "Could not find SCardIntroduceReaderA procedure address\n"); + LogDebugString(_CONV("Could not find SCardIntroduceReaderA procedure address\n")); return FALSE; } @@ -2418,7 +2418,7 @@ int initialize() IN LPCWSTR szDeviceName)) load_func(hOriginal, "SCardIntroduceReaderW"); if (!Original_SCardIntroduceReaderW) { - fprintf(stderr, "Could not find SCardIntroduceReaderW procedure address\n"); + LogDebugString(_CONV("Could not find SCardIntroduceReaderW procedure address\n")); return FALSE; } @@ -2428,7 +2428,7 @@ int initialize() IN LPCSTR szReaderName)) load_func(hOriginal, "SCardForgetReaderA"); if (!Original_SCardForgetReaderA) { - fprintf(stderr, "Could not find SCardForgetReaderA procedure address\n"); + LogDebugString(_CONV("Could not find SCardForgetReaderA procedure address\n")); return FALSE; } @@ -2438,7 +2438,7 @@ int initialize() IN LPCWSTR szReaderName)) load_func(hOriginal, "SCardForgetReaderW"); if (!Original_SCardForgetReaderW) { - fprintf(stderr, "Could not find SCardForgetReaderW procedure address\n"); + LogDebugString(_CONV("Could not find SCardForgetReaderW procedure address\n")); return FALSE; } @@ -2449,7 +2449,7 @@ int initialize() IN LPCSTR szGroupName)) load_func(hOriginal, "SCardAddReaderToGroupA"); if (!Original_SCardAddReaderToGroupA) { - fprintf(stderr, "Could not find SCardAddReaderToGroupA procedure address\n"); + LogDebugString(_CONV("Could not find SCardAddReaderToGroupA procedure address\n")); return FALSE; } @@ -2460,7 +2460,7 @@ int initialize() IN LPCWSTR szGroupName)) load_func(hOriginal, "SCardAddReaderToGroupW"); if (!Original_SCardAddReaderToGroupW) { - fprintf(stderr, "Could not find SCardAddReaderToGroupW procedure address\n"); + LogDebugString(_CONV("Could not find SCardAddReaderToGroupW procedure address\n")); return FALSE; } @@ -2471,7 +2471,7 @@ int initialize() IN LPCSTR szGroupName)) load_func(hOriginal, "SCardRemoveReaderFromGroupA"); if (!Original_SCardRemoveReaderFromGroupA) { - fprintf(stderr, "Could not find SCardRemoveReaderFromGroupA procedure address\n"); + LogDebugString(_CONV("Could not find SCardRemoveReaderFromGroupA procedure address\n")); return FALSE; } @@ -2482,7 +2482,7 @@ int initialize() IN LPCWSTR szGroupName)) load_func(hOriginal, "SCardRemoveReaderFromGroupW"); if (!Original_SCardRemoveReaderFromGroupW) { - fprintf(stderr, "Could not find SCardRemoveReaderFromGroupW procedure address\n"); + LogDebugString(_CONV("Could not find SCardRemoveReaderFromGroupW procedure address\n")); return FALSE; } @@ -2498,7 +2498,7 @@ int initialize() IN DWORD cbAtrLen)) load_func(hOriginal, "SCardIntroduceCardTypeA"); if (!Original_SCardIntroduceCardTypeA) { - fprintf(stderr, "Could not find SCardIntroduceCardTypeA procedure address\n"); + LogDebugString(_CONV("Could not find SCardIntroduceCardTypeA procedure address\n")); return FALSE; } @@ -2514,7 +2514,7 @@ int initialize() IN DWORD cbAtrLen)) load_func(hOriginal, "SCardIntroduceCardTypeW"); if (!Original_SCardIntroduceCardTypeW) { - fprintf(stderr, "Could not find SCardIntroduceCardTypeW procedure address\n"); + LogDebugString(_CONV("Could not find SCardIntroduceCardTypeW procedure address\n")); return FALSE; } @@ -2526,7 +2526,7 @@ int initialize() IN LPCSTR szProvider)) load_func(hOriginal, "SCardSetCardTypeProviderNameA"); if (!Original_SCardSetCardTypeProviderNameA) { - fprintf(stderr, "Could not find SCardSetCardTypeProviderNameA procedure address\n"); + LogDebugString(_CONV("Could not find SCardSetCardTypeProviderNameA procedure address\n")); return FALSE; } @@ -2538,7 +2538,7 @@ int initialize() IN LPCWSTR szProvider)) load_func(hOriginal, "SCardSetCardTypeProviderNameW"); if (!Original_SCardSetCardTypeProviderNameW) { - fprintf(stderr, "Could not find SCardSetCardTypeProviderNameW procedure address\n"); + LogDebugString(_CONV("Could not find SCardSetCardTypeProviderNameW procedure address\n")); return FALSE; } @@ -2548,7 +2548,7 @@ int initialize() IN LPCSTR szCardName)) load_func(hOriginal, "SCardForgetCardTypeA"); if (!Original_SCardForgetCardTypeA) { - fprintf(stderr, "Could not find SCardForgetCardTypeA procedure address\n"); + LogDebugString(_CONV("Could not find SCardForgetCardTypeA procedure address\n")); return FALSE; } @@ -2558,7 +2558,7 @@ int initialize() IN LPCWSTR szCardName)) load_func(hOriginal, "SCardForgetCardTypeW"); if (!Original_SCardForgetCardTypeW) { - fprintf(stderr, "Could not find SCardForgetCardTypeW procedure address\n"); + LogDebugString(_CONV("Could not find SCardForgetCardTypeW procedure address\n")); return FALSE; } @@ -2566,7 +2566,7 @@ int initialize() (HANDLE(STDCALL *)(void)) load_func(hOriginal, "SCardAccessStartedEvent"); if (!Original_SCardAccessStartedEvent) { - fprintf(stderr, "Could not find SCardAccessStartedEvent procedure address\n"); + LogDebugString(_CONV("Could not find SCardAccessStartedEvent procedure address\n")); return FALSE; } @@ -2574,7 +2574,7 @@ int initialize() (void(STDCALL *)(void)) load_func(hOriginal, "SCardReleaseStartedEvent"); if (!Original_SCardReleaseStartedEvent) { - fprintf(stderr, "Could not find SCardReleaseStartedEvent procedure address\n"); + LogDebugString(_CONV("Could not find SCardReleaseStartedEvent procedure address\n")); return FALSE; } @@ -2586,7 +2586,7 @@ int initialize() IN DWORD cReaders)) load_func(hOriginal, "SCardLocateCardsA"); if (!Original_SCardLocateCardsA) { - fprintf(stderr, "Could not find SCardLocateCardsA procedure address\n"); + LogDebugString(_CONV("Could not find SCardLocateCardsA procedure address\n")); return FALSE; } @@ -2598,7 +2598,7 @@ int initialize() IN DWORD cReaders)) load_func(hOriginal, "SCardLocateCardsW"); if (!Original_SCardLocateCardsW) { - fprintf(stderr, "Could not find SCardLocateCardsW procedure address\n"); + LogDebugString(_CONV("Could not find SCardLocateCardsW procedure address\n")); return FALSE; } @@ -2611,7 +2611,7 @@ int initialize() IN DWORD cReaders)) load_func(hOriginal, "SCardLocateCardsByATRA"); if (!Original_SCardLocateCardsByATRA) { - fprintf(stderr, "Could not find SCardLocateCardsByATRA procedure address\n"); + LogDebugString(_CONV("Could not find SCardLocateCardsByATRA procedure address\n")); return FALSE; } @@ -2624,7 +2624,7 @@ int initialize() IN DWORD cReaders)) load_func(hOriginal, "SCardLocateCardsByATRW"); if (!Original_SCardLocateCardsByATRW) { - fprintf(stderr, "Could not find SCardLocateCardsByATRW procedure address\n"); + LogDebugString(_CONV("Could not find SCardLocateCardsByATRW procedure address\n")); return FALSE; } @@ -2636,7 +2636,7 @@ int initialize() IN DWORD cReaders)) load_func(hOriginal, "SCardGetStatusChangeA"); if (!Original_SCardGetStatusChangeA) { - fprintf(stderr, "Could not find SCardGetStatusChangeA procedure address\n"); + LogDebugString(_CONV("Could not find SCardGetStatusChangeA procedure address\n")); return FALSE; } @@ -2648,7 +2648,7 @@ int initialize() IN DWORD cReaders)) load_func(hOriginal, "SCardGetStatusChangeW"); if (!Original_SCardGetStatusChangeW) { - fprintf(stderr, "Could not find SCardGetStatusChangeW procedure address\n"); + LogDebugString(_CONV("Could not find SCardGetStatusChangeW procedure address\n")); return FALSE; } @@ -2662,7 +2662,7 @@ int initialize() OUT LPDWORD pdwActiveProtocol)) load_func(hOriginal, "SCardConnectA"); if (!Original_SCardConnect) { - fprintf(stderr, "Could not find SCardConnectA procedure address\n"); + LogDebugString(_CONV("Could not find SCardConnectA procedure address\n")); return FALSE; } @@ -2676,7 +2676,7 @@ int initialize() OUT LPDWORD pdwActiveProtocol)) load_func(hOriginal, "SCardConnectW"); if (!Original_SCardConnectW) { - fprintf(stderr, "Could not find SCardConnectW procedure address\n"); + LogDebugString(_CONV("Could not find SCardConnectW procedure address\n")); return FALSE; } @@ -2685,7 +2685,7 @@ int initialize() IN SCARDHANDLE hCard)) load_func(hOriginal, "SCardCancelTransaction"); if (!Original_SCardCancelTransaction) { - LogWinscardRules(_CONV("Could not find SCardCancelTransaction procedure address\n")); + LogDebugString(_CONV("Could not find SCardCancelTransaction procedure address\n")); } Original_SCardState = @@ -2697,7 +2697,7 @@ int initialize() IN OUT LPDWORD pcbAtrLen)) load_func(hOriginal, "SCardState"); if (!Original_SCardState) { - fprintf(stderr, "Could not find SCardState procedure address\n"); + LogDebugString(_CONV("Could not find SCardState procedure address\n")); return FALSE; } @@ -2712,7 +2712,7 @@ int initialize() IN OUT LPDWORD pcbAtrLen)) load_func(hOriginal, "SCardStatusA"); if (!Original_SCardStatus) { - fprintf(stderr, "Could not find SCardStatusA procedure address\n"); + LogDebugString(_CONV("Could not find SCardStatusA procedure address\n")); return FALSE; } @@ -2727,7 +2727,7 @@ int initialize() IN OUT LPDWORD pcbAtrLen)) load_func(hOriginal, "SCardStatusW"); if (!Original_SCardStatusW) { - fprintf(stderr, "Could not find SCardStatusW procedure address\n"); + LogDebugString(_CONV("Could not find SCardStatusW procedure address\n")); return FALSE; } @@ -2736,7 +2736,7 @@ int initialize() LPOPENCARDNAMEA_EX)) load_func(hOriginal, "SCardUIDlgSelectCardA"); if (!Original_SCardUIDlgSelectCardA) { - LogWinscardRules(_CONV("Could not find SCardUIDlgSelectCardA procedure address\n")); + LogDebugString(_CONV("Could not find SCardUIDlgSelectCardA procedure address\n")); } Original_SCardUIDlgSelectCardW = @@ -2784,7 +2784,7 @@ int initialize() load_func(hOriginal, "SCardConnect"); if (!Original_SCardConnect) { error = dlerror(); - fprintf(stderr, "Could not find SCardConnect procedure address: %s\n", error); + LogDebugString(_CONV("Could not find SCardConnect procedure address: %s\n", error); return FALSE; } @@ -2793,7 +2793,7 @@ int initialize() load_func(hOriginal, "SCardStatus"); if ((!Original_SCardStatus)) { error = dlerror(); - fprintf(stderr, "Could not find SCardStatus procedure address: %s\n", error); + LogDebugString(_CONV("Could not find SCardStatus procedure address: %s\n", error); return FALSE; } @@ -2905,11 +2905,15 @@ BOOL CWinscardApp::InitInstance() #ifdef _WIN64 LogDebugString(string_format(_CONV("APDUPlay winscard.dll v%s, (64-bit version)\n"), LIBRARY_VERSION.c_str())); #endif + TCHAR szPath[MAX_PATH]; + memset(szPath, 0, sizeof(szPath) * sizeof(TCHAR)); + if (GetModuleFileName(NULL, szPath, MAX_PATH)) { + LogDebugString(string_format(_CONV("Target application: '%s'\n"), szPath)); + } // LOAD MODIFICATION RULES LoadRules(); - LogDebugString(_CONV("After LoadRules\n")); // CONNECT TO REMOTE SOCKET IF REQUIRED if (m_remoteConfig.bRedirect) { @@ -3645,7 +3649,6 @@ int CWinscardApp::LoadRules() { iniparser_freedict(dict); } else { - LogDebugString(_CONV("Rules file NOT found\n")); LogWinscardRules(_CONV("Rules file NOT found\n")); } @@ -3679,6 +3682,8 @@ int CWinscardApp::LoadRules() { instructionDict = iniparser_load((const char*) INSTRUCTION_FILE.c_str()); } + LogDebugString(string_format(_CONV("Finalizing LoadRules with status %s\n"), status)); + return status; } #endif From 6ba1d7472ff877f3d3cb40ff0a1a3bae7c9e1887 Mon Sep 17 00:00:00 2001 From: petrs Date: Tue, 10 Jul 2018 23:16:03 +0200 Subject: [PATCH 10/11] added REMOTE_READER_PREFIX configuration If REMOTE_READER_PREFIX is specified in winscard_rules.txt file, reader that shoudl be forwarded to remote are searched using this string --- Winscard/Winscard.cpp | 51 +++++++++++++++++++++++++------------------ Winscard/stdafx.h | 4 ++++ 2 files changed, 34 insertions(+), 21 deletions(-) diff --git a/Winscard/Winscard.cpp b/Winscard/Winscard.cpp index a94245a..5bf4cf8 100644 --- a/Winscard/Winscard.cpp +++ b/Winscard/Winscard.cpp @@ -102,10 +102,6 @@ BYTE GET_APDU2[] = { 0xC0, 0xC0, 0x00, 0x00 }; #define VIRT_READER_NAME "Simona /111.222.123.033@07" #define VIRTUAL_READERS_LEN strlen(VIRT_READER_NAME) -#define REMOTE_READER_PREFIX "Simona" -//#define REMOTE_READER_PREFIX "Generic EMV Smartcard" - - #define CMD_APDU "APDU" #define CMD_RESET "RESET" #define CMD_ENUM "ENUM" @@ -782,7 +778,7 @@ SCard LONG STDCALL SCardConnect( // Detect remote cards (now only via reader prefix) and assign virtual card handle string_type readerName = szReader; - if (readerName.find(REMOTE_READER_PREFIX) != -1) { + if (readerName.find(theApp.m_remoteConfig.remoteReaderPrefix) != -1) { theApp.m_nextRemoteCardID++; *phCard = theApp.m_nextRemoteCardID; theApp.remoteReadersMap[*phCard] = szReader; @@ -821,7 +817,7 @@ SCard LONG STDCALL SCardStatus( LPBYTE pbAtr, LPDWORD pcbAtrLen) { - LogWinscardRules(string_format(_CONV("SCardStatus(hCard:0x%x,szReaderName:%s,pcchReaderLen:%d,pcbAtrLen:%d) called\n"), hCard, szReaderName, *pcchReaderLen, *pcbAtrLen)); + LogWinscardRules(string_format(_CONV("SCardStatus(hCard:0x%x,pcchReaderLen:%d,pcbAtrLen:%d) called\n"), hCard, *pcchReaderLen, *pcbAtrLen)); if (theApp.IsRemoteCard(hCard)) { // According to https://docs.microsoft.com/en-us/windows/desktop/api/winscard/nf-winscard-scardstatusa @@ -2933,17 +2929,23 @@ int CWinscardApp::Remote_Connect(REMOTE_CONFIG* pRemoteConfig) { string_type sIP(pRemoteConfig->IP); try { - message = string_format(_CONV("Connnecting to remote proxy with IP:port = %s:%s\n"), pRemoteConfig->IP.c_str(), pRemoteConfig->port.c_str()); - LogWinscardRules(message); + message = string_format(_CONV("Connnecting to remote proxy with IP:port = %s:%s ... "), pRemoteConfig->IP.c_str(), pRemoteConfig->port.c_str()); + LogDebugString(message); pRemoteConfig->pSocket = new SocketClient(sIP, type_to_int(pRemoteConfig->port.c_str(), NULL, 10)); + if (pRemoteConfig->pSocket != NULL) { + LogDebugString(_CONV("success"), false); + } + else { + LogDebugString(_CONV("failed"), false); + } } catch (std::string error) { message = string_format(_CONV("Failed to connect to %s:%s (error: %s)\n"), pRemoteConfig->IP.c_str(), pRemoteConfig->port.c_str(), error); - LogWinscardRules(message); + LogDebugString(message, false); } catch (...) { message = string_format(_CONV("Failed to connect to %s:%s\n"), pRemoteConfig->IP.c_str(), pRemoteConfig->port.c_str()); - LogWinscardRules(message); + LogDebugString(message, false); } return STAT_OK; @@ -3082,7 +3084,7 @@ LONG CWinscardApp::Remote_SCardConnect(REMOTE_CONFIG* pRemoteConfig, string_type string_type l = Remote_FormatRequest(targetReader, theApp.m_remoteConfig.nextCommandID, CMD_RESET, "", "", CMD_LINE_SEPARATOR); pRemoteConfig->pSocket->SendLine(l); //message.Insert(0, "\n::-> "); - message.insert(0, _CONV("\n::-> ")); + message.insert(0, _CONV("::-> ")); LogWinscardRules(message); _sleep(500); @@ -3094,17 +3096,17 @@ LONG CWinscardApp::Remote_SCardConnect(REMOTE_CONFIG* pRemoteConfig, string_type string_type response; status = Remote_ParseResponse(l, theApp.m_remoteConfig.nextCommandID, &response); - message = string_format(_CONV("\n::<- %s\n"), response.c_str()); - replace(message.begin(), message.end(), '\n', ' '); + replace(response.begin(), response.end(), '\n', ' '); + message = string_format(_CONV("::<- %s\n"), response.c_str()); LogWinscardRules(message); } catch (const char* s) { - message = string_format(_CONV("Remote_SCardConnect(), SendLine(%s), fail with (%s)"), message.c_str(), s); + message = string_format(_CONV("Remote_SCardConnect(), SendLine(%s), fail with (%s)\n"), message.c_str(), s); LogWinscardRules(message); status = SCARD_F_UNKNOWN_ERROR; } catch (...) { - message = string_format(_CONV("Remote_SCardConnect(), SendLine(%s), fail with (unhandled exception)"), message.c_str()); + message = string_format(_CONV("Remote_SCardConnect(), SendLine(%s), fail with (unhandled exception)\n"), message.c_str()); LogWinscardRules(message); status = SCARD_F_UNKNOWN_ERROR; } @@ -3162,7 +3164,7 @@ LONG CWinscardApp::Remote_SCardTransmit(REMOTE_CONFIG* pRemoteConfig, string_typ string_type l = Remote_FormatRequest(targetReader, theApp.m_remoteConfig.nextCommandID, CMD_APDU, value, "", CMD_LINE_SEPARATOR); pRemoteConfig->pSocket->SendLine(l); //message.Insert(0, "\n::-> "); - message.insert(0, _CONV("\n::-> ")); + message.insert(0, _CONV("::-> ")); LogWinscardRules(message); // SLEEP LONGER, IF MORE DATA WILL BE RETURNED BY SYSTEM 00 0c 00 00 xx CALL @@ -3177,9 +3179,8 @@ LONG CWinscardApp::Remote_SCardTransmit(REMOTE_CONFIG* pRemoteConfig, string_typ string_type response; status = Remote_ParseResponse(l, theApp.m_remoteConfig.nextCommandID, &response); - message = string_format(_CONV("\n::<- %s\n"), l.c_str()); - //message.Replace("\n", " "); - replace(message.begin(), message.end(), '\n', ' '); + replace(l.begin(), l.end(), '\n', ' '); + message = string_format(_CONV("::<- %s\n"), l.c_str()); LogWinscardRules(message); if (response.find(CMD_RESPONSE_FAIL) == string_type::npos) { @@ -3197,12 +3198,12 @@ LONG CWinscardApp::Remote_SCardTransmit(REMOTE_CONFIG* pRemoteConfig, string_typ } } catch (const char* s) { - message = string_format(_CONV("\nRemote_SCardTransmit(), SendLine(%s), fail with (%s)"), message.c_str(), s); + message = string_format(_CONV("\nRemote_SCardTransmit(), SendLine(%s), fail with (%s)\n"), message.c_str(), s); LogWinscardRules(message); status = SCARD_F_UNKNOWN_ERROR; } catch (...) { - message = string_format(_CONV("\nRemote_SCardTransmit(), SendLine(%s), fail with (unhandled exception)"), message.c_str()); + message = string_format(_CONV("\nRemote_SCardTransmit(), SendLine(%s), fail with (unhandled exception)\n"), message.c_str()); LogWinscardRules(message); status = SCARD_F_UNKNOWN_ERROR; } @@ -3286,6 +3287,14 @@ int CWinscardApp::LoadRule(const char_type* section_name, dictionary* dict/*stri m_remoteConfig.bRedirect = value; } + type_copy(sec_and_key, section_name); + char_value = iniparser_getstring(dict, type_cat(sec_and_key, _CONV(":REMOTE_READER_PREFIX")), ""); + if (type_length(char_value) != 0) + { + m_remoteConfig.remoteReaderPrefix = char_value; + } + + type_copy(sec_and_key, section_name); char_value = iniparser_getstring(dict, type_cat(sec_and_key, _CONV(":IP")), ""); if (type_length(char_value) != 0) diff --git a/Winscard/stdafx.h b/Winscard/stdafx.h index 4052ab8..d9303a8 100644 --- a/Winscard/stdafx.h +++ b/Winscard/stdafx.h @@ -168,11 +168,14 @@ typedef std::list lptr; #if defined (_WIN32) +#define REMOTE_READER_PREFIX_DEFAULT "Simona" + typedef struct _REMOTE_CONFIG { BOOL bRedirect; string_type IP; string_type port; string_type cfgScript; + string_type remoteReaderPrefix; // prefix of reader name signalizing remote reader. If matches, all calls are redirected to remote proxy BYTE measureApdu[255]; BYTE measureApduLen; // number of used bytes from measureApdu array int measureApduByteCounter; // number of incoming apdu bytes before the measurement is run - part of get params 1 xx 0 command @@ -193,6 +196,7 @@ typedef struct _REMOTE_CONFIG { IP = _CONV(""); port = _CONV(""); cfgScript = _CONV(""); + remoteReaderPrefix = _CONV(REMOTE_READER_PREFIX_DEFAULT); memset(measureApdu, 0, sizeof(measureApdu)); measureApduLen = 0; measureApduByteCounter = 0; From ffe656fb04e83b09c824e49a43be9de8e55f3591 Mon Sep 17 00:00:00 2001 From: petrs Date: Tue, 10 Jul 2018 23:18:51 +0200 Subject: [PATCH 11/11] updated test application --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 7addfce..2d9597b 100644 --- a/README.md +++ b/README.md @@ -30,9 +30,9 @@ See more details at https://github.com/petrs/APDUPlay/wiki. ## Examples The localization of correct winscard.dll path can be tedious task for some applications. Here are some examples with increasing difficulty: - 1. Simple application directly using winscard.dll (example.exe) + 1. Simple application directly using winscard.dll (CAProfiler) 2. Application with persistent agent (gpg2.exe --card-edit) - 3. Java-based application: (GlobalPlatformPro gp -l) + 3. Java-based application accessing smartcards via JRE: (GlobalPlatformPro gp -l) ## Troubleshooting