WSH in BAT Clothing

hybrid.bat
Copy and paste the code from the text area below to hybrid.bat

The above program is both a batch file and a JavaScript WSH console file. The dual nature of the file is achieved via JavaScript block comments and the procedure by which the command interpreter searches for target labels in a batch file.

The first line of code is benign for a batch file; the REM command is a single line remark, so it ignores all text after it.

I have constructed this first line so that syntactically, it is also a valid JavaScript function call for a function called rem().

Immediately after the first left-parenthesis in the call, I began a block-comment. Batch commands follow on the next three lines, ending with a goto. These batch commands are ignored by the WSH JavaScript interpreter because they are contained in a set of JavaScript block comments.

When the command processor attempts to transfer control to a label via the GOTO verb, each line of the batch file is examined sequentially until a matching label is found. Any syntax errors encountered ( namely, JavaScript commands ) would be ignored.


Back to Jimbo's Demented Software

Back to Jimbo's Home Page