Windbg JavaScript引擎:从字节阵列铸造到类型

发布于 2025-02-01 21:48:25 字数 659 浏览 1 评论 0原文

因此,我具有以下数据结构:

struct A_TYPE {
UINT64 a;
UINT32 b;
UINT32 c[16];
}

并且我的字节数组与以下代码相似:

var buf = new ArrayBuffer(128);
var numbers = new Uint8Array(buf);
//code that sets the numbers array

现在,我想根据numbers byte数组创建一个A_TYPE对象。

我已经尝试执行以下操作,但没有任何效果:

//attempt 1:
var instantiatedType = host.typeSystem.marshalAs(numbers, srcName, typeName);

//attempt 2:
var type = host.getModuleType(srcName, typeName);
var instantiatedType = type.initialize(numbers) //initialize/constructor was a function i hoped to exist

此功能是否已经实施了什么想法? 听起来像是一个基本功能,但我找不到

So i have the following data structure:

struct A_TYPE {
UINT64 a;
UINT32 b;
UINT32 c[16];
}

and i have a byte array similar with the following code:

var buf = new ArrayBuffer(128);
var numbers = new Uint8Array(buf);
//code that sets the numbers array

Now i want to create a A_TYPE object based on the numbers byte array.

I have tried doing the following but nothing worked:

//attempt 1:
var instantiatedType = host.typeSystem.marshalAs(numbers, srcName, typeName);

//attempt 2:
var type = host.getModuleType(srcName, typeName);
var instantiatedType = type.initialize(numbers) //initialize/constructor was a function i hoped to exist

Any ideas whether this functionality is already implemented?
Sounds like a basic feature but i couldn't find it

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

与君绝 2025-02-08 21:48:25

我可以问到什么,您是否想以创建的“ a_type”的实例来做?

由您要调试的符号描述的类型仅在目标中的某个位置中存在。它们可以处于目标地址空间中的某个虚拟地址……也可以在线程或堆栈框架上下文的某些寄存器中。您不能仅仅由JavaScript数据中的符号描述的a_type的实例“创建”。

您可以创建使用 host.createTypedObject 方法说“在目标地址空间中,在虚拟地址0x1000(或其他)上说“有一个a_type键入对象。然后,您可以读取该对象的读取/写入字段通过您从 createTypedObject 方法呼叫的情况下,您正在修改目标过程的地址空间

。 typeystem.marshalas 旨在使您可以更改某些对象退出JavaScript,例如,如果您将本机枚举值带入JavaScript中 - 它将 Lost 它是“枚举”和 数字(JS中没有自定义值类型)。

// A property accessor on some class which returns a native enum...
get myValue()
{
    return this.someEnum;
}

只需成为一个 如果您真的想要一个将JavaScript推出为特定键入的枚举,而不仅仅是统一数字。

根据您的评论更新(重新解码内存a_type):

虽然您无法通过合成数据创建a_type的实例,但是有两种方法可以呈现类似您正在谈论的“解码”类型之类的东西。首先是返回一个JavaScript对象:

function decodeAType(aType)
{
    // your extraction code...
    var buf = new UInt8Array(...);

    // Just return a JavaScript object
    return { a: decoded_a, b: decoded_b, c: buf };
}

返回的对象将在EE(DX)中起作用,并且可以传递给并在任何其他C ++或JavaScript Debugger扩展程序中使用。是的 - 这不是“真实类型”,不能在诸如'dt'等旧命令中使用...但是它非常有用。

第二种方法是将可视化器与A_Type相关联,该type进行解码并显示解码字段:

class __MyATypeVisualizer
{
    get decoded_a() { ... }
    get decoded_b() { ... }
    get decoded_c() { ... }
}

function initializeScript()
{
    //
    // Make __MyATypeVisualizer the canonical visualizer for A_TYPE.
    // Any time it's displayed in the locals window or 'dx', the fields
    // in __MyATypeVisualizer will be shown instead of the native fields.
    // You can also use typeSignatureExtension below if you want those
    // fields to be added instead of displayed in lieu of the native ones.
    //
    return [new host.typeSignatureRegistration(__MyATypeVisualizer, "A_TYPE")];
}

在这里,可以将原始的A_TYPE转移并像常规键入对象一样传递并使用...但是当在当地人或手表窗口中显示时。 。如果将对象传递给另一个C ++/JavaScript调试器扩展程序,则可以像本机一样使用__ myatypevisualizer添加/可视化的字段。“ DX”中的表达式评估器也是如此。

我希望有帮助...

What, may I ask, are you trying to DO with the instance of "A_TYPE" that you create...?

Types which are described by the symbols of what you are debugging only exist at some location IN the target. They can be at some virtual address in the target's address space... or they can be in some register of a thread or stack frame's context. You cannot just "create an instance" of A_TYPE described by symbols from JavaScript data.

You can create use host.createTypedObject method to say "there is an A_TYPE typed object at virtual address 0x1000 (or whatever) in the address space of the target. You can then read/write fields of that object through what you get back from the createTypedObject method call. That said -- if you write -- you are modifying the address space of the target process.

I'll note that things like host.typeSystem.marshalAs are designed to allow you to change how some object exits JavaScript. If, for instance, you bring a native enum value into JavaScript -- it will lose it's "enumness" and just become a number (there are no custom value types in JS). You cannot, therefore create a property that does something like:

// A property accessor on some class which returns a native enum...
get myValue()
{
    return this.someEnum;
}

The moment someEnum enters JavaScript above, it becomes a number... and that number would get returned. If you really wanted an enum to get returned to the caller, you would need to use host.typeSystem.marshalAs to tell the marshaler that this number should be marshaled out of JavaScript as a specifically typed enum and not just a flat number.

UPDATED PER YOUR COMMENT (re decoding an in-memory A_TYPE):

While you cannot create an instance of A_TYPE from synthetic data, there are two ways to present something like the "decoded" type you are talking about. First is just to return a JavaScript object:

function decodeAType(aType)
{
    // your extraction code...
    var buf = new UInt8Array(...);

    // Just return a JavaScript object
    return { a: decoded_a, b: decoded_b, c: buf };
}

That returned object will work in the EE (dx) and can be passed to and used in any other C++ or JavaScript debugger extension. Yes -- it's not a "real type" and can't be used in legacy commands like 'dt', etc... but it's pretty functional.

The second way is to associate a visualizer with A_TYPE which does the decoding and presents the decoded fields:

class __MyATypeVisualizer
{
    get decoded_a() { ... }
    get decoded_b() { ... }
    get decoded_c() { ... }
}

function initializeScript()
{
    //
    // Make __MyATypeVisualizer the canonical visualizer for A_TYPE.
    // Any time it's displayed in the locals window or 'dx', the fields
    // in __MyATypeVisualizer will be shown instead of the native fields.
    // You can also use typeSignatureExtension below if you want those
    // fields to be added instead of displayed in lieu of the native ones.
    //
    return [new host.typeSignatureRegistration(__MyATypeVisualizer, "A_TYPE")];
}

Here, the original A_TYPE can be passed around and used like a regular typed object... but when DISPLAYED in the locals or watch window... or in the console via dx, you'll see the added/visualized decoded fields. If the object is passed to another C++/JavaScript debugger extension, the fields added/visualized by __MyATypeVisualizer can be used just like the native ones... The same goes for the expression evaluator in 'dx'.

I hope that helps...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文