From e59e24b8397c925a10a336d7f1413bffc71c213d Mon Sep 17 00:00:00 2001 From: MarekVan Date: Mon, 24 Oct 2016 19:59:51 +0200 Subject: [PATCH] compareWithNoCase moved to Winscard.cpp --- Winscard/CommonFnc.cpp | 2 +- Winscard/Winscard.cpp | 48 +++++++++++++++++++++++++----------------- Winscard/stdafx.h | 13 ------------ 3 files changed, 30 insertions(+), 33 deletions(-) diff --git a/Winscard/CommonFnc.cpp b/Winscard/CommonFnc.cpp index 26ad558..8160cb2 100644 --- a/Winscard/CommonFnc.cpp +++ b/Winscard/CommonFnc.cpp @@ -425,7 +425,7 @@ int CCommonFnc::SCSAT_EnsureFileHeader(string filePath, SCSAT_MEASURE_INFO* pInf toupper(*partchar); toupper(*SCSAT_MEASURE_SECTION_char); if(strcmp(partchar, SCSAT_MEASURE_SECTION_char) == 0) bNewFormat = TRUE; - //if (part.CompareNoCase(SCSAT_MEASURE_SECTION) == 0) bNewFormat = TRUE; + //if (part.compareWithNoCase(SCSAT_MEASURE_SECTION) == 0) bNewFormat = TRUE; else bNewFormat = FALSE; delete[] partchar; diff --git a/Winscard/Winscard.cpp b/Winscard/Winscard.cpp index 1c7f590..067d9c3 100644 --- a/Winscard/Winscard.cpp +++ b/Winscard/Winscard.cpp @@ -118,6 +118,19 @@ const SCARD_IO_REQUEST g_rgSCardT0Pci, g_rgSCardT1Pci, g_rgSCardRawPci; /* ******************************************************************************* */ +int compareWithNoCase(const char* str1, const char* str2) { + char *str1_2 = new char[strlen(str1)]; + char *str2_2 = new char[strlen(str2)]; + strcpy(str1_2, str1); + strcpy(str2_2, str2); + toupper(*str1_2); + toupper(*str2_2); + int result = strcmp(str1_2, str2_2); + delete[] str1_2; + delete[] str2_2; + return result; +} + void DumpMemory( LPCBYTE location, DWORD length ) { /* DWORD i, written; @@ -144,9 +157,6 @@ void DumpMemory( LPCBYTE location, DWORD length ) { } - - - static WINSCARDAPI LONG (WINAPI *Original_SCardEstablishContext)( IN DWORD dwScope, IN LPCVOID pvReserved1, @@ -2808,7 +2818,7 @@ int CWinscardApp::LoadRule(string ruleName, string filePath) { APDU_RULE rule; APDU_SINGLE_RULE singleRule; - if (compareNoCase(ruleName.c_str(), "WINSCARD") == 0) { + if (compareWithNoCase(ruleName.c_str(), "WINSCARD") == 0) { if ((GetPrivateProfileString((LPCTSTR) ruleName.c_str(), "AUTO_REQUEST_DATA", "", buffer, cBuffer, filePath.c_str())) > 0) { m_winscardConfig.bAUTO_REQUEST_DATA = (atoi(buffer) == 0) ? FALSE : TRUE; } @@ -2836,7 +2846,7 @@ int CWinscardApp::LoadRule(string ruleName, string filePath) { } - if (compareNoCase(ruleName.c_str(), "SCSAT04") == 0) { + if (compareWithNoCase(ruleName.c_str(), "SCSAT04") == 0) { // SCSAT04 CONFIGURATION RULE if ((GetPrivateProfileString((LPCTSTR) ruleName.c_str(), "REDIRECT", "", buffer, cBuffer, filePath.c_str())) > 0) { m_scsat04Config.bRedirect = (atoi(buffer) == 0) ? FALSE : TRUE; @@ -2867,7 +2877,7 @@ int CWinscardApp::LoadRule(string ruleName, string filePath) { } - if (compareNoCase(ruleName.substr(0, (int)strlen("RULE")).c_str(), "RULE") == 0) { + if (compareWithNoCase(ruleName.substr(0, (int)strlen("RULE")).c_str(), "RULE") == 0) { // COMMON RULE if ((GetPrivateProfileString((LPCTSTR) ruleName.c_str(), "USAGE", "", buffer, cBuffer, filePath.c_str())) > 0) { @@ -2911,32 +2921,32 @@ int CWinscardApp::LoadRule(string ruleName, string filePath) { //elemName = rulePart.Left(rulePart.Find("=")); elemName = rulePart.substr(0, rulePart.find("=")); - if (compareNoCase(elemName.c_str(), "CLA") == 0) { + if (compareWithNoCase(elemName.c_str(), "CLA") == 0) { singleRule.element = CLA_ELEM; CCommonFnc::BYTE_ConvertFromHexNumToByte(rulePart.substr(rulePart.find("=")+1, 2), &(singleRule.value)); singleRule.valid = TRUE;rule.matchRules.push_back(singleRule); } - if (compareNoCase(elemName.c_str(), "INS") == 0) { + if (compareWithNoCase(elemName.c_str(), "INS") == 0) { singleRule.element = INS_ELEM; CCommonFnc::BYTE_ConvertFromHexNumToByte(rulePart.substr(rulePart.find("=")+1, 2), &(singleRule.value)); singleRule.valid = TRUE;rule.matchRules.push_back(singleRule); } - if (compareNoCase(elemName.c_str(), "P1") == 0) { + if (compareWithNoCase(elemName.c_str(), "P1") == 0) { singleRule.element = P1_ELEM; CCommonFnc::BYTE_ConvertFromHexNumToByte(rulePart.substr(rulePart.find("=")+1, 2), &(singleRule.value)); singleRule.valid = TRUE;rule.matchRules.push_back(singleRule); } - if (compareNoCase(elemName.c_str(), "P2") == 0) { + if (compareWithNoCase(elemName.c_str(), "P2") == 0) { singleRule.element = P2_ELEM; CCommonFnc::BYTE_ConvertFromHexNumToByte(rulePart.substr(rulePart.find("=")+1, 2), &(singleRule.value)); singleRule.valid = TRUE;rule.matchRules.push_back(singleRule); } - if (compareNoCase(elemName.c_str(), "LC") == 0) { + if (compareWithNoCase(elemName.c_str(), "LC") == 0) { singleRule.element = LC_ELEM; CCommonFnc::BYTE_ConvertFromHexNumToByte(rulePart.substr(rulePart.find("=")+1, 2), &(singleRule.value)); singleRule.valid = TRUE;rule.matchRules.push_back(singleRule); } - if (compareNoCase(elemName.substr(0, (int) strlen("DATA")).c_str(), "DATA") == 0) { + if (compareWithNoCase(elemName.substr(0, (int) strlen("DATA")).c_str(), "DATA") == 0) { // DATA CAN BE WRITTEN IN MORE VALUES AT ONCE, STARTING ON POSITION DATAx // CREATE SEPARATE ELEMENT FOR EACH int offset = atoi(elemName.substr(ruleName.find_first_of("0123456789"), 0).c_str()); @@ -2983,37 +2993,37 @@ int CWinscardApp::LoadRule(string ruleName, string filePath) { elemName = rulePart.substr(0, rulePart.find("=")); - if (compareNoCase(elemName.c_str(), "CLA") == 0) { + if (compareWithNoCase(elemName.c_str(), "CLA") == 0) { singleRule.element = CLA_ELEM; CCommonFnc::BYTE_ConvertFromHexNumToByte(rulePart.substr(rulePart.find("=")+1, 2), &(singleRule.value)); singleRule.valid = TRUE;rule.actionRules.push_back(singleRule); } - if (compareNoCase(elemName.c_str(), "INS") == 0) { + if (compareWithNoCase(elemName.c_str(), "INS") == 0) { singleRule.element = INS_ELEM; CCommonFnc::BYTE_ConvertFromHexNumToByte(rulePart.substr(rulePart.find("=")+1, 2), &(singleRule.value)); singleRule.valid = TRUE;rule.actionRules.push_back(singleRule); } - if (compareNoCase(elemName.c_str(), "P1") == 0) { + if (compareWithNoCase(elemName.c_str(), "P1") == 0) { singleRule.element = P1_ELEM; CCommonFnc::BYTE_ConvertFromHexNumToByte(rulePart.substr(rulePart.find("=")+1, 2), &(singleRule.value)); singleRule.valid = TRUE;rule.actionRules.push_back(singleRule); } - if (compareNoCase(elemName.c_str(), "P2") == 0) { + if (compareWithNoCase(elemName.c_str(), "P2") == 0) { singleRule.element = P2_ELEM; CCommonFnc::BYTE_ConvertFromHexNumToByte(rulePart.substr(rulePart.find("=")+1, 2), &(singleRule.value)); singleRule.valid = TRUE;rule.actionRules.push_back(singleRule); } - if (compareNoCase(elemName.c_str(), "LC") == 0) { + if (compareWithNoCase(elemName.c_str(), "LC") == 0) { singleRule.element = LC_ELEM; CCommonFnc::BYTE_ConvertFromHexNumToByte(rulePart.substr(rulePart.find("=")+1, 2), &(singleRule.value)); singleRule.valid = TRUE;rule.actionRules.push_back(singleRule); } - if (compareNoCase(elemName.c_str(), "LE") == 0) { + if (compareWithNoCase(elemName.c_str(), "LE") == 0) { singleRule.element = LE_ELEM; CCommonFnc::BYTE_ConvertFromHexNumToByte(rulePart.substr(rulePart.find("=")+1, 2), &(singleRule.value)); singleRule.valid = TRUE;rule.actionRules.push_back(singleRule); } - if (compareNoCase(elemName.substr(0, (int) strlen("DATA")).c_str(), "DATA") == 0) { + if (compareWithNoCase(elemName.substr(0, (int) strlen("DATA")).c_str(), "DATA") == 0) { // DATA CAN BE WRITTEN IN MORE VALUES AT ONCE, STARTING ON POSITION DATAx // CREATE SEPARATE ELEMENT FOR EACH int offset = atoi(elemName.substr(ruleName.find_first_of("0123456789")).c_str()); diff --git a/Winscard/stdafx.h b/Winscard/stdafx.h index 3177043..12f0309 100644 --- a/Winscard/stdafx.h +++ b/Winscard/stdafx.h @@ -73,19 +73,6 @@ string string_format(const std::string& format, Args ... args) { return string(buf.get(), buf.get() + size - 1); // We don't want the '\0' inside } -int compareNoCase(const char* str1, const char* str2) { - char *str1_2 = new char[strlen(str1)]; - char *str2_2 = new char[strlen(str2)]; - strcpy(str1_2, str1); - strcpy(str2_2, str2); - toupper(*str1_2); - toupper(*str2_2); - int result = strcmp(str1_2, str2_2); - delete[] str1_2; - delete[] str2_2; - return result; -} - typedef list lcs; #define MAX_APDU_LENGTH 300