Skip to content

Commit 8e3d90c

Browse files
committedJul 31, 2024
Added --limit-file-checks command line option.
1 parent eb89b4d commit 8e3d90c

File tree

5 files changed

+37
-3
lines changed

5 files changed

+37
-3
lines changed
 

‎analyze.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -911,7 +911,7 @@ var wscript_proxy = new Proxy({
911911
quit: function() {
912912
lib.logIOC("WScript", "Quit()", "The sample explicitly called WScript.Quit().");
913913
//console.trace()
914-
if (!argv["ignore-wscript-quit"]) {
914+
if ((!argv["ignore-wscript-quit"]) || lib.doWscriptQuit()) {
915915
process.exit(0);
916916
}
917917
},

‎emulator/FileSystemObject.js

+22-2
Original file line numberDiff line numberDiff line change
@@ -174,18 +174,38 @@ function FileSystemObject() {
174174
return true;
175175
};
176176
this.fileexists = (path) => {
177-
const value = !argv["no-file-exists"];
177+
var value = !argv["no-file-exists"];
178178
if (value) {
179179
lib.info(`Returning true for FileSystemObject.FileExists(${path}); use --no-file-exists if nothing happens`);
180180
}
181+
if (typeof(this._fileCheckCount) == "undefined") this._fileCheckCount = 0;
182+
this._fileCheckCount++;
183+
if (argv["limit-file-checks"] && (this._fileCheckCount > 10)) {
184+
// Flip whether the file exists or not to see if that
185+
// breaks a loop.
186+
value = !value;
187+
// Might break emulation based on WScript.quit(). Stop
188+
// ignoring WScript.quit().
189+
lib.doWscriptQuit(true);
190+
}
181191
lib.logIOC("FileExists", path, "The script checked to see if a file exists.");
182192
return value;
183193
};
184194
this.folderexists = (path) => {
185-
const value = !argv["no-folder-exists"];
195+
var value = !argv["no-folder-exists"];
186196
if (value) {
187197
lib.info(`Returning true for FileSystemObject.FolderExists(${path}); use --no-folder-exists if nothing happens`);
188198
}
199+
if (typeof(this._fileCheckCount) == "undefined") this._fileCheckCount = 0;
200+
this._fileCheckCount++;
201+
if (argv["limit-file-checks"] && (this._fileCheckCount > 500)) {
202+
// Flip whether the file exists or not to see if that
203+
// breaks a loop.
204+
value = !value;
205+
// Might break emulation based on WScript.quit(). Stop
206+
// ignoring WScript.quit().
207+
lib.doWscriptQuit(true);
208+
}
189209
lib.logIOC("FolderExists", path, "The script checked to see if a folder exists.");
190210
return value;
191211
};

‎flags.json

+5
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,11 @@
122122
"type": "Boolean",
123123
"description": "Return `false` for Scripting.FileSystemObject.FileExists(x)"
124124
},
125+
{
126+
"name": "limit-file-checks",
127+
"type": "Boolean",
128+
"description": "Switch default value for folder/file exists checks if many checks are performed (try to break infinite file check loops)."
129+
},
125130
{
126131
"name": "no-folder-exists",
127132
"type": "Boolean",

‎lib.js

+7
Original file line numberDiff line numberDiff line change
@@ -184,13 +184,20 @@ function noCasePropObj(obj)
184184
return newObj; // object with upper cased keys
185185
};
186186

187+
_doWscriptQuit = false;
188+
function doWscriptQuit(flag) {
189+
if (typeof(flag) != "undefined") _doWscriptQuit = flag;
190+
return _doWscriptQuit;
191+
}
192+
187193
module.exports = {
188194
argv,
189195
kill,
190196
getUUID,
191197
throttleFileWrites,
192198
throttleCommands,
193199
noCasePropObj,
200+
doWscriptQuit,
194201

195202
debug: log.bind(null, "debug"),
196203
verbose: log.bind(null, "verb"),

‎patch.js

+2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@ let __PATCH_CODE_ADDED__ = true;
33
window = this;
44

55
_globalTimeOffset = 0;
6+
_sleepCount = 0;
67
WScript.sleep = function(delay) {
78
_globalTimeOffset += delay;
9+
_sleepCount++;
810
}
911

1012
let fullYearGetter = Date.prototype.getFullYear;

0 commit comments

Comments
 (0)
Please sign in to comment.