VB6 JSON


Author: 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:
with some googlefu turns out the following will work also:

Private Sub Form_Load()
    Dim elem As Object, sc As Object, json As Object
    Set sc = CreateObject("MSScriptControl.ScriptControl")
    sc.Language = "JScript"
    Set json = sc.eval("[{'id':90,'blah':21}]")
    Set elem = CallByName(json, 0, VbGet)
    Debug.Print "id: " & elem.id & " blah:" & elem.blah
End Sub

 
Leave Comment:
Name:
Email: (not shown)
Message: (Required)
Math Question: 97 + 78 = ? followed by the letter: L 



About Me
More Blogs
Main Site
Posts: (All)
2024 (3)
     VB6 JSON
     ffmpeg voodoo
     RegJump Vb
2023 (9)
     VB6 Virtual Files
     File handles across dlls
     python abort / script timeout
     py4vb
     VB6 Python embed w/debugger
     python embedding
     VB6 IDE Enhancements
     No Sleep
     A2W no ATL
2022 (4)
     More VB6 - C data passing
     Vb6 Asm listing
     Byte Array C to VB6
     Planet Source Code DVDs
2021 ( 2 )
2020 ( 4 )
2019 ( 5 )
2018 ( 6 )
2017 ( 6 )
2016 ( 22 )
2015 ( 15 )
2014 ( 25 )
2013 ( 4 )
2012 ( 10 )
2011 ( 7 )
2010 ( 11 )
2009 ( 3 )