From b0a200f97ad40c3e7c9c4a0237b850df1a53db3c Mon Sep 17 00:00:00 2001 From: bloodstalker Date: Sun, 1 Jul 2018 01:31:59 +0430 Subject: update --- dwasm-cpp/dwasm.cpp | 9 ++++++++- dwasm-cpp/dwasm.hpp | 2 +- dwasm-cpp/misc.hpp | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ dwasm-cpp/run.sh | 4 ++++ 4 files changed, 63 insertions(+), 2 deletions(-) create mode 100644 dwasm-cpp/misc.hpp create mode 100755 dwasm-cpp/run.sh diff --git a/dwasm-cpp/dwasm.cpp b/dwasm-cpp/dwasm.cpp index 35ab040..e326411 100644 --- a/dwasm-cpp/dwasm.cpp +++ b/dwasm-cpp/dwasm.cpp @@ -18,13 +18,20 @@ You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.*/ /**********************************************************************************************************************/ +#include +#include #include #include #include #include "dwasm.hpp" +#include "misc.hpp" #include "wasm.h" - +/**********************************************************************************************************************/ int main (int argc, char** argv) { + std::string path = "../test/injected.wasm"; + std::ifstream wasm(path, std::ios_base::binary); + read_header(wasm); + //dump_file(wasm); return 0; } /**********************************************************************************************************************/ diff --git a/dwasm-cpp/dwasm.hpp b/dwasm-cpp/dwasm.hpp index 9b9876d..3c9c4a5 100644 --- a/dwasm-cpp/dwasm.hpp +++ b/dwasm-cpp/dwasm.hpp @@ -21,7 +21,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.* #include #include #include - +/**********************************************************************************************************************/ #ifndef _WASM_HPP #define _WASM_HPP #define MAGIC_NUMBER 0x6d736100 diff --git a/dwasm-cpp/misc.hpp b/dwasm-cpp/misc.hpp new file mode 100644 index 0000000..74f61ad --- /dev/null +++ b/dwasm-cpp/misc.hpp @@ -0,0 +1,50 @@ + +/**********************************************************************************************************************/ +/*first line intentionally left blank.*/ +/*wasm interpreter*/ +/*Copyright (C) 2018 Farzad Sadeghi + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either version 3 +of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.*/ +/**********************************************************************************************************************/ +#include +#include +/**********************************************************************************************************************/ +int read_header(std::ifstream& wasm) { + char head[4]; + wasm.read(head, sizeof(uint32_t)); + std::cout << head[0] << head[1] << head[2] << head[3] << "\n"; + wasm.read(head, sizeof(uint32_t)); + std::cout << (int)(head[0]) << (int)(head[1]) << (int)(head[2]) << (int)(head[3]) << "\n"; + return 0; +} + +int dump_file(std::ifstream& wasm) { + while (wasm) { + std::ios::pos_type before = wasm.tellg(); + uint8_t x; + wasm >> x; + std::ios::pos_type after = wasm.tellg(); + std::cout << std::hex << static_cast(x) << "\n"; + } + return 0; +} + +int leb128_u_d(std::vector in) {} +int leb128_s_d(std::vector in) {} +std::vector leb128_u_e() {} +std::vector leb128_s_e() {} +/**********************************************************************************************************************/ +/*last line intentionally left blank.*/ + diff --git a/dwasm-cpp/run.sh b/dwasm-cpp/run.sh new file mode 100755 index 0000000..c4df11d --- /dev/null +++ b/dwasm-cpp/run.sh @@ -0,0 +1,4 @@ +#!/bin/sh + +"make" +"./dwasm" -- cgit v1.2.3