Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions .github/workflows/go-unit-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: Go Unit Test

on:
pull_request:
branches:
- develop

jobs:
build-and-test:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: 1.23.4

- name: Install Go Dependencies
run: go mod tidy

- name: Install Node.js
uses: actions/setup-node@v4
with:
node-version: 20.12.0

- name: Install JS Dependencies
run: npm install --prefix frontend

- name: Build Frontend to be embedded
run: npm run build --prefix frontend

- name: Run tests
run: go test -v -cover ./...
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
build/bin
node_modules
frontend/dist
.idea/
87 changes: 87 additions & 0 deletions backend/filesystem/dialog.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
package filesystem

import (
"context"
"errors"
"github.com/wailsapp/wails/v2/pkg/runtime"
"io/fs"
"os/exec"
"path/filepath"
goRuntime "runtime"
"strings"
)

type Dialog struct {
ctx context.Context
}

func NewDialog() *Dialog {
return &Dialog{}
}

func (d *Dialog) SetContext(ctx context.Context) {
d.ctx = ctx
}

func (d *Dialog) OpenMultipleFilesDialog() ([]string, error) {
return runtime.OpenMultipleFilesDialog(d.ctx, runtime.OpenDialogOptions{
Title: "Select file(s)",
Filters: []runtime.FileFilter{
{DisplayName: "JavaScript", Pattern: "*.js"},
{DisplayName: "PHP", Pattern: "*.php"},
{DisplayName: "All Files", Pattern: "*"},
},
ShowHiddenFiles: true,
})
}

func (d *Dialog) OpenDirectoryDialog() ([]string, error) {
path, err := runtime.OpenDirectoryDialog(d.ctx, runtime.OpenDialogOptions{
Title: "Select folder",
})
if err != nil {
return nil, err
}

if path == "" {
return nil, errors.New("could not open folder")
}

var files []string
err = filepath.WalkDir(path, func(path string, d fs.DirEntry, err error) error {
if err != nil {
return err
}

if !d.IsDir() && (strings.HasSuffix(path, ".js") || strings.HasSuffix(path, ".php")) {
files = append(files, path)
}

return nil
})
return files, err
}

func (d *Dialog) OpenFileLocation(path string) error {
currOS := goRuntime.GOOS
command, ok := map[string]string{
"windows": "explorer",
"darwin": "open",
"linux": "xdg-open",
}[currOS]
if !ok {
return errors.New("unsupported OS: " + currOS)
}

return exec.Command(command, filepath.Dir(path)).Run()
}

func (d *Dialog) MessageInfoDialog(title string, message string) error {
_, err := runtime.MessageDialog(d.ctx, runtime.MessageDialogOptions{
Title: title,
Message: message,
Type: runtime.InfoDialog,
})

return err
}
54 changes: 54 additions & 0 deletions backend/filesystem/file_manager.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package filesystem

import (
"context"
"fmt"
"os"
"path/filepath"
)

type FileManager struct {
ctx context.Context
}

func NewFileManager() *FileManager {
return &FileManager{}
}

func (f *FileManager) SetContext(ctx context.Context) {
f.ctx = ctx
}

func (f *FileManager) ReadFile(path string) (string, error) {
contents, err := os.ReadFile(path)
if err != nil {
return "", err
}

return string(contents), nil
}

func (f *FileManager) WriteFile(path string, content string) error {
if _, err := os.Stat(path); os.IsNotExist(err) {
if err = os.WriteFile(path, []byte(content), 0644); err != nil {
return err
}

return nil
}

extension := filepath.Ext(path)
filename := path[:len(path)-len(extension)]
index := 1
for {
path = fmt.Sprintf("%s_%d%s", filename, index, extension)
if _, ok := os.Stat(path); os.IsNotExist(ok) {
if err := os.WriteFile(path, []byte(content), 0644); err != nil {
return err
}

return nil
}
index++
}
}
85 changes: 85 additions & 0 deletions backend/obfuscator/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
package obfuscator

import (
"encoding/json"
"log"
"os"
"path/filepath"
)

