Browse Source

代码混淆:deadCodeInjection & controlFlowFlattening

Michael Wang 3 years ago
parent
commit
bb3e712b1a
1 changed files with 30 additions and 27 deletions
  1. 30 27
      vite.config.ts

+ 30 - 27
vite.config.ts

@@ -43,28 +43,33 @@ export default defineConfig({
         globalsPropValue: true, // Default `true`, (true | false | 'readonly' | 'readable' | 'writable' | 'writeable')
       },
     }),
+    legacy({
+      targets: ["chrome >= 58"],
+      additionalLegacyPolyfills: ["regenerator-runtime/runtime"],
+    }),
     process.env.NODE_ENV === "development"
       ? {}
       : obfuscator({
           // 不同的构建可能成功运行也可能不成功?
-          fileOptions: {
-            optionsPreset: "low-obfuscation",
-            debugProtection: false,
-            transformObjectKeys: false,
-            disableConsoleOutput: false,
-            // deadCodeInjectionThreshold: 0.4,
-            controlFlowFlattening: true,
-            controlFlowFlatteningThreshold: 0.9,
-            // per-file:
-            deadCodeInjection: true,
-            deadCodeInjectionThreshold: 1,
-            // stringArrayThreshold: 1,
-            // numbersToExpressions: true,
-            // controlFlowFlatteningThreshold: 1,
-            // stringArrayCallsTransform: true,
-            // stringArrayCallsTransformThreshold: 1,
-            // stringArrayEncoding: ["rc4"],
-          },
+          // 看看是不是单个文件做transform,然后对最终文件做renderChunk导致的构建结果不一致
+          fileOptions: false,
+          // fileOptions: {
+          //   optionsPreset: "low-obfuscation",
+          //   debugProtection: false,
+          //   transformObjectKeys: false,
+          //   disableConsoleOutput: false,
+          //   // controlFlowFlattening: true,
+          //   controlFlowFlatteningThreshold: 0.9,
+          //   // per-file:
+          //   deadCodeInjection: true,
+          //   deadCodeInjectionThreshold: 1,
+          //   // stringArrayThreshold: 1,
+          //   // numbersToExpressions: true,
+          //   // controlFlowFlatteningThreshold: 1,
+          //   // stringArrayCallsTransform: true,
+          //   // stringArrayCallsTransformThreshold: 1,
+          //   // stringArrayEncoding: ["rc4"],
+          // },
           globalOptions: {
             optionsPreset: "low-obfuscation",
             // debugProtection: true,
@@ -79,17 +84,19 @@ export default defineConfig({
             splitStrings: true,
             disableConsoleOutput: false,
             // // stringArrayCallsTransform: true,
-            // deadCodeInjection: true,
+            deadCodeInjection: true,
             // numbersToExpressions: true,
-            // controlFlowFlattening: true,
+            controlFlowFlattening: true,
             // stringArrayEncoding: ["none", "base64", "rc4"],
             // stringArrayRotate: true,
             // transformObjectKeys: true,
           },
           include: [
-            "**/utils/encDec.ts",
-            "**/UserLogin/**.ts",
-            "**/Examing/**/**.ts",
+            // "src/**/**.ts",
+            // "src/**/**.js",
+            "src/utils/**.ts",
+            // "**/UserLogin/**.ts",
+            // "**/Examing/**/**.ts",
           ],
           exclude: ["node_modules/**"],
           ...(disableObfuse
@@ -99,10 +106,6 @@ export default defineConfig({
               }
             : {}),
         }),
-    legacy({
-      targets: ["chrome >= 58"],
-      additionalLegacyPolyfills: ["regenerator-runtime/runtime"],
-    }),
   ],
   server: {
     port: 3000,