Skip to content

Commit

Permalink
fix: bug#170 (#206)
Browse files Browse the repository at this point in the history
* Remove mockedFunction for Node.js test runner mock method

* use Set to keep track literals removing doubles

* add test ensuring doubles morse symbol does not trigger warnings
  • Loading branch information
jean-michelet authored Jan 16, 2024
1 parent 5273190 commit 0b807a0
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
6 changes: 3 additions & 3 deletions src/SourceFile.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ export class SourceFile {
computedMemberExpr: 0,
memberExpr: 0,
deepBinaryExpr: 0,
encodedArrayValue: 0,
morseLiteral: 0
encodedArrayValue: 0
};
morseLiterals = new Set();
identifiersName = [];

constructor(sourceCodeString) {
Expand Down Expand Up @@ -107,7 +107,7 @@ export class SourceFile {

// Searching for morse string like "--.- --.--."
if (Utils.isMorse(str)) {
this.counter.morseLiteral++;
this.morseLiterals.add(str);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/obfuscators/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export function isObfuscatedCode(analysis) {
else if (jjencode.verify(analysis)) {
encoderName = "jjencode";
}
else if (analysis.counter.morseLiteral >= 36) {
else if (analysis.morseLiterals.size >= 36) {
encoderName = "morse";
}
else {
Expand Down
7 changes: 7 additions & 0 deletions test/obfuscated.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,13 @@ test("should not detect 'morse' obfuscation", () => {
assert.strictEqual(warnings.length, 0);
});

test("should not detect 'morse' obfuscation for high number of doubles morse symbols", () => {
const morseSymbolDoublesString = `const a = ${"'.' + '..' +".repeat(37)} '.'`;
const { warnings } = runASTAnalysis(morseSymbolDoublesString);

assert.strictEqual(warnings.length, 0);
});

test("should detect 'jjencode' obfuscation", () => {
const trycatch = readFileSync(
new URL("jjencode.js", FIXTURE_URL),
Expand Down

0 comments on commit 0b807a0

Please sign in to comment.