@@ -11,6 +11,36 @@ import * as trojan from "./obfuscators/trojan-source.js";
1111
1212// CONSTANTS
1313const kMaximumEncodedLiterals = 10 ;
14+ const kIdentifierOrMemberExps = [
15+ "crypto.createHash" ,
16+ "crypto.pbkdf2Sync" ,
17+ "crypto.scryptSync" ,
18+ "crypto.generateKeyPairSync" ,
19+ "fs.readFileSync" ,
20+ "fs.writeFileSync" ,
21+ "fs.appendFileSync" ,
22+ "fs.readSync" ,
23+ "fs.writeSync" ,
24+ "fs.readdirSync" ,
25+ "fs.statSync" ,
26+ "fs.mkdirSync" ,
27+ "fs.renameSync" ,
28+ "fs.unlinkSync" ,
29+ "fs.symlinkSync" ,
30+ "fs.openSync" ,
31+ "fs.fstatSync" ,
32+ "fs.linkSync" ,
33+ "fs.realpathSync" ,
34+ "child_process.execSync" ,
35+ "child_process.spawnSync" ,
36+ "child_process.execFileSync" ,
37+ "zlib.deflateSync" ,
38+ "zlib.inflateSync" ,
39+ "zlib.gzipSync" ,
40+ "zlib.gunzipSync" ,
41+ "zlib.brotliCompressSync" ,
42+ "zlib.brotliDecompressSync"
43+ ] ;
1444
1545export class SourceFile {
1646 inTryStatement = false ;
@@ -24,15 +54,30 @@ export class SourceFile {
2454
2555 constructor ( sourceCodeString , probesOptions = { } ) {
2656 this . tracer = new VariableTracer ( )
27- . enableDefaultTracing ( )
28- . trace ( "crypto.createHash" , {
29- followConsecutiveAssignment : true , moduleName : "crypto"
30- } ) ;
57+ . enableDefaultTracing ( ) ;
58+
59+ kIdentifierOrMemberExps . forEach ( ( identifierOrMemberExp ) => this . tracer . trace ( identifierOrMemberExp , {
60+ followConsecutiveAssignment : true ,
61+ moduleName : identifierOrMemberExp . split ( "." ) [ 0 ]
62+ } ) ) ;
3163
3264 let probes = ProbeRunner . Defaults ;
3365 if ( Array . isArray ( probesOptions . customProbes ) && probesOptions . customProbes . length > 0 ) {
3466 probes = probesOptions . skipDefaultProbes === true ? probesOptions . customProbes : [ ...probes , ...probesOptions . customProbes ] ;
3567 }
68+
69+ if ( typeof probesOptions . optionalWarnings === "boolean" ) {
70+ if ( probesOptions . optionalWarnings ) {
71+ probes = [ ...probes , ...Object . values ( ProbeRunner . Optionals ) ] ;
72+ }
73+ }
74+ else {
75+ const optionalProbes = Array . from ( probesOptions . optionalWarnings ?? [ ] )
76+ . flatMap ( ( warning ) => ProbeRunner . Optionals [ warning ] ?? [ ] ) ;
77+
78+ probes = [ ...probes , ...optionalProbes ] ;
79+ }
80+
3681 this . probesRunner = new ProbeRunner ( this , probes ) ;
3782
3883 if ( trojan . verify ( sourceCodeString ) ) {
0 commit comments