IE9 Javascript 引擎(代号“Chakra”)的 ProgId 或 CLSID 是什么?

发布于 2024-12-01 05:09:23 字数 1120 浏览 1 评论 0原文

使用 .NET,我可以编写一个应用程序,该应用程序托管符合 Microsoft 的 IActiveScript 约定的脚本引擎。这包括 Microsoft 的 JScript 和 VBScript,还有 PerlScript、RubyScript 和 我不知道第三方还有什么- 各方

在代码中执行此操作的方法如下:

    Type engine = Type.GetTypeFromProgID(progId, true);
    _engine = Activator.CreateInstance(engine) as IActiveScript;

其中 progId 可以采用 Javascript、JScript、ECMAScript、VBScript 等值。您可以在运行 cscript.exe 时执行类似的操作,使用 //E 选项在命令行上指定 progId。例如,此命令:

cscript.exe  <file>  //e:JScript

..将通过 JScript 引擎运行指定的文件,无论其扩展名如何。

在我的机器上,如果我查看 HKLM\SW\Classes\ ,三个 progIds {Javascript, JScript, ECMAScript} 都指向同一个 CLSID,我猜这是 JScript 5.8 脚本引擎: < code>{f414c260-6ac0-11cf-b6d1-00aa00bbbb58}

是否有我可以指定的 ProgId 或 CLSID运行 IE9 的 Javascript 引擎,又名“Chakra”?

IE9 的引擎仍然由 IActiveScript 加载吗?
Microsoft 文档表明确实如此,但不指定 ProgId 或 CLSID。

Using .NET, I can write an app that hosts a scripting engine that complies with Microsoft's IActiveScript conventions. This includes JScript and VBScript from Microsoft, and also PerlScript, RubyScript and I don't know what else from third-parties.

The way to do it in code is something like this:

    Type engine = Type.GetTypeFromProgID(progId, true);
    _engine = Activator.CreateInstance(engine) as IActiveScript;

where the progId can take the value Javascript, JScript, ECMAScript, VBScript, and others. You can do something similar when running cscript.exe, specifying the progId on the command line with the //E option. For example, this command:

cscript.exe  <file>  //e:JScript

..will run the specified file, regardless of its extension, through the JScript engine.

On my machine, if I look in HKLM\SW\Classes\ , the three progIds {Javascript, JScript, ECMAScript} all point to the same CLSID, which I guess is the JScript 5.8 script engine: {f414c260-6ac0-11cf-b6d1-00aa00bbbb58}

Is there a ProgId or CLSID I can specify to run IE9's Javascript engine, aka "Chakra"?

Does IE9's engine still get loaded by IActiveScript?
Microsoft's documentation suggests that it does, but does not specify a ProgId or CLSID.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

鹤仙姿 2024-12-08 05:09:23

与 IE9 一起安装的 Chakra Javascript 引擎的 CLSID 是
{16d51579-a30b-4c8b-a276-0ff4dc41e755}

InProcServer32 是 %windir%\System32\jscript9.dll

我找不到 ProgId。这有点奇怪;通常成对的 ProgId 和 CLSID 条目相互引用。对于给定的 COM 对象,注册表中的 ProgId 项有一个名为 CLSID 的子项,并且 CLSID 注册表项有一个名为 ProgId 的子项,它们相互引用。但 IE9 CLSID 的 ProgId 子键是“JScript”,这当然是指 v5.8 Jscript CLSID。不确定这是微软的错误,还是故意的混淆,因为他们不希望任何人在 IE9 之外使用 Chakra 引擎。对我来说看起来是有目的的。


我通过在注册表中搜索 jscript9.dll 了解到了 CLSID。


如果您有托管脚本引擎的 .NET 代码,则可以直接使用 CLSID 实例化 IE9 javascript 引擎(“Chakra”)的 IActiveScript 对象。代码需要如下所示:

