Sparx Systems Forum

Enterprise Architect => Automation Interface, Add-Ins and Tools => Topic started by: Heidi V. on January 29, 2020, 08:33:54 pm

Title: JScripts not working anymore: how to use jscript9.dll instead of jscript.dll
Post by: Heidi V. on January 29, 2020, 08:33:54 pm
Because of the vulnerability described on https://www.stormshield.com/news/cve-2020-0674-internet-explorer-jscript-dll-scripting-engine-memory-corruption-vulnerability, "Internet Explorer jscript.dll Scripting Engine Memory Corruption Vulnerability" , my organisation has blocked the access to jscript.dll, and therefore, I cannot run our scripts, written in JScript, anymore.


When running a test script on the command line I get the following:

Code: [Select]
cscript testjs.js
Microsoft (R) Windows Script Host Version 5.812
Copyright (C) Microsoft Corporation. All rights reserved.

Input Error: There is no script engine for file extension ".js".

cscript //E:{16d51579-a30b-4c8b-a276-0ff4dc41e755} testjs.js
Microsoft (R) Windows Script Host Version 5.812
Copyright (C) Microsoft Corporation. All rights reserved.

This is a JScript test

(UUID found via https://twitter.com/ItsReallyNick/status/1075766158652043266 )
Title: Re: JScripts not working anymore: how to use jscript9.dll instead of jscript.dll
Post by: Eve on January 30, 2020, 11:33:38 am
I'd strongly encourage shifting to Javascript.

If you're using a recent version of EA, that will be a recent implementation of Javascript including handling of COM objects (which in some cases now work better than the JScript version)

It also means that debugging of your scripts won't be dependent on a discontinued product from microsoft.
Title: Re: JScripts not working anymore: how to use jscript9.dll instead of jscript.dll
Post by: Heidi V. on January 30, 2020, 07:46:52 pm
Thanks for your reply. We actually had planned already to change to Java instead (following the method described at https://github.com/Helmut-Ortmann/EnterpriseArchitect_hoTools/wiki/HybridScripting). However, I was hoping for a workaround for the jscript.dll in the meantime, as it will take a few weeks to migrate and we depend rather heavily on our scripts for the automation of our workflows.
Title: Re: JScripts not working anymore: how to use jscript9.dll instead of jscript.dll
Post by: Eve on February 03, 2020, 10:05:14 am
For most situations the built-in Javascript should be compatible with the Microsoft JScript. (The most notable exception being use of ActiveX objects)

Title: Re: JScripts not working anymore: how to use jscript9.dll instead of jscript.dll
Post by: Heidi V. on February 03, 2020, 10:50:05 pm
We use ActiveX objects quite a lot. I updated all the scripts to make them Javascripts instead of JScripts, and did a find replace: "new ActiveXObject" -> "new COMObject". Simple scripts work indeed, also when they include variables or functions from scripts located in EAScriptLib, such as JScript-Logging. But as soon as COMObjects are involved, I get errors.

E.g. the following (copied and modified from EAScriptLib.JScript-CSV)

Code: [Select]
var valueMap = new COMObject("Scripting.Dictionary");
valueMap.add("Header", "value");

gives:

Code: [Select]
valueMap.add is not a function
When trying to manipulate XML using new COMObject("Msxml2.DOMDocument.6.0"), I get a new dialog box saying:

Code: [Select]
SScripter.exe has stopped working

A problem caused the program to stop working correctly. Please close the program.

Note: There is a topic on StackOverflow on XML and EA/SpiderMonkey: https://stackoverflow.com/questions/44570789/handling-xml-dom-in-spidermonkey-javascript-1-8-function-appendchildchildnode
Title: Re: JScripts not working anymore: how to use jscript9.dll instead of jscript.dll
Post by: Eve on February 04, 2020, 10:07:05 am
What version of EA are you using? You'll need to use EA 15 to use an updated Javascript engine which improves handling of ActiveX objects.
Title: Re: JScripts not working anymore: how to use jscript9.dll instead of jscript.dll
Post by: Heidi V. on February 04, 2020, 06:59:25 pm
I have 15.0.1507 installed. According to https://www.sparxsystems.com/products/ea/15/history.html that includes:

Build 1500
Quote
Javascript engine updated

    Built-in javascript support updated to use the Mozilla Spidermonkey 63
    Provides new functions such as JSON parsing


Build 1505:
Quote
Javascript handling of optional parameters on ActiveX objects improved
Title: Re: JScripts not working anymore: how to use jscript9.dll instead of jscript.dll
Post by: Heidi V. on February 04, 2020, 07:15:30 pm
I tested again, now with 15.1.1526, I get the same errors.
Title: Re: JScripts not working anymore: how to use jscript9.dll instead of jscript.dll
Post by: Eve on February 05, 2020, 09:25:33 am
https://docs.microsoft.com/en-us/office/vba/Language/Reference/User-Interface-Help/dictionary-object (https://docs.microsoft.com/en-us/office/vba/Language/Reference/User-Interface-Help/dictionary-object)

Try
Code: [Select]
var valueMap = new COMObject("Scripting.Dictionary");
valueMap.Add("Header", "value");
Title: Re: JScripts not working anymore: how to use jscript9.dll instead of jscript.dll
Post by: Heidi V. on February 05, 2020, 07:09:40 pm
Ok, so the difference with JScript is that the methods are case-sensitive. So I corrected that in the scripts where needed. And made a copy of the scripts from EAScriptLib that we use to change "new ActiveXObject" to "new COMObject" and included those instead of the original scripts.

Then I run into another problem with Scripting.Dictionary:

Code: [Select]
function main() {
Repository.EnsureOutputVisible("Script");
var valueMap = new COMObject("Scripting.Dictionary");
valueMap.Add("Header", "value");
Session.Output(valueMap.Exists("Header"));
Session.Output(valueMap.Item("Header"));
}

main();

gives the following error:

Code: [Select]
Sandbox.My first Javascript error: Incorrect number of arguments
passed:1, expected:2, Line:8

Any ideas on how to solve this? According to https://docs.microsoft.com/en-us/office/vba/Language/Reference/User-Interface-Help/item-property-dictionary-object (the site referred to in the previous post), this is a property, not a method, and it takes one parameter.

Title: Re: JScripts not working anymore: how to use jscript9.dll instead of jscript.dll
Post by: Heidi V. on January 12, 2022, 01:20:04 am
Ok, so the difference with JScript is that the methods are case-sensitive. So I corrected that in the scripts where needed. And made a copy of the scripts from EAScriptLib that we use to change "new ActiveXObject" to "new COMObject" and included those instead of the original scripts.

Then I run into another problem with Scripting.Dictionary:

Code: [Select]
function main() {
Repository.EnsureOutputVisible("Script");
var valueMap = new COMObject("Scripting.Dictionary");
valueMap.Add("Header", "value");
Session.Output(valueMap.Exists("Header"));
Session.Output(valueMap.Item("Header"));
}

main();

gives the following error:

Code: [Select]
Sandbox.My first Javascript error: Incorrect number of arguments
passed:1, expected:2, Line:8

Any ideas on how to solve this? According to https://docs.microsoft.com/en-us/office/vba/Language/Reference/User-Interface-Help/item-property-dictionary-object (the site referred to in the previous post), this is a property, not a method, and it takes one parameter.

JavaScript has built-in support for Maps, see e.g. https://www.w3schools.com/js/js_maps.asp

So the code above should be updated as follows:

Code: [Select]
function main() {
Repository.EnsureOutputVisible("Script");
var valueMap = new Map();
valueMap.set("Header", "value");
Session.Output(valueMap.has("Header"));
Session.Output(valueMap.get("Header"));
}

main();

For working with XML (see the error described above), I'll use Java instead, using the Hybrid Scripting Approach, e.g. as described at https://github.com/Helmut-Ortmann/EnterpriseArchitect_hoTools/wiki/HybridScripting.
Title: Re: JScripts not working anymore: how to use jscript9.dll instead of jscript.dll
Post by: Sunshine on January 13, 2022, 05:31:57 pm
You may not have to use a hybrid approach as the EAScriptLib has JScript-XML in V15 which has been ported to JavaScript-XML in V16 Beta. So you could potentially use that.
Title: Re: JScripts not working anymore: how to use jscript9.dll instead of jscript.dll
Post by: Heidi V. on January 18, 2022, 02:56:02 am
You may not have to use a hybrid approach as the EAScriptLib has JScript-XML in V15 which has been ported to JavaScript-XML in V16 Beta. So you could potentially use that.

Thanks for the information. I haven't migrated to EA 16 yet. I would like to use the hybrid approach for several reasons, not only XML handling, so I'll probably stick to that anyway, but I'll have a look at the ported libraries.