从WinDBG的JavaScript脚本访问文件系统

时间:2017-09-22 14:30:13

标签: javascript filesystems windbg

我目前正在玩用JavaScript编写的WinDBG脚本described by Microsoft

如何从JavaScript代码中访问文件系统?我对读取和写入位于磁盘上某处的文件感兴趣。对于在浏览器上执行的JavaScript,由于安全原因,这些功能被禁用,但是例如NodeJS有自己的库来支持文件系统操作。

2 个答案:

答案 0 :(得分:1)

这有效:

"use strict";

function invokeScript() {
    var debugControl = host.namespace.Debugger.Utility.Control;

    var output = debugControl.ExecuteCommand("vertarget");

    writeOutputToFile(output);
}

function writeOutputToFile(output) {

    var logFilePath = "c:\\debugging\\output\\output.log";

    var logFile;

    if (host.namespace.Debugger.Utility.FileSystem.FileExists(logFilePath)) {        
        logFile = host.namespace.Debugger.Utility.FileSystem.CreateFile(logFilePath, "OpenExisting");
    }
    else {        
        logFile = host.namespace.Debugger.Utility.FileSystem.CreateFile(logFilePath);
    }

    var textWriter = host.namespace.Debugger.Utility.FileSystem.CreateTextWriter(logFile, "Utf16");

    try {
        for (var line of output) {
            textWriter.WriteLine(line);
        }
    }
    finally {
        logFile.Close();
    }
}

答案 1 :(得分:0)

我按照互联网上的建议尝试了FileBlobActiveXObject,但它们都不适用于WinDbg。

您可以尝试.dvalloc + .writemem + .dvfree的组合。以下是一个起点,但远未完成:

function saveTextAsFile()
{
    var dbgOut = host.diagnostics.debugLog;
    var exec = host.namespace.Debugger.Utility.Control.ExecuteCommand;   
    var output = exec(".dvalloc 0x10000");  
    for (var line of output)
    {
        dbgOut("Output: "+line+"\n");
        var index = line.indexOf("starting at ");
        var address = line.substring(index+("starting at ".length));
        dbgOut("Allocated memory at "+address+"\n");
        exec(".writemem f:\\debug\\logs\\fromscript.txt "+address+" L10000")
        var output = exec(".dvfree " + address + " 0x10000");
        break;
    }
}