Skip to content

Commit

Permalink
Merge branch 'master' of github.com:jean-michelet/js-x-ray into bug#168
Browse files Browse the repository at this point in the history
  • Loading branch information
jean-michelet committed Jan 16, 2024
2 parents ee58acc + 331fc29 commit 405028f
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 405028f

Please sign in to comment.