This repository demonstrates a practical workflow for analyzing and simplifying a heavily obfuscated JavaScript file extracted from a real-world malware sample.
It documents the process of reducing multiple obfuscation layers through focused transformations, including string recovery, wrapper removal, syntax simplification, and AST-based cleanup. Rather than providing a universal deobfuscation framework, it aims to demonstrate how similar samples can be investigated and analyzed.
The current pipeline consists of the following transformation stages:
- Normalize hexadecimal numeric expressions.
replace_HexNumber.js
- Format the source code to make later analysis easier.
beautify.js
- Resolve numeric offset tables generated by the obfuscator.
replace_offset_table_k.jsreplace_offset_table_A.jsreplace_offset_table_M.js
- Remove generated wrapper functions around decoder logic.
unwrap_decoder_wrapper_L.jsunwrap_decoder_wrapper_o.jsunwrap_decoder_wrapper_I.jsunwrap_decoder_wrapper_H.js
- Recover the string lookup table used by the decoder.
resolve_string_table.js
- Remove unused parameters introduced by the obfuscator.
remove_unnecessary_parameters.js
- Decode obfuscated string values.
decode_string_array.js
- Reconstruct strings split across multiple expressions.
combine_chars.js
- Simplify unusual JavaScript syntax patterns.
replace_unorthodox_invocation.jsreplace_bracket_notation.js
- Perform AST-based inlining of dispatcher objects and aliases.
inline_dispatcher.jsinline_alias.js
- Remove variables and helper objects that are no longer referenced.
remove_unused_variables.js
- Generate the final readable output.
beautify_deobfuscated.js
Each transformation produces an intermediate output file:
step1.js
step2.js
step3.js
...
step19.jsThe final simplified source is produced after the last transformation step.
node ./pipeline.js- Obfuscated JavaScript
- Source normalization
- Resolve numeric obfuscation tables
- Remove decoder wrapper layers
- Recover hidden strings
- Simplify JavaScript syntax
- Perform AST-based cleanup
- Generate readable JavaScript code
The pipeline combines pattern-based rewriting and AST-based transformations to resolve obfuscation patterns, recover hidden values, simplify syntax, and remove generated code structures. Each transformation is kept small and focused, allowing intermediate results to be inspected throughout the analysis process.
This repository is not a general-purpose JavaScript deobfuscation framework.
The pipeline was developed around techniques observed in a specific malware sample. While the overall methodology may apply to similar obfuscation schemes, individual transformations may require modification when analyzing different samples.