Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: use LF line ending in cli.js #132

Merged
merged 1 commit into from
Nov 9, 2023
Merged
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
188 changes: 94 additions & 94 deletions src/cli.js
Original file line number Diff line number Diff line change
@@ -1,94 +1,94 @@
#!/usr/bin/env node
const { Deobfuscator } = require('../'),
yargs = require('yargs'),
path = require('path'),
fs = require('fs')
yargs
.scriptName('synchrony')
.usage('Usage: $0 <command> [args]')
.command(
['deobfuscate <file>', '$0 <file>'],
'Deobfuscate a file',
(yargs) =>
yargs
.positional('file', {
type: 'string',
describe: 'File to deobfuscate (include extension)',
})
.option('rename', {
type: 'boolean',
default: false,
description: 'Rename symbols automatically',
})
.option('ecma-version', {
alias: ['esversion', 'es'],
default: 'latest',
type: 'string',
description: 'Set ECMA version for AST parser (see acorn docs)',
})
.option('config', {
alias: 'c',
type: 'string',
description: 'Supply a custom deobfuscation config (see docs)',
})
.option('output', {
alias: 'o',
type: 'string',
description: 'Where to output deobfuscated file',
})
.option('loose', {
alias: 'l',
type: 'boolean',
default: false,
description: 'Enable loose parsing',
})
.option('sourceType', {
alias: 'type',
type: 'string',
default: 'both',
description: "Source type for file ('script', 'module', or 'both')",
}),
(args) => {
const abs = path.resolve(args.file)
fs.stat(abs, (err) => {
if (err) return console.error('Failed to stat', err.code)
fs.readFile(abs, 'utf8', (err, source) => {
if (err) return console.error('Failed to read file', err.code)
const deobfuscator = new Deobfuscator()
let opts = {
rename: args.rename,
ecmaVersion: args.ecmaVersion,
output: args.output,
loose: args.loose,
sourceType: args.sourceType,
}
if (args.config) {
let configPath = path.resolve(args.config)
if (!fs.existsSync(configPath)) {
console.error(
'Configuration file',
'"' + args.config + '"',
'does not exist on disk'
)
process.exit(1)
}
Object.assign(opts, require(configPath))
console.log('Loaded config from', '"' + args.config + '"')
}
// ready
deobfuscator.deobfuscateSource(source, opts).then((source) => {
let ext = path.extname(abs)
let newFilename = opts.output
? opts.output
: abs.substring(0, abs.length - ext.length) + '.cleaned' + ext
fs.writeFile(newFilename, source, 'utf8', (err) => {
if (err) return console.error('Failed to write file', err.code)
})
})
})
})
}
).argv
#!/usr/bin/env node
const { Deobfuscator } = require('../'),
yargs = require('yargs'),
path = require('path'),
fs = require('fs')

yargs
.scriptName('synchrony')
.usage('Usage: $0 <command> [args]')
.command(
['deobfuscate <file>', '$0 <file>'],
'Deobfuscate a file',
(yargs) =>
yargs
.positional('file', {
type: 'string',
describe: 'File to deobfuscate (include extension)',
})
.option('rename', {
type: 'boolean',
default: false,
description: 'Rename symbols automatically',
})
.option('ecma-version', {
alias: ['esversion', 'es'],
default: 'latest',
type: 'string',
description: 'Set ECMA version for AST parser (see acorn docs)',
})
.option('config', {
alias: 'c',
type: 'string',
description: 'Supply a custom deobfuscation config (see docs)',
})
.option('output', {
alias: 'o',
type: 'string',
description: 'Where to output deobfuscated file',
})
.option('loose', {
alias: 'l',
type: 'boolean',
default: false,
description: 'Enable loose parsing',
})
.option('sourceType', {
alias: 'type',
type: 'string',
default: 'both',
description: "Source type for file ('script', 'module', or 'both')",
}),
(args) => {
const abs = path.resolve(args.file)
fs.stat(abs, (err) => {
if (err) return console.error('Failed to stat', err.code)
fs.readFile(abs, 'utf8', (err, source) => {
if (err) return console.error('Failed to read file', err.code)
const deobfuscator = new Deobfuscator()
let opts = {
rename: args.rename,
ecmaVersion: args.ecmaVersion,
output: args.output,
loose: args.loose,
sourceType: args.sourceType,
}

if (args.config) {
let configPath = path.resolve(args.config)
if (!fs.existsSync(configPath)) {
console.error(
'Configuration file',
'"' + args.config + '"',
'does not exist on disk'
)
process.exit(1)
}
Object.assign(opts, require(configPath))
console.log('Loaded config from', '"' + args.config + '"')
}

// ready
deobfuscator.deobfuscateSource(source, opts).then((source) => {
let ext = path.extname(abs)
let newFilename = opts.output
? opts.output
: abs.substring(0, abs.length - ext.length) + '.cleaned' + ext
fs.writeFile(newFilename, source, 'utf8', (err) => {
if (err) return console.error('Failed to write file', err.code)
})
})
})
})
}
).argv
Loading