🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
DemoInstallSign in
Socket

github.com/naicoi92/obfuscator

Package Overview
Dependencies
Alerts
File Explorer
Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

github.com/naicoi92/obfuscator

v0.1.4
Source
Go
Version published
Created
Source

jsobfuscator-go

Go Report Card GoDoc

A Go library for JavaScript obfuscation using V8 JavaScript Engine.

English | Tiếng Việt

Introduction

jsobfuscator-go is a Go library that helps obfuscate JavaScript code by using JavaScript Obfuscator and V8 Engine. This library provides a simple way to protect your JavaScript code from being easily read and understood.

Installation

go get github.com/naicoi92/obfuscator

Requirements

  • Go 1.24.0 or later
  • v8go library (automatically installed when using go get)

Usage

Basic Example

package main

import (
	"fmt"
	"github.com/naicoi92/obfuscator"
)

func main() {
	// Initialize the obfuscator
	obf, err := obfuscator.NewObfuscator()
	if err != nil {
		panic(err)
	}

	// JavaScript code to obfuscate
	jsCode := `function sayHello() { return "Hello World"; }`

	// Perform obfuscation
	obfuscatedCode, err := obf.Obfuscate(jsCode)
	if err != nil {
		panic(err)
	}

	// Print the obfuscated code
	fmt.Println(obfuscatedCode)
}

Important Notes

  • JavaScript code cannot contain backtick characters (`) as they are used to wrap the code during processing.
  • The obfuscator uses the following default options:
    const options = {
        compact: (Math.random() < 0.5),
        controlFlowFlattening: true,
        controlFlowFlatteningThreshold: 1,
        numbersToExpressions: true,
        simplify: true,
        stringArrayShuffle: true,
        splitStrings: true,
        stringArrayThreshold: 1
    }
    

Performance Optimization

The library uses a caching mechanism to optimize performance when performing multiple obfuscations. You should reuse the same Obfuscator instance when you need to obfuscate multiple JavaScript code snippets.

obf, _ := obfuscator.NewObfuscator()

// Use the same instance for multiple obfuscations
result1, _ := obf.Obfuscate(jsCode1)
result2, _ := obf.Obfuscate(jsCode2)
result3, _ := obf.Obfuscate(jsCode3)

Contributing

Contributions are welcome! Please feel free to submit a Pull Request or create an Issue on GitHub.

License

This project is distributed under the MIT license.

FAQs

Package last updated on 15 Apr 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts