javascript-obfuscator / javascript-obfuscator

A powerful obfuscator for JavaScript and Node.js
https://obfuscator.io
BSD 2-Clause "Simplified" License
13.51k stars 1.48k forks source link

Error while obfuscating, Error : Error: ERROR at line 1: Unexpected token #1208

Open AlbertoMeQ opened 11 months ago

AlbertoMeQ commented 11 months ago

Here is my setup:

I've been using the obfuscator for a while and I've just recently updated to RN 0.72.5 and I started getting this error on build. Here is the configuration and error:

info Writing bundle output to:, ./android/app/src/main/assets/index.android.bundle
info Done writing bundle output
info Copying 131 asset files
info Done copying assets
info: Obfuscating Code
{
  config: {
    deadCodeInjection: false,
    disableConsoleOutput: true,
    identifierNamesGenerator: 'mangled',
    log: false,
    selfDefending: true,
    numbersToExpressions: true,
    renameGlobals: false,
    renameProperties: false,
    renamePropertiesMode: 'safe',
    simplify: true,
    splitStrings: true,
    stringArray: true,
    stringArrayCallsTransform: true,
    stringArrayCallsTransformThreshold: 0.75,
    stringArrayEncoding: [],
    stringArrayIndexShift: true,
    stringArrayRotate: true,
    stringArrayShuffle: true,
    stringArrayWrappersCount: 1,
    stringArrayWrappersChainedCalls: true,
    stringArrayWrappersParametersMaxCount: 2,
    stringArrayWrappersType: 'variable',
    stringArrayThreshold: 0.75,
    unicodeEscapeSequence: false
  },
  filesSrc: '**/*.js?(.map)',
  filesDest: '.jso/dist',
  cwd: '.jso/src'
}
Error while obfuscating, Error :  Error: ERROR at line 1: Unexpected token (1:853)
> ...is,j);var o=0,y.xliterate`<roo...
    at Function.processParsingError (/Users/me/my_project/node_modules/javascript-obfuscator/dist/webpack:/javascript-obfuscator/src/ASTParserFacade.ts:77:15)
    at Function.parse (/Users/me/my_project/node_modules/javascript-obfuscator/dist/webpack:/javascript-obfuscator/src/ASTParserFacade.ts:43:49)
    at o.parseCode (/Users/me/my_project/node_modules/javascript-obfuscator/dist/webpack:/javascript-obfuscator/src/JavaScriptObfuscator.ts:87:50)
    at obfuscate (/Users/me/my_project/node_modules/javascript-obfuscator/dist/webpack:/javascript-obfuscator/src/JavaScriptObfuscator.ts:78:30)
    at Function.obfuscate (/Users/me/my_project/node_modules/javascript-obfuscator/dist/webpack:/javascript-obfuscator/src/JavaScriptObfuscatorFacade.ts:16:56)
    at /Users/me/my_project/node_modules/obfuscator-io-metro-plugin/lib/javascriptObfuscatorAPI.js:36:54
    at Array.map (<anonymous>)
    at module.exports (/Users/me/my_project/node_modules/obfuscator-io-metro-plugin/lib/javascriptObfuscatorAPI.js:32:18)
    at obfuscateBundle (/Users/me/my_project/node_modules/obfuscator-io-metro-plugin/lib/index.js:62:3)
    at process.<anonymous> (/Users/me/my_project/node_modules/obfuscator-io-metro-plugin/lib/index.js:109:7)

This is the line referred by the error:

__d(function(g,r,i,a,m,_e,d){"JSO-BEG";
var e=r(d[0]);
Object.defineProperty(_e,"__esModule",{value:!0}),_e.default=void 0;
var t=e(r(d[1])),n=e(r(d[2])),o=e(r(d[3])),l=e(r(d[4])),s=e(r(d[5])),u=e(r(d[6])),c=r(d[7]),f=e(r(d[8])),p=r(d[9]),h=e(r(d[10])),y=r(d[11]),x=e(r(d[12])),j=e(r(d[13])),T=e(r(d[14])),v=e(r(d[15])),b=e(r(d[16])),C=r(d[17]);
function S(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;
if(Reflect.construct.sham)return!1;
if("function"==typeof Proxy)return!0;
try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch(e){return!1}}var k=_e.default=(function(e){(0,o.default)(j,e);
    var u,p,h=(u=j,p=S(),function(){var e,t=(0,s.default)(u);
    if(p){var n=(0,s.default)(this).constructor;
    e=Reflect.construct(t,arguments,n)}else e=t.apply(this,arguments);
return(0,l.default)(this,e)});
function j(e){var n;
    (0,t.default)(this,j);
    var o=0,y.xliterate`<root><p>Return to project's</p><link>updated ${(n=h.call(this,e)).props.agreementType}.</link></root>`;
return n.returnPromptJson=x.default.xmlToJson(o).root,n}return(0,n.default)(j,[{key:"render",value:function(){return(0,C.jsxs)(f.default,{visible:this.props.agreementRejected,style:R.modal,children:[(0,C.jsx)(c.View,{style:R.closeModalContainer,children:(0,C.jsx)(b.default,{styles:R.closeModal,onPress:this.props.onClose})}),(0,C.jsx)(c.View,{style:R.container,children:(0,C.jsxs)(c.View,{children:[(0,C.jsx)(c.Text,{style:R.title,children:0,y.xliterate`Do you have questions about our ${this.props.agreementType}?`}),(0,C.jsx)(c.Text,{style:R.message,children:0,y.xliterate`Before you continue, you'll need to agree to the updated ${this.props.agreementType}. The project Customer Care team can answer questions you may have.`}),(0,C.jsx)(c.Text,{style:R.header,children:(0,y.xlate)('Contact the Customer Care team:')}),(0,C.jsx)(c.TouchableOpacity,{onPress:function(){c.Linking.openURL('mailto:support@project.com')},children:(0,C.jsx)(c.Text,{style:R.link,children:"support@project.com"})}),(0,C.jsx)(c.Text,{style:R.header,children:this.returnPromptJson.p._text}),(0,C.jsx)(c.TouchableOpacity,{onPress:this.props.onClose,children:(0,C.jsx)(c.Text,{style:R.link,children:this.returnPromptJson.link._text})})]})})]})}}]),j})(u.default.Component);
k.propTypes={agreementType:j.default.string.isRequired,agreementRejected:j.default.bool.isRequired,onClose:j.default.func.isRequired},k.defaultProps={};
var R=c.StyleSheet.create({modal:{backgroundColor:h.default.white,alignItems:'center'},message:Object.assign({fontSize:16,justifyContent:'center',alignItems:'center',color:h.default.neutralDarkGray,paddingTop:20},T.default.fontFamilyWeightStyle(v.default.openSans)),container:{height:100*p.vh,width:100*p.vw,padding:20,backgroundColor:h.default.white,justifyContent:'center'},title:Object.assign({fontSize:24,color:h.default.mainTitles},T.default.fontFamilyWeightStyle(v.default.openSans,700)),header:Object.assign({fontSize:16,color:h.default.neutralDarkGray,paddingTop:20},T.default.fontFamilyWeightStyle(v.default.openSans,700)),link:Object.assign({color:h.default.grenadier,fontSize:16,textDecorationLine:'underline'},T.default.fontFamilyWeightStyle(v.default.openSans)),closeModalContainer:{marginTop:100,width:'100%',height:40,alignItems:'flex-end'}})"JSO-END";
},2647,[1,14,15,27,29,32,93,2,630,655,657,658,482,244,859,858,872,201]);

Which is this function:

    constructor(props) {
        super(props);

        const returnPromptXml = xliterate`<root><p>Return to project's</p><link>updated ${this.props.agreementType}.</link></root>`;
        this.returnPromptJson = FormatUtil.xmlToJson(returnPromptXml).root;
    }

When I check the code, I see that this line:

var o=0,y.xliterate

Return to project's

updated ${(n=h.call(this,e)).props.agreementType}.;

Has an invalid , which is probably why this is failing. How can I prevent that from happening? I don't mind loosening the configuration if that means the code won't break randomly.

j4k0xb commented 11 months ago

most likely not a javascript-obfuscator issue since it errors while parsing

bundlers/build-tools commonly convert import { foo } from 'lib'; foo(); to const lib = require(1); (0, lib.foo)(); RN or any of its dependencies tries to do the same for tagged templates but ends up generating invalid js it should be:

var o=(0,y.xliterate)`<root><p>Return to project's</p><link>updated ${(n=h.call(this,e)).props.agreementType}.</link></root>`;
AlbertoMeQ commented 11 months ago

Oh, interesting!

Do you know of any way to debug which step/tool is making that issue? If I remove the obfuscator, the build completes properly. So it's kind of hard to know exactly what step is failing.