Skip to content

Commit

Permalink
chore(training): add encoding scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
stfsy committed Nov 4, 2023
1 parent ccbbbc0 commit 050f35c
Show file tree
Hide file tree
Showing 8 changed files with 147 additions and 0 deletions.
16 changes: 16 additions & 0 deletions model/encode-w-jjencode.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
'use strict'

const je = require('jencrypt')
const category = 'jjencode'

const { encodeFilesInFolder } = require('./encoder.js')

async function encodeFiles() {
await encodeFilesInFolder({
category, callback: async (content) => {
return je.encode(content)
}
})
}

encodeFiles()
16 changes: 16 additions & 0 deletions model/encode-w-jsconfuser-minified.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
'use strict'

const jsconfuser = require('js-confuser')
const category = 'jsconfuser-minified'

const { encodeFilesInFolder } = require('./encoder.js')

async function encodeFiles() {
await encodeFilesInFolder({
category, callback: (content) => {
return jsconfuser.obfuscate(content, { target: 'node', deadCode: true, minify: true })
}
})
}

encodeFiles()
16 changes: 16 additions & 0 deletions model/encode-w-jsconfuser.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
'use strict'

const jsconfuser = require('js-confuser')
const category = 'jsconfuser'

const { encodeFilesInFolder } = require('./encoder.js')

async function encodeFiles() {
await encodeFilesInFolder({
category, callback: (content) => {
return jsconfuser.obfuscate(content, { target: 'node', deadCode: true, minify: false, preset: 'high' })
}
})
}

encodeFiles()
16 changes: 16 additions & 0 deletions model/encode-w-jsfuck.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
'use strict'

const { JSFuck: { encode } } = require('jsfuck')
const category = 'jsfuck'

const { encodeFilesInFolder } = require('./encoder.js')

async function encodeFiles() {
await encodeFilesInFolder({
category, callback: async (content) => {
return encode(content)
}
})
}

encodeFiles()
16 changes: 16 additions & 0 deletions model/encode-w-obfuscate.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
'use strict'

const { obfuscate } = require('javascript-obfuscator')
const category = 'obfuscate'

const { encodeFilesInFolder } = require('./encoder.js')

async function encodeFiles() {
await encodeFilesInFolder({
category, callback: async (content) => {
return obfuscate(content).getObfuscatedCode()
}
})
}

encodeFiles()
16 changes: 16 additions & 0 deletions model/encode-w-sake.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
'use strict'

const sake = require('sake-js')
const category = 'sake'

const { encodeFilesInFolder } = require('./encoder.js')

async function encodeFiles() {
await encodeFilesInFolder({
category, callback: async (content) => {
return sake.obfuscate(content, { random: true })
}
})
}

encodeFiles()
16 changes: 16 additions & 0 deletions model/encode-w-uglify.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
'use strict'

const { minify } = require('uglify-js')
const category = 'uglify'

const { encodeFilesInFolder } = require('./encoder.js')

async function encodeFiles() {
await encodeFilesInFolder({
category, callback: async (content) => {
return minify(content, { compress: true }).code
}
})
}

encodeFiles()
35 changes: 35 additions & 0 deletions model/encoder.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
'use strict'

const { readFile, writeFile, stat, readdir } = require('fs/promises')
const path = require('path')

const [, , baseFolder] = process.argv

module.exports.encodeFilesInFolder = async function ({ category, callback }) {
const input = `${baseFolder}/plain`
try {
const files = await readdir(input)

for (const file of files) {
const filePath = path.join(input, file)
const stats = await stat(filePath)

if (stats.isFile()) {
const content = await readFile(filePath, 'utf-8')

try {
const encoded = await callback(content)
const newPath = filePath.replace('plain', category)

await writeFile(newPath, encoded, 'utf-8')
console.log('File encoded:', filePath, '->', newPath)
} catch (e) {

}

}
}
} catch (err) {
console.error('Error reading directory:', err)
}
}

0 comments on commit 050f35c

Please sign in to comment.