feature request: react-native target
See original GitHub issueIn react-native require
can’t have evaluation for argument, only static strings. I can use // javascript-obfuscator:disable
for any require
, but it’s a lot of manual work for large project.
Expected Behavior
I’d like to keep static strings in require or imports without adding “// javascript-obfuscator:disable”
Current Behavior
it obfuscate the require argument moving it to global key-value object.
Steps to Reproduce (for bugs)
- npm install -g create-react-native-app
- create-react-native-app testapp
- create file without jsx
- add some imports and some require
- try to obfuscate the file and build app using
react-native run-android
orreact-native run ios
Your Environment
"dependencies": {
"react": "16.0.0",
"react-i18next": "^4.8.0",
"react-native": "0.50.4"
},
"devDependencies": {
"javascript-obfuscator": "^0.17.0",
"babel-core": "^6.26.0",
"babel-eslint": "^7.2.3",
"babel-jest": "21.2.0",
"babel-loader": "^7.0.0",
"babel-plugin-transform-decorators-legacy": "^1.3.4",
"babel-plugin-transform-react-remove-prop-types": "^0.4.10",
"babel-plugin-transform-remove-console": "^6.8.5",
"babel-preset-react-native": "4.0.0",
"flow-bin": "^0.56.0",
"fs-extra": "^3.0.1",
"zip-folder": "^1.0.0"
},
I use next script for obfuscation
const babel = require('babel-core');
const fs = require ("fs");
const JavaScriptObfuscator = require('javascript-obfuscator');
const {promisify} = require('util');
const babelOpts = {
ast: false,
compact: false,
comments: true
};
onst obsuscateOptions = {
compact: true,
controlFlowFlattening: false,
controlFlowFlatteningThreshold: 1,
deadCodeInjection: true,
deadCodeInjectionThreshold: 1,
debugProtection: false,
debugProtectionInterval: false,
disableConsoleOutput: true,
// identifierNamesGenerator: 'mangled',
log: false,
renameGlobals: false,
rotateStringArray: false,
selfDefending: false,
stringArray: false,
stringArrayEncoding: false,
target: 'browser-no-eval',
// stringArrayThreshold: 1,
transformObjectKeys: false,
unicodeEscapeSequence: false
}
const transformFileAsync = promisify(babel.transformFile);
const writeFileAsync = promisify(fs.writeFileSync);
const transformFile = (filePath, babelOpts, obsuscateOptions) => {
return transformFileAsync(filePath, babelOpts)
.then(r => JavaScriptObfuscator.obfuscate(
r.code,
obsuscateOptions
))
.then(r => r.getObfuscatedCode())
}
const encodeFiles = (fileList) => {
return Promise.all(fileList.map(filePath => {
return transformFile(filePath, babelOpts, obsuscateOptions)
.then(code => ({
code ,
filePath
}))
.then(({code, filePath}) => writeFileAsync(filePath, code))
}))
}
const paths = ['src/example1']
encodeFiles(paths)
.catch(e => {
console.error(e)
});
Minimal working example that will help to reproduce issue
obfuscate this file and import it in react-native app
import React, { Component} from "react"
const {View} = require("react-native")
export default () => {console.log("default module")}
Issue Analytics
- State:
- Created 5 years ago
- Comments:12 (8 by maintainers)
Top Results From Across the Web
In-App Feature Requests - Instabug
This page contains an overview of the content available in the In-App Feature Request sections of the Instabug Docs for React Native apps....
Read more >The State of React Native for Web, Windows, and macOS in ...
React Native is a cross-platform development framework that supports ... As well as some bug fixes, feature requests, and updates open ...
Read more >Integration with Existing Apps - React Native
With a few steps, you can add new React Native based features, screens, ... steps are different depending on what platform you're targeting....
Read more >Sharing - Expo Documentation
You can read more in the related feature request. ... If you're installing this in a bare React Native app, you should also...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
No. This is different subsystems.
require
is theIdentifierNode
and you can ignore renaming of this identifier. String inside require expression -LiteralNode
and obfuscator hasLiteralTransformer
to handle literals and extract them to the array of strings. So, best way not to connect this fix with react-native, but make a common way to exclude literals from transformation, andreservedStrings
option - best way. And anyone can use this option in a various ways.This issue was fixed by adding
reservedStrings
option in0.18.0
. (But this release was come with some problems that will fixed soon). For any thirdparty libraries likereact-native-obfuscating-transformer
- create issue in repository of this library.