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

Not working in react native .56 #5

Open
balapkm opened this issue Jul 17, 2018 · 13 comments
Open

Not working in react native .56 #5

balapkm opened this issue Jul 17, 2018 · 13 comments

Comments

@balapkm
Copy link

balapkm commented Jul 17, 2018

Cannot find module 'metro/src/transformer'

@garrethdev
Copy link

@balapkm any update with this issue?

@zenz
Copy link

zenz commented Oct 15, 2018

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
Copy link

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

@tobiarobi
Copy link

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
Copy link

wangghon commented Mar 6, 2019

@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
Copy link

@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
Copy link

wangghon commented Mar 7, 2019

@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
Copy link

tobiarobi commented Mar 7, 2019

@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
Copy link

wangghon commented Mar 8, 2019

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

@tobiarobi
Copy link

console.log the output of obfuscateCodePreservingSourceMap see

obfuscateCodePreservingSourceMap(

@frncs-eu
Copy link

I'm experiencing the same problem.

react-native: 0.57.8

@johcam12
Copy link

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
Copy link

kida7 commented Mar 29, 2019

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

kida7@6102158#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.

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

9 participants