代码混淆:对比 vue3 vite 和 webpack 的表现
最编程
2024-08-14 07:17:52
...
为什么用到vite 和webpack 代码混淆两种打包工具?
原因很尴尬 本来想用vue3+vite 但是需求是要求打包后,可以通过flie 文件访问不使用启动服务访问,*下采用了webpack打包
当然在vite中尝试了另一种方式直接访问file, 但是由于混淆后不可用放弃了vite。使用的插件@vitejs/plugin-legacy 可以访问file 但是不可以和混淆使用
然后上代码
vite.config.js 至于为什么用rollup-plugin-obfuscator 很艰辛 尝试过vite-plugin-javascript-obfuscator rollup-plugin-javascript-obfuscator rollup-obfuscator 都有点小问题
import obfuscatorBox from 'rollup-plugin-obfuscator';
plugins: [
...
obfuscatorBox({
global:true,
options: {
compact: true,
controlFlowFlattening: true,
controlFlowFlatteningThreshold: 0.75,
numbersToExpressions: true,
simplify: true,
stringArrayShuffle: true,
splitStrings: true,
splitStringsChunkLength: 10,
rotateUnicodeArray: true,
deadCodeInjection: true,
deadCodeInjectionThreshold: 0.4,
debugProtection: false,
debugProtectionInterval: 2000,
disableConsoleOutput: true,
domainLock: [],
identifierNamesGenerator: "hexadecimal",
identifiersPrefix: "",
inputFileName: "",
log: true,
renameGlobals: true,
reservedNames: [],
reservedStrings: [],
seed: 0,
selfDefending: true,
sourceMap: false,
sourceMapBaseUrl: "",
sourceMapFileName: "",
sourceMapMode: "separate",
stringArray: true,
stringArrayEncoding: ["base64"],
stringArrayThreshold: 0.75,
target: "browser",
transformObjectKeys: true,
unicodeEscapeSequence: true,
domainLockRedirectUrl: "about:blank",
forceTransformStrings: [],
identifierNamesCache: null,
identifiersDictionary: [],
ignoreImports: true,
optionsPreset: "default",
renameProperties: false,
renamePropertiesMode: "safe",
sourceMapSourcesMode: "sources-content",
stringArrayCallsTransform: true,
stringArrayCallsTransformThreshold: 0.5,
stringArrayIndexesType: ["hexadecimal-number"],
stringArrayIndexShift: true,
stringArrayRotate: true,
stringArrayWrappersCount: 1,
stringArrayWrappersChainedCalls: true,
stringArrayWrappersParametersMaxCount: 2,
stringArrayWrappersType: "variable",
},
}),
]
另外一种方式 webpack使用混淆
html-webpack-plugin 这个比较好用 一次就成
const HtmlWebpackPlugin = require('html-webpack-plugin')
new JavaScriptObfuscator({
compact: true,
controlFlowFlattening: true,
controlFlowFlatteningThreshold: 0.75,
numbersToExpressions: true,
simplify: true,
stringArrayShuffle: true,
splitStrings: true,
splitStringsChunkLength: 10,
rotateUnicodeArray: true,
deadCodeInjection: true,
deadCodeInjectionThreshold: 0.4,
debugProtection: false,
debugProtectionInterval: 2000,
disableConsoleOutput: true,
domainLock: [],
identifierNamesGenerator: "hexadecimal",
identifiersPrefix: "",
inputFileName: "",
log: true,
renameGlobals: true,
reservedNames: [],
reservedStrings: [],
seed: 0,
selfDefending: true,
sourceMap: false,
sourceMapBaseUrl: "",
sourceMapFileName: "",
sourceMapMode: "separate",
stringArray: true,
stringArrayEncoding: ["base64"],
stringArrayThreshold: 0.75,
target: "browser",
transformObjectKeys: true,
unicodeEscapeSequence: true,
domainLockRedirectUrl: "about:blank",
forceTransformStrings: [],
identifierNamesCache: null,
identifiersDictionary: [],
ignoreImports: true,
optionsPreset: "default",
renameProperties: false,
renamePropertiesMode: "safe",
sourceMapSourcesMode: "sources-content",
stringArrayCallsTransform: true,
stringArrayCallsTransformThreshold: 0.5,
stringArrayIndexesType: ["hexadecimal-number"],
stringArrayIndexShift: true,
stringArrayRotate: true,
stringArrayWrappersCount: 1,
stringArrayWrappersChainedCalls: true,
stringArrayWrappersParametersMaxCount: 2,
stringArrayWrappersType: "variable",
}, [])
效果图
由于理解不够多 以下来源gpt解释:
代码混淆是一种通过对源代码进行转换和优化的技术,目的是增加代码的复杂性,使其难以被理解和逆向工程。混淆可以帮助保护代码的知识产权,防止源代码被窃取、篡改或复制,提高代码的安全性。以下是一个简要的代码混淆的步骤和方法:
-
基本概念:
- 标识符重命名:通过将变量、函数和类的名称替换为无意义的字符或短名称,增加代码的复杂性和难以理解性。
- 控制流混淆:通过改变代码的控制流程,如插入无用的代码、重排序代码块、添加条件语句等,增加代码的复杂度和逻辑性。
-
使用工具:
- JavaScript混淆器:例如 UglifyJS、Terser、Obfuscator等,它们可以对 JavaScript 代码进行压缩和混淆处理。
- CSS和HTML压缩器:用于压缩和混淆CSS和HTML代码,例如 CSSNano、HTMLMinifier等。
- 专用混淆工具:例如 Jscrambler、CodeMorph等,它们提供更高级的混淆技术和功能。
-
混淆技术:
- 标识符重命名:通过替换变量和函数的名称为随机生成的字符或短名称,增加代码的复杂性和难以理解性。
- 字符串加密:将字符串转换为加密形式,需要时再解密,使得代码中的字符串难以被直接获取。
- 控制流转换:通过重排序代码块、添加条件语句和无用代码等,改变代码的控制流程,增加代码的逻辑性和难以分析性。
- 代码扁平化:将多个代码块合并为一个,减少函数和代码的层次结构,使代码更难以理解。
- 反调试和防篡改:通过在代码中添加检测和反调试的代码,防止代码被调试和篡改。
-
混淆策略:
- 混淆优化:根据具体的代码特点和需求,选择合适的混淆技术和配置选项,以最大程度地增加代码的复杂性和难以分析性。
- 混淆评估:对混淆后的代码进行测试和评估,确保混淆不影响代码的功能和性能,并且达到预期的安全性效果。
- 混淆后处理:对混淆后的代码进行压缩、优化和验证,以确保代码的质量和
上一篇: 【JavaScript逆向教程】深入理解ob混淆技术
下一篇: 加密与压缩VueJS代码的方法
推荐阅读
-
混淆代码打包:适用于 webpack2 和 webpack3 的低版本
-
Vue和Webpack的代码混淆加密方法被重新改写了
-
代码混淆:对比 vue3 vite 和 webpack 的表现
-
【摩尔线程+Colossal-AI强强联手】MusaBert登上CLUE榜单TOP10:技术细节揭秘 - 技术实力:摩尔线程凭借"软硬兼备"的技术底蕴,让MusaBert得以从底层优化到顶层。其内置多功能GPU配备AI加速和并行计算模块,提供了全面的AI与科学计算支持,为AI推理和低资源条件下的大模型训练等场景带来了高效、经济且环保的算力。 - 算法层面亮点:依托Colossal-AI AI大模型开发系统,MusaBert在训练过程中展现出了卓越的并行性能与易用性,特别在预处理阶段对DataLoader进行了优化,适应低资源环境高效处理海量数据。同时,通过精细的建模优化、领域内数据增强以及Adan优化器等手段,挖掘和展示了预训练语言模型出色的语义理解潜力。基于MusaBert,摩尔线程自主研发的MusaSim通过对比学习方法微调,结合百万对标注数据,MusaSim在多个任务如语义相似度、意图识别和情绪分析中均表现出色。 - 数据资源丰富:MusaBert除了自家高质量语义相似数据外,还融合了悟道开源200GB数据、CLUE社区80GB数据,以及浪潮公司提供的1TB高质量数据,保证模型即便在较小规模下仍具备良好性能。 当前,MusaBert已成功应用于摩尔线程的智能客服与数字人项目,并广泛服务于语义相似度、情绪识别、阅读理解与声韵识别等领域。为了降低大模型开发和应用难度,MusaBert及其相关高质量模型代码已在Colossal-AI仓库开源,可快速训练优质中文BERT模型。同时,通过摩尔线程与潞晨科技的深度合作,仅需一张多功能GPU单卡便能高效训练MusaBert或更大规模的GPT2模型,显著降低预训练成本,进一步推动双方在低资源大模型训练领域的共享目标。 MusaBert荣登CLUE榜单TOP10,象征着摩尔线程与潞晨科技联合研发团队在中文预训练研究领域的领先地位。展望未来,双方将携手探索更大规模的自然语言模型研究,充分运用上游数据资源,产出更为强大的模型并开源。持续强化在摩尔线程多功能GPU上的大模型训练能力,特别是在消费级显卡等低资源环境下,致力于降低使用大模型训练的门槛与成本,推动人工智能更加普惠。而潞晨科技作为重要合作伙伴,将继续发挥关键作用。
-
打包工具] - 对比 Vite 和 webpack 的原理和优缺点