From 16a298427121edeb98b76c3468316741549947da Mon Sep 17 00:00:00 2001 From: bloodstalker Date: Fri, 6 Jul 2018 02:20:53 +0430 Subject: update --- main.py | 1 + misc.py | 47 +++++++++++++++++++++++++++++++++++++++++++++++ resources/wasm.xml | 34 ++++++++++++++++++++++++++++++---- 3 files changed, 78 insertions(+), 4 deletions(-) create mode 100755 misc.py diff --git a/main.py b/main.py index 51e1dfe..46d550e 100755 --- a/main.py +++ b/main.py @@ -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() diff --git a/misc.py b/misc.py new file mode 100755 index 0000000..b7120e2 --- /dev/null +++ b/misc.py @@ -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 @@ - - + + + + + + + + @@ -19,7 +25,7 @@ - + @@ -34,8 +40,28 @@ - + + +
+ + + + + + + + + + + + + 0 + 1 + 2 + 3 + + -- cgit v1.2.3