|
| 1 | +import time |
| 2 | +import random |
| 3 | +import struct |
| 4 | +import io |
| 5 | +import json |
| 6 | + |
| 7 | + |
| 8 | +MOD = 1 << 64 |
| 9 | + |
| 10 | + |
| 11 | +def get_time_milli() -> int: |
| 12 | + return int(time.time() * 1000) |
| 13 | + |
| 14 | + |
| 15 | +def rotate_left(x: int, k: int) -> int: |
| 16 | + bin_str = bin(x)[2:].rjust(64, "0") |
| 17 | + return int(bin_str[k:] + bin_str[:k], base=2) |
| 18 | + |
| 19 | + |
| 20 | +def gen_uuid_infoc() -> str: |
| 21 | + t = get_time_milli() % 100000 |
| 22 | + mp = list("123456789ABCDEF") + ["10"] |
| 23 | + pck = [8, 4, 4, 4, 12] |
| 24 | + gen_part = lambda x: "".join([random.choice(mp) for _ in range(x)]) |
| 25 | + return "-".join([gen_part(l) for l in pck]) + str(t).ljust(5, "0") + "infoc" |
| 26 | + |
| 27 | + |
| 28 | +def gen_b_lsid() -> str: |
| 29 | + ret = "" |
| 30 | + for _ in range(8): |
| 31 | + ret += hex(random.randint(0, 15))[2:].upper() |
| 32 | + ret = f"{ret}_{hex(get_time_milli())[2:].upper()}" |
| 33 | + return ret |
| 34 | + |
| 35 | + |
| 36 | +def gen_buvid_fp(key: str, seed: int): |
| 37 | + source = io.BytesIO(bytes(key, "ascii")) |
| 38 | + m = murmur3_x64_128(source, seed) |
| 39 | + return "{}{}".format(hex(m & (MOD - 1))[2:], hex(m >> 64)[2:]) |
| 40 | + |
| 41 | + |
| 42 | +def murmur3_x64_128(source: io.BufferedIOBase, seed: int) -> str: |
| 43 | + C1 = 0x87C3_7B91_1142_53D5 |
| 44 | + C2 = 0x4CF5_AD43_2745_937F |
| 45 | + C3 = 0x52DC_E729 |
| 46 | + C4 = 0x3849_5AB5 |
| 47 | + R1, R2, R3, M = 27, 31, 33, 5 |
| 48 | + h1, h2 = seed, seed |
| 49 | + processed = 0 |
| 50 | + while 1: |
| 51 | + read = source.read(16) |
| 52 | + processed += len(read) |
| 53 | + if len(read) == 16: |
| 54 | + k1 = struct.unpack("<q", read[:8])[0] |
| 55 | + k2 = struct.unpack("<q", read[8:])[0] |
| 56 | + h1 ^= rotate_left(k1 * C1 % MOD, R2) * C2 % MOD |
| 57 | + h1 = ((rotate_left(h1, R1) + h2) * M + C3) % MOD |
| 58 | + h2 ^= rotate_left(k2 * C2 % MOD, R3) * C1 % MOD |
| 59 | + h2 = ((rotate_left(h2, R2) + h1) * M + C4) % MOD |
| 60 | + elif len(read) == 0: |
| 61 | + h1 ^= processed |
| 62 | + h2 ^= processed |
| 63 | + h1 = (h1 + h2) % MOD |
| 64 | + h2 = (h2 + h1) % MOD |
| 65 | + h1 = fmix64(h1) |
| 66 | + h2 = fmix64(h2) |
| 67 | + h1 = (h1 + h2) % MOD |
| 68 | + h2 = (h2 + h1) % MOD |
| 69 | + return (h2 << 64) | h1 |
| 70 | + else: |
| 71 | + k1 = 0 |
| 72 | + k2 = 0 |
| 73 | + if len(read) >= 15: |
| 74 | + k2 ^= int(read[14]) << 48 |
| 75 | + if len(read) >= 14: |
| 76 | + k2 ^= int(read[13]) << 40 |
| 77 | + if len(read) >= 13: |
| 78 | + k2 ^= int(read[12]) << 32 |
| 79 | + if len(read) >= 12: |
| 80 | + k2 ^= int(read[11]) << 24 |
| 81 | + if len(read) >= 11: |
| 82 | + k2 ^= int(read[10]) << 16 |
| 83 | + if len(read) >= 10: |
| 84 | + k2 ^= int(read[9]) << 8 |
| 85 | + if len(read) >= 9: |
| 86 | + k2 ^= int(read[8]) |
| 87 | + k2 = rotate_left(k2 * C2 % MOD, R3) * C1 % MOD |
| 88 | + h2 ^= k2 |
| 89 | + if len(read) >= 8: |
| 90 | + k1 ^= int(read[7]) << 56 |
| 91 | + if len(read) >= 7: |
| 92 | + k1 ^= int(read[6]) << 48 |
| 93 | + if len(read) >= 6: |
| 94 | + k1 ^= int(read[5]) << 40 |
| 95 | + if len(read) >= 5: |
| 96 | + k1 ^= int(read[4]) << 32 |
| 97 | + if len(read) >= 4: |
| 98 | + k1 ^= int(read[3]) << 24 |
| 99 | + if len(read) >= 3: |
| 100 | + k1 ^= int(read[2]) << 16 |
| 101 | + if len(read) >= 2: |
| 102 | + k1 ^= int(read[1]) << 8 |
| 103 | + if len(read) >= 1: |
| 104 | + k1 ^= int(read[0]) |
| 105 | + k1 = rotate_left(k1 * C1 % MOD, R2) * C2 % MOD |
| 106 | + h1 ^= k1 |
| 107 | + |
| 108 | + |
| 109 | +def fmix64(k: int) -> int: |
| 110 | + C1 = 0xFF51_AFD7_ED55_8CCD |
| 111 | + C2 = 0xC4CE_B9FE_1A85_EC53 |
| 112 | + R = 33 |
| 113 | + tmp = k |
| 114 | + tmp ^= tmp >> R |
| 115 | + tmp = tmp * C1 % MOD |
| 116 | + tmp ^= tmp >> R |
| 117 | + tmp = tmp * C2 % MOD |
| 118 | + tmp ^= tmp >> R |
| 119 | + return tmp |
| 120 | + |
| 121 | + |
| 122 | +def get_payload(uuid: str) -> str: |
| 123 | + content = { |
| 124 | + "3064": 1, |
| 125 | + "5062": get_time_milli(), |
| 126 | + "03bf": "https%3A%2F%2Fwww.bilibili.com%2F", |
| 127 | + "39c8": "333.788.fp.risk", |
| 128 | + "34f1": "", |
| 129 | + "d402": "", |
| 130 | + "654a": "", |
| 131 | + "6e7c": "839x959", |
| 132 | + "3c43": { |
| 133 | + "2673": 0, |
| 134 | + "5766": 24, |
| 135 | + "6527": 0, |
| 136 | + "7003": 1, |
| 137 | + "807e": 1, |
| 138 | + "b8ce": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.3 Safari/605.1.15", |
| 139 | + "641c": 0, |
| 140 | + "07a4": "en-US", |
| 141 | + "1c57": "not available", |
| 142 | + "0bd0": 8, |
| 143 | + "748e": [900, 1440], |
| 144 | + "d61f": [875, 1440], |
| 145 | + "fc9d": -480, |
| 146 | + "6aa9": "Asia/Shanghai", |
| 147 | + "75b8": 1, |
| 148 | + "3b21": 1, |
| 149 | + "8a1c": 0, |
| 150 | + "d52f": "not available", |
| 151 | + "adca": "MacIntel", |
| 152 | + "80c9": [ |
| 153 | + [ |
| 154 | + "PDF Viewer", |
| 155 | + "Portable Document Format", |
| 156 | + [["application/pdf", "pdf"], ["text/pdf", "pdf"]], |
| 157 | + ], |
| 158 | + [ |
| 159 | + "Chrome PDF Viewer", |
| 160 | + "Portable Document Format", |
| 161 | + [["application/pdf", "pdf"], ["text/pdf", "pdf"]], |
| 162 | + ], |
| 163 | + [ |
| 164 | + "Chromium PDF Viewer", |
| 165 | + "Portable Document Format", |
| 166 | + [["application/pdf", "pdf"], ["text/pdf", "pdf"]], |
| 167 | + ], |
| 168 | + [ |
| 169 | + "Microsoft Edge PDF Viewer", |
| 170 | + "Portable Document Format", |
| 171 | + [["application/pdf", "pdf"], ["text/pdf", "pdf"]], |
| 172 | + ], |
| 173 | + [ |
| 174 | + "WebKit built-in PDF", |
| 175 | + "Portable Document Format", |
| 176 | + [["application/pdf", "pdf"], ["text/pdf", "pdf"]], |
| 177 | + ], |
| 178 | + ], |
| 179 | + "13ab": "0dAAAAAASUVORK5CYII=", |
| 180 | + "bfe9": "QgAAEIQAACEIAABCCQN4FXANGq7S8KTZayAAAAAElFTkSuQmCC", |
| 181 | + "a3c1": [ |
| 182 | + "extensions:ANGLE_instanced_arrays;EXT_blend_minmax;EXT_color_buffer_half_float;EXT_float_blend;EXT_frag_depth;EXT_shader_texture_lod;EXT_texture_compression_bptc;EXT_texture_compression_rgtc;EXT_texture_filter_anisotropic;EXT_sRGB;KHR_parallel_shader_compile;OES_element_index_uint;OES_fbo_render_mipmap;OES_standard_derivatives;OES_texture_float;OES_texture_float_linear;OES_texture_half_float;OES_texture_half_float_linear;OES_vertex_array_object;WEBGL_color_buffer_float;WEBGL_compressed_texture_astc;WEBGL_compressed_texture_etc;WEBGL_compressed_texture_etc1;WEBGL_compressed_texture_pvrtc;WEBKIT_WEBGL_compressed_texture_pvrtc;WEBGL_compressed_texture_s3tc;WEBGL_compressed_texture_s3tc_srgb;WEBGL_debug_renderer_info;WEBGL_debug_shaders;WEBGL_depth_texture;WEBGL_draw_buffers;WEBGL_lose_context;WEBGL_multi_draw", |
| 183 | + "webgl aliased line width range:[1, 1]", |
| 184 | + "webgl aliased point size range:[1, 511]", |
| 185 | + "webgl alpha bits:8", |
| 186 | + "webgl antialiasing:yes", |
| 187 | + "webgl blue bits:8", |
| 188 | + "webgl depth bits:24", |
| 189 | + "webgl green bits:8", |
| 190 | + "webgl max anisotropy:16", |
| 191 | + "webgl max combined texture image units:32", |
| 192 | + "webgl max cube map texture size:16384", |
| 193 | + "webgl max fragment uniform vectors:1024", |
| 194 | + "webgl max render buffer size:16384", |
| 195 | + "webgl max texture image units:16", |
| 196 | + "webgl max texture size:16384", |
| 197 | + "webgl max varying vectors:30", |
| 198 | + "webgl max vertex attribs:16", |
| 199 | + "webgl max vertex texture image units:16", |
| 200 | + "webgl max vertex uniform vectors:1024", |
| 201 | + "webgl max viewport dims:[16384, 16384]", |
| 202 | + "webgl red bits:8", |
| 203 | + "webgl renderer:WebKit WebGL", |
| 204 | + "webgl shading language version:WebGL GLSL ES 1.0 (1.0)", |
| 205 | + "webgl stencil bits:0", |
| 206 | + "webgl vendor:WebKit", |
| 207 | + "webgl version:WebGL 1.0", |
| 208 | + "webgl unmasked vendor:Apple Inc.", |
| 209 | + "webgl unmasked renderer:Apple GPU", |
| 210 | + "webgl vertex shader high float precision:23", |
| 211 | + "webgl vertex shader high float precision rangeMin:127", |
| 212 | + "webgl vertex shader high float precision rangeMax:127", |
| 213 | + "webgl vertex shader medium float precision:23", |
| 214 | + "webgl vertex shader medium float precision rangeMin:127", |
| 215 | + "webgl vertex shader medium float precision rangeMax:127", |
| 216 | + "webgl vertex shader low float precision:23", |
| 217 | + "webgl vertex shader low float precision rangeMin:127", |
| 218 | + "webgl vertex shader low float precision rangeMax:127", |
| 219 | + "webgl fragment shader high float precision:23", |
| 220 | + "webgl fragment shader high float precision rangeMin:127", |
| 221 | + "webgl fragment shader high float precision rangeMax:127", |
| 222 | + "webgl fragment shader medium float precision:23", |
| 223 | + "webgl fragment shader medium float precision rangeMin:127", |
| 224 | + "webgl fragment shader medium float precision rangeMax:127", |
| 225 | + "webgl fragment shader low float precision:23", |
| 226 | + "webgl fragment shader low float precision rangeMin:127", |
| 227 | + "webgl fragment shader low float precision rangeMax:127", |
| 228 | + "webgl vertex shader high int precision:0", |
| 229 | + "webgl vertex shader high int precision rangeMin:31", |
| 230 | + "webgl vertex shader high int precision rangeMax:30", |
| 231 | + "webgl vertex shader medium int precision:0", |
| 232 | + "webgl vertex shader medium int precision rangeMin:31", |
| 233 | + "webgl vertex shader medium int precision rangeMax:30", |
| 234 | + "webgl vertex shader low int precision:0", |
| 235 | + "webgl vertex shader low int precision rangeMin:31", |
| 236 | + "webgl vertex shader low int precision rangeMax:30", |
| 237 | + "webgl fragment shader high int precision:0", |
| 238 | + "webgl fragment shader high int precision rangeMin:31", |
| 239 | + "webgl fragment shader high int precision rangeMax:30", |
| 240 | + "webgl fragment shader medium int precision:0", |
| 241 | + "webgl fragment shader medium int precision rangeMin:31", |
| 242 | + "webgl fragment shader medium int precision rangeMax:30", |
| 243 | + "webgl fragment shader low int precision:0", |
| 244 | + "webgl fragment shader low int precision rangeMin:31", |
| 245 | + "webgl fragment shader low int precision rangeMax:30", |
| 246 | + ], |
| 247 | + "6bc5": "Apple Inc.~Apple GPU", |
| 248 | + "ed31": 0, |
| 249 | + "72bd": 0, |
| 250 | + "097b": 0, |
| 251 | + "52cd": [0, 0, 0], |
| 252 | + "a658": [ |
| 253 | + "Andale Mono", |
| 254 | + "Arial", |
| 255 | + "Arial Black", |
| 256 | + "Arial Hebrew", |
| 257 | + "Arial Narrow", |
| 258 | + "Arial Rounded MT Bold", |
| 259 | + "Arial Unicode MS", |
| 260 | + "Comic Sans MS", |
| 261 | + "Courier", |
| 262 | + "Courier New", |
| 263 | + "Geneva", |
| 264 | + "Georgia", |
| 265 | + "Helvetica", |
| 266 | + "Helvetica Neue", |
| 267 | + "Impact", |
| 268 | + "LUCIDA GRANDE", |
| 269 | + "Microsoft Sans Serif", |
| 270 | + "Monaco", |
| 271 | + "Palatino", |
| 272 | + "Tahoma", |
| 273 | + "Times", |
| 274 | + "Times New Roman", |
| 275 | + "Trebuchet MS", |
| 276 | + "Verdana", |
| 277 | + "Wingdings", |
| 278 | + "Wingdings 2", |
| 279 | + "Wingdings 3", |
| 280 | + ], |
| 281 | + "d02f": "124.04345259929687", |
| 282 | + }, |
| 283 | + "54ef": '{"in_new_ab":true,"ab_version":{"remove_back_version":"REMOVE","login_dialog_version":"V_PLAYER_PLAY_TOAST","open_recommend_blank":"SELF","storage_back_btn":"HIDE","call_pc_app":"FORBID","clean_version_old":"GO_NEW","optimize_fmp_version":"LOADED_METADATA","for_ai_home_version":"V_OTHER","bmg_fallback_version":"DEFAULT","ai_summary_version":"SHOW","weixin_popup_block":"ENABLE","rcmd_tab_version":"DISABLE","in_new_ab":true},"ab_split_num":{"remove_back_version":11,"login_dialog_version":43,"open_recommend_blank":90,"storage_back_btn":87,"call_pc_app":47,"clean_version_old":46,"optimize_fmp_version":28,"for_ai_home_version":38,"bmg_fallback_version":86,"ai_summary_version":466,"weixin_popup_block":45,"rcmd_tab_version":90,"in_new_ab":0},"pageVersion":"new_video","videoGoOldVersion":-1}', |
| 284 | + "8b94": "https%3A%2F%2Fwww.bilibili.com%2F", |
| 285 | + "df35": uuid, |
| 286 | + "07a4": "en-US", |
| 287 | + "5f45": None, |
| 288 | + "db46": 0, |
| 289 | + } |
| 290 | + return json.dumps( |
| 291 | + {"payload": json.dumps(content, separators=(",", ":"))}, |
| 292 | + separators=(",", ":"), |
| 293 | + ) |
0 commit comments