天天看点

修改chromium代码,动态解析javascript脚本

一、目的

由于实验需要,我想要实现一个这样的功能,使用浏览器浏览一个网站时,将该网站的javascript脚本调用了哪些api记录下来。

test.html

修改chromium代码,动态解析javascript脚本

1.js

修改chromium代码,动态解析javascript脚本

以上面这段代码为例,当浏览器浏览test.html时,脚本引擎会解析document.write,screen.width,screen.height,screen.availLeft,,screen.availTop,并执行相应的函数,我想将哪个脚本掉用了什么样的函数记录下来,也就是输出格式如下的日志

Document::wirte onURL:test.html onJsURL:test.html

Document::write onURL:test.html onJsURL:test.html

Screen::width onURL:test.html onJsURL:test.html  

Screen::height onURL:test.html onJsURL:test.html  

Document::write onURL:test.html onJsURL:js/1.js  

Document::write onURL:test.html onJsURL:js/1.js  

Screen::availLeft onURL:test.html onJsURL:js/1.js  

Screen::availTop onURL:test.html onJsURL:js/1.js  

为什么要实验这样的功能呢?主要是为了分析javascript代码的行为,观测其动作,可以进行恶意代码检测等。

二、chromium简介

chromium的浏览器内核是webkit,而webkit中使用的v8脚本引擎。所谓浏览器内核就是要实现浏览器的核心功能,即排版渲染功能。如下图所示:

修改chromium代码,动态解析javascript脚本

那么浏览器是如何