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AAI,CAAC,cAAc,CAAC,CAAA;AAEtE,OAAO,EACL,cAAc,IAAI,cAAc,EACjC,CAAA\",\"sourcesContent\":[\"'use strict'\\n\\nimport { getObjectType } from '../objectType/index'\\nimport { Sandbox } from '../sandbox/index'\\nimport allowProtoProperties from './allowProtoProperties.config'\\n\\n// ShadowFunction\\nclass ShadowFunction {\\n  public sandbox = new Sandbox(false, this['allow properties'] || ['*'])\\n  public shadowWindow = this.sandbox.shadowWindow as ShadowWindow\\n  public ShadowFunction = this.shadowWindow.Function as FunctionConstructor\\n  private shadowHasOwnProperty = this.shadowWindow.Object.hasOwnProperty\\n  private ShadowObject = this.shadowWindow.Object\\n  private ShadowProxy = this.shadowWindow.Proxy\\n  private shadowFunction!: Function\\n  private allowProtoProperties = allowProtoProperties\\n  public run: Function = () => null\\n  public log (e: object): string | undefined | void {\\n    return console.log('Event Log:', e)\\n  }\\n  private tracker = (e: { origin: object, name: string | number | symbol, action: string, value?: any}) => {\\n    if (typeof (e.name) === 'symbol' || !isNaN(Number(e.name))) return 'no'\\n    switch (e.name) {\\n      case 'length':\\n      case '__proto__':\\n        break\\n      default:\\n        return this.log(e)\\n    }\\n    return 'no'\\n  }\\n\\n  constructor () {\\n    this.freezeShadowProto(this.shadowWindow)\\n  }\\n\\n  static debugger (isee: string, model = { 'no-Proxy': false }) {\\n    let msg = 'I know the danger!'\\n    if (isee === msg) {\\n      this.prototype['open debugger'] = true\\n      if (model['no-Proxy']) {\\n        this.prototype['open debugger: no-Proxy'] = true\\n      }\\n      if (Sandbox.prototype['unsafe-context'] !== true) {\\n        console.warn(`%c ShadowFunction: Opening the 'debugger' will result in a risk of losing security!`, 'font-size: 32px; color: red')\\n      }\\n    } else {\\n      console.log(`ShadowFunction: Opening 'debugger' input '${msg}'`)\\n    }\\n  }\\n\\n  static assignContextProperties (names = ['*']) {\\n    this.prototype['allow properties'] = names\\n  }\\n\\n  public setAllowProtoProperties (allowProperties: object | Array<string>) {\\n    Object.assign(this.allowProtoProperties, allowProperties)\\n    return this.preShadowFunction.bind(this)\\n  }\\n\\n  private freezeShadowProto (object: Object) {\\n    const Object = this.ShadowObject\\n    const propNames = Object.getOwnPropertyNames(object)\\n\\n    // Freeze properties before freezing self\\n    for (let name of propNames) {\\n      let value = object[name]\\n\\n      if (!value) break\\n      if (!(Object.getOwnPropertyDescriptor(object, name) || {}).writable) break\\n      typeof value === 'object' && this.freezeShadowProto(value)\\n    }\\n\\n    if (!Object.isFrozen(object['prototype'])) Object.freeze(object['prototype'])\\n  }\\n\\n  private getAllowProperties (object: object) {\\n    return this.getAllowProtoProperties(object).concat(Object.getOwnPropertyNames(object))\\n  }\\n\\n  private getAllowProtoProperties (object: object) {\\n    let propertyNames = this.allowProtoProperties[getObjectType(object)] || []\\n    if (object['__proto__']) return propertyNames.concat(this.getAllowProtoProperties(object['__proto__'] as object))\\n    return propertyNames\\n  }\\n\\n  private isElementObject (value: any): boolean {\\n    if (/HTML(\\\\w+)?Element/.exec(getObjectType(value))) return true\\n    return false\\n  }\\n\\n  private isFixedObject (value: any): boolean {\\n    if (this.isElementObject(value)) return false\\n    return typeof value === 'object'\\n  }\\n\\n  private safeGetter (origin: object, target: object, name: string | number | symbol) {\\n    if (this['open debugger'] && name === '...') {\\n      console.warn(`ShadowFunction: Unsafe return in debug mode！`)\\n      return origin\\n    }\\n    if (this.getAllowProperties(origin).indexOf(name as string) === -1) {\\n      this.tracker({\\n        origin,\\n        name,\\n        action: 'read'\\n      })\\n      return target[name]\\n    }\\n    if (origin[name] && !this.isFixedObject(origin[name]) && origin[name].hasOwnProperty === this.shadowHasOwnProperty) {\\n      return origin[name]\\n    }\\n    return this.proxy(origin[name], origin)\\n  }\\n\\n  private safeSetter (origin: object, target: object, name: string | number | symbol, value: any): boolean {\\n    target[name] = this.proxy(value, target)\\n    if (this.tracker({\\n      origin,\\n      name,\\n      action: 'write',\\n      value\\n    }) === `allow set ${name as string}`) origin[name] = target[name]\\n    return true\\n  }\\n\\n  private puppet (origin: object) {\\n    const Proxy = this.ShadowProxy\\n    const propNames = Object.getOwnPropertyNames(origin)\\n    const puppet = new this.ShadowObject()\\n    propNames.map((name) => {\\n      if ((Object.getOwnPropertyDescriptor(puppet, name) || { writable: true }).writable) puppet[name] = '...'\\n    })\\n    return new Proxy(puppet, {\\n      get: (target: object, name: string | number | symbol) => {\\n        return this.safeGetter(origin, target, name)\\n      },\\n      set: (target: any, name: string | number | symbol, value: any) => {\\n        return this.safeSetter(origin, target, name, value)\\n      }\\n    })\\n  }\\n\\n  private proxy (target: object, self: object | null = null) {\\n    if (this['open debugger: no-Proxy'] || !target) return target\\n    switch (typeof(target)) {\\n      case 'string':\\n      case 'number':\\n      case 'boolean':\\n      case 'undefined':\\n        return target\\n      case 'function':\\n        return this.safeReturnFunction(target as Function, self)\\n      case 'object':\\n        return this.puppet(target)\\n    }\\n    return\\n  }\\n\\n  private safeReturnFunction (fn: Function, origin: object | null) {\\n    const shadowFunction = new this.ShadowFunction('fn', 'origin', 'proxy', `\\n      return (function () {\\n        return function () {\\n          return proxy(fn.apply(origin, proxy(arguments)))\\n        }\\n      })()\\n    `)(fn, origin, this.proxy.bind(this))\\n    const propNames = Object.getOwnPropertyNames(fn)\\n    for (let name of propNames) {\\n      if ((Object.getOwnPropertyDescriptor(fn, name) || { writable: true }).writable) {\\n        if (name === 'prototype') continue\\n        shadowFunction[name] = this.proxy({ 0: fn[name] })[0]\\n      }\\n    }\\n    return shadowFunction\\n  }\\n\\n  public preShadowFunction (scriptStr: string) {\\n    this.shadowFunction = new this.ShadowFunction(`\\n      (function () {\\n        with (arguments[0].window || {}) {\\n          with (arguments[0].context || {}) {\\n            (function () {`\\n              + scriptStr +\\n            `}).bind(Object.assign(arguments[0].window || {}, arguments[0].context || {}))()\\n          }\\n        }\\n      })(this)`)\\n    return this.runShadowFunction.bind(this)\\n  }\\n\\n  public runShadowFunction (origin: object) {\\n    const target = this.proxy(origin)\\n    const shadowFunction = this.shadowFunction\\n    shadowFunction.apply(this.ShadowObject.assign(new this.ShadowObject(), { window: this.shadowWindow, context: target }))\\n\\n    return {\\n      run: this.preShadowFunction.bind(this),\\n      proxy: this.proxy.bind(this),\\n      sandbox: this.sandbox\\n    }\\n  }\\n}\\n\\nconst shadowFunction = (code: object | string, setting?: object, log?: (e: object) => void): void => {\\n  const sfnc = new ShadowFunction()\\n  if (log) sfnc.log = log\\n  if (setting) {\\n    sfnc.run = sfnc.setAllowProtoProperties(setting)(code as string)\\n  } else {\\n    switch (typeof (code)) {\\n      case 'object':\\n        sfnc.run = sfnc.setAllowProtoProperties(code as object)\\n        break\\n      case 'string':\\n        sfnc.run = sfnc.preShadowFunction(code as string)\\n        break\\n      default:\\n        throw new Error('ShadowFunction: Uncaught SyntaxError: Unexpected identifier.')\\n    }\\n  }\\n  return sfnc.run as unknown as void\\n}\\n\\nshadowFunction.debugger = ShadowFunction.debugger.bind(ShadowFunction)\\n\\nexport {\\n  shadowFunction as ShadowFunction\\n}\\n\"]}","code":"'use strict';\r\nimport { getObjectType } from '../objectType/index';\r\nimport { Sandbox } from '../sandbox/index';\r\nimport allowProtoProperties from './allowProtoProperties.config';\r\n// ShadowFunction\r\nvar ShadowFunction = /** @class */ (function () {\r\n    function ShadowFunction() {\r\n        var _this = this;\r\n        this.sandbox = new Sandbox(false, this['allow properties'] || ['*']);\r\n        this.shadowWindow = this.sandbox.shadowWindow;\r\n        this.ShadowFunction = this.shadowWindow.Function;\r\n        this.shadowHasOwnProperty = this.shadowWindow.Object.hasOwnProperty;\r\n        this.ShadowObject = this.shadowWindow.Object;\r\n        this.ShadowProxy = this.shadowWindow.Proxy;\r\n        this.allowProtoProperties = allowProtoProperties;\r\n        this.run = function () { return null; };\r\n        this.tracker = function (e) {\r\n            if (typeof (e.name) === 'symbol' || !isNaN(Number(e.name)))\r\n                return 'no';\r\n            switch (e.name) {\r\n                case 'length':\r\n                case '__proto__':\r\n                    break;\r\n                default:\r\n                    return _this.log(e);\r\n            }\r\n            return 'no';\r\n        };\r\n        this.freezeShadowProto(this.shadowWindow);\r\n    }\r\n    ShadowFunction.prototype.log = function (e) {\r\n        return console.log('Event Log:', e);\r\n    };\r\n    ShadowFunction.debugger = function (isee, model) {\r\n        if (model === void 0) { model = { 'no-Proxy': false }; }\r\n        var msg = 'I know the danger!';\r\n        if (isee === msg) {\r\n            this.prototype['open debugger'] = true;\r\n            if (model['no-Proxy']) {\r\n                this.prototype['open debugger: no-Proxy'] = true;\r\n            }\r\n            if (Sandbox.prototype['unsafe-context'] !== true) {\r\n                console.warn(\"%c ShadowFunction: Opening the 'debugger' will result in a risk of losing security!\", 'font-size: 32px; color: red');\r\n            }\r\n        }\r\n        else {\r\n            console.log(\"ShadowFunction: Opening 'debugger' input '\" + msg + \"'\");\r\n        }\r\n    };\r\n    ShadowFunction.assignContextProperties = function (names) {\r\n        if (names === void 0) { names = ['*']; }\r\n        this.prototype['allow properties'] = names;\r\n    };\r\n    ShadowFunction.prototype.setAllowProtoProperties = function (allowProperties) {\r\n        Object.assign(this.allowProtoProperties, allowProperties);\r\n        return this.preShadowFunction.bind(this);\r\n    };\r\n    ShadowFunction.prototype.freezeShadowProto = function (object) {\r\n        var Object = this.ShadowObject;\r\n        var propNames = Object.getOwnPropertyNames(object);\r\n        // Freeze properties before freezing self\r\n        for (var _i = 0, propNames_1 = propNames; _i < propNames_1.length; _i++) {\r\n            var name_1 = propNames_1[_i];\r\n            var value = object[name_1];\r\n            if (!value)\r\n                break;\r\n            if (!(Object.getOwnPropertyDescriptor(object, name_1) || {}).writable)\r\n                break;\r\n            typeof value === 'object' && this.freezeShadowProto(value);\r\n        }\r\n        if (!Object.isFrozen(object['prototype']))\r\n            Object.freeze(object['prototype']);\r\n    };\r\n    ShadowFunction.prototype.getAllowProperties = function (object) {\r\n        return this.getAllowProtoProperties(object).concat(Object.getOwnPropertyNames(object));\r\n    };\r\n    ShadowFunction.prototype.getAllowProtoProperties = function (object) {\r\n        var propertyNames = this.allowProtoProperties[getObjectType(object)] || [];\r\n        if (object['__proto__'])\r\n            return propertyNames.concat(this.getAllowProtoProperties(object['__proto__']));\r\n        return propertyNames;\r\n    };\r\n    ShadowFunction.prototype.isElementObject = function (value) {\r\n        if (/HTML(\\w+)?Element/.exec(getObjectType(value)))\r\n            return true;\r\n        return false;\r\n    };\r\n    ShadowFunction.prototype.isFixedObject = function (value) {\r\n        if (this.isElementObject(value))\r\n            return false;\r\n        return typeof value === 'object';\r\n    };\r\n    ShadowFunction.prototype.safeGetter = function (origin, target, name) {\r\n        if (this['open debugger'] && name === '...') {\r\n            console.warn(\"ShadowFunction: Unsafe return in debug mode\\uFF01\");\r\n            return origin;\r\n        }\r\n        if (this.getAllowProperties(origin).indexOf(name) === -1) {\r\n            this.tracker({\r\n                origin: origin,\r\n                name: name,\r\n                action: 'read'\r\n            });\r\n            return target[name];\r\n        }\r\n        if (origin[name] && !this.isFixedObject(origin[name]) && origin[name].hasOwnProperty === this.shadowHasOwnProperty) {\r\n            return origin[name];\r\n        }\r\n        return this.proxy(origin[name], origin);\r\n    };\r\n    ShadowFunction.prototype.safeSetter = function (origin, target, name, value) {\r\n        target[name] = this.proxy(value, target);\r\n        if (this.tracker({\r\n            origin: origin,\r\n            name: name,\r\n            action: 'write',\r\n            value: value\r\n        }) === \"allow set \" + name)\r\n            origin[name] = target[name];\r\n        return true;\r\n    };\r\n    ShadowFunction.prototype.puppet = function (origin) {\r\n        var _this = this;\r\n        var Proxy = this.ShadowProxy;\r\n        var propNames = Object.getOwnPropertyNames(origin);\r\n        var puppet = new this.ShadowObject();\r\n        propNames.map(function (name) {\r\n            if ((Object.getOwnPropertyDescriptor(puppet, name) || { writable: true }).writable)\r\n                puppet[name] = '...';\r\n        });\r\n        return new Proxy(puppet, {\r\n            get: function (target, name) {\r\n                return _this.safeGetter(origin, target, name);\r\n            },\r\n            set: function (target, name, value) {\r\n                return _this.safeSetter(origin, target, name, value);\r\n            }\r\n        });\r\n    };\r\n    ShadowFunction.prototype.proxy = function (target, self) {\r\n        if (self === void 0) { self = null; }\r\n        if (this['open debugger: no-Proxy'] || !target)\r\n            return target;\r\n        switch (typeof (target)) {\r\n            case 'string':\r\n            case 'number':\r\n            case 'boolean':\r\n            case 'undefined':\r\n                return target;\r\n            case 'function':\r\n                return this.safeReturnFunction(target, self);\r\n            case 'object':\r\n                return this.puppet(target);\r\n        }\r\n        return;\r\n    };\r\n    ShadowFunction.prototype.safeReturnFunction = function (fn, origin) {\r\n        var shadowFunction = new this.ShadowFunction('fn', 'origin', 'proxy', \"\\n      return (function () {\\n        return function () {\\n          return proxy(fn.apply(origin, proxy(arguments)))\\n        }\\n      })()\\n    \")(fn, origin, this.proxy.bind(this));\r\n        var propNames = Object.getOwnPropertyNames(fn);\r\n        for (var _i = 0, propNames_2 = propNames; _i < propNames_2.length; _i++) {\r\n            var name_2 = propNames_2[_i];\r\n            if ((Object.getOwnPropertyDescriptor(fn, name_2) || { writable: true }).writable) {\r\n                if (name_2 === 'prototype')\r\n                    continue;\r\n                shadowFunction[name_2] = this.proxy({ 0: fn[name_2] })[0];\r\n            }\r\n        }\r\n        return shadowFunction;\r\n    };\r\n    ShadowFunction.prototype.preShadowFunction = function (scriptStr) {\r\n        this.shadowFunction = new this.ShadowFunction(\"\\n      (function () {\\n        with (arguments[0].window || {}) {\\n          with (arguments[0].context || {}) {\\n            (function () {\"\r\n            + scriptStr +\r\n            \"}).bind(Object.assign(arguments[0].window || {}, arguments[0].context || {}))()\\n          }\\n        }\\n      })(this)\");\r\n        return this.runShadowFunction.bind(this);\r\n    };\r\n    ShadowFunction.prototype.runShadowFunction = function (origin) {\r\n        var target = this.proxy(origin);\r\n        var shadowFunction = this.shadowFunction;\r\n        shadowFunction.apply(this.ShadowObject.assign(new this.ShadowObject(), { window: this.shadowWindow, context: target }));\r\n        return {\r\n            run: this.preShadowFunction.bind(this),\r\n            proxy: this.proxy.bind(this),\r\n            sandbox: this.sandbox\r\n        };\r\n    };\r\n    return ShadowFunction;\r\n}());\r\nvar shadowFunction = function (code, setting, log) {\r\n    var sfnc = new ShadowFunction();\r\n    if (log)\r\n        sfnc.log = log;\r\n    if (setting) {\r\n        sfnc.run = sfnc.setAllowProtoProperties(setting)(code);\r\n    }\r\n    else {\r\n        switch (typeof (code)) {\r\n            case 'object':\r\n                sfnc.run = sfnc.setAllowProtoProperties(code);\r\n                break;\r\n            case 'string':\r\n                sfnc.run = sfnc.preShadowFunction(code);\r\n                break;\r\n            default:\r\n                throw new Error('ShadowFunction: Uncaught SyntaxError: Unexpected identifier.');\r\n        }\r\n    }\r\n    return sfnc.run;\r\n};\r\nshadowFunction.debugger = ShadowFunction.debugger.bind(ShadowFunction);\r\nexport { shadowFunction as ShadowFunction };\r\n//# sourceMappingURL=index.js.map","dts":{"name":"/Users/ioing/libdev/shadow-function/dist/typings/shadowFunction/index.d.ts","writeByteOrderMark":false,"text":"declare const shadowFunction: {\r\n    (code: string | object, setting?: object | undefined, log?: ((e: object) => void) | undefined): void;\r\n    debugger: (isee: string, model?: {\r\n        'no-Proxy': boolean;\r\n    } | undefined) => void;\r\n};\r\nexport { shadowFunction as ShadowFunction };\r\n"}}