private const string clsIdPattern =
    @"^(?<curly>\{)?[a-zA-Z0-9]{8}(?:-[a-zA-Z0-9]{4}){3}-[a-zA-Z0-9]{12}(?(curly)\})$";

public ScriptEngine(string language)
{
    if (language == null)
        throw new ArgumentNullException("language");

    Type engineType = null;

    if (Regex.IsMatch(language, clsIdPattern))
    {
        // it's a CLSID
        var guid = new System.Guid(language);
        engineType = Type.GetTypeFromCLSID(guid, true);
    }
    else
    {
        // assume vanilla progId
        engineType = Type.GetTypeFromProgID(language, true);
    }

    var engine = Activator.CreateInstance(engineType) as IActiveScript;

在上面,clsIdPattern 是一个与熟悉的 GUID 格式匹配的正则表达式,无论是否带有花括号。

根据上面的代码,您可以传递“jscript”、“Javascript”或“ECMAScript”并获取 v5.8 JScript 引擎。或者您可以传递“{16d51579-a30b-4c8b-a276-0ff4dc41e755}”并获取 IE9 Javascript 引擎。显然,您需要安装 IE9 才能正常工作。

我刚刚尝试过这个,它适用于简单的情况。我很快就会再玩这个。


如果您想从 WSH 运行 Chakra,例如从 cscript.exe,那么我认为您将需要一个 ProgId。
如果我在注册表中创建“Chakra”作为 Progid,引用正确的 CLSID,我可以通过 IE9 的引擎运行 JS 文件,如下所示:

cscript.exe  module.js  //E:Chakra 

例如,插入新的“Chakra”ProgId 后,给出如下脚本:

WScript.Echo( ScriptEngineMajorVersion() + "." +
              ScriptEngineMinorVersion() + "." +
              ScriptEngineBuildVersion());

..输出如下:

C:\dev\js>Version.js
5.8.16982

C:\dev\js>cscript.exe Version.js  //E:Chakra
9.0.16434

这是在 Javascript 中进行 AES 加密测试的结果,将 Chakra 与 JScript 5.8 进行比较:

C:\dev\js\SlowAES>cscript.exe test.aes.js
AES encryption in Javascript.
password  : Albatros1
salt      : saltines (73616c74696e6573)
iterations: 1000
key       : 172,52,20,51,98,71,49,195,14,31,141,51,129,8,94,66
iv        : 212,27,28,156,83,245,0,35,176,157,45,141,209,143,158,248
plaintext : Hello, /r/javascript.
ciphertext: fdebac9f1ed1a13bac58f3cc6558e8b0367a94245dbbfe53cacc4979799fc182
decrypted : Hello, /r/javascript.
elapsed   : 5011ms

C:\dev\js\SlowAES>cscript.exe test.aes.js //E:Chakra
AES encryption in Javascript.
password  : Albatros1
salt      : saltines (73616c74696e6573)
iterations: 1000
key       : 172,52,20,51,98,71,49,195,14,31,141,51,129,8,94,66
iv        : 212,27,28,156,83,245,0,35,176,157,45,141,209,143,158,248
plaintext : Hello, /r/javascript.
ciphertext: fdebac9f1ed1a13bac58f3cc6558e8b0367a94245dbbfe53cacc4979799fc182
decrypted : Hello, /r/javascript.
elapsed   : 2593ms

为了在注册表中设置 ProgId,我使用了以下命令

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\CLSID\{16d51579-a30b-4c8b-a276-0ff4dc41e755}\ProgID]
@="Chakra"

[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Wow6432Node\CLSID\{16d51579-a30b-4c8b-a276-0ff4dc41e755}\ProgID]
@="Chakra"

[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Chakra]
@="JScript Language"

[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Chakra\CLSID]
@="{16d51579-a30b-4c8b-a276-0ff4dc41e755}"

[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Chakra\OLEScript]

:取消暴露 Chakra,或恢复注册表,我这样做了:

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\CLSID\{16d51579-a30b-4c8b-a276-0ff4dc41e755}\ProgID]
@="JScript"

