📄 nagra2-0101.c
字号:
/* * Softcam plugin to VDR (C++) * * This code is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This code is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * Or, point your browser to http://www.gnu.org/copyleft/gpl.html */#include <stdio.h>#include <stdlib.h>#include <string.h>#include "nagra2.h"// -- cAuxSrv ------------------------------------------------------------------#ifdef HAS_AUXSRV#include "network.h"#define AUX_PROTOCOL_VERSION 2int auxEnabled=0;int auxPort=7777;char auxAddr[80]="localhost";char auxPassword[250]="auxserver";class cAuxSrv : public cMutex {private: cNetSocket so; // bool Login(void);public: cAuxSrv(void); int Map(int map, unsigned char *data, int len, int outlen); };cAuxSrv::cAuxSrv(void):so(DEFAULT_CONNECT_TIMEOUT,7,DEFAULT_IDLE_TIMEOUT){}bool cAuxSrv::Login(){ unsigned char buff[256]; PRINTF(L_SYS_MAP,"auxsrv: connecting to %s:%d",auxAddr,auxPort); if(so.Connect(auxAddr,auxPort)) { buff[0]=0xA7; buff[1]=0x7A; buff[2]=0; int l=strlen(auxPassword); buff[3]=l; memcpy(&buff[4],auxPassword,l); buff[4+l]=0xFF; if(so.Write(buff,l+5)==l+5 && so.Read(buff,sizeof(buff))>=9 && buff[0]==0x7A && buff[1]==0xA7 && buff[2]==0x00 && buff[3]==0x04 && buff[8]==0xff && ((buff[4]<<8)|buff[5])==AUX_PROTOCOL_VERSION) return true; PRINTF(L_SYS_MAP,"auxsrv: login write failed"); } so.Disconnect(); return false;}int cAuxSrv::Map(int map, unsigned char *data, int len, int outlen){ if(!auxEnabled) { PRINTF(L_SYS_MAP,"auxsrv: AUXserver is disabled!"); return -1; } if(len>500 || outlen>500) return -1; cMutexLock lock(this); if(!so.Connected() && !Login()) return false; PRINTF(L_SYS_MAP,"auxsrv: calling map%02x",map); unsigned char buff[512]; buff[0]=0xA7; buff[1]=0x7A; buff[2]=((len+1)>>8) & 0xff; buff[3]=(len+1)&0xff; buff[4]=map; memcpy(&buff[5],data,len); buff[len+5]=0xFF; if(so.Write(buff,len+6)==len+6) { if((len=so.Read(buff,sizeof(buff)))>0) { if(buff[0]==0x7A && buff[1]==0xA7) { if(buff[4]==0x00) { int cycles=(buff[5]<<16)|(buff[6]<<8)|buff[7]; int l=buff[2]*256+buff[3]; if(len>=l+5 && l==outlen+4) { if(buff[l+4]==0xFF) { memcpy(data,buff+8,outlen); return cycles; } else PRINTF(L_SYS_MAP,"auxsrv: bad footer in map%02x response",map); } else PRINTF(L_SYS_MAP,"auxsrv: bad length in map%02x response (got=%d,%d want=%d,%d)",map,l-4,len,outlen,l+8); } else PRINTF(L_SYS_MAP,"auxsrv: map%02x not successfull (unsupported?)",map); } else PRINTF(L_SYS_MAP,"auxsrv: bad response to map%02x",map); } else PRINTF(L_SYS_MAP,"auxsrv: map%02x read failed",map); } else PRINTF(L_SYS_MAP,"auxsrv: map%02x write failed",map); so.Disconnect(); return -1;}#endif //HAS_AUXSRV// -- cMap0101 ----------------------------------------------------------------class cMap0101 : public cMapCore {private: static const unsigned char primes[]; static const unsigned short coef22[][32];#ifdef HAS_AUXSRV cAuxSrv aux;#endif // void MakePrime(BIGNUM *n, unsigned char *residues);protected: void DoMap(int f, unsigned char *data=0, int l=0); };const unsigned char cMap0101::primes[] = { 0x03,0x05,0x07,0x0B,0x0D,0x11,0x13,0x17,0x1D,0x1F,0x25,0x29,0x2B,0x2F,0x35,0x3B, 0x3D,0x43,0x47,0x49,0x4F,0x53,0x59,0x61,0x65,0x67,0x6B,0x6D,0x71,0x7F,0x83,0x89, 0x8B,0x95,0x97,0x9D,0xA3,0xA7,0xAD,0xB3,0xB5,0xBF,0xC1,0xC5,0xC7,0xD3,0xDF,0xE3, 0xE5,0xE9,0xEF,0xF1,0xFB };const unsigned short cMap0101::coef22[256][32] = { {0,1,1,0,1,0,1,1,0,11,10,11,10,10,11,10,11,21,22,22,21,22,21,22,22,32,33,32,33,33,32,33}, {3,1,0,1,1,0,1,0,1,10,11,11,10,11,10,11,11,21,22,21,22,22,21,22,21,33,33,33,33,32,33,33}, {5,1,0,1,1,0,1,0,1,10,11,11,10,11,10,11,11,21,22,21,22,22,21,22,21,33,33,33,33,32,33,33}, {7,1,1,1,0,1,1,1,1,10,11,10,11,11,10,11,10,22,22,22,22,21,22,22,22,33,32,33,33,33,33,32}, {9,1,1,1,0,1,1,1,1,10,11,10,11,11,10,11,10,22,22,22,22,21,22,22,22,33,32,33,33,33,33,32}, {12,0,1,1,1,1,0,1,1,11,11,11,11,10,11,11,11,22,21,22,22,22,22,21,22,33,33,33,34,33,33,33}, {14,0,1,1,1,1,0,1,1,11,11,11,11,10,11,11,11,22,21,22,22,22,22,21,22,33,33,33,34,33,33,33}, {16,1,1,2,1,1,1,1,2,11,10,11,11,11,11,10,11,22,22,22,23,22,22,22,22,34,33,33,33,33,34,33}, {0,1,1,2,1,1,1,1,2,11,10,11,11,11,11,10,11,22,22,22,23,22,22,22,22,34,33,33,33,33,34,33}, {3,1,1,1,1,2,1,1,1,11,11,11,12,11,11,11,11,23,22,22,22,22,23,22,22,33,33,34,33,34,33,33}, {5,1,1,1,1,2,1,1,1,11,11,11,12,11,11,11,11,23,22,22,22,22,23,22,22,33,33,34,33,34,33,33}, {7,1,2,1,2,1,1,2,1,12,11,11,11,11,12,11,11,22,22,23,22,23,22,22,23,33,34,33,33,34,33,34}, {9,1,2,1,2,1,1,2,1,12,11,11,11,11,12,11,11,22,22,23,22,23,22,22,23,33,34,33,33,34,33,34}, {12,2,1,1,2,1,2,1,1,11,11,12,11,12,11,11,12,22,23,22,22,23,22,23,22,34,34,33,34,33,34,34}, {14,2,1,1,2,1,2,1,1,11,11,12,11,12,11,11,12,22,23,22,22,23,22,23,22,34,34,33,34,33,34,34}, {16,2,1,2,1,2,2,1,2,11,12,11,11,12,11,12,11,23,23,22,23,22,23,23,22,34,33,34,34,33,34,33}, {0,2,1,2,1,2,2,1,2,11,12,11,11,12,11,12,11,23,23,22,23,22,23,23,22,34,33,34,34,33,34,33}, {3,1,2,2,1,2,1,2,2,12,12,11,12,11,12,12,11,23,22,23,23,22,23,22,23,34,34,34,33,34,34,34}, {5,1,2,2,1,2,1,2,2,12,12,11,12,11,12,12,11,23,22,23,23,22,23,22,23,34,34,34,33,34,34,34}, {7,2,2,1,2,2,2,2,1,12,11,12,12,11,12,11,12,23,23,23,22,23,23,23,23,33,34,34,34,34,33,34}, {9,2,2,1,2,2,2,2,1,12,11,12,12,11,12,11,12,23,23,23,22,23,23,23,23,33,34,34,34,34,33,34}, {12,2,2,2,2,1,2,2,2,12,12,12,11,12,12,12,12,22,23,23,23,23,22,23,23,34,34,35,34,34,34,34}, {14,2,2,2,2,1,2,2,2,12,12,12,11,12,12,12,12,22,23,23,23,23,22,23,23,34,34,35,34,34,34,34}, {16,2,3,2,2,2,2,3,2,11,12,12,12,12,11,12,12,23,23,24,23,23,23,23,24,34,34,34,34,35,34,34}, {0,2,3,2,2,2,2,3,2,11,12,12,12,12,11,12,12,23,23,24,23,23,23,23,24,34,34,34,34,35,34,34}, {3,2,2,2,3,2,2,2,2,12,12,13,12,12,12,12,13,23,23,23,23,24,23,23,23,34,35,34,35,34,34,35}, {5,2,2,2,3,2,2,2,2,12,12,13,12,12,12,12,13,23,23,23,23,24,23,23,23,34,35,34,35,34,34,35}, {7,3,2,3,2,2,3,2,3,12,12,12,12,13,12,12,12,23,24,23,24,23,23,24,23,35,34,34,35,34,35,34}, {9,3,2,3,2,2,3,2,3,12,12,12,12,13,12,12,12,23,24,23,24,23,23,24,23,35,34,34,35,34,35,34}, {12,2,2,3,2,3,2,2,3,12,13,12,13,12,12,13,12,24,23,23,24,23,24,23,23,35,34,35,34,35,35,34}, {14,2,2,3,2,3,2,2,3,12,13,12,13,12,12,13,12,24,23,23,24,23,24,23,23,35,34,35,34,35,35,34}, {16,2,3,2,3,3,2,3,2,13,12,12,13,12,13,12,12,24,23,24,23,24,24,23,24,34,35,35,34,35,34,35}, {0,2,3,2,3,3,2,3,2,13,12,12,13,12,13,12,12,24,23,24,23,24,24,23,24,34,35,35,34,35,34,35}, {3,3,3,2,3,2,3,3,2,13,12,13,12,13,13,12,13,23,24,24,23,24,23,24,24,35,35,34,35,35,35,35}, {5,3,3,2,3,2,3,3,2,13,12,13,12,13,13,12,13,23,24,24,23,24,23,24,24,35,35,34,35,35,35,35}, {7,3,2,3,3,3,3,2,3,12,13,13,12,13,12,13,13,24,24,23,24,24,24,24,23,35,35,35,35,34,35,35}, {9,3,2,3,3,3,3,2,3,12,13,13,12,13,12,13,13,24,24,23,24,24,24,24,23,35,35,35,35,34,35,35}, {12,3,3,3,2,3,3,3,3,13,13,12,13,13,13,13,12,24,24,24,24,23,24,24,24,35,36,35,35,35,35,36}, {14,3,3,3,2,3,3,3,3,13,13,12,13,13,13,13,12,24,24,24,24,23,24,24,24,35,36,35,35,35,35,36}, {16,4,3,3,3,3,4,3,3,13,13,13,13,12,13,13,13,24,25,24,24,24,24,25,24,35,35,35,36,35,35,35}, {0,4,3,3,3,3,4,3,3,13,13,13,13,12,13,13,13,24,25,24,24,24,24,25,24,35,35,35,36,35,35,35}, {3,3,3,4,3,3,3,3,4,13,14,13,13,13,13,14,13,24,24,24,25,24,24,24,24,36,35,36,35,35,36,35}, {5,3,3,4,3,3,3,3,4,13,14,13,13,13,13,14,13,24,24,24,25,24,24,24,24,36,35,36,35,35,36,35}, {7,3,4,3,3,4,3,4,3,13,13,13,14,13,13,13,13,25,24,25,24,24,25,24,25,35,35,36,35,36,35,35}, {9,3,4,3,3,4,3,4,3,13,13,13,14,13,13,13,13,25,24,25,24,24,25,24,25,35,35,36,35,36,35,35}, {12,3,4,3,4,3,3,4,3,14,13,14,13,13,14,13,14,24,24,25,24,25,24,24,25,35,36,35,36,36,35,36}, {14,3,4,3,4,3,3,4,3,14,13,14,13,13,14,13,14,24,24,25,24,25,24,24,25,35,36,35,36,36,35,36}, {16,4,3,4,4,3,4,3,4,13,13,14,13,14,13,13,14,24,25,24,25,25,24,25,24,36,36,35,36,35,36,36}, {0,4,3,4,4,3,4,3,4,13,13,14,13,14,13,13,14,24,25,24,25,25,24,25,24,36,36,35,36,35,36,36}, {3,4,3,4,3,4,4,3,4,13,14,13,14,14,13,14,13,25,25,24,25,24,25,25,24,36,35,36,36,36,36,35}, {5,4,3,4,3,4,4,3,4,13,14,13,14,14,13,14,13,25,25,24,25,24,25,25,24,36,35,36,36,36,36,35}, {7,3,4,4,4,4,3,4,4,14,14,13,14,13,14,14,13,25,24,25,25,25,25,24,25,36,36,36,35,36,36,36}, {9,3,4,4,4,4,3,4,4,14,14,13,14,13,14,14,13,25,24,25,25,25,25,24,25,36,36,36,35,36,36,36}, {12,4,4,3,4,4,4,4,3,14,13,14,14,14,14,13,14,25,25,25,24,25,25,25,25,37,36,36,36,36,37,36}, {14,4,4,3,4,4,4,4,3,14,13,14,14,14,14,13,14,25,25,25,24,25,25,25,25,37,36,36,36,36,37,36}, {16,4,4,4,4,5,4,4,4,14,14,14,13,14,14,14,14,26,25,25,25,25,26,25,25,36,36,37,36,36,36,36}, {0,4,4,4,4,5,4,4,4,14,14,14,13,14,14,14,14,26,25,25,25,25,26,25,25,36,36,37,36,36,36,36}, {3,4,5,4,4,4,4,5,4,15,14,14,14,14,15,14,14,25,25,26,25,25,25,25,26,36,37,36,36,37,36,37}, {5,4,5,4,4,4,4,5,4,15,14,14,14,14,15,14,14,25,25,26,25,25,25,25,37,36,37,36,36,37,36,37}, {7,5,4,4,5,4,5,4,4,14,14,15,14,14,14,14,15,25,26,25,25,26,25,26,36,36,37,36,37,36,36,37}, {9,5,4,4,5,4,5,4,4,14,14,15,14,14,14,14,26,25,26,25,25,26,25,26,36,36,37,36,37,36,36,37}, {12,5,4,5,4,4,5,4,5,14,15,14,14,15,14,15,25,25,26,25,26,25,25,26,36,37,36,37,37,36,37,36}, {14,5,4,5,4,4,5,4,15,14,15,14,14,15,14,15,25,25,26,25,26,25,25,26,36,37,36,37,37,36,37,36}, {16,4,5,5,4,5,4,5,14,14,15,14,15,14,14,15,25,26,25,26,26,25,26,25,37,37,36,37,36,37,37,36}, {40,4,5,5,4,5,4,5,14,14,15,14,15,14,14,15,25,26,25,26,26,25,26,25,37,37,36,37,36,37,37,36}, {44,4,5,4,5,5,4,5,14,15,14,15,15,14,15,14,26,26,25,26,25,26,26,25,37,36,37,37,37,37,36,37}, {44,4,5,4,5,5,4,5,14,15,14,15,15,14,15,14,26,26,25,26,25,26,26,25,37,36,37,37,37,37,36,37}, {47,5,5,5,5,4,5,5,15,15,14,15,14,15,15,14,26,25,26,26,26,26,25,26,37,37,37,36,37,37,37,37}, {47,5,5,5,5,4,5,5,15,15,14,15,14,15,15,14,26,25,26,26,26,26,25,26,37,37,37,36,37,37,37,37}, {52,5,4,5,5,5,5,4,15,14,15,15,15,15,14,15,26,26,26,25,26,26,26,26,38,37,37,37,37,38,37,37}, {52,5,4,5,5,5,5,4,15,14,15,15,15,15,14,15,26,26,26,25,26,26,26,26,38,37,37,37,37,38,37,37}, {56,5,5,5,6,5,5,5,15,15,15,14,15,15,15,15,27,26,26,26,26,27,26,26,37,37,38,37,37,37,37,38}, {56,5,5,5,6,5,5,5,15,15,15,14,15,15,15,15,27,26,26,26,26,27,26,26,37,37,38,37,37,37,37,38}, {60,6,5,5,5,5,6,5,16,15,15,15,15,16,15,15,26,26,27,26,26,26,26,27,37,38,37,37,38,37,38,37}, {60,6,5,5,5,5,6,5,16,15,15,15,15,16,15,15,26,26,27,26,26,26,26,27,37,38,37,37,38,37,38,37}, {65,5,5,6,5,6,5,5,15,15,16,15,15,15,15,16,26,27,26,26,27,26,27,26,37,38,37,38,37,37,38,37}, {65,5,5,6,5,6,5,5,15,15,16,15,15,15,15,16,26,27,26,26,27,26,27,26,37,38,37,38,37,37,38,37}, {69,5,6,5,5,6,5,6,15,16,15,15,16,15,16,15,26,27,26,27,26,26,27,26,38,37,38,38,37,38,37,38}, {69,5,6,5,5,6,5,6,15,16,15,15,16,15,16,15,26,27,26,27,26,26,27,26,38,37,38,38,37,38,37,38}, {72,6,6,5,6,5,6,6,15,16,15,16,15,15,16,15,27,26,27,27,26,27,26,27,38,37,38,37,38,38,37,38}, {72,6,6,5,6,5,6,6,15,16,15,16,15,15,16,15,27,26,27,27,26,27,26,27,38,37,38,37,38,38,37,38}, {76,6,5,6,6,5,6,5,16,15,16,16,15,16,15,16,27,26,27,26,27,27,26,27,37,38,38,38,38,37,38,38}, {76,6,5,6,6,5,6,5,16,15,16,16,15,16,15,16,27,26,27,26,27,27,26,27,37,38,38,38,38,37,38,38}, {81,6,6,6,5,6,6,6,16,15,16,15,16,16,15,16,26,27,27,27,27,26,27,27,38,38,37,38,38,38,38,37}, {81,6,6,6,5,6,6,6,16,15,16,15,16,16,15,16,26,27,27,27,27,26,27,27,38,38,37,38,38,38,38,37}, {85,5,6,6,6,6,5,6,15,16,16,16,16,15,16,16,27,27,26,27,27,27,27,26,38,38,38,38,39,38,38,38}, {85,5,6,6,6,6,5,6,15,16,16,16,16,15,16,16,27,27,26,27,27,27,27,26,38,38,38,38,39,38,38,38}, {89,6,6,7,6,6,6,6,16,16,15,16,16,16,16,15,27,27,27,27,28,27,27,27,38,39,38,38,38,38,39,38}, {89,6,6,7,6,6,6,6,16,16,15,16,16,16,16,15,27,27,27,27,28,27,27,27,38,39,38,38,38,38,39,38}, {94,6,6,6,6,7,6,6,16,16,16,16,17,16,16,16,27,28,27,27,27,27,28,27,39,38,38,39,38,39,38,38}, {94,6,6,6,6,7,6,6,16,16,16,16,17,16,16,16,27,28,27,27,27,27,28,27,39,38,38,39,38,39,38,38}, {97,6,7,6,7,6,6,7,16,17,16,16,16,16,17,16,28,27,27,28,27,28,27,27,39,38,39,38,38,39,38,39}, {97,6,7,6,7,6,6,7,16,17,16,16,16,16,17,16,28,27,27,28,27,28,27,27,39,38,39,38,38,39,38,39}, {101,7,6,6,7,6,7,6,17,16,16,17,16,17,16,16,28,27,28,27,27,28,27,28,38,39,39,38,39,38,39,39}, {101,7,6,6,7,6,7,6,17,16,16,17,16,17,16,16,28,27,28,27,27,28,27,28,38,39,39,38,39,38,39,39}, {106,7,6,7,6,7,7,6,17,16,17,16,16,17,16,17,27,28,28,27,28,27,28,28,38,39,38,39,39,38,39,38}, {106,7,6,7,6,7,7,6,17,16,17,16,16,17,16,17,27,28,28,27,28,27,28,28,38,39,38,39,39,38,39,38}, {110,6,7,7,6,7,6,7,16,17,17,16,17,16,17,17,27,28,27,28,28,27,28,27,39,39,39,39,38,39,39,39}, {110,6,7,7,6,7,6,7,16,17,17,16,17,16,17,17,27,28,27,28,28,27,28,27,39,39,39,39,38,39,39,39}, {114,7,7,6,7,7,7,7,16,17,16,17,17,16,17,16,28,28,28,28,27,28,28,28,39,38,39,39,39,39,38,39}, {114,7,7,6,7,7,7,7,16,17,16,17,17,16,17,16,28,28,28,28,27,28,28,28,39,38,39,39,39,39,38,39}, {117,7,7,7,7,6,7,7,17,17,17,17,16,17,17,17,28,27,28,28,28,28,27,28,39,39,39,40,39,39,39,39}, {117,7,7,7,7,6,7,7,17,17,17,17,16,17,17,17,28,27,28,28,28,28,27,28,39,39,39,40,39,39,39,39}, {122,7,8,7,7,7,7,8,17,16,17,17,17,17,16,17,28,28,28,29,28,28,28,28,40,39,39,39,39,40,39,39}, {122,7,8,7,7,7,7,8,17,16,17,17,17,17,16,17,28,28,28,29,28,28,28,28,40,39,39,39,39,40,39,39}, {126,7,7,7,8,7,7,7,17,17,17,18,17,17,17,17,29,28,28,28,28,29,28,28,39,39,40,39,40,39,39,40}, {126,7,7,7,8,7,7,7,17,17,17,18,17,17,17,17,29,28,28,28,28,29,28,28,39,39,40,39,40,39,39,40}, {130,8,7,8,7,7,8,7,18,17,17,17,17,18,17,17,28,28,29,28,29,28,28,29,39,40,39,39,40,39,40,39}, {130,8,7,8,7,7,8,7,18,17,17,17,17,18,17,17,28,28,29,28,29,28,28,29,39,40,39,39,40,39,40,39}, {135,7,7,8,7,8,7,7,17,17,18,17,18,17,17,18,28,29,28,28,29,28,29,28,40,40,39,40,39,40,40,39}, {135,7,7,8,7,8,7,7,17,17,18,17,18,17,17,18,28,29,28,28,29,28,29,28,40,40,39,40,39,40,40,39}, {139,7,8,7,8,8,7,8,17,18,17,17,18,17,18,17,29,29,28,29,28,29,29,28,40,39,40,40,39,40,39,40}, {139,7,8,7,8,8,7,8,17,18,17,17,18,17,18,17,29,29,28,29,28,29,29,28,40,39,40,40,39,40,39,40}, {142,8,8,7,8,7,8,8,18,18,17,18,17,18,18,17,29,28,29,29,28,29,28,29,40,40,40,39,40,40,40,40}, {142,8,8,7,8,7,8,8,18,18,17,18,17,18,18,17,29,28,29,29,28,29,28,29,40,40,40,39,40,40,40,40}, {147,8,7,8,8,8,8,7,18,17,18,18,17,18,17,18,29,29,29,28,29,29,29,29,39,40,40,40,40,39,40,40}, {147,8,7,8,8,8,8,7,18,17,18,18,17,18,17,18,29,29,29,28,29,29,29,29,39,40,40,40,40,39,40,40}, {151,8,8,8,7,8,8,8,18,18,18,17,18,18,18,18,28,29,29,29,29,28,29,29,40,40,41,40,40,40,40,41}, {151,8,8,8,7,8,8,8,18,18,18,17,18,18,18,18,28,29,29,29,29,28,29,29,40,40,41,40,40,40,40,41}, {155,9,8,8,8,8,9,8,17,18,18,18,18,17,18,18,29,29,30,29,29,29,29,30,40,40,40,40,41,40,40,40},
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -