This commit is contained in:
fofolee 2020-07-14 21:04:13 +08:00
parent 7c32de1bbc
commit 1a3c9325a2

View File

@ -325,7 +325,7 @@ let modWindowHeight = height => {
}
// 屏蔽危险函数
var getuToolsLite = () => {
let getuToolsLite = () => {
var utoolsLite = Object.assign({}, utools)
delete utoolsLite.db
delete utoolsLite.removeFeature
@ -333,7 +333,7 @@ var getuToolsLite = () => {
return utoolsLite
}
var getSandboxFuns = () => {
let getSandboxFuns = () => {
var sandbox = {
utools: getuToolsLite(),
quickcommand: quickcommand,
@ -352,7 +352,7 @@ var getSandboxFuns = () => {
return sandbox
}
runCodeInVm = (cmd, cb, payload = "") => {
let createNodeVM = (payload = "") => {
var sandbox = getSandboxFuns()
sandbox.quickcommand.payload = payload
const vm = new NodeVM({
@ -364,32 +364,36 @@ runCodeInVm = (cmd, cb, payload = "") => {
env: process.env,
sandbox: sandbox,
});
return vm
}
var parseItem = item => {
if (typeof (item) == "object") {
if (Buffer.isBuffer(item)) {
var bufferString = `[Buffer ${item.slice(0, 50).toString('hex').match(/\w{1,2}/g).join(" ")}`
if (item.length > 50) bufferString += `... ${(item.length / 1000).toFixed(2)}kb`
return bufferString + ']'
} else {
try {
var cache = [];
var string = JSON.stringify(item, (key, value) => {
if (typeof value === 'object' && value !== null) {
if (cache.indexOf(value) !== -1) return
cache.push(value);
}
return value;
}, '\t')
if (string != "{}") return string
} catch (error) { }
}
} else if (typeof (item) == "undefined") {
return "undefined"
let parseItem = item => {
if (typeof (item) == "object") {
if (Buffer.isBuffer(item)) {
var bufferString = `[Buffer ${item.slice(0, 50).toString('hex').match(/\w{1,2}/g).join(" ")}`
if (item.length > 50) bufferString += `... ${(item.length / 1000).toFixed(2)}kb`
return bufferString + ']'
} else {
try {
var cache = [];
var string = JSON.stringify(item, (key, value) => {
if (typeof value === 'object' && value !== null) {
if (cache.indexOf(value) !== -1) return
cache.push(value);
}
return value;
}, '\t')
if (string != "{}") return string
} catch (error) { }
}
return item.toString()
} else if (typeof (item) == "undefined") {
return "undefined"
}
return item.toString()
}
runCodeInVm = (cmd, cb, payload = "") => {
const vm = createNodeVM(payload)
//重定向 console
vm.on('console.log', stdout => {
console.log(stdout);