-
Notifications
You must be signed in to change notification settings - Fork 148
disasm: allow to disassemble code without validating it #81
Conversation
Codecov Report
@@ Coverage Diff @@
## master #81 +/- ##
=========================================
+ Coverage 67.52% 67.7% +0.18%
=========================================
Files 32 32
Lines 2987 3010 +23
=========================================
+ Hits 2017 2038 +21
- Misses 736 737 +1
- Partials 234 235 +1
Continue to review full report at Codecov.
|
thanks. I think I'd rather go the other way around:
perhaps have a Alternatively, we could perhaps introduce a new type, akin to the perhaps the less invasive for now would be something along the lines of: // Disassemble disassembles a given function body into a set of instructions.
// It won't check operations for validity.
func Disassemble(code []byte) ([]Instr, error) {
...
}
type Disassembly struct { ... }
// Disassemble disassembles the given function. It also takes the function's
// parent module as an argument for locating any other functions referenced by
// fn.
func (d *Disassembly) Disassemble(fn wasm.Function, module *wasm.Module) error {
instrs, err := Disassemble(fn.Body.Code)
if err != nil { ... }
// ... what used to be the body of Disassemble ...
return err
} what do you think? |
I think the I like an idea of defining a Populating a |
sorry... I have been distracted (by apache/go-arrow) I am not sure I completely get what you're advocating for (sorry!). point noted about populating what about: // Disassemble disassembles a given function body into a set of instructions.
// It won't check operations for validity.
func Disassemble(code []byte) ([]Instr, error) {
...
}
// NewDisassembly disassembles the given function. It also takes the function's
// parent module as an argument for locating any other functions referenced by
// fn.
func NewDisassembly(fn wasm.Function, module *wasm.Module) (*Disassembly, error) {
instrs, err := Disassemble(fn.Body.Code)
if err != nil { ... }
// ... what used to be the body of Disassemble ...
return err
} |
@sbinet Changed according to your last suggestion. PTAL |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM (modulo that last one nitpick.)
@@ -0,0 +1,41 @@ | |||
package disasm_test |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add a copyright header.
Meh... I can add the header later :) |
This CL splits
Disassemble
function into two separate functions:DisassebleRaw
andDisasseble
. The first one decodes WASM instructions without checking for validity. And the second function validates the list of instructions from the first function.This was done to bypass any bugs in the validation code like #69 and be able to manipulate assembly code.