aboutsummaryrefslogtreecommitdiffstats
path: root/test/autowasm.c
diff options
context:
space:
mode:
authorbloodstalker <thabogre@gmail.com>2018-08-04 10:01:15 +0000
committerbloodstalker <thabogre@gmail.com>2018-08-04 10:01:15 +0000
commit35d02ccd72a09db1839a4aed6fc65de57c9a0809 (patch)
treeb4959ca73ac37c884c8a14cab2748e3c1ce007e6 /test/autowasm.c
parentupdate (diff)
downloadfaultreiber-35d02ccd72a09db1839a4aed6fc65de57c9a0809.tar.gz
faultreiber-35d02ccd72a09db1839a4aed6fc65de57c9a0809.zip
update
Diffstat (limited to 'test/autowasm.c')
-rw-r--r--test/autowasm.c35
1 files changed, 3 insertions, 32 deletions
diff --git a/test/autowasm.c b/test/autowasm.c
index 02e0379..7e4150a 100644
--- a/test/autowasm.c
+++ b/test/autowasm.c
@@ -5,39 +5,10 @@
#include <stdlib.h>
#include <unistd.h>
-#include "./read.c"
+#include "./structs.h"
+#include "./read.h"
#include "./aggregate.h"
-uint64_t read_leb128_u(int _fd, int max_size) {
- uint8_t read_bytes = 0U;
- uint8_t byte = 0;
- uint64_t result = 0U;
- uint32_t shift = 0U;
- do {
- read(_fd, &byte, 1);read_bytes++;read_bytes++;
- result |= (byte & 0x7f) << shift;
- shift += 7;
- } while(((byte & 0x80) != 0) && (read_bytes < max_size));
- return result;
-}
-
-int64_t read_leb128_s(int _fd, int max_size) {
- uint8_t byte;
- uint8_t read_bytes = 0U;
- uint8_t last_byte;
- int64_t result = 0;
- uint32_t shift = 0U;
- read(_fd, &byte, 1);
- do {
- read(_fd, &byte, 1);read_bytes++;
- result |= (byte & 0x7f) << shift;
- last_byte = byte;
- shift += 7;
- } while(((byte & 0x80) != 0) && read_bytes < max_size);
- if ((last_byte & 0x40) != 0) result |= -(1 << shift);
- return result;
-}
-
#pragma weak main
int main (int argc, char** argv) {
int wasm = open("./test.wasm", O_RDONLY);
@@ -56,7 +27,7 @@ int main (int argc, char** argv) {
printf("test_byte:%08x\n", word);
lseek(wasm, 9, SEEK_SET);
- test_u = READ_VAR_UINT_32(wasm);
+ test_u = read_leb_128_u(wasm, 5);
printf("read u res is: %lu.\n", test_u);
lseek(wasm, 0, SEEK_SET);
while(read(wasm, &word, sizeof(uint32_t))) {