002.指纹浏览器进阶-传参指定操作系统为macOS
一、目标:
- 实现传入参数--platform=mac,将浏览器获取到的操作系统变为macOS
- 并且可以通过creepjs和browserscan的检测。
二、js如何判断操作系统是否为Mac
方法比较多,这里我们只能挨个列出来,然后挨个修改
- 1 . 通过navigator.platform
console.log(navigator.platform)
输出:
MacIntel
- 2 . 通过navigator.userAgent
正常mac的UA类似长这样:Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.0.0 Safari/537.36
function detectOS() { const userAgent = navigator.userAgent.toLowerCase(); if (userAgent.includes('win')) { return 'Windows'; } else if (userAgent.includes('mac')) { return 'Mac'; } return '其他系统'; } console.log(detectOS())
输出:
Mac
- 3 . 通过navigator.userAgentData
let tmp = await navigator.userAgentData.getHighEntropyValues(["platform", "platformVersion"]) console.log("操作系统:", tmp.platform) console.log("版本号:", tmp.platformVersion)
输出:
操作系统: macOS 版本号: 10.11.2
- 4 . 通过字体
function detectOSByFont() { // 定义系统特征字体(按检测优先级排序) const osFonts = { mac: ["Geneva", "Helvetica Neue", "Luminari"], win: ["Segoe UI", "Ink Free", "Segoe UI Emoji"] }; // 字体检测方法 const isFontAvailable = fontName => { try { await (new FontFace("Helvetica Neue", `local("${fontName} Neue"`)).load() return true; } catch (e) { return false; } }; // 优先检测Mac字体 for (const font of osFonts.mac) { if (isFontAvailable(font)) return "Mac"; } // 其次检测Windows字体 for (const font of osFonts.win) { if (isFontAvailable(font)) return "Windows"; } // 最终回退到UserAgent检测 const ua = navigator.userAgent; if (/Mac/i.test(ua)) return "操作系统:Mac"; if (/Win/i.test(ua)) return "操作系统:Windows"; return "其他操作系统"; } console.log(detectOSByFont())
输出:
Mac
- 5.通过特性
if('BarcodeDetector' in window){ console.log('是Mac') }else{ console.log('不是Mac') }
输出:
是Mac
三、修改navigator.platform
-
打开文件 \third_party\blink\renderer\core\execution_context\navigator_base.cc
-
找到函数:
String GetReducedNavigatorPlatform() {
- 追加几行:
String GetReducedNavigatorPlatform() { // 开始追加 ===================================== base::CommandLine* base_command_line = base::CommandLine::ForCurrentProcess(); std::string platform = base_command_line->GetSwitchValueASCII("platform"); if (platform == "mac"){ return "MacIntel"; } // 结束追加 ==================================
四、修改navigator.userAgent
-
打开文件:\components\embedder_support\user_agent_utils.cc
-
找到:
std::string GetUserAgent( UserAgentReductionEnterprisePolicyState user_agent_reduction) { std::optional custom_ua = GetUserAgentFromCommandLine(); if (custom_ua.has_value()) { return custom_ua.value(); } return GetUserAgentInternal(user_agent_reduction); }
- 替换为:
std::string GetUserAgent( ForceMajorVersionToMinorPosition force_major_to_minor, UserAgentReductionEnterprisePolicyState user_agent_reduction) { absl::optional custom_ua = GetUserAgentFromCommandLine(); if (custom_ua.has_value()) { return custom_ua.value(); } // 开始修改======================== //return GetUserAgentInternal(user_agent_reduction); // 133版 base::CommandLine* base_command_line = base::CommandLine::ForCurrentProcess(); std::string ignores = base_command_line->GetSwitchValueASCII("ignores"); if(!base_command_line->HasSwitch("user-agent") && ignores.find("useragent") == std::string::npos){ std::string ua; std::string target; std::string replacemen; std::string result = ua; size_t pos; std::string platform = base_command_line->GetSwitchValueASCII("platform"); if (platform == "mac"){ target = "Windows NT 10.0; Win64; x64"; replacement = "Macintosh; Intel Mac OS X 10_11_2"; pos = 0; while ((pos = result.find(target, pos))!= std::string::npos) { result.replace(pos, target.length(), replacement); pos += replacement.length(); } } return result; }else{ return GetUserAgentInternal(user_agent_reduction); } // 结束修改======================================= }
注意:不同大版本的源代码会略有不同,不要直接覆盖,注意理解。
五、修改navigator.userAgentData
-
还是打开:\components\embedder_support\user_agent_utils.cc
-
找到函数:
std::string GetPlatformForUAMetadata() {
- 追加几行:
std::string GetPlatformForUAMetadata() { // 开始追加 ================================= base::CommandLine* base_command_line = base::CommandLine::ForCurrentProcess(); std::string platform = base_command_line->GetSwitchValueASCII("platform"); if (platform == "mac"){ return "macOS"; }else if (platform == "win"){ return "Windows"; }else if (platform == "linux"){ return "Linux"; } // 结束追加===========================================
六、修改font
-
打开:\third_party\blink\renderer\core\css\css_font_family_value.cc
-
找到函数:
CSSFontFamilyValue* CSSFontFamilyValue::Create(
- 追加几行:
CSSFontFamilyValue* CSSFontFamilyValue::Create( const AtomicString& family_name) { // 开始追加======================================= base::CommandLine* base_command_line = base::CommandLine::ForCurrentProcess(); std::string ignores = base_command_line->GetSwitchValueASCII("ignores"); std::string now_font_str = family_name.GetString().Utf8(); if (base_command_line->HasSwitch("finger-log")) { std::cerr int seed; auto now = std::chrono::system_clock::now(); std::time_t now_time_t = std::chrono::system_clock::to_time_t(now); int int_now = static_cast std::istringstream(base_command_line-GetSwitchValueASCII("fingerprints")) > seed; }else{ seed = int_now; } std::vector stringsAarry = {"Goudy Old Style", "Bell MT", "Browallia New", "Rod", "Zurich Ex BT", "BinnerD", "Gill Sans Ultra Bold Condensed", "INTERSTATE", "Arabic Typesetting", "Fransiscan", "AvantGarde Md BT", "Segoe Fluent Icons", "Broadway", "Bodoni MT Poster Compressed", "Miriam Fixed", "PetitaBold", "DFKai-SB", "Poster", "MS Outlook", "DIN", "Charlesworth", "Cuckoo", "VisualUI", "Geometr231 Lt BT", "Denmark", "Adobe Garamond", "Eras Bold ITC", "Meiryo", "MS PMincho", "Herald", "Didot", "Bodoni MT", "Bazooka", "Kristen ITC", "MS Mincho", "Khmer UI", "Lydian BT", "ShelleyVolante BT", "Kailasa", "Pickwick", "GOTHAM", "ZapfEllipt BT", "Geometr231 BT", "MT Extra", "Papyrus", "Mrs Eaves", "Letter Gothic", "Albertus Extra Bold", "Vladimir Script", "Chalkboard SE", "SCRIPTINA", "Storybook", "OzHandicraft BT", "Wingdings 2", "Tunga", "PosterBodoni BT", "Baskerville Old Face"}; auto selectedArray = selectRandomFonts2(stringsAarry, 199, seed); if (std::find(selectedArray.begin(), selectedArray.end(), now_font_str) != selectedArray.end()) { //如果在selectedArray中 return MakeGarbageCollected(AtomicString("sans-serif")); } std::vector winFontsAarry = {"Segoe Fluent Icons", "Ink Free", "Bahnschrift", "Segoe MDL2 Assets", "HoloLens MDL2 Assets", "Segoe UI Emoji", "Javanese Text", "Leelawadee UI", "Nirmala UI", "Myanmar Text", "Gadugi", "Aldhabi", "Lucida Console", "Cambria Math"}; if (base_command_line->GetSwitchValueASCII("platform") == "mac"){ std::vector macFontsAarry = {"Helvetica Neue", "Geneva", "Kohinoor Devanagari Medium", "Luminari", "PingFang HK Light", "InaiMathi Bold", "PGalvji", "Chakra Petch" }; if(std::find(winFontsAarry.begin(), winFontsAarry.end(), now_font_str) != winFontsAarry.end()){ //std::cerr return MakeGarbageCollected // 随机选多个 std::mt19937 rng(seed); std::uniform_int_distribution size_t index = dist(rng); if (!selected[index]) { selectedFonts.push_back(fontArray[index]); selected[index] = true; } } return selectedFonts; } name: "BarcodeDetector", status: { // Built-in barcode detection APIs are only available from some // platforms. See //services/shape_detection. "Android": "stable", "ChromeOS_Ash": "stable", "ChromeOS_Lacros": "stable", "Mac": "stable", "default": "test", }, base_feature: "none", } name: "BarcodeDetector", status: { // Built-in barcode detection APIs are only available from some // platforms. See //services/shape_detection. "Android": "stable", "ChromeOS_Ash": "stable", "ChromeOS_Lacros": "stable", "Mac": "stable", // 追加一行 ============================ "Win": "stable", "default": "test", }, base_feature: "none", }
- 追加几行:
-
- 追加几行:
-
- 替换为:
-
- 追加几行:
-
- 5.通过特性
- 4 . 通过字体
- 3 . 通过navigator.userAgentData
- 2 . 通过navigator.userAgent
- 1 . 通过navigator.platform
免责声明:我们致力于保护作者版权,注重分享,被刊用文章因无法核实真实出处,未能及时与作者取得联系,或有版权异议的,请联系管理员,我们会立即处理! 部分文章是来自自研大数据AI进行生成,内容摘自(百度百科,百度知道,头条百科,中国民法典,刑法,牛津词典,新华词典,汉语词典,国家院校,科普平台)等数据,内容仅供学习参考,不准确地方联系删除处理! 图片声明:本站部分配图来自人工智能系统AI生成,觅知网授权图片,PxHere摄影无版权图库和百度,360,搜狗等多加搜索引擎自动关键词搜索配图,如有侵权的图片,请第一时间联系我们。