Smart card ATR parsing

Smart card ATR parsing

http://ludovic.rousseau.free.fr/softwares/pcsc-tools/smartcard_list.txt

http://dexterous-programmer.blogspot.com/2012/05/emv-tags.html

https://www.rapidtables.com/convert/number/hex-to-decimal.html


Sample code to find ATR with smartcard_list.txt

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    Edit1: TEdit;
    Memo1: TMemo;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
    FSmartCardL: TStrings;
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
var
  i,j : integer;
begin
  FSmartCardL:= TStringList.create;
  if FileExists(ExtractFilePath(paramstr(0))+'smartcard_list.txt') then
  begin
    FSmartCardL.LoadFromFile(ExtractFilePath(paramstr(0))+'smartcard_list.txt');
    for i  := 0 to Pred(FSmartCardL.Count) do
    begin
      if FSmartCardL.Strings[i] = trim(Edit1.text) then
      begin
        memo1.clear;
        j:= 1;
        while (Length(Trim(FSmartCardL.Strings[i+j])) > 0) do begin
           memo1.lines.add(Trim(  FSmartCardL.Strings[i+j] ) ) ;
           inc(j);
        end;
        break;
      end;
    end;
  end;

  FSmartCardL.free;
end;

end.


object Form1: TForm1
  Left = 322
  Top = 180
  Width = 589
  Height = 293
  Caption = 'Form1'
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  OldCreateOrder = False
  PixelsPerInch = 96
  TextHeight = 13
  object Button1: TButton
    Left = 480
    Top = 0
    Width = 75
    Height = 25
    Caption = 'Get ATR Description'
    TabOrder = 0
    OnClick = Button1Click
  end
  object Edit1: TEdit
    Left = 16
    Top = 8
    Width = 441
    Height = 21
    TabOrder = 1
    Text = '3B 04 A2 13 10 91'
  end
  object Memo1: TMemo
    Left = 16
    Top = 32
    Width = 537
    Height = 201
    Lines.Strings = (
      'Memo1')
    TabOrder = 2
  end
end

Comments