Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] WebAssembly support in miasm #1060

Draft
wants to merge 6 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@
# Emacs files
*~
# Compiled python files
*\.pyc
*\.pyc
# Version file
/miasm/VERSION
48 changes: 48 additions & 0 deletions miasm/analysis/binary.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,53 @@ def parse(self, data, vm=None, addr=0, apply_reloc=False, **kwargs):
fill_loc_db_with_symbols(self._executable, self.loc_db, addr)


class ContainerWasm(Container):
"Container abstraction for ELF"

def parse(self, data, vm=None, addr=0, apply_reloc=False, **kwargs):
"""Load a wasm from @data
@data: bytes containing the wasm bytes bytes
"""
#from miasm.jitter.loader.elf import vm_load_elf, guess_arch, \
# fill_loc_db_with_symbols
from miasm.loader import wasm_init

self._executable = wasm_init.Wasm(data)

# Parse signature
#if not data.startswith(b'\x7fELF'):
# raise ContainerSignatureException()

# Build executable instance
# try:
# if vm is not None:
# self._executable = vm_load_elf(
# vm,
# data,
# loc_db=self.loc_db,
# base_addr=addr,
# apply_reloc=apply_reloc
# )
# else:
# self._executable = elf_init.ELF(data)
# except Exception as error:
# raise ContainerParsingException('Cannot read ELF: %s' % error)

# Set the architecture
self._arch = 'wasm'

# Build the bin_stream instance and set the entry point
try:
#self._bin_stream = bin_stream_wasm(self._executable)
self._entry_point = self._executable.content.entry
except Exception as error:
self._entry_point = None
#raise ContainerParsingException('Cannot read ELF: %s' % error)

#if vm is None:
# # Add known symbols (vm_load_elf already does it)
# fill_loc_db_with_symbols(self._executable, self.loc_db, addr)


class ContainerUnknown(Container):
"Container abstraction for unknown format"
Expand All @@ -233,4 +280,5 @@ def parse(self, data, vm=None, addr=0, **kwargs):
## Register containers
Container.register_container(ContainerPE)
Container.register_container(ContainerELF)
Container.register_container(ContainerWasm)
Container.register_fallback(ContainerUnknown)
13 changes: 12 additions & 1 deletion miasm/analysis/machine.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class Machine(object):

__available = ["arml", "armb", "armtl", "armtb", "sh4", "x86_16", "x86_32",
"x86_64", "msp430", "mips32b", "mips32l",
"aarch64l", "aarch64b", "ppc32b", "mepl", "mepb"]
"aarch64l", "aarch64b", "ppc32b", "mepl", "mepb", "wasm"]


def __init__(self, machine_name):
Expand Down Expand Up @@ -200,6 +200,17 @@ def __init__(self, machine_name):
mn = arch.mn_mep
from miasm.arch.mep.ira import ir_a_mepl as ira
from miasm.arch.mep.sem import ir_mepl as ir
elif machine_name == "wasm":
from miasm.arch.wasm.disasm import dis_wasm as dis_engine
from miasm.arch.wasm import arch
# try:
# from miasm.arch.arm import jit
# jitter = jit.jitter_arml
# except ImportError:
# pass
mn = arch.mn_wasm
#from miasm.arch.wasm.ira import ir_a_wasm as ira
from miasm.arch.wasm.sem import ir_wasm as ir
else:
raise ValueError('Unknown machine: %s' % machine_name)

Expand Down
4 changes: 2 additions & 2 deletions miasm/arch/msp430/arch.py
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,7 @@ def encode(self):
class bs_cond_off_s(bs_cond):

@classmethod
def flen(cls, mode, v):
def flen(cls, mode, v, bs, offset_b):
if v['a_s'] == 0b00:
return None
elif v['a_s'] == 0b01:
Expand Down Expand Up @@ -501,7 +501,7 @@ def decode(self, v):
class bs_cond_off_d(bs_cond_off_s):

@classmethod
def flen(cls, mode, v):
def flen(cls, mode, v, bs, offset_b):
if v['a_d'] == 0:
return None
elif v['a_d'] == 1:
Expand Down
Empty file added miasm/arch/wasm/__init__.py
Empty file.
Loading