AustinZuniga / react-native-obfuscator

obfuscate react native app js code
MIT License
15 stars 4 forks source link

Getting an error after adding transformer #6

Open shashank1501 opened 2 years ago

shashank1501 commented 2 years ago

I have created an empty project and tried to use this package but got following error after running the following command

Command

react-native bundle --platform android --dev false --entry-file index.js --bundle-output android/app/src/main/assets/index.android.bundle --assets-dest android/app/src/main/res

Error

transform[stdout]: Obfuscating src/App.js
error src/App.js: function (prevType) {
  this.state.exprAllowed = false;

  if (prevType === types._let || prevType === types._c...<omitted>...
} could not be cloned.
Error: function (prevType) {
  this.state.exprAllowed = false;

  if (prevType === types._let || prevType === types._c...<omitted>...
} could not be cloned.
    at Object.serialize (v8.js:331:7)
    at _default (/home/ceinfo/Desktop/jsoff/node_modules/@babel/core/lib/transformation/util/clone-deep.js:22:34)
    at normalizeFile (/home/ceinfo/Desktop/jsoff/node_modules/@babel/core/lib/transformation/normalize-file.js:84:36)
    at normalizeFile.next (<anonymous>)
    at run (/home/ceinfo/Desktop/jsoff/node_modules/@babel/core/lib/transformation/index.js:29:50)
    at run.next (<anonymous>)
    at /home/ceinfo/Desktop/jsoff/node_modules/@babel/core/lib/transform-ast.js:26:41
    at Generator.next (<anonymous>)
    at evaluateSync (/home/ceinfo/Desktop/jsoff/node_modules/gensync/index.js:251:28)

//package.json

{
  "name": "jsoff",
  "version": "0.0.1",
  "private": true,
  "scripts": {
    "android": "react-native run-android",
    "ios": "react-native run-ios",
    "start": "react-native start",
    "test": "jest",
    "lint": "eslint ."
  },
  "dependencies": {
    "babel-traverse": "^6.26.0",
    "babylon": "^6.18.0",
    "react": "17.0.2",
    "react-native": "0.66.3",
    "react-native-obfuscator": "git+https://github.com/AustinZuniga/react-native-obfuscator.git"
  },
  "devDependencies": {
    "@babel/core": "7.16.0",
    "@babel/runtime": "7.16.3",
    "@react-native-community/eslint-config": "2.0.0",
    "babel-jest": "26.6.3",
    "eslint": "7.14.0",
    "jest": "26.6.3",
    "metro-react-native-babel-preset": "0.66.2",
    "react-test-renderer": "17.0.2"
  },
  "jest": {
    "preset": "react-native"
  }
}

//transformer.js

const obfuscatingTransformer = require('react-native-obfuscator');
const filter = filename => {
  return filename.startsWith('src');
};

module.exports = obfuscatingTransformer({
  obfuscatorOptions: {
    compact: true, // default true
    controlFlowFlattening: false, // default false
    controlFlowFlatteningThreshold: 0.75, // default 0.75
    deadCodeInjection: false, // default false
    deadCodeInjectionThreshold: 1, // default 0.4
    debugProtection: false, // default false
    debugProtectionInterval: false, // default false
    disableConsoleOutput: true,
    identifierNamesGenerator: 'hexadecimal', // default hexadecimal
    log: false, // default false
    renameGlobals: true, // default false
    rotateStringArray: true, // default true
    seed: 0, // default 0
    selfDefending: false, // default true: not working if true
    shuffleStringArray: true, // default true
    sourceMapMode: 'separate', // default seperate
    splitStrings: true, // default false
    splitStringsChunckLength: 10, // default 10
    stringArray: true, // default true
    stringArrayEncoding: 'rc4', // default false
    stringArrayThreshold: 0.75, // default 0.8
    target: 'browser', // default browser
    transformObjectKeys: true, // default false
    unicodeEscapeSequence: true,
  },
  upstreamTransformer: require('metro-react-native-babel-transformer'),
  emitObfuscatedFiles: false,
  enableInDevelopment: true,
  filter: filter,
  trace: true,
});

metro.config.js

/**
 * Metro configuration for React Native
 * https://github.com/facebook/react-native
 *
 * @format
 */

module.exports = {
  transformer: {
    getTransformOptions: async () => ({
      transform: {
        experimentalImportSupport: false,
        inlineRequires: true,
      },
    }),
    babelTransformerPath: require.resolve('./transformer'),
  },
};
iurybrasileiro commented 2 years ago

Same problem