Skip to content

Commit

Permalink
Merge pull request #10 from crocs-muni/devel
Browse files Browse the repository at this point in the history
Devel
  • Loading branch information
petrs committed Jul 10, 2018
2 parents 10f0d2b + a9ff172 commit 4bbfa4f
Show file tree
Hide file tree
Showing 16 changed files with 769 additions and 565 deletions.
29 changes: 24 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 (CAProfiler)
2. Application with persistent agent (gpg2.exe --card-edit)
3. Java-based application accessing smartcards via JRE: (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.

Expand Down
3 changes: 1 addition & 2 deletions Winscard/CommonFnc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion Winscard/ReadMe.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading

0 comments on commit 4bbfa4f

Please sign in to comment.