MichaelXF / js-confuser

JS-Confuser is a JavaScript obfuscation tool to make your programs *impossible* to read.
https://js-confuser.com
MIT License
204 stars 32 forks source link

Add progress bar #97

Closed fuzzbuck closed 2 months ago

fuzzbuck commented 1 year ago

Add 'progress' to Options, which displays a visual progress bar of the obfuscation process in STDOUT image

Example:

JsConfuser.obfuscate(contents, {
    target: "browser",
    progress: true,
    preset: "high"
})
MichaelXF commented 1 year ago

This could be implemented using the JsConfuser.debugObfuscation, the same method the js-confuser.com uses to display a progress bar. This way you can avoid the extra dependency. Here's an example:

var outputObject = await JsConfuser.debugObfuscation(
  CODE,
  {
    target: "node",
    preset: "high"
  },
  (transformName, index, totalTransforms) => {
    console.log(transformName + " is done!", index, "/", totalTransforms);
  },
  require("perf_hooks").performance
);

var output: string = outputObject.obfuscated; // The obfuscated code

console.log(outputObject.transformationTimes); // Object of transformation times

/*
Preparation is done! 1 / 21
ObjectExtraction is done! 2 / 21
Flatten is done! 3 / 21
Dispatcher is done! 4 / 21
DeadCode is done! 5 / 21
Calculator is done! 6 / 21
ControlFlowFlattening is done! 7 / 21
GlobalConcealing is done! 8 / 21
OpaquePredicates is done! 9 / 21
StringSplitting is done! 10 / 21
StringConcealing is done! 11 / 21
StringCompression is done! 12 / 21
Stack is done! 13 / 21
DuplicateLiteralsRemoval is done! 14 / 21
Shuffle is done! 15 / 21
MovedDeclarations is done! 16 / 21
RenameLabels is done! 17 / 21
Minify is done! 18 / 21
RenameVariables is done! 19 / 21
AntiTooling is done! 20 / 21
Finalizer is done! 21 / 21
[Object: null prototype] {
  Preparation: 1.0094190000090748,
  ObjectExtraction: 0.9722220000112429,
  Flatten: 2.585480000008829,
  Dispatcher: 6.410395000013523,
  DeadCode: 7.101765999919735,
  Calculator: 4.634364000055939,
  ControlFlowFlattening: 65.66039700002875,
  GlobalConcealing: 40.353111999924295,
  OpaquePredicates: 8.849830999970436,
  StringSplitting: 6.999255000031553,
  StringConcealing: 19.94320500001777,
  StringCompression: 14.935447999974713,
  Stack: 116.39931500004604,
  DuplicateLiteralsRemoval: 37.37533099995926,
  Shuffle: 12.675785999977961,
  MovedDeclarations: 12.70788200001698,
  RenameLabels: 32.359866000013426,
  Minify: 70.36959400004707,
  RenameVariables: 216.08912899997085,
  AntiTooling: 13.917390999966301,
  Finalizer: 22.79970700002741
}
*/
fuzzbuck commented 1 year ago

This could be implemented using the JsConfuser.debugObfuscation, the same method the js-confuser.com uses to display a progress bar. This way you can avoid the extra dependency. Here's an example:

var outputObject = await JsConfuser.debugObfuscation(
  CODE,
  {
    target: "node",
    preset: "high"
  },
  (transformName, index, totalTransforms) => {
    console.log(transformName + " is done!", index, "/", totalTransforms);
  },
  require("perf_hooks").performance
);

var output: string = outputObject.obfuscated; // The obfuscated code

console.log(outputObject.transformationTimes); // Object of transformation times

/*
Preparation is done! 1 / 21
ObjectExtraction is done! 2 / 21
Flatten is done! 3 / 21
Dispatcher is done! 4 / 21
DeadCode is done! 5 / 21
Calculator is done! 6 / 21
ControlFlowFlattening is done! 7 / 21
GlobalConcealing is done! 8 / 21
OpaquePredicates is done! 9 / 21
StringSplitting is done! 10 / 21
StringConcealing is done! 11 / 21
StringCompression is done! 12 / 21
Stack is done! 13 / 21
DuplicateLiteralsRemoval is done! 14 / 21
Shuffle is done! 15 / 21
MovedDeclarations is done! 16 / 21
RenameLabels is done! 17 / 21
Minify is done! 18 / 21
RenameVariables is done! 19 / 21
AntiTooling is done! 20 / 21
Finalizer is done! 21 / 21
[Object: null prototype] {
  Preparation: 1.0094190000090748,
  ObjectExtraction: 0.9722220000112429,
  Flatten: 2.585480000008829,
  Dispatcher: 6.410395000013523,
  DeadCode: 7.101765999919735,
  Calculator: 4.634364000055939,
  ControlFlowFlattening: 65.66039700002875,
  GlobalConcealing: 40.353111999924295,
  OpaquePredicates: 8.849830999970436,
  StringSplitting: 6.999255000031553,
  StringConcealing: 19.94320500001777,
  StringCompression: 14.935447999974713,
  Stack: 116.39931500004604,
  DuplicateLiteralsRemoval: 37.37533099995926,
  Shuffle: 12.675785999977961,
  MovedDeclarations: 12.70788200001698,
  RenameLabels: 32.359866000013426,
  Minify: 70.36959400004707,
  RenameVariables: 216.08912899997085,
  AntiTooling: 13.917390999966301,
  Finalizer: 22.79970700002741
}
*/

cli-progress is a very small library and providers helpers for repeatedly updating stdout, I think there is no need to reinvent the wheel here

MichaelXF commented 2 months ago

This is not planned. You must interface with the custom callback option and feed that into the progress bar library. This is because JS-Confuser.com cannot use system packages.