从 WinDBG 的 JavaScript 脚本访问文件系统
Access to filesystem from WinDBG's JavaScript script
我目前正在玩用 JavaScript 编写的 WinDBG 脚本,因为它是 described by Microsoft。
如何从 JavaScript 代码中访问文件系统?我对读取和写入位于磁盘某处的文件感兴趣。对于在浏览器上执行的 JavaScript,出于安全原因,这些功能被禁用,但例如 NodeJS 有自己的库来支持文件系统操作。
我按照整个 Internet 上的建议尝试了 File
、Blob
和 ActiveXObject
,但其中 none 在 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;
}
}
这个有效:
"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();
}
}
我目前正在玩用 JavaScript 编写的 WinDBG 脚本,因为它是 described by Microsoft。
如何从 JavaScript 代码中访问文件系统?我对读取和写入位于磁盘某处的文件感兴趣。对于在浏览器上执行的 JavaScript,出于安全原因,这些功能被禁用,但例如 NodeJS 有自己的库来支持文件系统操作。
我按照整个 Internet 上的建议尝试了 File
、Blob
和 ActiveXObject
,但其中 none 在 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;
}
}
这个有效:
"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();
}
}