//====================================== // ScanServer: constructor... //-------------------------------------- ScanServer::ScanServer(int question,int xavailable,str card,str copt) { ask = question; withx = xavailable; SetCard(card); SetCardModule(copt); checkQuestion = 0; checkPCIVendor = 0; elements = 0; current = 0; pcheck = 1; }
static void SetCardStr(CardImage &ci, const char *pcszKeyword, PCTCHAR pcszStr, const char *pcszComment = nullptr) { char sz[256]; #ifdef UNICODE char *psz = sz; *psz++ = '\''; ie_UnicodeToLatin1(psz, pcszStr, sizeof(sz)-2); psz += strlen(psz); *psz++ = '\''; *psz = 0; #else _stprintf(sz, _T("'%s'"), pcszStr); #endif SetCard(ci, pcszKeyword, sz, pcszComment); }
ieResult ie_fits_Writer::WriteImageX(ieImage *pim, PCTCHAR pcszSubFormat, ieClrFormat cfClrFormat, int iRealZ, int iCompParam, iePProgress pProgress) { DWORD nBpP = pim->fL() ? 4 : (pim->wL() ? 2 : (pim->L() ? 1 : 0)); if (!nBpP) return IE_E_INVALIDPARAM; // Write Primary HDU CardImage cis[CardsPerRecord]; memset(cis, int(' '), sizeof(cis)); // Fill with blanks CardImage *pci = cis; SetCard(*pci++, "SIMPLE", "T", "Standard FITS file"); SetCardInt(*pci++, "BITPIX", (nBpP == 4) ? -32 : (nBpP * 8), "No. of bits per pixel"); SetCardInt(*pci++, "NAXIS", 2, "No. of axes in matrix"); SetCardInt(*pci++, "NAXIS1", pim->X(), "No. of pixels in X"); SetCardInt(*pci++, "NAXIS2", pim->Y(), "No. of pixels in Y"); PCTCHAR pcsz; if (pim->Text()->Have(ieTextInfoType::Name)) { pcsz = pim->Text()->Get(ieTextInfoType::Name); SetCardStr(*pci++, "OBJECT", pcsz); } if (pim->Text()->Have(ieTextInfoType::Author)) { pcsz = pim->Text()->Get(ieTextInfoType::Author); SetCardStr(*pci++, "AUTHOR", pcsz); } if (pim->Text()->Have(ieTextInfoType::Source)) { pcsz = pim->Text()->Get(ieTextInfoType::Source); SetCardStr(*pci++, "OBSERVER", pcsz); } if (pim->Text()->Have(ieTextInfoType::CreationDate)) { pcsz = pim->Text()->Get(ieTextInfoType::CreationDate); SetCardStr(*pci++, "DATE", pcsz); } if (pim->Text()->Have(ieTextInfoType::Comment)) { pcsz = pim->Text()->Get(ieTextInfoType::Comment); #ifdef UNICODE ie_UnicodeToLatin1(&pci->cValueIndicator, pcsz, 71); #else memcpy(&pci->cValueIndicator, pcsz, min(71, _tcslen(pcsz))); #endif SetCard(*pci++, "COMMENT"); } SetCard(*pci++, "END"); ief_Write(hf, cis, sizeof(cis)); // Write Primary Data Array DWORD nSrcBpL = pim->Pitch() * nBpP; PBYTE pbSrc = pim->RawPixelPtr() + pim->Y()*nSrcBpL; PBYTE pbBuf = nullptr; DWORD nDstBpL = pim->X() * nBpP; if (nBpP > 1) { pbBuf = new BYTE[nDstBpL]; if (!pbBuf) return IE_E_OUTOFMEMORY; } for (DWORD yc = pim->Y(); yc--; ) { pbSrc -= nSrcBpL; if (nBpP == 1) { pbBuf = pbSrc; } else if (nBpP == 2) { ie_SetWords2BSSWords(PSWORD(pbBuf), PCWORD(pbSrc), pim->X()); } else if (nBpP == 4) { ie_SetFloats((float *)pbBuf, iePCfL(pbSrc), pim->X(), 1, true); } ief_Write(hf, pbBuf, nDstBpL); } if (nBpP > 1) { delete [] pbBuf; } return IE_S_OK; }
static void SetCardInt(CardImage &ci, const char *pcszKeyword, int nValue, const char *pcszComment = nullptr) { char sz[32]; sprintf(sz, "%d", nValue); SetCard(ci, pcszKeyword, sz, pcszComment); }
bool cSmartCardVideoGuard2::Init(void) { static const unsigned char vg2Hist[] = { 'i',0xff,'J','P' }; if(atr->histLen<4 || memcmp(&atr->hist[3],vg2Hist,4)) { PRINTF(L_SC_INIT,"doesn't look like a VideoGuard2 card"); return false; } infoStr.Begin(); infoStr.Strcat("VideoGuard2 smartcard\n"); snprintf(idStr,sizeof(idStr),"%s (%c%c.%d)",SC_NAME,atr->hist[10],atr->hist[11],atr->hist[12]); ResetIdSet(); delete cmdList; cmdList=0; static unsigned char ins7401[] = { 0xD0,0x74,0x01,0x00,0x00 }; int l; if((l=ReadCmdLen(ins7401))<0) { PRINTF(L_SC_ERROR,"bogus answer. Now try delayed mode"); NewCardConfig(&cardCfgDelay); if((l=ReadCmdLen(ins7401))<0) return false; } ins7401[4]=l; unsigned char buff[256]; if(!IsoRead(ins7401,buff) || !Status()) { PRINTF(L_SC_ERROR,"failed to read cmd list"); return false; } cmdList=new CmdTable(buff,l); static const unsigned char ins7416[5] = { 0xD0,0x74,0x16,0x00,0x00 }; if(DoCmd(ins7416)<0 || !Status()) { PRINTF(L_SC_ERROR,"cmd 7416 failed"); return false; } static const unsigned char ins36[5] = { 0xD0,0x36,0x00,0x00,0x00 }; bool boxidOK=false; if((l=DoCmd(ins36,0,buff))>0 && Status()) for(int i=0; i<l ;i++) { if(buff[i]==0x00 && buff[i+1]==0xF3) { memcpy(&boxID,&buff[i+2],sizeof(boxID)); boxidOK=true; break; } } if(!boxidOK) { cSmartCardDataVideoGuard2 cd(dtBoxId); cSmartCardDataVideoGuard2 *entry=(cSmartCardDataVideoGuard2 *)smartcards.FindCardData(&cd); if(entry) { memcpy(&boxID,entry->boxid,sizeof(boxID)); boxidOK=true; } } if(!boxidOK) { PRINTF(L_SC_ERROR,"no boxID available"); return false; } static const unsigned char ins4C[5] = { 0xD0,0x4C,0x00,0x00,0x00 }; static unsigned char payload4C[9] = { 0,0,0,0, 3,0,0,2,4 }; memcpy(payload4C,boxID,4); if(DoCmd(ins4C,payload4C)<0 || !Status()) { PRINTF(L_SC_ERROR,"sending boxid failed"); return false; } static const unsigned char ins58[5] = { 0xD0,0x58,0x00,0x00,0x00 }; if(DoCmd(ins58,0,buff)<0 || !Status()) { PRINTF(L_SC_ERROR,"failed to read card details"); return false; } unsigned int c=WORD(buff,0x1D,0xFFFF); if(c!=CAID) CaidsChanged(); CAID=c; memcpy(&cardID,&buff[8],4); memcpy(&groupID,&buff[8],4); groupID[3]=0; SetCard(new cCardNDS(cardID)); AddProv(new cProviderNDS(groupID)); char str[20], str2[20]; infoStr.Printf("Cardtype: %c%c.%d\n" "BoxID %s Caid %04x CardID %s\n", atr->hist[10],atr->hist[11],atr->hist[12],HexStr(str,boxID,4),CAID,HexStr(str2,cardID,4)); PRINTF(L_SC_INIT,"cardtype: %c%c.%d boxID %s caid %04x cardID %s",atr->hist[10],atr->hist[11],atr->hist[12],HexStr(str,boxID,4),CAID,HexStr(str2,cardID,4)); cSmartCardDataVideoGuard2 cd(dtSeed); cSmartCardDataVideoGuard2 *entry=(cSmartCardDataVideoGuard2 *)smartcards.FindCardData(&cd); if(!entry) { PRINTF(L_SC_ERROR,"no NDS seed available"); return false; } state.SetSeed(entry->seed0,entry->seed1); unsigned char tbuff[64]; state.GetCamKey(tbuff); static const unsigned char insB4[5] = { 0xD0,0xB4,0x00,0x00,0x00 }; if(DoCmd(insB4,tbuff)<0 || !Status()) { PRINTF(L_SC_ERROR,"cmd D0B4 failed"); return false; } static const unsigned char insBC[5] = { 0xD0,0xBC,0x00,0x00,0x00 }; if(DoCmd(insBC)<0 || !Status()) { PRINTF(L_SC_ERROR,"cmd D0BC failed"); return false; } static const unsigned char insBE[5] = { 0xD3,0xBE,0x00,0x00,0x00 }; if(DoCmd(insBE)<0 || !Status()) { PRINTF(L_SC_ERROR,"cmd D3BE failed"); return false; } static const unsigned char ins58a[5] = { 0xD1,0x58,0x00,0x00,0x00 }; if(DoCmd(ins58a)<0 || !Status()) { PRINTF(L_SC_ERROR,"cmd D158 failed"); return false; } static const unsigned char ins4Ca[5] = { 0xD1,0x4C,0x00,0x00,0x00 }; if(DoCmd(ins4Ca,payload4C)<0 || !Status()) { PRINTF(L_SC_ERROR,"cmd D14C failed"); return false; } ReadTiers(); return true; }
bool cSmartCardNagra::Init(void) { block=0; isTiger=isT14Nagra=isN3=swapCW=false; caid=SYSTEM_NAGRA; ResetIdSet(); static const unsigned char atrDNASP[] = { 'D','N','A','S','P' }; static const unsigned char atrTIGER[] = { 'T','I','G','E','R' }; static const unsigned char atrNCMED[] = { 'N','C','M','E','D' }; static const unsigned char atrIRDET[] = { 'I','R','D','E','T','O' }; if(!memcmp(atr->hist,atrDNASP,sizeof(atrDNASP))) { if(atr->hist[5]=='2' && atr->hist[6]=='4') isN3=true; PRINTF(L_SC_INIT,"detected native T1 nagra card (N%d Mode)",isN3?3:2); if(!SetIFS(0xFE)) return false; memcpy(rominfo,atr->hist,sizeof(rominfo)); } else if(!memcmp(atr->hist,atrTIGER,sizeof(atrTIGER)) || !memcmp(atr->hist,atrNCMED,sizeof(atrNCMED))) { PRINTF(L_SC_INIT,"detected nagra tiger card"); if(!SetIFS(0xFE)) return false; memcpy(rominfo,atr->hist,sizeof(rominfo)); cardId=0xFFFFFFFF; isTiger=true; } else if(!memcmp(atr->hist,atrIRDET,sizeof(atrIRDET))) { PRINTF(L_SC_INIT,"detected tunneled T14 nagra card"); if(!allowT14) { PRINTF(L_SC_INIT,"Nagra mode for T14 card disabled in setup"); return false; } PRINTF(L_SC_INIT,"using nagra mode"); isT14Nagra=true; if(!DoBlkCmd(0x10,0x02,0x90,0x11)) { PRINTF(L_SC_ERROR,"get rom version failed"); return false; } memcpy(rominfo,&buff[2],15); } else { PRINTF(L_SC_INIT,"doesn't look like a nagra card"); return false; } infoStr.Begin(); infoStr.Strcat("Nagra smartcard\n"); char rom[12], rev[12]; snprintf(rom,sizeof(rom),"%c%c%c%c%c%c%c%c",rominfo[0],rominfo[1],rominfo[2],rominfo[3],rominfo[4],rominfo[5],rominfo[6],rominfo[7]); snprintf(rev,sizeof(rev),"%c%c%c%c%c%c",rominfo[9],rominfo[10],rominfo[11],rominfo[12],rominfo[13],rominfo[14]); PRINTF(L_SC_INIT,"rom version: %s revision: %s",rom,rev); infoStr.Printf("Rom %s Rev %s\n",rom,rev); if(!isTiger) { GetCardStatus(); if(!DoBlkCmd(0x12,0x02,0x92,0x06) || !Status()) return false; cardId=UINT32_BE(buff+5); SetCard(new cCardNagra2(buff+5)); if(!GetDataType(DT01,0x0E)) return false; GetCardStatus(); if(!GetDataType(IRDINFO,0x39)) return false; GetCardStatus(); if(!GetDataType(CAMDATA,0x55)) return false; GetCardStatus(); if(!GetDataType(DT04,0x44)) return false; GetCardStatus(); if(memcmp(rominfo+5,"181",3)!=0) { // not working on ROM181 infoStr.Printf("Tiers\n"); infoStr.Printf("|id |chid| dates |\n"); infoStr.Printf("+----+----+---------------------+\n"); if(!GetDataType(TIERS,0x57)) return false; GetCardStatus(); } if(!GetDataType(DT06,0x16)) return false; GetCardStatus(); } if(!HasCamMod()) { cSmartCardDataNagra cd(cardId,false); cSmartCardDataNagra *entry=(cSmartCardDataNagra *)smartcards.FindCardData(&cd); if(entry) { SetCardData(cardId,entry->bk,entry->exp); SetCamMod(entry->mod); } else { PRINTF(L_SC_ERROR,"can't find CARD modulus"); return false; } } if(!DoCamExchange()) return false; infoStr.Finish(); return true; }