admin管理员组文章数量:1360367
I have been trying to obfuscate the code for a while by using react-native-obfuscating-transformer. Everything seems okay but when I check the bundle.js. I can't see any obfuscated code.
PS: Currently, I try only for IOS.
Here are my config files.
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: {
pact: 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,
},
});
I have been trying to obfuscate the code for a while by using react-native-obfuscating-transformer. Everything seems okay but when I check the bundle.js. I can't see any obfuscated code.
PS: Currently, I try only for IOS.
Here are my config files.
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: {
pact: 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,
},
});
Share
Improve this question
edited Oct 13, 2020 at 16:52
Halil İbrahim Özdoğan
asked Oct 8, 2020 at 14:58
Halil İbrahim ÖzdoğanHalil İbrahim Özdoğan
5971 gold badge5 silver badges13 bronze badges
2 Answers
Reset to default 4 +50I finally figured out how to make it work after several test.
my react and react native version:
"react": "16.9.0",
"react-native": "0.61.5",
install other dependencies needed:
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./javascript-obfuscator/javascript-obfuscator
obfuscatorOptions:{
pact: 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: ['base64'],
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
},
};
NOTE:
set emitObfuscatedFiles to true in obfuscatorOptions to emit the obfuscated versions of files alongside their originals, for parison.
If you're building in release, you can also pare the generated index.android.bundle (located in \android\app\build\generated\assets\react\release) with and without using the react-native-obfuscating-transformer using online diff tool to see the difference
I was not able to get my js code obfuscated with this method, but I think I managed to do it with this package. I am interested in hearing your opinions. https://www.npmjs./package/obfuscator-io-metro-plugin
本文标签: javascriptHow to obfuscate code in reactnative for IOSStack Overflow
版权声明:本文标题:javascript - How to obfuscate code in react-native for IOS - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1743908527a2559953.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论