zy-补环境框架-实现-window补环境

This commit is contained in:
aiyingfeng 2023-08-12 14:53:33 +08:00
parent 25b7f8ad74
commit cbb1f773e0
26 changed files with 0 additions and 753 deletions

View File

@ -1,23 +0,0 @@
const HtmlDivElement =function HtmlDivElement()
{
throw new TypeError('Illegal constructor')
}
catvm.safefunction(HtmlDivElement);
Object.defineProperties(HtmlDivElement.prototype,{
[Symbol.toStringTag]:{
value:'HtmlDivElement',
configurable:true,
}
})
//htmlDivElement = catvm.proxy(htmlDivElement)
catvm.memory.htmlElements['div'] = function(){
const div = new (function(){})
div.align = ''
div.__proto__ = HtmlDivElement.prototype
return div
}

View File

@ -1,14 +0,0 @@
import fs from 'fs';
import path from 'path';
import { fileURLToPath } from 'url';
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
export default function GetCode(){
let code = ''
code += fs.readFileSync(`${__dirname}/htmlDivElement.js`) + '\r\n'
return code
}

View File

@ -1,38 +0,0 @@
const Document =function Document()
{
}
catvm.safefunction(Document);
Object.defineProperties(Document.prototype,{
[Symbol.toStringTag]:{
value:'Document',
configurable:true,
}
})
document = {}
document.__proto__ = Document.prototype
document.cookie = ''
document.referrer = location.href || ''
document.getElementById = function getElementById(id){
return null
}
catvm.safefunction(document.getElementById)
document.addEventListener = function addEventListener(type,listener,useCapture){
}
catvm.safefunction(document.addEventListener)
document.createElement = function createElement(tagName){
let tagname = tagName.toLowerCase() + ''
if(catvm.memory.htmlElements[tagname] == undefined){
debugger
}
return catvm.proxy(catvm.memory.htmlElements[tagname]())
}
catvm.safefunction(document.createElement)
document = catvm.proxy(document)

View File

@ -1,27 +0,0 @@
const EventTarget =function EventTarget()
{
}
catvm.safefunction(EventTarget);
Object.defineProperties(EventTarget.prototype,{
[Symbol.toStringTag]:{
value:'EventTarget',
configurable:true,
}
})
EventTarget.prototype.addEventListener = function addEventListener(type,callback){
if(!(type in catvm.memory.listeners)){
catvm.memory.listeners[type] = []
}
catvm.memory.listeners[type].push(callback)
}
catvm.safefunction(EventTarget.prototype.addEventListener);
EventTarget.prototype.dispatchEvent = function dispatchEvent(){
}
catvm.safefunction(EventTarget.prototype.dispatchEvent);
EventTarget.prototype.removeEventListener = function removeEventListener(){
}
catvm.safefunction(EventTarget.prototype.removeEventListener);

View File

@ -1,19 +0,0 @@
const History =function History()
{
throw new TypeError('Illegal constructor')
}
catvm.safefunction(History);
Object.defineProperties(History.prototype,{
[Symbol.toStringTag]:{
value:'History',
configurable:true,
}
})
History.prototype.back = function back(){}
catvm.safefunction(History.prototype.back);
history = {}
history.__proto__ = History.prototype
history = catvm.proxy(history)

View File

@ -1,18 +0,0 @@
const Location =function Location()
{
throw new TypeError('Illegal constructor')
}
catvm.safefunction(Location);
Object.defineProperties(Location.prototype,{
[Symbol.toStringTag]:{
value:'Location',
configurable:true,
}
})
location = {}
location.__proto__ = Location.prototype
location.href = ''
location = catvm.proxy(location)

View File

@ -1,42 +0,0 @@
catvm.memory.MimeType = {}
const MimeType =function MimeType()
{
throw new TypeError('Illegal constructor')
}
catvm.safefunction(MimeType);
Object.defineProperties(MimeType.prototype,{
[Symbol.toStringTag]:{
value:'MimeType',
configurable:true,
}
})
MimeType.prototype.description = ''
MimeType.prototype.enabledPlugin = null
MimeType.prototype.suffixes = ''
MimeType.prototype.type = 0
for (let pr in MimeType.prototype) {
if(typeof (MimeType.prototype[pr]) != 'function'){
MimeType.prototype.__defineGetter__(pr,function(){
return this[pr]
}
)
}
}
catvm.memory.MimeType.new = function(data,initPlugin){
let mimeType = {}
if(data != undefined){
mimeType.description = data.description
mimeType.enabledPlugin = initPlugin
mimeType.suffixes = data.suffixes
mimeType.type = data.type
}
mimeType.__proto__ = MimeType.prototype
return mimeType
}

