code wiki / _hdl_build / nx_kvs_gate.nx

nx_kvs_gate.nx source

↩ module page · 100 lines · 8160 B

1import "nx_gate_base.nx" 2// nx_kvs_gate.nx -- proves the KVS de-obfuscator is a faithful port: exact token vector for a real license, and 3// correct URL surgery on the real bitchesgirls flashvars (both are VERIFIED facts captured from the live page). 4import "nx_syscalls.nx" 5import "nx_kvs.nx" 6 7func grow(name: *u8, ok: i64) -> i64 { if ok==1 { gw(" PASS " as *u8) } else { gw(" FAIL " as *u8) } gw(name); gw(" 8" as *u8); return ok } 9func pw(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 } 10func pn(v: i64) -> i64 { let b: *u8=sys_mmap(24); var m: i64=v; if m<0{pw("-" as *u8);m=0-m} let t: *u8=sys_mmap(24); var k: i64=0; if m==0{t[0]=48 as u8;k=1} while m>0{t[k]=(48+(m%10)) as u8;m=m/10;k=k+1} var i: i64=0; while i<k{b[i]=t[k-1-i];i=i+1} sys_write(1,b,k); return 0 } 11func g_has(hay: *u8, hl: i64, needle: *u8) -> i64 { let nl: i64=g_slen(needle); if nl==0 {return 1} var i: i64=0; let last: i64=hl-nl; while i<=last { var j: i64=0; var m: i64=1; while j<nl { if (hay[i+j]&0xff)!=(needle[j]&0xff){m=0;j=nl} else {j=j+1} } if m==1 {return 1} i=i+1 } return 0 } 12func chk(label: *u8, ok: i64) -> i64 { if ok==1 { pw(" ok " as *u8) } else { pw(" FAIL " as *u8) } pw(label); pw("\n" as *u8); return ok } 13 14func main(argc: i64, argv: *i64) -> i64 { 15 pw("== nx_kvs_gate ==\n" as *u8) 16 var pass: i64 = 0 17 var total: i64 = 0 18 19 // ---- token math for the REAL license captured from the live page ---- 20 let tok: *i64 = sys_mmap(8*32) as *i64 21 let nt: i64 = kvs_license_token("$662765921865805" as *u8, 16, tok) 22 let exp: *i64 = sys_mmap(8*32) as *i64 23 exp[0]=7; exp[1]=7; exp[2]=3; exp[3]=8 24 exp[4]=3; exp[5]=9; exp[6]=4; exp[7]=3 25 exp[8]=9; exp[9]=4; exp[10]=3; exp[11]=2 26 exp[12]=3; exp[13]=2; exp[14]=1; exp[15]=5 27 exp[16]=0; exp[17]=9; exp[18]=3; exp[19]=6 28 exp[20]=8; exp[21]=2; exp[22]=5; exp[23]=4 29 exp[24]=0; exp[25]=3; exp[26]=2; exp[27]=9 30 exp[28]=2; exp[29]=1; exp[30]=8; exp[31]=6 31 total=total+1; pass=pass+chk("K1 token count == 32\x00" as *u8, (nt == 32) as i64) 32 var mism: i64 = 0 33 var i: i64 = 0 34 while i < 32 { if tok[i] != exp[i] { mism = mism + 1 } i = i + 1 } 35 total=total+1; pass=pass+chk("K2 token vector matches hand-computed reference (0 mismatches)\x00" as *u8, (mism == 0) as i64) 36 if mism != 0 { pw(" got: " as *u8); var d: i64=0; while d<32 { pn(tok[d]); pw(" " as *u8); d=d+1 } pw("\n" as *u8) } 37 38 // ---- URL surgery on the REAL obfuscated video_url ---- 39 let vurl: *u8 = "function/0/https://bitchesgirls.tv/get_file/3/fd47cfa1d5b8fd299e609f07e7d66b95/103000/103849/103849_1080p.mp4/" as *u8 40 let vlen: i64 = g_slen(vurl) 41 let out: *u8 = sys_mmap(4096) 42 let ol: i64 = kvs_real_url(vurl, vlen, "$662765921865805" as *u8, 16, out, 4096) 43 pw("deobfuscated: " as *u8); sys_write(1, out, ol); pw("\n" as *u8) 44 total=total+1; pass=pass+chk("K3 length preserved (permutation, not truncation)\x00" as *u8, (ol == (vlen - 11)) as i64) 45 total=total+1; pass=pass+chk("K4 keeps /get_file/3/ structure\x00" as *u8, g_has(out, ol, "https://bitchesgirls.tv/get_file/3/" as *u8)) 46 total=total+1; pass=pass+chk("K5 keeps the video path/name\x00" as *u8, g_has(out, ol, "/103000/103849/103849_1080p.mp4/" as *u8)) 47 total=total+1; pass=pass+chk("K6 hash actually changed (scrambled hash gone)\x00" as *u8, (g_has(out, ol, "fd47cfa1d5b8fd299e609f07e7d66b95" as *u8) == 0) as i64) 48 49 // ---- page-level extract from a KVS flashvars fixture ---- 50 let page: *u8 = "<script>var flashvars={video_url: 'function/0/https://bitchesgirls.tv/get_file/3/fd47cfa1d5b8fd299e609f07e7d66b95/103000/103849/103849_1080p.mp4/', video_url_hd: '1', license_code: '$662765921865805', kt_player:'v6'};</script>" as *u8 51 let plen: i64 = g_slen(page) 52 let out2: *u8 = sys_mmap(4096) 53 let ol2: i64 = kvs_extract(page, plen, out2, 4096) 54 total=total+1; pass=pass+chk("K7 kvs_extract pulls + de-obfuscates from a page\x00" as *u8, (ol2 > 40) as i64) 55 total=total+1; pass=pass+chk("K8 page extract matches direct de-obfuscation\x00" as *u8, (ol2 == ol) as i64) 56 57 // ---- best-quality selection: alt url is HIGHER res than the primary -> must pick the alt ---- 58 let page2: *u8 = "<script>var flashvars={video_url: 'https://h/get_file/3/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/1/2/clip_720p.mp4/', video_alt_url: 'https://h/get_file/3/bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb/1/2/clip_1080p.mp4/', license_code: ''};</script>" as *u8 59 let plen2: i64 = g_slen(page2) 60 let out3: *u8 = sys_mmap(4096) 61 let ol3: i64 = kvs_extract(page2, plen2, out3, 4096) 62 total=total+1; pass=pass+chk("K9 picks the higher-res alt (1080p over 720p)\x00" as *u8, g_has(out3, ol3, "clip_1080p.mp4" as *u8)) 63 total=total+1; pass=pass+chk("K10 did NOT pick the lower 720p\x00" as *u8, (g_has(out3, ol3, "clip_720p.mp4" as *u8) == 0) as i64) 64 65 // ---- 8K over 4K (no ladder -- parsed pixel heights) ---- 66 let page4: *u8 = "<script>var flashvars={video_url: 'https://h/get_file/3/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/1/2/clip_2160p.mp4/', video_alt_url: 'https://h/get_file/3/bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb/1/2/clip_4320p.mp4/', license_code: ''};</script>" as *u8 67 let out4: *u8 = sys_mmap(4096) 68 let ol4: i64 = kvs_extract(page4, g_slen(page4), out4, 4096) 69 total=total+1; pass=pass+chk("K11 picks 8K (4320p) over 4K (2160p)\x00" as *u8, g_has(out4, ol4, "clip_4320p.mp4" as *u8)) 70 total=total+1; pass=pass+chk("K12 did NOT pick the 2160p\x00" as *u8, (g_has(out4, ol4, "clip_2160p.mp4" as *u8) == 0) as i64) 71 72 // ---- kvs_res_score parses real heights (unit) ---- 73 total=total+1; pass=pass+chk("K13 parses 4320p -> 4320\x00" as *u8, (kvs_res_score("zz_4320p.mp4" as *u8, 12) == 4320) as i64) 74 total=total+1; pass=pass+chk("K14 4K alias -> 2160\x00" as *u8, (kvs_res_score("movie_4K.mp4" as *u8, 12) == 2160) as i64) 75 total=total+1; pass=pass+chk("K15 8K alias -> 4320\x00" as *u8, (kvs_res_score("v_8K.mp4" as *u8, 8) == 4320) as i64) 76 total=total+1; pass=pass+chk("K16 WxH takes the height (1920x1080 -> 1080)\x00" as *u8, (kvs_res_score("clip_1920x1080.mp4" as *u8, 18) == 1080) as i64) 77 78 // ---- resolution from the site's _text label when the filename has none ---- 79 let page5: *u8 = "<script>var flashvars={video_url: 'https://h/get_file/3/cccccccccccccccccccccccccccccccc/1/2/lowfile.mp4/', video_url_text: '360p', video_alt_url: 'https://h/get_file/3/dddddddddddddddddddddddddddddddd/1/2/hifile.mp4/', video_alt_url_text: '2160p', license_code: ''};</script>" as *u8 80 let out5: *u8 = sys_mmap(4096) 81 let ol5: i64 = kvs_extract(page5, g_slen(page5), out5, 4096) 82 total=total+1; pass=pass+chk("K17 picks by _text label (2160p over 360p) when URL lacks resolution\x00" as *u8, g_has(out5, ol5, "hifile.mp4" as *u8)) 83 84 // ---- progressive gate: an .m3u8 in video_url is rejected in favor of a progressive alt ---- 85 let page6: *u8 = "<script>var flashvars={video_url: 'https://h/get_file/3/eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee/1/2/master.m3u8', video_alt_url: 'https://h/get_file/3/ffffffffffffffffffffffffffffffff/1/2/clip_480p.mp4/', license_code: ''};</script>" as *u8 86 let out6: *u8 = sys_mmap(4096) 87 let ol6: i64 = kvs_extract(page6, g_slen(page6), out6, 4096) 88 total=total+1; pass=pass+chk("K18 rejects .m3u8 video_url, picks the progressive mp4 alt\x00" as *u8, g_has(out6, ol6, "clip_480p.mp4" as *u8)) 89 total=total+1; pass=pass+chk("K19 did NOT return the m3u8\x00" as *u8, (g_has(out6, ol6, "master.m3u8" as *u8) == 0) as i64) 90 // ---- only-manifest KVS -> returns nothing (assembler's job, not a broken <video>) ---- 91 let page7: *u8 = "<script>var flashvars={video_url: 'https://h/get_file/3/gggggggggggggggggggggggggggggggg/1/2/master.m3u8', license_code: ''};</script>" as *u8 92 let out7: *u8 = sys_mmap(4096) 93 let ol7: i64 = kvs_extract(page7, g_slen(page7), out7, 4096) 94 total=total+1; pass=pass+chk("K20 only-m3u8 KVS returns 0 (no broken player)\x00" as *u8, (ol7 == 0) as i64) 95 96 pw("== kvs gate: " as *u8); pn(pass); pw("/" as *u8); pn(total); pw(" ==\n" as *u8) 97 if pass == total { sys_exit(0); return 0 } 98 sys_exit(1) 99 return 1 100}