|
SASC
DVBSoftCAM
|
00001 /* 00002 * Softcam plugin to VDR (C++) 00003 * 00004 * This code is free software; you can redistribute it and/or 00005 * modify it under the terms of the GNU General Public License 00006 * as published by the Free Software Foundation; either version 2 00007 * of the License, or (at your option) any later version. 00008 * 00009 * This code is distributed in the hope that it will be useful, 00010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 * GNU General Public License for more details. 00013 * 00014 * You should have received a copy of the GNU General Public License 00015 * along with this program; if not, write to the Free Software 00016 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 00017 * Or, point your browser to http://www.gnu.org/copyleft/gpl.html 00018 */ 00019 00020 #include <stdlib.h> 00021 #include <string.h> 00022 #include <ctype.h> 00023 00024 #include "system-common.h" 00025 00026 #include "irdeto.h" 00027 #include "log-irdeto.h" 00028 #include "version.h" 00029 00030 SCAPIVERSTAG(); 00031 00032 static const struct LogModule lm_sys = { 00033 (LMOD_ENABLE|L_SYS_ALL)&LOPT_MASK, 00034 (LMOD_ENABLE|L_SYS_DEFDEF)&LOPT_MASK, 00035 "irdeto", 00036 { L_SYS_DEFNAMES,"rawemm","rawecm" } 00037 }; 00038 ADD_MODULE(L_SYS,lm_sys) 00039 00040 // -- cPlainKeyIrd ------------------------------------------------------------- 00041 00042 #define I1_KEYLEN 8 00043 #define I2_KEYLEN 16 00044 00045 class cPlainKeyIrd : public cHexKey { 00046 private: 00047 bool IsI2Key(void); 00048 protected: 00049 virtual int IdSize(void); 00050 virtual cString PrintKeyNr(void); 00051 public: 00052 cPlainKeyIrd(bool Super); 00053 virtual bool Parse(const char *line); 00054 virtual bool SetKey(void *Key, int Keylen); 00055 virtual bool SetBinKey(unsigned char *Mem, int Keylen); 00056 }; 00057 00058 static cPlainKeyTypeReg<cPlainKeyIrd,'I'> KeyReg; 00059 00060 cPlainKeyIrd::cPlainKeyIrd(bool Super) 00061 :cHexKey(Super) 00062 {} 00063 00064 bool cPlainKeyIrd::SetKey(void *Key, int Keylen) 00065 { 00066 if(!IsI2Key()) SetSupersede(false); 00067 return cHexKey::SetKey(Key,Keylen); 00068 } 00069 00070 bool cPlainKeyIrd::SetBinKey(unsigned char *Mem, int Keylen) 00071 { 00072 if(!IsI2Key()) SetSupersede(false); 00073 return cHexKey::SetBinKey(Mem,Keylen); 00074 } 00075 00076 int cPlainKeyIrd::IdSize(void) 00077 { 00078 return IsI2Key() ? 4 : 2; 00079 } 00080 00081 bool cPlainKeyIrd::IsI2Key(void) 00082 { 00083 return TYPE(keynr)!=TYPE_I1; 00084 } 00085 00086 bool cPlainKeyIrd::Parse(const char *line) 00087 { 00088 unsigned char sid[2], skey[I2_KEYLEN]; 00089 int klen; 00090 if(GetChar(line,&type,1) && (klen=GetHex(line,sid,2,false))) { 00091 type=toupper(type); id=Bin2Int(sid,klen); 00092 line=skipspace(line); 00093 bool ok=false; 00094 if(klen==2) { 00095 klen=I2_KEYLEN; 00096 unsigned char prov; 00097 if(GetHex(line,&prov,1)) { 00098 line=skipspace(line); 00099 int typ, id; 00100 if(!strncasecmp(line,"IV",2)) { typ=TYPE_IV; id=0; line+=2; ok=true; } 00101 else if(!strncasecmp(line,"ECM",3)) { typ=TYPE_SEED; id=0; line+=3; ok=true; } 00102 else if(!strncasecmp(line,"EMM",3)) { typ=TYPE_SEED; id=1; line+=3; ok=true; } 00103 else if(!strncasecmp(line,"MK",2)) { typ=TYPE_PMK; id=line[2]-'0'; line+=3; ok=true; } 00104 else { typ=TYPE_OP; ok=GetHex(line,sid,1); id=sid[0]; } 00105 keynr=KEYSET(prov,typ,id); 00106 } 00107 } 00108 else { 00109 klen=I1_KEYLEN; 00110 ok=GetHex(line,sid,1); 00111 keynr=KEYSET(0,TYPE_I1,sid[0]); 00112 } 00113 line=skipspace(line); 00114 if(ok && GetHex(line,skey,klen)) { 00115 SetBinKey(skey,klen); 00116 return true; 00117 } 00118 } 00119 return false; 00120 } 00121 00122 cString cPlainKeyIrd::PrintKeyNr(void) 00123 { 00124 char tmp[16]; 00125 if(IsI2Key()) { 00126 snprintf(tmp,sizeof(tmp),"%02X ",PROV(keynr)); 00127 switch(TYPE(keynr)) { 00128 case TYPE_OP: snprintf(tmp+3,sizeof(tmp)-3,"%02X",ID(keynr)); break; 00129 case TYPE_IV: snprintf(tmp+3,sizeof(tmp)-3,"IV"); break; 00130 case TYPE_SEED: snprintf(tmp+3,sizeof(tmp)-3,"%s",ID(keynr)?"EMM":"ECM"); break; 00131 case TYPE_PMK: snprintf(tmp+3,sizeof(tmp)-3,"MK%d",ID(keynr)); break; 00132 } 00133 } 00134 else 00135 snprintf(tmp,sizeof(tmp),"%02X",ID(keynr)); 00136 return tmp; 00137 }