View File

@ -1,72 +0,0 @@
catvm.memory.MimeTypeArray = {}
const MimeTypeArray =function MimeTypeArray()
{
throw new TypeError('Illegal constructor')
}
catvm.safefunction(MimeTypeArray);
catvm.memory.MimeTypeArray.iterator = function values(){
debugger
}
catvm.safefunction(catvm.memory.MimeTypeArray.iterator);
Object.defineProperties(MimeTypeArray.prototype,{
[Symbol.toStringTag]:{
value:'MimeTypeArray',
configurable:true,
},
[Symbol.iterator]:{
value:catvm.memory.MimeTypeArray.iterator,
configurable:true,
}
})
MimeTypeArray.prototype.item = function item(index){
debugger
return this[index]
}
catvm.safefunction(MimeTypeArray.prototype.item)
MimeTypeArray.prototype.namedItem = function namedItem(key){
debugger
return this[key]
}
catvm.safefunction(MimeTypeArray.prototype.namedItem)
MimeTypeArray.prototype.length = 0
for (let pr in MimeTypeArray.prototype) {
if(typeof (MimeTypeArray.prototype[pr]) != 'function'){
MimeTypeArray.prototype.__defineGetter__(pr,function(){
throw new TypeError('Illegal constructor')
}
)
}
}
navigator.mimeTypes = {}
/* navigator.mimeTypes.temp = 0
for (let pindex = 0; pindex < navigator.plugins.length; pindex++) {
let plugin_ = navigator.plugins.item(pindex)
for (let mindex = 0; mindex < plugin_.length; mindex++) {
let mimeType_ = plugin.item(mindex)
if(navigator.mimeTypes[mimeType_.type] == undefined){
navigator.mimeTypes[navigator.mimeTypes.temp] = mimeType_
Object.defineProperty(navigator.mimeTypes,mimeType_.type,{
value:mimeType_,
})
navigator.mimeTypes.temp++
}
}
}
delete navigator.mimeTypes.temp */
navigator.mimeTypes.__proto__ = MimeTypeArray.prototype
navigator.mimeTypes = catvm.proxy(navigator.mimeTypes)

View File

@ -1,35 +0,0 @@
const Navigator =function Navigator()
{
throw new TypeError('Illegal constructor')
}
catvm.safefunction(Navigator);
Object.defineProperties(Navigator.prototype,{
[Symbol.toStringTag]:{
value:'Navigator',
configurable:true,
}
})
Object.getOwnPropertyDescriptor_ = Object.getOwnPropertyDescriptor;
Object.getOwnPropertyDescriptor = function(tag, val){
// tag[Symbol.toStringtag]
if(tag.toLocaleString() == '[object Navigator]'){
return undefined;
}
return Object.getOwnPropertyDescriptor_.apply(this,arguments)
}
Navigator.prototype.plugins = []
Navigator.prototype.language = ['zh-CN','zh']
Navigator.prototype.userAgent = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.0.0 Safari/537.36'
navigator = {}
navigator.__proto__ = Navigator.prototype
for (let prototype_ in Navigator.prototype) {
navigator[prototype_] = Navigator.prototype[prototype_]
Navigator.prototype.__defineGetter__(prototype_,function(){
throw new TypeError('Illegal constructor')
})
}
navigator = catvm.proxy(navigator)

View File

