Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't make it work #2

Open
ramsestom opened this issue Mar 6, 2018 · 22 comments
Open

Can't make it work #2

ramsestom opened this issue Mar 6, 2018 · 22 comments

Comments

@ramsestom
Copy link

ramsestom commented Mar 6, 2018

Hi
I am trying to use this module. I created the rn-cli.config.js and transformer.js file in my project root folder and kept the default obfuscatingTransformer options (So module.exports = obfuscatingTransformer({})).
But this doesn't seem to work. The index.android.bundle file in the generated app-release.apk still remains unobfuscated (I performed a gradlew assembleRelease like usual to create the bundle before
react-native run-android --variant=release)
What am I doing wrong?

@ds300
Copy link
Contributor

ds300 commented Mar 6, 2018

Hi @ramsestom !

By default, this transformer only obfuscates files in your src directory, but leaves node_modules untouched. If you inspect the bundle, it may look unobfuscated for the most part, since such a large portion of it will come from node_modules. If your project-specific files are indeed also unobfuscated, I'm happy to offer more help.

@ramsestom
Copy link
Author

I checked and my project-specific code is also unobfuscated in the bundle.
Actually I am not sure that the rn-cli.config.js file is correctly checked by the packager because there seems to be issues with it: facebook/react-native#12133 . Is there a simple way to check that the obfuscator is actually called?
I am using RN version 0.53.3 (will try to update to 0.54). What version do you use?

@tombailey
Copy link

tombailey commented Apr 12, 2018

I have tested this with "react-native": "^0.55.2" and it seems to work okay.

Note that I didn't use gradlew assembleRelease but instead
react-native bundle --platform android --dev false --entry-file index.android.js --bundle-output android/app/src/main/assets/index.android.bundle --assets-dest android/app/src/main/res

@zenz
Copy link

zenz commented Jun 19, 2018

not work for me either,
React-Native 0.55.4, no script obfuscated.

@Nantris
Copy link

Nantris commented Mar 6, 2019

No obfuscation as far as I can tell here.

@wangghon
Copy link

wangghon commented Mar 7, 2019

Same as us, no obfuscation on our specific code.

@imelos
Copy link

imelos commented Mar 22, 2019

same here

@marcorm
Copy link

marcorm commented Mar 25, 2019

same here :(

"react": "16.6.0-alpha.8af6728",
"react-native": "0.57.4",

did anyone of you found at least a workaround?

@horsewin
Copy link

same here...

These are my setting below.

    "react": "^16.5.0",
    "react-native": "0.57.8",
// transformer.js
const obfuscatingTransformer = require("react-native-obfuscating-transformer");
const typescriptTransformer = require("react-native-typescript-transformer");

module.exports = obfuscatingTransformer({
  upstreamTransformer: typescriptTransformer,
});
// rn-cli.config.js
module.exports = {
  getTransformModulePath() {
    return require.resolve('react-native-typescript-transformer');
  },
  transformer: {
    babelTransformerPath: require.resolve("./transformer")
  },
};

i execute this command, but no diff are shown before no obfuscation.

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

@varunjithtk22
Copy link

I have tested this with "react-native": "^0.55.2" and it seems to work okay.

Note that I didn't use gradlew assembleRelease but instead
react-native bundle --platform android --dev false --entry-file index.android.js --bundle-output android/app/src/main/assets/index.android.bundle --assets-dest android/app/src/main/res

Can you please provide the steps you followed.

@lorenc-tomasz
Copy link

The same on 0.59.10. Tried the above method as well.

@zenz
Copy link

zenz commented Jul 29, 2019

The same on 0.59.10. Tried the above method as well.

With react-native hermes engine, I think you don't need obfuscator any more. it's compiled to bytecode.

@lanjinglingxx
Copy link

hermes engine just work in android,but what ios can do

@ghost
Copy link

ghost commented Jan 14, 2020

Hey guys I would suggest to use https://github.com/javascript-obfuscator/javascript-obfuscator directly on your bundle. It will make obfuscation more efficient in sense that it will obfuscate code so much more... But probably at cost - your app will be more slow.

Also note that for ios you will be able to get it work, but for android with hermes enabled I am not sure how to done it at the moment. Also note that with hermes it is true that result bundle is some kind of bytecode but big portion of strings are not "obfuscated" by hermes in our case...

@AustinZuniga
Copy link

I 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.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
  },
};

