V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
anonydmer
V2EX  ›  问与答

大家帮给看看微信这个脚本具体干了些啥事?

  •  
  •   anonydmer · 2021-11-29 16:15:04 +08:00 · 1519 次点击
    这是一个创建于 870 天前的主题,其中的信息可能已经有所发展或是发生改变。

    这个是 mac 版 weixin 中的一个叫 wxhook.js的文件,本人 js 不大行,看的一知半解,貌似对地理位置做监控了,但是这个监控到底达到了什么效果不大清楚。

    
    // 这个脚本会注入到主 frame 和 iframe 中
    try {
        if (typeof window.weixinPostMessageHandlers === 'undefined') {
            window.weixinPostMessageHandlers = window.webkit.messageHandlers;
            Object.defineProperty(window, 'weixinPostMessageHandlers', { value: window.weixinPostMessageHandlers,writable:false });
        }
    
        // hook navigator.geolocation.getCurrentPosition, 增加监控
        var oriGetCurrLocation = navigator.geolocation.getCurrentPosition;
        Object.defineProperty(navigator.geolocation, 'getCurrentPosition',
            { value: function(successCallback,errorCallback,opt)
                  {
                      var option = (typeof opt !== 'undefined') ? opt : {};
                      // alert(JSON.stringify(option));
                      oriGetCurrLocation.call(this,
                          function(position) {
                            if (typeof successCallback !== 'undefined') {
                              // alert(position.coords.longitude);
                              window.weixinPostMessageHandlers.monitorHandler.postMessage(JSON.stringify({event: 'getCurrentLocation', errCode: 0, option: option, funcType:1}));
                              successCallback(position);
                            };
                          },
                          function(err) {
                            // alert(err.code + ' ' + err.message);
                            window.weixinPostMessageHandlers.monitorHandler.postMessage(JSON.stringify({event: 'getCurrentLocation', errCode: err.code, option: option, funcType: 1}));
                            if (typeof errorCallback !== 'undefined') {
                              errorCallback(err);
                            };
    
                          },
                          option
                      );
                  },
              writable:true, //用户反馈 angular build 会修改这个属性,如果 false 会 js 运行错误
              configurable: false
            });
    
        // hook navigator.geolocation.watchPosition ,增加监控
        var oriWatchPosition = navigator.geolocation.watchPosition;
        Object.defineProperty(navigator.geolocation, 'watchPosition',
            { value: function(successCallback,errorCallback,opt)
                  {
                      var option = (typeof opt !== 'undefined') ? opt : {};
                      var bHaveReport = false;
                      // alert(JSON.stringify(option));
                      oriWatchPosition.call(this,
                          function(position) {
                            if (typeof successCallback !== 'undefined') {
                              // alert(position.coords.longitude);
                              if (!bHaveReport) {
                                bHaveReport = true;
                                window.weixinPostMessageHandlers.monitorHandler.postMessage(JSON.stringify({event: 'getCurrentLocation', errCode: 0, option: option, funcType: 2}));
                              };
                              successCallback(position);
                            };
                          },
                          function(err) {
                            // alert(err.code + ' ' + err.message);
                            window.weixinPostMessageHandlers.monitorHandler.postMessage(JSON.stringify({event: 'getCurrentLocation', errCode: err.code, option: option, funcType: 2}));
                            if (typeof errorCallback !== 'undefined') {
                              errorCallback(err);
                            };
    
                          },
                          option
                      );
                  },
              writable:true,
              configurable: false
            });
    } catch (e) {}
    
    
    5 条回复    2021-11-29 16:45:24 +08:00
    iold
        1
    iold  
       2021-11-29 16:31:08 +08:00
    你猜的没错,Geolocation.watchPosition() 用于注册监听器,在设备的地理位置发生改变的时候自动被调用。
    下面是文档连接:
    https://developer.mozilla.org/zh-CN/docs/Web/API/Geolocation/watchPosition
    flyhaozi
        2
    flyhaozi  
       2021-11-29 16:32:44 +08:00
    就只是给 getCurrentPosition 和 watchPosition 加了调用成功失败的监控日志吧,要监控具体位置也是在 successCallback 里做,这里也看不到,地理位置权限本来就是给了它想干嘛就干嘛,没必要别给权限就是了
    anonydmer
        3
    anonydmer  
    OP
       2021-11-29 16:38:55 +08:00
    @iold @flyhaozi 感谢。 所以我是否可以理解为,因为这个注入,我在微信中打开一个普通网页,这个普通网页用标准 js 接口获取地理位置的同时,微信都会把这个获取的地理位置信息上报给自己的服务器
    flyhaozi
        4
    flyhaozi  
       2021-11-29 16:42:13 +08:00   ❤️ 1
    @anonydmer window.weixinPostMessageHandlers.monitorHandler.postMessage(JSON.stringify({event: 'getCurrentLocation', errCode: 0, option: option, funcType:1}));
    报告的内容并没有地理位置,只有调用的函数还有错误代码啥的,而且也不能确定是报给了哪,说不定只是报给本地程序来写日志
    iold
        5
    iold  
       2021-11-29 16:45:24 +08:00   ❤️ 1
    @anonydmer #3 获取了地理位置是肯定的,上没上报 在 successCallback 里,这只有小聋知道了。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5418 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 05:47 · PVG 13:47 · LAX 22:47 · JFK 01:47
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.