@ -1,95 +0,0 @@
catvm.memory.Plugin = {}
const Plugin =function Plugin()
{
throw new TypeError('Illegal constructor')
}
catvm.safefunction(Plugin);
catvm.memory.Plugin.iterator = function values(){
debugger
return {
next:function(){
if(this.index_ == undefined){
this.index_ = 0
}
let temp = this.self_[this.index_]
this.index_++
if(temp!=undefined)
{
return {done:false,value:temp}
}
else
{
return {done:true,value:undefined}
}
},
self_:this,
}
}
catvm.safefunction(catvm.memory.Plugin.iterator);
Object.defineProperties(Plugin.prototype,{
[Symbol.toStringTag]:{
value:'Plugin',
configurable:true,
},
[Symbol.iterator]:{
value:catvm.memory.Plugin.iterator,
configurable:true,
}
})
Plugin.prototype.description = ''
Plugin.prototype.filename = ''
Plugin.prototype.name = ''
Plugin.prototype.length = 0
Plugin.prototype.item = function item(index){
debugger
return this[index]
}
catvm.safefunction(Plugin.prototype.item);
Plugin.prototype.namedItem = function namedItem(key){
debugger
return this[key]
}
catvm.safefunction(Plugin.prototype.namedItem);
for (let pr in Plugin.prototype) {
if(typeof (Plugin.prototype[pr]) != 'function'){
Plugin.prototype.__defineGetter__(pr,function(){
throw new TypeError('Illegal constructor')
}
)
}
}
catvm.memory.Plugin.new = function(data){
let plugin = {}
if(data != undefined){
plugin.description = data.description
plugin.filename = data.filename
plugin.name = data.name
if(data.MimeTypes != undefined){
for (let mtindex = 0; mtindex < data.MimeTypes.length; mtindex++) {
let mtindex = data.MimeTypes[mtindex]
let mimeType = catvm.memory.MimeType.new(mtindex,plugin)
plugin[mtindex] = mimeType
/* plugin[mimeType.type] = mimeType */
Object.defineProperty(plugin,mimeType.type,{
value:mimeType,
})
}}
plugin.length = data.MimeTypes.length
}
plugin.__proto__ = Plugin.prototype
return plugin
}

View File

@ -1,57 +0,0 @@
const PluginArray =function PluginArray()
{
throw new TypeError('Illegal constructor')
}
catvm.safefunction(PluginArray);
catvm.memory.PluginArray.iterator = function values(){
debugger
}
catvm.safefunction(catvm.memory.PluginArray.iterator);
Object.defineProperties(PluginArray.prototype,{
[Symbol.toStringTag]:{
value:'PluginArray',
configurable:true,
},
[Symbol.iterator]:{
value:catvm.memory.PluginArray.iterator,
configurable:true,
}
})
PluginArray.prototype.item = function item(index){
debugger
return this[index]
}
catvm.safefunction(PluginArray.prototype.item)
PluginArray.prototype.namedItem = function namedItem(key){
debugger
return this[key]
}
catvm.safefunction(PluginArray.prototype.namedItem)
PluginArray.prototype.refresh = function refresh(){
debugger
}
catvm.safefunction(PluginArray.prototype.refresh)
PluginArray.prototype.length = 0
for (let pr in PluginArray.prototype) {
if(typeof (PluginArray.prototype[pr]) != 'function'){
PluginArray.prototype.__defineGetter__(pr,function(){
throw new TypeError('Illegal constructor')
}
)
}
}
catvm.memory.PluginArray._ = {}
catvm.memory.PluginArray._.__proto__ = PluginArray.prototype
catvm.memory.PluginArray._= catvm.proxy(catvm.memory.PluginArray._)
navigator.plugins = catvm.memory.PluginArray._

View File

@ -1,17 +0,0 @@
const Screen =function Screen()
{
throw new TypeError('Illegal constructor')
}
catvm.safefunction(Screen);
Object.defineProperties(Screen.prototype,{
[Symbol.toStringTag]:{
value:'Screen',
configurable:true,
}
})
screen = {}
screen.__proto__ = Screen.prototype
screen = catvm.proxy(screen)

View File

@ -1,50 +0,0 @@
const Storage =function Storage()
{
throw new TypeError('Illegal constructor')
}
catvm.safefunction(Storage);
Object.defineProperties(Storage.prototype,{
[Symbol.toStringTag]:{
value:'Storage',
configurable:true,
}
})
Storage.prototype.length=0;
Storage.prototype.clear=function clear(){
debugger
let temp = Object.keys(this)
for(let key =0 ;key<temp.length;key++){
delete this[key]
}
}; catvm.safefunction(Storage.prototype.clear);
Storage.prototype.getItem=function getItem(k){
debugger
return this[k]
return
}; catvm.safefunction(Storage.prototype.getItem);
Storage.prototype.key=function key(){
debugger
return Object.keys(this)[index]
}; catvm.safefunction(Storage.prototype.key);
Storage.prototype.removeItem=function removeItem(k){
debugger
delete this[k]
}; catvm.safefunction(Storage.prototype.removeItem);
Storage.prototype.setItem=function setItem(k,v){
debugger
this[k] = v
}; catvm.safefunction(Storage.prototype.setItem);
Storage.prototype.__defineGetter__('length',function length(){
return Object.keys(this).length
})
localStorage = {}
localStorage.__proto__ = Storage.prototype
localStorage = catvm.proxy(localStorage)
sessionStorage = {}
sessionStorage.__proto__ = Storage.prototype
sessionStorage = catvm.proxy(sessionStorage)