NOTE:

set emitObfuscatedFiles to true in obfuscatorOptions to emit the obfuscated versions of files alongside their originals, for comparison.

If you're building in release, you can also compare 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

@rohitmodi12
Copy link

rohitmodi12 commented May 19, 2020

I 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.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
  },
};

NOTE:

set emitObfuscatedFiles to true in obfuscatorOptions to emit the obfuscated versions of files alongside their originals, for comparison.

If you're building in release, you can also compare 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 am getting this error:
error ObfuscatorFolder/ConstantData.js: The number of constructor arguments in the derived class t must be >= than the number of constructor arguments of its base class. Run CLI with --verbose flag for more details.

getTargets (/Users/apple/Desktop/DemoObfuscateDemo/node_modules/react-native-obfuscating-transformer/node_modules/inversify/lib/planning/reflection_utils.js:32:15)
at Object.getDependencies (/Users/apple/Desktop/DemoObfuscateDemo/node_modules/react-native-obfuscating-transformer/node_modules/inversify/lib/planning/reflection_utils.js:10:19)
at /Users/apple/Desktop/DemoObfuscateDemo/node_modules/react-native-obfuscating-transformer/node_modules/inversify/lib/planning/planner.js:106:51
at Array.forEach ()

@fesoares
Copy link

I 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.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
  },
};

NOTE:
set emitObfuscatedFiles to true in obfuscatorOptions to emit the obfuscated versions of files alongside their originals, for comparison.
If you're building in release, you can also compare 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 am getting this error:
error ObfuscatorFolder/ConstantData.js: The number of constructor arguments in the derived class t must be >= than the number of constructor arguments of its base class. Run CLI with --verbose flag for more details.

getTargets (/Users/apple/Desktop/DemoObfuscateDemo/node_modules/react-native-obfuscating-transformer/node_modules/inversify/lib/planning/reflection_utils.js:32:15)
at Object.getDependencies (/Users/apple/Desktop/DemoObfuscateDemo/node_modules/react-native-obfuscating-transformer/node_modules/inversify/lib/planning/reflection_utils.js:10:19)
at /Users/apple/Desktop/DemoObfuscateDemo/node_modules/react-native-obfuscating-transformer/node_modules/inversify/lib/planning/planner.js:106:51
at Array.forEach ()

any solution for this ?

@quantjamespecutus
Copy link

I 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.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
  },
};

NOTE:
set emitObfuscatedFiles to true in obfuscatorOptions to emit the obfuscated versions of files alongside their originals, for comparison.
If you're building in release, you can also compare 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 am getting this error:
error ObfuscatorFolder/ConstantData.js: The number of constructor arguments in the derived class t must be >= than the number of constructor arguments of its base class. Run CLI with --verbose flag for more details.
getTargets (/Users/apple/Desktop/DemoObfuscateDemo/node_modules/react-native-obfuscating-transformer/node_modules/inversify/lib/planning/reflection_utils.js:32:15)
at Object.getDependencies (/Users/apple/Desktop/DemoObfuscateDemo/node_modules/react-native-obfuscating-transformer/node_modules/inversify/lib/planning/reflection_utils.js:10:19)
at /Users/apple/Desktop/DemoObfuscateDemo/node_modules/react-native-obfuscating-transformer/node_modules/inversify/lib/planning/planner.js:106:51
at Array.forEach ()

any solution for this ?

same issue here, it seems to work on 99% of my source files, but throws on (at least) one of my components.

@MouhcineFD
Copy link

@fesoares you need to use javascript-obfuscator version 1.1.0 or upper
if you use yarn just add
"resolutions": { "javascript-obfuscator": "^1.1.0" },
to your package.json
or you can make a patch for this outdated package

@2linziyi2
Copy link

not work for me either,
React-Native 0.59.5, no script obfuscated.
follow the tutorial exactly

@adamalexander
Copy link

this plugin just dont work.

@whoami-shubham
Copy link

try this https://www.npmjs.com/package/obfuscator-io-metro-plugin

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests