getkey / rollup-plugin-obfuscator

The most powerful rollup plugin for javascript-obfuscator.
Mozilla Public License 2.0
117 stars 9 forks source link

deadCodeInjection: x[y] is not a function with Nuxt 3 #8

Closed Extarys closed 2 years ago

Extarys commented 2 years ago

With deadCodeInjection, each seed generate a different error message ending by "is not a function". I doubt this belongs to javascript-obfuscator, but feel free to redirect me there nonetheless if you believe this isn't plugin error :wink:

image

While building the Nuxt project, I also get 1 to 2 warnings: WARN The 'this' keyword is equivalent to 'undefined' at the top level of an ES module, and has been rewritten

Steps to reproduce:

  1. Create a Nuxt project: npx nuxi new testproject && ce testproject && yarn install
  2. Add dependencies: yarn add --dev rollup-plugin-obfuscator javascript-obfuscator
  3. Edit nuxt.config.ts:
    
    import { defineNuxtConfig } from 'nuxt3'
    import obfuscator from 'rollup-plugin-obfuscator';

// https://v3.nuxtjs.org/docs/directory-structure/nuxt.config export default defineNuxtConfig({ buildModules: [ ], vite: { plugins: [ obfuscator({ exclude: ['node_modules/', '.nuxt/', '.output/**'], fileOptions: false, globalOptions: { compact: true, simplify: true, selfDefending: false, controlFlowFlattening: true, controlFlowFlatteningThreshold: 0.5, deadCodeInjection: true, deadCodeInjectionThreshold: 0.1, stringArrayRotate: true, stringArrayShuffle: true, stringArrayIndexesType: [ 'hexadecimal-numeric-string' ], stringArrayWrappersCount: 2, stringArrayWrappersType: 'function', stringArrayEncoding: ['base64'], identifierNamesGenerator: 'mangled-shuffled', } }), ] } })


4. Build and run the project with `npx nuxi build && npx nuxi preview`
Setting `deadCodeInjection` to false solves this issue.

[Thanks for this plugin, it's awesome :smile:, can't wait to test different options and benchmark my app]

**EDIT** Enabling `stringArrayCallsTransform` results in a similar error.
getkey commented 2 years ago

Sorry for the slow response. I'm almost certain it's an issue in javascript-obfuscator. rollup-plugin-obfuscator is merely passing down the options you set to javascript-obfuscator so if it works with a certain set of options but not another, it smells like an issue in javascript-obfuscator. :wink: I tried your reproduce steps but didn't get any error. Could you upgrade javascript-obfuscator and try again? Mostly likely, the issue has been fixed upstream since you opened this ticket, which is why it works on the newer version of javascript-obfuscator I just downloaded (v4.0.0).

Extarys commented 2 years ago

Sorry for the slow response.

Hey, no worries! :heart:

I'm almost certain it's an issue in javascript-obfuscator. rollup-plugin-obfuscator is merely passing down the options you set to javascript-obfuscator so if it works with a certain set of options but not another, it smells like an issue in javascript-obfuscator. wink

Makes sense.

Could you upgrade javascript-obfuscator and try again?

I will definitely give it a try!

I just downloaded (v4.0.0).

Ohh, new version! How exciting! :heart_eyes: