027.指纹浏览器开发-修改语言和时区

一、为啥要改时区:

  • 使用代理访问网络是,浏览器会出现ip所在地和我们的时区所在地不一致,很容易被识别出们使用了代理。
  • 最简单的修改时区的办法是直接将windows时间设置中,找到时区,改成ip所在的时区即可。
  • 这里,我还提供下choromium源码中修改时区的方法。

二、修改源码

  • 找到文件 \third_party\icu\source\i18n\timezone.cpp
1.找到
TimeZone *default_zone = TimeZone::detectHostTimeZone();
1.替换为:
TimeZone *default_zone = TimeZone::createTimeZone(icu::UnicodeString::fromUTF8("Asia/Tokyo"));

注意:这里只改成了日本时区,其他自行更换即可。

3.编译
ninja  -C  out/Default chrome

注意:因为这个文件接收不到参数,所以我的解决方案是:启动时将参数写进一个文件中,后续这里再读文件的。小伙伴们有其他好的解决方案可以留言。

三、更改语言:

  • 真的有人会拿这个做风控吗?
  • 这个非常简单,就是追加2个已有的chrome参数即可:--lang=en-US--accept-lang=en-US

四、2025-01-22追加:通过读文件方式获取时区参数

  • 很多小伙伴还是想知道我是怎么获取到时区信息的,虽然我已经反复强调过,我这种读文件不是个好方法~
1.找到 /content/browser/browser_main_loop.cc
void BrowserMainLoop::PostCreateThreadsImpl() {
  TRACE_EVENT0("startup", "BrowserMainLoop::PostCreateThreadsImpl");

  // Bring up Mojo IPC and the embedded Service Manager as early as possible.
  // Initializaing mojo requires the IO thread to have been initialized first,
  // so this cannot happen any earlier than now.
  InitializeMojo();

2.替换为
void BrowserMainLoop::PostCreateThreadsImpl() {
  TRACE_EVENT0("startup", "BrowserMainLoop::PostCreateThreadsImpl");

  // Bring up Mojo IPC and the embedded Service Manager as early as possible.
  // Initializaing mojo requires the IO thread to have been initialized first,
  // so this cannot happen any earlier than now.
  InitializeMojo();
  
  // 追加===================================================
  base::CommandLine* cmdLine = base::CommandLine::ForCurrentProcess();
  std::string timeZonePath = "./timezone.txt"; 
  if (!cmdLine->HasSwitch("timezone")) {
    std::filesystem::remove(timeZonePath);
  }else{
    std::ofstream outputFileZ(timeZonePath);
    outputFileZ << cmdLine->GetSwitchValueASCII("timezone");
    outputFileZ.close(); 
  }

这里是浏览器启动时,将--timezone获取的值写入./timezone.txt

3.再找到:\third_party\icu\source\i18n\timezone.cpp
TimeZone *default_zone = TimeZone::detectHostTimeZone()
4.替换为
// 修改================================================
	TimeZone *default_zone;
    std::string timeZonePath = "./timezone.txt"; 
    std::ifstream inputFileZ(timeZonePath);
    if (inputFileZ.is_open()) {
		std::string content;
        inputFileZ >> content;
		default_zone = TimeZone::createTimeZone(icu::UnicodeString::fromUTF8(content));
		inputFileZ.close();
		//if(content.size()>4){std::filesystem::remove(timeZonePath);}
	}else{
		default_zone = TimeZone::detectHostTimeZone();
	}
	// 结束修改================================================

这里是再在文件里读取时区并使用。

5.编译
ninja  -C  out/Default chrome

五、2025-05-08追加

  • 群友提供了更优秀的时区传参位置解决方案:
  • 打开 /base/i18n/icu_util.cc
#include <iostream>
#include "base/command_line.h"
#include "third_party/icu/source/i18n/unicode/timezone.h"
bool InitializeICU() {
#if DCHECK_IS_ON()
  DCHECK(!g_check_called_once || !g_called_once);
  g_called_once = true;
#endif

#if (ICU_UTIL_DATA_IMPL == ICU_UTIL_DATA_STATIC)
  // The ICU data is statically linked.
#elif (ICU_UTIL_DATA_IMPL == ICU_UTIL_DATA_FILE)
  if (!InitializeICUFromDataFile())
    return false;
#else
#error Unsupported ICU_UTIL_DATA_IMPL value
#endif  // (ICU_UTIL_DATA_IMPL == ICU_UTIL_DATA_STATIC)

  // 开始追加 ======================
  base::CommandLine* cmdLine = base::CommandLine::ForCurrentProcess();
  if (cmdLine->HasSwitch("timezone")) {
      std::string timezone_str = cmdLine->GetSwitchValueASCII("timezone");
      std::cerr << "timezone_str: " << timezone_str << std::endl;
      icu::TimeZone *default_zone = icu::TimeZone::createTimeZone(icu::UnicodeString::fromUTF8(timezone_str));
      icu::TimeZone::adoptDefault(default_zone);
  }
  // 结束追加 ======================
  return DoCommonInitialization();
}
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

王辉辉的猫

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值