├── CMake
├── FindPin.cmake
└── UsePin.cmake
├── CMakeLists.txt
├── LICENSE
├── README.md
├── demo
├── code_virtualizer.png
├── mobfus_cfg.pdf
├── mobfus_cfg_orig.pdf
├── rescfg_bb.pdf
├── rescfg_switch_bb.pdf
├── rescfg_virtual.pdf
├── rescfg_vmprotect_bb.pdf
└── virt_virt_mobfus_exp.pdf
├── experiments
├── appqsort.c
├── arguments
├── bublesort.c
├── bublesort_obf.c
├── bublesort_recursive.c
├── bublesort_recursive_obf.c
├── bublesort_recursive_obf2.c
├── virsuper_bbsort_recur2.c
└── virtualize_super_bublesort_recursive.c
├── results
├── bublesort_bb.pdf
├── bublesort_bb.trace1
├── bublesort_bb.trace2
├── bublesort_bb1.pdf
├── bublesort_bb1.trace
├── bublesort_bb2.pdf
├── bublesort_bb2.trace
├── bublesort_obf_bb.pdf
├── bublesort_obf_bb.trace1
├── bublesort_obf_bb.trace2
├── bublesort_obf_bb1.pdf
├── bublesort_obf_bb1.trace
├── bublesort_obf_bb2.pdf
├── bublesort_obf_bb2.trace
├── bublesort_ollvm_bb1.pdf
├── bublesort_ollvm_bb1.trace
├── bublesort_ollvm_bb2.pdf
├── bublesort_ollvm_bb2.trace
├── bublesort_recursive_bb.pdf
├── bublesort_recursive_bb1.trace
├── bublesort_recursive_bb2.trace
├── bublesort_recursive_obf2_bb.pdf
├── bublesort_recursive_obf2_bb1.trace
├── bublesort_recursive_obf2_bb2.trace
├── bublesort_recursive_obf_bb.pdf
├── bublesort_recursive_obf_bb1.trace
├── bublesort_recursive_obf_bb2.trace
├── resmsign_codevirtualizer.pdf
├── virsuper_bbsort_recur2_bb.pdf
├── virtualize_super_bublesort_recursive_bb.pdf
├── virtualize_super_bublesort_recursive_bb.trace1
└── virtualize_super_bublesort_recursive_bb.trace2
└── src
├── engine
├── traceExpAnalysis.ml
└── traceExpDirectAnalysis.ml
├── jump_table
├── CMakeLists.txt
├── dump.cpp
├── elfio
│ ├── elf_types.hpp
│ ├── elfio.hpp
│ ├── elfio_dump.hpp
│ ├── elfio_dynamic.hpp
│ ├── elfio_header.hpp
│ ├── elfio_note.hpp
│ ├── elfio_relocation.hpp
│ ├── elfio_section.hpp
│ ├── elfio_segment.hpp
│ ├── elfio_strings.hpp
│ ├── elfio_symbols.hpp
│ └── elfio_utils.hpp
├── main.cpp
└── tinyformat.h
├── lib
├── cap
│ ├── cap.h
│ ├── graph.cpp
│ ├── parser.cpp
│ ├── saver.cpp
│ ├── trace.h
│ ├── trace.pb.h
│ └── tracer.cpp
├── framework
│ └── analysis_callback.h
├── tinyformat.h
└── type
│ ├── instruction.cpp
│ ├── instruction.h
│ ├── operand.cpp
│ ├── operand.h
│ ├── trace.pb.h
│ ├── trace_graph.cpp
│ └── trace_graph.h
├── main.cpp
├── parsing_helper.h
└── virtual_cfg
├── CMakeLists.txt
├── main.cpp
├── relative.cpp
└── tinyformat.h
/CMake/FindPin.cmake:
--------------------------------------------------------------------------------
1 | # - Find PIN SDK.
2 | # This module finds a pin installation and selects a default one.
3 | #
4 | # Author: Manuel Niekamp
5 | # Email: niekma@upb.de
6 | #
7 | # The following variables are set after the configuration is done:
8 | #
9 | # PIN_FOUND - Set to TRUE if pin was found.
10 | # PIN_ROOT_DIR - base directory of pin
11 | # PIN_INCLUDE_DIRS - Include directories.
12 | # PIN_LIBRARY_DIRS - compile time link dirs, useful for
13 | # rpath on UNIX. Typically an empty string
14 | # in WIN32 environment.
15 | # PIN_DEFINITIONS - Contains defines required to compile/link
16 | # against pin
17 | # PIN_COMPILE_FLAGS - Compiler flags for C an C++
18 | # PIN_CXX_FLAGS - Extra C++ compiler flags
19 | # PIN_C_FLAGS - Extra C compiler flags
20 | # PIN_USE_FILE - Convenience include file.
21 | # PIN_CPU_ARCH - ia32, ia64
22 |
23 | set(PIN_FOUND false)
24 |
25 | # Add the convenience use file if available.
26 | set(PIN_USE_FILE "")
27 | get_filename_component(TMP_CURRENT_LIST_DIR ${CMAKE_CURRENT_LIST_FILE} PATH)
28 | # Prefer an existing customized version
29 | if(EXISTS "${TMP_CURRENT_LIST_DIR}/UsePin.cmake")
30 | set(PIN_USE_FILE "${TMP_CURRENT_LIST_DIR}/UsePin.cmake")
31 | else(EXISTS "${TMP_CURRENT_LIST_DIR}/UsePin.cmake")
32 | set(PIN_USE_FILE UsePin.cmake)
33 | endif(EXISTS "${TMP_CURRENT_LIST_DIR}/UsePin.cmake")
34 |
35 |
36 | execute_process(
37 | COMMAND uname -m
38 | OUTPUT_VARIABLE PIN_CPU_ARCH
39 | RESULT_VARIABLE uname_result
40 | OUTPUT_STRIP_TRAILING_WHITESPACE
41 | ERROR_QUIET
42 | )
43 |
44 | if("${PIN_CPU_ARCH}" STREQUAL "x86_64")
45 | set(PIN_CPU_ARCH "ia32e")
46 | set(PIN_CPU_ARCH_LONG "intel64")
47 | elseif("${PIN_CPU_ARCH}" STREQUAL "amd64")
48 | set(PIN_CPU_ARCH "ia32e")
49 | set(PIN_CPU_ARCH_LONG "intel64")
50 | elseif("${PIN_CPU_ARCH}" STREQUAL "i686")
51 | set(PIN_CPU_ARCH "ia32")
52 | set(PIN_CPU_ARCH_LONG "ia32")
53 | elseif("${PIN_CPU_ARCH}" STREQUAL "x86")
54 | set(PIN_CPU_ARCH "ia32")
55 | set(PIN_CPU_ARCH_LONG "ia32")
56 | elseif("${PIN_CPU_ARCH}" STREQUAL "i386")
57 | set(PIN_CPU_ARCH "ia32")
58 | set(PIN_CPU_ARCH_LONG "ia32")
59 | elseif("${PIN_CPU_ARCH}" STREQUAL "ia64")
60 | set(PIN_CPU_ARCH "ipf")
61 | set(PIN_CPU_ARCH_LONG "ia62")
62 | endif("${PIN_CPU_ARCH}" STREQUAL "x86_64")
63 |
64 | set(PIN_CPU_ARCH "ia32")
65 | set(PIN_CPU_ARCH_LONG "ia32")
66 |
67 | message(STATUS "PIN_CPU_ARCH: ${PIN_CPU_ARCH}")
68 |
69 | find_path(PIN_ROOT_DIR
70 | NAMES source/include/pin/pin.H
71 | PATHS $ENV{PIN_ROOT_DIR}
72 | DOC "Pin's base directory"
73 | )
74 |
75 | if(NOT PIN_ROOT_DIR)
76 | message(FATAL_ERROR
77 | "\nPin not found!\n"
78 | "Please set the environment variable PIN_ROOT_DIR to the base directory"
79 | " of the pin library.\n"
80 | )
81 | endif(NOT PIN_ROOT_DIR)
82 |
83 | message(STATUS "PIN_ROOT_DIR: ${PIN_ROOT_DIR}")
84 |
85 | set(PIN_INCLUDE_DIRS
86 | ${PIN_ROOT_DIR}/extras/xed-${PIN_CPU_ARCH_LONG}/include
87 | ${PIN_ROOT_DIR}/source/include/pin
88 | ${PIN_ROOT_DIR}/source/include/pin/gen
89 | ${PIN_ROOT_DIR}/extras/components/include
90 | )
91 |
92 | set(PIN_LIBRARY_DIRS
93 | ${PIN_ROOT_DIR}/extras/xed-${PIN_CPU_ARCH_LONG}/lib
94 | ${PIN_ROOT_DIR}/${PIN_CPU_ARCH_LONG}/lib
95 | ${PIN_ROOT_DIR}/${PIN_CPU_ARCH_LONG}/lib-ext
96 | )
97 |
98 | set(PIN_VERSION_SCRIPT ${PIN_ROOT_DIR}/source/include/pin/pintool.ver)
99 |
100 | #set(PIN_COMPILE_FLAGS "-Wall -Werror -Wno-unknown-pragmas -O3 -fomit-frame-pointer -fno-strict-aliasing -DBOOST_LOG_DYN_LINK")
101 | set(PIN_COMPILE_FLAGS "-Wall -Werror -Wno-unknown-pragmas -O3 -fomit-frame-pointer -fno-strict-aliasing")
102 | set(PIN_C_FLAGS "${PIN_COMPILE_FLAGS}")
103 | #set(PIN_CXX_FLAGS "${PIN_COMPILE_FLAGS} -MMD")
104 | set(PIN_CXX_FLAGS "${PIN_COMPILE_FLAGS} -MMD -std=c++11")
105 | # set(PIN_CXX_FLAGS "${PIN_COMPILE_FLAGS} -MMD -std=c++11 -DENABLE_FAST_ROLLBACK -DNDEBUG")
106 | set(PIN_LINKER_FLAGS "-Wl,--hash-style=sysv -shared -Wl,-Bsymbolic -Wl,--version-script=${PIN_VERSION_SCRIPT}")
107 | # set(PIN_LINKER_FLAGS "-Wl,--hash-style=sysv -Wl,-Bsymbolic -Wl,--version-script=${PIN_VERSION_SCRIPT}")
108 |
109 | set(PIN_DEFINITIONS "")
110 | list(APPEND PIN_DEFINITIONS BIGARRAY_MULTIPLIER=1 USING_XED)
111 |
112 | if("${PIN_CPU_ARCH}" STREQUAL "ia32e")
113 | list(APPEND PIN_DEFINITIONS TARGET_IA32E HOST_IA32E)
114 | elseif("${PIN_CPU_ARCH}" STREQUAL "ia32")
115 | list(APPEND PIN_DEFINITIONS TARGET_IA32 HOST_IA32)
116 | elseif("${PIN_CPU_ARCH}" STREQUAL "ipf")
117 | list(APPEND PIN_DEFINITIONS TARGET_IPF HOST_IPF)
118 | endif("${PIN_CPU_ARCH}" STREQUAL "ia32e")
119 |
120 | set(PIN_FOUND true)
121 |
--------------------------------------------------------------------------------
/CMake/UsePin.cmake:
--------------------------------------------------------------------------------
1 | # - Convenience include for using pin library
2 | # Finds if pin is installed
3 | # and set the appropriate libs, incdirs, flags etc.
4 | # INCLUDE_DIRECTORIES, LINK_DIRECTORIES and ADD_DEFINITIONS
5 | # are called.
6 | #
7 | # If you need to link extra libraries use PINTOOL_LINK_LIBS
8 | # variable to set them.
9 | #
10 | # Author: Manuel Niekamp
11 | # Email: niekma@upb.de
12 | #
13 |
14 | if(PIN_FOUND)
15 |
16 | macro(ADD_PINTOOL pin_tool_name)
17 |
18 | if(PIN_INCLUDE_DIRS)
19 | include_directories(${PIN_INCLUDE_DIRS})
20 | endif(PIN_INCLUDE_DIRS)
21 |
22 | if(PIN_LIBRARY_DIRS)
23 | link_directories(${PIN_LIBRARY_DIRS})
24 | endif(PIN_LIBRARY_DIRS)
25 |
26 | add_library(${pin_tool_name} SHARED ${ARGN})
27 |
28 | set_target_properties(${pin_tool_name} PROPERTIES
29 | PREFIX ""
30 | SUFFIX ".pin"
31 | COMPILE_DEFINITIONS "${PIN_DEFINITIONS}"
32 | LINK_FLAGS "${PIN_LINKER_FLAGS}"
33 | )
34 |
35 | foreach(_entry ${ARGN})
36 | get_source_file_property(_prop ${_entry} LANGUAGE)
37 | if("${_prop}" STREQUAL "C")
38 | list(APPEND ${pin_tool_name}_C_FILES ${_entry})
39 | elseif("${_prop}" STREQUAL "CXX")
40 | list(APPEND ${pin_tool_name}_CXX_FILES ${_entry})
41 | endif("${_prop}" STREQUAL "C")
42 | endforeach()
43 |
44 | set_source_files_properties(${${pin_tool_name}_C_FILES} PROPERTIES
45 | COMPILE_FLAGS ${PIN_C_FLAGS}
46 | )
47 |
48 | set_source_files_properties(${${pin_tool_name}_CXX_FILES} PROPERTIES
49 | COMPILE_FLAGS ${PIN_CXX_FLAGS}
50 | )
51 |
52 | target_link_libraries(${pin_tool_name} ${PINTOOL_LINK_LIBS} pin xed dwarf elf dl)
53 |
54 | endmacro(ADD_PINTOOL pin_tool_name)
55 |
56 | else(PIN_FOUND)
57 |
58 | message(FATAL_ERROR "Pin was not found!")
59 |
60 | endif(PIN_FOUND)
61 |
62 |
--------------------------------------------------------------------------------
/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | project(PinICap)
2 | cmake_minimum_required(VERSION 2.8)
3 |
4 | set(CMAKE_BUILD_TYPE "None")
5 |
6 | if(NOT PIN_ROOT_DIR)
7 | message(FATAL_ERROR
8 | "\nPin not found!\n"
9 | "Please set the environment variable PIN_ROOT_DIR to the base directory"
10 | " of the pin library.\n"
11 | )
12 | endif(NOT PIN_ROOT_DIR)
13 | message(STATUS "PIN_ROOT_DIR: ${PIN_ROOT_DIR}")
14 |
15 | set(PIN_CPU_ARCH "ia32")
16 | set(PIN_CPU_ARCH_LONG "ia32")
17 |
18 | set(PIN_INCLUDE_DIRS
19 | ${PIN_ROOT_DIR}/extras/xed2-${PIN_CPU_ARCH_LONG}/include
20 | ${PIN_ROOT_DIR}/source/include/pin
21 | ${PIN_ROOT_DIR}/source/include/pin/gen
22 | ${PIN_ROOT_DIR}/extras/components/include
23 | ${LOCAL_INCLUDE_DIR})
24 |
25 | set(PIN_LIBRARY_DIRS
26 | ${PIN_ROOT_DIR}/extras/xed2-${PIN_CPU_ARCH_LONG}/lib
27 | ${PIN_ROOT_DIR}/${PIN_CPU_ARCH_LONG}/lib
28 | ${PIN_ROOT_DIR}/${PIN_CPU_ARCH_LONG}/lib-ext)
29 |
30 | set(SOURCES
31 | src/main.cpp
32 | src/lib/cap/tracer.cpp
33 | src/lib/cap/parser.cpp
34 | src/lib/cap/graph.cpp
35 | src/lib/type/instruction.cpp)
36 |
37 | # ========================================= start host configuration
38 |
39 | if(${CMAKE_SYSTEM_NAME} MATCHES "Windows")
40 | set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/CMake/")
41 |
42 | set(PIN_DEFS "/D TARGET_IA32 /D HOST_IA32 /D TARGET_WINDOWS /D USING_XED /D_SECURE_SCL=0 /D_ITERATOR_DEBUG_LEVEL=0 /Zc:auto")
43 | set(LINKER_DEFS "/D _WINDLL /D _MBCS /GS- /MT /EHsc /Ox /O2 /Ob2 /nologo")
44 |
45 | set(PIN_LIBRARY_DIRS
46 | ${PIN_ROOT_DIR}/extras/xed-${PIN_CPU_ARCH_LONG}/lib
47 | ${PIN_ROOT_DIR}/${PIN_CPU_ARCH_LONG}/lib
48 | ${PIN_ROOT_DIR}/${PIN_CPU_ARCH_LONG}/lib-ext)
49 |
50 | set(PIN_LIBS pin pinvm libxed ntdll-32 dbghelp)
51 |
52 | set(OTHER_LIBS libcpmt libcmt)
53 |
54 | if(NOT DEFINED BOOST_ROOT_DIR)
55 | message(FATAL_ERROR "\nBoost not found!\n"
56 | "Please set the environment variable BOOST_ROOT_DIR to the base directory"
57 | " of the Boost library.\n")
58 | endif(NOT DEFINED BOOST_ROOT_DIR)
59 | message(STATUS "BOOST_ROOT_DIR: ${BOOST_ROOT_DIR}")
60 |
61 | set(INCLUDE_DIRS
62 | ${PIN_INCLUDE_DIRS}
63 | ${BOOST_ROOT_DIR})
64 |
65 | include_directories(${INCLUDE_DIRS})
66 | link_directories(${PIN_LIBRARY_DIRS})
67 |
68 | add_definitions(${PIN_DEFS})
69 | add_definitions(${LINKER_DEFS})
70 | add_definitions(${FUNC_DEFS})
71 |
72 | set(CMAKE_CXX_FLAGS "${FUNC_DEFS} ${OTHER_DEFS} ${PIN_DEFS}")
73 | set(CMAKE_SHARED_LINKER_FLAGS "/DLL /EXPORT:main /NODEFAULTLIB /MACHINE:x86 /ENTRY:Ptrace_DllMainCRTStartup@12 /BASE:0x55000000")
74 |
75 | add_library(vtrace SHARED ${SOURCES})
76 | target_link_libraries(vtrace ${PIN_LIBS} ${OTHER_LIBS})
77 |
78 | else()
79 |
80 | set(PIN_DEFINITIONS "")
81 | list(APPEND PIN_DEFINITIONS
82 | TARGET_LINUX
83 | BIGARRAY_MULTIPLIER=1
84 | USING_XED
85 | TARGET_IA32 HOST_IA32)
86 |
87 | set(PIN_VERSION_SCRIPT ${PIN_ROOT_DIR}/source/include/pin/pintool.ver)
88 |
89 | set(PIN_COMPILE_FLAGS "-Wall -Wno-unknown-pragmas -std=c++11 -m32 -MMD -O3 -fomit-frame-pointer -fno-strict-aliasing -fno-stack-protector")
90 |
91 | set(PIN_LINKER_FLAGS "-Wl,--hash-style=sysv -Wl,-Bsymbolic -Wl,--version-script=${PIN_VERSION_SCRIPT}")
92 |
93 | set(PIN_LINK_LIBS pin xed dwarf elf dl protobuf)
94 |
95 | link_directories(${PIN_LIBRARY_DIRS})
96 | include_directories(${PIN_INCLUDE_DIRS})
97 |
98 | # add Pintool
99 | add_library(vtrace SHARED ${SOURCES})
100 |
101 | # set compile and link flags
102 | set_source_files_properties(${SOURCES} PROPERTIES
103 | COMPILE_FLAGS "${PIN_COMPILE_FLAGS}"
104 | COMPILE_DEFINITIONS "${PIN_DEFINITIONS}")
105 |
106 | set_target_properties(vtrace PROPERTIES
107 | PREFIX ""
108 | SUFFIX ".pin"
109 | COMPILE_DEFINITIONS "${PIN_DEFINITIONS}"
110 | COMPILE_FLAGS "${PIN_COMPILE_FLAGS}"
111 | LINK_FLAGS "${PIN_LINKER_FLAGS} -v -m32")
112 |
113 | target_link_libraries(vtrace ${PIN_LINK_LIBS})
114 | endif()
115 |
116 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # relative-pattern
2 | This is a tool experimenting a *formal method* to recover program control flow graph from binaries obfuscated by *virtualizing obfuscation*, even when binaries are virtualized **mutliple times**. Currently, it considers the transformations of
3 |
4 | * [Tigress](http://tigress.cs.arizona.edu/)
5 | * [VMProtect](http://vmpsoft.com/)
6 | * [Code Virtualizer](http://oreans.com/)
7 | * [O-LLVM](https://github.com/obfuscator-llvm/obfuscator)1
8 | * Other ad-hoc implementations2.
9 |
10 | The code is in active development, still buggy and difficult to use. The [underlying concolic execution engine](http://binsec.gforge.inria.fr/) are not fully published yet3, though the current published code can work with any concolic/fuzzing engine. Moreover *the strength of this tool depends only on the execution engine*, that is a rational theoretical limit of the method.
11 |
12 | Though I follow a mathematical approach, the main idea is simple. It might have been considered implicitly in many "unpack tutorials" of great hackers and crackers. The only original contribution here is to give a more solid *theoretical base* that explains these concrete techniques, and this leads to a "less ad-hoc" deobfuscation technique.
13 |
14 | The tool is written mostly in C++ and OCaml, and uses the following great softwares:
15 | * [BinSec](http://binsec.gforge.inria.fr/)3
16 | * [Pin](https://software.intel.com/en-us/articles/pin-a-dynamic-binary-instrumentation-tool)
17 | * [Boost](http://www.boost.org/)
18 | * [tinyformat](https://github.com/c42f/tinyformat)
19 | * [Protocol Buffers](https://github.com/google/protobuf)
20 | * [ELFIO - ELF](https://github.com/serge1/ELFIO)
21 |
22 | Currently there is no documentation (if you are interested in, I am very happy to answer any question). I try also to prepare a paper on this but there are still a lot of things to do.
23 |
24 | 
25 |
26 | 1[O-LLVM](https://github.com/obfuscator-llvm/obfuscator) does not support yet virtualization transformations, though control-flow-graph flattening can be considered as a "light-weight" virtualization.
27 |
28 | 2Collected from [crackmes.de](http://crackmes.de/).
29 |
30 | 3[BinSec](http://binsec.gforge.inria.fr/) is in very active development and it will be open when it is ready, some technical documents and (rather old) source codes can be referenced [here](http://sebastien.bardin.free.fr/binsec.html).
31 |
--------------------------------------------------------------------------------
/demo/code_virtualizer.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/melbshark/relative-pattern/c68f205eaddf4e7832ade0eab69de081b7e56c51/demo/code_virtualizer.png
--------------------------------------------------------------------------------
/demo/mobfus_cfg.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/melbshark/relative-pattern/c68f205eaddf4e7832ade0eab69de081b7e56c51/demo/mobfus_cfg.pdf
--------------------------------------------------------------------------------
/demo/mobfus_cfg_orig.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/melbshark/relative-pattern/c68f205eaddf4e7832ade0eab69de081b7e56c51/demo/mobfus_cfg_orig.pdf
--------------------------------------------------------------------------------
/demo/rescfg_bb.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/melbshark/relative-pattern/c68f205eaddf4e7832ade0eab69de081b7e56c51/demo/rescfg_bb.pdf
--------------------------------------------------------------------------------
/demo/rescfg_switch_bb.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/melbshark/relative-pattern/c68f205eaddf4e7832ade0eab69de081b7e56c51/demo/rescfg_switch_bb.pdf
--------------------------------------------------------------------------------
/demo/rescfg_virtual.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/melbshark/relative-pattern/c68f205eaddf4e7832ade0eab69de081b7e56c51/demo/rescfg_virtual.pdf
--------------------------------------------------------------------------------
/demo/rescfg_vmprotect_bb.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/melbshark/relative-pattern/c68f205eaddf4e7832ade0eab69de081b7e56c51/demo/rescfg_vmprotect_bb.pdf
--------------------------------------------------------------------------------
/demo/virt_virt_mobfus_exp.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/melbshark/relative-pattern/c68f205eaddf4e7832ade0eab69de081b7e56c51/demo/virt_virt_mobfus_exp.pdf
--------------------------------------------------------------------------------
/experiments/appqsort.c:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2000-2006 Apple Computer, Inc. All rights reserved.
3 | *
4 | * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
5 | *
6 | * This file contains Original Code and/or Modifications of Original Code
7 | * as defined in and that are subject to the Apple Public Source License
8 | * Version 2.0 (the 'License'). You may not use this file except in
9 | * compliance with the License. The rights granted to you under the License
10 | * may not be used to create, or enable the creation or redistribution of,
11 | * unlawful or unlicensed copies of an Apple operating system, or to
12 | * circumvent, violate, or enable the circumvention or violation of, any
13 | * terms of an Apple operating system software license agreement.
14 | *
15 | * Please obtain a copy of the License at
16 | * http://www.opensource.apple.com/apsl/ and read it before using this file.
17 | *
18 | * The Original Code and all software distributed under the License are
19 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 | * Please see the License for the specific language governing rights and
24 | * limitations under the License.
25 | *
26 | * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
27 | */
28 | /*
29 | * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved
30 | *
31 | * Copyright (c) 1992, 1993
32 | * The Regents of the University of California. All rights reserved.
33 | *
34 | * Redistribution and use in source and binary forms, with or without
35 | * modification, are permitted provided that the following conditions
36 | * are met:
37 | * 1. Redistributions of source code must retain the above copyright
38 | * notice, this list of conditions and the following disclaimer.
39 | * 2. Redistributions in binary form must reproduce the above copyright
40 | * notice, this list of conditions and the following disclaimer in the
41 | * documentation and/or other materials provided with the distribution.
42 | * 3. All advertising materials mentioning features or use of this software
43 | * must display the following acknowledgement:
44 | * This product includes software developed by the University of
45 | * California, Berkeley and its contributors.
46 | * 4. Neither the name of the University nor the names of its contributors
47 | * may be used to endorse or promote products derived from this software
48 | * without specific prior written permission.
49 | *
50 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
51 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
52 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
53 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
54 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
55 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
56 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
57 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
58 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
59 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
60 | * SUCH DAMAGE.
61 | *
62 | * @(#)mqsort.c 8.1 (Berkeley) 6/4/93
63 | */
64 |
65 |
66 | #include
67 | //#include
68 |
69 | void mqsort(void *a, size_t n, size_t es, int (*cmp)(const void *, const void *));
70 |
71 | static inline char *med3(char *, char *, char *, int (*)(const void *, const void *));
72 | static inline void swapfunc(char *, char *, int, int);
73 |
74 | #define min(a, b) (a) < (b) ? a : b
75 |
76 | /*
77 | * Qsort routine from Bentley & McIlroy's "Engineering a Sort Function".
78 | */
79 | #define swapcode(TYPE, parmi, parmj, n) { \
80 | long i = (n) / sizeof (TYPE); \
81 | TYPE *pi = (TYPE *) (parmi); \
82 | TYPE *pj = (TYPE *) (parmj); \
83 | do { \
84 | TYPE t = *pi; \
85 | *pi++ = *pj; \
86 | *pj++ = t; \
87 | } while (--i > 0); \
88 | }
89 |
90 | #define SWAPINIT(a, es) swaptype = ((char *)a - (char *)0) % sizeof(long) || \
91 | es % sizeof(long) ? 2 : es == sizeof(long)? 0 : 1;
92 |
93 | static inline void swapfunc(char *a, char *b, int n, int swaptype)
94 | {
95 | if(swaptype <= 1)
96 | swapcode(long, a, b, n)
97 | else
98 | swapcode(char, a, b, n)
99 | }
100 |
101 | #define swap(a, b) \
102 | if (swaptype == 0) { \
103 | long t = *(long *)(a); \
104 | *(long *)(a) = *(long *)(b); \
105 | *(long *)(b) = t; \
106 | } else \
107 | swapfunc(a, b, es, swaptype)
108 |
109 | #define vecswap(a, b, n) if ((n) > 0) swapfunc(a, b, n, swaptype)
110 |
111 | static inline char *med3(char *a, char *b, char *c, int (*cmp)(const void *, const void *))
112 | {
113 | return cmp(a, b) < 0 ?
114 | (cmp(b, c) < 0 ? b : (cmp(a, c) < 0 ? c : a ))
115 | :(cmp(b, c) > 0 ? b : (cmp(a, c) < 0 ? a : c ));
116 | }
117 |
118 |
119 | void mqsort(void *a, size_t n, size_t es, int (*cmp)(const void *, const void *))
120 | {
121 | char *pa, *pb, *pc, *pd, *pl, *pm, *pn;
122 | int d, swaptype, swap_cnt;
123 | int r;
124 |
125 | loop: SWAPINIT(a, es);
126 | swap_cnt = 0;
127 | if (n < 7) {
128 | for (pm = (char *)a + es; pm < (char *) a + n * es; pm += es)
129 | for (pl = pm; pl > (char *) a && cmp(pl - es, pl) > 0;
130 | pl -= es)
131 | swap(pl, pl - es);
132 | return;
133 | }
134 | pm = (char *)a + (n / 2) * es;
135 | if (n > 7) {
136 | pl = a;
137 | pn = (char *)a + (n - 1) * es;
138 | if (n > 40) {
139 | d = (n / 8) * es;
140 | pl = med3(pl, pl + d, pl + 2 * d, cmp);
141 | pm = med3(pm - d, pm, pm + d, cmp);
142 | pn = med3(pn - 2 * d, pn - d, pn, cmp);
143 | }
144 | pm = med3(pl, pm, pn, cmp);
145 | }
146 | swap(a, pm);
147 | pa = pb = (char *)a + es;
148 |
149 | pc = pd = (char *)a + (n - 1) * es;
150 | for (;;) {
151 | while (pb <= pc && (r = cmp(pb, a)) <= 0) {
152 | if (r == 0) {
153 | swap_cnt = 1;
154 | swap(pa, pb);
155 | pa += es;
156 | }
157 | pb += es;
158 | }
159 | while (pb <= pc && (r = cmp(pc, a)) >= 0) {
160 | if (r == 0) {
161 | swap_cnt = 1;
162 | swap(pc, pd);
163 | pd -= es;
164 | }
165 | pc -= es;
166 | }
167 | if (pb > pc)
168 | break;
169 | swap(pb, pc);
170 | swap_cnt = 1;
171 | pb += es;
172 | pc -= es;
173 | }
174 | if (swap_cnt == 0) { /* Switch to insertion sort */
175 | for (pm = (char *)a + es; pm < (char *) a + n * es; pm += es)
176 | for (pl = pm; pl > (char *) a && cmp(pl - es, pl) > 0;
177 | pl -= es)
178 | swap(pl, pl - es);
179 | return;
180 | }
181 |
182 | pn = (char *)a + n * es;
183 | r = min(pa - (char *)a, pb - pa);
184 | vecswap(a, pb - r, r);
185 | r = min((size_t)(pd - pc), pn - pd - es);
186 | vecswap(pb, pn - r, r);
187 | if ((size_t)(r = pb - pa) > es)
188 | mqsort(a, r / es, es, cmp);
189 | if ((size_t)(r = pd - pc) > es) {
190 | /* Iterate rather than recurse to save stack space */
191 | a = pn - r;
192 | n = r / es;
193 | goto loop;
194 | }
195 | }
196 |
197 | int compare_int(int* x, int *y)
198 | {
199 | if (*x == *y) return 0;
200 | else if (*x < *y) return -1;
201 | else return 1;
202 | }
203 |
204 |
205 | int main(int argc, char* argv[])
206 | {
207 | int array[7] = { 15, 4, 1, 8, 17, 3, 6 };
208 | mqsort(array, 7, sizeof(int*), compare_int);
209 | }
210 |
--------------------------------------------------------------------------------
/experiments/arguments:
--------------------------------------------------------------------------------
1 | O-LLVM compiler
2 |
3 | clang bublesort.c -o bublesort_ollvm -m32 -mllvm -fla
4 |
5 | ./pin67257/ia32/bin/pinbin -t build/vtrace.pin -opt "bublesort_ollvm.opt" -out "bublesort_ollvm.trace" -dot "bublesort_ollvm.dot" -dot-bb "bublesort_ollvm_bb.dot" -trace-bb "bublesort_ollvm_bb.trace1" -- ./bublesort_ollvm 5 3 1 7 6 5
6 |
7 | ./pin67257/ia32/bin/pinbin -t build/vtrace.pin -opt "bublesort_ollvm.opt" -out "bublesort_ollvm.trace" -dot "bublesort_ollvm.dot" -dot-bb "bublesort_ollvm_bb.dot" -trace-bb "bublesort_ollvm_bb.trace2" -- ./bublesort_ollvm 6 9 3 1 7 6 5
8 |
9 | Tigress compiler
10 |
11 | tigress --Transform=InitOpaque --Functions=sort --Transform=Flatten --Functions=sort --FlattenDispatch=switch --out=./bublesort_obf.c bublesort.c
12 |
13 | ./pin67257/ia32/bin/pinbin -t build/vtrace.pin -opt "bublesort_obf.opt" -out "bublesort_obf.trace" -dot "bublesort_obf.dot" -dot-bb "bublesort_obf_bb.dot" -trace-bb "bublesort_obf_bb.trace1" -- ./bublesort_obf 5 3 1 7 6 5
14 |
15 | ./pin67257/ia32/bin/pinbin -t build/vtrace.pin -opt "bublesort_obf.opt" -out "bublesort_obf.trace" -dot "bublesort_obf.dot" -dot-bb "bublesort_obf_bb.dot" -trace-bb "bublesort_obf_bb.trace2" -- ./bublesort_obf 6 9 3 1 7 6 5
16 |
17 | ./pin67257/ia32/bin/pinbin -t build/vtrace.pin -opt "bublesort_recursive_obf.opt" -out "bublesort_recursive_obf.trace" -dot "bublesort_recursive_obf.dot" -dot-bb "bublesort_recursive_obf_bb.dot" -trace-bb "bublesort_recursive_obf_bb1.trace" -- ./bublesort_recursive_obf 5 3 1 7 6 5
18 |
19 | ./pin67257/ia32/bin/pinbin -t build/vtrace.pin -opt "bublesort_recursive_obf.opt" -out "bublesort_recursive_obf.trace" -dot "bublesort_recursive_obf.dot" -dot-bb "bublesort_recursive_obf_bb.dot" -trace-bb "bublesort_recursive_obf_bb2.trace" -- ./bublesort_recursive_obf 6 9 3 1 7 6 5
20 |
21 | Normal
22 |
23 | ./pin67257/ia32/bin/pinbin -t build/vtrace.pin -opt "bublesort.opt" -out "bublesort.trace" -dot "bublesort.dot" -dot-bb "bublesort_bb.dot" -trace-bb "bublesort_bb.trace1" -- ./bublesort 5 3 1 7 6 5
24 |
25 | ./pin67257/ia32/bin/pinbin -t build/vtrace.pin -opt "bublesort.opt" -out "bublesort.trace" -dot "bublesort.dot" -dot-bb "bublesort_bb.dot" -trace-bb "bublesort_bb.trace2" -- ./bublesort 6 9 3 1 7 6 5
26 |
27 | ./pin67257/ia32/bin/pinbin -t build/vtrace.pin -opt "bublesort_recursive.opt" -out "bublesort_recursive.trace" -dot "bublesort_recursive.dot" -dot-bb "bublesort_recursive_bb.dot" -trace-bb "bublesort_recursive_bb.trace" -- ./bublesort_recursive 5 3 1 7 6 5
28 |
29 | ./pin67257/ia32/bin/pinbin -t build/vtrace.pin -opt "bublesort_recursive.opt" -out "bublesort_recursive.trace" -dot "bublesort_recursive.dot" -dot-bb "bublesort_recursive_bb.dot" -trace-bb "bublesort_recursive_bb2.trace" -- ./bublesort_recursive 6 9 3 1 7 6 5
30 |
--------------------------------------------------------------------------------
/experiments/bublesort.c:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 | #include
5 |
6 | void sort (int* mlist, int size)
7 | {
8 | for (int i = 0; i < (size - 1); ++i)
9 | for (int j = 0; j < size - 1 - i; ++j) {
10 | if (mlist[j] > mlist[j+1]) {
11 | int tmp = mlist[j];
12 | mlist[j] = mlist[j+1];
13 | mlist[j+1] = tmp;
14 | }
15 | }
16 | return;
17 | }
18 |
19 | int main(int argc, char* argv[])
20 | {
21 | /* unsigned char read_list[5] = {2, 5, 3, 6, 1}; */
22 | /* unsigned char read_list[6] = {7, 2, 5, 3, 6, 1}; */
23 | /* unsigned char read_list[5] = {2, 5, 7, 6, 1}; */
24 | /* unsigned char read_list[5] = {2, 5, 8, 6, 1}; */
25 | /* unsigned char read_list[5] = {7, 5, 8, 6, 1}; */
26 | /* unsigned char read_list[6] = {7, 5, 8, 6, 1, 10}; */
27 | /* unsigned char read_list[7] = {7, 5, 8, 6, 1, 10, 2}; */
28 |
29 | int size_of_list = atoi(argv[1]);
30 |
31 | int* list = (int*)malloc(size_of_list * sizeof(int));
32 | for (int i = 0; i < size_of_list; ++i) {
33 | list[i] = atoi(argv[2 + i]);
34 | }
35 |
36 | sort(list, size_of_list);
37 |
38 | for (int i = 0; i < size_of_list; ++i) {
39 | printf("%d", list[i]);
40 | }
41 | printf("\n");
42 |
43 | /* int fd = open("data.dat", O_RDONLY); */
44 | /* if (fd >= 0) { */
45 | /* unsigned char read_list[5] = {2, 5, 3, 6, 1}; */
46 | /* read(fd, read_list, 5); */
47 | /* sort(read_list, 5); */
48 | /* close(fd); */
49 | /* } */
50 | return 0;
51 | }
52 |
--------------------------------------------------------------------------------
/experiments/bublesort_obf.c:
--------------------------------------------------------------------------------
1 | /* Generated by CIL v. 1.7.0 */
2 | /* print_CIL_Input is false */
3 |
4 | struct _1_sort__opaque_Node_1;
5 | struct _IO_FILE;
6 | struct timeval;
7 | extern void signal(int sig , void *func ) ;
8 | extern float strtof(char const *str , char const *endptr ) ;
9 | typedef unsigned long size_t;
10 | typedef struct _IO_FILE FILE;
11 | extern __attribute__((__nothrow__)) int ( __attribute__((__nonnull__(1), __leaf__)) atoi)(char const *__nptr ) __attribute__((__pure__)) ;
12 | extern double strtod(char const *str , char const *endptr ) ;
13 | extern int fclose(void *stream ) ;
14 | extern void *fopen(char const *filename , char const *mode ) ;
15 | extern void abort() ;
16 | extern void exit(int status ) ;
17 | extern int raise(int sig ) ;
18 | extern int fprintf(struct _IO_FILE *stream , char const *format , ...) ;
19 | extern int rand() ;
20 | extern unsigned long strtoul(char const *str , char const *endptr , int base ) ;
21 | typedef struct _1_sort__opaque_Node_1 *_1_sort__opaque_List_1;
22 | extern int strncmp(char const *s1 , char const *s2 , unsigned long maxlen ) ;
23 | struct _1_sort__opaque_Node_1 {
24 | int data ;
25 | struct _1_sort__opaque_Node_1 *next ;
26 | };
27 | struct _1_sort__opaque_Node_1 *_1_sort__opaque_list2_1 = (struct _1_sort__opaque_Node_1 *)0;
28 | extern int gettimeofday(struct timeval *tv , void *tz , ...) ;
29 | extern int printf(char const * __restrict __format , ...) ;
30 | int main(int argc , char **argv ) ;
31 | void megaInit(void) ;
32 | extern unsigned long strlen(char const *s ) ;
33 | void sort(int *mlist , int size ) ;
34 | extern long strtol(char const *str , char const *endptr , int base ) ;
35 | struct _1_sort__opaque_Node_1 *_1_sort__opaque_list1_1 = (struct _1_sort__opaque_Node_1 *)0;
36 | extern unsigned long strnlen(char const *s , unsigned long maxlen ) ;
37 | extern void *memcpy(void *s1 , void const *s2 , unsigned long size ) ;
38 | struct timeval {
39 | long tv_sec ;
40 | long tv_usec ;
41 | };
42 | extern __attribute__((__nothrow__)) void *( __attribute__((__leaf__)) malloc)(size_t __size ) __attribute__((__malloc__)) ;
43 | extern int scanf(char const *format , ...) ;
44 | void sort(int *mlist , int size )
45 | {
46 | int i ;
47 | int j ;
48 | int tmp ;
49 | int i6 ;
50 | int r7 ;
51 | struct _1_sort__opaque_Node_1 *p8 ;
52 | int _1_sort__BEGIN_0 ;
53 | int _1_sort__END_0 ;
54 | int _1_sort__BARRIER_1 ;
55 | unsigned long _2_sort_next ;
56 |
57 | {
58 | { /* __blockattribute__(__ATOMIC__)*/
59 | _1_sort__BEGIN_0 = 1;
60 | i6 = 0;
61 | while (i6 < 2) {
62 | r7 = rand();
63 | p8 = (struct _1_sort__opaque_Node_1 *)malloc(sizeof(struct _1_sort__opaque_Node_1 ));
64 | if (p8 != (struct _1_sort__opaque_Node_1 *)0UL) {
65 | p8->data = r7;
66 | if (_1_sort__opaque_list1_1 != (struct _1_sort__opaque_Node_1 *)0UL) {
67 | p8->next = _1_sort__opaque_list1_1->next;
68 | _1_sort__opaque_list1_1->next = p8;
69 | } else {
70 | p8->next = p8;
71 | _1_sort__opaque_list1_1 = p8;
72 | }
73 | } else {
74 |
75 | }
76 | i6 ++;
77 | }
78 | _1_sort__opaque_list2_1 = _1_sort__opaque_list1_1;
79 | _1_sort__END_0 = 1;
80 | }
81 | _1_sort__BARRIER_1 = 1;
82 | _2_sort_next = 12 * ! (_1_sort__opaque_list2_1 == (struct _1_sort__opaque_Node_1 *)0UL);
83 | while (1) {
84 | switch (_2_sort_next) {
85 | case 0: ;
86 | return;
87 | break;
88 | case 10: ;
89 | if (i < size - 1) {
90 | _2_sort_next = 8 + (_1_sort__opaque_list1_1 == (struct _1_sort__opaque_Node_1 *)0UL);
91 | } else {
92 | _2_sort_next = (unsigned long )(_1_sort__opaque_list1_1 != _1_sort__opaque_list2_1) + (unsigned long )(_1_sort__opaque_list1_1 != _1_sort__opaque_list2_1);
93 | }
94 | break;
95 | case 12:
96 | i = 0;
97 | _2_sort_next = 10 - ! (_1_sort__opaque_list2_1 != (struct _1_sort__opaque_Node_1 *)0UL);
98 | break;
99 | case 4: ;
100 | if (*(mlist + j) > *(mlist + (j + 1))) {
101 | _2_sort_next = ((unsigned long )(_1_sort__opaque_list2_1 != (struct _1_sort__opaque_Node_1 *)0UL) - (unsigned long )(_1_sort__opaque_list2_1 == (struct _1_sort__opaque_Node_1 *)0UL)) + ((unsigned long )(! ((unsigned long )(_1_sort__opaque_list1_1 != _1_sort__opaque_list2_1))) + 1);
102 | } else {
103 | _2_sort_next = (unsigned long )(! ((unsigned long )(_1_sort__opaque_list1_1 != _1_sort__opaque_list2_1))) + 1;
104 | }
105 | break;
106 | case 14:
107 | *(mlist + j) = *(mlist + (j + 1));
108 | _2_sort_next = _1_sort__opaque_list1_1 != (struct _1_sort__opaque_Node_1 *)0UL ? 13 : 5;
109 | break;
110 | case 2:
111 | j ++;
112 | _2_sort_next = 6 - (_1_sort__opaque_list1_1 == (struct _1_sort__opaque_Node_1 *)0UL);
113 | break;
114 | case 13:
115 | *(mlist + (j + 1)) = tmp;
116 | _2_sort_next = ((unsigned long )(_1_sort__opaque_list1_1 == (struct _1_sort__opaque_Node_1 *)0UL) + (unsigned long )(_1_sort__opaque_list1_1 == _1_sort__opaque_list2_1)) + 1;
117 | break;
118 | case 8:
119 | j = 0;
120 | _2_sort_next = _1_sort__opaque_list1_1 != _1_sort__opaque_list2_1 ? 2 : 6;
121 | break;
122 | case 6: ;
123 | if (j < (size - 1) - i) {
124 | _2_sort_next = 4 + ((_1_sort__opaque_list1_1 != _1_sort__opaque_list2_1) + (_1_sort__opaque_list1_1 != _1_sort__opaque_list2_1));
125 | } else {
126 | _2_sort_next = (unsigned long )(! ((unsigned long )(_1_sort__opaque_list2_1 == (struct _1_sort__opaque_Node_1 *)0UL)));
127 | }
128 | break;
129 | case 1:
130 | i ++;
131 | _2_sort_next = 10 - ((_1_sort__opaque_list1_1 != (struct _1_sort__opaque_Node_1 *)0UL) - (_1_sort__opaque_list1_1 != (struct _1_sort__opaque_Node_1 *)0UL));
132 | break;
133 | case 3:
134 | tmp = *(mlist + j);
135 | _2_sort_next = 14 - ((_1_sort__opaque_list1_1 == (struct _1_sort__opaque_Node_1 *)0UL) + (_1_sort__opaque_list1_1 == (struct _1_sort__opaque_Node_1 *)0UL));
136 | break;
137 | }
138 | }
139 | }
140 | }
141 | void megaInit(void)
142 | {
143 |
144 |
145 | {
146 |
147 | }
148 | }
149 | int main(int argc , char **argv )
150 | {
151 | int size_of_list ;
152 | int tmp ;
153 | int *list ;
154 | void *tmp___0 ;
155 | int i ;
156 | int i___0 ;
157 |
158 | {
159 | megaInit();
160 | tmp = atoi((char const *)*(argv + 1));
161 | size_of_list = tmp;
162 | tmp___0 = malloc((unsigned long )size_of_list * sizeof(int ));
163 | list = (int *)tmp___0;
164 | i = 0;
165 | while (i < size_of_list) {
166 | *(list + i) = atoi((char const *)*(argv + (2 + i)));
167 | i ++;
168 | }
169 | sort(list, size_of_list);
170 | i___0 = 0;
171 | while (i___0 < size_of_list) {
172 | printf((char const */* __restrict */)"%d", *(list + i___0));
173 | i___0 ++;
174 | }
175 | printf((char const */* __restrict */)"\n");
176 | return (0);
177 | }
178 | }
179 |
--------------------------------------------------------------------------------
/experiments/bublesort_recursive.c:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 | #include
5 |
6 | void sort(int* mlist, int size)
7 | {
8 | if (size > 1) {
9 | for (int i = 0; i < size - 1; ++i) {
10 | if (mlist[i] > mlist[i+1]) {
11 | int tmp = mlist[i];
12 | mlist[i] = mlist[i + 1];
13 | mlist[i + 1] = tmp;
14 | }
15 | }
16 | sort(mlist, size - 1);
17 | }
18 |
19 | return;
20 | }
21 |
22 | int main(int argc, char* argv[])
23 | {
24 | int lsize = atoi(argv[1]);
25 | int* list = (int*)malloc(lsize * sizeof(int));
26 | for (int i = 0; i < lsize; ++i) {
27 | list[i] = atoi(argv[2 + i]);
28 | }
29 |
30 | sort(list, lsize);
31 | for (int i = 0; i < lsize; ++i) {
32 | printf("%d", list[i]);
33 | }
34 | printf("\n");
35 |
36 | return 0;
37 | }
38 |
39 |
40 |
41 |
--------------------------------------------------------------------------------
/experiments/bublesort_recursive_obf.c:
--------------------------------------------------------------------------------
1 | /* Generated by CIL v. 1.7.0 */
2 | /* print_CIL_Input is false */
3 |
4 | struct _1_sort__opaque_Node_1;
5 | struct _IO_FILE;
6 | struct timeval;
7 | extern float strtof(char const *str , char const *endptr ) ;
8 | extern void signal(int sig , void *func ) ;
9 | typedef unsigned long size_t;
10 | typedef struct _IO_FILE FILE;
11 | extern __attribute__((__nothrow__)) int ( __attribute__((__nonnull__(1), __leaf__)) atoi)(char const *__nptr ) __attribute__((__pure__)) ;
12 | extern double strtod(char const *str , char const *endptr ) ;
13 | extern int fclose(void *stream ) ;
14 | extern void *fopen(char const *filename , char const *mode ) ;
15 | extern void abort() ;
16 | extern void exit(int status ) ;
17 | extern int raise(int sig ) ;
18 | extern int fprintf(struct _IO_FILE *stream , char const *format , ...) ;
19 | extern int rand() ;
20 | extern unsigned long strtoul(char const *str , char const *endptr , int base ) ;
21 | typedef struct _1_sort__opaque_Node_1 *_1_sort__opaque_List_1;
22 | struct _1_sort__opaque_Node_1 {
23 | int data ;
24 | struct _1_sort__opaque_Node_1 *next ;
25 | };
26 | struct _1_sort__opaque_Node_1 *_1_sort__opaque_list2_1 = (struct _1_sort__opaque_Node_1 *)0;
27 | extern int strncmp(char const *s1 , char const *s2 , unsigned long maxlen ) ;
28 | extern int gettimeofday(struct timeval *tv , void *tz , ...) ;
29 | extern int printf(char const * __restrict __format , ...) ;
30 | int main(int argc , char **argv ) ;
31 | void megaInit(void) ;
32 | extern unsigned long strlen(char const *s ) ;
33 | void sort(int *mlist , int size ) ;
34 | extern long strtol(char const *str , char const *endptr , int base ) ;
35 | struct _1_sort__opaque_Node_1 *_1_sort__opaque_list1_1 = (struct _1_sort__opaque_Node_1 *)0;
36 | extern unsigned long strnlen(char const *s , unsigned long maxlen ) ;
37 | extern void *memcpy(void *s1 , void const *s2 , unsigned long size ) ;
38 | struct timeval {
39 | long tv_sec ;
40 | long tv_usec ;
41 | };
42 | extern __attribute__((__nothrow__)) void *( __attribute__((__leaf__)) malloc)(size_t __size ) __attribute__((__malloc__)) ;
43 | extern int scanf(char const *format , ...) ;
44 | void megaInit(void)
45 | {
46 |
47 |
48 | {
49 |
50 | }
51 | }
52 | int main(int argc , char **argv )
53 | {
54 | int lsize ;
55 | int tmp ;
56 | int *list ;
57 | void *tmp___0 ;
58 | int i ;
59 | int i___0 ;
60 |
61 | {
62 | megaInit();
63 | tmp = atoi((char const *)*(argv + 1));
64 | lsize = tmp;
65 | tmp___0 = malloc((unsigned long )lsize * sizeof(int ));
66 | list = (int *)tmp___0;
67 | i = 0;
68 | while (i < lsize) {
69 | *(list + i) = atoi((char const *)*(argv + (2 + i)));
70 | i ++;
71 | }
72 | sort(list, lsize);
73 | i___0 = 0;
74 | while (i___0 < lsize) {
75 | printf((char const */* __restrict */)"%d", *(list + i___0));
76 | i___0 ++;
77 | }
78 | printf((char const */* __restrict */)"\n");
79 | return (0);
80 | }
81 | }
82 | void sort(int *mlist , int size )
83 | {
84 | int i ;
85 | int tmp ;
86 | int i5 ;
87 | int r6 ;
88 | struct _1_sort__opaque_Node_1 *p7 ;
89 | int _1_sort__BEGIN_0 ;
90 | int _1_sort__END_0 ;
91 | int _1_sort__BARRIER_1 ;
92 | unsigned long _2_sort_next ;
93 |
94 | {
95 | { /* __blockattribute__(__ATOMIC__)*/
96 | _1_sort__BEGIN_0 = 1;
97 | i5 = 0;
98 | while (i5 < 2) {
99 | r6 = rand();
100 | p7 = (struct _1_sort__opaque_Node_1 *)malloc(sizeof(struct _1_sort__opaque_Node_1 ));
101 | if (p7 != (struct _1_sort__opaque_Node_1 *)0UL) {
102 | p7->data = r6;
103 | if (_1_sort__opaque_list1_1 != (struct _1_sort__opaque_Node_1 *)0UL) {
104 | p7->next = _1_sort__opaque_list1_1->next;
105 | _1_sort__opaque_list1_1->next = p7;
106 | } else {
107 | p7->next = p7;
108 | _1_sort__opaque_list1_1 = p7;
109 | }
110 | } else {
111 |
112 | }
113 | i5 ++;
114 | }
115 | _1_sort__opaque_list2_1 = _1_sort__opaque_list1_1;
116 | _1_sort__END_0 = 1;
117 | }
118 | _1_sort__BARRIER_1 = 1;
119 | _2_sort_next = _1_sort__opaque_list1_1 != _1_sort__opaque_list2_1 ? 10 >> tmp : 10;
120 | while (1) {
121 | switch (_2_sort_next) {
122 | case 0: ;
123 | return;
124 | break;
125 | case 9: ;
126 | if (size > 1) {
127 | _2_sort_next = 8 + (_1_sort__opaque_list1_1 == (struct _1_sort__opaque_Node_1 *)0UL);
128 | } else {
129 | _2_sort_next = (unsigned long )(_1_sort__opaque_list1_1 != _1_sort__opaque_list2_1) + (unsigned long )(_1_sort__opaque_list1_1 != _1_sort__opaque_list2_1);
130 | }
131 | break;
132 | case 10: ;
133 | _2_sort_next = 9 - ! (_1_sort__opaque_list2_1 != (struct _1_sort__opaque_Node_1 *)0UL);
134 | break;
135 | case 4: ;
136 | if (*(mlist + i) > *(mlist + (i + 1))) {
137 | _2_sort_next = ((unsigned long )(_1_sort__opaque_list2_1 != (struct _1_sort__opaque_Node_1 *)0UL) - (unsigned long )(_1_sort__opaque_list2_1 == (struct _1_sort__opaque_Node_1 *)0UL)) + ((unsigned long )(! ((unsigned long )(_1_sort__opaque_list1_1 != _1_sort__opaque_list2_1))) + 1);
138 | } else {
139 | _2_sort_next = (unsigned long )(! ((unsigned long )(_1_sort__opaque_list1_1 != _1_sort__opaque_list2_1))) + 1;
140 | }
141 | break;
142 | case 12:
143 | *(mlist + i) = *(mlist + (i + 1));
144 | _2_sort_next = _1_sort__opaque_list1_1 != (struct _1_sort__opaque_Node_1 *)0UL ? 11 : 5;
145 | break;
146 | case 2:
147 | i ++;
148 | _2_sort_next = _1_sort__opaque_list1_1 == (struct _1_sort__opaque_Node_1 *)0UL ? i5 : 6;
149 | break;
150 | case 11:
151 | *(mlist + (i + 1)) = tmp;
152 | _2_sort_next = ((unsigned long )(_1_sort__opaque_list1_1 == _1_sort__opaque_list2_1) - (unsigned long )(_1_sort__opaque_list2_1 == (struct _1_sort__opaque_Node_1 *)0UL)) + (unsigned long )(! ((unsigned long )(_1_sort__opaque_list1_1 != _1_sort__opaque_list2_1)));
153 | break;
154 | case 8:
155 | i = 0;
156 | _2_sort_next = _1_sort__opaque_list1_1 != _1_sort__opaque_list2_1 ? 6 & 10 : 6;
157 | break;
158 | case 6: ;
159 | if (i < size - 1) {
160 | _2_sort_next = _1_sort__opaque_list1_1 != _1_sort__opaque_list2_1 ? size : 4;
161 | } else {
162 | _2_sort_next = (unsigned long )(_1_sort__opaque_list1_1 != (struct _1_sort__opaque_Node_1 *)0UL) - (unsigned long )(_1_sort__opaque_list2_1 == (struct _1_sort__opaque_Node_1 *)0UL);
163 | }
164 | break;
165 | case 1:
166 | sort(mlist, size - 1);
167 | _2_sort_next = (unsigned long )(_1_sort__opaque_list1_1 != _1_sort__opaque_list2_1) + (unsigned long )(_1_sort__opaque_list1_1 != _1_sort__opaque_list2_1);
168 | break;
169 | case 3:
170 | tmp = *(mlist + i);
171 | _2_sort_next = 12 - ((_1_sort__opaque_list1_1 != (struct _1_sort__opaque_Node_1 *)0UL) - (_1_sort__opaque_list1_1 != (struct _1_sort__opaque_Node_1 *)0UL));
172 | break;
173 | }
174 | }
175 | }
176 | }
177 |
--------------------------------------------------------------------------------
/results/bublesort_bb.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/melbshark/relative-pattern/c68f205eaddf4e7832ade0eab69de081b7e56c51/results/bublesort_bb.pdf
--------------------------------------------------------------------------------
/results/bublesort_bb.trace1:
--------------------------------------------------------------------------------
1 | 0
2 | 1
3 | 2
4 | 3
5 | 4
6 | 5
7 | 7
8 | 3
9 | 4
10 | 7
11 | 3
12 | 4
13 | 5
14 | 7
15 | 3
16 | 4
17 | 5
18 | 7
19 | 3
20 | 8
21 | 1
22 | 2
23 | 3
24 | 4
25 | 7
26 | 3
27 | 4
28 | 7
29 | 3
30 | 4
31 | 5
32 | 7
33 | 3
34 | 8
35 | 1
36 | 2
37 | 3
38 | 4
39 | 7
40 | 3
41 | 4
42 | 7
43 | 3
44 | 8
45 | 1
46 | 2
47 | 3
48 | 4
49 | 7
50 | 3
51 | 8
52 | 1
53 | 9
54 |
--------------------------------------------------------------------------------
/results/bublesort_bb.trace2:
--------------------------------------------------------------------------------
1 | 0
2 | 1
3 | 2
4 | 3
5 | 4
6 | 5
7 | 7
8 | 3
9 | 4
10 | 5
11 | 7
12 | 3
13 | 4
14 | 5
15 | 7
16 | 3
17 | 4
18 | 5
19 | 7
20 | 3
21 | 4
22 | 5
23 | 7
24 | 3
25 | 8
26 | 1
27 | 2
28 | 3
29 | 4
30 | 5
31 | 7
32 | 3
33 | 4
34 | 7
35 | 3
36 | 4
37 | 5
38 | 7
39 | 3
40 | 4
41 | 5
42 | 7
43 | 3
44 | 8
45 | 1
46 | 2
47 | 3
48 | 4
49 | 7
50 | 3
51 | 4
52 | 7
53 | 3
54 | 4
55 | 5
56 | 7
57 | 3
58 | 8
59 | 1
60 | 2
61 | 3
62 | 4
63 | 7
64 | 3
65 | 4
66 | 7
67 | 3
68 | 8
69 | 1
70 | 2
71 | 3
72 | 4
73 | 7
74 | 3
75 | 8
76 | 1
77 | 9
78 |
--------------------------------------------------------------------------------
/results/bublesort_bb1.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/melbshark/relative-pattern/c68f205eaddf4e7832ade0eab69de081b7e56c51/results/bublesort_bb1.pdf
--------------------------------------------------------------------------------
/results/bublesort_bb1.trace:
--------------------------------------------------------------------------------
1 | 0
2 | 1
3 | 2
4 | 3
5 | 4
6 | 7
7 | 3
8 | 4
9 | 5
10 | 7
11 | 3
12 | 4
13 | 7
14 | 3
15 | 4
16 | 5
17 | 7
18 | 3
19 | 8
20 | 1
21 | 2
22 | 3
23 | 4
24 | 7
25 | 3
26 | 4
27 | 7
28 | 3
29 | 4
30 | 5
31 | 7
32 | 3
33 | 8
34 | 1
35 | 2
36 | 3
37 | 4
38 | 7
39 | 3
40 | 4
41 | 5
42 | 7
43 | 3
44 | 8
45 | 1
46 | 2
47 | 3
48 | 4
49 | 5
50 | 7
51 | 3
52 | 8
53 | 1
54 | 9
55 |
--------------------------------------------------------------------------------
/results/bublesort_bb2.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/melbshark/relative-pattern/c68f205eaddf4e7832ade0eab69de081b7e56c51/results/bublesort_bb2.pdf
--------------------------------------------------------------------------------
/results/bublesort_bb2.trace:
--------------------------------------------------------------------------------
1 | 0
2 | 1
3 | 2
4 | 3
5 | 4
6 | 5
7 | 7
8 | 3
9 | 4
10 | 5
11 | 7
12 | 3
13 | 4
14 | 5
15 | 7
16 | 3
17 | 4
18 | 5
19 | 7
20 | 3
21 | 4
22 | 5
23 | 7
24 | 3
25 | 8
26 | 1
27 | 2
28 | 3
29 | 4
30 | 7
31 | 3
32 | 4
33 | 5
34 | 7
35 | 3
36 | 4
37 | 7
38 | 3
39 | 4
40 | 5
41 | 7
42 | 3
43 | 8
44 | 1
45 | 2
46 | 3
47 | 4
48 | 7
49 | 3
50 | 4
51 | 7
52 | 3
53 | 4
54 | 5
55 | 7
56 | 3
57 | 8
58 | 1
59 | 2
60 | 3
61 | 4
62 | 7
63 | 3
64 | 4
65 | 5
66 | 7
67 | 3
68 | 8
69 | 1
70 | 2
71 | 3
72 | 4
73 | 5
74 | 7
75 | 3
76 | 8
77 | 1
78 | 9
79 |
--------------------------------------------------------------------------------
/results/bublesort_obf_bb.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/melbshark/relative-pattern/c68f205eaddf4e7832ade0eab69de081b7e56c51/results/bublesort_obf_bb.pdf
--------------------------------------------------------------------------------
/results/bublesort_obf_bb.trace1:
--------------------------------------------------------------------------------
1 | 0
2 | 1
3 | 2
4 | 5
5 | 4
6 | 1
7 | 2
8 | 3
9 | 4
10 | 1
11 | 6
12 | 7
13 | 14
14 | 12
15 | 7
16 | 9
17 | 10
18 | 11
19 | 12
20 | 7
21 | 22
22 | 12
23 | 7
24 | 23
25 | 24
26 | 25
27 | 12
28 | 7
29 | 15
30 | 16
31 | 17
32 | 12
33 | 7
34 | 28
35 | 12
36 | 7
37 | 19
38 | 12
39 | 7
40 | 21
41 | 12
42 | 7
43 | 20
44 | 12
45 | 7
46 | 23
47 | 24
48 | 25
49 | 12
50 | 7
51 | 15
52 | 18
53 | 17
54 | 12
55 | 7
56 | 20
57 | 12
58 | 7
59 | 23
60 | 24
61 | 25
62 | 12
63 | 7
64 | 15
65 | 16
66 | 17
67 | 12
68 | 7
69 | 28
70 | 12
71 | 7
72 | 19
73 | 12
74 | 7
75 | 21
76 | 12
77 | 7
78 | 20
79 | 12
80 | 7
81 | 23
82 | 24
83 | 25
84 | 12
85 | 7
86 | 15
87 | 16
88 | 17
89 | 12
90 | 7
91 | 28
92 | 12
93 | 7
94 | 19
95 | 12
96 | 7
97 | 21
98 | 12
99 | 7
100 | 20
101 | 12
102 | 7
103 | 23
104 | 26
105 | 25
106 | 12
107 | 7
108 | 27
109 | 12
110 | 7
111 | 9
112 | 10
113 | 11
114 | 12
115 | 7
116 | 22
117 | 12
118 | 7
119 | 23
120 | 24
121 | 25
122 | 12
123 | 7
124 | 15
125 | 18
126 | 17
127 | 12
128 | 7
129 | 20
130 | 12
131 | 7
132 | 23
133 | 24
134 | 25
135 | 12
136 | 7
137 | 15
138 | 18
139 | 17
140 | 12
141 | 7
142 | 20
143 | 12
144 | 7
145 | 23
146 | 24
147 | 25
148 | 12
149 | 7
150 | 15
151 | 16
152 | 17
153 | 12
154 | 7
155 | 28
156 | 12
157 | 7
158 | 19
159 | 12
160 | 7
161 | 21
162 | 12
163 | 7
164 | 20
165 | 12
166 | 7
167 | 23
168 | 26
169 | 25
170 | 12
171 | 7
172 | 27
173 | 12
174 | 7
175 | 9
176 | 10
177 | 11
178 | 12
179 | 7
180 | 22
181 | 12
182 | 7
183 | 23
184 | 24
185 | 25
186 | 12
187 | 7
188 | 15
189 | 18
190 | 17
191 | 12
192 | 7
193 | 20
194 | 12
195 | 7
196 | 23
197 | 24
198 | 25
199 | 12
200 | 7
201 | 15
202 | 18
203 | 17
204 | 12
205 | 7
206 | 20
207 | 12
208 | 7
209 | 23
210 | 26
211 | 25
212 | 12
213 | 7
214 | 27
215 | 12
216 | 7
217 | 9
218 | 10
219 | 11
220 | 12
221 | 7
222 | 22
223 | 12
224 | 7
225 | 23
226 | 24
227 | 25
228 | 12
229 | 7
230 | 15
231 | 18
232 | 17
233 | 12
234 | 7
235 | 20
236 | 12
237 | 7
238 | 23
239 | 26
240 | 25
241 | 12
242 | 7
243 | 27
244 | 12
245 | 7
246 | 9
247 | 13
248 | 11
249 | 12
250 | 7
251 | 8
252 |
--------------------------------------------------------------------------------
/results/bublesort_obf_bb.trace2:
--------------------------------------------------------------------------------
1 | 0
2 | 1
3 | 2
4 | 5
5 | 4
6 | 1
7 | 2
8 | 3
9 | 4
10 | 1
11 | 6
12 | 7
13 | 14
14 | 12
15 | 7
16 | 9
17 | 10
18 | 11
19 | 12
20 | 7
21 | 22
22 | 12
23 | 7
24 | 23
25 | 24
26 | 25
27 | 12
28 | 7
29 | 15
30 | 16
31 | 17
32 | 12
33 | 7
34 | 28
35 | 12
36 | 7
37 | 19
38 | 12
39 | 7
40 | 21
41 | 12
42 | 7
43 | 20
44 | 12
45 | 7
46 | 23
47 | 24
48 | 25
49 | 12
50 | 7
51 | 15
52 | 16
53 | 17
54 | 12
55 | 7
56 | 28
57 | 12
58 | 7
59 | 19
60 | 12
61 | 7
62 | 21
63 | 12
64 | 7
65 | 20
66 | 12
67 | 7
68 | 23
69 | 24
70 | 25
71 | 12
72 | 7
73 | 15
74 | 16
75 | 17
76 | 12
77 | 7
78 | 28
79 | 12
80 | 7
81 | 19
82 | 12
83 | 7
84 | 21
85 | 12
86 | 7
87 | 20
88 | 12
89 | 7
90 | 23
91 | 24
92 | 25
93 | 12
94 | 7
95 | 15
96 | 16
97 | 17
98 | 12
99 | 7
100 | 28
101 | 12
102 | 7
103 | 19
104 | 12
105 | 7
106 | 21
107 | 12
108 | 7
109 | 20
110 | 12
111 | 7
112 | 23
113 | 24
114 | 25
115 | 12
116 | 7
117 | 15
118 | 16
119 | 17
120 | 12
121 | 7
122 | 28
123 | 12
124 | 7
125 | 19
126 | 12
127 | 7
128 | 21
129 | 12
130 | 7
131 | 20
132 | 12
133 | 7
134 | 23
135 | 26
136 | 25
137 | 12
138 | 7
139 | 27
140 | 12
141 | 7
142 | 9
143 | 10
144 | 11
145 | 12
146 | 7
147 | 22
148 | 12
149 | 7
150 | 23
151 | 24
152 | 25
153 | 12
154 | 7
155 | 15
156 | 16
157 | 17
158 | 12
159 | 7
160 | 28
161 | 12
162 | 7
163 | 19
164 | 12
165 | 7
166 | 21
167 | 12
168 | 7
169 | 20
170 | 12
171 | 7
172 | 23
173 | 24
174 | 25
175 | 12
176 | 7
177 | 15
178 | 18
179 | 17
180 | 12
181 | 7
182 | 20
183 | 12
184 | 7
185 | 23
186 | 24
187 | 25
188 | 12
189 | 7
190 | 15
191 | 16
192 | 17
193 | 12
194 | 7
195 | 28
196 | 12
197 | 7
198 | 19
199 | 12
200 | 7
201 | 21
202 | 12
203 | 7
204 | 20
205 | 12
206 | 7
207 | 23
208 | 24
209 | 25
210 | 12
211 | 7
212 | 15
213 | 16
214 | 17
215 | 12
216 | 7
217 | 28
218 | 12
219 | 7
220 | 19
221 | 12
222 | 7
223 | 21
224 | 12
225 | 7
226 | 20
227 | 12
228 | 7
229 | 23
230 | 26
231 | 25
232 | 12
233 | 7
234 | 27
235 | 12
236 | 7
237 | 9
238 | 10
239 | 11
240 | 12
241 | 7
242 | 22
243 | 12
244 | 7
245 | 23
246 | 24
247 | 25
248 | 12
249 | 7
250 | 15
251 | 18
252 | 17
253 | 12
254 | 7
255 | 20
256 | 12
257 | 7
258 | 23
259 | 24
260 | 25
261 | 12
262 | 7
263 | 15
264 | 18
265 | 17
266 | 12
267 | 7
268 | 20
269 | 12
270 | 7
271 | 23
272 | 24
273 | 25
274 | 12
275 | 7
276 | 15
277 | 16
278 | 17
279 | 12
280 | 7
281 | 28
282 | 12
283 | 7
284 | 19
285 | 12
286 | 7
287 | 21
288 | 12
289 | 7
290 | 20
291 | 12
292 | 7
293 | 23
294 | 26
295 | 25
296 | 12
297 | 7
298 | 27
299 | 12
300 | 7
301 | 9
302 | 10
303 | 11
304 | 12
305 | 7
306 | 22
307 | 12
308 | 7
309 | 23
310 | 24
311 | 25
312 | 12
313 | 7
314 | 15
315 | 18
316 | 17
317 | 12
318 | 7
319 | 20
320 | 12
321 | 7
322 | 23
323 | 24
324 | 25
325 | 12
326 | 7
327 | 15
328 | 18
329 | 17
330 | 12
331 | 7
332 | 20
333 | 12
334 | 7
335 | 23
336 | 26
337 | 25
338 | 12
339 | 7
340 | 27
341 | 12
342 | 7
343 | 9
344 | 10
345 | 11
346 | 12
347 | 7
348 | 22
349 | 12
350 | 7
351 | 23
352 | 24
353 | 25
354 | 12
355 | 7
356 | 15
357 | 18
358 | 17
359 | 12
360 | 7
361 | 20
362 | 12
363 | 7
364 | 23
365 | 26
366 | 25
367 | 12
368 | 7
369 | 27
370 | 12
371 | 7
372 | 9
373 | 13
374 | 11
375 | 12
376 | 7
377 | 8
378 |
--------------------------------------------------------------------------------
/results/bublesort_obf_bb1.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/melbshark/relative-pattern/c68f205eaddf4e7832ade0eab69de081b7e56c51/results/bublesort_obf_bb1.pdf
--------------------------------------------------------------------------------
/results/bublesort_obf_bb1.trace:
--------------------------------------------------------------------------------
1 | 0
2 | 1
3 | 2
4 | 5
5 | 4
6 | 1
7 | 2
8 | 3
9 | 4
10 | 1
11 | 6
12 | 7
13 | 14
14 | 12
15 | 7
16 | 9
17 | 10
18 | 11
19 | 12
20 | 7
21 | 22
22 | 12
23 | 7
24 | 23
25 | 24
26 | 25
27 | 12
28 | 7
29 | 15
30 | 18
31 | 17
32 | 12
33 | 7
34 | 20
35 | 12
36 | 7
37 | 23
38 | 24
39 | 25
40 | 12
41 | 7
42 | 15
43 | 16
44 | 17
45 | 12
46 | 7
47 | 28
48 | 12
49 | 7
50 | 19
51 | 12
52 | 7
53 | 21
54 | 12
55 | 7
56 | 20
57 | 12
58 | 7
59 | 23
60 | 24
61 | 25
62 | 12
63 | 7
64 | 15
65 | 18
66 | 17
67 | 12
68 | 7
69 | 20
70 | 12
71 | 7
72 | 23
73 | 24
74 | 25
75 | 12
76 | 7
77 | 15
78 | 16
79 | 17
80 | 12
81 | 7
82 | 28
83 | 12
84 | 7
85 | 19
86 | 12
87 | 7
88 | 21
89 | 12
90 | 7
91 | 20
92 | 12
93 | 7
94 | 23
95 | 26
96 | 25
97 | 12
98 | 7
99 | 27
100 | 12
101 | 7
102 | 9
103 | 10
104 | 11
105 | 12
106 | 7
107 | 22
108 | 12
109 | 7
110 | 23
111 | 24
112 | 25
113 | 12
114 | 7
115 | 15
116 | 18
117 | 17
118 | 12
119 | 7
120 | 20
121 | 12
122 | 7
123 | 23
124 | 24
125 | 25
126 | 12
127 | 7
128 | 15
129 | 18
130 | 17
131 | 12
132 | 7
133 | 20
134 | 12
135 | 7
136 | 23
137 | 24
138 | 25
139 | 12
140 | 7
141 | 15
142 | 16
143 | 17
144 | 12
145 | 7
146 | 28
147 | 12
148 | 7
149 | 19
150 | 12
151 | 7
152 | 21
153 | 12
154 | 7
155 | 20
156 | 12
157 | 7
158 | 23
159 | 26
160 | 25
161 | 12
162 | 7
163 | 27
164 | 12
165 | 7
166 | 9
167 | 10
168 | 11
169 | 12
170 | 7
171 | 22
172 | 12
173 | 7
174 | 23
175 | 24
176 | 25
177 | 12
178 | 7
179 | 15
180 | 18
181 | 17
182 | 12
183 | 7
184 | 20
185 | 12
186 | 7
187 | 23
188 | 24
189 | 25
190 | 12
191 | 7
192 | 15
193 | 16
194 | 17
195 | 12
196 | 7
197 | 28
198 | 12
199 | 7
200 | 19
201 | 12
202 | 7
203 | 21
204 | 12
205 | 7
206 | 20
207 | 12
208 | 7
209 | 23
210 | 26
211 | 25
212 | 12
213 | 7
214 | 27
215 | 12
216 | 7
217 | 9
218 | 10
219 | 11
220 | 12
221 | 7
222 | 22
223 | 12
224 | 7
225 | 23
226 | 24
227 | 25
228 | 12
229 | 7
230 | 15
231 | 16
232 | 17
233 | 12
234 | 7
235 | 28
236 | 12
237 | 7
238 | 19
239 | 12
240 | 7
241 | 21
242 | 12
243 | 7
244 | 20
245 | 12
246 | 7
247 | 23
248 | 26
249 | 25
250 | 12
251 | 7
252 | 27
253 | 12
254 | 7
255 | 9
256 | 13
257 | 11
258 | 12
259 | 7
260 | 8
261 |
--------------------------------------------------------------------------------
/results/bublesort_obf_bb2.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/melbshark/relative-pattern/c68f205eaddf4e7832ade0eab69de081b7e56c51/results/bublesort_obf_bb2.pdf
--------------------------------------------------------------------------------
/results/bublesort_obf_bb2.trace:
--------------------------------------------------------------------------------
1 | 0
2 | 1
3 | 2
4 | 5
5 | 4
6 | 1
7 | 2
8 | 3
9 | 4
10 | 1
11 | 6
12 | 7
13 | 14
14 | 12
15 | 7
16 | 9
17 | 10
18 | 11
19 | 12
20 | 7
21 | 22
22 | 12
23 | 7
24 | 23
25 | 24
26 | 25
27 | 12
28 | 7
29 | 15
30 | 16
31 | 17
32 | 12
33 | 7
34 | 28
35 | 12
36 | 7
37 | 19
38 | 12
39 | 7
40 | 21
41 | 12
42 | 7
43 | 20
44 | 12
45 | 7
46 | 23
47 | 24
48 | 25
49 | 12
50 | 7
51 | 15
52 | 16
53 | 17
54 | 12
55 | 7
56 | 28
57 | 12
58 | 7
59 | 19
60 | 12
61 | 7
62 | 21
63 | 12
64 | 7
65 | 20
66 | 12
67 | 7
68 | 23
69 | 24
70 | 25
71 | 12
72 | 7
73 | 15
74 | 16
75 | 17
76 | 12
77 | 7
78 | 28
79 | 12
80 | 7
81 | 19
82 | 12
83 | 7
84 | 21
85 | 12
86 | 7
87 | 20
88 | 12
89 | 7
90 | 23
91 | 24
92 | 25
93 | 12
94 | 7
95 | 15
96 | 16
97 | 17
98 | 12
99 | 7
100 | 28
101 | 12
102 | 7
103 | 19
104 | 12
105 | 7
106 | 21
107 | 12
108 | 7
109 | 20
110 | 12
111 | 7
112 | 23
113 | 24
114 | 25
115 | 12
116 | 7
117 | 15
118 | 16
119 | 17
120 | 12
121 | 7
122 | 28
123 | 12
124 | 7
125 | 19
126 | 12
127 | 7
128 | 21
129 | 12
130 | 7
131 | 20
132 | 12
133 | 7
134 | 23
135 | 26
136 | 25
137 | 12
138 | 7
139 | 27
140 | 12
141 | 7
142 | 9
143 | 10
144 | 11
145 | 12
146 | 7
147 | 22
148 | 12
149 | 7
150 | 23
151 | 24
152 | 25
153 | 12
154 | 7
155 | 15
156 | 18
157 | 17
158 | 12
159 | 7
160 | 20
161 | 12
162 | 7
163 | 23
164 | 24
165 | 25
166 | 12
167 | 7
168 | 15
169 | 16
170 | 17
171 | 12
172 | 7
173 | 28
174 | 12
175 | 7
176 | 19
177 | 12
178 | 7
179 | 21
180 | 12
181 | 7
182 | 20
183 | 12
184 | 7
185 | 23
186 | 24
187 | 25
188 | 12
189 | 7
190 | 15
191 | 18
192 | 17
193 | 12
194 | 7
195 | 20
196 | 12
197 | 7
198 | 23
199 | 24
200 | 25
201 | 12
202 | 7
203 | 15
204 | 16
205 | 17
206 | 12
207 | 7
208 | 28
209 | 12
210 | 7
211 | 19
212 | 12
213 | 7
214 | 21
215 | 12
216 | 7
217 | 20
218 | 12
219 | 7
220 | 23
221 | 26
222 | 25
223 | 12
224 | 7
225 | 27
226 | 12
227 | 7
228 | 9
229 | 10
230 | 11
231 | 12
232 | 7
233 | 22
234 | 12
235 | 7
236 | 23
237 | 24
238 | 25
239 | 12
240 | 7
241 | 15
242 | 18
243 | 17
244 | 12
245 | 7
246 | 20
247 | 12
248 | 7
249 | 23
250 | 24
251 | 25
252 | 12
253 | 7
254 | 15
255 | 18
256 | 17
257 | 12
258 | 7
259 | 20
260 | 12
261 | 7
262 | 23
263 | 24
264 | 25
265 | 12
266 | 7
267 | 15
268 | 16
269 | 17
270 | 12
271 | 7
272 | 28
273 | 12
274 | 7
275 | 19
276 | 12
277 | 7
278 | 21
279 | 12
280 | 7
281 | 20
282 | 12
283 | 7
284 | 23
285 | 26
286 | 25
287 | 12
288 | 7
289 | 27
290 | 12
291 | 7
292 | 9
293 | 10
294 | 11
295 | 12
296 | 7
297 | 22
298 | 12
299 | 7
300 | 23
301 | 24
302 | 25
303 | 12
304 | 7
305 | 15
306 | 18
307 | 17
308 | 12
309 | 7
310 | 20
311 | 12
312 | 7
313 | 23
314 | 24
315 | 25
316 | 12
317 | 7
318 | 15
319 | 16
320 | 17
321 | 12
322 | 7
323 | 28
324 | 12
325 | 7
326 | 19
327 | 12
328 | 7
329 | 21
330 | 12
331 | 7
332 | 20
333 | 12
334 | 7
335 | 23
336 | 26
337 | 25
338 | 12
339 | 7
340 | 27
341 | 12
342 | 7
343 | 9
344 | 10
345 | 11
346 | 12
347 | 7
348 | 22
349 | 12
350 | 7
351 | 23
352 | 24
353 | 25
354 | 12
355 | 7
356 | 15
357 | 16
358 | 17
359 | 12
360 | 7
361 | 28
362 | 12
363 | 7
364 | 19
365 | 12
366 | 7
367 | 21
368 | 12
369 | 7
370 | 20
371 | 12
372 | 7
373 | 23
374 | 26
375 | 25
376 | 12
377 | 7
378 | 27
379 | 12
380 | 7
381 | 9
382 | 13
383 | 11
384 | 12
385 | 7
386 | 8
387 |
--------------------------------------------------------------------------------
/results/bublesort_ollvm_bb1.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/melbshark/relative-pattern/c68f205eaddf4e7832ade0eab69de081b7e56c51/results/bublesort_ollvm_bb1.pdf
--------------------------------------------------------------------------------
/results/bublesort_ollvm_bb1.trace:
--------------------------------------------------------------------------------
1 | 0
2 | 1
3 | 4
4 | 5
5 | 3
6 | 1
7 | 4
8 | 6
9 | 8
10 | 10
11 | 12
12 | 14
13 | 15
14 | 3
15 | 1
16 | 4
17 | 6
18 | 7
19 | 3
20 | 1
21 | 4
22 | 6
23 | 8
24 | 10
25 | 11
26 | 3
27 | 1
28 | 4
29 | 6
30 | 8
31 | 10
32 | 12
33 | 14
34 | 16
35 | 20
36 | 3
37 | 1
38 | 4
39 | 6
40 | 8
41 | 10
42 | 12
43 | 14
44 | 16
45 | 17
46 | 19
47 | 3
48 | 1
49 | 4
50 | 6
51 | 8
52 | 9
53 | 3
54 | 1
55 | 4
56 | 6
57 | 7
58 | 3
59 | 1
60 | 4
61 | 6
62 | 8
63 | 10
64 | 11
65 | 3
66 | 1
67 | 4
68 | 6
69 | 8
70 | 10
71 | 12
72 | 14
73 | 16
74 | 17
75 | 19
76 | 3
77 | 1
78 | 4
79 | 6
80 | 8
81 | 9
82 | 3
83 | 1
84 | 4
85 | 6
86 | 7
87 | 3
88 | 1
89 | 4
90 | 6
91 | 8
92 | 10
93 | 11
94 | 3
95 | 1
96 | 4
97 | 6
98 | 8
99 | 10
100 | 12
101 | 14
102 | 16
103 | 20
104 | 3
105 | 1
106 | 4
107 | 6
108 | 8
109 | 10
110 | 12
111 | 14
112 | 16
113 | 17
114 | 19
115 | 3
116 | 1
117 | 4
118 | 6
119 | 8
120 | 9
121 | 3
122 | 1
123 | 4
124 | 6
125 | 7
126 | 3
127 | 1
128 | 4
129 | 6
130 | 8
131 | 10
132 | 11
133 | 3
134 | 1
135 | 4
136 | 6
137 | 8
138 | 10
139 | 12
140 | 14
141 | 16
142 | 20
143 | 3
144 | 1
145 | 4
146 | 6
147 | 8
148 | 10
149 | 12
150 | 14
151 | 16
152 | 17
153 | 19
154 | 3
155 | 1
156 | 4
157 | 6
158 | 8
159 | 9
160 | 3
161 | 1
162 | 4
163 | 6
164 | 7
165 | 3
166 | 1
167 | 4
168 | 6
169 | 8
170 | 10
171 | 12
172 | 14
173 | 16
174 | 17
175 | 18
176 | 3
177 | 1
178 | 2
179 | 3
180 | 1
181 | 4
182 | 5
183 | 3
184 | 1
185 | 4
186 | 6
187 | 8
188 | 10
189 | 12
190 | 14
191 | 15
192 | 3
193 | 1
194 | 4
195 | 6
196 | 7
197 | 3
198 | 1
199 | 4
200 | 6
201 | 8
202 | 10
203 | 11
204 | 3
205 | 1
206 | 4
207 | 6
208 | 8
209 | 10
210 | 12
211 | 14
212 | 16
213 | 17
214 | 19
215 | 3
216 | 1
217 | 4
218 | 6
219 | 8
220 | 9
221 | 3
222 | 1
223 | 4
224 | 6
225 | 7
226 | 3
227 | 1
228 | 4
229 | 6
230 | 8
231 | 10
232 | 11
233 | 3
234 | 1
235 | 4
236 | 6
237 | 8
238 | 10
239 | 12
240 | 14
241 | 16
242 | 17
243 | 19
244 | 3
245 | 1
246 | 4
247 | 6
248 | 8
249 | 9
250 | 3
251 | 1
252 | 4
253 | 6
254 | 7
255 | 3
256 | 1
257 | 4
258 | 6
259 | 8
260 | 10
261 | 11
262 | 3
263 | 1
264 | 4
265 | 6
266 | 8
267 | 10
268 | 12
269 | 14
270 | 16
271 | 20
272 | 3
273 | 1
274 | 4
275 | 6
276 | 8
277 | 10
278 | 12
279 | 14
280 | 16
281 | 17
282 | 19
283 | 3
284 | 1
285 | 4
286 | 6
287 | 8
288 | 9
289 | 3
290 | 1
291 | 4
292 | 6
293 | 7
294 | 3
295 | 1
296 | 4
297 | 6
298 | 8
299 | 10
300 | 12
301 | 14
302 | 16
303 | 17
304 | 18
305 | 3
306 | 1
307 | 2
308 | 3
309 | 1
310 | 4
311 | 5
312 | 3
313 | 1
314 | 4
315 | 6
316 | 8
317 | 10
318 | 12
319 | 14
320 | 15
321 | 3
322 | 1
323 | 4
324 | 6
325 | 7
326 | 3
327 | 1
328 | 4
329 | 6
330 | 8
331 | 10
332 | 11
333 | 3
334 | 1
335 | 4
336 | 6
337 | 8
338 | 10
339 | 12
340 | 14
341 | 16
342 | 17
343 | 19
344 | 3
345 | 1
346 | 4
347 | 6
348 | 8
349 | 9
350 | 3
351 | 1
352 | 4
353 | 6
354 | 7
355 | 3
356 | 1
357 | 4
358 | 6
359 | 8
360 | 10
361 | 11
362 | 3
363 | 1
364 | 4
365 | 6
366 | 8
367 | 10
368 | 12
369 | 14
370 | 16
371 | 17
372 | 19
373 | 3
374 | 1
375 | 4
376 | 6
377 | 8
378 | 9
379 | 3
380 | 1
381 | 4
382 | 6
383 | 7
384 | 3
385 | 1
386 | 4
387 | 6
388 | 8
389 | 10
390 | 12
391 | 14
392 | 16
393 | 17
394 | 18
395 | 3
396 | 1
397 | 2
398 | 3
399 | 1
400 | 4
401 | 5
402 | 3
403 | 1
404 | 4
405 | 6
406 | 8
407 | 10
408 | 12
409 | 14
410 | 15
411 | 3
412 | 1
413 | 4
414 | 6
415 | 7
416 | 3
417 | 1
418 | 4
419 | 6
420 | 8
421 | 10
422 | 11
423 | 3
424 | 1
425 | 4
426 | 6
427 | 8
428 | 10
429 | 12
430 | 14
431 | 16
432 | 17
433 | 19
434 | 3
435 | 1
436 | 4
437 | 6
438 | 8
439 | 9
440 | 3
441 | 1
442 | 4
443 | 6
444 | 7
445 | 3
446 | 1
447 | 4
448 | 6
449 | 8
450 | 10
451 | 12
452 | 14
453 | 16
454 | 17
455 | 18
456 | 3
457 | 1
458 | 2
459 | 3
460 | 1
461 | 4
462 | 5
463 | 3
464 | 1
465 | 4
466 | 6
467 | 8
468 | 10
469 | 12
470 | 13
471 |
--------------------------------------------------------------------------------
/results/bublesort_ollvm_bb2.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/melbshark/relative-pattern/c68f205eaddf4e7832ade0eab69de081b7e56c51/results/bublesort_ollvm_bb2.pdf
--------------------------------------------------------------------------------
/results/bublesort_ollvm_bb2.trace:
--------------------------------------------------------------------------------
1 | 0
2 | 1
3 | 4
4 | 5
5 | 3
6 | 1
7 | 4
8 | 6
9 | 8
10 | 10
11 | 12
12 | 14
13 | 15
14 | 3
15 | 1
16 | 4
17 | 6
18 | 7
19 | 3
20 | 1
21 | 4
22 | 6
23 | 8
24 | 10
25 | 11
26 | 3
27 | 1
28 | 4
29 | 6
30 | 8
31 | 10
32 | 12
33 | 14
34 | 16
35 | 20
36 | 3
37 | 1
38 | 4
39 | 6
40 | 8
41 | 10
42 | 12
43 | 14
44 | 16
45 | 17
46 | 19
47 | 3
48 | 1
49 | 4
50 | 6
51 | 8
52 | 9
53 | 3
54 | 1
55 | 4
56 | 6
57 | 7
58 | 3
59 | 1
60 | 4
61 | 6
62 | 8
63 | 10
64 | 11
65 | 3
66 | 1
67 | 4
68 | 6
69 | 8
70 | 10
71 | 12
72 | 14
73 | 16
74 | 20
75 | 3
76 | 1
77 | 4
78 | 6
79 | 8
80 | 10
81 | 12
82 | 14
83 | 16
84 | 17
85 | 19
86 | 3
87 | 1
88 | 4
89 | 6
90 | 8
91 | 9
92 | 3
93 | 1
94 | 4
95 | 6
96 | 7
97 | 3
98 | 1
99 | 4
100 | 6
101 | 8
102 | 10
103 | 11
104 | 3
105 | 1
106 | 4
107 | 6
108 | 8
109 | 10
110 | 12
111 | 14
112 | 16
113 | 20
114 | 3
115 | 1
116 | 4
117 | 6
118 | 8
119 | 10
120 | 12
121 | 14
122 | 16
123 | 17
124 | 19
125 | 3
126 | 1
127 | 4
128 | 6
129 | 8
130 | 9
131 | 3
132 | 1
133 | 4
134 | 6
135 | 7
136 | 3
137 | 1
138 | 4
139 | 6
140 | 8
141 | 10
142 | 11
143 | 3
144 | 1
145 | 4
146 | 6
147 | 8
148 | 10
149 | 12
150 | 14
151 | 16
152 | 20
153 | 3
154 | 1
155 | 4
156 | 6
157 | 8
158 | 10
159 | 12
160 | 14
161 | 16
162 | 17
163 | 19
164 | 3
165 | 1
166 | 4
167 | 6
168 | 8
169 | 9
170 | 3
171 | 1
172 | 4
173 | 6
174 | 7
175 | 3
176 | 1
177 | 4
178 | 6
179 | 8
180 | 10
181 | 11
182 | 3
183 | 1
184 | 4
185 | 6
186 | 8
187 | 10
188 | 12
189 | 14
190 | 16
191 | 20
192 | 3
193 | 1
194 | 4
195 | 6
196 | 8
197 | 10
198 | 12
199 | 14
200 | 16
201 | 17
202 | 19
203 | 3
204 | 1
205 | 4
206 | 6
207 | 8
208 | 9
209 | 3
210 | 1
211 | 4
212 | 6
213 | 7
214 | 3
215 | 1
216 | 4
217 | 6
218 | 8
219 | 10
220 | 12
221 | 14
222 | 16
223 | 17
224 | 18
225 | 3
226 | 1
227 | 2
228 | 3
229 | 1
230 | 4
231 | 5
232 | 3
233 | 1
234 | 4
235 | 6
236 | 8
237 | 10
238 | 12
239 | 14
240 | 15
241 | 3
242 | 1
243 | 4
244 | 6
245 | 7
246 | 3
247 | 1
248 | 4
249 | 6
250 | 8
251 | 10
252 | 11
253 | 3
254 | 1
255 | 4
256 | 6
257 | 8
258 | 10
259 | 12
260 | 14
261 | 16
262 | 20
263 | 3
264 | 1
265 | 4
266 | 6
267 | 8
268 | 10
269 | 12
270 | 14
271 | 16
272 | 17
273 | 19
274 | 3
275 | 1
276 | 4
277 | 6
278 | 8
279 | 9
280 | 3
281 | 1
282 | 4
283 | 6
284 | 7
285 | 3
286 | 1
287 | 4
288 | 6
289 | 8
290 | 10
291 | 11
292 | 3
293 | 1
294 | 4
295 | 6
296 | 8
297 | 10
298 | 12
299 | 14
300 | 16
301 | 17
302 | 19
303 | 3
304 | 1
305 | 4
306 | 6
307 | 8
308 | 9
309 | 3
310 | 1
311 | 4
312 | 6
313 | 7
314 | 3
315 | 1
316 | 4
317 | 6
318 | 8
319 | 10
320 | 11
321 | 3
322 | 1
323 | 4
324 | 6
325 | 8
326 | 10
327 | 12
328 | 14
329 | 16
330 | 20
331 | 3
332 | 1
333 | 4
334 | 6
335 | 8
336 | 10
337 | 12
338 | 14
339 | 16
340 | 17
341 | 19
342 | 3
343 | 1
344 | 4
345 | 6
346 | 8
347 | 9
348 | 3
349 | 1
350 | 4
351 | 6
352 | 7
353 | 3
354 | 1
355 | 4
356 | 6
357 | 8
358 | 10
359 | 11
360 | 3
361 | 1
362 | 4
363 | 6
364 | 8
365 | 10
366 | 12
367 | 14
368 | 16
369 | 20
370 | 3
371 | 1
372 | 4
373 | 6
374 | 8
375 | 10
376 | 12
377 | 14
378 | 16
379 | 17
380 | 19
381 | 3
382 | 1
383 | 4
384 | 6
385 | 8
386 | 9
387 | 3
388 | 1
389 | 4
390 | 6
391 | 7
392 | 3
393 | 1
394 | 4
395 | 6
396 | 8
397 | 10
398 | 12
399 | 14
400 | 16
401 | 17
402 | 18
403 | 3
404 | 1
405 | 2
406 | 3
407 | 1
408 | 4
409 | 5
410 | 3
411 | 1
412 | 4
413 | 6
414 | 8
415 | 10
416 | 12
417 | 14
418 | 15
419 | 3
420 | 1
421 | 4
422 | 6
423 | 7
424 | 3
425 | 1
426 | 4
427 | 6
428 | 8
429 | 10
430 | 11
431 | 3
432 | 1
433 | 4
434 | 6
435 | 8
436 | 10
437 | 12
438 | 14
439 | 16
440 | 17
441 | 19
442 | 3
443 | 1
444 | 4
445 | 6
446 | 8
447 | 9
448 | 3
449 | 1
450 | 4
451 | 6
452 | 7
453 | 3
454 | 1
455 | 4
456 | 6
457 | 8
458 | 10
459 | 11
460 | 3
461 | 1
462 | 4
463 | 6
464 | 8
465 | 10
466 | 12
467 | 14
468 | 16
469 | 17
470 | 19
471 | 3
472 | 1
473 | 4
474 | 6
475 | 8
476 | 9
477 | 3
478 | 1
479 | 4
480 | 6
481 | 7
482 | 3
483 | 1
484 | 4
485 | 6
486 | 8
487 | 10
488 | 11
489 | 3
490 | 1
491 | 4
492 | 6
493 | 8
494 | 10
495 | 12
496 | 14
497 | 16
498 | 20
499 | 3
500 | 1
501 | 4
502 | 6
503 | 8
504 | 10
505 | 12
506 | 14
507 | 16
508 | 17
509 | 19
510 | 3
511 | 1
512 | 4
513 | 6
514 | 8
515 | 9
516 | 3
517 | 1
518 | 4
519 | 6
520 | 7
521 | 3
522 | 1
523 | 4
524 | 6
525 | 8
526 | 10
527 | 12
528 | 14
529 | 16
530 | 17
531 | 18
532 | 3
533 | 1
534 | 2
535 | 3
536 | 1
537 | 4
538 | 5
539 | 3
540 | 1
541 | 4
542 | 6
543 | 8
544 | 10
545 | 12
546 | 14
547 | 15
548 | 3
549 | 1
550 | 4
551 | 6
552 | 7
553 | 3
554 | 1
555 | 4
556 | 6
557 | 8
558 | 10
559 | 11
560 | 3
561 | 1
562 | 4
563 | 6
564 | 8
565 | 10
566 | 12
567 | 14
568 | 16
569 | 17
570 | 19
571 | 3
572 | 1
573 | 4
574 | 6
575 | 8
576 | 9
577 | 3
578 | 1
579 | 4
580 | 6
581 | 7
582 | 3
583 | 1
584 | 4
585 | 6
586 | 8
587 | 10
588 | 11
589 | 3
590 | 1
591 | 4
592 | 6
593 | 8
594 | 10
595 | 12
596 | 14
597 | 16
598 | 17
599 | 19
600 | 3
601 | 1
602 | 4
603 | 6
604 | 8
605 | 9
606 | 3
607 | 1
608 | 4
609 | 6
610 | 7
611 | 3
612 | 1
613 | 4
614 | 6
615 | 8
616 | 10
617 | 12
618 | 14
619 | 16
620 | 17
621 | 18
622 | 3
623 | 1
624 | 2
625 | 3
626 | 1
627 | 4
628 | 5
629 | 3
630 | 1
631 | 4
632 | 6
633 | 8
634 | 10
635 | 12
636 | 14
637 | 15
638 | 3
639 | 1
640 | 4
641 | 6
642 | 7
643 | 3
644 | 1
645 | 4
646 | 6
647 | 8
648 | 10
649 | 11
650 | 3
651 | 1
652 | 4
653 | 6
654 | 8
655 | 10
656 | 12
657 | 14
658 | 16
659 | 17
660 | 19
661 | 3
662 | 1
663 | 4
664 | 6
665 | 8
666 | 9
667 | 3
668 | 1
669 | 4
670 | 6
671 | 7
672 | 3
673 | 1
674 | 4
675 | 6
676 | 8
677 | 10
678 | 12
679 | 14
680 | 16
681 | 17
682 | 18
683 | 3
684 | 1
685 | 2
686 | 3
687 | 1
688 | 4
689 | 5
690 | 3
691 | 1
692 | 4
693 | 6
694 | 8
695 | 10
696 | 12
697 | 13
698 |
--------------------------------------------------------------------------------
/results/bublesort_recursive_bb.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/melbshark/relative-pattern/c68f205eaddf4e7832ade0eab69de081b7e56c51/results/bublesort_recursive_bb.pdf
--------------------------------------------------------------------------------
/results/bublesort_recursive_bb1.trace:
--------------------------------------------------------------------------------
1 | 0
2 | 1
3 | 3
4 | 4
5 | 6
6 | 8
7 | 3
8 | 4
9 | 8
10 | 3
11 | 4
12 | 6
13 | 8
14 | 3
15 | 4
16 | 6
17 | 8
18 | 3
19 | 5
20 | 0
21 | 1
22 | 3
23 | 4
24 | 8
25 | 3
26 | 4
27 | 8
28 | 3
29 | 4
30 | 6
31 | 8
32 | 3
33 | 5
34 | 0
35 | 1
36 | 3
37 | 4
38 | 8
39 | 3
40 | 4
41 | 8
42 | 3
43 | 5
44 | 0
45 | 1
46 | 3
47 | 4
48 | 8
49 | 3
50 | 5
51 | 0
52 | 2
53 |
--------------------------------------------------------------------------------
/results/bublesort_recursive_bb2.trace:
--------------------------------------------------------------------------------
1 | 0
2 | 1
3 | 3
4 | 4
5 | 6
6 | 8
7 | 3
8 | 4
9 | 6
10 | 8
11 | 3
12 | 4
13 | 6
14 | 8
15 | 3
16 | 4
17 | 6
18 | 8
19 | 3
20 | 4
21 | 6
22 | 8
23 | 3
24 | 5
25 | 0
26 | 1
27 | 3
28 | 4
29 | 6
30 | 8
31 | 3
32 | 4
33 | 8
34 | 3
35 | 4
36 | 6
37 | 8
38 | 3
39 | 4
40 | 6
41 | 8
42 | 3
43 | 5
44 | 0
45 | 1
46 | 3
47 | 4
48 | 8
49 | 3
50 | 4
51 | 8
52 | 3
53 | 4
54 | 6
55 | 8
56 | 3
57 | 5
58 | 0
59 | 1
60 | 3
61 | 4
62 | 8
63 | 3
64 | 4
65 | 8
66 | 3
67 | 5
68 | 0
69 | 1
70 | 3
71 | 4
72 | 8
73 | 3
74 | 5
75 | 0
76 | 2
77 |
--------------------------------------------------------------------------------
/results/bublesort_recursive_obf2_bb.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/melbshark/relative-pattern/c68f205eaddf4e7832ade0eab69de081b7e56c51/results/bublesort_recursive_obf2_bb.pdf
--------------------------------------------------------------------------------
/results/bublesort_recursive_obf2_bb1.trace:
--------------------------------------------------------------------------------
1 | 0
2 | 1
3 | 2
4 | 5
5 | 8
6 | 1
7 | 2
8 | 4
9 | 8
10 | 1
11 | 3
12 | 6
13 | 33
14 | 116
15 | 6
16 | 35
17 | 116
18 | 6
19 | 39
20 | 88
21 | 122
22 | 116
23 | 6
24 | 45
25 | 95
26 | 132
27 | 95
28 | 130
29 | 95
30 | 131
31 | 116
32 | 6
33 | 40
34 | 95
35 | 134
36 | 95
37 | 133
38 | 116
39 | 6
40 | 49
41 | 116
42 | 6
43 | 37
44 | 116
45 | 6
46 | 50
47 | 116
48 | 6
49 | 19
50 | 116
51 | 6
52 | 41
53 | 116
54 | 6
55 | 53
56 | 116
57 | 6
58 | 21
59 | 116
60 | 6
61 | 39
62 | 88
63 | 122
64 | 116
65 | 6
66 | 45
67 | 95
68 | 132
69 | 95
70 | 130
71 | 95
72 | 131
73 | 116
74 | 6
75 | 40
76 | 95
77 | 134
78 | 95
79 | 133
80 | 116
81 | 6
82 | 49
83 | 116
84 | 6
85 | 37
86 | 116
87 | 6
88 | 50
89 | 116
90 | 6
91 | 19
92 | 116
93 | 6
94 | 41
95 | 116
96 | 6
97 | 53
98 | 116
99 | 6
100 | 21
101 | 116
102 | 6
103 | 39
104 | 89
105 | 122
106 | 116
107 | 6
108 | 25
109 | 116
110 | 6
111 | 10
112 | 116
113 | 6
114 | 54
115 | 116
116 | 6
117 | 46
118 | 116
119 | 6
120 | 23
121 | 116
122 | 6
123 | 51
124 | 103
125 | 145
126 | 116
127 | 6
128 | 29
129 | 116
130 | 6
131 | 51
132 | 102
133 | 145
134 | 116
135 | 6
136 | 55
137 | 116
138 | 6
139 | 31
140 | 79
141 | 120
142 | 116
143 | 6
144 | 52
145 | 116
146 | 6
147 | 51
148 | 108
149 | 145
150 | 116
151 | 6
152 | 14
153 | 116
154 | 6
155 | 36
156 | 116
157 | 6
158 | 42
159 | 116
160 | 6
161 | 51
162 | 109
163 | 145
164 | 116
165 | 6
166 | 38
167 | 116
168 | 6
169 | 18
170 | 65
171 | 118
172 | 116
173 | 6
174 | 13
175 | 116
176 | 6
177 | 20
178 | 116
179 | 6
180 | 51
181 | 104
182 | 145
183 | 116
184 | 6
185 | 28
186 | 116
187 | 6
188 | 43
189 | 93
190 | 129
191 | 116
192 | 6
193 | 22
194 | 116
195 | 6
196 | 51
197 | 111
198 | 145
199 | 116
200 | 6
201 | 15
202 | 116
203 | 6
204 | 34
205 | 116
206 | 6
207 | 51
208 | 105
209 | 145
210 | 116
211 | 6
212 | 27
213 | 116
214 | 6
215 | 17
216 | 116
217 | 6
218 | 12
219 | 116
220 | 6
221 | 51
222 | 107
223 | 145
224 | 116
225 | 6
226 | 16
227 | 116
228 | 6
229 | 32
230 | 116
231 | 6
232 | 51
233 | 106
234 | 145
235 | 116
236 | 6
237 | 48
238 | 116
239 | 6
240 | 30
241 | 116
242 | 6
243 | 26
244 | 116
245 | 6
246 | 51
247 | 109
248 | 145
249 | 116
250 | 6
251 | 38
252 | 116
253 | 6
254 | 18
255 | 65
256 | 118
257 | 116
258 | 6
259 | 13
260 | 116
261 | 6
262 | 20
263 | 116
264 | 6
265 | 51
266 | 104
267 | 145
268 | 116
269 | 6
270 | 28
271 | 116
272 | 6
273 | 43
274 | 94
275 | 129
276 | 116
277 | 6
278 | 47
279 | 116
280 | 6
281 | 51
282 | 106
283 | 145
284 | 116
285 | 6
286 | 48
287 | 116
288 | 6
289 | 30
290 | 116
291 | 6
292 | 26
293 | 116
294 | 6
295 | 51
296 | 109
297 | 145
298 | 116
299 | 6
300 | 38
301 | 116
302 | 6
303 | 18
304 | 65
305 | 118
306 | 116
307 | 6
308 | 13
309 | 116
310 | 6
311 | 20
312 | 116
313 | 6
314 | 51
315 | 104
316 | 145
317 | 116
318 | 6
319 | 28
320 | 116
321 | 6
322 | 43
323 | 93
324 | 129
325 | 116
326 | 6
327 | 22
328 | 116
329 | 6
330 | 51
331 | 111
332 | 145
333 | 116
334 | 6
335 | 15
336 | 116
337 | 6
338 | 34
339 | 116
340 | 6
341 | 51
342 | 105
343 | 145
344 | 116
345 | 6
346 | 27
347 | 116
348 | 6
349 | 17
350 | 116
351 | 6
352 | 12
353 | 116
354 | 6
355 | 51
356 | 107
357 | 145
358 | 116
359 | 6
360 | 16
361 | 116
362 | 6
363 | 32
364 | 116
365 | 6
366 | 51
367 | 106
368 | 145
369 | 116
370 | 6
371 | 48
372 | 116
373 | 6
374 | 30
375 | 116
376 | 6
377 | 26
378 | 116
379 | 6
380 | 51
381 | 109
382 | 145
383 | 116
384 | 6
385 | 38
386 | 116
387 | 6
388 | 18
389 | 65
390 | 118
391 | 116
392 | 6
393 | 13
394 | 116
395 | 6
396 | 20
397 | 116
398 | 6
399 | 51
400 | 104
401 | 145
402 | 116
403 | 6
404 | 28
405 | 116
406 | 6
407 | 43
408 | 93
409 | 129
410 | 116
411 | 6
412 | 22
413 | 116
414 | 6
415 | 51
416 | 111
417 | 145
418 | 116
419 | 6
420 | 15
421 | 116
422 | 6
423 | 34
424 | 116
425 | 6
426 | 51
427 | 105
428 | 145
429 | 116
430 | 6
431 | 27
432 | 116
433 | 6
434 | 17
435 | 116
436 | 6
437 | 12
438 | 116
439 | 6
440 | 51
441 | 107
442 | 145
443 | 116
444 | 6
445 | 16
446 | 116
447 | 6
448 | 32
449 | 116
450 | 6
451 | 51
452 | 106
453 | 145
454 | 116
455 | 6
456 | 48
457 | 116
458 | 6
459 | 30
460 | 116
461 | 6
462 | 26
463 | 116
464 | 6
465 | 51
466 | 109
467 | 145
468 | 116
469 | 6
470 | 38
471 | 116
472 | 6
473 | 18
474 | 66
475 | 118
476 | 116
477 | 6
478 | 11
479 | 116
480 | 6
481 | 51
482 | 110
483 | 145
484 | 116
485 | 6
486 | 44
487 | 0
488 | 1
489 | 2
490 | 4
491 | 8
492 | 1
493 | 2
494 | 4
495 | 8
496 | 1
497 | 3
498 | 6
499 | 33
500 | 116
501 | 6
502 | 35
503 | 116
504 | 6
505 | 39
506 | 88
507 | 122
508 | 116
509 | 6
510 | 45
511 | 95
512 | 132
513 | 95
514 | 130
515 | 95
516 | 131
517 | 116
518 | 6
519 | 40
520 | 95
521 | 134
522 | 95
523 | 133
524 | 116
525 | 6
526 | 49
527 | 116
528 | 6
529 | 37
530 | 116
531 | 6
532 | 50
533 | 116
534 | 6
535 | 19
536 | 116
537 | 6
538 | 41
539 | 116
540 | 6
541 | 53
542 | 116
543 | 6
544 | 21
545 | 116
546 | 6
547 | 39
548 | 88
549 | 122
550 | 116
551 | 6
552 | 45
553 | 95
554 | 132
555 | 95
556 | 130
557 | 95
558 | 131
559 | 116
560 | 6
561 | 40
562 | 95
563 | 134
564 | 95
565 | 133
566 | 116
567 | 6
568 | 49
569 | 116
570 | 6
571 | 37
572 | 116
573 | 6
574 | 50
575 | 116
576 | 6
577 | 19
578 | 116
579 | 6
580 | 41
581 | 116
582 | 6
583 | 53
584 | 116
585 | 6
586 | 21
587 | 116
588 | 6
589 | 39
590 | 89
591 | 122
592 | 116
593 | 6
594 | 25
595 | 116
596 | 6
597 | 10
598 | 116
599 | 6
600 | 54
601 | 116
602 | 6
603 | 46
604 | 116
605 | 6
606 | 23
607 | 116
608 | 6
609 | 51
610 | 103
611 | 145
612 | 116
613 | 6
614 | 29
615 | 116
616 | 6
617 | 51
618 | 102
619 | 145
620 | 116
621 | 6
622 | 55
623 | 116
624 | 6
625 | 31
626 | 79
627 | 120
628 | 116
629 | 6
630 | 52
631 | 116
632 | 6
633 | 51
634 | 108
635 | 145
636 | 116
637 | 6
638 | 14
639 | 116
640 | 6
641 | 36
642 | 116
643 | 6
644 | 42
645 | 116
646 | 6
647 | 51
648 | 109
649 | 145
650 | 116
651 | 6
652 | 38
653 | 116
654 | 6
655 | 18
656 | 65
657 | 118
658 | 116
659 | 6
660 | 13
661 | 116
662 | 6
663 | 20
664 | 116
665 | 6
666 | 51
667 | 104
668 | 145
669 | 116
670 | 6
671 | 28
672 | 116
673 | 6
674 | 43
675 | 94
676 | 129
677 | 116
678 | 6
679 | 47
680 | 116
681 | 6
682 | 51
683 | 106
684 | 145
685 | 116
686 | 6
687 | 48
688 | 116
689 | 6
690 | 30
691 | 116
692 | 6
693 | 26
694 | 116
695 | 6
696 | 51
697 | 109
698 | 145
699 | 116
700 | 6
701 | 38
702 | 116
703 | 6
704 | 18
705 | 65
706 | 118
707 | 116
708 | 6
709 | 13
710 | 116
711 | 6
712 | 20
713 | 116
714 | 6
715 | 51
716 | 104
717 | 145
718 | 116
719 | 6
720 | 28
721 | 116
722 | 6
723 | 43
724 | 94
725 | 129
726 | 116
727 | 6
728 | 47
729 | 116
730 | 6
731 | 51
732 | 106
733 | 145
734 | 116
735 | 6
736 | 48
737 | 116
738 | 6
739 | 30
740 | 116
741 | 6
742 | 26
743 | 116
744 | 6
745 | 51
746 | 109
747 | 145
748 | 116
749 | 6
750 | 38
751 | 116
752 | 6
753 | 18
754 | 65
755 | 118
756 | 116
757 | 6
758 | 13
759 | 116
760 | 6
761 | 20
762 | 116
763 | 6
764 | 51
765 | 104
766 | 145
767 | 116
768 | 6
769 | 28
770 | 116
771 | 6
772 | 43
773 | 93
774 | 129
775 | 116
776 | 6
777 | 22
778 | 116
779 | 6
780 | 51
781 | 111
782 | 145
783 | 116
784 | 6
785 | 15
786 | 116
787 | 6
788 | 34
789 | 116
790 | 6
791 | 51
792 | 105
793 | 145
794 | 116
795 | 6
796 | 27
797 | 116
798 | 6
799 | 17
800 | 116
801 | 6
802 | 12
803 | 116
804 | 6
805 | 51
806 | 107
807 | 145
808 | 116
809 | 6
810 | 16
811 | 116
812 | 6
813 | 32
814 | 116
815 | 6
816 | 51
817 | 106
818 | 145
819 | 116
820 | 6
821 | 48
822 | 116
823 | 6
824 | 30
825 | 116
826 | 6
827 | 26
828 | 116
829 | 6
830 | 51
831 | 109
832 | 145
833 | 116
834 | 6
835 | 38
836 | 116
837 | 6
838 | 18
839 | 66
840 | 118
841 | 116
842 | 6
843 | 11
844 | 116
845 | 6
846 | 51
847 | 110
848 | 145
849 | 116
850 | 6
851 | 44
852 | 0
853 | 1
854 | 2
855 | 4
856 | 8
857 | 1
858 | 2
859 | 4
860 | 8
861 | 1
862 | 3
863 | 6
864 | 33
865 | 116
866 | 6
867 | 35
868 | 116
869 | 6
870 | 39
871 | 88
872 | 122
873 | 116
874 | 6
875 | 45
876 | 95
877 | 132
878 | 95
879 | 130
880 | 95
881 | 131
882 | 116
883 | 6
884 | 40
885 | 95
886 | 134
887 | 95
888 | 133
889 | 116
890 | 6
891 | 49
892 | 116
893 | 6
894 | 37
895 | 116
896 | 6
897 | 50
898 | 116
899 | 6
900 | 19
901 | 116
902 | 6
903 | 41
904 | 116
905 | 6
906 | 53
907 | 116
908 | 6
909 | 21
910 | 116
911 | 6
912 | 39
913 | 88
914 | 122
915 | 116
916 | 6
917 | 45
918 | 95
919 | 132
920 | 95
921 | 130
922 | 95
923 | 131
924 | 116
925 | 6
926 | 40
927 | 95
928 | 134
929 | 95
930 | 133
931 | 116
932 | 6
933 | 49
934 | 116
935 | 6
936 | 37
937 | 116
938 | 6
939 | 50
940 | 116
941 | 6
942 | 19
943 | 116
944 | 6
945 | 41
946 | 116
947 | 6
948 | 53
949 | 116
950 | 6
951 | 21
952 | 116
953 | 6
954 | 39
955 | 89
956 | 122
957 | 116
958 | 6
959 | 25
960 | 116
961 | 6
962 | 10
963 | 116
964 | 6
965 | 54
966 | 116
967 | 6
968 | 46
969 | 116
970 | 6
971 | 23
972 | 116
973 | 6
974 | 51
975 | 103
976 | 145
977 | 116
978 | 6
979 | 29
980 | 116
981 | 6
982 | 51
983 | 102
984 | 145
985 | 116
986 | 6
987 | 55
988 | 116
989 | 6
990 | 31
991 | 79
992 | 120
993 | 116
994 | 6
995 | 52
996 | 116
997 | 6
998 | 51
999 | 108
1000 | 145
1001 | 116
1002 | 6
1003 | 14
1004 | 116
1005 | 6
1006 | 36
1007 | 116
1008 | 6
1009 | 42
1010 | 116
1011 | 6
1012 | 51
1013 | 109
1014 | 145
1015 | 116
1016 | 6
1017 | 38
1018 | 116
1019 | 6
1020 | 18
1021 | 65
1022 | 118
1023 | 116
1024 | 6
1025 | 13
1026 | 116
1027 | 6
1028 | 20
1029 | 116
1030 | 6
1031 | 51
1032 | 104
1033 | 145
1034 | 116
1035 | 6
1036 | 28
1037 | 116
1038 | 6
1039 | 43
1040 | 94
1041 | 129
1042 | 116
1043 | 6
1044 | 47
1045 | 116
1046 | 6
1047 | 51
1048 | 106
1049 | 145
1050 | 116
1051 | 6
1052 | 48
1053 | 116
1054 | 6
1055 | 30
1056 | 116
1057 | 6
1058 | 26
1059 | 116
1060 | 6
1061 | 51
1062 | 109
1063 | 145
1064 | 116
1065 | 6
1066 | 38
1067 | 116
1068 | 6
1069 | 18
1070 | 65
1071 | 118
1072 | 116
1073 | 6
1074 | 13
1075 | 116
1076 | 6
1077 | 20
1078 | 116
1079 | 6
1080 | 51
1081 | 104
1082 | 145
1083 | 116
1084 | 6
1085 | 28
1086 | 116
1087 | 6
1088 | 43
1089 | 94
1090 | 129
1091 | 116
1092 | 6
1093 | 47
1094 | 116
1095 | 6
1096 | 51
1097 | 106
1098 | 145
1099 | 116
1100 | 6
1101 | 48
1102 | 116
1103 | 6
1104 | 30
1105 | 116
1106 | 6
1107 | 26
1108 | 116
1109 | 6
1110 | 51
1111 | 109
1112 | 145
1113 | 116
1114 | 6
1115 | 38
1116 | 116
1117 | 6
1118 | 18
1119 | 66
1120 | 118
1121 | 116
1122 | 6
1123 | 11
1124 | 116
1125 | 6
1126 | 51
1127 | 110
1128 | 145
1129 | 116
1130 | 6
1131 | 44
1132 | 0
1133 | 1
1134 | 2
1135 | 4
1136 | 8
1137 | 1
1138 | 2
1139 | 4
1140 | 8
1141 | 1
1142 | 3
1143 | 6
1144 | 33
1145 | 116
1146 | 6
1147 | 35
1148 | 116
1149 | 6
1150 | 39
1151 | 88
1152 | 122
1153 | 116
1154 | 6
1155 | 45
1156 | 95
1157 | 132
1158 | 95
1159 | 130
1160 | 95
1161 | 131
1162 | 116
1163 | 6
1164 | 40
1165 | 95
1166 | 134
1167 | 95
1168 | 133
1169 | 116
1170 | 6
1171 | 49
1172 | 116
1173 | 6
1174 | 37
1175 | 116
1176 | 6
1177 | 50
1178 | 116
1179 | 6
1180 | 19
1181 | 116
1182 | 6
1183 | 41
1184 | 116
1185 | 6
1186 | 53
1187 | 116
1188 | 6
1189 | 21
1190 | 116
1191 | 6
1192 | 39
1193 | 88
1194 | 122
1195 | 116
1196 | 6
1197 | 45
1198 | 95
1199 | 132
1200 | 95
1201 | 130
1202 | 95
1203 | 131
1204 | 116
1205 | 6
1206 | 40
1207 | 95
1208 | 134
1209 | 95
1210 | 133
1211 | 116
1212 | 6
1213 | 49
1214 | 116
1215 | 6
1216 | 37
1217 | 116
1218 | 6
1219 | 50
1220 | 116
1221 | 6
1222 | 19
1223 | 116
1224 | 6
1225 | 41
1226 | 116
1227 | 6
1228 | 53
1229 | 116
1230 | 6
1231 | 21
1232 | 116
1233 | 6
1234 | 39
1235 | 89
1236 | 122
1237 | 116
1238 | 6
1239 | 25
1240 | 116
1241 | 6
1242 | 10
1243 | 116
1244 | 6
1245 | 54
1246 | 116
1247 | 6
1248 | 46
1249 | 116
1250 | 6
1251 | 23
1252 | 116
1253 | 6
1254 | 51
1255 | 103
1256 | 145
1257 | 116
1258 | 6
1259 | 29
1260 | 116
1261 | 6
1262 | 51
1263 | 102
1264 | 145
1265 | 116
1266 | 6
1267 | 55
1268 | 116
1269 | 6
1270 | 31
1271 | 79
1272 | 120
1273 | 116
1274 | 6
1275 | 52
1276 | 116
1277 | 6
1278 | 51
1279 | 108
1280 | 145
1281 | 116
1282 | 6
1283 | 14
1284 | 116
1285 | 6
1286 | 36
1287 | 116
1288 | 6
1289 | 42
1290 | 116
1291 | 6
1292 | 51
1293 | 109
1294 | 145
1295 | 116
1296 | 6
1297 | 38
1298 | 116
1299 | 6
1300 | 18
1301 | 65
1302 | 118
1303 | 116
1304 | 6
1305 | 13
1306 | 116
1307 | 6
1308 | 20
1309 | 116
1310 | 6
1311 | 51
1312 | 104
1313 | 145
1314 | 116
1315 | 6
1316 | 28
1317 | 116
1318 | 6
1319 | 43
1320 | 94
1321 | 129
1322 | 116
1323 | 6
1324 | 47
1325 | 116
1326 | 6
1327 | 51
1328 | 106
1329 | 145
1330 | 116
1331 | 6
1332 | 48
1333 | 116
1334 | 6
1335 | 30
1336 | 116
1337 | 6
1338 | 26
1339 | 116
1340 | 6
1341 | 51
1342 | 109
1343 | 145
1344 | 116
1345 | 6
1346 | 38
1347 | 116
1348 | 6
1349 | 18
1350 | 66
1351 | 118
1352 | 116
1353 | 6
1354 | 11
1355 | 116
1356 | 6
1357 | 51
1358 | 110
1359 | 145
1360 | 116
1361 | 6
1362 | 44
1363 | 0
1364 | 1
1365 | 2
1366 | 4
1367 | 8
1368 | 1
1369 | 2
1370 | 4
1371 | 8
1372 | 1
1373 | 3
1374 | 6
1375 | 33
1376 | 116
1377 | 6
1378 | 35
1379 | 116
1380 | 6
1381 | 39
1382 | 88
1383 | 122
1384 | 116
1385 | 6
1386 | 45
1387 | 95
1388 | 132
1389 | 95
1390 | 130
1391 | 95
1392 | 131
1393 | 116
1394 | 6
1395 | 40
1396 | 95
1397 | 134
1398 | 95
1399 | 133
1400 | 116
1401 | 6
1402 | 49
1403 | 116
1404 | 6
1405 | 37
1406 | 116
1407 | 6
1408 | 50
1409 | 116
1410 | 6
1411 | 19
1412 | 116
1413 | 6
1414 | 41
1415 | 116
1416 | 6
1417 | 53
1418 | 116
1419 | 6
1420 | 21
1421 | 116
1422 | 6
1423 | 39
1424 | 88
1425 | 122
1426 | 116
1427 | 6
1428 | 45
1429 | 95
1430 | 132
1431 | 95
1432 | 130
1433 | 95
1434 | 131
1435 | 116
1436 | 6
1437 | 40
1438 | 95
1439 | 134
1440 | 95
1441 | 133
1442 | 116
1443 | 6
1444 | 49
1445 | 116
1446 | 6
1447 | 37
1448 | 116
1449 | 6
1450 | 50
1451 | 116
1452 | 6
1453 | 19
1454 | 116
1455 | 6
1456 | 41
1457 | 116
1458 | 6
1459 | 53
1460 | 116
1461 | 6
1462 | 21
1463 | 116
1464 | 6
1465 | 39
1466 | 89
1467 | 122
1468 | 116
1469 | 6
1470 | 25
1471 | 116
1472 | 6
1473 | 10
1474 | 116
1475 | 6
1476 | 54
1477 | 116
1478 | 6
1479 | 46
1480 | 116
1481 | 6
1482 | 23
1483 | 116
1484 | 6
1485 | 51
1486 | 103
1487 | 145
1488 | 116
1489 | 6
1490 | 29
1491 | 116
1492 | 6
1493 | 51
1494 | 102
1495 | 145
1496 | 116
1497 | 6
1498 | 55
1499 | 116
1500 | 6
1501 | 31
1502 | 80
1503 | 120
1504 | 116
1505 | 6
1506 | 56
1507 | 116
1508 | 6
1509 | 51
1510 | 101
1511 | 145
1512 | 116
1513 | 6
1514 | 24
1515 | 116
1516 | 6
1517 | 9
1518 |
--------------------------------------------------------------------------------
/results/bublesort_recursive_obf_bb.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/melbshark/relative-pattern/c68f205eaddf4e7832ade0eab69de081b7e56c51/results/bublesort_recursive_obf_bb.pdf
--------------------------------------------------------------------------------
/results/bublesort_recursive_obf_bb1.trace:
--------------------------------------------------------------------------------
1 | 0
2 | 1
3 | 2
4 | 5
5 | 8
6 | 1
7 | 2
8 | 4
9 | 8
10 | 1
11 | 3
12 | 6
13 | 11
14 | 31
15 | 6
16 | 10
17 | 20
18 | 33
19 | 31
20 | 6
21 | 16
22 | 31
23 | 6
24 | 17
25 | 29
26 | 37
27 | 31
28 | 6
29 | 12
30 | 23
31 | 35
32 | 31
33 | 6
34 | 19
35 | 31
36 | 6
37 | 13
38 | 31
39 | 6
40 | 15
41 | 31
42 | 6
43 | 14
44 | 31
45 | 6
46 | 17
47 | 29
48 | 37
49 | 31
50 | 6
51 | 12
52 | 24
53 | 35
54 | 31
55 | 6
56 | 14
57 | 31
58 | 6
59 | 17
60 | 29
61 | 37
62 | 31
63 | 6
64 | 12
65 | 23
66 | 35
67 | 31
68 | 6
69 | 19
70 | 31
71 | 6
72 | 13
73 | 31
74 | 6
75 | 15
76 | 31
77 | 6
78 | 14
79 | 31
80 | 6
81 | 17
82 | 29
83 | 37
84 | 31
85 | 6
86 | 12
87 | 23
88 | 35
89 | 31
90 | 6
91 | 19
92 | 31
93 | 6
94 | 13
95 | 31
96 | 6
97 | 15
98 | 31
99 | 6
100 | 14
101 | 31
102 | 6
103 | 17
104 | 30
105 | 37
106 | 31
107 | 6
108 | 18
109 | 0
110 | 1
111 | 2
112 | 4
113 | 8
114 | 1
115 | 2
116 | 4
117 | 8
118 | 1
119 | 3
120 | 6
121 | 11
122 | 31
123 | 6
124 | 10
125 | 20
126 | 33
127 | 31
128 | 6
129 | 16
130 | 31
131 | 6
132 | 17
133 | 29
134 | 37
135 | 31
136 | 6
137 | 12
138 | 24
139 | 35
140 | 31
141 | 6
142 | 14
143 | 31
144 | 6
145 | 17
146 | 29
147 | 37
148 | 31
149 | 6
150 | 12
151 | 24
152 | 35
153 | 31
154 | 6
155 | 14
156 | 31
157 | 6
158 | 17
159 | 29
160 | 37
161 | 31
162 | 6
163 | 12
164 | 23
165 | 35
166 | 31
167 | 6
168 | 19
169 | 31
170 | 6
171 | 13
172 | 31
173 | 6
174 | 15
175 | 31
176 | 6
177 | 14
178 | 31
179 | 6
180 | 17
181 | 30
182 | 37
183 | 31
184 | 6
185 | 18
186 | 0
187 | 1
188 | 2
189 | 4
190 | 8
191 | 1
192 | 2
193 | 4
194 | 8
195 | 1
196 | 3
197 | 6
198 | 11
199 | 31
200 | 6
201 | 10
202 | 20
203 | 33
204 | 31
205 | 6
206 | 16
207 | 31
208 | 6
209 | 17
210 | 29
211 | 37
212 | 31
213 | 6
214 | 12
215 | 24
216 | 35
217 | 31
218 | 6
219 | 14
220 | 31
221 | 6
222 | 17
223 | 29
224 | 37
225 | 31
226 | 6
227 | 12
228 | 24
229 | 35
230 | 31
231 | 6
232 | 14
233 | 31
234 | 6
235 | 17
236 | 30
237 | 37
238 | 31
239 | 6
240 | 18
241 | 0
242 | 1
243 | 2
244 | 4
245 | 8
246 | 1
247 | 2
248 | 4
249 | 8
250 | 1
251 | 3
252 | 6
253 | 11
254 | 31
255 | 6
256 | 10
257 | 20
258 | 33
259 | 31
260 | 6
261 | 16
262 | 31
263 | 6
264 | 17
265 | 29
266 | 37
267 | 31
268 | 6
269 | 12
270 | 24
271 | 35
272 | 31
273 | 6
274 | 14
275 | 31
276 | 6
277 | 17
278 | 30
279 | 37
280 | 31
281 | 6
282 | 18
283 | 0
284 | 1
285 | 2
286 | 4
287 | 8
288 | 1
289 | 2
290 | 4
291 | 8
292 | 1
293 | 3
294 | 6
295 | 11
296 | 31
297 | 6
298 | 10
299 | 21
300 | 33
301 | 31
302 | 6
303 | 9
304 |
--------------------------------------------------------------------------------
/results/bublesort_recursive_obf_bb2.trace:
--------------------------------------------------------------------------------
1 | 0
2 | 1
3 | 2
4 | 5
5 | 8
6 | 1
7 | 2
8 | 4
9 | 8
10 | 1
11 | 3
12 | 6
13 | 11
14 | 31
15 | 6
16 | 10
17 | 20
18 | 33
19 | 31
20 | 6
21 | 16
22 | 31
23 | 6
24 | 17
25 | 29
26 | 37
27 | 31
28 | 6
29 | 12
30 | 23
31 | 35
32 | 31
33 | 6
34 | 19
35 | 31
36 | 6
37 | 13
38 | 31
39 | 6
40 | 15
41 | 31
42 | 6
43 | 14
44 | 31
45 | 6
46 | 17
47 | 29
48 | 37
49 | 31
50 | 6
51 | 12
52 | 23
53 | 35
54 | 31
55 | 6
56 | 19
57 | 31
58 | 6
59 | 13
60 | 31
61 | 6
62 | 15
63 | 31
64 | 6
65 | 14
66 | 31
67 | 6
68 | 17
69 | 29
70 | 37
71 | 31
72 | 6
73 | 12
74 | 23
75 | 35
76 | 31
77 | 6
78 | 19
79 | 31
80 | 6
81 | 13
82 | 31
83 | 6
84 | 15
85 | 31
86 | 6
87 | 14
88 | 31
89 | 6
90 | 17
91 | 29
92 | 37
93 | 31
94 | 6
95 | 12
96 | 23
97 | 35
98 | 31
99 | 6
100 | 19
101 | 31
102 | 6
103 | 13
104 | 31
105 | 6
106 | 15
107 | 31
108 | 6
109 | 14
110 | 31
111 | 6
112 | 17
113 | 29
114 | 37
115 | 31
116 | 6
117 | 12
118 | 23
119 | 35
120 | 31
121 | 6
122 | 19
123 | 31
124 | 6
125 | 13
126 | 31
127 | 6
128 | 15
129 | 31
130 | 6
131 | 14
132 | 31
133 | 6
134 | 17
135 | 30
136 | 37
137 | 31
138 | 6
139 | 18
140 | 0
141 | 1
142 | 2
143 | 4
144 | 8
145 | 1
146 | 2
147 | 4
148 | 8
149 | 1
150 | 3
151 | 6
152 | 11
153 | 31
154 | 6
155 | 10
156 | 20
157 | 33
158 | 31
159 | 6
160 | 16
161 | 31
162 | 6
163 | 17
164 | 29
165 | 37
166 | 31
167 | 6
168 | 12
169 | 23
170 | 35
171 | 31
172 | 6
173 | 19
174 | 31
175 | 6
176 | 13
177 | 31
178 | 6
179 | 15
180 | 31
181 | 6
182 | 14
183 | 31
184 | 6
185 | 17
186 | 29
187 | 37
188 | 31
189 | 6
190 | 12
191 | 24
192 | 35
193 | 31
194 | 6
195 | 14
196 | 31
197 | 6
198 | 17
199 | 29
200 | 37
201 | 31
202 | 6
203 | 12
204 | 23
205 | 35
206 | 31
207 | 6
208 | 19
209 | 31
210 | 6
211 | 13
212 | 31
213 | 6
214 | 15
215 | 31
216 | 6
217 | 14
218 | 31
219 | 6
220 | 17
221 | 29
222 | 37
223 | 31
224 | 6
225 | 12
226 | 23
227 | 35
228 | 31
229 | 6
230 | 19
231 | 31
232 | 6
233 | 13
234 | 31
235 | 6
236 | 15
237 | 31
238 | 6
239 | 14
240 | 31
241 | 6
242 | 17
243 | 30
244 | 37
245 | 31
246 | 6
247 | 18
248 | 0
249 | 1
250 | 2
251 | 4
252 | 8
253 | 1
254 | 2
255 | 4
256 | 8
257 | 1
258 | 3
259 | 6
260 | 11
261 | 31
262 | 6
263 | 10
264 | 20
265 | 33
266 | 31
267 | 6
268 | 16
269 | 31
270 | 6
271 | 17
272 | 29
273 | 37
274 | 31
275 | 6
276 | 12
277 | 24
278 | 35
279 | 31
280 | 6
281 | 14
282 | 31
283 | 6
284 | 17
285 | 29
286 | 37
287 | 31
288 | 6
289 | 12
290 | 24
291 | 35
292 | 31
293 | 6
294 | 14
295 | 31
296 | 6
297 | 17
298 | 29
299 | 37
300 | 31
301 | 6
302 | 12
303 | 23
304 | 35
305 | 31
306 | 6
307 | 19
308 | 31
309 | 6
310 | 13
311 | 31
312 | 6
313 | 15
314 | 31
315 | 6
316 | 14
317 | 31
318 | 6
319 | 17
320 | 30
321 | 37
322 | 31
323 | 6
324 | 18
325 | 0
326 | 1
327 | 2
328 | 4
329 | 8
330 | 1
331 | 2
332 | 4
333 | 8
334 | 1
335 | 3
336 | 6
337 | 11
338 | 31
339 | 6
340 | 10
341 | 20
342 | 33
343 | 31
344 | 6
345 | 16
346 | 31
347 | 6
348 | 17
349 | 29
350 | 37
351 | 31
352 | 6
353 | 12
354 | 24
355 | 35
356 | 31
357 | 6
358 | 14
359 | 31
360 | 6
361 | 17
362 | 29
363 | 37
364 | 31
365 | 6
366 | 12
367 | 24
368 | 35
369 | 31
370 | 6
371 | 14
372 | 31
373 | 6
374 | 17
375 | 30
376 | 37
377 | 31
378 | 6
379 | 18
380 | 0
381 | 1
382 | 2
383 | 4
384 | 8
385 | 1
386 | 2
387 | 4
388 | 8
389 | 1
390 | 3
391 | 6
392 | 11
393 | 31
394 | 6
395 | 10
396 | 20
397 | 33
398 | 31
399 | 6
400 | 16
401 | 31
402 | 6
403 | 17
404 | 29
405 | 37
406 | 31
407 | 6
408 | 12
409 | 24
410 | 35
411 | 31
412 | 6
413 | 14
414 | 31
415 | 6
416 | 17
417 | 30
418 | 37
419 | 31
420 | 6
421 | 18
422 | 0
423 | 1
424 | 2
425 | 4
426 | 8
427 | 1
428 | 2
429 | 4
430 | 8
431 | 1
432 | 3
433 | 6
434 | 11
435 | 31
436 | 6
437 | 10
438 | 21
439 | 33
440 | 31
441 | 6
442 | 9
443 |
--------------------------------------------------------------------------------
/results/resmsign_codevirtualizer.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/melbshark/relative-pattern/c68f205eaddf4e7832ade0eab69de081b7e56c51/results/resmsign_codevirtualizer.pdf
--------------------------------------------------------------------------------
/results/virsuper_bbsort_recur2_bb.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/melbshark/relative-pattern/c68f205eaddf4e7832ade0eab69de081b7e56c51/results/virsuper_bbsort_recur2_bb.pdf
--------------------------------------------------------------------------------
/results/virtualize_super_bublesort_recursive_bb.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/melbshark/relative-pattern/c68f205eaddf4e7832ade0eab69de081b7e56c51/results/virtualize_super_bublesort_recursive_bb.pdf
--------------------------------------------------------------------------------
/results/virtualize_super_bublesort_recursive_bb.trace1:
--------------------------------------------------------------------------------
1 | 0
2 | 1
3 | 2
4 | 5
5 | 11
6 | 20
7 | 1
8 | 2
9 | 4
10 | 8
11 | 16
12 | 30
13 | 20
14 | 1
15 | 3
16 | 6
17 | 13
18 | 23
19 | 31
20 | 46
21 | 20
22 | 1
23 | 3
24 | 7
25 | 14
26 | 25
27 | 35
28 | 20
29 | 1
30 | 3
31 | 6
32 | 12
33 | 21
34 | 20
35 | 1
36 | 2
37 | 4
38 | 8
39 | 16
40 | 30
41 | 20
42 | 1
43 | 3
44 | 7
45 | 14
46 | 25
47 | 36
48 | 47
49 | 56
50 | 20
51 | 1
52 | 3
53 | 7
54 | 15
55 | 27
56 | 41
57 | 20
58 | 1
59 | 2
60 | 4
61 | 8
62 | 17
63 | 30
64 | 20
65 | 1
66 | 3
67 | 7
68 | 15
69 | 27
70 | 40
71 | 20
72 | 1
73 | 3
74 | 6
75 | 12
76 | 22
77 | 20
78 | 1
79 | 3
80 | 7
81 | 15
82 | 28
83 | 44
84 | 54
85 | 62
86 | 20
87 | 1
88 | 3
89 | 7
90 | 14
91 | 26
92 | 37
93 | 49
94 | 58
95 | 20
96 | 1
97 | 3
98 | 7
99 | 15
100 | 28
101 | 44
102 | 54
103 | 62
104 | 20
105 | 1
106 | 3
107 | 6
108 | 13
109 | 24
110 | 34
111 | 20
112 | 1
113 | 3
114 | 7
115 | 15
116 | 28
117 | 43
118 | 52
119 | 60
120 | 64
121 | 67
122 | 20
123 | 1
124 | 3
125 | 7
126 | 15
127 | 28
128 | 44
129 | 54
130 | 62
131 | 20
132 | 1
133 | 3
134 | 6
135 | 13
136 | 24
137 | 33
138 | 20
139 | 1
140 | 3
141 | 7
142 | 15
143 | 28
144 | 44
145 | 54
146 | 62
147 | 20
148 | 1
149 | 3
150 | 7
151 | 15
152 | 28
153 | 43
154 | 51
155 | 20
156 | 1
157 | 2
158 | 4
159 | 9
160 | 20
161 | 1
162 | 3
163 | 7
164 | 15
165 | 28
166 | 43
167 | 52
168 | 59
169 | 20
170 | 1
171 | 3
172 | 7
173 | 15
174 | 28
175 | 44
176 | 54
177 | 62
178 | 20
179 | 1
180 | 3
181 | 7
182 | 14
183 | 26
184 | 38
185 | 20
186 | 1
187 | 2
188 | 5
189 | 10
190 | 20
191 | 1
192 | 3
193 | 7
194 | 15
195 | 27
196 | 39
197 | 20
198 | 1
199 | 3
200 | 6
201 | 12
202 | 21
203 | 20
204 | 1
205 | 2
206 | 4
207 | 8
208 | 16
209 | 30
210 | 20
211 | 1
212 | 3
213 | 7
214 | 14
215 | 25
216 | 36
217 | 47
218 | 56
219 | 20
220 | 1
221 | 3
222 | 7
223 | 15
224 | 27
225 | 41
226 | 20
227 | 1
228 | 2
229 | 4
230 | 8
231 | 17
232 | 30
233 | 20
234 | 1
235 | 3
236 | 7
237 | 15
238 | 27
239 | 40
240 | 20
241 | 1
242 | 3
243 | 6
244 | 12
245 | 22
246 | 20
247 | 1
248 | 3
249 | 7
250 | 15
251 | 28
252 | 44
253 | 54
254 | 62
255 | 20
256 | 1
257 | 3
258 | 7
259 | 14
260 | 26
261 | 37
262 | 50
263 | 58
264 | 20
265 | 1
266 | 3
267 | 7
268 | 15
269 | 27
270 | 39
271 | 20
272 | 1
273 | 2
274 | 5
275 | 10
276 | 20
277 | 1
278 | 3
279 | 7
280 | 15
281 | 27
282 | 39
283 | 20
284 | 1
285 | 3
286 | 6
287 | 12
288 | 21
289 | 20
290 | 1
291 | 2
292 | 4
293 | 8
294 | 16
295 | 30
296 | 20
297 | 1
298 | 3
299 | 7
300 | 14
301 | 25
302 | 36
303 | 47
304 | 56
305 | 20
306 | 1
307 | 3
308 | 7
309 | 15
310 | 27
311 | 41
312 | 20
313 | 1
314 | 2
315 | 4
316 | 8
317 | 17
318 | 30
319 | 20
320 | 1
321 | 3
322 | 7
323 | 15
324 | 27
325 | 40
326 | 20
327 | 1
328 | 3
329 | 6
330 | 12
331 | 22
332 | 20
333 | 1
334 | 3
335 | 7
336 | 15
337 | 28
338 | 44
339 | 54
340 | 62
341 | 20
342 | 1
343 | 3
344 | 7
345 | 14
346 | 26
347 | 37
348 | 49
349 | 58
350 | 20
351 | 1
352 | 3
353 | 7
354 | 15
355 | 28
356 | 44
357 | 54
358 | 62
359 | 20
360 | 1
361 | 3
362 | 6
363 | 13
364 | 24
365 | 34
366 | 20
367 | 1
368 | 3
369 | 7
370 | 15
371 | 28
372 | 43
373 | 52
374 | 60
375 | 64
376 | 67
377 | 20
378 | 1
379 | 3
380 | 7
381 | 15
382 | 28
383 | 44
384 | 54
385 | 62
386 | 20
387 | 1
388 | 3
389 | 6
390 | 13
391 | 24
392 | 33
393 | 20
394 | 1
395 | 3
396 | 7
397 | 15
398 | 28
399 | 44
400 | 54
401 | 62
402 | 20
403 | 1
404 | 3
405 | 7
406 | 15
407 | 28
408 | 43
409 | 51
410 | 20
411 | 1
412 | 2
413 | 4
414 | 9
415 | 20
416 | 1
417 | 3
418 | 7
419 | 15
420 | 28
421 | 43
422 | 52
423 | 59
424 | 20
425 | 1
426 | 3
427 | 7
428 | 15
429 | 28
430 | 44
431 | 54
432 | 62
433 | 20
434 | 1
435 | 3
436 | 7
437 | 14
438 | 26
439 | 38
440 | 20
441 | 1
442 | 2
443 | 5
444 | 10
445 | 20
446 | 1
447 | 3
448 | 7
449 | 15
450 | 27
451 | 39
452 | 20
453 | 1
454 | 3
455 | 6
456 | 12
457 | 21
458 | 20
459 | 1
460 | 2
461 | 4
462 | 8
463 | 16
464 | 30
465 | 20
466 | 1
467 | 3
468 | 7
469 | 14
470 | 25
471 | 36
472 | 47
473 | 56
474 | 20
475 | 1
476 | 3
477 | 7
478 | 15
479 | 27
480 | 41
481 | 20
482 | 1
483 | 2
484 | 4
485 | 8
486 | 17
487 | 30
488 | 20
489 | 1
490 | 3
491 | 7
492 | 15
493 | 27
494 | 40
495 | 20
496 | 1
497 | 3
498 | 6
499 | 12
500 | 22
501 | 20
502 | 1
503 | 3
504 | 7
505 | 15
506 | 28
507 | 44
508 | 54
509 | 62
510 | 20
511 | 1
512 | 3
513 | 7
514 | 14
515 | 26
516 | 37
517 | 49
518 | 58
519 | 20
520 | 1
521 | 3
522 | 7
523 | 15
524 | 28
525 | 44
526 | 54
527 | 62
528 | 20
529 | 1
530 | 3
531 | 6
532 | 13
533 | 24
534 | 34
535 | 20
536 | 1
537 | 3
538 | 7
539 | 15
540 | 28
541 | 43
542 | 52
543 | 60
544 | 64
545 | 67
546 | 20
547 | 1
548 | 3
549 | 7
550 | 15
551 | 28
552 | 44
553 | 54
554 | 62
555 | 20
556 | 1
557 | 3
558 | 6
559 | 13
560 | 24
561 | 33
562 | 20
563 | 1
564 | 3
565 | 7
566 | 15
567 | 28
568 | 44
569 | 54
570 | 62
571 | 20
572 | 1
573 | 3
574 | 7
575 | 15
576 | 28
577 | 43
578 | 51
579 | 20
580 | 1
581 | 2
582 | 4
583 | 9
584 | 20
585 | 1
586 | 3
587 | 7
588 | 15
589 | 28
590 | 43
591 | 52
592 | 59
593 | 20
594 | 1
595 | 3
596 | 7
597 | 15
598 | 28
599 | 44
600 | 54
601 | 62
602 | 20
603 | 1
604 | 3
605 | 7
606 | 14
607 | 26
608 | 38
609 | 20
610 | 1
611 | 2
612 | 5
613 | 10
614 | 20
615 | 1
616 | 3
617 | 7
618 | 15
619 | 27
620 | 39
621 | 20
622 | 1
623 | 3
624 | 6
625 | 12
626 | 21
627 | 20
628 | 1
629 | 2
630 | 4
631 | 8
632 | 16
633 | 30
634 | 20
635 | 1
636 | 3
637 | 7
638 | 14
639 | 25
640 | 36
641 | 48
642 | 56
643 | 20
644 | 1
645 | 3
646 | 7
647 | 15
648 | 27
649 | 39
650 | 20
651 | 1
652 | 3
653 | 7
654 | 15
655 | 27
656 | 39
657 | 20
658 | 1
659 | 3
660 | 7
661 | 15
662 | 28
663 | 44
664 | 54
665 | 62
666 | 20
667 | 1
668 | 3
669 | 7
670 | 15
671 | 28
672 | 43
673 | 52
674 | 60
675 | 64
676 | 68
677 | 20
678 | 1
679 | 3
680 | 7
681 | 15
682 | 28
683 | 44
684 | 53
685 | 62
686 | 20
687 | 1
688 | 3
689 | 7
690 | 15
691 | 28
692 | 43
693 | 52
694 | 60
695 | 63
696 | 65
697 | 20
698 | 1
699 | 3
700 | 7
701 | 15
702 | 27
703 | 42
704 | 0
705 | 1
706 | 2
707 | 5
708 | 11
709 | 20
710 | 1
711 | 2
712 | 4
713 | 8
714 | 16
715 | 30
716 | 20
717 | 1
718 | 3
719 | 6
720 | 13
721 | 23
722 | 31
723 | 46
724 | 20
725 | 1
726 | 3
727 | 7
728 | 14
729 | 25
730 | 35
731 | 20
732 | 1
733 | 3
734 | 6
735 | 12
736 | 21
737 | 20
738 | 1
739 | 2
740 | 4
741 | 8
742 | 16
743 | 30
744 | 20
745 | 1
746 | 3
747 | 7
748 | 14
749 | 25
750 | 36
751 | 47
752 | 56
753 | 20
754 | 1
755 | 3
756 | 7
757 | 15
758 | 27
759 | 41
760 | 20
761 | 1
762 | 2
763 | 4
764 | 8
765 | 17
766 | 30
767 | 20
768 | 1
769 | 3
770 | 7
771 | 15
772 | 27
773 | 40
774 | 20
775 | 1
776 | 3
777 | 6
778 | 12
779 | 22
780 | 20
781 | 1
782 | 3
783 | 7
784 | 15
785 | 28
786 | 44
787 | 54
788 | 62
789 | 20
790 | 1
791 | 3
792 | 7
793 | 14
794 | 26
795 | 37
796 | 50
797 | 58
798 | 20
799 | 1
800 | 3
801 | 7
802 | 15
803 | 27
804 | 39
805 | 20
806 | 1
807 | 2
808 | 5
809 | 10
810 | 20
811 | 1
812 | 3
813 | 7
814 | 15
815 | 27
816 | 39
817 | 20
818 | 1
819 | 3
820 | 6
821 | 12
822 | 21
823 | 20
824 | 1
825 | 2
826 | 4
827 | 8
828 | 16
829 | 30
830 | 20
831 | 1
832 | 3
833 | 7
834 | 14
835 | 25
836 | 36
837 | 47
838 | 56
839 | 20
840 | 1
841 | 3
842 | 7
843 | 15
844 | 27
845 | 41
846 | 20
847 | 1
848 | 2
849 | 4
850 | 8
851 | 17
852 | 30
853 | 20
854 | 1
855 | 3
856 | 7
857 | 15
858 | 27
859 | 40
860 | 20
861 | 1
862 | 3
863 | 6
864 | 12
865 | 22
866 | 20
867 | 1
868 | 3
869 | 7
870 | 15
871 | 28
872 | 44
873 | 54
874 | 62
875 | 20
876 | 1
877 | 3
878 | 7
879 | 14
880 | 26
881 | 37
882 | 50
883 | 58
884 | 20
885 | 1
886 | 3
887 | 7
888 | 15
889 | 27
890 | 39
891 | 20
892 | 1
893 | 2
894 | 5
895 | 10
896 | 20
897 | 1
898 | 3
899 | 7
900 | 15
901 | 27
902 | 39
903 | 20
904 | 1
905 | 3
906 | 6
907 | 12
908 | 21
909 | 20
910 | 1
911 | 2
912 | 4
913 | 8
914 | 16
915 | 30
916 | 20
917 | 1
918 | 3
919 | 7
920 | 14
921 | 25
922 | 36
923 | 47
924 | 56
925 | 20
926 | 1
927 | 3
928 | 7
929 | 15
930 | 27
931 | 41
932 | 20
933 | 1
934 | 2
935 | 4
936 | 8
937 | 17
938 | 30
939 | 20
940 | 1
941 | 3
942 | 7
943 | 15
944 | 27
945 | 40
946 | 20
947 | 1
948 | 3
949 | 6
950 | 12
951 | 22
952 | 20
953 | 1
954 | 3
955 | 7
956 | 15
957 | 28
958 | 44
959 | 54
960 | 62
961 | 20
962 | 1
963 | 3
964 | 7
965 | 14
966 | 26
967 | 37
968 | 49
969 | 58
970 | 20
971 | 1
972 | 3
973 | 7
974 | 15
975 | 28
976 | 44
977 | 54
978 | 62
979 | 20
980 | 1
981 | 3
982 | 6
983 | 13
984 | 24
985 | 34
986 | 20
987 | 1
988 | 3
989 | 7
990 | 15
991 | 28
992 | 43
993 | 52
994 | 60
995 | 64
996 | 67
997 | 20
998 | 1
999 | 3
1000 | 7
1001 | 15
1002 | 28
1003 | 44
1004 | 54
1005 | 62
1006 | 20
1007 | 1
1008 | 3
1009 | 6
1010 | 13
1011 | 24
1012 | 33
1013 | 20
1014 | 1
1015 | 3
1016 | 7
1017 | 15
1018 | 28
1019 | 44
1020 | 54
1021 | 62
1022 | 20
1023 | 1
1024 | 3
1025 | 7
1026 | 15
1027 | 28
1028 | 43
1029 | 51
1030 | 20
1031 | 1
1032 | 2
1033 | 4
1034 | 9
1035 | 20
1036 | 1
1037 | 3
1038 | 7
1039 | 15
1040 | 28
1041 | 43
1042 | 52
1043 | 59
1044 | 20
1045 | 1
1046 | 3
1047 | 7
1048 | 15
1049 | 28
1050 | 44
1051 | 54
1052 | 62
1053 | 20
1054 | 1
1055 | 3
1056 | 7
1057 | 14
1058 | 26
1059 | 38
1060 | 20
1061 | 1
1062 | 2
1063 | 5
1064 | 10
1065 | 20
1066 | 1
1067 | 3
1068 | 7
1069 | 15
1070 | 27
1071 | 39
1072 | 20
1073 | 1
1074 | 3
1075 | 6
1076 | 12
1077 | 21
1078 | 20
1079 | 1
1080 | 2
1081 | 4
1082 | 8
1083 | 16
1084 | 30
1085 | 20
1086 | 1
1087 | 3
1088 | 7
1089 | 14
1090 | 25
1091 | 36
1092 | 48
1093 | 56
1094 | 20
1095 | 1
1096 | 3
1097 | 7
1098 | 15
1099 | 27
1100 | 39
1101 | 20
1102 | 1
1103 | 3
1104 | 7
1105 | 15
1106 | 27
1107 | 39
1108 | 20
1109 | 1
1110 | 3
1111 | 7
1112 | 15
1113 | 28
1114 | 44
1115 | 54
1116 | 62
1117 | 20
1118 | 1
1119 | 3
1120 | 7
1121 | 15
1122 | 28
1123 | 43
1124 | 52
1125 | 60
1126 | 64
1127 | 68
1128 | 20
1129 | 1
1130 | 3
1131 | 7
1132 | 15
1133 | 28
1134 | 44
1135 | 53
1136 | 62
1137 | 20
1138 | 1
1139 | 3
1140 | 7
1141 | 15
1142 | 28
1143 | 43
1144 | 52
1145 | 60
1146 | 63
1147 | 65
1148 | 20
1149 | 1
1150 | 3
1151 | 7
1152 | 15
1153 | 27
1154 | 42
1155 | 0
1156 | 1
1157 | 2
1158 | 5
1159 | 11
1160 | 20
1161 | 1
1162 | 2
1163 | 4
1164 | 8
1165 | 16
1166 | 30
1167 | 20
1168 | 1
1169 | 3
1170 | 6
1171 | 13
1172 | 23
1173 | 31
1174 | 46
1175 | 20
1176 | 1
1177 | 3
1178 | 7
1179 | 14
1180 | 25
1181 | 35
1182 | 20
1183 | 1
1184 | 3
1185 | 6
1186 | 12
1187 | 21
1188 | 20
1189 | 1
1190 | 2
1191 | 4
1192 | 8
1193 | 16
1194 | 30
1195 | 20
1196 | 1
1197 | 3
1198 | 7
1199 | 14
1200 | 25
1201 | 36
1202 | 47
1203 | 56
1204 | 20
1205 | 1
1206 | 3
1207 | 7
1208 | 15
1209 | 27
1210 | 41
1211 | 20
1212 | 1
1213 | 2
1214 | 4
1215 | 8
1216 | 17
1217 | 30
1218 | 20
1219 | 1
1220 | 3
1221 | 7
1222 | 15
1223 | 27
1224 | 40
1225 | 20
1226 | 1
1227 | 3
1228 | 6
1229 | 12
1230 | 22
1231 | 20
1232 | 1
1233 | 3
1234 | 7
1235 | 15
1236 | 28
1237 | 44
1238 | 54
1239 | 62
1240 | 20
1241 | 1
1242 | 3
1243 | 7
1244 | 14
1245 | 26
1246 | 37
1247 | 50
1248 | 58
1249 | 20
1250 | 1
1251 | 3
1252 | 7
1253 | 15
1254 | 27
1255 | 39
1256 | 20
1257 | 1
1258 | 2
1259 | 5
1260 | 10
1261 | 20
1262 | 1
1263 | 3
1264 | 7
1265 | 15
1266 | 27
1267 | 39
1268 | 20
1269 | 1
1270 | 3
1271 | 6
1272 | 12
1273 | 21
1274 | 20
1275 | 1
1276 | 2
1277 | 4
1278 | 8
1279 | 16
1280 | 30
1281 | 20
1282 | 1
1283 | 3
1284 | 7
1285 | 14
1286 | 25
1287 | 36
1288 | 47
1289 | 56
1290 | 20
1291 | 1
1292 | 3
1293 | 7
1294 | 15
1295 | 27
1296 | 41
1297 | 20
1298 | 1
1299 | 2
1300 | 4
1301 | 8
1302 | 17
1303 | 30
1304 | 20
1305 | 1
1306 | 3
1307 | 7
1308 | 15
1309 | 27
1310 | 40
1311 | 20
1312 | 1
1313 | 3
1314 | 6
1315 | 12
1316 | 22
1317 | 20
1318 | 1
1319 | 3
1320 | 7
1321 | 15
1322 | 28
1323 | 44
1324 | 54
1325 | 62
1326 | 20
1327 | 1
1328 | 3
1329 | 7
1330 | 14
1331 | 26
1332 | 37
1333 | 50
1334 | 58
1335 | 20
1336 | 1
1337 | 3
1338 | 7
1339 | 15
1340 | 27
1341 | 39
1342 | 20
1343 | 1
1344 | 2
1345 | 5
1346 | 10
1347 | 20
1348 | 1
1349 | 3
1350 | 7
1351 | 15
1352 | 27
1353 | 39
1354 | 20
1355 | 1
1356 | 3
1357 | 6
1358 | 12
1359 | 21
1360 | 20
1361 | 1
1362 | 2
1363 | 4
1364 | 8
1365 | 16
1366 | 30
1367 | 20
1368 | 1
1369 | 3
1370 | 7
1371 | 14
1372 | 25
1373 | 36
1374 | 48
1375 | 56
1376 | 20
1377 | 1
1378 | 3
1379 | 7
1380 | 15
1381 | 27
1382 | 39
1383 | 20
1384 | 1
1385 | 3
1386 | 7
1387 | 15
1388 | 27
1389 | 39
1390 | 20
1391 | 1
1392 | 3
1393 | 7
1394 | 15
1395 | 28
1396 | 44
1397 | 54
1398 | 62
1399 | 20
1400 | 1
1401 | 3
1402 | 7
1403 | 15
1404 | 28
1405 | 43
1406 | 52
1407 | 60
1408 | 64
1409 | 68
1410 | 20
1411 | 1
1412 | 3
1413 | 7
1414 | 15
1415 | 28
1416 | 44
1417 | 53
1418 | 62
1419 | 20
1420 | 1
1421 | 3
1422 | 7
1423 | 15
1424 | 28
1425 | 43
1426 | 52
1427 | 60
1428 | 63
1429 | 65
1430 | 20
1431 | 1
1432 | 3
1433 | 7
1434 | 15
1435 | 27
1436 | 42
1437 | 0
1438 | 1
1439 | 2
1440 | 5
1441 | 11
1442 | 20
1443 | 1
1444 | 2
1445 | 4
1446 | 8
1447 | 16
1448 | 30
1449 | 20
1450 | 1
1451 | 3
1452 | 6
1453 | 13
1454 | 23
1455 | 31
1456 | 46
1457 | 20
1458 | 1
1459 | 3
1460 | 7
1461 | 14
1462 | 25
1463 | 35
1464 | 20
1465 | 1
1466 | 3
1467 | 6
1468 | 12
1469 | 21
1470 | 20
1471 | 1
1472 | 2
1473 | 4
1474 | 8
1475 | 16
1476 | 30
1477 | 20
1478 | 1
1479 | 3
1480 | 7
1481 | 14
1482 | 25
1483 | 36
1484 | 47
1485 | 56
1486 | 20
1487 | 1
1488 | 3
1489 | 7
1490 | 15
1491 | 27
1492 | 41
1493 | 20
1494 | 1
1495 | 2
1496 | 4
1497 | 8
1498 | 17
1499 | 30
1500 | 20
1501 | 1
1502 | 3
1503 | 7
1504 | 15
1505 | 27
1506 | 40
1507 | 20
1508 | 1
1509 | 3
1510 | 6
1511 | 12
1512 | 22
1513 | 20
1514 | 1
1515 | 3
1516 | 7
1517 | 15
1518 | 28
1519 | 44
1520 | 54
1521 | 62
1522 | 20
1523 | 1
1524 | 3
1525 | 7
1526 | 14
1527 | 26
1528 | 37
1529 | 50
1530 | 58
1531 | 20
1532 | 1
1533 | 3
1534 | 7
1535 | 15
1536 | 27
1537 | 39
1538 | 20
1539 | 1
1540 | 2
1541 | 5
1542 | 10
1543 | 20
1544 | 1
1545 | 3
1546 | 7
1547 | 15
1548 | 27
1549 | 39
1550 | 20
1551 | 1
1552 | 3
1553 | 6
1554 | 12
1555 | 21
1556 | 20
1557 | 1
1558 | 2
1559 | 4
1560 | 8
1561 | 16
1562 | 30
1563 | 20
1564 | 1
1565 | 3
1566 | 7
1567 | 14
1568 | 25
1569 | 36
1570 | 48
1571 | 56
1572 | 20
1573 | 1
1574 | 3
1575 | 7
1576 | 15
1577 | 27
1578 | 39
1579 | 20
1580 | 1
1581 | 3
1582 | 7
1583 | 15
1584 | 27
1585 | 39
1586 | 20
1587 | 1
1588 | 3
1589 | 7
1590 | 15
1591 | 28
1592 | 44
1593 | 54
1594 | 62
1595 | 20
1596 | 1
1597 | 3
1598 | 7
1599 | 15
1600 | 28
1601 | 43
1602 | 52
1603 | 60
1604 | 64
1605 | 68
1606 | 20
1607 | 1
1608 | 3
1609 | 7
1610 | 15
1611 | 28
1612 | 44
1613 | 53
1614 | 62
1615 | 20
1616 | 1
1617 | 3
1618 | 7
1619 | 15
1620 | 28
1621 | 43
1622 | 52
1623 | 60
1624 | 63
1625 | 65
1626 | 20
1627 | 1
1628 | 3
1629 | 7
1630 | 15
1631 | 27
1632 | 42
1633 | 0
1634 | 1
1635 | 2
1636 | 5
1637 | 11
1638 | 20
1639 | 1
1640 | 2
1641 | 4
1642 | 8
1643 | 16
1644 | 30
1645 | 20
1646 | 1
1647 | 3
1648 | 6
1649 | 13
1650 | 23
1651 | 32
1652 | 46
1653 | 20
1654 | 1
1655 | 3
1656 | 7
1657 | 15
1658 | 27
1659 | 39
1660 | 20
1661 | 1
1662 | 3
1663 | 7
1664 | 15
1665 | 28
1666 | 43
1667 | 52
1668 | 60
1669 | 63
1670 | 66
1671 |
--------------------------------------------------------------------------------
/src/jump_table/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | project(jump_table)
2 | cmake_minimum_required(VERSION 2.9)
3 |
4 | aux_source_directory(. SRC_LIST)
5 |
6 | include_directories(.)
7 |
8 | add_definitions(-std=c++11)
9 |
10 | add_executable(${PROJECT_NAME} ${SRC_LIST})
11 | #target_compile_features(${PROJECT_NAME} PRIVATE cxx_autotype)
12 |
13 |
--------------------------------------------------------------------------------
/src/jump_table/dump.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 |
5 | #include
6 | #include "tinyformat.h"
7 |
8 | auto dump(const uint8_t* section_data, uint32_t section_addr, uint32_t section_size,
9 | uint32_t start_dumping_addr, uint32_t stop_dumping_addr, const std::string& output_file) -> void
10 | {
11 | try {
12 | if ((start_dumping_addr < section_addr) ||
13 | (stop_dumping_addr > section_addr + section_size)) throw 1;
14 |
15 | auto start_dumped_entry = (const uint8_t*)(section_data + (start_dumping_addr - section_addr));
16 | auto stop_dumped_entry = (const uint8_t*)(section_data + (stop_dumping_addr - section_addr));
17 |
18 | std::ofstream dumped_file(output_file.c_str(),
19 | std::ofstream::out | std::ofstream::binary | std::ofstream::trunc);
20 |
21 | // auto count = uint32_t{0};
22 | auto dumped_value = *start_dumped_entry;
23 | tfm::format(dumped_file, "0x%x", dumped_value);
24 | for (auto dumped_entry = start_dumped_entry + 1; dumped_entry < stop_dumped_entry; ++dumped_entry) {
25 | dumped_value = *dumped_entry;
26 | tfm::format(dumped_file, ";0x%x", dumped_value);
27 | // ++count; if (count % 32 == 0) tfm::format(dumped_file, "\n");
28 | }
29 |
30 | dumped_file.close();
31 | } catch (int e) {
32 | tfm::printfln("[start, stop) range must be located in section");
33 | }
34 | catch (const std::exception& expt) {
35 | tfm::printfln("%s", expt.what());
36 | }
37 |
38 | return;
39 | }
40 |
--------------------------------------------------------------------------------
/src/jump_table/elfio/elfio_dynamic.hpp:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (C) 2001-2015 by Serge Lamikhov-Center
3 |
4 | Permission is hereby granted, free of charge, to any person obtaining a copy
5 | of this software and associated documentation files (the "Software"), to deal
6 | in the Software without restriction, including without limitation the rights
7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 | copies of the Software, and to permit persons to whom the Software is
9 | furnished to do so, subject to the following conditions:
10 |
11 | The above copyright notice and this permission notice shall be included in
12 | all copies or substantial portions of the Software.
13 |
14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20 | THE SOFTWARE.
21 | */
22 |
23 | #ifndef ELFIO_DYNAMIC_HPP
24 | #define ELFIO_DYNAMIC_HPP
25 |
26 | namespace ELFIO {
27 |
28 | //------------------------------------------------------------------------------
29 | class dynamic_section_accessor
30 | {
31 | public:
32 | //------------------------------------------------------------------------------
33 | dynamic_section_accessor( const elfio& elf_file_, section* section_ ) :
34 | elf_file( elf_file_ ),
35 | dynamic_section( section_ )
36 | {
37 | }
38 |
39 | //------------------------------------------------------------------------------
40 | Elf_Xword
41 | get_entries_num() const
42 | {
43 | Elf_Xword nRet = 0;
44 |
45 | if ( 0 != dynamic_section->get_entry_size() ) {
46 | nRet = dynamic_section->get_size() / dynamic_section->get_entry_size();
47 | }
48 |
49 | return nRet;
50 | }
51 |
52 | //------------------------------------------------------------------------------
53 | bool
54 | get_entry( Elf_Xword index,
55 | Elf_Xword& tag,
56 | Elf_Xword& value,
57 | std::string& str ) const
58 | {
59 | if ( index >= get_entries_num() ) { // Is index valid
60 | return false;
61 | }
62 |
63 | if ( elf_file.get_class() == ELFCLASS32 ) {
64 | generic_get_entry_dyn< Elf32_Dyn >( index, tag, value );
65 | }
66 | else {
67 | generic_get_entry_dyn< Elf64_Dyn >( index, tag, value );
68 | }
69 |
70 | // If the tag may have a string table reference, prepare the string
71 | if ( tag == DT_NEEDED ||
72 | tag == DT_SONAME ||
73 | tag == DT_RPATH ||
74 | tag == DT_RUNPATH ) {
75 | string_section_accessor strsec =
76 | elf_file.sections[ get_string_table_index() ];
77 | str = strsec.get_string( value );
78 | }
79 | else {
80 | str.clear();
81 | }
82 |
83 | return true;
84 | }
85 |
86 | //------------------------------------------------------------------------------
87 | void
88 | add_entry( Elf_Xword& tag,
89 | Elf_Xword& value )
90 | {
91 | if ( elf_file.get_class() == ELFCLASS32 ) {
92 | generic_add_entry< Elf32_Dyn >( tag, value );
93 | }
94 | else {
95 | generic_add_entry< Elf64_Dyn >( tag, value );
96 | }
97 | }
98 |
99 | //------------------------------------------------------------------------------
100 | void
101 | add_entry( Elf_Xword& tag,
102 | std::string& str )
103 | {
104 | string_section_accessor strsec =
105 | elf_file.sections[ get_string_table_index() ];
106 | Elf_Xword value = strsec.add_string( str );
107 | add_entry( tag, value );
108 | }
109 |
110 | //------------------------------------------------------------------------------
111 | private:
112 | //------------------------------------------------------------------------------
113 | Elf_Half
114 | get_string_table_index() const
115 | {
116 | return (Elf_Half)dynamic_section->get_link();
117 | }
118 |
119 | //------------------------------------------------------------------------------
120 | template< class T >
121 | void
122 | generic_get_entry_dyn( Elf_Xword index,
123 | Elf_Xword& tag,
124 | Elf_Xword& value ) const
125 | {
126 | const endianess_convertor& convertor = elf_file.get_convertor();
127 |
128 | // Check unusual case when dynamic section has no data
129 | if( dynamic_section->get_data() == 0 ||
130 | ( index + 1 ) * dynamic_section->get_entry_size() > dynamic_section->get_size() ) {
131 | tag = DT_NULL;
132 | value = 0;
133 | return;
134 | }
135 |
136 | const T* pEntry = reinterpret_cast(
137 | dynamic_section->get_data() +
138 | index * dynamic_section->get_entry_size() );
139 | tag = convertor( pEntry->d_tag );
140 | switch ( tag ) {
141 | case DT_NULL:
142 | case DT_SYMBOLIC:
143 | case DT_TEXTREL:
144 | case DT_BIND_NOW:
145 | value = 0;
146 | break;
147 | case DT_NEEDED:
148 | case DT_PLTRELSZ:
149 | case DT_RELASZ:
150 | case DT_RELAENT:
151 | case DT_STRSZ:
152 | case DT_SYMENT:
153 | case DT_SONAME:
154 | case DT_RPATH:
155 | case DT_RELSZ:
156 | case DT_RELENT:
157 | case DT_PLTREL:
158 | case DT_INIT_ARRAYSZ:
159 | case DT_FINI_ARRAYSZ:
160 | case DT_RUNPATH:
161 | case DT_FLAGS:
162 | case DT_PREINIT_ARRAYSZ:
163 | value = convertor( pEntry->d_un.d_val );
164 | break;
165 | case DT_PLTGOT:
166 | case DT_HASH:
167 | case DT_STRTAB:
168 | case DT_SYMTAB:
169 | case DT_RELA:
170 | case DT_INIT:
171 | case DT_FINI:
172 | case DT_REL:
173 | case DT_DEBUG:
174 | case DT_JMPREL:
175 | case DT_INIT_ARRAY:
176 | case DT_FINI_ARRAY:
177 | case DT_PREINIT_ARRAY:
178 | default:
179 | value = convertor( pEntry->d_un.d_ptr );
180 | break;
181 | }
182 | }
183 |
184 | //------------------------------------------------------------------------------
185 | template< class T >
186 | void
187 | generic_add_entry( Elf_Xword tag, Elf_Xword value )
188 | {
189 | const endianess_convertor& convertor = elf_file.get_convertor();
190 |
191 | T entry;
192 |
193 | switch ( tag ) {
194 | case DT_NULL:
195 | case DT_SYMBOLIC:
196 | case DT_TEXTREL:
197 | case DT_BIND_NOW:
198 | value = 0;
199 | case DT_NEEDED:
200 | case DT_PLTRELSZ:
201 | case DT_RELASZ:
202 | case DT_RELAENT:
203 | case DT_STRSZ:
204 | case DT_SYMENT:
205 | case DT_SONAME:
206 | case DT_RPATH:
207 | case DT_RELSZ:
208 | case DT_RELENT:
209 | case DT_PLTREL:
210 | case DT_INIT_ARRAYSZ:
211 | case DT_FINI_ARRAYSZ:
212 | case DT_RUNPATH:
213 | case DT_FLAGS:
214 | case DT_PREINIT_ARRAYSZ:
215 | entry.d_un.d_val = convertor( value );
216 | break;
217 | case DT_PLTGOT:
218 | case DT_HASH:
219 | case DT_STRTAB:
220 | case DT_SYMTAB:
221 | case DT_RELA:
222 | case DT_INIT:
223 | case DT_FINI:
224 | case DT_REL:
225 | case DT_DEBUG:
226 | case DT_JMPREL:
227 | case DT_INIT_ARRAY:
228 | case DT_FINI_ARRAY:
229 | case DT_PREINIT_ARRAY:
230 | default:
231 | entry.d_un.d_ptr = convertor( value );
232 | break;
233 | }
234 |
235 | entry.d_tag = convertor( tag );
236 |
237 | dynamic_section->append_data( reinterpret_cast( &entry ), sizeof( entry ) );
238 | }
239 |
240 | //------------------------------------------------------------------------------
241 | private:
242 | const elfio& elf_file;
243 | section* dynamic_section;
244 | };
245 |
246 | } // namespace ELFIO
247 |
248 | #endif // ELFIO_DYNAMIC_HPP
249 |
--------------------------------------------------------------------------------
/src/jump_table/elfio/elfio_header.hpp:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (C) 2001-2015 by Serge Lamikhov-Center
3 |
4 | Permission is hereby granted, free of charge, to any person obtaining a copy
5 | of this software and associated documentation files (the "Software"), to deal
6 | in the Software without restriction, including without limitation the rights
7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 | copies of the Software, and to permit persons to whom the Software is
9 | furnished to do so, subject to the following conditions:
10 |
11 | The above copyright notice and this permission notice shall be included in
12 | all copies or substantial portions of the Software.
13 |
14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20 | THE SOFTWARE.
21 | */
22 |
23 | #ifndef ELF_HEADER_HPP
24 | #define ELF_HEADER_HPP
25 |
26 | #include
27 |
28 | namespace ELFIO {
29 |
30 | class elf_header
31 | {
32 | public:
33 | virtual ~elf_header() {};
34 | virtual bool load( std::istream& stream ) = 0;
35 | virtual bool save( std::ostream& stream ) const = 0;
36 |
37 | // ELF header functions
38 | ELFIO_GET_ACCESS_DECL( unsigned char, class );
39 | ELFIO_GET_ACCESS_DECL( unsigned char, elf_version );
40 | ELFIO_GET_ACCESS_DECL( unsigned char, encoding );
41 | ELFIO_GET_ACCESS_DECL( Elf_Word, version );
42 | ELFIO_GET_ACCESS_DECL( Elf_Half, header_size );
43 | ELFIO_GET_ACCESS_DECL( Elf_Half, section_entry_size );
44 | ELFIO_GET_ACCESS_DECL( Elf_Half, segment_entry_size );
45 |
46 | ELFIO_GET_SET_ACCESS_DECL( unsigned char, os_abi );
47 | ELFIO_GET_SET_ACCESS_DECL( unsigned char, abi_version );
48 | ELFIO_GET_SET_ACCESS_DECL( Elf_Half, type );
49 | ELFIO_GET_SET_ACCESS_DECL( Elf_Half, machine );
50 | ELFIO_GET_SET_ACCESS_DECL( Elf_Word, flags );
51 | ELFIO_GET_SET_ACCESS_DECL( Elf64_Addr, entry );
52 | ELFIO_GET_SET_ACCESS_DECL( Elf_Half, sections_num );
53 | ELFIO_GET_SET_ACCESS_DECL( Elf64_Off, sections_offset );
54 | ELFIO_GET_SET_ACCESS_DECL( Elf_Half, segments_num );
55 | ELFIO_GET_SET_ACCESS_DECL( Elf64_Off, segments_offset );
56 | ELFIO_GET_SET_ACCESS_DECL( Elf_Half, section_name_str_index );
57 | };
58 |
59 |
60 | template< class T > struct elf_header_impl_types;
61 | template<> struct elf_header_impl_types {
62 | typedef Elf32_Phdr Phdr_type;
63 | typedef Elf32_Shdr Shdr_type;
64 | static const unsigned char file_class = ELFCLASS32;
65 | };
66 | template<> struct elf_header_impl_types {
67 | typedef Elf64_Phdr Phdr_type;
68 | typedef Elf64_Shdr Shdr_type;
69 | static const unsigned char file_class = ELFCLASS64;
70 | };
71 |
72 | template< class T > class elf_header_impl : public elf_header
73 | {
74 | public:
75 | elf_header_impl( endianess_convertor* convertor_,
76 | unsigned char encoding )
77 | {
78 | convertor = convertor_;
79 |
80 | std::fill_n( reinterpret_cast( &header ), sizeof( header ), '\0' );
81 |
82 | header.e_ident[EI_MAG0] = ELFMAG0;
83 | header.e_ident[EI_MAG1] = ELFMAG1;
84 | header.e_ident[EI_MAG2] = ELFMAG2;
85 | header.e_ident[EI_MAG3] = ELFMAG3;
86 | header.e_ident[EI_CLASS] = elf_header_impl_types::file_class;
87 | header.e_ident[EI_DATA] = encoding;
88 | header.e_ident[EI_VERSION] = EV_CURRENT;
89 | header.e_version = EV_CURRENT;
90 | header.e_version = (*convertor)( header.e_version );
91 | header.e_ehsize = ( sizeof( header ) );
92 | header.e_ehsize = (*convertor)( header.e_ehsize );
93 | header.e_shstrndx = (*convertor)( (Elf_Half)1 );
94 | header.e_phentsize = sizeof( typename elf_header_impl_types::Phdr_type );
95 | header.e_shentsize = sizeof( typename elf_header_impl_types::Shdr_type );
96 | header.e_phentsize = (*convertor)( header.e_phentsize );
97 | header.e_shentsize = (*convertor)( header.e_shentsize );
98 | }
99 |
100 | bool
101 | load( std::istream& stream )
102 | {
103 | stream.seekg( 0 );
104 | stream.read( reinterpret_cast( &header ), sizeof( header ) );
105 |
106 | return (stream.gcount() == sizeof( header ) );
107 | }
108 |
109 | bool
110 | save( std::ostream& stream ) const
111 | {
112 | stream.seekp( 0 );
113 | stream.write( reinterpret_cast( &header ), sizeof( header ) );
114 |
115 | return stream.good();
116 | }
117 |
118 | // ELF header functions
119 | ELFIO_GET_ACCESS( unsigned char, class, header.e_ident[EI_CLASS] );
120 | ELFIO_GET_ACCESS( unsigned char, elf_version, header.e_ident[EI_VERSION] );
121 | ELFIO_GET_ACCESS( unsigned char, encoding, header.e_ident[EI_DATA] );
122 | ELFIO_GET_ACCESS( Elf_Word, version, header.e_version );
123 | ELFIO_GET_ACCESS( Elf_Half, header_size, header.e_ehsize );
124 | ELFIO_GET_ACCESS( Elf_Half, section_entry_size, header.e_shentsize );
125 | ELFIO_GET_ACCESS( Elf_Half, segment_entry_size, header.e_phentsize );
126 |
127 | ELFIO_GET_SET_ACCESS( unsigned char, os_abi, header.e_ident[EI_OSABI] );
128 | ELFIO_GET_SET_ACCESS( unsigned char, abi_version, header.e_ident[EI_ABIVERSION] );
129 | ELFIO_GET_SET_ACCESS( Elf_Half, type, header.e_type );
130 | ELFIO_GET_SET_ACCESS( Elf_Half, machine, header.e_machine );
131 | ELFIO_GET_SET_ACCESS( Elf_Word, flags, header.e_flags );
132 | ELFIO_GET_SET_ACCESS( Elf_Half, section_name_str_index, header.e_shstrndx );
133 | ELFIO_GET_SET_ACCESS( Elf64_Addr, entry, header.e_entry );
134 | ELFIO_GET_SET_ACCESS( Elf_Half, sections_num, header.e_shnum );
135 | ELFIO_GET_SET_ACCESS( Elf64_Off, sections_offset, header.e_shoff );
136 | ELFIO_GET_SET_ACCESS( Elf_Half, segments_num, header.e_phnum );
137 | ELFIO_GET_SET_ACCESS( Elf64_Off, segments_offset, header.e_phoff );
138 |
139 | private:
140 | T header;
141 | endianess_convertor* convertor;
142 | };
143 |
144 | } // namespace ELFIO
145 |
146 | #endif // ELF_HEADER_HPP
147 |
--------------------------------------------------------------------------------
/src/jump_table/elfio/elfio_note.hpp:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (C) 2001-2015 by Serge Lamikhov-Center
3 |
4 | Permission is hereby granted, free of charge, to any person obtaining a copy
5 | of this software and associated documentation files (the "Software"), to deal
6 | in the Software without restriction, including without limitation the rights
7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 | copies of the Software, and to permit persons to whom the Software is
9 | furnished to do so, subject to the following conditions:
10 |
11 | The above copyright notice and this permission notice shall be included in
12 | all copies or substantial portions of the Software.
13 |
14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20 | THE SOFTWARE.
21 | */
22 |
23 | #ifndef ELFIO_NOTE_HPP
24 | #define ELFIO_NOTE_HPP
25 |
26 | namespace ELFIO {
27 |
28 | //------------------------------------------------------------------------------
29 | class note_section_accessor
30 | {
31 | public:
32 | //------------------------------------------------------------------------------
33 | note_section_accessor( const elfio& elf_file_, section* section_ ) :
34 | elf_file( elf_file_ ), note_section( section_ )
35 | {
36 | process_section();
37 | }
38 |
39 | //------------------------------------------------------------------------------
40 | Elf_Word
41 | get_notes_num() const
42 | {
43 | return (Elf_Word)note_start_positions.size();
44 | }
45 |
46 | //------------------------------------------------------------------------------
47 | bool
48 | get_note( Elf_Word index,
49 | Elf_Word& type,
50 | std::string& name,
51 | void*& desc,
52 | Elf_Word& descSize ) const
53 | {
54 | if ( index >= note_section->get_size() ) {
55 | return false;
56 | }
57 |
58 | const char* pData = note_section->get_data() + note_start_positions[index];
59 |
60 | const endianess_convertor& convertor = elf_file.get_convertor();
61 | type = convertor( *(Elf_Word*)( pData + 2*sizeof( Elf_Word ) ) );
62 | Elf_Word namesz = convertor( *(Elf_Word*)( pData ) );
63 | descSize = convertor( *(Elf_Word*)( pData + sizeof( namesz ) ) );
64 | Elf_Word max_name_size = note_section->get_size() - note_start_positions[index];
65 | if ( namesz > max_name_size ||
66 | namesz + descSize > max_name_size ) {
67 | return false;
68 | }
69 | name.assign( pData + 3 * sizeof( Elf_Word ), namesz );
70 | if ( 0 == descSize ) {
71 | desc = 0;
72 | }
73 | else {
74 | int align = sizeof( Elf_Xword );
75 | if ( elf_file.get_class() == ELFCLASS32 ) {
76 | align = sizeof( Elf_Word );
77 | }
78 | desc = const_cast ( pData + 3*sizeof( Elf_Word ) +
79 | ( ( namesz + align - 1 ) / align ) * align );
80 | }
81 |
82 | return true;
83 | }
84 |
85 | //------------------------------------------------------------------------------
86 | void add_note( Elf_Word type,
87 | const std::string& name,
88 | const void* desc,
89 | Elf_Word descSize )
90 | {
91 | const endianess_convertor& convertor = elf_file.get_convertor();
92 |
93 | Elf_Word nameLen = (Elf_Word)name.size() + 1;
94 | Elf_Word nameLenConv = convertor( nameLen );
95 | std::string buffer( reinterpret_cast( &nameLenConv ), sizeof( nameLenConv ) );
96 | Elf_Word descSizeConv = convertor( descSize );
97 | buffer.append( reinterpret_cast( &descSizeConv ), sizeof( descSizeConv ) );
98 | type = convertor( type );
99 | buffer.append( reinterpret_cast( &type ), sizeof( type ) );
100 | buffer.append( name );
101 | buffer.append( 1, '\x00' );
102 | const char pad[] = { '\0', '\0', '\0', '\0' };
103 | if ( nameLen % sizeof( Elf_Word ) != 0 ) {
104 | buffer.append( pad, sizeof( Elf_Word ) -
105 | nameLen % sizeof( Elf_Word ) );
106 | }
107 | if ( desc != 0 && descSize != 0 ) {
108 | buffer.append( reinterpret_cast( desc ), descSize );
109 | if ( descSize % sizeof( Elf_Word ) != 0 ) {
110 | buffer.append( pad, sizeof( Elf_Word ) -
111 | descSize % sizeof( Elf_Word ) );
112 | }
113 | }
114 |
115 | note_start_positions.push_back( note_section->get_size() );
116 | note_section->append_data( buffer );
117 | }
118 |
119 | private:
120 | //------------------------------------------------------------------------------
121 | void process_section()
122 | {
123 | const endianess_convertor& convertor = elf_file.get_convertor();
124 | const char* data = note_section->get_data();
125 | Elf_Xword size = note_section->get_size();
126 | Elf_Xword current = 0;
127 |
128 | note_start_positions.clear();
129 |
130 | // Is it empty?
131 | if ( 0 == data || 0 == size ) {
132 | return;
133 | }
134 |
135 | while ( current + 3*sizeof( Elf_Word ) <= size ) {
136 | note_start_positions.push_back( current );
137 | Elf_Word namesz = convertor(
138 | *(Elf_Word*)( data + current ) );
139 | Elf_Word descsz = convertor(
140 | *(Elf_Word*)( data + current + sizeof( namesz ) ) );
141 |
142 | int align = sizeof( Elf_Xword );
143 | if ( elf_file.get_class() == ELFCLASS32 ) {
144 | align = sizeof( Elf_Word );
145 | }
146 |
147 | current += 3*sizeof( Elf_Word ) +
148 | ( ( namesz + align - 1 ) / align ) * align +
149 | ( ( descsz + align - 1 ) / align ) * align;
150 | }
151 | }
152 |
153 | //------------------------------------------------------------------------------
154 | private:
155 | const elfio& elf_file;
156 | section* note_section;
157 | std::vector note_start_positions;
158 | };
159 |
160 | } // namespace ELFIO
161 |
162 | #endif // ELFIO_NOTE_HPP
163 |
--------------------------------------------------------------------------------
/src/jump_table/elfio/elfio_relocation.hpp:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (C) 2001-2015 by Serge Lamikhov-Center
3 |
4 | Permission is hereby granted, free of charge, to any person obtaining a copy
5 | of this software and associated documentation files (the "Software"), to deal
6 | in the Software without restriction, including without limitation the rights
7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 | copies of the Software, and to permit persons to whom the Software is
9 | furnished to do so, subject to the following conditions:
10 |
11 | The above copyright notice and this permission notice shall be included in
12 | all copies or substantial portions of the Software.
13 |
14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20 | THE SOFTWARE.
21 | */
22 |
23 | #ifndef ELFIO_RELOCATION_HPP
24 | #define ELFIO_RELOCATION_HPP
25 |
26 | namespace ELFIO {
27 |
28 | template struct get_sym_and_type;
29 | template<> struct get_sym_and_type< Elf32_Rel >
30 | {
31 | static int get_r_sym( Elf_Xword info )
32 | {
33 | return ELF32_R_SYM( (Elf_Word)info );
34 | }
35 | static int get_r_type( Elf_Xword info )
36 | {
37 | return ELF32_R_TYPE( (Elf_Word)info );
38 | }
39 | };
40 | template<> struct get_sym_and_type< Elf32_Rela >
41 | {
42 | static int get_r_sym( Elf_Xword info )
43 | {
44 | return ELF32_R_SYM( (Elf_Word)info );
45 | }
46 | static int get_r_type( Elf_Xword info )
47 | {
48 | return ELF32_R_TYPE( (Elf_Word)info );
49 | }
50 | };
51 | template<> struct get_sym_and_type< Elf64_Rel >
52 | {
53 | static int get_r_sym( Elf_Xword info )
54 | {
55 | return ELF64_R_SYM( info );
56 | }
57 | static int get_r_type( Elf_Xword info )
58 | {
59 | return ELF64_R_TYPE( info );
60 | }
61 | };
62 | template<> struct get_sym_and_type< Elf64_Rela >
63 | {
64 | static int get_r_sym( Elf_Xword info )
65 | {
66 | return ELF64_R_SYM( info );
67 | }
68 | static int get_r_type( Elf_Xword info )
69 | {
70 | return ELF64_R_TYPE( info );
71 | }
72 | };
73 |
74 |
75 | //------------------------------------------------------------------------------
76 | class relocation_section_accessor
77 | {
78 | public:
79 | //------------------------------------------------------------------------------
80 | relocation_section_accessor( const elfio& elf_file_, section* section_ ) :
81 | elf_file( elf_file_ ),
82 | relocation_section( section_ )
83 | {
84 | }
85 |
86 | //------------------------------------------------------------------------------
87 | Elf_Xword
88 | get_entries_num() const
89 | {
90 | Elf_Xword nRet = 0;
91 |
92 | if ( 0 != relocation_section->get_entry_size() ) {
93 | nRet = relocation_section->get_size() / relocation_section->get_entry_size();
94 | }
95 |
96 | return nRet;
97 | }
98 |
99 | //------------------------------------------------------------------------------
100 | bool
101 | get_entry( Elf_Xword index,
102 | Elf64_Addr& offset,
103 | Elf_Word& symbol,
104 | Elf_Word& type,
105 | Elf_Sxword& addend ) const
106 | {
107 | if ( index >= get_entries_num() ) { // Is index valid
108 | return false;
109 | }
110 |
111 | if ( elf_file.get_class() == ELFCLASS32 ) {
112 | if ( SHT_REL == relocation_section->get_type() ) {
113 | generic_get_entry_rel< Elf32_Rel >( index, offset, symbol,
114 | type, addend );
115 | }
116 | else if ( SHT_RELA == relocation_section->get_type() ) {
117 | generic_get_entry_rela< Elf32_Rela >( index, offset, symbol,
118 | type, addend );
119 | }
120 | }
121 | else {
122 | if ( SHT_REL == relocation_section->get_type() ) {
123 | generic_get_entry_rel< Elf64_Rel >( index, offset, symbol,
124 | type, addend );
125 | }
126 | else if ( SHT_RELA == relocation_section->get_type() ) {
127 | generic_get_entry_rela< Elf64_Rela >( index, offset, symbol,
128 | type, addend );
129 | }
130 | }
131 |
132 | return true;
133 | }
134 |
135 | //------------------------------------------------------------------------------
136 | bool
137 | get_entry( Elf_Xword index,
138 | Elf64_Addr& offset,
139 | Elf64_Addr& symbolValue,
140 | std::string& symbolName,
141 | Elf_Word& type,
142 | Elf_Sxword& addend,
143 | Elf_Sxword& calcValue ) const
144 | {
145 | // Do regular job
146 | Elf_Word symbol;
147 | bool ret = get_entry( index, offset, symbol, type, addend );
148 |
149 | // Find the symbol
150 | Elf_Xword size;
151 | unsigned char bind;
152 | unsigned char symbolType;
153 | Elf_Half section;
154 | unsigned char other;
155 |
156 | symbol_section_accessor symbols( elf_file, elf_file.sections[get_symbol_table_index()] );
157 | ret = symbols.get_symbol( symbol, symbolName, symbolValue,
158 | size, bind, symbolType, section, other );
159 |
160 | if ( ret ) { // Was it successful?
161 | switch ( type ) {
162 | case R_386_NONE: // none
163 | calcValue = 0;
164 | break;
165 | case R_386_32: // S + A
166 | calcValue = symbolValue + addend;
167 | break;
168 | case R_386_PC32: // S + A - P
169 | calcValue = symbolValue + addend - offset;
170 | break;
171 | case R_386_GOT32: // G + A - P
172 | calcValue = 0;
173 | break;
174 | case R_386_PLT32: // L + A - P
175 | calcValue = 0;
176 | break;
177 | case R_386_COPY: // none
178 | calcValue = 0;
179 | break;
180 | case R_386_GLOB_DAT: // S
181 | case R_386_JMP_SLOT: // S
182 | calcValue = symbolValue;
183 | break;
184 | case R_386_RELATIVE: // B + A
185 | calcValue = addend;
186 | break;
187 | case R_386_GOTOFF: // S + A - GOT
188 | calcValue = 0;
189 | break;
190 | case R_386_GOTPC: // GOT + A - P
191 | calcValue = 0;
192 | break;
193 | default: // Not recognized symbol!
194 | calcValue = 0;
195 | break;
196 | }
197 | }
198 |
199 | return ret;
200 | }
201 |
202 | //------------------------------------------------------------------------------
203 | void
204 | add_entry( Elf64_Addr offset, Elf_Xword info )
205 | {
206 | if ( elf_file.get_class() == ELFCLASS32 ) {
207 | generic_add_entry< Elf32_Rel >( offset, info );
208 | }
209 | else {
210 | generic_add_entry< Elf64_Rel >( offset, info );
211 | }
212 | }
213 |
214 | //------------------------------------------------------------------------------
215 | void
216 | add_entry( Elf64_Addr offset, Elf_Word symbol, unsigned char type )
217 | {
218 | Elf_Xword info;
219 | if ( elf_file.get_class() == ELFCLASS32 ) {
220 | info = ELF32_R_INFO( symbol, type );
221 | }
222 | else {
223 | info = ELF64_R_INFO( symbol, type );
224 | }
225 |
226 | add_entry( offset, info );
227 | }
228 |
229 | //------------------------------------------------------------------------------
230 | void
231 | add_entry( Elf64_Addr offset, Elf_Xword info, Elf_Sxword addend )
232 | {
233 | if ( elf_file.get_class() == ELFCLASS32 ) {
234 | generic_add_entry< Elf32_Rela >( offset, info, addend );
235 | }
236 | else {
237 | generic_add_entry< Elf64_Rela >( offset, info, addend );
238 | }
239 | }
240 |
241 | //------------------------------------------------------------------------------
242 | void
243 | add_entry( Elf64_Addr offset, Elf_Word symbol, unsigned char type,
244 | Elf_Sxword addend )
245 | {
246 | Elf_Xword info;
247 | if ( elf_file.get_class() == ELFCLASS32 ) {
248 | info = ELF32_R_INFO( symbol, type );
249 | }
250 | else {
251 | info = ELF64_R_INFO( symbol, type );
252 | }
253 |
254 | add_entry( offset, info, addend );
255 | }
256 |
257 | //------------------------------------------------------------------------------
258 | void
259 | add_entry( string_section_accessor str_writer,
260 | const char* str,
261 | symbol_section_accessor sym_writer,
262 | Elf64_Addr value,
263 | Elf_Word size,
264 | unsigned char sym_info,
265 | unsigned char other,
266 | Elf_Half shndx,
267 | Elf64_Addr offset,
268 | unsigned char type )
269 | {
270 | Elf_Word str_index = str_writer.add_string( str );
271 | Elf_Word sym_index = sym_writer.add_symbol( str_index, value, size,
272 | sym_info, other, shndx );
273 | add_entry( offset, sym_index, type );
274 | }
275 |
276 | //------------------------------------------------------------------------------
277 | private:
278 | //------------------------------------------------------------------------------
279 | Elf_Half
280 | get_symbol_table_index() const
281 | {
282 | return (Elf_Half)relocation_section->get_link();
283 | }
284 |
285 | //------------------------------------------------------------------------------
286 | template< class T >
287 | void
288 | generic_get_entry_rel( Elf_Xword index,
289 | Elf64_Addr& offset,
290 | Elf_Word& symbol,
291 | Elf_Word& type,
292 | Elf_Sxword& addend ) const
293 | {
294 | const endianess_convertor& convertor = elf_file.get_convertor();
295 |
296 | const T* pEntry = reinterpret_cast(
297 | relocation_section->get_data() +
298 | index * relocation_section->get_entry_size() );
299 | offset = convertor( pEntry->r_offset );
300 | Elf_Xword tmp = convertor( pEntry->r_info );
301 | symbol = get_sym_and_type::get_r_sym( tmp );
302 | type = get_sym_and_type::get_r_type( tmp );
303 | addend = 0;
304 | }
305 |
306 | //------------------------------------------------------------------------------
307 | template< class T >
308 | void
309 | generic_get_entry_rela( Elf_Xword index,
310 | Elf64_Addr& offset,
311 | Elf_Word& symbol,
312 | Elf_Word& type,
313 | Elf_Sxword& addend ) const
314 | {
315 | const endianess_convertor& convertor = elf_file.get_convertor();
316 |
317 | const T* pEntry = reinterpret_cast(
318 | relocation_section->get_data() +
319 | index * relocation_section->get_entry_size() );
320 | offset = convertor( pEntry->r_offset );
321 | Elf_Xword tmp = convertor( pEntry->r_info );
322 | symbol = get_sym_and_type::get_r_sym( tmp );
323 | type = get_sym_and_type::get_r_type( tmp );
324 | addend = convertor( pEntry->r_addend );
325 | }
326 |
327 | //------------------------------------------------------------------------------
328 | template< class T >
329 | void
330 | generic_add_entry( Elf64_Addr offset, Elf_Xword info )
331 | {
332 | const endianess_convertor& convertor = elf_file.get_convertor();
333 |
334 | T entry;
335 | entry.r_offset = offset;
336 | entry.r_info = info;
337 | entry.r_offset = convertor( entry.r_offset );
338 | entry.r_info = convertor( entry.r_info );
339 |
340 | relocation_section->append_data( reinterpret_cast( &entry ), sizeof( entry ) );
341 | }
342 |
343 | //------------------------------------------------------------------------------
344 | template< class T >
345 | void
346 | generic_add_entry( Elf64_Addr offset, Elf_Xword info, Elf_Sxword addend )
347 | {
348 | const endianess_convertor& convertor = elf_file.get_convertor();
349 |
350 | T entry;
351 | entry.r_offset = offset;
352 | entry.r_info = info;
353 | entry.r_addend = addend;
354 | entry.r_offset = convertor( entry.r_offset );
355 | entry.r_info = convertor( entry.r_info );
356 | entry.r_addend = convertor( entry.r_addend );
357 |
358 | relocation_section->append_data( reinterpret_cast( &entry ), sizeof( entry ) );
359 | }
360 |
361 | //------------------------------------------------------------------------------
362 | private:
363 | const elfio& elf_file;
364 | section* relocation_section;
365 | };
366 |
367 | } // namespace ELFIO
368 |
369 | #endif // ELFIO_RELOCATION_HPP
370 |
--------------------------------------------------------------------------------
/src/jump_table/elfio/elfio_section.hpp:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (C) 2001-2015 by Serge Lamikhov-Center
3 |
4 | Permission is hereby granted, free of charge, to any person obtaining a copy
5 | of this software and associated documentation files (the "Software"), to deal
6 | in the Software without restriction, including without limitation the rights
7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 | copies of the Software, and to permit persons to whom the Software is
9 | furnished to do so, subject to the following conditions:
10 |
11 | The above copyright notice and this permission notice shall be included in
12 | all copies or substantial portions of the Software.
13 |
14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20 | THE SOFTWARE.
21 | */
22 |
23 | #ifndef ELFIO_SECTION_HPP
24 | #define ELFIO_SECTION_HPP
25 |
26 | #include
27 | #include
28 |
29 | namespace ELFIO {
30 |
31 | class section
32 | {
33 | friend class elfio;
34 | public:
35 | virtual ~section() {};
36 |
37 | ELFIO_GET_ACCESS_DECL ( Elf_Half, index );
38 | ELFIO_GET_SET_ACCESS_DECL( std::string, name );
39 | ELFIO_GET_SET_ACCESS_DECL( Elf_Word, type );
40 | ELFIO_GET_SET_ACCESS_DECL( Elf_Xword, flags );
41 | ELFIO_GET_SET_ACCESS_DECL( Elf_Word, info );
42 | ELFIO_GET_SET_ACCESS_DECL( Elf_Word, link );
43 | ELFIO_GET_SET_ACCESS_DECL( Elf_Xword, addr_align );
44 | ELFIO_GET_SET_ACCESS_DECL( Elf_Xword, entry_size );
45 | ELFIO_GET_SET_ACCESS_DECL( Elf64_Addr, address );
46 | ELFIO_GET_SET_ACCESS_DECL( Elf_Xword, size );
47 | ELFIO_GET_SET_ACCESS_DECL( Elf_Word, name_string_offset );
48 |
49 | virtual const char* get_data() const = 0;
50 | virtual void set_data( const char* pData, Elf_Word size ) = 0;
51 | virtual void set_data( const std::string& data ) = 0;
52 | virtual void append_data( const char* pData, Elf_Word size ) = 0;
53 | virtual void append_data( const std::string& data ) = 0;
54 |
55 | protected:
56 | ELFIO_GET_SET_ACCESS_DECL( Elf64_Off, offset );
57 | ELFIO_SET_ACCESS_DECL( Elf_Half, index );
58 |
59 | virtual void load( std::istream& f,
60 | std::streampos header_offset ) = 0;
61 | virtual void save( std::ostream& f,
62 | std::streampos header_offset,
63 | std::streampos data_offset ) = 0;
64 | virtual bool is_address_initialized() const = 0;
65 | };
66 |
67 |
68 | template< class T >
69 | class section_impl : public section
70 | {
71 | public:
72 | //------------------------------------------------------------------------------
73 | section_impl( const endianess_convertor* convertor_ ) : convertor( convertor_ )
74 | {
75 | std::fill_n( reinterpret_cast( &header ), sizeof( header ), '\0' );
76 | is_address_set = false;
77 | data = 0;
78 | data_size = 0;
79 | }
80 |
81 | //------------------------------------------------------------------------------
82 | ~section_impl()
83 | {
84 | delete [] data;
85 | }
86 |
87 | //------------------------------------------------------------------------------
88 | // Section info functions
89 | ELFIO_GET_SET_ACCESS( Elf_Word, type, header.sh_type );
90 | ELFIO_GET_SET_ACCESS( Elf_Xword, flags, header.sh_flags );
91 | ELFIO_GET_SET_ACCESS( Elf_Xword, size, header.sh_size );
92 | ELFIO_GET_SET_ACCESS( Elf_Word, link, header.sh_link );
93 | ELFIO_GET_SET_ACCESS( Elf_Word, info, header.sh_info );
94 | ELFIO_GET_SET_ACCESS( Elf_Xword, addr_align, header.sh_addralign );
95 | ELFIO_GET_SET_ACCESS( Elf_Xword, entry_size, header.sh_entsize );
96 | ELFIO_GET_SET_ACCESS( Elf_Word, name_string_offset, header.sh_name );
97 | ELFIO_GET_ACCESS ( Elf64_Addr, address, header.sh_addr );
98 |
99 | //------------------------------------------------------------------------------
100 | Elf_Half
101 | get_index() const
102 | {
103 | return index;
104 | }
105 |
106 |
107 | //------------------------------------------------------------------------------
108 | std::string
109 | get_name() const
110 | {
111 | return name;
112 | }
113 |
114 | //------------------------------------------------------------------------------
115 | void
116 | set_name( std::string name_ )
117 | {
118 | name = name_;
119 | }
120 |
121 | //------------------------------------------------------------------------------
122 | void
123 | set_address( Elf64_Addr value )
124 | {
125 | header.sh_addr = value;
126 | header.sh_addr = (*convertor)( header.sh_addr );
127 | is_address_set = true;
128 | }
129 |
130 | //------------------------------------------------------------------------------
131 | bool
132 | is_address_initialized() const
133 | {
134 | return is_address_set;
135 | }
136 |
137 | //------------------------------------------------------------------------------
138 | const char*
139 | get_data() const
140 | {
141 | return data;
142 | }
143 |
144 | //------------------------------------------------------------------------------
145 | void
146 | set_data( const char* raw_data, Elf_Word size )
147 | {
148 | if ( get_type() != SHT_NOBITS ) {
149 | delete [] data;
150 | data = new char[size];
151 | if ( 0 != data && 0 != raw_data ) {
152 | data_size = size;
153 | std::copy( raw_data, raw_data + size, data );
154 | }
155 | }
156 |
157 | set_size( size );
158 | }
159 |
160 | //------------------------------------------------------------------------------
161 | void
162 | set_data( const std::string& str_data )
163 | {
164 | return set_data( str_data.c_str(), (Elf_Word)str_data.size() );
165 | }
166 |
167 | //------------------------------------------------------------------------------
168 | void
169 | append_data( const char* raw_data, Elf_Word size )
170 | {
171 | if ( get_type() != SHT_NOBITS ) {
172 | if ( get_size() + size < data_size ) {
173 | std::copy( raw_data, raw_data + size, data + get_size() );
174 | }
175 | else {
176 | data_size = 2*( data_size + size);
177 | char* new_data = new char[data_size];
178 | if ( 0 != new_data ) {
179 | std::copy( data, data + get_size(), new_data );
180 | std::copy( raw_data, raw_data + size, new_data + get_size() );
181 | delete [] data;
182 | data = new_data;
183 | }
184 | }
185 | set_size( get_size() + size );
186 | }
187 | }
188 |
189 | //------------------------------------------------------------------------------
190 | void
191 | append_data( const std::string& str_data )
192 | {
193 | return append_data( str_data.c_str(), (Elf_Word)str_data.size() );
194 | }
195 |
196 | //------------------------------------------------------------------------------
197 | protected:
198 | //------------------------------------------------------------------------------
199 | ELFIO_GET_SET_ACCESS( Elf64_Off, offset, header.sh_offset );
200 |
201 | //------------------------------------------------------------------------------
202 | void
203 | set_index( Elf_Half value )
204 | {
205 | index = value;
206 | }
207 |
208 | //------------------------------------------------------------------------------
209 | void
210 | load( std::istream& stream,
211 | std::streampos header_offset )
212 | {
213 | std::fill_n( reinterpret_cast( &header ), sizeof( header ), '\0' );
214 | stream.seekg( header_offset );
215 | stream.read( reinterpret_cast( &header ), sizeof( header ) );
216 |
217 | Elf_Xword size = get_size();
218 | if ( 0 == data && SHT_NULL != get_type() && SHT_NOBITS != get_type() ) {
219 | data = new char[size];
220 | if ( 0 != size ) {
221 | stream.seekg( (*convertor)( header.sh_offset ) );
222 | stream.read( data, size );
223 | data_size = size;
224 | }
225 | }
226 | }
227 |
228 | //------------------------------------------------------------------------------
229 | void
230 | save( std::ostream& f,
231 | std::streampos header_offset,
232 | std::streampos data_offset )
233 | {
234 | if ( 0 != get_index() ) {
235 | header.sh_offset = data_offset;
236 | header.sh_offset = (*convertor)( header.sh_offset );
237 | }
238 |
239 | save_header( f, header_offset );
240 | if ( get_type() != SHT_NOBITS && get_type() != SHT_NULL &&
241 | get_size() != 0 && data != 0 ) {
242 | save_data( f, data_offset );
243 | }
244 | }
245 |
246 | //------------------------------------------------------------------------------
247 | private:
248 | //------------------------------------------------------------------------------
249 | void
250 | save_header( std::ostream& f,
251 | std::streampos header_offset ) const
252 | {
253 | f.seekp( header_offset );
254 | f.write( reinterpret_cast( &header ), sizeof( header ) );
255 | }
256 |
257 | //------------------------------------------------------------------------------
258 | void
259 | save_data( std::ostream& f,
260 | std::streampos data_offset ) const
261 | {
262 | f.seekp( data_offset );
263 | f.write( get_data(), get_size() );
264 | }
265 |
266 | //------------------------------------------------------------------------------
267 | private:
268 | T header;
269 | Elf_Half index;
270 | std::string name;
271 | char* data;
272 | Elf_Word data_size;
273 | const endianess_convertor* convertor;
274 | bool is_address_set;
275 | };
276 |
277 | } // namespace ELFIO
278 |
279 | #endif // ELFIO_SECTION_HPP
280 |
--------------------------------------------------------------------------------
/src/jump_table/elfio/elfio_segment.hpp:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (C) 2001-2015 by Serge Lamikhov-Center
3 |
4 | Permission is hereby granted, free of charge, to any person obtaining a copy
5 | of this software and associated documentation files (the "Software"), to deal
6 | in the Software without restriction, including without limitation the rights
7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 | copies of the Software, and to permit persons to whom the Software is
9 | furnished to do so, subject to the following conditions:
10 |
11 | The above copyright notice and this permission notice shall be included in
12 | all copies or substantial portions of the Software.
13 |
14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20 | THE SOFTWARE.
21 | */
22 |
23 | #ifndef ELFIO_SEGMENT_HPP
24 | #define ELFIO_SEGMENT_HPP
25 |
26 | #include
27 | #include
28 |
29 | namespace ELFIO {
30 |
31 | class segment
32 | {
33 | friend class elfio;
34 | public:
35 | virtual ~segment() {};
36 |
37 | ELFIO_GET_ACCESS_DECL ( Elf_Half, index );
38 | ELFIO_GET_SET_ACCESS_DECL( Elf_Word, type );
39 | ELFIO_GET_SET_ACCESS_DECL( Elf_Word, flags );
40 | ELFIO_GET_SET_ACCESS_DECL( Elf_Xword, align );
41 | ELFIO_GET_SET_ACCESS_DECL( Elf64_Addr, virtual_address );
42 | ELFIO_GET_SET_ACCESS_DECL( Elf64_Addr, physical_address );
43 | ELFIO_GET_SET_ACCESS_DECL( Elf_Xword, file_size );
44 | ELFIO_GET_SET_ACCESS_DECL( Elf_Xword, memory_size );
45 | ELFIO_GET_ACCESS_DECL( Elf64_Off, offset );
46 |
47 | virtual const char* get_data() const = 0;
48 |
49 | virtual Elf_Half add_section_index( Elf_Half index, Elf_Xword addr_align ) = 0;
50 | virtual Elf_Half get_sections_num() const = 0;
51 | virtual Elf_Half get_section_index_at( Elf_Half num ) const = 0;
52 | virtual bool is_offset_initialized() const = 0;
53 |
54 | protected:
55 | ELFIO_SET_ACCESS_DECL( Elf64_Off, offset );
56 | ELFIO_SET_ACCESS_DECL( Elf_Half, index );
57 |
58 | virtual const std::vector& get_sections() const = 0;
59 | virtual void load( std::istream& stream, std::streampos header_offset ) = 0;
60 | virtual void save( std::ostream& f, std::streampos header_offset,
61 | std::streampos data_offset ) = 0;
62 | };
63 |
64 |
65 | //------------------------------------------------------------------------------
66 | template< class T >
67 | class segment_impl : public segment
68 | {
69 | public:
70 | //------------------------------------------------------------------------------
71 | segment_impl( endianess_convertor* convertor_ ) :
72 | convertor( convertor_ )
73 | {
74 | is_offset_set = false;
75 | std::fill_n( reinterpret_cast( &ph ), sizeof( ph ), '\0' );
76 | data = 0;
77 | }
78 |
79 | //------------------------------------------------------------------------------
80 | virtual ~segment_impl()
81 | {
82 | delete [] data;
83 | }
84 |
85 | //------------------------------------------------------------------------------
86 | // Section info functions
87 | ELFIO_GET_SET_ACCESS( Elf_Word, type, ph.p_type );
88 | ELFIO_GET_SET_ACCESS( Elf_Word, flags, ph.p_flags );
89 | ELFIO_GET_SET_ACCESS( Elf_Xword, align, ph.p_align );
90 | ELFIO_GET_SET_ACCESS( Elf64_Addr, virtual_address, ph.p_vaddr );
91 | ELFIO_GET_SET_ACCESS( Elf64_Addr, physical_address, ph.p_paddr );
92 | ELFIO_GET_SET_ACCESS( Elf_Xword, file_size, ph.p_filesz );
93 | ELFIO_GET_SET_ACCESS( Elf_Xword, memory_size, ph.p_memsz );
94 | ELFIO_GET_ACCESS( Elf64_Off, offset, ph.p_offset );
95 |
96 | //------------------------------------------------------------------------------
97 | Elf_Half
98 | get_index() const
99 | {
100 | return index;
101 | }
102 |
103 | //------------------------------------------------------------------------------
104 | const char*
105 | get_data() const
106 | {
107 | return data;
108 | }
109 |
110 | //------------------------------------------------------------------------------
111 | Elf_Half
112 | add_section_index( Elf_Half index, Elf_Xword addr_align )
113 | {
114 | sections.push_back( index );
115 | if ( addr_align > get_align() ) {
116 | set_align( addr_align );
117 | }
118 |
119 | return (Elf_Half)sections.size();
120 | }
121 |
122 | //------------------------------------------------------------------------------
123 | Elf_Half
124 | get_sections_num() const
125 | {
126 | return (Elf_Half)sections.size();
127 | }
128 |
129 | //------------------------------------------------------------------------------
130 | Elf_Half
131 | get_section_index_at( Elf_Half num ) const
132 | {
133 | if ( num < sections.size() ) {
134 | return sections[num];
135 | }
136 |
137 | return -1;
138 | }
139 |
140 | //------------------------------------------------------------------------------
141 | protected:
142 | //------------------------------------------------------------------------------
143 |
144 | //------------------------------------------------------------------------------
145 | void
146 | set_offset( Elf64_Off value )
147 | {
148 | ph.p_offset = value;
149 | ph.p_offset = (*convertor)( ph.p_offset );
150 | is_offset_set = true;
151 | }
152 |
153 | //------------------------------------------------------------------------------
154 | bool
155 | is_offset_initialized() const
156 | {
157 | return is_offset_set;
158 | }
159 |
160 | //------------------------------------------------------------------------------
161 | const std::vector&
162 | get_sections() const
163 | {
164 | return sections;
165 | }
166 |
167 | //------------------------------------------------------------------------------
168 | void
169 | set_index( Elf_Half value )
170 | {
171 | index = value;
172 | }
173 |
174 | //------------------------------------------------------------------------------
175 | void
176 | load( std::istream& stream,
177 | std::streampos header_offset )
178 | {
179 | stream.seekg( header_offset );
180 | stream.read( reinterpret_cast( &ph ), sizeof( ph ) );
181 | is_offset_set = true;
182 |
183 | if ( PT_NULL != get_type() && 0 != get_file_size() ) {
184 | stream.seekg( (*convertor)( ph.p_offset ) );
185 | Elf_Xword size = get_file_size();
186 | data = new char[size];
187 | if ( 0 != data ) {
188 | stream.read( data, size );
189 | }
190 | }
191 | }
192 |
193 | //------------------------------------------------------------------------------
194 | void save( std::ostream& f,
195 | std::streampos header_offset,
196 | std::streampos data_offset )
197 | {
198 | ph.p_offset = data_offset;
199 | ph.p_offset = (*convertor)(ph.p_offset);
200 | f.seekp( header_offset );
201 | f.write( reinterpret_cast( &ph ), sizeof( ph ) );
202 | }
203 |
204 | //------------------------------------------------------------------------------
205 | private:
206 | T ph;
207 | Elf_Half index;
208 | char* data;
209 | std::vector sections;
210 | endianess_convertor* convertor;
211 | bool is_offset_set;
212 | };
213 |
214 | } // namespace ELFIO
215 |
216 | #endif // ELFIO_SEGMENT_HPP
217 |
--------------------------------------------------------------------------------
/src/jump_table/elfio/elfio_strings.hpp:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (C) 2001-2015 by Serge Lamikhov-Center
3 |
4 | Permission is hereby granted, free of charge, to any person obtaining a copy
5 | of this software and associated documentation files (the "Software"), to deal
6 | in the Software without restriction, including without limitation the rights
7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 | copies of the Software, and to permit persons to whom the Software is
9 | furnished to do so, subject to the following conditions:
10 |
11 | The above copyright notice and this permission notice shall be included in
12 | all copies or substantial portions of the Software.
13 |
14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20 | THE SOFTWARE.
21 | */
22 |
23 | #ifndef ELFIO_STRINGS_HPP
24 | #define ELFIO_STRINGS_HPP
25 |
26 | #include
27 | #include
28 | #include
29 |
30 | namespace ELFIO {
31 |
32 | //------------------------------------------------------------------------------
33 | class string_section_accessor
34 | {
35 | public:
36 | //------------------------------------------------------------------------------
37 | string_section_accessor( section* section_ ) :
38 | string_section( section_ )
39 | {
40 | }
41 |
42 |
43 | //------------------------------------------------------------------------------
44 | const char*
45 | get_string( Elf_Word index ) const
46 | {
47 | if ( index < string_section->get_size() ) {
48 | const char* data = string_section->get_data();
49 | if ( 0 != data ) {
50 | return data + index;
51 | }
52 | }
53 |
54 | return 0;
55 | }
56 |
57 |
58 | //------------------------------------------------------------------------------
59 | Elf_Word
60 | add_string( const char* str )
61 | {
62 | // Strings are addeded to the end of the current section data
63 | Elf_Word current_position = (Elf_Word)string_section->get_size();
64 |
65 | if ( current_position == 0 ) {
66 | char empty_string = '\0';
67 | string_section->append_data( &empty_string, 1 );
68 | current_position++;
69 | }
70 | string_section->append_data( str, (Elf_Word)std::strlen( str ) + 1 );
71 |
72 | return current_position;
73 | }
74 |
75 |
76 | //------------------------------------------------------------------------------
77 | Elf_Word
78 | add_string( const std::string& str )
79 | {
80 | return add_string( str.c_str() );
81 | }
82 |
83 | //------------------------------------------------------------------------------
84 | private:
85 | section* string_section;
86 | };
87 |
88 | } // namespace ELFIO
89 |
90 | #endif // ELFIO_STRINGS_HPP
91 |
--------------------------------------------------------------------------------
/src/jump_table/elfio/elfio_symbols.hpp:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (C) 2001-2015 by Serge Lamikhov-Center
3 |
4 | Permission is hereby granted, free of charge, to any person obtaining a copy
5 | of this software and associated documentation files (the "Software"), to deal
6 | in the Software without restriction, including without limitation the rights
7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 | copies of the Software, and to permit persons to whom the Software is
9 | furnished to do so, subject to the following conditions:
10 |
11 | The above copyright notice and this permission notice shall be included in
12 | all copies or substantial portions of the Software.
13 |
14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20 | THE SOFTWARE.
21 | */
22 |
23 | #ifndef ELFIO_SYMBOLS_HPP
24 | #define ELFIO_SYMBOLS_HPP
25 |
26 | namespace ELFIO {
27 |
28 | //------------------------------------------------------------------------------
29 | class symbol_section_accessor
30 | {
31 | public:
32 | //------------------------------------------------------------------------------
33 | symbol_section_accessor( const elfio& elf_file_, section* symbol_section_ ) :
34 | elf_file( elf_file_ ),
35 | symbol_section( symbol_section_ )
36 | {
37 | find_hash_section();
38 | }
39 |
40 | //------------------------------------------------------------------------------
41 | Elf_Xword
42 | get_symbols_num() const
43 | {
44 | Elf_Xword nRet = 0;
45 | if ( 0 != symbol_section->get_entry_size() ) {
46 | nRet = symbol_section->get_size() / symbol_section->get_entry_size();
47 | }
48 |
49 | return nRet;
50 | }
51 |
52 | //------------------------------------------------------------------------------
53 | bool
54 | get_symbol( Elf_Xword index,
55 | std::string& name,
56 | Elf64_Addr& value,
57 | Elf_Xword& size,
58 | unsigned char& bind,
59 | unsigned char& type,
60 | Elf_Half& section_index,
61 | unsigned char& other ) const
62 | {
63 | bool ret = false;
64 |
65 | if ( elf_file.get_class() == ELFCLASS32 ) {
66 | ret = generic_get_symbol( index, name, value, size, bind,
67 | type, section_index, other );
68 | }
69 | else {
70 | ret = generic_get_symbol( index, name, value, size, bind,
71 | type, section_index, other );
72 | }
73 |
74 | return ret;
75 | }
76 |
77 | //------------------------------------------------------------------------------
78 | bool
79 | get_symbol( const std::string& name,
80 | Elf64_Addr& value,
81 | Elf_Xword& size,
82 | unsigned char& bind,
83 | unsigned char& type,
84 | Elf_Half& section_index,
85 | unsigned char& other ) const
86 | {
87 | bool ret = false;
88 |
89 | if ( 0 != get_hash_table_index() ) {
90 | Elf_Word nbucket = *(Elf_Word*)hash_section->get_data();
91 | Elf_Word nchain = *(Elf_Word*)( hash_section->get_data() +
92 | sizeof( Elf_Word ) );
93 | Elf_Word val = elf_hash( (const unsigned char*)name.c_str() );
94 |
95 | Elf_Word y = *(Elf_Word*)( hash_section->get_data() +
96 | ( 2 + val % nbucket ) * sizeof( Elf_Word ) );
97 | std::string str;
98 | get_symbol( y, str, value, size, bind, type, section_index, other );
99 | while ( str != name && STN_UNDEF != y && y < nchain ) {
100 | y = *(Elf_Word*)( hash_section->get_data() +
101 | ( 2 + nbucket + y ) * sizeof( Elf_Word ) );
102 | get_symbol( y, str, value, size, bind, type, section_index, other );
103 | }
104 | if ( str == name ) {
105 | ret = true;
106 | }
107 | }
108 |
109 | return ret;
110 | }
111 |
112 | //------------------------------------------------------------------------------
113 | Elf_Word
114 | add_symbol( Elf_Word name, Elf64_Addr value, Elf_Xword size,
115 | unsigned char info, unsigned char other,
116 | Elf_Half shndx )
117 | {
118 | Elf_Word nRet;
119 |
120 | if ( symbol_section->get_size() == 0 ) {
121 | if ( elf_file.get_class() == ELFCLASS32 ) {
122 | nRet = generic_add_symbol( 0, 0, 0, 0, 0, 0 );
123 | }
124 | else {
125 | nRet = generic_add_symbol( 0, 0, 0, 0, 0, 0 );
126 | }
127 | }
128 |
129 | if ( elf_file.get_class() == ELFCLASS32 ) {
130 | nRet = generic_add_symbol( name, value, size, info, other,
131 | shndx );
132 | }
133 | else {
134 | nRet = generic_add_symbol( name, value, size, info, other,
135 | shndx );
136 | }
137 |
138 | return nRet;
139 | }
140 |
141 | //------------------------------------------------------------------------------
142 | Elf_Word
143 | add_symbol( Elf_Word name, Elf64_Addr value, Elf_Xword size,
144 | unsigned char bind, unsigned char type, unsigned char other,
145 | Elf_Half shndx )
146 | {
147 | return add_symbol( name, value, size, ELF_ST_INFO( bind, type ), other, shndx );
148 | }
149 |
150 | //------------------------------------------------------------------------------
151 | Elf_Word
152 | add_symbol( string_section_accessor& pStrWriter, const char* str,
153 | Elf64_Addr value, Elf_Xword size,
154 | unsigned char info, unsigned char other,
155 | Elf_Half shndx )
156 | {
157 | Elf_Word index = pStrWriter.add_string( str );
158 | return add_symbol( index, value, size, info, other, shndx );
159 | }
160 |
161 | //------------------------------------------------------------------------------
162 | Elf_Word
163 | add_symbol( string_section_accessor& pStrWriter, const char* str,
164 | Elf64_Addr value, Elf_Xword size,
165 | unsigned char bind, unsigned char type, unsigned char other,
166 | Elf_Half shndx )
167 | {
168 | return add_symbol( pStrWriter, str, value, size, ELF_ST_INFO( bind, type ), other, shndx );
169 | }
170 |
171 | //------------------------------------------------------------------------------
172 | private:
173 | //------------------------------------------------------------------------------
174 | void
175 | find_hash_section()
176 | {
177 | hash_section = 0;
178 | hash_section_index = 0;
179 | Elf_Half nSecNo = elf_file.sections.size();
180 | for ( Elf_Half i = 0; i < nSecNo && 0 == hash_section_index; ++i ) {
181 | const section* sec = elf_file.sections[i];
182 | if ( sec->get_link() == symbol_section->get_index() ) {
183 | hash_section = sec;
184 | hash_section_index = i;
185 | }
186 | }
187 | }
188 |
189 | //------------------------------------------------------------------------------
190 | Elf_Half
191 | get_string_table_index() const
192 | {
193 | return (Elf_Half)symbol_section->get_link();
194 | }
195 |
196 | //------------------------------------------------------------------------------
197 | Elf_Half
198 | get_hash_table_index() const
199 | {
200 | return hash_section_index;
201 | }
202 |
203 | //------------------------------------------------------------------------------
204 | template< class T >
205 | bool
206 | generic_get_symbol( Elf_Xword index,
207 | std::string& name, Elf64_Addr& value,
208 | Elf_Xword& size,
209 | unsigned char& bind, unsigned char& type,
210 | Elf_Half& section_index,
211 | unsigned char& other ) const
212 | {
213 | bool ret = false;
214 |
215 | if ( index < get_symbols_num() ) {
216 | const T* pSym = reinterpret_cast(
217 | symbol_section->get_data() +
218 | index * symbol_section->get_entry_size() );
219 |
220 | const endianess_convertor& convertor = elf_file.get_convertor();
221 |
222 | section* string_section = elf_file.sections[get_string_table_index()];
223 | string_section_accessor str_reader( string_section );
224 | const char* pStr = str_reader.get_string( convertor( pSym->st_name ) );
225 | if ( 0 != pStr ) {
226 | name = pStr;
227 | }
228 | value = convertor( pSym->st_value );
229 | size = convertor( pSym->st_size );
230 | bind = ELF_ST_BIND( pSym->st_info );
231 | type = ELF_ST_TYPE( pSym->st_info );
232 | section_index = convertor( pSym->st_shndx );
233 | other = pSym->st_other;
234 |
235 | ret = true;
236 | }
237 |
238 | return ret;
239 | }
240 |
241 | //------------------------------------------------------------------------------
242 | template< class T >
243 | Elf_Word
244 | generic_add_symbol( Elf_Word name, Elf64_Addr value, Elf_Xword size,
245 | unsigned char info, unsigned char other,
246 | Elf_Half shndx )
247 | {
248 | const endianess_convertor& convertor = elf_file.get_convertor();
249 |
250 | T entry;
251 | entry.st_name = convertor( name );
252 | entry.st_value = value;
253 | entry.st_value = convertor( entry.st_value );
254 | entry.st_size = size;
255 | entry.st_size = convertor( entry.st_size );
256 | entry.st_info = convertor( info );
257 | entry.st_other = convertor( other );
258 | entry.st_shndx = convertor( shndx );
259 |
260 | symbol_section->append_data( reinterpret_cast( &entry ),
261 | sizeof( entry ) );
262 |
263 | Elf_Word nRet = symbol_section->get_size() / sizeof( entry ) - 1;
264 |
265 | return nRet;
266 | }
267 |
268 | //------------------------------------------------------------------------------
269 | private:
270 | const elfio& elf_file;
271 | section* symbol_section;
272 | Elf_Half hash_section_index;
273 | const section* hash_section;
274 | };
275 |
276 | } // namespace ELFIO
277 |
278 | #endif // ELFIO_SYMBOLS_HPP
279 |
--------------------------------------------------------------------------------
/src/jump_table/elfio/elfio_utils.hpp:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (C) 2001-2015 by Serge Lamikhov-Center
3 |
4 | Permission is hereby granted, free of charge, to any person obtaining a copy
5 | of this software and associated documentation files (the "Software"), to deal
6 | in the Software without restriction, including without limitation the rights
7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 | copies of the Software, and to permit persons to whom the Software is
9 | furnished to do so, subject to the following conditions:
10 |
11 | The above copyright notice and this permission notice shall be included in
12 | all copies or substantial portions of the Software.
13 |
14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20 | THE SOFTWARE.
21 | */
22 |
23 | #ifndef ELFIO_UTILS_HPP
24 | #define ELFIO_UTILS_HPP
25 |
26 | #define ELFIO_GET_ACCESS( TYPE, NAME, FIELD ) \
27 | TYPE get_##NAME() const \
28 | { \
29 | return (*convertor)( FIELD ); \
30 | }
31 | #define ELFIO_SET_ACCESS( TYPE, NAME, FIELD ) \
32 | void set_##NAME( TYPE value ) \
33 | { \
34 | FIELD = value; \
35 | FIELD = (*convertor)( FIELD ); \
36 | }
37 | #define ELFIO_GET_SET_ACCESS( TYPE, NAME, FIELD ) \
38 | TYPE get_##NAME() const \
39 | { \
40 | return (*convertor)( FIELD ); \
41 | } \
42 | void set_##NAME( TYPE value ) \
43 | { \
44 | FIELD = value; \
45 | FIELD = (*convertor)( FIELD ); \
46 | }
47 |
48 | #define ELFIO_GET_ACCESS_DECL( TYPE, NAME ) \
49 | virtual TYPE get_##NAME() const = 0
50 |
51 | #define ELFIO_SET_ACCESS_DECL( TYPE, NAME ) \
52 | virtual void set_##NAME( TYPE value ) = 0
53 |
54 | #define ELFIO_GET_SET_ACCESS_DECL( TYPE, NAME ) \
55 | virtual TYPE get_##NAME() const = 0; \
56 | virtual void set_##NAME( TYPE value ) = 0
57 |
58 | namespace ELFIO {
59 |
60 | //------------------------------------------------------------------------------
61 | class endianess_convertor {
62 | public:
63 | //------------------------------------------------------------------------------
64 | endianess_convertor()
65 | {
66 | need_conversion = false;
67 | }
68 |
69 | //------------------------------------------------------------------------------
70 | void
71 | setup( unsigned char elf_file_encoding )
72 | {
73 | need_conversion = ( elf_file_encoding != get_host_encoding() );
74 | }
75 |
76 | //------------------------------------------------------------------------------
77 | uint64_t
78 | operator()( uint64_t value ) const
79 | {
80 | if ( !need_conversion ) {
81 | return value;
82 | }
83 | value =
84 | ( ( value & 0x00000000000000FFull ) << 56 ) |
85 | ( ( value & 0x000000000000FF00ull ) << 40 ) |
86 | ( ( value & 0x0000000000FF0000ull ) << 24 ) |
87 | ( ( value & 0x00000000FF000000ull ) << 8 ) |
88 | ( ( value & 0x000000FF00000000ull ) >> 8 ) |
89 | ( ( value & 0x0000FF0000000000ull ) >> 24 ) |
90 | ( ( value & 0x00FF000000000000ull ) >> 40 ) |
91 | ( ( value & 0xFF00000000000000ull ) >> 56 );
92 |
93 | return value;
94 | }
95 |
96 | //------------------------------------------------------------------------------
97 | int64_t
98 | operator()( int64_t value ) const
99 | {
100 | if ( !need_conversion ) {
101 | return value;
102 | }
103 | return (int64_t)(*this)( (uint64_t)value );
104 | }
105 |
106 | //------------------------------------------------------------------------------
107 | uint32_t
108 | operator()( uint32_t value ) const
109 | {
110 | if ( !need_conversion ) {
111 | return value;
112 | }
113 | value =
114 | ( ( value & 0x000000FF ) << 24 ) |
115 | ( ( value & 0x0000FF00 ) << 8 ) |
116 | ( ( value & 0x00FF0000 ) >> 8 ) |
117 | ( ( value & 0xFF000000 ) >> 24 );
118 |
119 | return value;
120 | }
121 |
122 | //------------------------------------------------------------------------------
123 | int32_t
124 | operator()( int32_t value ) const
125 | {
126 | if ( !need_conversion ) {
127 | return value;
128 | }
129 | return (int32_t)(*this)( (uint32_t)value );
130 | }
131 |
132 | //------------------------------------------------------------------------------
133 | uint16_t
134 | operator()( uint16_t value ) const
135 | {
136 | if ( !need_conversion ) {
137 | return value;
138 | }
139 | value =
140 | ( ( value & 0x00FF ) << 8 ) |
141 | ( ( value & 0xFF00 ) >> 8 );
142 |
143 | return value;
144 | }
145 |
146 | //------------------------------------------------------------------------------
147 | int16_t
148 | operator()( int16_t value ) const
149 | {
150 | if ( !need_conversion ) {
151 | return value;
152 | }
153 | return (int16_t)(*this)( (uint16_t)value );
154 | }
155 |
156 | //------------------------------------------------------------------------------
157 | int8_t
158 | operator()( int8_t value ) const
159 | {
160 | return value;
161 | }
162 |
163 | //------------------------------------------------------------------------------
164 | uint8_t
165 | operator()( uint8_t value ) const
166 | {
167 | return value;
168 | }
169 |
170 | //------------------------------------------------------------------------------
171 | private:
172 | //------------------------------------------------------------------------------
173 | unsigned char
174 | get_host_encoding() const
175 | {
176 | static const int tmp = 1;
177 | if ( 1 == *(char*)&tmp ) {
178 | return ELFDATA2LSB;
179 | }
180 | else {
181 | return ELFDATA2MSB;
182 | }
183 | }
184 |
185 | //------------------------------------------------------------------------------
186 | private:
187 | bool need_conversion;
188 | };
189 |
190 |
191 | //------------------------------------------------------------------------------
192 | inline
193 | uint32_t
194 | elf_hash( const unsigned char *name )
195 | {
196 | uint32_t h = 0, g;
197 | while ( *name ) {
198 | h = (h << 4) + *name++;
199 | g = h & 0xf0000000;
200 | if ( g != 0 )
201 | h ^= g >> 24;
202 | h &= ~g;
203 | }
204 | return h;
205 | }
206 |
207 | } // namespace ELFIO
208 |
209 | #endif // ELFIO_UTILS_HPP
210 |
--------------------------------------------------------------------------------
/src/jump_table/main.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 |
5 | #include
6 | #include "tinyformat.h"
7 |
8 | auto dump(const uint8_t* section_data, uint32_t section_addr, uint32_t section_size,
9 | uint32_t start_dumping_addr, uint32_t stop_dumping_addr, const std::string& output_file) -> void;
10 |
11 | int main(int argc, char* argv[])
12 | {
13 | ELFIO::elfio elf_reader;
14 | elf_reader.load(argv[1]);
15 |
16 | try {
17 | tfm::printf("ELF file class: ");
18 | switch (elf_reader.get_class()) {
19 | case ELFCLASS32: tfm::printfln("ELF32"); break;
20 | case ELFCLASS64: tfm::printfln("ELF64"); break;
21 | default: throw 1; break;
22 | }
23 |
24 | tfm::printf("ELF file encoding: ");
25 | switch (elf_reader.get_encoding()) {
26 | case ELFDATA2LSB: tfm::printfln("Little endian"); break;
27 | case ELFDATA2MSB: tfm::printfln("Big endian"); break;
28 | default: throw 2; break;
29 | }
30 |
31 | auto sec_number = elf_reader.sections.size();
32 | tfm::printfln("Number of sections: %d", sec_number);
33 | // for (uint32_t i = 0; i < sec_number; ++i) {
34 | // const auto psection = elf_reader.sections[i];
35 | // tfm::printfln("%2d %-25s %-7d 0x8%x",
36 | // i, psection->get_name(), psection->get_size(), psection->get_address());
37 | // }
38 |
39 | auto seg_number = elf_reader.segments.size();
40 | tfm::printfln("Number of segments: %d", seg_number);
41 | // for (uint32_t i = 0; i < seg_number; ++i) {
42 | // const auto psegment = elf_reader.segments[i];
43 | // tfm::printfln("%2d 0x8%x 0x%-8x 0x%-4x %3d",
44 | // i, psegment->get_flags(), psegment->get_virtual_address(),
45 | // psegment->get_file_size(), psegment->get_memory_size());
46 | // }
47 |
48 | auto section_name = std::string(argv[2]);
49 | auto data_base_address = 0;
50 | auto data = (const uint8_t*){nullptr};
51 | auto data_size = uint32_t{0};
52 |
53 | for (uint32_t i = 0; i < sec_number; ++i) {
54 | auto psection = elf_reader.sections[i];
55 |
56 | if (psection->get_name() == section_name) {
57 | data_base_address = psection->get_address();
58 | data = reinterpret_cast(psection->get_data());
59 | data_size = psection->get_size();
60 | break;
61 | }
62 | }
63 |
64 | //=== dumping data
65 | if (data == nullptr) throw 3;
66 |
67 | auto start_dumping_address = std::stoul(argv[3], nullptr, 0x10);
68 | auto stop_dumping_address = std::stoul(argv[4], nullptr, 0x10);
69 | auto dumped_data_file = std::string(argv[5]);
70 |
71 | tfm::printfln("Section %s of size %d bytes found at range [0x%x, 0x%x), dumping %d bytes in range [0x%x, 0x%x) to file %s",
72 | section_name,
73 | data_size, data_base_address, data_base_address + data_size,
74 | stop_dumping_address - start_dumping_address, start_dumping_address, stop_dumping_address,
75 | dumped_data_file);
76 |
77 | dump(data, data_base_address, data_size, start_dumping_address, stop_dumping_address, dumped_data_file);
78 | }
79 | catch (int e) {
80 | switch (e) {
81 | case 1: tfm::printfln("Invalid file class"); break;
82 | case 2: tfm::printfln("Invalid file encoding"); break;
83 | case 3: tfm::printfln("Cannot read data from section"); break;
84 | default: break;
85 | }
86 | }
87 | catch (const std::exception& expt) {
88 | tfm::printfln("%s", expt.what());
89 | }
90 |
91 | return 0;
92 | }
93 |
94 |
--------------------------------------------------------------------------------
/src/lib/cap/cap.h:
--------------------------------------------------------------------------------
1 | #ifndef CAP_H
2 | #define CAP_H
3 |
4 | #include "../../parsing_helper.h"
5 | #include
6 | #include
7 |
8 | // support functions
9 | auto cap_initialize () -> void;
10 | auto cap_initialize_state () -> void;
11 | auto cap_set_trace_length (uint32_t trace_length) -> void;
12 | auto cap_set_start_address (ADDRINT address) -> void;
13 | auto cap_set_stop_address (ADDRINT address) -> void;
14 | auto cap_add_full_skip_call_address (ADDRINT address) -> void;
15 | auto cap_add_selective_skip_address (ADDRINT address) -> void;
16 | auto cap_add_auto_skip_call_addresses (ADDRINT address) -> void;
17 | auto cap_set_loop_count (uint32_t count) -> void;
18 | auto cap_verify_parameters () -> void;
19 |
20 | auto cap_add_patched_memory_value (ADDRINT ins_address, UINT32 exec_order, bool be_or_af,
21 | ADDRINT mem_address, UINT8 mem_size, ADDRINT mem_value) -> void;
22 | auto cap_add_patched_register_value (ADDRINT ins_address, UINT32 exec_order, bool be_or_af,
23 | REG reg, UINT8 lo_pos, UINT8 hi_pos, ADDRINT reg_value) -> void;
24 |
25 | // report functions
26 | auto cap_save_trace_to_file (const std::string& filename) -> void;
27 | auto cap_load_trace_from_file (const std::string& filename) -> void; // TODO or not TODO
28 | auto cap_save_trace_to_dot_file (const std::string& filename) -> void;
29 | auto cap_save_basic_block_cfg_to_dot_file (const std::string& filename) -> void;
30 | auto cap_save_basic_block_trace_to_file (const std::string& filename) -> void;
31 | auto cap_save_virtual_trace_to_file (const std::string& filename) -> void;
32 |
33 | // instrumentation functions
34 | // instruction mode
35 | auto cap_ins_mode_get_ins_info (INS ins, VOID* data) -> VOID;
36 |
37 | // trace mode
38 | auto cap_trace_mode_patch_ins_info (TRACE trace, VOID* data) -> VOID;
39 | auto cap_trace_mode_get_ins_info (TRACE trace, VOID* data) -> VOID;
40 |
41 | // img mode
42 | auto cap_img_mode_get_ins_info (IMG img, VOID* data) -> VOID;
43 |
44 | auto cap_get_syscall_entry_info (THREADID thread_id, CONTEXT* p_context, SYSCALL_STANDARD syscall_std, VOID* data) -> VOID;
45 | auto cap_get_syscall_exit_info (THREADID thread_id, CONTEXT* p_context, SYSCALL_STANDARD syscall_std, VOID* data) -> VOID;
46 |
47 | //using syscall_instrumentation_t = VOID (*)(THREADID thread_id, const CONTEXT* p_context, SYSCALL_STANDARD std, VOID* data);
48 | //extern ins_instrumentation_t cap_instrument_instruction_not_follow_call;
49 | // the following functions are generated in compile time by template system
50 | //auto cap_instrument_instruction_follow_call (INS ins, VOID* data) -> VOID;
51 | //auto cap_instrument_instruction_not_follow_call (INS ins, VOID* data) -> VOID;
52 |
53 | #endif
54 |
--------------------------------------------------------------------------------
/src/lib/cap/saver.cpp:
--------------------------------------------------------------------------------
1 | #include "cap.h"
2 | #include "trace.h"
3 |
4 | #include "../tinyformat.h"
5 |
6 | #include
7 | #include
8 |
9 |
10 |
11 | /*====================================================================================================================*/
12 | /* exported functions */
13 | /*====================================================================================================================*/
14 |
15 | //auto cap_save_trace_to_file (const std::string& filename) noexcept -> void
16 | //{
17 | // std::ofstream trace_file(filename.c_str(),
18 | // std::ofstream::out | std::ofstream::binary | std::ofstream::trunc);
19 |
20 | // if (trace_file.is_open()) {
21 | // save_in_simple_format(trace_file);
22 | //// save_in_protobuf_format(trace_file);
23 |
24 | // trace_file.close();
25 | // }
26 | // else {
27 | // tfm::printfln("cannot save to file %", filename);
28 | // }
29 |
30 | // return;
31 | //}
32 |
--------------------------------------------------------------------------------
/src/lib/cap/trace.h:
--------------------------------------------------------------------------------
1 | #ifndef TRACE_H
2 | #define TRACE_H
3 |
4 | #include "../type/instruction.h"
5 |
6 | #include
7 | #include
8 | #include
9 | #include
10 | #include
11 |
12 | #include
13 |
14 | typedef std::pair dyn_reg_t;
15 | typedef std::pair dyn_mem_t;
16 |
17 | typedef std::map dyn_regs_t;
18 | typedef std::map dyn_mems_t;
19 |
20 | enum
21 | {
22 | CAP_SYS_READ = 3,
23 | CAP_SYS_WRITE = 4,
24 | CAP_SYS_OPEN = 5,
25 | CAP_SYS_SOCKET = 102,
26 | CAP_SYS_OTHER = 1000
27 | };
28 |
29 | template
30 | struct syscall_t
31 | {
32 | enum { id = sys_id };
33 | };
34 |
35 | struct sys_read_info_t : syscall_t
36 | {
37 | int file_desc;
38 | ADDRINT buffer_addr;
39 | size_t buffer_length;
40 | size_t read_length;
41 | std::shared_ptr buffer;
42 | };
43 |
44 | struct sys_write_info_t : syscall_t
45 | {
46 | int file_desc;
47 | ADDRINT buffer_addr;
48 | size_t buffer_length;
49 | size_t write_length;
50 | std::shared_ptr buffer;
51 | };
52 |
53 | struct sys_open_info_t : syscall_t
54 | {
55 | std::string path_name;
56 | int flags;
57 | int mode;
58 | int file_desc;
59 | };
60 |
61 | struct sys_other_info_t : syscall_t
62 | {
63 | uint32_t real_id;
64 | sys_other_info_t(uint32_t syscall_id) : real_id(syscall_id) {};
65 | };
66 |
67 | struct call_info_t
68 | {
69 | ADDRINT called_fun_addr;
70 | std::string called_fun_name;
71 | bool is_traced;
72 | };
73 |
74 | typedef boost::variant
75 | <
76 | sys_open_info_t, // which = 0
77 | sys_read_info_t, // 1
78 | sys_write_info_t, // 2
79 | sys_other_info_t, // 3
80 | call_info_t // 4
81 | > concrete_info_t;
82 |
83 | typedef std::tuple<
84 | ADDRINT, // address of instructions
85 | THREADID, // id of containing thread
86 | dyn_regs_t, // read registers
87 | dyn_regs_t, // write registers
88 | dyn_mems_t, // read memory addresses
89 | dyn_mems_t, // write memory addresses
90 | concrete_info_t // concrete information
91 | > dyn_ins_t;
92 |
93 | // list is prefered since new instructions will be added regularly
94 | typedef std::list dyn_inss_t;
95 |
96 | extern dyn_inss_t trace;
97 | extern map_address_instruction_t cached_ins_at_addr;
98 | extern std::vector virtual_trace;
99 |
100 | enum
101 | {
102 | INS_ADDRESS = 0,
103 | INS_THREAD_ID = 1,
104 | INS_READ_REGS = 2,
105 | INS_WRITE_REGS = 3,
106 | INS_READ_MEMS = 4,
107 | INS_WRITE_MEMS = 5,
108 | INS_CONCRETE_INFO = 6
109 | };
110 |
111 | #endif // TRACE_H
112 |
--------------------------------------------------------------------------------
/src/lib/framework/analysis_callback.h:
--------------------------------------------------------------------------------
1 | #ifndef ANALYSIS_CALLBACK_H
2 | #define ANALYSIS_CALLBACK_H
3 |
4 |
5 | #include
6 |
7 | #include
8 | #include
9 |
10 | //#include "../tinyformat.h"
11 |
12 | template
13 | struct is_well_formed
14 | {
15 | // template
16 | // static auto value () -> bool
17 | // {
18 | // return (sizeof...(args) == 0);
19 | // }
20 | };
21 |
22 | template
23 | struct is_well_formed