question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

feature request: react-native target

See original GitHub issue

In 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)

  1. npm install -g create-react-native-app
  2. create-react-native-app testapp
  3. create file without jsx
  4. add some imports and some require
  5. try to obfuscate the file and build app using react-native run-android or react-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:closed
  • Created 5 years ago
  • Comments:12 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
sanex3339commented, Jul 4, 2018

No. This is different subsystems. require is the IdentifierNode and you can ignore renaming of this identifier. String inside require expression - LiteralNode and obfuscator has LiteralTransformer 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, and reservedStrings option - best way. And anyone can use this option in a various ways.

0reactions
sanex3339commented, Aug 20, 2018

This issue was fixed by adding reservedStrings option in 0.18.0. (But this release was come with some problems that will fixed soon). For any thirdparty libraries like react-native-obfuscating-transformer - create issue in repository of this library.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Feature Requests | React Native - Canny
A framework for building native apps with React.
Read more >
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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found