Browse Source

Renamed TObject -> TDictionary (#616)

* Renamed TObject -> TDictionary
* Added key features to the README.md
Timofey Kachalov 5 năm trước cách đây
mục cha
commit
9213a13b2c

+ 8 - 0
README.md

@@ -10,6 +10,14 @@
 
 JavaScript Obfuscator is a powerful free obfuscator for JavaScript, containing a variety of features which provide protection for your source code.
 
+**Key features:**
+- variables renaming
+- strings extraction and encryption
+- dead code injection
+- control flow flattening
+- various code transformations
+- and [more](#javascript-obfuscator-options)...
+
 The example of obfuscated code: [github.com](https://github.com/javascript-obfuscator/javascript-obfuscator/blob/master/examples/javascript-obfuscator.js)
 
 #### Online version:

Những thai đổi đã bị hủy bỏ vì nó quá lớn
+ 0 - 0
dist/index.cli.js


Những thai đổi đã bị hủy bỏ vì nó quá lớn
+ 0 - 0
dist/index.js


+ 1 - 1
package.json

@@ -54,7 +54,7 @@
     "@types/mkdirp": "1.0.0",
     "@types/mocha": "7.0.2",
     "@types/multimatch": "4.0.0",
-    "@types/node": "14.0.5",
+    "@types/node": "14.0.6",
     "@types/rimraf": "3.0.0",
     "@types/sinon": "9.0.4",
     "@types/string-template": "1.0.2",

+ 2 - 2
src/JavaScriptObfuscatorFacade.ts

@@ -4,7 +4,7 @@ import { ServiceIdentifiers } from './container/ServiceIdentifiers';
 
 import { TInputOptions } from './types/options/TInputOptions';
 import { TObfuscationResultsObject } from './types/TObfuscationResultsObject';
-import { TObject } from './types/TObject';
+import { TDictionary } from './types/TDictionary';
 
 import { IInversifyContainerFacade } from './interfaces/container/IInversifyContainerFacade';
 import { IJavaScriptObfuscator } from './interfaces/IJavaScriptObfsucator';
@@ -43,7 +43,7 @@ class JavaScriptObfuscatorFacade {
      * @param {TInputOptions} inputOptions
      * @returns {TObfuscationResultsObject<TSourceCodesObject>}
      */
-    public static obfuscateMultiple <TSourceCodesObject extends TObject<string>> (
+    public static obfuscateMultiple <TSourceCodesObject extends TDictionary<string>> (
         sourceCodesObject: TSourceCodesObject,
         inputOptions: TInputOptions = {}
     ): TObfuscationResultsObject<TSourceCodesObject> {

+ 4 - 4
src/cli/utils/CLIUtils.ts

@@ -1,12 +1,12 @@
-import { TObject } from '../../types/TObject';
+import { TDictionary } from '../../types/TDictionary';
 
 export class CLIUtils {
     /**
      * @param {string} configPath
-     * @returns {TObject}
+     * @returns {TDictionary}
      */
-    public static getUserConfig (configPath: string): TObject {
-        let config: TObject;
+    public static getUserConfig (configPath: string): TDictionary {
+        let config: TDictionary;
 
         try {
             config = require(configPath);

+ 6 - 6
src/code-transformers/CodeTransformersRunner.ts

@@ -3,7 +3,7 @@ import { inject, injectable } from 'inversify';
 import { ServiceIdentifiers } from '../container/ServiceIdentifiers';
 
 import { TCodeTransformerFactory } from '../types/container/code-transformers/TCodeTransformerFactory';
-import { TObject } from '../types/TObject';
+import { TDictionary } from '../types/TDictionary';
 
 import { ICodeTransformer } from '../interfaces/code-transformers/ICodeTransformer';
 import { ICodeTransformersRunner } from '../interfaces/code-transformers/ICodeTransformersRunner';
@@ -59,7 +59,7 @@ export class CodeTransformersRunner implements ICodeTransformersRunner {
             return code;
         }
 
-        const normalizedCodeTransformers: TObject<ICodeTransformer> =
+        const normalizedCodeTransformers: TDictionary<ICodeTransformer> =
             this.buildNormalizedCodeTransformers(codeTransformerNames, codeTransformationStage);
         const codeTransformerNamesGroups: CodeTransformer[][] =
             this.codeTransformerNamesGroupsBuilder.build(normalizedCodeTransformers);
@@ -78,15 +78,15 @@ export class CodeTransformersRunner implements ICodeTransformersRunner {
     /**
      * @param {NodeTransformer[]} codeTransformerNames
      * @param {NodeTransformationStage} codeTransformationStage
-     * @returns {TObject<INodeTransformer>}
+     * @returns {TDictionary<INodeTransformer>}
      */
     private buildNormalizedCodeTransformers (
         codeTransformerNames: CodeTransformer[],
         codeTransformationStage: CodeTransformationStage
-    ): TObject<ICodeTransformer> {
+    ): TDictionary<ICodeTransformer> {
         return codeTransformerNames
-            .reduce<TObject<ICodeTransformer>>(
-                (acc: TObject<ICodeTransformer>, codeTransformerName: CodeTransformer) => {
+            .reduce<TDictionary<ICodeTransformer>>(
+                (acc: TDictionary<ICodeTransformer>, codeTransformerName: CodeTransformer) => {
                     const codeTransformer: ICodeTransformer = this.codeTransformerFactory(codeTransformerName);
 
                     return {

+ 2 - 2
src/custom-code-helpers/CustomCodeHelperFormatter.ts

@@ -5,7 +5,7 @@ import * as estraverse from 'estraverse';
 import * as ESTree from 'estree';
 import format from 'string-template';
 
-import { TObject } from '../types/TObject';
+import { TDictionary } from '../types/TDictionary';
 import { TStatement } from '../types/node/TStatement';
 
 import { ICustomCodeHelperFormatter } from '../interfaces/custom-code-helpers/ICustomCodeHelperFormatter';
@@ -32,7 +32,7 @@ export class CustomCodeHelperFormatter implements ICustomCodeHelperFormatter {
      * @param {TMapping} mapping
      * @returns {string}
      */
-    public formatTemplate <TMapping extends TObject> (
+    public formatTemplate <TMapping extends TDictionary> (
         template: string,
         mapping: TMapping
     ): string {

+ 2 - 2
src/interfaces/custom-code-helpers/ICustomCodeHelperFormatter.ts

@@ -1,4 +1,4 @@
-import { TObject } from '../../types/TObject';
+import { TDictionary } from '../../types/TDictionary';
 import { TStatement } from '../../types/node/TStatement';
 
 export interface ICustomCodeHelperFormatter {
@@ -7,7 +7,7 @@ export interface ICustomCodeHelperFormatter {
      * @param {TMapping} mapping
      * @returns {string}
      */
-    formatTemplate <TMapping extends TObject> (
+    formatTemplate <TMapping extends TDictionary> (
         template: string,
         mapping: TMapping
     ): string;

+ 3 - 3
src/interfaces/utils/ITransformerNamesGroupsBuilder.ts

@@ -1,12 +1,12 @@
-import { TObject } from '../../types/TObject';
+import { TDictionary } from '../../types/TDictionary';
 
 export interface ITransformerNamesGroupsBuilder <
     TTransformerName extends string,
     TTransformer
 > {
     /**
-     * @param {TObject<TTransformer>} normalizedTransformers
+     * @param {TDictionary<TTransformer>} normalizedTransformers
      * @returns {TTransformerName[][]}
      */
-    build (normalizedTransformers: TObject<TTransformer>): TTransformerName[][];
+    build (normalizedTransformers: TDictionary<TTransformer>): TTransformerName[][];
 }

+ 6 - 6
src/node-transformers/NodeTransformersRunner.ts

@@ -6,7 +6,7 @@ import * as estraverse from 'estraverse';
 import * as ESTree from 'estree';
 
 import { TNodeTransformerFactory } from '../types/container/node-transformers/TNodeTransformerFactory';
-import { TObject } from '../types/TObject';
+import { TDictionary } from '../types/TDictionary';
 import { TVisitorDirection } from '../types/node-transformers/TVisitorDirection';
 import { TVisitorFunction } from '../types/node-transformers/TVisitorFunction';
 import { TVisitorResult } from '../types/node-transformers/TVisitorResult';
@@ -70,7 +70,7 @@ export class NodeTransformersRunner implements INodeTransformersRunner {
             return astTree;
         }
 
-        const normalizedNodeTransformers: TObject<INodeTransformer> =
+        const normalizedNodeTransformers: TDictionary<INodeTransformer> =
             this.buildNormalizedNodeTransformers(nodeTransformerNames, nodeTransformationStage);
         const nodeTransformerNamesGroups: NodeTransformer[][] =
             this.nodeTransformerNamesGroupsBuilder.build(normalizedNodeTransformers);
@@ -112,15 +112,15 @@ export class NodeTransformersRunner implements INodeTransformersRunner {
     /**
      * @param {NodeTransformer[]} nodeTransformerNames
      * @param {NodeTransformationStage} nodeTransformationStage
-     * @returns {TObject<INodeTransformer>}
+     * @returns {TDictionary<INodeTransformer>}
      */
     private buildNormalizedNodeTransformers (
         nodeTransformerNames: NodeTransformer[],
         nodeTransformationStage: NodeTransformationStage
-    ): TObject<INodeTransformer> {
+    ): TDictionary<INodeTransformer> {
         return nodeTransformerNames
-            .reduce<TObject<INodeTransformer>>(
-                (acc: TObject<INodeTransformer>, nodeTransformerName: NodeTransformer) => {
+            .reduce<TDictionary<INodeTransformer>>(
+                (acc: TDictionary<INodeTransformer>, nodeTransformerName: NodeTransformer) => {
                     const nodeTransformer: INodeTransformer = this.nodeTransformerFactory(nodeTransformerName);
 
                     if (!nodeTransformer.getVisitor(nodeTransformationStage)) {

+ 2 - 2
src/options/ValidationErrorsFormatter.ts

@@ -1,6 +1,6 @@
 import { ValidationError } from 'class-validator';
 
-import { TObject } from '../types/TObject';
+import { TDictionary } from '../types/TDictionary';
 
 export class ValidationErrorsFormatter {
     /**
@@ -24,7 +24,7 @@ export class ValidationErrorsFormatter {
      * @returns {string}
      */
     private static formatWithNestedConstraints (error: ValidationError): string {
-        const constraints: TObject<string> | undefined = error.constraints;
+        const constraints: TDictionary<string> | undefined = error.constraints;
 
         if (!constraints) {
             return `\`${error.property}\` error\n`;

+ 1 - 1
src/types/TObject.ts → src/types/TDictionary.ts

@@ -1,3 +1,3 @@
 /* eslint-disable @typescript-eslint/consistent-type-definitions */
 
-export type TObject <T = unknown> = {[key: string]: T};
+export type TDictionary <T = unknown> = {[key: string]: T};

+ 2 - 2
src/types/options/TInputCLIOptions.ts

@@ -1,5 +1,5 @@
-import { TObject } from '../TObject';
+import { TDictionary } from '../TDictionary';
 
 import { ICLIOptions } from '../../interfaces/options/ICLIOptions';
 
-export type TInputCLIOptions = Partial<Pick<ICLIOptions, keyof ICLIOptions>> & TObject;
+export type TInputCLIOptions = Partial<Pick<ICLIOptions, keyof ICLIOptions>> & TDictionary;

+ 2 - 2
src/types/options/TInputOptions.ts

@@ -1,5 +1,5 @@
-import { TObject } from '../TObject';
+import { TDictionary } from '../TDictionary';
 
 import { IOptions } from '../../interfaces/options/IOptions';
 
-export type TInputOptions = Partial<Pick<IOptions, keyof IOptions>> & TObject;
+export type TInputOptions = Partial<Pick<IOptions, keyof IOptions>> & TDictionary;

+ 5 - 5
src/utils/AbstractTransformerNamesGroupsBuilder.ts

@@ -1,7 +1,7 @@
 import { inject, injectable } from 'inversify';
 import { ServiceIdentifiers } from '../container/ServiceIdentifiers';
 
-import { TObject } from '../types/TObject';
+import { TDictionary } from '../types/TDictionary';
 import { TTransformersRelationEdge } from '../types/utils/TTransformersRelationEdge';
 
 import { ILevelledTopologicalSorter } from '../interfaces/utils/ILevelledTopologicalSorter';
@@ -48,10 +48,10 @@ export abstract class AbstractTransformerNamesGroupsBuilder <
      *      ]
      *  ]
      *
-     * @param {TObject<TTransformer>} normalizedTransformers
+     * @param {TDictionary<TTransformer>} normalizedTransformers
      * @returns {TTransformerName[][]}
      */
-    public build (normalizedTransformers: TObject<TTransformer>): TTransformerName[][] {
+    public build (normalizedTransformers: TDictionary<TTransformer>): TTransformerName[][] {
         const transformerNames: TTransformerName[] = <TTransformerName[]>Object.keys(normalizedTransformers);
         const relationEdges: TTransformersRelationEdge<TTransformerName>[] = this.buildTransformersRelationEdges(
             transformerNames,
@@ -67,12 +67,12 @@ export abstract class AbstractTransformerNamesGroupsBuilder <
 
     /**
      * @param {TTransformerName[]} transformerNames
-     * @param {TObject<TTransformer>} normalizedTransformers
+     * @param {TDictionary<TTransformer>} normalizedTransformers
      * @returns {TTransformersRelationEdge<TTransformerName>[]}
      */
     private buildTransformersRelationEdges (
         transformerNames: TTransformerName[],
-        normalizedTransformers: TObject<TTransformer>
+        normalizedTransformers: TDictionary<TTransformer>
     ): TTransformersRelationEdge<TTransformerName>[] {
         const relationEdges: TTransformersRelationEdge<TTransformerName>[] = [];
 

+ 2 - 2
test/functional-tests/javascript-obfuscator/JavaScriptObfuscator.spec.ts

@@ -2,7 +2,7 @@ import { assert } from 'chai';
 import { TypeFromEnum } from '@gradecam/tsenum';
 
 import { TInputOptions } from '../../../src/types/options/TInputOptions';
-import { TObject } from '../../../src/types/TObject';
+import { TDictionary } from '../../../src/types/TDictionary';
 
 import { IObfuscatedCode } from '../../../src/interfaces/source-code/IObfuscatedCode';
 
@@ -974,7 +974,7 @@ describe('JavaScriptObfuscator', () => {
         });
 
         describe('invalid source codes object', () => {
-            let testFunc: () => TObject<IObfuscatedCode>;
+            let testFunc: () => TDictionary<IObfuscatedCode>;
 
             beforeEach(() => {
                 testFunc = () => JavaScriptObfuscator.obfuscateMultiple(

+ 4 - 4
yarn.lock

@@ -364,10 +364,10 @@
   resolved "https://registry.yarnpkg.com/@types/node/-/node-13.9.3.tgz#6356df2647de9eac569f9a52eda3480fa9e70b4d"
   integrity sha512-01s+ac4qerwd6RHD+mVbOEsraDHSgUaefQlEdBbUolnQFjKwCr7luvAlEwW1RFojh67u0z4OUTjPn9LEl4zIkA==
 
-"@types/[email protected].5":
-  version "14.0.5"
-  resolved "https://registry.yarnpkg.com/@types/node/-/node-14.0.5.tgz#3d03acd3b3414cf67faf999aed11682ed121f22b"
-  integrity sha512-90hiq6/VqtQgX8Sp0EzeIsv3r+ellbGj4URKj5j30tLlZvRUpnAe9YbYnjl3pJM93GyXU0tghHhvXHq+5rnCKA==
+"@types/[email protected].6":
+  version "14.0.6"
+  resolved "https://registry.yarnpkg.com/@types/node/-/node-14.0.6.tgz#f9e178b2da31a4b0ec60b64649e244c31ce18daf"
+  integrity sha512-FbNmu4F67d3oZMWBV6Y4MaPER+0EpE9eIYf2yaHhCWovc1dlXCZkqGX4NLHfVVr6umt20TNBdRzrNJIzIKfdbw==
 
 "@types/normalize-package-data@^2.4.0":
   version "2.4.0"

Một số tệp đã không được hiển thị bởi vì quá nhiều tập tin thay đổi trong này khác