Book a Demo

Author Topic: JScripts not working anymore: how to use jscript9.dll instead of jscript.dll  (Read 10328 times)

Heidi V.

  • EA User
  • **
  • Posts: 23
  • Karma: +0/-0
    • View Profile
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.

  • Is it a solution to make Enterprise Architect use jscript9.dll, or requires Enterprise Architect the old engine?
  • If it is a solution to make Enterprise Architect use jscript9.dll, how to do that?

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 )

Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 8090
  • Karma: +118/-20
    • View Profile
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.

Heidi V.

  • EA User
  • **
  • Posts: 23
  • Karma: +0/-0
    • View Profile
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.

Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 8090
  • Karma: +118/-20
    • View Profile
For most situations the built-in Javascript should be compatible with the Microsoft JScript. (The most notable exception being use of ActiveX objects)


Heidi V.

  • EA User
  • **
  • Posts: 23
  • Karma: +0/-0
    • View Profile
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
« Last Edit: February 03, 2020, 10:53:12 pm by Heidi V. »

Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 8090
  • Karma: +118/-20
    • View Profile
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.

Heidi V.

  • EA User
  • **
  • Posts: 23
  • Karma: +0/-0
    • View Profile
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

Heidi V.

  • EA User
  • **
  • Posts: 23
  • Karma: +0/-0
    • View Profile
I tested again, now with 15.1.1526, I get the same errors.

Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 8090
  • Karma: +118/-20
    • View Profile
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");

Heidi V.

  • EA User
  • **
  • Posts: 23
  • Karma: +0/-0
    • View Profile
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.


Heidi V.

  • EA User
  • **
  • Posts: 23
  • Karma: +0/-0
    • View Profile
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.

Sunshine

  • EA Practitioner
  • ***
  • Posts: 1346
  • Karma: +121/-10
  • Its the results that count
    • View Profile
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.
Happy to help
:)

Heidi V.

  • EA User
  • **
  • Posts: 23
  • Karma: +0/-0
    • View Profile
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.