javascript-obfuscator / react-native-obfuscating-transformer

Obfuscation for React Native bundles
MIT License
195 stars 99 forks source link

Not working in react native .56 #5

Open balapkm opened 6 years ago

balapkm commented 6 years ago

Cannot find module 'metro/src/transformer'

garrethdev commented 6 years ago

@balapkm any update with this issue?

zenz commented 5 years ago

I'm using 0.57.2 there's no errors, but it's not obfuscated js bundles either. I can't figure out what's going wrong.

fungilation commented 5 years ago

Same. No error, no log, nothing. On RN 0.57.5

tobiarobi commented 5 years ago

I see that the files are being processed (trace: true) and I also printed the output of obfuscateCode and it does obfuscate the code. However:

  1. emitObfuscatedFiles is broken, because it emits before obfuscating (obfuscateCodePreservingSourceMap is called after)
  2. It seems like when the obfuscated code is handed over to the maybeTransformMetroResult, it is further processed (and perhaps at a later stage when packed to a single bundle), and most of the obfuscation becomes redundant? Searching for "_0x" in the final bundle yields no results. I haven't dug further to determine exactly what's going on. (p.s. I'm working with an upstream typescript transformer).
wangghon commented 5 years ago

@tobiarobi Hi tobiarobi, I also set the trace to true but got nothing obfuscated, and I use typescript as well, is it possible to share your transformer.js file? Thanks. Following is my transformer.js file:

const obfuscatingTransformer = require("react-native-obfuscating-transformer")
const typescriptTransformer = require('react-native-typescript-transformer')

module.exports = obfuscatingTransformer({
    upstreamTransformer: typescriptTransformer,
    obfuscatorOptions: {
        compact: true,
        controlFlowFlattening: false,
        controlFlowFlatteningThreshold: 0.75,
        deadCodeInjection: true,
        deadCodeInjectionThreshold: 0.4,
        debugProtection: false,
        debugProtectionInterval: false,
        disableConsoleOutput: false,
        domainLock: [],
        identifierNamesGenerator: 'hexadecimal',
        identifiersPrefix: '',
        inputFileName: '',
        log: true,
        renameGlobals: true,
        reservedNames: [],
        reservedStrings: ['react-native'],
        rotateStringArray: true,
        seed: 0,
        selfDefending: true,
        sourceMap: false,
        sourceMapBaseUrl: '',
        sourceMapFileName: '',
        sourceMapMode: 'separate',
        stringArray: true,
        stringArrayEncoding: false,
        stringArrayThreshold: 0.75,
        target: 'browser',
        transformObjectKeys: false,
        unicodeEscapeSequence: false
    },
    trace: true,
    emitObfuscatedFiles: true,
    enableInDevelopment: true
})
tobiarobi commented 5 years ago

@wangghon That's because there is a bug in the default filter function. The default function searches for an absolute path of the function (with the help of app-root-path package), while the filename sent to the filter function are with relative path. To fix this I used my own filter function.

const filter = filename => { 
  return filename.startsWith("src");
};

module.exports = obfuscatingTransformer({
  filter: filter,
  upstreamTransformer: typescriptTransformer,
  trace: true,
})
wangghon commented 5 years ago

@tobiarobi Thanks for the response. Your suggestion works.

when I enable trace flag, see the output in console that all the files are obfuscating, however I found that the code is not obfuscated at all, did you experience the similar issue?

tobiarobi commented 5 years ago

@wangghon As I've explained in the first comment. It does work when you print the obfuscated code returned by the transformer (just add console.log for the obfuscated code and you'll see that it works). However somewhere afterwards in the flow (when its bundled together) perhaps its minified afterwards and some of the work that the obfuscator does is lost. I haven't had a chance to investigate this thoroughly, nevertheless I can say that the output is somewhat different than running without the transformer. (for example: for my project the output with the obfuscator was larger than without it)

wangghon commented 5 years ago

@tobiarobi Thanks. We tried to log the obfuscated code out, It seems no obfuscation happens. :(

tobiarobi commented 5 years ago

console.log the output of obfuscateCodePreservingSourceMap see https://github.com/javascript-obfuscator/react-native-obfuscating-transformer/blob/9a0271046c276b0270b57cc2a855103b3ad24def/src/obfuscatingTransformer.ts#L101

frncs-eu commented 5 years ago

I'm experiencing the same problem.

react-native: 0.57.8

johcam12 commented 5 years ago

Same issue here. No obfuscation takes place at all. I changed filter options, and traced the output, which does not seem to be correct.

kida7 commented 5 years ago

I guess the author disable string encryption in src/obfuscatingTransformer.ts. I tried edit it:

https://github.com/kida7/react-native-obfuscating-transformer/commit/610215873c24a91d6dfa6c400820af9b0d14353e#diff-579dbaeadaa3587b0767bdec80686f2f

And build bundle with the following obfuscator options: stringArray: true, stringArrayEncoding: 'base64', stringArrayThreshold: 1,

But we will get errors because obfuscator encrypt all strings in "require" function. So I think, the solution for this is split all the code you want to encyript to specific modules an import/require them. Then you change the filter function to encrypt only those files.