From bea8ed60e9fdbb5c46b439661f3f915755aa9f0f Mon Sep 17 00:00:00 2001 From: leslie Date: Tue, 14 Oct 2008 20:37:30 +0800 Subject: [PATCH] add fake PW NDS support (needs flash file) --- systems/nds/log-nds.h | 23 +++++++++ systems/nds/nds.c | 29 +++++++++++ systems/nds/nds.h | 21 ++++++++ systems/nds/nds.mk | 6 +++ systems/nds/pw-nds.c | 117 ++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 196 insertions(+) create mode 100644 systems/nds/log-nds.h create mode 100644 systems/nds/nds.c create mode 100644 systems/nds/nds.h create mode 100644 systems/nds/nds.mk create mode 100644 systems/nds/pw-nds.c diff --git a/systems/nds/log-nds.h b/systems/nds/log-nds.h new file mode 100644 index 0000000..793af59 --- /dev/null +++ b/systems/nds/log-nds.h @@ -0,0 +1,23 @@ +/* + * 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 "log-sys.h" + +#define L_SYS 18 +#define L_SYS_ALL LALL(L_SYS_LASTDEF) diff --git a/systems/nds/nds.c b/systems/nds/nds.c new file mode 100644 index 0000000..0d04ed0 --- /dev/null +++ b/systems/nds/nds.c @@ -0,0 +1,29 @@ +/* + * 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 "nds.h" +#include "log-nds.h" + +static const struct LogModule lm_sys = { + (LMOD_ENABLE|L_SYS_ALL)&LOPT_MASK, + (LMOD_ENABLE|L_SYS_DEFDEF)&LOPT_MASK, + "nds", + { L_SYS_DEFNAMES } + }; +ADD_MODULE(L_SYS,lm_sys) diff --git a/systems/nds/nds.h b/systems/nds/nds.h new file mode 100644 index 0000000..3d07110 --- /dev/null +++ b/systems/nds/nds.h @@ -0,0 +1,21 @@ +/* + * 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 + */ + +#define SYSTEM_NDS 0x0900 +#define FILEMAP_DOMAIN "nds" diff --git a/systems/nds/nds.mk b/systems/nds/nds.mk new file mode 100644 index 0000000..364d98c --- /dev/null +++ b/systems/nds/nds.mk @@ -0,0 +1,6 @@ +# +# Conax +# +TARGET = nds +OBJS = nds.o pw-nds.o +LIBS = -lcrypto diff --git a/systems/nds/pw-nds.c b/systems/nds/pw-nds.c new file mode 100644 index 0000000..6ae0034 --- /dev/null +++ b/systems/nds/pw-nds.c @@ -0,0 +1,117 @@ +/* + * 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 +#include + +#include + +#include "system-common.h" +#include "data.h" +#include "helper.h" + +#include "nds.h" +#include "log-nds.h" + +#define SYSTEM_NAME "PW-NDS" +#define SYSTEM_PRI -12 + +// -- cSystemPwNDS --------------------------------------------------------------- + +class cSystemPwNDS : public cSystem { +private: + cFileMap *fm; +public: + cSystemPwNDS(void); + ~cSystemPwNDS(); + virtual bool ProcessECM(const cEcmInfo *ecm, unsigned char *data); + }; + +cSystemPwNDS::cSystemPwNDS(void) +:cSystem(SYSTEM_NAME,SYSTEM_PRI) +{ + fm=0; + memset(cw,0,sizeof(cw)); +} + +cSystemPwNDS::~cSystemPwNDS() +{ + if(fm) fm->Unmap(); +} + +bool cSystemPwNDS::ProcessECM(const cEcmInfo *ecm, unsigned char *data) +{ + int len=SCT_LEN(data); + if(len<7 || data[3]!=0x00 || data[4]!=0x00 || data[5]!=0x01) { + if(doLog) PRINTF(L_SYS_ECM,"ECM format check failed"); + return false; + } + int iLen=data[6]; + if(iLen+6>len || iLen<0x1C) { + if(doLog) PRINTF(L_SYS_ECM,"IRD block length check failed"); + return false; + } + + // check cw in IRD block + if(!(data[6+9]&1) || !(data[6+10]&16)) { + if(doLog) PRINTF(L_SYS_ECM,"no CW in IRD block"); + return false; + } + + if(!fm) fm=filemaps.GetFileMap("PR-HD1000_060000.bin",FILEMAP_DOMAIN,false); + if(!fm || (!fm->Addr() && !fm->Map())) return false; + unsigned char *m=fm->Addr(); + + unsigned char md[16]; + MD5(m,fm->Size(),md); + const unsigned char app10039[] = { 0xff,0x25,0x38,0x51,0xec,0xcb,0xc8,0xfa,0xab,0x97,0x59,0x15,0x4d,0x14,0x05,0xfa }; + if(fm->Size()<0x2603c0 || memcmp(md,app10039,16)) { + if(doLog) PRINTF(L_SYS_ECM,"MD5 checksum failed on flash bin"); + return false; + } + + unsigned char hash[94]; + memcpy(&hash[0],&data[6+1],10); + memcpy(&hash[10],&data[6+23],4); + memcpy(&hash[14],m+0x22D344,64); + memcpy(&hash[78],m+0x25c620,16); + MD5(hash,94,md); + xxor(cw+((data[0]&1)<<3),8,&data[6+14],&md[8]); + return true; +} + +// -- cSystemLinkPwNDS --------------------------------------------------------- + +class cSystemLinkPwNDS : public cSystemLink { +public: + cSystemLinkPwNDS(void); + virtual bool CanHandle(unsigned short SysId); + virtual cSystem *Create(void) { return new cSystemPwNDS; } + }; + +static cSystemLinkPwNDS staticInit; + +cSystemLinkPwNDS::cSystemLinkPwNDS(void) +:cSystemLink(SYSTEM_NAME,SYSTEM_PRI) +{} + +bool cSystemLinkPwNDS::CanHandle(unsigned short SysId) +{ + return (SysId&SYSTEM_MASK)==SYSTEM_NDS; +} -- 2.39.5