一段时间以来,我一直在尝试使用react-native-obfuscating-transformer来混淆代码。一切似乎都还好,但是当我检查bundle.js时。我看不到任何混淆的代码。
PS:目前,我仅尝试使用IOS。
这是我的配置文件。
metro.config.js
module.exports = {
transformer: {
babelTransformerPath: require.resolve('./transformer'),
getTransformOptions: async () => ({
transform: {
experimentalImportSupport: false,
inlineRequires: false,
},
}),
},
};
transformer.js
const obfuscatingTransformer = require('react-native-obfuscating-transformer');
module.exports = obfuscatingTransformer({
upstreamTransformer: require('metro-react-native-babel-transformer'),
enableInDevelopment: true,
obfuscatorOptions: {
compact: true,
controlFlowFlattening: true,
controlFlowFlatteningThreshold: 0.75,
deadCodeInjection: true,
deadCodeInjectionThreshold: 0.4,
debugProtection: false,
debugProtectionInterval: false,
disableConsoleOutput: true,
identifierNamesGenerator: 'hexadecimal',
log: false,
numbersToExpressions: true,
renameGlobals: false,
rotateStringArray: true,
selfDefending: true,
shuffleStringArray: true,
simplify: true,
splitStrings: true,
splitStringsChunkLength: 10,
stringArray: true,
stringArrayEncoding: ['base64'],
stringArrayWrappersCount: 2,
stringArrayWrappersChainedCalls: true,
stringArrayWrappersType: 'variable',
stringArrayThreshold: 0.75,
transformObjectKeys: true,
unicodeEscapeSequence: false,
},
});
答案 0 :(得分:2)
经过几次测试,我终于弄清楚了如何使它工作。
我的反应和反应的本机版本:
"react": "16.9.0",
"react-native": "0.61.5",
安装所需的其他依赖项:
npm install babylon --save
npm install --save babel-traverse
transformer.js
const obfuscatingTransformer = require("react-native-obfuscating-transformer")
const filter = filename => {
return filename.startsWith("src");
};
module.exports = obfuscatingTransformer({
// this configuration is based on https://github.com/javascript-obfuscator/javascript-obfuscator
obfuscatorOptions:{
compact: true,
controlFlowFlattening: false,
deadCodeInjection: false,
debugProtection: false,
debugProtectionInterval: false,
disableConsoleOutput: true,
identifierNamesGenerator: 'hexadecimal',
log: false,
renameGlobals: false,
rotateStringArray: true,
selfDefending: true,
shuffleStringArray: true,
splitStrings: false,
stringArray: true,
stringArrayEncoding: false,
stringArrayThreshold: 0.75,
unicodeEscapeSequence: false
},
upstreamTransformer: require('metro-react-native-babel-transformer'),
emitObfuscatedFiles: false,
enableInDevelopment: true,
filter: filter,
trace: true
})
metro.config.js
module.exports = {
transformer: {
getTransformOptions: async () => ({
transform: {
experimentalImportSupport: false,
inlineRequires: false,
},
}),
babelTransformerPath: require.resolve("./transformer") // add here the transformer.js
},
};
注意:
在obfuscatorOptions中将embedObfuscatedFiles设置为true,以将经过混淆的文件版本与原始文件一起发出,以进行比较。
如果要在发行版中进行构建,则可以将生成的 index.android.bundle (位于\ android \ app \ build \ generated \ assets \ react \ release中)进行比较,也可以将其进行比较。使用在线差异工具的react-native-obfuscating-transformer查看差异
答案 1 :(得分:0)
我无法用这种方法混淆我的 js 代码,但我想我设法用这个包做到了。我很想听听你的意见。 https://www.npmjs.com/package/obfuscator-io-metro-plugin