【问题标题】:Can I get all custom section from a WebAssembly in Node.JS?我可以从 Node.JS 中的 WebAssembly 获取所有自定义部分吗?
【发布时间】:2022-01-18 14:24:21
【问题描述】:

我知道有办法获得具有给定名称的特定自定义部分。

var nameSections = WebAssembly.Module.customSections(module, "sec_name");

有什么方法可以获取给定 WebAssembly 模块中的所有自定义部分?

【问题讨论】:

  • 这可能取决于是否有办法获取所有自定义部分名称.. idk 所以我只是潜伏

标签: node.js rust webassembly


【解决方案1】:

JavaScript interface 目前不提供该功能。 customSection 功能已讨论并批准here。目前有一个未解决的问题来解决您提出的问题here。通常这个时候的问题状态是提供这样的 API 会带来太多的复杂性(与其说是关于列表的部分,而是关于每个部分的内容)。这对我来说很有意义,因为 WebAssembly 标准目前正处于非常活跃的开发阶段(许多后 MVP 功能正在开发中)。

也就是说,您似乎无法自己解析二进制文件。二进制格式记录在here。基本上,在解析magic number and the version 之后,有一个list of sections: 1 字节ID,一个u32LEB128 format,允许尾随零)用于该部分的byte content length,然后是该部分内容的字节(带有那个长度)。在这 headercontent 字节之后,是下一部分,如果有的话,直到结束。

自定义部分有一个id0。这些部分的contentname 开头,之后是“用户”字节部分。此名称是字节向量。每个向量都有一个长度(同样是 u32),后跟必须是 UTF-8 编码字符串的字节数。

所以伪代码是这样的:

parse the magic 
parse the version
loop till there are bytes
  read the section id
  read the section u32 length
  if id = 0 then  
    read the name u32 length
    skip the name bytes
    use the user bytes till the end of the section
  jump to the end of the section

【讨论】:

    猜你喜欢
    • 2013-08-19
    • 1970-01-01
    • 2019-02-18
    • 2013-09-25
    • 1970-01-01
    • 2020-08-31
    • 2011-05-06
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多