设备内存指纹

server/2024/11/30 0:18:15/

一、前端通过获取Navigator.deviceMemory来查询系统内存。

二、Navigator.deviceMemory

1、navigator_device_memory.idl接口定义:

// https://github.com/w3c/device-memory#the-web-exposed-apiinterface mixin NavigatorDeviceMemory {[HighEntropy=Direct,MeasureAs=NavigatorDeviceMemory,SecureContext]readonly attribute float deviceMemory;
};

2、v8_navigator

out\Debug\gen\third_party\blink\renderer\bindings\modules\v8\v8_navigator.cc

void DeviceMemoryAttributeGetCallback(const v8::FunctionCallbackInfo<v8::Value>& info) {RUNTIME_CALL_TIMER_SCOPE_DISABLED_BY_DEFAULT(info.GetIsolate(), "Blink_Navigator_deviceMemory_Getter");
BLINK_BINDINGS_TRACE_EVENT("Navigator.deviceMemory.get");
// [HighEntropy]
const Dactyloscoper::HighEntropyTracer  high_entropy_tracer("Navigator.deviceMemory.get", info);
v8::Isolate* isolate = info.GetIsolate();
v8::Local<v8::Context> current_context = isolate->GetCurrentContext();
ExecutionContext* current_execution_context = ExecutionContext::From(current_context);
// [Measure], [MeasureAs]
UseCounter::Count(current_execution_context, WebFeature::kNavigatorDeviceMemory);v8::Local<v8::Object> v8_receiver = info.This();
Navigator* blink_receiver = V8Navigator::ToWrappableUnsafe(isolate, v8_receiver);
auto&& return_value = blink_receiver->deviceMemory();
bindings::V8SetReturnValue(info, return_value, bindings::V8ReturnValue::PrimitiveType<float>());
// [HighEntropy=Direct]
Dactyloscoper::RecordDirectSurface(current_execution_context, WebFeature::kNavigatorDeviceMemory, return_value);
}

3、接口实现c++:

third_party\blink\renderer\core\frame\navigator_device_memory.h

third_party\blink\renderer\core\frame\navigator_device_memory.cc

namespace blink {float NavigatorDeviceMemory::deviceMemory() const {return ApproximatedDeviceMemory::GetApproximatedDeviceMemory();
}}  // namespace blink

third_party\blink\common\device_memory\approximated_device_memory.cc

namespace blink {// static
float ApproximatedDeviceMemory::approximated_device_memory_gb_ = 0.0;
int64_t ApproximatedDeviceMemory::physical_memory_mb_ = 0;// static
void ApproximatedDeviceMemory::Initialize() {if (approximated_device_memory_gb_ > 0.0)return;DCHECK_EQ(0, physical_memory_mb_);physical_memory_mb_ = ::base::SysInfo::AmountOfPhysicalMemoryMB();CalculateAndSetApproximatedDeviceMemory();
}// static
float ApproximatedDeviceMemory::GetApproximatedDeviceMemory() {return approximated_device_memory_gb_;
}// static
void ApproximatedDeviceMemory::CalculateAndSetApproximatedDeviceMemory() {// The calculations in this method are described in the specification:// https://w3c.github.io/device-memory/.DCHECK_GT(physical_memory_mb_, 0);int lower_bound = physical_memory_mb_;int power = 0;// Extract the most-significant-bit and its location.while (lower_bound > 1) {lower_bound >>= 1;power++;}// The remaining should always be equal to exactly 1.DCHECK_EQ(lower_bound, 1);int64_t upper_bound = lower_bound + 1;lower_bound = lower_bound << power;upper_bound = upper_bound << power;// Find the closest bound, and convert it to GB.if (physical_memory_mb_ - lower_bound <= upper_bound - physical_memory_mb_)approximated_device_memory_gb_ = static_cast<float>(lower_bound) / 1024.0;elseapproximated_device_memory_gb_ = static_cast<float>(upper_bound) / 1024.0;// Max-limit the reported value to 8GB to reduce fingerprintability of// high-spec machines.if (approximated_device_memory_gb_ > 8)approximated_device_memory_gb_ = 8.0;
}// static
void ApproximatedDeviceMemory::SetPhysicalMemoryMBForTesting(int64_t physical_memory_mb) {physical_memory_mb_ = physical_memory_mb;CalculateAndSetApproximatedDeviceMemory();
}}  // namespace blink

