How do I share Javascript code between files in Windbg preview?

拜拜、爱过 提交于 2020-01-15 12:06:19

问题


How do I share Javascript code between files in Windbg preview?

Right now I have several helper methods that I have copied and pasted into different javascript files. I'm not all that experienced with javascript, so my apologies if this is a stupid question.

As an example, let's say I want to use this function in more than one file:

function GetGuid( objectPtr )
{
    return ExecuteCommandToString( "dt nt!_GUID " + objectPtr )
    .FindLineContaining("{").trim().replace("{", "").replace("}","");
}

回答1:


I have a common.js which has a few functions that are normally reusable like host.diagnostics.debugLog()

i first load it using .scriptload

then in other js files I create a var to those functions and use it

see if this helps

contents of common function file

C:\>cat c:\wdscr\common.js
function log(instr) {
    host.diagnostics.debugLog(instr + "\n");
}
function exec (cmdstr){
    return host.namespace.Debugger.Utility.Control.ExecuteCommand(cmdstr);
}

a js file using the function from common.js

C:\>cat c:\wdscr\usecommon.js
function foo(){
    var commonlog = host.namespace.Debugger.State.Scripts.common.Contents.log
    var commonexec = host.namespace.Debugger.State.Scripts.common.Contents.exec
    commonlog("we are using the logging function from the common.js file")

    var blah = commonexec("lma @$exentry")
    for(var a of blah) {
        commonlog(a)
    }
}

actual usage

C:\>cdb calc
Microsoft (R) Windows Debugger Version 10.0.16299.15 X86

0:000> .load jsprovider

0:000> .scriptload c:\wdscr\common.js
JavaScript script successfully loaded from 'c:\wdscr\common.js'

0:000> .scriptload c:\wdscr\usecommon.js
JavaScript script successfully loaded from 'c:\wdscr\usecommon.js'

0:000> dx @$scriptContents.foo()

we are using the logging function from the common.js file 
start    end        module name
00f10000 00fd0000   calc       (deferred)
@$scriptContents.foo()
0:000>


来源:https://stackoverflow.com/questions/48243964/how-do-i-share-javascript-code-between-files-in-windbg-preview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!