View File

@ -1,41 +0,0 @@
window = this
const Window =function Window()
{
throw new TypeError('Illegal constructor')
}
catvm.safefunction(Window);
window,setTimeout = function setTimeout(callback,delay){
typeof(callback) === 'function' ? callback() : undefined
typeof(callback) === 'string' ? eval(callback) : undefined
return 0
}
catvm.safefunction(window.setTimeout );
Window.prototype.PERSISTENT = 1
Window.prototype.TEMPORARY = 0
window.open =function open(){}
window.chrome = catvm.proxy(class chrome{})
window.DeviceOrientationEvent = function DeviceOrientationEvent(){}
window.DeviceMotionEvent = function DeviceMotionEvent(){}
catvm.safefunction(window.open);
catvm.safefunction(window.DeviceOrientationEvent);
catvm.safefunction(window.DeviceMotionEvent);
window.localStorage = class localStorage{}
window.localStorage.getItem = function getItem(){}
window.localStorage.setItem = function getItem(){}
catvm.safefunction(window.localStorage.getItem );
catvm.safefunction(window.localStorage.setItem );
catvm.proxy(window.localStorage)
Window.prototype.__proto__ = windowProperties.prototype;
window.__proto__ = Window.prototype
Object.defineProperties(Window.prototype,{
[Symbol.toStringTag]:{
value:'Window',
configurable:true,
}
})
window = catvm.proxy(window)

View File

@ -1,13 +0,0 @@
const windowProperties =function windowProperties()
{
}
catvm.safefunction(windowProperties);
Object.defineProperties(windowProperties.prototype,{
[Symbol.toStringTag]:{
value:'windowProperties',
configurable:true,
}
})
windowProperties.prototype.__proto__ = EventTarget.prototype;

View File

@ -1,40 +0,0 @@
import fs from 'fs'
// 框架的工具模块
import vmtools from './tools/node.js'
import htmlElements from './browser/HTMLElements/htmlElements.node.js'
import path from 'path';
import { fileURLToPath } from 'url';
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
export default function GetCode(config,fun_text){
let code = ''
// 引入框架的工具代码
code += vmtools() +'\r\n'
// 引入用户框架配置
for (let item in config) {
code += 'catvm.memory.config.' + item + '=' + config[item] + '\r\n'
}
// 引入浏览器相关
code += fs.readFileSync(`${__dirname}/browser/eventTarget.js`) + '\r\n'
code += fs.readFileSync(`${__dirname}/browser/windowProperties.js`) + '\r\n'
code += fs.readFileSync(`${__dirname}/browser/window.js`) + '\r\n'
code += fs.readFileSync(`${__dirname}/browser/location.js`) + '\r\n'
code += fs.readFileSync(`${__dirname}/browser/navigator.js`) + '\r\n'
code += fs.readFileSync(`${__dirname}/browser/history.js`) + '\r\n'
code += fs.readFileSync(`${__dirname}/browser/screen.js`) + '\r\n'
code += fs.readFileSync(`${__dirname}/browser/storage.js`) + '\r\n'
code += fs.readFileSync(`${__dirname}/browser/mimeType.js`) + '\r\n'
code += fs.readFileSync(`${__dirname}/browser/plugin.js`) + '\r\n'
code += fs.readFileSync(`${__dirname}/browser/pluginArray.js`) + '\r\n'
code += fs.readFileSync(`${__dirname}/browser/mimeTypeArray.js`) + '\r\n'
code += htmlElements() + '\r\n'
code += fs.readFileSync(`${__dirname}/browser/document.js`) + '\r\n'
// 引入用户自定义环境
code += 'debugger;\r\n'
return code
}

View File

@ -1,9 +0,0 @@
global.catvm = {}
// 框架运行内存
catvm.memory = {
config: {print: false, proxy: false},
}
catvm.memory.htmlElements = {}
catvm.memory.listeners = {}
catvm.memory.PluginArray = {}

View File

