USECAManager.pas ( File view )

  • By sathex 2016-03-20
  • View(s):0
  • Download(s):0
  • Point(s): 1
			unit USECAManager;

interface

uses Windows,Sysutils,USmartCardISO,ComCtrls,UnitTimer,SyncObjs,Classes;

Type TSECA_Provider=record
    Ident: WORD;
    Name: String;
    PPUA: DWORD;
    ExpireDate: WORD;
    PBM: Array [0..7] of BYTE;
    Keys: array [0..15] of BYTE;
end;

Type PSECA_Provider=^TSECA_PROVIDER;

Type TCardDetails=record
    Serial: Array[0..5] of BYTE;
    ROMChecksum: array[0..15] of BYTE;
    CopyRight: array[0..63] of char;
end;

type TSECA_CALLBACK=procedure(Me: Pointer) of object;
type TCALLBACK_ADDTOCAMLOG=procedure(Buffer: Pointer) of object;

type TSECAManager=class(TObject)
  Private
    function GetSerialHexString: string;
    function GetHexFromArray(P: PBYTEARRAY;Start: DWORD; Len: DWORD; Separator: string): string;
    function GetSerialDecimalString: string;
//    function GetCopyright: string;
    function GetROMChecksum: string;
    function StatusWord(ar: Array of Byte): WORD;
    function GetProvider(index: integer): PSECA_Provider;
    Function ISOWrite(INS, Data, Status: PBYTEARRAY): Boolean;
    Function ISORead(INS, Data, Status: PBYTEARRAY): Boolean;
    procedure AddToCAMLog(INS,Data,Status: PBYTEARRAY;TimeTake: DWORD);
    function GetLastINSStatus: WORD;
    function GetLastINSData: PBYTEARRAY;
    function GetCardSerial: PBYTEARRAY;
    function GetLastINSHeader: PBYTEARRAY;
  Protected
    mvarProviders: Array[0..15] of TSECA_Provider;
    mvarProvidersCounter: integer;
    mvarCard: TCardDetails;
    mvarISO: TCOMISO;
    mvarCallBack: TSECA_CALLBACK;
    mvarOnInsSent: TSECA_CALLBACK;
    mvarOnAddToCAMLog: TCALLBACK_ADDTOCAMLOG;
    mvarDataBuffer: array [0..255] of BYTE;
    mvarINS: array [0..4] of BYTE;
    mvarStatus: array [0..1] of BYTE;
    mvarCritical: TCriticalSection;
    Procedure AddProvider(Ident: WORD);
  Public
    function EndianChange(const Value: WORD): WORD; overload;
    function EndianChange(const Value: DWORD): DWORD; overload;
    procedure FillArray(AR: Array of byte; P: PBYTEARRAY; Len: integer);
    property ISO: TCOMISO read mvarISO write mvarISO;
    property CallBack: TSECA_CALLBACK read mvarCallBack write mvarCallBack;
    property OnSentINS: TSECA_CALLBACK read mvarOnInsSent write mvarOnInsSent;
    property OnAddToCAMLog: TCALLBACK_ADDTOCAMLOG read mvarOnAddToCAMLog write mvarOnAddToCAMLog;
    property Providers: integer read mvarProvidersCounter write mvarProvidersCounter;
    Property SerialHexString: string Read GetSerialHexString;
    property SerialDecimalString: string read GetSerialDecimalString;
    property Serial: PBYTEARRAY read GetCardSerial;
    property ROMChecksum: string read GetROMChecksum;
//    property Copyright: string read GetCopyright;
    Property Provider[index: integer]: PSECA_Provider read GetProvider;
    Property LastINSStatus: WORD read GetLastINSStatus;
    property LastINSData: PBYTEARRAY read GetLastINSData;
    property LastINSHeader: PBYTEARRAY read GetLastINSHeader;
    property LastINSDataLength: BYTE read mvarINS[4];
    property CriticalFlag: TCriticalSection read mvarCritical;
    Function ConvertDate(SECADate: WORD): String;
    Function GetIndexForProvider(ProviderID: WORD): BYTE;
    Function GetStatusText(Status: PBYTEARRAY): string;
    procedure SendINS(INS: PBYTEARRAY);
    function HaveRightsToView(ProvID: WORD; PBM: PBYTEARRAY; EventID: WORD;Date: WORD): Boolean;
    Procedure BootCard;
    Constructor Create;
    Destructor Destroy; override;
