├── NEWS
├── config.rpath
├── README
├── dot_cardpeek_dir
├── version
├── scripts
│ ├── etc
│ │ ├── grenoble-tag_stops.lua
│ │ ├── gironde-transgironde.lua
│ │ ├── grenoble-tag_lines.lua
│ │ └── brussels-metro.lua
│ ├── lib
│ │ ├── treeflex.lua
│ │ ├── network_codes.lua
│ │ ├── strict.lua
│ │ ├── calypso_card_num.lua
│ │ └── compatibility-with-0.7.lua
│ ├── atr.lua
│ ├── calypso
│ │ ├── c250n64.lua
│ │ ├── c250n502.lua
│ │ └── c250n901.lua
│ └── thai eID.lua
├── cardpeekrc.lua
└── config.lua
├── win32
├── resource.rc
├── cardpeek.ico
├── config.h
├── win32compat.h
├── winscard.def
└── win32compat.c
├── linux
└── compile.sh
├── osx
├── gtkrc
├── cardpeek.iconset
│ ├── icon_128x128.png
│ ├── icon_16x16.png
│ ├── icon_256x256.png
│ ├── icon_32x32.png
│ ├── icon_512x512.png
│ └── icon_64x64.png
├── generate_bundle.sh
├── Info-cardpeek.plist.in
├── README.md
└── cardpeek-osx.m
├── dyntree_model.c
├── doc
├── sample-emv.jpg
├── sample-navigo.jpg
├── cardpeek_ref.en.odt
├── cardpeek_ref.en.pdf
├── build-freebsd.md
├── navigo.md
├── emv.md
├── emv.fr.md
├── build-windows.md
├── navigo.fr.md
└── build-debian.md
├── icons
├── cardpeek-atr.png
├── cardpeek-block.png
├── cardpeek-body.png
├── cardpeek-file.png
├── cardpeek-item.png
├── cardpeek-logo.png
├── cardpeek-menu.png
├── image-missing.png
├── cardpeek-analyzer.png
├── cardpeek-folder.png
├── cardpeek-header.png
├── cardpeek-record.png
├── cardpeek-smartcard.png
└── cardpeek-application.png
├── main.h
├── cardpeek.c
├── script_version.h
├── http_download.h
├── cardpeek.desktop
├── .whitesource
├── .gitignore
├── cardpeek_public_key.h
├── clean.sh
├── lua_bit.h
├── lua_log.h
├── lua_ui.h
├── lua_asn1.h
├── lua_nodes.h
├── ui
├── gtk
│ ├── gui_about.h
│ ├── gui_core.h
│ ├── gui_scratchpad.h
│ ├── gui_logview.h
│ ├── gui_cardview.h
│ ├── gui_inprogress.h
│ ├── gui_readerview.h
│ ├── gui_toolbar.h
│ ├── gui_flexi_cell_renderer.h
│ ├── gui_about.c
│ ├── gui_scratchpad.c
│ ├── gui_toolbar.c
│ └── gui_inprogress.c
└── console
│ ├── console_about.h
│ ├── console_core.h
│ ├── console_inprogress.h
│ ├── console_inprogress.c
│ └── console_about.c
├── lua_crypto.h
├── lua_iconv.h
├── compile-cardpeek.sh
├── lua_card.h
├── system_info.h
├── cardpeek_update.h
├── cardpeek_resources.gresource
├── cardpeek_resources.gresource.xml
├── README.fr.md
├── lua_bytes.h
├── AUTHORS
├── cardpeek.appdata.xml
├── asn1.h
├── lua_log.c
├── README.md
├── lua_ext.h
├── drivers
├── null_driver.c
└── replay_driver.c
├── http_download.c
├── lua_bit.c
├── crypto.h
├── pathconfig.h
├── a_string.h
├── replay.h
├── iso7816.h
├── misc.h
├── cardpeek.1
├── ui.h
├── update_dot_cardpeek_dir.sh
├── pathconfig.c
├── system_info.c
├── lua_iconv.c
├── m4
├── lib-ld.m4
├── ax_lib_readline.m4
└── ax_check_openssl.m4
├── smartcard.h
├── ui.c
├── bytestring.h
├── Makefile.am
├── deps-win32.sh
├── lua_crypto.c
└── dyntree_model.h
/NEWS:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/config.rpath:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/README:
--------------------------------------------------------------------------------
1 | README.md
--------------------------------------------------------------------------------
/dot_cardpeek_dir/version:
--------------------------------------------------------------------------------
1 | 1439474525
2 |
--------------------------------------------------------------------------------
/win32/resource.rc:
--------------------------------------------------------------------------------
1 | ID ICON "cardpeek.ico"
2 |
3 |
--------------------------------------------------------------------------------
/linux/compile.sh:
--------------------------------------------------------------------------------
1 | cd ..
2 | autoreconf -i
3 | ./configure
4 | make
5 |
--------------------------------------------------------------------------------
/osx/gtkrc:
--------------------------------------------------------------------------------
1 | gtk-icon-theme-name = "Default"
2 | gtk-enable-mnemonics = 0
3 |
--------------------------------------------------------------------------------
/dyntree_model.c:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/L1L1/cardpeek/HEAD/dyntree_model.c
--------------------------------------------------------------------------------
/doc/sample-emv.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/L1L1/cardpeek/HEAD/doc/sample-emv.jpg
--------------------------------------------------------------------------------
/win32/cardpeek.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/L1L1/cardpeek/HEAD/win32/cardpeek.ico
--------------------------------------------------------------------------------
/doc/sample-navigo.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/L1L1/cardpeek/HEAD/doc/sample-navigo.jpg
--------------------------------------------------------------------------------
/icons/cardpeek-atr.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/L1L1/cardpeek/HEAD/icons/cardpeek-atr.png
--------------------------------------------------------------------------------
/doc/cardpeek_ref.en.odt:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/L1L1/cardpeek/HEAD/doc/cardpeek_ref.en.odt
--------------------------------------------------------------------------------
/doc/cardpeek_ref.en.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/L1L1/cardpeek/HEAD/doc/cardpeek_ref.en.pdf
--------------------------------------------------------------------------------
/icons/cardpeek-block.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/L1L1/cardpeek/HEAD/icons/cardpeek-block.png
--------------------------------------------------------------------------------
/icons/cardpeek-body.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/L1L1/cardpeek/HEAD/icons/cardpeek-body.png
--------------------------------------------------------------------------------
/icons/cardpeek-file.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/L1L1/cardpeek/HEAD/icons/cardpeek-file.png
--------------------------------------------------------------------------------
/icons/cardpeek-item.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/L1L1/cardpeek/HEAD/icons/cardpeek-item.png
--------------------------------------------------------------------------------
/icons/cardpeek-logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/L1L1/cardpeek/HEAD/icons/cardpeek-logo.png
--------------------------------------------------------------------------------
/icons/cardpeek-menu.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/L1L1/cardpeek/HEAD/icons/cardpeek-menu.png
--------------------------------------------------------------------------------
/icons/image-missing.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/L1L1/cardpeek/HEAD/icons/image-missing.png
--------------------------------------------------------------------------------
/icons/cardpeek-analyzer.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/L1L1/cardpeek/HEAD/icons/cardpeek-analyzer.png
--------------------------------------------------------------------------------
/icons/cardpeek-folder.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/L1L1/cardpeek/HEAD/icons/cardpeek-folder.png
--------------------------------------------------------------------------------
/icons/cardpeek-header.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/L1L1/cardpeek/HEAD/icons/cardpeek-header.png
--------------------------------------------------------------------------------
/icons/cardpeek-record.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/L1L1/cardpeek/HEAD/icons/cardpeek-record.png
--------------------------------------------------------------------------------
/icons/cardpeek-smartcard.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/L1L1/cardpeek/HEAD/icons/cardpeek-smartcard.png
--------------------------------------------------------------------------------
/icons/cardpeek-application.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/L1L1/cardpeek/HEAD/icons/cardpeek-application.png
--------------------------------------------------------------------------------
/main.h:
--------------------------------------------------------------------------------
1 | #ifndef _MAIN_H_
2 | #define _MAIN_H_
3 |
4 | int cardpeek_main(int argc, char **argv);
5 |
6 | #endif
7 |
--------------------------------------------------------------------------------
/osx/cardpeek.iconset/icon_128x128.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/L1L1/cardpeek/HEAD/osx/cardpeek.iconset/icon_128x128.png
--------------------------------------------------------------------------------
/osx/cardpeek.iconset/icon_16x16.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/L1L1/cardpeek/HEAD/osx/cardpeek.iconset/icon_16x16.png
--------------------------------------------------------------------------------
/osx/cardpeek.iconset/icon_256x256.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/L1L1/cardpeek/HEAD/osx/cardpeek.iconset/icon_256x256.png
--------------------------------------------------------------------------------
/osx/cardpeek.iconset/icon_32x32.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/L1L1/cardpeek/HEAD/osx/cardpeek.iconset/icon_32x32.png
--------------------------------------------------------------------------------
/osx/cardpeek.iconset/icon_512x512.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/L1L1/cardpeek/HEAD/osx/cardpeek.iconset/icon_512x512.png
--------------------------------------------------------------------------------
/osx/cardpeek.iconset/icon_64x64.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/L1L1/cardpeek/HEAD/osx/cardpeek.iconset/icon_64x64.png
--------------------------------------------------------------------------------
/cardpeek.c:
--------------------------------------------------------------------------------
1 | #include "main.h"
2 |
3 | int main(int argc, char **argv)
4 | {
5 | return cardpeek_main(argc,argv);
6 | }
7 |
--------------------------------------------------------------------------------
/script_version.h:
--------------------------------------------------------------------------------
1 | #ifndef SCRIPT_VERSION_H
2 | #define SCRIPT_VERSION_H
3 |
4 | #define SCRIPT_VERSION 1439474525
5 |
6 | #endif
7 |
--------------------------------------------------------------------------------
/dot_cardpeek_dir/scripts/etc/grenoble-tag_stops.lua:
--------------------------------------------------------------------------------
1 | STOPS_LIST = {
2 | [1018] = "Grenoble - Île Verte",
3 | [1019] = "Grenoble - Victor Hugo"
4 | }
5 |
--------------------------------------------------------------------------------
/dot_cardpeek_dir/scripts/etc/gironde-transgironde.lua:
--------------------------------------------------------------------------------
1 | TRANSGIRONDE_STOPS_LIST = {
2 | [1005] = "Mérignac - Quatre Chemins",
3 | [6001] = "Andernos - Centre"
4 | }
5 |
--------------------------------------------------------------------------------
/http_download.h:
--------------------------------------------------------------------------------
1 | #ifndef _HTTP_DOWNLOAD_H_
2 | #define _HTTP_DOWNLOAD_H_
3 |
4 | int http_download(const char *src_url, const char *dst_filename);
5 |
6 | #endif
7 |
--------------------------------------------------------------------------------
/dot_cardpeek_dir/scripts/etc/grenoble-tag_lines.lua:
--------------------------------------------------------------------------------
1 | LINES_LIST = {
2 | [80] = {
3 | ["name"] = ""
4 | },
5 | [81] = {
6 | ["name"] = ""
7 | },
8 | [89] = {
9 | ["name"] = "Ligne B"
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/cardpeek.desktop:
--------------------------------------------------------------------------------
1 | [Desktop Entry]
2 | Name=Cardpeek
3 | Comment=Tool to read the contents of smart cards
4 | Exec=cardpeek
5 | Icon=cardpeek-logo
6 | Terminal=false
7 | Type=Application
8 | Categories=GTK;System;Security;
9 |
--------------------------------------------------------------------------------
/osx/generate_bundle.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 |
3 | export DESTINATION="$HOME/Desktop/"
4 |
5 | echo "This script will install the app in $DESTINATION"
6 |
7 | iconutil -c icns cardpeek.iconset
8 |
9 | gtk-mac-bundler cardpeek.bundle
10 |
11 |
12 |
--------------------------------------------------------------------------------
/dot_cardpeek_dir/cardpeekrc.lua:
--------------------------------------------------------------------------------
1 | -- This file is free for the user to modify
2 | -- It is executed after config.lua
3 |
4 |
5 | -- The next line is needed for card commands.
6 | require("scripts.lib.apdu")
7 | dofile("scripts/lib/compatibility-with-0.7.lua")
8 |
--------------------------------------------------------------------------------
/.whitesource:
--------------------------------------------------------------------------------
1 | ##########################################################
2 | #### WhiteSource Integration configuration file ####
3 | ##########################################################
4 |
5 | # Configuration #
6 | #---------------#
7 | ws.repo.scan=true
8 | vulnerable.check.run.conclusion.level=failure
9 |
--------------------------------------------------------------------------------
/doc/build-freebsd.md:
--------------------------------------------------------------------------------
1 | Specific installation instructions for FreeBSD
2 | ==============================================
3 |
4 | If you get the following error, after using configure and make:
5 |
6 | invalid DSO for symbol `libiconv_open' definition
7 |
8 | Try running the following commands:
9 |
10 | ICONV_LIBS="-l iconv" ./configure
11 | make
12 |
--------------------------------------------------------------------------------
/dot_cardpeek_dir/scripts/lib/treeflex.lua:
--------------------------------------------------------------------------------
1 | --
2 |
3 | local TREEFLEX_WARNING=false
4 |
5 | if TREEFLEX_WARNING==false then
6 | log.print(log.WARNING,"the treeflex library included in this script is obsolete, please use the new 'nodes' API\n" ..
7 | "\tThis warning is only printed once.")
8 | TREEFLEX_WARNING=true
9 | end
10 |
11 |
--------------------------------------------------------------------------------
/dot_cardpeek_dir/config.lua:
--------------------------------------------------------------------------------
1 | --
2 | -- This file is automatically generated by Cardpeek.
3 | -- It holds cardpeek configuration parameters, which are stored in the
4 | -- lua 'cardpeek' table.
5 | --
6 | -- See cardpeekrc.lua for adding your own functions and variables to
7 | -- cardpeek.
8 | --
9 | cardpeek = {
10 | }
11 |
12 | dofile('scripts/lib/apdu.lua')
13 | -- end --
14 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | Makefile.in
2 | Makefile
3 | aclocal.m4
4 | autom4te.cache
5 | compile
6 | config.guess
7 | config.sub
8 | config.log
9 | config.h
10 | config.status
11 | configure
12 | stamp-h1
13 | depcomp
14 | install-sh
15 | missing
16 | *.o
17 | *~
18 | .deps
19 | .dirstamp
20 | dot_cardpeek.tar.gz
21 | cardpeek
22 | cardpeek.exe
23 | cardpeek_resources.c
24 | win32/libwinscard.a
25 | deps
26 | build
27 | .vscode
28 |
--------------------------------------------------------------------------------
/win32/config.h:
--------------------------------------------------------------------------------
1 | #ifndef WIN32_CONFIG_H
2 | #define WIN32_CONFIG_H
3 | #ifdef _WIN32
4 |
5 | #define VERSION "0.8.5-win64"
6 |
7 | #define ICONV_CONST
8 |
9 | #define HAVE_GSTATBUF
10 |
11 | #define HAVE_LIBREADLINE
12 | #define HAVE_READLINE_HISTORY
13 | #define HAVE_READLINE_READLINE_H
14 | #define HAVE_READLINE_HISTORY_H
15 |
16 | #else /* not win32 */
17 | #ifndef O_BINARY
18 | #define O_BINARY 0
19 | #endif
20 | #endif /* _WIN32 */
21 | #endif
22 |
--------------------------------------------------------------------------------
/win32/win32compat.h:
--------------------------------------------------------------------------------
1 | #ifndef _WIN32COMPAT_H
2 | #define _WIN32COMPAT_H
3 | #ifdef _WIN32
4 |
5 | #include
6 |
7 | #define rindex strrchr
8 |
9 | int scandir (const char *dir, struct dirent ***namelist,int (*select)(const struct dirent *),int (*compar)(const struct dirent **, const struct dirent**));
10 |
11 | int alphasort (const struct dirent **a, const struct dirent **b);
12 |
13 | const char *pcsc_stringify_error(long err);
14 |
15 | #endif
16 | #endif
17 |
--------------------------------------------------------------------------------
/cardpeek_public_key.h:
--------------------------------------------------------------------------------
1 |
2 |
3 | #define CARDPEEK_PUBLIC_KEY \
4 | "-----BEGIN PUBLIC KEY-----\n" \
5 | "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAxY/1mOsNZnWpdDxdfOWy\n" \
6 | "Db/R0uM6MXtNcAIlGnF22Ial5ecbTejBcI+L6ctUK3hxa9vswv0b2rqbcEh+dkAl\n" \
7 | "EPDrw3dUm2Oyn7ysuToa5RXcSYw1yX1BVLDI82+1XPEV5yAQBb8rQ42877e50U0B\n" \
8 | "nshI5FXRSY4/qtrd7/twpr5DeSEo9K/wsyfbG/z3kieGVPdJViffF4JSZi1qVZE/\n" \
9 | "/GFm4Bf/APtMkELrhLUnY69TQw1vDROTVJOQU/hEsEmQIAO7RH/NbLQaMqpBklGE\n" \
10 | "jAfJQO54IHU2DuCHjSByz17ujovszwmsC8xpI00X9pH9OO5CnLUP4V0NNSeEdhNH\n" \
11 | "RQIDAQAB\n" \
12 | "-----END PUBLIC KEY-----\n" \
13 | ""
14 |
15 |
16 |
--------------------------------------------------------------------------------
/clean.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | [ -f Makefile ] && make clean
3 | make -f Makefile.win32 clean
4 | for p in $(find -type f -name "*.o"); do
5 | rm "$p"
6 | done
7 | for p in $(find -type f -name "*.dirstamp"); do
8 | rm "$p"
9 | done
10 | for p in $(find -type d -name "*.deps"); do
11 | rm -r "$p"
12 | done
13 | rm -f Makefile
14 | rm -f Makefile.in
15 | rm -f aclocal.m4
16 | rm -f cardpeek
17 | rm -f cardpeek.exe
18 | rm -f cardpeek_resources.c
19 | rm -f compile
20 | rm -f config.guess
21 | rm -f config.h
22 | rm -f config.log
23 | rm -f config.status
24 | rm -f config.sub
25 | rm -f configure
26 | rm -f depcomp
27 | rm -f install-sh
28 | rm -f missing
29 | rm -f stamp-h1
30 | rm -f dot_cardpeek.tar.gz
31 | rm -f win32/libwinscard.a
32 | rm -rf autom4te.cache
33 |
--------------------------------------------------------------------------------
/lua_bit.h:
--------------------------------------------------------------------------------
1 | /**********************************************************************
2 | *
3 | * This file is part of Cardpeek, the smart card reader utility.
4 | *
5 | * Copyright 2009-2013 by Alain Pannetrat
6 | *
7 | * Cardpeek is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * Cardpeek is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with Cardpeek. If not, see .
19 | *
20 | */
21 | #ifndef LUA_BIT_H
22 |
23 | #include
24 |
25 | int luaopen_bit(lua_State* L);
26 |
27 | #endif
28 |
--------------------------------------------------------------------------------
/lua_log.h:
--------------------------------------------------------------------------------
1 | /**********************************************************************
2 | *
3 | * This file is part of Cardpeek, the smart card reader utility.
4 | *
5 | * Copyright 2009-2013 by Alain Pannetrat
6 | *
7 | * Cardpeek is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * Cardpeek is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with Cardpeek. If not, see .
19 | *
20 | */
21 | #ifndef LUA_LOG_H
22 |
23 | #include
24 |
25 | int luaopen_log(lua_State* L);
26 |
27 | #endif
28 |
--------------------------------------------------------------------------------
/lua_ui.h:
--------------------------------------------------------------------------------
1 | /**********************************************************************
2 | *
3 | * This file is part of Cardpeek, the smart card reader utility.
4 | *
5 | * Copyright 2009-2013 by Alain Pannetrat
6 | *
7 | * Cardpeek is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * Cardpeek is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with Cardpeek. If not, see .
19 | *
20 | */
21 | #ifndef LUA_UI_H
22 |
23 | #include
24 |
25 | int luaopen_ui(lua_State* L);
26 |
27 | #endif
28 |
--------------------------------------------------------------------------------
/lua_asn1.h:
--------------------------------------------------------------------------------
1 | /**********************************************************************
2 | *
3 | * This file is part of Cardpeek, the smart card reader utility.
4 | *
5 | * Copyright 2009-2013 by Alain Pannetrat
6 | *
7 | * Cardpeek is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * Cardpeek is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with Cardpeek. If not, see .
19 | *
20 | */
21 | #ifndef LUA_ASN1_H
22 |
23 | #include
24 |
25 | int luaopen_asn1(lua_State* L);
26 |
27 | #endif
28 |
--------------------------------------------------------------------------------
/lua_nodes.h:
--------------------------------------------------------------------------------
1 | /**********************************************************************
2 | *
3 | * This file is part of Cardpeek, the smart card reader utility.
4 | *
5 | * Copyright 2009-2013 by Alain Pannetrat
6 | *
7 | * Cardpeek is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * Cardpeek is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with Cardpeek. If not, see .
19 | *
20 | */
21 | #ifndef LUA_NODES_H
22 |
23 | #include
24 |
25 | int luaopen_nodes(lua_State* L);
26 |
27 | #endif
28 |
--------------------------------------------------------------------------------
/ui/gtk/gui_about.h:
--------------------------------------------------------------------------------
1 | /**********************************************************************
2 | *
3 | * This file is part of Cardpeek, the smart card reader utility.
4 | *
5 | * Copyright 2009-2013 by Alain Pannetrat
6 | *
7 | * Cardpeek is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * Cardpeek is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with Cardpeek. If not, see .
19 | *
20 | */
21 |
22 | #ifndef GUI_ABOUT_H
23 | #define GUI_ABOUT_H
24 |
25 | void gui_about(void);
26 |
27 | #endif
28 |
--------------------------------------------------------------------------------
/lua_crypto.h:
--------------------------------------------------------------------------------
1 | /**********************************************************************
2 | *
3 | * This file is part of Cardpeek, the smart card reader utility.
4 | *
5 | * Copyright 2009-2013 by Alain Pannetrat
6 | *
7 | * Cardpeek is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * Cardpeek is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with Cardpeek. If not, see .
19 | *
20 | */
21 | #ifndef LUA_CRYPTO_H
22 |
23 | #include
24 |
25 | int luaopen_crypto(lua_State* L);
26 |
27 | #endif
28 |
--------------------------------------------------------------------------------
/dot_cardpeek_dir/scripts/atr.lua:
--------------------------------------------------------------------------------
1 | --
2 | -- This file is part of Cardpeek, the smartcard reader utility.
3 | --
4 | -- Copyright 2009-2011 by 'L1L1'
5 | --
6 | -- Cardpeek is free software: you can redistribute it and/or modify
7 | -- it under the terms of the GNU General Public License as published by
8 | -- the Free Software Foundation, either version 3 of the License, or
9 | -- (at your option) any later version.
10 | --
11 | -- Cardpeek is distributed in the hope that it will be useful,
12 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | -- GNU General Public License for more details.
15 | --
16 | -- You should have received a copy of the GNU General Public License
17 | -- along with Cardpeek. If not, see .
18 | --
19 | -- @description Get card ATR (Answer To Reset)
20 | -- @targets 0.8
21 |
22 | require('lib.apdu')
23 |
24 | if card.connect() then
25 | card.tree_startup("ATR")
26 | card.disconnect()
27 | end
28 |
--------------------------------------------------------------------------------
/lua_iconv.h:
--------------------------------------------------------------------------------
1 | /**********************************************************************
2 | *
3 | * This file is part of Cardpeek, the smart card reader utility.
4 | *
5 | * Copyright 2009-2014 by Alain Pannetrat
6 | *
7 | * Cardpeek is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * Cardpeek is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with Cardpeek. If not, see .
19 | *
20 | */
21 | #ifndef LUA_ICONV_H
22 | #define LUA_ICONV_H
23 |
24 | #include
25 |
26 | int luaopen_iconv(lua_State* L);
27 |
28 | #endif
29 |
--------------------------------------------------------------------------------
/ui/console/console_about.h:
--------------------------------------------------------------------------------
1 | /**********************************************************************
2 | *
3 | * This file is part of Cardpeek, the smart card reader utility.
4 | *
5 | * Copyright 2009-2014 by Alain Pannetrat
6 | *
7 | * Cardpeek is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * Cardpeek is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with Cardpeek. If not, see .
19 | *
20 | */
21 |
22 | #ifndef _CONSOLE_ABOUT_H_
23 | #define _CONSOLE_ABOUT_H_
24 |
25 | void console_about(void);
26 |
27 | #endif
28 |
--------------------------------------------------------------------------------
/compile-cardpeek.sh:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 | # Created @ 13.01.2015 by Christian Mayer
3 |
4 |
5 | # You also need to install DBus:
6 | # https://gist.github.com/TheFox/dc3f1b88757ba0a8a7a9
7 | #1. Xcode 4.6.2 Command Line Tools.
8 | #2. Homebrew (http://mxcl.github.io/homebrew/), used to install libgtk+, liblua and libssl.
9 | #3. XQuartz (http://xquartz.macosforge.org/).
10 |
11 | # Install 'gnome-icon-theme' for GTK+ 3.
12 | brew install gnome-icon-theme
13 | brew install openssl
14 | brew link openssl --force
15 | brew install glib
16 | brew install gtk+3
17 | brew install curl
18 | brew install lua
19 |
20 | # Check out the source.
21 | pwd
22 |
23 | # Create files for compiling.
24 | autoreconf -fi
25 |
26 | # './configure' may fail with
27 | # Package 'xyz', required by 'abc', not found
28 | # So we need to set the path for PkgConfig.
29 | export PKG_CONFIG_PATH=/opt/X11/lib/pkgconfig
30 | ./configure
31 |
32 | # Compile.
33 | make
34 |
35 | # Alternatively you can install
36 | # cardpeek into your system.
37 | #make install
38 |
--------------------------------------------------------------------------------
/lua_card.h:
--------------------------------------------------------------------------------
1 | /**********************************************************************
2 | *
3 | * This file is part of Cardpeek, the smart card reader utility.
4 | *
5 | * Copyright 2009-2014 by Alain Pannetrat
6 | *
7 | * Cardpeek is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * Cardpeek is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with Cardpeek. If not, see .
19 | *
20 | */
21 | #ifndef LUA_CARD_H
22 |
23 | #include
24 |
25 | int luaopen_card(lua_State* L);
26 |
27 | int luax_card_reset_values(lua_State *L);
28 |
29 | #endif
30 |
--------------------------------------------------------------------------------
/ui/console/console_core.h:
--------------------------------------------------------------------------------
1 | /**********************************************************************
2 | *
3 | * This file is part of Cardpeek, the smart card reader utility.
4 | *
5 | * Copyright 2009-2014 by Alain Pannetrat
6 | *
7 | * Cardpeek is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * Cardpeek is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with Cardpeek. If not, see .
19 | *
20 | */
21 |
22 | #ifndef _CONSOLE_CORE_H_
23 | #define _CONSOLE_CORE_H_
24 |
25 | #include "ui.h"
26 |
27 | ui_driver_t *ui_driver_for_console(void);
28 |
29 | #endif
30 |
--------------------------------------------------------------------------------
/dot_cardpeek_dir/scripts/lib/network_codes.lua:
--------------------------------------------------------------------------------
1 | NETWORK_CODES = {
2 | -- ------------------------------------------------------------------------
3 | -- Belgium
4 | -- ------------------------------------------------------------------------
5 | [56] = {
6 | [1] = "Brussels",
7 | },
8 | -- ------------------------------------------------------------------------
9 | -- France
10 | -- ------------------------------------------------------------------------
11 | [250] = {
12 | [000] = "Nord-Pas-de-Calais",
13 | [502] = "Rhône-Alpes",
14 | [901] = "Île-de-France",
15 | [920] = "Provence-Alpes-Côte d'Azur",
16 | [921] = "Aquitaine",
17 | },
18 | }
19 |
20 | function network_code_name(cc, network_code)
21 | local country_network_codes = NETWORK_CODES[cc]
22 | if country_network_codes then
23 | local network_name = country_network_codes[network_code]
24 | if network_name then
25 | return network_name
26 | end
27 | end
28 | return tostring(network_code)
29 | end
30 |
--------------------------------------------------------------------------------
/system_info.h:
--------------------------------------------------------------------------------
1 | /**********************************************************************
2 | *
3 | * This file is part of Cardpeek, the smart card reader utility.
4 | *
5 | * Copyright 2009-2014 by Alain Pannetrat
6 | *
7 | * Cardpeek is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * Cardpeek is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with Cardpeek. If not, see .
19 | *
20 | */
21 | #ifndef SYSTEM_INFO_H
22 |
23 | const char *system_type(void);
24 |
25 | const char *system_string_info(void);
26 |
27 | unsigned int system_name_hash(void);
28 |
29 | #endif
30 |
--------------------------------------------------------------------------------
/cardpeek_update.h:
--------------------------------------------------------------------------------
1 | /**********************************************************************
2 | *
3 | * This file is part of Cardpeek, the smart card reader utility.
4 | *
5 | * Copyright 2009-2014 by Alain Pannetrat
6 | *
7 | * Cardpeek is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * Cardpeek is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with Cardpeek. If not, see .
19 | *
20 | */
21 |
22 | #ifndef _CARDPEEK_UPDATE_H
23 | #define _CARDPEEK_UPDATE_H
24 |
25 | int cardpeek_update_check(void);
26 |
27 | int cardpeek_update_perform(void);
28 |
29 | #endif /* _CARDPEEK_UPDATE_H_ */
30 |
--------------------------------------------------------------------------------
/cardpeek_resources.gresource:
--------------------------------------------------------------------------------
1 | /**********************************************************************
2 | *
3 | * This file is part of Cardpeek, the smartcard reader utility.
4 | *
5 | * Copyright 2009i-2013 by 'L1L1'
6 | *
7 | * Cardpeek is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * Cardpeek is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with Cardpeek. If not, see .
19 | *
20 | */
21 |
22 |
23 | #ifndef __RESOURCE_cardpeek_resources_H__
24 | #define __RESOURCE_cardpeek_resources_H__
25 |
26 | #include
27 |
28 | extern GResource *cardpeek_resources_get_resource (void);
29 |
30 |
31 | #endif
32 |
--------------------------------------------------------------------------------
/doc/navigo.md:
--------------------------------------------------------------------------------
1 | How to read the content of your Navigo Pass?
2 | ============================================
3 |
4 | 
5 |
6 | The "calypso" script included in **cardpeek** can read the content of Navigo cards used in Paris. It provides enhanced "event log" analysis notably with subway/train station names, as illustrated in the screenshot above. It has been successfully tested on Navigo Découverte, Navigo and Navigo Intégrale cards.
7 |
8 | ## Notes
9 |
10 | You must use the contact interface to read a Navigo card (or a special contactless reader), because they cannot be read with a normal conctactless card-reader (these cards use a specific protocol that is not fully compatible with ISO 14443 B).
11 |
12 | ## Privacy notes
13 |
14 | These transport cards keep an "event log" describing at least 3 of the last stations/stops you have been through. This "event log", which could pose a privacy risk, is not protected by any access control means and is freely readable.
15 | Note however that your name does not appear on the card (to our best knowledge), as opposed to the MOBIB card in Brussels.
16 |
--------------------------------------------------------------------------------
/ui/gtk/gui_core.h:
--------------------------------------------------------------------------------
1 | /**********************************************************************
2 | *
3 | * This file is part of Cardpeek, the smart card reader utility.
4 | *
5 | * Copyright 2009-2014 by Alain Pannetrat
6 | *
7 | * Cardpeek is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * Cardpeek is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with Cardpeek. If not, see .
19 | *
20 | */
21 |
22 | #ifndef GUI_CORE_H
23 | #define GUI_CORE_H
24 |
25 | #include "ui.h"
26 |
27 | ui_driver_t *ui_driver_for_gtk(void);
28 |
29 | #include
30 |
31 | extern GtkWidget *MAIN_WINDOW;
32 |
33 | #endif
34 |
--------------------------------------------------------------------------------
/ui/gtk/gui_scratchpad.h:
--------------------------------------------------------------------------------
1 | /**********************************************************************
2 | *
3 | * This file is part of Cardpeek, the smart card reader utility.
4 | *
5 | * Copyright 2009-2013 by Alain Pannetrat
6 | *
7 | * Cardpeek is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * Cardpeek is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with Cardpeek. If not, see .
19 | *
20 | */
21 |
22 | #ifndef GUI_SCRATCHPAD_H
23 | #define GUI_SCRATCHPAD_H
24 |
25 | #include
26 |
27 | GtkWidget *gui_scratchpad_create_window(void);
28 |
29 | void gui_scratchpad_cleanup(void);
30 |
31 | #endif
32 |
--------------------------------------------------------------------------------
/cardpeek_resources.gresource.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | dot_cardpeek.tar.gz
5 | icons/cardpeek-analyzer.png
6 | icons/cardpeek-application.png
7 | icons/cardpeek-block.png
8 | icons/cardpeek-record.png
9 | icons/cardpeek-logo.png
10 | icons/cardpeek-file.png
11 | icons/cardpeek-folder.png
12 | icons/cardpeek-item.png
13 | icons/cardpeek-smartcard.png
14 | icons/cardpeek-atr.png
15 | icons/cardpeek-header.png
16 | icons/cardpeek-body.png
17 | icons/image-missing.png
18 | AUTHORS
19 |
20 |
21 |
--------------------------------------------------------------------------------
/ui/gtk/gui_logview.h:
--------------------------------------------------------------------------------
1 | /**********************************************************************
2 | *
3 | * This file is part of Cardpeek, the smart card reader utility.
4 | *
5 | * Copyright 2009-2013 by Alain Pannetrat
6 | *
7 | * Cardpeek is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * Cardpeek is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with Cardpeek. If not, see .
19 | *
20 | */
21 |
22 | #ifndef GUI_LOGVIEW_H
23 | #define GUI_LOGVIEW_H
24 |
25 | #include
26 |
27 | GtkWidget *gui_logview_create_window(void);
28 |
29 | GtkWidget *gui_logview_create_status_bar(void);
30 |
31 | void gui_logview_cleanup(void);
32 |
33 | #endif
34 |
--------------------------------------------------------------------------------
/README.fr.md:
--------------------------------------------------------------------------------
1 | A propos de Cardpeek
2 | ====================
3 |
4 | _([English version](README.md))_
5 |
6 | Cardpeek est un outil de lecture de carte à puce avec une interface graphique basée sur GTK, fonctionnant sous GNU Linux/Windows/Mac OS X et extensible par le langage de programmation LUA.
7 |
8 | Cardpeek est un outil qui a pour objectif de vous permettre d’accéder aux informations personnelles qui sont stockées dans vos carte à puce. Vous pouvez ainsi être mieux informé des données qui sont collectées sur vous.
9 |
10 | Dans cette version, l’application est capable de lire le contenu des cartes suivantes :
11 |
12 | * Les cartes à puce bancaires [EMV](doc/emv.fr.md), dont les cartes NFC - _[capture d'écran](doc/sample-emv.jpg)_
13 | * Les cartes de transport de Paris / Île de France [Navigo](doc/navigo.fr.md), ainsi que MOBIB (Belgique) et RavKav (Israel) - _[capture d'écran](doc/sample-navigo.jpg)_
14 | * Les cartes Monéo
15 | * Les cartes Vitales 2
16 | * Les passports électroniques/biométriques avec une sécurité BAC.
17 | * La carte d'identité belge (eID)
18 | * Les cartes SIM GSM (beta)
19 | * Les cartes Mifare (beta)
20 | * Les cartes conducteur tachygraphes
21 | * Les cartes OpenPGP (beta)
22 |
--------------------------------------------------------------------------------
/doc/emv.md:
--------------------------------------------------------------------------------
1 | # How can I read the contents of my EMV bank card? #
2 |
3 | 
4 |
5 | The « emv » script in **cardpeek** provides an analysis of EMV banking cards used across the
6 | world.
7 |
8 | # Notes #
9 |
10 | This script will ask you if you want to issue a Get Processing Option (GPO)
11 | command for each application on the card. Since some cards have several applications
12 | (e.g. a national and an international application), this question may be asked twice or
13 | more. This command is needed to allow access to some information in the card. Issuing this command will also increase an internal counter inside the card (the ATC).
14 |
15 | # Notes on privacy #
16 |
17 | You will notice that many of these bank cards keep a \transaction log" of the last
18 | transactions you have made with your card. Some banks cards keep way over a hundred
19 | transactions that are freely readable, containing the date, the amount and the country of the transaction, which brings up some privacy issues. Why do banks need to keep so much information in the card?
20 |
21 | The security elements in the card, such as the PIN and the cryptographic keys are protected in the card and cannot be read.
--------------------------------------------------------------------------------
/doc/emv.fr.md:
--------------------------------------------------------------------------------
1 | # How can I read the contents of my EMV bank card? #
2 |
3 | 
4 |
5 | The "emv" script in **cardpeek** provides an analysis of EMV banking cards used across the
6 | world.
7 |
8 | # Notes #
9 |
10 | This script will ask you if you want to issue a Get Processing Option (GPO)
11 | command for each application on the card. Since some cards have several applications
12 | (e.g. a national and an international application), this question may be asked twice or
13 | more. This command is needed to allow access to some information in the card. Issuing this command will also increase an internal counter inside the card (the ATC).
14 |
15 | # Notes on privacy #
16 |
17 | You will notice that many of these bank cards keep a \transaction log" of the last
18 | transactions you have made with your card. Some banks cards keep way over a hundred
19 | transactions that are freely readable, containing the date, the amount and the country of the transaction, which brings up some privacy issues. Why do banks need to keep so much information in the card?
20 |
21 | The security elements in the card, such as the PIN and the cryptographic keys are fully protected in the card and cannot be read.
--------------------------------------------------------------------------------
/lua_bytes.h:
--------------------------------------------------------------------------------
1 | /**********************************************************************
2 | *
3 | * This file is part of Cardpeek, the smart card reader utility.
4 | *
5 | * Copyright 2009-2013 by Alain Pannetrat
6 | *
7 | * Cardpeek is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * Cardpeek is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with Cardpeek. If not, see .
19 | *
20 | */
21 | #ifndef LUA_BYTES_H
22 |
23 | #include
24 | #include "bytestring.h"
25 |
26 | int luaopen_bytes(lua_State* L);
27 |
28 | bytestring_t* luaL_check_bytestring(lua_State *L, int p);
29 |
30 | int luaL_is_bytestring(lua_State *L, int p);
31 |
32 | void lua_push_bytestring(lua_State *L, bytestring_t* bs);
33 |
34 | #endif
35 |
--------------------------------------------------------------------------------
/osx/Info-cardpeek.plist.in:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | CFBundleDevelopmentRegion
6 | English
7 | CFBundleExecutable
8 | cardpeek
9 | CFBundleGetInfoString
10 | Cardpeek @PACKAGE_VERSION@, (C) Alain Pannetrat, http://pannetrat.com/Cardpeek
11 | CFBundleIconFile
12 | cardpeek.icns
13 | CFBundleIdentifier
14 | com.pannetrat.cardpeek
15 | CFBundleInfoDictionaryVersion
16 | 6.0
17 | CFBundlePackageType
18 | APPL
19 | CFBundleShortVersionString
20 | @PACKAGE_VERSION@
21 | CFBundleSignature
22 | ????
23 | CFBundleVersion
24 | @PACKAGE_VERSION@
25 | NSHumanReadableCopyright
26 | Copyright Alain Pannetrat, GNU General Public License.
27 | LSMinimumSystemVersion
28 | 10.4
29 |
30 |
31 |
--------------------------------------------------------------------------------
/ui/gtk/gui_cardview.h:
--------------------------------------------------------------------------------
1 | /**********************************************************************
2 | *
3 | * This file is part of Cardpeek, the smart card reader utility.
4 | *
5 | * Copyright 2009-2013 by Alain Pannetrat
6 | *
7 | * Cardpeek is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * Cardpeek is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with Cardpeek. If not, see .
19 | *
20 | */
21 |
22 | #ifndef GUI_CARDVIEW_H
23 | #define GUI_CARDVIEW_H
24 |
25 | #include
26 | #include "dyntree_model.h"
27 |
28 | DyntreeModel* gui_cardview_get_store(void);
29 |
30 | GtkWidget *gui_cardview_create_window(GtkAccelGroup *accel_group);
31 |
32 | void gui_cardview_expand_all(void);
33 |
34 | void gui_cardview_cleanup(void);
35 |
36 | #endif
37 |
--------------------------------------------------------------------------------
/ui/gtk/gui_inprogress.h:
--------------------------------------------------------------------------------
1 | /**********************************************************************
2 | *
3 | * This file is part of Cardpeek, the smart card reader utility.
4 | *
5 | * Copyright 2009-2014 by Alain Pannetrat
6 | *
7 | * Cardpeek is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * Cardpeek is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with Cardpeek. If not, see .
19 | *
20 | */
21 |
22 | #ifndef GUI_INPROGRESS_H
23 | #define GUI_INPROGRESS_H
24 |
25 | #include
26 |
27 | void* gui_inprogress_new(const char *title, const char *message);
28 |
29 | unsigned gui_inprogress_pulse(void *pulser);
30 |
31 | unsigned gui_inprogress_set_fraction(void *pulser, gdouble level);
32 |
33 | void gui_inprogress_free(void *pulser);
34 |
35 | #endif
36 |
--------------------------------------------------------------------------------
/ui/console/console_inprogress.h:
--------------------------------------------------------------------------------
1 | /**********************************************************************
2 | *
3 | * This file is part of Cardpeek, the smart card reader utility.
4 | *
5 | * Copyright 2009-2014 by Alain Pannetrat
6 | *
7 | * Cardpeek is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * Cardpeek is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with Cardpeek. If not, see .
19 | *
20 | */
21 |
22 | #ifndef _CONSOLE_INPROGRESS_H_
23 | #define _CONSOLE_INPROGRESS_H_
24 |
25 | void *console_inprogress_new(const char *title, const char *message);
26 |
27 | unsigned console_inprogress_pulse(void *pulser);
28 |
29 | unsigned console_inprogress_set_fraction(void *pulser, double level);
30 |
31 | void console_inprogress_free(void *pulser);
32 |
33 | #endif
34 |
--------------------------------------------------------------------------------
/AUTHORS:
--------------------------------------------------------------------------------
1 | Cardpeek is (c) 2009-2014 Alain Pannetrat
2 |
3 |
4 | Kind contributors:
5 | - Anthony Berkow: Calypso script for the RavKav card in Israel.
6 | - Stanislav Brabec: Intial patch for LUA 5.2 upgrade and GSM script improvements.
7 | - Stephane Dorte: Helped by providing some tachograph card CLF dumps and logs.
8 | - Patrick Gueulle: Suggested an extended list of file IDs for Calypso and corrections for GPO handling in EMV cards.
9 | - Andreas Heiduk: Author of the OpenPGP script.
10 | - Andrew R. Kozlik: Many enhancements to parsing capabilities of the EMV script, added AIDs, added GPO format 1.
11 | - Ludovic Lange: Initial patch for Mac OS X version.
12 | - Adam Laurie: CVM parsing in EMV.
13 | - Kalev Lember: Bug and compatibility fixes.
14 | - Kalon33: Initial data for Gironde/Grenoble Calypso cards.
15 | - David Ludovino, Duarte Barbosa and Rafael Santos: Authors of Calypso script for the Lisboa Viva card.
16 | - Darius Matboo: Human friendly data parsing for Moneo.
17 | - Ludovic Rousseau: Lots of code cleanup, better use of autotools.
18 | - Nicolas Salguero: Upgraded Mifare script to new API.
19 | - Pascal Terjan: Paris metro/RER name decoding and bug fixes.
20 | - and a few anonymous contributors...
21 |
22 | This software uses the smartcard_list.txt (c) from Ludovic Rousseau.
23 |
--------------------------------------------------------------------------------
/doc/build-windows.md:
--------------------------------------------------------------------------------
1 | Build on Windows
2 | ================
3 |
4 | **!!! Produced binaries do not run yet - See [issue #1](https://github.com/ipamo/cardpeek/issues/1) !!!**
5 |
6 | ## Pre-requisites
7 |
8 | Download and install [msys2](https://www.msys2.org/), which provide gcc toolchains for 32-bit and 64-bit Windows (both powered by MinGW-w64).
9 |
10 | ## Build for 32-bit Windows
11 |
12 | Open a 32-bit mingw shell (usually `C:\msys64\mingw32.exe`).
13 |
14 | Install dependencies:
15 |
16 | pacman -S tar make pkg-config mingw32/mingw-w64-i686-gcc mingw32/mingw-w64-i686-gtk3 mingw32/mingw-w64-i686-lua mingw32/mingw-w64-i686-curl
17 |
18 | Clean:
19 |
20 | ./clean.sh
21 |
22 | Build:
23 |
24 | make -f Makefile.win32
25 | make install -f Makefile.win32
26 |
27 | ## Build for 64-bit Windows
28 |
29 | Open a 64-bit mingw shell (usually `C:\msys64\mingw64.exe`).
30 |
31 | Install dependencies:
32 |
33 | pacman -S tar make pkg-config mingw64/mingw-w64-x86_64-gcc mingw64/mingw-w64-x86_64-gtk3 mingw64/mingw-w64-x86_64-lua mingw64/mingw-w64-x86_64-curl
34 |
35 | Clean:
36 |
37 | ./clean.sh
38 |
39 | Build:
40 |
41 | make -f Makefile.win32 DEPS=/mingw64 MPLATFORM=mingw64 TARGET="/C/Program Files/Cardpeek"
42 | make install -f Makefile.win32 DEPS=/mingw64 MPLATFORM=mingw64 TARGET="/C/Program Files/Cardpeek"
43 |
--------------------------------------------------------------------------------
/doc/navigo.fr.md:
--------------------------------------------------------------------------------
1 | Comment lire le contenu de son Pass Navigo ?
2 | ============================================
3 |
4 | 
5 |
6 | Le script "calypso" inclu dans **cardpeek** permet de lire le contenu des cartes "Navigo" utilisées en région parisienne. Cet outil offre une analyse améliorée des "journaux d'évènements" de la carte affichant notamment le nom des stations de métro/RER où la carte a été utilisée. Cet outil a été testé avec succès sur les cartes Navigo Découverte, Navigo et Navigo Intégrale.
7 |
8 | ## Notes
9 |
10 | Il faut utiliser **cardpeek** avec un lecteur de carte à puce à contact pour lire le contenu d'une carte "navigo" (ou un lecteur sans contact spécialisé). En effet, les cartes "navigo" ne peuvent pas êtres lues avec des lecteurs sans contact _classiques_ (car elles utilisent un protocole de communication radio qui n'est pas totalement compatible avec l'ISO 14443 B).
11 |
12 | ## Protection de la vie privée
13 |
14 | Ces cartes de transport conservent un "journal d'évènement" décrivant les 3 dernières validations effectuées par le porteur de la carte. Ce journal, qui peut poser un risque pour la protection de la vie privée, n'est pas protégé en lecture.
15 | Par contre le nom du porteur de la carte n'est pas, selon nos analyses, accessible en lisant la carte. En revanche, c'est le cas pour la carte MOBIB utilsée à Bruxelles.
16 |
--------------------------------------------------------------------------------
/dot_cardpeek_dir/scripts/lib/strict.lua:
--------------------------------------------------------------------------------
1 | ------------------------------------------------------------
2 | -- NOTE: This file was taken from the LUA 5.1 distribution
3 | -- It is public domain
4 | ------------------------------------------------------------
5 |
6 | --
7 | -- strict.lua
8 | -- checks uses of undeclared global variables
9 | -- All global variables must be 'declared' through a regular assignment
10 | -- (even assigning nil will do) in a main chunk before being used
11 | -- anywhere or assigned to inside a function.
12 | --
13 |
14 |
15 | local mt = getmetatable(_G)
16 | if mt == nil then
17 | mt = {}
18 | setmetatable(_G, mt)
19 | end
20 |
21 | __STRICT = true
22 | mt.__declared = {}
23 |
24 | mt.__newindex = function (t, n, v)
25 | if __STRICT and not mt.__declared[n] and not string.sub(n,1,2) == "__" then
26 | local w = debug.getinfo(2, "S").what
27 | if w ~= "main" and w ~= "C" then
28 | error("assign to undeclared variable '"..n.."'", 2)
29 | end
30 | mt.__declared[n] = true
31 | end
32 | rawset(t, n, v)
33 | end
34 |
35 | mt.__index = function (t, n)
36 | if not mt.__declared[n] and string.sub(n,1,2) ~= "__" and debug.getinfo(2, "S").what ~= "C" then
37 | error("variable '"..n.."' is not declared", 2)
38 | end
39 | return rawget(t, n)
40 | end
41 |
42 | function global(...)
43 | for _, v in ipairs{...} do mt.__declared[v] = true end
44 | end
45 |
--------------------------------------------------------------------------------
/ui/gtk/gui_readerview.h:
--------------------------------------------------------------------------------
1 | /**********************************************************************
2 | *
3 | * This file is part of Cardpeek, the smart card reader utility.
4 | *
5 | * Copyright 2009-2013 by Alain Pannetrat
6 | *
7 | * Cardpeek is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * Cardpeek is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with Cardpeek. If not, see .
19 | *
20 | */
21 |
22 | #ifndef GUI_READERVIEW_H
23 | #define GUI_READERVIEW_H
24 |
25 | #include
26 | #include "bytestring.h"
27 |
28 | void gui_readerview_print(unsigned event,
29 | const bytestring_t *command,
30 | unsigned short sw,
31 | const bytestring_t *response,
32 | void *extra_data);
33 |
34 | GtkWidget *gui_readerview_create_window(void);
35 |
36 | void gui_readerview_cleanup(void);
37 |
38 | #endif
39 |
--------------------------------------------------------------------------------
/ui/gtk/gui_toolbar.h:
--------------------------------------------------------------------------------
1 | /**********************************************************************
2 | *
3 | * This file is part of Cardpeek, the smart card reader utility.
4 | *
5 | * Copyright 2009-2013 by Alain Pannetrat
6 | *
7 | * Cardpeek is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * Cardpeek is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with Cardpeek. If not, see .
19 | *
20 | */
21 |
22 | #ifndef GUI_TOOLBAR_H
23 | #define GUI_TOOLBAR_H
24 |
25 | #include
26 |
27 | typedef struct {
28 | const gchar *id;
29 | const gchar *icon;
30 | const gchar *text;
31 | GCallback callback;
32 | gconstpointer callback_data;
33 | const gchar *tooltip;
34 | } toolbar_item_t;
35 |
36 | #define TOOLBAR_ITEM_SEPARATOR "separator"
37 | #define TOOLBAR_ITEM_EXPANDER "expander"
38 |
39 | GtkWidget *gui_toolbar_new(toolbar_item_t *tbitems);
40 |
41 | void gui_toolbar_run_command_cb(GtkWidget *w, gconstpointer user_data);
42 |
43 | #endif
44 |
--------------------------------------------------------------------------------
/cardpeek.appdata.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | cardpeek.desktop
5 | CC-BY-SA-3.0
6 | GPL-3.0+
7 | Cardpeek
8 | A tool to read the content of smart cards
9 |
10 |
11 | Cardpeek is a cross-platform graphical tool to read the contents of smart cards, including:
12 |
13 | - Bank cards with a chip (EMV);
14 | - Electronic/biometric passports;
15 | - Transport cards from Paris (Navigo), Brussels (Mobib), Lisbon (VIVA) and Israel (RavKav);
16 | - GSM SIM cards;
17 | - Vitale 2, the French health card;
18 | - Moneo, the French electronic purse;
19 | - Driver Tachograph cards;
20 | - OpenPGP Cards (beta);
21 | - Mifare classic;
22 |
23 |
24 |
25 | It features a GTK GUI to represent card data is a tree view, and is extensible with a scripting language (LUA).
26 |
27 |
28 | The goal of this project is to allow smart card owners to be better informed about what type of personal information is stored in these devices.
29 |
30 |
31 |
32 |
33 | http://4.bp.blogspot.com/-iu2fS_ovwj8/UIqPFKy31lI/AAAAAAAAHx0/WM1qPUbUzxo/s1600/cardpeek+record.png
34 | Reading the content of a bank card.
35 |
36 |
37 | http://pannetrat.com/Cardpeek/
38 | l1l1_at_gmx.com
39 |
40 |
--------------------------------------------------------------------------------
/doc/build-debian.md:
--------------------------------------------------------------------------------
1 | Build instructions for Debian 9 (Stretch)
2 | =========================================
3 |
4 | **!!! Produced binaries do not run yet - See [issue #1](https://github.com/ipamo/cardpeek/issues/1) !!!**
5 |
6 | ## For local Debian host
7 |
8 | Required libraries:
9 |
10 | sudo apt install autoconf make libglib2.0-dev libgtk-3-dev liblua5.2-dev libcurl4-openssl-dev libssl-dev
11 |
12 | Build:
13 |
14 | autoreconf --install
15 | ./configure
16 | make
17 |
18 | Install (use sudo if necessary):
19 |
20 | make install
21 |
22 |
23 | ## Cross-compile for Windows (32 bits)
24 |
25 | Requirements:
26 |
27 | sudo apt install libpcsclite1:i386 dirmngr mingw-w64 mingw-w64-tools binutils-mingw-w64
28 |
29 | Download mingw-W64 package dependencies either from a Windows MSys2 installation, or directly from [MSys2 repository](http://repo.msys2.org/mingw/i686/),
30 | unpack the packages and merge them into a new directory called `deps/win32` (which will then contain subdirectories `bin`, `lib`, `include`, etc):
31 |
32 | ./deps-win32.sh
33 |
34 | Build:
35 |
36 | make -f Makefile.win32 CCPRE=i686-w64-mingw32- DEPS=deps/win32 TARGET=/opt/cardpeek-win32
37 |
38 | Install:
39 |
40 | make install -f Makefile.win32 CCPRE=i686-w64-mingw32- DEPS=deps/win32 TARGET=/opt/cardpeek-win32
41 |
42 | Run:
43 |
44 | wine build/win32/cardpeek.exe
45 |
46 |
47 | ## Cross-compile for Windows (64 bits)
48 |
49 | Adapt previous commands as follow
50 |
51 | ./clean.sh
52 | PLATFORM=win64 ./deps-win32.sh
53 | make -f Makefile.win32 CCPRE=x86_64-w64-mingw32- DEPS=deps/win64 MPLATFORM=mingw64 TARGET=/opt/cardpeek-win64
54 | make install -f Makefile.win32 CCPRE=x86_64-w64-mingw32- DEPS=deps/win64 MPLATFORM=mingw64 TARGET=/opt/cardpeek-win64
55 |
--------------------------------------------------------------------------------
/dot_cardpeek_dir/scripts/lib/calypso_card_num.lua:
--------------------------------------------------------------------------------
1 | --
2 | -- This file is part of Cardpeek, the smart card reader utility.
3 | --
4 | -- Copyright 2009-2013 by Alain Pannetrat
5 | --
6 | -- Cardpeek is free software: you can redistribute it and/or modify
7 | -- it under the terms of the GNU General Public License as published by
8 | -- the Free Software Foundation, either version 3 of the License, or
9 | -- (at your option) any later version.
10 | --
11 | -- Cardpeek is distributed in the hope that it will be useful,
12 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | -- GNU General Public License for more details.
15 | --
16 | -- You should have received a copy of the GNU General Public License
17 | -- along with Cardpeek. If not, see .
18 | --
19 | --********************************************************************--
20 | --
21 | --
22 | --
23 | --********************************************************************--
24 |
25 | -----------------------------------------------------------
26 | -- calypso_card_num : Reads card number from ATR and
27 | -- writes it in the tree in decimal format.
28 | -----------------------------------------------------------
29 | function calypso_card_num()
30 | local atr
31 | local hex_card_num
32 | local card_num
33 |
34 | atr = card.last_atr();
35 | hex_card_num = bytes.sub(atr,-7,-4)
36 | card_num = (hex_card_num:get(0)*256*65536)+(hex_card_num:get(1)*65536)+(hex_card_num:get(2)*256)+hex_card_num:get(3)
37 |
38 | CARD:find_first({ label = "cold ATR" } )
39 | :append{ classname = "item",
40 | label = "card number",
41 | size = 4,
42 | val = hex_card_num,
43 | alt = card_num }
44 | end
45 |
--------------------------------------------------------------------------------
/asn1.h:
--------------------------------------------------------------------------------
1 | /**********************************************************************
2 | *
3 | * This file is part of Cardpeek, the smart card reader utility.
4 | *
5 | * Copyright 2009-2013 by Alain Pannetrat
6 | *
7 | * Cardpeek is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * Cardpeek is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with Cardpeek. If not, see .
19 | *
20 | */
21 |
22 | #ifndef ASN1_H
23 | #define ASN1_H
24 |
25 | #include "bytestring.h"
26 |
27 |
28 | int asn1_force_single_byte_length_parsing(int enable);
29 |
30 | int asn1_skip_tlv(unsigned* pos, const bytestring_t* tlvlist);
31 |
32 | int asn1_decode_tag(unsigned* pos, const bytestring_t* tlv, unsigned* tag);
33 |
34 | int asn1_decode_length(unsigned* pos, const bytestring_t* tlv, unsigned* len);
35 |
36 | int asn1_skip_value(unsigned* pos, const bytestring_t* lv);
37 |
38 | int asn1_decode_value(unsigned* pos, const bytestring_t* lv, bytestring_t* val);
39 |
40 | int asn1_decode_tlv(unsigned* pos, const bytestring_t* tlv, unsigned *tag, bytestring_t* val);
41 |
42 | int asn1_encode_tag(unsigned tag, bytestring_t* bertag);
43 |
44 | int asn1_encode_tlv(unsigned tag, const bytestring_t* val, bytestring_t* bertlv);
45 |
46 | int asn1_parse_path(const char* path, const bytestring_t* src, bytestring_t* val);
47 |
48 | #endif
49 |
--------------------------------------------------------------------------------
/lua_log.c:
--------------------------------------------------------------------------------
1 | /**********************************************************************
2 | *
3 | * This file is part of Cardpeek, the smart card reader utility.
4 | *
5 | * Copyright 2009-2013 by Alain Pannetrat
6 | *
7 | * Cardpeek is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * Cardpeek is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with Cardpeek. If not, see .
19 | *
20 | */
21 | #include
22 | #include "lua_log.h"
23 | #include "misc.h"
24 |
25 | /***********************************************************
26 | * LOG FUNCTIONS
27 | */
28 |
29 | static int subr_log_print(lua_State* L)
30 | {
31 | int level = lua_tointeger(L,1);
32 | const char *message = luaL_checkstring(L,2);
33 | log_printf(level,"%s",message);
34 | return 0;
35 | }
36 |
37 | static const struct luaL_Reg loglib [] = {
38 | { "print", subr_log_print },
39 | { NULL, NULL} /* sentinel */
40 | };
41 |
42 | int luaopen_log(lua_State* L)
43 | {
44 | luaL_newlib(L,loglib);
45 | lua_pushstring(L,"DEBUG"); lua_pushinteger(L, LOG_DEBUG); lua_settable(L,-3);
46 | lua_pushstring(L,"INFO"); lua_pushinteger(L, LOG_INFO); lua_settable(L,-3);
47 | lua_pushstring(L,"WARNING"); lua_pushinteger(L, LOG_WARNING); lua_settable(L,-3);
48 | lua_pushstring(L,"ERROR"); lua_pushinteger(L, LOG_ERROR); lua_settable(L,-3);
49 | lua_setglobal(L, "log");
50 |
51 | return 1;
52 | }
53 |
54 |
55 |
--------------------------------------------------------------------------------
/ui/gtk/gui_flexi_cell_renderer.h:
--------------------------------------------------------------------------------
1 | #ifndef GUI_FLEXI_CELL_RENDERER_H
2 | #define GUI_FLEXI_CELL_RENDERER_H
3 |
4 | /* This file is WORK IN PROGRESS */
5 | /* it has not use in cardpeek yet */
6 |
7 |
8 | #include
9 | #include "a_string.h"
10 |
11 | #define CUSTOM_TYPE_CELL_RENDERER_FLEXI (custom_cell_renderer_flexi_get_type())
12 | #define CUSTOM_CELL_RENDERER_FLEXI(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), CUSTOM_TYPE_CELL_RENDERER_FLEXI, CustomCellRendererFlexi))
13 | #define CUSTOM_CELL_RENDERER_FLEXI_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), CUSTOM_TYPE_CELL_RENDERER_FLEXI, CustomCellRendererFlexiClass))
14 | #define CUSTOM_IS_CELL_FLEXI_FLEXI(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), CUSTOM_TYPE_CELL_RENDERER_FLEXI))
15 | #define CUSTOM_IS_CELL_FLEXI_FLEXI_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), CUSTOM_TYPE_CELL_RENDERER_FLEXI))
16 | #define CUSTOM_CELL_RENDERER_FLEXI_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), CUSTOM_TYPE_CELL_RENDERER_FLEXI, CustomCellRendererFlexiClass))
17 |
18 | typedef struct _CustomCellRendererFlexi CustomCellRendererFlexi;
19 | typedef struct _CustomCellRendererFlexiClass CustomCellRendererFlexiClass;
20 |
21 | /* CustomCellRendererFlexi: Our custom cell renderer
22 | * structure. Extend according to need */
23 |
24 | struct _CustomCellRendererFlexi
25 | {
26 | GtkCellRenderer parent;
27 |
28 | gboolean is_raw;
29 | a_string_t *raw_value;
30 | a_string_t *alt_text;
31 | a_string_t *mime_type;
32 | unsigned rendered_type;
33 | gpointer rendered_value;
34 | int default_width;
35 | int default_line_height;
36 | };
37 |
38 |
39 | struct _CustomCellRendererFlexiClass
40 | {
41 | GtkCellRendererClass parent_class;
42 | };
43 |
44 | GType custom_cell_renderer_flexi_get_type (void);
45 |
46 | GtkCellRenderer *custom_cell_renderer_flexi_new (gboolean is_raw);
47 |
48 | #endif
49 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | Cardpeek
2 | ========
3 |
4 | ## About
5 |
6 | _([Version française](README.fr.md))_
7 |
8 | Cardpeek is a Linux/Windows/Mac OS X tool to read the contents of ISO7816 smart cards. It features a GTK GUI to represent card data in a tree view, and is extendable with a scripting language (LUA).
9 |
10 | The goal of this project is to allow smart card owners to be better informed about what type of personal information is stored in these devices.
11 |
12 | The tool currently reads the contents of :
13 |
14 | * [EMV](doc/emv.md) Pin and Chip cards, including NFC ones - _[screenshot](doc/sample-emv.jpg)_
15 | * [Navigo](doc/navigo.md) (Paris), MOBIB (Belgium), RavKav (Israel) and other public transport cards of the Calypso family - _[screenshot](doc/sample-navigo.jpg)_
16 | * The French health card "Vitale 2"
17 | * Electronic/Biometric passports in BAC security mode
18 | * GSM SIM cards (but not USIM data)
19 | * The Belgian eID card
20 | * Driver tachograph cards
21 | * OpenPGP cards (beta)
22 |
23 | It can also read the following cards with limited interpretation of data:
24 | * Some Mifare cards (such as the Thalys card)
25 | * Moneo, the French electronic purse
26 |
27 | ## Build
28 |
29 | **!!! Produced binaries do not run yet - See [issue #1](https://github.com/ipamo/cardpeek/issues/1) !!!**
30 |
31 | - [Build instructions for Debian](doc/build-debian.md), either for the local Debian host, or for cross-compilation to Windows using mingw-w64.
32 | - [Build instructions for Windows](doc/build-windows.md), using msys2.
33 | - [Specific instructions for FreeBSD](doc/build-freebsd.md) in case of errors.
34 |
35 | ## Usage
36 |
37 | The [Reference Manual](doc/cardpeek_ref.en.pdf) provides detailed usage instructions.
38 |
39 | ## Authors
40 |
41 | Written initially by Alain Pannetrat under the [GNU General Public License, version 3](COPYING), with the additional exemption that compiling, linking, and/or using OpenSSL is allowed.
42 |
43 | More info here: http://pannetrat.com/Cardpeek/
44 |
--------------------------------------------------------------------------------
/lua_ext.h:
--------------------------------------------------------------------------------
1 | /**********************************************************************
2 | *
3 | * This file is part of Cardpeek, the smart card reader utility.
4 | *
5 | * Copyright 2009-2014 by Alain Pannetrat
6 | *
7 | * Cardpeek is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * Cardpeek is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with Cardpeek. If not, see .
19 | *
20 | */
21 |
22 | #ifndef LUAX_H
23 | #define LUAX_H
24 |
25 | #include "smartcard.h"
26 | #include
27 |
28 | void luax_set_card_reader(cardreader_t* r);
29 |
30 | void luax_run_script(const char* scriptname);
31 |
32 | void luax_run_command(const char* command);
33 |
34 | int luax_init(void);
35 |
36 | void luax_release(void);
37 |
38 | char *luax_escape_string(const char *src);
39 |
40 | enum {
41 | LUAX_INIT_WITHOUT_UI=0,
42 | LUAX_INIT_WITH_UI=1
43 | };
44 |
45 | /*****/
46 |
47 | gboolean luax_config_table_save(void);
48 |
49 | char *luax_variable_get_strdup(const char *vname);
50 |
51 | gboolean luax_variable_set_strval(const char *vname, const char *value);
52 |
53 | int luax_variable_get_integer(const char *vname);
54 |
55 | gboolean luax_variable_set_integer(const char *vname, int value);
56 |
57 | gboolean luax_variable_get_boolean(const char *vname);
58 |
59 | gboolean luax_variable_set_boolean(const char *vname, gboolean value);
60 |
61 | gboolean luax_variable_is_defined(const char *vname);
62 |
63 | gboolean luax_variable_call(const char *vname, const char *format, ...);
64 |
65 | #endif
66 |
--------------------------------------------------------------------------------
/dot_cardpeek_dir/scripts/etc/brussels-metro.lua:
--------------------------------------------------------------------------------
1 | BRUSSELS_METRO =
2 | {
3 | [14658] = "De Brouckere",
4 | [14668] = "Gare Centrale",
5 | [14677] = "Park",
6 | [14687] = "Art-Loi",
7 | [14697] = "Maelbeek",
8 | [14707] = "Schuman",
9 | [14716] = "Merode",
10 | [14726] = "Montgomery",
11 | [14736] = "Josephine-Charlotte",
12 | [14746] = "Gribaumont",
13 | [14755] = "Tomberg",
14 | [14765] = "Roodebeek",
15 | [14775] = "Vandervelde",
16 | [14785] = "Alma",
17 | [14795] = "Crainhem",
18 | [14804] = "Stockel",
19 | [14912] = "Sainte Catherine",
20 | [14921] = "Comte de Flandres",
21 | [14931] = "Etangs Noirs",
22 | [17314] = "Gare de l'Ouest",
23 | [17324] = "Beekant",
24 | [24707] = "Trone",
25 | [24716] = "Porte de Namur",
26 | [24726] = "Louise",
27 | [24736] = "Hotel des Monnaies",
28 | [24746] = "Porte de Hal",
29 | [24755] = "Gare du Midi",
30 | [24765] = "Clemenceau",
31 | [24775] = "Delacroix",
32 | [24814] = "Madou",
33 | [24824] = "Botanique",
34 | [24834] = "Rogier",
35 | [24843] = "Yser",
36 | [24863] = "Ribaucourt",
37 | [27099] = "Osseghem",
38 | [27109] = "Simonis",
39 | [53906] = "Thieffry",
40 | [53916] = "Petillon",
41 | [53925] = "Hankar",
42 | [53935] = "Delta",
43 | [53945] = "Beaulieu",
44 | [53955] = "Demey",
45 | [53964] = "Hermann-Debroux",
46 | [56289] = "Erasme",
47 | [56299] = "Eddy Merckx",
48 | [56308] = "CERIA",
49 | [56318] = "La Roue",
50 | [56328] = "Bizet",
51 | [56337] = "Veeweyde",
52 | [56347] = "Saint Guidon",
53 | [56357] = "Aumale",
54 | [56367] = "Jacques Brel",
55 | [64732] = "Georges Henri",
56 | [64742] = "Diamant",
57 | [64820] = "Boileau",
58 | [66181] = "Belgica",
59 | [66191] = "Pannehuis",
60 | [66201] = "Bockstael",
61 | [66211] = "Stuyvenbergh",
62 | [66220] = "Houba-Brugmann",
63 | [66230] = "Heysel",
64 | [66240] = "Roi Baudouin",
65 | [93746] = "Gare du Nord",
66 | [93824] = "Bourse",
67 | [93833] = "Anneessens",
68 | [93843] = "Lemonnier",
69 | [93873] = "Parvis Saint Gilles",
70 | [93882] = "Horta",
71 | [93892] = "Albert"
72 | }
73 |
--------------------------------------------------------------------------------
/ui/console/console_inprogress.c:
--------------------------------------------------------------------------------
1 | /**********************************************************************
2 | *
3 | * This file is part of Cardpeek, the smart card reader utility.
4 | *
5 | * Copyright 2009-2014 by Alain Pannetrat
6 | *
7 | * Cardpeek is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * Cardpeek is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with Cardpeek. If not, see .
19 | *
20 | */
21 |
22 | #include
23 | #include
24 | #include
25 | #include "console_inprogress.h"
26 |
27 | char ascii_pulse[4] = { '|', '/', '-', '\\' };
28 |
29 | typedef struct {
30 | char *message;
31 | int pulse;
32 | } inprogress_t;
33 |
34 | void *console_inprogress_new(const char *title, const char *message)
35 | {
36 | inprogress_t *prog = g_malloc(sizeof(inprogress_t));
37 | prog->message = strdup(message);
38 | prog->pulse = 0;
39 | printf("%s:\n",title);
40 | console_inprogress_pulse(prog);
41 | return prog;
42 | }
43 |
44 | unsigned console_inprogress_pulse(void *pulser)
45 | {
46 | inprogress_t *prog = (inprogress_t *)pulser;
47 | printf("%s: %c\r",prog->message,ascii_pulse[prog->pulse%4]);
48 | prog->pulse++;
49 | return 1;
50 | }
51 |
52 | unsigned console_inprogress_set_fraction(void *pulser, double level)
53 | {
54 | inprogress_t *prog = (inprogress_t *)pulser;
55 | printf("%s: %3i\r",prog->message,(int)(level*100));
56 | return 1;
57 | }
58 |
59 | void console_inprogress_free(void *pulser)
60 | {
61 | printf("\n");
62 | g_free(pulser);
63 | }
64 |
65 |
66 |
--------------------------------------------------------------------------------
/drivers/null_driver.c:
--------------------------------------------------------------------------------
1 | /**********************************************************************
2 | *
3 | * This file is part of Cardpeek, the smartcard reader utility.
4 | *
5 | * Copyright 2009 by 'L1L1'
6 | *
7 | * Cardpeek is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * Cardpeek is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with Cardpeek. If not, see .
19 | *
20 | */
21 |
22 |
23 | static int null_error(cardreader_t *cr)
24 | {
25 | UNUSED(cr);
26 |
27 | log_printf(LOG_ERROR,"Operation failed: no connected reader selected");
28 | return 0;
29 | }
30 |
31 | static int null_connect(cardreader_t *cr, unsigned prefered_protocol)
32 | {
33 | UNUSED(prefered_protocol);
34 |
35 | return null_error(cr);
36 | }
37 |
38 | static unsigned short null_transmit(cardreader_t* cr,
39 | const bytestring_t* command,
40 | bytestring_t* result)
41 | {
42 | UNUSED(command);
43 | UNUSED(result);
44 |
45 | null_error(cr);
46 | return CARDPEEK_ERROR_SW;
47 | }
48 |
49 | static const bytestring_t* null_last_atr(cardreader_t* cr)
50 | {
51 | return cr->atr;
52 | }
53 |
54 | static int null_fail(cardreader_t* cr)
55 | {
56 | UNUSED(cr);
57 |
58 | return 1;
59 | }
60 |
61 | static void null_finalize(cardreader_t* cr)
62 | {
63 | /* null_error(cr); */
64 | }
65 |
66 | static int null_initialize(cardreader_t *reader)
67 | {
68 | reader->connect = null_connect;
69 | reader->disconnect = null_error;
70 | reader->reset = null_error;
71 | reader->transmit = null_transmit;
72 | reader->last_atr = null_last_atr;
73 | reader->fail = null_fail;
74 | reader->finalize = null_finalize;
75 | return 1;
76 | }
77 |
78 |
--------------------------------------------------------------------------------
/http_download.c:
--------------------------------------------------------------------------------
1 | #include "ui.h"
2 | #include "config.h"
3 | #include "misc.h"
4 | #include "a_string.h"
5 | #include "http_download.h"
6 | #include
7 | #include
8 | #include
9 | #include
10 |
11 | static int progress_download(void *clientp, double dltotal, double dlnow, double ultotal, double ulnow)
12 | {
13 | UNUSED(ultotal);
14 | UNUSED(ulnow);
15 |
16 | if (dltotal==0)
17 | return !ui_inprogress_pulse(clientp);
18 | return !ui_inprogress_set_fraction(clientp,dlnow/dltotal);
19 | }
20 |
21 |
22 | int http_download(const char *src_url, const char *dst_filename)
23 | {
24 | CURL *curl;
25 | CURLcode res;
26 | void *progress;
27 | a_string_t *user_agent;
28 | a_string_t *progress_title;
29 | FILE *temp_fd;
30 |
31 | curl = curl_easy_init();
32 |
33 | if (!curl)
34 | return 0;
35 |
36 | progress_title = a_strnew(NULL);
37 | a_sprintf(progress_title,"Updating %s",dst_filename);
38 |
39 | user_agent = a_strnew(NULL);
40 | a_sprintf(user_agent,"cardpeek/%s",VERSION);
41 |
42 | progress = ui_inprogress_new(a_strval(progress_title),"Please wait...");
43 |
44 | temp_fd = fopen(dst_filename,"wb");
45 |
46 | curl_easy_setopt(curl,CURLOPT_URL,src_url);
47 | curl_easy_setopt(curl,CURLOPT_WRITEDATA, temp_fd);
48 | curl_easy_setopt(curl,CURLOPT_USERAGENT, a_strval(user_agent));
49 | curl_easy_setopt(curl,CURLOPT_FAILONERROR, 1L);
50 | curl_easy_setopt(curl,CURLOPT_NOPROGRESS, 0L);
51 | curl_easy_setopt(curl,CURLOPT_PROGRESSFUNCTION, progress_download);
52 | curl_easy_setopt(curl,CURLOPT_PROGRESSDATA, progress);
53 | curl_easy_setopt(curl,CURLOPT_FOLLOWLOCATION, 1L);
54 |
55 | res = curl_easy_perform(curl);
56 |
57 | fclose(temp_fd);
58 |
59 | if (res!=CURLE_OK)
60 | {
61 | log_printf(LOG_ERROR,"Failed to fetch %s: %s", src_url, curl_easy_strerror(res));
62 | unlink(dst_filename);
63 | }
64 |
65 | curl_easy_cleanup(curl);
66 |
67 | ui_inprogress_free(progress);
68 |
69 | a_strfree(user_agent);
70 | a_strfree(progress_title);
71 |
72 | return (res==CURLE_OK);
73 | }
74 |
--------------------------------------------------------------------------------
/win32/winscard.def:
--------------------------------------------------------------------------------
1 | ;
2 | ; Definition file of WinSCard.dll
3 | ; Automatic generated by gendef
4 | ; written by Kai Tietz 2008
5 | ;
6 | LIBRARY "WinSCard.dll"
7 | EXPORTS
8 | ClassInstall32
9 | SCardAccessNewReaderEvent
10 | SCardPciRaw
11 | SCardPciT0
12 | SCardPciT1
13 | SCardReleaseAllEvents
14 | SCardReleaseNewReaderEvent
15 | SCardAccessStartedEvent
16 | SCardAddReaderToGroupA
17 | SCardAddReaderToGroupW
18 | SCardAudit
19 | SCardBeginTransaction
20 | SCardCancel
21 | SCardConnectA
22 | SCardConnectW
23 | SCardControl
24 | SCardDisconnect
25 | SCardEndTransaction
26 | SCardEstablishContext
27 | SCardForgetCardTypeA
28 | SCardForgetCardTypeW
29 | SCardForgetReaderA
30 | SCardForgetReaderGroupA
31 | SCardForgetReaderGroupW
32 | SCardForgetReaderW
33 | SCardFreeMemory
34 | SCardGetAttrib
35 | SCardGetCardTypeProviderNameA
36 | SCardGetCardTypeProviderNameW
37 | SCardGetDeviceTypeIdA
38 | SCardGetDeviceTypeIdW
39 | SCardGetProviderIdA
40 | SCardGetProviderIdW
41 | SCardGetReaderDeviceInstanceIdA
42 | SCardGetReaderDeviceInstanceIdW
43 | SCardGetReaderIconA
44 | SCardGetReaderIconW
45 | SCardGetStatusChangeA
46 | SCardGetStatusChangeW
47 | SCardGetTransmitCount
48 | SCardIntroduceCardTypeA
49 | SCardIntroduceCardTypeW
50 | SCardIntroduceReaderA
51 | SCardIntroduceReaderGroupA
52 | SCardIntroduceReaderGroupW
53 | SCardIntroduceReaderW
54 | SCardIsValidContext
55 | SCardListCardsA
56 | SCardListCardsW
57 | SCardListInterfacesA
58 | SCardListInterfacesW
59 | SCardListReaderGroupsA
60 | SCardListReaderGroupsW
61 | SCardListReadersA
62 | SCardListReadersW
63 | SCardListReadersWithDeviceInstanceIdA
64 | SCardListReadersWithDeviceInstanceIdW
65 | SCardLocateCardsA
66 | SCardLocateCardsByATRA
67 | SCardLocateCardsByATRW
68 | SCardLocateCardsW
69 | SCardReadCacheA
70 | SCardReadCacheW
71 | SCardReconnect
72 | SCardReleaseContext
73 | SCardReleaseStartedEvent
74 | SCardRemoveReaderFromGroupA
75 | SCardRemoveReaderFromGroupW
76 | SCardSetAttrib
77 | SCardSetCardTypeProviderNameA
78 | SCardSetCardTypeProviderNameW
79 | SCardState
80 | SCardStatusA
81 | SCardStatusW
82 | SCardTransmit
83 | SCardWriteCacheA
84 | SCardWriteCacheW
85 | g_rgSCardRawPci DATA
86 | g_rgSCardT0Pci DATA
87 | g_rgSCardT1Pci DATA
88 |
--------------------------------------------------------------------------------
/dot_cardpeek_dir/scripts/lib/compatibility-with-0.7.lua:
--------------------------------------------------------------------------------
1 |
2 | local DEPRECATED_FUNCS = {}
3 |
4 | function DEPRECATED_FOR(fname)
5 | local func = debug.getinfo(2, "n")
6 | local orig = debug.getinfo(3, "lS")
7 |
8 | if DEPRECATED_FUNCS[func.name]==nil then
9 | log.print(log.WARNING,orig.short_src .. "[" .. orig.currentline .. "]: " .. func.name .. "() is deprecated, please use " .. fname .. "() instead.\n" ..
10 | "\tThis warning will only be printed once for " .. func.name .. "().")
11 | DEPRECATED_FUNCS[func.name]=true
12 | end
13 | end
14 |
15 | function ui.tree_find_all_nodes(origin_ref, alabel, aid)
16 | DEPRECATED_FOR("nodes.find")
17 |
18 | local node
19 | local ret = {}
20 |
21 | if origin_ref==nil then
22 | origin_ref = nodes.root()
23 | end
24 | for node in nodes.find(origin_ref, {label=alabel, id=aid}) do
25 | ret[#ret+1]=node;
26 | end
27 |
28 | return ret;
29 | end
30 |
31 | function ui.tree_find_node(origin_ref, alabel, aid)
32 | DEPRECATED_FOR("nodes.find_first")
33 |
34 | if origin_ref==nil then
35 | origin_ref = nodes.root()
36 | end
37 | return nodes.find_first(origin_ref, {label=alabel, id=aid})
38 | end
39 |
40 | function ui.tree_add_node(parent_ref, ...)
41 | DEPRECATED_FOR("nodes.append")
42 |
43 | local arg={...}
44 | if parent_ref==nil then
45 | parent_ref = nodes.root()
46 | end
47 | return nodes.append(parent_ref,{ classname=arg[1], label=arg[2], id=arg[3], size=arg[4] })
48 | end
49 |
50 | function ui.tree_set_value(node,val)
51 | DEPRECATED_FOR("nodes.set_attribute")
52 |
53 | return node:set_attribute("val",val)
54 | end
55 |
56 | function ui.tree_get_value(node,val)
57 | DEPRECATED_FOR("nodes.get_attribute")
58 |
59 | return node:get_attribute("val",val)
60 | end
61 |
62 | function ui.tree_set_alt_value(node,val)
63 | DEPRECATED_FOR("nodes.set_attribute")
64 |
65 | return node:set_attribute("alt",val)
66 | end
67 |
68 | function ui.tree_get_alt_value(node,val)
69 | DEPRECATED_FOR("nodes.get_attribute")
70 |
71 | return node:get_attribute("alt",val)
72 | end
73 |
74 | function ui.tree_delete_node(node)
75 | DEPRECATED_FOR("nodes.remove")
76 |
77 | return nodes.remove(node)
78 | end
79 |
--------------------------------------------------------------------------------
/osx/README.md:
--------------------------------------------------------------------------------
1 | Experimental MacOSX Cardpeek bundle
2 | ===================================
3 |
4 | Context
5 | -------
6 |
7 | In order to integrate Cardpeek in OSX, we need to generate an application bundle (i.e. cardpeek.app).
8 | To this end:
9 |
10 | 1. We modified the autoconf files to allow this specific approach.
11 |
12 | 2. We compile cardpeek through the objective-c program `cardpeek-osx.m` instead of the normal `cardpeek.c`.
13 |
14 | 3. We use gtk-mac-bundler (with the pacth below), with the adequate bundle, icns and plist files.
15 |
16 | Caveats
17 | -------
18 |
19 | This has gone through very limited testing.
20 | Currently Cardpeek does not have a menu is OSX and does not have the quit shortcut.
21 |
22 | Patching gtk-mac-bundler
23 | ------------------------
24 |
25 | Below between markdown triple quotes is the patch to apply to gtk-mac-bundler in order to make this work.
26 |
27 | ```
28 | diff --git a/bundler/bundler.py b/bundler/bundler.py
29 | index 8061ac1..d9b16af 100644
30 | --- a/bundler/bundler.py
31 | +++ b/bundler/bundler.py
32 | @@ -247,7 +247,7 @@ class Bundler:
33 | relative_dest = self.project.evaluate_path(Path.source[m.end():])
34 | dest = self.project.get_bundle_path("Contents/Resources", relative_dest)
35 | else:
36 | - print "Invalid bundle file, missing or invalid 'dest' property: " + Path.dest
37 | + print "Invalid bundle file, missing or invalid 'dest' property: " + source
38 | sys.exit(1)
39 |
40 | (dest_parent, dest_tail) = os.path.split(dest)
41 | @@ -302,7 +302,7 @@ class Bundler:
42 | dir_util.copy_tree (str(globbed_source), str(dest),
43 | preserve_mode=1,
44 | preserve_times=1,
45 | - preserve_symlinks=1,
46 | + preserve_symlinks=0,
47 | update=1,
48 | verbose=1,
49 | dry_run=0)
50 | @@ -612,7 +612,7 @@ class Bundler:
51 | self.copy_plist()
52 |
53 | # Note: could move this to xml file...
54 | - self.copy_path(Path("${prefix}/lib/charset.alias"))
55 | + #self.copy_path(Path("${prefix}/lib/charset.alias"))
56 |
57 | # Main binary
58 | path = self.project.get_main_binary()
59 | ```
60 |
--------------------------------------------------------------------------------
/ui/console/console_about.c:
--------------------------------------------------------------------------------
1 | /**********************************************************************
2 | *
3 | * This file is part of Cardpeek, the smart card reader utility.
4 | *
5 | * Copyright 2009-2014 by Alain Pannetrat
6 | *
7 | * Cardpeek is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * Cardpeek is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with Cardpeek. If not, see .
19 | *
20 | */
21 |
22 | #include
23 | #include
24 | #ifndef _WIN32
25 | #include "config.h"
26 | #else
27 | #include "win32/config.h"
28 | #endif
29 |
30 | static const char* LICENSE=
31 | "CARDPEEK is free software: you can redistribute it and/or modify it under the terms of the GNU "
32 | "General Public License as published by the Free Software Foundation, either version 3 of the "
33 | "License, or (at your option) any later version.\n\n"
34 | "As an exemption to the GNU General Public License, compiling, linking, and/or using OpenSSL is "
35 | "allowed.\n\n"
36 | "CARDPEEK is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without "
37 | "even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU "
38 | "General Public License for more details.\n\n"
39 | "You should have received a copy of the GNU General Public License along with this program. If "
40 | "not, see http://www.gnu.org/licenses/.";
41 |
42 |
43 | void console_about(void)
44 | {
45 | GBytes* authors_bytes;
46 | gsize size;
47 | const char *authors;
48 |
49 | authors_bytes = g_resources_lookup_data("/com/pannetrat/cardpeek/AUTHORS",G_RESOURCE_LOOKUP_FLAGS_NONE,NULL);
50 | authors = (const char *)g_bytes_get_data(authors_bytes,&size);
51 |
52 | printf("\n\nThis is cardpeek %s\n\n"
53 | "LICENCE \n"
54 | "======= \n\n%s\n\n"
55 | "AUTHORS \n"
56 | "======= \n\n%s\n\n"
57 | "WEBSITE \n"
58 | "======= \n\n"
59 | "http://pannetrat.com/Cardpeek/\n\n",
60 | VERSION,
61 | LICENSE,
62 | authors);
63 | }
64 |
65 |
66 |
--------------------------------------------------------------------------------
/lua_bit.c:
--------------------------------------------------------------------------------
1 | /**********************************************************************
2 | *
3 | * This file is part of Cardpeek, the smart card reader utility.
4 | *
5 | * Copyright 2009-2013 by Alain Pannetrat
6 | *
7 | * Cardpeek is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * Cardpeek is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with Cardpeek. If not, see .
19 | *
20 | */
21 | #include
22 | #include "lua_bit.h"
23 |
24 | /***********************************************************
25 | * GENERAL FUNCTIONS
26 | * - Binary integer ops that LUA lacks
27 | */
28 |
29 | static int subr_bit_and(lua_State* L)
30 | {
31 | unsigned a = (unsigned)lua_tointeger(L,1);
32 | unsigned b = (unsigned)lua_tointeger(L,2);
33 | lua_pushinteger(L,(int)(a&b));
34 | return 1;
35 | }
36 |
37 | static int subr_bit_or(lua_State* L)
38 | {
39 | unsigned a = (unsigned)lua_tointeger(L,1);
40 | unsigned b = (unsigned)lua_tointeger(L,2);
41 | lua_pushinteger(L,(int)(a|b));
42 | return 1;
43 | }
44 |
45 | static int subr_bit_xor(lua_State* L)
46 | {
47 | unsigned a = (unsigned)lua_tointeger(L,1);
48 | unsigned b = (unsigned)lua_tointeger(L,2);
49 | lua_pushinteger(L,(int)(a^b));
50 | return 1;
51 | }
52 |
53 | static int subr_bit_shl(lua_State* L)
54 | {
55 | unsigned a = (unsigned)lua_tointeger(L,1);
56 | unsigned b = (unsigned)lua_tointeger(L,2);
57 | lua_pushinteger(L,(int)((a<>b));
66 | return 1;
67 | }
68 |
69 | static const struct luaL_Reg bitlib [] = {
70 | { "AND", subr_bit_and },
71 | { "OR", subr_bit_or },
72 | { "XOR", subr_bit_xor },
73 | { "SHL", subr_bit_shl },
74 | { "SHR", subr_bit_shr },
75 | { NULL, NULL } /* sentinel */
76 | };
77 |
78 | int luaopen_bit(lua_State* L)
79 | {
80 | luaL_newlib(L,bitlib);
81 | lua_setglobal(L,"bit");
82 | /* luaL_openlib(L, "bit", bitlib, 0);*/
83 | return 1;
84 | }
85 |
86 |
87 |
--------------------------------------------------------------------------------
/crypto.h:
--------------------------------------------------------------------------------
1 | /**********************************************************************
2 | *
3 | * This file is part of Cardpeek, the smart card reader utility.
4 | *
5 | * Copyright 2009-2013 by Alain Pannetrat
6 | *
7 | * Cardpeek is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * Cardpeek is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with Cardpeek. If not, see .
19 | *
20 | */
21 |
22 | #ifndef CRYPTO_H
23 | #define CRYPTO_H
24 |
25 | #include "bytestring.h"
26 |
27 | typedef enum {
28 | CRYPTO_OK,
29 | CRYPTO_ERROR_BAD_KEY_FORMAT,
30 | CRYPTO_ERROR_UNKNOWN_KEY_TYPE,
31 | CRYPTO_ERROR_BAD_CLEARTEXT_LENGTH,
32 | CRYPTO_ERROR_BAD_IV_LENGTH,
33 | CRYPTO_ERROR_UNKNOWN_PADDING_METHOD,
34 | CRYPTO_ERROR_UNKNOWN_ALGORITHM,
35 |
36 | CRYPTO_ERROR_UNKNOWN
37 | } crypto_error_t;
38 |
39 | typedef unsigned crypto_alg_t;
40 |
41 | #define CRYPTO_ALG_DES_ECB (0x0000)
42 | #define CRYPTO_ALG_DES_CBC (0x0001)
43 | #define CRYPTO_ALG_DES2_EDE_ECB (0x0010)
44 | #define CRYPTO_ALG_DES2_EDE_CBC (0x0011)
45 | #define CRYPTO_ALG_ISO9797_M3 (0x0021)
46 | #define CRYPTO_ALG_SHA1 (0x0030)
47 |
48 | #define CRYPTO_PAD_ZERO (0x0000)
49 | #define CRYPTO_PAD_OPT_80_ZERO (0x0100)
50 | #define CRYPTO_PAD_ISO9797_P2 (0x0200)
51 |
52 |
53 | crypto_error_t crypto_create_context(bytestring_t *ctx,
54 | crypto_alg_t alg_type,
55 | const bytestring_t* key_bin);
56 |
57 | crypto_error_t crypto_encrypt(bytestring_t* dst,
58 | const bytestring_t* ctx,
59 | const bytestring_t* src,
60 | const bytestring_t* iv);
61 |
62 | crypto_error_t crypto_decrypt(bytestring_t* dst,
63 | const bytestring_t* ctx,
64 | const bytestring_t* src,
65 | const bytestring_t* iv);
66 |
67 | crypto_error_t crypto_mac(bytestring_t* dst,
68 | const bytestring_t* ctx,
69 | const bytestring_t* src);
70 |
71 | crypto_error_t crypto_digest(bytestring_t* dst,
72 | const bytestring_t* ctx,
73 | const bytestring_t* src);
74 |
75 | const char *crypto_stringify_error(crypto_error_t err);
76 | #endif
77 |
78 |
--------------------------------------------------------------------------------
/pathconfig.h:
--------------------------------------------------------------------------------
1 | /**********************************************************************
2 | *
3 | * This file is part of Cardpeek, the smart card reader utility.
4 | *
5 | * Copyright 2009-2014 by Alain Pannetrat
6 | *
7 | * Cardpeek is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * Cardpeek is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with Cardpeek. If not, see .
19 | *
20 | */
21 |
22 | #ifndef PATH_CONFIG_H
23 | #define PATH_CONFIG_H
24 |
25 | enum {
26 | PATH_CONFIG_FOLDER_WORKING, /* Current Working directory */
27 | PATH_CONFIG_FILE_CARDPEEK_LOG, /* PATH_CONFIG_FOLDER_CARDPEEK + /.cardpeek.log */
28 | PATH_CONFIG_FOLDER_HOME, /* $HOME on Linux or equivalent in Windows */
29 | PATH_CONFIG_FOLDER_CARDPEEK, /* $CARDPEEK_DIR if defined, otherwise $HOME */
30 | PATH_CONFIG_FOLDER_SCRIPTS, /* PATH_CONFIG_FOLDER_CARDPEEK + "/.cardpeek/scripts" */
31 | PATH_CONFIG_FOLDER_REPLAY, /* PATH_CONFIG_FOLDER_CARDPEEK + "/.cardpeek/replay" */
32 | PATH_CONFIG_FOLDER_OLD_REPLAY, /* legacy */
33 | PATH_CONFIG_FILE_CONFIG_LUA, /* PATH_CONFIG_FOLDER_CARDPEEK + "/.cardpeek/config.lua" */
34 | PATH_CONFIG_FILE_CARDPEEK_RC, /* PATH_CONFIG_FOLDER_CARDPEEK + "/.cardpeek/cardpeek_rc.lua" */
35 | PATH_CONFIG_FILE_VERSION, /* PATH_CONFIG_FOLDER_CARDPEEK + "/.cardpeek/version" */
36 | PATH_CONFIG_FILE_SMARTCARD_LIST_TXT, /* legacy */
37 | PATH_CONFIG_FILE_SMARTCARD_LIST_DOWNLOAD, /* legacy */
38 | PATH_CONFIG_FILE_CARDPEEK_UPDATE, /* PATH_CONFIG_FOLDER_CARDPEEK + "/.cardpeek/cardpeek.update" */
39 | NUM_PATH_CONFIG_OPTIONS
40 | };
41 |
42 |
43 | int path_config_init(void);
44 | /* Populate the mapping between PATH_* identfiers and strings */
45 |
46 | const char *path_config_get_string(unsigned index);
47 | /* Translate the PATH_* numerical identifiers above into strings */
48 |
49 | int path_config_set_string(unsigned index, const char *path);
50 | /* Changes any PATH_* numeral identifier to a specicifc path */
51 |
52 | void path_config_release(void);
53 | /* Release allocated mapping created by path_config_init() */
54 |
55 | #endif
56 |
--------------------------------------------------------------------------------
/a_string.h:
--------------------------------------------------------------------------------
1 | /**********************************************************************
2 | *
3 | * This file is part of Cardpeek, the smart card reader utility.
4 | *
5 | * Copyright 2009-2014 by Alain Pannetrat
6 | *
7 | * Cardpeek is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * Cardpeek is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with Cardpeek. If not, see .
19 | *
20 | */
21 |
22 | #ifndef A_STRING_H
23 | #define A_STRING_H
24 |
25 | typedef struct {
26 | unsigned _alloc;
27 | unsigned _size;
28 | char* _data;
29 | } a_string_t;
30 |
31 | a_string_t* a_strnnew(unsigned n, const char* str);
32 | a_string_t* a_strnew(const char* str);
33 | void a_strfree(a_string_t* cs);
34 | char* a_strfinalize(a_string_t* cs);
35 |
36 | /* Functions for copying and appending zero terminated strings:
37 |
38 | The a_strn*() function copy at most n bytes form the str, halting
39 | before n if an ending 0 is found.
40 | */
41 |
42 | const char* a_strncpy(a_string_t* cs, unsigned n, const char* str);
43 | const char* a_strcpy(a_string_t* cs, const char* str);
44 | const char* a_strncat(a_string_t* cs, unsigned n, const char* str);
45 | const char* a_strcat(a_string_t* cs, const char* str);
46 |
47 | const char* a_strpushback(a_string_t* cs, char c);
48 |
49 | /* Functions for non zero terminated strings:
50 |
51 | They operate like the a_strn*() functions but copy or append exactly
52 | n bytes of data to the string including any 0s found.
53 |
54 | */
55 |
56 | const char* a_memcpy(a_string_t* cs, unsigned n, const void* str);
57 | const char* a_memcat(a_string_t* cs, unsigned n, const void* str);
58 | const char* a_mempushback(a_string_t* cs, unsigned char c);
59 |
60 | /*
61 | a_strval() is guaranteed to return a null terminated string.
62 |
63 | a_strlen() returns the total length of the string *excluding*
64 | the additonal 0 that is added to guarantee that the string is null
65 | terminated.
66 |
67 | */
68 | const char* a_strval(const a_string_t* cs);
69 | unsigned a_strlen(const a_string_t* cs);
70 |
71 | int a_sprintf(a_string_t* cs, const char *format, ...);
72 | int a_strnequal(const a_string_t* cs, unsigned n, const char *value);
73 | int a_strequal(const a_string_t* cs, const char *value);
74 |
75 | #endif
76 |
--------------------------------------------------------------------------------
/replay.h:
--------------------------------------------------------------------------------
1 | /**********************************************************************
2 | *
3 | * This file is part of Cardpeek, the smart card reader utility.
4 | *
5 | * Copyright 2009-2013 by Alain Pannetrat
6 | *
7 | * Cardpeek is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * Cardpeek is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with Cardpeek. If not, see .
19 | *
20 | */
21 |
22 | #ifndef REPLAY_H
23 | #define REPLAY_H
24 |
25 | #include "bytestring.h"
26 |
27 | enum {
28 | CARDREPLAY_COMMAND,
29 | CARDREPLAY_RESET
30 | };
31 |
32 | enum {
33 | CARDREPLAY_ERROR,
34 | CARDREPLAY_OK
35 | };
36 |
37 | typedef struct _anyreplay_t {
38 | struct _anyreplay_t *next;
39 | unsigned type;
40 | } anyreplay_t;
41 |
42 | typedef struct _comreplay_t {
43 | anyreplay_t *next;
44 | unsigned type;
45 | bytestring_t *query;
46 | unsigned sw;
47 | bytestring_t *response;
48 | } comreplay_t;
49 |
50 | typedef struct _resreplay_t {
51 | anyreplay_t *next;
52 | unsigned type;
53 | bytestring_t *atr;
54 | } resreplay_t;
55 |
56 | typedef union {
57 | anyreplay_t *any;
58 | comreplay_t *com;
59 | resreplay_t *res;
60 | } replay_t;
61 |
62 | typedef struct _cardreplay_t {
63 | int count;
64 | replay_t start;
65 | replay_t pos;
66 | replay_t atr;
67 | } cardreplay_t;
68 |
69 | int cardreplay_add_command(cardreplay_t* ce,
70 | const bytestring_t* command,
71 | unsigned sw, const bytestring_t* result);
72 |
73 | int cardreplay_add_reset(cardreplay_t* ce, const bytestring_t* atr);
74 |
75 | cardreplay_t* cardreplay_new(void);
76 |
77 | void cardreplay_free(cardreplay_t* ce);
78 |
79 | anyreplay_t* cardreplay_after_atr(cardreplay_t* ce);
80 |
81 | int cardreplay_run_command(cardreplay_t* ce,
82 | const bytestring_t* command,
83 | unsigned short *sw,
84 | bytestring_t *response);
85 |
86 | int cardreplay_run_cold_reset(cardreplay_t* ce);
87 |
88 | int cardreplay_run_warm_reset(cardreplay_t* ce);
89 |
90 | int cardreplay_run_last_atr(const cardreplay_t* ce, bytestring_t *atr);
91 |
92 | int cardreplay_save_to_file(const cardreplay_t* ce, const char *filename);
93 |
94 | cardreplay_t* cardreplay_new_from_file(const char *filename);
95 |
96 | int cardreplay_count_records(const cardreplay_t* ce);
97 |
98 | #endif
99 |
--------------------------------------------------------------------------------
/ui/gtk/gui_about.c:
--------------------------------------------------------------------------------
1 | /**********************************************************************
2 | *
3 | * This file is part of Cardpeek, the smart card reader utility.
4 | *
5 | * Copyright 2009-2014 by Alain Pannetrat
6 | *
7 | * Cardpeek is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * Cardpeek is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with Cardpeek. If not, see .
19 | *
20 | */
21 |
22 | #include "ui.h"
23 | #include "gui_core.h"
24 | #include "gui_about.h"
25 |
26 | #include
27 | #ifndef _WIN32
28 | #include "config.h"
29 | #else
30 | #include "win32/config.h"
31 | /*#include "win32/win32compat.h"*/
32 | #endif
33 |
34 |
35 | static const char* LICENSE=
36 | "CARDPEEK is free software: you can redistribute it and/or modify it under the terms of the GNU "
37 | "General Public License as published by the Free Software Foundation, either version 3 of the "
38 | "License, or (at your option) any later version.\n\n"
39 | "As an exemption to the GNU General Public License, compiling, linking, and/or using OpenSSL is "
40 | "allowed.\n\n"
41 | "CARDPEEK is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without "
42 | "even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU "
43 | "General Public License for more details.\n\n"
44 | "You should have received a copy of the GNU General Public License along with this program. If "
45 | "not, see http://www.gnu.org/licenses/.";
46 |
47 |
48 | void gui_about(void)
49 | {
50 | GBytes* authors_bytes;
51 | gsize size;
52 | const char *authors[2];
53 |
54 | authors_bytes = g_resources_lookup_data("/com/pannetrat/cardpeek/AUTHORS",G_RESOURCE_LOOKUP_FLAGS_NONE,NULL);
55 | authors[0] = (const char *)g_bytes_get_data(authors_bytes,&size);
56 | authors[1] = NULL;
57 |
58 | gtk_show_about_dialog(GTK_WINDOW(MAIN_WINDOW),
59 | "program-name", "cardpeek",
60 | "version", VERSION,
61 | "license", LICENSE,
62 | "wrap-license", TRUE,
63 | "authors", authors,
64 | "comments", "Cardpeek is a tool to read the contents of smart cards.",
65 | "copyright", "Copyright Alain Pannetrat ",
66 | "website", "http://pannetrat.com/Cardpeek/",
67 | "website-label", "http://pannetrat.com/Cardpeek/",
68 | NULL);
69 | }
70 |
71 |
72 |
--------------------------------------------------------------------------------
/ui/gtk/gui_scratchpad.c:
--------------------------------------------------------------------------------
1 | /**********************************************************************
2 | *
3 | * This file is part of Cardpeek, the smart card reader utility.
4 | *
5 | * Copyright 2009-2014 by Alain Pannetrat
6 | *
7 | * Cardpeek is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * Cardpeek is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with Cardpeek. If not, see .
19 | *
20 | */
21 |
22 | #include "ui.h"
23 | #include "lua_ext.h"
24 | #include "gui_scratchpad.h"
25 | #include "misc.h"
26 |
27 | /*********************************************************/
28 | /* THE INFAMOUS UGLY GLOBALS *****************************/
29 | /*********************************************************/
30 |
31 | GtkListStore *COMPLETION=NULL;
32 |
33 | /*********************************************************/
34 | /* IMPLEMENTATION ****************************************/
35 | /*********************************************************/
36 |
37 | static void gui_run_command_cb(GtkWidget *widget,
38 | GtkWidget *entry )
39 | {
40 | GtkTreeIter iter;
41 | const gchar *entry_text = gtk_entry_get_text (GTK_ENTRY (entry));
42 | UNUSED(widget);
43 |
44 | luax_run_command(entry_text);
45 | gtk_list_store_append(COMPLETION,&iter);
46 | gtk_list_store_set(COMPLETION,&iter,0,entry_text,-1);
47 | ui_update();
48 | }
49 |
50 | GtkWidget *gui_scratchpad_create_window(void)
51 | {
52 | GtkWidget *label;
53 | GtkWidget *hbox;
54 | GtkWidget *entry;
55 | GtkEntryCompletion* compl;
56 | GtkWidget *icon;
57 |
58 | entry = gtk_entry_new();
59 |
60 | COMPLETION = gtk_list_store_new(1,G_TYPE_STRING);
61 | compl = gtk_entry_completion_new();
62 | gtk_entry_completion_set_model(compl, GTK_TREE_MODEL(COMPLETION));
63 | gtk_entry_completion_set_text_column(compl, 0);
64 | gtk_entry_set_completion(GTK_ENTRY(entry), compl);
65 |
66 | label = gtk_label_new("Command:");
67 | hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 4);
68 |
69 | if ((icon = gtk_image_new_from_icon_name("system-run",GTK_ICON_SIZE_MENU)))
70 | gtk_box_pack_start (GTK_BOX (hbox), icon, FALSE, FALSE, 0);
71 |
72 | gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
73 | gtk_box_pack_start (GTK_BOX (hbox), entry, TRUE, TRUE, 0);
74 |
75 | g_signal_connect (G_OBJECT (entry), "activate",
76 | G_CALLBACK (gui_run_command_cb),
77 | (gpointer) entry);
78 |
79 | return hbox;
80 | }
81 |
82 | void gui_scratchpad_cleanup(void)
83 | {
84 | /* FIXME: check this out */
85 | }
86 |
--------------------------------------------------------------------------------
/osx/cardpeek-osx.m:
--------------------------------------------------------------------------------
1 | //
2 | // main.m
3 | // NoNIBCodeOnlyGUIAppBootstrapping
4 | //
5 | // Created by Hoon H. on 2014/06/13.
6 | // Copyright (c) 2014 Eonil. All rights reserved.
7 | //
8 |
9 | #import
10 | #include "main.h"
11 |
12 | @interface BoilerplateApplicationController : NSResponder
13 | - (void)userTapQuitMenu:(id)sender;
14 | @end
15 |
16 | @implementation BoilerplateApplicationController
17 | {
18 | NSWindow* _main_window;
19 | }
20 | - (void)applicationDidFinishLaunching:(NSNotification *)notification
21 | {
22 | {
23 | /*!
24 | But it's OK to create after launching finished.
25 | */
26 | /*
27 | _main_window = [[NSWindow alloc] init];
28 | [_main_window setStyleMask:NSResizableWindowMask | NSClosableWindowMask | NSTitledWindowMask | NSMiniaturizableWindowMask];
29 | [_main_window setContentSize:CGSizeMake(400, 300)];
30 | [_main_window makeKeyAndOrderFront:self];
31 | */
32 | }
33 |
34 | /*!
35 | Make a menu to let you to quit application by @c Command+Q.
36 |
37 | Notice that;
38 |
39 | - "Menu 1" means the main menu bar itself. So it will not be visible.
40 | - "Item 2" means the application menu item. The specified title will be ignored,
41 | and will be replaced by system provided application name.
42 | - "Menu 3" means a drop-down menu when you cliked the application menu.
43 | - "Item 4" means the first menu will be visible to you.
44 | - @c keyEquivalent of "Item 4" is specified as lowercase letter to avoid requiring
45 | shift key combination. If you put uppercase letter, then you have to press shift
46 | key for the shortcut.
47 |
48 | The selector @c userTapQuitMenu: will be passed to first-responder, and the
49 | application-delegate object in this case, which is an instance of @c TestApp1 class.
50 |
51 | */
52 | /*
53 | NSCAssert([[NSApplication sharedApplication] mainMenu] == nil, @"An application should have no main-menu at first.");
54 |
55 | SEL s1 = NSSelectorFromString(@"userTapQuitMenu:"); // Made from a string to avoid warning.
56 |
57 | NSMenu* m1 = [[NSMenu alloc] initWithTitle:@"Menu 1"];
58 | NSMenuItem* m2 = [[NSMenuItem alloc] initWithTitle:@"Item 2" action:s1 keyEquivalent:@""];
59 |
60 | NSMenu* m3 = [[NSMenu alloc] initWithTitle:@"Menu 3"];
61 | NSMenuItem* m4 = [[NSMenuItem alloc] initWithTitle:@"Item 4" action:s1 keyEquivalent:@"q"];
62 |
63 | [[NSApplication sharedApplication] setMainMenu:m1];
64 | [m1 addItem:m2];
65 | [m2 setSubmenu:m3];
66 | [m3 addItem:m4];*/
67 | cardpeek_main(0,NULL);
68 | /* [NSApp terminate: nil]; */
69 | [[NSApplication sharedApplication] terminate:self];
70 | }
71 | - (void)userTapQuitMenu:(id)sender
72 | {
73 | [[NSApplication sharedApplication] terminate:self];
74 | }
75 | @end
76 |
77 |
78 | int main(int argc, const char * argv[])
79 | {
80 | @autoreleasepool
81 | {
82 | BoilerplateApplicationController* del1 = [[BoilerplateApplicationController alloc] init];
83 | NSApplication* app1 = [NSApplication sharedApplication]; /// Let it to be created by accessing it.
84 | [app1 setDelegate:del1];
85 | [app1 run];
86 | }
87 | }
88 |
--------------------------------------------------------------------------------
/dot_cardpeek_dir/scripts/calypso/c250n64.lua:
--------------------------------------------------------------------------------
1 | --
2 | -- This file is part of Cardpeek, the smartcard reader utility.
3 | --
4 | -- Copyright 2009-2013 by 'L1L1'
5 | --
6 | -- Cardpeek is free software: you can redistribute it and/or modify
7 | -- it under the terms of the GNU General Public License as published by
8 | -- the Free Software Foundation, either version 3 of the License, or
9 | -- (at your option) any later version.
10 | --
11 | -- Cardpeek is distributed in the hope that it will be useful,
12 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | -- GNU General Public License for more details.
15 | --
16 | -- You should have received a copy of the GNU General Public License
17 | -- along with Cardpeek. If not, see .
18 | --
19 |
20 | require('lib.strict')
21 |
22 | SERVICE_PROVIDERS = {
23 | [5] = "TAM"
24 | }
25 |
26 | TRANSPORT_LIST = {
27 | [1] = "Urban Bus",
28 | [2] = "Interurban Bus",
29 | [3] = "Metro",
30 | [4] = "Tram",
31 | [5] = "Train",
32 | [8] = "Parking"
33 | }
34 |
35 | TRANSITION_LIST = {
36 | [1] = "Entry",
37 | [2] = "Exit",
38 | [4] = "Inspection",
39 | [6] = "Interchange (entry)",
40 | [7] = "Interchange (exit)"
41 | }
42 |
43 | function process_events(cardenv,node_label)
44 | local event_node
45 | local record_node
46 | local ref_node
47 |
48 | local code_value
49 | local code_transport
50 | local code_transition
51 | local code_transport_string
52 | local code_transition_string
53 | local code_string
54 | local service_provider_value
55 | local location_id_value
56 | local sector_id
57 | local station_id
58 | local location_string
59 |
60 | event_node = cardenv:find_first({label=node_label, parsed="true"})
61 |
62 | if event_node==nil then
63 | log.print(log.WARNING,"No " .. node_label .. " found in card")
64 | return 0
65 | end
66 |
67 | for record_node in event_node:find({label="record"}) do
68 |
69 | -- is it TAM?
70 | ref_node = record_node:find_first({label="EventServiceProvider"})
71 | service_provider_value = bytes.tonumber(ref_node:get_attribute("val"))
72 | ref_node:set_attribute("alt",SERVICE_PROVIDERS[service_provider_value])
73 |
74 | ref_node = record_node:find_first({label="EventCode"})
75 | code_value = bytes.tonumber(ref_node:get_attribute("val"))
76 |
77 | -- is it a bus, a tram, ...?
78 | code_transport = bit.SHR(code_value,4)
79 | code_transport_string = TRANSPORT_LIST[code_transport]
80 | if code_transport_string==nil then code_transport_string = code_transport end
81 |
82 | -- is it an entry, an exit, ...?
83 | code_transition = bit.AND(code_value,0xF)
84 | code_transition_string = TRANSITION_LIST[code_transition]
85 | if (code_transition_string==nil) then code_transition_string = code_transition end
86 |
87 | ref_node:set_attribute("alt",code_transport_string.." - "..code_transition_string)
88 | end
89 | end
90 |
91 | process_events(CARD,"Event logs")
92 |
--------------------------------------------------------------------------------
/iso7816.h:
--------------------------------------------------------------------------------
1 | /**********************************************************************
2 | *
3 | * This file is part of Cardpeek, the smart card reader utility.
4 | *
5 | * Copyright 2009-2013 by Alain Pannetrat
6 | *
7 | * Cardpeek is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * Cardpeek is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with Cardpeek. If not, see .
19 | *
20 | */
21 |
22 | #ifndef ISO7816_H
23 | #define ISO7816_H
24 |
25 | #include "bytestring.h"
26 |
27 |
28 | typedef struct {
29 | unsigned apdu_class;
30 | unsigned lc_len;
31 | unsigned lc;
32 | unsigned le_len;
33 | unsigned le;
34 | } apdu_descriptor_t;
35 |
36 | enum {
37 | APDU_CLASS_NONE,
38 | APDU_CLASS_1,
39 | APDU_CLASS_2S,
40 | APDU_CLASS_3S,
41 | APDU_CLASS_4S,
42 | APDU_CLASS_2E,
43 | APDU_CLASS_3E,
44 | APDU_CLASS_4E
45 | };
46 |
47 | #define ISO7816_OK 1
48 | #define ISO7816_ERROR 0
49 |
50 | const char* iso7816_stringify_sw(unsigned short sw);
51 |
52 | const char* iso7816_stringify_apdu_class(unsigned apdu_class);
53 |
54 | int iso7816_describe_apdu(apdu_descriptor_t *ad,
55 | const bytestring_t* apdu);
56 |
57 | int iso7816_make_file_path(bytestring_t* file_path,
58 | int *path_type,
59 | const char* path);
60 |
61 | /**
62 | iso7816_make_file_path() converts a string 'path' into a couple
63 | { path_file, path_type } according to the following rules :
64 |
65 | path | path_type |
66 | ------------------+-----------+-----------------------------------------
67 | '#' | 0 | Select the MF (equiv. #3F00)
68 | '#HHHH' | 0 | Select file with ID=HHHH
69 | '#HHHHHH...' | 4 | Select by AID HHHHHH... (5 to 16 bytes)
70 | '.HHHH' | 1 | select child *EF* with file ID=HHHH
71 | '.HHHH/' | 2 | select child *DF* with file ID=HHHH
72 | '..' | 3 | select parent of current EF or DF
73 | '/HHHH/HHHH/...' | 8 | select absolute path /3F00/HHHH/HHHH/...
74 | | | without specifying the MF (3F00)
75 | './HHHH/HHHH/...' | 9 | select by relative path ./HHHH/HHHH/...
76 | | | without specifiying the current DF.
77 |
78 | The values "HH" reperesents hexadecimal pairs of digits (i.e 1 byte).
79 |
80 | 'path_file' is a bytestring representing 'path' in a binary form that
81 | is compatible with SELECT_FILE is ISO 7816-4.
82 |
83 | This approach is designed to cover all the cases presented in the
84 | specification of SELECT_FILE in ISO 7816-4 : path_type maps to the
85 | parameter P1 in the SELECT_FILE command.
86 | **/
87 |
88 | #endif
89 |
90 |
--------------------------------------------------------------------------------
/misc.h:
--------------------------------------------------------------------------------
1 | /**********************************************************************
2 | *
3 | * This file is part of Cardpeek, the smart card reader utility.
4 | *
5 | * Copyright 2009-2014 by Alain Pannetrat
6 | *
7 | * Cardpeek is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * Cardpeek is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with Cardpeek. If not, see .
19 | *
20 | */
21 |
22 | #ifndef MISC_H
23 | #define MISC_H
24 | #include
25 |
26 | #ifdef _WIN32
27 | #include "win32/config.h"
28 | #else
29 | #include "config.h"
30 | #endif
31 |
32 | #ifndef HAVE_GSTATBUF
33 | #include
34 | typedef struct stat GStatBuf;
35 | #endif
36 |
37 | /* Not needed for maverick anymore *
38 | #ifdef __APPLE__
39 | #define DIRENT_T struct dirent
40 | #else*/
41 | #define DIRENT_T const struct dirent
42 | /* #endif
43 | */
44 |
45 |
46 | #define is_hex(a) ((a>='0' && a<='9') || \
47 | (a>='A' && a<='F') || \
48 | (a>='a' && a<='f'))
49 |
50 | #define is_blank(a) (a==' ' || a=='\t' || a=='\r' || a=='\n')
51 |
52 | /*****************************************************
53 | *
54 | * filename parsing
55 | */
56 |
57 | const char *filename_extension(const char *fname);
58 |
59 | const char *filename_base(const char *fname);
60 |
61 | /*****************************************************
62 | *
63 | * log functions
64 | */
65 |
66 | typedef void (*logfunc_t)(int,const char*);
67 |
68 | int log_printf(int level, const char *format, ...);
69 |
70 | void log_set_function(logfunc_t logfunc);
71 |
72 | void log_open_file(void);
73 |
74 | void log_close_file(void);
75 |
76 | enum {
77 | LOG_DEBUG,
78 | LOG_INFO,
79 | LOG_WARNING,
80 | LOG_ERROR
81 | };
82 |
83 | /*****************************************************
84 | *
85 | * String functions for hash maps
86 | */
87 |
88 | guint cstring_hash(gconstpointer data);
89 |
90 | gint cstring_equal(gconstpointer a, gconstpointer b);
91 |
92 | /******************************************************
93 | *
94 | * version_to_bcd convert string version to BCD as
95 | * MM.mm.rrrr
96 | * | | |
97 | * | | +- revision (0000-9999)
98 | * | +------ minor (00-99)
99 | * +--------- major (00-99)
100 | */
101 |
102 | unsigned version_to_bcd(const char *version);
103 |
104 | /******************************************************
105 | *
106 | * debug function
107 | */
108 |
109 | #include
110 | #define HERE() { fprintf(stderr,"%s[%i]\n",__FILE__,__LINE__); fflush(stderr); }
111 |
112 | #define UNUSED(x) (void)x
113 |
114 | #endif /* _MISC_H_ */
115 |
--------------------------------------------------------------------------------
/cardpeek.1:
--------------------------------------------------------------------------------
1 | .TH CARDPEEK 1
2 |
3 | .SH NAME
4 | cardpeek \- A gui tool to explore the contents of ISO 7816 smart cards.
5 |
6 | .SH SYNOPSIS
7 | .B cardpeek
8 | .RB [\fIoptions\fR]
9 |
10 | .SH DESCRIPTION
11 | .PP
12 | Cardpeek is a tool to read the contents of ISO7816 smart cards.
13 | It features a GTK+ GUI to represent card data is a tree view, and is
14 | extendable with a scripting language (LUA).
15 | .TP
16 | \fB\-c\fR, \fB\-\-console\fR
17 | Run Cardpeek in console mode, without the GTK+ GUI.
18 | .TP
19 | \fB\-r\fR, \fB\-\-reader\fR=\fIREADER\fR
20 | Connect to the reader identified by READER.
21 | .TP
22 | \fB\-e\fR, \fB\-\-exec\fR=\fICOMMAND\fR
23 | Execute the lua commands described in COMMAND.
24 | .TP
25 | \fB\-v\fR, \fB\-\-version\fR
26 | Print version info and list of detected smart card readers.
27 | .PP
28 | The goal of this project is to allow smart card owners to be better
29 | informed about what type of personal information is stored in these
30 | devices.
31 |
32 | .PP
33 | This tool is capable of reading the contents of the following types of cards:
34 | .IP \[bu]
35 | EMV "chip and PIN" bank cards, including:
36 | .RS
37 | .IP \[bu]
38 | VISA, MasterCard, CB and UK Post Office Account contact cards;
39 | .IP \[bu]
40 | PayWave (VISA) and PayPass (MasterCard) contactless cards;
41 | .RE
42 | .IP \[bu]
43 | Electronic/Biometric passports, which have an embedded contactless chip;
44 | .IP \[bu]
45 | The Belgian eID card;
46 | .IP \[bu]
47 | Calypso transport cards including:
48 | .RS
49 | .IP \[bu]
50 | Navigo transport cards used in Paris;
51 | .IP \[bu]
52 | MOBIB cards used in Brussels;
53 | .IP \[bu]
54 | RavKav cards used in Israel;
55 | .IP \[bu]
56 | VIVA cards used in Lisbon;
57 | .RE
58 | .IP \[bu]
59 | GSM SIM cards (without USIM data used in recent cards);
60 | .IP \[bu]
61 | Vitale 2, the French health card.
62 | .IP \[bu]
63 | Moneo, the French electronic purse;
64 | .IP \[bu]
65 | Driver Tachograph cards;
66 | .IP \[bu]
67 | OpenPGP Cards (beta);
68 |
69 | .PP
70 | This is not a real man-page, for more detailed information see
71 | included PDF documentation
72 | .B cardpeek_ref.en.pdf
73 | available online here:
74 |
75 | http://cardpeek.googlecode.com/files/cardpeek_ref.en.pdf
76 |
77 | or in your in your system
78 | .B doc/
79 | directory (e.g. /usr/share/doc/cardpeek).
80 |
81 | .SH COPYRIGHT
82 | Cardpeek is Copyright (c) 2009-2015 Alain Pannetrat.
83 |
84 | Cardpeek is free software: you can redistribute it and/or modify
85 | it under the terms of the GNU General Public License as published by
86 | the Free Software Foundation, either version 3 of the License, or
87 | (at your option) any later version.
88 |
89 | As an exemption to the GNU General Public License, compiling,
90 | linking, and/or using OpenSSL is allowed.
91 |
92 | Cardpeek is distributed in the hope that it will be useful,
93 | but WITHOUT ANY WARRANTY; without even the implied warranty of
94 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
95 | GNU General Public License for more details.
96 |
97 | You should have received a copy of the GNU General Public License
98 | along with this program. If not, see http://www.gnu.org/licenses/.
99 |
100 | .SH AUTHORS
101 | Alain Pannetrat
102 |
103 |
--------------------------------------------------------------------------------
/ui.h:
--------------------------------------------------------------------------------
1 | /**********************************************************************
2 | *
3 | * This file is part of Cardpeek, the smart card reader utility.
4 | *
5 | * Copyright 2009-2014 by Alain Pannetrat
6 | *
7 | * Cardpeek is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * Cardpeek is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with Cardpeek. If not, see .
19 | *
20 | */
21 |
22 | #ifndef UI_H
23 | #define UI_H
24 |
25 | #include "bytestring.h"
26 |
27 | typedef struct {
28 | const char *(* ui_driver_name)(void);
29 | int (* ui_initialize)(int *argc, char ***argv);
30 | int (* ui_run)(const char *optional_command);
31 | void (* ui_exit)(void);
32 | void (* ui_update)();
33 | char* (* ui_select_reader)(unsigned list_size, const char** list);
34 | int (* ui_question_l)(const char *message, unsigned item_count, const char** items);
35 | int (* ui_readline)(const char *message, unsigned input_max, char* input);
36 | char** (* ui_select_file)(const char *title, const char *path, const char *filename);
37 | void (* ui_set_title)(const char *title);
38 | void (* ui_about)(void);
39 | void *(* ui_inprogress_new)(const char *title, const char *message);
40 | unsigned (* ui_inprogress_pulse)(void *pulser);
41 | unsigned (* ui_inprogress_set_fraction)(void *pulser, double level);
42 | void (* ui_inprogress_free)(void *pulser);
43 | void (* ui_card_event_print)(unsigned event,
44 | const bytestring_t *command,
45 | unsigned short sw,
46 | const bytestring_t *response,
47 | void *extra_data);
48 | } ui_driver_t;
49 |
50 | const char *ui_driver_name(void);
51 |
52 | int ui_initialize(ui_driver_t *driver, int *argc, char ***argv);
53 |
54 | int ui_run(const char *optinal_command);
55 |
56 | void ui_exit(void);
57 |
58 | void ui_update();
59 |
60 | char* ui_select_reader(unsigned list_size, const char** list);
61 |
62 | int ui_question_l(const char *message, unsigned item_count, const char** items);
63 |
64 | int ui_question(const char *message, ...);
65 |
66 | int ui_readline(const char *message, unsigned input_max, char* input);
67 |
68 |
69 | char** ui_select_file(const char *title,
70 | const char *path,
71 | const char *filename);
72 |
73 | void ui_set_title(const char *title);
74 |
75 | void ui_about(void);
76 |
77 | void *ui_inprogress_new(const char *title, const char *message);
78 |
79 | unsigned ui_inprogress_pulse(void *pulser);
80 |
81 | unsigned ui_inprogress_set_fraction(void *pulser, double level);
82 |
83 | void ui_inprogress_free(void *pulser);
84 |
85 | void ui_card_event_print(unsigned event,
86 | const bytestring_t *command,
87 | unsigned short sw,
88 | const bytestring_t *response,
89 | void *extra_data);
90 |
91 | #endif
92 |
--------------------------------------------------------------------------------
/drivers/replay_driver.c:
--------------------------------------------------------------------------------
1 | /**********************************************************************
2 | *
3 | * This file is part of Cardpeek, the smartcard reader utility.
4 | *
5 | * Copyright 2009 by 'L1L1'
6 | *
7 | * Cardpeek is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * Cardpeek is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with Cardpeek. If not, see .
19 | *
20 | */
21 | #include
22 | #include "../replay.h"
23 |
24 | static int replay_connect(cardreader_t *cr, unsigned prefered_protocol)
25 | {
26 | cardreplay_t* emul = cr->extra_data;
27 | UNUSED(prefered_protocol);
28 |
29 | cr->connected = 1;
30 | return cardreplay_run_cold_reset(emul);
31 | }
32 |
33 | static int replay_disconnect(cardreader_t *cr)
34 | {
35 | cr->connected = 0;
36 | log_printf(LOG_INFO,"Disconnected reader");
37 | return 1;
38 | }
39 |
40 | static int replay_reset(cardreader_t *cr)
41 | {
42 | cardreplay_t* emul = cr->extra_data;
43 | log_printf(LOG_INFO,"Reset reader");
44 | return cardreplay_run_warm_reset(emul);
45 | }
46 |
47 | static unsigned short replay_transmit(cardreader_t* cr,
48 | const bytestring_t* command,
49 | bytestring_t* result)
50 | {
51 | cardreplay_t* emul = cr->extra_data;
52 | unsigned short SW = CARDPEEK_ERROR_SW;
53 |
54 | if (cr->connected)
55 | cardreplay_run_command(emul,command,&SW,result);
56 | return SW;
57 | }
58 |
59 | static const bytestring_t* replay_last_atr(cardreader_t* cr)
60 | {
61 | cardreplay_t* emul = cr->extra_data;
62 |
63 | if (cr->connected)
64 | cardreplay_run_last_atr(emul,cr->atr);
65 | return cr->atr;
66 | }
67 |
68 | static char** replay_get_info(cardreader_t* cr)
69 | {
70 | UNUSED(cr);
71 | return NULL; /* nothing to add */
72 | }
73 |
74 | static int replay_fail(cardreader_t* cr)
75 | {
76 | return (cr->connected==0);
77 | }
78 |
79 | static void replay_finalize(cardreader_t* cr)
80 | {
81 | cardreplay_t* emul = cr->extra_data;
82 | free(emul);
83 | }
84 |
85 | static int replay_initialize(cardreader_t *reader)
86 | {
87 | char fname[PATH_MAX];
88 | cardreplay_t* emul = cardreplay_new_from_file(fname);
89 |
90 | sprintf(fname,"%s/%s",path_config_get_string(PATH_CONFIG_FOLDER_REPLAY), reader->name+9);
91 |
92 | emul = cardreplay_new_from_file(fname);
93 |
94 | if (emul==NULL)
95 | {
96 | log_printf(LOG_ERROR,"Could not load %s",fname);
97 | return 0;
98 | }
99 |
100 | reader->extra_data = emul;
101 |
102 | reader->connect = replay_connect;
103 | reader->disconnect = replay_disconnect;
104 | reader->reset = replay_reset;
105 | reader->transmit = replay_transmit;
106 | reader->last_atr = replay_last_atr;
107 | reader->get_info = replay_get_info;
108 | reader->fail = replay_fail;
109 | reader->finalize = replay_finalize;
110 | return 1;
111 | }
112 |
113 |
--------------------------------------------------------------------------------
/update_dot_cardpeek_dir.sh:
--------------------------------------------------------------------------------
1 | #/bin/bash
2 |
3 | VERSION=`date +%s`
4 |
5 | SOURCE_DST=`pwd`
6 |
7 | if [ "x$CARDPEEK_DST"="x" ]
8 | then
9 | DOT_CARDPEEK_SRC=~/.cardpeek
10 | else
11 | DOT_CARDPEEK_SRC=$CARDPEEK_DST
12 | fi
13 |
14 | DOT_CARDPEEK_DST="$SOURCE_DST/dot_cardpeek_dir"
15 |
16 | MODIFIED='no'
17 |
18 | case "$1"
19 | in
20 | dryrun)
21 | TODO=dryrun
22 | ;;
23 | update)
24 | TODO=update
25 | ;;
26 | *)
27 | echo "Usage: $0 [dryrun|update]"
28 | echo " 'dryrun' just prints what the script would do, without actually doing it."
29 | echo " 'update' actually does the work."
30 | exit
31 | ;;
32 | esac
33 |
34 |
35 | if [ -d "$DOT_CARDPEEK_SRC" ]; then
36 |
37 | cd $DOT_CARDPEEK_SRC
38 |
39 | echo "## Retrieving new files:"
40 | IFS=$'\t\n'
41 | for i in `find * \! -path replay/\* \! -path scripts.old\* \! -name \\.\*`;
42 | do
43 | if [ -d "$i" ]; then
44 | if [ ! -e "$DOT_CARDPEEK_DST/$i" ]; then
45 | echo "!! creating dir $DOT_CARDPEEK_DST/$i"
46 | if [ $TODO = "update" ]; then
47 | mkdir -p "$DOT_CARDPEEK_DST/$i"
48 | MODIFIED='yes'
49 | fi
50 | fi
51 | elif test ! -e "$DOT_CARDPEEK_DST/$i" || (diff -q "$i" "$DOT_CARDPEEK_DST/$i" | grep differ) &> /dev/null; then
52 | if [ "$i" -nt "$DOT_CARDPEEK_DST/$i" ]; then
53 | echo ">> $DOT_CARDPEEK_SRC/$i will be copied to $DOT_CARDPEEK_DST/$i"
54 | if [ $TODO = "update" ]; then
55 | cp -pRv "$i" "$DOT_CARDPEEK_DST/$i"
56 | MODIFIED='yes'
57 | fi
58 | elif [ "$i" -ot "$DOT_CARDPEEK_DST/$i" ]; then
59 | echo "<< $DOT_CARDPEEK_SRC/$i will be replaced by $DOT_CARDPEEK_DST/$i"
60 | if [ $TODO = "update" ]; then
61 | cp -pRv "$DOT_CARDPEEK_DST/$i" "$i"
62 | MODIFIED='yes'
63 | fi
64 | fi
65 | fi
66 | done
67 |
68 | if [ "$TODO" = "update" ]; then
69 | if [ "$MODIFIED" = 'yes' ]; then
70 | echo "## Removing unecessary files and updating directory modfication time:"
71 | rm -vf $DOT_CARDPEEK_DST/replay/*
72 | touch $DOT_CARDPEEK_DST
73 |
74 | echo "## Creating default config.lua"
75 | cat > "$DOT_CARDPEEK_DST/config.lua" << __EOF
76 | --
77 | -- This file is automatically generated by Cardpeek.
78 | -- It holds cardpeek configuration parameters, which are stored in the
79 | -- lua 'cardpeek' table.
80 | --
81 | -- See cardpeekrc.lua for adding your own functions and variables to
82 | -- cardpeek.
83 | --
84 | cardpeek = {
85 | }
86 |
87 | dofile('scripts/lib/apdu.lua')
88 | -- end --
89 | __EOF
90 |
91 | echo "## Set version info:"
92 | echo " Version ID is now $VERSION"
93 | echo $VERSION > $DOT_CARDPEEK_DST/version
94 | echo $VERSION > $DOT_CARDPEEK_SRC/version
95 | cat > "$SOURCE_DST/script_version.h" << __EOF
96 | #ifndef SCRIPT_VERSION_H
97 | #define SCRIPT_VERSION_H
98 |
99 | #define SCRIPT_VERSION $VERSION
100 |
101 | #endif
102 | __EOF
103 | if (echo "$OSTYPE"| grep -q "darwin"); then
104 | echo "## Removing OS X annoying extended attributes."
105 | find $DOT_CARDPEEK_DST -xattr -exec xattr -c {} \;
106 | fi
107 | else
108 | echo "## No updates performed."
109 | fi
110 | fi
111 | echo "## Done"
112 | else
113 | echo "Error: ~/.cardpeek does not exist. Doing nothing"
114 | fi
115 |
--------------------------------------------------------------------------------
/pathconfig.c:
--------------------------------------------------------------------------------
1 | /**********************************************************************
2 | *
3 | * This file is part of Cardpeek, the smart card reader utility.
4 | *
5 | * Copyright 2009-2014 by Alain Pannetrat
6 | *
7 | * Cardpeek is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * Cardpeek is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with Cardpeek. If not, see .
19 | *
20 | */
21 |
22 | #include "pathconfig.h"
23 | #include
24 | #include
25 | #include
26 | #include
27 | #include
28 | #include "misc.h"
29 |
30 | const char *PATH_CONFIG_OPTIONS[NUM_PATH_CONFIG_OPTIONS]=
31 | {
32 | NULL,
33 | NULL,
34 | NULL,
35 | "",
36 | "scripts",
37 | "replay",
38 | "logs",
39 | "config.lua",
40 | "cardpeekrc.lua",
41 | "version",
42 | "scripts/etc/smartcard_list.txt",
43 | "scripts/etc/smartcard_list.download",
44 | "cardpeek.update"
45 | };
46 |
47 | char *PATH_CONFIG_STRING[NUM_PATH_CONFIG_OPTIONS];
48 |
49 |
50 | int path_config_init(void)
51 | {
52 | char path_config_string[PATH_MAX];
53 | char current_working_dir[PATH_MAX];
54 | char cardpeek_dir[PATH_MAX];
55 | const char *home_dir;
56 | unsigned i;
57 |
58 | #ifndef _WIN32
59 | home_dir = getenv("HOME");
60 | #else
61 | home_dir = getenv("USERDATA");
62 | if (home_dir==NULL)
63 | home_dir = getenv("USERPROFILE");
64 | #endif
65 | if (home_dir==NULL)
66 | return 0;
67 |
68 | if (getenv("CARDPEEK_DIR"))
69 | strncpy(cardpeek_dir,getenv("CARDPEEK_DIR"),PATH_MAX);
70 | else
71 | snprintf(cardpeek_dir,PATH_MAX,"%s/.cardpeek",home_dir);
72 |
73 | if (getcwd(current_working_dir,PATH_MAX))
74 | PATH_CONFIG_STRING[0]=strdup(current_working_dir);
75 | else
76 | PATH_CONFIG_STRING[0]=strdup(home_dir);
77 |
78 | snprintf(path_config_string,PATH_MAX,"%s/.cardpeek.log",home_dir);
79 | PATH_CONFIG_STRING[1]=strdup(path_config_string);
80 |
81 | PATH_CONFIG_STRING[2]=strdup(home_dir);
82 |
83 | for (i=PATH_CONFIG_FOLDER_CARDPEEK; iNUM_PATH_CONFIG_OPTIONS)
94 | return NULL;
95 |
96 | return PATH_CONFIG_STRING[c_index];
97 | }
98 |
99 | int path_config_set_string(unsigned c_index, const char *path)
100 | {
101 | if (c_index>NUM_PATH_CONFIG_OPTIONS)
102 | return 0;
103 | if (PATH_CONFIG_STRING[c_index])
104 | free(PATH_CONFIG_STRING[c_index]);
105 | if (path)
106 | PATH_CONFIG_STRING[c_index]=strdup(path);
107 | else
108 | PATH_CONFIG_STRING[c_index]=strdup("");
109 | return 1;
110 | }
111 |
112 | void path_config_release(void)
113 | {
114 | unsigned i;
115 | for (i=0; i
6 | *
7 | * Cardpeek is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * Cardpeek is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with Cardpeek. If not, see .
19 | *
20 | */
21 | #include "system_info.h"
22 |
23 | /* this hash function is used by SDBM. */
24 | static unsigned int simple_hash(const char *str)
25 | {
26 | unsigned int hash = 0;
27 | int c;
28 |
29 | while ((c = *str++)!=0)
30 | hash = c + (hash << 6) + (hash << 16) - hash;
31 | return hash;
32 | }
33 |
34 | #ifndef _WIN32
35 | #include
36 | #include
37 | #include "config.h"
38 | #include
39 |
40 | const char *system_type(void)
41 | {
42 | static char info[32];
43 | static struct utsname u;
44 |
45 | if (uname(&u)<0)
46 | {
47 | return "Unknown";
48 | }
49 | snprintf(info,32,"%s",u.sysname);
50 |
51 | return info;
52 | }
53 |
54 | const char *system_string_info(void)
55 | {
56 | static char info[128];
57 | static struct utsname u;
58 |
59 | if (uname(&u)<0)
60 | {
61 | return "Unknown OS";
62 | }
63 | snprintf(info,128,"%s %s %s",u.sysname,u.release,u.machine);
64 |
65 | return info;
66 | }
67 |
68 | unsigned int system_name_hash(void)
69 | {
70 | static struct utsname u;
71 | if (uname(&u)<0)
72 | {
73 | return 0;
74 | }
75 | return simple_hash(u.nodename);
76 | }
77 |
78 | #else
79 |
80 | #include
81 | #include
82 | #include
83 | #include "win32/config.h"
84 |
85 | const char *system_type(void)
86 | {
87 | return "Windows";
88 | }
89 |
90 | typedef void (WINAPI *PGNSI)(LPSYSTEM_INFO);
91 |
92 | const char *system_string_info(void)
93 | {
94 | static char info[128];
95 | SYSTEM_INFO si;
96 | OSVERSIONINFOEX osvi;
97 | PGNSI GetNativeSystemInfo_func;
98 |
99 | memset(&si,0,sizeof(si));
100 | memset(&osvi,0,sizeof(osvi));
101 |
102 | osvi.dwOSVersionInfoSize = sizeof(osvi);
103 | GetVersionEx((OSVERSIONINFO*)&osvi);
104 |
105 | GetNativeSystemInfo_func = (PGNSI) GetProcAddress(
106 | GetModuleHandle(TEXT("kernel32.dll")),
107 | "GetNativeSystemInfo");
108 |
109 | if (GetNativeSystemInfo_func!=NULL)
110 | GetNativeSystemInfo_func(&si);
111 | else
112 | GetSystemInfo(&si);
113 |
114 | snprintf(info,110,"Cardpeek %s on Windows NT_%u.%u (%s) ",
115 | VERSION,
116 | (unsigned)osvi.dwMajorVersion,
117 | (unsigned)osvi.dwMinorVersion,
118 | osvi.szCSDVersion);
119 |
120 | switch (si.wProcessorArchitecture) {
121 | case 9: strcat(info,"AMD64");
122 | break;
123 | case 6: strcat(info,"IA64");
124 | break;
125 | case 0: strcat(info,"x86");
126 | break;
127 | default: strcat(info,"Unknown platform");
128 | };
129 | return info;
130 | }
131 |
132 | unsigned int system_name_hash()
133 | {
134 | static char computer_name[1024];
135 | DWORD size = 1024;
136 | GetComputerName(computer_name,&size);
137 | return simple_hash(computer_name);
138 | }
139 |
140 |
141 | #endif
142 |
143 |
--------------------------------------------------------------------------------
/lua_iconv.c:
--------------------------------------------------------------------------------
1 | /**********************************************************************
2 | *
3 | * This file is part of Cardpeek, the smart card reader utility.
4 | *
5 | * Copyright 2009-2014 by Alain Pannetrat
6 | *
7 | * Cardpeek is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * Cardpeek is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with Cardpeek. If not, see .
19 | *
20 | */
21 | #include
22 | #include "lua_iconv.h"
23 | #include
24 | #include "a_string.h"
25 | #include
26 | #include
27 | #include "misc.h"
28 | #include "win32/config.h"
29 |
30 | static void lua_push_iconv(lua_State* L, iconv_t ic)
31 | {
32 | iconv_t *ptr = (iconv_t*)lua_newuserdata(L,sizeof(iconv_t));
33 | *ptr = ic;
34 | luaL_getmetatable(L, "iconv.type");
35 | lua_setmetatable(L,-2);
36 | }
37 |
38 | static iconv_t luaL_check_iconv(lua_State *L, int p)
39 | {
40 | void *ud = luaL_checkudata(L,p,"iconv.type");
41 | luaL_argcheck(L, ud != NULL, p, "`iconv' expected");
42 | return *(iconv_t *)ud;
43 | }
44 |
45 | static int subr_iconv_open(lua_State *L)
46 | {
47 | const char *fromcode = luaL_checkstring(L,1);
48 | const char *tocode = luaL_checkstring(L,2);
49 | iconv_t ic = iconv_open(tocode,fromcode);
50 |
51 | if (ic==(iconv_t)(-1))
52 | {
53 | lua_pushnil(L);
54 | return 1;
55 | }
56 | lua_push_iconv(L,ic);
57 | return 1;
58 | }
59 |
60 | static int subr_iconv_iconv(lua_State *L)
61 | {
62 | iconv_t ic = luaL_check_iconv(L,1);
63 | ICONV_CONST char *src = (ICONV_CONST char *)luaL_checkstring(L,2);
64 | size_t src_len = strlen(src);
65 | char conv_block[16];
66 | size_t conv_len;
67 | char *conv_block_ptr;
68 | a_string_t *dst = a_strnew(NULL);
69 |
70 | while (src_len>0)
71 | {
72 | conv_len = 16;
73 | conv_block_ptr = conv_block;
74 | if (iconv(ic, &src, &src_len, &conv_block_ptr, &conv_len)==(size_t)(-1))
75 | {
76 | if (errno!=E2BIG)
77 | {
78 | a_strfree(dst);
79 | lua_pushnil(L);
80 | return 1;
81 | }
82 | }
83 | a_strncat(dst,16-conv_len,conv_block);
84 | }
85 | lua_pushstring(L,a_strval(dst));
86 | a_strfree(dst);
87 | return 1;
88 | }
89 |
90 | static int subr_iconv_close(lua_State *L)
91 | {
92 | iconv_t ic = luaL_check_iconv(L,1);
93 |
94 | iconv_close(ic);
95 |
96 | return 0;
97 | }
98 |
99 | static const struct luaL_Reg iconvlib_m [] = {
100 | {"__gc",subr_iconv_close},
101 | {"open",subr_iconv_open},
102 | {"iconv",subr_iconv_iconv},
103 | {NULL,NULL}
104 | };
105 |
106 | static const struct luaL_Reg iconvlib_f [] = {
107 | {"open",subr_iconv_open},
108 | {"iconv",subr_iconv_iconv},
109 | {NULL,NULL}
110 | };
111 |
112 | int luaopen_iconv(lua_State* L)
113 | {
114 | luaL_newmetatable(L, "iconv.type");
115 | lua_pushstring(L, "__index");
116 | lua_pushvalue(L, -2); /* pushes the metatable */
117 | lua_settable(L, -3); /* metatable.__index = metatable */
118 | luaL_setfuncs(L, iconvlib_m, 0);
119 | luaL_newlib(L, iconvlib_f);
120 | lua_setglobal(L,"iconv");
121 | lua_pop(L,1); /* pop the metatable */
122 | return 1;
123 | }
124 |
125 |
126 |
127 |
--------------------------------------------------------------------------------
/m4/lib-ld.m4:
--------------------------------------------------------------------------------
1 | # lib-ld.m4 serial 6
2 | dnl Copyright (C) 1996-2003, 2009-2013 Free Software Foundation, Inc.
3 | dnl This file is free software; the Free Software Foundation
4 | dnl gives unlimited permission to copy and/or distribute it,
5 | dnl with or without modifications, as long as this notice is preserved.
6 |
7 | dnl Subroutines of libtool.m4,
8 | dnl with replacements s/_*LT_PATH/AC_LIB_PROG/ and s/lt_/acl_/ to avoid
9 | dnl collision with libtool.m4.
10 |
11 | dnl From libtool-2.4. Sets the variable with_gnu_ld to yes or no.
12 | AC_DEFUN([AC_LIB_PROG_LD_GNU],
13 | [AC_CACHE_CHECK([if the linker ($LD) is GNU ld], [acl_cv_prog_gnu_ld],
14 | [# I'd rather use --version here, but apparently some GNU lds only accept -v.
15 | case `$LD -v 2>&1 /dev/null 2>&1 \
45 | && { (PATH='/bin:/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 \
46 | || PATH_SEPARATOR=';'
47 | }
48 | fi
49 |
50 | ac_prog=ld
51 | if test "$GCC" = yes; then
52 | # Check if gcc -print-prog-name=ld gives a path.
53 | AC_MSG_CHECKING([for ld used by $CC])
54 | case $host in
55 | *-*-mingw*)
56 | # gcc leaves a trailing carriage return which upsets mingw
57 | ac_prog=`($CC -print-prog-name=ld) 2>&5 | tr -d '\015'` ;;
58 | *)
59 | ac_prog=`($CC -print-prog-name=ld) 2>&5` ;;
60 | esac
61 | case $ac_prog in
62 | # Accept absolute paths.
63 | [[\\/]]* | ?:[[\\/]]*)
64 | re_direlt='/[[^/]][[^/]]*/\.\./'
65 | # Canonicalize the pathname of ld
66 | ac_prog=`echo "$ac_prog"| sed 's%\\\\%/%g'`
67 | while echo "$ac_prog" | grep "$re_direlt" > /dev/null 2>&1; do
68 | ac_prog=`echo $ac_prog| sed "s%$re_direlt%/%"`
69 | done
70 | test -z "$LD" && LD="$ac_prog"
71 | ;;
72 | "")
73 | # If it fails, then pretend we aren't using GCC.
74 | ac_prog=ld
75 | ;;
76 | *)
77 | # If it is relative, then search for the first ld in PATH.
78 | with_gnu_ld=unknown
79 | ;;
80 | esac
81 | elif test "$with_gnu_ld" = yes; then
82 | AC_MSG_CHECKING([for GNU ld])
83 | else
84 | AC_MSG_CHECKING([for non-GNU ld])
85 | fi
86 | AC_CACHE_VAL([acl_cv_path_LD],
87 | [if test -z "$LD"; then
88 | acl_save_ifs="$IFS"; IFS=$PATH_SEPARATOR
89 | for ac_dir in $PATH; do
90 | IFS="$acl_save_ifs"
91 | test -z "$ac_dir" && ac_dir=.
92 | if test -f "$ac_dir/$ac_prog" || test -f "$ac_dir/$ac_prog$ac_exeext"; then
93 | acl_cv_path_LD="$ac_dir/$ac_prog"
94 | # Check to see if the program is GNU ld. I'd rather use --version,
95 | # but apparently some variants of GNU ld only accept -v.
96 | # Break only if it was the GNU/non-GNU ld that we prefer.
97 | case `"$acl_cv_path_LD" -v 2>&1
6 | *
7 | * Cardpeek is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * Cardpeek is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with Cardpeek. If not, see .
19 | *
20 | */
21 |
22 | #include "gui_toolbar.h"
23 | #include "string.h"
24 | #include "misc.h"
25 | #include "lua_ext.h"
26 |
27 | /*********************************************************/
28 | /* EXPERIMENTAL ******************************************/
29 | /*********************************************************/
30 | /*
31 | GHashTable *WIDGET_TABLE = NULL;
32 |
33 | static guint stringhash(gconstpointer str)
34 | {
35 | const unsigned char *s = str;
36 | guint res=0;
37 | while (*s)
38 | {
39 | res = (res*27)+(*s);
40 | s++;
41 | }
42 | return res;
43 | }
44 |
45 | static gint stringcompare(gconstpointer a, gconstpointer b)
46 | {
47 | return (strcmp(a,b)==0);
48 | }
49 |
50 | static gboolean gui_widget_table_init(void)
51 | {
52 | WIDGET_TABLE = g_hash_table_new(stringhash,stringcompare);
53 | return TRUE;
54 | }
55 |
56 | static void gui_widget_table_release(void)
57 | {
58 | g_hash_table_destroy(WIDGET_TABLE);
59 | }
60 |
61 | #ifdef _DEAD_CODE_
62 | static GtkWidget *gui_widget_table_lookup(const gchar *name)
63 | {
64 | return (GtkWidget *)g_hash_table_lookup(WIDGET_TABLE,name);
65 | }
66 | #endif
67 |
68 | static void gui_widget_table_insert(const gchar *name, const GtkWidget *widget)
69 | {
70 | g_hash_table_insert(WIDGET_TABLE,(gpointer)name,(gpointer)widget);
71 | }
72 | */
73 |
74 |
75 | GtkWidget *gui_toolbar_new(toolbar_item_t *tbitems)
76 | {
77 | GtkWidget *icon;
78 | GtkWidget *toolbar;
79 | GtkToolItem *item;
80 | int i;
81 |
82 | toolbar = gtk_toolbar_new();
83 |
84 | gtk_orientable_set_orientation (GTK_ORIENTABLE (toolbar), GTK_ORIENTATION_HORIZONTAL );
85 | gtk_toolbar_set_style (GTK_TOOLBAR (toolbar), GTK_TOOLBAR_BOTH);
86 |
87 | for (i=0; tbitems[i].icon!=NULL; i++)
88 | {
89 | if (strcmp(tbitems[i].icon,TOOLBAR_ITEM_SEPARATOR)==0)
90 | {
91 | item = gtk_separator_tool_item_new();
92 | gtk_toolbar_insert(GTK_TOOLBAR(toolbar), GTK_TOOL_ITEM(item),-1);
93 |
94 | }
95 | else if (strcmp(tbitems[i].icon,TOOLBAR_ITEM_EXPANDER)==0)
96 | {
97 | item = gtk_separator_tool_item_new();
98 | gtk_separator_tool_item_set_draw (GTK_SEPARATOR_TOOL_ITEM(item),FALSE);
99 | gtk_tool_item_set_expand(GTK_TOOL_ITEM(item),TRUE);
100 | gtk_toolbar_insert(GTK_TOOLBAR(toolbar), GTK_TOOL_ITEM(item),-1);
101 |
102 | }
103 | else
104 | {
105 | icon = gtk_image_new_from_icon_name(tbitems[i].icon, GTK_ICON_SIZE_LARGE_TOOLBAR);
106 | item = gtk_tool_button_new(icon, tbitems[i].text);
107 | if (tbitems[i].callback)
108 | g_signal_connect(G_OBJECT(item),"clicked",G_CALLBACK(tbitems[i].callback),(gpointer)tbitems[i].callback_data);
109 | if (tbitems[i].tooltip)
110 | gtk_widget_set_tooltip_text(GTK_WIDGET(item),tbitems[i].tooltip);
111 | gtk_toolbar_insert(GTK_TOOLBAR(toolbar), GTK_TOOL_ITEM(item),-1);
112 | }
113 | }
114 | return toolbar;
115 | }
116 |
117 | void gui_toolbar_run_command_cb(GtkWidget *w, gconstpointer user_data)
118 | {
119 | UNUSED(w);
120 |
121 | if (user_data)
122 | luax_run_command((char *)user_data);
123 | else
124 | log_printf(LOG_ERROR,"No command to execute");
125 | }
126 |
127 |
--------------------------------------------------------------------------------
/smartcard.h:
--------------------------------------------------------------------------------
1 | /**********************************************************************
2 | *
3 | * This file is part of Cardpeek, the smart card reader utility.
4 | *
5 | * Copyright 2009-2013 by Alain Pannetrat
6 | *
7 | * Cardpeek is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * Cardpeek is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with Cardpeek. If not, see .
19 | *
20 | */
21 |
22 | #include
23 |
24 | #ifndef SMARTCARD_H
25 | #define SMARTCARD_H
26 |
27 | #include "bytestring.h"
28 | #include "replay.h"
29 |
30 | #define PROTOCOL_T0 1
31 | #define PROTOCOL_T1 2
32 |
33 | enum {
34 | SMARTCARD_ERROR,
35 | SMARTCARD_OK
36 | };
37 |
38 | #define CARDPEEK_ERROR_SW 0x6FFF
39 |
40 | /********************************************************************
41 | * CARDMANAGER
42 | */
43 |
44 | typedef struct {
45 | char **readers;
46 | unsigned readers_count;
47 | } cardmanager_t;
48 |
49 | cardmanager_t *cardmanager_new(void);
50 |
51 | void cardmanager_free(cardmanager_t* cm);
52 |
53 | unsigned cardmanager_count_readers(cardmanager_t* cm);
54 |
55 | const char *cardmanager_reader_name(cardmanager_t* cm, unsigned index);
56 |
57 | const char **cardmanager_reader_name_list(cardmanager_t* cm);
58 |
59 | /********************************************************************
60 | * CARDREADER
61 | */
62 |
63 | enum {
64 | CARDREADER_EVENT_CONNECT,
65 | CARDREADER_EVENT_DISCONNECT,
66 | CARDREADER_EVENT_RESET,
67 | CARDREADER_EVENT_TRANSMIT,
68 | CARDREADER_EVENT_FINALIZE,
69 | CARDREADER_EVENT_CLEAR_LOG,
70 | CARDREADER_EVENT_SAVE_LOG
71 | };
72 |
73 | typedef void (*cardreader_callback_t)(unsigned,const bytestring_t*,unsigned short, const bytestring_t*,void*);
74 |
75 | typedef struct _cardreader_t cardreader_t;
76 |
77 | struct _cardreader_t {
78 | char *name;
79 | unsigned connected;
80 | #ifdef __APPLE__
81 | uint32_t protocol;
82 | #else
83 | unsigned long protocol;
84 | #endif
85 | uint16_t sw;
86 | unsigned command_interval;
87 | bytestring_t *atr;
88 | void *extra_data;
89 | cardreader_callback_t cb_func;
90 | void *cb_data;
91 | cardreplay_t *cardlog;
92 |
93 | int (*connect)(cardreader_t*, unsigned);
94 | int (*disconnect)(cardreader_t*);
95 | int (*reset)(cardreader_t*);
96 | unsigned short (*transmit)(cardreader_t*,const bytestring_t*, bytestring_t*);
97 | const bytestring_t* (*last_atr)(cardreader_t*);
98 | char** (*get_info)(cardreader_t*);
99 | int (*fail)(cardreader_t*);
100 | void (*finalize)(cardreader_t*);
101 | };
102 |
103 |
104 | cardreader_t* cardreader_new(const char *card_reader_name);
105 |
106 | int cardreader_connect(cardreader_t *reader, unsigned protocol);
107 |
108 | int cardreader_disconnect(cardreader_t *reader);
109 |
110 | int cardreader_warm_reset(cardreader_t *reader);
111 |
112 | unsigned short cardreader_transmit(cardreader_t *reader,
113 | const bytestring_t* command,
114 | bytestring_t* result);
115 |
116 | unsigned short cardreader_get_sw(cardreader_t *reader);
117 |
118 | const bytestring_t* cardreader_last_atr(cardreader_t *reader);
119 |
120 | char** cardreader_get_info(cardreader_t *reader);
121 |
122 | int cardreader_fail(cardreader_t *reader);
123 |
124 | void cardreader_free(cardreader_t *reader);
125 |
126 | void cardreader_set_command_interval(cardreader_t *reader, unsigned interval);
127 |
128 | void cardreader_set_callback(cardreader_t *reader, cardreader_callback_t func, void *user_data);
129 |
130 | void cardreader_log_clear(cardreader_t *reader);
131 |
132 | int cardreader_log_save(const cardreader_t *reader, const char *filename);
133 |
134 | int cardreader_log_count_records(const cardreader_t *reader);
135 |
136 | #endif
137 |
--------------------------------------------------------------------------------
/ui.c:
--------------------------------------------------------------------------------
1 | /**********************************************************************
2 | *
3 | * This file is part of Cardpeek, the smart card reader utility.
4 | *
5 | * Copyright 2009-2013 by Alain Pannetrat
6 | *
7 | * Cardpeek is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * Cardpeek is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with Cardpeek. If not, see .
19 | *
20 | */
21 |
22 | #include
23 | #include
24 | #include
25 | #include "ui.h"
26 |
27 | ui_driver_t *UI_DRIVER = NULL;
28 |
29 | const char *ui_driver_name(void)
30 | {
31 | if (UI_DRIVER==NULL)
32 | return NULL;
33 | return UI_DRIVER->ui_driver_name();
34 | }
35 |
36 | int ui_initialize(ui_driver_t *driver, int *argc, char ***argv)
37 | {
38 | UI_DRIVER = driver;
39 | return UI_DRIVER->ui_initialize(argc, argv);
40 | }
41 |
42 | int ui_question(const char *message, ...)
43 | {
44 | va_list al;
45 | const char *item;
46 | unsigned item_count=0;
47 | const char **item_table;
48 | int retval;
49 |
50 | va_start(al,message);
51 | while (va_arg(al,const char *)) item_count++;
52 | va_end(al);
53 |
54 | item_table=g_malloc(sizeof(const char *)*item_count);
55 | item_count=0;
56 |
57 | va_start(al,message);
58 | while ((item=va_arg(al,const char *)))
59 | item_table[item_count++]=item;
60 | va_end(al);
61 |
62 | retval = ui_question_l(message,item_count,item_table);
63 | g_free(item_table);
64 | return retval;
65 | }
66 |
67 | int ui_question_l(const char *message, unsigned item_count, const char **items)
68 | {
69 | return UI_DRIVER->ui_question_l(message,item_count,items);
70 | }
71 |
72 | int ui_readline(const char *message, unsigned input_max, char *input)
73 | /* input_max does not include final '\0' */
74 | {
75 | return UI_DRIVER->ui_readline(message,input_max,input);
76 | }
77 |
78 | char **ui_select_file(const char *title,
79 | const char *path,
80 | const char *filename)
81 | {
82 | return UI_DRIVER->ui_select_file(title,path,filename);
83 | }
84 |
85 | void ui_update(void)
86 | {
87 | UI_DRIVER->ui_update();
88 | }
89 |
90 | void ui_exit(void)
91 | {
92 | UI_DRIVER->ui_exit();
93 | }
94 |
95 | char *ui_select_reader(unsigned list_size, const char **list)
96 | {
97 | return UI_DRIVER->ui_select_reader(list_size,list);
98 | }
99 |
100 | int ui_run(const char *optional_command)
101 | {
102 | return UI_DRIVER->ui_run(optional_command);
103 | }
104 |
105 | void ui_set_title(const char *title)
106 | {
107 | char atitle[80];
108 |
109 | g_snprintf(atitle,80,"cardpeek: %s",title);
110 | atitle[79]=0;
111 | UI_DRIVER->ui_set_title(atitle);
112 | }
113 |
114 | void ui_about(void)
115 | {
116 | UI_DRIVER->ui_about();
117 | }
118 |
119 | void *ui_inprogress_new(const char *title, const char *message)
120 | {
121 | return UI_DRIVER->ui_inprogress_new(title,message);
122 | }
123 |
124 | unsigned ui_inprogress_pulse(void *pulser)
125 | {
126 | return UI_DRIVER->ui_inprogress_pulse(pulser);
127 | }
128 |
129 | unsigned ui_inprogress_set_fraction(void *pulser, double level)
130 | {
131 | return UI_DRIVER->ui_inprogress_set_fraction(pulser,level);
132 | }
133 |
134 | void ui_inprogress_free(void *pulser)
135 | {
136 | UI_DRIVER->ui_inprogress_free(pulser);
137 | }
138 |
139 | void ui_card_event_print(unsigned event,
140 | const bytestring_t *command,
141 | unsigned short sw,
142 | const bytestring_t *response,
143 | void *extra_data)
144 | {
145 | UI_DRIVER->ui_card_event_print(event,command,sw,response,extra_data);
146 | }
147 | /************/
148 |
149 |
150 |
--------------------------------------------------------------------------------
/m4/ax_lib_readline.m4:
--------------------------------------------------------------------------------
1 | # ===========================================================================
2 | # http://www.gnu.org/software/autoconf-archive/ax_lib_readline.html
3 | # ===========================================================================
4 | #
5 | # SYNOPSIS
6 | #
7 | # AX_LIB_READLINE
8 | #
9 | # DESCRIPTION
10 | #
11 | # Searches for a readline compatible library. If found, defines
12 | # `HAVE_LIBREADLINE'. If the found library has the `add_history' function,
13 | # sets also `HAVE_READLINE_HISTORY'. Also checks for the locations of the
14 | # necessary include files and sets `HAVE_READLINE_H' or
15 | # `HAVE_READLINE_READLINE_H' and `HAVE_READLINE_HISTORY_H' or
16 | # 'HAVE_HISTORY_H' if the corresponding include files exists.
17 | #
18 | # The libraries that may be readline compatible are `libedit',
19 | # `libeditline' and `libreadline'. Sometimes we need to link a termcap
20 | # library for readline to work, this macro tests these cases too by trying
21 | # to link with `libtermcap', `libcurses' or `libncurses' before giving up.
22 | #
23 | # Here is an example of how to use the information provided by this macro
24 | # to perform the necessary includes or declarations in a C file:
25 | #
26 | # #ifdef HAVE_LIBREADLINE
27 | # # if defined(HAVE_READLINE_READLINE_H)
28 | # # include
29 | # # elif defined(HAVE_READLINE_H)
30 | # # include
31 | # # else /* !defined(HAVE_READLINE_H) */
32 | # extern char *readline ();
33 | # # endif /* !defined(HAVE_READLINE_H) */
34 | # char *cmdline = NULL;
35 | # #else /* !defined(HAVE_READLINE_READLINE_H) */
36 | # /* no readline */
37 | # #endif /* HAVE_LIBREADLINE */
38 | #
39 | # #ifdef HAVE_READLINE_HISTORY
40 | # # if defined(HAVE_READLINE_HISTORY_H)
41 | # # include
42 | # # elif defined(HAVE_HISTORY_H)
43 | # # include
44 | # # else /* !defined(HAVE_HISTORY_H) */
45 | # extern void add_history ();
46 | # extern int write_history ();
47 | # extern int read_history ();
48 | # # endif /* defined(HAVE_READLINE_HISTORY_H) */
49 | # /* no history */
50 | # #endif /* HAVE_READLINE_HISTORY */
51 | #
52 | # LICENSE
53 | #
54 | # Copyright (c) 2008 Ville Laurikari
55 | #
56 | # Copying and distribution of this file, with or without modification, are
57 | # permitted in any medium without royalty provided the copyright notice
58 | # and this notice are preserved. This file is offered as-is, without any
59 | # warranty.
60 |
61 | #serial 6
62 |
63 | AU_ALIAS([VL_LIB_READLINE], [AX_LIB_READLINE])
64 | AC_DEFUN([AX_LIB_READLINE], [
65 | AC_CACHE_CHECK([for a readline compatible library],
66 | ax_cv_lib_readline, [
67 | ORIG_LIBS="$LIBS"
68 | for readline_lib in readline edit editline; do
69 | for termcap_lib in "" termcap curses ncurses; do
70 | if test -z "$termcap_lib"; then
71 | TRY_LIB="-l$readline_lib"
72 | else
73 | TRY_LIB="-l$readline_lib -l$termcap_lib"
74 | fi
75 | LIBS="$ORIG_LIBS $TRY_LIB"
76 | AC_TRY_LINK_FUNC(readline, ax_cv_lib_readline="$TRY_LIB")
77 | if test -n "$ax_cv_lib_readline"; then
78 | break
79 | fi
80 | done
81 | if test -n "$ax_cv_lib_readline"; then
82 | break
83 | fi
84 | done
85 | if test -z "$ax_cv_lib_readline"; then
86 | ax_cv_lib_readline="no"
87 | fi
88 | LIBS="$ORIG_LIBS"
89 | ])
90 |
91 | if test "$ax_cv_lib_readline" != "no"; then
92 | LIBS="$LIBS $ax_cv_lib_readline"
93 | AC_DEFINE(HAVE_LIBREADLINE, 1,
94 | [Define if you have a readline compatible library])
95 | AC_CHECK_HEADERS(readline.h readline/readline.h)
96 | AC_CACHE_CHECK([whether readline supports history],
97 | ax_cv_lib_readline_history, [
98 | ax_cv_lib_readline_history="no"
99 | AC_TRY_LINK_FUNC(add_history, ax_cv_lib_readline_history="yes")
100 | ])
101 | if test "$ax_cv_lib_readline_history" = "yes"; then
102 | AC_DEFINE(HAVE_READLINE_HISTORY, 1,
103 | [Define if your readline library has \`add_history'])
104 | AC_CHECK_HEADERS(history.h readline/history.h)
105 | fi
106 | fi
107 | ])dnl
108 |
--------------------------------------------------------------------------------
/ui/gtk/gui_inprogress.c:
--------------------------------------------------------------------------------
1 | /**********************************************************************
2 | *
3 | * This file is part of Cardpeek, the smart card reader utility.
4 | *
5 | * Copyright 2009-2014 by Alain Pannetrat
6 | *
7 | * Cardpeek is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * Cardpeek is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with Cardpeek. If not, see .
19 | *
20 | */
21 |
22 | #include "ui.h"
23 | #include "gui_inprogress.h"
24 | #include "misc.h"
25 | #include "gui_core.h"
26 |
27 | /*********************************************************/
28 | /* LOG FUNCTIONS AND UI CALLBACKS ************************/
29 | /*********************************************************/
30 |
31 | typedef struct {
32 | unsigned in_progress;
33 | GtkWidget *progress_bar;
34 | } progress_info_t;
35 |
36 | static void internal_inprogress_response_cb(GtkDialog *dialog,
37 | gint response_id,
38 | gpointer user_data)
39 | {
40 | progress_info_t *progress = user_data;
41 | UNUSED(dialog);
42 | UNUSED(response_id);
43 |
44 | progress->in_progress = 0;
45 | }
46 |
47 | void* gui_inprogress_new(const char *title, const char *message)
48 | {
49 | GtkWidget *dialog;
50 | GtkWidget *label;
51 | GtkWidget *content_area;
52 | GtkWidget *progress_bar;
53 | GtkWidget *vbox;
54 | progress_info_t *progress;
55 |
56 |
57 | dialog = gtk_dialog_new_with_buttons (title,
58 | GTK_WINDOW(MAIN_WINDOW),
59 | GTK_DIALOG_DESTROY_WITH_PARENT | GTK_DIALOG_MODAL,
60 | "_Cancel",
61 | GTK_RESPONSE_CANCEL,
62 | NULL);
63 |
64 | progress = g_malloc(sizeof(progress_info_t));
65 | progress->in_progress = 1;
66 | g_object_set_data(G_OBJECT(dialog),"progress",progress);
67 |
68 | content_area = gtk_dialog_get_content_area (GTK_DIALOG (dialog));
69 |
70 | vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL,16);
71 | gtk_container_set_border_width(GTK_CONTAINER(vbox),16);
72 |
73 | label = gtk_label_new (message);
74 | gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0);
75 |
76 | progress_bar = gtk_progress_bar_new();
77 | gtk_box_pack_end (GTK_BOX (vbox), progress_bar, FALSE, FALSE, 0);
78 | progress->progress_bar = progress_bar;
79 |
80 | g_signal_connect (dialog,
81 | "response",
82 | G_CALLBACK (internal_inprogress_response_cb),
83 | progress);
84 |
85 | g_signal_connect (dialog,
86 | "delete-event",
87 | G_CALLBACK (gtk_true),
88 | NULL);
89 |
90 | gtk_container_add (GTK_CONTAINER (content_area), vbox);
91 | gtk_widget_show_all (dialog);
92 |
93 | return (void *)dialog;
94 | }
95 |
96 | unsigned gui_inprogress_pulse(void *pulser)
97 | {
98 | GtkWidget *dialog = GTK_WIDGET(pulser);
99 | progress_info_t *progress = g_object_get_data(G_OBJECT(dialog),"progress");
100 | gtk_progress_bar_pulse(GTK_PROGRESS_BAR(progress->progress_bar));
101 | ui_update();
102 | return progress->in_progress;
103 | }
104 |
105 | unsigned gui_inprogress_set_fraction(void *pulser, gdouble level)
106 | {
107 | GtkWidget *dialog = GTK_WIDGET(pulser);
108 | progress_info_t *progress = g_object_get_data(G_OBJECT(dialog),"progress");
109 | gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(progress->progress_bar),level);
110 | ui_update();
111 | return progress->in_progress;
112 | }
113 |
114 | void gui_inprogress_free(void *pulser)
115 | {
116 | GtkWidget *dialog = GTK_WIDGET(pulser);
117 | progress_info_t *progress = g_object_get_data(G_OBJECT(dialog),"progress");
118 |
119 | g_free(progress);
120 | gtk_widget_destroy(dialog);
121 | }
122 |
--------------------------------------------------------------------------------
/bytestring.h:
--------------------------------------------------------------------------------
1 | /**********************************************************************
2 | *
3 | * This file is part of Cardpeek, the smart card reader utility.
4 | *
5 | * Copyright 2009-2013 by Alain Pannetrat
6 | *
7 | * Cardpeek is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * Cardpeek is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with Cardpeek. If not, see .
19 | *
20 | */
21 |
22 | #ifndef BYTESTRING_H
23 | #define BYTESTRING_H
24 |
25 | typedef struct {
26 | unsigned len;
27 | unsigned alloc;
28 | unsigned char width;
29 | unsigned char mask;
30 | unsigned char *data;
31 | } bytestring_t;
32 |
33 | enum {
34 | BYTESTRING_ERROR=0,
35 | BYTESTRING_OK=1,
36 | BYTESTRING_NPOS=0x7FFFFFFF
37 | };
38 |
39 | /* constructors */
40 |
41 | int bytestring_init(bytestring_t *bs, unsigned element_width);
42 |
43 | bytestring_t* bytestring_new(unsigned element_width);
44 |
45 | bytestring_t* bytestring_new_from_string(const char *str);
46 |
47 | bytestring_t* bytestring_duplicate(const bytestring_t *bs);
48 |
49 | /* assign */
50 |
51 | int bytestring_assign_data(bytestring_t* bs,
52 | unsigned len, const unsigned char *data);
53 | int bytestring_assign_element(bytestring_t* bs,
54 | unsigned len, unsigned char c);
55 | int bytestring_assign_digit_string(bytestring_t* bs,
56 | const char* str);
57 |
58 | /* copy */
59 |
60 | int bytestring_copy(bytestring_t *bs,
61 | const bytestring_t *src);
62 |
63 | /* convert */
64 |
65 | int bytestring_convert(bytestring_t *bs,
66 | const bytestring_t *src);
67 |
68 | /* append data */
69 |
70 | int bytestring_append(bytestring_t *bs,
71 | const bytestring_t *extra);
72 | int bytestring_append_data(bytestring_t *bs,
73 | unsigned len, const unsigned char *data);
74 | int bytestring_append_element(bytestring_t* bs,
75 | unsigned len, unsigned char c);
76 |
77 | int bytestring_pushback(bytestring_t *bs,
78 | unsigned char c);
79 |
80 | /* accessors */
81 |
82 | int bytestring_set_element(const bytestring_t *bs,
83 | int pos, unsigned char element);
84 |
85 |
86 | int bytestring_get_element(unsigned char* element,
87 | const bytestring_t *bs,
88 | int pos);
89 |
90 | const unsigned char *bytestring_get_data(const bytestring_t *bs);
91 |
92 | /* invert */
93 |
94 | int bytestring_invert(bytestring_t *bs);
95 |
96 | /* clear */
97 |
98 | void bytestring_clear(bytestring_t *bs);
99 |
100 |
101 | int bytestring_erase(bytestring_t *bs,
102 | unsigned pos,
103 | unsigned len);
104 |
105 | /* tests */
106 |
107 | int bytestring_is_equal(const bytestring_t *a, const bytestring_t *b);
108 |
109 | int bytestring_is_empty(const bytestring_t *bs);
110 |
111 | int bytestring_is_printable(const bytestring_t *bs);
112 |
113 | /* insertion */
114 |
115 | int bytestring_insert_data(bytestring_t *bs,
116 | unsigned pos,
117 | unsigned len, const unsigned char* data);
118 | int bytestring_insert_element(bytestring_t *bs,
119 | unsigned pos,
120 | unsigned len, unsigned char c);
121 | int bytestring_insert(bytestring_t *bs,
122 | unsigned pos,
123 | const bytestring_t *src);
124 |
125 | int bytestring_pad_left(bytestring_t *bs,
126 | unsigned block_size, unsigned char c);
127 |
128 | int bytestring_pad_right(bytestring_t *bs,
129 | unsigned block_size, unsigned char c);
130 |
131 | /* get size / resize */
132 |
133 | int bytestring_resize(bytestring_t *bs, unsigned len);
134 |
135 | unsigned bytestring_get_size(const bytestring_t *bs);
136 |
137 | /* substring */
138 |
139 | int bytestring_substr(bytestring_t *dst,
140 | unsigned pos, unsigned len,
141 | const bytestring_t* src);
142 |
143 | /* conversion to other types */
144 |
145 | char *bytestring_to_format(const char *format, const bytestring_t *bs);
146 |
147 | double bytestring_to_number(const bytestring_t *bs);
148 |
149 | /* destructors */
150 |
151 | void bytestring_release(bytestring_t *bs);
152 |
153 | void bytestring_free(bytestring_t *bs);
154 |
155 | /* bytestring_release frees data in bs, bytestring_free also frees bs itself. */
156 |
157 | #endif
158 |
159 |
160 |
--------------------------------------------------------------------------------
/win32/win32compat.c:
--------------------------------------------------------------------------------
1 | #include "win32compat.h"
2 | #include
3 | #include
4 | #include
5 | #include "winscard.h"
6 | #include
7 |
8 | SCARD_IO_REQUEST g_rgSCardT0Pci = { SCARD_PROTOCOL_T0, 8 };
9 | SCARD_IO_REQUEST g_rgSCardT1Pci = { SCARD_PROTOCOL_T1, 8 };
10 |
11 | const char *PCSC_ERROR[] = {
12 | /* 00 */ "No error",
13 | /* 01 */ "Error 01",
14 | /* 02 */ "The action was cancelled by an SCardCancel request",
15 | /* 03 */ "The supplied handle was invalid",
16 | /* 04 */ "Error 04",
17 | /* 05 */ "Error 05",
18 | /* 06 */ "Error 06",
19 | /* 07 */ "Error 07",
20 | /* 08 */ "Error 08",
21 | /* 09 */ "Error 09",
22 | /* OA */ "The user-specified timeout value has expired",
23 | /* 0B */ "The smart card cannot be accessed because of other connections outstanding",
24 | /* 0C */ "The operation requires a smart card, but no smart card is currently in the device",
25 | /* 0D */ "Error 0D",
26 | /* 0E */ "Error 0E",
27 | /* 0F */ "The requested protocols are incompatible with the protocol currently in use with the smart card",
28 | /* 10 */ "Error 10",
29 | /* 11 */ "Error 11",
30 | /* 12 */ "Error 12",
31 | /* 13 */ "Error 13",
32 | /* 14 */ "Error 14",
33 | /* 15 */ "Error 15",
34 | /* 16 */ "An attempt was made to end a non-existent transaction",
35 | /* 17 */ "The specified reader is not currently available for use",
36 | /* 18 */ "Error 1A",
37 | /* 19 */ "Error 1B",
38 | /* 1A */ "Error 1C",
39 | /* 1B */ "Error 1D",
40 | /* 1C */ "Error 1C",
41 | /* 1D */ "The Smart card resource manager is not running",
42 | /* 1E */ "Error 1E",
43 | /* 1F */ "Error 1F",
44 | /* 20 */ "Error 20",
45 | /* 21 */ "Error 21",
46 | /* 22 */ "Error 22",
47 | /* 23 */ "Error 23",
48 | /* 24 */ "Error 24",
49 | /* 25 */ "Error 25",
50 | /* 26 */ "Error 26",
51 | /* 27 */ "Error 27",
52 | /* 28 */ "Error 28",
53 | /* 29 */ "Error 29",
54 | /* 2A */ "Error 2A",
55 | /* 2B */ "Error 2B",
56 | /* 2C */ "Error 2C",
57 | /* 2D */ "Error 2D",
58 | /* 2E */ "Cannot find a smart card reader",
59 | /* 2F */ "Error 2F",
60 |
61 | /* 66 */ "The smart card is not responding to a reset",
62 | /* 67 */ "Power has been removed from the smart card, so that further communication is not possible",
63 | /* 68 */ "The smart card has been reset, so any shared state information is invalid",
64 | /* 69 */ "The smart card has been removed, so further communication is not possible"
65 | };
66 |
67 | static const char *system_stringify_error(DWORD err)
68 | {
69 | static char error_string[256];
70 | char *p;
71 |
72 | if (!FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
73 | NULL,
74 | err,
75 | MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
76 | (LPSTR)error_string,
77 | 255,
78 | NULL))
79 | {
80 | sprintf(error_string,"Unknown system error (0x%08X)",(unsigned)err);
81 | }
82 | else
83 | {
84 | /* FIXME: not UT8 clean */
85 | for (p = error_string;*p!='\0';p++)
86 | if (*p=='\n' || *p=='\r')
87 | {
88 | *p='\0';
89 | break;
90 | }
91 | }
92 | return error_string;
93 | }
94 |
95 | const char *pcsc_stringify_error(long err)
96 | {
97 | static char default_buf[64];
98 | unsigned index;
99 | if ((err&0xFFFFFF00)==0x80100000)
100 | {
101 | index = err&0xFF;
102 | if (index<0x30)
103 | return PCSC_ERROR[index];
104 | if (index>=0x66 || index<=0x69)
105 | return PCSC_ERROR[index-0x66+0x30];
106 | }
107 | else if (err<1700)
108 | {
109 | return system_stringify_error(err);
110 | }
111 | sprintf(default_buf,"Unknown error (0x%08X)",(unsigned)err);
112 | return default_buf;
113 | }
114 |
115 |
116 | int scandir(const char *dir, struct dirent ***namelist,
117 | int (*select)(const struct dirent *),
118 | int (*compar)(const struct dirent **, const struct dirent**))
119 | {
120 | struct dirent **entries;
121 | unsigned max;
122 | DIR* Hdir;
123 | struct dirent *candidate;
124 | Hdir=opendir(dir);
125 | if (Hdir==NULL)
126 | return 0;
127 | max = 0;
128 | while (readdir(Hdir)) max++;
129 | entries = malloc(sizeof(struct dirent *)*max);
130 | rewinddir(Hdir);
131 | max = 0;
132 | while ((candidate = readdir(Hdir))!=NULL)
133 | {
134 | if (select==NULL || select(candidate))
135 | {
136 | entries[max]=malloc(sizeof(struct dirent));
137 | memcpy(entries[max],candidate,sizeof(struct dirent));
138 | max++;
139 | }
140 | }
141 | closedir(Hdir);
142 | *namelist = entries;
143 | return max;
144 | }
145 |
146 | int alphasort (const struct dirent **a, const struct dirent **b)
147 | {
148 | return strcmp((*a)->d_name,(*b)->d_name);
149 | }
150 |
151 |
152 |
--------------------------------------------------------------------------------
/m4/ax_check_openssl.m4:
--------------------------------------------------------------------------------
1 | # ===========================================================================
2 | # http://www.gnu.org/software/autoconf-archive/ax_check_openssl.html
3 | # ===========================================================================
4 | #
5 | # SYNOPSIS
6 | #
7 | # AX_CHECK_OPENSSL([action-if-found[, action-if-not-found]])
8 | #
9 | # DESCRIPTION
10 | #
11 | # Look for OpenSSL in a number of default spots, or in a user-selected
12 | # spot (via --with-openssl). Sets
13 | #
14 | # OPENSSL_INCLUDES to the include directives required
15 | # OPENSSL_LIBS to the -l directives required
16 | # OPENSSL_LDFLAGS to the -L or -R flags required
17 | #
18 | # and calls ACTION-IF-FOUND or ACTION-IF-NOT-FOUND appropriately
19 | #
20 | # This macro sets OPENSSL_INCLUDES such that source files should use the
21 | # openssl/ directory in include directives:
22 | #
23 | # #include
24 | #
25 | # LICENSE
26 | #
27 | # Copyright (c) 2009,2010 Zmanda Inc.
28 | # Copyright (c) 2009,2010 Dustin J. Mitchell
29 | #
30 | # Copying and distribution of this file, with or without modification, are
31 | # permitted in any medium without royalty provided the copyright notice
32 | # and this notice are preserved. This file is offered as-is, without any
33 | # warranty.
34 |
35 | #serial 8
36 |
37 | AU_ALIAS([CHECK_SSL], [AX_CHECK_OPENSSL])
38 | AC_DEFUN([AX_CHECK_OPENSSL], [
39 | found=false
40 | AC_ARG_WITH([openssl],
41 | [AS_HELP_STRING([--with-openssl=DIR],
42 | [root of the OpenSSL directory])],
43 | [
44 | case "$withval" in
45 | "" | y | ye | yes | n | no)
46 | AC_MSG_ERROR([Invalid --with-openssl value])
47 | ;;
48 | *) ssldirs="$withval"
49 | ;;
50 | esac
51 | ], [
52 | # if pkg-config is installed and openssl has installed a .pc file,
53 | # then use that information and don't search ssldirs
54 | AC_PATH_PROG([PKG_CONFIG], [pkg-config])
55 | if test x"$PKG_CONFIG" != x""; then
56 | OPENSSL_LDFLAGS=`$PKG_CONFIG openssl --libs-only-L 2>/dev/null`
57 | if test $? = 0; then
58 | OPENSSL_LIBS=`$PKG_CONFIG openssl --libs-only-l 2>/dev/null`
59 | OPENSSL_INCLUDES=`$PKG_CONFIG openssl --cflags-only-I 2>/dev/null`
60 | found=true
61 | fi
62 | fi
63 |
64 | # no such luck; use some default ssldirs
65 | if ! $found; then
66 | ssldirs="/usr/local/ssl /usr/lib/ssl /usr/ssl /usr/pkg /usr/local /usr"
67 | fi
68 | ]
69 | )
70 |
71 |
72 | # note that we #include , so the OpenSSL headers have to be in
73 | # an 'openssl' subdirectory
74 |
75 | if ! $found; then
76 | OPENSSL_INCLUDES=
77 | for ssldir in $ssldirs; do
78 | AC_MSG_CHECKING([for openssl/ssl.h in $ssldir])
79 | if test -f "$ssldir/include/openssl/ssl.h"; then
80 | OPENSSL_INCLUDES="-I$ssldir/include"
81 | OPENSSL_LDFLAGS="-L$ssldir/lib"
82 | OPENSSL_LIBS="-lssl -lcrypto"
83 | found=true
84 | AC_MSG_RESULT([yes])
85 | break
86 | else
87 | AC_MSG_RESULT([no])
88 | fi
89 | done
90 |
91 | # if the file wasn't found, well, go ahead and try the link anyway -- maybe
92 | # it will just work!
93 | fi
94 |
95 | # try the preprocessor and linker with our new flags,
96 | # being careful not to pollute the global LIBS, LDFLAGS, and CPPFLAGS
97 |
98 | AC_MSG_CHECKING([whether compiling and linking against OpenSSL works])
99 | echo "Trying link with OPENSSL_LDFLAGS=$OPENSSL_LDFLAGS;" \
100 | "OPENSSL_LIBS=$OPENSSL_LIBS; OPENSSL_INCLUDES=$OPENSSL_INCLUDES" >&AS_MESSAGE_LOG_FD
101 |
102 | save_LIBS="$LIBS"
103 | save_LDFLAGS="$LDFLAGS"
104 | save_CPPFLAGS="$CPPFLAGS"
105 | LDFLAGS="$LDFLAGS $OPENSSL_LDFLAGS"
106 | LIBS="$OPENSSL_LIBS $LIBS"
107 | CPPFLAGS="$OPENSSL_INCLUDES $CPPFLAGS"
108 | AC_LINK_IFELSE(
109 | [AC_LANG_PROGRAM([#include ], [SSL_new(NULL)])],
110 | [
111 | AC_MSG_RESULT([yes])
112 | $1
113 | ], [
114 | AC_MSG_RESULT([no])
115 | $2
116 | ])
117 | CPPFLAGS="$save_CPPFLAGS"
118 | LDFLAGS="$save_LDFLAGS"
119 | LIBS="$save_LIBS"
120 |
121 | AC_SUBST([OPENSSL_INCLUDES])
122 | AC_SUBST([OPENSSL_LIBS])
123 | AC_SUBST([OPENSSL_LDFLAGS])
124 | ])
125 |
--------------------------------------------------------------------------------
/dot_cardpeek_dir/scripts/calypso/c250n502.lua:
--------------------------------------------------------------------------------
1 | --
2 | -- This file is part of Cardpeek, the smartcard reader utility.
3 | --
4 | -- Copyright 2009 by 'L1L1' and 2013-2014 by 'kalon33'
5 | --
6 | -- Cardpeek is free software: you can redistribute it and/or modify
7 | -- it under the terms of the GNU General Public License as published by
8 | -- the Free Software Foundation, either version 3 of the License, or
9 | -- (at your option) any later version.
10 | --
11 | -- Cardpeek is distributed in the hope that it will be useful,
12 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | -- GNU General Public License for more details.
15 | --
16 | -- You should have received a copy of the GNU General Public License
17 | -- along with Cardpeek. If not, see .
18 | --
19 |
20 | ---------------------------------------------------------------------
21 | -- Most of the data and coding ideas in this file
22 | -- was contributed by 'Pascal Terjan', based on location
23 | -- data from 'Nicolas Derive'.
24 | ---------------------------------------------------------------------
25 |
26 | require('lib.strict')
27 | require('etc.grenoble-tag_stops')
28 | require('etc.grenoble-tag_lines')
29 |
30 | SERVICE_PROVIDERS = {
31 | [3] = "TAG"
32 | }
33 |
34 | TRANSPORT_LIST = {
35 | [1] = "Tram"
36 | }
37 |
38 | TRANSITION_LIST = {
39 | [1] = "Entry",
40 | [2] = "Exit",
41 | [4] = "Inspection",
42 | [6] = "Interchange (entry)",
43 | [7] = "Interchange (exit)"
44 | }
45 |
46 | function navigo_process_events(ctx)
47 | local EVENTS
48 | local RECORD
49 | local REF
50 | local rec_index
51 | local code_value
52 | local code_transport
53 | local code_transition
54 | local code_transport_string
55 | local code_transition_string
56 | local code_string
57 | local service_provider_value
58 | local location_id_value
59 | local route_number_value
60 | local route_string
61 | local sector_id
62 | local station_id
63 | local location_string
64 |
65 | EVENTS = ui.tree_find_node(ctx,"Event logs, parsed");
66 | if EVENTS==nil then
67 | log.print(log.WARNING,"No event found in card")
68 | return 0
69 | end
70 |
71 | for rec_index=1,16 do
72 | RECORD = ui.tree_find_node(EVENTS,"record",rec_index)
73 | if RECORD==nil then break end
74 |
75 | REF = ui.tree_find_node(RECORD,"EventServiceProvider")
76 | service_provider_value = bytes.tonumber(ui.tree_get_value(REF))
77 | ui.tree_set_alt_value(REF,SERVICE_PROVIDERS[service_provider_value])
78 |
79 | REF = ui.tree_find_node(RECORD,"EventCode")
80 | code_value = bytes.tonumber(ui.tree_get_value(REF))
81 |
82 | code_transport = bit.SHR(code_value,4)
83 | code_transport_string = TRANSPORT_LIST[code_transport]
84 | if code_transport_string==nil then code_transport_string = code_transport end
85 |
86 | code_transition = bit.AND(code_value,0xF)
87 | code_transition_string = TRANSITION_LIST[code_transition]
88 | if (code_transition_string==nil) then code_transition_string = code_transition end
89 |
90 | ui.tree_set_alt_value(REF,code_transport_string.." - "..code_transition_string)
91 |
92 | if service_provider_value == 3 and code_transport <=1 then
93 | REF = ui.tree_find_node(RECORD,"EventLocationId")
94 | location_id_value = bytes.tonumber(ui.tree_get_value(REF))
95 | -- sector_id = bit.SHR(location_id_value,9)
96 | -- station_id = bit.AND(bit.SHR(location_id_value,4),0x1F)
97 |
98 | -- if STOPS_LIST[sector_id]~=nil then
99 | -- location_string = "secteur "..STOPS_LIST[sector_id]['name'].." - station "
100 | -- if STOPS_LIST[sector_id][station_id]==nil then
101 | -- location_string = location_string .. station_id
102 | -- else
103 | -- location_string = location_string .. STOPS_LIST[sector_id][station_id]
104 | -- end
105 | -- else
106 | -- location_string = "secteur "..sector_id.." - station "..station_id
107 | -- end
108 | -- end
109 | if STOPS_LIST[location_id_value]~=nil then
110 | location_string = STOPS_LIST[location_id_value]
111 | else
112 | location_string = location_id_value
113 | end
114 | ui.tree_set_alt_value(REF,location_string)
115 |
116 | REF = ui.tree_find_node(RECORD,"EventRouteNumber")
117 | route_number_value = bytes.tonumber(ui.tree_get_value(REF))
118 | if LINES_LIST[route_number_value]["name"] then
119 | route_string = LINES_LIST[route_number_value]["name"]
120 | else
121 | -- route_string = route_number_value
122 | route_string = LINES_LIST[route_number_value]["name"]
123 | end
124 | ui.tree_set_alt_value(REF,route_string)
125 | end
126 | end
127 | end
128 |
129 | navigo_process_events(CARD)
130 |
131 |
132 |
--------------------------------------------------------------------------------
/dot_cardpeek_dir/scripts/calypso/c250n901.lua:
--------------------------------------------------------------------------------
1 | --
2 | -- This file is part of Cardpeek, the smartcard reader utility.
3 | --
4 | -- Copyright 2009-2013 by 'L1L1'
5 | --
6 | -- Cardpeek is free software: you can redistribute it and/or modify
7 | -- it under the terms of the GNU General Public License as published by
8 | -- the Free Software Foundation, either version 3 of the License, or
9 | -- (at your option) any later version.
10 | --
11 | -- Cardpeek is distributed in the hope that it will be useful,
12 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | -- GNU General Public License for more details.
15 | --
16 | -- You should have received a copy of the GNU General Public License
17 | -- along with Cardpeek. If not, see .
18 | --
19 |
20 | ---------------------------------------------------------------------
21 | -- Most of the data and coding ideas in this file
22 | -- was contributed by 'Pascal Terjan', based on location
23 | -- data from 'Aurélien Baro'.
24 | ---------------------------------------------------------------------
25 |
26 | require('lib.strict')
27 | require('etc.paris-metro')
28 | require('etc.paris-rer')
29 |
30 | SERVICE_PROVIDERS = {
31 | [2] = "SNCF",
32 | [3] = "RATP"
33 | }
34 |
35 | TRANSPORT_LIST = {
36 | [1] = "Urban Bus",
37 | [2] = "Interurban Bus",
38 | [3] = "Metro",
39 | [4] = "Tram",
40 | [5] = "Train",
41 | [8] = "Parking"
42 | }
43 |
44 | TRANSITION_LIST = {
45 | [1] = "Entry",
46 | [2] = "Exit",
47 | [4] = "Inspection",
48 | [6] = "Interchange (entry)",
49 | [7] = "Interchange (exit)"
50 | }
51 |
52 | function navigo_process_events(cardenv,node_label)
53 | local event_node
54 | local record_node
55 | local ref_node
56 |
57 | local code_value
58 | local code_transport
59 | local code_transition
60 | local code_transport_string
61 | local code_transition_string
62 | local code_string
63 | local service_provider_value
64 | local location_id_value
65 | local sector_id
66 | local station_id
67 | local location_string
68 |
69 | event_node = cardenv:find_first({label=node_label, parsed="true"})
70 |
71 | if event_node==nil then
72 | log.print(log.WARNING,"No " .. node_label .. " found in card")
73 | return 0
74 | end
75 |
76 | for record_node in event_node:find({label="record"}) do
77 |
78 | -- is it RATP or SNCF ?
79 | ref_node = record_node:find_first({label="EventServiceProvider"})
80 | service_provider_value = bytes.tonumber(ref_node:get_attribute("val"))
81 | ref_node:set_attribute("alt",SERVICE_PROVIDERS[service_provider_value])
82 |
83 | ref_node = record_node:find_first({label="EventCode"})
84 | code_value = bytes.tonumber(ref_node:get_attribute("val"))
85 |
86 | -- is it a bus, a tram, a metro, ... ?
87 | code_transport = bit.SHR(code_value,4)
88 | code_transport_string = TRANSPORT_LIST[code_transport]
89 | if code_transport_string==nil then code_transport_string = code_transport end
90 |
91 | -- is it an entry, an exit, ... ?
92 | code_transition = bit.AND(code_value,0xF)
93 | code_transition_string = TRANSITION_LIST[code_transition]
94 | if (code_transition_string==nil) then code_transition_string = code_transition end
95 |
96 | ref_node:set_attribute("alt",code_transport_string.." - "..code_transition_string)
97 |
98 | -- service_provider_value == RATP and code_transport in { metro, tram, train } ?
99 | if (service_provider_value==3 or service_provider_value==2) and code_transport>=3 and code_transport<=5 then
100 | ref_node = record_node:find_first({label="EventLocationId"})
101 | location_id_value = bytes.tonumber(ref_node:get_attribute("val"))
102 | sector_id = bit.SHR(location_id_value,9)
103 | station_id = bit.AND(bit.SHR(location_id_value,4),0x1F)
104 |
105 | if code_transport==5 and BANLIEUE_LIST[sector_id] and BANLIEUE_LIST[sector_id][station_id] then
106 | location_string = "secteur "..sector_id.." - station "..BANLIEUE_LIST[sector_id][station_id]
107 | else
108 | if METRO_LIST[sector_id]~=nil then
109 | location_string = "secteur "..METRO_LIST[sector_id]['name'].." - station "
110 | if METRO_LIST[sector_id][station_id]==nil then
111 | location_string = location_string .. station_id
112 | else
113 | location_string = location_string .. METRO_LIST[sector_id][station_id]
114 | end
115 | else
116 | location_string = "secteur "..sector_id.." - station "..station_id
117 | end
118 | end
119 |
120 | ref_node:set_attribute("alt",location_string)
121 |
122 | end
123 | end
124 | end
125 |
126 | navigo_process_events(CARD,"Event logs")
127 | navigo_process_events(CARD,"Special events")
128 |
129 |
130 |
--------------------------------------------------------------------------------
/Makefile.am:
--------------------------------------------------------------------------------
1 | AUTOMAKE_OPTIONS = gnu subdir-objects
2 |
3 | AM_CFLAGS=-Wall -pedantic -Wno-overlength-strings @LUA_CFLAGS@ @PCSC_CFLAGS@ @GLIB_CFLAGS@ @GTK_CFLAGS@ @CURL_CFLAGS@ @OPENSSL_INCLUDES@
4 |
5 | bin_PROGRAMS= cardpeek
6 |
7 | cardpeek_SOURCES = asn1.c asn1.h \
8 | bytestring.c bytestring.h \
9 | ui/gtk/gui_flexi_cell_renderer.c \
10 | ui/gtk/gui_flexi_cell_renderer.h \
11 | dyntree_model.c dyntree_model.h \
12 | crypto.c crypto.h \
13 | replay.c replay.h \
14 | ui.c ui.h \
15 | iso7816.c iso7816.h \
16 | lua_nodes.c lua_nodes.h \
17 | lua_asn1.c lua_asn1.h \
18 | lua_bit.c lua_bit.h \
19 | lua_bytes.c lua_bytes.h \
20 | lua_card.c lua_card.h \
21 | lua_crypto.c lua_crypto.h \
22 | lua_ext.c lua_ext.h \
23 | lua_log.c lua_log.h \
24 | lua_ui.c lua_ui.h \
25 | main.c main.h \
26 | misc.c misc.h \
27 | pathconfig.c pathconfig.h \
28 | smartcard.c smartcard.h \
29 | system_info.c system_info.h \
30 | a_string.c a_string.h \
31 | ui/gtk/gui_core.c ui/gtk/gui_core.h \
32 | ui/gtk/gui_about.c ui/gtk/gui_about.h \
33 | ui/gtk/gui_toolbar.c ui/gtk/gui_toolbar.h \
34 | ui/gtk/gui_logview.c ui/gtk/gui_logview.h \
35 | ui/gtk/gui_cardview.c ui/gtk/gui_cardview.h \
36 | ui/gtk/gui_readerview.c ui/gtk/gui_readerview.h \
37 | ui/gtk/gui_scratchpad.c ui/gtk/gui_scratchpad.h \
38 | ui/gtk/gui_inprogress.c ui/gtk/gui_inprogress.h \
39 | ui/console/console_core.c ui/console/console_core.h \
40 | ui/console/console_inprogress.c ui/console/console_inprogress.h \
41 | ui/console/console_about.c ui/console/console_about.h \
42 | http_download.c http_download.h \
43 | lua_iconv.c lua_iconv.h \
44 | cardpeek_update.c cardpeek_update.h \
45 | cardpeek_public_key.h \
46 | win32/config.h
47 |
48 | EXTRA_cardpeek_SOURCES=cardpeek.c osx/cardpeek-osx.m
49 |
50 | doc_DATA=doc/cardpeek_ref.en.pdf
51 |
52 | cardpeek_LDADD=cardpeek_resources.$(OBJEXT) @LUA_LIBS@ @PCSC_LIBS@ @GLIB_LIBS@ @GTK_LIBS@ @CURL_LIBS@ @ICONV_LIBS@ @OPENSSL_LIBS@ @OPENSSL_LDFLAGS@
53 |
54 | cardpeek_LDFLAGS=-g
55 | #cardpeek_LDFLAGS=-O2
56 |
57 | #
58 | # We add stuff needed for MacOSX (an obj-c file) or else the default (a c file)
59 | #
60 | if OSX_BUNDLE
61 | cardpeek_SOURCES+=osx/cardpeek-osx.m
62 | cardpeek_LDFLAGS+=-framework Cocoa
63 | else
64 | cardpeek_SOURCES += cardpeek.c
65 | endif
66 |
67 | dist_man_MANS=cardpeek.1
68 |
69 | DRIVERS=drivers/replay_driver.c drivers/null_driver.c drivers/pcsc_driver.c
70 |
71 | ICONS=icons/cardpeek-analyzer.png icons/cardpeek-item.png icons/cardpeek-record.png icons/cardpeek-smartcard.png icons/cardpeek-folder.png icons/cardpeek-logo.png icons/cardpeek-application.png icons/cardpeek-file.png icons/cardpeek-block.png icons/cardpeek-atr.png icons/cardpeek-header.png icons/cardpeek-body.png icons/image-missing.png
72 |
73 | OSX_ICONS=osx/cardpeek.iconset/icon_128x128.png osx/cardpeek.iconset/icon_16x16.png osx/cardpeek.iconset/icon_256x256.png osx/cardpeek.iconset/icon_32x32.png osx/cardpeek.iconset/icon_512x512.png osx/cardpeek.iconset/icon_64x64.png
74 |
75 | OSX_EXTRA=osx/cardpeek-launcher.sh osx/cardpeek.bundle osx/generate_bundle.sh osx/gtkrc osx/Info-cardpeek.plist.in
76 |
77 | CLEANFILES=cardpeek_resources.c dot_cardpeek.tar.gz osx/cardpeek.icns
78 |
79 | EXTRA_DIST=cardpeek_resources.gresource.xml cardpeek_resources.gresource $(DRIVERS) $(ICONS) dot_cardpeek_dir doc/cardpeek_ref.en.pdf doc/cardpeek_ref.en.odt update_dot_cardpeek_dir.sh script_version.h cardpeek.desktop cardpeek.appdata.xml $(OSX_ICONS)
80 |
81 | GLIB_COMPILE_RESOURCES=@GLIB_COMPILE_RESOURCES@
82 |
83 | desktopdir = $(datadir)/applications
84 | desktop_DATA = cardpeek.desktop
85 |
86 | iconsdir = $(datadir)/icons/hicolor/48x48/apps
87 | icons_DATA = icons/cardpeek-logo.png
88 |
89 | appdatadir = $(datadir)/appdata
90 | appdata_DATA = cardpeek.appdata.xml
91 |
92 | mostlyclean-local @OPENSSL_LIBS@ :
93 | rm -rf .cardpeek
94 |
95 | dist-hook:
96 | rm -rf `find $(distdir)/ -name .svn`
97 |
98 | dot_cardpeek.tar.gz: dot_cardpeek_dir
99 | @echo " TAR $<"
100 | $(AM_V_at)tar --help|grep -q sort= && taropts="--sort=name --clamp-mtime --format=gnu --owner=0 --group=0" ; tar -c $$taropts --directory $(srcdir)/dot_cardpeek_dir --exclude=.svn --exclude='\._*' . | gzip -cn9 > dot_cardpeek.tar.gz
101 |
102 | cardpeek_resources.$(OBJEXT): dot_cardpeek.tar.gz $(ICONS) AUTHORS COPYING cardpeek_resources.gresource.xml
103 | @echo " GLIB_COMPILE_RESOURCES cardpeek_resources.gresource.xml"
104 | $(AM_V_at)$(GLIB_COMPILE_RESOURCES) --generate-source --sourcedir=. --sourcedir=$(srcdir) --target=cardpeek_resources.c $(srcdir)/cardpeek_resources.gresource.xml
105 | $(AM_V_CC)$(COMPILE) -c cardpeek_resources.c
106 |
107 | smartcard.$(OBJEXT): smartcard.c smartcard.h $(DRIVERS)
108 | $(AM_V_CC)$(COMPILE) -c $<
109 |
110 |
--------------------------------------------------------------------------------
/deps-win32.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | #
3 | # Download and extract dependencies for cross-compilation from Debian for Windows.
4 | # See doc/build-debian.md
5 | #
6 | RED='\033[0;31m'
7 | YELLOW='\033[0;33m'
8 | NC='\033[0m' # No Color
9 |
10 | PLATFORM=${PLATFORM=-win32}
11 | DEPS=deps/$PLATFORM
12 | if [[ `uname -s` == MINGW* ]] || [[ `uname -s` == MSYS* ]]; then
13 | echo -e "${RED}This script should not be run from msys${NC}"
14 | exit 1
15 | fi
16 |
17 | function import_signing_key {
18 | #
19 | # Import Alexey Pavlov (maintener of mingw-w64 repository) signing key, if necessary
20 | #
21 | local keyid=AD351C50AE085775EB59333B5F92EFC1A47D45A1
22 | gpg --list-keys --keyid-format LONG | grep $keyid > /dev/null
23 | if [ $? -eq 0 ]; then
24 | return 0
25 | fi
26 | echo -e "${YELLOW}Import signing key${NC}"
27 | gpg --recv-key $keyid
28 | }
29 |
30 | function get_package {
31 | #
32 | # Download (if necessary), verify, and extract a package.
33 | # @param $1: Name of the package
34 | #
35 | local name=$1
36 | local mplatform=mingw32
37 | local iplatform=i686
38 | if [ "$PLATFORM" == "win64" ]; then
39 | mplatform=mingw64
40 | iplatform=x86_64
41 | fi
42 |
43 | if [[ $name == mingw-w64-cross-* ]]; then
44 | # special package to retrieve libgcc_s_dw2-1.dll
45 | local archive_src=http://repo.msys2.org/msys/i686/$name.tar.xz
46 | local archive_dst=$DEPS/archives/$name.tar.xz
47 |
48 | local sign_src=http://repo.msys2.org/msys/i686/$name.tar.xz.sig
49 | local sign_dst=$DEPS/archives/$name.tar.xz.sig
50 | else
51 | local archive_src=http://repo.msys2.org/mingw/$iplatform/mingw-w64-$iplatform-$name.pkg.tar.xz
52 | local archive_dst=$DEPS/archives/mingw-w64-$iplatform-$name.pkg.tar.xz
53 |
54 | local sign_src=http://repo.msys2.org/mingw/$iplatform/mingw-w64-$iplatform-$name.pkg.tar.xz.sig
55 | local sign_dst=$DEPS/archives/mingw-w64-$iplatform-$name.pkg.tar.xz.sig
56 | fi
57 |
58 | mkdir -p $DEPS/archives
59 |
60 | # Download
61 | if [ ! -f $archive_dst ]; then
62 | echo -e "${YELLOW}Download $name (package)${NC}"
63 | curl -o $archive_dst $archive_src
64 | fi
65 | if [ ! -f $sign_dst ]; then
66 | echo -e "${YELLOW}Download $name (sig)${NC}"
67 | curl -o $sign_dst $sign_src
68 | fi
69 |
70 | # Verify
71 | echo -e "${YELLOW}Check $name${NC}"
72 | gpg --verify $sign_dst $archive_dst
73 | if [ ! $? -eq 0 ]; then
74 | echo -e "${RED}Signature error for $name${NC}"
75 | exit 1
76 | fi
77 |
78 | # Extract
79 | echo -e "${YELLOW}Extract $name${NC}"
80 |
81 | if [[ $name == mingw-w64-cross-* ]]; then
82 | tar -C $DEPS -xf $archive_dst
83 | else
84 | tar -C $DEPS -xf $archive_dst $mplatform/ --strip-components=1
85 | fi
86 |
87 | if [ ! $? -eq 0 ]; then
88 | echo -e "${RED}Cannot extract $name${NC}"
89 | exit 1
90 | fi
91 | }
92 |
93 | packages=(
94 | atk-2.30.0-1-any
95 | brotli-1.0.7-1-any
96 | bzip2-1.0.6-6-any
97 | cairo-1.16.0-1-any
98 | curl-7.62.0-1-any
99 | expat-2.2.6-1-any
100 | fontconfig-2.13.1-1-any
101 | freetype-2.9.1-1-any
102 | fribidi-1.0.5-1-any
103 | gdk-pixbuf2-2.38.0-2-any
104 | gettext-0.19.8.1-7-any
105 | glib2-2.58.1-1-any
106 | graphite2-1.3.9-1-any
107 | gtk3-3.24.1-1-any
108 | harfbuzz-2.2.0-1-any
109 | libdatrie-0.2.12-1-any
110 | libepoxy-1.5.3-1-any
111 | libffi-3.2.1-4-any
112 | libiconv-1.15-3-any
113 | libidn2-2.0.5-1-any
114 | libpng-1.6.36-1-any
115 | libpsl-0.20.2-1-any
116 | libthai-0.1.28-2-any
117 | libtiff-4.0.10-1-any
118 | libunistring-0.9.10-1-any
119 | libwinpthread-git-7.0.0.5273.3e5acf5d-1-any
120 | lua-5.3.5-1-any
121 | ncurses-6.1.20180908-1-any
122 | nghttp2-1.35.0-1-any
123 | openssl-1.1.1-4-any
124 | pango-1.42.4-2-any
125 | pcre-8.42-1-any
126 | pixman-0.36.0-1-any
127 | readline-7.0.005-1-any
128 | termcap-1.3.1-3-any
129 | zlib-1.2.11-5-any
130 | )
131 |
132 | # ------ Get mingw packages ------
133 | import_signing_key
134 | for name in "${packages[@]}"; do
135 | get_package $name
136 | done
137 |
138 | # ----- Get local files ------
139 | if [ "$PLATFORM" == "win32" ]; then
140 | # We're cross-compiling for 32-bit Windows from Linux
141 | get_package mingw-w64-cross-gcc-7.3.0-2-i686.pkg # necessary to get libgcc_s_dw2-1.dll
142 | cp -u $DEPS/opt/lib/gcc/i686-w64-mingw32/7.3.0/libgcc_s_dw2-1.dll $DEPS/bin/
143 | cp -u /usr/lib/gcc/i686-w64-mingw32/6.3-win32/libgcc_s_sjlj-1.dll $DEPS/bin/
144 | cp -u /usr/lib/gcc/i686-w64-mingw32/6.3-win32/libstdc++-6.dll $DEPS/bin/
145 | else
146 | # We're cross-compiling for 64-bit Windows from Linux
147 | cp -u /usr/lib/gcc/x86_64-w64-mingw32/6.3-win32/libgcc_s_seh-1.dll $DEPS/bin/
148 | cp -u /usr/lib/gcc/x86_64-w64-mingw32/6.3-win32/libstdc++-6.dll $DEPS/bin/
149 | fi
150 |
--------------------------------------------------------------------------------
/dot_cardpeek_dir/scripts/thai eID.lua:
--------------------------------------------------------------------------------
1 | -- By David Huang
2 | -- Based on information from https://github.com/chakphanu/ThaiNationalIDCard
3 | --
4 | -- @name Thai eID
5 | -- @description Thai national ID card.
6 | -- @targets 0.8
7 |
8 | require("lib.strict")
9 |
10 | -- Convert a TIS-620-encoded string to UTF-8 and remove trailing spaces
11 | function format_string(node)
12 | local data = node:get_attribute("val")
13 | local s = converter:iconv(data:format("%C"))
14 | s = string.gsub(s, " +$", "")
15 | node:set_attribute("alt", s)
16 | return s
17 | end
18 |
19 | -- Split string with "#" as the delimiter, and label the pieces
20 | function format_splithash(node, labels)
21 | local s = format_string(node)
22 | local pattern = string.rep("([^#]*)", #labels, "#")
23 | for i,e in ipairs({string.match(s, pattern)}) do
24 | if labels[i] then
25 | node:append({ classname="item", label=labels[i], val=e })
26 | end
27 | end
28 | end
29 |
30 | function format_name(node)
31 | local labels = { "Prefix", "First", "Middle", "Last" }
32 | format_splithash(node, labels)
33 | end
34 |
35 | function format_address(node)
36 | local labels = {
37 | "House Number", "Village Number (Mu Ban)",
38 | "Lane (Trok/Soi)", "Road (Thanon)", nil, "Tambon/Khwaeng",
39 | "Amphur/Khet", "Province"
40 | }
41 | format_splithash(node, labels)
42 | end
43 |
44 | -- Thai ID number
45 | function format_id(node)
46 | local s = format_string(node)
47 | local a, b, c, d, e
48 | local _, _, a, b, c, d, e = string.find(s, "(.)(....)(.....)(..)(.)")
49 | node:set_attribute("alt", string.format("%s-%s-%s-%s-%s", a, b, c, d, e))
50 | end
51 |
52 | -- Thai ID card serial number
53 | function format_serial(node)
54 | local s = format_string(node)
55 | local a, b, c
56 | local _, _, a, b, c = string.find(s, "(....)(..)(.*)")
57 | node:set_attribute("alt", string.format("%s-%s-%s", a, b, c))
58 | end
59 |
60 | -- Convert Buddhist calendar date to Gregorian
61 | -- Expiration date of 9999-99-99 means no expiration
62 | -- Note that some people may only have a birth year, with no birth month
63 | -- or day. In that case, the month and day will be "00".
64 | function format_date(node)
65 | local s = format_string(node)
66 | local m, d, y
67 | if s == "99999999" then
68 | s = "Lifelong"
69 | else
70 | _, _, y, m, d = string.find(s, "(....)(..)(..)")
71 | y = tonumber(y)
72 | m = tonumber(m)
73 | d = tonumber(d)
74 | s = string.format("%04d-%02d-%02d", y-543, m, d)
75 | end
76 | node:set_attribute("alt", s)
77 | end
78 |
79 | function format_sex(node)
80 | local data = bytes.get(node:get_attribute("val"), 0)
81 | local s
82 | if data == 0x31 then
83 | s = "Male"
84 | elseif data == 0x32 then
85 | s = "Female"
86 | else
87 | s = string.format("Unknown %c", data)
88 | end
89 | node:set_attribute("alt", s)
90 | end
91 |
92 | function format_photo(node)
93 | node:set_attribute("mime-type", "image/jpeg")
94 | end
95 |
96 | local eid_elements =
97 | { -- Label, offset, length, format function
98 | { "Citizen ID", 4, 13, format_id },
99 | { "Thai Name", 17, 100, format_name },
100 | { "Romanized Name", 117, 100, format_name } ,
101 | { "Date of Birth", 217, 8, format_date },
102 | { "Sex", 225, 1, format_sex },
103 | { "Address", 5497, 160, format_address },
104 | { "Date of Issue", 359, 8, format_date },
105 | { "Date of Expiry", 367, 8, format_date },
106 | { "Issuer", 246, 100, format_string },
107 | { "Card Number", 5657, 14, format_serial },
108 | -- { "Unknown", 375, 2, format_string }, -- Is 0x3031 ("01") on my cards
109 | -- { "Unknown", 377, 2, },
110 | -- { "Unknown (Fingerprints?)", 5671, 279, },
111 | { "Photo", 379, 5118, format_photo }
112 | }
113 |
114 | function thaiid_get_binary(offset, length)
115 | return card.send(bytes.new(8, 0x80, 0xB0, bit.AND(bit.SHR(offset,8),0x7F), bit.AND(offset,0xFF), 0x02, 0x00, length))
116 | end
117 |
118 | -- Read the contents of the card into a bytestring
119 | function thaiid_read_data(card)
120 | local sw, resp
121 | local data
122 |
123 | -- Thailand Ministry of Interior AID
124 | sw, resp = card.select("#A000000054480001")
125 | if sw == 0x9000 then
126 | local offset, size, chunk
127 |
128 | data = bytes.new(8)
129 | size = 5950
130 | chunk = 255
131 |
132 | for offset = 0, size-1, chunk do
133 | sw, resp = thaiid_get_binary(offset, math.min(chunk, size))
134 | if sw ~= 0x9000 then
135 | break
136 | end
137 | data = data .. resp
138 | size = size - chunk
139 | end
140 | end
141 |
142 | return data
143 | end
144 |
145 | if card.connect() then
146 | local CARD
147 | local data
148 |
149 | CARD = card.tree_startup("Thai eID")
150 | data = thaiid_read_data(card)
151 | card.disconnect()
152 |
153 | -- Strings are encoded in TIS-620; need to convert to UTF-8 for Cardpeek
154 | converter = iconv.open("TIS-620", "UTF-8")
155 |
156 | -- Extract info from the bytestring by offset and length
157 | for k, v in ipairs(eid_elements) do
158 | local element
159 | local node
160 |
161 | element = bytes.sub(data, v[2], v[2]+v[3]-1)
162 | node = CARD:append({ classname="item", label=v[1], val=element, size=v[3] })
163 | if type(v[4])=="function" then
164 | v[4](node)
165 | end
166 | end
167 | end
168 |
--------------------------------------------------------------------------------
/lua_crypto.c:
--------------------------------------------------------------------------------
1 | /**********************************************************************
2 | *
3 | * This file is part of Cardpeek, the smart card reader utility.
4 | *
5 | * Copyright 2009-2013 by Alain Pannetrat
6 | *
7 | * Cardpeek is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * Cardpeek is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with Cardpeek. If not, see .
19 | *
20 | */
21 | #include
22 | #include "lua_crypto.h"
23 | #include "crypto.h"
24 | #include "lua_bytes.h"
25 |
26 | /***********************************************************
27 | * BASIC CRYPTO FUNCTIONS
28 | */
29 |
30 | static int subr_crypto_create_context(lua_State* L)
31 | {
32 | int alg = luaL_checkinteger(L,1);
33 | bytestring_t* bs;
34 | bytestring_t* res = bytestring_new(8);
35 | crypto_error_t e;
36 |
37 | if (lua_isnoneornil(L,2))
38 | bs = NULL;
39 | else
40 | bs = luaL_check_bytestring(L,2);
41 |
42 | if ((e=crypto_create_context(res,alg,bs))==CRYPTO_OK)
43 | lua_push_bytestring(L,res);
44 | else
45 | {
46 | bytestring_free(res);
47 | return luaL_error(L,crypto_stringify_error(e));
48 | }
49 | return 1;
50 | }
51 |
52 | static int subr_crypto_encrypt(lua_State* L)
53 | {
54 | bytestring_t* ctx = luaL_check_bytestring(L,1);
55 | bytestring_t* src = luaL_check_bytestring(L,2);
56 | bytestring_t* iv;
57 | bytestring_t* res = bytestring_new(8);
58 | crypto_error_t e;
59 |
60 | if (lua_isnoneornil(L,3))
61 | iv = NULL;
62 | else
63 | iv = luaL_check_bytestring(L,3);
64 |
65 | if ((e=crypto_encrypt(res,ctx,src,iv))==CRYPTO_OK)
66 | lua_push_bytestring(L,res);
67 | else
68 | {
69 | bytestring_free(res);
70 | return luaL_error(L,crypto_stringify_error(e));
71 | }
72 | return 1;
73 | }
74 |
75 | static int subr_crypto_decrypt(lua_State* L)
76 | {
77 | bytestring_t* ctx = luaL_check_bytestring(L,1);
78 | bytestring_t* src = luaL_check_bytestring(L,2);
79 | bytestring_t* iv;
80 | bytestring_t* res = bytestring_new(8);
81 | crypto_error_t e;
82 |
83 | if (lua_isnoneornil(L,3))
84 | iv = NULL;
85 | else
86 | iv = luaL_check_bytestring(L,3);
87 |
88 | if ((e=crypto_decrypt(res,ctx,src,iv))==CRYPTO_OK)
89 | lua_push_bytestring(L,res);
90 | else
91 | {
92 | bytestring_free(res);
93 | return luaL_error(L,crypto_stringify_error(e));
94 | }
95 | return 1;
96 | }
97 |
98 | static int subr_crypto_mac(lua_State* L)
99 | {
100 | bytestring_t* ctx = luaL_check_bytestring(L,1);
101 | bytestring_t* src = luaL_check_bytestring(L,2);
102 | bytestring_t* res = bytestring_new(8);
103 | crypto_error_t e;
104 |
105 | if ((e=crypto_mac(res,ctx,src))==CRYPTO_OK)
106 | lua_push_bytestring(L,res);
107 | else
108 | {
109 | bytestring_free(res);
110 | return luaL_error(L,crypto_stringify_error(e));
111 | }
112 | return 1;
113 | }
114 |
115 | static int subr_crypto_digest(lua_State* L)
116 | {
117 | bytestring_t* ctx = luaL_check_bytestring(L,1);
118 | bytestring_t* src = luaL_check_bytestring(L,2);
119 | bytestring_t* res = bytestring_new(8);
120 | crypto_error_t e;
121 |
122 | if ((e=crypto_digest(res,ctx,src))==CRYPTO_OK)
123 | lua_push_bytestring(L,res);
124 | else
125 | {
126 | bytestring_free(res);
127 | return luaL_error(L,crypto_stringify_error(e));
128 | }
129 | return 1;
130 | }
131 |
132 | static const struct luaL_Reg cryptolib [] = {
133 | { "create_context", subr_crypto_create_context },
134 | { "encrypt", subr_crypto_encrypt },
135 | { "decrypt", subr_crypto_decrypt },
136 | { "mac", subr_crypto_mac },
137 | { "digest", subr_crypto_digest },
138 | { NULL, NULL} /* sentinel */
139 | };
140 |
141 | struct luaL_reg_integer {
142 | const char* name;
143 | int value;
144 | };
145 |
146 | static const struct luaL_reg_integer cryptoconstants [] = {
147 | { "ALG_DES_ECB", CRYPTO_ALG_DES_ECB },
148 | { "ALG_DES_CBC", CRYPTO_ALG_DES_CBC },
149 | { "ALG_DES2_EDE_ECB", CRYPTO_ALG_DES2_EDE_ECB },
150 | { "ALG_DES2_EDE_CBC", CRYPTO_ALG_DES2_EDE_CBC },
151 | { "ALG_ISO9797_M3", CRYPTO_ALG_ISO9797_M3 },
152 | { "ALG_SHA1", CRYPTO_ALG_SHA1 },
153 | { "PAD_ZERO", CRYPTO_PAD_ZERO },
154 | { "PAD_OPT_80_ZERO", CRYPTO_PAD_OPT_80_ZERO },
155 | { "PAD_ISO9797_P2", CRYPTO_PAD_ISO9797_P2 },
156 | { NULL, 0} /* sentinel */
157 | };
158 |
159 | int luaopen_crypto(lua_State* L)
160 | {
161 | int i;
162 | luaL_newlib(L,cryptolib);
163 |
164 | for (i=0;cryptoconstants[i].name;i++)
165 | {
166 | lua_pushstring (L, cryptoconstants[i].name);
167 | lua_pushinteger(L, cryptoconstants[i].value);
168 | lua_settable(L,-3);
169 | }
170 | lua_setglobal(L,"crypto");
171 |
172 | return 1;
173 | }
174 |
175 |
176 |
--------------------------------------------------------------------------------
/dyntree_model.h:
--------------------------------------------------------------------------------
1 | #ifndef dyntree_model_h
2 | #define dyntree_model_h
3 |
4 | #include
5 |
6 | #define DYNTREE_MODEL_TYPE (dyntree_model_get_type())
7 | #define DYNTREE_MODEL(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj),DYNTREE_MODEL_TYPE, DyntreeModel))
8 | #define DYNTREE_MODEL_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), DYNTREE_MODEL, DyntreeModelClass))
9 | #define DYNTREE_IS_MODEL(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), DYNTREE_MODEL_TYPE))
10 | #define DYNTREE_IS_MODEL_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), DYNTREE_MODEL_TYPE))
11 | #define DYNTREE_MODEL_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), DYNTREE_MODEL_TYPE, CustomListClass))
12 |
13 | enum {
14 | CC_CLASSNAME = 0, /* 0 */
15 | CC_LABEL,
16 | CC_ID,
17 | CC_SIZE,
18 | CC_VAL,
19 | CC_ALT, /* 5 */
20 | CC_MIME_TYPE, /* 6 */
21 | CC_INITIAL_COUNT /* 7 */
22 | };
23 |
24 | typedef struct {
25 | char *name;
26 | } DyntreeModelAttributeDescriptor;
27 |
28 | typedef struct {
29 | char *value;
30 | } DyntreeModelAttributeValue;
31 |
32 |
33 | typedef struct _DyntreeModelNode {
34 | struct _DyntreeModelNode *parent;
35 | struct _DyntreeModelNode *prev;
36 | struct _DyntreeModelNode *next;
37 | struct _DyntreeModelNode *children;
38 | DyntreeModelAttributeValue *attributes;
39 | int max_attributes;
40 | int sibling_index;
41 | int n_children;
42 | } DyntreeModelNode;
43 |
44 | typedef struct {
45 | GObject parent;
46 | DyntreeModelNode *root;
47 |
48 | /* extras */
49 | GHashTable *columns_by_name;
50 | DyntreeModelAttributeDescriptor *columns_by_index;
51 | gint n_columns;
52 | gint max_columns;
53 | gint stamp;
54 | } DyntreeModel;
55 |
56 | typedef struct {
57 | GObjectClass parent_class;
58 | } DyntreeModelClass;
59 |
60 | typedef gboolean (* DyntreeModelFunc)(DyntreeModel *, GtkTreeIter *, gpointer);
61 |
62 |
63 | GType dyntree_model_get_type(void);
64 |
65 | /***** USER FUNCS *****/
66 |
67 | extern DyntreeModel *CARD_DATA_STORE;
68 |
69 | /* Creating our model */
70 |
71 | DyntreeModel *dyntree_model_new (void);
72 |
73 | /* Adding columns to our model */
74 |
75 | int dyntree_model_column_register(DyntreeModel *ctm,
76 | const char *column_name);
77 |
78 | int dyntree_model_column_name_to_index(DyntreeModel *ctm,
79 | const char *column_name);
80 |
81 | const char *dyntree_model_column_index_to_name(DyntreeModel *ctm,
82 | int index);
83 |
84 | gint dyntree_model_get_n_columns (GtkTreeModel *tree_model);
85 |
86 | /* Setting attributes */
87 |
88 | gboolean dyntree_model_iter_attribute_set(DyntreeModel *m,
89 | GtkTreeIter *iter,
90 | int index,
91 | const char *str);
92 |
93 | gboolean dyntree_model_iter_attribute_set_by_name(DyntreeModel *m,
94 | GtkTreeIter *iter,
95 | const char *attr_name,
96 | const char *str);
97 |
98 | gboolean dyntree_model_iter_attributes_setvalist(DyntreeModel *ctm,
99 | GtkTreeIter *iter,
100 | va_list al);
101 |
102 | gboolean dyntree_model_iter_attributes_set(DyntreeModel *ctm,
103 | GtkTreeIter *iter,
104 | ...);
105 |
106 | /* Reading attributes */
107 |
108 | gboolean dyntree_model_iter_attribute_get(DyntreeModel *m,
109 | GtkTreeIter *iter,
110 | int index,
111 | const char **str);
112 |
113 | gboolean dyntree_model_iter_attribute_get_by_name(DyntreeModel *m,
114 | GtkTreeIter *iter,
115 | const char *attr_name,
116 | const char **ptr);
117 |
118 | gboolean dyntree_model_iter_attributes_getvalist(DyntreeModel *ctm,
119 | GtkTreeIter *iter,
120 | va_list al);
121 |
122 | gboolean dyntree_model_iter_attributes_get(DyntreeModel *ctm,
123 | GtkTreeIter *iter,
124 | ...);
125 |
126 | /* Removing a node */
127 |
128 | gboolean dyntree_model_iter_remove(DyntreeModel *ctm,
129 | GtkTreeIter *iter);
130 |
131 | void dyntree_model_iter_clear(DyntreeModel *ctm);
132 |
133 | /* Adding a node */
134 |
135 | void dyntree_model_iter_append (DyntreeModel *ctm,
136 | GtkTreeIter *child,
137 | GtkTreeIter *parent);
138 |
139 | /* Testing if empty */
140 |
141 | #define dyntree_model_is_empty(ctm) (ctm->root==NULL)
142 |
143 | /* exporting/importing XML */
144 |
145 | char* dyntree_model_iter_to_xml(DyntreeModel *ctm, GtkTreeIter *root, gboolean full_xml);
146 | /* result (char*) must be freed with g_free() */
147 |
148 | gboolean dyntree_model_iter_to_xml_file(DyntreeModel* ct, GtkTreeIter *root, const char *fname);
149 |
150 | gboolean dyntree_model_iter_from_xml(DyntreeModel *ct, GtkTreeIter *parent, gboolean full_xml, const char *source_val, int source_len);
151 |
152 | gboolean dyntree_model_iter_from_xml_file(DyntreeModel *ct, GtkTreeIter *parent, const char *fname);
153 |
154 | /* exporting to other formats */
155 | char* dyntree_model_iter_to_text(DyntreeModel *ctm, GtkTreeIter *root);
156 |
157 | /* searching */
158 |
159 | gboolean dyntree_model_iter_find_first(DyntreeModel *ctm,
160 | GtkTreeIter *result,
161 | GtkTreeIter *root,
162 | int *indices,
163 | char **str,
164 | int n_values);
165 |
166 | gboolean dyntree_model_iter_find_next(DyntreeModel *ctm,
167 | GtkTreeIter *result,
168 | GtkTreeIter *root,
169 | int *indices,
170 | char **str,
171 | int n_values);
172 |
173 | /* iterating */
174 |
175 | gboolean dyntree_model_foreach(DyntreeModel *ctm, GtkTreeIter *root, DyntreeModelFunc func, gpointer user_data);
176 |
177 | #endif
178 |
--------------------------------------------------------------------------------