Come offuscare il codice in React-Native per IOS
Ho cercato di offuscare il codice per un po 'usando il trasformatore di offuscamento del nativo di reazione . Sembra tutto a posto, ma quando controllo bundle.js. Non riesco a vedere alcun codice offuscato.
PS: attualmente provo solo per IOS.
Ecco i miei file di configurazione.
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,
},
});
Risposte
Alla fine ho capito come farlo funzionare dopo diversi test.
la mia versione nativa di reazione e reazione:
"react": "16.9.0",
"react-native": "0.61.5",
installa altre dipendenze necessarie:
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
},
};
NOTA:
impostare emitObfuscatedFiles su true in obfuscatorOptions per emettere le versioni offuscate dei file insieme agli originali, per il confronto.
Se stai creando in versione, puoi anche confrontare il index.android.bundle generato (che si trova in \ android \ app \ build \ generated \ assets \ react \ release) con e senza utilizzare il trasformatore di offuscamento-nativo-reattivo usando strumento diff online per vedere la differenza