end;

implementation

const MAX_INS_LOG=500;

{
 TSECAManager 
}

procedure TSECAManager.AddProvider(Ident: WORD);
begin
    mvarProviders[mvarProvidersCounter].Ident:=EndianChange(Ident);
    inc(mvarProvidersCounter);
end;

procedure TSECAManager.BootCard;
var
    PW: PWORD;
    PDW: PDWORD;
    provC: WORD;
    P1: BYTE;
    s: string;
begin
    mvarCritical.Enter;
    ISO.SoftSleep(50);
    //Read serial number...
    FillArray([$C1,$0E,$00,$00,$08],@mvarINS[0],5);
    if not ISORead(@mvarINS[0],@mvarDataBuffer[0],@mvarStatus[0]) then begin
        mvarCritical.Release;
        Exit;
    end;
    move(pchar(@mvarDataBuffer[2])^,pchar(@mvarCard.Serial[0])^,6);

    mvarCallBack(Self);

    //Request Copyright Message... C1 0A 00 00 3E
    //It does not work in all cards... removed from code...
{
*    FillArray([$C1,$0A,$00,$00,$44],@mvarINS[0],5);
    if ISORead(@mvarINS[0],@mvarDataBuffer[0],@mvarStatus[0]) then begin
        move(pchar(@mvarDataBuffer[26])^,pchar(@mvarCard.ROMChecksum[0])^,16);
        move(pchar(@mvarDataBuffer[42])^,pchar(@mvarCard.CopyRight[0])^,26);
        mvarCard.CopyRight[26]:=char(0);
    end;*
}
//    mvarCallBack(Self);

    //Request providers
    FillArray([$C1,$16,$00,$00,$06],@mvarINS[0],5);
    if ISORead(@mvarINS[0],@mvarDataBuffer[0],@mvarStatus[0]) then begin
        if StatusWord(mvarStatus)=$9000 Then begin
            PW:=@mvarDataBuffer[2];
            ProvC:=EndianChange(PW^);
            P1:=0;
            while provC>0 Do begin
                //Request Provider Name & data
                FillArray([$C1,$12,P1,$00,$19],@mvarINS[0],5);
                if ISORead(@mvarINS[0],@mvarDataBuffer[0],@mvarStatus[0]) then begin
                    if StatusWord(mvarStatus)=$9000 Then begin
                        PW:=@mvarDataBuffer[0];
                        AddProvider(PW^);
                        SetLength(S,16);
                        move(pchar(@mvarDataBuffer[2])^,pchar(S)^,16);
                        mvarProviders[mvarProvidersCounter-1].Name:=Trim(S);
                        PDW:=@mvarDataBuffer[18];
                        mvarProviders[mvarProvidersCounter-1].PPUA:=EndianChange(PDW^);
                        PW:=@mvarDataBuffer[22];
                        mvarProviders[mvarProvidersCounter-1].ExpireDate:=EndianChange(PW^);
                    end;
                end;
                //Read PBM
                FillArray([$C1,$34,P1,$00,$03],@mvarINS[0],5);
                FillArray([$00,$00,$00],@mvarDataBuffer[0],3);
                if ISOWrite(@mvarINS[0],@mvarDataBuffer[0],@mvarStatus[0]) then begin
                    if StatusWord(mvarStatus)=$9000 Then begin
                        FillArray([$C1,$32,P1,$00,$0A],@mvarINS[0],5);
                        if ISORead(@mvarINS[0],@mvarDataBuffer[0],@mvarStatus[0]) then begin
                            if StatusWord(mvarStatus)=$9000 Then begin
                                if mvarDataBuffer[0]=$83 Then begin
                                    move(pchar(@mvarDataBuffer[1])^,pchar(@mvarProviders[mvarProvidersCounter-1].PBM[0])^,8);
{
 Added to test different PBMs...
        with mvarProviders[mvarProvidersCounter-1] do begin
        PBM[0]:=$78;
        PBM[1]:=$b7;
        PBM[2]:=$f1;
        PBM[3]:=$3d;
        PBM[4]:=$39;
        PBM[5]:=$fa;
        PBM[6]:=$b0;
        PBM[7]:=$a1;
        end;
}
                                end;
                            end;
                        end;
                    end;
                end;
                //Read available Keys...
                FillArray([$C1,$1A,P1,$00,$15],@mvarINS[0],5);
                if ISORead(@mvarINS[0],@mvarDataBuffer[0],@mvarStatus[0]) then begin
                    if StatusWord(mvarStatus)=$9000 Then begin
                        move(pchar(@mvarDataBuffer[5])^,pchar(@mvarProviders[mvarProvidersCounter-1].Keys[0])^,16);
                    end;
                end;
                mvarCallBack(Self);
                //Next Provider...
                inc(P1);
                ProvC:=ProvC shr 1;
            end;
        end;
    end;
    mvarCritical.Release;
