diff options
author | bloodstalker <thabogre@gmail.com> | 2018-07-05 21:50:53 +0000 |
---|---|---|
committer | bloodstalker <thabogre@gmail.com> | 2018-07-05 21:50:53 +0000 |
commit | 16a298427121edeb98b76c3468316741549947da (patch) | |
tree | c03b2022fd9ae104317f5ca2d84a8a9ff618f585 | |
parent | update (diff) | |
download | faultreiber-16a298427121edeb98b76c3468316741549947da.tar.gz faultreiber-16a298427121edeb98b76c3468316741549947da.zip |
update
Diffstat (limited to '')
-rwxr-xr-x | main.py | 1 | ||||
-rwxr-xr-x | misc.py | 47 | ||||
-rw-r--r-- | resources/wasm.xml | 34 |
3 files changed, 78 insertions, 4 deletions
@@ -12,6 +12,7 @@ import sys from text import text import datetime import xml.etree.ElementTree +from misc import * def SigHandler_SIGINT(signum, frame): print() @@ -0,0 +1,47 @@ + +def LEB128UnsignedDecode(bytelist): + result = 0 + shift = 0 + for byte in bytelist: + result |= (byte & 0x7f) << shift + if (byte & 0x80) == 0: + break + shift += 7 + return(result) + +def LEB128SignedDecode(bytelist): + result = 0 + shift = 0 + for byte in bytelist: + result |= (byte & 0x7f) << shift + last_byte = byte + shift += 7 + if (byte & 0x80) == 0: + break + if last_byte & 0x40: + result |= - (1 << shift) + return(result) + +def LEB128UnsignedEncode(int_val): + if int_val < 0: + raise Exception("value must not be negative") + elif int_val == 0: + return bytes([0]) + byte_array = bytearray() + while int_val: + byte = int_val & 0x7f + byte_array.append(byte | 0x80) + int_val >>= 7 + byte_array[-1] ^= 0x80 + return(byte_array) + +def LEB128SignedEncode(int_val): + byte_array = bytearray() + while True: + byte = int_val & 0x7f + byte_array.append(byte | 0x80) + int_val >>= 7 + if (int_val == 0 and byte&0x40 == 0) or (int_val == -1 and byte&0x40): + byte_array[-1] ^= 0x80 + break + return(byte_array) diff --git a/resources/wasm.xml b/resources/wasm.xml index f1402bb..f0935c6 100644 --- a/resources/wasm.xml +++ b/resources/wasm.xml @@ -3,8 +3,14 @@ <Read> <Magic_Number size="4"></Magic_Number> <Version size="4"></Version> - <Type_Section count="1" type="" isaggregate="true"></Type_Section> - <Import_Section count="1" type="" isaggregate="true"></Import_Section> + <Type_Section count="1" type="" isaggregate="true"> + <Count name="count" encoding="leb128u" type="uint32" count="1"/> + <Type_Section_Entry count="self::Count"/> + </Type_Section> + <Import_Section count="1" type="" isaggregate="true"> + <Count name="count" encoding="leb128u" type="uint32" count="1"/> + <Entries name="entries" type="self::Import_Section_Entry" count="self::Count"/> + </Import_Section> <Function_Section count="1" type="" isaggregate="true"></Function_Section> <Table_Section count="1" type="" isaggregate="true"></Table_Section> <Memory_Section count="1" type="" isaggregate="true"></Memory_Section> @@ -19,7 +25,7 @@ <Definition> <Init_Expr name="init_expr_t" isaggregate="true"> <Size name="size" encoding="leb128u" type="varuint32" count="1"></Size> - <Code name="code" type="char*" coutn="1"></Code> + <Code name="code" type="string" coutn="1" size="self::Size"></Code> </Init_Expr> <Resizable_Limit name="resizable_limit_t" isaggregate="true"> <Flags name="flags" encoding="leb128u" type="uint8" count="1"></Flags> @@ -34,8 +40,28 @@ <Element_Type name="element_type" encoding="leb128s" type="int8" count="1"></Element_Type> <Resizable_Limit count="1"></Resizable_Limit> </Table_Type> - <Memory_Type> + <Memory_Type name="memory_type_t" isaggregate="true"> <Resizable_Limit count="1"></Resizable_Limit> </Memory_Type> + <Type_Section_Entry name="W_Type_Section_Entry" isaggregate="true"> + <Form name="form" encoding="leb128s" type="int8" count="1"/> + <Param_Count name="param_count" encoding="leb128s" type="uint32" count="1"/> + <Param_Types name="param_types" encoding="leb128s" type="int8" count="self::Param_Count"/> + <Return_Count name="return_count" encoding="leb128u" type="uint8"/> + <Return_Types name="return_types" encoding="leb128s" type="int8"/> + </Type_Section_Entry> + <Import_Section_Entry name="W_Import_Section_Entry" isaggregate="true"> + <Module_Length name="module_length" encoding="leb128u" type="uint32" count="1"/> + <Module_Str name="module_str" type="string" count="1" size="self::Module_Length"/> + <Field_Len name="field_len" encoding="leb128u" type="uint32" couny="1"/> + <Field_Str name="field_str" type="string" count="1" size="self::Field_Len"/> + <Kind name="kind" encoding="leb128u" type="uint8" count="1"/> + <Type name="type" conditional="true" condition="self::Kind"> + <condition0 encoding="leb128u" type="uint32">0</condition0> + <condition1 type="Table_Type">1</condition1> + <condition2 type="Memory_Type">2</condition2> + <condition3 type="Global_Type">3</condition3> + </Type> + </Import_Section_Entry> </Definition> </wasm:Structure> |