[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Wow6432Node\CLSID\{16d51579-a30b-4c8b-a276-0ff4dc41e755}\ProgID]
@="JScript"

[-HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Chakra]

此注册表脚本适用于 x64 Windows;如果您没有 x64,那么您需要删除 WOW6432Node 行。

The CLSID for the Chakra Javascript engine installed with IE9 is
{16d51579-a30b-4c8b-a276-0ff4dc41e755}.

The InProcServer32 is %windir%\System32\jscript9.dll .

There is no ProgId that I could find. That's a bit odd; normally paired ProgId and CLSID entries refer to each other. For a given COM object, the ProgId key in the registry has a subkey called CLSID, and the CLSID registry key has a subkey called ProgId, and they refer to each other. But the ProgId subkey for the IE9 CLSID is "JScript", which of course refers to the v5.8 Jscript CLSID. Not sure if this was a mistake by Microsoft, or a purposeful bit of obfuscation, because they don't want anyone using the Chakra engine outside of IE9. Looks purposeful to me.


I learned of the CLSID by just searching the registry for jscript9.dll .


If you have .NET code that hosts scripting engines, you can instantiate the IActiveScript object for the IE9 javascript engine ("Chakra") by using the CLSID directly. The code needs to be something like this:

private const string clsIdPattern =
    @"^(?<curly>\{)?[a-zA-Z0-9]{8}(?:-[a-zA-Z0-9]{4}){3}-[a-zA-Z0-9]{12}(?(curly)\})$";

public ScriptEngine(string language)
{
    if (language == null)
        throw new ArgumentNullException("language");

    Type engineType = null;

    if (Regex.IsMatch(language, clsIdPattern))
    {
        // it's a CLSID
        var guid = new System.Guid(language);
        engineType = Type.GetTypeFromCLSID(guid, true);
    }
    else
    {
        // assume vanilla progId
        engineType = Type.GetTypeFromProgID(language, true);
    }

    var engine = Activator.CreateInstance(engineType) as IActiveScript;

In the above, clsIdPattern is a regular expression that matches the familiar GUID format, either with or without surrounding curlies.

Given the code above, you could pass "jscript", "Javascript", or "ECMAScript" and get the v5.8 JScript engine. Or you could pass "{16d51579-a30b-4c8b-a276-0ff4dc41e755}" and get the IE9 Javascript engine. Obviously you need to have IE9 installed in order for this to work.

I just tried this and it works for simple cases. I'll be playing with that some more, real soon.


If you want to run Chakra from WSH, like from cscript.exe, then you will need a ProgId, I think.
If I create "Chakra" as a Progid in the registry, referring to the correct CLSID, I can run JS files through IE9's engine like this:

cscript.exe  module.js  //E:Chakra 

For example, after inserting the new "Chakra" ProgId, given a script like this:

WScript.Echo( ScriptEngineMajorVersion() + "." +
              ScriptEngineMinorVersion() + "." +
              ScriptEngineBuildVersion());

...the output is like this:

C:\dev\js>Version.js
5.8.16982

C:\dev\js>cscript.exe Version.js  //E:Chakra
9.0.16434

And here's the result of a test of AES encryption in Javascript, comparing Chakra with JScript 5.8:

C:\dev\js\SlowAES>cscript.exe test.aes.js
AES encryption in Javascript.
password  : Albatros1
salt      : saltines (73616c74696e6573)
iterations: 1000
key       : 172,52,20,51,98,71,49,195,14,31,141,51,129,8,94,66
iv        : 212,27,28,156,83,245,0,35,176,157,45,141,209,143,158,248
plaintext : Hello, /r/javascript.
ciphertext: fdebac9f1ed1a13bac58f3cc6558e8b0367a94245dbbfe53cacc4979799fc182
decrypted : Hello, /r/javascript.
elapsed   : 5011ms

C:\dev\js\SlowAES>cscript.exe test.aes.js //E:Chakra
AES encryption in Javascript.
password  : Albatros1
salt      : saltines (73616c74696e6573)
iterations: 1000
key       : 172,52,20,51,98,71,49,195,14,31,141,51,129,8,94,66
iv        : 212,27,28,156,83,245,0,35,176,157,45,141,209,143,158,248
plaintext : Hello, /r/javascript.
ciphertext: fdebac9f1ed1a13bac58f3cc6558e8b0367a94245dbbfe53cacc4979799fc182
decrypted : Hello, /r/javascript.
elapsed   : 2593ms

To set the ProgId in my registry, I used this:

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\CLSID\{16d51579-a30b-4c8b-a276-0ff4dc41e755}\ProgID]
@="Chakra"

[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Wow6432Node\CLSID\{16d51579-a30b-4c8b-a276-0ff4dc41e755}\ProgID]
@="Chakra"

[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Chakra]
@="JScript Language"

[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Chakra\CLSID]
@="{16d51579-a30b-4c8b-a276-0ff4dc41e755}"

[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Chakra\OLEScript]

and to unexpose Chakra, or revert the registry, I did this:

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\CLSID\{16d51579-a30b-4c8b-a276-0ff4dc41e755}\ProgID]
@="JScript"

[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Wow6432Node\CLSID\{16d51579-a30b-4c8b-a276-0ff4dc41e755}\ProgID]
@="JScript"

[-HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Chakra]

This registry script worked with x64 Windows; if you don't have x64, then you'll need to remove the WOW6432Node lines.

短暂陪伴 2024-12-08 05:09:23

可能有点晚了,但是:

您也可以通过 //E 参数简单地指定要使用的引擎的 CLSID:

cscript.exe  <file>  //E:{16d51579-a30b-4c8b-a276-0ff4dc41e755}

编辑: 根据 Cheeso 的回答,我发现添加就足够了以下注册表项能够在不指定 CLSID 的情况下使用 jscript9。我在这里使用键名JScript9,如果您愿意,可以将其替换为Chakra。键名是您在 //E: then:

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\JScript9]
@="JScript9 Language"

[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\JScript9\CLSID]
@="{16d51579-a30b-4c8b-a276-0ff4dc41e755}"

[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\JScript9\OLEScript]

And then: 之后指定的名称

cscript.exe  <file>  //E:JScript9

Might be a bit late, but:

You can also simply specify the CLSID of the engine you want to use via the //E argument:

cscript.exe  <file>  //E:{16d51579-a30b-4c8b-a276-0ff4dc41e755}

Edit: According to Cheeso's answer I found that it is enough to add the following registry entries to be able to use jscript9 without specifying the CLSID. I use the key name JScript9 here, you may replace it with Chakra if you like. The key name is what you specify after //E: then:

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\JScript9]
@="JScript9 Language"

[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\JScript9\CLSID]
@="{16d51579-a30b-4c8b-a276-0ff4dc41e755}"

[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\JScript9\OLEScript]

And then:

cscript.exe  <file>  //E:JScript9
悟红尘 2024-12-08 05:09:23

您现在可以通过已发布的 API 直接调用 Chakra 运行时,而不必再使用 IActiveScript

以下是 MSDN 上的一篇文章,展示了如何使用 C++ 或 C# 托管 Chakra 运行时:

https://web.archive.org/web/20151103122111/https://code.msdn.microsoft.com/windowsdesktop/JavaScript-Runtime-Hosting-d3a13880

注意: 截至 2019 年,代码示例位于 github.com/微软/Chakra-样本)

You can now call the Chakra runtime directly through published API's and you don't have to use IActiveScript anymore.

Here is an article on MSDN showing how to host the Chakra runtime in C++ or C#:

https://web.archive.org/web/20151103122111/https://code.msdn.microsoft.com/windowsdesktop/JavaScript-Runtime-Hosting-d3a13880

(Note: As of 2019, The code example is on github.com/microsoft/Chakra-Samples)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文