javascript-obfuscator / react-native-obfuscating-transformer

Obfuscation for React Native bundles

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

toddrimes opened this issue · comments

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

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
  }
})

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. :(