javascript-obfuscator / react-native-obfuscating-transformer

Obfuscation for React Native bundles
MIT License
196 stars 100 forks source link

I think I set it up, but nothing seems to 'happen'. #22

Closed toddrimes closed 4 years ago

toddrimes commented 4 years ago

I installed with 'npm install react-native-obfuscating-transformer --save-dev'. I have this in metro.config.js:

module.exports = {
  transformer: {
    babelTransformerPath: require.resolve("./transformer")
  },
}

...and this in transformer.js:

const obfuscatingTransformer = require("react-native-obfuscating-transformer")
const babelTransformer = require("metro-react-native-babel-transformer")

module.exports = obfuscatingTransformer({
  upstreamTransformer: babelTransformer,
  compact: true,
  controlFlowFlattening: false,
  controlFlowFlatteningThreshold: 1,
  deadCodeInjection: true,
  deadCodeInjectionThreshold: 1,
  debugProtection: false,
  debugProtectionInterval: false,
  disableConsoleOutput: true,
  emitObfuscatedFiles: true,
  enableInDevelopment: true,
  // identifierNamesGenerator: 'mangled',
  log: false,
  renameGlobals: false,
  rotateStringArray: false,
  selfDefending: false,
  stringArray: false,
  stringArrayEncoding: false,
  target: 'browser-no-eval',
  // stringArrayThreshold: 1,
  trace: true,
  transformObjectKeys: false,
  unicodeEscapeSequence: false
})

But when I do 'react-native run-ios --configuration [Debug | Release]', nothing happens and no new files like *-obfuscated.js' appear. I get no errors, either.

What have I missed?

Thank you, ~Todd

gokhandoslu commented 4 years ago

I tried to log the obfuscated code out but it seems no obfuscation happens :(

If you want to create output files with suffix '.obfuscated.js', set emitObfuscatedFiles: true.

Example:

module.exports = obfuscatingTransformer({
  upstreamTransformer: require("metro-react-native-babel-transformer"),
  trace: true,
  filter: filename => filename.startsWith("src"),
  emitObfuscatedFiles: true,
  obfuscatorOptions: {
    compact: true,
    controlFlowFlattening: false,
    controlFlowFlatteningThreshold: 1,
    deadCodeInjection: true,
    deadCodeInjectionThreshold: 1,
    debugProtection: false,
    debugProtectionInterval: false,
    disableConsoleOutput: true,
    emitObfuscatedFiles: true,
    enableInDevelopment: true,
    // identifierNamesGenerator: 'mangled',
    log: false,
    renameGlobals: false,
    rotateStringArray: false,
    selfDefending: false,
    stringArray: false,
    stringArrayEncoding: false,
    target: 'browser-no-eval',
    // stringArrayThreshold: 1,
    trace: true,
    transformObjectKeys: false,
    unicodeEscapeSequence: false
  }
})
toddrimes commented 4 years ago

Thank you. I have it set to true in my original post (as you can see above), but I did not have a separate 'obfuscatorOptions' like you do. I'll give that a try if I decide to try obfuscation again. After reading several posts about it, it seemed a rather futile way to discourage code-theft anyway. :(