Skip to content
Open
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
The diff you're trying to view is too large. We only load the first 3000 changed files.
Binary file added .DS_Store
Binary file not shown.
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ EMCC_SRC=$(wildcard src/*.cc src/**/*.cc !(src/wasmdec.cc))
OBJS=$(SRC:.cc=.o)
OUT=wasmdec
CC=g++
CCOPTS=-std=c++14 -Iexternal/binaryen/src -Iexternal/cxxopts/include -c -Wall -g
RELEASE_CCOPTS=-std=c++14 -Iexternal/binaryen/src -c -Wall -O3
CCOPTS=-std=c++11 -Iexternal/binaryen/src -Iexternal/cxxopts/include -c -Wall -g
RELEASE_CCOPTS=-std=c++11 -Iexternal/binaryen/src -c -Wall -O3
LDOPTS=-Lexternal/binaryen/lib -lbinaryen -lpthread

default: $(SRC) $(OUT)
Expand All @@ -22,7 +22,7 @@ wasm:
# make wasmBinaryen
mkdir -p emcc_out
EMCC_DEBUG=1 em++ external/binaryen/lib/libbinaryen.so $(EMCC_SRC) \
-std=c++14 -Iexternal/binaryen/src -Iexternal/cxxopts/include -Wall -O3 \
-std=c++11 -Iexternal/binaryen/src -Iexternal/cxxopts/include -Wall -O3 \
-Wall -o emcc_out/wasmdec.js \
-s EXPORTED_FUNCTIONS='["_wasmdec_create_decompiler", "_wasmdec_decompile", "_wasmdec_get_decompiled_code", "_wasmdec_destroy_decompiler"]' \
-s EXTRA_EXPORTED_RUNTIME_METHODS='["ccall", "cwrap", "addOnPostRun"]' -s ASSERTIONS=1 -s SAFE_HEAP=1
Expand Down
39 changes: 23 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
# wasmdec
## Bu depo bir çataldır ve Web-Assembly dosyalarını okunabilecek seviyede C diline dönüştürür. Bu depo normalde Silikon Mac'ler üzerinde çalışmayacak kodun güncellenmiş ve kullanıma hazır hale getirilmiş halidir.

## wasmdec
wasmdec is a program that converts WebAssembly binaries to C.

