|
5 | 5 | import java.io.UnsupportedEncodingException; |
6 | 6 | import java.net.HttpURLConnection; |
7 | 7 | import java.net.URL; |
8 | | -import java.net.URLDecoder; |
9 | 8 | import java.net.URLEncoder; |
10 | 9 | import java.util.Arrays; |
| 10 | +import java.util.Base64; |
11 | 11 | import java.util.Collections; |
12 | 12 | import java.util.HashMap; |
13 | 13 | import java.util.List; |
14 | 14 | import java.util.Map; |
| 15 | +import java.util.Random; |
15 | 16 | import java.util.regex.Matcher; |
16 | 17 | import java.util.regex.Pattern; |
17 | 18 | import java.util.stream.Collectors; |
@@ -235,7 +236,12 @@ public static void uploadFingerprint() { |
235 | 236 | String b_lsid = ResourcesUtil.randomHex(8) + "_" + Long.toHexString(currentTime).toUpperCase(); |
236 | 237 | HttpCookies.set("b_lsid", b_lsid); |
237 | 238 | } |
238 | | - |
| 239 | + // 设置 browser_resolution |
| 240 | + Matcher mResolution = pResolution.matcher(Global.userAgentPayload); |
| 241 | + if(mResolution.find()) { |
| 242 | + String resolution = String.format("%s-%s", mResolution.group(1), mResolution.group(2)); |
| 243 | + HttpCookies.set("browser_resolution", resolution); |
| 244 | + } |
239 | 245 | // TODO payload |
240 | 246 | String payload = Global.userAgentPayload; |
241 | 247 | payload = payload.replaceFirst("\"5062\":\"[^\"]+\"", "\"5062\":\"" + currentTime + "\""); |
@@ -293,10 +299,67 @@ public static String genNewFingerprint() { |
293 | 299 | String buvid_fp = Global.userAgentFingerprint; |
294 | 300 | kvMap.put("buvid_fp", buvid_fp); |
295 | 301 | kvMap.put("fingerprint", buvid_fp); |
| 302 | + // 获取 browser_resolution |
| 303 | + Matcher mResolution = pResolution.matcher(Global.userAgentPayload); |
| 304 | + mResolution.find(); |
| 305 | + String resolution = String.format("%s-%s", mResolution.group(1), mResolution.group(2)); |
| 306 | + kvMap.put("browser_resolution", resolution); |
296 | 307 | return HttpCookies.map2CookieStr(kvMap); |
297 | 308 | } catch (IOException e) { |
298 | 309 | e.printStackTrace(); |
299 | 310 | } |
300 | 311 | return ""; |
301 | 312 | } |
| 313 | + |
| 314 | + static String b64Sub2(String data) { |
| 315 | + try { |
| 316 | + String result = new String(Base64.getEncoder().encode(data.getBytes("UTF-8")), "UTF-8"); |
| 317 | + result = result.substring(0, result.length() - 2); |
| 318 | + return result; |
| 319 | + } catch (UnsupportedEncodingException e) { |
| 320 | + throw new RuntimeException(e); |
| 321 | + } |
| 322 | + } |
| 323 | + |
| 324 | + static Random random = new Random(); |
| 325 | + |
| 326 | + static String f114(int a, int b) { |
| 327 | + int t = random.nextInt(114); |
| 328 | + return String.format("[%d,%d,%d]", 2 * a + 2 * b + 3 * t, 4 * a - b + t, t); |
| 329 | + } |
| 330 | + |
| 331 | + static String f514(int a, int b) { |
| 332 | + int t = random.nextInt(514); |
| 333 | + return String.format("[%d,%d,%d]", 3 * a + 2 * b + t, 4 * a - 4 * b + 2 * t, t); |
| 334 | + } |
| 335 | + |
| 336 | + static Pattern pWebglVersion = Pattern.compile("\"webgl version:([^\"]+)\""); |
| 337 | + static Pattern pResolution = Pattern.compile("\"6e7c\":\"(\\d+)x(\\d+)\""); |
| 338 | + static Pattern pWebglUnRenderer = Pattern.compile("\"webgl unmasked renderer:([^\"]+)\""); |
| 339 | + static Pattern pWebglUnVendor = Pattern.compile("\"webgl unmasked vendor:([^\"]+)\""); |
| 340 | + |
| 341 | + public static String genDmImgParams() { |
| 342 | + // TODO dm_img_list 浏览器加载完毕后,如果没什么动作,请求始终为[] |
| 343 | + String dm_img_list = "[]"; |
| 344 | + // dm_img_str |
| 345 | + Matcher mWebglVersion = pWebglVersion.matcher(Global.userAgentPayload); |
| 346 | + mWebglVersion.find(); |
| 347 | + String dm_img_str = b64Sub2(mWebglVersion.group(1).trim()); |
| 348 | + // TODO dm_img_inter 浏览器加载完毕后第一个请求始终为 |
| 349 | + // {"ds":[],"wh":f114(width, height),"of":f514(0,0)} |
| 350 | + Matcher mResolution = pResolution.matcher(Global.userAgentPayload); |
| 351 | + mResolution.find(); |
| 352 | + String _wh = f114(Integer.parseInt(mResolution.group(1)), Integer.parseInt(mResolution.group(2))); |
| 353 | + String _of = f514(0, 0); |
| 354 | + String dm_img_inter = String.format("{\"ds\":[],\"wh\":%s,\"of\":%s}", _wh, _of); |
| 355 | + // dm_cover_img_str |
| 356 | + Matcher mWebglUnRenderer = pWebglUnRenderer.matcher(Global.userAgentPayload); |
| 357 | + mWebglUnRenderer.find(); |
| 358 | + Matcher mWebglUnVendor = pWebglUnVendor.matcher(Global.userAgentPayload); |
| 359 | + mWebglUnVendor.find(); |
| 360 | + String dm_cover_img_str = mWebglUnRenderer.group(1).trim() + mWebglUnVendor.group(1).trim(); |
| 361 | + dm_cover_img_str = b64Sub2(dm_cover_img_str); |
| 362 | + return String.format("&dm_img_list=%s&dm_img_str=%s&dm_img_inter=%s&dm_cover_img_str=%s", dm_img_list, |
| 363 | + dm_img_str, dm_img_inter, dm_cover_img_str); |
| 364 | + } |
302 | 365 | } |
0 commit comments