|
1 | 1 | using System;
|
2 | 2 | using System.Collections.Generic;
|
3 | 3 | using System.IO;
|
| 4 | +using System.Linq; |
4 | 5 | using System.Net;
|
5 | 6 | using System.Net.Http;
|
6 | 7 | using System.Text;
|
@@ -83,7 +84,7 @@ public static Dictionary<string, string> DefaultBrowserHeaders(Dictionary<string
|
83 | 84 | Dictionary<string, string> headers = new Dictionary<string, string>{
|
84 | 85 | {"Accept", "*/*"},
|
85 | 86 | {"Accept-Language", "en-US,en;q=0.5"},
|
86 |
| - {"sec-ch-ua", $"\"Not.A/Brand\";v=\"8\", \"Chromium\";v=\"{BROWSER_VERSION}\", \"Google Chrome\";v=\"{BROWSER_VERSION}\""}, |
| 87 | + {"sec-ch-ua", GetGreasedChromeVersion()}, |
87 | 88 | {"sec-ch-ua-mobile", "?0"},
|
88 | 89 | {"sec-ch-ua-platform", "\"Windows\""},
|
89 | 90 | {"sec-fetch-dest", "empty"},
|
@@ -139,6 +140,67 @@ public static async Task<string> GetLatestChromeVersion()
|
139 | 140 |
|
140 | 141 | return majorNum;
|
141 | 142 | }
|
| 143 | + |
| 144 | + // https://github.com/chromium/chromium/blob/3d78f2a1a74d5fed08f55e0349c21acc7fc2f5fa/components/embedder_support/user_agent_utils.cc#L430 |
| 145 | + public static string GetGreasedChromeVersion() |
| 146 | + { |
| 147 | + int seed = int.Parse(BROWSER_VERSION); |
| 148 | + var greasyChars = new string[] { " ", "(", ":", "-", ".", "/", ")", ";", "=", "?", "_" }; |
| 149 | + var greasedVersions = new string[] { "8", "99", "24" }; |
| 150 | + |
| 151 | + string greasyBrand = |
| 152 | + "Not" + greasyChars[seed % greasyChars.Length] + |
| 153 | + "A" + greasyChars[(seed + 1) % greasyChars.Length] + |
| 154 | + "Brand"; |
| 155 | + string greasyVersion = greasedVersions[seed % greasedVersions.Length]; |
| 156 | + |
| 157 | + var brandVersionList = new List<string[]>{ |
| 158 | + new string[] {greasyBrand, greasyVersion}, |
| 159 | + new string[] {"Chromium", BROWSER_VERSION}, |
| 160 | + new string[] {"Google Chrome", BROWSER_VERSION} |
| 161 | + }; |
| 162 | + |
| 163 | + int[] order; |
| 164 | + int size = brandVersionList.Count; |
| 165 | + switch(size) |
| 166 | + { |
| 167 | + case 2: |
| 168 | + order = new int[] { seed % size, (seed + 1) % size }; |
| 169 | + break; |
| 170 | + case 3: |
| 171 | + { |
| 172 | + var orders = new List<int[]> |
| 173 | + { |
| 174 | + new int[] {0, 1, 2}, new int[] {0, 2, 1}, new int[] {1, 0, 2}, new int[] {1, 2, 0}, new int[] {2, 0, 1}, new int[] {2, 1, 0} |
| 175 | + }; |
| 176 | + order = orders[seed % orders.Count]; |
| 177 | + break; |
| 178 | + } |
| 179 | + default: |
| 180 | + { |
| 181 | + var orders = new List<int[]> |
| 182 | + { |
| 183 | + new int[] {0, 1, 2, 3}, new int[] {0, 1, 3, 2}, new int[] {0, 2, 1, 3}, new int[] {0, 2, 3, 1}, new int[] {0, 3, 1, 2}, |
| 184 | + new int[] {0, 3, 2, 1}, new int[] {1, 0, 2, 3}, new int[] {1, 0, 3, 2}, new int[] {1, 2, 0, 3}, new int[] {1, 2, 3, 0}, |
| 185 | + new int[] {1, 3, 0, 2}, new int[] {1, 3, 2, 0}, new int[] {2, 0, 1, 3}, new int[] {2, 0, 3, 1}, new int[] {2, 1, 0, 3}, |
| 186 | + new int[] {2, 1, 3, 0}, new int[] {2, 3, 0, 1}, new int[] {2, 3, 1, 0}, new int[] {3, 0, 1, 2}, new int[] {3, 0, 2, 1}, |
| 187 | + new int[] {3, 1, 0, 2}, new int[] {3, 1, 2, 0}, new int[] {3, 2, 0, 1}, new int[] {3, 2, 1, 0} |
| 188 | + }; |
| 189 | + order = orders[seed % orders.Count]; |
| 190 | + break; |
| 191 | + } |
| 192 | + } |
| 193 | + |
| 194 | + // Initializing this with `brandVersionList` because it's the cleanest way to avoid the index of out bounds error. |
| 195 | + // No, setting Capacity doesn't work for some reason. |
| 196 | + var shuffled = new List<string[]>(brandVersionList); |
| 197 | + for(int i=0;i<order.Length;i++) |
| 198 | + { |
| 199 | + shuffled[order[i]] = brandVersionList[i]; |
| 200 | + } |
| 201 | + |
| 202 | + return String.Join(", ", shuffled.Select(x => $"\"{x[0]}\";v=\"{x[1]}\"")); |
| 203 | + } |
142 | 204 | }
|
143 | 205 | class DRequest
|
144 | 206 | {
|
|
0 commit comments