# Demo
## Demo
[An online real-time WebAssembly decompiler utilizing wasmdec is avalible here](https://wwwg.github.io/web-wasmdec/)

# Simple Example
## Simple Example
wasmdec will translate this WebAssembly binary:
```wasm
(module
Expand All @@ -22,7 +24,7 @@ int fn_addTwo(int arg0, int arg1) {
return arg0 + arg1;
}
```
# More practical examples
## More practical examples

### [Diep.io](https://diep.io) (HTML5 web game written in C++ and compiled to WASM)
Diep.io is a real time web game written in C++ and compiled to WebAssembly via Emscripten.
Expand All @@ -39,18 +41,8 @@ From the [WebDSP repository](https://github.com/shamadee/web-dsp):
```
WebDSP is a collection of highly performant algorithms, which are designed to be building blocks for web applications that aim to operate on media data. The methods are written in C++ and compiled to WASM, and exposed as simple vanilla Javascript functions developers can run on the client side.
```
* A compiled version of the library is avalible on the WebDSP demo page
* [The decompiled library is avalible here](examples/webdsp_decompiled.c)

# Applications
[A CTF write-up which uses wasmdec to reverse engineer a WASM binary](http://maroueneboubakri.blogspot.com/2018/04/nuit-du-hack-ctf-quals-2018-assemblyme.html)

# Installing with release

- Grab a release on the releases page and select the correct tarball for your OS and arch.
- Extract and run `install.sh` as root.

# Installing manually
## Installing manually

## Getting the code
Clone the repository with
Expand All @@ -59,9 +51,24 @@ git clone https://github.com/wwwg/wasmdec.git --recursive
```
Make sure the recursive flag is set to clone all the submodules.
## Building
First of all if u don't have /usr/local/lib folder, create it.

Install pyenv with homebrew `brew install pyenv`

Install python 2.7.18 with `pyenv install 2.7.18`

Run `pyenv global 2.7.18` `export PATH="$(pyenv root)/shims:$PATH"
eval "$(pyenv init -)"`

Add these lines to your terminal preferences file.

Then type `source <path of your terminal preferences file>`.

Restart your terminal and check python version with `python --version` if you see Python 2.7.18 now you are ready for build!

To build wasmdec and install all of it's dependencies, run `sudo make all` in the `wasmdec` directory. GCC 7 or higher is reccomended.

# Usage
## Usage
```bash
wasmdec -o (output file) (options) [input files]
```
Expand Down
Binary file added external/.DS_Store
Binary file not shown.
1 change: 0 additions & 1 deletion external/binaryen
Submodule binaryen deleted from 9f49e3
7 changes: 7 additions & 0 deletions external/binaryen/.clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
BasedOnStyle: LLVM
PointerAlignment: Left
IndentCaseLabels: true
ColumnLimit: 100
ContinuationIndentWidth: 2
ConstructorInitializerIndentWidth: 2
AlignAfterOpenBracket: DontAlign
8 changes: 8 additions & 0 deletions external/binaryen/.flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[flake8]
ignore =
E111, # indentation not a multiple of 4 (we use 2))
E114, # comment indentation not a multiple of 4
E501, # line too long
E121, # continuation line under-indented for hanging indent
E241 # space after comma (ignored for list in gen-s-parser.py)
exclude = ./test/emscripten,./test/spec,./test/wasm-install
3 changes: 3 additions & 0 deletions external/binaryen/.gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*.a binary
bin/wasm.js -diff
bin/binaryen.js -diff
66 changes: 66 additions & 0 deletions external/binaryen/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
*.pyc
*~
*.diff

# autogenerated during the build
src/passes/WasmIntrinsics.cpp

# files generated by build-js.sh
WebIDLGrammar.pkl
glue.cpp
glue.js
parser.out
shared.bc

# autogenerated files by check.py
a.*
b.*
c.*
ab.wast
actual.out
example.o
split.wast
trace.cpp
test/wasm-binaries-*.tbz2
test/wasm-torture-s-*.tbz2
test/wasm-install/
test/validator/*.wasm
*.map

# files related to building in-tree
CMakeFiles/
CMakeCache.txt
Makefile
cmake_install.cmake
*.ninja
.ninja_deps
.ninja_log
bin/wasm-shell
bin/wasm-opt
bin/asm2wasm
bin/wasm2asm
bin/wasm-as
bin/wasm-dis
bin/wasm-ctor-eval
bin/wasm-emscripten-finalize
bin/wasm-merge
bin/wasm-metadce
bin/wasm-reduce
bin/wasm2js
lib/

# files related to windows build
.vs/
*.vcxproj*
*.dir/
*.sln
*.sdf
*.VC.opendb
Win32/

# macOS
.DS_Store

# files related to VS Code
.history
.vscode
6 changes: 6 additions & 0 deletions external/binaryen/.gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[submodule "test/spec"]
path = test/spec
url = https://github.com/WebAssembly/testsuite.git
[submodule "test/emscripten"]
path = test/emscripten
url = https://github.com/kripken/emscripten.git
157 changes: 157 additions & 0 deletions external/binaryen/.travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
sudo: false
dist: trusty
language: cpp

stages:
- name: test
- name: build
# Don't run build stage for pull requests and other branches than master
# to save time and resources.
if: type != pull_request AND (branch = master OR tag IS present)

jobs:
include:
# Build with clang and run tests on the host system (Ubuntu).
- &test-ubuntu
stage: test
compiler: clang
python:
- 2.7
- 3.6
addons:
apt:
sources: ['ubuntu-toolchain-r-test']
packages: ['cmake', 'g++-5']
before_install:
- export ASAN_OPTIONS="symbolize=1"
install:
- nvm install 10
- nvm use 10
- pip install --user flake8==3.4.1
# get jsvu in order to get more js engines
- npm install jsvu -g
- export PATH="${HOME}/.jsvu:${PATH}"
- jsvu --os=linux64 --engines=spidermonkey
script:
- set -o errexit
- flake8
# ensure generated parser is up to date
- ./scripts/gen-s-parser.py | diff src/gen-s-parser.inc -
- BUILD_SUBDIR=${BUILD_SUBDIR:-.}
- mkdir -p ${BUILD_SUBDIR} && cd ${BUILD_SUBDIR}
- cmake ${TRAVIS_BUILD_DIR} -DCMAKE_C_FLAGS="$COMPILER_FLAGS" -DCMAKE_CXX_FLAGS="$COMPILER_FLAGS" -DCMAKE_INSTALL_PREFIX=install
- make -j2 install
- cd ${TRAVIS_BUILD_DIR}
- ./check.py --binaryen-bin=${BUILD_SUBDIR}/install/bin

- <<: *test-ubuntu
env: |
BUILD_SUBDIR=out

- <<: *test-ubuntu
env: |
COMPILER_FLAGS="-fsanitize=undefined -fno-sanitize-recover=all -fsanitize-blacklist=$(pwd)/ubsan.blacklist"

# FIXME we currently must disable LSAN entirely, see #1351
#- <<: *test-ubuntu
# env: |
# COMPILER_FLAGS="-fsanitize=address"

- <<: *test-ubuntu
env: |
COMPILER_FLAGS="-fsanitize=thread"

# Build with gcc 5 and run tests on the host system (Ubuntu).
- <<: *test-ubuntu
compiler: gcc
env: |
CC="gcc-5"
CXX="g++-5"

# Build the .js outputs using emcc
- &test-emcc
stage: test
compiler: clang
python: 2.7
language: node_js
sudo: required
services:
- docker
before_install:
- docker run -dit --name emscripten -v $(pwd):/src trzeci/emscripten:sdk-incoming-64bit bash
script:
# run binaryen.js and wasm.js tests before and after building, so we see if the bundled
# version is good too
- docker exec -it emscripten bash ./travis-emcc-tests.sh

# Build with gcc 6.3 and run tests on Alpine Linux (inside chroot).
# Note: Alpine uses musl libc.
- &test-alpine
stage: test
sudo: true
language: minimal
compiler: gcc
env: ARCH=x86_64
before_install:
- docker run -w /src -dit --name alpine -v $(pwd):/src node:10-alpine
- alpine() { docker exec -it alpine "$@"; }
install:
- alpine apk update
- alpine apk add build-base cmake git python2
script:
- alpine cmake .
- alpine make -j2
- alpine ./check.py

# Build statically linked release binaries with gcc 6.3 on Alpine Linux
# (inside chroot). If building a tagged commit, then deploy release tarball
# to GitHub Releases.
- &build-alpine
<<: *test-alpine
stage: build
env: ARCH=x86_64
# Don't run before_script inherited from *test-alpine.
before_script: skip
script:
- alpine cmake -DCMAKE_BUILD_TYPE=Release
-DCMAKE_VERBOSE_MAKEFILE=ON
-DCMAKE_CXX_FLAGS="-static -no-pie"
-DCMAKE_C_FLAGS="-static -no-pie" .
- alpine make -j2
- alpine find bin/ -type f -perm -u=x -exec strip {} +
- alpine ls -lh bin/
# Check if the built executables are really statically linked.
- if [ -n "$(find bin/ -type f -perm -u=x -exec file {} + | grep -Fvw 'statically linked')" ]; then
file bin/*; false;
fi
before_deploy:
- PKGNAME="binaryen-$TRAVIS_TAG-$ARCH-linux"
- mv bin binaryen-$TRAVIS_TAG
- tar -czf $PKGNAME.tar.gz binaryen-$TRAVIS_TAG
- sha256sum $PKGNAME.tar.gz > $PKGNAME.tar.gz.sha256
deploy:
provider: releases
api_key:
secure: "cu6CD5BaycXdCylvcs+Fho5+OVTkh9mZwH8RTnNpXo9hAQzLJDFgcNBHeXHEHtcp4IWf/YZSMu48UKnpU9sP5iF0AS4rtuEBJk5gOKkgB8GWnuIOePFkfANAZMN+EncuUwhAdN56iOAESXqnlHYgmJjyRVCHOxiezuWTOYui4lxoIAdxvOMJc3E9yfzUq4Epm2GDszSDN7ObmRIJpVgDXD9Sze1Xv4IkbIwc0biCmduGGLp3ow2KM+RZ4tOF0c8P0ki49vOFHr6n2Vmqg0QCiVNd4JJBRBCGn6Tzip2jsTQewnUUvpYCZafLeRV//v//voNA6ZUz91yXR23GIhkfdlyuqnz3/7l335Sa749M1lpYfSRWvwg9mJEqP66mxqTrWzj1xSItr9T+p0WhSmRN/4UEJPuItYPSma6kfv+H7qhLa3ZYKECH8hHW79grYmUWtiX0vQVIgnctJGgboPNLfG/1mNtmCI241wK0S3zvL2okdZH8/PqxfllYHMBTUp9lUrop8eoLKPgHZPm6+V20dgTUgOuGTZzTWwQ7Uk/Pg8JMUgkre5y0eo6pP3z0vDW1NNFNhouJ5oGkAeK/HAznr8Q0zWWF1vGFhoyC8ok/IJ7yKxK9scJVPBDe4oox6tr1zlsxzNEYE0/mY3JjuWV0z8RgjrIAbRe8IpGTkYz5VOM="
file: binaryen-$TRAVIS_TAG-*.tar.gz*
file_glob: true
skip_cleanup: true
on:
tags: true

# Build binaries for other architectures using QEMU user-mode emulation.
# Note: We don't run tests for these architectures, because some fail under
# QEMU/binfmt and it takes too long time (hits time limit on Travis).
# Note: We had to remove ppc64le, because it takes more than 50 minutes
# (Travis limit) to build. :(
- <<: *build-alpine
env: ARCH=x86

- <<: *build-alpine
env: ARCH=aarch64

- <<: *build-alpine
env: ARCH=armhf

notifications:
email: false
31 changes: 31 additions & 0 deletions external/binaryen/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
This document describes changes between tagged Binaryen versions.

To browse or download snapshots of old tagged versions, visit
https://github.com/WebAssembly/binaryen/releases.

Not all changes are documented here. In particular, new features, user-oriented
fixes, options, command-line parameters, usage changes, deprecations,
significant internal modifications and optimizations etc. generally deserve a
mention. To examine the full set of changes between versions, visit the link to
full changeset diff at the end of each section.

Current Trunk
-------------

### BREAKING CHANGES (old to new)

v.55
====
- `RelooperCreate` in the C API now has a Module parameter, and `RelooperRenderAndDispose` does not.
- The JS API now has the `Relooper` constructor receive the `Module`.
- Relooper: Condition properties on Branches must not have side effects.

older
=====

- `BinaryenSetFunctionTable` in the C API no longer accepts an array of functions, instead it accepts an array of function names, `const char** funcNames`. Previously, you could not include imported functions because they are of type `BinaryenImportRef` instead of `BinaryenFunctionRef`. #1650

- `BinaryenSetFunctionTable` in the C API now expects the initial and maximum table size as additional parameters, like `BinaryenSetMemory` does for pages, so tables can be grown dynamically. #1687

- Add `shared` parameters to `BinaryenAddMemoryImport` and `BinaryenSetMemory`, to support a shared memory. #1686

Loading