三、调用堆栈:

Navigator.deviceMemory 调用c++NavigatorDeviceMemory::deviceMemory()接口 返回内存大小指纹。

注意:当系统内存大于8GB时候浏览器默认是8G

四、总结:

修改内存指纹只需要在NavigatorDeviceMemory::deviceMemory()函数里面修改即可。

五、看下效果:

本人机器64G内存,浏览器默认指纹显示8G,将其改为18G编译看下效果。


http://www.ppmy.cn/server/146029.html

相关文章

STM32-- 看门狗--介绍、使用场景、失效场景

STM32 中的看门狗&#xff08;Watchdog Timer&#xff0c;简称 WDG&#xff09;有两种主要类型&#xff1a;独立看门狗&#xff08;IWDG&#xff09; 和 窗口看门狗&#xff08;WWDG&#xff09;。它们的喂狗机制各有特点&#xff0c;主要区别如下&#xff1a; 1. 独立看门狗&a…

基于Java实现的潜艇大战游戏

基于Java实现的潜艇大战游戏 一.需求分析 1.1 设计任务 本次游戏课程设计小组成员团队合作的方式&#xff0c;通过游戏总体分析设计&#xff0c;场景画面的绘制&#xff0c;游戏事件的处理&#xff0c;游戏核心算法的分析实现&#xff0c;游戏的碰撞检测&#xff0c;游戏的反…

【GPT】力量训练是什么,必要吗,有可以替代的方式吗

什么是力量训练&#xff1f; 力量训练是一种通过抵抗力&#xff08;如重量、阻力带、自身体重等&#xff09;来刺激肌肉收缩&#xff0c;从而提高肌肉力量、耐力和体积的运动形式。它包括以下常见形式&#xff1a; 自由重量训练&#xff1a;使用哑铃、杠铃、壶铃等。固定器械…

【HarmonyOS开发模板/组件分享 – 用户隐私政策弹窗】

介绍 元服务或应用在上架应用市场时&#xff0c;审核要求在启动界面或登录界面以显著的方式展示隐私政策&#xff0c;提示用户阅读隐私政策。 本篇Codelab介绍了如何使用自定义弹窗设计用户隐私政策弹窗&#xff0c;方便开发者快速集成到自己的工程项目中&#xff0c;满足审…

R-Meta分析

原文&#xff1a;R-Meta分析https://mp.weixin.qq.com/s/9ziVzSNRsgUbV9hTtXz5_g?token340211611&langzh_CN 一&#xff1a;AIMeta分析检索 1、AI大模型助力Meta分析的选题与文献检索 1)什么是Meta分析 2)Meta分析的选题策略 3)精确检索策略&#xff0c;如何检索全、检索…

【JAVA】IntelliJ IDEA 如何创建一个 Java 项目

链接: IntelliJ IDEA 如何创建一个 Java 项目

2024下半年——【寒假】自学黑客计划(网络安全)

CSDN大礼包&#xff1a;&#x1f449;基于入门网络安全/黑客打造的&#xff1a;&#x1f449;黑客&网络安全入门&进阶学习资源包 前言 什么是网络安全 网络安全可以基于攻击和防御视角来分类&#xff0c;我们经常听到的 “红队”、“渗透测试” 等就是研究攻击技术&a…

ensp配置静态路由与RIP协议

一、简介 RIP是典型的基于矢量计算路由的动态路由协议 RIP会选择经过路由器少的那条&#xff0c;超过15个路由器之后将不会再进行路由传递 RIP适合小型、中型的网络结构&#xff0c;有两个版本&#xff0c;一种不会对ip地址的网段进行特殊的子网掩码设置&#xff0c;只能理解…