├── .dockerignore ├── .gitignore ├── Dockerfile ├── LICENSE ├── Makefile ├── README.md ├── images ├── invcond.png ├── qt_memory.png └── visual.png ├── install.sh ├── plasma ├── __init__.py ├── lib │ ├── __init__.py │ ├── analyzer.py │ ├── api.py │ ├── arch │ │ ├── __init__.py │ │ ├── arm │ │ │ ├── __init__.py │ │ │ ├── analyzer.c │ │ │ ├── output.py │ │ │ ├── process_ast.py │ │ │ └── utils.py │ │ ├── mips │ │ │ ├── __init__.py │ │ │ ├── analyzer.c │ │ │ ├── output.py │ │ │ ├── process_ast.py │ │ │ └── utils.py │ │ └── x86 │ │ │ ├── __init__.py │ │ │ ├── analyzer.c │ │ │ ├── int80.py │ │ │ ├── output.py │ │ │ ├── process_ast.py │ │ │ └── utils.py │ ├── ast.py │ ├── colors.py │ ├── consts.py │ ├── custom_colors.py │ ├── database.py │ ├── disassembler.py │ ├── exceptions.py │ ├── fileformat │ │ ├── __init__.py │ │ ├── binary.py │ │ ├── elf.py │ │ ├── pe.py │ │ ├── pefile2.py │ │ ├── raw.py │ │ └── relocations │ │ │ ├── LICENSE │ │ │ ├── README │ │ │ ├── __init__.py │ │ │ ├── amd64.py │ │ │ ├── arm.py │ │ │ ├── arm64.py │ │ │ ├── defines.py │ │ │ ├── generic.py │ │ │ ├── i386.py │ │ │ ├── mips.py │ │ │ ├── mips64.py │ │ │ ├── ppc.py │ │ │ └── ppc64.py │ ├── generate_ast.py │ ├── graph.py │ ├── memmap.py │ ├── memory.py │ ├── output.py │ ├── ui │ │ ├── __init__.py │ │ ├── console.py │ │ ├── disasmbox.py │ │ ├── inlineed.py │ │ ├── listbox.py │ │ ├── utils.py │ │ ├── vim.py │ │ ├── visual.py │ │ ├── widget.py │ │ └── window.py │ └── utils.py ├── main.py └── scripts │ ├── asm.py │ ├── crypto.py │ ├── disasm.py │ ├── strings.py │ └── xrefsto.py ├── requirements.txt ├── run_plasma.py ├── setup.py ├── test_plasma.py └── tests ├── analyzer ├── arrays.bin ├── arrays.c ├── arrays.py ├── arrays.rev ├── ifexit.bin ├── ifexit.c ├── ifexit.py ├── ifexit.rev ├── invert_cond.bin ├── invert_cond.c ├── invert_cond.py ├── invert_cond.rev ├── mips_prefetch.bin ├── mips_prefetch.py ├── mips_prefetch.rev ├── overlap.S ├── overlap.bin ├── overlap.py ├── overlap.rev ├── pusha.S ├── pusha.bin ├── pusha.py ├── pusha.rev ├── regsim.S ├── regsim.bin ├── regsim.py ├── regsim.rev ├── run.sh ├── stack.S ├── stack.bin ├── stack.py ├── stack.rev ├── switch.bin ├── switch.c ├── switch.py └── switch.rev ├── and1.bin ├── and1.c ├── and1.rev ├── and2.bin ├── and2.c ├── and2.rev ├── and3.bin ├── and3.c ├── and3.rev ├── and4.bin ├── and4.c ├── and4.rev ├── andor1.bin ├── andor1.c ├── andor1.rev ├── andor2.bin ├── andor2.c ├── andor2.rev ├── andor3.bin ├── andor3.c ├── andor3.rev ├── andor4.bin ├── andor4.c ├── andor4.rev ├── andor5.bin ├── andor5.c ├── andor5.rev ├── andor6.bin ├── andor6.c ├── andor6.rev ├── break1.bin ├── break1.c ├── break1.rev ├── break2.bin ├── break2.c ├── break2.rev ├── break3.bin ├── break3.c ├── break3.rev ├── canary_plt.bin ├── canary_plt.c ├── canary_plt.rev ├── chars1.bin ├── chars1.c ├── chars1.rev ├── continue1.bin ├── continue1.c ├── continue1.rev ├── continue2.bin ├── continue2.c ├── continue2.rev ├── continue3.bin ├── continue3.c ├── continue3.rev ├── diff.sh ├── dowhile1.bin ├── dowhile1.c ├── dowhile1.rev ├── dowhile2..rev ├── dowhile2.bin ├── dowhile2.c ├── dowhile2.rev ├── dowhile3.bin ├── dowhile3.c ├── dowhile3.rev ├── dowhile4.bin ├── dowhile4.c ├── dowhile4.rev ├── entryloop1.bin ├── entryloop1.c ├── entryloop1_0x4041b0.rev ├── goto1.bin ├── goto1.c ├── goto1.rev ├── goto2.bin ├── goto2.c ├── goto2.rev ├── goto3.bin ├── goto3.c ├── goto3.rev ├── goto4.bin ├── goto4.c ├── goto4.rev ├── goto5.bin ├── goto5.c ├── goto5.rev ├── goto6.bin ├── goto6.c ├── goto6.rev ├── goto7.bin ├── goto7.c ├── goto7.rev ├── goto8.bin ├── goto8.c ├── goto8.rev ├── goto9.bin ├── goto9.c ├── goto9.rev ├── gotoinloop1.bin ├── gotoinloop1.c ├── gotoinloop1.rev ├── gotoinloop10.bin ├── gotoinloop10.c ├── gotoinloop10.rev ├── gotoinloop11.bin ├── gotoinloop11.c ├── gotoinloop11.rev ├── gotoinloop12.bin ├── gotoinloop12.c ├── gotoinloop12.rev ├── gotoinloop13.bin ├── gotoinloop13.c ├── gotoinloop13.rev ├── gotoinloop14.bin ├── gotoinloop14.c ├── gotoinloop14.rev ├── gotoinloop15.bin ├── gotoinloop15.c ├── gotoinloop15.rev ├── gotoinloop16.bin ├── gotoinloop16.c ├── gotoinloop16.rev ├── gotoinloop17.bin ├── gotoinloop17.c ├── gotoinloop17.rev ├── gotoinloop18.bin ├── gotoinloop18.c ├── gotoinloop18.rev ├── gotoinloop19.bin ├── gotoinloop19.c ├── gotoinloop19.rev ├── gotoinloop2.bin ├── gotoinloop2.c ├── gotoinloop2.rev ├── gotoinloop20_2_nestedloop7.bin ├── gotoinloop20_2_nestedloop7.rev ├── gotoinloop20_nestedloop7.bin ├── gotoinloop20_nestedloop7.c ├── gotoinloop20_nestedloop7.rev ├── gotoinloop3.bin ├── gotoinloop3.c ├── gotoinloop3.rev ├── gotoinloop4.bin ├── gotoinloop4.c ├── gotoinloop4.rev ├── gotoinloop5.bin ├── gotoinloop5.c ├── gotoinloop5.rev ├── gotoinloop6.bin ├── gotoinloop6.c ├── gotoinloop6.rev ├── gotoinloop7.bin ├── gotoinloop7.c ├── gotoinloop7.rev ├── gotoinloop8.bin ├── gotoinloop8.c ├── gotoinloop8.rev ├── gotoinloop9.bin ├── gotoinloop9.c ├── gotoinloop9.rev ├── if1.bin ├── if1.c ├── if1.rev ├── if2.bin ├── if2.c ├── if2.rev ├── if3.bin ├── if3.c ├── if3.rev ├── if4.bin ├── if4.c ├── if4.rev ├── if5.bin ├── if5.c ├── if5.rev ├── if6.bin ├── if6.c ├── if6.rev ├── if7.bin ├── if7.c ├── if7.rev ├── if8.bin ├── if8.c ├── if8.rev ├── if9.bin ├── if9.c ├── if9.rev ├── jump_is_loop.bin ├── jump_is_loop.c ├── jump_is_loop.rev ├── loopends1.bin ├── loopends1.c ├── loopends1.rev ├── loopends2.bin ├── loopends2.c ├── loopends2.rev ├── loopinf1.bin ├── loopinf1.c ├── loopinf1.rev ├── loopinf2.bin ├── loopinf2.c ├── loopinf2.rev ├── loopinf3.bin ├── loopinf3.c ├── loopinf3.rev ├── loopinf4.bin ├── loopinf4.c ├── loopinf4.rev ├── nestedloop1.bin ├── nestedloop1.c ├── nestedloop1.rev ├── nestedloop2.bin ├── nestedloop2.c ├── nestedloop2.rev ├── nestedloop3.bin ├── nestedloop3.c ├── nestedloop3.rev ├── nestedloop4.bin ├── nestedloop4.c ├── nestedloop4.rev ├── nestedloop5.bin ├── nestedloop5.c ├── nestedloop5.rev ├── nestedloop6.bin ├── nestedloop6.c ├── nestedloop6.rev ├── nestedloop7.bin ├── nestedloop7.rev ├── or1.bin ├── or1.c ├── or1.rev ├── or2.bin ├── or2.c ├── or2.rev ├── or3.bin ├── or3.c ├── or3.rev ├── or4.bin ├── or4.c ├── or4.rev ├── pendu.bin ├── pendu.c ├── pendu____main.rev ├── pendu___imp___cexit.rev ├── pendu__main.rev ├── regen.sh ├── return1.bin ├── return1.c ├── return1.rev ├── return2.bin ├── return2.c ├── return2.rev ├── server.bin ├── server.c ├── server_connection_handler.rev ├── server_main.rev ├── shellcode.bin ├── shellcode.c ├── shellcode_0x0.rev ├── strlen.bin ├── strlen.c ├── strlen.rev ├── x86.bin ├── x86.c └── x86.rev /.dockerignore: -------------------------------------------------------------------------------- 1 | .git 2 | .gitignore 3 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | __pycache__/ 2 | *.py[cod] 3 | build 4 | *.so 5 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | # docker build -t plasma:latest . 2 | # docker run --rm -ti plasma:latest 3 | 4 | FROM ubuntu:16.04 5 | MAINTAINER netantho@gmail.com 6 | 7 | ENV LC_ALL C 8 | ENV DEBIAN_FRONTEND noninteractive 9 | ENV TERM xterm-256color 10 | 11 | RUN apt-get update --fix-missing && apt-get -y install --no-install-recommends \ 12 | python3-pip \ 13 | python3-dev \ 14 | python3-setuptools \ 15 | python3-wheel \ 16 | git \ 17 | build-essential \ 18 | sudo 19 | 20 | ADD . /plasma 21 | RUN cd /plasma && /plasma/install.sh 22 | 23 | WORKDIR /plasma 24 | ENTRYPOINT ["/plasma/run_plasma.py"] 25 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | TESTS_DIR = tests 2 | SRC = $(shell ls -d $(TESTS_DIR)/*.c) 3 | REV = $(patsubst $(TESTS_DIR)/%.c, $(TESTS_DIR)/%.rev, $(SRC)) 4 | BIN = $(patsubst $(TESTS_DIR)/%.c, $(TESTS_DIR)/%.bin, $(SRC)) 5 | .PHONY : all check compile FORCE clean 6 | 7 | FLAGS[tests/server.c] = "-lpthread" 8 | FLAGS[tests/canary_plt.c] = "-fstack-protector" 9 | FLAGS[tests/strlen.c] = "-Os" 10 | FLAGS[tests/andor5.c] = "-O3" 11 | FLAGS[tests/andor6.c] = "-O3" 12 | 13 | SYMBOLS[tests/server.rev] = "main" "connection_handler" 14 | SYMBOLS[tests/pendu.rev] = "_main" "___main" "__imp___cexit" 15 | SYMBOLS[tests/shellcode.rev] = "0x0" 16 | SYMBOLS[tests/entryloop1.rev] = "0x4041b0" 17 | 18 | OPTIONS[tests/shellcode.rev] = "--raw x86" 19 | OPTIONS[tests/entryloop1.rev] = "--raw x64 --rawbase 0x4041b0" 20 | 21 | all: check 22 | 23 | 24 | check: 25 | @python3 test_plasma.py 26 | @cd tests/analyzer && ./run.sh 27 | 28 | 29 | # Verbose : print the diff at each test 30 | # set the variable V=1 on the commande line 31 | 32 | 33 | # Don't rebuild. We want to keep the original rev file. 34 | # You need to recreate the file .rev at hand (with the options -nc -ns) 35 | # Or you can use the file regen.sh 36 | oldcheck: $(REV) 37 | FORCE: 38 | $(TESTS_DIR)/%.rev: FORCE 39 | @./tests/diff.sh $@ ${OPTIONS[$@]} ${V} $(SYMBOLS[$@]) 40 | 41 | 42 | clean: 43 | @rm -f tmp* 44 | 45 | 46 | compile: $(BIN) 47 | $(TESTS_DIR)/%.bin: $(TESTS_DIR)/%.c 48 | gcc $< $(FLAGS[$^]) -o $@ 49 | -------------------------------------------------------------------------------- /images/invcond.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/plasma-disassembler/plasma/ec7df9b2b9b356dd5d8caf01b7e68c0ab5a1ef42/images/invcond.png -------------------------------------------------------------------------------- /images/qt_memory.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/plasma-disassembler/plasma/ec7df9b2b9b356dd5d8caf01b7e68c0ab5a1ef42/images/qt_memory.png -------------------------------------------------------------------------------- /images/visual.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/plasma-disassembler/plasma/ec7df9b2b9b356dd5d8caf01b7e68c0ab5a1ef42/images/visual.png -------------------------------------------------------------------------------- /install.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | umask 002 4 | 5 | if [ "$1" != "--update" ]; then 6 | if [ $(tput colors) -ne 256 ]; then 7 | echo -n "warning: your terminal doesn't support 256 colors, continue ? [Y/n] " 8 | read line 9 | if [ "$line" == "n" ]; then 10 | exit 11 | fi 12 | fi 13 | 14 | REQ_EXEC="python3 pip3 c++filt" 15 | for EXEC in ${REQ_EXEC} 16 | do 17 | if [ ! -x "$(command -v $EXEC)" ] 18 | then 19 | echo "error: unable to find $EXEC, this is required to setup this project" 20 | exit 21 | fi 22 | done 23 | 24 | PYTHON_VERSION=`python3 -c 'import sys; print("%i" % (sys.hexversion<0x03040000))'` 25 | if [ $PYTHON_VERSION -ne 0 ]; then 26 | echo "error: you need at least python 3.4 to run this project" 27 | exit 28 | fi 29 | 30 | # Capstone 31 | pushd . > /dev/null 32 | mkdir -p build 33 | cd build 34 | CAPSTONE_VERSION="4.0-alpha5" 35 | if [ -d capstone_$CAPSTONE_VERSION ]; then 36 | cd capstone_$CAPSTONE_VERSION 37 | make clean 38 | else 39 | git clone -b $CAPSTONE_VERSION --depth 1 https://github.com/aquynh/capstone 40 | mv capstone capstone_$CAPSTONE_VERSION 41 | cd capstone_$CAPSTONE_VERSION 42 | fi 43 | ./make.sh 44 | sudo -H ./make.sh install 45 | cd bindings/python/ 46 | make install3 47 | popd > /dev/null 48 | 49 | sudo -H pip3 install -r requirements.txt 50 | sudo -H pip3 install future 51 | fi 52 | 53 | python3 setup.py build_ext --inplace 54 | 55 | # Or create an alias to run_plasma.py 56 | sudo -H python3 setup.py install 57 | -------------------------------------------------------------------------------- /plasma/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/plasma-disassembler/plasma/ec7df9b2b9b356dd5d8caf01b7e68c0ab5a1ef42/plasma/__init__.py -------------------------------------------------------------------------------- /plasma/lib/arch/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/plasma-disassembler/plasma/ec7df9b2b9b356dd5d8caf01b7e68c0ab5a1ef42/plasma/lib/arch/__init__.py -------------------------------------------------------------------------------- /plasma/lib/arch/arm/__init__.py: -------------------------------------------------------------------------------- 1 | import plasma.lib.arch.arm.output 2 | import plasma.lib.arch.arm.utils 3 | import plasma.lib.arch.arm.process_ast 4 | 5 | registered = [ 6 | process_ast.convert_cond_to_if, 7 | process_ast.fuse_inst_with_if, 8 | ] 9 | -------------------------------------------------------------------------------- /plasma/lib/arch/mips/__init__.py: -------------------------------------------------------------------------------- 1 | import plasma.lib.arch.mips.output 2 | import plasma.lib.arch.mips.utils 3 | import plasma.lib.arch.mips.process_ast 4 | 5 | registered = [ 6 | # TODO 7 | process_ast.fuse_inst_with_if, 8 | ] 9 | -------------------------------------------------------------------------------- /plasma/lib/arch/mips/process_ast.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # 3 | # PLASMA : Generate an indented asm code (pseudo-C) with colored syntax. 4 | # Copyright (C) 2015 Joel 5 | # 6 | # This program is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License as published by 8 | # the Free Software Foundation, either version 3 of the License, or 9 | # (at your option) any later version. 10 | # 11 | # This program is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU General Public License 17 | # along with this program. If not, see . 18 | # 19 | 20 | from capstone.mips import (MIPS_OP_IMM, MIPS_INS_ADDIU, MIPS_INS_ORI, 21 | MIPS_INS_LUI, MIPS_OP_REG, MIPS_REG_ZERO, MipsOpValue) 22 | 23 | from plasma.lib.ast import (Ast_Branch, Ast_Loop, Ast_IfGoto, Ast_Ifelse, 24 | Ast_AndIf, Ast_If_cond) 25 | from plasma.lib.arch.mips.output import ASSIGNMENT_OPS 26 | 27 | 28 | FUSE_OPS = set(ASSIGNMENT_OPS) 29 | 30 | 31 | def fuse_inst_with_if(ctx, ast): 32 | if isinstance(ast, Ast_Branch): 33 | types_ast = (Ast_Ifelse, Ast_IfGoto, Ast_AndIf, Ast_If_cond) 34 | for i, n in enumerate(ast.nodes): 35 | if isinstance(n, list): 36 | if n[-1].id in FUSE_OPS and i + 1 < len(ast.nodes) \ 37 | and isinstance(ast.nodes[i + 1], types_ast): 38 | ast.nodes[i + 1].fused_inst = n[-1] 39 | ctx.all_fused_inst.add(n[-1].address) 40 | else: # ast 41 | fuse_inst_with_if(ctx, n) 42 | 43 | elif isinstance(ast, Ast_Ifelse): 44 | ast.fused_inst = ast.jump_inst 45 | fuse_inst_with_if(ctx, ast.br_next) 46 | fuse_inst_with_if(ctx, ast.br_next_jump) 47 | 48 | elif isinstance(ast, Ast_Loop): 49 | fuse_inst_with_if(ctx, ast.branch) 50 | 51 | -------------------------------------------------------------------------------- /plasma/lib/arch/x86/__init__.py: -------------------------------------------------------------------------------- 1 | import plasma.lib.arch.x86.output 2 | import plasma.lib.arch.x86.utils 3 | import plasma.lib.arch.x86.process_ast 4 | import plasma.lib.arch.x86.int80 5 | 6 | registered = [ 7 | process_ast.fuse_inst_with_if, 8 | int80.int80, 9 | ] 10 | -------------------------------------------------------------------------------- /plasma/lib/custom_colors.py: -------------------------------------------------------------------------------- 1 | # Warning: don't use colors 1-16, they will be used to redefine colors 2 | # with background. 3 | 4 | class COLOR: 5 | def __init__(self, val, bold): 6 | self.val = val 7 | self.bold = bold 8 | 9 | COLOR_SECTION = COLOR(81, False) 10 | COLOR_KEYWORD = COLOR(161, True) 11 | 12 | # Don't reuse this color for other tokens 13 | # COLOR_VAR is also used to detect if a token has the type VAR 14 | # FIXME: lib.ui.window.get_tok_type_under_cursor 15 | COLOR_VAR = COLOR(214, False) 16 | 17 | COLOR_TYPE = COLOR(81, False) 18 | COLOR_COMMENT = COLOR(242, False) 19 | COLOR_ADDR = COLOR(242, False) 20 | COLOR_SYMBOL = COLOR(144, False) 21 | COLOR_RETCALL = COLOR(161, False) 22 | COLOR_INTERN_COMMENT = COLOR(217, False) 23 | COLOR_CODE_ADDR = COLOR(226, False) 24 | COLOR_USER_COMMENT = COLOR(38, False) 25 | COLOR_UNK = COLOR(154, False) 26 | COLOR_DATA = COLOR(230, False) 27 | COLOR_STRING = COLOR(154, False) 28 | COLOR_OFFSET_NOT_FOUND = COLOR(196, False) 29 | COLOR_PUSHPOP = COLOR(171, False) 30 | COLOR_ERROR = COLOR(161, True) 31 | 32 | # This couple will redefine the color 1 33 | COLOR_SEARCH_BG = 66 34 | COLOR_SEARCH_FG = 253 35 | 36 | COLOR_SCROLL_CURSOR = 238 37 | -------------------------------------------------------------------------------- /plasma/lib/exceptions.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # 3 | # PLASMA : Generate an indented asm code (pseudo-C) with colored syntax. 4 | # Copyright (C) 2015 Joel 5 | # 6 | # This program is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License as published by 8 | # the Free Software Foundation, either version 3 of the License, or 9 | # (at your option) any later version. 10 | # 11 | # This program is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU General Public License 17 | # along with this program. If not, see . 18 | # 19 | 20 | 21 | class ExcArch(Exception): 22 | def __init__(self, arch): 23 | self.arch = arch 24 | 25 | 26 | class ExcElf(Exception): 27 | pass 28 | 29 | 30 | class ExcFileFormat(Exception): 31 | pass 32 | 33 | 34 | class ExcIfelse(Exception): 35 | def __init__(self, addr): 36 | self.addr = addr 37 | 38 | 39 | class ExcPEFail(Exception): 40 | def __init__(self, e): 41 | self.e = e 42 | -------------------------------------------------------------------------------- /plasma/lib/fileformat/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/plasma-disassembler/plasma/ec7df9b2b9b356dd5d8caf01b7e68c0ab5a1ef42/plasma/lib/fileformat/__init__.py -------------------------------------------------------------------------------- /plasma/lib/fileformat/raw.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # 3 | # PLASMA : Generate an indented asm code (pseudo-C) with colored syntax. 4 | # Copyright (C) 2015 Joel 5 | # 6 | # This program is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License as published by 8 | # the Free Software Foundation, either version 3 of the License, or 9 | # (at your option) any later version. 10 | # 11 | # This program is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU General Public License 17 | # along with this program. If not, see . 18 | # 19 | 20 | from plasma.lib.fileformat.binary import SectionAbs, Binary 21 | 22 | 23 | class Raw(Binary): 24 | def __init__(self, filename, raw_type, raw_base, raw_big_endian): 25 | Binary.__init__(self) 26 | 27 | self.raw = open(filename, "rb").read() 28 | self.raw_base = raw_base 29 | self.raw_big_endian = raw_big_endian 30 | 31 | arch_lookup = { 32 | "x86": "x86", 33 | "x64": "x64", 34 | "arm": "ARM", 35 | "mips": "MIPS32", 36 | "mips64": "MIPS64", 37 | } 38 | 39 | self.arch = arch_lookup.get(raw_type, None) 40 | 41 | self.add_section( 42 | raw_base, 43 | "raw", 44 | len(self.raw), 45 | len(self.raw), 46 | False, # is_exec 47 | True, # is_data 48 | False, # is_bss 49 | self.raw) 50 | 51 | 52 | def is_big_endian(self): 53 | return self.raw_big_endian 54 | 55 | 56 | def get_entry_point(self): 57 | return self.raw_base 58 | -------------------------------------------------------------------------------- /plasma/lib/fileformat/relocations/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2015, The Regents of the University of California 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are met: 6 | 7 | * Redistributions of source code must retain the above copyright notice, this 8 | list of conditions and the following disclaimer. 9 | 10 | * Redistributions in binary form must reproduce the above copyright notice, 11 | this list of conditions and the following disclaimer in the documentation 12 | and/or other materials provided with the distribution. 13 | 14 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 15 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 18 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 20 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 21 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 22 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | 25 | -------------------------------------------------------------------------------- /plasma/lib/fileformat/relocations/README: -------------------------------------------------------------------------------- 1 | These files comes from the project https://github.com/angr/cle 2 | -------------------------------------------------------------------------------- /plasma/lib/fileformat/relocations/__init__.py: -------------------------------------------------------------------------------- 1 | import sys 2 | 3 | from .generic import Relocation 4 | from .defines import defines 5 | from plasma.lib.utils import warning 6 | from . import arm64, i386, mips64, ppc64, amd64, arm, mips, ppc 7 | 8 | ALL_RELOCATIONS = {} 9 | complaint_log = set() 10 | 11 | 12 | def load_relocations(): 13 | for module in [arm64, i386, mips64, ppc64, amd64, arm, mips, ppc]: 14 | try: 15 | arch_name = module.arch 16 | except AttributeError: 17 | continue 18 | 19 | for item_name in dir(module): 20 | if item_name not in defines: 21 | continue 22 | item = getattr(module, item_name) 23 | if not isinstance(item, type) or not issubclass(item, Relocation): 24 | continue 25 | 26 | if arch_name not in ALL_RELOCATIONS: 27 | ALL_RELOCATIONS[arch_name] = {} 28 | ALL_RELOCATIONS[arch_name][defines[item_name]] = item 29 | 30 | 31 | def get_relocation(arch, r_type): 32 | if r_type == 0: 33 | return None 34 | try: 35 | return ALL_RELOCATIONS[arch][r_type] 36 | except KeyError: 37 | if (arch, r_type) not in complaint_log: 38 | complaint_log.add((arch, r_type)) 39 | warning("Unknown reloc %d on %s" % (r_type, arch)) 40 | return None 41 | 42 | 43 | load_relocations() 44 | -------------------------------------------------------------------------------- /plasma/lib/fileformat/relocations/amd64.py: -------------------------------------------------------------------------------- 1 | from . import generic 2 | 3 | arch = 'x64' 4 | 5 | R_X86_64_64 = generic.GenericAbsoluteAddendReloc 6 | R_X86_64_COPY = generic.GenericCopyReloc 7 | R_X86_64_GLOB_DAT = generic.GenericJumpslotReloc 8 | R_X86_64_JUMP_SLOT = generic.GenericJumpslotReloc 9 | R_X86_64_RELATIVE = generic.GenericRelativeReloc 10 | R_X86_64_IRELATIVE = generic.GenericIRelativeReloc 11 | 12 | R_X86_64_DTPMOD64 = generic.GenericTLSModIdReloc 13 | R_X86_64_DTPOFF64 = generic.GenericTLSDoffsetReloc 14 | R_X86_64_TPOFF64 = generic.GenericTLSOffsetReloc 15 | -------------------------------------------------------------------------------- /plasma/lib/fileformat/relocations/arm.py: -------------------------------------------------------------------------------- 1 | from . import generic 2 | 3 | # http://infocenter.arm.com/help/topic/com.arm.doc.ihi0044e/IHI0044E_aaelf.pdf 4 | arch = 'ARM' 5 | 6 | R_ARM_COPY = generic.GenericCopyReloc 7 | R_ARM_GLOB_DAT = generic.GenericJumpslotReloc 8 | R_ARM_JUMP_SLOT = generic.GenericJumpslotReloc 9 | R_ARM_RELATIVE = generic.GenericRelativeReloc 10 | R_ARM_ABS32 = generic.GenericAbsoluteAddendReloc 11 | 12 | R_ARM_TLS_DTPMOD32 = generic.GenericTLSModIdReloc 13 | R_ARM_TLS_DTPOFF32 = generic.GenericTLSDoffsetReloc 14 | R_ARM_TLS_TPOFF32 = generic.GenericTLSOffsetReloc 15 | -------------------------------------------------------------------------------- /plasma/lib/fileformat/relocations/arm64.py: -------------------------------------------------------------------------------- 1 | from . import generic 2 | 3 | # http://infocenter.arm.com/help/topic/com.arm.doc.ihi0056b/IHI0056B_aaelf64.pdf 4 | arch = 'AARCH64' 5 | 6 | R_AARCH64_ABS64 = generic.GenericAbsoluteAddendReloc 7 | R_AARCH64_COPY = generic.GenericCopyReloc 8 | R_AARCH64_GLOB_DAT = generic.GenericJumpslotReloc 9 | R_AARCH64_JUMP_SLOT = generic.GenericJumpslotReloc 10 | R_AARCH64_RELATIVE = generic.GenericRelativeReloc 11 | R_AARCH64_IRELATIVE = generic.GenericIRelativeReloc 12 | R_AARCH64_TLS_DTPREL = generic.GenericTLSDoffsetReloc 13 | R_AARCH64_TLS_DTPMOD = generic.GenericTLSModIdReloc 14 | R_AARCH64_TLS_TPREL = generic.GenericTLSOffsetReloc 15 | -------------------------------------------------------------------------------- /plasma/lib/fileformat/relocations/i386.py: -------------------------------------------------------------------------------- 1 | from . import generic 2 | 3 | arch = 'x86' 4 | 5 | R_386_32 = generic.GenericAbsoluteAddendReloc 6 | R_386_COPY = generic.GenericCopyReloc 7 | R_386_GLOB_DAT = generic.GenericJumpslotReloc 8 | R_386_JMP_SLOT = generic.GenericJumpslotReloc 9 | R_386_RELATIVE = generic.GenericRelativeReloc 10 | R_386_IRELATIVE = generic.GenericIRelativeReloc 11 | 12 | R_386_TLS_DTPMOD32 = generic.GenericTLSModIdReloc 13 | R_386_TLS_TPOFF = generic.GenericTLSOffsetReloc 14 | R_386_TLS_DTPOFF32 = generic.GenericTLSDoffsetReloc 15 | 16 | class R_386_PC32(generic.Relocation): 17 | @property 18 | def value(self): 19 | return self.resolvedby.rebased_addr + self.addend - self.rebased_addr 20 | -------------------------------------------------------------------------------- /plasma/lib/fileformat/relocations/mips.py: -------------------------------------------------------------------------------- 1 | from . import generic 2 | 3 | arch = 'MIPS32' 4 | 5 | R_MIPS_32 = generic.GenericAbsoluteAddendReloc 6 | R_MIPS_REL32 = generic.GenericRelativeReloc 7 | R_MIPS_TLS_DTPMOD32 = generic.GenericTLSModIdReloc 8 | R_MIPS_TLS_TPREL32 = generic.GenericTLSOffsetReloc 9 | R_MIPS_TLS_DTPREL32 = generic.GenericTLSDoffsetReloc 10 | R_MIPS_JUMP_SLOT = generic.GenericAbsoluteReloc 11 | R_MIPS_GLOB_DAT = generic.GenericAbsoluteReloc 12 | -------------------------------------------------------------------------------- /plasma/lib/fileformat/relocations/mips64.py: -------------------------------------------------------------------------------- 1 | from . import generic 2 | 3 | arch = 'MIPS64' 4 | 5 | R_MIPS_64 = generic.GenericAbsoluteAddendReloc 6 | R_MIPS_REL32 = generic.GenericRelativeReloc 7 | R_MIPS_COPY = generic.GenericCopyReloc 8 | R_MIPS_TLS_DTPMOD64 = generic.GenericTLSModIdReloc 9 | R_MIPS_TLS_DTPREL64 = generic.GenericTLSDoffsetReloc 10 | R_MIPS_TLS_TPREL64 = generic.GenericTLSOffsetReloc 11 | -------------------------------------------------------------------------------- /plasma/lib/fileformat/relocations/ppc.py: -------------------------------------------------------------------------------- 1 | from . import generic 2 | 3 | # http://www.polyomino.org.uk/publications/2011/Power-Arch-32-bit-ABI-supp-1.0-Unified.pdf 4 | arch = 'PPC32' 5 | 6 | R_PPC_ADDR32 = generic.GenericAbsoluteAddendReloc 7 | R_PPC_COPY = generic.GenericCopyReloc 8 | R_PPC_GLOB_DAT = generic.GenericJumpslotReloc 9 | R_PPC_JMP_SLOT = generic.GenericJumpslotReloc 10 | R_PPC_RELATIVE = generic.GenericRelativeReloc 11 | R_PPC_DTPMOD32 = generic.GenericTLSModIdReloc 12 | R_PPC_DTPREL32 = generic.GenericTLSDoffsetReloc 13 | R_PPC_TPREL32 = generic.GenericTLSOffsetReloc 14 | -------------------------------------------------------------------------------- /plasma/lib/fileformat/relocations/ppc64.py: -------------------------------------------------------------------------------- 1 | from . import generic 2 | 3 | # http://refspecs.linuxfoundation.org/ELF/ppc64/PPC-elf64abi-1.9.pdf 4 | arch = 'PPC64' 5 | 6 | class R_PPC64_JMP_SLOT(generic.Relocation): 7 | def relocate(self, solist): 8 | if not self.resolve_symbol(solist): 9 | return False 10 | 11 | if self.owner_obj.is_ppc64_abiv1: 12 | # R_PPC64_JMP_SLOT 13 | # http://osxr.org/glibc/source/sysdeps/powerpc/powerpc64/dl-machine.h?v=glibc-2.15#0405 14 | # copy an entire function descriptor struct 15 | addr = self.resolvedby.owner_obj.memory.read_addr_at(self.resolvedby.addr) 16 | toc = self.resolvedby.owner_obj.memory.read_addr_at(self.resolvedby.addr + 8) 17 | aux = self.resolvedby.owner_obj.memory.read_addr_at(self.resolvedby.addr + 16) 18 | self.owner_obj.memory.write_addr_at(self.addr, addr) 19 | self.owner_obj.memory.write_addr_at(self.addr + 8, toc) 20 | self.owner_obj.memory.write_addr_at(self.addr + 16, aux) 21 | else: 22 | self.owner_obj.memory.write_addr_at(self.addr, self.resolvedby.rebased_addr) 23 | return True 24 | 25 | R_PPC64_DTPMOD64 = generic.GenericTLSModIdReloc 26 | R_PPC64_DTPREL64 = generic.GenericTLSDoffsetReloc 27 | R_PPC64_TPREL64 = generic.GenericTLSOffsetReloc 28 | R_PPC64_RELATIVE = generic.GenericRelativeReloc 29 | R_PPC64_IRELATIVE = generic.GenericIRelativeReloc 30 | R_PPC64_ADDR64 = generic.GenericAbsoluteAddendReloc 31 | R_PPC64_GLOB_DAT = generic.GenericJumpslotReloc 32 | -------------------------------------------------------------------------------- /plasma/lib/ui/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/plasma-disassembler/plasma/ec7df9b2b9b356dd5d8caf01b7e68c0ab5a1ef42/plasma/lib/ui/__init__.py -------------------------------------------------------------------------------- /plasma/scripts/asm.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | from keystone import * 4 | 5 | 6 | arch_lookup = { 7 | "x86": KS_ARCH_X86, 8 | "x64": KS_ARCH_X86, 9 | "ARM": KS_ARCH_ARM, 10 | "MIPS32": KS_ARCH_MIPS, 11 | "MIPS64": KS_ARCH_MIPS, 12 | } 13 | 14 | mode_lookup = { 15 | "x86": KS_MODE_32, 16 | "x64": KS_MODE_64, 17 | "ARM": KS_ARCH_ARM, 18 | "MIPS32": KS_MODE_MIPS32, 19 | "MIPS64": KS_MODE_MIPS64, 20 | } 21 | 22 | endianness = { 23 | True: KS_MODE_BIG_ENDIAN, 24 | False: KS_MODE_LITTLE_ENDIAN, 25 | } 26 | 27 | 28 | if len(args) != 2: 29 | print("usage: asm.py 'multi line asm code with \\n'") 30 | else: 31 | code = args[1].replace("\\n", "\n") 32 | 33 | flags = mode_lookup[api.arch] | endianness[api.is_big_endian] 34 | ks = Ks(arch_lookup[api.arch], flags) 35 | 36 | buf, nb_stmts = ks.asm(code.encode()) 37 | 38 | for b in buf: 39 | print("%02x " % b, end="") 40 | 41 | print() 42 | -------------------------------------------------------------------------------- /plasma/scripts/disasm.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | import binascii 4 | from capstone import * 5 | 6 | 7 | arch_lookup = { 8 | "x86": CS_ARCH_X86, 9 | "x64": CS_ARCH_X86, 10 | "ARM": CS_ARCH_ARM, 11 | "MIPS32": CS_ARCH_MIPS, 12 | "MIPS64": CS_ARCH_MIPS, 13 | } 14 | 15 | mode_lookup = { 16 | "x86": CS_MODE_32, 17 | "x64": CS_MODE_64, 18 | "ARM": CS_ARCH_ARM, 19 | "MIPS32": CS_MODE_MIPS32, 20 | "MIPS64": CS_MODE_MIPS64, 21 | } 22 | 23 | endianness = { 24 | True: CS_MODE_BIG_ENDIAN, 25 | False: CS_MODE_LITTLE_ENDIAN, 26 | } 27 | 28 | 29 | if len(args) != 2: 30 | print("usage: diasm.py HEX_FORMAT") 31 | print("HEX_FORMAT can contain spaces or not") 32 | print("example disasm.py '80 3d 24 e9 04 08 00'") 33 | else: 34 | buf = binascii.unhexlify(args[1].replace(" ", "")) 35 | flags = mode_lookup[api.arch] | endianness[api.is_big_endian] 36 | cs = Cs(arch_lookup[api.arch], flags) 37 | 38 | for i in cs.disasm(buf, 0): 39 | print(i.mnemonic, i.op_str) 40 | -------------------------------------------------------------------------------- /plasma/scripts/strings.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | import pydoc 4 | 5 | buf = [] 6 | 7 | for s in api.iter_sections(): 8 | ad = s.start 9 | while ad < s.end: 10 | if api.is_string(ad, s): 11 | string = api.get_string(ad, s) 12 | if len(string) >= 3: 13 | buf.append("0x%x \"%s\"\n" % (ad, string.replace("\n", "\\n"))) 14 | ad += len(string) + 1 15 | else: 16 | ad += 1 17 | 18 | pydoc.pager("".join(buf)) 19 | -------------------------------------------------------------------------------- /plasma/scripts/xrefsto.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | import threading 4 | import os 5 | from tempfile import mkstemp 6 | from subprocess import call, DEVNULL 7 | 8 | DOT_BINARY = "/usr/bin/xdot" 9 | links = set() 10 | 11 | 12 | class Xdot(threading.Thread): 13 | def __init__(self, filename): 14 | threading.Thread.__init__(self) 15 | self.filename = filename 16 | 17 | def run(self): 18 | call([DOT_BINARY, filename], stderr=DEVNULL, stdout=DEVNULL) 19 | os.remove(filename) 20 | 21 | 22 | def rec_xref(output, first_ad, ad, depth): 23 | global links 24 | 25 | label = api.get_symbol(ad) 26 | 27 | if label is None: 28 | if api.mem.is_code(ad): 29 | o = api.dump_asm(ad, 1) 30 | label = "%s" % o.lines[0] 31 | else: 32 | return 33 | 34 | if ad == first_ad: 35 | output.write('node_%x [label="%s" fillcolor="#B6FFDD"];\n' % (ad, label)) 36 | else: 37 | output.write('node_%x [label="%s"];\n' % (ad, label)) 38 | 39 | if depth != -1: 40 | if depth == 0: 41 | return 42 | depth -= 1 43 | 44 | for x in api.xrefsto(ad): 45 | if api.mem.is_code(x): 46 | f = api.get_func_addr(x) 47 | if f is not None: 48 | x = f 49 | 50 | if (x, ad) not in links: 51 | links.add((x, ad)) 52 | output.write('node_%x -> node_%x;\n' % (x, ad)) 53 | rec_xref(output, first_ad, x, depth) 54 | 55 | 56 | if len(args) > 3 or len(args) <= 1: 57 | print("usage: xrefsto.py SYMBOL|0xXXXX|EP [maxdepth]") 58 | else: 59 | ad = api.get_addr_from_symbol(args[1]) 60 | depth = -1 if len(args) == 2 else int(args[2]) 61 | 62 | filename = mkstemp(prefix="plasma")[1] 63 | 64 | output = open(filename, "w+") 65 | output.write('digraph {\n') 66 | output.write('node [fontname="liberation mono" style=filled fillcolor=white shape=box];\n') 67 | 68 | if api.mem.is_code(ad): 69 | f = api.get_func_addr(ad) 70 | if f is not None: 71 | ad = f 72 | 73 | rec_xref(output, ad, ad, depth) 74 | output.write('}') 75 | output.close() 76 | 77 | Xdot(filename).start() 78 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | pefile 2 | pyelftools 3 | msgpack-python>=0.4.6 4 | nose 5 | -------------------------------------------------------------------------------- /run_plasma.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # 3 | # PLASMA : Generate an indented asm code (pseudo-C) with colored syntax. 4 | # Copyright (C) 2015 Joel 5 | # 6 | # This program is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License as published by 8 | # the Free Software Foundation, either version 3 of the License, or 9 | # (at your option) any later version. 10 | # 11 | # This program is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU General Public License 17 | # along with this program. If not, see . 18 | # 19 | 20 | from plasma.main import console_entry 21 | 22 | if __name__ == "__main__": 23 | console_entry() 24 | -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | try: 4 | from setuptools import setup, find_packages 5 | except ImportError: 6 | from distutils.core import setup 7 | 8 | try: 9 | from pip._internal.req import parse_requirements 10 | except ImportError: 11 | from pip.req import parse_requirements 12 | 13 | from distutils.core import Extension 14 | import plasma 15 | 16 | requirements = parse_requirements('requirements.txt', session=False) 17 | 18 | requires = [] 19 | for item in requirements: 20 | # we want to handle package names and also repo urls 21 | if getattr(item, 'url', None): # older pip has url 22 | links.append(str(item.url)) 23 | if getattr(item, 'link', None): # newer pip has link 24 | links.append(str(item.link)) 25 | if item.req: 26 | requires.append(str(item.req)) 27 | 28 | 29 | x86_analyzer = Extension('plasma.lib.arch.x86.analyzer', 30 | sources = ['plasma/lib/arch/x86/analyzer.c']) 31 | 32 | mips_analyzer = Extension('plasma.lib.arch.mips.analyzer', 33 | sources = ['plasma/lib/arch/mips/analyzer.c']) 34 | 35 | arm_analyzer = Extension('plasma.lib.arch.arm.analyzer', 36 | sources = ['plasma/lib/arch/arm/analyzer.c']) 37 | 38 | 39 | setup( 40 | name='plasma', 41 | version='1.0', 42 | url="https://github.com/joelpx/plasma", 43 | description='plasma disassembler for x86/ARM/MIPS', 44 | license="GPLv3", 45 | ext_modules=[ 46 | x86_analyzer, 47 | mips_analyzer, 48 | arm_analyzer, 49 | ], 50 | packages=['plasma', 51 | 'plasma.lib', 52 | 'plasma.lib.arch', 53 | 'plasma.lib.arch.x86', 54 | 'plasma.lib.arch.mips', 55 | 'plasma.lib.arch.arm', 56 | 'plasma.lib.ui', 57 | 'plasma.lib.fileformat', 58 | 'plasma.lib.fileformat.relocations', 59 | 'plasma.scripts', 60 | ], 61 | package_dir={'plasma':'plasma'}, 62 | install_requires=requires, 63 | entry_points = { 64 | "console_scripts": [ 65 | "plasma = plasma.main:console_entry", 66 | ], 67 | }, 68 | ) 69 | -------------------------------------------------------------------------------- /tests/analyzer/arrays.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/plasma-disassembler/plasma/ec7df9b2b9b356dd5d8caf01b7e68c0ab5a1ef42/tests/analyzer/arrays.bin -------------------------------------------------------------------------------- /tests/analyzer/arrays.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int global_array[] = {0,1,2,3,4,5,6,7,8,9}; 5 | char global_string[] = "this is a string.\n"; 6 | void *global_ptr[] = {global_array, global_string, global_string+4}; 7 | 8 | int main(int argc, char **argv) { 9 | int a = global_array[0]; 10 | int b = global_array[5]; 11 | int c = global_array[9]; 12 | char d = global_string[7]; 13 | void *p = global_ptr[0]; 14 | 15 | printf("%d\n", global_array[8]); 16 | printf("%s\n", global_string); 17 | printf("%s\n", global_string + 3); 18 | 19 | return 0; 20 | } 21 | -------------------------------------------------------------------------------- /tests/analyzer/arrays.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | 4 | def check(boolean): 5 | if boolean: 6 | print("ok") 7 | else: 8 | print("error") 9 | 10 | 11 | # Check some xrefs 12 | 13 | global_string = api.get_addr_from_symbol("global_string") 14 | global_ptr = api.get_addr_from_symbol("global_ptr") 15 | 16 | # in this order the xrefs failed before 17 | api.set_ascii(global_string) 18 | api.set_offset(global_ptr + 8, MEM_QWORD) # there is an address to global_string 19 | check(api.xrefsto(global_string) == {global_ptr + 8}) 20 | 21 | api.set_byte(global_ptr + 8) 22 | check(api.xrefsto(global_string) == set()) 23 | 24 | api.set_offset(global_ptr + 8, MEM_QWORD) 25 | check(api.xrefsto(global_string) == {global_ptr + 8}) 26 | 27 | api.set_byte(global_string) 28 | api.set_byte(global_ptr + 8) 29 | api.set_ascii(global_string) 30 | api.set_offset(global_ptr + 8, MEM_QWORD) 31 | check(api.xrefsto(global_string) == {global_ptr + 8}) 32 | 33 | 34 | # now analyze the code 35 | 36 | ep = api.entry_point() 37 | api.set_code(ep) 38 | 39 | ad = api.get_addr_from_symbol("global_array") 40 | api.set_array(ad, 10, MEM_DWORD) 41 | 42 | api.set_array(global_ptr, 3, MEM_QOFFSET) 43 | 44 | ad = api.get_addr_from_symbol(".text") 45 | s = api.get_section(ad) 46 | api.dump_asm(ad, until=s.end+1).print() 47 | 48 | ad = api.get_addr_from_symbol(".data") 49 | s = api.get_section(ad) 50 | api.dump_asm(ad, until=s.end+1).print() 51 | -------------------------------------------------------------------------------- /tests/analyzer/ifexit.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/plasma-disassembler/plasma/ec7df9b2b9b356dd5d8caf01b7e68c0ab5a1ef42/tests/analyzer/ifexit.bin -------------------------------------------------------------------------------- /tests/analyzer/ifexit.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() { 5 | int i, j; 6 | 7 | if (i == 0) { 8 | if (j == 0) { 9 | printf("exit\n"); 10 | exit(0); 11 | } 12 | 13 | for (i = 0 ; i < 10 ; i++) { 14 | printf("loop\n"); 15 | } 16 | } 17 | 18 | return 0; 19 | } 20 | -------------------------------------------------------------------------------- /tests/analyzer/ifexit.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | ep = api.entry_point() 3 | api.set_code(ep) 4 | ad = api.get_addr_from_symbol("main") 5 | api.decompile(ad).print() 6 | -------------------------------------------------------------------------------- /tests/analyzer/ifexit.rev: -------------------------------------------------------------------------------- 1 | function main (.text) { 2 | 3 | frame_size = 24 4 | int var_10 = -0x10 5 | int var_c = -0xc 6 | 7 | 0x400536: push rbp 8 | 0x400537: rbp = rsp 9 | 0x40053a: rsp -= 16 10 | # 0x40053e: cmp dword ptr [rbp - 4], 0 11 | # 0x400542: jne 0x40057b 12 | if (var_c == 0) { 13 | # 0x400544: cmp dword ptr [rbp - 8], 0 14 | # 0x400548: jne 0x40055e 15 | if (var_10 == 0) { 16 | 0x40054a: edi = asc_400614 "exit" 17 | 0x40054f: call puts 18 | 0x400554: edi = 0 19 | 0x400559: call exit 20 | } 21 | 22 | 0x40055e: var_c = 0 23 | 0x400565: jmp loop_0x400575 24 | loop { 25 | loop_0x400575: 26 | # 0x400575: cmp dword ptr [rbp - 4], 9 27 | # 0x400579: jle 0x400567 28 | if (var_c > 9) goto ret_0x40057b 29 | 0x400567: edi = asc_400619 "loop" 30 | 0x40056c: call puts 31 | 0x400571: var_c += 1 32 | } ; loop_0x400575 33 | 34 | } 35 | ret_0x40057b: 36 | 0x40057b: eax = 0 37 | 0x400580: leave 38 | 0x400581: ret 39 | } 40 | -------------------------------------------------------------------------------- /tests/analyzer/invert_cond.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/plasma-disassembler/plasma/ec7df9b2b9b356dd5d8caf01b7e68c0ab5a1ef42/tests/analyzer/invert_cond.bin -------------------------------------------------------------------------------- /tests/analyzer/invert_cond.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | void func1() { 5 | int i; 6 | if (i < 5) { 7 | printf("1\n"); 8 | exit(0); 9 | } 10 | printf("2\n"); 11 | return; 12 | } 13 | 14 | void func2() { 15 | int i; 16 | if (i < 5) { 17 | printf("1\n"); 18 | } 19 | printf("2\n"); 20 | return; 21 | } 22 | 23 | int main() { 24 | int i, j, k, l, m; 25 | 26 | if (i != 0) { 27 | if (j != 1) { 28 | if (k != 2) { 29 | printf("1\n"); 30 | } 31 | else { 32 | printf("2\n"); 33 | } 34 | } 35 | else { 36 | printf("3\n"); 37 | } 38 | } 39 | else { 40 | printf("4\n"); 41 | } 42 | 43 | func1(); 44 | func2(); 45 | return 0; 46 | } 47 | -------------------------------------------------------------------------------- /tests/analyzer/invert_cond.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | main = api.get_addr_from_symbol("main") 3 | func1 = api.get_addr_from_symbol("func1") 4 | func2 = api.get_addr_from_symbol("func2") 5 | 6 | api.set_function(main) 7 | 8 | api.decompile(main).print() 9 | api.decompile(func1).print() 10 | api.decompile(func2).print() 11 | 12 | jumps = [0x6f2, 0x6f8, 0x6fe, 0x696, 0x6c9] 13 | 14 | for ad in jumps: 15 | api.invert_cond(ad) 16 | 17 | api.decompile(main).print() 18 | api.decompile(func1).print() 19 | api.decompile(func2).print() 20 | -------------------------------------------------------------------------------- /tests/analyzer/mips_prefetch.bin: -------------------------------------------------------------------------------- 1 | <@$B$B -------------------------------------------------------------------------------- /tests/analyzer/mips_prefetch.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | ep = api.entry_point() 4 | api.set_code(ep) 5 | 6 | s = api.get_section(ep) 7 | api.dump_asm(ep, until=s.end+1).print() 8 | -------------------------------------------------------------------------------- /tests/analyzer/mips_prefetch.rev: -------------------------------------------------------------------------------- 1 | ; --------------------------------------------------------------------- 2 | raw 0x400000 -> 0x400013 3 | 4 | _start: 5 | 0x400000: $v0 = 0x400000 6 | 0x400004: b loc_40000c 7 | 8 | loc_400008: 9 | 0x400008: !$v0 = loc_400008 10 | 11 | loc_40000c: 12 | 0x40000c: !$v0 = loc_40000c 13 | 0x400010: nop 14 | -------------------------------------------------------------------------------- /tests/analyzer/overlap.S: -------------------------------------------------------------------------------- 1 | // gcc -nostdlib overlap.S -e _start 2 | 3 | .intel_syntax noprefix 4 | .global main 5 | .global _start 6 | 7 | .section .text 8 | 9 | obfuscated_call: 10 | ret 11 | 12 | 13 | overlap_1: 14 | mov eax, 0xBBC10300 15 | mov ecx, 0x05000000 16 | add eax, ecx 17 | jmp $-10 18 | add eax, ebx 19 | ret 20 | 21 | 22 | overlap_2: 23 | xor ecx, ecx 24 | dec ecx 25 | inc ecx 26 | jnz $+3 27 | .byte 0xb8 // this is the mnemonic for a mov eax 28 | 29 | // do some stuff 30 | xor ecx, ecx 31 | loop: 32 | call obfuscated_call 33 | inc ecx 34 | cmp ecx, 15 35 | jle loop 36 | ret 37 | 38 | 39 | _start: 40 | call overlap_1 41 | call overlap_2 42 | ret 43 | 44 | 45 | -------------------------------------------------------------------------------- /tests/analyzer/overlap.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/plasma-disassembler/plasma/ec7df9b2b9b356dd5d8caf01b7e68c0ab5a1ef42/tests/analyzer/overlap.bin -------------------------------------------------------------------------------- /tests/analyzer/overlap.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | ep = api.entry_point() 3 | api.set_code(ep) 4 | 5 | ad = api.get_addr_from_symbol("overlap_1") 6 | api.decompile(ad).print() 7 | 8 | ad = api.get_addr_from_symbol("overlap_2") 9 | api.decompile(ad).print() 10 | -------------------------------------------------------------------------------- /tests/analyzer/overlap.rev: -------------------------------------------------------------------------------- 1 | function overlap_1 (.text) { 2 | 0x4000d5: eax = -1144978688 3 | 0x4000da: ecx = 83886080 4 | 0x4000df: eax += ecx 5 | 0x4000e1: jmp ret_0x4000d7 6 | ret_0x4000d7: 7 | 0x4000d7: eax += ecx 8 | 0x4000d9: ebx = 185 9 | 0x4000de: eax += -185874431 10 | 0x4000e3: eax += ebx 11 | 0x4000e5: ret 12 | } 13 | function overlap_2 (.text) { 14 | 0x4000e6: ecx = 0 15 | 0x4000e8: ecx-- 16 | 0x4000ea: ecx++ 17 | # 0x4000ec: jne 0x4000ef 18 | if == { 19 | 0x4000ee: eax = -555169487 20 | } 21 | unk_4000ef: 22 | 0x4000ef: ecx = 0 23 | loop { 24 | loop: 25 | 0x4000f1: call obfuscated_call 26 | 0x4000f6: ecx++ 27 | # 0x4000f8: cmp ecx, 0xf 28 | # 0x4000fb: jle 0x4000f1 29 | if (ecx > 15) goto break_0x4000fd 30 | } ; loop 31 | 32 | break_0x4000fd: 33 | 0x4000fd: ret 34 | } 35 | -------------------------------------------------------------------------------- /tests/analyzer/pusha.S: -------------------------------------------------------------------------------- 1 | // gcc -nostdlib pusha.S -e _start -o pusha.bin -m32 2 | 3 | .intel_syntax noprefix 4 | .global main 5 | .global _start 6 | 7 | .section .text 8 | 9 | .macro ACCESS_VARS 10 | // these two access must be the same 11 | mov eax, [ebp - 4] 12 | mov eax, [esp - 4 + 16] 13 | .endm 14 | 15 | __pusha_func: 16 | pushaw 17 | pushad 18 | pushfd 19 | popfd 20 | popad 21 | popaw 22 | ret 23 | 24 | __noreturn: 25 | jmp __noreturn 26 | 27 | _start: 28 | call main 29 | call __noreturn 30 | ret 31 | 32 | main: 33 | push ebp 34 | mov ebp, esp 35 | sub esp, 16 36 | 37 | ACCESS_VARS 38 | 39 | call __pusha_func 40 | 41 | ACCESS_VARS 42 | 43 | leave 44 | ret 45 | -------------------------------------------------------------------------------- /tests/analyzer/pusha.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/plasma-disassembler/plasma/ec7df9b2b9b356dd5d8caf01b7e68c0ab5a1ef42/tests/analyzer/pusha.bin -------------------------------------------------------------------------------- /tests/analyzer/pusha.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | ep = api.entry_point() 3 | api.set_code(ep) 4 | ad = api.get_addr_from_symbol(".text") 5 | s = api.get_section(ad) 6 | api.dump_asm(ad, until=s.end+1).print() 7 | -------------------------------------------------------------------------------- /tests/analyzer/pusha.rev: -------------------------------------------------------------------------------- 1 | ; --------------------------------------------------------------------- 2 | .text 0x8048098 -> 0x80480c8 3 | 4 | ; --------------------------------------------------------------------- 5 | ; SUBROUTINE 6 | ; --------------------------------------------------------------------- 7 | __pusha_func: 8 | 0x8048098: pushaw 9 | 0x804809a: pushal 10 | 0x804809b: pushfd 11 | 0x804809c: popfd 12 | 0x804809d: popal 13 | 0x804809e: popaw 14 | 0x80480a0: ret 15 | ; end function __pusha_func 16 | 17 | ; --------------------------------------------------------------------- 18 | ; SUBROUTINE 19 | ; --------------------------------------------------------------------- 20 | __noreturn: __noreturn__ 21 | 0x80480a1: jmp __noreturn 22 | ; end function __noreturn 23 | 24 | _start: 25 | 0x80480a3: call main 26 | 0x80480a8: call __noreturn 27 | 28 | 0x80480ad: .db c3 29 | 30 | ; --------------------------------------------------------------------- 31 | ; SUBROUTINE 32 | ; --------------------------------------------------------------------- 33 | main: 34 | 35 | frame_size = 20 36 | int var_8 = -0x8 37 | 38 | 0x80480ae: push ebp 39 | 0x80480af: ebp = esp 40 | 0x80480b1: esp -= 16 41 | 0x80480b4: eax = var_8 42 | 0x80480b7: eax = var_8 43 | 0x80480bb: call __pusha_func 44 | 0x80480c0: eax = var_8 45 | 0x80480c3: eax = var_8 46 | 0x80480c7: leave 47 | 0x80480c8: ret 48 | ; end function main 49 | 50 | -------------------------------------------------------------------------------- /tests/analyzer/regsim.S: -------------------------------------------------------------------------------- 1 | // gcc -nostdlib regsim.S -e _start -o regsim.bin 2 | 3 | .intel_syntax noprefix 4 | .global main 5 | .global _start 6 | 7 | .section .text 8 | 9 | __noreturn: 10 | jmp __noreturn 11 | 12 | _start: 13 | call main 14 | call __noreturn 15 | ret 16 | 17 | main: 18 | push rbp 19 | 20 | mov rax, 0 21 | loop: 22 | add rax, 1 # the analyzer should not replace by rax = 1 23 | cmp rax, 10 24 | jne loop 25 | 26 | 27 | mov rbx, 10 28 | lea rax, qword ptr [rbx + one_byte - 100] 29 | add rax, 90 # the analyzer mut find one_byte 30 | 31 | leave 32 | ret 33 | 34 | one_byte: .byte 0 35 | -------------------------------------------------------------------------------- /tests/analyzer/regsim.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/plasma-disassembler/plasma/ec7df9b2b9b356dd5d8caf01b7e68c0ab5a1ef42/tests/analyzer/regsim.bin -------------------------------------------------------------------------------- /tests/analyzer/regsim.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | ep = api.entry_point() 3 | api.set_code(ep) 4 | ad = api.get_addr_from_symbol(".text") 5 | s = api.get_section(ad) 6 | api.dump_asm(ad, until=s.end+1).print() 7 | -------------------------------------------------------------------------------- /tests/analyzer/regsim.rev: -------------------------------------------------------------------------------- 1 | ; --------------------------------------------------------------------- 2 | .text 0x4000d4 -> 0x400107 3 | 4 | ; --------------------------------------------------------------------- 5 | ; SUBROUTINE 6 | ; --------------------------------------------------------------------- 7 | __noreturn: __noreturn__ 8 | 0x4000d4: jmp __noreturn 9 | ; end function __noreturn 10 | 11 | _start: 12 | 0x4000d6: call main 13 | 0x4000db: call __noreturn 14 | 15 | 0x4000e0: .db c3 16 | 17 | ; --------------------------------------------------------------------- 18 | ; SUBROUTINE 19 | ; --------------------------------------------------------------------- 20 | main: 21 | 22 | frame_size = 8 23 | 0x4000e1: push rbp 24 | 0x4000e2: rax = 0 25 | 26 | loop: 27 | 0x4000e9: rax += 1 28 | 0x4000ed: rax cmp 10 29 | 0x4000f1: jne loop 30 | 0x4000f3: rbx = 10 31 | 0x4000fa: rax = rbx + 4194467 32 | 0x400101: !rax = one_byte 33 | 0x400105: leave 34 | 0x400106: ret 35 | ; end function main 36 | 37 | one_byte: 38 | 0x400107: .db 00 39 | -------------------------------------------------------------------------------- /tests/analyzer/run.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | color() { 4 | local color="$1" 5 | if [ "$3" == "" ]; then 6 | local prefix="" 7 | local txt="$2" 8 | else 9 | local prefix="$2 " 10 | local txt="$3" 11 | fi 12 | echo -en "${prefix}\x1b[;${color}m${txt}\x1b[0m" 13 | } 14 | 15 | red() { 16 | color 31 "$1" "$2" 17 | } 18 | 19 | green() { 20 | color 32 "$1" "$2" 21 | } 22 | 23 | echo "analyzer tests..." 24 | 25 | ls *.bin | while read file; do 26 | name=`basename $file .bin` 27 | 28 | case "$name" in 29 | "mips_prefetch") 30 | opt="--raw mips --rawbe --rawbase 0x400000" 31 | ;; 32 | *) 33 | opt="" 34 | ;; 35 | esac 36 | 37 | echo -e "py ${name}.py\n exit" | \ 38 | ../../run_plasma.py -i -na -nc ${name}.bin $opt >tmp 2>/dev/null 39 | 40 | diff -q ${name}.rev tmp >/dev/null 41 | if [ $? -eq 0 ]; then 42 | green "$name" "[OK]\n" 43 | else 44 | red "$name" "[FAIL]\n" 45 | fi 46 | done 47 | 48 | rm tmp 49 | -------------------------------------------------------------------------------- /tests/analyzer/stack.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/plasma-disassembler/plasma/ec7df9b2b9b356dd5d8caf01b7e68c0ab5a1ef42/tests/analyzer/stack.bin -------------------------------------------------------------------------------- /tests/analyzer/stack.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | ep = api.entry_point() 3 | api.set_code(ep) 4 | ad = api.get_addr_from_symbol(".text") 5 | s = api.get_section(ad) 6 | api.dump_asm(ad, until=s.end+1).print() 7 | -------------------------------------------------------------------------------- /tests/analyzer/switch.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/plasma-disassembler/plasma/ec7df9b2b9b356dd5d8caf01b7e68c0ab5a1ef42/tests/analyzer/switch.bin -------------------------------------------------------------------------------- /tests/analyzer/switch.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() { 5 | int i = 2; 6 | 7 | switch (i) { 8 | case 2: 9 | printf("2\n"); 10 | break; 11 | case 3: 12 | printf("3\n"); 13 | break; 14 | case 4: 15 | printf("4\n"); 16 | break; 17 | case 5: 18 | printf("5\n"); 19 | break; 20 | case 10: 21 | printf("10\n"); 22 | break; 23 | default: 24 | printf("default\n"); 25 | break; 26 | } 27 | 28 | return 0; 29 | } 30 | -------------------------------------------------------------------------------- /tests/analyzer/switch.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | ep = api.entry_point() 3 | api.set_code(ep) 4 | ad = api.get_addr_from_symbol(".text") 5 | s = api.get_section(ad) 6 | api.dump_asm(ad, until=s.end+1).print() 7 | -------------------------------------------------------------------------------- /tests/and1.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/plasma-disassembler/plasma/ec7df9b2b9b356dd5d8caf01b7e68c0ab5a1ef42/tests/and1.bin -------------------------------------------------------------------------------- /tests/and1.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() { 5 | int i = 123, j = 5; 6 | 7 | if (i != 0 && i > time(NULL) && i != j && i > 5 && j < 10) { 8 | printf("1\n"); 9 | } 10 | else { 11 | printf("2\n"); 12 | } 13 | 14 | printf("3\n"); 15 | 16 | return 0; 17 | } 18 | 19 | 20 | -------------------------------------------------------------------------------- /tests/and1.rev: -------------------------------------------------------------------------------- 1 | function main (.text) { 2 | 0x400546: push rbp 3 | 0x400547: rbp = rsp 4 | 0x40054a: rsp -= 16 5 | 0x40054e: *(rbp - 4) = 123 6 | 0x400555: *(rbp - 8) = 5 7 | # 0x40055c: cmp dword ptr [rbp - 4], 0 8 | # 0x400560: je 0x400596 9 | if (*(rbp - 4) != 0) { 10 | 0x400562: edi = 0 11 | 0x400567: eax = 0 12 | 0x40056c: call time 13 | # 0x400571: cmp eax, dword ptr [rbp - 4] 14 | # 0x400574: jge 0x400596 15 | and if (eax < *(rbp - 4)) 16 | 0x400576: eax = *(rbp - 4) 17 | # 0x400579: cmp eax, dword ptr [rbp - 8] 18 | # 0x40057c: je 0x400596 19 | and if (eax != *(rbp - 8)) 20 | # 0x40057e: cmp dword ptr [rbp - 4], 5 21 | # 0x400582: jle 0x400596 22 | and if (*(rbp - 4) > 5) 23 | # 0x400584: cmp dword ptr [rbp - 8], 9 24 | # 0x400588: jg 0x400596 25 | and if (*(rbp - 8) <= 9) 26 | 0x40058a: edi = 0x400644 "1" 27 | 0x40058f: call puts 28 | 0x400594: jmp ret_0x4005a0 29 | } else { 30 | 0x400596: edi = 0x400646 "2" 31 | 0x40059b: call puts 32 | } 33 | ret_0x4005a0: 34 | 0x4005a0: edi = 0x400648 "3" 35 | 0x4005a5: call puts 36 | 0x4005aa: eax = 0 37 | 0x4005af: leave 38 | 0x4005b0: ret 39 | } 40 | -------------------------------------------------------------------------------- /tests/and2.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/plasma-disassembler/plasma/ec7df9b2b9b356dd5d8caf01b7e68c0ab5a1ef42/tests/and2.bin -------------------------------------------------------------------------------- /tests/and2.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() { 5 | int i = 123, j = 5; 6 | 7 | while (1) { 8 | if (i != 0 && j < 10 && i != j) { 9 | printf("1\n"); 10 | } 11 | printf("2\n"); 12 | i++; 13 | if (i == 0) 14 | printf("3\n"); 15 | j++; 16 | } 17 | 18 | return 0; 19 | } 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /tests/and2.rev: -------------------------------------------------------------------------------- 1 | function main (.text) { 2 | 0x400506: push rbp 3 | 0x400507: rbp = rsp 4 | 0x40050a: rsp -= 16 5 | 0x40050e: *(rbp - 4) = 123 6 | 0x400515: *(rbp - 8) = 5 7 | for (;;) { 8 | loop_0x40051c: 9 | # 0x40051c: cmp dword ptr [rbp - 4], 0 10 | # 0x400520: je 0x40053a 11 | if (*(rbp - 4) != 0) { 12 | # 0x400522: cmp dword ptr [rbp - 8], 9 13 | # 0x400526: jg 0x40053a 14 | and if (*(rbp - 8) <= 9) 15 | 0x400528: eax = *(rbp - 4) 16 | # 0x40052b: cmp eax, dword ptr [rbp - 8] 17 | # 0x40052e: je 0x40053a 18 | and if (eax != *(rbp - 8)) 19 | 0x400530: edi = 0x4005e4 "1" 20 | 0x400535: call puts 21 | } 22 | 0x40053a: edi = 0x4005e6 "2" 23 | 0x40053f: call puts 24 | 0x400544: *(rbp - 4) += 1 25 | # 0x400548: cmp dword ptr [rbp - 4], 0 26 | # 0x40054c: jne 0x400558 27 | if (*(rbp - 4) == 0) { 28 | 0x40054e: edi = 0x4005e8 "3" 29 | 0x400553: call puts 30 | } 31 | 0x400558: *(rbp - 8) += 1 32 | 0x40055c: jmp loop_0x40051c 33 | } ; loop_0x40051c 34 | 35 | } 36 | -------------------------------------------------------------------------------- /tests/and3.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/plasma-disassembler/plasma/ec7df9b2b9b356dd5d8caf01b7e68c0ab5a1ef42/tests/and3.bin -------------------------------------------------------------------------------- /tests/and3.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() { 5 | int i = 123, j = 5; 6 | 7 | if (i != 0 && i > 1 && i > 2) { 8 | if (j != 0 && j > 1 && j > 2) 9 | printf("1\n"); 10 | else 11 | printf("2\n"); 12 | } 13 | else { 14 | printf("3\n"); 15 | } 16 | 17 | printf("4\n"); 18 | 19 | return 0; 20 | } 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /tests/and3.rev: -------------------------------------------------------------------------------- 1 | function main (.text) { 2 | 0x400506: push rbp 3 | 0x400507: rbp = rsp 4 | 0x40050a: rsp -= 16 5 | 0x40050e: *(rbp - 4) = 123 6 | 0x400515: *(rbp - 8) = 5 7 | # 0x40051c: cmp dword ptr [rbp - 4], 0 8 | # 0x400520: je 0x400558 9 | if (*(rbp - 4) != 0) { 10 | # 0x400522: cmp dword ptr [rbp - 4], 1 11 | # 0x400526: jle 0x400558 12 | and if (*(rbp - 4) > 1) 13 | # 0x400528: cmp dword ptr [rbp - 4], 2 14 | # 0x40052c: jle 0x400558 15 | and if (*(rbp - 4) > 2) 16 | # 0x40052e: cmp dword ptr [rbp - 8], 0 17 | # 0x400532: je 0x40054c 18 | if (*(rbp - 8) != 0) { 19 | # 0x400534: cmp dword ptr [rbp - 8], 1 20 | # 0x400538: jle 0x40054c 21 | and if (*(rbp - 8) > 1) 22 | # 0x40053a: cmp dword ptr [rbp - 8], 2 23 | # 0x40053e: jle 0x40054c 24 | and if (*(rbp - 8) > 2) 25 | 0x400540: edi = 0x400604 "1" 26 | 0x400545: call puts 27 | 0x40054a: jmp ret_0x400562 28 | } else { 29 | 0x40054c: edi = 0x400606 "2" 30 | 0x400551: call puts 31 | 0x400556: jmp ret_0x400562 32 | } 33 | } else { 34 | 0x400558: edi = 0x400608 "3" 35 | 0x40055d: call puts 36 | } 37 | ret_0x400562: 38 | 0x400562: edi = 0x40060a "4" 39 | 0x400567: call puts 40 | 0x40056c: eax = 0 41 | 0x400571: leave 42 | 0x400572: ret 43 | } 44 | -------------------------------------------------------------------------------- /tests/and4.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/plasma-disassembler/plasma/ec7df9b2b9b356dd5d8caf01b7e68c0ab5a1ef42/tests/and4.bin -------------------------------------------------------------------------------- /tests/and4.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() { 5 | int i = 123, j = 5; 6 | 7 | while (i < 100 && i < 50 && i < 20 && i < 10) { 8 | if (i == 5) 9 | printf("1\n"); 10 | i++; 11 | } 12 | printf("2\n"); 13 | 14 | return 0; 15 | } 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /tests/and4.rev: -------------------------------------------------------------------------------- 1 | function main (.text) { 2 | 0x400506: push rbp 3 | 0x400507: rbp = rsp 4 | 0x40050a: rsp -= 16 5 | 0x40050e: *(rbp - 4) = 123 6 | 0x400515: *(rbp - 8) = 5 7 | 0x40051c: jmp loop_0x400532 8 | loop { 9 | loop_0x400532: 10 | # 0x400532: cmp dword ptr [rbp - 4], 0x63 11 | # 0x400536: jg 0x40054a 12 | if (*(rbp - 4) > 99) goto ret_0x40054a 13 | # 0x400538: cmp dword ptr [rbp - 4], 0x31 14 | # 0x40053c: jg 0x40054a 15 | if (*(rbp - 4) > 49) goto ret_0x40054a 16 | # 0x40053e: cmp dword ptr [rbp - 4], 0x13 17 | # 0x400542: jg 0x40054a 18 | if (*(rbp - 4) > 19) goto ret_0x40054a 19 | # 0x400544: cmp dword ptr [rbp - 4], 9 20 | # 0x400548: jle 0x40051e 21 | if (*(rbp - 4) > 9) goto ret_0x40054a 22 | # 0x40051e: cmp dword ptr [rbp - 4], 5 23 | # 0x400522: jne 0x40052e 24 | if (*(rbp - 4) == 5) { 25 | 0x400524: edi = 0x4005e4 "1" 26 | 0x400529: call puts 27 | } 28 | 0x40052e: *(rbp - 4) += 1 29 | } ; loop_0x400532 30 | 31 | ret_0x40054a: 32 | 0x40054a: edi = 0x4005e6 "2" 33 | 0x40054f: call puts 34 | 0x400554: eax = 0 35 | 0x400559: leave 36 | 0x40055a: ret 37 | } 38 | -------------------------------------------------------------------------------- /tests/andor1.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/plasma-disassembler/plasma/ec7df9b2b9b356dd5d8caf01b7e68c0ab5a1ef42/tests/andor1.bin -------------------------------------------------------------------------------- /tests/andor1.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | 6 | int main(int argc, char *argv[]) 7 | { 8 | int i, j, k; 9 | 10 | while (i < 10 && j < 10 || i == k) 11 | { 12 | printf("1\n"); 13 | while (k < 20) 14 | printf("2\n"); 15 | } 16 | 17 | return 0; 18 | } 19 | -------------------------------------------------------------------------------- /tests/andor1.rev: -------------------------------------------------------------------------------- 1 | function main (.text) { 2 | 0x400506: push rbp 3 | 0x400507: rbp = rsp 4 | 0x40050a: rsp -= 32 5 | 0x40050e: *(rbp - 20) = edi 6 | 0x400511: *(rbp - 32) = rsi 7 | 0x400515: jmp loop_0x400533 8 | loop { 9 | loop_0x400533: 10 | # 0x400533: cmp dword ptr [rbp - 4], 9 11 | # 0x400537: jg 0x40053f 12 | if (*(rbp - 4) <= 9) { 13 | # 0x400539: cmp dword ptr [rbp - 8], 9 14 | # 0x40053d: jle 0x400517 15 | and if (*(rbp - 8) <= 9) 16 | goto 0x400517 17 | } else { 18 | 0x40053f: eax = *(rbp - 4) 19 | # 0x400542: cmp eax, dword ptr [rbp - 0xc] 20 | # 0x400545: je 0x400517 21 | if (eax != *(rbp - 12)) goto ret_0x400547 22 | } 23 | 0x400517: edi = 0x4005d4 "1" 24 | 0x40051c: call puts 25 | 0x400521: jmp loop_0x40052d 26 | loop { 27 | loop_0x40052d: 28 | # 0x40052d: cmp dword ptr [rbp - 0xc], 0x13 29 | # 0x400531: jle 0x400523 30 | if (*(rbp - 12) > 19) goto loop_0x400533 31 | 0x400523: edi = 0x4005d6 "2" 32 | 0x400528: call puts 33 | } ; loop_0x40052d 34 | 35 | } ; loop_0x400533 36 | 37 | ret_0x400547: 38 | 0x400547: eax = 0 39 | 0x40054c: leave 40 | 0x40054d: ret 41 | } 42 | -------------------------------------------------------------------------------- /tests/andor2.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/plasma-disassembler/plasma/ec7df9b2b9b356dd5d8caf01b7e68c0ab5a1ef42/tests/andor2.bin -------------------------------------------------------------------------------- /tests/andor2.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | 6 | int main(int argc, char *argv[]) 7 | { 8 | int i, j, k; 9 | 10 | while (i < 10 && j < 10 || i == k) 11 | { 12 | printf("1\n"); 13 | while (k < 20) { 14 | printf("2\n"); 15 | while (j < 20) { 16 | printf("3\n"); 17 | } 18 | printf("4\n"); 19 | } 20 | printf("5\n"); 21 | } 22 | 23 | return 0; 24 | } 25 | 26 | 27 | -------------------------------------------------------------------------------- /tests/andor2.rev: -------------------------------------------------------------------------------- 1 | function main (.text) { 2 | 0x400506: push rbp 3 | 0x400507: rbp = rsp 4 | 0x40050a: rsp -= 32 5 | 0x40050e: *(rbp - 20) = edi 6 | 0x400511: *(rbp - 32) = rsi 7 | 0x400515: jmp loop_0x400559 8 | loop { 9 | loop_0x400559: 10 | # 0x400559: cmp dword ptr [rbp - 4], 9 11 | # 0x40055d: jg 0x400565 12 | if (*(rbp - 4) <= 9) { 13 | # 0x40055f: cmp dword ptr [rbp - 8], 9 14 | # 0x400563: jle 0x400517 15 | and if (*(rbp - 8) <= 9) 16 | goto 0x400517 17 | } else { 18 | 0x400565: eax = *(rbp - 4) 19 | # 0x400568: cmp eax, dword ptr [rbp - 0xc] 20 | # 0x40056b: je 0x400517 21 | if (eax != *(rbp - 12)) goto ret_0x40056d 22 | } 23 | 0x400517: edi = 0x400604 "1" 24 | 0x40051c: call puts 25 | 0x400521: jmp loop_0x400549 26 | loop { 27 | loop_0x400549: 28 | # 0x400549: cmp dword ptr [rbp - 0xc], 0x13 29 | # 0x40054d: jle 0x400523 30 | if (*(rbp - 12) > 19) goto break_0x40054f 31 | 0x400523: edi = 0x400606 "2" 32 | 0x400528: call puts 33 | 0x40052d: jmp loop_0x400539 34 | loop { 35 | loop_0x400539: 36 | # 0x400539: cmp dword ptr [rbp - 8], 0x13 37 | # 0x40053d: jle 0x40052f 38 | if (*(rbp - 8) > 19) goto break_0x40053f 39 | 0x40052f: edi = 0x400608 "3" 40 | 0x400534: call puts 41 | } ; loop_0x400539 42 | 43 | break_0x40053f: 44 | 0x40053f: edi = 0x40060a "4" 45 | 0x400544: call puts 46 | } ; loop_0x400549 47 | 48 | break_0x40054f: 49 | 0x40054f: edi = 0x40060c "5" 50 | 0x400554: call puts 51 | } ; loop_0x400559 52 | 53 | ret_0x40056d: 54 | 0x40056d: eax = 0 55 | 0x400572: leave 56 | 0x400573: ret 57 | } 58 | -------------------------------------------------------------------------------- /tests/andor3.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/plasma-disassembler/plasma/ec7df9b2b9b356dd5d8caf01b7e68c0ab5a1ef42/tests/andor3.bin -------------------------------------------------------------------------------- /tests/andor3.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() { 5 | int i, j; 6 | 7 | if (i == 1) { 8 | i--; 9 | if (i == 0) { 10 | label: 11 | printf("1\n"); 12 | } 13 | } else { 14 | printf("2\n"); 15 | if (i == 2) 16 | goto label; 17 | } 18 | 19 | return 0; 20 | } 21 | -------------------------------------------------------------------------------- /tests/andor3.rev: -------------------------------------------------------------------------------- 1 | function main (.text) { 2 | 0x400506: push rbp 3 | 0x400507: rbp = rsp 4 | 0x40050a: rsp -= 16 5 | # 0x40050e: cmp dword ptr [rbp - 4], 1 6 | # 0x400512: jne 0x400526 7 | if (*(rbp - 4) == 1) { 8 | 0x400514: edi = 0x4005d4 "2" 9 | 0x400519: call puts 10 | # 0x40051e: cmp dword ptr [rbp - 4], 2 11 | # 0x400522: jne 0x40053a 12 | if (*(rbp - 4) == 2) { 13 | 0x400524: jmp 0x400530 14 | } 15 | } else { 16 | 0x400526: *(rbp - 4) -= 1 17 | # 0x40052a: cmp dword ptr [rbp - 4], 0 18 | # 0x40052e: jne 0x40053a 19 | if (*(rbp - 4) == 0) { 20 | 0x400530: edi = 0x4005d6 "1" 21 | 0x400535: call puts 22 | } 23 | } 24 | ret_0x40053a: 25 | 0x40053a: eax = 0 26 | 0x40053f: leave 27 | 0x400540: ret 28 | } 29 | -------------------------------------------------------------------------------- /tests/andor4.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/plasma-disassembler/plasma/ec7df9b2b9b356dd5d8caf01b7e68c0ab5a1ef42/tests/andor4.bin -------------------------------------------------------------------------------- /tests/andor4.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | int main() { 6 | srand(time(NULL)); 7 | int i = rand(); 8 | int j = rand(); 9 | 10 | if (i == 1) { 11 | printf("2\n"); 12 | if (j == 2) 13 | goto label; 14 | } else { 15 | j--; 16 | if (j == 0) { 17 | label: 18 | printf("1\n"); 19 | } 20 | } 21 | 22 | return 0; 23 | } 24 | -------------------------------------------------------------------------------- /tests/andor4.rev: -------------------------------------------------------------------------------- 1 | function main (.text) { 2 | 0x4005d6: push rbp 3 | 0x4005d7: rbp = rsp 4 | 0x4005da: rsp -= 16 5 | 0x4005de: edi = 0 6 | 0x4005e3: call time 7 | 0x4005e8: edi = eax 8 | 0x4005ea: call srand 9 | 0x4005ef: call rand 10 | 0x4005f4: *(rbp - 4) = eax 11 | 0x4005f7: call rand 12 | 0x4005fc: *(rbp - 8) = eax 13 | # 0x4005ff: cmp dword ptr [rbp - 4], 1 14 | # 0x400603: jne 0x400617 15 | if (*(rbp - 4) == 1) { 16 | 0x400605: edi = 0x4006c4 "2" 17 | 0x40060a: call puts 18 | # 0x40060f: cmp dword ptr [rbp - 8], 2 19 | # 0x400613: jne 0x40062b 20 | if (*(rbp - 8) == 2) { 21 | 0x400615: jmp 0x400621 22 | } 23 | } else { 24 | 0x400617: *(rbp - 8) -= 1 25 | # 0x40061b: cmp dword ptr [rbp - 8], 0 26 | # 0x40061f: jne 0x40062b 27 | if (*(rbp - 8) == 0) { 28 | 0x400621: edi = 0x4006c6 "1" 29 | 0x400626: call puts 30 | } 31 | } 32 | ret_0x40062b: 33 | 0x40062b: eax = 0 34 | 0x400630: leave 35 | 0x400631: ret 36 | } 37 | -------------------------------------------------------------------------------- /tests/andor5.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/plasma-disassembler/plasma/ec7df9b2b9b356dd5d8caf01b7e68c0ab5a1ef42/tests/andor5.bin -------------------------------------------------------------------------------- /tests/andor5.c: -------------------------------------------------------------------------------- 1 | // same as tests/andor4.c but compiled with -O3 2 | #include 3 | #include 4 | #include 5 | 6 | int main() { 7 | srand(time(NULL)); 8 | int i = rand(); 9 | int j = rand(); 10 | 11 | if (i == 1) { 12 | printf("2\n"); 13 | if (j == 2) 14 | goto label; 15 | } else { 16 | j--; 17 | if (j == 0) { 18 | label: 19 | printf("1\n"); 20 | } 21 | } 22 | 23 | return 0; 24 | } 25 | -------------------------------------------------------------------------------- /tests/andor5.rev: -------------------------------------------------------------------------------- 1 | function main (.text) { 2 | 0x4004e0: push rbp 3 | 0x4004e1: push rbx 4 | 0x4004e2: edi = 0 5 | 0x4004e4: rsp -= 8 6 | 0x4004e8: call time 7 | 0x4004ed: edi = eax 8 | 0x4004ef: call srand 9 | 0x4004f4: call rand 10 | 0x4004f9: ebx = eax 11 | 0x4004fb: call rand 12 | 0x400500: ebx cmp 1 13 | 0x400503: ebp = eax 14 | # 0x400505: je 0x400515 15 | if != { 16 | # 0x400507: cmp eax, 1 17 | # 0x40050a: je 0x400524 18 | if (eax == 1) { 19 | goto 0x400524 20 | } 21 | } else { 22 | 0x400515: edi = 0x4006b4 "2" 23 | 0x40051a: call puts 24 | # 0x40051f: cmp ebp, 2 25 | # 0x400522: jne 0x40050c 26 | if (ebp == 2) { 27 | 0x400524: edi = 0x4006b6 "1" 28 | 0x400529: call puts 29 | 0x40052e: jmp ret_0x40050c 30 | } 31 | } 32 | ret_0x40050c: 33 | 0x40050c: rsp += 8 34 | 0x400510: eax = 0 35 | 0x400512: pop rbx 36 | 0x400513: pop rbp 37 | 0x400514: ret 38 | } 39 | -------------------------------------------------------------------------------- /tests/andor6.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/plasma-disassembler/plasma/ec7df9b2b9b356dd5d8caf01b7e68c0ab5a1ef42/tests/andor6.bin -------------------------------------------------------------------------------- /tests/andor6.c: -------------------------------------------------------------------------------- 1 | // same as tests/andor3.c but compiled with -O3 2 | #include 3 | #include 4 | #include 5 | 6 | int main() { 7 | srand(time(NULL)); 8 | int i = rand(); 9 | int j = rand(); 10 | 11 | if (i == 1) { 12 | i--; 13 | if (j == 0) { 14 | label: 15 | printf("1\n"); 16 | } 17 | } else { 18 | printf("2\n"); 19 | if (i == 2) 20 | goto label; 21 | } 22 | 23 | return 0; 24 | } 25 | -------------------------------------------------------------------------------- /tests/andor6.rev: -------------------------------------------------------------------------------- 1 | function main (.text) { 2 | 0x4004e0: push rbx 3 | 0x4004e1: edi = 0 4 | 0x4004e3: call time 5 | 0x4004e8: edi = eax 6 | 0x4004ea: call srand 7 | 0x4004ef: call rand 8 | 0x4004f4: ebx = eax 9 | 0x4004f6: call rand 10 | # 0x4004fb: cmp ebx, 1 11 | # 0x4004fe: je 0x400513 12 | if (ebx != 1) { 13 | 0x400500: edi = 0x4006b6 "2" 14 | 0x400505: call puts 15 | # 0x40050a: cmp ebx, 2 16 | # 0x40050d: je 0x400517 17 | if (ebx == 2) { 18 | goto 0x400517 19 | } 20 | } else { 21 | # 0x400513: test eax, eax 22 | # 0x400515: jne 0x40050f 23 | if (eax == 0) { 24 | 0x400517: edi = 0x4006b4 "1" 25 | 0x40051c: call puts 26 | 0x400521: jmp ret_0x40050f 27 | } 28 | } 29 | ret_0x40050f: 30 | 0x40050f: eax = 0 31 | 0x400511: pop rbx 32 | 0x400512: ret 33 | } 34 | -------------------------------------------------------------------------------- /tests/break1.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/plasma-disassembler/plasma/ec7df9b2b9b356dd5d8caf01b7e68c0ab5a1ef42/tests/break1.bin -------------------------------------------------------------------------------- /tests/break1.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() { 5 | int i = 0, j = 2; 6 | 7 | while (i < 10 && j != i*2) { 8 | printf("1\n"); 9 | 10 | if (i == 8) { 11 | while (j < 4) { 12 | j += 5*2+i; 13 | printf("2\n"); 14 | } 15 | j += 2*i+i*3+i*4; 16 | break; 17 | } 18 | 19 | i++; 20 | j++; 21 | } 22 | 23 | printf("3\n"); 24 | 25 | return 0; 26 | } 27 | 28 | -------------------------------------------------------------------------------- /tests/break1.rev: -------------------------------------------------------------------------------- 1 | function main (.text) { 2 | 0x400506: push rbp 3 | 0x400507: rbp = rsp 4 | 0x40050a: rsp -= 16 5 | 0x40050e: *(rbp - 4) = 0 6 | 0x400515: *(rbp - 8) = 2 7 | 0x40051c: jmp loop_0x400560 8 | loop { 9 | loop_0x400560: 10 | # 0x400560: cmp dword ptr [rbp - 4], 9 11 | # 0x400564: jg 0x400570 12 | if (*(rbp - 4) > 9) goto ret_0x400570 13 | 0x400566: eax = *(rbp - 4) 14 | 0x400569: eax += eax 15 | # 0x40056b: cmp eax, dword ptr [rbp - 8] 16 | # 0x40056e: jne 0x40051e 17 | if (eax == *(rbp - 8)) goto ret_0x400570 18 | 0x40051e: edi = 0x400614 "1" 19 | 0x400523: call puts 20 | # 0x400528: cmp dword ptr [rbp - 4], 8 21 | # 0x40052c: jne 0x400558 22 | if (*(rbp - 4) == 8) goto break_0x40052e 23 | 0x400558: *(rbp - 4) += 1 24 | 0x40055c: *(rbp - 8) += 1 25 | } ; loop_0x400560 26 | 27 | break_0x40052e: 28 | 0x40052e: jmp loop_0x400543 29 | loop { 30 | loop_0x400543: 31 | # 0x400543: cmp dword ptr [rbp - 8], 3 32 | # 0x400547: jle 0x400530 33 | if (*(rbp - 8) > 3) goto break_0x400549 34 | 0x400530: eax = *(rbp - 4) 35 | 0x400533: eax += 10 36 | 0x400536: *(rbp - 8) += eax 37 | 0x400539: edi = 0x400616 "2" 38 | 0x40053e: call puts 39 | } ; loop_0x400543 40 | 41 | break_0x400549: 42 | 0x400549: edx = *(rbp - 4) 43 | 0x40054c: eax = edx 44 | 0x40054e: eax <<= 3 45 | 0x400551: eax += edx 46 | 0x400553: *(rbp - 8) += eax 47 | 0x400556: jmp ret_0x400570 48 | ret_0x400570: 49 | 0x400570: edi = 0x400618 "3" 50 | 0x400575: call puts 51 | 0x40057a: eax = 0 52 | 0x40057f: leave 53 | 0x400580: ret 54 | } 55 | -------------------------------------------------------------------------------- /tests/break2.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/plasma-disassembler/plasma/ec7df9b2b9b356dd5d8caf01b7e68c0ab5a1ef42/tests/break2.bin -------------------------------------------------------------------------------- /tests/break2.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() { 5 | int i = 0, j = 2, z; 6 | 7 | for (z = 0 ; z < 20 ; z++) { 8 | while (i < 10 && j != i*2) { 9 | printf("1\n"); 10 | 11 | if (i == 8) { 12 | printf("2\n"); 13 | break; 14 | } 15 | 16 | if (j == 5) { 17 | while (1) { 18 | printf("3\n"); 19 | } 20 | } 21 | 22 | i++; 23 | j++; 24 | } 25 | 26 | if (z == 15) { 27 | printf("4\n"); 28 | break; 29 | } 30 | 31 | printf("5\n"); 32 | } 33 | 34 | printf("6\n"); 35 | 36 | return 0; 37 | } 38 | 39 | 40 | -------------------------------------------------------------------------------- /tests/break3.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/plasma-disassembler/plasma/ec7df9b2b9b356dd5d8caf01b7e68c0ab5a1ef42/tests/break3.bin -------------------------------------------------------------------------------- /tests/break3.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() { 5 | int i = 0, j; 6 | 7 | for (i = 0 ; i < 1000 ; i++) { 8 | printf("1\n"); 9 | 10 | j = rand(); 11 | if (j == 1) { 12 | if (i < 500) { 13 | printf("2\n"); 14 | if (i < 200) { 15 | printf("3\n"); 16 | if (i == 1 || i == 2 || i == 3) { 17 | printf("4\n"); 18 | } 19 | } 20 | 21 | else if (i == 42) { 22 | while (1) { 23 | printf("loooop!\n"); 24 | } 25 | } 26 | } 27 | printf("break!\n"); 28 | break; 29 | } 30 | 31 | printf("5\n"); 32 | } 33 | printf("6\n"); 34 | 35 | return 0; 36 | } 37 | 38 | 39 | 40 | -------------------------------------------------------------------------------- /tests/canary_plt.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/plasma-disassembler/plasma/ec7df9b2b9b356dd5d8caf01b7e68c0ab5a1ef42/tests/canary_plt.bin -------------------------------------------------------------------------------- /tests/canary_plt.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() { 5 | int i = 0; 6 | char c[128]; 7 | 8 | while (i < 100) { 9 | c[i] = 'a'; 10 | } 11 | 12 | return 0; 13 | } 14 | -------------------------------------------------------------------------------- /tests/canary_plt.rev: -------------------------------------------------------------------------------- 1 | function main (.text) { 2 | 0x400526: push rbp 3 | 0x400527: rbp = rsp 4 | 0x40052a: rsp -= 160 5 | 0x400531: rax = *(fs + 40) 6 | 0x40053a: *(rbp - 8) = rax 7 | 0x40053e: eax = 0 8 | 0x400540: *(rbp - 148) = 0 9 | 0x40054a: jmp loop_0x40055c 10 | loop { 11 | loop_0x40055c: 12 | # 0x40055c: cmp dword ptr [rbp - 0x94], 0x63 13 | # 0x400563: jle 0x40054c 14 | if (*(rbp - 148) > 99) goto break_0x400565 15 | 0x40054c: eax = *(rbp - 148) 16 | 0x400552: rax = eax 17 | 0x400554: *(rbp + rax - 144) = 'a' 18 | } ; loop_0x40055c 19 | 20 | break_0x400565: 21 | 0x400565: eax = 0 22 | 0x40056a: rdx = *(rbp - 8) 23 | # 0x40056e: xor rdx, qword ptr fs:[0x28] 24 | # 0x400577: je 0x40057e 25 | if ((rdx ^= *(fs + 40)) != 0) { 26 | 0x400579: call __stack_chk_fail 27 | } 28 | ret_0x40057e: 29 | 0x40057e: leave 30 | 0x40057f: ret 31 | } 32 | -------------------------------------------------------------------------------- /tests/chars1.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/plasma-disassembler/plasma/ec7df9b2b9b356dd5d8caf01b7e68c0ab5a1ef42/tests/chars1.bin -------------------------------------------------------------------------------- /tests/chars1.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() { 5 | unsigned char c = 0; 6 | 7 | if (c == 'a') 8 | printf("1\n"); 9 | else if (c == 'b') 10 | printf("2\n"); 11 | else if (c == 'c') 12 | printf("3\n"); 13 | else if (c == 250) 14 | printf("4\n"); 15 | else if (c == '\n') 16 | printf("5\n"); 17 | 18 | return 0; 19 | } 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /tests/chars1.rev: -------------------------------------------------------------------------------- 1 | function main (.text) { 2 | 0x400506: push rbp 3 | 0x400507: rbp = rsp 4 | 0x40050a: rsp -= 16 5 | 0x40050e: *(rbp - 1) = '\0' 6 | # 0x400512: cmp byte ptr [rbp - 1], 0x61 7 | # 0x400516: jne 0x400524 8 | if (*(rbp - 1) == 'a') { 9 | 0x400518: edi = 0x400604 "1" 10 | 0x40051d: call puts 11 | 0x400522: jmp ret_0x40056a 12 | } 13 | # 0x400524: cmp byte ptr [rbp - 1], 0x62 14 | # 0x400528: jne 0x400536 15 | else if (*(rbp - 1) == 'b') { 16 | 0x40052a: edi = 0x400606 "2" 17 | 0x40052f: call puts 18 | 0x400534: jmp ret_0x40056a 19 | } 20 | # 0x400536: cmp byte ptr [rbp - 1], 0x63 21 | # 0x40053a: jne 0x400548 22 | else if (*(rbp - 1) == 'c') { 23 | 0x40053c: edi = 0x400608 "3" 24 | 0x400541: call puts 25 | 0x400546: jmp ret_0x40056a 26 | } 27 | # 0x400548: cmp byte ptr [rbp - 1], 0xfa 28 | # 0x40054c: jne 0x40055a 29 | else if (*(rbp - 1) == '\xfa') { 30 | 0x40054e: edi = 0x40060a "4" 31 | 0x400553: call puts 32 | 0x400558: jmp ret_0x40056a 33 | } 34 | # 0x40055a: cmp byte ptr [rbp - 1], 0xa 35 | # 0x40055e: jne 0x40056a 36 | else if (*(rbp - 1) == '\n') { 37 | 0x400560: edi = 0x40060c "5" 38 | 0x400565: call puts 39 | } 40 | ret_0x40056a: 41 | 0x40056a: eax = 0 42 | 0x40056f: leave 43 | 0x400570: ret 44 | } 45 | -------------------------------------------------------------------------------- /tests/continue1.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/plasma-disassembler/plasma/ec7df9b2b9b356dd5d8caf01b7e68c0ab5a1ef42/tests/continue1.bin -------------------------------------------------------------------------------- /tests/continue1.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() { 5 | int i = 0, j = 2; 6 | 7 | while (i < 10 && j != i*2) { 8 | printf("1\n"); 9 | 10 | if (i == 8) { 11 | while (j < 4) { 12 | j += 5*2+i; 13 | printf("2\n"); 14 | } 15 | j += 2*i+i*3+i*4; 16 | continue; 17 | } 18 | 19 | i++; 20 | j++; 21 | } 22 | 23 | printf("3\n"); 24 | 25 | return 0; 26 | } 27 | 28 | 29 | -------------------------------------------------------------------------------- /tests/continue1.rev: -------------------------------------------------------------------------------- 1 | function main (.text) { 2 | 0x400506: push rbp 3 | 0x400507: rbp = rsp 4 | 0x40050a: rsp -= 16 5 | 0x40050e: *(rbp - 4) = 0 6 | 0x400515: *(rbp - 8) = 2 7 | 0x40051c: jmp loop_0x400560 8 | loop { 9 | loop_0x400560: 10 | # 0x400560: cmp dword ptr [rbp - 4], 9 11 | # 0x400564: jg 0x400570 12 | if (*(rbp - 4) > 9) goto ret_0x400570 13 | 0x400566: eax = *(rbp - 4) 14 | 0x400569: eax += eax 15 | # 0x40056b: cmp eax, dword ptr [rbp - 8] 16 | # 0x40056e: jne 0x40051e 17 | if (eax == *(rbp - 8)) goto ret_0x400570 18 | 0x40051e: edi = 0x400614 "1" 19 | 0x400523: call puts 20 | # 0x400528: cmp dword ptr [rbp - 4], 8 21 | # 0x40052c: jne 0x400558 22 | if (*(rbp - 4) == 8) { 23 | 0x40052e: jmp loop_0x400543 24 | loop { 25 | loop_0x400543: 26 | # 0x400543: cmp dword ptr [rbp - 8], 3 27 | # 0x400547: jle 0x400530 28 | if (*(rbp - 8) > 3) goto break_0x400549 29 | 0x400530: eax = *(rbp - 4) 30 | 0x400533: eax += 10 31 | 0x400536: *(rbp - 8) += eax 32 | 0x400539: edi = 0x400616 "2" 33 | 0x40053e: call puts 34 | } ; loop_0x400543 35 | 36 | break_0x400549: 37 | 0x400549: edx = *(rbp - 4) 38 | 0x40054c: eax = edx 39 | 0x40054e: eax <<= 3 40 | 0x400551: eax += edx 41 | 0x400553: *(rbp - 8) += eax 42 | 0x400556: jmp loop_0x400560 43 | } else { 44 | 0x400558: *(rbp - 4) += 1 45 | 0x40055c: *(rbp - 8) += 1 46 | } 47 | } ; loop_0x400560 48 | 49 | ret_0x400570: 50 | 0x400570: edi = 0x400618 "3" 51 | 0x400575: call puts 52 | 0x40057a: eax = 0 53 | 0x40057f: leave 54 | 0x400580: ret 55 | } 56 | -------------------------------------------------------------------------------- /tests/continue2.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/plasma-disassembler/plasma/ec7df9b2b9b356dd5d8caf01b7e68c0ab5a1ef42/tests/continue2.bin -------------------------------------------------------------------------------- /tests/continue2.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() { 5 | int i = 0, j = 2, z; 6 | 7 | for (z = 0 ; z < 20 ; z++) { 8 | while (i < 10 && j != i*2) { 9 | printf("1\n"); 10 | 11 | if (i == 8) { 12 | printf("2\n"); 13 | continue; 14 | } 15 | 16 | if (j == 5) { 17 | while (1) { 18 | printf("3\n"); 19 | } 20 | } 21 | 22 | i++; 23 | j++; 24 | } 25 | 26 | if (z == 15) { 27 | printf("4\n"); 28 | continue; 29 | } 30 | 31 | printf("5\n"); 32 | } 33 | 34 | printf("6\n"); 35 | 36 | return 0; 37 | } 38 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /tests/continue3.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/plasma-disassembler/plasma/ec7df9b2b9b356dd5d8caf01b7e68c0ab5a1ef42/tests/continue3.bin -------------------------------------------------------------------------------- /tests/continue3.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() { 5 | int i = 0, j; 6 | 7 | for (i = 0 ; i < 1000 ; i++) { 8 | printf("1\n"); 9 | 10 | j = rand(); 11 | if (j == 1) { 12 | if (i < 500) { 13 | printf("2\n"); 14 | if (i < 200) { 15 | printf("3\n"); 16 | if (i == 1 || i == 2 || i == 3) { 17 | printf("4\n"); 18 | } 19 | } 20 | 21 | else if (i == 42) { 22 | while (1) { 23 | printf("loooop!\n"); 24 | } 25 | } 26 | } 27 | printf("continue!\n"); 28 | continue; 29 | } 30 | 31 | printf("5\n"); 32 | } 33 | printf("6\n"); 34 | 35 | return 0; 36 | } 37 | 38 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /tests/diff.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | color() { 4 | local color="$1" 5 | if [ "$3" == "" ]; then 6 | local prefix="" 7 | local txt="$2" 8 | else 9 | local prefix="$2 " 10 | local txt="$3" 11 | fi 12 | echo -en "${prefix}\x1b[;${color}m${txt}\x1b[0m" 13 | } 14 | 15 | red() { 16 | color 31 "$1" "$2" 17 | } 18 | 19 | green() { 20 | color 32 "$1" "$2" 21 | } 22 | 23 | OPTIONS="--nocolor" 24 | VERBOSE=1 25 | 26 | __diff() { 27 | local name=$1 28 | local suffix="" 29 | local more_opt="" 30 | local tmp=tmp$$ 31 | 32 | if [ "$2" != "" ]; then 33 | local more_opt="-x=$2" 34 | local suffix="_$2" 35 | fi 36 | 37 | 38 | if [ -f "tests/${name}${suffix}.rev" ]; then 39 | ./run_plasma.py "tests/${name}.bin" $more_opt $OPTIONS >$tmp 2>/dev/null 40 | if [ $? -eq 0 ]; then 41 | if [ $VERBOSE -eq 1 ]; then 42 | diff $tmp "tests/${name}${suffix}.rev" 43 | else 44 | diff -q $tmp "tests/${name}${suffix}.rev" >/dev/null 45 | fi 46 | 47 | if [ $? -eq 0 ]; then 48 | green "$name$suffix" "[OK]\n" 49 | else 50 | red "$name$suffix" "[FAIL]\n" 51 | fi 52 | rm $tmp 53 | else 54 | red "$name$suffix" "[EXCEPTION]\n" 55 | fi 56 | else 57 | red "$name$suffix" "[NOT FOUND]\n" 58 | fi 59 | } 60 | 61 | name=`basename "$1" .rev` 62 | shift 63 | 64 | while true; do 65 | case "$1" in 66 | "1") 67 | VERBOSE=1 68 | ;; 69 | -*) 70 | OPTIONS="$OPTIONS $1" 71 | ;; 72 | *) 73 | break 74 | ;; 75 | esac 76 | 77 | shift 78 | done 79 | 80 | if [ "$1" == "" ]; then 81 | __diff "$name" 82 | else 83 | while [ "$1" != "" ]; do 84 | __diff "$name" "$1" 85 | shift 86 | done 87 | fi 88 | -------------------------------------------------------------------------------- /tests/dowhile1.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/plasma-disassembler/plasma/ec7df9b2b9b356dd5d8caf01b7e68c0ab5a1ef42/tests/dowhile1.bin -------------------------------------------------------------------------------- /tests/dowhile1.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() { 5 | int j = 2; 6 | 7 | do { 8 | printf("%x\n", j); 9 | j++; 10 | } while (j < 10); 11 | 12 | return 0; 13 | } 14 | 15 | -------------------------------------------------------------------------------- /tests/dowhile1.rev: -------------------------------------------------------------------------------- 1 | function main (.text) { 2 | 0x400506: push rbp 3 | 0x400507: rbp = rsp 4 | 0x40050a: rsp -= 16 5 | 0x40050e: *(rbp - 4) = 2 6 | loop { 7 | loop_0x400515: 8 | 0x400515: eax = *(rbp - 4) 9 | 0x400518: esi = eax 10 | 0x40051a: edi = 0x4005c4 "%x\n" 11 | 0x40051f: eax = 0 12 | 0x400524: call printf 13 | 0x400529: *(rbp - 4) += 1 14 | # 0x40052d: cmp dword ptr [rbp - 4], 9 15 | # 0x400531: jle 0x400515 16 | if (*(rbp - 4) > 9) goto ret_0x400533 17 | } ; loop_0x400515 18 | 19 | ret_0x400533: 20 | 0x400533: eax = 0 21 | 0x400538: leave 22 | 0x400539: ret 23 | } 24 | -------------------------------------------------------------------------------- /tests/dowhile2..rev: -------------------------------------------------------------------------------- 1 | function main { 2 | int32_t var1 3 | int32_t var2 4 | 0x4004b6: push rbp 5 | 0x4004b7: rbp = rsp # mov rbp, rsp 6 | 0x4004ba: var1 = 123 # mov dword ptr [rbp - 4], 0x7b 7 | 0x4004c1: var2 = 5 # mov dword ptr [rbp - 8], 5 8 | loop { 9 | 0x4004c8: var1 += 1 # add dword ptr [rbp - 4], 1 10 | loop { 11 | 0x4004cc: var2 += 1 # add dword ptr [rbp - 8], 1 12 | # 0x4004d0: cmp dword ptr [rbp - 8], 4 13 | # 0x4004d4: jle 0x4004cc 14 | if (var2 > 4) goto 0x4004d6 15 | } 16 | # 0x4004d6: cmp dword ptr [rbp - 4], 9 17 | # 0x4004da: jle 0x4004c8 18 | if (var1 > 9) goto 0x4004dc 19 | } 20 | 0x4004dc: eax = 0 # mov eax, 0 21 | 0x4004e1: pop rbp 22 | 0x4004e2: ret 23 | } 24 | -------------------------------------------------------------------------------- /tests/dowhile2.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/plasma-disassembler/plasma/ec7df9b2b9b356dd5d8caf01b7e68c0ab5a1ef42/tests/dowhile2.bin -------------------------------------------------------------------------------- /tests/dowhile2.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() { 5 | int i = 123, j = 5; 6 | 7 | do { 8 | i++; 9 | do { 10 | j++; 11 | } while (j < 5); 12 | } while (i < 10); 13 | 14 | return 0; 15 | } 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /tests/dowhile2.rev: -------------------------------------------------------------------------------- 1 | function main (.text) { 2 | 0x4004b6: push rbp 3 | 0x4004b7: rbp = rsp 4 | 0x4004ba: *(rbp - 4) = 123 5 | 0x4004c1: *(rbp - 8) = 5 6 | loop { 7 | loop_0x4004c8: 8 | 0x4004c8: *(rbp - 4) += 1 9 | loop { 10 | loop_0x4004cc: 11 | 0x4004cc: *(rbp - 8) += 1 12 | # 0x4004d0: cmp dword ptr [rbp - 8], 4 13 | # 0x4004d4: jle 0x4004cc 14 | if (*(rbp - 8) > 4) goto break_0x4004d6 15 | } ; loop_0x4004cc 16 | 17 | break_0x4004d6: 18 | # 0x4004d6: cmp dword ptr [rbp - 4], 9 19 | # 0x4004da: jle 0x4004c8 20 | if (*(rbp - 4) > 9) goto ret_0x4004dc 21 | } ; loop_0x4004c8 22 | 23 | ret_0x4004dc: 24 | 0x4004dc: eax = 0 25 | 0x4004e1: pop rbp 26 | 0x4004e2: ret 27 | } 28 | -------------------------------------------------------------------------------- /tests/dowhile3.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/plasma-disassembler/plasma/ec7df9b2b9b356dd5d8caf01b7e68c0ab5a1ef42/tests/dowhile3.bin -------------------------------------------------------------------------------- /tests/dowhile3.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() { 5 | int i = 123, j = 5, k = 1; 6 | 7 | do { 8 | i++; 9 | do { 10 | j++; 11 | do { 12 | k++; 13 | } while (k < 4); 14 | } while (j < 2); 15 | } while (i < 5); 16 | 17 | return 0; 18 | } 19 | 20 | 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /tests/dowhile3.rev: -------------------------------------------------------------------------------- 1 | function main (.text) { 2 | 0x4004b6: push rbp 3 | 0x4004b7: rbp = rsp 4 | 0x4004ba: *(rbp - 4) = 123 5 | 0x4004c1: *(rbp - 8) = 5 6 | 0x4004c8: *(rbp - 12) = 1 7 | loop { 8 | loop_0x4004cf: 9 | 0x4004cf: *(rbp - 4) += 1 10 | loop { 11 | loop_0x4004d3: 12 | 0x4004d3: *(rbp - 8) += 1 13 | loop { 14 | loop_0x4004d7: 15 | 0x4004d7: *(rbp - 12) += 1 16 | # 0x4004db: cmp dword ptr [rbp - 0xc], 3 17 | # 0x4004df: jle 0x4004d7 18 | if (*(rbp - 12) > 3) goto break_0x4004e1 19 | } ; loop_0x4004d7 20 | 21 | break_0x4004e1: 22 | # 0x4004e1: cmp dword ptr [rbp - 8], 1 23 | # 0x4004e5: jle 0x4004d3 24 | if (*(rbp - 8) > 1) goto break_0x4004e7 25 | } ; loop_0x4004d3 26 | 27 | break_0x4004e7: 28 | # 0x4004e7: cmp dword ptr [rbp - 4], 4 29 | # 0x4004eb: jle 0x4004cf 30 | if (*(rbp - 4) > 4) goto ret_0x4004ed 31 | } ; loop_0x4004cf 32 | 33 | ret_0x4004ed: 34 | 0x4004ed: eax = 0 35 | 0x4004f2: pop rbp 36 | 0x4004f3: ret 37 | } 38 | -------------------------------------------------------------------------------- /tests/dowhile4.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/plasma-disassembler/plasma/ec7df9b2b9b356dd5d8caf01b7e68c0ab5a1ef42/tests/dowhile4.bin -------------------------------------------------------------------------------- /tests/dowhile4.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() { 5 | int i = 123; 6 | 7 | for (i = 0 ; i < 10 ; i++) { 8 | int j = 0; 9 | do { 10 | printf("1\n"); 11 | j++; 12 | } while (j < 10); 13 | do { 14 | printf("2\n"); 15 | j++; 16 | } while (j < 20); 17 | } 18 | 19 | printf("3\n"); 20 | 21 | return 0; 22 | } 23 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /tests/dowhile4.rev: -------------------------------------------------------------------------------- 1 | function main (.text) { 2 | 0x400506: push rbp 3 | 0x400507: rbp = rsp 4 | 0x40050a: rsp -= 16 5 | 0x40050e: *(rbp - 4) = 123 6 | 0x400515: *(rbp - 4) = 0 7 | 0x40051c: jmp loop_0x400551 8 | loop { 9 | loop_0x400551: 10 | # 0x400551: cmp dword ptr [rbp - 4], 9 11 | # 0x400555: jle 0x40051e 12 | if (*(rbp - 4) > 9) goto ret_0x400557 13 | 0x40051e: *(rbp - 8) = 0 14 | loop { 15 | loop_0x400525: 16 | 0x400525: edi = 0x4005f4 "1" 17 | 0x40052a: call puts 18 | 0x40052f: *(rbp - 8) += 1 19 | # 0x400533: cmp dword ptr [rbp - 8], 9 20 | # 0x400537: jle 0x400525 21 | if (*(rbp - 8) > 9) goto loop_0x400539 22 | } ; loop_0x400525 23 | 24 | loop { 25 | loop_0x400539: 26 | 0x400539: edi = 0x4005f6 "2" 27 | 0x40053e: call puts 28 | 0x400543: *(rbp - 8) += 1 29 | # 0x400547: cmp dword ptr [rbp - 8], 0x13 30 | # 0x40054b: jle 0x400539 31 | if (*(rbp - 8) > 19) goto break_0x40054d 32 | } ; loop_0x400539 33 | 34 | break_0x40054d: 35 | 0x40054d: *(rbp - 4) += 1 36 | } ; loop_0x400551 37 | 38 | ret_0x400557: 39 | 0x400557: edi = 0x4005f8 "3" 40 | 0x40055c: call puts 41 | 0x400561: eax = 0 42 | 0x400566: leave 43 | 0x400567: ret 44 | } 45 | -------------------------------------------------------------------------------- /tests/entryloop1.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/plasma-disassembler/plasma/ec7df9b2b9b356dd5d8caf01b7e68c0ab5a1ef42/tests/entryloop1.bin -------------------------------------------------------------------------------- /tests/entryloop1.c: -------------------------------------------------------------------------------- 1 | #error "This file is just for the make check" 2 | -------------------------------------------------------------------------------- /tests/entryloop1_0x4041b0.rev: -------------------------------------------------------------------------------- 1 | function _start (raw) { 2 | loop { 3 | 0x4041b0: push rbx 4 | 0x4041b1: rbx = rdi 5 | 0x4041b4: call 0x401600 6 | # 0x4041b9: test rax, rax 7 | # 0x4041bc: jne 0x4041c3 8 | if (rax != 0) goto ret_0x4041c3 9 | # 0x4041be: test rbx, rbx 10 | # 0x4041c1: jne 0x4041c5 11 | if (rbx == 0) goto ret_0x4041c3 12 | 0x4041c5: call 0x4043c0 13 | 0x4041ca: nop *(rax + rax) 14 | 0x4041d0: edx = 0 15 | 0x4041d2: rax = -1 16 | 0x4041d9: div rsi 17 | # 0x4041dc: cmp rax, rdi 18 | # 0x4041df: jb 0x4041ea 19 | if (rax (unsigned) >= rdi) { 20 | 0x4041e1: rdi *= rsi 21 | 0x4041e5: jmp _start 22 | } 23 | 0x4041ea: push rax 24 | 0x4041eb: call 0x4043c0 25 | 0x4041f0: jmp _start 26 | } ; _start 27 | 28 | ret_0x4041c3: 29 | 0x4041c3: pop rbx 30 | 0x4041c4: ret 31 | } 32 | -------------------------------------------------------------------------------- /tests/goto1.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/plasma-disassembler/plasma/ec7df9b2b9b356dd5d8caf01b7e68c0ab5a1ef42/tests/goto1.bin -------------------------------------------------------------------------------- /tests/goto1.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() { 5 | int i = rand(); 6 | 7 | if (i == 0) { 8 | printf("NULL\n"); 9 | goto err; 10 | } 11 | 12 | 13 | restart: 14 | i = 5; 15 | while (i < 100) { 16 | printf("1\n"); 17 | printf("2\n"); 18 | int j = 0; 19 | 20 | while (j < 50) { 21 | printf("3\n"); 22 | int tmp = rand(); 23 | if (tmp == 1) { 24 | printf("restart!\n"); 25 | goto restart; 26 | } 27 | 28 | if (tmp == 2) { 29 | printf("stop\n"); 30 | goto err; 31 | } 32 | j++; 33 | } 34 | 35 | i++; 36 | } 37 | 38 | printf("4\n"); 39 | printf("5\n"); 40 | return 0; 41 | 42 | err: 43 | printf("err exit\n"); 44 | return 1; 45 | } 46 | 47 | 48 | 49 | -------------------------------------------------------------------------------- /tests/goto2.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/plasma-disassembler/plasma/ec7df9b2b9b356dd5d8caf01b7e68c0ab5a1ef42/tests/goto2.bin -------------------------------------------------------------------------------- /tests/goto2.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() { 5 | int i = 0, j = 0, k = 0; 6 | 7 | if (i == 0) { 8 | if (k == 5) { 9 | printf("1\n"); 10 | goto label; 11 | } 12 | goto end; 13 | } else { 14 | printf("2\n"); 15 | } 16 | 17 | printf("3\n"); 18 | 19 | label: 20 | printf("4\n"); 21 | 22 | end: 23 | return 0; 24 | } 25 | 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /tests/goto2.rev: -------------------------------------------------------------------------------- 1 | function main (.text) { 2 | 0x400506: push rbp 3 | 0x400507: rbp = rsp 4 | 0x40050a: rsp -= 16 5 | 0x40050e: *(rbp - 4) = 0 6 | 0x400515: *(rbp - 8) = 0 7 | 0x40051c: *(rbp - 12) = 0 8 | # 0x400523: cmp dword ptr [rbp - 4], 0 9 | # 0x400527: jne 0x40053d 10 | if (*(rbp - 4) == 0) { 11 | # 0x400529: cmp dword ptr [rbp - 0xc], 5 12 | # 0x40052d: jne 0x40053b 13 | if (*(rbp - 12) == 5) { 14 | 0x40052f: edi = 0x4005f4 "1" 15 | 0x400534: call puts 16 | 0x400539: jmp 0x400551 17 | } else { 18 | 0x40053b: jmp ret_0x40055b 19 | } 20 | } else { 21 | 0x40053d: edi = 0x4005f6 "2" 22 | 0x400542: call puts 23 | 0x400547: edi = 0x4005f8 "3" 24 | 0x40054c: call puts 25 | 0x400551: edi = 0x4005fa "4" 26 | 0x400556: call puts 27 | } 28 | ret_0x40055b: 29 | 0x40055b: eax = 0 30 | 0x400560: leave 31 | 0x400561: ret 32 | } 33 | -------------------------------------------------------------------------------- /tests/goto3.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/plasma-disassembler/plasma/ec7df9b2b9b356dd5d8caf01b7e68c0ab5a1ef42/tests/goto3.bin -------------------------------------------------------------------------------- /tests/goto3.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() { 5 | int i = 0, j = 0, k = 0; 6 | 7 | while (j < 20) { 8 | if (i == 0) { 9 | if (k == 5) { 10 | printf("1\n"); 11 | goto label; 12 | } 13 | } else { 14 | printf("2\n"); 15 | label: 16 | printf("3\n"); 17 | j++; 18 | } 19 | j += 5; 20 | } 21 | 22 | return 0; 23 | } 24 | 25 | 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /tests/goto3.rev: -------------------------------------------------------------------------------- 1 | function main (.text) { 2 | 0x400506: push rbp 3 | 0x400507: rbp = rsp 4 | 0x40050a: rsp -= 16 5 | 0x40050e: *(rbp - 8) = 0 6 | 0x400515: *(rbp - 4) = 0 7 | 0x40051c: *(rbp - 12) = 0 8 | 0x400523: jmp loop_0x400559 9 | loop { 10 | loop_0x400559: 11 | # 0x400559: cmp dword ptr [rbp - 4], 0x13 12 | # 0x40055d: jle 0x400525 13 | if (*(rbp - 4) > 19) goto ret_0x40055f 14 | # 0x400525: cmp dword ptr [rbp - 8], 0 15 | # 0x400529: jne 0x40053d 16 | if (*(rbp - 8) == 0) { 17 | # 0x40052b: cmp dword ptr [rbp - 0xc], 5 18 | # 0x40052f: jne 0x400555 19 | if (*(rbp - 12) == 5) { 20 | 0x400531: edi = 0x4005f4 "1" 21 | 0x400536: call puts 22 | 0x40053b: jmp 0x400547 23 | } 24 | } else { 25 | 0x40053d: edi = 0x4005f6 "2" 26 | 0x400542: call puts 27 | 0x400547: edi = 0x4005f8 "3" 28 | 0x40054c: call puts 29 | 0x400551: *(rbp - 4) += 1 30 | } 31 | 0x400555: *(rbp - 4) += 5 32 | } ; loop_0x400559 33 | 34 | ret_0x40055f: 35 | 0x40055f: eax = 0 36 | 0x400564: leave 37 | 0x400565: ret 38 | } 39 | -------------------------------------------------------------------------------- /tests/goto4.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/plasma-disassembler/plasma/ec7df9b2b9b356dd5d8caf01b7e68c0ab5a1ef42/tests/goto4.bin -------------------------------------------------------------------------------- /tests/goto4.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() { 4 | int i, j, k; 5 | 6 | while (i < 30) { 7 | printf("1\n"); 8 | if (j == 15) { 9 | printf("2\n"); 10 | goto end; 11 | } 12 | printf("3\n"); 13 | } 14 | 15 | if (i == 123) { 16 | printf("4\n"); 17 | goto finish; 18 | } else { 19 | printf("5\n"); 20 | } 21 | 22 | end: 23 | printf("end\n"); 24 | finish: 25 | printf("finish\n"); 26 | 27 | return 0; 28 | } 29 | -------------------------------------------------------------------------------- /tests/goto4.rev: -------------------------------------------------------------------------------- 1 | function main (.text) { 2 | 0x400506: push rbp 3 | 0x400507: rbp = rsp 4 | 0x40050a: rsp -= 16 5 | 0x40050e: jmp loop_0x400536 6 | loop { 7 | loop_0x400536: 8 | # 0x400536: cmp dword ptr [rbp - 4], 0x1d 9 | # 0x40053a: jle 0x400510 10 | if (*(rbp - 4) > 29) goto break_0x40053c 11 | 0x400510: edi = 0x400604 "1" 12 | 0x400515: call puts 13 | # 0x40051a: cmp dword ptr [rbp - 8], 0xf 14 | # 0x40051e: jne 0x40052c 15 | if (*(rbp - 8) == 15) goto break_0x400520 16 | 0x40052c: edi = 0x400608 "3" 17 | 0x400531: call puts 18 | } ; loop_0x400536 19 | 20 | break_0x400520: 21 | 0x400520: edi = 0x400606 "2" 22 | 0x400525: call puts 23 | 0x40052a: jmp 0x400558 24 | break_0x40053c: 25 | # 0x40053c: cmp dword ptr [rbp - 4], 0x7b 26 | # 0x400540: jne 0x40054e 27 | if (*(rbp - 4) == 123) { 28 | 0x400542: edi = 0x40060a "4" 29 | 0x400547: call puts 30 | 0x40054c: jmp ret_0x400562 31 | } else { 32 | 0x40054e: edi = 0x40060c "5" 33 | 0x400553: call puts 34 | goto 0x400558 35 | } 36 | goto ret_0x400562 37 | 0x400558: edi = 0x40060e "end" 38 | 0x40055d: call puts 39 | ret_0x400562: 40 | 0x400562: edi = 0x400612 "finish" 41 | 0x400567: call puts 42 | 0x40056c: eax = 0 43 | 0x400571: leave 44 | 0x400572: ret 45 | } 46 | -------------------------------------------------------------------------------- /tests/goto5.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/plasma-disassembler/plasma/ec7df9b2b9b356dd5d8caf01b7e68c0ab5a1ef42/tests/goto5.bin -------------------------------------------------------------------------------- /tests/goto5.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() { 4 | int i, j, k; 5 | 6 | if (k) { 7 | while (i < 30) { 8 | printf("1\n"); 9 | if (j == 15) { 10 | printf("2\n"); 11 | goto end; 12 | } 13 | printf("3\n"); 14 | } 15 | } 16 | 17 | if (i == 123) { 18 | printf("4\n"); 19 | goto finish; 20 | } else { 21 | printf("5\n"); 22 | } 23 | 24 | end: 25 | printf("end\n"); 26 | finish: 27 | printf("finish\n"); 28 | 29 | return 0; 30 | } 31 | -------------------------------------------------------------------------------- /tests/goto5.rev: -------------------------------------------------------------------------------- 1 | function main (.text) { 2 | 0x400506: push rbp 3 | 0x400507: rbp = rsp 4 | 0x40050a: rsp -= 16 5 | # 0x40050e: cmp dword ptr [rbp - 4], 0 6 | # 0x400512: je 0x400542 7 | if (*(rbp - 4) != 0) { 8 | 0x400514: jmp loop_0x40053c 9 | loop { 10 | loop_0x40053c: 11 | # 0x40053c: cmp dword ptr [rbp - 8], 0x1d 12 | # 0x400540: jle 0x400516 13 | if (*(rbp - 8) > 29) goto break_0x400542 14 | 0x400516: edi = 0x400604 "1" 15 | 0x40051b: call puts 16 | # 0x400520: cmp dword ptr [rbp - 0xc], 0xf 17 | # 0x400524: jne 0x400532 18 | if (*(rbp - 12) == 15) goto break_0x400526 19 | 0x400532: edi = 0x400608 "3" 20 | 0x400537: call puts 21 | } ; loop_0x40053c 22 | 23 | break_0x400526: 24 | 0x400526: edi = 0x400606 "2" 25 | 0x40052b: call puts 26 | 0x400530: jmp 0x40055e 27 | 0x40055e: edi = 0x40060e "end" 28 | 0x400563: call puts 29 | } 30 | break_0x400542: 31 | # 0x400542: cmp dword ptr [rbp - 8], 0x7b 32 | # 0x400546: jne 0x400554 33 | else if (*(rbp - 8) == 123) { 34 | 0x400548: edi = 0x40060a "4" 35 | 0x40054d: call puts 36 | 0x400552: jmp ret_0x400568 37 | } else { 38 | 0x400554: edi = 0x40060c "5" 39 | 0x400559: call puts 40 | goto 0x40055e 41 | } 42 | ret_0x400568: 43 | 0x400568: edi = 0x400612 "finish" 44 | 0x40056d: call puts 45 | 0x400572: eax = 0 46 | 0x400577: leave 47 | 0x400578: ret 48 | } 49 | -------------------------------------------------------------------------------- /tests/goto6.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/plasma-disassembler/plasma/ec7df9b2b9b356dd5d8caf01b7e68c0ab5a1ef42/tests/goto6.bin -------------------------------------------------------------------------------- /tests/goto6.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | int main() { 4 | int i, j; 5 | for (i = 0 ; i < 20 ; i++) { 6 | printf("1\n"); 7 | 8 | for (j = 0 ; j < 30 ; j++) { 9 | printf("3\n"); 10 | if (j == 2) { 11 | printf("4\n"); 12 | goto next; 13 | } 14 | if (j == 3) { 15 | printf("8\n"); 16 | goto next2; 17 | } 18 | printf("5\n"); 19 | } 20 | 21 | printf("2\n"); 22 | } 23 | 24 | printf("6\n"); 25 | 26 | next: 27 | printf("7\n"); 28 | 29 | next2: 30 | printf("9\n"); 31 | 32 | return 0; 33 | } 34 | -------------------------------------------------------------------------------- /tests/goto6.rev: -------------------------------------------------------------------------------- 1 | function main (.text) { 2 | 0x400506: push rbp 3 | 0x400507: rbp = rsp 4 | 0x40050a: rsp -= 16 5 | 0x40050e: *(rbp - 4) = 0 6 | 0x400515: jmp loop_0x40057a 7 | loop { 8 | loop_0x40057a: 9 | # 0x40057a: cmp dword ptr [rbp - 4], 0x13 10 | # 0x40057e: jle 0x400517 11 | if (*(rbp - 4) > 19) goto break_0x400580 12 | 0x400517: edi = 0x400634 "1" 13 | 0x40051c: call puts 14 | 0x400521: *(rbp - 8) = 0 15 | 0x400528: jmp loop_0x400566 16 | loop { 17 | loop_0x400566: 18 | # 0x400566: cmp dword ptr [rbp - 8], 0x1d 19 | # 0x40056a: jle 0x40052a 20 | if (*(rbp - 8) > 29) goto break_0x40056c 21 | 0x40052a: edi = 0x400636 "3" 22 | 0x40052f: call puts 23 | # 0x400534: cmp dword ptr [rbp - 8], 2 24 | # 0x400538: jne 0x400546 25 | if (*(rbp - 8) == 2) goto break_0x40053a 26 | # 0x400546: cmp dword ptr [rbp - 8], 3 27 | # 0x40054a: jne 0x400558 28 | if (*(rbp - 8) == 3) goto break_0x40054c 29 | 0x400558: edi = 0x40063c "5" 30 | 0x40055d: call puts 31 | 0x400562: *(rbp - 8) += 1 32 | } ; loop_0x400566 33 | 34 | break_0x40056c: 35 | 0x40056c: edi = 0x40063e "2" 36 | 0x400571: call puts 37 | 0x400576: *(rbp - 4) += 1 38 | } ; loop_0x40057a 39 | 40 | break_0x40054c: 41 | 0x40054c: edi = 0x40063a "8" 42 | 0x400551: call puts 43 | 0x400556: jmp ret_0x400594 44 | break_0x40053a: 45 | 0x40053a: edi = 0x400638 "4" 46 | 0x40053f: call puts 47 | 0x400544: jmp 0x40058a 48 | break_0x400580: 49 | 0x400580: edi = 0x400640 "6" 50 | 0x400585: call puts 51 | 0x40058a: edi = 0x400642 "7" 52 | 0x40058f: call puts 53 | ret_0x400594: 54 | 0x400594: edi = 0x400644 "9" 55 | 0x400599: call puts 56 | 0x40059e: eax = 0 57 | 0x4005a3: leave 58 | 0x4005a4: ret 59 | } 60 | -------------------------------------------------------------------------------- /tests/goto7.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/plasma-disassembler/plasma/ec7df9b2b9b356dd5d8caf01b7e68c0ab5a1ef42/tests/goto7.bin -------------------------------------------------------------------------------- /tests/goto7.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | int main() { 4 | int i = 0; 5 | 6 | while (i < 20) { 7 | printf("1\n"); 8 | if (i == 15) { 9 | printf("2\n"); 10 | int j; 11 | for (j = 0 ; j < 10 ; j++) { 12 | printf("3\n"); 13 | if (j == 5) { 14 | printf("4\n"); 15 | if (i == 2) { 16 | printf("foo\n"); 17 | } 18 | else { 19 | printf("bar\n"); 20 | } 21 | printf("11\n"); 22 | } 23 | else { 24 | printf("5\n"); 25 | goto out; 26 | } 27 | } 28 | printf("6\n"); 29 | } 30 | out: 31 | printf("7\n"); 32 | if (i == 16) { 33 | printf("8\n"); 34 | } 35 | else { 36 | printf("9\n"); 37 | } 38 | printf("10\n"); 39 | i++; 40 | } 41 | 42 | return 0; 43 | } 44 | 45 | -------------------------------------------------------------------------------- /tests/goto8.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/plasma-disassembler/plasma/ec7df9b2b9b356dd5d8caf01b7e68c0ab5a1ef42/tests/goto8.bin -------------------------------------------------------------------------------- /tests/goto8.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() { 5 | int i; 6 | 7 | for (;;) { 8 | if (i > 0) { 9 | if (i == 5) 10 | goto end; 11 | } 12 | else { 13 | if (i == -5) 14 | goto end; 15 | } 16 | } 17 | 18 | end: 19 | return 0; 20 | } 21 | -------------------------------------------------------------------------------- /tests/goto8.rev: -------------------------------------------------------------------------------- 1 | function main (.text) { 2 | 0x4004a6: push rbp 3 | 0x4004a7: rbp = rsp 4 | loop { 5 | loop_0x4004aa: 6 | # 0x4004aa: cmp dword ptr [rbp - 4], 0 7 | # 0x4004ae: jle 0x4004b8 8 | if (*(rbp - 4) > 0) { 9 | # 0x4004b0: cmp dword ptr [rbp - 4], 5 10 | # 0x4004b4: jne 0x4004aa 11 | if (*(rbp - 4) == 5) goto break_0x4004b6 12 | } else { 13 | # 0x4004b8: cmp dword ptr [rbp - 4], -5 14 | # 0x4004bc: je 0x4004c0 15 | if (*(rbp - 4) == -5) goto break_0x4004c0 16 | 0x4004be: jmp loop_0x4004aa 17 | } 18 | } ; loop_0x4004aa 19 | 20 | break_0x4004c0: 21 | 0x4004c0: nop 22 | goto ret_0x4004c1 23 | break_0x4004b6: 24 | 0x4004b6: jmp ret_0x4004c1 25 | ret_0x4004c1: 26 | 0x4004c1: eax = 0 27 | 0x4004c6: pop rbp 28 | 0x4004c7: ret 29 | } 30 | -------------------------------------------------------------------------------- /tests/goto9.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/plasma-disassembler/plasma/ec7df9b2b9b356dd5d8caf01b7e68c0ab5a1ef42/tests/goto9.bin -------------------------------------------------------------------------------- /tests/goto9.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() { 5 | int i; 6 | 7 | for (;;) { 8 | if (i > 0) { 9 | if (i == 5) 10 | goto end; 11 | printf("123\n"); 12 | } 13 | else { 14 | if (i == -5) 15 | goto end; 16 | printf("456\n"); 17 | } 18 | printf("789\n"); 19 | } 20 | 21 | end: 22 | return 0; 23 | } 24 | -------------------------------------------------------------------------------- /tests/goto9.rev: -------------------------------------------------------------------------------- 1 | function main (.text) { 2 | 0x4004e6: push rbp 3 | 0x4004e7: rbp = rsp 4 | 0x4004ea: rsp -= 16 5 | loop { 6 | loop_0x4004ee: 7 | # 0x4004ee: cmp dword ptr [rbp - 4], 0 8 | # 0x4004f2: jle 0x400506 9 | if (*(rbp - 4) > 0) { 10 | # 0x4004f4: cmp dword ptr [rbp - 4], 5 11 | # 0x4004f8: je 0x400522 12 | if (*(rbp - 4) == 5) goto break_0x400522 13 | 0x4004fa: edi = 0x4005b4 "123" 14 | 0x4004ff: call puts 15 | 0x400504: jmp 0x400516 16 | } else { 17 | # 0x400506: cmp dword ptr [rbp - 4], -5 18 | # 0x40050a: je 0x400525 19 | if (*(rbp - 4) == -5) goto break_0x400525 20 | 0x40050c: edi = 0x4005b8 "456" 21 | 0x400511: call puts 22 | } 23 | 0x400516: edi = 0x4005bc "789" 24 | 0x40051b: call puts 25 | 0x400520: jmp loop_0x4004ee 26 | } ; loop_0x4004ee 27 | 28 | break_0x400525: 29 | 0x400525: nop 30 | goto ret_0x400526 31 | break_0x400522: 32 | 0x400522: nop 33 | 0x400523: jmp ret_0x400526 34 | ret_0x400526: 35 | 0x400526: eax = 0 36 | 0x40052b: leave 37 | 0x40052c: ret 38 | } 39 | -------------------------------------------------------------------------------- /tests/gotoinloop1.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/plasma-disassembler/plasma/ec7df9b2b9b356dd5d8caf01b7e68c0ab5a1ef42/tests/gotoinloop1.bin -------------------------------------------------------------------------------- /tests/gotoinloop1.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() { 5 | int i, j; 6 | 7 | if (i == 1) { 8 | printf("1\n"); 9 | goto next; 10 | } else { 11 | printf("2\n"); 12 | } 13 | 14 | while (i < 1) { 15 | printf("loop\n"); 16 | if (j == 6) { 17 | printf("3\n"); 18 | } else { 19 | printf("4\n"); 20 | } 21 | 22 | next: 23 | if (j == 5) { 24 | printf("5\n"); 25 | } else { 26 | printf("6\n"); 27 | } 28 | i++; 29 | } 30 | 31 | return 0; 32 | } 33 | -------------------------------------------------------------------------------- /tests/gotoinloop1.rev: -------------------------------------------------------------------------------- 1 | function main (.text) { 2 | 0x400506: push rbp 3 | 0x400507: rbp = rsp 4 | 0x40050a: rsp -= 16 5 | # 0x40050e: cmp dword ptr [rbp - 4], 1 6 | # 0x400512: jne 0x400520 7 | if (*(rbp - 4) == 1) { 8 | 0x400514: edi = 0x400604 "1" 9 | 0x400519: call puts 10 | 0x40051e: jmp 0x400552 11 | } 12 | 0x400520: edi = 0x400606 "2" 13 | 0x400525: call puts 14 | 0x40052a: jmp loop_0x400572 15 | loop { 16 | loop_0x400572: 17 | # 0x400572: cmp dword ptr [rbp - 4], 0 18 | # 0x400576: jle 0x40052c 19 | if (*(rbp - 4) > 0) goto ret_0x400578 20 | 0x40052c: edi = 0x400608 "loop" 21 | 0x400531: call puts 22 | # 0x400536: cmp dword ptr [rbp - 8], 6 23 | # 0x40053a: jne 0x400548 24 | if (*(rbp - 8) == 6) { 25 | 0x40053c: edi = 0x40060d "3" 26 | 0x400541: call puts 27 | 0x400546: jmp 0x400552 28 | } else { 29 | 0x400548: edi = 0x40060f "4" 30 | 0x40054d: call puts 31 | } 32 | # 0x400552: cmp dword ptr [rbp - 8], 5 33 | # 0x400556: jne 0x400564 34 | if (*(rbp - 8) == 5) { 35 | 0x400558: edi = 0x400611 "5" 36 | 0x40055d: call puts 37 | 0x400562: jmp 0x40056e 38 | } else { 39 | 0x400564: edi = 0x400613 "6" 40 | 0x400569: call puts 41 | } 42 | 0x40056e: *(rbp - 4) += 1 43 | } ; loop_0x400572 44 | 45 | ret_0x400578: 46 | 0x400578: eax = 0 47 | 0x40057d: leave 48 | 0x40057e: ret 49 | } 50 | -------------------------------------------------------------------------------- /tests/gotoinloop10.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/plasma-disassembler/plasma/ec7df9b2b9b356dd5d8caf01b7e68c0ab5a1ef42/tests/gotoinloop10.bin -------------------------------------------------------------------------------- /tests/gotoinloop10.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() { 5 | int i, j, k; 6 | 7 | if (i == 1) { 8 | printf("1\n"); 9 | goto next; 10 | } else { 11 | printf("2\n"); 12 | } 13 | 14 | 15 | while (i < 123) { 16 | while (j < 456) { 17 | while (k < 789) { 18 | if (i == j) { 19 | next: 20 | printf("3\n"); 21 | } else { 22 | if (j == k) { 23 | printf("4\n"); 24 | } else if (i == k) { 25 | printf("5\n"); 26 | } 27 | } 28 | printf("6\n"); 29 | } 30 | printf("7\n"); 31 | } 32 | printf("8\n"); 33 | } 34 | 35 | return 0; 36 | } 37 | -------------------------------------------------------------------------------- /tests/gotoinloop11.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/plasma-disassembler/plasma/ec7df9b2b9b356dd5d8caf01b7e68c0ab5a1ef42/tests/gotoinloop11.bin -------------------------------------------------------------------------------- /tests/gotoinloop11.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() { 5 | int i, j, k, l; 6 | 7 | 8 | while (l < 1337) { 9 | if (i == 1) { 10 | printf("1\n"); 11 | goto next; 12 | } else { 13 | printf("2\n"); 14 | } 15 | 16 | 17 | while (i < 123) { 18 | while (j < 456) { 19 | while (k < 789) { 20 | if (i == j) { 21 | next: 22 | printf("3\n"); 23 | } else { 24 | if (j == k) { 25 | printf("4\n"); 26 | } else if (i == k) { 27 | printf("5\n"); 28 | } 29 | } 30 | printf("6\n"); 31 | } 32 | printf("7\n"); 33 | } 34 | printf("8\n"); 35 | } 36 | printf("9\n"); 37 | } 38 | 39 | return 0; 40 | } 41 | 42 | 43 | 44 | 45 | -------------------------------------------------------------------------------- /tests/gotoinloop12.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/plasma-disassembler/plasma/ec7df9b2b9b356dd5d8caf01b7e68c0ab5a1ef42/tests/gotoinloop12.bin -------------------------------------------------------------------------------- /tests/gotoinloop12.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() { 5 | int i, j, k; 6 | 7 | if (i == 1) { 8 | printf("1\n"); 9 | goto next; 10 | } else { 11 | printf("2\n"); 12 | } 13 | 14 | 15 | for (;;) { 16 | while (j < 456) { 17 | while (k < 789) { 18 | if (i == j) { 19 | next: 20 | printf("3\n"); 21 | } else { 22 | if (j == k) { 23 | printf("4\n"); 24 | } else if (i == k) { 25 | printf("5\n"); 26 | } 27 | } 28 | printf("6\n"); 29 | } 30 | } 31 | } 32 | 33 | return 0; 34 | } 35 | 36 | 37 | 38 | -------------------------------------------------------------------------------- /tests/gotoinloop12.rev: -------------------------------------------------------------------------------- 1 | function main (.text) { 2 | 0x400506: push rbp 3 | 0x400507: rbp = rsp 4 | 0x40050a: rsp -= 16 5 | # 0x40050e: cmp dword ptr [rbp - 4], 1 6 | # 0x400512: jne 0x400520 7 | if (*(rbp - 4) == 1) { 8 | 0x400514: edi = 0x400614 "1" 9 | 0x400519: call puts 10 | 0x40051e: jmp 0x400536 11 | } 12 | 0x400520: edi = 0x400616 "2" 13 | 0x400525: call puts 14 | 0x40052a: jmp loop_0x40057b 15 | for (;;) { 16 | loop_0x40057b: 17 | # 0x40057b: cmp dword ptr [rbp - 8], 0x1c7 18 | # 0x400582: jle 0x400572 19 | if (*(rbp - 8) > 455) { 20 | 0x400584: jmp 0x40052c 21 | 0x40052c: jmp loop_0x40057b 22 | } 23 | loop { 24 | loop_0x400572: 25 | # 0x400572: cmp dword ptr [rbp - 0xc], 0x314 26 | # 0x400579: jle 0x40052e 27 | if (*(rbp - 12) > 788) goto loop_0x40057b 28 | 0x40052e: eax = *(rbp - 4) 29 | # 0x400531: cmp eax, dword ptr [rbp - 8] 30 | # 0x400534: jne 0x400542 31 | if (eax == *(rbp - 8)) { 32 | 0x400536: edi = 0x400618 "3" 33 | 0x40053b: call puts 34 | 0x400540: jmp 0x400568 35 | } 36 | 0x400542: eax = *(rbp - 8) 37 | # 0x400545: cmp eax, dword ptr [rbp - 0xc] 38 | # 0x400548: jne 0x400556 39 | if (eax == *(rbp - 12)) { 40 | 0x40054a: edi = 0x40061a "4" 41 | 0x40054f: call puts 42 | 0x400554: jmp 0x400568 43 | } else { 44 | 0x400556: eax = *(rbp - 4) 45 | # 0x400559: cmp eax, dword ptr [rbp - 0xc] 46 | # 0x40055c: jne 0x400568 47 | if (eax == *(rbp - 12)) { 48 | 0x40055e: edi = 0x40061c "5" 49 | 0x400563: call puts 50 | } 51 | } 52 | 0x400568: edi = 0x40061e "6" 53 | 0x40056d: call puts 54 | } ; loop_0x400572 55 | 56 | } ; loop_0x40057b 57 | 58 | } 59 | -------------------------------------------------------------------------------- /tests/gotoinloop13.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/plasma-disassembler/plasma/ec7df9b2b9b356dd5d8caf01b7e68c0ab5a1ef42/tests/gotoinloop13.bin -------------------------------------------------------------------------------- /tests/gotoinloop13.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() { 5 | int i, j; 6 | 7 | if (i == 1337) { 8 | printf("1\n"); 9 | goto next; 10 | } 11 | 12 | while (i < 15) { 13 | printf("2\n"); 14 | next: 15 | for (j = 0 ; j < 20 ; j++) { 16 | printf("3\n"); 17 | } 18 | i++; 19 | } 20 | 21 | return 0; 22 | } 23 | -------------------------------------------------------------------------------- /tests/gotoinloop13.rev: -------------------------------------------------------------------------------- 1 | function main (.text) { 2 | 0x400506: push rbp 3 | 0x400507: rbp = rsp 4 | 0x40050a: rsp -= 16 5 | # 0x40050e: cmp dword ptr [rbp - 4], 0x539 6 | # 0x400515: jne 0x40054e 7 | if (*(rbp - 4) == 1337) { 8 | 0x400517: edi = 0x4005e4 "1" 9 | 0x40051c: call puts 10 | 0x400521: jmp 0x40052d 11 | } 12 | loop { 13 | loop_0x40054e: 14 | # 0x40054e: cmp dword ptr [rbp - 4], 0xe 15 | # 0x400552: jle 0x400523 16 | if (*(rbp - 4) > 14) goto ret_0x400554 17 | 0x400523: edi = 0x4005e6 "2" 18 | 0x400528: call puts 19 | 0x40052d: *(rbp - 8) = 0 20 | 0x400534: jmp loop_0x400544 21 | loop { 22 | loop_0x400544: 23 | # 0x400544: cmp dword ptr [rbp - 8], 0x13 24 | # 0x400548: jle 0x400536 25 | if (*(rbp - 8) > 19) goto break_0x40054a 26 | 0x400536: edi = 0x4005e8 "3" 27 | 0x40053b: call puts 28 | 0x400540: *(rbp - 8) += 1 29 | } ; loop_0x400544 30 | 31 | break_0x40054a: 32 | 0x40054a: *(rbp - 4) += 1 33 | } ; loop_0x40054e 34 | 35 | ret_0x400554: 36 | 0x400554: eax = 0 37 | 0x400559: leave 38 | 0x40055a: ret 39 | } 40 | -------------------------------------------------------------------------------- /tests/gotoinloop14.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/plasma-disassembler/plasma/ec7df9b2b9b356dd5d8caf01b7e68c0ab5a1ef42/tests/gotoinloop14.bin -------------------------------------------------------------------------------- /tests/gotoinloop14.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() { 5 | int i, j; 6 | 7 | if (i == 1337) { 8 | while (i < 15) { 9 | if (i == 2) { 10 | printf("1\n"); 11 | goto next; 12 | } 13 | i++; 14 | } 15 | } 16 | 17 | while (i < 15) { 18 | if (i == 3) { 19 | next: 20 | printf("2\n"); 21 | } 22 | i++; 23 | } 24 | 25 | return 0; 26 | } 27 | -------------------------------------------------------------------------------- /tests/gotoinloop14.rev: -------------------------------------------------------------------------------- 1 | function main (.text) { 2 | 0x400506: push rbp 3 | 0x400507: rbp = rsp 4 | 0x40050a: rsp -= 16 5 | # 0x40050e: cmp dword ptr [rbp - 4], 0x539 6 | # 0x400515: jne 0x40054b 7 | if (*(rbp - 4) == 1337) { 8 | 0x400517: jmp loop_0x40052f 9 | loop { 10 | loop_0x40052f: 11 | # 0x40052f: cmp dword ptr [rbp - 4], 0xe 12 | # 0x400533: jle 0x400519 13 | if (*(rbp - 4) > 14) goto break_0x400535 14 | # 0x400519: cmp dword ptr [rbp - 4], 2 15 | # 0x40051d: jne 0x40052b 16 | if (*(rbp - 4) == 2) goto break_0x40051f 17 | 0x40052b: *(rbp - 4) += 1 18 | } ; loop_0x40052f 19 | 20 | break_0x40051f: 21 | 0x40051f: edi = 0x4005e4 "1" 22 | 0x400524: call puts 23 | 0x400529: jmp 0x40053d 24 | break_0x400535: 25 | 0x400535: jmp loop_0x40054b 26 | 0x40053d: edi = 0x4005e6 "2" 27 | 0x400542: call puts 28 | 0x400547: *(rbp - 4) += 1 29 | } 30 | loop { 31 | loop_0x40054b: 32 | # 0x40054b: cmp dword ptr [rbp - 4], 0xe 33 | # 0x40054f: jle 0x400537 34 | if (*(rbp - 4) > 14) goto ret_0x400551 35 | # 0x400537: cmp dword ptr [rbp - 4], 3 36 | # 0x40053b: jne 0x400547 37 | if (*(rbp - 4) == 3) { 38 | goto 0x40053d 39 | } 40 | goto 0x400547 41 | } ; loop_0x40054b 42 | 43 | ret_0x400551: 44 | 0x400551: eax = 0 45 | 0x400556: leave 46 | 0x400557: ret 47 | } 48 | -------------------------------------------------------------------------------- /tests/gotoinloop15.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/plasma-disassembler/plasma/ec7df9b2b9b356dd5d8caf01b7e68c0ab5a1ef42/tests/gotoinloop15.bin -------------------------------------------------------------------------------- /tests/gotoinloop15.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() { 5 | int i, j; 6 | 7 | if (i == 1337) { 8 | printf("1\n"); 9 | goto next; 10 | } 11 | 12 | while (i < 15) { 13 | j = 0; 14 | while (j < 30) { 15 | printf("2\n"); 16 | j++; 17 | } 18 | printf("3\n"); 19 | j = 0; 20 | while (j < 20) { 21 | if (j == 10) { 22 | next: 23 | printf("4\n"); 24 | } 25 | j++; 26 | } 27 | printf("5\n"); 28 | j = 0; 29 | while (j < 30) { 30 | printf("6\n"); 31 | j++; 32 | } 33 | i++; 34 | } 35 | 36 | return 0; 37 | } 38 | 39 | -------------------------------------------------------------------------------- /tests/gotoinloop16.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/plasma-disassembler/plasma/ec7df9b2b9b356dd5d8caf01b7e68c0ab5a1ef42/tests/gotoinloop16.bin -------------------------------------------------------------------------------- /tests/gotoinloop16.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() { 5 | int i, j; 6 | 7 | if (i == 1337) { 8 | while (i < 15) { 9 | if (i == 2) { 10 | printf("1\n"); 11 | goto next; 12 | } 13 | i++; 14 | } 15 | } 16 | 17 | while (i < 15) { 18 | next: 19 | printf("2\n"); 20 | i++; 21 | } 22 | 23 | return 0; 24 | } 25 | -------------------------------------------------------------------------------- /tests/gotoinloop16.rev: -------------------------------------------------------------------------------- 1 | function main (.text) { 2 | 0x400506: push rbp 3 | 0x400507: rbp = rsp 4 | 0x40050a: rsp -= 16 5 | # 0x40050e: cmp dword ptr [rbp - 4], 0x539 6 | # 0x400515: jne 0x400545 7 | if (*(rbp - 4) == 1337) { 8 | 0x400517: jmp loop_0x40052f 9 | loop { 10 | loop_0x40052f: 11 | # 0x40052f: cmp dword ptr [rbp - 4], 0xe 12 | # 0x400533: jle 0x400519 13 | if (*(rbp - 4) > 14) goto break_0x400535 14 | # 0x400519: cmp dword ptr [rbp - 4], 2 15 | # 0x40051d: jne 0x40052b 16 | if (*(rbp - 4) == 2) goto break_0x40051f 17 | 0x40052b: *(rbp - 4) += 1 18 | } ; loop_0x40052f 19 | 20 | break_0x40051f: 21 | 0x40051f: edi = 0x4005e4 "1" 22 | 0x400524: call puts 23 | 0x400529: jmp 0x400537 24 | break_0x400535: 25 | 0x400535: jmp loop_0x400545 26 | 0x400537: edi = 0x4005e6 "2" 27 | 0x40053c: call puts 28 | 0x400541: *(rbp - 4) += 1 29 | } 30 | loop { 31 | loop_0x400545: 32 | # 0x400545: cmp dword ptr [rbp - 4], 0xe 33 | # 0x400549: jle 0x400537 34 | if (*(rbp - 4) > 14) goto ret_0x40054b 35 | goto 0x400537 36 | } ; loop_0x400545 37 | 38 | ret_0x40054b: 39 | 0x40054b: eax = 0 40 | 0x400550: leave 41 | 0x400551: ret 42 | } 43 | -------------------------------------------------------------------------------- /tests/gotoinloop17.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/plasma-disassembler/plasma/ec7df9b2b9b356dd5d8caf01b7e68c0ab5a1ef42/tests/gotoinloop17.bin -------------------------------------------------------------------------------- /tests/gotoinloop17.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() { 5 | int i, j; 6 | 7 | if (i == 1) { 8 | printf("1\n"); 9 | while (i < 10) { 10 | if (i == 2) 11 | goto next; 12 | } 13 | printf("2\n"); 14 | __asm__("ret"); 15 | } 16 | 17 | while (j < 15) { 18 | next: 19 | printf("3\n"); 20 | } 21 | 22 | return 0; 23 | } 24 | -------------------------------------------------------------------------------- /tests/gotoinloop17.rev: -------------------------------------------------------------------------------- 1 | function main (.text) { 2 | 0x400506: push rbp 3 | 0x400507: rbp = rsp 4 | 0x40050a: rsp -= 16 5 | # 0x40050e: cmp dword ptr [rbp - 4], 1 6 | # 0x400512: jne 0x400544 7 | if (*(rbp - 4) == 1) { 8 | 0x400514: edi = 0x4005e4 "1" 9 | 0x400519: call puts 10 | 0x40051e: jmp loop_0x400526 11 | loop { 12 | loop_0x400526: 13 | # 0x400526: cmp dword ptr [rbp - 4], 9 14 | # 0x40052a: jle 0x400520 15 | if (*(rbp - 4) > 9) goto ret_0x40052c 16 | # 0x400520: cmp dword ptr [rbp - 4], 2 17 | # 0x400524: je 0x400539 18 | if (*(rbp - 4) == 2) goto break_0x400539 19 | } ; loop_0x400526 20 | 21 | break_0x400539: 22 | 0x400539: nop 23 | goto 0x40053a 24 | ret_0x40052c: 25 | 0x40052c: edi = 0x4005e6 "2" 26 | 0x400531: call puts 27 | 0x400536: ret 28 | } 29 | loop { 30 | loop_0x400544: 31 | # 0x400544: cmp dword ptr [rbp - 8], 0xe 32 | # 0x400548: jle 0x40053a 33 | if (*(rbp - 8) > 14) goto ret_0x40054a 34 | 0x40053a: edi = 0x4005e8 "3" 35 | 0x40053f: call puts 36 | } ; loop_0x400544 37 | 38 | ret_0x40054a: 39 | 0x40054a: eax = 0 40 | 0x40054f: leave 41 | 0x400550: ret 42 | } 43 | -------------------------------------------------------------------------------- /tests/gotoinloop18.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/plasma-disassembler/plasma/ec7df9b2b9b356dd5d8caf01b7e68c0ab5a1ef42/tests/gotoinloop18.bin -------------------------------------------------------------------------------- /tests/gotoinloop18.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() { 5 | int i, j, k; 6 | 7 | for (i = 0 ; i < 100 ; i++) { 8 | printf("1\n"); 9 | 10 | while (j < 20) { 11 | printf("2\n"); 12 | if (j == 10) { 13 | loop1: 14 | printf("3\n"); 15 | } 16 | if (j == 15) 17 | goto loop2; 18 | j++; 19 | } 20 | 21 | printf("4\n"); 22 | 23 | while (k < 30) { 24 | printf("5\n"); 25 | if (k == 20) { 26 | loop2: 27 | printf("6\n"); 28 | } 29 | if (k == 25) 30 | goto loop1; 31 | k++; 32 | } 33 | } 34 | 35 | return 0; 36 | } 37 | -------------------------------------------------------------------------------- /tests/gotoinloop19.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/plasma-disassembler/plasma/ec7df9b2b9b356dd5d8caf01b7e68c0ab5a1ef42/tests/gotoinloop19.bin -------------------------------------------------------------------------------- /tests/gotoinloop19.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() { 5 | int i, j, k; 6 | 7 | printf("1\n"); 8 | 9 | while (j < 20) { 10 | printf("2\n"); 11 | if (j == 10) { 12 | loop1: 13 | printf("3\n"); 14 | } 15 | if (j == 15) 16 | goto loop2; 17 | j++; 18 | } 19 | 20 | printf("4\n"); 21 | 22 | while (k < 30) { 23 | printf("5\n"); 24 | if (k == 20) { 25 | loop2: 26 | printf("6\n"); 27 | } 28 | if (k == 25) 29 | goto loop1; 30 | k++; 31 | } 32 | 33 | return 0; 34 | } 35 | -------------------------------------------------------------------------------- /tests/gotoinloop2.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/plasma-disassembler/plasma/ec7df9b2b9b356dd5d8caf01b7e68c0ab5a1ef42/tests/gotoinloop2.bin -------------------------------------------------------------------------------- /tests/gotoinloop2.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() { 5 | int i, j; 6 | 7 | if (i == 1) { 8 | printf("1\n"); 9 | } else { 10 | printf("2\n"); 11 | goto next; 12 | } 13 | 14 | while (i < 1) { 15 | printf("loop\n"); 16 | if (j == 6) { 17 | printf("3\n"); 18 | } else { 19 | printf("4\n"); 20 | } 21 | 22 | next: 23 | if (j == 5) { 24 | printf("5\n"); 25 | } else { 26 | printf("6\n"); 27 | } 28 | i++; 29 | } 30 | 31 | return 0; 32 | } 33 | 34 | -------------------------------------------------------------------------------- /tests/gotoinloop2.rev: -------------------------------------------------------------------------------- 1 | function main (.text) { 2 | 0x400506: push rbp 3 | 0x400507: rbp = rsp 4 | 0x40050a: rsp -= 16 5 | # 0x40050e: cmp dword ptr [rbp - 4], 1 6 | # 0x400512: jne 0x400520 7 | if (*(rbp - 4) == 1) { 8 | 0x400514: edi = 0x400604 "1" 9 | 0x400519: call puts 10 | 0x40051e: jmp 0x400572 11 | } 12 | 0x400520: edi = 0x400606 "2" 13 | 0x400525: call puts 14 | 0x40052a: jmp loop_0x400552 15 | loop { 16 | loop_0x400552: 17 | # 0x400552: cmp dword ptr [rbp - 8], 5 18 | # 0x400556: jne 0x400564 19 | if (*(rbp - 8) == 5) { 20 | 0x400558: edi = 0x400611 "5" 21 | 0x40055d: call puts 22 | 0x400562: jmp 0x40056e 23 | } else { 24 | 0x400564: edi = 0x400613 "6" 25 | 0x400569: call puts 26 | } 27 | 0x40056e: *(rbp - 4) += 1 28 | # 0x400572: cmp dword ptr [rbp - 4], 0 29 | # 0x400576: jle 0x40052c 30 | if (*(rbp - 4) > 0) goto ret_0x400578 31 | 0x40052c: edi = 0x400608 "loop" 32 | 0x400531: call puts 33 | # 0x400536: cmp dword ptr [rbp - 8], 6 34 | # 0x40053a: jne 0x400548 35 | if (*(rbp - 8) == 6) { 36 | 0x40053c: edi = 0x40060d "3" 37 | 0x400541: call puts 38 | 0x400546: jmp loop_0x400552 39 | } else { 40 | 0x400548: edi = 0x40060f "4" 41 | 0x40054d: call puts 42 | } 43 | } ; loop_0x400552 44 | 45 | ret_0x400578: 46 | 0x400578: eax = 0 47 | 0x40057d: leave 48 | 0x40057e: ret 49 | } 50 | -------------------------------------------------------------------------------- /tests/gotoinloop20_2_nestedloop7.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/plasma-disassembler/plasma/ec7df9b2b9b356dd5d8caf01b7e68c0ab5a1ef42/tests/gotoinloop20_2_nestedloop7.bin -------------------------------------------------------------------------------- /tests/gotoinloop20_nestedloop7.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/plasma-disassembler/plasma/ec7df9b2b9b356dd5d8caf01b7e68c0ab5a1ef42/tests/gotoinloop20_nestedloop7.bin -------------------------------------------------------------------------------- /tests/gotoinloop20_nestedloop7.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() { 5 | int i, j, k, l, m, n, o; 6 | 7 | while (i != 0) { 8 | if (j == 0) { 9 | while (l < 0) { 10 | printf("4\n"); 11 | } 12 | printf("5\n"); 13 | } else { 14 | printf("6\n"); 15 | do { 16 | if (m < 0) { 17 | goto loop2end; 18 | } 19 | } while (n <= 0); 20 | 21 | while(o > 0) { 22 | printf("7\n"); 23 | loop2end: 24 | printf("10\n"); 25 | } 26 | 27 | printf("8\n"); 28 | } 29 | } 30 | 31 | return 0; 32 | } 33 | -------------------------------------------------------------------------------- /tests/gotoinloop20_nestedloop7.rev: -------------------------------------------------------------------------------- 1 | function main (.text) { 2 | 0x67a: push rbp 3 | 0x67b: rbp = rsp 4 | 0x67e: rsp -= 32 5 | 0x682: jmp loop_0x6f3 6 | loop { 7 | loop_0x6f3: 8 | # 0x6f3: cmp dword ptr [rbp - 0x18], 0 9 | # 0x6f7: jne 0x684 10 | if (*(rbp - 24) == 0) goto ret_0x6f9 11 | # 0x684: cmp dword ptr [rbp - 0x14], 0 12 | # 0x688: jne 0x6ac 13 | if (*(rbp - 20) == 0) { 14 | 0x68a: jmp loop_0x698 15 | loop { 16 | loop_0x698: 17 | # 0x698: cmp dword ptr [rbp - 4], 0 18 | # 0x69c: js 0x68c 19 | if (*(rbp - 4) >= 0) goto break_0x69e 20 | 0x68c: rdi = 0x784 "4" 21 | 0x693: call puts 22 | } ; loop_0x698 23 | 24 | break_0x69e: 25 | 0x69e: rdi = 0x786 "5" 26 | 0x6a5: call puts 27 | 0x6aa: jmp loop_0x6f3 28 | } else { 29 | 0x6ac: rdi = 0x788 "6" 30 | 0x6b3: call puts 31 | loop { 32 | loop_0x6b8: 33 | # 0x6b8: cmp dword ptr [rbp - 0x10], 0 34 | # 0x6bc: js 0x6d4 35 | if (*(rbp - 16) < 0) goto break_0x6d4 36 | # 0x6be: cmp dword ptr [rbp - 0xc], 0 37 | # 0x6c2: jle 0x6b8 38 | if (*(rbp - 12) > 0) goto break_0x6c4 39 | } ; loop_0x6b8 40 | 41 | break_0x6c4: 42 | 0x6c4: jmp loop_0x6e1 43 | loop { 44 | loop_0x6e1: 45 | # 0x6e1: cmp dword ptr [rbp - 8], 0 46 | # 0x6e5: jg 0x6c6 47 | if (*(rbp - 8) <= 0) goto break_0x6e7 48 | 0x6c6: rdi = 0x78a "7" 49 | 0x6cd: call puts 50 | 0x6d2: jmp 0x6d5 51 | 0x6d5: rdi = 0x78c "10" 52 | 0x6dc: call puts 53 | } ; loop_0x6e1 54 | 55 | break_0x6e7: 56 | 0x6e7: rdi = 0x78f "8" 57 | 0x6ee: call puts 58 | } 59 | } ; loop_0x6f3 60 | 61 | break_0x6d4: 62 | 0x6d4: nop 63 | goto 0x6d5 64 | ret_0x6f9: 65 | 0x6f9: eax = 0 66 | 0x6fe: leave 67 | 0x6ff: ret 68 | } 69 | -------------------------------------------------------------------------------- /tests/gotoinloop3.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/plasma-disassembler/plasma/ec7df9b2b9b356dd5d8caf01b7e68c0ab5a1ef42/tests/gotoinloop3.bin -------------------------------------------------------------------------------- /tests/gotoinloop3.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() { 5 | int i, j; 6 | 7 | if (i == 1) { 8 | printf("1\n"); 9 | goto next; 10 | } else { 11 | printf("2\n"); 12 | } 13 | 14 | for (;;) { 15 | printf("loop\n"); 16 | if (j == 6) { 17 | printf("3\n"); 18 | } else { 19 | printf("4\n"); 20 | } 21 | 22 | next: 23 | if (j == 5) { 24 | printf("5\n"); 25 | } else { 26 | printf("6\n"); 27 | } 28 | i++; 29 | } 30 | 31 | return 0; 32 | } 33 | 34 | -------------------------------------------------------------------------------- /tests/gotoinloop3.rev: -------------------------------------------------------------------------------- 1 | function main (.text) { 2 | 0x400506: push rbp 3 | 0x400507: rbp = rsp 4 | 0x40050a: rsp -= 16 5 | # 0x40050e: cmp dword ptr [rbp - 4], 1 6 | # 0x400512: jne 0x400520 7 | if (*(rbp - 4) == 1) { 8 | 0x400514: edi = 0x400604 "1" 9 | 0x400519: call puts 10 | 0x40051e: jmp 0x400550 11 | } 12 | 0x400520: edi = 0x400606 "2" 13 | 0x400525: call puts 14 | for (;;) { 15 | loop_0x40052a: 16 | 0x40052a: edi = 0x400608 "loop" 17 | 0x40052f: call puts 18 | # 0x400534: cmp dword ptr [rbp - 8], 6 19 | # 0x400538: jne 0x400546 20 | if (*(rbp - 8) == 6) { 21 | 0x40053a: edi = 0x40060d "3" 22 | 0x40053f: call puts 23 | 0x400544: jmp 0x400550 24 | } else { 25 | 0x400546: edi = 0x40060f "4" 26 | 0x40054b: call puts 27 | } 28 | # 0x400550: cmp dword ptr [rbp - 8], 5 29 | # 0x400554: jne 0x400562 30 | if (*(rbp - 8) == 5) { 31 | 0x400556: edi = 0x400611 "5" 32 | 0x40055b: call puts 33 | 0x400560: jmp 0x40056c 34 | } else { 35 | 0x400562: edi = 0x400613 "6" 36 | 0x400567: call puts 37 | } 38 | 0x40056c: *(rbp - 4) += 1 39 | 0x400570: jmp loop_0x40052a 40 | } ; loop_0x40052a 41 | 42 | } 43 | -------------------------------------------------------------------------------- /tests/gotoinloop4.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/plasma-disassembler/plasma/ec7df9b2b9b356dd5d8caf01b7e68c0ab5a1ef42/tests/gotoinloop4.bin -------------------------------------------------------------------------------- /tests/gotoinloop4.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() { 5 | int i, j; 6 | 7 | if (i == 1) { 8 | printf("1\n"); 9 | } else { 10 | printf("2\n"); 11 | goto next; 12 | } 13 | 14 | for (;;) { 15 | printf("loop\n"); 16 | if (j == 6) { 17 | printf("3\n"); 18 | } else { 19 | printf("4\n"); 20 | } 21 | 22 | next: 23 | if (j == 5) { 24 | printf("5\n"); 25 | } else { 26 | printf("6\n"); 27 | } 28 | i++; 29 | } 30 | 31 | return 0; 32 | } 33 | 34 | 35 | -------------------------------------------------------------------------------- /tests/gotoinloop4.rev: -------------------------------------------------------------------------------- 1 | function main (.text) { 2 | 0x400506: push rbp 3 | 0x400507: rbp = rsp 4 | 0x40050a: rsp -= 16 5 | # 0x40050e: cmp dword ptr [rbp - 4], 1 6 | # 0x400512: jne 0x400520 7 | if (*(rbp - 4) == 1) { 8 | 0x400514: edi = 0x400604 "1" 9 | 0x400519: call puts 10 | 0x40051e: jmp 0x40052c 11 | } 12 | 0x400520: edi = 0x400606 "2" 13 | 0x400525: call puts 14 | 0x40052a: jmp loop_0x400552 15 | for (;;) { 16 | loop_0x400552: 17 | # 0x400552: cmp dword ptr [rbp - 8], 5 18 | # 0x400556: jne 0x400564 19 | if (*(rbp - 8) == 5) { 20 | 0x400558: edi = 0x400611 "5" 21 | 0x40055d: call puts 22 | 0x400562: jmp 0x40056e 23 | } else { 24 | 0x400564: edi = 0x400613 "6" 25 | 0x400569: call puts 26 | } 27 | 0x40056e: *(rbp - 4) += 1 28 | 0x400572: jmp 0x40052c 29 | 0x40052c: edi = 0x400608 "loop" 30 | 0x400531: call puts 31 | # 0x400536: cmp dword ptr [rbp - 8], 6 32 | # 0x40053a: jne 0x400548 33 | if (*(rbp - 8) == 6) { 34 | 0x40053c: edi = 0x40060d "3" 35 | 0x400541: call puts 36 | 0x400546: jmp loop_0x400552 37 | } else { 38 | 0x400548: edi = 0x40060f "4" 39 | 0x40054d: call puts 40 | } 41 | } ; loop_0x400552 42 | 43 | } 44 | -------------------------------------------------------------------------------- /tests/gotoinloop5.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/plasma-disassembler/plasma/ec7df9b2b9b356dd5d8caf01b7e68c0ab5a1ef42/tests/gotoinloop5.bin -------------------------------------------------------------------------------- /tests/gotoinloop5.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() { 5 | int i, j; 6 | 7 | if (i == 1) { 8 | printf("1\n"); 9 | goto next_1; 10 | } else if (i == 2) { 11 | printf("2\n"); 12 | goto next_2; 13 | } else { 14 | printf("3\n"); 15 | } 16 | 17 | while (i < 10) { 18 | printf("loop\n"); 19 | if (j == 111) { 20 | printf("3\n"); 21 | } else { 22 | printf("4\n"); 23 | } 24 | 25 | next_1: 26 | if (j == 222) { 27 | printf("5\n"); 28 | } else { 29 | printf("6\n"); 30 | } 31 | 32 | next_2: 33 | if (j == 333) { 34 | printf("7\n"); 35 | } else { 36 | printf("8\n"); 37 | } 38 | 39 | i++; 40 | } 41 | 42 | return 0; 43 | } 44 | 45 | -------------------------------------------------------------------------------- /tests/gotoinloop5.rev: -------------------------------------------------------------------------------- 1 | function main (.text) { 2 | 0x400506: push rbp 3 | 0x400507: rbp = rsp 4 | 0x40050a: rsp -= 16 5 | # 0x40050e: cmp dword ptr [rbp - 4], 1 6 | # 0x400512: jne 0x400520 7 | if (*(rbp - 4) == 1) { 8 | 0x400514: edi = 0x400644 "1" 9 | 0x400519: call puts 10 | 0x40051e: jmp 0x400564 11 | } 12 | # 0x400520: cmp dword ptr [rbp - 4], 2 13 | # 0x400524: jne 0x400532 14 | if (*(rbp - 4) == 2) { 15 | 0x400526: edi = 0x400646 "2" 16 | 0x40052b: call puts 17 | 0x400530: jmp 0x400583 18 | } 19 | 0x400532: edi = 0x400648 "3" 20 | 0x400537: call puts 21 | 0x40053c: jmp loop_0x4005a6 22 | loop { 23 | loop_0x4005a6: 24 | # 0x4005a6: cmp dword ptr [rbp - 4], 9 25 | # 0x4005aa: jle 0x40053e 26 | if (*(rbp - 4) > 9) goto ret_0x4005ac 27 | 0x40053e: edi = 0x40064a "loop" 28 | 0x400543: call puts 29 | # 0x400548: cmp dword ptr [rbp - 8], 0x6f 30 | # 0x40054c: jne 0x40055a 31 | if (*(rbp - 8) == 111) { 32 | 0x40054e: edi = 0x400648 "3" 33 | 0x400553: call puts 34 | 0x400558: jmp 0x400564 35 | } else { 36 | 0x40055a: edi = 0x40064f "4" 37 | 0x40055f: call puts 38 | } 39 | # 0x400564: cmp dword ptr [rbp - 8], 0xde 40 | # 0x40056b: jne 0x400579 41 | if (*(rbp - 8) == 222) { 42 | 0x40056d: edi = 0x400651 "5" 43 | 0x400572: call puts 44 | 0x400577: jmp 0x400583 45 | } else { 46 | 0x400579: edi = 0x400653 "6" 47 | 0x40057e: call puts 48 | } 49 | # 0x400583: cmp dword ptr [rbp - 8], 0x14d 50 | # 0x40058a: jne 0x400598 51 | if (*(rbp - 8) == 333) { 52 | 0x40058c: edi = 0x400655 "7" 53 | 0x400591: call puts 54 | 0x400596: jmp 0x4005a2 55 | } else { 56 | 0x400598: edi = 0x400657 "8" 57 | 0x40059d: call puts 58 | } 59 | 0x4005a2: *(rbp - 4) += 1 60 | } ; loop_0x4005a6 61 | 62 | ret_0x4005ac: 63 | 0x4005ac: eax = 0 64 | 0x4005b1: leave 65 | 0x4005b2: ret 66 | } 67 | -------------------------------------------------------------------------------- /tests/gotoinloop6.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/plasma-disassembler/plasma/ec7df9b2b9b356dd5d8caf01b7e68c0ab5a1ef42/tests/gotoinloop6.bin -------------------------------------------------------------------------------- /tests/gotoinloop6.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() { 5 | int i, j, k; 6 | 7 | if (i == 1) { 8 | printf("1\n"); 9 | goto next; 10 | } else { 11 | printf("2\n"); 12 | } 13 | 14 | 15 | while (i < 123) { 16 | while (j < 456) { 17 | while (k < 789) { 18 | if (i == j) { 19 | next: 20 | printf("3\n"); 21 | } else { 22 | if (j == k) { 23 | printf("4\n"); 24 | } else if (i == k) { 25 | printf("5\n"); 26 | } 27 | } 28 | printf("6\n"); 29 | } 30 | } 31 | } 32 | 33 | return 0; 34 | } 35 | 36 | 37 | -------------------------------------------------------------------------------- /tests/gotoinloop7.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/plasma-disassembler/plasma/ec7df9b2b9b356dd5d8caf01b7e68c0ab5a1ef42/tests/gotoinloop7.bin -------------------------------------------------------------------------------- /tests/gotoinloop7.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() { 5 | int i, j, k; 6 | 7 | while (i < 1) { 8 | printf("loop\n"); 9 | 10 | if (i == 1) { 11 | printf("1\n"); 12 | goto next; 13 | } else { 14 | printf("2\n"); 15 | } 16 | 17 | while (k < 25) { 18 | for (j = 0 ; j < 123 ; j++) { 19 | printf("for\n"); 20 | next: 21 | printf("3\n"); 22 | } 23 | } 24 | i++; 25 | } 26 | 27 | return 0; 28 | } 29 | 30 | -------------------------------------------------------------------------------- /tests/gotoinloop7.rev: -------------------------------------------------------------------------------- 1 | function main (.text) { 2 | 0x400506: push rbp 3 | 0x400507: rbp = rsp 4 | 0x40050a: rsp -= 16 5 | 0x40050e: jmp loop_0x400569 6 | loop { 7 | loop_0x400569: 8 | # 0x400569: cmp dword ptr [rbp - 4], 0 9 | # 0x40056d: jle 0x400510 10 | if (*(rbp - 4) > 0) goto ret_0x40056f 11 | 0x400510: edi = 0x400604 "loop" 12 | 0x400515: call puts 13 | # 0x40051a: cmp dword ptr [rbp - 4], 1 14 | # 0x40051e: jne 0x40052c 15 | if (*(rbp - 4) == 1) { 16 | 0x400520: edi = 0x400609 "1" 17 | 0x400525: call puts 18 | 0x40052a: jmp 0x40054b 19 | } 20 | 0x40052c: edi = 0x40060b "2" 21 | 0x400531: call puts 22 | 0x400536: jmp loop_0x40055f 23 | loop { 24 | loop_0x40055f: 25 | # 0x40055f: cmp dword ptr [rbp - 0xc], 0x18 26 | # 0x400563: jle 0x400538 27 | if (*(rbp - 12) > 24) goto break_0x400565 28 | 0x400538: *(rbp - 8) = 0 29 | 0x40053f: jmp loop_0x400559 30 | loop { 31 | loop_0x400559: 32 | # 0x400559: cmp dword ptr [rbp - 8], 0x7a 33 | # 0x40055d: jle 0x400541 34 | if (*(rbp - 8) > 122) goto loop_0x40055f 35 | 0x400541: edi = 0x40060d "for" 36 | 0x400546: call puts 37 | 0x40054b: edi = 0x400611 "3" 38 | 0x400550: call puts 39 | 0x400555: *(rbp - 8) += 1 40 | } ; loop_0x400559 41 | 42 | } ; loop_0x40055f 43 | 44 | break_0x400565: 45 | 0x400565: *(rbp - 4) += 1 46 | } ; loop_0x400569 47 | 48 | ret_0x40056f: 49 | 0x40056f: eax = 0 50 | 0x400574: leave 51 | 0x400575: ret 52 | } 53 | -------------------------------------------------------------------------------- /tests/gotoinloop8.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/plasma-disassembler/plasma/ec7df9b2b9b356dd5d8caf01b7e68c0ab5a1ef42/tests/gotoinloop8.bin -------------------------------------------------------------------------------- /tests/gotoinloop8.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() { 5 | int i, j, k; 6 | 7 | while (i < 1) { 8 | printf("1\n"); 9 | next: 10 | while (k < 25) { 11 | 12 | if (i == 1) { 13 | printf("2\n"); 14 | goto next; 15 | } else { 16 | printf("3\n"); 17 | } 18 | k++; 19 | } 20 | i++; 21 | } 22 | 23 | return 0; 24 | } 25 | 26 | -------------------------------------------------------------------------------- /tests/gotoinloop8.rev: -------------------------------------------------------------------------------- 1 | function main (.text) { 2 | 0x400506: push rbp 3 | 0x400507: rbp = rsp 4 | 0x40050a: rsp -= 16 5 | 0x40050e: jmp loop_0x400546 6 | loop { 7 | loop_0x400546: 8 | # 0x400546: cmp dword ptr [rbp - 4], 0 9 | # 0x40054a: jle 0x400510 10 | if (*(rbp - 4) > 0) goto ret_0x40054c 11 | 0x400510: edi = 0x4005e4 "1" 12 | 0x400515: call puts 13 | loop { 14 | loop_0x40051a: 15 | 0x40051a: jmp loop_0x40053c 16 | loop { 17 | loop_0x40053c: 18 | # 0x40053c: cmp dword ptr [rbp - 8], 0x18 19 | # 0x400540: jle 0x40051c 20 | if (*(rbp - 8) > 24) goto break_0x400542 21 | # 0x40051c: cmp dword ptr [rbp - 4], 1 22 | # 0x400520: jne 0x40052e 23 | if (*(rbp - 4) == 1) goto break_0x400522 24 | 0x40052e: edi = 0x4005e8 "3" 25 | 0x400533: call puts 26 | 0x400538: *(rbp - 8) += 1 27 | } ; loop_0x40053c 28 | 29 | break_0x400522: 30 | 0x400522: edi = 0x4005e6 "2" 31 | 0x400527: call puts 32 | 0x40052c: jmp loop_0x40051a 33 | } ; loop_0x40051a 34 | 35 | break_0x400542: 36 | 0x400542: *(rbp - 4) += 1 37 | } ; loop_0x400546 38 | 39 | ret_0x40054c: 40 | 0x40054c: eax = 0 41 | 0x400551: leave 42 | 0x400552: ret 43 | } 44 | -------------------------------------------------------------------------------- /tests/gotoinloop9.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/plasma-disassembler/plasma/ec7df9b2b9b356dd5d8caf01b7e68c0ab5a1ef42/tests/gotoinloop9.bin -------------------------------------------------------------------------------- /tests/gotoinloop9.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() { 5 | int i, j, k, l; 6 | 7 | while (l < 1337) { 8 | if (i == 1) { 9 | printf("1\n"); 10 | goto next; 11 | } else { 12 | printf("2\n"); 13 | } 14 | 15 | while (i < 123) { 16 | while (j < 456) { 17 | while (k < 789) { 18 | if (i == j) { 19 | next: 20 | printf("3\n"); 21 | } else { 22 | if (j == k) { 23 | printf("4\n"); 24 | } else if (i == k) { 25 | printf("5\n"); 26 | } 27 | } 28 | printf("6\n"); 29 | } 30 | } 31 | } 32 | } 33 | 34 | return 0; 35 | } 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /tests/if1.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/plasma-disassembler/plasma/ec7df9b2b9b356dd5d8caf01b7e68c0ab5a1ef42/tests/if1.bin -------------------------------------------------------------------------------- /tests/if1.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() { 5 | int i = 123; 6 | 7 | if (i > 0) 8 | printf("1\n"); 9 | else 10 | printf("2\n"); 11 | 12 | printf("3\n"); 13 | 14 | return 0; 15 | } 16 | 17 | 18 | -------------------------------------------------------------------------------- /tests/if1.rev: -------------------------------------------------------------------------------- 1 | function main (.text) { 2 | 0x400506: push rbp 3 | 0x400507: rbp = rsp 4 | 0x40050a: rsp -= 16 5 | 0x40050e: *(rbp - 4) = 123 6 | # 0x400515: cmp dword ptr [rbp - 4], 0 7 | # 0x400519: jle 0x400527 8 | if (*(rbp - 4) > 0) { 9 | 0x40051b: edi = 0x4005d4 "1" 10 | 0x400520: call puts 11 | 0x400525: jmp ret_0x400531 12 | } else { 13 | 0x400527: edi = 0x4005d6 "2" 14 | 0x40052c: call puts 15 | } 16 | ret_0x400531: 17 | 0x400531: edi = 0x4005d8 "3" 18 | 0x400536: call puts 19 | 0x40053b: eax = 0 20 | 0x400540: leave 21 | 0x400541: ret 22 | } 23 | -------------------------------------------------------------------------------- /tests/if2.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/plasma-disassembler/plasma/ec7df9b2b9b356dd5d8caf01b7e68c0ab5a1ef42/tests/if2.bin -------------------------------------------------------------------------------- /tests/if2.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() { 5 | int i = 123; 6 | 7 | if (i > 0) { 8 | if (i == 5) { 9 | printf("1\n"); 10 | } else if (i == 6) { 11 | printf("2\n"); 12 | } else { 13 | if (i == 7) 14 | printf("3\n"); 15 | else 16 | printf("4\n"); 17 | } 18 | } 19 | 20 | printf("5\n"); 21 | 22 | return 0; 23 | } 24 | 25 | -------------------------------------------------------------------------------- /tests/if2.rev: -------------------------------------------------------------------------------- 1 | function main (.text) { 2 | 0x400506: push rbp 3 | 0x400507: rbp = rsp 4 | 0x40050a: rsp -= 16 5 | 0x40050e: *(rbp - 4) = 123 6 | # 0x400515: cmp dword ptr [rbp - 4], 0 7 | # 0x400519: jle 0x40055b 8 | if (*(rbp - 4) > 0) { 9 | # 0x40051b: cmp dword ptr [rbp - 4], 5 10 | # 0x40051f: jne 0x40052d 11 | if (*(rbp - 4) == 5) { 12 | 0x400521: edi = 0x4005f4 "1" 13 | 0x400526: call puts 14 | 0x40052b: jmp ret_0x40055b 15 | } 16 | # 0x40052d: cmp dword ptr [rbp - 4], 6 17 | # 0x400531: jne 0x40053f 18 | else if (*(rbp - 4) == 6) { 19 | 0x400533: edi = 0x4005f6 "2" 20 | 0x400538: call puts 21 | 0x40053d: jmp ret_0x40055b 22 | } 23 | # 0x40053f: cmp dword ptr [rbp - 4], 7 24 | # 0x400543: jne 0x400551 25 | else if (*(rbp - 4) == 7) { 26 | 0x400545: edi = 0x4005f8 "3" 27 | 0x40054a: call puts 28 | 0x40054f: jmp ret_0x40055b 29 | } else { 30 | 0x400551: edi = 0x4005fa "4" 31 | 0x400556: call puts 32 | } 33 | } 34 | ret_0x40055b: 35 | 0x40055b: edi = 0x4005fc "5" 36 | 0x400560: call puts 37 | 0x400565: eax = 0 38 | 0x40056a: leave 39 | 0x40056b: ret 40 | } 41 | -------------------------------------------------------------------------------- /tests/if3.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/plasma-disassembler/plasma/ec7df9b2b9b356dd5d8caf01b7e68c0ab5a1ef42/tests/if3.bin -------------------------------------------------------------------------------- /tests/if3.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() { 5 | int i = 0, j = 0, k = 0; 6 | 7 | while (i < 8) { 8 | printf("1\n"); 9 | 10 | if (j > 10) { 11 | k = 0; 12 | } else { 13 | k++; 14 | } 15 | 16 | i++; 17 | printf("2\n"); 18 | } 19 | 20 | return 0; 21 | } 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /tests/if3.rev: -------------------------------------------------------------------------------- 1 | function main (.text) { 2 | 0x400506: push rbp 3 | 0x400507: rbp = rsp 4 | 0x40050a: rsp -= 16 5 | 0x40050e: *(rbp - 4) = 0 6 | 0x400515: *(rbp - 12) = 0 7 | 0x40051c: *(rbp - 8) = 0 8 | 0x400523: jmp loop_0x400550 9 | loop { 10 | loop_0x400550: 11 | # 0x400550: cmp dword ptr [rbp - 4], 7 12 | # 0x400554: jle 0x400525 13 | if (*(rbp - 4) > 7) goto ret_0x400556 14 | 0x400525: edi = 0x4005e4 "1" 15 | 0x40052a: call puts 16 | # 0x40052f: cmp dword ptr [rbp - 0xc], 0xa 17 | # 0x400533: jle 0x40053e 18 | if (*(rbp - 12) > 10) { 19 | 0x400535: *(rbp - 8) = 0 20 | 0x40053c: jmp 0x400542 21 | } else { 22 | 0x40053e: *(rbp - 8) += 1 23 | } 24 | 0x400542: *(rbp - 4) += 1 25 | 0x400546: edi = 0x4005e6 "2" 26 | 0x40054b: call puts 27 | } ; loop_0x400550 28 | 29 | ret_0x400556: 30 | 0x400556: eax = 0 31 | 0x40055b: leave 32 | 0x40055c: ret 33 | } 34 | -------------------------------------------------------------------------------- /tests/if4.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/plasma-disassembler/plasma/ec7df9b2b9b356dd5d8caf01b7e68c0ab5a1ef42/tests/if4.bin -------------------------------------------------------------------------------- /tests/if4.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | int main(int argc, char *argv[]) 6 | { 7 | int i, j, k; 8 | do { 9 | if (i == 1) 10 | for(j = 0 ; j < k ; k++) 11 | printf("1\n"); 12 | 13 | if (i == 2) 14 | printf("2\n"); 15 | } while (i != 3); 16 | 17 | return 0; 18 | } 19 | -------------------------------------------------------------------------------- /tests/if4.rev: -------------------------------------------------------------------------------- 1 | function main (.text) { 2 | 0x400506: push rbp 3 | 0x400507: rbp = rsp 4 | 0x40050a: rsp -= 32 5 | 0x40050e: *(rbp - 20) = edi 6 | 0x400511: *(rbp - 32) = rsi 7 | loop { 8 | loop_0x400515: 9 | # 0x400515: cmp dword ptr [rbp - 8], 1 10 | # 0x400519: jne 0x40053a 11 | if (*(rbp - 8) == 1) { 12 | 0x40051b: *(rbp - 12) = 0 13 | 0x400522: jmp loop_0x400532 14 | loop { 15 | loop_0x400532: 16 | 0x400532: eax = *(rbp - 12) 17 | # 0x400535: cmp eax, dword ptr [rbp - 4] 18 | # 0x400538: jl 0x400524 19 | if (eax >= *(rbp - 4)) goto break_0x40053a 20 | 0x400524: edi = 0x4005e4 "1" 21 | 0x400529: call puts 22 | 0x40052e: *(rbp - 4) += 1 23 | } ; loop_0x400532 24 | 25 | } 26 | break_0x40053a: 27 | # 0x40053a: cmp dword ptr [rbp - 8], 2 28 | # 0x40053e: jne 0x40054a 29 | if (*(rbp - 8) == 2) { 30 | 0x400540: edi = 0x4005e6 "2" 31 | 0x400545: call puts 32 | } 33 | # 0x40054a: cmp dword ptr [rbp - 8], 3 34 | # 0x40054e: jne 0x400515 35 | if (*(rbp - 8) == 3) goto ret_0x400550 36 | } ; loop_0x400515 37 | 38 | ret_0x400550: 39 | 0x400550: eax = 0 40 | 0x400555: leave 41 | 0x400556: ret 42 | } 43 | -------------------------------------------------------------------------------- /tests/if5.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/plasma-disassembler/plasma/ec7df9b2b9b356dd5d8caf01b7e68c0ab5a1ef42/tests/if5.bin -------------------------------------------------------------------------------- /tests/if5.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() { 5 | int i, j, k; 6 | 7 | if (k == 42) { 8 | if (i == 10) 9 | { 10 | printf("1\n"); 11 | } 12 | if (j == 12 && i != j) 13 | { 14 | printf("2\n"); 15 | } 16 | } 17 | 18 | return 0; 19 | } 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /tests/if5.rev: -------------------------------------------------------------------------------- 1 | function main (.text) { 2 | 0x400506: push rbp 3 | 0x400507: rbp = rsp 4 | 0x40050a: rsp -= 16 5 | # 0x40050e: cmp dword ptr [rbp - 4], 0x2a 6 | # 0x400512: jne 0x40053c 7 | if (*(rbp - 4) == 42) { 8 | # 0x400514: cmp dword ptr [rbp - 8], 0xa 9 | # 0x400518: jne 0x400524 10 | if (*(rbp - 8) == 10) { 11 | 0x40051a: edi = 0x4005d4 "1" 12 | 0x40051f: call puts 13 | } 14 | # 0x400524: cmp dword ptr [rbp - 0xc], 0xc 15 | # 0x400528: jne 0x40053c 16 | if (*(rbp - 12) == 12) { 17 | 0x40052a: eax = *(rbp - 8) 18 | # 0x40052d: cmp eax, dword ptr [rbp - 0xc] 19 | # 0x400530: je 0x40053c 20 | and if (eax != *(rbp - 12)) 21 | 0x400532: edi = 0x4005d6 "2" 22 | 0x400537: call puts 23 | } 24 | } 25 | ret_0x40053c: 26 | 0x40053c: eax = 0 27 | 0x400541: leave 28 | 0x400542: ret 29 | } 30 | -------------------------------------------------------------------------------- /tests/if6.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/plasma-disassembler/plasma/ec7df9b2b9b356dd5d8caf01b7e68c0ab5a1ef42/tests/if6.bin -------------------------------------------------------------------------------- /tests/if6.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | 6 | int main(int argc, char *argv[]) 7 | { 8 | int i, j, k; 9 | 10 | if (k == 1) 11 | { 12 | while (i < 10) 13 | { 14 | printf("1\n"); 15 | } 16 | 17 | printf("2\n"); 18 | } 19 | 20 | if (k == 2) 21 | { 22 | do 23 | { 24 | printf("3\n"); 25 | } while (j < 15); 26 | } 27 | 28 | return 0; 29 | } 30 | 31 | -------------------------------------------------------------------------------- /tests/if6.rev: -------------------------------------------------------------------------------- 1 | function main (.text) { 2 | 0x400506: push rbp 3 | 0x400507: rbp = rsp 4 | 0x40050a: rsp -= 32 5 | 0x40050e: *(rbp - 20) = edi 6 | 0x400511: *(rbp - 32) = rsi 7 | # 0x400515: cmp dword ptr [rbp - 4], 1 8 | # 0x400519: jne 0x400537 9 | if (*(rbp - 4) == 1) { 10 | 0x40051b: jmp loop_0x400527 11 | loop { 12 | loop_0x400527: 13 | # 0x400527: cmp dword ptr [rbp - 8], 9 14 | # 0x40052b: jle 0x40051d 15 | if (*(rbp - 8) > 9) goto break_0x40052d 16 | 0x40051d: edi = 0x4005e4 "1" 17 | 0x400522: call puts 18 | } ; loop_0x400527 19 | 20 | break_0x40052d: 21 | 0x40052d: edi = 0x4005e6 "2" 22 | 0x400532: call puts 23 | } 24 | # 0x400537: cmp dword ptr [rbp - 4], 2 25 | # 0x40053b: jne 0x40054d 26 | if (*(rbp - 4) == 2) { 27 | loop { 28 | loop_0x40053d: 29 | 0x40053d: edi = 0x4005e8 "3" 30 | 0x400542: call puts 31 | # 0x400547: cmp dword ptr [rbp - 0xc], 0xe 32 | # 0x40054b: jle 0x40053d 33 | if (*(rbp - 12) > 14) goto ret_0x40054d 34 | } ; loop_0x40053d 35 | 36 | } 37 | ret_0x40054d: 38 | 0x40054d: eax = 0 39 | 0x400552: leave 40 | 0x400553: ret 41 | } 42 | -------------------------------------------------------------------------------- /tests/if7.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/plasma-disassembler/plasma/ec7df9b2b9b356dd5d8caf01b7e68c0ab5a1ef42/tests/if7.bin -------------------------------------------------------------------------------- /tests/if7.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | 6 | int main(int argc, char *argv[]) { 7 | 8 | int i, j; 9 | 10 | printf("0\n"); 11 | 12 | while(i < 20) { 13 | printf("1\n"); 14 | } 15 | 16 | if (j == 0) { 17 | printf("2\n"); 18 | } 19 | else if (j == -1) { 20 | printf("3\n"); 21 | } 22 | 23 | printf("4\n"); 24 | 25 | return 0; 26 | } 27 | -------------------------------------------------------------------------------- /tests/if7.rev: -------------------------------------------------------------------------------- 1 | function main (.text) { 2 | 0x400506: push rbp 3 | 0x400507: rbp = rsp 4 | 0x40050a: rsp -= 32 5 | 0x40050e: *(rbp - 20) = edi 6 | 0x400511: *(rbp - 32) = rsi 7 | 0x400515: edi = 0x4005f4 "0" 8 | 0x40051a: call puts 9 | 0x40051f: jmp loop_0x40052b 10 | loop { 11 | loop_0x40052b: 12 | # 0x40052b: cmp dword ptr [rbp - 4], 0x13 13 | # 0x40052f: jle 0x400521 14 | if (*(rbp - 4) > 19) goto break_0x400531 15 | 0x400521: edi = 0x4005f6 "1" 16 | 0x400526: call puts 17 | } ; loop_0x40052b 18 | 19 | break_0x400531: 20 | # 0x400531: cmp dword ptr [rbp - 8], 0 21 | # 0x400535: jne 0x400543 22 | if (*(rbp - 8) == 0) { 23 | 0x400537: edi = 0x4005f8 "2" 24 | 0x40053c: call puts 25 | 0x400541: jmp ret_0x400553 26 | } 27 | # 0x400543: cmp dword ptr [rbp - 8], -1 28 | # 0x400547: jne 0x400553 29 | else if (*(rbp - 8) == -1) { 30 | 0x400549: edi = 0x4005fa "3" 31 | 0x40054e: call puts 32 | } 33 | ret_0x400553: 34 | 0x400553: edi = 0x4005fc "4" 35 | 0x400558: call puts 36 | 0x40055d: eax = 0 37 | 0x400562: leave 38 | 0x400563: ret 39 | } 40 | -------------------------------------------------------------------------------- /tests/if8.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/plasma-disassembler/plasma/ec7df9b2b9b356dd5d8caf01b7e68c0ab5a1ef42/tests/if8.bin -------------------------------------------------------------------------------- /tests/if9.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/plasma-disassembler/plasma/ec7df9b2b9b356dd5d8caf01b7e68c0ab5a1ef42/tests/if9.bin -------------------------------------------------------------------------------- /tests/if9.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() { 5 | int i, j, k; 6 | 7 | while (i < 30) { 8 | if (i == j) { 9 | printf("3\n"); 10 | } else { 11 | if (j == k) { 12 | printf("4\n"); 13 | } else if (i == k) { 14 | printf("5\n"); 15 | } 16 | } 17 | printf("6\n"); 18 | } 19 | 20 | return 0; 21 | } 22 | -------------------------------------------------------------------------------- /tests/if9.rev: -------------------------------------------------------------------------------- 1 | function main (.text) { 2 | 0x4004e6: push rbp 3 | 0x4004e7: rbp = rsp 4 | 0x4004ea: rsp -= 16 5 | 0x4004ee: jmp loop_0x400534 6 | loop { 7 | loop_0x400534: 8 | # 0x400534: cmp dword ptr [rbp - 4], 0x1d 9 | # 0x400538: jle 0x4004f0 10 | if (*(rbp - 4) > 29) goto ret_0x40053a 11 | 0x4004f0: eax = *(rbp - 4) 12 | # 0x4004f3: cmp eax, dword ptr [rbp - 8] 13 | # 0x4004f6: jne 0x400504 14 | if (eax == *(rbp - 8)) { 15 | 0x4004f8: edi = 0x4005d4 "3" 16 | 0x4004fd: call puts 17 | 0x400502: jmp 0x40052a 18 | } else { 19 | 0x400504: eax = *(rbp - 8) 20 | # 0x400507: cmp eax, dword ptr [rbp - 0xc] 21 | # 0x40050a: jne 0x400518 22 | if (eax == *(rbp - 12)) { 23 | 0x40050c: edi = 0x4005d6 "4" 24 | 0x400511: call puts 25 | 0x400516: jmp 0x40052a 26 | } else { 27 | 0x400518: eax = *(rbp - 4) 28 | # 0x40051b: cmp eax, dword ptr [rbp - 0xc] 29 | # 0x40051e: jne 0x40052a 30 | if (eax == *(rbp - 12)) { 31 | 0x400520: edi = 0x4005d8 "5" 32 | 0x400525: call puts 33 | } 34 | } 35 | } 36 | 0x40052a: edi = 0x4005da "6" 37 | 0x40052f: call puts 38 | } ; loop_0x400534 39 | 40 | ret_0x40053a: 41 | 0x40053a: eax = 0 42 | 0x40053f: leave 43 | 0x400540: ret 44 | } 45 | -------------------------------------------------------------------------------- /tests/jump_is_loop.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/plasma-disassembler/plasma/ec7df9b2b9b356dd5d8caf01b7e68c0ab5a1ef42/tests/jump_is_loop.bin -------------------------------------------------------------------------------- /tests/jump_is_loop.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() { 4 | __asm__("jmp cond"); 5 | __asm__("myloop:"); 6 | __asm__("inc %rax"); 7 | __asm__("cond:"); 8 | __asm__("jle myloop"); 9 | __asm__("ret"); 10 | } 11 | -------------------------------------------------------------------------------- /tests/jump_is_loop.rev: -------------------------------------------------------------------------------- 1 | function main (.text) { 2 | 0x4004b6: push rbp 3 | 0x4004b7: rbp = rsp 4 | 0x4004ba: jmp cond 5 | loop { 6 | cond: 7 | # 0x4004bf: jle 0x4004bc 8 | if > goto ret_0x4004c1 9 | myloop: 10 | 0x4004bc: rax++ 11 | } ; cond 12 | 13 | ret_0x4004c1: 14 | 0x4004c1: ret 15 | } 16 | -------------------------------------------------------------------------------- /tests/loopends1.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/plasma-disassembler/plasma/ec7df9b2b9b356dd5d8caf01b7e68c0ab5a1ef42/tests/loopends1.bin -------------------------------------------------------------------------------- /tests/loopends1.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() { 5 | int i, j; 6 | 7 | while (i < 10) { 8 | printf("1\n"); 9 | if (i == 1) 10 | break; 11 | } 12 | 13 | while (i < 20) { 14 | printf("2\n"); 15 | } 16 | 17 | 18 | return 0; 19 | } 20 | -------------------------------------------------------------------------------- /tests/loopends1.rev: -------------------------------------------------------------------------------- 1 | function main (.text) { 2 | 0x400506: push rbp 3 | 0x400507: rbp = rsp 4 | 0x40050a: rsp -= 16 5 | 0x40050e: jmp loop_0x400522 6 | loop { 7 | loop_0x400522: 8 | # 0x400522: cmp dword ptr [rbp - 4], 9 9 | # 0x400526: jle 0x400510 10 | if (*(rbp - 4) > 9) goto break_0x400528 11 | 0x400510: edi = 0x4005d4 "1" 12 | 0x400515: call puts 13 | # 0x40051a: cmp dword ptr [rbp - 4], 1 14 | # 0x40051e: jne 0x400522 15 | if (*(rbp - 4) == 1) goto break_0x400520 16 | } ; loop_0x400522 17 | 18 | break_0x400520: 19 | 0x400520: jmp break_0x400528 20 | break_0x400528: 21 | 0x400528: jmp loop_0x400534 22 | loop { 23 | loop_0x400534: 24 | # 0x400534: cmp dword ptr [rbp - 4], 0x13 25 | # 0x400538: jle 0x40052a 26 | if (*(rbp - 4) > 19) goto ret_0x40053a 27 | 0x40052a: edi = 0x4005d6 "2" 28 | 0x40052f: call puts 29 | } ; loop_0x400534 30 | 31 | ret_0x40053a: 32 | 0x40053a: eax = 0 33 | 0x40053f: leave 34 | 0x400540: ret 35 | } 36 | -------------------------------------------------------------------------------- /tests/loopends2.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/plasma-disassembler/plasma/ec7df9b2b9b356dd5d8caf01b7e68c0ab5a1ef42/tests/loopends2.bin -------------------------------------------------------------------------------- /tests/loopends2.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() { 5 | int i, j, k; 6 | 7 | while (i < 111) { 8 | if (i == 0) { 9 | if (j == 1) { 10 | printf("0 1\n"); 11 | } else { 12 | printf("0 2\n"); 13 | } 14 | goto label1; 15 | } 16 | 17 | if (i == 10) { 18 | if (j == 1) { 19 | printf("1 1\n"); 20 | } else { 21 | printf("1 2\n"); 22 | } 23 | break; 24 | } 25 | 26 | if (i == 15) { 27 | printf("goto exit\n"); 28 | goto exit; 29 | } 30 | 31 | if (i == 20) { 32 | if (j == 1) { 33 | printf("2 1\n"); 34 | } else { 35 | printf("2 2\n"); 36 | } 37 | exit: 38 | __asm__("leave"); 39 | __asm__("ret"); 40 | } 41 | 42 | if (i == 30) { 43 | if (j == 1) { 44 | printf("3 1\n"); 45 | } else { 46 | printf("3 2\n"); 47 | } 48 | goto label2; 49 | } 50 | 51 | if (i == 40) { 52 | while (1) { 53 | if (k == 1) { 54 | printf("loop1 1\n"); 55 | } else { 56 | printf("loop1 2\n"); 57 | } 58 | } 59 | } 60 | } 61 | 62 | printf("end\n"); 63 | 64 | if (i == 1337) { 65 | while (1) { 66 | printf("loop2\n"); 67 | } 68 | } 69 | 70 | label1: 71 | if (j == 1) { 72 | printf("label1 1\n"); 73 | } else { 74 | printf("label1 2\n"); 75 | } 76 | 77 | for (i = 0 ; i < 100 ; i++) { 78 | if (i == 50) { 79 | printf("for 1\n"); 80 | } else { 81 | printf("for 2\n"); 82 | } 83 | } 84 | 85 | label2: 86 | if (j == 1) { 87 | printf("label2 1\n"); 88 | } else { 89 | printf("label2 2\n"); 90 | } 91 | 92 | return 0; 93 | } 94 | 95 | 96 | 97 | -------------------------------------------------------------------------------- /tests/loopinf1.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/plasma-disassembler/plasma/ec7df9b2b9b356dd5d8caf01b7e68c0ab5a1ef42/tests/loopinf1.bin -------------------------------------------------------------------------------- /tests/loopinf1.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() { 5 | int i = 123; 6 | 7 | if (i > 0) { 8 | while (1) { 9 | if (i == 456) 10 | printf("1\n"); 11 | i++; 12 | } 13 | } 14 | 15 | printf("2\n"); 16 | 17 | return 0; 18 | } 19 | 20 | 21 | -------------------------------------------------------------------------------- /tests/loopinf1.rev: -------------------------------------------------------------------------------- 1 | function main (.text) { 2 | 0x400506: push rbp 3 | 0x400507: rbp = rsp 4 | 0x40050a: rsp -= 16 5 | 0x40050e: *(rbp - 4) = 123 6 | # 0x400515: cmp dword ptr [rbp - 4], 0 7 | # 0x400519: jle 0x400534 8 | if (*(rbp - 4) > 0) { 9 | for (;;) { 10 | loop_0x40051b: 11 | # 0x40051b: cmp dword ptr [rbp - 4], 0x1c8 12 | # 0x400522: jne 0x40052e 13 | if (*(rbp - 4) == 456) { 14 | 0x400524: edi = 0x4005d4 "1" 15 | 0x400529: call puts 16 | } 17 | 0x40052e: *(rbp - 4) += 1 18 | 0x400532: jmp loop_0x40051b 19 | } ; loop_0x40051b 20 | 21 | } 22 | ret_0x400534: 23 | 0x400534: edi = 0x4005d6 "2" 24 | 0x400539: call puts 25 | 0x40053e: eax = 0 26 | 0x400543: leave 27 | 0x400544: ret 28 | } 29 | -------------------------------------------------------------------------------- /tests/loopinf2.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/plasma-disassembler/plasma/ec7df9b2b9b356dd5d8caf01b7e68c0ab5a1ef42/tests/loopinf2.bin -------------------------------------------------------------------------------- /tests/loopinf2.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() { 5 | int i = 123; 6 | 7 | if (i > 0) { 8 | while (1) { 9 | if (i == 456) 10 | printf("1\n"); 11 | i++; 12 | } 13 | } else { 14 | while (1) { 15 | if (i == 123) 16 | printf("2\n"); 17 | i++; 18 | } 19 | } 20 | 21 | return 0; 22 | } 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /tests/loopinf2.rev: -------------------------------------------------------------------------------- 1 | function main (.text) { 2 | 0x400506: push rbp 3 | 0x400507: rbp = rsp 4 | 0x40050a: rsp -= 16 5 | 0x40050e: *(rbp - 4) = 123 6 | # 0x400515: cmp dword ptr [rbp - 4], 0 7 | # 0x400519: jle 0x400534 8 | if (*(rbp - 4) > 0) { 9 | for (;;) { 10 | loop_0x40051b: 11 | # 0x40051b: cmp dword ptr [rbp - 4], 0x1c8 12 | # 0x400522: jne 0x40052e 13 | if (*(rbp - 4) == 456) { 14 | 0x400524: edi = 0x4005d4 "1" 15 | 0x400529: call puts 16 | } 17 | 0x40052e: *(rbp - 4) += 1 18 | 0x400532: jmp loop_0x40051b 19 | } ; loop_0x40051b 20 | 21 | } 22 | for (;;) { 23 | loop_0x400534: 24 | # 0x400534: cmp dword ptr [rbp - 4], 0x7b 25 | # 0x400538: jne 0x400544 26 | if (*(rbp - 4) == 123) { 27 | 0x40053a: edi = 0x4005d6 "2" 28 | 0x40053f: call puts 29 | } 30 | 0x400544: *(rbp - 4) += 1 31 | 0x400548: jmp loop_0x400534 32 | } ; loop_0x400534 33 | 34 | } 35 | -------------------------------------------------------------------------------- /tests/loopinf3.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/plasma-disassembler/plasma/ec7df9b2b9b356dd5d8caf01b7e68c0ab5a1ef42/tests/loopinf3.bin -------------------------------------------------------------------------------- /tests/loopinf3.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() { 5 | int i = 123; 6 | 7 | if (i > 0) 8 | printf("1\n"); 9 | else { 10 | while (1) { 11 | if (i == 456) 12 | printf("2\n"); 13 | i++; 14 | } 15 | } 16 | 17 | printf("3\n"); 18 | 19 | return 0; 20 | } 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /tests/loopinf3.rev: -------------------------------------------------------------------------------- 1 | function main (.text) { 2 | 0x400506: push rbp 3 | 0x400507: rbp = rsp 4 | 0x40050a: rsp -= 16 5 | 0x40050e: *(rbp - 4) = 123 6 | # 0x400515: cmp dword ptr [rbp - 4], 0 7 | # 0x400519: jle 0x400527 8 | if (*(rbp - 4) > 0) { 9 | 0x40051b: edi = 0x4005e4 "1" 10 | 0x400520: call puts 11 | 0x400525: jmp ret_0x400540 12 | ret_0x400540: 13 | 0x400540: edi = 0x4005e8 "3" 14 | 0x400545: call puts 15 | 0x40054a: eax = 0 16 | 0x40054f: leave 17 | 0x400550: ret 18 | } 19 | for (;;) { 20 | loop_0x400527: 21 | # 0x400527: cmp dword ptr [rbp - 4], 0x1c8 22 | # 0x40052e: jne 0x40053a 23 | if (*(rbp - 4) == 456) { 24 | 0x400530: edi = 0x4005e6 "2" 25 | 0x400535: call puts 26 | } 27 | 0x40053a: *(rbp - 4) += 1 28 | 0x40053e: jmp loop_0x400527 29 | } ; loop_0x400527 30 | 31 | } 32 | -------------------------------------------------------------------------------- /tests/loopinf4.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/plasma-disassembler/plasma/ec7df9b2b9b356dd5d8caf01b7e68c0ab5a1ef42/tests/loopinf4.bin -------------------------------------------------------------------------------- /tests/loopinf4.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() { 5 | __asm__("next: jmp next"); 6 | return 0; 7 | } 8 | -------------------------------------------------------------------------------- /tests/loopinf4.rev: -------------------------------------------------------------------------------- 1 | function main (.text) { 2 | 0x4004b6: push rbp 3 | 0x4004b7: rbp = rsp 4 | for (;;) { 5 | next: 6 | 0x4004ba: jmp next 7 | } ; next 8 | 9 | } 10 | -------------------------------------------------------------------------------- /tests/nestedloop1.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/plasma-disassembler/plasma/ec7df9b2b9b356dd5d8caf01b7e68c0ab5a1ef42/tests/nestedloop1.bin -------------------------------------------------------------------------------- /tests/nestedloop1.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() { 5 | int i = 123, j; 6 | 7 | if (i > 0) { 8 | for (i = 0 ; i < 10 ; i++) { 9 | for (j = 0 ; j < 5 ; j++) { 10 | if (i == j) 11 | printf("1\n"); 12 | } 13 | } 14 | printf("2\n"); 15 | } 16 | 17 | printf("3\n"); 18 | 19 | return 0; 20 | } 21 | 22 | 23 | -------------------------------------------------------------------------------- /tests/nestedloop1.rev: -------------------------------------------------------------------------------- 1 | function main (.text) { 2 | 0x400506: push rbp 3 | 0x400507: rbp = rsp 4 | 0x40050a: rsp -= 16 5 | 0x40050e: *(rbp - 4) = 123 6 | # 0x400515: cmp dword ptr [rbp - 4], 0 7 | # 0x400519: jle 0x40055d 8 | if (*(rbp - 4) > 0) { 9 | 0x40051b: *(rbp - 4) = 0 10 | 0x400522: jmp loop_0x40054d 11 | loop { 12 | loop_0x40054d: 13 | # 0x40054d: cmp dword ptr [rbp - 4], 9 14 | # 0x400551: jle 0x400524 15 | if (*(rbp - 4) > 9) goto break_0x400553 16 | 0x400524: *(rbp - 8) = 0 17 | 0x40052b: jmp loop_0x400543 18 | loop { 19 | loop_0x400543: 20 | # 0x400543: cmp dword ptr [rbp - 8], 4 21 | # 0x400547: jle 0x40052d 22 | if (*(rbp - 8) > 4) goto break_0x400549 23 | 0x40052d: eax = *(rbp - 4) 24 | # 0x400530: cmp eax, dword ptr [rbp - 8] 25 | # 0x400533: jne 0x40053f 26 | if (eax == *(rbp - 8)) { 27 | 0x400535: edi = 0x4005f4 "1" 28 | 0x40053a: call puts 29 | } 30 | 0x40053f: *(rbp - 8) += 1 31 | } ; loop_0x400543 32 | 33 | break_0x400549: 34 | 0x400549: *(rbp - 4) += 1 35 | } ; loop_0x40054d 36 | 37 | break_0x400553: 38 | 0x400553: edi = 0x4005f6 "2" 39 | 0x400558: call puts 40 | } 41 | ret_0x40055d: 42 | 0x40055d: edi = 0x4005f8 "3" 43 | 0x400562: call puts 44 | 0x400567: eax = 0 45 | 0x40056c: leave 46 | 0x40056d: ret 47 | } 48 | -------------------------------------------------------------------------------- /tests/nestedloop2.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/plasma-disassembler/plasma/ec7df9b2b9b356dd5d8caf01b7e68c0ab5a1ef42/tests/nestedloop2.bin -------------------------------------------------------------------------------- /tests/nestedloop2.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() { 5 | int i = 123, j = 5; 6 | 7 | while (i < 10) { 8 | while (j < 5) { 9 | j++; 10 | } 11 | } 12 | 13 | return 0; 14 | } 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /tests/nestedloop2.rev: -------------------------------------------------------------------------------- 1 | function main (.text) { 2 | 0x4004b6: push rbp 3 | 0x4004b7: rbp = rsp 4 | 0x4004ba: *(rbp - 8) = 123 5 | 0x4004c1: *(rbp - 4) = 5 6 | 0x4004c8: jmp loop_0x4004d6 7 | loop { 8 | loop_0x4004d6: 9 | # 0x4004d6: cmp dword ptr [rbp - 8], 9 10 | # 0x4004da: jle 0x4004ca 11 | if (*(rbp - 8) > 9) goto ret_0x4004dc 12 | 0x4004ca: jmp loop_0x4004d0 13 | loop { 14 | loop_0x4004d0: 15 | # 0x4004d0: cmp dword ptr [rbp - 4], 4 16 | # 0x4004d4: jle 0x4004cc 17 | if (*(rbp - 4) > 4) goto loop_0x4004d6 18 | 0x4004cc: *(rbp - 4) += 1 19 | } ; loop_0x4004d0 20 | 21 | } ; loop_0x4004d6 22 | 23 | ret_0x4004dc: 24 | 0x4004dc: eax = 0 25 | 0x4004e1: pop rbp 26 | 0x4004e2: ret 27 | } 28 | -------------------------------------------------------------------------------- /tests/nestedloop3.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/plasma-disassembler/plasma/ec7df9b2b9b356dd5d8caf01b7e68c0ab5a1ef42/tests/nestedloop3.bin -------------------------------------------------------------------------------- /tests/nestedloop3.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() { 5 | int i = 123, j = 5, k = 1; 6 | 7 | while (i < 5) { 8 | while (j < 2) { 9 | while (k < 4) { 10 | } 11 | } 12 | } 13 | 14 | return 0; 15 | } 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /tests/nestedloop3.rev: -------------------------------------------------------------------------------- 1 | function main (.text) { 2 | 0x4004b6: push rbp 3 | 0x4004b7: rbp = rsp 4 | 0x4004ba: *(rbp - 4) = 123 5 | 0x4004c1: *(rbp - 8) = 5 6 | 0x4004c8: *(rbp - 12) = 1 7 | 0x4004cf: jmp loop_0x4004df 8 | loop { 9 | loop_0x4004df: 10 | # 0x4004df: cmp dword ptr [rbp - 4], 4 11 | # 0x4004e3: jle 0x4004d1 12 | if (*(rbp - 4) > 4) goto ret_0x4004e5 13 | 0x4004d1: jmp loop_0x4004d9 14 | loop { 15 | loop_0x4004d9: 16 | # 0x4004d9: cmp dword ptr [rbp - 8], 1 17 | # 0x4004dd: jle 0x4004d3 18 | if (*(rbp - 8) > 1) goto loop_0x4004df 19 | loop { 20 | loop_0x4004d3: 21 | # 0x4004d3: cmp dword ptr [rbp - 0xc], 3 22 | # 0x4004d7: jle 0x4004d3 23 | if (*(rbp - 12) > 3) goto loop_0x4004d9 24 | } ; loop_0x4004d3 25 | 26 | } ; loop_0x4004d9 27 | 28 | } ; loop_0x4004df 29 | 30 | ret_0x4004e5: 31 | 0x4004e5: eax = 0 32 | 0x4004ea: pop rbp 33 | 0x4004eb: ret 34 | } 35 | -------------------------------------------------------------------------------- /tests/nestedloop4.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/plasma-disassembler/plasma/ec7df9b2b9b356dd5d8caf01b7e68c0ab5a1ef42/tests/nestedloop4.bin -------------------------------------------------------------------------------- /tests/nestedloop4.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() { 5 | int i = 123; 6 | 7 | for (i = 0 ; i < 10 ; i++) { 8 | int j = 0; 9 | while (j < 10) { 10 | printf("1\n"); 11 | j++; 12 | } 13 | while (j < 20) { 14 | printf("2\n"); 15 | j++; 16 | } 17 | } 18 | 19 | printf("3\n"); 20 | 21 | return 0; 22 | } 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /tests/nestedloop4.rev: -------------------------------------------------------------------------------- 1 | function main (.text) { 2 | 0x400506: push rbp 3 | 0x400507: rbp = rsp 4 | 0x40050a: rsp -= 16 5 | 0x40050e: *(rbp - 4) = 123 6 | 0x400515: *(rbp - 4) = 0 7 | 0x40051c: jmp loop_0x400555 8 | loop { 9 | loop_0x400555: 10 | # 0x400555: cmp dword ptr [rbp - 4], 9 11 | # 0x400559: jle 0x40051e 12 | if (*(rbp - 4) > 9) goto ret_0x40055b 13 | 0x40051e: *(rbp - 8) = 0 14 | 0x400525: jmp loop_0x400535 15 | loop { 16 | loop_0x400535: 17 | # 0x400535: cmp dword ptr [rbp - 8], 9 18 | # 0x400539: jle 0x400527 19 | if (*(rbp - 8) > 9) goto break_0x40053b 20 | 0x400527: edi = 0x4005f4 "1" 21 | 0x40052c: call puts 22 | 0x400531: *(rbp - 8) += 1 23 | } ; loop_0x400535 24 | 25 | break_0x40053b: 26 | 0x40053b: jmp loop_0x40054b 27 | loop { 28 | loop_0x40054b: 29 | # 0x40054b: cmp dword ptr [rbp - 8], 0x13 30 | # 0x40054f: jle 0x40053d 31 | if (*(rbp - 8) > 19) goto break_0x400551 32 | 0x40053d: edi = 0x4005f6 "2" 33 | 0x400542: call puts 34 | 0x400547: *(rbp - 8) += 1 35 | } ; loop_0x40054b 36 | 37 | break_0x400551: 38 | 0x400551: *(rbp - 4) += 1 39 | } ; loop_0x400555 40 | 41 | ret_0x40055b: 42 | 0x40055b: edi = 0x4005f8 "3" 43 | 0x400560: call puts 44 | 0x400565: eax = 0 45 | 0x40056a: leave 46 | 0x40056b: ret 47 | } 48 | -------------------------------------------------------------------------------- /tests/nestedloop5.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/plasma-disassembler/plasma/ec7df9b2b9b356dd5d8caf01b7e68c0ab5a1ef42/tests/nestedloop5.bin -------------------------------------------------------------------------------- /tests/nestedloop5.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | 6 | int main(int argc, char *argv[]) { 7 | int i, j, k; 8 | 9 | do 10 | { 11 | if (k == 1) 12 | { 13 | while (j > 0) 14 | { 15 | printf("1\n"); 16 | for (i = 0 ; i < 50 ; i++) { 17 | printf("2\n"); 18 | } 19 | } 20 | } 21 | } while (k < 50); 22 | 23 | return 0; 24 | } 25 | -------------------------------------------------------------------------------- /tests/nestedloop5.rev: -------------------------------------------------------------------------------- 1 | function main (.text) { 2 | 0x400506: push rbp 3 | 0x400507: rbp = rsp 4 | 0x40050a: rsp -= 32 5 | 0x40050e: *(rbp - 20) = edi 6 | 0x400511: *(rbp - 32) = rsi 7 | loop { 8 | loop_0x400515: 9 | # 0x400515: cmp dword ptr [rbp - 8], 1 10 | # 0x400519: jne 0x40054a 11 | if (*(rbp - 8) == 1) { 12 | 0x40051b: jmp loop_0x400544 13 | loop { 14 | loop_0x400544: 15 | # 0x400544: cmp dword ptr [rbp - 0xc], 0 16 | # 0x400548: jg 0x40051d 17 | if (*(rbp - 12) <= 0) goto break_0x40054a 18 | 0x40051d: edi = 0x4005e4 "1" 19 | 0x400522: call puts 20 | 0x400527: *(rbp - 4) = 0 21 | 0x40052e: jmp loop_0x40053e 22 | loop { 23 | loop_0x40053e: 24 | # 0x40053e: cmp dword ptr [rbp - 4], 0x31 25 | # 0x400542: jle 0x400530 26 | if (*(rbp - 4) > 49) goto loop_0x400544 27 | 0x400530: edi = 0x4005e6 "2" 28 | 0x400535: call puts 29 | 0x40053a: *(rbp - 4) += 1 30 | } ; loop_0x40053e 31 | 32 | } ; loop_0x400544 33 | 34 | } 35 | break_0x40054a: 36 | # 0x40054a: cmp dword ptr [rbp - 8], 0x31 37 | # 0x40054e: jle 0x400515 38 | if (*(rbp - 8) > 49) goto ret_0x400550 39 | } ; loop_0x400515 40 | 41 | ret_0x400550: 42 | 0x400550: eax = 0 43 | 0x400555: leave 44 | 0x400556: ret 45 | } 46 | -------------------------------------------------------------------------------- /tests/nestedloop6.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/plasma-disassembler/plasma/ec7df9b2b9b356dd5d8caf01b7e68c0ab5a1ef42/tests/nestedloop6.bin -------------------------------------------------------------------------------- /tests/nestedloop6.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() { 5 | int i = 123, j = 5, k; 6 | 7 | if (i == 1) { 8 | while (i <= 2) { 9 | while (j <= 3) { 10 | while (k <= 4) { 11 | if (i == 5) { 12 | while (i <= 6) { 13 | while (j <= 7) { 14 | while (k <= 8) { 15 | } 16 | } 17 | } 18 | } 19 | } 20 | } 21 | } 22 | } 23 | 24 | return 0; 25 | } 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /tests/nestedloop7.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/plasma-disassembler/plasma/ec7df9b2b9b356dd5d8caf01b7e68c0ab5a1ef42/tests/nestedloop7.bin -------------------------------------------------------------------------------- /tests/or1.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/plasma-disassembler/plasma/ec7df9b2b9b356dd5d8caf01b7e68c0ab5a1ef42/tests/or1.bin -------------------------------------------------------------------------------- /tests/or1.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() { 5 | int i = 123, j = 5; 6 | 7 | if (i != 0 || i > time(NULL) || i != j || i > 5 || j < 10) { 8 | printf("1\n"); 9 | } 10 | else { 11 | printf("2\n"); 12 | } 13 | 14 | printf("3\n"); 15 | 16 | return 0; 17 | } 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /tests/or1.rev: -------------------------------------------------------------------------------- 1 | function main (.text) { 2 | 0x400546: push rbp 3 | 0x400547: rbp = rsp 4 | 0x40054a: rsp -= 16 5 | 0x40054e: *(rbp - 4) = 123 6 | 0x400555: *(rbp - 8) = 5 7 | # 0x40055c: cmp dword ptr [rbp - 4], 0 8 | # 0x400560: jne 0x40058a 9 | if (*(rbp - 4) == 0) { 10 | 0x400562: edi = 0 11 | 0x400567: eax = 0 12 | 0x40056c: call time 13 | # 0x400571: cmp eax, dword ptr [rbp - 4] 14 | # 0x400574: jl 0x40058a 15 | and if (eax >= *(rbp - 4)) 16 | 0x400576: eax = *(rbp - 4) 17 | # 0x400579: cmp eax, dword ptr [rbp - 8] 18 | # 0x40057c: jne 0x40058a 19 | and if (eax == *(rbp - 8)) 20 | # 0x40057e: cmp dword ptr [rbp - 4], 5 21 | # 0x400582: jg 0x40058a 22 | and if (*(rbp - 4) <= 5) 23 | # 0x400584: cmp dword ptr [rbp - 8], 9 24 | # 0x400588: jg 0x400596 25 | and if (*(rbp - 8) > 9) 26 | 0x400596: edi = 0x400646 "2" 27 | 0x40059b: call puts 28 | } else { 29 | 0x40058a: edi = 0x400644 "1" 30 | 0x40058f: call puts 31 | 0x400594: jmp ret_0x4005a0 32 | } 33 | ret_0x4005a0: 34 | 0x4005a0: edi = 0x400648 "3" 35 | 0x4005a5: call puts 36 | 0x4005aa: eax = 0 37 | 0x4005af: leave 38 | 0x4005b0: ret 39 | } 40 | -------------------------------------------------------------------------------- /tests/or2.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/plasma-disassembler/plasma/ec7df9b2b9b356dd5d8caf01b7e68c0ab5a1ef42/tests/or2.bin -------------------------------------------------------------------------------- /tests/or2.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() { 5 | int i = time(NULL); 6 | 7 | while (i < 100 || i < 20 || i < 10 || i < 5) { 8 | printf("1\n"); 9 | i++; 10 | } 11 | 12 | printf("2\n"); 13 | 14 | return 0; 15 | } 16 | -------------------------------------------------------------------------------- /tests/or2.rev: -------------------------------------------------------------------------------- 1 | function main (.text) { 2 | 0x400546: push rbp 3 | 0x400547: rbp = rsp 4 | 0x40054a: rsp -= 16 5 | 0x40054e: edi = 0 6 | 0x400553: eax = 0 7 | 0x400558: call time 8 | 0x40055d: *(rbp - 4) = eax 9 | 0x400560: jmp loop_0x400570 10 | loop { 11 | loop_0x400570: 12 | # 0x400570: cmp dword ptr [rbp - 4], 0x63 13 | # 0x400574: jle 0x400562 14 | if (*(rbp - 4) > 99) { 15 | # 0x400576: cmp dword ptr [rbp - 4], 0x13 16 | # 0x40057a: jle 0x400562 17 | and if (*(rbp - 4) > 19) 18 | # 0x40057c: cmp dword ptr [rbp - 4], 9 19 | # 0x400580: jle 0x400562 20 | and if (*(rbp - 4) > 9) 21 | # 0x400582: cmp dword ptr [rbp - 4], 4 22 | # 0x400586: jle 0x400562 23 | if (*(rbp - 4) > 4) goto ret_0x400588 24 | } 25 | 0x400562: edi = 0x400624 "1" 26 | 0x400567: call puts 27 | 0x40056c: *(rbp - 4) += 1 28 | } ; loop_0x400570 29 | 30 | ret_0x400588: 31 | 0x400588: edi = 0x400626 "2" 32 | 0x40058d: call puts 33 | 0x400592: eax = 0 34 | 0x400597: leave 35 | 0x400598: ret 36 | } 37 | -------------------------------------------------------------------------------- /tests/or3.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/plasma-disassembler/plasma/ec7df9b2b9b356dd5d8caf01b7e68c0ab5a1ef42/tests/or3.bin -------------------------------------------------------------------------------- /tests/or3.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() { 5 | int i = time(NULL); 6 | 7 | while (i < 100 || i < 20 || i < 10 || i < 5) { 8 | if (i == 55) 9 | printf("1\n"); 10 | else { 11 | printf("2\n"); 12 | break; 13 | } 14 | i++; 15 | } 16 | 17 | printf("3\n"); 18 | 19 | return 0; 20 | } 21 | 22 | -------------------------------------------------------------------------------- /tests/or3.rev: -------------------------------------------------------------------------------- 1 | function main (.text) { 2 | 0x400546: push rbp 3 | 0x400547: rbp = rsp 4 | 0x40054a: rsp -= 16 5 | 0x40054e: edi = 0 6 | 0x400553: eax = 0 7 | 0x400558: call time 8 | 0x40055d: *(rbp - 4) = eax 9 | 0x400560: jmp loop_0x400584 10 | loop { 11 | loop_0x400584: 12 | # 0x400584: cmp dword ptr [rbp - 4], 0x63 13 | # 0x400588: jle 0x400562 14 | if (*(rbp - 4) > 99) { 15 | # 0x40058a: cmp dword ptr [rbp - 4], 0x13 16 | # 0x40058e: jle 0x400562 17 | and if (*(rbp - 4) > 19) 18 | # 0x400590: cmp dword ptr [rbp - 4], 9 19 | # 0x400594: jle 0x400562 20 | and if (*(rbp - 4) > 9) 21 | # 0x400596: cmp dword ptr [rbp - 4], 4 22 | # 0x40059a: jle 0x400562 23 | if (*(rbp - 4) > 4) goto ret_0x40059c 24 | } 25 | # 0x400562: cmp dword ptr [rbp - 4], 0x37 26 | # 0x400566: jne 0x400574 27 | if (*(rbp - 4) != 55) goto break_0x400574 28 | 0x400568: edi = 0x400634 "1" 29 | 0x40056d: call puts 30 | 0x400572: jmp 0x400580 31 | 0x400580: *(rbp - 4) += 1 32 | } ; loop_0x400584 33 | 34 | break_0x400574: 35 | 0x400574: edi = 0x400636 "2" 36 | 0x400579: call puts 37 | 0x40057e: jmp ret_0x40059c 38 | ret_0x40059c: 39 | 0x40059c: edi = 0x400638 "3" 40 | 0x4005a1: call puts 41 | 0x4005a6: eax = 0 42 | 0x4005ab: leave 43 | 0x4005ac: ret 44 | } 45 | -------------------------------------------------------------------------------- /tests/or4.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/plasma-disassembler/plasma/ec7df9b2b9b356dd5d8caf01b7e68c0ab5a1ef42/tests/or4.bin -------------------------------------------------------------------------------- /tests/or4.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() { 5 | int i = 0, j; 6 | 7 | if (i < 200) { 8 | printf("1\n"); 9 | if (i == 1 || i == 2 || i == 3) { 10 | printf("2\n"); 11 | } 12 | } 13 | printf("3\n"); 14 | 15 | return 0; 16 | } 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /tests/or4.rev: -------------------------------------------------------------------------------- 1 | function main (.text) { 2 | 0x400506: push rbp 3 | 0x400507: rbp = rsp 4 | 0x40050a: rsp -= 16 5 | 0x40050e: *(rbp - 4) = 0 6 | # 0x400515: cmp dword ptr [rbp - 4], 0xc7 7 | # 0x40051c: jg 0x400544 8 | if (*(rbp - 4) <= 199) { 9 | 0x40051e: edi = 0x4005e4 "1" 10 | 0x400523: call puts 11 | # 0x400528: cmp dword ptr [rbp - 4], 1 12 | # 0x40052c: je 0x40053a 13 | if (*(rbp - 4) != 1) { 14 | # 0x40052e: cmp dword ptr [rbp - 4], 2 15 | # 0x400532: je 0x40053a 16 | and if (*(rbp - 4) != 2) 17 | # 0x400534: cmp dword ptr [rbp - 4], 3 18 | # 0x400538: jne 0x400544 19 | and if (*(rbp - 4) != 3) 20 | goto ret_0x400544 21 | } else { 22 | 0x40053a: edi = 0x4005e6 "2" 23 | 0x40053f: call puts 24 | } 25 | } 26 | ret_0x400544: 27 | 0x400544: edi = 0x4005e8 "3" 28 | 0x400549: call puts 29 | 0x40054e: eax = 0 30 | 0x400553: leave 31 | 0x400554: ret 32 | } 33 | -------------------------------------------------------------------------------- /tests/pendu.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/plasma-disassembler/plasma/ec7df9b2b9b356dd5d8caf01b7e68c0ab5a1ef42/tests/pendu.bin -------------------------------------------------------------------------------- /tests/pendu____main.rev: -------------------------------------------------------------------------------- 1 | function ___main (.text) { 2 | 0x4018c0: push ebp 3 | 0x4018c1: ebp = esp 4 | 0x4018c3: push ebx 5 | 0x4018c4: esp -= 4 6 | 0x4018c7: eax = *(0x404020) 7 | # 0x4018cc: test eax, eax 8 | # 0x4018ce: jne 0x401906 9 | if (eax == 0) { 10 | 0x4018d0: eax = *(___CTOR_LIST__) 11 | 0x4018d5: ebx = 1 12 | 0x4018da: *(0x404020) = ebx 13 | # 0x4018e0: cmp eax, -1 14 | # 0x4018e3: je 0x40190a 15 | if (eax == -1) { 16 | 0x40190a: ecx = *(0x401e94) 17 | 0x401910: eax = 0 18 | 0x401912: test ecx, ecx 19 | 0x401914: jmp loop_0x401920 20 | loop { 21 | loop_0x401920: 22 | # 0x401920: jne 0x401916 23 | if == goto break_0x401922 24 | 0x401916: eax++ 25 | 0x401917: edx = *((eax*4) + 0x401e94) 26 | 0x40191e: test edx, edx 27 | } ; loop_0x401920 28 | 29 | break_0x401922: 30 | 0x401922: jmp 0x4018e5 31 | } 32 | 0x4018e5: test eax, eax 33 | 0x4018e7: ebx = eax 34 | # 0x4018e9: je 0x4018fa 35 | if != { 36 | 0x4018eb: nop 37 | 0x4018ec: esi = esi 38 | loop { 39 | loop_0x4018f0: 40 | 0x4018f0: call *((ebx*4) + ___CTOR_LIST__) 41 | 0x4018f7: ebx-- 42 | # 0x4018f8: jne 0x4018f0 43 | if == goto break_0x4018fa 44 | } ; loop_0x4018f0 45 | 46 | } 47 | break_0x4018fa: 48 | 0x4018fa: *(esp) = ___do_global_dtors 49 | 0x401901: call _atexit 50 | } 51 | ret_0x401906: 52 | 0x401906: pop ebx 53 | 0x401907: pop ebx 54 | 0x401908: pop ebp 55 | 0x401909: ret 56 | } 57 | -------------------------------------------------------------------------------- /tests/regen.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # Regen .rev files (only for the symbol main !) 4 | # otherwise specifial cases at the end 5 | 6 | cd .. 7 | 8 | if [ "$1" == "force" ]; then 9 | ls tests/*.bin | while read file; do 10 | echo "$file" 11 | name=`basename "$file" .bin` 12 | ./run_plasma.py --nocolor "tests/${name}.bin" >"tests/${name}.rev" 13 | done 14 | 15 | mv tests/server.rev tests/server_main.rev 16 | ./run_plasma.py tests/server.bin -x=connection_handler -nc >tests/server_connection_handler.rev 17 | 18 | mv tests/pendu.rev tests/pendu__main.rev 19 | ./run_plasma.py tests/pendu.bin -x=___main -nc >tests/pendu____main.rev 20 | ./run_plasma.py tests/pendu.bin -x=__imp___cexit -nc >tests/pendu___imp___cexit.rev 21 | 22 | else 23 | echo "Are you sure ?" 24 | echo "if yes add 'force' in argument" 25 | fi 26 | -------------------------------------------------------------------------------- /tests/return1.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/plasma-disassembler/plasma/ec7df9b2b9b356dd5d8caf01b7e68c0ab5a1ef42/tests/return1.bin -------------------------------------------------------------------------------- /tests/return1.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() { 5 | int i = 123, j = 5; 6 | 7 | while (i < 100) { 8 | if (i == 5) { 9 | printf("1\n"); 10 | return 1; 11 | } 12 | if (i == 6) { 13 | printf("2\n"); 14 | return 2; 15 | } 16 | i++; 17 | } 18 | printf("3\n"); 19 | 20 | return 0; 21 | } 22 | 23 | -------------------------------------------------------------------------------- /tests/return1.rev: -------------------------------------------------------------------------------- 1 | function main (.text) { 2 | 0x400506: push rbp 3 | 0x400507: rbp = rsp 4 | 0x40050a: rsp -= 16 5 | 0x40050e: *(rbp - 4) = 123 6 | 0x400515: *(rbp - 8) = 5 7 | 0x40051c: jmp loop_0x400550 8 | loop { 9 | loop_0x400550: 10 | # 0x400550: cmp dword ptr [rbp - 4], 0x63 11 | # 0x400554: jle 0x40051e 12 | if (*(rbp - 4) > 99) goto break_0x400556 13 | # 0x40051e: cmp dword ptr [rbp - 4], 5 14 | # 0x400522: jne 0x400535 15 | if (*(rbp - 4) == 5) goto break_0x400524 16 | # 0x400535: cmp dword ptr [rbp - 4], 6 17 | # 0x400539: jne 0x40054c 18 | if (*(rbp - 4) == 6) goto break_0x40053b 19 | 0x40054c: *(rbp - 4) += 1 20 | } ; loop_0x400550 21 | 22 | break_0x40053b: 23 | 0x40053b: edi = 0x4005f6 "2" 24 | 0x400540: call puts 25 | 0x400545: eax = 2 26 | 0x40054a: jmp ret_0x400565 27 | break_0x400524: 28 | 0x400524: edi = 0x4005f4 "1" 29 | 0x400529: call puts 30 | 0x40052e: eax = 1 31 | 0x400533: jmp ret_0x400565 32 | break_0x400556: 33 | 0x400556: edi = 0x4005f8 "3" 34 | 0x40055b: call puts 35 | 0x400560: eax = 0 36 | ret_0x400565: 37 | 0x400565: leave 38 | 0x400566: ret 39 | } 40 | -------------------------------------------------------------------------------- /tests/return2.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/plasma-disassembler/plasma/ec7df9b2b9b356dd5d8caf01b7e68c0ab5a1ef42/tests/return2.bin -------------------------------------------------------------------------------- /tests/return2.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() { 5 | int i = 123, j = 5; 6 | 7 | if (i == 5) { 8 | printf("1\n"); 9 | return 1; 10 | } 11 | if (i == 6) { 12 | printf("2\n"); 13 | return 2; 14 | } 15 | printf("3\n"); 16 | 17 | return 0; 18 | } 19 | 20 | 21 | -------------------------------------------------------------------------------- /tests/return2.rev: -------------------------------------------------------------------------------- 1 | function main (.text) { 2 | 0x400506: push rbp 3 | 0x400507: rbp = rsp 4 | 0x40050a: rsp -= 16 5 | 0x40050e: *(rbp - 4) = 123 6 | 0x400515: *(rbp - 8) = 5 7 | # 0x40051c: cmp dword ptr [rbp - 4], 5 8 | # 0x400520: jne 0x400533 9 | if (*(rbp - 4) == 5) { 10 | 0x400522: edi = 0x4005e4 "1" 11 | 0x400527: call puts 12 | 0x40052c: eax = 1 13 | 0x400531: jmp ret_0x400559 14 | } 15 | # 0x400533: cmp dword ptr [rbp - 4], 6 16 | # 0x400537: jne 0x40054a 17 | else if (*(rbp - 4) == 6) { 18 | 0x400539: edi = 0x4005e6 "2" 19 | 0x40053e: call puts 20 | 0x400543: eax = 2 21 | 0x400548: jmp ret_0x400559 22 | } else { 23 | 0x40054a: edi = 0x4005e8 "3" 24 | 0x40054f: call puts 25 | 0x400554: eax = 0 26 | } 27 | ret_0x400559: 28 | 0x400559: leave 29 | 0x40055a: ret 30 | } 31 | -------------------------------------------------------------------------------- /tests/server.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/plasma-disassembler/plasma/ec7df9b2b9b356dd5d8caf01b7e68c0ab5a1ef42/tests/server.bin -------------------------------------------------------------------------------- /tests/shellcode.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/plasma-disassembler/plasma/ec7df9b2b9b356dd5d8caf01b7e68c0ab5a1ef42/tests/shellcode.bin -------------------------------------------------------------------------------- /tests/shellcode.c: -------------------------------------------------------------------------------- 1 | #error "This file is just for the make check" 2 | -------------------------------------------------------------------------------- /tests/shellcode_0x0.rev: -------------------------------------------------------------------------------- 1 | function _start (raw) { 2 | 0x0: eax = 0 3 | 0x2: al = '\x0b' 4 | 0x4: cdq 5 | 0x5: push edx 6 | 0x6: push 1752379246 "n/sh" 7 | 0xb: push 1768042287 "//bi" 8 | 0x10: ebx = esp 9 | 0x12: push edx 10 | 0x13: push ebx 11 | 0x14: ecx = esp 12 | 0x16: int 128 ; execve(ebx, ecx, edx) 13 | } 14 | -------------------------------------------------------------------------------- /tests/strlen.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/plasma-disassembler/plasma/ec7df9b2b9b356dd5d8caf01b7e68c0ab5a1ef42/tests/strlen.bin -------------------------------------------------------------------------------- /tests/strlen.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(int argc, char **argv) { 4 | return strlen(argv[0]); 5 | } 6 | -------------------------------------------------------------------------------- /tests/strlen.rev: -------------------------------------------------------------------------------- 1 | function main (.text) { 2 | 0x4003c0: rdi = *(rsi) 3 | 0x4003c3: eax = 0 4 | 0x4003c5: rcx = -1 5 | 0x4003c9: 6 | while (!rcx) { 7 | 0x4003c9: al cmp *(rdi) 8 | 0x4003c9: rdi += D ? -1 : 1 9 | 0x4003c9: rcx-- 10 | if (Z) break 11 | } 12 | 0x4003cb: rax = rcx 13 | 0x4003ce: rax ~= rax 14 | 0x4003d1: rax-- 15 | 0x4003d4: ret 16 | } 17 | -------------------------------------------------------------------------------- /tests/x86.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/plasma-disassembler/plasma/ec7df9b2b9b356dd5d8caf01b7e68c0ab5a1ef42/tests/x86.bin -------------------------------------------------------------------------------- /tests/x86.c: -------------------------------------------------------------------------------- 1 | /* gcc tests/x86.c -o tests/x86.bin -masm=intel */ 2 | 3 | int main() { 4 | __asm__("stosb"); 5 | __asm__("stosw"); 6 | __asm__("stosd"); 7 | __asm__("stosq"); 8 | 9 | __asm__("movsb"); 10 | __asm__("movsw"); 11 | __asm__("movsd"); 12 | __asm__("movsq"); 13 | 14 | __asm__("lodsb"); 15 | __asm__("lodsw"); 16 | __asm__("lodsd"); 17 | __asm__("lodsq"); 18 | 19 | __asm__("cmpsb"); 20 | __asm__("cmpsw"); 21 | __asm__("cmpsd"); 22 | __asm__("cmpsq"); 23 | 24 | __asm__("scasb"); 25 | __asm__("scasw"); 26 | __asm__("scasd"); 27 | __asm__("scasq"); 28 | 29 | __asm__("repne scasb"); 30 | __asm__("rep stosb"); 31 | 32 | return 0; 33 | } 34 | -------------------------------------------------------------------------------- /tests/x86.rev: -------------------------------------------------------------------------------- 1 | function main (.text) { 2 | 0x4004b6: push rbp 3 | 0x4004b7: rbp = rsp 4 | 0x4004ba: *(rdi) = al 5 | 0x4004ba: rdi += D ? -1 : 1 6 | 0x4004bb: *(rdi) = ax 7 | 0x4004bb: rdi += D ? -2 : 2 8 | 0x4004bd: *(rdi) = eax 9 | 0x4004bd: rdi += D ? -4 : 4 10 | 0x4004be: *(rdi) = rax 11 | 0x4004be: rdi += D ? -8 : 8 12 | 0x4004c0: *(rdi) = *(rsi) 13 | 0x4004c0: rdi += D ? -1 : 1 14 | 0x4004c0: rsi += D ? -1 : 1 15 | 0x4004c1: *(rdi) = *(rsi) 16 | 0x4004c1: rdi += D ? -2 : 2 17 | 0x4004c1: rsi += D ? -2 : 2 18 | 0x4004c3: *(rdi) = *(rsi) 19 | 0x4004c3: rdi += D ? -4 : 4 20 | 0x4004c3: rsi += D ? -4 : 4 21 | 0x4004c4: *(rdi) = *(rsi) 22 | 0x4004c4: rdi += D ? -8 : 8 23 | 0x4004c4: rsi += D ? -8 : 8 24 | 0x4004c6: al = *(rsi) 25 | 0x4004c6: rsi += D ? -1 : 1 26 | 0x4004c7: ax = *(rsi) 27 | 0x4004c7: rsi += D ? -2 : 2 28 | 0x4004c9: eax = *(rsi) 29 | 0x4004c9: rsi += D ? -4 : 4 30 | 0x4004ca: rax = *(rsi) 31 | 0x4004ca: rsi += D ? -8 : 8 32 | 0x4004cc: *(rsi) cmp *(rdi) 33 | 0x4004cc: rsi += D ? -1 : 1 34 | 0x4004cc: rdi += D ? -1 : 1 35 | 0x4004cd: *(rsi) cmp *(rdi) 36 | 0x4004cd: rsi += D ? -2 : 2 37 | 0x4004cd: rdi += D ? -2 : 2 38 | 0x4004cf: *(rsi) cmp *(rdi) 39 | 0x4004cf: rsi += D ? -4 : 4 40 | 0x4004cf: rdi += D ? -4 : 4 41 | 0x4004d0: *(rsi) cmp *(rdi) 42 | 0x4004d0: rsi += D ? -8 : 8 43 | 0x4004d0: rdi += D ? -8 : 8 44 | 0x4004d2: al cmp *(rdi) 45 | 0x4004d2: rdi += D ? -1 : 1 46 | 0x4004d3: ax cmp *(rdi) 47 | 0x4004d3: rdi += D ? -2 : 2 48 | 0x4004d5: eax cmp *(rdi) 49 | 0x4004d5: rdi += D ? -4 : 4 50 | 0x4004d6: rax cmp *(rdi) 51 | 0x4004d6: rdi += D ? -8 : 8 52 | 0x4004d8: 53 | while (!rcx) { 54 | 0x4004d8: al cmp *(rdi) 55 | 0x4004d8: rdi += D ? -1 : 1 56 | 0x4004d8: rcx-- 57 | if (Z) break 58 | } 59 | 0x4004da: 60 | while (!rcx) { 61 | 0x4004da: *(rdi) = al 62 | 0x4004da: rdi += D ? -1 : 1 63 | 0x4004da: rcx-- 64 | } 65 | 0x4004dc: eax = 0 66 | 0x4004e1: pop rbp 67 | 0x4004e2: ret 68 | } 69 | --------------------------------------------------------------------------------