end;

constructor TSECAManager.Create;
var
    j: integer;
begin
    mvarCritical:=TCriticalSection.Create;
    for j := 0 to $F do begin
        with mvarProviders[j] do begin
            Ident:=$FFFF;
            PPUA:=0;
            ExpireDate:=0;
            FillChar(PBM,Sizeof(PBM),$00);
            FillChar(KEYS,Sizeof(KEYS),$FF);
        end;
    end;
    mvarProvidersCounter:=0;
    mvarCallBack:=nil;
    mvarOnInsSent:=nil;
    mvarOnAddToCAMLog:=nil;
    FillChar(mvarDataBuffer,sizeof(mvarDataBuffer),$00);
    FillChar(mvarStatus,sizeof(mvarStatus),$00);
end;

destructor TSECAManager.Destroy;
begin
    mvarCritical.Free;
  inherited;
end;

procedure TSECAManager.FillArray(AR: array of byte; P: PBYTEARRAY;
  Len: integer);
var
    j: integer;
begin
    for j := 0 to Len-1 do begin
        P[j]:=AR[j];
    end;
end;

function TSECAManager.EndianChange(const Value: Word): Word;
begin
    Result:=(Value shr 8) or (Value shl 8);
end;

function TSECAManager.EndianChange(const Value: DWORD): DWORD;
begin
    Result:=(Value shr 24) or
            ((Value shr 8) and $0000FF00) or
            ((Value shl 8) and $00FF0000) or
            ((Value shl 24) and $FF000000);
end;

function TSECAManager.GetSerialHexString: string;
begin
    Result:=GetHexFromArray(@mvarCard.Serial[0],0,6,'');
end;

function TSECAManager.GetHexFromArray(P: PBYTEARRAY;Start: DWORD; Len: DWORD; Separator: string): string;
var
    i: DWORD;
    s: string;
begin
    for i := Start to Start+Len-1 do begin
        s:=s+format('%.2x',[P[i]]);
        if i<Start+Len-1 Then begin
            s:=s+Separator;
        end;
    end;
    Result:=S;
end;

function TSECAManager.GetSerialDecimalString: string;
var
    s: string;
    p: PChar;
    Conta: integer;
    V: int64;
    C: integer;
begin
    P:=(@mvarCard.Serial[2]);
    s:='$';
    for Conta := 0 to 3 do
    begin
      s:=s+format('%.2x',[integer(PByte(P)^)]);
      Inc(P,1);
    end;
    Val(s,V,C);
    Result:=inttostr(V);
end;

{
*function TSECAManager.GetCopyright: string;
begin
    Result:=mvarCard.CopyRight;
end;*
}

function TSECAManager.GetROMChecksum: string;
begin
    Result:=GetHexFromArray(@mvarCard.ROMCheckSum[0],0,16,'');
end;

