Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 427 Vote(s) - 3.54 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Having difficulty exposing XmlDocument to JScript using ClearScript

#1
Context: Windows Azure; Visual Studio Community 2015; ClearScript; JScript

I'm having problems exposing an XmlDocument object to the JScripts I'm executing using ClearScript.

I am instantiating a JScript interpreter using

JScriptEngine JSengine = new JScriptEngine(WindowsScriptEngineFlags.EnableDebugging | WindowsScriptEngineFlags.EnableJITDebugging);

To instantiate the XmlDocument object I have tried both

using System.Xml;
...
JSengine.AddHostType("CSXmlDocument", typeof(XmlDocument));
...

and

...
JSengine.AddCOMObject("CSXmlDocument", "MSXML2.DOMDocument");
...

and I execute the JScript script using this

...
object answer = JSengine.Evaluate(File.ReadAllText(rulesetFilename));
...

My difficulty is in how to use the `CSXmlDocument` object inside the script. I have tried all of the following to no avail.

var xmlObj1 = CSXmlDocument;
var xmlObj2 = new CSXmlDocument;
var xmlObj3 = CSXmlDocument();
var xmlObj4 = new CSXmlDocument();

When `CSXmlDocument` is defined using `AddCOMObject`, the second through fourth invocations give an error of

Unable to evaluate the expression. Operation not supported. Unknown error: 0x8013baff.

The first invocation only gives me access to three methods, `Equals`, `GetHashCode`, `GetType`.

When `CSXmlDocument` is defined using `AddHostType`, the first gives just the three methods as above. The second invocation seems to give access to the full set of properties and methods (at least that's what VS2015 says in a debugging session) however, when I try to use the `LoadXml` method I get

xmlObj2.LoadXml(body)
Unable to evaluate the expression. Operation not supported. Unknown error: 0x8013baff.

I am currently working through two possible gotchas:

1. Character encoding, in the light of [another StackOverflow posting][1].
2. HTML-XML markup conflicts.


[1]:

[To see links please register here]

Reply

#2
Hmm, I'm not sure what you're doing differently, but the following works for me:

using (var JSengine = new JScriptEngine())
{
JSengine.AddHostType("CSXmlDocument", typeof(XmlDocument));
JSengine.AddHostType("CSConsole", typeof(Console));
JSengine.Execute(@"
var doc = new CSXmlDocument();
doc.LoadXml('<Hello>World</Hello>');
var node = doc.FirstChild;
CSConsole.WriteLine('{0} {1}!', node.Name, node.InnerText);");
}

This produces the expected output "Hello World!" with ClearScript 5.4.4. Does it work for you?
Reply

#3
Instead of passing in the object, I elected to create the object in the script. Thus I have

var htmlDoc = new ActiveXObject("Msxml2.FreeThreadedDOMDocument.6.0");

What benefit there is in using `FreeThreaded` I don't know but it's working.

I still had problems, mind you, with how Msxml2 was handling the HTML I was throwing at it, and had to add the following

htmlDoc.setProperty("ProhibitDTD", false);
htmlDoc.validateOnParse = false;

Also Msxml2 can't handle ` ` so I swapped that for its character equivalent:

body = body.replace(/ /g, " ");

The `ProhibitDTD` meant that ripping out the DOCTYPE was also required, viz

body = body.replace("<!DOCTYPE html>", "");

With all that done, the rest happened fairly quickly:

htmlDoc.loadXML(body);
leadLink = htmlDoc.selectNodes('//*[@title="View this lead"]')[0].attributes[0].value;

Reply



Forum Jump:


Users browsing this thread:
2 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through