wabt icon indicating copy to clipboard operation
wabt copied to clipboard

[Feature/Binary Request] List Exported functions only

Open walksanatora opened this issue 2 years ago • 11 comments

I noticed that wasm-objdump can dump all functions and symbols but it does it weirdly it doesen't quite go functions (then their data) it seems to switch between all the diffrent data assocated whether being size, where it is pulled from etc

walksanatora avatar Nov 02 '23 19:11 walksanatora

You can list the exports using wasm-objdump -j export.

We could add a flag to allow you to disassamble just exported functions but I'm not clear why that would be useful. Why would you only want to disassemble the exported functions?

Aside from that I'm not quite sure what you are asking for here. The data in wasm module is no generally associated with particular function. Any function can access any data. There may have been some link/assosiation in the source language but those links are not present in the binaryn.

sbc100 avatar Nov 02 '23 19:11 sbc100

In the case of a shared library and I forgot all the exported functions I included in it

walksanatora avatar Nov 03 '23 06:11 walksanatora

Also I just tried wasm-objdump -j export and I had to add -x and then it told me "section not found: export" also checked the plural form

walksanatora avatar Nov 03 '23 06:11 walksanatora

Also I just tried wasm-objdump -j export and I had to add -x and then it told me "section not found: export" also checked the plural form

What don't wasm-objdump -h tell you? Does the file really not have an export section?

sbc100 avatar Nov 03 '23 09:11 sbc100

all wasm-objdump -h tells me is

wasm-objdump: expected filename argument.
Try '--help' for more information.

if I try --help

usage: wasm-objdump [options] filename+

  Print information about the contents of wasm binaries.

examples:
  $ wasm-objdump test.wasm

options:
      --help                   Print this help message
      --version                Print version information
  -h, --headers                Print headers
  -j, --section=SECTION        Select just one section
  -s, --full-contents          Print raw section contents
  -d, --disassemble            Disassemble function bodies
      --debug                  Print extra debug information
  -x, --details                Show section details
  -r, --reloc                  Show relocations inline with disassembly
      --section-offsets        Print section offsets instead of file offsets in code disassembly

and idk how to check for export section (all i know is that wasm2c produces valid C code)

walksanatora avatar Nov 04 '23 01:11 walksanatora

The -h or --headers flag lists the headers of a wasm file. You need to also specify the wasm file on the command line along with the -h flag. Sorry I wasn't more clear about that.

sbc100 avatar Nov 04 '23 05:11 sbc100

so it appears the propper command is wasm-objdump -j Export -x but this includes the export of memory and also fails to include the function types (inputs/outputs)

walksanatora avatar Nov 04 '23 05:11 walksanatora

Right, -j Export lists all the exports, not just the functions. There is not flag for listing just part of the export section. Each section is listed in it's entirety, or not at all.

The signatures are in a different section so you would use a different -j flag to list those.

If you are looking for other ways to introspect a wasm module you might also want to take a look at wasm-dis from the binaryen project.

sbc100 avatar Nov 04 '23 05:11 sbc100

wasm-dis imo feels like a worse wasm2wat

walksanatora avatar Nov 04 '23 06:11 walksanatora

(also totally not considering implementing my own WASM VM in lua since the only wasm2lua I can find is broken and apparently abandoned)

walksanatora avatar Nov 04 '23 06:11 walksanatora

afterall for my specific binary I would only have to implement 101 diffrent opcodes (not including some other important stuff)

walksanatora avatar Nov 04 '23 06:11 walksanatora