JSPM

  • Created
  • Published
  • Downloads 126
  • Score
    100M100P100Q81483F
  • License MIT

Code obfuscator that protects your code regardless of the programming language or framework.

Package Exports

  • codefend
  • codefend/build/cjs/index.js
  • codefend/build/esm/index.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (codefend) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

Codefend

Codefend short for "Code Defender" encrypts your code regardless of your source code language or framework.

Installation

Globally

npm install -g codefend

Dev dependency

npm install -D codefend

npx

In case you want to execute it directly without installing it on your machine:

npx codefend -i  //generates .codefendrc.json
npx codefend -o  //obfuscates your whole project inside a new directory: 'codefend-output'

Commands

Usage: codefend [options]

Defend Your Code By All Means Necessary. 💪 😎

Options:
  -V, --version    output the version number
  -i, --init       Create .codefendrc.json (configuration file)
  -c, --check      Check .codefendrc.json for potential warnings/errors
  -o, --obfuscate  Obfuscate your project (based on .codefendrc.json)
  -h, --help       display help for command

Philosophy

The only thing Codefend needs from you as a programmer is to follow a specific naming convention for the words that you want to obfuscate (variable/functions/classes...) and Codefend will do the rest ✨
This basic rule applies to all the languages and the frameworks that you will be programming with while using Codefend to defend your source.

Basic Usage

Step 1: Naming convention

Add prefixes to the words that you want to encrypt.

/** 
1- local variable -> starts with l_
2- parameter -> starts with p_
3- function -> starts with f_
4- class -> starts with c_
*/
class c_Calculator {
  f_sum(p_a, p_b) {
    const l_results = p_a + p_b;
    return l_results;
  }
}

//>>>>>>==== Will Become ======<<<<<<
class Ox0 {
  Ox1(Ox2, Ox3) {
    const Ox4 = Ox2 + Ox3;
    return Ox4;
  }
}

Step 2: Run the CLI

navigate to the root of your project and run the following commands:

codefend -i  //generates .codefendrc.json
codefend -o  //obfuscates your whole project inside a new directory: 'codefend-output'

Step 3: install dependencies, build and deploy the obfuscated project

      cd codefend-output  //navigate to the output folder (codefend-output by default)
      npm install //install dependencies
      npm run build //build the obfuscated project
      npm run deploy  //deploy the obfuscated project

Examples

  1. Node js

  2. Angular (coming soon)

  3. React (coming soon)

  4. Vue (coming soon)

  5. Svelte (coming soon)

  6. Python (coming soon)

  7. C# (coming soon)

  8. C++ (coming soon)

Configuration

//default configuration generated inside .codefendrc.json
{
  debug: true,    // for additional logs
  generationOptions: {
    inputDir: ".", // the folder that should be copied and obfuscated ( keep it . if you're running in the same directory)
    outputDir: "codefend-output", // the output folder that will be an obfuscated clone of your code
    ignoredFilesInGeneration: [ // the files that should not be copied to the output folder
      "codefend-output",
      ".codefendrc.json",
      "node_modules",
      ".git",
      ".github",
      ".gitignore",
      ".vscode",
      "build",
      "dist",
    ],
  },

  obfuscationOptions: {
    prefix: "Ox", // the prefix of each variable, make sure its a valid character to start with a variable ( e.g do not start with "-"" or a number)
    predefinedWords: [], // words that you want to obfuscate them in a static way (determined output)
                         // {"originalWord":"l_secretVar" , "targetWord": "123456"}
                         // note that the original word should have a prefix 'l_' to be detected and replaced

    ignoredWords: ["node_modules"], // words that you wish not to obfuscate them and they unfortunately match the regex :)
    regexList: [
      {
        name: "main",
        value: "([a-zA-Z]+(_[a-zA-Z0-9]+)+)",//regex for variables,functions,classes ...
        flag: "g",
      },
      {
        name: "file",
        value: "((cmp|lib)+(-[a-zA-Z]+)+)",//regex for files (coming soon)
        flag: "g",
      },
    ],
  },
}

Advanced Usage (beta)

Prefix

default: "Ox"

Naming convention

Note: its possible to not follow the exact naming convention as long as the words you want to encrypts match the regex.

```js
//as an example you can use the same prefix for all words:
class l_Calculator {
  l_sum(l_a, l_b) {
    const l_results = l_a + l_b;
    return l_results;
  }
}
// or use a custom prefix
class myApp_Calculator {
  myApp_sum(myApp_a, myApp_b) {
    const myApp_results = myApp_a + myApp_b;
    return myApp_results;
  }
}

Ignore Files

its possible to ignore some files from being generated into the new obfuscated folder

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

License

MIT