type Config struct {
SingleLineOutput bool `json:"single_line_output"`
StringLiteral bool `json:"string_literal"`
LoopStatement bool `json:"loop_statement"`
IfStatement bool `json:"if_statement"`
ConstantName bool `json:"constant_name"`
VariableName bool `json:"variable_name"`
FunctionName bool `json:"function_name"`
RemoveComments bool `json:"remove_comments"`
path string
}

func NewConfig() Config {
var config Config

err := config.load()
if os.IsNotExist(err) {
if err = config.save(); err != nil {
log.Fatal(err)
}
} else if err != nil {
log.Fatal(err)
}

log.Println("Hyperion config:", config.path)

return config
}

func (config *Config) load() error {
configDir, err := os.UserConfigDir()
if err != nil {
return err
}

appConfigDir := filepath.Join(configDir, "hyperion")
_, err = os.Stat(appConfigDir)
if os.IsNotExist(err) {
if err = os.MkdirAll(appConfigDir, os.ModePerm); err != nil {
return err
}
}

config.path = filepath.Join(appConfigDir, "config.json")
if _, err = os.Stat(config.path); err != nil {
return err
}

data, err := os.ReadFile(config.path)
if err != nil {
return err
}

if err = json.Unmarshal(data, &config); err != nil {
return err
}

return nil
}

func (config *Config) save() error {
data, err := json.MarshalIndent(config, "", " ")
if err != nil {
return err
}

return os.WriteFile(config.path, data, os.ModePerm)
}

func (config *Config) Save(c Config) {
log.Println("Saving obfuscation configuration", c)
}

func (config *Config) GetConfig() Config {
return *config
}
74 changes: 74 additions & 0 deletions backend/obfuscator/examples/example.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
const constantName = 'constantName';
const CONSTANT_NAME = 'CONSTANT_NAME';
const constant_name = 'constant_name';
const ConstantName = 'ConstantName';

let variableName1 = 'VARIABLE_NAME_1';
var variableName2 = 'VARIABLE_NAME_2';
let variableName3, variableName4;
var variableName5, variableName6;
let variableName7,variableName8 ,variableName9 , variableName10;

// REGULAR FUNCTION WITHOUT RETURN
function functionName1 () {
// constantName
// console.log("DECEPTION: constantNameCONSTANT_NAME constant_name-ConstantName");
console.log("DECEPTION: constantNameCONSTANT_NAME constant_name-ConstantName"); // Just string
console.log(`DECEPTION: ${constantName} ${CONSTANT_NAME}`); // This is constant, bro
console.log('DECEPTION: ${CONSTANT_NAME}'); // String
console.log("DECEPTION: ${constant_name}"); // String again
console.log(constantName, CONSTANT_NAME, constant_name, ConstantName);
}

// ARROW FUNCTION WITHOUT RETURN
const functionName2 = () => {
// variableName6
// console.log("DECEPTION: variableName1 variableName6variableName4");
console.log("DECEPTION: variableName3 variableName2variableName5"); // Just string
console.log(`DECEPTION: ${variableName6} ${variableName2}`); // This is variable, bro
console.log('DECEPTION: ${variableName6}'); // String
console.log("DECEPTION: ${variableName6}"); // String again
console.log(variableName6, variableName5, variableName2, variableName3, variableName4);
};

/**
* functionName3 - regular function to sum parameters
* @param params1 {int}
* @param params2 {int}
* @returns {int}
*/
function functionName3 (params1, params2) {
return params1 + params2;
}

/**
* functionName4 - arrow function to sum parameters
* @param params1
* @param params2
* @returns {*}
*/
const functionName4 = (params1, params2) => params1 + params2;

// ARROW FUNCTION WITHOUT PARENTHESES AND BRACKETS
const functionName5 = params => console.log(params);

// REGULAR FUNCTION WITH SPREAD PARAMETER
function functionName6 (...params) {
for (const param of params) {
console.log(param);
}
}

functionName1();
functionName2();
const functionName3Result = functionName3(10, 20);
let functionName4Result = functionName4(20, 10);
functionName5('DONE');
functionName6('A', 'N', 'J', 'A', 'Y');

/** LAST STATEMENT **/
if (functionName3Result === functionName4Result) {
console.log('FUNCTION RESULT IS IDENTICAL');
}


Loading
Loading