VB6 JSONAuthor: Dave Date: 11.06.24 - 8:32am here is another little surprise, pretty fast too. The MSScript control can return javascript json objects directly for use with vb6. Note the () wrapper around the json text to function as an eval. Also it gets faster with early binding to the script control. Private Sub Form_Load() Dim o As Object, json As Object Set o = CreateObject("MSScriptControl.ScriptControl") o.Language = "JScript" Set json = o.eval("({'id':90,'blah':21})") Debug.Print TypeName(json) 'JScriptTypeInfo Debug.Print "id: " & json.id & " blah:" & json.blah End Sub Now some things do not seem to been seamlessly accessible to vb through this mechanism such as array access. So far the only way i have figured out to get access to js array elements is with some help from the js engine again. Private Sub Form_Load() Dim elem As Object, sc As Object Set sc = CreateObject("MSScriptControl.ScriptControl") sc.Language = "JScript" sc.addcode "var json = [{'id':90,'blah':21}]" Set elem = sc.Eval("json[0]") 'InputBox "objptr", , Hex(ObjPtr(elem)) Debug.Print "id: " & elem.id & " blah:" & elem.blah End Sub Just out of curosity if you want to inspect the COM object that MS wraps around the JS object you can check out its objptr (note I rebased the address of first segment in IDA to match the loaded imagebase of the dll obtained from olly for simplicity) Comments: (1)On 11.07.24 - 2:37pm Dave wrote:
|
About Me More Blogs Main Site
|
|||||||||||||||||||||||||||||||||