Skip to content

Commit

Permalink
Merge pull request #9 from crocs-muni/devel
Browse files Browse the repository at this point in the history
Devel
  • Loading branch information
petrs authored Jul 9, 2018
2 parents 24f85dd + 49a0c4b commit eb7b6e2
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 16 deletions.
21 changes: 11 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,31 +7,32 @@ Windows DLL: [![Build status](https://ci.appveyor.com/api/projects/status/ktwde2
Linux SO: [![Build Status](https://travis-ci.org/crocs-muni/apduplay.svg?branch=master)](https://travis-ci.org/crocs-muni/apduplay)


The project APDUPlay is based on ApduView tool (http://www.fernandes.org/apduview/index.html) which allows you to log communication realized via PC/SC interface (winscard.dll library). If you are interested only in the log of transmitted data, you can readily
use APDUView project (although APDUPlay project provides information about communication in more structured way more suitable for later post-processing and add some additional information).
The project APDUPlay is based on ApduView tool (http://www.fernandes.org/apduview/index.html) which allows you to log communication realized via PC/SC interface (winscard.dll library). The APDUPlay project provides a winscard.dll library which is stub used instead of original winscard.dll provided by Microsoft. For correct usage, you need to find Microsoft's library and copy it to the folder with an application you are trying to control with APDUPlay.

Note: The APDUPlay tool is available for download including source codes, yet documentation still lack a bit behind. But as it was requested several times, and I hope it will be useful.

The APDUPlay project is providing following functionality:
* Log content and additional information about exchanged PC/SC communication
* Manipulate communication in real time
* Redirect communication via socket to other device/computer
* Redirect communication via socket to other device/computer (only Windows version at the moment)
* Reorder list of smart card readers detected in a system
* Visualize captured data in a structured way by GraphViz
* Visualize captured data in a structured way by GraphViz (Java project Parser)

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 32bit target application or c:\Windows\SysWOW64\winscard.dll for 64bit application) to the folder with target application and rename it to original.dll
2. Copy Winscard.dll from APDUPlay project to the folder with target application
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
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)

The APDUPlay project provides a winscard.dll library which is stub used instead of original winscard.dll provided by Microsoft. For correct usage, you need to find Microsoft's library and copy it to the folder with an application you are trying to control with APDUPlay.

## Troubleshooting
NOTE: If you use (wrongly) 64bit version of library winscard.dll, it will fail with "The procedure entry point original.g_rgSCardT1Pci could not be located in the dynamic link library WinSCard.dll."

* 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."




Please, open an issue in case of any bug found.

Expand Down
30 changes: 24 additions & 6 deletions Winscard/Winscard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ static SCard \1 (STDCALL *Original_\2)
/**/
#pragma warning(disable:4996)

static string_type ENV_WINSCARD_RULES_PATH = _CONV("APDUPLAY");
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");
Expand Down Expand Up @@ -2785,9 +2786,6 @@ END_MESSAGE_MAP()

CWinscardApp::CWinscardApp()
{
// TODO: add construction code here,
// Place all significant initialization in InitInstance

m_bRulesActive = FALSE;

#ifdef __linux__
Expand Down Expand Up @@ -2820,7 +2818,6 @@ void GetDesktopPath(char_type* path)
}

#if defined (_WIN32)

BOOL CWinscardApp::InitInstance()
{
CWinApp::InitInstance();
Expand Down Expand Up @@ -3497,8 +3494,29 @@ int CWinscardApp::LoadRules() {
WINSCARD_LOG += _CONV("_") + date_and_time + _CONV(".txt");
WINSCARD_RULES_LOG += _CONV("_") + date_and_time + _CONV(".txt");

if (!(file = fopen(path, "r"))) // try to open file in actual directory
{
//
// Searching for 'winscard_rules.txt' (priority)
// 1. Lookup in local directory
// 2. Lookup for APDUPLAY environmental variable
// 3. Lookup on user Desktop

if (!file) { // 1. Lookup in local directory
file = fopen(path, "r");
}

if (!file) { // 2. Lookup for APDUPLAY environmental variable
char* configPath = std::getenv(ENV_WINSCARD_RULES_PATH.c_str());
if (configPath != NULL) {
// variable detected, try to open
string newRuleFile = string_format(_CONV("%s\\%s"), configPath, RULE_FILE.c_str());
file = fopen(newRuleFile.c_str(), "r");
if (file) {
type_copy(path, newRuleFile.c_str());
}
}
}

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
Expand Down
2 changes: 2 additions & 0 deletions WinscardTests/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,8 @@ TEST_CASE("Winscard tests", "[winscard_tests]")
{
SECTION("Aplly rules test")
{
LoadFunctionPtrs();

// Prepare configuration files
ofstream myfile;
std::string ruleFilePath = GetLogsPath() + "winscard_rules.txt";
Expand Down
15 changes: 15 additions & 0 deletions WinscardTests/winscard_rules.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[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
9 changes: 9 additions & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,12 @@ build:
# MSBuild verbosity level
verbosity: normal


#---------------------------------#
# artifacts #
#---------------------------------#
artifacts:
- path: c:\projects\APDUPlay\x64\Release\winscard.dll
name: winscard.dll 64bit
- path: c:\projects\APDUPlay\Release\winscard.dll
name: winscard.dll 32bit

0 comments on commit eb7b6e2

Please sign in to comment.