-
Notifications
You must be signed in to change notification settings - Fork 46
Overhaul and More Modularity #150
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
Conversation
…ss. Update the algorithm description for clarity and improve iteration tracking during safe and unsafe method applications.
…ty and functionality. Split the normalization process into separate functions for matching and transforming computed properties, improving code organization and readability. Update comments for better understanding of the transformation process.
…lization. Introduced separate functions for matching and transforming empty statements, enhancing clarity and maintainability. Updated comments to better explain the logic and conditions for preserving empty statements in control flow structures.
…te literal processing. Introduced separate functions for matching and transforming template literals, improving code organization and readability. Updated comments to clarify the transformation logic and conditions for processing literals. Expanded test cases to cover various scenarios, ensuring robust handling of template literals with different expressions.
…g. Introduced separate functions for matching and transforming sequence expressions in return statements and if conditions, enhancing code readability. Updated comments for clarity on the transformation process. Added new test cases to cover various scenarios, ensuring correct behavior for multiple expressions and edge cases.
…nality and modules
…ntainability. Each module now includes separate functions for matching and transforming nodes, improving code organization. Updated comments to better explain the transformation processes and added return statements to ensure proper handling of the Arborist object.
…ansformation processes into distinct functions. Updated documentation to clarify the purpose and algorithm of each function, improving code organization and readability. This refactor allows for better handling of switch statements with deterministic flow, converting them into sequential code blocks.
… Introduced separate functions for matching and transforming dead nodes, enhancing code organization and readability. Updated documentation to clarify the purpose and algorithm of each function, ensuring better understanding of the dead code removal logic.
…ination in block statements. Introduced separate functions for matching and transforming redundant blocks, enhancing code organization and readability. Updated documentation to clarify the purpose and algorithm of each function, ensuring better understanding of the block statement flattening process.
…sion handling. Introduced separate functions for matching and transforming logical expressions into explicit if statements, improving code organization and readability. Updated documentation to clarify the purpose and algorithm of each function, ensuring better understanding of the transformation process. Added comprehensive test cases to validate various logical expression scenarios.
Introduced a comprehensive guide for refactoring REstringer JavaScript deobfuscator modules. The document outlines overall approach, code structure requirements, performance requirements, documentation standards, testing requirements, and a checklist for each module. It emphasizes best practices for separating matching and transformation logic, optimizing performance, and ensuring thorough documentation and testing.
…/transform pattern - Split into separate match and transform functions following established pattern - Extract static FUNCTION_EXPRESSION_TYPES array to avoid recreation overhead - Remove spread operators from typeMap access for better performance - Add comprehensive JSDoc documentation for all functions - Add inline comments explaining algorithm steps and edge cases - Enhance test coverage from 2 to 9 cases (TP and TN scenarios) - Add isUnwrappableExpression helper to reduce code duplication - Maintain full backward compatibility and functionality
…ttern Split into match/transform functions, optimize performance, add documentation and tests
… pattern Split into match/transform functions, extract static arrays, optimize performance, add comprehensive documentation and tests
…form pattern Split into match/transform functions, fix condition ordering, add safety checks, optimize performance, add comprehensive documentation and tests
…rm pattern Split into match/transform functions, add helper function, optimize condition ordering, add safety checks, optimize performance, add comprehensive documentation and tests
…on match/transform pattern Split into match/transform functions, extract static regex, optimize performance, add comprehensive documentation and tests
… pattern Split into match/transform functions, extract helper functions, optimize performance, add comprehensive documentation and tests
…performance optimization, enhanced test coverage - Split into match/transform functions following established pattern - Optimized performance with helper functions and eliminated spread operators - Added comprehensive JSDoc documentation and algorithm explanations - Enhanced test coverage from 2 to 12 test cases with edge cases - Improved safety checks and array building efficiency
… unary expression support, enhanced truthiness handling - Split into match/transform functions following established pattern - Added support for UnaryExpression nodes (e.g., -1, +5, !true) - Enhanced JavaScript truthiness evaluation with proper edge case handling - Optimized performance with helper functions and eliminated spread operators - Added comprehensive JSDoc documentation and algorithm explanations - Enhanced test coverage from 1 to 14 test cases covering all literal types and edge cases - Improved safety checks and unary operator evaluation
…sform pattern - Extract helper functions buildArgumentsString and generateFunctionExpression - Add comprehensive JSDoc documentation and inline comments - Optimize performance with direct typeMap access - Enhance test coverage with 13 test cases for edge cases - Maintain original behavior for any .constructor call with literal arguments - Add error handling for invalid function syntax
…atch/transform pattern - Separate matching and transformation logic into distinct functions - Add comprehensive validation with bounds checking and type validation - Extract MIN_ARRAY_LENGTH constant and optimize performance - Add JSDoc documentation explaining array resolution algorithm - Enhance test coverage with 6 additional edge cases - Use traditional for loops and direct typeMap access for performance
…tch/transform pattern - Separate matching and transformation logic into distinct functions - Add conservative computed property access validation (literals only) - Enhance modification detection for assignments and update expressions - Extract helper functions for property name resolution and reference checking - Add comprehensive JSDoc documentation explaining safety constraints - Optimize performance with traditional for loops and direct typeMap access - Enhance test coverage with 8 additional test cases for edge scenarios
…oxy function resolution - Introduce separate functions for matching and transforming proxy calls - Enhance validation to ensure proxy functions meet specific criteria - Add comprehensive JSDoc documentation detailing function behavior and safety constraints - Expand test coverage with multiple test cases for various proxy scenarios and edge cases - Ensure that only valid proxy functions are transformed, maintaining original behavior for non-proxy functions
…with comprehensive safety checks - Split logic into match and transform functions following established pattern - Extract SUPPORTED_REFERENCE_TYPES array and LOOP_STATEMENT_REGEX for performance - Add helper functions for proxy pattern validation and replacement safety - Enhance loop detection to include while/do-while statements - Remove overly restrictive safety check that prevented valid transformations - Add comprehensive JSDoc documentation and inline comments - Expand test coverage with positive, negative, and edge cases - Use single optional chaining checks for cleaner code
…r proxy variable handling - Introduce separate functions for matching and transforming proxy variable declarations - Enhance validation to ensure only valid proxy patterns are processed - Add comprehensive JSDoc documentation detailing function behavior and safety constraints - Expand test coverage with multiple test cases for various proxy scenarios, including edge cases - Ensure that transformations maintain original behavior for non-proxy variables and handle unused declarations
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This pull request refactors utility modules to improve code organization, modularity, and testability. The primary focus is separating matching and transformation logic in AST normalization modules, along with renaming files and constants for consistency.
Summary:
- Refactors argument parsing to use Commander.js library
- Renames
obfuscatorIo.jstoobfuscator.io.jsfor naming consistency - Separates match/transform logic in processor modules for better modularity
- Updates constant naming from camelCase to UPPER_SNAKE_CASE
- Adds comprehensive test coverage across multiple modules
- Improves documentation with JSDoc comments
Key Changes:
- Argument parsing now uses Commander.js with better validation and error handling
- Processors refactored to export match/transform functions separately
- Import statements updated to reflect BAD_VALUE constant rename
- Test files expanded with extensive coverage for edge cases
Reviewed changes
Copilot reviewed 84 out of 89 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| tests/utils.test.js | Removed argsAreValid tests, updated parseArgs test expectations |
| tests/samples.test.js | Updated filename reference from obfuscatorIo.js to obfuscator.io.js |
| tests/resources/obfuscator.io.js* | Added test resource files for obfuscator.io pattern testing |
| tests/processors.test.js | Updated import path and added comprehensive test cases |
| tests/modules.utils.test.js | Updated imports, constant names (badValue → BAD_VALUE), added extensive test coverage |
| tests/modules.unsafe.test.js | Updated imports, constant names, added comprehensive test cases |
| tests/modules.safe.test.js | Updated imports, added extensive test coverage for safe modules |
| src/utils/parseArgs.js | Complete refactor using Commander.js with improved validation |
| src/restringer.js | Fixed typo "asyc" → "async", updated constant references |
| src/processors/obfuscatorIo.js | Deleted (renamed to obfuscator.io.js) |
| src/processors/obfuscator.io.js | New file with refactored match/transform pattern |
| src/processors/index.js | Updated import path |
| src/processors/functionToArray.js | Enhanced documentation |
| src/processors/caesarp.js | Updated regex constant names to UPPER_SNAKE_CASE |
| src/processors/augmentedArray.js | Refactored with match/transform separation |
| src/processors/README.md | Comprehensive documentation expansion |
| src/modules/utils/safeImplementations.js | Enhanced documentation |
| src/modules/utils/safe-btoa.js | Improved JSDoc comments |
| src/modules/utils/safe-atob.js | Improved JSDoc comments |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…iciency - Simplify the normalization logic by processing MemberExpression, MethodDefinition, and Property nodes separately. - Add a missing use case where object keys that are strings can be stripped of their quotes.
- Change parameter documentation to indicate optional filters using square brackets for clarity. - Simplify the initialization of relevant nodes in several functions by removing unnecessary concatenation.
- Upgrade 'commander' to version 14.0.2 for improved functionality. - Update 'isolated-vm' to version 6.0.2 and 'obfuscation-detector' to version 2.0.6 for enhanced performance and security. - Revise development dependencies: bump '@babel/eslint-parser' to 7.28.5, '@babel/plugin-syntax-import-assertions' to 7.27.1, 'eslint' to 9.39.1, and 'globals' to 16.5.0 for better linting support.
…validation - Add support for `null` as a context argument. - Fix issue with property name extraction failure
- Rename variables for clarity: `consequentEmpty` to `isConsequentEmpty` and `alternateEmpty` to `isAlternateEmpty`. - Enhance conditional checks to improve code understanding and maintainability.
…nment.js - Improve logic to prevent replacing references if any modifying references are found. - Add additional check to ensure references belong to the same scope as the assignment. - Simplify condition for adding candidates based on replaceable references.
…rnate is not null before removal to avoid unwanted recursion
…nedAtDeclaration.js - Update conditional checks to ensure references have a length before processing. - Add scope validation to ensure references are replaced only if they match the assignment's scope.
… results - Add a test case for handling `null` as a context argument in function calls. - Update test case to use `undefined` instead of `null` for context in specific scenarios. - Adjust expected result for a test case to match the original code structure.
…on and package-lock.json
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
Copilot reviewed 88 out of 93 changed files in this pull request and generated 2 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| return opts; | ||
| } catch (error) { | ||
| // Provide meaningful error context instead of silent failure | ||
| console.warn(`Warning: Error parsing arguments, using defaults. Error: ${error.message}`); |
Copilot
AI
Nov 25, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The error message uses console.warn which may not be appropriate for a library. Consider using a proper logger or throwing an error instead of silently falling back to defaults. This could mask critical configuration issues from users.
| 'floor', | ||
| 'left' | ||
| ];;) | ||
| for (var r = t();;) |
Copilot
AI
Nov 25, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The initial value of r is unused, since it is always overwritten.
This pull request refactors several utility modules in the codebase to separate matching and transformation logic for AST node normalization, improving modularity and testability. It also adds new scripts for targeted test runs. The most significant changes are grouped below.
Refactoring and modularization of normalization utilities:
src/modules/safe/normalizeComputed.js,src/modules/safe/normalizeEmptyStatements.js, andsrc/modules/safe/parseTemplateLiteralsIntoStringLiterals.jsinto three distinct parts: a matcher to find relevant nodes, a transformer to apply changes, and a default function that applies the transformation to all matches. This makes the code more modular and easier to test. [1] [2] [3] [4] Fd318880L1, [5]Configuration and constants improvements:
src/modules/config.jsto export constants directly, renamed variables for clarity, and expanded lists of properties and identifiers to skip during deobfuscation.Testing improvements:
package.jsonfor running quick targeted tests and watch mode, improving developer workflow for running subsets of tests.These changes collectively improve maintainability, clarity, and project alignment with its new organizational context.