├── DLLS-X64 ├── FFDecsa_064_LONG.dll ├── FFDecsa_064_LONG_C2.dll ├── FFDecsa_128_2LONG.dll └── FFDecsa_128_2LONG_C2.dll ├── FFDeCsa-1.0.2-Altx ├── FFDecsa.dll ├── FFDecsa_gcc.def ├── FFDecsa_gpp.def ├── FFdecsa.c ├── Makefile ├── README.md ├── _StartShell.cmd ├── fftable.h ├── make_dlls.sh ├── parallel_032_4char.h ├── parallel_032_4charA.h ├── parallel_032_int.h ├── parallel_064_2int.h ├── parallel_064_8char.h ├── parallel_064_8charA.h ├── parallel_064_long.h ├── parallel_064_mmx.h ├── parallel_128_16char.h ├── parallel_128_16charA.h ├── parallel_128_2long.h ├── parallel_128_2mmx.h ├── parallel_128_4int.h ├── parallel_128_sse.h ├── parallel_128_sse2.h ├── parallel_generic.h ├── parallel_std_def.h └── stream.c ├── LICENSE ├── README.md ├── Screens ├── Snipaste_2023-02-11_01-53-41.jpg └── Snipaste_2023-02-12_02-19-06.jpg └── TSDecryptGUI ├── App.config ├── App.xaml ├── App.xaml.cs ├── BenchmarkUtil.cs ├── MainWindow.xaml ├── MainWindow.xaml.cs ├── MessageUtil.cs ├── Properties ├── AssemblyInfo.cs ├── Resources.Designer.cs ├── Resources.resx ├── Settings.Designer.cs └── Settings.settings ├── TSDecrypt.cs ├── TSDecryptGUI.csproj ├── Util.cs └── satellite-dish-icon-white.ico /DLLS-X64/FFDecsa_064_LONG.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nilaoda/TSDecrypt/15a516e51ab1dfa8e2a5f3692c3634ac9ec381b3/DLLS-X64/FFDecsa_064_LONG.dll -------------------------------------------------------------------------------- /DLLS-X64/FFDecsa_064_LONG_C2.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nilaoda/TSDecrypt/15a516e51ab1dfa8e2a5f3692c3634ac9ec381b3/DLLS-X64/FFDecsa_064_LONG_C2.dll -------------------------------------------------------------------------------- /DLLS-X64/FFDecsa_128_2LONG.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nilaoda/TSDecrypt/15a516e51ab1dfa8e2a5f3692c3634ac9ec381b3/DLLS-X64/FFDecsa_128_2LONG.dll -------------------------------------------------------------------------------- /DLLS-X64/FFDecsa_128_2LONG_C2.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nilaoda/TSDecrypt/15a516e51ab1dfa8e2a5f3692c3634ac9ec381b3/DLLS-X64/FFDecsa_128_2LONG_C2.dll -------------------------------------------------------------------------------- /FFDeCsa-1.0.2-Altx/FFDecsa.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nilaoda/TSDecrypt/15a516e51ab1dfa8e2a5f3692c3634ac9ec381b3/FFDeCsa-1.0.2-Altx/FFDecsa.dll -------------------------------------------------------------------------------- /FFDeCsa-1.0.2-Altx/FFDecsa_gcc.def: -------------------------------------------------------------------------------- 1 | EXPORTS 2 | decrypt_packets = decrypt_packets@8 @1 3 | get_keyset_size = get_keyset_size@0 @2 4 | set_control_words = set_control_words@12 @3 5 | get_parallelism = get_internal_parallelism@0 @4 6 | -------------------------------------------------------------------------------- /FFDeCsa-1.0.2-Altx/FFDecsa_gpp.def: -------------------------------------------------------------------------------- 1 | EXPORTS 2 | decrypt_packets = _Z15decrypt_packetsPPhP10csa_keys_t@8 @1 3 | get_keyset_size = _Z15get_keyset_sizev@0 @2 4 | set_control_words = _Z17set_control_wordsPhS_P10csa_keys_t@12 @3 5 | get_parallelism = _Z24get_internal_parallelismv@0 @4 6 | -------------------------------------------------------------------------------- /FFDeCsa-1.0.2-Altx/FFdecsa.c: -------------------------------------------------------------------------------- 1 | /* FFdecsa -- fast decsa algorithm 2 | * 3 | * Copyright (C) 2003-2004 fatih89r 4 | * 5 | * This program is free software; you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation; either version 2 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program; if not, write to the Free Software 17 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 18 | */ 19 | 20 | 21 | #include 22 | #include 23 | #include 24 | 25 | #ifndef NULL 26 | #define NULL 0 27 | #endif 28 | 29 | // all lines containing DBG are filtered by the Makefile. 30 | // activate debug by changing the grep command there. 31 | // don't edit autogenerated files (name beginning with "_"). 32 | #define DBG 33 | 34 | #ifdef MAKE_DLL 35 | #define DOEXP __declspec(dllexport) 36 | #else 37 | #define DOEXP 38 | #endif 39 | 40 | //// parallelization stuff, large speed differences are possible 41 | // possible choices 42 | #define PARALLEL_032_4CHAR 320 43 | #define PARALLEL_032_4CHARA 321 44 | #define PARALLEL_032_INT 322 45 | #define PARALLEL_064_8CHAR 640 46 | #define PARALLEL_064_8CHARA 641 47 | #define PARALLEL_064_2INT 642 48 | #define PARALLEL_064_LONG 643 49 | #define PARALLEL_064_MMX 644 50 | #define PARALLEL_128_16CHAR 1280 51 | #define PARALLEL_128_16CHARA 1281 52 | #define PARALLEL_128_4INT 1282 53 | #define PARALLEL_128_2LONG 1283 54 | #define PARALLEL_128_2MMX 1284 55 | #define PARALLEL_128_SSE 1285 56 | #define PARALLEL_128_SSE2 1286 57 | 58 | //////// our choice //////////////// our choice //////////////// our choice //////////////// our choice //////// 59 | #ifndef PARALLEL_MODE 60 | #include "tmp_ffmode.h" 61 | //#define PARALLEL_MODE PARALLEL_032_INT 62 | #endif 63 | //////// our choice //////////////// our choice //////////////// our choice //////////////// our choice //////// 64 | 65 | #include "parallel_generic.h" 66 | //// conditionals 67 | #if PARALLEL_MODE==PARALLEL_032_4CHAR 68 | #include "parallel_032_4char.h" 69 | #elif PARALLEL_MODE==PARALLEL_032_4CHARA 70 | #include "parallel_032_4charA.h" 71 | #elif PARALLEL_MODE==PARALLEL_032_INT 72 | #include "parallel_032_int.h" 73 | #elif PARALLEL_MODE==PARALLEL_064_8CHAR 74 | #include "parallel_064_8char.h" 75 | #elif PARALLEL_MODE==PARALLEL_064_8CHARA 76 | #include "parallel_064_8charA.h" 77 | #elif PARALLEL_MODE==PARALLEL_064_2INT 78 | #include "parallel_064_2int.h" 79 | #elif PARALLEL_MODE==PARALLEL_064_LONG 80 | #include "parallel_064_long.h" 81 | #elif PARALLEL_MODE==PARALLEL_064_MMX 82 | #include "parallel_064_mmx.h" 83 | #elif PARALLEL_MODE==PARALLEL_128_16CHAR 84 | #include "parallel_128_16char.h" 85 | #elif PARALLEL_MODE==PARALLEL_128_16CHARA 86 | #include "parallel_128_16charA.h" 87 | #elif PARALLEL_MODE==PARALLEL_128_4INT 88 | #include "parallel_128_4int.h" 89 | #elif PARALLEL_MODE==PARALLEL_128_2LONG 90 | #include "parallel_128_2long.h" 91 | #elif PARALLEL_MODE==PARALLEL_128_2MMX 92 | #include "parallel_128_2mmx.h" 93 | #elif PARALLEL_MODE==PARALLEL_128_SSE 94 | #include "parallel_128_sse.h" 95 | #elif PARALLEL_MODE==PARALLEL_128_SSE2 96 | #include "parallel_128_sse2.h" 97 | #else 98 | #error "unknown/undefined parallel mode" 99 | #endif 100 | 101 | // stuff depending on conditionals 102 | 103 | #define BYTES_PER_GROUP (GROUP_PARALLELISM/8) 104 | #define BYPG BYTES_PER_GROUP 105 | #define BITS_PER_GROUP GROUP_PARALLELISM 106 | #define BIPG BITS_PER_GROUP 107 | 108 | #ifndef MEMALIGN 109 | #define MEMALIGN 110 | #endif 111 | 112 | //// debug tool 113 | // Lines with DBG will be removed 114 | 115 | DBG static void dump_mem(unsigned char *string, unsigned char *p, int len, int linelen){ 116 | DBG int i; 117 | DBG for(i=0;i>4)&0xf; 167 | iA[1]=(ck[0] )&0xf; 168 | iA[2]=(ck[1]>>4)&0xf; 169 | iA[3]=(ck[1] )&0xf; 170 | iA[4]=(ck[2]>>4)&0xf; 171 | iA[5]=(ck[2] )&0xf; 172 | iA[6]=(ck[3]>>4)&0xf; 173 | iA[7]=(ck[3] )&0xf; 174 | iB[0]=(ck[4]>>4)&0xf; 175 | iB[1]=(ck[4] )&0xf; 176 | iB[2]=(ck[5]>>4)&0xf; 177 | iB[3]=(ck[5] )&0xf; 178 | iB[4]=(ck[6]>>4)&0xf; 179 | iB[5]=(ck[6] )&0xf; 180 | iB[6]=(ck[7]>>4)&0xf; 181 | iB[7]=(ck[7] )&0xf; 182 | } 183 | 184 | //----- stream main function 185 | 186 | #define STREAM_INIT 187 | #include "tmp_stream.c" 188 | #undef STREAM_INIT 189 | 190 | #define STREAM_NORMAL 191 | #include "tmp_stream.c" 192 | #undef STREAM_NORMAL 193 | 194 | 195 | //-----block decypher 196 | 197 | //-----key schedule for block decypher 198 | 199 | static void key_schedule_block( 200 | unsigned char *ck, // [In] ck[0]-ck[7] 8 bytes | Key. 201 | unsigned char *kk) // [Out] kk[0]-kk[55] 56 bytes | Key schedule. 202 | { 203 | static const unsigned char key_perm[0x40] = { 204 | 0x12,0x24,0x09,0x07,0x2A,0x31,0x1D,0x15, 0x1C,0x36,0x3E,0x32,0x13,0x21,0x3B,0x40, 205 | 0x18,0x14,0x25,0x27,0x02,0x35,0x1B,0x01, 0x22,0x04,0x0D,0x0E,0x39,0x28,0x1A,0x29, 206 | 0x33,0x23,0x34,0x0C,0x16,0x30,0x1E,0x3A, 0x2D,0x1F,0x08,0x19,0x17,0x2F,0x3D,0x11, 207 | 0x3C,0x05,0x38,0x2B,0x0B,0x06,0x0A,0x2C, 0x20,0x3F,0x2E,0x0F,0x03,0x26,0x10,0x37, 208 | }; 209 | 210 | int i,j,k; 211 | int bit[64]; 212 | int newbit[64]; 213 | int kb[7][8]; 214 | 215 | // 56 steps 216 | // 56 key bytes kk(55)..kk(0) by key schedule from ck 217 | 218 | // kb(6,0) .. kb(6,7) = ck(0) .. ck(7) 219 | kb[6][0] = ck[0]; 220 | kb[6][1] = ck[1]; 221 | kb[6][2] = ck[2]; 222 | kb[6][3] = ck[3]; 223 | kb[6][4] = ck[4]; 224 | kb[6][5] = ck[5]; 225 | kb[6][6] = ck[6]; 226 | kb[6][7] = ck[7]; 227 | 228 | // calculate kb[5] .. kb[0] 229 | for(i=5; i>=0; i--){ 230 | // 64 bit perm on kb 231 | for(j=0; j<8; j++){ 232 | for(k=0; k<8; k++){ 233 | bit[j*8+k] = (kb[i+1][j] >> (7-k)) & 1; 234 | newbit[key_perm[j*8+k]-1] = bit[j*8+k]; 235 | } 236 | } 237 | for(j=0; j<8; j++){ 238 | kb[i][j] = 0; 239 | for(k=0; k<8; k++){ 240 | kb[i][j] |= newbit[j*8+k] << (7-k); 241 | } 242 | } 243 | } 244 | 245 | // xor to give kk 246 | for(i=0; i<7; i++){ 247 | for(j=0; j<8; j++){ 248 | kk[i*8+j] = kb[i][j] ^ i; 249 | } 250 | } 251 | 252 | } 253 | 254 | //-----block utils 255 | 256 | static inline __attribute__((always_inline)) void trasp_N_8 (unsigned char *in,unsigned char* out,int count){ 257 | int *ri=(int *)in; 258 | int *ibi=(int *)out; 259 | int j,i,k,g; 260 | // copy and first step 261 | for(g=0;g>16) | (b&0xffff0000) ; 276 | } 277 | } 278 | } 279 | //dump_mem("NE2 r[roff]",&r[roff],GROUP_PARALLELISM*8,GROUP_PARALLELISM); 280 | // now 01010101 281 | for(j=0;j<8;j+=2){ 282 | for(i=0;i<1;i++){ 283 | for(k=0;k>8) | (b&0xff00ff00); 289 | } 290 | } 291 | } 292 | //dump_mem("NE3 r[roff]",&r[roff],GROUP_PARALLELISM*8,GROUP_PARALLELISM); 293 | // now 00000000 294 | } 295 | 296 | static inline __attribute__((always_inline)) void trasp_8_N (unsigned char *in,unsigned char* out,int count){ 297 | int *ri=(int *)in; 298 | int *bdi=(int *)out; 299 | int j,i,k,g; 300 | #define INTS_PER_ROW (GROUP_PARALLELISM/8*2) 301 | //dump_mem("NE1 r[roff]",&r[roff],GROUP_PARALLELISM*8,GROUP_PARALLELISM); 302 | // now 00000000 303 | for(j=0;j<8;j+=2){ 304 | for(i=0;i<1;i++){ 305 | for(k=0;k>8) | (b&0xff00ff00); 311 | } 312 | } 313 | } 314 | //dump_mem("NE2 r[roff]",&r[roff],GROUP_PARALLELISM*8,GROUP_PARALLELISM); 315 | // now 01010101 316 | for(j=0;j<8;j+=4){ 317 | for(i=0;i<2;i++){ 318 | for(k=0;k>16) | (b&0xffff0000) ; 324 | } 325 | } 326 | } 327 | //dump_mem("NE3 r[roff]",&r[roff],GROUP_PARALLELISM*8,GROUP_PARALLELISM); 328 | // now 01230123 329 | for(g=0;g=0;i--){ 387 | { 388 | MEMALIGN batch tkkmulti=kkmulti[i]; 389 | batch *si=(batch *)sbox_in; 390 | batch *r6_N=(batch *)(r+roff+GROUP_PARALLELISM*6); 391 | for(g=0;g=*(clst+1)){ 581 | // out of this range, try next 582 | clst++;clst++; 583 | pkt=*clst; 584 | continue; 585 | } 586 | 587 | do{ // handle this packet 588 | xc0=pkt[3]&0xc0; 589 | DBG fprintf(stderr," exam pkt=%p, xc0=%02x, can_adv=%i\n",pkt,xc0,can_advance); 590 | if(xc0==0x00){ 591 | DBG fprintf(stderr,"skip clear pkt %p (can_advance is %i)\n",pkt,can_advance); 592 | advanced+=can_advance; 593 | stat_no_scramble++; 594 | break; 595 | } 596 | if(xc0==0x40){ 597 | DBG fprintf(stderr,"skip reserved pkt %p (can_advance is %i)\n",pkt,can_advance); 598 | advanced+=can_advance; 599 | stat_reserved++; 600 | break; 601 | } 602 | if(xc0==0x80||xc0==0xc0){ // encrypted 603 | ev_od=(xc0&0x40)>>6; // 0 even, 1 odd 604 | if(grouped==0) group_ev_od=ev_od; // this group will be all even (or odd) 605 | if(group_ev_od==ev_od){ // could be added to group 606 | pkt[3]&=0x3f; // consider it decrypted now 607 | if(pkt[3]&0x20){ // incomplete packet 608 | offset=4+pkt[4]+1; 609 | len=188-offset; 610 | n=len>>3; 611 | residue=len-(n<<3); 612 | if(n==0){ // decrypted==encrypted! 613 | DBG fprintf(stderr,"DECRYPTED MINI! (can_advance is %i)\n",can_advance); 614 | advanced+=can_advance; 615 | stat_decrypted_mini++; 616 | break; // this doesn't need more processing 617 | } 618 | }else{ 619 | len=184; 620 | offset=4; 621 | n=23; 622 | residue=0; 623 | } 624 | g_pkt[grouped]=pkt; 625 | g_len[grouped]=len; 626 | g_offset[grouped]=offset; 627 | g_n[grouped]=n; 628 | g_residue[grouped]=residue; 629 | DBG fprintf(stderr,"%2i: eo=%i pkt=%p len=%03i n=%2i residue=%i\n",grouped,ev_od,pkt,len,n,residue); 630 | grouped++; 631 | advanced+=can_advance; 632 | stat_decrypted[ev_od]++; 633 | } 634 | else{ 635 | can_advance=0; 636 | DBG fprintf(stderr,"skip pkt %p and can_advance set to 0\n",pkt); 637 | break; // skip and go on 638 | } 639 | } 640 | } while(0); 641 | 642 | if(can_advance){ 643 | // move range start forward 644 | *clst+=188; 645 | } 646 | // next packet, if there is one 647 | pkt+=188; 648 | } while(1); 649 | DBG fprintf(stderr,"-- result: grouped %i pkts, advanced %i pkts\n",grouped,advanced); 650 | 651 | // delete empty ranges and compact list 652 | clst2=cluster; 653 | for(clst=cluster;*clst!=NULL;clst+=2){ 654 | // if not empty 655 | if(*clst<*(clst+1)){ 656 | // it will remain 657 | *clst2=*clst; 658 | *(clst2+1)=*(clst+1); 659 | clst2+=2; 660 | } 661 | } 662 | *clst2=NULL; 663 | 664 | if(grouped==0){ 665 | // no processing needed 666 | return advanced; 667 | } 668 | 669 | // sort them, longest payload first 670 | // we expect many n=23 packets and a few n<23 671 | DBG fprintf(stderr,"PRESORTING\n"); 672 | DBG for(i=0;i=0;tsmall--){ 708 | if(g_n[tsmall]==23) break; 709 | } 710 | DBG fprintf(stderr,"tsmall after for =%i\n",tsmall); 711 | 712 | if(tsmall-t23<1) break; 713 | 714 | DBG fprintf(stderr,"swap t23=%i,tsmall=%i\n",t23,tsmall); 715 | 716 | g_swap(t23,tsmall); 717 | 718 | t23++; 719 | tsmall--; 720 | DBG fprintf(stderr,"new t23=%i,tsmall=%i\n\n",t23,tsmall); 721 | } 722 | DBG fprintf(stderr,"packets with n=23, t23=%i grouped=%i\n",t23,grouped); 723 | DBG fprintf(stderr,"MIDSORTING\n"); 724 | DBG for(i=0;ig_n[i]){ 732 | g_swap(i,j); 733 | } 734 | } 735 | } 736 | DBG fprintf(stderr,"POSTSORTING\n"); 737 | DBG for(i=0;i=0;i--){ 752 | alive[i]+=alive[i+1]; 753 | } 754 | DBG fprintf(stderr,"ALIVE\n"); 755 | DBG for(i=0;i<=23;i++){ 756 | DBG fprintf(stderr,"alive%2i=%i\n",i,alive[i]); 757 | DBG } 758 | 759 | // choose key 760 | if(group_ev_od==0){ 761 | k=&(*myKeys).even; 762 | } 763 | else{ 764 | k=&(*myKeys).odd; 765 | } 766 | 767 | //INIT 768 | //#define INITIALIZE_UNUSED_INPUT 769 | #ifdef INITIALIZE_UNUSED_INPUT 770 | // unnecessary zeroing. 771 | // without this, we operate on uninitialized memory 772 | // when grouped>>>>ITER 0\n"); 792 | iter=0; 793 | stream_cypher_group_init(®s,k->iA_g,k->iB_g,stream_in); 794 | // fill first ib 795 | for(g=0;g0;iter++){ 801 | DBG fprintf(stderr,">>>>>ITER %i\n",iter); 802 | // alive and just dead packets: calc block 803 | block_decypher_group(k->kkmulti,ib,block_out,alive[iter-1]); 804 | DBG dump_mem("BLO_ib ",block_out,8*alive[iter-1],8); 805 | // all packets (dead too): calc stream 806 | stream_cypher_group_normal(®s,stream_out); 807 | //dump_mem("stream_out",stream_out,GROUP_PARALLELISM*8,BYPG); 808 | 809 | // alive packets: calc ib 810 | for(g=0;g>>>>ITER 23\n"); 845 | iter=23; 846 | // calc block 847 | block_decypher_group(k->kkmulti,ib,block_out,alive[iter-1]); 848 | DBG dump_mem("23BLO_ib ",block_out,8*alive[iter-1],8); 849 | // just dead packets: write decrypted data 850 | for(g=alive[iter];gtmp_ffmode.h 65 | grep -v DBG FFdecsa.c >tmp_FFdecsa.c 66 | 67 | tmp_stream.c: stream.c 68 | grep -v DBG stream.c >tmp_stream.c 69 | 70 | ############################################################################### 71 | # Warning: .DEF file must be edited to fix exported function names (altx)! 72 | 73 | def:FFdecsa_def 74 | dll:FFdecsa_dll 75 | 76 | FFdecsa_def: FFdecsaDll.o 77 | $(COMPILER) -shared -o FFdecsa.dll FFdecsaDll.o -Wl,--kill-at,--output-def,FFDecsa_gxx.def 78 | 79 | FFdecsa_dll: FFdecsaDll.o 80 | ifeq ($(COMPILER),gcc) 81 | dllwrap -o FFDecsa_v2_$(FFMODE)_$(DPROC)_Gcc.dll -Wl,--strip-all,--gc-sections --def FFdecsa_gcc.def FFdecsaDll.o 82 | else 83 | dllwrap -o FFDecsa.dll -Wl,--strip-all,--gc-sections --def FFdecsa_gpp.def FFdecsaDll.o 84 | endif 85 | 86 | 87 | #Compile object file with flag "MAKE_DLL" 88 | FFdecsaDll.o: tmp_FFdecsa.c tmp_stream.c $(H_FILES) 89 | $(COMPILER) $(CFLAGS) -DMAKE_DLL -c tmp_FFdecsa.c -o FFdecsaDll.o 90 | 91 | 92 | ############################################################################### 93 | 94 | clean: 95 | rm -f *.o tmp_*.c tmp_*.h || true 96 | -------------------------------------------------------------------------------- /FFDeCsa-1.0.2-Altx/README.md: -------------------------------------------------------------------------------- 1 | ## FFDecsa 2 | FFdecsa is a fast implementation of a CSA decryption algorithm for MPEG TS packets. 3 | It is shockingly fast, more than 800% the speed of the standard single packet implementation. 4 | Thanks faith89r for your exceptional work ! 5 | 6 | ## Performance 7 | * AMD Duron @ 1.6 GHz : 160 Mbit/s (Mode: 128_SSE) 8 | * Intel P4 @ 3.0 GHz : 310 Mbit/s (Mode: 128_SSE2) 9 | * Intel E8400 @ 3.0 GHz : 668 Mbit/s (Mode: 128_SSE2) 10 | * Intel Core i3 @ 3.4 GHz : 1130 Mbit/s (Mode: 128_SSE2) 11 | 12 | ## How to compile on Windows: 13 | 1. Download installer from www.mingw.org and install packages: 14 | “mingw32-base”, “mingw32-gcc-g++”, “msys-base” 15 | 2. Run **StartShell.cmd** from FFDecsa sources directory 16 | 3. Optional: edit make_dlls.sh and makefile with your options 17 | 4. From shell, run **make_dlls.sh** 18 | 19 | ## Changelog 20 | * v1.0.0 21 | * public release by fatih89r 22 | * v1.0.1-Altx 23 | * added windows compatibility 24 | * removed FFdecsa_test.c 25 | * updated makefile 26 | * batch build script (make_dlls.sh) 27 | * v1.0.2-Altx 28 | * added MEMALIGN_16 & SSE2 29 | 30 | ## Legal 31 | As FFdecsa implements a standard, it is completly legal to use it. 32 | 33 | Copyright 2003-2004 fatih89r 34 | Copyright 2004-2015 altxro 35 | Released under GPL 36 | 37 | ## Website 38 | https://www.altx.ro/projects/ffdecsa/ -------------------------------------------------------------------------------- /FFDeCsa-1.0.2-Altx/_StartShell.cmd: -------------------------------------------------------------------------------- 1 | @ECHO OFF 2 | SET PATH=C:\MinGw\Bin;%PATH% 3 | SET HOME=. 4 | C:\MinGw\msys\1.0\bin\sh.exe --login -i -------------------------------------------------------------------------------- /FFDeCsa-1.0.2-Altx/fftable.h: -------------------------------------------------------------------------------- 1 | /* FFdecsa -- fast decsa algorithm 2 | * 3 | * Copyright (C) 2007 Dark Avenger 4 | * 2003-2004 fatih89r 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 2 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, write to the Free Software 18 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 19 | */ 20 | 21 | #ifndef FFTABLE_H 22 | #define FFTABLE_H 23 | 24 | void static inline FFTABLEIN(unsigned char *tab, int g, unsigned char *data) 25 | { 26 | #if 0 27 | *(((int *)tab)+2*g)=*((int *)data); 28 | *(((int *)tab)+2*g+1)=*(((int *)data)+1); 29 | #else 30 | *(((long long *)tab)+g)=*((long long *)data); 31 | #endif 32 | } 33 | 34 | void static inline FFTABLEOUT(unsigned char *data, unsigned char *tab, int g) 35 | { 36 | #if 1 37 | *((int *)data)=*(((int *)tab)+2*g); 38 | *(((int *)data)+1)=*(((int *)tab)+2*g+1); 39 | #else 40 | *((long long *)data)=*(((long long *)tab)+g); 41 | #endif 42 | } 43 | 44 | void static inline FFTABLEOUTXORNBY(int n, unsigned char *data, unsigned char *tab, int g) 45 | { 46 | for(int j=0;j=4?32-1:0))+j); 99 | } 100 | } 101 | 102 | struct batch_t{ 103 | unsigned char s1,s2,s3,s4; 104 | }; 105 | typedef struct batch_t batch; 106 | 107 | #define BYTES_PER_BATCH 4 108 | 109 | batch static inline B_FFAND(batch a,batch b){ 110 | batch res; 111 | res.s1=a.s1&b.s1; 112 | res.s2=a.s2&b.s2; 113 | res.s3=a.s3&b.s3; 114 | res.s4=a.s4&b.s4; 115 | return res; 116 | } 117 | 118 | batch static inline B_FFOR(batch a,batch b){ 119 | batch res; 120 | res.s1=a.s1|b.s1; 121 | res.s2=a.s2|b.s2; 122 | res.s3=a.s3|b.s3; 123 | res.s4=a.s4|b.s4; 124 | return res; 125 | } 126 | 127 | batch static inline B_FFXOR(batch a,batch b){ 128 | batch res; 129 | res.s1=a.s1^b.s1; 130 | res.s2=a.s2^b.s2; 131 | res.s3=a.s3^b.s3; 132 | res.s4=a.s4^b.s4; 133 | return res; 134 | } 135 | 136 | 137 | batch static inline B_FFN_ALL_29(){ 138 | batch res; 139 | res.s1=0x29; 140 | res.s2=0x29; 141 | res.s3=0x29; 142 | res.s4=0x29; 143 | return res; 144 | } 145 | batch static inline B_FFN_ALL_02(){ 146 | batch res; 147 | res.s1=0x02; 148 | res.s2=0x02; 149 | res.s3=0x02; 150 | res.s4=0x02; 151 | return res; 152 | } 153 | batch static inline B_FFN_ALL_04(){ 154 | batch res; 155 | res.s1=0x04; 156 | res.s2=0x04; 157 | res.s3=0x04; 158 | res.s4=0x04; 159 | return res; 160 | } 161 | batch static inline B_FFN_ALL_10(){ 162 | batch res; 163 | res.s1=0x10; 164 | res.s2=0x10; 165 | res.s3=0x10; 166 | res.s4=0x10; 167 | return res; 168 | } 169 | batch static inline B_FFN_ALL_40(){ 170 | batch res; 171 | res.s1=0x40; 172 | res.s2=0x40; 173 | res.s3=0x40; 174 | res.s4=0x40; 175 | return res; 176 | } 177 | batch static inline B_FFN_ALL_80(){ 178 | batch res; 179 | res.s1=0x80; 180 | res.s2=0x80; 181 | res.s3=0x80; 182 | res.s4=0x80; 183 | return res; 184 | } 185 | 186 | batch static inline B_FFSH8L(batch a,int n){ 187 | batch res; 188 | res.s1=a.s1<>n; 198 | res.s2=a.s2>>n; 199 | res.s3=a.s3>>n; 200 | res.s4=a.s4>>n; 201 | return res; 202 | } 203 | 204 | 205 | void static inline M_EMPTY(void){ 206 | } 207 | -------------------------------------------------------------------------------- /FFDeCsa-1.0.2-Altx/parallel_032_4charA.h: -------------------------------------------------------------------------------- 1 | /* FFdecsa -- fast decsa algorithm 2 | * 3 | * Copyright (C) 2003-2004 fatih89r 4 | * 5 | * This program is free software; you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation; either version 2 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program; if not, write to the Free Software 17 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 18 | */ 19 | 20 | 21 | struct group_t{ 22 | unsigned char s1[4]; 23 | }; 24 | typedef struct group_t group; 25 | 26 | #define GROUP_PARALLELISM 32 27 | 28 | group static inline FF0(){ 29 | group res; 30 | int i; 31 | for(i=0;i<4;i++) res.s1[i]=0x0; 32 | return res; 33 | } 34 | 35 | group static inline FF1(){ 36 | group res; 37 | int i; 38 | for(i=0;i<4;i++) res.s1[i]=0xff; 39 | return res; 40 | } 41 | 42 | group static inline FFAND(group a,group b){ 43 | group res; 44 | int i; 45 | for(i=0;i<4;i++) res.s1[i]=a.s1[i]&b.s1[i]; 46 | return res; 47 | } 48 | 49 | group static inline FFOR(group a,group b){ 50 | group res; 51 | int i; 52 | for(i=0;i<4;i++) res.s1[i]=a.s1[i]|b.s1[i]; 53 | return res; 54 | } 55 | 56 | group static inline FFXOR(group a,group b){ 57 | group res; 58 | int i; 59 | for(i=0;i<4;i++) res.s1[i]=a.s1[i]^b.s1[i]; 60 | return res; 61 | } 62 | 63 | group static inline FFNOT(group a){ 64 | group res; 65 | int i; 66 | for(i=0;i<4;i++) res.s1[i]=~a.s1[i]; 67 | return res; 68 | } 69 | 70 | 71 | /* 64 rows of 32 bits */ 72 | 73 | void static inline FFTABLEIN(unsigned char *tab, int g, unsigned char *data){ 74 | *(((int *)tab)+g)=*((int *)data); 75 | *(((int *)tab)+32+g)=*(((int *)data)+1); 76 | } 77 | 78 | void static inline FFTABLEOUT(unsigned char *data, unsigned char *tab, int g){ 79 | *((int *)data)=*(((int *)tab)+g); 80 | *(((int *)data)+1)=*(((int *)tab)+32+g); 81 | } 82 | 83 | void static inline FFTABLEOUTXORNBY(int n, unsigned char *data, unsigned char *tab, int g){ 84 | int j; 85 | for(j=0;j=4?32-1:0))+j); 87 | } 88 | } 89 | 90 | struct batch_t{ 91 | unsigned char s1[4]; 92 | }; 93 | typedef struct batch_t batch; 94 | 95 | #define BYTES_PER_BATCH 4 96 | 97 | batch static inline B_FFAND(batch a,batch b){ 98 | batch res; 99 | int i; 100 | for(i=0;i<4;i++) res.s1[i]=a.s1[i]&b.s1[i]; 101 | return res; 102 | } 103 | 104 | batch static inline B_FFOR(batch a,batch b){ 105 | batch res; 106 | int i; 107 | for(i=0;i<4;i++) res.s1[i]=a.s1[i]|b.s1[i]; 108 | return res; 109 | } 110 | 111 | batch static inline B_FFXOR(batch a,batch b){ 112 | batch res; 113 | int i; 114 | for(i=0;i<4;i++) res.s1[i]=a.s1[i]^b.s1[i]; 115 | return res; 116 | } 117 | 118 | 119 | batch static inline B_FFN_ALL_29(){ 120 | batch res; 121 | int i; 122 | for(i=0;i<4;i++) res.s1[i]=0x29; 123 | return res; 124 | } 125 | batch static inline B_FFN_ALL_02(){ 126 | batch res; 127 | int i; 128 | for(i=0;i<4;i++) res.s1[i]=0x02; 129 | return res; 130 | } 131 | batch static inline B_FFN_ALL_04(){ 132 | batch res; 133 | int i; 134 | for(i=0;i<4;i++) res.s1[i]=0x04; 135 | return res; 136 | } 137 | batch static inline B_FFN_ALL_10(){ 138 | batch res; 139 | int i; 140 | for(i=0;i<4;i++) res.s1[i]=0x10; 141 | return res; 142 | } 143 | batch static inline B_FFN_ALL_40(){ 144 | batch res; 145 | int i; 146 | for(i=0;i<4;i++) res.s1[i]=0x40; 147 | return res; 148 | } 149 | batch static inline B_FFN_ALL_80(){ 150 | batch res; 151 | int i; 152 | for(i=0;i<4;i++) res.s1[i]=0x80; 153 | return res; 154 | } 155 | 156 | batch static inline B_FFSH8L(batch a,int n){ 157 | batch res; 158 | int i; 159 | for(i=0;i<4;i++) res.s1[i]=a.s1[i]<>n; 167 | return res; 168 | } 169 | 170 | void static inline M_EMPTY(void){ 171 | } 172 | -------------------------------------------------------------------------------- /FFDeCsa-1.0.2-Altx/parallel_032_int.h: -------------------------------------------------------------------------------- 1 | /* FFdecsa -- fast decsa algorithm 2 | * 3 | * Copyright (C) 2003-2004 fatih89r 4 | * 5 | * This program is free software; you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation; either version 2 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program; if not, write to the Free Software 17 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 18 | */ 19 | 20 | #include "parallel_std_def.h" 21 | 22 | typedef unsigned int group; 23 | #define GROUP_PARALLELISM 32 24 | #define FF0() 0x0 25 | #define FF1() 0xffffffff 26 | 27 | /* 64 rows of 32 bits */ 28 | 29 | void static inline FFTABLEIN(unsigned char *tab, int g, unsigned char *data){ 30 | *(((int *)tab)+g)=*((int *)data); 31 | *(((int *)tab)+32+g)=*(((int *)data)+1); 32 | } 33 | 34 | void static inline FFTABLEOUT(unsigned char *data, unsigned char *tab, int g){ 35 | *((int *)data)=*(((int *)tab)+g); 36 | *(((int *)data)+1)=*(((int *)tab)+32+g); 37 | } 38 | 39 | void static inline FFTABLEOUTXORNBY(int n, unsigned char *data, unsigned char *tab, int g){ 40 | int j; 41 | for(j=0;j=4?32-1:0))+j); 43 | } 44 | } 45 | 46 | typedef unsigned int batch; 47 | #define BYTES_PER_BATCH 4 48 | #define B_FFN_ALL_29() 0x29292929 49 | #define B_FFN_ALL_02() 0x02020202 50 | #define B_FFN_ALL_04() 0x04040404 51 | #define B_FFN_ALL_10() 0x10101010 52 | #define B_FFN_ALL_40() 0x40404040 53 | #define B_FFN_ALL_80() 0x80808080 54 | 55 | #define M_EMPTY() 56 | -------------------------------------------------------------------------------- /FFDeCsa-1.0.2-Altx/parallel_064_2int.h: -------------------------------------------------------------------------------- 1 | /* FFdecsa -- fast decsa algorithm 2 | * 3 | * Copyright (C) 2003-2004 fatih89r 4 | * 5 | * This program is free software; you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation; either version 2 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program; if not, write to the Free Software 17 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 18 | */ 19 | 20 | 21 | struct group_t{ 22 | unsigned int s1; 23 | unsigned int s2; 24 | }; 25 | typedef struct group_t group; 26 | 27 | #define GROUP_PARALLELISM 64 28 | 29 | group static inline FF0(){ 30 | group res; 31 | res.s1=0x0; 32 | res.s2=0x0; 33 | return res; 34 | } 35 | 36 | group static inline FF1(){ 37 | group res; 38 | res.s1=0xffffffff; 39 | res.s2=0xffffffff; 40 | return res; 41 | } 42 | 43 | group static inline FFAND(group a,group b){ 44 | group res; 45 | res.s1=a.s1&b.s1; 46 | res.s2=a.s2&b.s2; 47 | return res; 48 | } 49 | 50 | group static inline FFOR(group a,group b){ 51 | group res; 52 | res.s1=a.s1|b.s1; 53 | res.s2=a.s2|b.s2; 54 | return res; 55 | } 56 | 57 | group static inline FFXOR(group a,group b){ 58 | group res; 59 | res.s1=a.s1^b.s1; 60 | res.s2=a.s2^b.s2; 61 | return res; 62 | } 63 | 64 | group static inline FFNOT(group a){ 65 | group res; 66 | res.s1=~a.s1; 67 | res.s2=~a.s2; 68 | return res; 69 | } 70 | 71 | 72 | /* 64 rows of 64 bits */ 73 | 74 | void static inline FFTABLEIN(unsigned char *tab, int g, unsigned char *data){ 75 | *(((int *)tab)+2*g)=*((int *)data); 76 | *(((int *)tab)+2*g+1)=*(((int *)data)+1); 77 | } 78 | 79 | void static inline FFTABLEOUT(unsigned char *data, unsigned char *tab, int g){ 80 | *((int *)data)=*(((int *)tab)+2*g); 81 | *(((int *)data)+1)=*(((int *)tab)+2*g+1); 82 | } 83 | 84 | void static inline FFTABLEOUTXORNBY(int n, unsigned char *data, unsigned char *tab, int g){ 85 | int j; 86 | for(j=0;j>n; 169 | res.s2=a.s2>>n; 170 | return res; 171 | } 172 | 173 | 174 | void static inline M_EMPTY(void){ 175 | } 176 | -------------------------------------------------------------------------------- /FFDeCsa-1.0.2-Altx/parallel_064_8char.h: -------------------------------------------------------------------------------- 1 | /* FFdecsa -- fast decsa algorithm 2 | * 3 | * Copyright (C) 2003-2004 fatih89r 4 | * 5 | * This program is free software; you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation; either version 2 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program; if not, write to the Free Software 17 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 18 | */ 19 | 20 | 21 | struct group_t{ 22 | unsigned char s1,s2,s3,s4,s5,s6,s7,s8; 23 | }; 24 | typedef struct group_t group; 25 | 26 | #define GROUP_PARALLELISM 64 27 | 28 | group static inline FF0(){ 29 | group res; 30 | res.s1=0x0; 31 | res.s2=0x0; 32 | res.s3=0x0; 33 | res.s4=0x0; 34 | res.s5=0x0; 35 | res.s6=0x0; 36 | res.s7=0x0; 37 | res.s8=0x0; 38 | return res; 39 | } 40 | 41 | group static inline FF1(){ 42 | group res; 43 | res.s1=0xff; 44 | res.s2=0xff; 45 | res.s3=0xff; 46 | res.s4=0xff; 47 | res.s5=0xff; 48 | res.s6=0xff; 49 | res.s7=0xff; 50 | res.s8=0xff; 51 | return res; 52 | } 53 | 54 | group static inline FFAND(group a,group b){ 55 | group res; 56 | res.s1=a.s1&b.s1; 57 | res.s2=a.s2&b.s2; 58 | res.s3=a.s3&b.s3; 59 | res.s4=a.s4&b.s4; 60 | res.s5=a.s5&b.s5; 61 | res.s6=a.s6&b.s6; 62 | res.s7=a.s7&b.s7; 63 | res.s8=a.s8&b.s8; 64 | return res; 65 | } 66 | 67 | group static inline FFOR(group a,group b){ 68 | group res; 69 | res.s1=a.s1|b.s1; 70 | res.s2=a.s2|b.s2; 71 | res.s3=a.s3|b.s3; 72 | res.s4=a.s4|b.s4; 73 | res.s5=a.s5|b.s5; 74 | res.s6=a.s6|b.s6; 75 | res.s7=a.s7|b.s7; 76 | res.s8=a.s8|b.s8; 77 | return res; 78 | } 79 | 80 | group static inline FFXOR(group a,group b){ 81 | group res; 82 | res.s1=a.s1^b.s1; 83 | res.s2=a.s2^b.s2; 84 | res.s3=a.s3^b.s3; 85 | res.s4=a.s4^b.s4; 86 | res.s5=a.s5^b.s5; 87 | res.s6=a.s6^b.s6; 88 | res.s7=a.s7^b.s7; 89 | res.s8=a.s8^b.s8; 90 | return res; 91 | } 92 | 93 | group static inline FFNOT(group a){ 94 | group res; 95 | res.s1=~a.s1; 96 | res.s2=~a.s2; 97 | res.s3=~a.s3; 98 | res.s4=~a.s4; 99 | res.s5=~a.s5; 100 | res.s6=~a.s6; 101 | res.s7=~a.s7; 102 | res.s8=~a.s8; 103 | return res; 104 | } 105 | 106 | 107 | /* 64 rows of 64 bits */ 108 | 109 | void static inline FFTABLEIN(unsigned char *tab, int g, unsigned char *data){ 110 | *(((int *)tab)+2*g)=*((int *)data); 111 | *(((int *)tab)+2*g+1)=*(((int *)data)+1); 112 | } 113 | 114 | void static inline FFTABLEOUT(unsigned char *data, unsigned char *tab, int g){ 115 | *((int *)data)=*(((int *)tab)+2*g); 116 | *(((int *)data)+1)=*(((int *)tab)+2*g+1); 117 | } 118 | 119 | void static inline FFTABLEOUTXORNBY(int n, unsigned char *data, unsigned char *tab, int g){ 120 | int j; 121 | for(j=0;j>n; 262 | res.s2=a.s2>>n; 263 | res.s3=a.s3>>n; 264 | res.s4=a.s4>>n; 265 | res.s5=a.s5>>n; 266 | res.s6=a.s6>>n; 267 | res.s7=a.s7>>n; 268 | res.s8=a.s8>>n; 269 | return res; 270 | } 271 | 272 | 273 | void static inline M_EMPTY(void){ 274 | } 275 | -------------------------------------------------------------------------------- /FFDeCsa-1.0.2-Altx/parallel_064_8charA.h: -------------------------------------------------------------------------------- 1 | /* FFdecsa -- fast decsa algorithm 2 | * 3 | * Copyright (C) 2003-2004 fatih89r 4 | * 5 | * This program is free software; you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation; either version 2 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program; if not, write to the Free Software 17 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 18 | */ 19 | 20 | 21 | struct group_t{ 22 | unsigned char s1[8]; 23 | }; 24 | typedef struct group_t group; 25 | 26 | #define GROUP_PARALLELISM 64 27 | 28 | group static inline FF0(){ 29 | group res; 30 | int i; 31 | for(i=0;i<8;i++) res.s1[i]=0x0; 32 | return res; 33 | } 34 | 35 | group static inline FF1(){ 36 | group res; 37 | int i; 38 | for(i=0;i<8;i++) res.s1[i]=0xff; 39 | return res; 40 | } 41 | 42 | group static inline FFAND(group a,group b){ 43 | group res; 44 | int i; 45 | for(i=0;i<8;i++) res.s1[i]=a.s1[i]&b.s1[i]; 46 | return res; 47 | } 48 | 49 | group static inline FFOR(group a,group b){ 50 | group res; 51 | int i; 52 | for(i=0;i<8;i++) res.s1[i]=a.s1[i]|b.s1[i]; 53 | return res; 54 | } 55 | 56 | group static inline FFXOR(group a,group b){ 57 | group res; 58 | int i; 59 | for(i=0;i<8;i++) res.s1[i]=a.s1[i]^b.s1[i]; 60 | return res; 61 | } 62 | 63 | group static inline FFNOT(group a){ 64 | group res; 65 | int i; 66 | for(i=0;i<8;i++) res.s1[i]=~a.s1[i]; 67 | return res; 68 | } 69 | 70 | 71 | /* 64 rows of 64 bits */ 72 | 73 | void static inline FFTABLEIN(unsigned char *tab, int g, unsigned char *data){ 74 | *(((int *)tab)+2*g)=*((int *)data); 75 | *(((int *)tab)+2*g+1)=*(((int *)data)+1); 76 | } 77 | 78 | void static inline FFTABLEOUT(unsigned char *data, unsigned char *tab, int g){ 79 | *((int *)data)=*(((int *)tab)+2*g); 80 | *(((int *)data)+1)=*(((int *)tab)+2*g+1); 81 | } 82 | 83 | void static inline FFTABLEOUTXORNBY(int n, unsigned char *data, unsigned char *tab, int g){ 84 | int j; 85 | for(j=0;j>n; 167 | return res; 168 | } 169 | 170 | void static inline M_EMPTY(void){ 171 | } 172 | -------------------------------------------------------------------------------- /FFDeCsa-1.0.2-Altx/parallel_064_long.h: -------------------------------------------------------------------------------- 1 | /* FFdecsa -- fast decsa algorithm 2 | * 3 | * Copyright (C) 2007 Dark Avenger 4 | * 2003-2004 fatih89r 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 2 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, write to the Free Software 18 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 19 | */ 20 | 21 | #include "parallel_std_def.h" 22 | 23 | typedef unsigned long long group; 24 | #define GROUP_PARALLELISM 64 25 | #define FF0() 0x0ULL 26 | #define FF1() 0xffffffffffffffffULL 27 | 28 | typedef unsigned long long batch; 29 | #define BYTES_PER_BATCH 8 30 | #define B_FFN_ALL_29() 0x2929292929292929ULL 31 | #define B_FFN_ALL_02() 0x0202020202020202ULL 32 | #define B_FFN_ALL_04() 0x0404040404040404ULL 33 | #define B_FFN_ALL_10() 0x1010101010101010ULL 34 | #define B_FFN_ALL_40() 0x4040404040404040ULL 35 | #define B_FFN_ALL_80() 0x8080808080808080ULL 36 | 37 | #define M_EMPTY() 38 | 39 | #include "fftable.h" 40 | -------------------------------------------------------------------------------- /FFDeCsa-1.0.2-Altx/parallel_064_mmx.h: -------------------------------------------------------------------------------- 1 | /* FFdecsa -- fast decsa algorithm 2 | * 3 | * Copyright (C) 2007 Dark Avenger 4 | * 2003-2004 fatih89r 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 2 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, write to the Free Software 18 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 19 | */ 20 | 21 | #include 22 | 23 | #define MEMALIGN __attribute__((aligned(16))) 24 | 25 | union __u64 { 26 | unsigned int u[2]; 27 | __m64 v; 28 | }; 29 | 30 | static const union __u64 ff0 = {{0x00000000U, 0x00000000U}}; 31 | static const union __u64 ff1 = {{0xffffffffU, 0xffffffffU}}; 32 | 33 | typedef __m64 group; 34 | #define GROUP_PARALLELISM 64 35 | #define FF0() ff0.v 36 | #define FF1() ff1.v 37 | #define FFAND(a,b) _mm_and_si64((a),(b)) 38 | #define FFOR(a,b) _mm_or_si64((a),(b)) 39 | #define FFXOR(a,b) _mm_xor_si64((a),(b)) 40 | #define FFNOT(a) _mm_xor_si64((a),FF1()) 41 | 42 | /* 64 rows of 64 bits */ 43 | 44 | static const union __u64 ff29 = {{0x29292929U, 0x29292929U}}; 45 | static const union __u64 ff02 = {{0x02020202U, 0x02020202U}}; 46 | static const union __u64 ff04 = {{0x04040404U, 0x04040404U}}; 47 | static const union __u64 ff10 = {{0x10101010U, 0x10101010U}}; 48 | static const union __u64 ff40 = {{0x40404040U, 0x40404040U}}; 49 | static const union __u64 ff80 = {{0x80808080U, 0x80808080U}}; 50 | 51 | typedef __m64 batch; 52 | #define BYTES_PER_BATCH 8 53 | #define B_FFAND(a,b) FFAND((a),(b)) 54 | #define B_FFOR(a,b) FFOR((a),(b)) 55 | #define B_FFXOR(a,b) FFXOR((a),(b)) 56 | #define B_FFN_ALL_29() ff29.v 57 | #define B_FFN_ALL_02() ff02.v 58 | #define B_FFN_ALL_04() ff04.v 59 | #define B_FFN_ALL_10() ff10.v 60 | #define B_FFN_ALL_40() ff40.v 61 | #define B_FFN_ALL_80() ff80.v 62 | #define B_FFSH8L(a,n) _mm_slli_si64((a),(n)) 63 | #define B_FFSH8R(a,n) _mm_srli_si64((a),(n)) 64 | 65 | #define M_EMPTY() _mm_empty() 66 | 67 | 68 | #undef XOR_8_BY 69 | #define XOR_8_BY(d,s1,s2) do { *(__m64*)d = _mm_xor_si64(*(__m64*)(s1), *(__m64*)(s2)); } while(0) 70 | 71 | #undef XOREQ_8_BY 72 | #define XOREQ_8_BY(d,s) XOR_8_BY(d, d, s) 73 | 74 | #undef COPY_8_BY 75 | #define COPY_8_BY(d,s) do { *(__m64 *)(d) = *(__m64 *)(s); } while(0) 76 | 77 | #undef BEST_SPAN 78 | #define BEST_SPAN 8 79 | 80 | #undef XOR_BEST_BY 81 | #define XOR_BEST_BY(d,s1,s2) XOR_8_BY(d,s1,s2) 82 | 83 | #include "fftable.h" 84 | -------------------------------------------------------------------------------- /FFDeCsa-1.0.2-Altx/parallel_128_16char.h: -------------------------------------------------------------------------------- 1 | /* FFdecsa -- fast decsa algorithm 2 | * 3 | * Copyright (C) 2003-2004 fatih89r 4 | * 5 | * This program is free software; you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation; either version 2 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program; if not, write to the Free Software 17 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 18 | */ 19 | 20 | 21 | struct group_t{ 22 | unsigned char s1,s2,s3,s4,s5,s6,s7,s8,s9,s10,s11,s12,s13,s14,s15,s16; 23 | }; 24 | typedef struct group_t group; 25 | 26 | #define GROUP_PARALLELISM 128 27 | 28 | group static inline FF0(){ 29 | group res; 30 | res.s1=0x0; 31 | res.s2=0x0; 32 | res.s3=0x0; 33 | res.s4=0x0; 34 | res.s5=0x0; 35 | res.s6=0x0; 36 | res.s7=0x0; 37 | res.s8=0x0; 38 | res.s9=0x0; 39 | res.s10=0x0; 40 | res.s11=0x0; 41 | res.s12=0x0; 42 | res.s13=0x0; 43 | res.s14=0x0; 44 | res.s15=0x0; 45 | res.s16=0x0; 46 | return res; 47 | } 48 | 49 | group static inline FF1(){ 50 | group res; 51 | res.s1=0xff; 52 | res.s2=0xff; 53 | res.s3=0xff; 54 | res.s4=0xff; 55 | res.s5=0xff; 56 | res.s6=0xff; 57 | res.s7=0xff; 58 | res.s8=0xff; 59 | res.s9=0xff; 60 | res.s10=0xff; 61 | res.s11=0xff; 62 | res.s12=0xff; 63 | res.s13=0xff; 64 | res.s14=0xff; 65 | res.s15=0xff; 66 | res.s16=0xff; 67 | return res; 68 | } 69 | 70 | group static inline FFAND(group a,group b){ 71 | group res; 72 | res.s1=a.s1&b.s1; 73 | res.s2=a.s2&b.s2; 74 | res.s3=a.s3&b.s3; 75 | res.s4=a.s4&b.s4; 76 | res.s5=a.s5&b.s5; 77 | res.s6=a.s6&b.s6; 78 | res.s7=a.s7&b.s7; 79 | res.s8=a.s8&b.s8; 80 | res.s9=a.s9&b.s9; 81 | res.s10=a.s10&b.s10; 82 | res.s11=a.s11&b.s11; 83 | res.s12=a.s12&b.s12; 84 | res.s13=a.s13&b.s13; 85 | res.s14=a.s14&b.s14; 86 | res.s15=a.s15&b.s15; 87 | res.s16=a.s16&b.s16; 88 | return res; 89 | } 90 | 91 | group static inline FFOR(group a,group b){ 92 | group res; 93 | res.s1=a.s1|b.s1; 94 | res.s2=a.s2|b.s2; 95 | res.s3=a.s3|b.s3; 96 | res.s4=a.s4|b.s4; 97 | res.s5=a.s5|b.s5; 98 | res.s6=a.s6|b.s6; 99 | res.s7=a.s7|b.s7; 100 | res.s8=a.s8|b.s8; 101 | res.s9=a.s9|b.s9; 102 | res.s10=a.s10|b.s10; 103 | res.s11=a.s11|b.s11; 104 | res.s12=a.s12|b.s12; 105 | res.s13=a.s13|b.s13; 106 | res.s14=a.s14|b.s14; 107 | res.s15=a.s15|b.s15; 108 | res.s16=a.s16|b.s16; 109 | return res; 110 | } 111 | 112 | group static inline FFXOR(group a,group b){ 113 | group res; 114 | res.s1=a.s1^b.s1; 115 | res.s2=a.s2^b.s2; 116 | res.s3=a.s3^b.s3; 117 | res.s4=a.s4^b.s4; 118 | res.s5=a.s5^b.s5; 119 | res.s6=a.s6^b.s6; 120 | res.s7=a.s7^b.s7; 121 | res.s8=a.s8^b.s8; 122 | res.s9=a.s9^b.s9; 123 | res.s10=a.s10^b.s10; 124 | res.s11=a.s11^b.s11; 125 | res.s12=a.s12^b.s12; 126 | res.s13=a.s13^b.s13; 127 | res.s14=a.s14^b.s14; 128 | res.s15=a.s15^b.s15; 129 | res.s16=a.s16^b.s16; 130 | return res; 131 | } 132 | 133 | group static inline FFNOT(group a){ 134 | group res; 135 | res.s1=~a.s1; 136 | res.s2=~a.s2; 137 | res.s3=~a.s3; 138 | res.s4=~a.s4; 139 | res.s5=~a.s5; 140 | res.s6=~a.s6; 141 | res.s7=~a.s7; 142 | res.s8=~a.s8; 143 | res.s9=~a.s9; 144 | res.s10=~a.s10; 145 | res.s11=~a.s11; 146 | res.s12=~a.s12; 147 | res.s13=~a.s13; 148 | res.s14=~a.s14; 149 | res.s15=~a.s15; 150 | res.s16=~a.s16; 151 | return res; 152 | } 153 | 154 | 155 | /* 64 rows of 128 bits */ 156 | 157 | void static inline FFTABLEIN(unsigned char *tab, int g, unsigned char *data){ 158 | *(((int *)tab)+2*g)=*((int *)data); 159 | *(((int *)tab)+2*g+1)=*(((int *)data)+1); 160 | } 161 | 162 | void static inline FFTABLEOUT(unsigned char *data, unsigned char *tab, int g){ 163 | *((int *)data)=*(((int *)tab)+2*g); 164 | *(((int *)data)+1)=*(((int *)tab)+2*g+1); 165 | } 166 | 167 | void static inline FFTABLEOUTXORNBY(int n, unsigned char *data, unsigned char *tab, int g){ 168 | int j; 169 | for(j=0;j>n; 391 | res.s2=a.s2>>n; 392 | res.s3=a.s3>>n; 393 | res.s4=a.s4>>n; 394 | res.s5=a.s5>>n; 395 | res.s6=a.s6>>n; 396 | res.s7=a.s7>>n; 397 | res.s8=a.s8>>n; 398 | res.s9=a.s9>>n; 399 | res.s10=a.s10>>n; 400 | res.s11=a.s11>>n; 401 | res.s12=a.s12>>n; 402 | res.s13=a.s13>>n; 403 | res.s14=a.s14>>n; 404 | res.s15=a.s15>>n; 405 | res.s16=a.s16>>n; 406 | return res; 407 | } 408 | 409 | 410 | void static inline M_EMPTY(void){ 411 | } 412 | -------------------------------------------------------------------------------- /FFDeCsa-1.0.2-Altx/parallel_128_16charA.h: -------------------------------------------------------------------------------- 1 | /* FFdecsa -- fast decsa algorithm 2 | * 3 | * Copyright (C) 2003-2004 fatih89r 4 | * 5 | * This program is free software; you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation; either version 2 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program; if not, write to the Free Software 17 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 18 | */ 19 | 20 | 21 | struct group_t{ 22 | unsigned char s1[16]; 23 | }; 24 | typedef struct group_t group; 25 | 26 | #define GROUP_PARALLELISM 128 27 | 28 | group static inline FF0(){ 29 | group res; 30 | int i; 31 | for(i=0;i<16;i++) res.s1[i]=0x0; 32 | return res; 33 | } 34 | 35 | group static inline FF1(){ 36 | group res; 37 | int i; 38 | for(i=0;i<16;i++) res.s1[i]=0xff; 39 | return res; 40 | } 41 | 42 | group static inline FFAND(group a,group b){ 43 | group res; 44 | int i; 45 | for(i=0;i<16;i++) res.s1[i]=a.s1[i]&b.s1[i]; 46 | return res; 47 | } 48 | 49 | group static inline FFOR(group a,group b){ 50 | group res; 51 | int i; 52 | for(i=0;i<16;i++) res.s1[i]=a.s1[i]|b.s1[i]; 53 | return res; 54 | } 55 | 56 | group static inline FFXOR(group a,group b){ 57 | group res; 58 | int i; 59 | for(i=0;i<16;i++) res.s1[i]=a.s1[i]^b.s1[i]; 60 | return res; 61 | } 62 | 63 | group static inline FFNOT(group a){ 64 | group res; 65 | int i; 66 | for(i=0;i<16;i++) res.s1[i]=~a.s1[i]; 67 | return res; 68 | } 69 | 70 | 71 | /* 64 rows of 128 bits */ 72 | 73 | void static inline FFTABLEIN(unsigned char *tab, int g, unsigned char *data){ 74 | *(((int *)tab)+2*g)=*((int *)data); 75 | *(((int *)tab)+2*g+1)=*(((int *)data)+1); 76 | } 77 | 78 | void static inline FFTABLEOUT(unsigned char *data, unsigned char *tab, int g){ 79 | *((int *)data)=*(((int *)tab)+2*g); 80 | *(((int *)data)+1)=*(((int *)tab)+2*g+1); 81 | } 82 | 83 | void static inline FFTABLEOUTXORNBY(int n, unsigned char *data, unsigned char *tab, int g){ 84 | int j; 85 | for(j=0;j>n; 168 | return res; 169 | } 170 | 171 | void static inline M_EMPTY(void){ 172 | } 173 | -------------------------------------------------------------------------------- /FFDeCsa-1.0.2-Altx/parallel_128_2long.h: -------------------------------------------------------------------------------- 1 | /* FFdecsa -- fast decsa algorithm 2 | * 3 | * Copyright (C) 2003-2004 fatih89r 4 | * 5 | * This program is free software; you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation; either version 2 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program; if not, write to the Free Software 17 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 18 | */ 19 | 20 | 21 | struct group_t{ 22 | unsigned long long int s1; 23 | unsigned long long int s2; 24 | }; 25 | typedef struct group_t group; 26 | 27 | #define GROUP_PARALLELISM 128 28 | 29 | group static inline FF0(){ 30 | group res; 31 | res.s1=0x0ULL; 32 | res.s2=0x0ULL; 33 | return res; 34 | } 35 | 36 | group static inline FF1(){ 37 | group res; 38 | res.s1=0xffffffffffffffffULL; 39 | res.s2=0xffffffffffffffffULL; 40 | return res; 41 | } 42 | 43 | group static inline FFAND(group a,group b){ 44 | group res; 45 | res.s1=a.s1&b.s1; 46 | res.s2=a.s2&b.s2; 47 | return res; 48 | } 49 | 50 | group static inline FFOR(group a,group b){ 51 | group res; 52 | res.s1=a.s1|b.s1; 53 | res.s2=a.s2|b.s2; 54 | return res; 55 | } 56 | 57 | group static inline FFXOR(group a,group b){ 58 | group res; 59 | res.s1=a.s1^b.s1; 60 | res.s2=a.s2^b.s2; 61 | return res; 62 | } 63 | 64 | group static inline FFNOT(group a){ 65 | group res; 66 | res.s1=~a.s1; 67 | res.s2=~a.s2; 68 | return res; 69 | } 70 | 71 | 72 | /* 64 rows of 128 bits */ 73 | 74 | void static inline FFTABLEIN(unsigned char *tab, int g, unsigned char *data){ 75 | *(((int *)tab)+2*g)=*((int *)data); 76 | *(((int *)tab)+2*g+1)=*(((int *)data)+1); 77 | } 78 | 79 | void static inline FFTABLEOUT(unsigned char *data, unsigned char *tab, int g){ 80 | *((int *)data)=*(((int *)tab)+2*g); 81 | *(((int *)data)+1)=*(((int *)tab)+2*g+1); 82 | } 83 | 84 | void static inline FFTABLEOUTXORNBY(int n, unsigned char *data, unsigned char *tab, int g){ 85 | int j; 86 | for(j=0;j>n; 169 | res.s2=a.s2>>n; 170 | return res; 171 | } 172 | 173 | 174 | void static inline M_EMPTY(void){ 175 | } 176 | -------------------------------------------------------------------------------- /FFDeCsa-1.0.2-Altx/parallel_128_2mmx.h: -------------------------------------------------------------------------------- 1 | /* FFdecsa -- fast decsa algorithm 2 | * 3 | * Copyright (C) 2003-2004 fatih89r 4 | * 5 | * This program is free software; you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation; either version 2 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program; if not, write to the Free Software 17 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 18 | */ 19 | 20 | 21 | #include 22 | 23 | #define MEMALIGN __attribute__((aligned(16))) 24 | 25 | struct group_t{ 26 | __m64 s1,s2; 27 | }; 28 | typedef struct group_t group; 29 | 30 | #define GROUP_PARALLELISM 128 31 | 32 | group static inline FF0(){ 33 | group res; 34 | res.s1=(__m64)0x0ULL; 35 | res.s2=(__m64)0x0ULL; 36 | return res; 37 | } 38 | 39 | group static inline FF1(){ 40 | group res; 41 | res.s1=(__m64)0xffffffffffffffffULL; 42 | res.s2=(__m64)0xffffffffffffffffULL; 43 | return res; 44 | } 45 | 46 | group static inline FFAND(group a,group b){ 47 | group res; 48 | res.s1=_m_pand(a.s1,b.s1); 49 | res.s2=_m_pand(a.s2,b.s2); 50 | return res; 51 | } 52 | 53 | group static inline FFOR(group a,group b){ 54 | group res; 55 | res.s1=_m_por(a.s1,b.s1); 56 | res.s2=_m_por(a.s2,b.s2); 57 | return res; 58 | } 59 | 60 | group static inline FFXOR(group a,group b){ 61 | group res; 62 | res.s1=_m_pxor(a.s1,b.s1); 63 | res.s2=_m_pxor(a.s2,b.s2); 64 | return res; 65 | } 66 | 67 | group static inline FFNOT(group a){ 68 | group res; 69 | res.s1=_m_pxor(a.s1,FF1().s1); 70 | res.s2=_m_pxor(a.s2,FF1().s2); 71 | return res; 72 | } 73 | 74 | 75 | /* 64 rows of 128 bits */ 76 | 77 | void static inline FFTABLEIN(unsigned char *tab, int g, unsigned char *data){ 78 | *(((int *)tab)+2*g)=*((int *)data); 79 | *(((int *)tab)+2*g+1)=*(((int *)data)+1); 80 | } 81 | 82 | void static inline FFTABLEOUT(unsigned char *data, unsigned char *tab, int g){ 83 | *((int *)data)=*(((int *)tab)+2*g); 84 | *(((int *)data)+1)=*(((int *)tab)+2*g+1); 85 | } 86 | 87 | void static inline FFTABLEOUTXORNBY(int n, unsigned char *data, unsigned char *tab, int g){ 88 | int j; 89 | for(j=0;j>n; 199 | res.s2=a.s2>>n; 200 | res.s3=a.s3>>n; 201 | res.s4=a.s4>>n; 202 | return res; 203 | } 204 | 205 | 206 | void static inline M_EMPTY(void){ 207 | } 208 | -------------------------------------------------------------------------------- /FFDeCsa-1.0.2-Altx/parallel_128_sse.h: -------------------------------------------------------------------------------- 1 | /* FFdecsa -- fast decsa algorithm 2 | * 3 | * Copyright (C) 2007 Dark Avenger 4 | * 2003-2004 fatih89r 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 2 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, write to the Free Software 18 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 19 | */ 20 | 21 | 22 | #include 23 | 24 | #define MEMALIGN __attribute__((aligned(16))) 25 | 26 | union __u128 { 27 | unsigned int u[4]; 28 | __m128 v; 29 | }; 30 | 31 | static const union __u128 ff0 = {{0x00000000U, 0x00000000U, 0x00000000U, 0x00000000U}}; 32 | static const union __u128 ff1 = {{0xffffffffU, 0xffffffffU, 0xffffffffU, 0xffffffffU}}; 33 | 34 | typedef __m128 group; 35 | #define GROUP_PARALLELISM 128 36 | #define FF0() ff0.v 37 | #define FF1() ff1.v 38 | #define FFAND(a,b) _mm_and_ps((a),(b)) 39 | #define FFOR(a,b) _mm_or_ps((a),(b)) 40 | #define FFXOR(a,b) _mm_xor_ps((a),(b)) 41 | #define FFNOT(a) _mm_xor_ps((a),FF1()) 42 | #define MALLOC(X) _mm_malloc(X,16) 43 | #define FREE(X) _mm_free(X) 44 | 45 | union __u64 { 46 | unsigned int u[2]; 47 | __m64 v; 48 | }; 49 | 50 | static const union __u64 ff29 = {{0x29292929U, 0x29292929U}}; 51 | static const union __u64 ff02 = {{0x02020202U, 0x02020202U}}; 52 | static const union __u64 ff04 = {{0x04040404U, 0x04040404U}}; 53 | static const union __u64 ff10 = {{0x10101010U, 0x10101010U}}; 54 | static const union __u64 ff40 = {{0x40404040U, 0x40404040U}}; 55 | static const union __u64 ff80 = {{0x80808080U, 0x80808080U}}; 56 | 57 | typedef __m64 batch; 58 | #define BYTES_PER_BATCH 8 59 | #define B_FFN_ALL_29() ff29.v 60 | #define B_FFN_ALL_02() ff02.v 61 | #define B_FFN_ALL_04() ff04.v 62 | #define B_FFN_ALL_10() ff10.v 63 | #define B_FFN_ALL_40() ff40.v 64 | #define B_FFN_ALL_80() ff80.v 65 | #define B_FFAND(a,b) _mm_and_si64((a),(b)) 66 | #define B_FFOR(a,b) _mm_or_si64((a),(b)) 67 | #define B_FFXOR(a,b) _mm_xor_si64((a),(b)) 68 | #define B_FFSH8L(a,n) _mm_slli_si64((a),(n)) 69 | #define B_FFSH8R(a,n) _mm_srli_si64((a),(n)) 70 | 71 | #define M_EMPTY() _mm_empty() 72 | 73 | 74 | #undef XOR_8_BY 75 | #define XOR_8_BY(d,s1,s2) do { *(__m64*)d = _mm_xor_si64(*(__m64*)(s1), *(__m64*)(s2)); } while(0) 76 | 77 | #undef XOREQ_8_BY 78 | #define XOREQ_8_BY(d,s) XOR_8_BY(d, d, s) 79 | 80 | #undef COPY_8_BY 81 | #define COPY_8_BY(d,s) do { *(__m64 *)(d) = *(__m64 *)(s); } while(0) 82 | 83 | #undef BEST_SPAN 84 | #define BEST_SPAN 16 85 | 86 | #undef XOR_BEST_BY 87 | static inline void XOR_BEST_BY(unsigned char *d, unsigned char *s1, unsigned char *s2) 88 | { 89 | __m128 vs1 = _mm_load_ps((float*)s1); 90 | __m128 vs2 = _mm_load_ps((float*)s2); 91 | vs1 = _mm_xor_ps(vs1, vs2); 92 | _mm_store_ps((float*)d, vs1); 93 | } 94 | 95 | #include "fftable.h" 96 | -------------------------------------------------------------------------------- /FFDeCsa-1.0.2-Altx/parallel_128_sse2.h: -------------------------------------------------------------------------------- 1 | /* FFdecsa -- fast decsa algorithm 2 | * 3 | * Copyright (C) 2007 Dark Avenger 4 | * 2003-2004 fatih89r 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 2 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, write to the Free Software 18 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 19 | */ 20 | 21 | #include 22 | 23 | #define MEMALIGN __attribute__((aligned(16))) 24 | 25 | union __u128i { 26 | unsigned int u[4]; 27 | __m128i v; 28 | }; 29 | 30 | static const union __u128i ff0 = {{0x00000000U, 0x00000000U, 0x00000000U, 0x00000000U}}; 31 | static const union __u128i ff1 = {{0xffffffffU, 0xffffffffU, 0xffffffffU, 0xffffffffU}}; 32 | 33 | typedef __m128i group; 34 | #define GROUP_PARALLELISM 128 35 | #define FF0() ff0.v 36 | #define FF1() ff1.v 37 | #define FFAND(a,b) _mm_and_si128((a),(b)) 38 | #define FFOR(a,b) _mm_or_si128((a),(b)) 39 | #define FFXOR(a,b) _mm_xor_si128((a),(b)) 40 | #define FFNOT(a) _mm_xor_si128((a),FF1()) 41 | #define MALLOC(X) _mm_malloc(X,16) 42 | #define FREE(X) _mm_free(X) 43 | 44 | /* BATCH */ 45 | 46 | static const union __u128i ff29 = {{0x29292929U, 0x29292929U, 0x29292929U, 0x29292929U}}; 47 | static const union __u128i ff02 = {{0x02020202U, 0x02020202U, 0x02020202U, 0x02020202U}}; 48 | static const union __u128i ff04 = {{0x04040404U, 0x04040404U, 0x04040404U, 0x04040404U}}; 49 | static const union __u128i ff10 = {{0x10101010U, 0x10101010U, 0x10101010U, 0x10101010U}}; 50 | static const union __u128i ff40 = {{0x40404040U, 0x40404040U, 0x40404040U, 0x40404040U}}; 51 | static const union __u128i ff80 = {{0x80808080U, 0x80808080U, 0x80808080U, 0x80808080U}}; 52 | 53 | typedef __m128i batch; 54 | #define BYTES_PER_BATCH 16 55 | #define B_FFN_ALL_29() ff29.v 56 | #define B_FFN_ALL_02() ff02.v 57 | #define B_FFN_ALL_04() ff04.v 58 | #define B_FFN_ALL_10() ff10.v 59 | #define B_FFN_ALL_40() ff40.v 60 | #define B_FFN_ALL_80() ff80.v 61 | 62 | #define B_FFAND(a,b) FFAND(a,b) 63 | #define B_FFOR(a,b) FFOR(a,b) 64 | #define B_FFXOR(a,b) FFXOR(a,b) 65 | #define B_FFSH8L(a,n) _mm_slli_epi64((a),(n)) 66 | #define B_FFSH8R(a,n) _mm_srli_epi64((a),(n)) 67 | 68 | #define M_EMPTY() 69 | 70 | #undef BEST_SPAN 71 | #define BEST_SPAN 16 72 | 73 | #undef XOR_BEST_BY 74 | static inline void XOR_BEST_BY(unsigned char *d, unsigned char *s1, unsigned char *s2) 75 | { 76 | __m128i vs1 = _mm_load_si128((__m128i*)s1); 77 | __m128i vs2 = _mm_load_si128((__m128i*)s2); 78 | vs1 = _mm_xor_si128(vs1, vs2); 79 | _mm_store_si128((__m128i*)d, vs1); 80 | } 81 | 82 | #include "fftable.h" 83 | -------------------------------------------------------------------------------- /FFDeCsa-1.0.2-Altx/parallel_generic.h: -------------------------------------------------------------------------------- 1 | /* FFdecsa -- fast decsa algorithm 2 | * 3 | * Copyright (C) 2003-2004 fatih89r 4 | * 5 | * This program is free software; you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation; either version 2 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program; if not, write to the Free Software 17 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 18 | */ 19 | 20 | 21 | 22 | #if 0 23 | //// generics 24 | #define COPY4BY(d,s) do{ int *pd=(int *)(d), *ps=(int *)(s); \ 25 | *pd = *ps; }while(0) 26 | #define COPY8BY(d,s) do{ long long int *pd=(long long int *)(d), *ps=(long long int *)(s); \ 27 | *pd = *ps; }while(0) 28 | #define COPY16BY(d,s) do{ long long int *pd=(long long int *)(d), *ps=(long long int *)(s); \ 29 | *pd = *ps; \ 30 | *(pd+1) = *(ps+1); }while(0) 31 | #define COPY32BY(d,s) do{ long long int *pd=(long long int *)(d), *ps=(long long int *)(s); \ 32 | *pd = *ps; \ 33 | *(pd+1) = *(ps+1) \ 34 | *(pd+2) = *(ps+2) \ 35 | *(pd+3) = *(ps+3); }while(0) 36 | #define XOR4BY(d,s1,s2) do{ int *pd=(int *)(d), *ps1=(int *)(s1), *ps2=(int *)(s2); \ 37 | *pd = *ps1 ^ *ps2; }while(0) 38 | #define XOR8BY(d,s1,s2) do{ long long int *pd=(long long int *)(d), *ps1=(long long int *)(s1), *ps2=(long long int *)(s2); \ 39 | *pd = *ps1 ^ *ps2; }while(0) 40 | #define XOR16BY(d,s1,s2) do{ long long int *pd=(long long int *)(d), *ps1=(long long int *)(s1), *ps2=(long long int *)(s2); \ 41 | *pd = *ps1 ^ *ps2; \ 42 | *(pd+8) = *(ps1+8) ^ *(ps2+8); }while(0) 43 | #define XOR32BY(d,s1,s2) do{ long long int *pd=(long long int *)(d), *ps1=(long long int *)(s1), *ps2=(long long int *)(s2); \ 44 | *pd = *ps1 ^ *ps2; \ 45 | *(pd+1) = *(ps1+1) ^ *(ps2+1); \ 46 | *(pd+2) = *(ps1+2) ^ *(ps2+2); \ 47 | *(pd+3) = *(ps1+3) ^ *(ps2+3); }while(0) 48 | #define XOR32BV(d,s1,s2) do{ int *const pd=(int *const)(d), *ps1=(const int *const)(s1), *ps2=(const int *const)(s2); \ 49 | int z; \ 50 | for(z=0;z<8;z++){ \ 51 | pd[z]=ps1[z]^ps2[z]; \ 52 | } \ 53 | }while(0) 54 | #define XOREQ4BY(d,s) do{ int *pd=(int *)(d), *ps=(int *)(s); \ 55 | *pd ^= *ps; }while(0) 56 | #define XOREQ8BY(d,s) do{ long long int *pd=(long long int *)(d), *ps=(long long int *)(s); \ 57 | *pd ^= *ps; }while(0) 58 | #define XOREQ16BY(d,s) do{ long long int *pd=(long long int *)(d), *ps=(long long int *)(s); \ 59 | *pd ^= *ps; \ 60 | *(pd+1) ^=*(ps+1); }while(0) 61 | #define XOREQ32BY(d,s) do{ long long int *pd=(long long int *)(d), *ps=(long long int *)(s); \ 62 | *pd ^= *ps; \ 63 | *(pd+1) ^=*(ps+1); \ 64 | *(pd+2) ^=*(ps+2); \ 65 | *(pd+3) ^=*(ps+3); }while(0) 66 | #define XOREQ32BY4(d,s) do{ int *pd=(int *)(d), *ps=(int *)(s); \ 67 | *pd ^= *ps; \ 68 | *(pd+1) ^=*(ps+1); \ 69 | *(pd+2) ^=*(ps+2); \ 70 | *(pd+3) ^=*(ps+3); \ 71 | *(pd+4) ^=*(ps+4); \ 72 | *(pd+5) ^=*(ps+5); \ 73 | *(pd+6) ^=*(ps+6); \ 74 | *(pd+7) ^=*(ps+7); }while(0) 75 | #define XOREQ32BV(d,s) do{ unsigned char *pd=(unsigned char *)(d), *ps=(unsigned char *)(s); \ 76 | int z; \ 77 | for(z=0;z<32;z++){ \ 78 | pd[z]^=ps[z]; \ 79 | } \ 80 | }while(0) 81 | 82 | #else 83 | #define XOR_4_BY(d,s1,s2) do{ int *pd=(int *)(d), *ps1=(int *)(s1), *ps2=(int *)(s2); \ 84 | *pd = *ps1 ^ *ps2; }while(0) 85 | #define XOR_8_BY(d,s1,s2) do{ long long int *pd=(long long int *)(d), *ps1=(long long int *)(s1), *ps2=(long long int *)(s2); \ 86 | *pd = *ps1 ^ *ps2; }while(0) 87 | #define XOREQ_4_BY(d,s) do{ int *pd=(int *)(d), *ps=(int *)(s); \ 88 | *pd ^= *ps; }while(0) 89 | #define XOREQ_8_BY(d,s) do{ long long int *pd=(long long int *)(d), *ps=(long long int *)(s); \ 90 | *pd ^= *ps; }while(0) 91 | #define COPY_4_BY(d,s) do{ int *pd=(int *)(d), *ps=(int *)(s); \ 92 | *pd = *ps; }while(0) 93 | #define COPY_8_BY(d,s) do{ long long int *pd=(long long int *)(d), *ps=(long long int *)(s); \ 94 | *pd = *ps; }while(0) 95 | 96 | #define BEST_SPAN 8 97 | #define XOR_BEST_BY(d,s1,s2) do{ XOR_8_BY(d,s1,s2); }while(0); 98 | #define XOREQ_BEST_BY(d,s) do{ XOREQ_8_BY(d,s); }while(0); 99 | #define COPY_BEST_BY(d,s) do{ COPY_8_BY(d,s); }while(0); 100 | 101 | #define END_MM do{ }while(0); 102 | #endif 103 | -------------------------------------------------------------------------------- /FFDeCsa-1.0.2-Altx/parallel_std_def.h: -------------------------------------------------------------------------------- 1 | /* FFdecsa -- fast decsa algorithm 2 | * 3 | * Copyright (C) 2003-2004 fatih89r 4 | * 5 | * This program is free software; you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation; either version 2 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program; if not, write to the Free Software 17 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 18 | */ 19 | 20 | #define FFXOR(a,b) ((a)^(b)) 21 | #define FFAND(a,b) ((a)&(b)) 22 | #define FFOR(a,b) ((a)|(b)) 23 | #define FFNOT(a) (~(a)) 24 | 25 | #define B_FFAND(a,b) ((a)&(b)) 26 | #define B_FFOR(a,b) ((a)|(b)) 27 | #define B_FFXOR(a,b) ((a)^(b)) 28 | #define B_FFSH8L(a,n) ((a)<<(n)) 29 | #define B_FFSH8R(a,n) ((a)>>(n)) 30 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 2, June 1991 3 | 4 | Copyright (C) 1989, 1991 Free Software Foundation, Inc., 5 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 6 | Everyone is permitted to copy and distribute verbatim copies 7 | of this license document, but changing it is not allowed. 8 | 9 | Preamble 10 | 11 | The licenses for most software are designed to take away your 12 | freedom to share and change it. By contrast, the GNU General Public 13 | License is intended to guarantee your freedom to share and change free 14 | software--to make sure the software is free for all its users. This 15 | General Public License applies to most of the Free Software 16 | Foundation's software and to any other program whose authors commit to 17 | using it. (Some other Free Software Foundation software is covered by 18 | the GNU Lesser General Public License instead.) You can apply it to 19 | your programs, too. 20 | 21 | When we speak of free software, we are referring to freedom, not 22 | price. Our General Public Licenses are designed to make sure that you 23 | have the freedom to distribute copies of free software (and charge for 24 | this service if you wish), that you receive source code or can get it 25 | if you want it, that you can change the software or use pieces of it 26 | in new free programs; and that you know you can do these things. 27 | 28 | To protect your rights, we need to make restrictions that forbid 29 | anyone to deny you these rights or to ask you to surrender the rights. 30 | These restrictions translate to certain responsibilities for you if you 31 | distribute copies of the software, or if you modify it. 32 | 33 | For example, if you distribute copies of such a program, whether 34 | gratis or for a fee, you must give the recipients all the rights that 35 | you have. You must make sure that they, too, receive or can get the 36 | source code. And you must show them these terms so they know their 37 | rights. 38 | 39 | We protect your rights with two steps: (1) copyright the software, and 40 | (2) offer you this license which gives you legal permission to copy, 41 | distribute and/or modify the software. 42 | 43 | Also, for each author's protection and ours, we want to make certain 44 | that everyone understands that there is no warranty for this free 45 | software. If the software is modified by someone else and passed on, we 46 | want its recipients to know that what they have is not the original, so 47 | that any problems introduced by others will not reflect on the original 48 | authors' reputations. 49 | 50 | Finally, any free program is threatened constantly by software 51 | patents. We wish to avoid the danger that redistributors of a free 52 | program will individually obtain patent licenses, in effect making the 53 | program proprietary. To prevent this, we have made it clear that any 54 | patent must be licensed for everyone's free use or not licensed at all. 55 | 56 | The precise terms and conditions for copying, distribution and 57 | modification follow. 58 | 59 | GNU GENERAL PUBLIC LICENSE 60 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 61 | 62 | 0. This License applies to any program or other work which contains 63 | a notice placed by the copyright holder saying it may be distributed 64 | under the terms of this General Public License. The "Program", below, 65 | refers to any such program or work, and a "work based on the Program" 66 | means either the Program or any derivative work under copyright law: 67 | that is to say, a work containing the Program or a portion of it, 68 | either verbatim or with modifications and/or translated into another 69 | language. (Hereinafter, translation is included without limitation in 70 | the term "modification".) Each licensee is addressed as "you". 71 | 72 | Activities other than copying, distribution and modification are not 73 | covered by this License; they are outside its scope. The act of 74 | running the Program is not restricted, and the output from the Program 75 | is covered only if its contents constitute a work based on the 76 | Program (independent of having been made by running the Program). 77 | Whether that is true depends on what the Program does. 78 | 79 | 1. You may copy and distribute verbatim copies of the Program's 80 | source code as you receive it, in any medium, provided that you 81 | conspicuously and appropriately publish on each copy an appropriate 82 | copyright notice and disclaimer of warranty; keep intact all the 83 | notices that refer to this License and to the absence of any warranty; 84 | and give any other recipients of the Program a copy of this License 85 | along with the Program. 86 | 87 | You may charge a fee for the physical act of transferring a copy, and 88 | you may at your option offer warranty protection in exchange for a fee. 89 | 90 | 2. You may modify your copy or copies of the Program or any portion 91 | of it, thus forming a work based on the Program, and copy and 92 | distribute such modifications or work under the terms of Section 1 93 | above, provided that you also meet all of these conditions: 94 | 95 | a) You must cause the modified files to carry prominent notices 96 | stating that you changed the files and the date of any change. 97 | 98 | b) You must cause any work that you distribute or publish, that in 99 | whole or in part contains or is derived from the Program or any 100 | part thereof, to be licensed as a whole at no charge to all third 101 | parties under the terms of this License. 102 | 103 | c) If the modified program normally reads commands interactively 104 | when run, you must cause it, when started running for such 105 | interactive use in the most ordinary way, to print or display an 106 | announcement including an appropriate copyright notice and a 107 | notice that there is no warranty (or else, saying that you provide 108 | a warranty) and that users may redistribute the program under 109 | these conditions, and telling the user how to view a copy of this 110 | License. (Exception: if the Program itself is interactive but 111 | does not normally print such an announcement, your work based on 112 | the Program is not required to print an announcement.) 113 | 114 | These requirements apply to the modified work as a whole. If 115 | identifiable sections of that work are not derived from the Program, 116 | and can be reasonably considered independent and separate works in 117 | themselves, then this License, and its terms, do not apply to those 118 | sections when you distribute them as separate works. But when you 119 | distribute the same sections as part of a whole which is a work based 120 | on the Program, the distribution of the whole must be on the terms of 121 | this License, whose permissions for other licensees extend to the 122 | entire whole, and thus to each and every part regardless of who wrote it. 123 | 124 | Thus, it is not the intent of this section to claim rights or contest 125 | your rights to work written entirely by you; rather, the intent is to 126 | exercise the right to control the distribution of derivative or 127 | collective works based on the Program. 128 | 129 | In addition, mere aggregation of another work not based on the Program 130 | with the Program (or with a work based on the Program) on a volume of 131 | a storage or distribution medium does not bring the other work under 132 | the scope of this License. 133 | 134 | 3. You may copy and distribute the Program (or a work based on it, 135 | under Section 2) in object code or executable form under the terms of 136 | Sections 1 and 2 above provided that you also do one of the following: 137 | 138 | a) Accompany it with the complete corresponding machine-readable 139 | source code, which must be distributed under the terms of Sections 140 | 1 and 2 above on a medium customarily used for software interchange; or, 141 | 142 | b) Accompany it with a written offer, valid for at least three 143 | years, to give any third party, for a charge no more than your 144 | cost of physically performing source distribution, a complete 145 | machine-readable copy of the corresponding source code, to be 146 | distributed under the terms of Sections 1 and 2 above on a medium 147 | customarily used for software interchange; or, 148 | 149 | c) Accompany it with the information you received as to the offer 150 | to distribute corresponding source code. (This alternative is 151 | allowed only for noncommercial distribution and only if you 152 | received the program in object code or executable form with such 153 | an offer, in accord with Subsection b above.) 154 | 155 | The source code for a work means the preferred form of the work for 156 | making modifications to it. For an executable work, complete source 157 | code means all the source code for all modules it contains, plus any 158 | associated interface definition files, plus the scripts used to 159 | control compilation and installation of the executable. However, as a 160 | special exception, the source code distributed need not include 161 | anything that is normally distributed (in either source or binary 162 | form) with the major components (compiler, kernel, and so on) of the 163 | operating system on which the executable runs, unless that component 164 | itself accompanies the executable. 165 | 166 | If distribution of executable or object code is made by offering 167 | access to copy from a designated place, then offering equivalent 168 | access to copy the source code from the same place counts as 169 | distribution of the source code, even though third parties are not 170 | compelled to copy the source along with the object code. 171 | 172 | 4. You may not copy, modify, sublicense, or distribute the Program 173 | except as expressly provided under this License. Any attempt 174 | otherwise to copy, modify, sublicense or distribute the Program is 175 | void, and will automatically terminate your rights under this License. 176 | However, parties who have received copies, or rights, from you under 177 | this License will not have their licenses terminated so long as such 178 | parties remain in full compliance. 179 | 180 | 5. You are not required to accept this License, since you have not 181 | signed it. However, nothing else grants you permission to modify or 182 | distribute the Program or its derivative works. These actions are 183 | prohibited by law if you do not accept this License. Therefore, by 184 | modifying or distributing the Program (or any work based on the 185 | Program), you indicate your acceptance of this License to do so, and 186 | all its terms and conditions for copying, distributing or modifying 187 | the Program or works based on it. 188 | 189 | 6. Each time you redistribute the Program (or any work based on the 190 | Program), the recipient automatically receives a license from the 191 | original licensor to copy, distribute or modify the Program subject to 192 | these terms and conditions. You may not impose any further 193 | restrictions on the recipients' exercise of the rights granted herein. 194 | You are not responsible for enforcing compliance by third parties to 195 | this License. 196 | 197 | 7. If, as a consequence of a court judgment or allegation of patent 198 | infringement or for any other reason (not limited to patent issues), 199 | conditions are imposed on you (whether by court order, agreement or 200 | otherwise) that contradict the conditions of this License, they do not 201 | excuse you from the conditions of this License. If you cannot 202 | distribute so as to satisfy simultaneously your obligations under this 203 | License and any other pertinent obligations, then as a consequence you 204 | may not distribute the Program at all. For example, if a patent 205 | license would not permit royalty-free redistribution of the Program by 206 | all those who receive copies directly or indirectly through you, then 207 | the only way you could satisfy both it and this License would be to 208 | refrain entirely from distribution of the Program. 209 | 210 | If any portion of this section is held invalid or unenforceable under 211 | any particular circumstance, the balance of the section is intended to 212 | apply and the section as a whole is intended to apply in other 213 | circumstances. 214 | 215 | It is not the purpose of this section to induce you to infringe any 216 | patents or other property right claims or to contest validity of any 217 | such claims; this section has the sole purpose of protecting the 218 | integrity of the free software distribution system, which is 219 | implemented by public license practices. Many people have made 220 | generous contributions to the wide range of software distributed 221 | through that system in reliance on consistent application of that 222 | system; it is up to the author/donor to decide if he or she is willing 223 | to distribute software through any other system and a licensee cannot 224 | impose that choice. 225 | 226 | This section is intended to make thoroughly clear what is believed to 227 | be a consequence of the rest of this License. 228 | 229 | 8. If the distribution and/or use of the Program is restricted in 230 | certain countries either by patents or by copyrighted interfaces, the 231 | original copyright holder who places the Program under this License 232 | may add an explicit geographical distribution limitation excluding 233 | those countries, so that distribution is permitted only in or among 234 | countries not thus excluded. In such case, this License incorporates 235 | the limitation as if written in the body of this License. 236 | 237 | 9. The Free Software Foundation may publish revised and/or new versions 238 | of the General Public License from time to time. Such new versions will 239 | be similar in spirit to the present version, but may differ in detail to 240 | address new problems or concerns. 241 | 242 | Each version is given a distinguishing version number. If the Program 243 | specifies a version number of this License which applies to it and "any 244 | later version", you have the option of following the terms and conditions 245 | either of that version or of any later version published by the Free 246 | Software Foundation. If the Program does not specify a version number of 247 | this License, you may choose any version ever published by the Free Software 248 | Foundation. 249 | 250 | 10. If you wish to incorporate parts of the Program into other free 251 | programs whose distribution conditions are different, write to the author 252 | to ask for permission. For software which is copyrighted by the Free 253 | Software Foundation, write to the Free Software Foundation; we sometimes 254 | make exceptions for this. Our decision will be guided by the two goals 255 | of preserving the free status of all derivatives of our free software and 256 | of promoting the sharing and reuse of software generally. 257 | 258 | NO WARRANTY 259 | 260 | 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY 261 | FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN 262 | OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES 263 | PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED 264 | OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 265 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS 266 | TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE 267 | PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, 268 | REPAIR OR CORRECTION. 269 | 270 | 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 271 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR 272 | REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, 273 | INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING 274 | OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED 275 | TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY 276 | YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER 277 | PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE 278 | POSSIBILITY OF SUCH DAMAGES. 279 | 280 | END OF TERMS AND CONDITIONS 281 | 282 | How to Apply These Terms to Your New Programs 283 | 284 | If you develop a new program, and you want it to be of the greatest 285 | possible use to the public, the best way to achieve this is to make it 286 | free software which everyone can redistribute and change under these terms. 287 | 288 | To do so, attach the following notices to the program. It is safest 289 | to attach them to the start of each source file to most effectively 290 | convey the exclusion of warranty; and each file should have at least 291 | the "copyright" line and a pointer to where the full notice is found. 292 | 293 | 294 | Copyright (C) 295 | 296 | This program is free software; you can redistribute it and/or modify 297 | it under the terms of the GNU General Public License as published by 298 | the Free Software Foundation; either version 2 of the License, or 299 | (at your option) any later version. 300 | 301 | This program is distributed in the hope that it will be useful, 302 | but WITHOUT ANY WARRANTY; without even the implied warranty of 303 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 304 | GNU General Public License for more details. 305 | 306 | You should have received a copy of the GNU General Public License along 307 | with this program; if not, write to the Free Software Foundation, Inc., 308 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 309 | 310 | Also add information on how to contact you by electronic and paper mail. 311 | 312 | If the program is interactive, make it output a short notice like this 313 | when it starts in an interactive mode: 314 | 315 | Gnomovision version 69, Copyright (C) year name of author 316 | Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 317 | This is free software, and you are welcome to redistribute it 318 | under certain conditions; type `show c' for details. 319 | 320 | The hypothetical commands `show w' and `show c' should show the appropriate 321 | parts of the General Public License. Of course, the commands you use may 322 | be called something other than `show w' and `show c'; they could even be 323 | mouse-clicks or menu items--whatever suits your program. 324 | 325 | You should also get your employer (if you work as a programmer) or your 326 | school, if any, to sign a "copyright disclaimer" for the program, if 327 | necessary. Here is a sample; alter the names: 328 | 329 | Yoyodyne, Inc., hereby disclaims all copyright interest in the program 330 | `Gnomovision' (which makes passes at compilers) written by James Hacker. 331 | 332 | , 1 April 1989 333 | Ty Coon, President of Vice 334 | 335 | This General Public License does not permit incorporating your program into 336 | proprietary programs. If your program is a subroutine library, you may 337 | consider it more useful to permit linking proprietary applications with the 338 | library. If this is what you want to do, use the GNU Lesser General 339 | Public License instead of this License. 340 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # TSDecrypt 2 | 一个Windows GUI软件,通过调用 [FFdecsa](https://github.com/nilaoda/TSDecrypt/tree/main/FFDeCsa-1.0.2-Altx) 来实现CSA加扰TS文件的高性能解扰. 目前已初步实现基本功能. 3 | 4 | ![image](Screens/Snipaste_2023-02-11_01-53-41.jpg) 5 | 6 | 7 | # Performance 8 | * `x86` 机器使用 `PARALLEL_064_MMX` ,在主流CPU上解密速度可达**110MB/s**. 9 | * `x64` 机器使用 `PARALLEL_128_2LONG` ,在主流CPU上解密速度可达**190MB/s**. 10 | 11 | 输入`benchmark`以测试当前机器最大解密速度 12 | 13 | ![image](Screens/Snipaste_2023-02-12_02-19-06.jpg) 14 | 15 | # Compile dll on Windows 16 | * `x86` https://sourceforge.net/projects/mingw/ 17 | * `x64` https://winlibs.com/ 18 | 19 | # Command Line 20 | ``` 21 | TSDecryptGUI [OPTIONS] 22 | --output-file Set output file 23 | --output-dir Set output directory 24 | --key Set decryption key 25 | --auto Auto decrypt, then close 26 | --del Delete source after done 27 | --no-check Do not check CW 28 | ``` 29 | 30 | # Batch Jobs 31 | Create `.bat` file, write command one by one: 32 | ```bat 33 | :: Target file: D:\FEED_1_dec.ts 34 | start /wait TSDecryptGUI.exe D:\FEED_1.ts --key 2021084925aaaa79 --auto 35 | 36 | :: Delete source after decryption. Target file: G:\DEC\FEED_2_dec.ts 37 | start /wait TSDecryptGUI.exe D:\FEED_2.ts --key 2022014317aacc8d --output-dir G:\DEC --auto --del 38 | 39 | :: Set output file. Target file: G:\DEC\3.ts 40 | start /wait TSDecryptGUI.exe D:\FEED_3.ts --key 2022014317aacc8d --output-file G:\DEC\3.ts --auto --del 41 | ``` 42 | Run `.bat` 43 | 44 | 45 | # Thanks 46 | 47 | **fatih89r**, 48 | **Altx**, 49 | **hez2010** 50 | -------------------------------------------------------------------------------- /Screens/Snipaste_2023-02-11_01-53-41.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nilaoda/TSDecrypt/15a516e51ab1dfa8e2a5f3692c3634ac9ec381b3/Screens/Snipaste_2023-02-11_01-53-41.jpg -------------------------------------------------------------------------------- /Screens/Snipaste_2023-02-12_02-19-06.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nilaoda/TSDecrypt/15a516e51ab1dfa8e2a5f3692c3634ac9ec381b3/Screens/Snipaste_2023-02-12_02-19-06.jpg -------------------------------------------------------------------------------- /TSDecryptGUI/App.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /TSDecryptGUI/App.xaml: -------------------------------------------------------------------------------- 1 |  6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /TSDecryptGUI/App.xaml.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Configuration; 4 | using System.Data; 5 | using System.Linq; 6 | using System.Threading.Tasks; 7 | using System.Windows; 8 | 9 | namespace TSDecryptGUI 10 | { 11 | /// 12 | /// App.xaml 的交互逻辑 13 | /// 14 | public partial class App : Application 15 | { 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /TSDecryptGUI/BenchmarkUtil.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Diagnostics; 4 | using System.IO; 5 | using System.Linq; 6 | using System.Text; 7 | using System.Threading.Tasks; 8 | using System.Windows; 9 | 10 | namespace TSDecryptGUI 11 | { 12 | internal class BenchmarkUtil 13 | { 14 | static int PACKET_SIZE = 188; 15 | static int TS_PKTS_FOR_TEST = 500 * 1000; 16 | static string test_2_key = "2022014317aacc8d"; 17 | static byte[] test_2_encrypted = { 18 | 0x47, 0x40, 0x21, 0x91, 0x2A, 0xFA, 0xA8, 0x84, 0x09, 0x9F, 0x86, 0x68, 0xCD, 0x16, 0xA0, 0x4E, 19 | 0xC2, 0x58, 0x2E, 0xA3, 0xCC, 0x00, 0x0F, 0x5A, 0xD6, 0x9B, 0x07, 0x83, 0x67, 0x79, 0x94, 0xE0, 20 | 0x55, 0xB8, 0xA9, 0xF0, 0x85, 0xE1, 0xE9, 0x5F, 0x5C, 0xA4, 0xBC, 0x24, 0x24, 0xA8, 0x0D, 0x98, 21 | 0xFF, 0xA7, 0xCE, 0x1D, 0x52, 0xE5, 0x12, 0xDE, 0xC1, 0x74, 0x1D, 0xD1, 0xFF, 0xBD, 0x89, 0xC6, 22 | 0x10, 0x66, 0x42, 0xE0, 0x28, 0x0A, 0x53, 0xF8, 0xAB, 0xC1, 0xE8, 0xF2, 0x65, 0xD4, 0xE6, 0x50, 23 | 0xE8, 0x1D, 0x92, 0x24, 0x2C, 0x73, 0xE4, 0x2D, 0x83, 0x97, 0xBD, 0x94, 0xED, 0x97, 0xF4, 0x2A, 24 | 0x12, 0xB1, 0x4D, 0xC0, 0x4B, 0x38, 0x89, 0x31, 0x97, 0x99, 0x4E, 0xF9, 0xF2, 0x8E, 0x90, 0x34, 25 | 0x9B, 0x37, 0xC8, 0xCB, 0xA3, 0x5F, 0x20, 0x8F, 0x5C, 0xF2, 0x91, 0xDB, 0xA8, 0x46, 0x1B, 0x6B, 26 | 0x9D, 0xFB, 0xCC, 0x18, 0x89, 0x9C, 0x02, 0x5D, 0xA0, 0xE8, 0x5C, 0x83, 0xDD, 0x73, 0xF4, 0xCC, 27 | 0x36, 0x9A, 0xB7, 0xD0, 0xB9, 0x06, 0xE2, 0xE3, 0xC3, 0x5E, 0xA7, 0x71, 0x11, 0xB1, 0xDF, 0x0C, 28 | 0xEB, 0x07, 0x03, 0x7F, 0xFE, 0x43, 0x1B, 0xC0, 0x42, 0xB6, 0x09, 0xC5, 0xBF, 0xD5, 0xCA, 0x23, 29 | 0xAA, 0x41, 0xA1, 0xAA, 0xEE, 0x68, 0xAC, 0xE1, 0x8F, 0xD6, 0x13, 0x3F 30 | }; 31 | 32 | public static void Run(Action action) 33 | { 34 | var encrypted = new byte[PACKET_SIZE * TS_PKTS_FOR_TEST]; 35 | for (int i = 0; i < TS_PKTS_FOR_TEST; i++) 36 | { 37 | Array.Copy(test_2_encrypted, 0, encrypted, i * PACKET_SIZE, PACKET_SIZE); 38 | } 39 | 40 | var stopwatch = new Stopwatch(); 41 | stopwatch.Start(); 42 | 43 | using (var stream = new MemoryStream(encrypted)) 44 | { 45 | var tsdecrypt = new TSDecrypt(); 46 | tsdecrypt.SetKey(test_2_key); 47 | var readSize = 0; 48 | var buffer = new byte[PACKET_SIZE * tsdecrypt.PARALL_SIZE]; // MAX TS Packets 49 | while ((readSize = stream.Read(buffer, 0, buffer.Length)) > 0) 50 | { 51 | tsdecrypt.DecryptBytes(readSize, ref buffer); 52 | } 53 | } 54 | 55 | stopwatch.Stop(); 56 | 57 | action(encrypted.Length, stopwatch.ElapsedMilliseconds); 58 | } 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /TSDecryptGUI/MainWindow.xaml: -------------------------------------------------------------------------------- 1 |  9 | 10 | 11 | 12 | 13 | 14 | 15 | 18 | 19 | 20 | 输入TS文件(请拖入或选择) 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 35 | 36 | 37 | 输出TS文件(请拖入或选择) 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 解密选项 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | KEY: 72 | 73 | Pkts Offset: 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 刷新间隔: 84 | 85 | Pkts Limit: 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 其他选项: 97 | 解密后删除 98 | 验证CW正确性 99 | 实时验证解密结果 100 | 101 | 解密状态: 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | -------------------------------------------------------------------------------- /TSDecryptGUI/MainWindow.xaml.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.Win32; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.IO; 5 | using System.Linq; 6 | using System.Threading.Tasks; 7 | using System.Timers; 8 | using System.Windows; 9 | using System.Windows.Controls; 10 | 11 | namespace TSDecryptGUI 12 | { 13 | /// 14 | /// MainWindow.xaml 的交互逻辑 15 | /// 16 | public partial class MainWindow : Window 17 | { 18 | const int PACKET_SIZE = 188; 19 | 20 | 21 | bool DONE = false; 22 | long TOTOAL_SIZE = 0; //文件总大小 23 | long DE_SIZE = 0; //已解密大小 24 | long LAST_SIZE = 0; 25 | double TIME_SPAN = 0; //耗时 26 | long MESS_COUNT = 0; //解密错误时此值会增加 27 | Timer tmr = new Timer() 28 | { 29 | AutoReset = true 30 | }; 31 | 32 | 33 | bool EXIT_AFTER_DONE = false; 34 | bool DELETE_AFTER_DONE = false; 35 | bool OVER_WRITTEN = false; 36 | bool REALTIME_CHECK = false; //实时检测正确性 37 | 38 | 39 | public MainWindow() 40 | { 41 | InitializeComponent(); 42 | try 43 | { 44 | /** 45 | * COMMAND LINE: 46 | * TSDecryptGUI [OPTIONS] 47 | * --output-file Set output file 48 | * --output-dir Set output directory 49 | * --key Set decryption key 50 | * --auto Auto decrypt, then close 51 | * --del Delete source after done 52 | * --no-check Do not check CW 53 | */ 54 | #region 解密命令行 55 | var args = new List(Environment.GetCommandLineArgs()); 56 | if (args.Count > 1 && File.Exists(args[1]) && Path.GetExtension(args[1]).ToLower() == ".ts") 57 | { 58 | //输入文件 59 | Txt_InputFile.Text = Path.GetFullPath(args[1]); 60 | //输出文件 61 | var i1 = args.IndexOf("--output-file"); 62 | var ii1 = args.IndexOf("--output-dir"); 63 | if (i1 >= 0) 64 | { 65 | Txt_OutputFile.Text = Path.GetFullPath(args[i1 + 1]); 66 | } 67 | //输出文件夹 68 | else if (ii1 > 0 && Directory.Exists(args[ii1 + 1])) 69 | { 70 | ChangeOutputFile(args[ii1 + 1]); 71 | } 72 | else 73 | { 74 | ChangeOutputFile(Path.GetDirectoryName(Txt_InputFile.Text)); 75 | } 76 | //KEY 77 | var i2 = args.IndexOf("--key"); 78 | if (i2 > 0) 79 | { 80 | var key = args[i2 + 1]; 81 | Txt_InputKey.Text = key; 82 | } 83 | //自动删除 84 | if (args.Contains("--del")) 85 | { 86 | DELETE_AFTER_DONE = true; 87 | } 88 | //自动关闭 89 | if (args.Contains("--auto")) 90 | { 91 | EXIT_AFTER_DONE = true; 92 | OVER_WRITTEN = true; 93 | Btn_DoDecrypt.RaiseEvent(new RoutedEventArgs(Button.ClickEvent)); 94 | } 95 | //不检测 96 | if (args.Contains("--no-check")) 97 | { 98 | Chk_CheckCW.IsChecked = false; 99 | } 100 | } 101 | #endregion 102 | } 103 | catch (Exception) { } 104 | } 105 | 106 | public delegate void Handler(); 107 | 108 | /// 109 | /// 根据输入文件设置输出文件全路径 110 | /// 111 | /// 输出文件目录 112 | private void ChangeOutputFile(string dir) 113 | { 114 | var input = Txt_InputFile.Text.Split(';').First(); 115 | Txt_OutputFile.Text = Path.Combine(dir, Path.GetFileNameWithoutExtension(input) + "_dec" + Path.GetExtension(input)); 116 | } 117 | 118 | private void SelectedFile(UIElement ele, Handler any = null, bool multiFile = false) 119 | { 120 | var textbox = ele as TextBox; 121 | OpenFileDialog openFileDialog = new OpenFileDialog(); 122 | openFileDialog.Filter = "MPEG-TS文件(*.ts)|*.ts"; 123 | openFileDialog.Multiselect = multiFile; 124 | if (openFileDialog.ShowDialog() == true) 125 | { 126 | textbox.Text = openFileDialog.FileName; 127 | if (any != null) any(); 128 | } 129 | } 130 | 131 | private void Btn_SelectFile_Click(object sender, RoutedEventArgs e) 132 | { 133 | SelectedFile(Txt_InputFile, () => 134 | { 135 | ChangeOutputFile(Path.GetDirectoryName(Txt_InputFile.Text.Split(';').First())); 136 | }, true); 137 | } 138 | 139 | private void Btn_SelectOutputFile_Click(object sender, RoutedEventArgs e) 140 | { 141 | if (string.IsNullOrEmpty(Txt_InputFile.Text) || !File.Exists(Txt_InputFile.Text)) 142 | { 143 | MessageUtil.AlertInfo("请确保输入文件正确!"); 144 | return; 145 | } 146 | SelectedFile(Txt_OutputFile); 147 | } 148 | 149 | private void GroupBox_Input_PreviewDragOver(object sender, DragEventArgs e) 150 | { 151 | e.Handled = true; 152 | } 153 | 154 | private void GroupBox_Input_Drop(object sender, DragEventArgs e) 155 | { 156 | if (e.Data.GetDataPresent(DataFormats.FileDrop)) 157 | { 158 | string[] files = (string[])e.Data.GetData(DataFormats.FileDrop); 159 | var ts = files.Where(f => Path.GetExtension(f).ToUpper() == ".TS"); 160 | if (ts.Any()) 161 | { 162 | //按住Ctrl键时 新增文件 163 | if (e.KeyStates == DragDropKeyStates.ControlKey) 164 | { 165 | Txt_InputFile.Text = string.Join(";", Txt_InputFile.Text.Split(';').Concat(ts)); 166 | } 167 | else 168 | { 169 | Txt_InputFile.Text = string.Join(";", ts); 170 | ChangeOutputFile(Path.GetDirectoryName(Txt_InputFile.Text.Split(';').First())); 171 | } 172 | } 173 | } 174 | } 175 | 176 | private void GroupBox_Output_Drop(object sender, DragEventArgs e) 177 | { 178 | if (string.IsNullOrEmpty(Txt_InputFile.Text) || !File.Exists(Txt_InputFile.Text)) 179 | { 180 | MessageUtil.AlertInfo("请确保输入文件正确!"); 181 | return; 182 | } 183 | if (e.Data.GetDataPresent(DataFormats.FileDrop)) 184 | { 185 | string path = ((string[])e.Data.GetData(DataFormats.FileDrop)).First(); 186 | if (File.Exists(path)) 187 | { 188 | var dir = Path.GetDirectoryName(path); 189 | ChangeOutputFile(dir); 190 | } 191 | else if (Directory.Exists(path)) 192 | { 193 | ChangeOutputFile(path); 194 | } 195 | } 196 | } 197 | 198 | private void GroupBox_Output_PreviewDragOver(object sender, DragEventArgs e) 199 | { 200 | e.Handled = true; 201 | } 202 | 203 | private async void Btn_DoDecrypt_Click(object sender, RoutedEventArgs e) 204 | { 205 | try 206 | { 207 | //测试速度 208 | if (Txt_InputFile.Text.ToLower() == "benchmark") 209 | { 210 | BenchmarkUtil.Run((size, time) => 211 | { 212 | var speed = (double)size / time * 1000; 213 | MessageBox.Show($"{Util.FormatFileSize(speed)}/s", "最大解密速度"); 214 | }); 215 | return; 216 | } 217 | 218 | if (tmr != null) 219 | { 220 | tmr.Dispose(); 221 | tmr = new Timer() 222 | { 223 | AutoReset = true 224 | }; 225 | } 226 | 227 | if (Btn_DoDecrypt.Content.ToString() == "停止") 228 | { 229 | DONE = true; 230 | tmr.Elapsed -= ReportStatus; 231 | tmr.Stop(); 232 | Btn_DoDecrypt.Content = "开始解密"; 233 | return; 234 | } 235 | 236 | var keyTxt = Txt_InputKey.Text.Trim(); 237 | if (keyTxt.Contains(" ")) keyTxt = string.Join("", keyTxt.Split(' ').Select(s => s.PadLeft(2, '0'))); 238 | if (keyTxt.Length != 12 && keyTxt.Length != 16) 239 | throw new Exception("KEY格式有误!"); 240 | 241 | tmr.Interval = Convert.ToDouble(Txt_TimerInterval.Text); 242 | var offset = 0L; 243 | var limit = 0L; 244 | if (Txt_PktsOffset.Text.StartsWith("0x")) 245 | { 246 | offset = Convert.ToInt64(Txt_PktsOffset.Text.Substring(2), 16) * PACKET_SIZE; 247 | } 248 | else 249 | { 250 | offset = Convert.ToInt64(Txt_PktsOffset.Text) * PACKET_SIZE; 251 | } 252 | 253 | if (!string.IsNullOrEmpty(Txt_PktsLimit.Text)) 254 | { 255 | if (Txt_PktsLimit.Text.StartsWith("0x")) 256 | { 257 | limit = Convert.ToInt64(Txt_PktsLimit.Text.Substring(2), 16) * PACKET_SIZE; 258 | } 259 | else 260 | { 261 | limit = Convert.ToInt64(Txt_PktsLimit.Text) * PACKET_SIZE; 262 | } 263 | } 264 | 265 | TOTOAL_SIZE = Txt_InputFile.Text.Split(';').Sum(f => new FileInfo(f).Length) - offset; 266 | if (limit != 0) TOTOAL_SIZE = limit; 267 | if (TOTOAL_SIZE == 0) 268 | { 269 | throw new Exception("输入文件为空!!"); 270 | } 271 | if (File.Exists(Txt_OutputFile.Text)) 272 | { 273 | if (!OVER_WRITTEN && !MessageUtil.AlertConfirm("输出文件已存在! 要删除并继续吗?")) return; 274 | else File.Delete(Txt_OutputFile.Text); 275 | } 276 | if (Util.GetDiskFreeSpaceEx(Path.GetDirectoryName(Txt_OutputFile.Text), out ulong freeSize, out _, out _) && (long)freeSize < TOTOAL_SIZE) 277 | { 278 | throw new Exception("输出磁盘空间不足!!"); 279 | } 280 | 281 | //检测KEY是否正确 282 | if (Chk_CheckCW.IsChecked == true) 283 | { 284 | Btn_DoDecrypt.IsEnabled = false; 285 | if (!await Util.CheckCWAsync(keyTxt, Txt_InputFile.Text.Split(';').First(), offset)) 286 | throw new Exception("CW错误或非加密文件!!"); 287 | } 288 | 289 | 290 | Btn_DoDecrypt.IsEnabled = true; 291 | DE_SIZE = LAST_SIZE = MESS_COUNT = 0; 292 | TIME_SPAN = 0d; 293 | DONE = false; 294 | ProBar.Value = 0; 295 | var tsdecrypt = new TSDecrypt(); 296 | tsdecrypt.SetKey(keyTxt); 297 | tmr.Elapsed += ReportStatus; 298 | Btn_DoDecrypt.Content = "停止"; 299 | await DecryptTaskAsync(tsdecrypt, offset, limit, Txt_InputFile.Text, Txt_OutputFile.Text); 300 | DONE = true; 301 | if (DELETE_AFTER_DONE) 302 | { 303 | if (File.Exists(Txt_InputFile.Text) && File.Exists(Txt_OutputFile.Text)) 304 | { 305 | var sizeDiff = Math.Abs(new FileInfo(Txt_InputFile.Text).Length - new FileInfo(Txt_OutputFile.Text).Length); 306 | if (sizeDiff <= 10 * 1024 * 1024) File.Delete(Txt_InputFile.Text); 307 | } 308 | } 309 | if (EXIT_AFTER_DONE) 310 | { 311 | //退出程序 312 | Environment.Exit(0); 313 | } 314 | } 315 | catch (Exception ex) 316 | { 317 | Btn_DoDecrypt.IsEnabled = true; 318 | Btn_DoDecrypt.Content = "开始解密"; 319 | tmr.Stop(); 320 | MessageUtil.AlertInfo(ex.Message); 321 | } 322 | } 323 | 324 | /// 325 | /// 汇报进度 326 | /// 327 | /// 328 | /// 329 | private void ReportStatus(object sender, ElapsedEventArgs e) 330 | { 331 | this.ProBar.Dispatcher.Invoke(new Action(() => 332 | { 333 | if (DE_SIZE == TOTOAL_SIZE || DONE) 334 | { 335 | //ProBar.Value = ProBar.Maximum; 336 | tmr.Stop(); 337 | Btn_DoDecrypt.Content = "开始解密"; 338 | } 339 | TIME_SPAN += tmr.Interval; 340 | var speed = (DE_SIZE - LAST_SIZE) / tmr.Interval * 1000; 341 | Txt_Status.Text = $"耗时: {Util.FormatTime((int)(TIME_SPAN / 1000))}, " + 342 | $"速度: {Util.FormatFileSize(speed)}/s, " + 343 | $"进度: {Util.FormatFileSize(DE_SIZE)}/{Util.FormatFileSize(TOTOAL_SIZE)} ({((double)DE_SIZE / TOTOAL_SIZE * 100).ToString("0.00")}%), " + 344 | $"预计剩余时间: {Util.FormatTime((int)((TOTOAL_SIZE - DE_SIZE) / (speed == 0 ? 1 : speed)))}" + 345 | $"{(MESS_COUNT > 0 ? ", Errors: " + MESS_COUNT : "")}"; 346 | LAST_SIZE = DE_SIZE; 347 | ProBar.Value = Math.Ceiling((double)DE_SIZE / TOTOAL_SIZE * 1000); 348 | //完成后报告 349 | if (ProBar.Value == ProBar.Maximum) 350 | { 351 | ProBar.Value = 0; 352 | Txt_Status.Text = $"耗时: {Util.FormatTime((int)(TIME_SPAN / 1000))}, " + 353 | $"平均速度: {Util.FormatFileSize(DE_SIZE / TIME_SPAN * 1000)}/s, " + 354 | $"进度: {Util.FormatFileSize(DE_SIZE)}/{Util.FormatFileSize(TOTOAL_SIZE)} ({((double)DE_SIZE / TOTOAL_SIZE * 100).ToString("0.00")}%)"; 355 | } 356 | })); 357 | } 358 | 359 | async Task DecryptTaskAsync(TSDecrypt tsdecrypt, long offset, long limit, string input, string outpout) 360 | { 361 | await Task.Run(() => DecryptTask(tsdecrypt, offset, limit, input, outpout)); 362 | } 363 | 364 | void DecryptTask(TSDecrypt tsdecrypt, long offset, long limit, string input, string outpout) 365 | { 366 | var buffer = new byte[PACKET_SIZE * tsdecrypt.PARALL_SIZE]; // 64 TS Packets 367 | int readSize; 368 | var errorDic = new Dictionary(); //Position == Counter 369 | using (var output = new BufferedStream(new FileStream(outpout, FileMode.Create))) 370 | { 371 | foreach (var oneFile in input.Split(';')) 372 | { 373 | var pids = new List(); 374 | if (REALTIME_CHECK) 375 | { 376 | pids.AddRange(Util.CheckIsEncrypted(oneFile, offset).Item2); 377 | } 378 | using (var stream = new FileStream(oneFile, FileMode.Open, FileAccess.Read)) 379 | { 380 | //偏移 381 | if (offset < stream.Length) stream.Position = offset; 382 | tmr.Start(); //开始刷新状态 383 | while (!DONE && (readSize = stream.Read(buffer, 0, buffer.Length)) > 0) 384 | { 385 | //解密限制 386 | if (limit != 0 && DE_SIZE > limit) 387 | { 388 | TOTOAL_SIZE = DE_SIZE; 389 | break; 390 | } 391 | if (buffer[0] != 0x47) 392 | { 393 | stream.Position = stream.Position - readSize + 1; 394 | continue; 395 | } 396 | //var before = new byte[buffer.Length]; 397 | //Array.Copy(buffer, 0, before, 0, buffer.Length); 398 | //解密buffer中的数据 399 | var result = tsdecrypt.DecryptBytes(readSize, ref buffer); 400 | if (result != -1) 401 | { 402 | //尝试检测解密结果 403 | if (REALTIME_CHECK) 404 | { 405 | var checkResult = Util.CheckPesIsRight(buffer, pids, result); 406 | if (checkResult >= 0) 407 | { 408 | var toWriteSize = checkResult * PACKET_SIZE; 409 | output.Write(buffer, 0, toWriteSize); 410 | DE_SIZE += toWriteSize; 411 | stream.Position -= readSize - toWriteSize; 412 | Console.WriteLine($"解密异常:{stream.Position}"); 413 | File.WriteAllText(outpout + ".peserror.log", 414 | $"Source: {input}{Environment.NewLine}{Environment.NewLine}" + 415 | $"Stopped at #{stream.Position} of {stream.Length}, {stream.Position / 188} packets processed(NOT ACCURATE)." 416 | ); 417 | DONE = true; 418 | continue; 419 | } 420 | } 421 | 422 | if (result == (readSize / PACKET_SIZE)) 423 | { 424 | output.Write(buffer, 0, readSize); 425 | DE_SIZE += readSize; 426 | } 427 | else 428 | { 429 | //仅解密了部分,需要回退再解密 430 | var toWriteSize = result * PACKET_SIZE; 431 | output.Write(buffer, 0, toWriteSize); 432 | DE_SIZE += toWriteSize; 433 | stream.Position -= readSize - toWriteSize; 434 | } 435 | } 436 | else 437 | { 438 | MESS_COUNT++; 439 | TOTOAL_SIZE -= 188; 440 | stream.Position = stream.Position - readSize + 188; 441 | if (errorDic.Keys.Count > 0 && stream.Position == errorDic.Keys.Last() + 188 * errorDic[errorDic.Keys.Last()]) 442 | { 443 | errorDic[errorDic.Keys.Last()]++; 444 | } 445 | else 446 | { 447 | errorDic[stream.Position] = 1; 448 | } 449 | continue; 450 | } 451 | } 452 | } 453 | } 454 | DONE = true; 455 | } 456 | if (errorDic.Count > 0) 457 | { 458 | File.WriteAllText(outpout + ".errors.log", 459 | $"Source: {input}{Environment.NewLine}{Environment.NewLine}" + 460 | string.Join(Environment.NewLine, errorDic.Select((k, v) => $"skipped {k.Value} packets after pointer: #{k.Key}")) + 461 | $"{Environment.NewLine}{Environment.NewLine}Total: {errorDic.Values.Sum()} packets skipped" 462 | ); 463 | } 464 | } 465 | 466 | private void Chk_Del_Checked(object sender, RoutedEventArgs e) 467 | { 468 | DELETE_AFTER_DONE = Chk_Del.IsChecked == true; 469 | } 470 | 471 | private void Chk_RealtimeCheckCW_Checked(object sender, RoutedEventArgs e) 472 | { 473 | REALTIME_CHECK = Chk_RealtimeCheckCW.IsChecked == true; 474 | } 475 | } 476 | } 477 | -------------------------------------------------------------------------------- /TSDecryptGUI/MessageUtil.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using System.Windows; 7 | 8 | namespace TSDecryptGUI 9 | { 10 | internal class MessageUtil 11 | { 12 | public static MessageBoxResult AlertInfo(string msg) 13 | { 14 | return MessageBox.Show(msg, "提示信息", MessageBoxButton.OK, MessageBoxImage.Information); 15 | } 16 | 17 | public static MessageBoxResult AlertError(string msg) 18 | { 19 | return MessageBox.Show(msg, "错误信息", MessageBoxButton.OK, MessageBoxImage.Error); 20 | } 21 | 22 | public static bool AlertConfirm(string msg) 23 | { 24 | return MessageBox.Show(msg, "请确认", MessageBoxButton.OKCancel, MessageBoxImage.Question) == MessageBoxResult.OK; 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /TSDecryptGUI/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Resources; 3 | using System.Runtime.CompilerServices; 4 | using System.Runtime.InteropServices; 5 | using System.Windows; 6 | 7 | // 有关程序集的一般信息由以下 8 | // 控制。更改这些特性值可修改 9 | // 与程序集关联的信息。 10 | [assembly: AssemblyTitle("TSDecryptGUI")] 11 | [assembly: AssemblyDescription("")] 12 | [assembly: AssemblyConfiguration("")] 13 | [assembly: AssemblyCompany("")] 14 | [assembly: AssemblyProduct("TSDecryptGUI")] 15 | [assembly: AssemblyCopyright("Copyright © 2023")] 16 | [assembly: AssemblyTrademark("")] 17 | [assembly: AssemblyCulture("")] 18 | 19 | // 将 ComVisible 设置为 false 会使此程序集中的类型 20 | //对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型 21 | //请将此类型的 ComVisible 特性设置为 true。 22 | [assembly: ComVisible(false)] 23 | 24 | //若要开始生成可本地化的应用程序,请设置 25 | //.csproj 文件中的 CultureYouAreCodingWith 26 | //例如,如果您在源文件中使用的是美国英语, 27 | //使用的是美国英语,请将 设置为 en-US。 然后取消 28 | //对以下 NeutralResourceLanguage 特性的注释。 更新 29 | //以下行中的“en-US”以匹配项目文件中的 UICulture 设置。 30 | 31 | //[assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.Satellite)] 32 | 33 | 34 | [assembly: ThemeInfo( 35 | ResourceDictionaryLocation.None, //主题特定资源词典所处位置 36 | //(未在页面中找到资源时使用, 37 | //或应用程序资源字典中找到时使用) 38 | ResourceDictionaryLocation.SourceAssembly //常规资源词典所处位置 39 | //(未在页面中找到资源时使用, 40 | //、应用程序或任何主题专用资源字典中找到时使用) 41 | )] 42 | 43 | 44 | // 程序集的版本信息由下列四个值组成: 45 | // 46 | // 主版本 47 | // 次版本 48 | // 生成号 49 | // 修订号 50 | // 51 | //可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值 52 | //通过使用 "*",如下所示: 53 | // [assembly: AssemblyVersion("1.0.*")] 54 | [assembly: AssemblyVersion("1.0.6.0")] 55 | [assembly: AssemblyFileVersion("1.0.6.0")] 56 | -------------------------------------------------------------------------------- /TSDecryptGUI/Properties/Resources.Designer.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // 此代码由工具生成。 4 | // 运行时版本: 4.0.30319.42000 5 | // 6 | // 对此文件的更改可能导致不正确的行为,如果 7 | // 重新生成代码,则所做更改将丢失。 8 | // 9 | //------------------------------------------------------------------------------ 10 | 11 | namespace TSDecryptGUI.Properties 12 | { 13 | 14 | 15 | /// 16 | /// 强类型资源类,用于查找本地化字符串等。 17 | /// 18 | // 此类是由 StronglyTypedResourceBuilder 19 | // 类通过类似于 ResGen 或 Visual Studio 的工具自动生成的。 20 | // 若要添加或移除成员,请编辑 .ResX 文件,然后重新运行 ResGen 21 | // (以 /str 作为命令选项),或重新生成 VS 项目。 22 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] 23 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] 24 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 25 | internal class Resources 26 | { 27 | 28 | private static global::System.Resources.ResourceManager resourceMan; 29 | 30 | private static global::System.Globalization.CultureInfo resourceCulture; 31 | 32 | [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] 33 | internal Resources() 34 | { 35 | } 36 | 37 | /// 38 | /// 返回此类使用的缓存 ResourceManager 实例。 39 | /// 40 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] 41 | internal static global::System.Resources.ResourceManager ResourceManager 42 | { 43 | get 44 | { 45 | if ((resourceMan == null)) 46 | { 47 | global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("TSDecryptGUI.Properties.Resources", typeof(Resources).Assembly); 48 | resourceMan = temp; 49 | } 50 | return resourceMan; 51 | } 52 | } 53 | 54 | /// 55 | /// 重写当前线程的 CurrentUICulture 属性,对 56 | /// 使用此强类型资源类的所有资源查找执行重写。 57 | /// 58 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] 59 | internal static global::System.Globalization.CultureInfo Culture 60 | { 61 | get 62 | { 63 | return resourceCulture; 64 | } 65 | set 66 | { 67 | resourceCulture = value; 68 | } 69 | } 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /TSDecryptGUI/Properties/Resources.resx: -------------------------------------------------------------------------------- 1 |  2 | 3 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | text/microsoft-resx 107 | 108 | 109 | 2.0 110 | 111 | 112 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 113 | 114 | 115 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 116 | 117 | -------------------------------------------------------------------------------- /TSDecryptGUI/Properties/Settings.Designer.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // This code was generated by a tool. 4 | // Runtime Version:4.0.30319.42000 5 | // 6 | // Changes to this file may cause incorrect behavior and will be lost if 7 | // the code is regenerated. 8 | // 9 | //------------------------------------------------------------------------------ 10 | 11 | namespace TSDecryptGUI.Properties 12 | { 13 | 14 | 15 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 16 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")] 17 | internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase 18 | { 19 | 20 | private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); 21 | 22 | public static Settings Default 23 | { 24 | get 25 | { 26 | return defaultInstance; 27 | } 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /TSDecryptGUI/Properties/Settings.settings: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /TSDecryptGUI/TSDecrypt.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Diagnostics.CodeAnalysis; 4 | using System.IO; 5 | using System.Linq; 6 | using System.Runtime.InteropServices; 7 | using System.Text; 8 | using System.Threading.Tasks; 9 | 10 | namespace TSDecryptGUI 11 | { 12 | internal class TSDecrypt 13 | { 14 | [DllImport("FFDecsa_128_2LONG", EntryPoint = "_Z15decrypt_packetsPPhP10csa_keys_t", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)] 15 | static unsafe extern int decrypt_packets(byte*[] cluster, ref csa_keys_t csa_keys_t); 16 | [DllImport("FFDecsa_128_2LONG", EntryPoint = "_Z15get_keyset_sizev")] 17 | static extern int get_keyset_size(); 18 | [DllImport("FFDecsa_128_2LONG", EntryPoint = "_Z24get_internal_parallelismv")] 19 | static extern int get_parallelism(); 20 | [DllImport("FFDecsa_128_2LONG", EntryPoint = "_Z17set_control_wordsPhS_P10csa_keys_t", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] 21 | static unsafe extern void set_control_words(byte[] even, byte[] odd, ref csa_keys_t csa_keys_t); 22 | 23 | static csa_keys_t KEY_SET = new csa_keys_t(); 24 | public int PARALL_SIZE = get_parallelism(); 25 | 26 | /** 27 | * X64 PARALLEL_064_LONG 28 | */ 29 | 30 | //[StructLayout(LayoutKind.Explicit)] 31 | //public struct csa_keys_t 32 | //{ 33 | // [FieldOffset(0)] public csa_key_t even; 34 | // [FieldOffset(1600)] public csa_key_t odd; 35 | //} 36 | // 37 | //[StructLayout(LayoutKind.Explicit)] 38 | //public unsafe struct csa_key_t 39 | //{ 40 | // [FieldOffset(0)] public fixed byte ck[8]; 41 | // [FieldOffset(8)] public fixed int iA[8]; 42 | // [FieldOffset(40)] public fixed int iB[8]; 43 | // [FieldOffset(72)] public fixed int ck_g[64 * 2]; 44 | // [FieldOffset(584)] public fixed int iA_g[32 * 2]; 45 | // [FieldOffset(840)] public fixed int iB_g[32 * 2]; 46 | // [FieldOffset(1096)] public fixed byte kk[56]; 47 | // [FieldOffset(1152)] public fixed uint kkmulti[56 * 2]; 48 | //} 49 | 50 | /** 51 | * X64 PARALLEL_128_2LONG 52 | */ 53 | 54 | public struct csa_keys_t 55 | { 56 | public csa_key_t even; 57 | public csa_key_t odd; 58 | } 59 | 60 | public unsafe struct csa_key_t 61 | { 62 | public fixed byte ck[8]; 63 | public fixed int iA[8]; 64 | public fixed int iB[8]; 65 | public fixed int ck_g[64 * 4]; 66 | public fixed int iA_g[32 * 4]; 67 | public fixed int iB_g[32 * 4]; 68 | public fixed byte kk[56]; 69 | public fixed uint kkmulti[56 * 4]; 70 | } 71 | 72 | 73 | public void SetKey(string keyTxt) 74 | { 75 | var decKey = new byte[8]; 76 | var bytes = Util.HexToBytes(keyTxt); 77 | if (bytes.Length == 6) 78 | { 79 | //计算hash 80 | decKey[0] = bytes[0]; 81 | decKey[1] = bytes[1]; 82 | decKey[2] = bytes[2]; 83 | decKey[3] = (byte)((bytes[0] + bytes[1] + bytes[2]) % 256); 84 | decKey[4] = bytes[3]; 85 | decKey[5] = bytes[4]; 86 | decKey[6] = bytes[5]; 87 | decKey[7] = (byte)((bytes[3] + bytes[4] + bytes[5]) % 256); 88 | } 89 | else 90 | { 91 | decKey = bytes; 92 | } 93 | set_control_words(decKey, decKey, ref KEY_SET); 94 | } 95 | 96 | [System.Runtime.ExceptionServices.HandleProcessCorruptedStateExceptions] 97 | public unsafe int DecryptBytes(int size, ref byte[] encBytes) 98 | { 99 | int result = 0; 100 | try 101 | { 102 | var cluster = new byte*[PARALL_SIZE]; 103 | fixed (byte* pOneBuf = encBytes) 104 | { 105 | cluster[0] = pOneBuf; 106 | cluster[1] = pOneBuf + size; 107 | cluster[2] = null; 108 | result = decrypt_packets(cluster, ref KEY_SET); 109 | } 110 | } 111 | catch (System.AccessViolationException) 112 | { 113 | result = - 1; 114 | } 115 | return result; 116 | } 117 | } 118 | } 119 | -------------------------------------------------------------------------------- /TSDecryptGUI/TSDecryptGUI.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {98829705-D0B5-48AB-BF6A-FAA927150E2F} 8 | WinExe 9 | TSDecryptGUI 10 | TSDecryptGUI 11 | v4.6 12 | 512 13 | {60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} 14 | 4 15 | true 16 | true 17 | 18 | 19 | AnyCPU 20 | true 21 | full 22 | false 23 | bin\Debug\ 24 | DEBUG;TRACE 25 | prompt 26 | 4 27 | true 28 | 29 | 30 | AnyCPU 31 | pdbonly 32 | true 33 | bin\Release\ 34 | TRACE 35 | prompt 36 | 4 37 | true 38 | 39 | 40 | true 41 | bin\x64\Debug\ 42 | DEBUG;TRACE 43 | full 44 | x64 45 | 7.3 46 | prompt 47 | true 48 | true 49 | 50 | 51 | bin\x64\Release\ 52 | TRACE 53 | true 54 | pdbonly 55 | x64 56 | 7.3 57 | prompt 58 | true 59 | true 60 | 61 | 62 | x86 63 | bin\x86\Debug\ 64 | true 65 | 66 | 67 | x86 68 | bin\x86\Release\ 69 | true 70 | 71 | 72 | satellite-dish-icon-logo.ico 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 4.0 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | MSBuild:Compile 93 | Designer 94 | 95 | 96 | 97 | 98 | 99 | 100 | MSBuild:Compile 101 | Designer 102 | 103 | 104 | App.xaml 105 | Code 106 | 107 | 108 | MainWindow.xaml 109 | Code 110 | 111 | 112 | 113 | 114 | Code 115 | 116 | 117 | True 118 | True 119 | Resources.resx 120 | 121 | 122 | True 123 | Settings.settings 124 | True 125 | 126 | 127 | ResXFileCodeGenerator 128 | Resources.Designer.cs 129 | 130 | 131 | SettingsSingleFileGenerator 132 | Settings.Designer.cs 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | -------------------------------------------------------------------------------- /TSDecryptGUI/Util.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using System.Linq; 5 | using System.Runtime.InteropServices; 6 | using System.Text; 7 | using System.Threading.Tasks; 8 | using System.Windows.Markup; 9 | 10 | namespace TSDecryptGUI 11 | { 12 | internal class Util 13 | { 14 | [DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Auto)] 15 | [return: MarshalAs(UnmanagedType.Bool)] 16 | public static extern bool GetDiskFreeSpaceEx(string lpDirectoryName, out ulong lpFreeBytesAvailable, out ulong lpTotalNumberOfBytes, out ulong lpTotalNumberOfFreeBytes); 17 | 18 | public static byte[] HexToBytes(string hex) 19 | { 20 | hex = hex.Trim(); 21 | byte[] bytes = new byte[hex.Length / 2]; 22 | 23 | for (int i = 0; i < hex.Length; i += 2) 24 | bytes[i / 2] = Convert.ToByte(hex.Substring(i, 2), 16); 25 | 26 | return bytes; 27 | } 28 | 29 | public static String FormatFileSize(Double fileSize) 30 | { 31 | if (fileSize < 0) 32 | { 33 | throw new ArgumentOutOfRangeException("fileSize"); 34 | } 35 | else if (fileSize >= 1024 * 1024 * 1024) 36 | { 37 | return string.Format("{0:########0.00}GB", ((Double)fileSize) / (1024 * 1024 * 1024)); 38 | } 39 | else if (fileSize >= 1024 * 1024) 40 | { 41 | return string.Format("{0:####0.00}MB", ((Double)fileSize) / (1024 * 1024)); 42 | } 43 | else if (fileSize >= 1024) 44 | { 45 | return string.Format("{0:####0.00}KB", ((Double)fileSize) / 1024); 46 | } 47 | else 48 | { 49 | return string.Format("{0}bytes", fileSize); 50 | } 51 | } 52 | 53 | //此函数用于格式化输出时长 54 | public static String FormatTime(Int32 time) 55 | { 56 | TimeSpan ts = new TimeSpan(0, 0, time); 57 | string str = ""; 58 | str = (ts.Hours.ToString("00") == "00" ? "" : ts.Hours.ToString("00") + "h") + ts.Minutes.ToString("00") + "m" + ts.Seconds.ToString("00") + "s"; 59 | return str; 60 | } 61 | 62 | /// 63 | /// 获取采样数据 64 | /// 65 | /// 66 | /// 67 | /// data1, data2, data3, pesIndex1, pesIndex2 pesIndex3 68 | /// 69 | private static Tuple GetTsSamples(int[] inputPids, byte[] data) 70 | { 71 | var list = new List(); 72 | var pesIndexList = new List(); 73 | var offset = 0; 74 | using (var stream = new MemoryStream(data)) 75 | { 76 | //确定起始位置 77 | while (true) 78 | { 79 | var buffer = new byte[188]; 80 | var buffer2 = new byte[188]; 81 | stream.Read(buffer, 0, buffer.Length); 82 | stream.Read(buffer2, 0, buffer2.Length); 83 | if (buffer[0] == 0x47 && buffer2[0] == 0x47) 84 | { 85 | stream.Position = offset; 86 | break; 87 | } 88 | stream.Position = ++offset; 89 | } 90 | for (int n = 0; n < inputPids.Length && list.Count < 3; n++) 91 | { 92 | var inputPid = inputPids[n]; 93 | stream.Position = offset; //复位 94 | var tsData = new byte[188]; 95 | var size = 0; 96 | while ((size = stream.Read(tsData, 0, tsData.Length)) > 0) 97 | { 98 | var tsHeaderInt = BitConverter.ToUInt32(BitConverter.IsLittleEndian ? tsData.Take(4).Reverse().ToArray() : tsData.Take(4).ToArray(), 0); 99 | var pid = (tsHeaderInt & 0x1fff00) >> 8; 100 | if (pid != inputPid) 101 | continue; 102 | var adaptationControl = (tsHeaderInt & 0x30) >> 4; 103 | var payloadUnitStart = (tsHeaderInt & 0x400000) >> 22; 104 | if (payloadUnitStart != 1) 105 | continue; 106 | if (adaptationControl == 3) 107 | { 108 | //adaptationField长度 109 | var adaptationFieldLength = (int)tsData[4]; 110 | //跳过adaptationField 111 | var startIndex = 5 + adaptationFieldLength; 112 | var hexString = BitConverter.ToString(tsData).Replace("-", ""); 113 | pesIndexList.Add(startIndex); 114 | list.Add(hexString); 115 | } 116 | else if (adaptationControl == 1) 117 | { 118 | var hexString = BitConverter.ToString(tsData).Replace("-", ""); 119 | pesIndexList.Add(4); 120 | list.Add(hexString); 121 | } 122 | if (list.Count >= 3) 123 | break; 124 | } 125 | } 126 | } 127 | if (list.Count < 3) 128 | throw new Exception("获取采样数据异常!"); 129 | return new Tuple(list[0], list[1], list[2], pesIndexList[0], pesIndexList[1], pesIndexList[2]); 130 | } 131 | 132 | /// 133 | /// 判断是否加密并返回PID 134 | /// 135 | /// 136 | /// 置信次数 137 | /// 138 | public static Tuple CheckIsEncrypted(string file, long offset = 0) 139 | { 140 | var data = new byte[20 * 1024 * 1024]; 141 | using (var stream = new FileStream(file, FileMode.Open, FileAccess.Read)) 142 | { 143 | //偏移 144 | if (offset < stream.Length) stream.Position = offset; 145 | stream.Read(data, 0, data.Length); 146 | } 147 | return CheckIsEncrypted(data); 148 | } 149 | 150 | /// 151 | /// 判断是否加密并返回PID 152 | /// 153 | /// 154 | /// 置信次数 155 | /// 156 | private static Tuple CheckIsEncrypted(byte[] data, int count = 20) 157 | { 158 | var list = new List(); //加密PID 159 | int counter = 0; 160 | bool enc = false; 161 | var offset = 0; 162 | using (var stream = new MemoryStream(data)) 163 | { 164 | //确定起始位置 165 | while (true) 166 | { 167 | var buffer = new byte[188]; 168 | var buffer2 = new byte[188]; 169 | stream.Read(buffer, 0, buffer.Length); 170 | stream.Read(buffer2, 0, buffer2.Length); 171 | if (buffer[0] == 0x47 && buffer2[0] == 0x47) 172 | { 173 | stream.Position = offset; 174 | break; 175 | } 176 | stream.Position = ++offset; 177 | } 178 | var tsData = new byte[188]; 179 | var size = 0; 180 | while ((size = stream.Read(tsData, 0, tsData.Length)) > 0) 181 | { 182 | var tsHeaderInt = BitConverter.ToUInt32(BitConverter.IsLittleEndian ? tsData.Take(4).Reverse().ToArray() : tsData.Take(4).ToArray(), 0); 183 | var pid = (tsHeaderInt & 0x1fff00) >> 8; 184 | var adaptationControl = (tsHeaderInt & 0x30) >> 4; 185 | if (pid > 8191 || pid <= 32 || adaptationControl != 1) 186 | continue; 187 | var encTag = (tsHeaderInt & 0xc0) >> 6; 188 | /** 189 | * '00' = Not scrambled. 190 | * '01' (0x40) = Reserved for future use 191 | * '10' (0x80) = Scrambled with even key 192 | * '11' (0xC0) = Scrambled with odd key 193 | */ 194 | if (encTag == 2 || encTag == 3) 195 | { 196 | if (++counter > count) 197 | { 198 | enc = true; 199 | if (!list.Contains((int)pid)) list.Add((int)pid); 200 | } 201 | } 202 | else 203 | { 204 | counter = 0; 205 | } 206 | } 207 | } 208 | if (list.Count == 0) list.Add(-1); 209 | return new Tuple(enc, list.ToArray()); 210 | } 211 | 212 | static TSDecrypt tsdecrypt = null; 213 | public static async Task CheckCWAsync(string keyTxt, string file, long offset = 0) 214 | { 215 | var data = new byte[20 * 1024 * 1024]; 216 | using (var stream = new FileStream(file, FileMode.Open, FileAccess.Read)) 217 | { 218 | //偏移 219 | if (offset < stream.Length) stream.Position = offset; 220 | await stream.ReadAsync(data, 0, data.Length); 221 | } 222 | var isEnc = CheckIsEncrypted(data); 223 | if (isEnc.Item1 == false) return false; 224 | var pidArray = isEnc.Item2; 225 | var samples = GetTsSamples(pidArray, data); 226 | var ts1 = HexToBytes(samples.Item1); 227 | var ts2 = HexToBytes(samples.Item2); 228 | var ts3 = HexToBytes(samples.Item3); 229 | var pesIndex1 = samples.Item4; 230 | var pesIndex2 = samples.Item5; 231 | var pesIndex3 = samples.Item6; 232 | 233 | if (tsdecrypt == null) tsdecrypt = new TSDecrypt(); 234 | tsdecrypt.SetKey(keyTxt); 235 | tsdecrypt.DecryptBytes(ts1.Length, ref ts1); 236 | if (!(ts1[pesIndex1] == 0x00 && ts1[pesIndex1 + 1] == 0x00 && ts1[pesIndex1 + 2] == 0x01)) return false; 237 | tsdecrypt.DecryptBytes(ts2.Length, ref ts2); 238 | if (!(ts2[pesIndex2] == 0x00 && ts2[pesIndex2 + 1] == 0x00 && ts2[pesIndex2 + 2] == 0x01)) return false; 239 | tsdecrypt.DecryptBytes(ts3.Length, ref ts3); 240 | if (!(ts3[pesIndex3] == 0x00 && ts3[pesIndex3 + 1] == 0x00 && ts3[pesIndex3 + 2] == 0x01)) return false; 241 | return true; 242 | } 243 | 244 | /// 245 | /// 检测是否正确解密 246 | /// 247 | /// 248 | /// 249 | /// 250 | /// 出现问题的包序号(0开始) 251 | public static int CheckPesIsRight(byte[] data, List pids, long packetCount) 252 | { 253 | var result = -1; // -1是没问题 254 | var buffer = new byte[188]; 255 | using (var stream = new MemoryStream(data)) 256 | { 257 | for (int i = 0; i < packetCount; i++) 258 | { 259 | stream.Read(buffer, 0, buffer.Length); 260 | 261 | var tsHeaderInt = BitConverter.ToUInt32(BitConverter.IsLittleEndian ? buffer.Take(4).Reverse().ToArray() : buffer.Take(4).ToArray(), 0); 262 | var pid = (tsHeaderInt & 0x1fff00) >> 8; 263 | 264 | if (pid > 8191 || pid <= 32 || !pids.Contains((int)pid)) 265 | continue; 266 | 267 | var adaptationControl = (tsHeaderInt & 0x30) >> 4; 268 | var payloadUnitStart = (tsHeaderInt & 0x400000) >> 22; 269 | if (payloadUnitStart != 1) 270 | continue; 271 | if (adaptationControl == 3) 272 | { 273 | //adaptationField长度 274 | var adaptationFieldLength = (int)buffer[4]; 275 | //跳过adaptationField 276 | var startIndex = 5 + adaptationFieldLength; 277 | if (!(buffer[startIndex] == 0x00 && buffer[startIndex + 1] == 0x00 && buffer[startIndex + 2] == 0x01)) return i; 278 | } 279 | else if (adaptationControl == 1) 280 | { 281 | var startIndex = 4; 282 | if (!(buffer[startIndex] == 0x00 && buffer[startIndex + 1] == 0x00 && buffer[startIndex + 2] == 0x01)) return i; 283 | } 284 | } 285 | } 286 | 287 | return result; 288 | } 289 | } 290 | } 291 | -------------------------------------------------------------------------------- /TSDecryptGUI/satellite-dish-icon-white.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nilaoda/TSDecrypt/15a516e51ab1dfa8e2a5f3692c3634ac9ec381b3/TSDecryptGUI/satellite-dish-icon-white.ico --------------------------------------------------------------------------------