function TSECAManager.StatusWord(ar: array of Byte): WORD;
begin
    Result:=ar[0] shl 8 or ar[1];
end;

function TSECAManager.GetProvider(index: integer): PSECA_Provider;
begin
    Resu
...
...
(Not finished, please download and read the complete file)
			
...
Expand> <Close

Want complete source code? Download it here

Point(s): 1

Download
0 lines left, continue to read
Sponsored links

File list

Tips: You can preview the content of files by clicking file names^_^
Name Size Date
About.rtf20.49 kB2005-03-15|17:16
changelog.txt4.26 kB2005-03-15|17:16
clean.bat92.00 B2005-01-05|02:35
DVBCore.pas31.98 kB2004-12-17|23:45
frmPPVInfo.dfm15.69 kB2004-12-19|19:54
frmPPVInfo.pas6.17 kB2005-03-03|01:02
01.96 kB
About.bmp3.05 kB2004-12-17|23:52
About.ico2.40 kB2004-12-17|23:52
Add.bmp1.30 kB2004-12-17|23:52
bluenote.ico7.23 kB2004-12-17|23:52
bug.jpg6.04 kB2005-01-05|02:35
CAM.ico2.40 kB2004-12-17|23:52
Close.bmp3.05 kB2004-12-17|23:52
EPG.bmp1.05 kB2005-01-05|21:10
EPG.ico1.37 kB2004-12-17|23:52
EPGOFF.bmp1.62 kB2004-12-17|23:52
EPGON.bmp1.62 kB2004-12-17|23:52
EPG_Gliph.bmp3.43 kB2004-12-17|23:52
Event.ico1.37 kB2004-12-17|23:52
jetons.ico1.37 kB2004-12-17|23:52
leftLogo.bmp9.96 kB2004-12-17|23:52
logger.ico1.68 kB2004-12-17|23:52
MagicWand.bmp1.30 kB2004-12-17|23:52
MagicWand.ico1.37 kB2004-12-17|23:52
MAS.ico1.37 kB2004-12-17|23:52
MENOS.ico1.37 kB2004-12-17|23:52
nemesis.ico4.19 kB2004-12-17|23:52
Phoenix.ico1.72 kB2004-12-17|23:52
Provider.ico1.37 kB2004-12-17|23:52
Remove.bmp1.30 kB2004-12-17|23:52
Reset.bmp3.05 kB2004-12-17|23:52
Restart.bmp1.30 kB2004-12-17|23:52
Save.bmp2.05 kB2004-12-17|23:52
scriptengine.ico7.23 kB2004-12-17|23:52
ScriptsEngine.bmp6.80 kB2004-12-17|23:52
Tools.bmp246.00 B2004-12-17|23:52
tuxprogramming.jpg4.15 kB2005-01-13|19:01
V9Card.jpg11.00 kB2005-03-03|01:02
IFSI_IniFiles.pas10.45 kB2004-12-19|19:54
MpgLib.DLL141.50 kB2004-12-24|17:03
PMCAM0.00 B2005-03-15|17:18
PMCAM4.67 kB2005-01-05|17:24
PMCAM4.69 kB2005-01-05|17:24
PMCAM4.52 kB2005-01-05|17:24
PMCAM.rc3.60 kB2004-12-17|23:47
PMCAM2.dpr6.30 kB2005-03-11|20:15
PMCAM2.res1.70 kB2005-03-15|17:16
PMCAM2StandAlone.dpr1.19 kB2005-03-03|01:02
PMCAM2StandAlone.res4.95 kB2005-03-11|20:15
PMCAMMenu.rc259.00 B2004-12-26|20:10
PMCAMMenu.RES162.25 kB2005-03-15|17:16
rUPClickSplitter.res740.00 B2004-12-19|19:54
santa_rock.jpg5.65 kB2004-12-24|17:59
UBitManager.pas4.18 kB2004-12-17|23:45
uDecode123.pas4.01 kB2004-12-29|01:33
UDVBConditionalAccessSystemNames.pas1.49 kB2004-12-17|23:45
UDVBCoreToMD.pas4.59 kB2004-12-17|23:45
UDVBPIDNames.pas1.23 kB2004-12-17|23:45
UDVBTablesHolder.pas2.68 kB2004-12-28|02:17
UEPGEntry.pas3.29 kB2004-12-17|23:45
UEPGMHW.dfm7.72 kB2005-01-11|02:38
UEPGMHW.pas40.85 kB2005-01-11|02:38
UfrmAddFilter.dfm6.86 kB2004-12-17|23:46
UfrmAddFilter.pas3.68 kB2004-12-17|23:45
UfrmCAM.dfm217.00 kB2005-03-15|03:22
UfrmCAM.pas159.37 kB2005-03-15|17:16
ufrmDLLForm.dfm420.00 B2004-12-19|19:54
ufrmDLLForm.pas1.87 kB2004-12-26|20:10
UfrmEMM.dfm1.28 kB2004-12-17|23:46
UfrmEMM.pas1.47 kB2004-12-17|23:45
UfrmEPGAdvanced.dfm7.01 kB2005-01-05|21:10
UfrmEPGAdvanced.pas2.56 kB2005-01-05|21:10
UfrmMHWEPGEntries.dfm3.81 kB2004-12-17|23:46
UfrmMHWEPGEntries.pas4.33 kB2004-12-17|23:45
ufrmMHWRadio.dfm35.85 kB2005-01-21|18:53
ufrmMHWRadio.pas37.84 kB2005-01-21|18:53
UfrmPMTDetails.dfm2.31 kB2005-01-21|18:53
UfrmPMTDetails.pas2.74 kB2005-01-21|18:53
UfrmWarningOnExit.dfm15.64 kB2005-01-05|21:10
UfrmWarningOnExit.pas1.44 kB2005-01-05|21:10
ULogEngine.pas15.89 kB2005-03-12|17:11
UMDDefs.pas4.07 kB2005-03-03|01:02
UMD_Impl.pas11.26 kB2005-03-03|01:02
United32.pas14.20 kB2004-12-17|23:45
UnitISO639_3.pas10.04 kB2005-03-03|01:02
UnitMDInterface.pas28.92 kB2005-03-15|03:22
UnitTimer.pas1.39 kB2004-12-17|23:45
Unit_CRC32.pas3.62 kB2004-12-17|23:45
uPESToTS.pas6.11 kB2005-03-03|01:02
UScriptFunctions.pas2.97 kB2005-01-03|16:45
UScriptsEditor.dfm58.10 kB2005-01-21|18:53
UScriptsEditor.pas22.02 kB2005-03-03|01:02
USECAManager.pas18.26 kB2005-03-03|01:02
USECATableStore.pas12.92 kB2004-12-17|23:45
USECA_EMM.pas7.74 kB2005-03-12|03:36
USmartCardISO.pas14.45 kB2004-12-17|23:45
UTfrmMultiDec.dfm407.00 B2005-01-21|18:53
UTfrmMultiDec.pas4.38 kB2005-01-21|18:53
UTranslate.pas6.49 kB2004-12-24|17:03
UTS184ToBitFilter.pas36.28 kB2005-03-11|20:15
uUPClickSplitter.dcr488.00 B2004-12-19|19:54
uUPClickSplitter.dcu18.09 kB2005-03-03|01:02
uUPClickSplitter.pas20.43 kB2004-12-26|20:10
PMCAM2_2.50.zip870.87 kB2016-03-19|22:08
...
Sponsored links

USECAManager.pas (1.30 MB)

Need 1 point
Your Point(s)

Your Point isn't enough.

Get point immediately by PayPal

More(Debit card / Credit card / PayPal Credit / Online Banking)

Submit your source codes. Get more point

LOGIN

Don't have an account? Register now
Need any help?
Mail to: support@codeforge.com

切换到中文版?

CodeForge Chinese Version
CodeForge English Version

Where are you going?

^_^"Oops ...

Sorry!This guy is mysterious, its blog hasn't been opened, try another, please!
OK

Warm tip!

CodeForge to FavoriteFavorite by Ctrl+D