@ -1,15 +0,0 @@
import fs from 'fs';
import path from 'path';
import { fileURLToPath } from 'url';
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
export default function GetCode(){
let code = ''
code += fs.readFileSync(`${__dirname}/memory.js`) + '\r\n'
code += fs.readFileSync(`${__dirname}/safefunction.js`) + '\r\n'
code += fs.readFileSync(`${__dirname}/print.js`) + '\r\n'
code += fs.readFileSync(`${__dirname}/proxy.js`) + '\r\n'
return code
}

View File

@ -1,15 +0,0 @@
// 框架日志功能
catvm.print = {}
catvm.memory.print = []
// 是否输出日志
catvm.print.log = function(){
if (catvm.memory.config.print){
}
}
// 获得所有日志
catvm.print.getall = function(){
}

View File

@ -1,22 +0,0 @@
// 框架代理功能
catvm.proxy = function(o){
if(catvm.memory.config.proxy == false){return o}
return new Proxy(o,{
set(target,key,value)
{
console.log('set',target,key,value);
return Reflect.set(...arguments);
},
get(target,key,receiver)
{
console.log('get',target,key,target[key]);
return target[key];
},
deleteProperty:function(target,key){
console.log('delete',target,key);
return true
}
});
}

View File

@ -1,27 +0,0 @@
// 补环境的自定义方法通过toString方法被检测
;(() => {
'use strict';
const $toString = Function.toString
const myFunction_toString_symbol = Symbol('('.concat('', ')_', (Math.random() + '').toString(36)))
const myToString = function () {
return typeof this == 'function' && this[myFunction_toString_symbol] || $toString.call(this)
}
function set_native(func, key, value) {
Object.defineProperty(func, key, {
"enumerable": false,
'configurable': true,
'writable': true,
'value': value
})
}
delete Function.prototype['toString'];// 删除原型链上的toString
set_native(Function.prototype, 'toString', myToString);// 自己定义一个getter方法
// 套娃给 toString 方法设置一个 toString
set_native(Function.prototype.toString, myFunction_toString_symbol, 'function toString(){ [native code] }')
this.catvm.safefunction = (func) => {
set_native(func, myFunction_toString_symbol, `function ${myFunction_toString_symbol, func.name || ''}() { [native code] }`)
}
}).call(this);

View File

@ -1,5 +0,0 @@
//更改浏览器某些参数
catvm.AddPlugin = function(data){
}

View File

@ -1,38 +0,0 @@
项目参考js逆向之模拟浏览器环境
https://hexo-fanchangrui.vercel.app/2022/08/05/js%E9%80%86%E5%90%91%E4%B9%8B%E6%A8%A1%E6%8B%9F%E6%B5%8F%E8%A7%88%E5%99%A8%E7%8E%AF%E5%A2%83/
# 补环境框架实现
```
.
├── CatVm2 文件目录
│ ├── browser 浏览器环境
│ │ ├── HTMLElements
│ │ ├── document.js
│ │ ├── eventTarget.js
│ │ ├── history.js
│ │ ├── htmlDocument.js
│ │ ├── location.js
│ │ ├── mimeType.js
│ │ ├── mimeTypeArray.js
│ │ ├── navigator.js
│ │ ├── plugin.js
│ │ ├── pluginArray.js
│ │ ├── screen.js
│ │ ├── storage.js
│ │ ├── window.js window环境
│ │ ├── windowProperties.js
│ │── tools
│ │ ├── memory.js 框架运行内存
│ │ ├── node.js 将工具代码组合
│ │ ├── print.js 框架日志功能
│ │ ├── proxy.js 框架代理功能
│ │ ├── safefunction.js 补环境的自定义方法
│ │ ├── tools.js 更改浏览器某些参数
│ │─── catvm2.node.js 补环境的拼接代码
├── code.js 原代码
├── index.js 启动代码
├── README.md 文档
```
## 补window环境

View File

@ -1,21 +0,0 @@
import fs from 'fs';
// 从 vm2 模块中导入了 VM 和 VMScript 两个类
import {VM, VMScript} from 'vm2';
// 引入需要执行的js文件
import cat_vm2 from './CatVm2/catvm2.node.js';
import path from 'path';
// 获取当前文件的目录
import {fileURLToPath} from 'url';
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const cat_vm2_code = cat_vm2({proxy: true});
const code_file = `${__dirname}/code.js`;
const vm = new VM()
const script = new VMScript(cat_vm2_code + fs.readFileSync(code_file), `${__dirname}/调试.js`);
debugger
vm.run(script);
debugger