mirror of
https://github.com/lifting-bits/sleigh
synced 2026-06-21 13:56:12 +00:00
Compare commits
17 Commits
v10.1.4
...
irene2-final
| Author | SHA1 | Date | |
|---|---|---|---|
| 0474bbdc17 | |||
| ff84f3c8de | |||
| 2aa04f941e | |||
| a057b409fa | |||
| b3e26db5c3 | |||
| 01cf5e5240 | |||
| 8a0ad2de4a | |||
| e6cfbacd67 | |||
| 66a6b7c472 | |||
| 70bbd6ce0b | |||
| 5ee2f2c162 | |||
| 08b2fdbe4b | |||
| 60f5ab437c | |||
| b8609d4673 | |||
| 52bb4a54d6 | |||
| ed9eb2e521 | |||
| c6cf5f3728 |
@@ -45,7 +45,7 @@ jobs:
|
||||
graphviz
|
||||
|
||||
# Minimum supported CMake version testing
|
||||
curl -L "https://github.com/Kitware/CMake/releases/download/v3.15.0/cmake-3.15.0-Linux-$(uname -m).sh" -o /tmp/cmake-install.sh
|
||||
curl -L "https://github.com/Kitware/CMake/releases/download/v3.18.0/cmake-3.18.0-Linux-$(uname -m).sh" -o /tmp/cmake-install.sh
|
||||
mkdir -p "${HOME}/.local"
|
||||
bash /tmp/cmake-install.sh --skip-license --exclude-subdir "--prefix=${HOME}/.local"
|
||||
|
||||
@@ -109,7 +109,7 @@ jobs:
|
||||
-DCMAKE_CXX_COMPILER_LAUNCHER=ccache
|
||||
-DCMAKE_C_COMPILER_LAUNCHER=ccache
|
||||
-DCMAKE_BUILD_TYPE=${{ matrix.build_type }}
|
||||
-Dsleigh_GHIDRA_RELEASE_TYPE=${{ matrix.release }}
|
||||
-Dsleigh_RELEASE_TYPE=${{ matrix.release }}
|
||||
-Dsleigh_ENABLE_TESTS=ON
|
||||
-Dsleigh_ENABLE_EXAMPLES=ON
|
||||
-Dsleigh_ENABLE_PACKAGING=ON
|
||||
|
||||
@@ -14,7 +14,7 @@ jobs:
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
- uses: actions/setup-python@v3
|
||||
- uses: actions/setup-python@v4
|
||||
with:
|
||||
# Use oldest supported version for maximum script compatibility
|
||||
python-version: '3.7'
|
||||
|
||||
+137
-42
@@ -6,12 +6,16 @@
|
||||
# the LICENSE file found in the root directory of this source tree.
|
||||
#
|
||||
|
||||
cmake_minimum_required(VERSION 3.15)
|
||||
cmake_minimum_required(VERSION 3.18)
|
||||
|
||||
# Sets "library_root" variable for decompiler cpp root directory
|
||||
# Sets "ghidra_version" for numeric version number
|
||||
# Use "ghidrasource_SOURCE_DIR" variable for Ghidra repo root
|
||||
include(src/setup-ghidra-source.cmake)
|
||||
set(sleigh_RELEASE_IS_HEAD FALSE)
|
||||
if("${sleigh_RELEASE_TYPE}" STREQUAL "HEAD")
|
||||
set(sleigh_RELEASE_IS_HEAD TRUE)
|
||||
endif()
|
||||
|
||||
project("sleigh"
|
||||
VERSION "${ghidra_version}"
|
||||
@@ -35,33 +39,119 @@ set(public_include_header_list
|
||||
"${PROJECT_SOURCE_DIR}/include/libsleigh.hh"
|
||||
"${PROJECT_SOURCE_DIR}/support/Support.h"
|
||||
"${PROJECT_SOURCE_DIR}/support/Version.h"
|
||||
|
||||
"${library_root}/action.hh"
|
||||
"${library_root}/address.hh"
|
||||
"${library_root}/architecture.hh"
|
||||
"${library_root}/block.hh"
|
||||
"${library_root}/blockaction.hh"
|
||||
"${library_root}/callgraph.hh"
|
||||
"${library_root}/capability.hh"
|
||||
"${library_root}/cast.hh"
|
||||
"${library_root}/codedata.hh"
|
||||
"${library_root}/comment.hh"
|
||||
"${library_root}/comment_ghidra.hh"
|
||||
"${library_root}/condexe.hh"
|
||||
"${library_root}/context.hh"
|
||||
"${library_root}/coreaction.hh"
|
||||
"${library_root}/cover.hh"
|
||||
"${library_root}/cpool.hh"
|
||||
"${library_root}/cpool_ghidra.hh"
|
||||
"${library_root}/crc32.hh"
|
||||
"${library_root}/database.hh"
|
||||
"${library_root}/database_ghidra.hh"
|
||||
"${library_root}/doccore.hh"
|
||||
"${library_root}/docmain.hh"
|
||||
"${library_root}/double.hh"
|
||||
"${library_root}/dynamic.hh"
|
||||
"${library_root}/emulate.hh"
|
||||
"${library_root}/emulateutil.hh"
|
||||
"${library_root}/error.hh"
|
||||
"${library_root}/filemanage.hh"
|
||||
"${library_root}/float.hh"
|
||||
"${library_root}/flow.hh"
|
||||
"${library_root}/fspec.hh"
|
||||
"${library_root}/funcdata.hh"
|
||||
"${library_root}/ghidra_arch.hh"
|
||||
"${library_root}/ghidra_context.hh"
|
||||
"${library_root}/ghidra_process.hh"
|
||||
"${library_root}/ghidra_translate.hh"
|
||||
"${library_root}/globalcontext.hh"
|
||||
"${library_root}/grammar.hh"
|
||||
"${library_root}/graph.hh"
|
||||
"${library_root}/heritage.hh"
|
||||
"${library_root}/ifacedecomp.hh"
|
||||
"${library_root}/ifaceterm.hh"
|
||||
"${library_root}/inject_ghidra.hh"
|
||||
"${library_root}/inject_sleigh.hh"
|
||||
"${library_root}/interface.hh"
|
||||
"${library_root}/jumptable.hh"
|
||||
"${library_root}/libdecomp.hh"
|
||||
"${library_root}/loadimage.hh"
|
||||
"${library_root}/loadimage_ghidra.hh"
|
||||
"${library_root}/loadimage_xml.hh"
|
||||
"${library_root}/memstate.hh"
|
||||
"${library_root}/merge.hh"
|
||||
"${library_root}/op.hh"
|
||||
"${library_root}/opbehavior.hh"
|
||||
"${library_root}/opcodes.hh"
|
||||
"${library_root}/options.hh"
|
||||
"${library_root}/override.hh"
|
||||
"${library_root}/paramid.hh"
|
||||
"${library_root}/partmap.hh"
|
||||
"${library_root}/pcodecompile.hh"
|
||||
"${library_root}/pcodeinject.hh"
|
||||
"${library_root}/pcodeparse.hh"
|
||||
"${library_root}/pcoderaw.hh"
|
||||
"${library_root}/prefersplit.hh"
|
||||
"${library_root}/prettyprint.hh"
|
||||
"${library_root}/printc.hh"
|
||||
"${library_root}/printjava.hh"
|
||||
"${library_root}/printlanguage.hh"
|
||||
"${library_root}/rangemap.hh"
|
||||
"${library_root}/rangeutil.hh"
|
||||
"${library_root}/raw_arch.hh"
|
||||
"${library_root}/ruleaction.hh"
|
||||
"${library_root}/rulecompile.hh"
|
||||
"${library_root}/semantics.hh"
|
||||
"${library_root}/sleigh.hh"
|
||||
"${library_root}/sleigh_arch.hh"
|
||||
"${library_root}/sleighbase.hh"
|
||||
"${library_root}/slgh_compile.hh"
|
||||
"${library_root}/slghparse.hh"
|
||||
"${library_root}/slghpatexpress.hh"
|
||||
"${library_root}/slghpattern.hh"
|
||||
"${library_root}/slghsymbol.hh"
|
||||
"${library_root}/space.hh"
|
||||
"${library_root}/string_ghidra.hh"
|
||||
"${library_root}/stringmanage.hh"
|
||||
"${library_root}/subflow.hh"
|
||||
"${library_root}/testfunction.hh"
|
||||
"${library_root}/transform.hh"
|
||||
"${library_root}/translate.hh"
|
||||
"${library_root}/type.hh"
|
||||
"${library_root}/typegrp_ghidra.hh"
|
||||
"${library_root}/typeop.hh"
|
||||
"${library_root}/types.h"
|
||||
"${library_root}/unify.hh"
|
||||
"${library_root}/userop.hh"
|
||||
"${library_root}/variable.hh"
|
||||
"${library_root}/varmap.hh"
|
||||
"${library_root}/varnode.hh"
|
||||
"${library_root}/xml.hh"
|
||||
"${library_root}/xml_arch.hh"
|
||||
)
|
||||
if(sleigh_RELEASE_IS_HEAD)
|
||||
list(APPEND public_include_header_list
|
||||
"${library_root}/unionresolve.hh"
|
||||
"${library_root}/marshal.hh"
|
||||
)
|
||||
endif()
|
||||
# Create custom target so that IDEs know these files are part of the sources
|
||||
add_custom_target(sleigh_all_headers SOURCES ${public_include_header_list})
|
||||
set(public_headers_dir ${CMAKE_CURRENT_BINARY_DIR}/include)
|
||||
file(MAKE_DIRECTORY "${public_headers_dir}/sleigh")
|
||||
configure_file(cmake/libconfig.h.in include/sleigh/libconfig.h)
|
||||
# Copy the public headers into our build directory so that we can control the layout.
|
||||
# Ideally, we want to let people '#include <sleigh/{header}>' without installing sleigh
|
||||
foreach(public_header ${public_include_header_list})
|
||||
@@ -78,6 +168,11 @@ set(sleigh_core_source_list
|
||||
"${library_root}/opcodes.cc"
|
||||
"${library_root}/globalcontext.cc"
|
||||
)
|
||||
if(sleigh_RELEASE_IS_HEAD)
|
||||
list(APPEND sleigh_core_source_list
|
||||
"${library_root}/marshal.cc"
|
||||
)
|
||||
endif()
|
||||
|
||||
set(sleigh_deccore_source_list
|
||||
"${library_root}/capability.cc"
|
||||
@@ -133,7 +228,7 @@ set(sleigh_deccore_source_list
|
||||
"${library_root}/opbehavior.cc"
|
||||
"${library_root}/paramid.cc"
|
||||
)
|
||||
if("${sleigh_GHIDRA_RELEASE_TYPE}" STREQUAL "HEAD")
|
||||
if(sleigh_RELEASE_IS_HEAD)
|
||||
list(APPEND sleigh_deccore_source_list
|
||||
"${library_root}/unionresolve.cc"
|
||||
)
|
||||
@@ -191,7 +286,6 @@ set(sleigh_slacomp_source_list
|
||||
#
|
||||
# sleigh settings
|
||||
#
|
||||
|
||||
add_library(sleigh_settings INTERFACE)
|
||||
add_library(sleigh::sleigh_settings ALIAS sleigh_settings)
|
||||
|
||||
@@ -262,7 +356,6 @@ endforeach()
|
||||
#
|
||||
# decomp_opt, decomp_dbg
|
||||
#
|
||||
|
||||
add_executable(decomp_opt
|
||||
${sleigh_core_source_list}
|
||||
${sleigh_deccore_source_list}
|
||||
@@ -297,7 +390,6 @@ endif()
|
||||
#
|
||||
# ghidra_test_dbg
|
||||
#
|
||||
|
||||
if(sleigh_ENABLE_TESTS)
|
||||
add_executable(ghidra_test_dbg
|
||||
${sleigh_core_source_list}
|
||||
@@ -310,7 +402,7 @@ if(sleigh_ENABLE_TESTS)
|
||||
"${library_root}/../unittests/testcirclerange.cc"
|
||||
"${library_root}/../unittests/testfloatemu.cc"
|
||||
"${library_root}/../unittests/testtypes.cc"
|
||||
)
|
||||
)
|
||||
|
||||
target_link_libraries(ghidra_test_dbg PRIVATE
|
||||
sleigh::sleigh_settings
|
||||
@@ -331,15 +423,14 @@ if(sleigh_ENABLE_TESTS)
|
||||
add_test(
|
||||
NAME ghidra_datatest_dbg
|
||||
COMMAND ghidra_test_dbg -sleighpath "${CMAKE_CURRENT_BINARY_DIR}"
|
||||
-path "${ghidrasource_SOURCE_DIR}/Ghidra/Features/Decompiler/src/decompile/datatests"
|
||||
datatests
|
||||
-path "${ghidrasource_SOURCE_DIR}/Ghidra/Features/Decompiler/src/decompile/datatests"
|
||||
datatests
|
||||
)
|
||||
endif()
|
||||
|
||||
#
|
||||
# ghidra_opt, ghidra_dbg
|
||||
#
|
||||
|
||||
add_executable(ghidra_opt
|
||||
${sleigh_core_source_list}
|
||||
${sleigh_deccore_source_list}
|
||||
@@ -373,7 +464,6 @@ endif()
|
||||
#
|
||||
# sleigh_opt, sleigh_dbg
|
||||
#
|
||||
|
||||
add_executable(sleigh_opt
|
||||
${sleigh_core_source_list}
|
||||
${sleigh_source_list}
|
||||
@@ -395,7 +485,6 @@ endif()
|
||||
#
|
||||
# sla, sla_dbg
|
||||
#
|
||||
|
||||
add_library(sla
|
||||
${sleigh_core_source_list}
|
||||
${sleigh_source_list}
|
||||
@@ -411,8 +500,10 @@ add_library(sleigh::sla ALIAS sla)
|
||||
target_link_libraries(sla PUBLIC
|
||||
sleigh::sleigh_settings
|
||||
)
|
||||
|
||||
# Private include search path '#include "..."
|
||||
target_include_directories(sla PRIVATE $<BUILD_INTERFACE:${library_root}>)
|
||||
|
||||
# Public include search path in build directory
|
||||
target_include_directories(
|
||||
sla SYSTEM
|
||||
@@ -432,7 +523,6 @@ endif()
|
||||
#
|
||||
# decomp, decomp_dbg
|
||||
#
|
||||
|
||||
add_library(decomp
|
||||
${sleigh_core_source_list}
|
||||
${sleigh_deccore_source_list}
|
||||
@@ -444,8 +534,10 @@ add_library(sleigh::decomp ALIAS decomp)
|
||||
target_link_libraries(decomp PUBLIC
|
||||
sleigh::sleigh_settings
|
||||
)
|
||||
|
||||
# Private include search path '#include "..."
|
||||
target_include_directories(decomp PRIVATE $<BUILD_INTERFACE:${library_root}>)
|
||||
|
||||
# Public include search path in build directory
|
||||
target_include_directories(
|
||||
decomp SYSTEM
|
||||
@@ -461,13 +553,13 @@ endif()
|
||||
#
|
||||
# Documentation
|
||||
#
|
||||
|
||||
if(sleigh_ENABLE_DOCUMENTATION)
|
||||
message(STATUS "sleigh: Documentation has been enabled")
|
||||
|
||||
find_package(Doxygen REQUIRED COMPONENTS dot)
|
||||
|
||||
set(documentation_output "${CMAKE_CURRENT_BINARY_DIR}/doc")
|
||||
|
||||
# Always run this target because we have no source file tracking for incremental builds
|
||||
add_custom_target(sleigh_documentation
|
||||
COMMAND "${CMAKE_COMMAND}" -E remove_directory "${library_root}/../doc" "${documentation_output}"
|
||||
@@ -483,16 +575,18 @@ endif()
|
||||
# Spec files
|
||||
#
|
||||
# Sets 'spec_file_list' variable
|
||||
if(NOT "${sleigh_GHIDRA_RELEASE_TYPE}" STREQUAL "HEAD")
|
||||
include(spec-files-list/spec_files_stable.cmake)
|
||||
else()
|
||||
if(sleigh_RELEASE_IS_HEAD)
|
||||
include(spec-files-list/spec_files_HEAD.cmake)
|
||||
else()
|
||||
include(spec-files-list/spec_files_stable.cmake)
|
||||
endif()
|
||||
|
||||
# This prefix should match the Ghidra repo to where the sla spec files are located
|
||||
set(spec_files_dir_prefix Ghidra/Processors)
|
||||
|
||||
# This is the root directory where all individual processor spec file directories will be created
|
||||
set(spec_files_build_dir "${CMAKE_CURRENT_BINARY_DIR}/specfiles")
|
||||
|
||||
# This is where we will be copying the generated artifacts for each processor
|
||||
set(spec_files_root_dir "${spec_files_build_dir}/${spec_files_dir_prefix}")
|
||||
set(spec_files_build_log_dir ${CMAKE_CURRENT_BINARY_DIR}/spec_build_logs)
|
||||
@@ -507,6 +601,7 @@ set(spec_targets)
|
||||
set(spec_files)
|
||||
set(spec_dirs)
|
||||
include(cmake/modules/sleighCompile.cmake)
|
||||
|
||||
# Example: '<ghidra_source_prefix>/Ghidra/Processors/8051/data/languages/mx51.slaspec'
|
||||
foreach(spec_file ${spec_file_list})
|
||||
# Get 'mx51'
|
||||
@@ -529,9 +624,11 @@ foreach(spec_file ${spec_file_list})
|
||||
get_filename_component(proc_name "${proc_name}" DIRECTORY)
|
||||
|
||||
set(spec_build_log "${spec_files_build_log_dir}/${spec_name}_build.log")
|
||||
|
||||
# Combine back again for the build directory output like
|
||||
# '<build_prefix>/Ghidra/Processors/8051/data/languages'
|
||||
set(spec_out_dir "${spec_files_root_dir}/${spec_proc_dir}")
|
||||
|
||||
# '<build_prefix>/Ghidra/Processors/8051/data/languages/mx51.sla'
|
||||
set(spec_out "${spec_out_dir}/${spec_name}.sla")
|
||||
|
||||
@@ -554,6 +651,7 @@ endforeach()
|
||||
|
||||
# Copy and create specfile directories
|
||||
list(REMOVE_DUPLICATES spec_dirs)
|
||||
|
||||
foreach(spec_dir ${spec_dirs})
|
||||
set(spec_src_dir "${ghidrasource_SOURCE_DIR}/${spec_files_dir_prefix}/${spec_dir}")
|
||||
set(spec_out_dir "${spec_files_root_dir}/${spec_dir}")
|
||||
@@ -585,7 +683,6 @@ add_custom_target(sleigh_all_sla_specs ALL DEPENDS
|
||||
#
|
||||
# Examples
|
||||
#
|
||||
|
||||
if(sleigh_ENABLE_EXAMPLES)
|
||||
add_executable(sleighexample
|
||||
"${library_root}/sleighexample.cc"
|
||||
@@ -615,44 +712,43 @@ add_subdirectory(support)
|
||||
#
|
||||
# Install targets
|
||||
#
|
||||
|
||||
if(NOT CMAKE_SKIP_INSTALL_RULES)
|
||||
include("GNUInstallDirs")
|
||||
|
||||
install(
|
||||
TARGETS
|
||||
sleigh_settings
|
||||
sleigh_settings
|
||||
|
||||
sla
|
||||
decomp
|
||||
support
|
||||
sla
|
||||
decomp
|
||||
support
|
||||
|
||||
decomp_opt
|
||||
ghidra_opt
|
||||
sleigh_opt
|
||||
decomp_opt
|
||||
ghidra_opt
|
||||
sleigh_opt
|
||||
|
||||
EXPORT
|
||||
sleighTargets
|
||||
sleighTargets
|
||||
|
||||
INCLUDES DESTINATION
|
||||
${CMAKE_INSTALL_INCLUDEDIR}
|
||||
${CMAKE_INSTALL_INCLUDEDIR}
|
||||
)
|
||||
|
||||
install(
|
||||
FILES
|
||||
${public_include_header_list}
|
||||
DIRECTORY
|
||||
"${CMAKE_CURRENT_BINARY_DIR}/include/"
|
||||
|
||||
DESTINATION
|
||||
${CMAKE_INSTALL_INCLUDEDIR}/sleigh
|
||||
${CMAKE_INSTALL_INCLUDEDIR}
|
||||
)
|
||||
|
||||
# Install the compiled sla files found in 'Ghidra' top-level directory
|
||||
install(
|
||||
DIRECTORY
|
||||
"${spec_files_build_dir}"
|
||||
"${spec_files_build_dir}"
|
||||
|
||||
DESTINATION
|
||||
"${CMAKE_INSTALL_DATADIR}/sleigh"
|
||||
"${CMAKE_INSTALL_DATADIR}/sleigh"
|
||||
)
|
||||
|
||||
set(CMAKE_INSTALL_DOCDIR "${CMAKE_INSTALL_DATAROOTDIR}/doc/sleigh")
|
||||
@@ -667,10 +763,10 @@ if(NOT CMAKE_SKIP_INSTALL_RULES)
|
||||
)
|
||||
install(
|
||||
DIRECTORY
|
||||
"${documentation_output}/html/"
|
||||
"${documentation_output}/html/"
|
||||
|
||||
DESTINATION
|
||||
"${CMAKE_INSTALL_DOCDIR}"
|
||||
"${CMAKE_INSTALL_DOCDIR}"
|
||||
)
|
||||
endif(sleigh_ENABLE_DOCUMENTATION)
|
||||
|
||||
@@ -691,9 +787,8 @@ if(NOT CMAKE_SKIP_INSTALL_RULES)
|
||||
add_custom_target(sleigh_symlinks_builder ALL)
|
||||
|
||||
foreach(target_name "decomp"
|
||||
"ghidra"
|
||||
"sleigh")
|
||||
|
||||
"ghidra"
|
||||
"sleigh")
|
||||
set(source_name "${target_name}_dbg")
|
||||
set(destination_name "${target_name}_opt")
|
||||
set(output_path "${output_folder_path}/${destination_name}")
|
||||
@@ -721,15 +816,15 @@ if(NOT CMAKE_SKIP_INSTALL_RULES)
|
||||
|
||||
install(
|
||||
FILES
|
||||
"${output_path}"
|
||||
"${output_path}"
|
||||
|
||||
DESTINATION
|
||||
"${CMAKE_INSTALL_BINDIR}"
|
||||
"${CMAKE_INSTALL_BINDIR}"
|
||||
|
||||
PERMISSIONS
|
||||
OWNER_READ OWNER_WRITE OWNER_EXECUTE
|
||||
GROUP_READ GROUP_EXECUTE
|
||||
WORLD_READ WORLD_EXECUTE
|
||||
OWNER_READ OWNER_WRITE OWNER_EXECUTE
|
||||
GROUP_READ GROUP_EXECUTE
|
||||
WORLD_READ WORLD_EXECUTE
|
||||
)
|
||||
endforeach()
|
||||
endif()
|
||||
|
||||
@@ -10,7 +10,7 @@ This repository provides a CMake-based build project for SLEIGH so that it can b
|
||||
| ---- | ------- |
|
||||
| Linux | Yes |
|
||||
| macOS | Yes |
|
||||
| Windows | Not yet |
|
||||
| Windows | Yes |
|
||||
|
||||
## Dependencies and Prerequisites
|
||||
|
||||
@@ -19,7 +19,7 @@ This repository provides a CMake-based build project for SLEIGH so that it can b
|
||||
| Name | Version | Linux Package to Install | macOS Homebrew Package to Install |
|
||||
| ---- | ------- | ------------------------ | --------------------------------- |
|
||||
| [Git](https://git-scm.com/) | Latest | git | N/A |
|
||||
| [CMake](https://cmake.org/) | 3.21+ | cmake | cmake |
|
||||
| [CMake](https://cmake.org/) | 3.18+ | cmake | cmake |
|
||||
|
||||
**NOTE**: This CMake project pulls the Ghidra source code from the internet during configuration. See the [note on Ghidra source code section](#note-on-ghidra-source-code) for more details.
|
||||
|
||||
|
||||
@@ -5,5 +5,8 @@ include("${CMAKE_CURRENT_LIST_DIR}/sleighTargets.cmake")
|
||||
# Path relative-root to reach installed specfiles directory
|
||||
set_and_check(sleigh_INSTALL_SPECDIR "@PACKAGE_sleigh_INSTALL_SPECDIR@")
|
||||
|
||||
# Extra version details. Either 'stable' or 'HEAD'
|
||||
set(sleigh_RELEASE_IS_HEAD "@sleigh_RELEASE_IS_HEAD@")
|
||||
|
||||
# Helpers exposed by default when finding sleigh
|
||||
include("${CMAKE_CURRENT_LIST_DIR}/modules/sleighCompile.cmake")
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
#ifndef SLEIGH_LIBCONFIG_H
|
||||
#define SLEIGH_LIBCONFIG_H
|
||||
|
||||
#cmakedefine sleigh_RELEASE_IS_HEAD
|
||||
#cmakedefine sleigh_VERSION "@sleigh_VERSION@"
|
||||
#cmakedefine sleigh_VERSION_MAJOR @sleigh_VERSION_MAJOR@
|
||||
#cmakedefine sleigh_VERSION_MINOR @sleigh_VERSION_MINOR@
|
||||
#cmakedefine sleigh_VERSION_PATCH @sleigh_VERSION_PATCH@
|
||||
#cmakedefine sleigh_VERSION_TWEAK @sleigh_VERSION_TWEAK@
|
||||
|
||||
#endif
|
||||
@@ -6,7 +6,7 @@
|
||||
# the LICENSE file found in the root directory of this source tree.
|
||||
#
|
||||
|
||||
cmake_minimum_required(VERSION 3.15)
|
||||
cmake_minimum_required(VERSION 3.18)
|
||||
|
||||
# Takes the following required arguments:
|
||||
#
|
||||
|
||||
@@ -11,6 +11,8 @@ option(sleigh_ENABLE_EXAMPLES "Set to true to build examples" ON)
|
||||
option(sleigh_ENABLE_DOCUMENTATION "Set to true to enable the documentation")
|
||||
option(sleigh_ENABLE_PACKAGING "Set to true to enable packaging")
|
||||
option(sleigh_ENABLE_SANITIZERS "Set to true to enable sanitizers")
|
||||
set(sleigh_ADDITIONAL_PATCHES "" CACHE STRING
|
||||
"The accepted patch format is git patch files, to be applied via git am. The format of the list is a CMake semicolon separated list.")
|
||||
|
||||
# Internal debug settings
|
||||
option(sleigh_OPACTION_DEBUG "Turns on all the action tracing facilities")
|
||||
@@ -34,12 +36,14 @@ endif()
|
||||
# This is to provide a user experience similar to find_package when
|
||||
# add_subdirectory or FetchContent is used to consume this project
|
||||
set(warning_guard "")
|
||||
|
||||
if(NOT PROJECT_IS_TOP_LEVEL)
|
||||
option(sleigh_INCLUDES_WITH_SYSTEM
|
||||
"Use SYSTEM modifier for sleigh's includes, disabling warnings"
|
||||
ON
|
||||
)
|
||||
mark_as_advanced(sleigh_INCLUDES_WITH_SYSTEM)
|
||||
|
||||
if(sleigh_INCLUDES_WITH_SYSTEM)
|
||||
set(warning_guard SYSTEM)
|
||||
endif()
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
#
|
||||
|
||||
set(PACKAGE_VERSION 1)
|
||||
if("${sleigh_GHIDRA_RELEASE_TYPE}" STREQUAL "HEAD")
|
||||
if("${sleigh_RELEASE_TYPE}" STREQUAL "HEAD")
|
||||
set(PACKAGE_VERSION "DEV.${ghidra_short_commit}")
|
||||
endif()
|
||||
|
||||
|
||||
+110
-24
@@ -6,6 +6,8 @@
|
||||
the LICENSE file found in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
#include <sleigh/libconfig.h>
|
||||
|
||||
#pragma once
|
||||
#ifndef _MSC_VER
|
||||
#pragma GCC diagnostic push
|
||||
@@ -13,31 +15,115 @@
|
||||
#pragma GCC diagnostic ignored "-Wsign-compare"
|
||||
#pragma GCC diagnostic ignored "-Wunused-parameter"
|
||||
#endif
|
||||
#include "address.hh"
|
||||
#include "context.hh"
|
||||
#include "emulate.hh"
|
||||
#include "error.hh"
|
||||
#include "float.hh"
|
||||
#include "globalcontext.hh"
|
||||
#include "loadimage.hh"
|
||||
#include "memstate.hh"
|
||||
#include "opbehavior.hh"
|
||||
#include "opcodes.hh"
|
||||
#include "partmap.hh"
|
||||
#include "pcoderaw.hh"
|
||||
#include "semantics.hh"
|
||||
#include "sleigh.hh"
|
||||
#include "sleighbase.hh"
|
||||
#include "slghpatexpress.hh"
|
||||
#include "slghpattern.hh"
|
||||
#include "slghsymbol.hh"
|
||||
#include "space.hh"
|
||||
#include "translate.hh"
|
||||
#include "types.h"
|
||||
#include "xml.hh"
|
||||
#include <sleigh/action.hh>
|
||||
#include <sleigh/address.hh>
|
||||
#include <sleigh/architecture.hh>
|
||||
#include <sleigh/block.hh>
|
||||
#include <sleigh/blockaction.hh>
|
||||
#include <sleigh/callgraph.hh>
|
||||
#include <sleigh/capability.hh>
|
||||
#include <sleigh/cast.hh>
|
||||
#include <sleigh/codedata.hh>
|
||||
#include <sleigh/comment.hh>
|
||||
#include <sleigh/comment_ghidra.hh>
|
||||
#include <sleigh/condexe.hh>
|
||||
#include <sleigh/context.hh>
|
||||
#include <sleigh/coreaction.hh>
|
||||
#include <sleigh/cover.hh>
|
||||
#include <sleigh/cpool.hh>
|
||||
#include <sleigh/cpool_ghidra.hh>
|
||||
#include <sleigh/crc32.hh>
|
||||
#include <sleigh/database.hh>
|
||||
#include <sleigh/database_ghidra.hh>
|
||||
#include <sleigh/doccore.hh>
|
||||
#include <sleigh/docmain.hh>
|
||||
#include <sleigh/double.hh>
|
||||
#include <sleigh/dynamic.hh>
|
||||
#include <sleigh/emulate.hh>
|
||||
#include <sleigh/emulateutil.hh>
|
||||
#include <sleigh/error.hh>
|
||||
#include <sleigh/filemanage.hh>
|
||||
#include <sleigh/float.hh>
|
||||
#include <sleigh/flow.hh>
|
||||
#include <sleigh/fspec.hh>
|
||||
#include <sleigh/funcdata.hh>
|
||||
#include <sleigh/ghidra_arch.hh>
|
||||
#include <sleigh/ghidra_context.hh>
|
||||
#include <sleigh/ghidra_process.hh>
|
||||
#include <sleigh/ghidra_translate.hh>
|
||||
#include <sleigh/globalcontext.hh>
|
||||
#include <sleigh/grammar.hh>
|
||||
#include <sleigh/graph.hh>
|
||||
#include <sleigh/heritage.hh>
|
||||
#include <sleigh/ifacedecomp.hh>
|
||||
#include <sleigh/ifaceterm.hh>
|
||||
#include <sleigh/inject_ghidra.hh>
|
||||
#include <sleigh/inject_sleigh.hh>
|
||||
#include <sleigh/interface.hh>
|
||||
#include <sleigh/jumptable.hh>
|
||||
#include <sleigh/libdecomp.hh>
|
||||
#include <sleigh/loadimage.hh>
|
||||
#include <sleigh/loadimage_ghidra.hh>
|
||||
#include <sleigh/loadimage_xml.hh>
|
||||
#include <sleigh/memstate.hh>
|
||||
#include <sleigh/merge.hh>
|
||||
#include <sleigh/op.hh>
|
||||
#include <sleigh/opbehavior.hh>
|
||||
#include <sleigh/opcodes.hh>
|
||||
#include <sleigh/options.hh>
|
||||
#include <sleigh/override.hh>
|
||||
#include <sleigh/paramid.hh>
|
||||
#include <sleigh/partmap.hh>
|
||||
#include <sleigh/pcodecompile.hh>
|
||||
#include <sleigh/pcodeinject.hh>
|
||||
#include <sleigh/pcodeparse.hh>
|
||||
#include <sleigh/pcoderaw.hh>
|
||||
#include <sleigh/prefersplit.hh>
|
||||
#include <sleigh/prettyprint.hh>
|
||||
#include <sleigh/printc.hh>
|
||||
#include <sleigh/printjava.hh>
|
||||
#include <sleigh/printlanguage.hh>
|
||||
#include <sleigh/rangemap.hh>
|
||||
#include <sleigh/rangeutil.hh>
|
||||
#include <sleigh/raw_arch.hh>
|
||||
#include <sleigh/ruleaction.hh>
|
||||
#include <sleigh/rulecompile.hh>
|
||||
#include <sleigh/semantics.hh>
|
||||
#include <sleigh/sleigh.hh>
|
||||
#include <sleigh/sleigh_arch.hh>
|
||||
#include <sleigh/sleighbase.hh>
|
||||
#include <sleigh/slgh_compile.hh>
|
||||
#include <sleigh/slghparse.hh>
|
||||
#include <sleigh/slghpatexpress.hh>
|
||||
#include <sleigh/slghpattern.hh>
|
||||
#include <sleigh/slghsymbol.hh>
|
||||
#include <sleigh/space.hh>
|
||||
#include <sleigh/string_ghidra.hh>
|
||||
#include <sleigh/stringmanage.hh>
|
||||
#include <sleigh/subflow.hh>
|
||||
#include <sleigh/testfunction.hh>
|
||||
#include <sleigh/transform.hh>
|
||||
#include <sleigh/translate.hh>
|
||||
#include <sleigh/type.hh>
|
||||
#include <sleigh/typegrp_ghidra.hh>
|
||||
#include <sleigh/typeop.hh>
|
||||
#include <sleigh/types.h>
|
||||
#include <sleigh/unify.hh>
|
||||
#include <sleigh/userop.hh>
|
||||
#include <sleigh/variable.hh>
|
||||
#include <sleigh/varmap.hh>
|
||||
#include <sleigh/varnode.hh>
|
||||
#include <sleigh/xml.hh>
|
||||
#include <sleigh/xml_arch.hh>
|
||||
|
||||
#ifdef sleigh_RELEASE_IS_HEAD
|
||||
#include <sleigh/unionresolve.hh>
|
||||
#include <sleigh/marshal.hh>
|
||||
#endif
|
||||
|
||||
#ifndef _MSC_VER
|
||||
#pragma GCC diagnostic pop
|
||||
#endif
|
||||
|
||||
#include "Support.h"
|
||||
#include "Version.h"
|
||||
#include <sleigh/Support.h>
|
||||
#include <sleigh/Version.h>
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
From ae78cca16d5d34d61912cbe6d9cb2f959cc36d21 Mon Sep 17 00:00:00 2001
|
||||
From: Eric Kilmer <eric.d.kilmer@gmail.com>
|
||||
Date: Wed, 27 Jul 2022 11:53:41 -0400
|
||||
Subject: [PATCH] Initialize ID lookup tables to fix sleighexample
|
||||
|
||||
---
|
||||
Ghidra/Features/Decompiler/src/decompile/cpp/sleighexample.cc | 3 +++
|
||||
1 file changed, 3 insertions(+)
|
||||
|
||||
diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/sleighexample.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/sleighexample.cc
|
||||
index 3a61418e6..87a4d7980 100644
|
||||
--- a/Ghidra/Features/Decompiler/src/decompile/cpp/sleighexample.cc
|
||||
+++ b/Ghidra/Features/Decompiler/src/decompile/cpp/sleighexample.cc
|
||||
@@ -294,6 +294,9 @@ int main(int argc,char **argv)
|
||||
}
|
||||
string action(argv[1]);
|
||||
|
||||
+ AttributeId::initialize();
|
||||
+ ElementId::initialize();
|
||||
+
|
||||
// Set up the loadimage
|
||||
MyLoadImage loader(0x80483b4,myprog,408);
|
||||
// loader->open();
|
||||
--
|
||||
2.37.1
|
||||
|
||||
@@ -0,0 +1,137 @@
|
||||
From 44c439d879c18c2873d5605821132957680a4405 Mon Sep 17 00:00:00 2001
|
||||
From: Eric Kilmer <eric.d.kilmer@gmail.com>
|
||||
Date: Thu, 28 Jul 2022 09:20:03 -0400
|
||||
Subject: [PATCH] Add include guards to decompiler C++ headers
|
||||
|
||||
---
|
||||
Ghidra/Features/Decompiler/src/decompile/cpp/bfd_arch.hh | 5 +++++
|
||||
Ghidra/Features/Decompiler/src/decompile/cpp/graph.hh | 6 ++++++
|
||||
Ghidra/Features/Decompiler/src/decompile/cpp/ifaceterm.hh | 5 +++++
|
||||
Ghidra/Features/Decompiler/src/decompile/cpp/raw_arch.hh | 5 +++++
|
||||
.../Features/Decompiler/src/decompile/cpp/slgh_compile.hh | 5 +++++
|
||||
Ghidra/Features/Decompiler/src/decompile/cpp/xml_arch.hh | 6 ++++++
|
||||
6 files changed, 32 insertions(+)
|
||||
|
||||
diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/bfd_arch.hh b/Ghidra/Features/Decompiler/src/decompile/cpp/bfd_arch.hh
|
||||
index 875d3bb78..6ade01ecc 100644
|
||||
--- a/Ghidra/Features/Decompiler/src/decompile/cpp/bfd_arch.hh
|
||||
+++ b/Ghidra/Features/Decompiler/src/decompile/cpp/bfd_arch.hh
|
||||
@@ -17,6 +17,9 @@
|
||||
/// \file bfd_arch.hh
|
||||
/// \brief Specific implementation of Architecture using GNU BFD libraries
|
||||
|
||||
+#ifndef __BFD_ARCH__
|
||||
+#define __BFD_ARCH__
|
||||
+
|
||||
#include "sleigh_arch.hh"
|
||||
#include "loadimage_bfd.hh"
|
||||
|
||||
@@ -47,3 +50,5 @@ class BfdArchitecture : public SleighArchitecture {
|
||||
BfdArchitecture(const string &fname,const string &targ,ostream *estream); ///< Constructor
|
||||
virtual ~BfdArchitecture(void) {}
|
||||
};
|
||||
+
|
||||
+#endif
|
||||
diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/graph.hh b/Ghidra/Features/Decompiler/src/decompile/cpp/graph.hh
|
||||
index 364a5258d..edd6ce865 100644
|
||||
--- a/Ghidra/Features/Decompiler/src/decompile/cpp/graph.hh
|
||||
+++ b/Ghidra/Features/Decompiler/src/decompile/cpp/graph.hh
|
||||
@@ -14,8 +14,14 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
+
|
||||
+#ifndef __GRAPH__
|
||||
+#define __GRAPH__
|
||||
+
|
||||
#include "funcdata.hh"
|
||||
|
||||
extern void dump_dataflow_graph(Funcdata &data,ostream &s);
|
||||
extern void dump_controlflow_graph(const string &name,const BlockGraph &graph,ostream &s);
|
||||
extern void dump_dom_graph(const string &name,const BlockGraph &graph,ostream &s);
|
||||
+
|
||||
+#endif
|
||||
diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/ifaceterm.hh b/Ghidra/Features/Decompiler/src/decompile/cpp/ifaceterm.hh
|
||||
index 3ca912dd6..0b70d8b22 100644
|
||||
--- a/Ghidra/Features/Decompiler/src/decompile/cpp/ifaceterm.hh
|
||||
+++ b/Ghidra/Features/Decompiler/src/decompile/cpp/ifaceterm.hh
|
||||
@@ -16,6 +16,9 @@
|
||||
/// \file ifaceterm.hh
|
||||
/// \brief Add some terminal capabilities to the command-line interface (IfaceStatus)
|
||||
|
||||
+#ifndef __IFACE_TERM__
|
||||
+#define __IFACE_TERM__
|
||||
+
|
||||
#include "interface.hh"
|
||||
|
||||
#ifdef __TERMINAL__
|
||||
@@ -48,3 +51,5 @@ class IfaceTerm : public IfaceStatus {
|
||||
virtual void popScript(void);
|
||||
virtual bool isStreamFinished(void) const;
|
||||
};
|
||||
+
|
||||
+#endif
|
||||
diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/raw_arch.hh b/Ghidra/Features/Decompiler/src/decompile/cpp/raw_arch.hh
|
||||
index 2245840a0..490abf901 100644
|
||||
--- a/Ghidra/Features/Decompiler/src/decompile/cpp/raw_arch.hh
|
||||
+++ b/Ghidra/Features/Decompiler/src/decompile/cpp/raw_arch.hh
|
||||
@@ -15,6 +15,10 @@
|
||||
*/
|
||||
/// \file raw_arch.hh
|
||||
/// \brief Bare bones capability for treating a file as a raw executable image
|
||||
+
|
||||
+#ifndef __RAW_ARCH__
|
||||
+#define __RAW_ARCH__
|
||||
+
|
||||
#include "sleigh_arch.hh"
|
||||
#include "loadimage.hh"
|
||||
|
||||
@@ -46,3 +50,4 @@ class RawBinaryArchitecture : public SleighArchitecture {
|
||||
virtual ~RawBinaryArchitecture(void) {}
|
||||
};
|
||||
|
||||
+#endif
|
||||
diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/slgh_compile.hh b/Ghidra/Features/Decompiler/src/decompile/cpp/slgh_compile.hh
|
||||
index e7ab19185..8fd9ba2fd 100644
|
||||
--- a/Ghidra/Features/Decompiler/src/decompile/cpp/slgh_compile.hh
|
||||
+++ b/Ghidra/Features/Decompiler/src/decompile/cpp/slgh_compile.hh
|
||||
@@ -16,6 +16,9 @@
|
||||
/// \file slgh_compile.hh
|
||||
/// \brief High-level control of the sleigh compilation process
|
||||
|
||||
+#ifndef __SLGH_COMPILE__
|
||||
+#define __SLGH_COMPILE__
|
||||
+
|
||||
#include "sleighbase.hh"
|
||||
#include "pcodecompile.hh"
|
||||
#include "filemanage.hh"
|
||||
@@ -446,3 +449,5 @@ class SleighCompile : public SleighBase {
|
||||
|
||||
extern SleighCompile *slgh; ///< A global reference to the SLEIGH compiler accessible to the parse functions
|
||||
extern int yydebug; ///< Debug state for the SLEIGH parse functions
|
||||
+
|
||||
+#endif
|
||||
diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/xml_arch.hh b/Ghidra/Features/Decompiler/src/decompile/cpp/xml_arch.hh
|
||||
index d395fb8a3..6371148b0 100644
|
||||
--- a/Ghidra/Features/Decompiler/src/decompile/cpp/xml_arch.hh
|
||||
+++ b/Ghidra/Features/Decompiler/src/decompile/cpp/xml_arch.hh
|
||||
@@ -15,6 +15,10 @@
|
||||
*/
|
||||
/// \file xml_arch.hh
|
||||
/// \brief Extension to read executables based on an XML format
|
||||
+
|
||||
+#ifndef __XML_ARCH__
|
||||
+#define __XML_ARCH__
|
||||
+
|
||||
#include "sleigh_arch.hh"
|
||||
#include "loadimage_xml.hh"
|
||||
|
||||
@@ -45,3 +49,5 @@ class XmlArchitecture : public SleighArchitecture {
|
||||
XmlArchitecture(const string &fname,const string &targ,ostream *estream); ///< Constructor
|
||||
virtual ~XmlArchitecture(void) {}
|
||||
};
|
||||
+
|
||||
+#endif
|
||||
--
|
||||
2.37.1
|
||||
|
||||
@@ -0,0 +1,293 @@
|
||||
From f62b1e5483a99efe3ae6598291ec010ecee749d4 Mon Sep 17 00:00:00 2001
|
||||
From: Alex Cameron <asc@tetsuo.sh>
|
||||
Date: Mon, 7 Feb 2022 02:02:03 +1100
|
||||
Subject: [PATCH] Fix UBSAN errors in decompiler
|
||||
|
||||
---
|
||||
.../Decompiler/src/decompile/cpp/address.cc | 4 ++--
|
||||
.../Decompiler/src/decompile/cpp/fspec.cc | 8 ++++++--
|
||||
.../src/decompile/cpp/funcdata_varnode.cc | 8 +++++++-
|
||||
.../Decompiler/src/decompile/cpp/op.cc | 6 +++++-
|
||||
.../Decompiler/src/decompile/cpp/opbehavior.cc | 8 +++++++-
|
||||
.../src/decompile/cpp/pcodecompile.cc | 18 +++++++++++-------
|
||||
.../Decompiler/src/decompile/cpp/ruleaction.cc | 18 ++++++++++++++----
|
||||
.../Decompiler/src/decompile/cpp/semantics.cc | 2 ++
|
||||
.../Decompiler/src/decompile/cpp/semantics.hh | 2 +-
|
||||
.../src/decompile/cpp/slgh_compile.cc | 2 +-
|
||||
.../Decompiler/src/decompile/cpp/slghsymbol.cc | 2 +-
|
||||
.../Decompiler/src/decompile/cpp/type.cc | 2 +-
|
||||
.../src/decompile/unittests/testfloatemu.cc | 2 +-
|
||||
13 files changed, 59 insertions(+), 23 deletions(-)
|
||||
|
||||
diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/address.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/address.cc
|
||||
index 1cb02c5b2..3a60d1322 100644
|
||||
--- a/Ghidra/Features/Decompiler/src/decompile/cpp/address.cc
|
||||
+++ b/Ghidra/Features/Decompiler/src/decompile/cpp/address.cc
|
||||
@@ -685,7 +685,7 @@ uintb sign_extend(uintb in,int4 sizein,int4 sizeout)
|
||||
void sign_extend(intb &val,int4 bit)
|
||||
|
||||
{
|
||||
- intb mask = 0;
|
||||
+ uintb mask = 0;
|
||||
mask = (~mask)<<bit;
|
||||
if (((val>>bit)&1)!=0)
|
||||
val |= mask;
|
||||
@@ -699,7 +699,7 @@ void sign_extend(intb &val,int4 bit)
|
||||
void zero_extend(intb &val,int4 bit)
|
||||
|
||||
{
|
||||
- intb mask = 0;
|
||||
+ uintb mask = 0;
|
||||
mask = (~mask)<<bit;
|
||||
mask <<= 1;
|
||||
val &= (~mask);
|
||||
diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/fspec.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/fspec.cc
|
||||
index 0526ed04c..e79fd041e 100644
|
||||
--- a/Ghidra/Features/Decompiler/src/decompile/cpp/fspec.cc
|
||||
+++ b/Ghidra/Features/Decompiler/src/decompile/cpp/fspec.cc
|
||||
@@ -2633,8 +2633,12 @@ void ProtoModelMerged::decode(Decoder &decoder)
|
||||
modellist.push_back(mymodel);
|
||||
}
|
||||
decoder.closeElement(elemId);
|
||||
- ((ParamListMerged *)input)->finalize();
|
||||
- ((ParamListMerged *)output)->finalize();
|
||||
+ if (input->getType() == ParamList::p_merged) {
|
||||
+ ((ParamListMerged *)input)->finalize();
|
||||
+ }
|
||||
+ if (output->getType() == ParamList::p_merged) {
|
||||
+ ((ParamListMerged *)output)->finalize();
|
||||
+ }
|
||||
}
|
||||
|
||||
void ParameterBasic::setTypeLock(bool val)
|
||||
diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/funcdata_varnode.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/funcdata_varnode.cc
|
||||
index e6b282ac7..f6a35728f 100644
|
||||
--- a/Ghidra/Features/Decompiler/src/decompile/cpp/funcdata_varnode.cc
|
||||
+++ b/Ghidra/Features/Decompiler/src/decompile/cpp/funcdata_varnode.cc
|
||||
@@ -501,7 +501,13 @@ void Funcdata::setHighLevel(void)
|
||||
void Funcdata::transferVarnodeProperties(Varnode *vn,Varnode *newVn,int4 lsbOffset)
|
||||
|
||||
{
|
||||
- uintb newConsume = (vn->getConsume() >> 8*lsbOffset) & calc_mask(newVn->getSize());
|
||||
+ uintb newConsume = vn->getConsume();
|
||||
+ if (8*lsbOffset < sizeof(newConsume)) {
|
||||
+ newConsume >>= 8*lsbOffset;
|
||||
+ } else {
|
||||
+ newConsume = 0;
|
||||
+ }
|
||||
+ newConsume &= calc_mask(newVn->getSize());
|
||||
|
||||
uint4 vnFlags = vn->getFlags() & (Varnode::directwrite|Varnode::addrforce);
|
||||
|
||||
diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/op.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/op.cc
|
||||
index b4f8a3f8e..068393416 100644
|
||||
--- a/Ghidra/Features/Decompiler/src/decompile/cpp/op.cc
|
||||
+++ b/Ghidra/Features/Decompiler/src/decompile/cpp/op.cc
|
||||
@@ -667,7 +667,11 @@ uintb PcodeOp::getNZMaskLocal(bool cliploop) const
|
||||
break;
|
||||
case CPUI_PIECE:
|
||||
resmask = getIn(0)->getNZMask();
|
||||
- resmask <<= 8*getIn(1)->getSize();
|
||||
+ if (8*getIn(1)->getSize() < sizeof(resmask)) {
|
||||
+ resmask <<= 8*getIn(1)->getSize();
|
||||
+ } else {
|
||||
+ resmask = 0;
|
||||
+ }
|
||||
resmask |= getIn(1)->getNZMask();
|
||||
break;
|
||||
case CPUI_INT_MULT:
|
||||
diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/opbehavior.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/opbehavior.cc
|
||||
index 3b84bac6a..3e0c39904 100644
|
||||
--- a/Ghidra/Features/Decompiler/src/decompile/cpp/opbehavior.cc
|
||||
+++ b/Ghidra/Features/Decompiler/src/decompile/cpp/opbehavior.cc
|
||||
@@ -747,7 +747,13 @@ uintb OpBehaviorPiece::evaluateBinary(int4 sizeout,int4 sizein,uintb in1,uintb i
|
||||
uintb OpBehaviorSubpiece::evaluateBinary(int4 sizeout,int4 sizein,uintb in1,uintb in2) const
|
||||
|
||||
{
|
||||
- uintb res = (in1>>(in2*8)) & calc_mask(sizeout);
|
||||
+ uintb res = in1;
|
||||
+ if ((in2*8) < sizeof(in1)) {
|
||||
+ res >>= (in2*8);
|
||||
+ } else {
|
||||
+ res = 0;
|
||||
+ }
|
||||
+ res &= calc_mask(sizeout);
|
||||
return res;
|
||||
}
|
||||
|
||||
diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/pcodecompile.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/pcodecompile.cc
|
||||
index 49128f7e6..133da8178 100644
|
||||
--- a/Ghidra/Features/Decompiler/src/decompile/cpp/pcodecompile.cc
|
||||
+++ b/Ghidra/Features/Decompiler/src/decompile/cpp/pcodecompile.cc
|
||||
@@ -619,8 +619,10 @@ vector<OpTpl *> *PcodeCompile::assignBitRange(VarnodeTpl *vn,uint4 bitoffset,uin
|
||||
uint4 smallsize = (numbits+7)/8; // Size of input (output of rhs)
|
||||
bool shiftneeded = (bitoffset != 0);
|
||||
bool zextneeded = true;
|
||||
- uintb mask = (uintb)2;
|
||||
- mask = ~(((mask<<(numbits-1))-1) << bitoffset);
|
||||
+ uintb mask = 0;
|
||||
+ const int4 masknumbits = sizeof(mask) * 8;
|
||||
+ if (numbits - 1 < masknumbits && bitoffset < masknumbits)
|
||||
+ mask = ~(((static_cast<uintb>(2) << (numbits - 1)) - 1) << bitoffset);
|
||||
|
||||
if (vn->getSize().getType()==ConstTpl::real) {
|
||||
// If we know the size of the bitranged varnode, we can
|
||||
@@ -724,9 +726,6 @@ ExprTree *PcodeCompile::createBitRange(SpecificSymbol *sym,uint4 bitoffset,uint4
|
||||
}
|
||||
}
|
||||
|
||||
- uintb mask = (uintb)2;
|
||||
- mask = ((mask<<(numbits-1))-1);
|
||||
-
|
||||
if (truncneeded && ((bitoffset % 8)==0)) {
|
||||
truncshift = bitoffset/8;
|
||||
bitoffset = 0;
|
||||
@@ -749,8 +748,13 @@ ExprTree *PcodeCompile::createBitRange(SpecificSymbol *sym,uint4 bitoffset,uint4
|
||||
appendOp(CPUI_INT_RIGHT,res,bitoffset,4);
|
||||
if (truncneeded)
|
||||
appendOp(CPUI_SUBPIECE,res,truncshift,4);
|
||||
- if (maskneeded)
|
||||
- appendOp(CPUI_INT_AND,res,mask,finalsize);
|
||||
+ if (maskneeded) {
|
||||
+ uintb mask = 0;
|
||||
+ if (numbits - 1 < sizeof(mask) * 8)
|
||||
+ mask = static_cast<uintb>(2) << (numbits - 1);
|
||||
+ --mask;
|
||||
+ appendOp(CPUI_INT_AND, res, mask, finalsize);
|
||||
+ }
|
||||
force_size(res->outvn,ConstTpl(ConstTpl::real,finalsize),*res->ops);
|
||||
return res;
|
||||
}
|
||||
diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/ruleaction.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/ruleaction.cc
|
||||
index b5bdb4700..ef741545c 100644
|
||||
--- a/Ghidra/Features/Decompiler/src/decompile/cpp/ruleaction.cc
|
||||
+++ b/Ghidra/Features/Decompiler/src/decompile/cpp/ruleaction.cc
|
||||
@@ -974,7 +974,12 @@ int4 RulePullsubIndirect::applyOp(PcodeOp *op,Funcdata &data)
|
||||
Varnode *outvn = op->getOut();
|
||||
if (outvn->isPrecisLo()||outvn->isPrecisHi()) return 0; // Don't pull apart double precision object
|
||||
|
||||
- uintb consume = calc_mask(newSize) << 8 * minByte;
|
||||
+ uintb consume = calc_mask(newSize);
|
||||
+ if (8 * minByte < sizeof(consume)) {
|
||||
+ consume <<= 8 * minByte;
|
||||
+ } else {
|
||||
+ consume = 0;
|
||||
+ }
|
||||
consume = ~consume;
|
||||
if ((consume & indir->getIn(0)->getConsume())!=0) return 0;
|
||||
|
||||
@@ -6785,8 +6790,9 @@ int4 RulePtrsubCharConstant::applyOp(PcodeOp *op,Funcdata &data)
|
||||
Varnode *sb = op->getIn(0);
|
||||
Datatype *sbType = sb->getTypeReadFacing(op);
|
||||
if (sbType->getMetatype() != TYPE_PTR) return 0;
|
||||
- TypeSpacebase *sbtype = (TypeSpacebase *)((TypePointer *)sbType)->getPtrTo();
|
||||
- if (sbtype->getMetatype() != TYPE_SPACEBASE) return 0;
|
||||
+ Datatype *sbTypePtr = ((TypePointer *)sbType)->getPtrTo();
|
||||
+ if (sbTypePtr->getMetatype() != TYPE_SPACEBASE) return 0;
|
||||
+ TypeSpacebase *sbtype = (TypeSpacebase *)sbTypePtr;
|
||||
Varnode *vn1 = op->getIn(1);
|
||||
if (!vn1->isConstant()) return 0;
|
||||
Varnode *outvn = op->getOut();
|
||||
@@ -7822,7 +7828,11 @@ int4 RuleSubvarSubpiece::applyOp(PcodeOp *op,Funcdata &data)
|
||||
Varnode *outvn = op->getOut();
|
||||
int4 flowsize = outvn->getSize();
|
||||
uintb mask = calc_mask( flowsize );
|
||||
- mask <<= 8*((int4)op->getIn(1)->getOffset());
|
||||
+ if (8*((int4)op->getIn(1)->getOffset()) < sizeof(mask)) {
|
||||
+ mask <<= 8*((int4)op->getIn(1)->getOffset());
|
||||
+ } else {
|
||||
+ mask = 0;
|
||||
+ }
|
||||
bool aggressive = outvn->isPtrFlow();
|
||||
if (!aggressive) {
|
||||
if ((vn->getConsume() & mask) != vn->getConsume()) return 0;
|
||||
diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/semantics.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/semantics.cc
|
||||
index f8c1580a8..8ae5ff293 100644
|
||||
--- a/Ghidra/Features/Decompiler/src/decompile/cpp/semantics.cc
|
||||
+++ b/Ghidra/Features/Decompiler/src/decompile/cpp/semantics.cc
|
||||
@@ -20,6 +20,7 @@ ConstTpl::ConstTpl(const_type tp)
|
||||
|
||||
{ // Constructor for relative jump constants and uniques
|
||||
type = tp;
|
||||
+ select = v_space;
|
||||
}
|
||||
|
||||
ConstTpl::ConstTpl(const_type tp,uintb val)
|
||||
@@ -54,6 +55,7 @@ ConstTpl::ConstTpl(AddrSpace *sid)
|
||||
{
|
||||
type = spaceid;
|
||||
value.spaceid = sid;
|
||||
+ select = v_space;
|
||||
}
|
||||
|
||||
bool ConstTpl::isConstSpace(void) const
|
||||
diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/semantics.hh b/Ghidra/Features/Decompiler/src/decompile/cpp/semantics.hh
|
||||
index dccf0437d..f7f598667 100644
|
||||
--- a/Ghidra/Features/Decompiler/src/decompile/cpp/semantics.hh
|
||||
+++ b/Ghidra/Features/Decompiler/src/decompile/cpp/semantics.hh
|
||||
@@ -46,7 +46,7 @@ private:
|
||||
static void printHandleSelector(ostream &s,v_field val);
|
||||
static v_field readHandleSelector(const string &name);
|
||||
public:
|
||||
- ConstTpl(void) { type = real; value_real = 0; }
|
||||
+ ConstTpl(void) { type = real; value_real = 0; select = v_space; }
|
||||
ConstTpl(const ConstTpl &op2) {
|
||||
type=op2.type; value=op2.value; value_real=op2.value_real; select=op2.select; }
|
||||
ConstTpl(const_type tp,uintb val);
|
||||
diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/slgh_compile.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/slgh_compile.cc
|
||||
index 3ec58b9d0..55fcfd7c8 100644
|
||||
--- a/Ghidra/Features/Decompiler/src/decompile/cpp/slgh_compile.cc
|
||||
+++ b/Ghidra/Features/Decompiler/src/decompile/cpp/slgh_compile.cc
|
||||
@@ -2150,8 +2150,8 @@ string SleighCompile::checkSymbols(SymbolScope *scope)
|
||||
ostringstream msg;
|
||||
SymbolTree::const_iterator iter;
|
||||
for(iter=scope->begin();iter!=scope->end();++iter) {
|
||||
+ if ((*iter)->getType() != SleighSymbol::label_symbol) continue;
|
||||
LabelSymbol *sym = (LabelSymbol *)*iter;
|
||||
- if (sym->getType() != SleighSymbol::label_symbol) continue;
|
||||
if (sym->getRefCount() == 0)
|
||||
msg << " Label <" << sym->getName() << "> was placed but not used" << endl;
|
||||
else if (!sym->isPlaced())
|
||||
diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/slghsymbol.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/slghsymbol.cc
|
||||
index 5f4a8fe32..50bc33b8b 100644
|
||||
--- a/Ghidra/Features/Decompiler/src/decompile/cpp/slghsymbol.cc
|
||||
+++ b/Ghidra/Features/Decompiler/src/decompile/cpp/slghsymbol.cc
|
||||
@@ -2499,7 +2499,7 @@ void ContextOp::restoreXml(const Element *el,SleighBase *trans)
|
||||
const List &list(el->getChildren());
|
||||
List::const_iterator iter;
|
||||
iter = list.begin();
|
||||
- patexp = (PatternValue *)PatternExpression::restoreExpression(*iter,trans);
|
||||
+ patexp = PatternExpression::restoreExpression(*iter,trans);
|
||||
patexp->layClaim();
|
||||
}
|
||||
|
||||
diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/type.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/type.cc
|
||||
index b8dbcd55b..b2d0c1bb6 100644
|
||||
--- a/Ghidra/Features/Decompiler/src/decompile/cpp/type.cc
|
||||
+++ b/Ghidra/Features/Decompiler/src/decompile/cpp/type.cc
|
||||
@@ -3073,8 +3073,8 @@ void TypeFactory::recalcPointerSubmeta(Datatype *base,sub_metatype sub)
|
||||
top.submeta = sub; // Search on the incorrect submeta
|
||||
iter = tree.lower_bound(&top);
|
||||
while(iter != tree.end()) {
|
||||
+ if ((*iter)->getMetatype() != TYPE_PTR) break;
|
||||
TypePointer *ptr = (TypePointer *)*iter;
|
||||
- if (ptr->getMetatype() != TYPE_PTR) break;
|
||||
if (ptr->ptrto != base) break;
|
||||
++iter;
|
||||
if (ptr->submeta == sub) {
|
||||
diff --git a/Ghidra/Features/Decompiler/src/decompile/unittests/testfloatemu.cc b/Ghidra/Features/Decompiler/src/decompile/unittests/testfloatemu.cc
|
||||
index ab99382a3..67d92c573 100644
|
||||
--- a/Ghidra/Features/Decompiler/src/decompile/unittests/testfloatemu.cc
|
||||
+++ b/Ghidra/Features/Decompiler/src/decompile/unittests/testfloatemu.cc
|
||||
@@ -338,7 +338,7 @@ TEST(float_opTrunc_to_int) {
|
||||
|
||||
for(float f:float_test_values) {
|
||||
// avoid undefined behavior
|
||||
- if((int64_t)f > std::numeric_limits<int>::max() || (int64_t)f < std::numeric_limits<int>::min())
|
||||
+ if(f > std::numeric_limits<int>::max() || f < std::numeric_limits<int>::min() || std::isnan(f))
|
||||
continue;
|
||||
uintb true_result = ((uintb)(int32_t)f) & 0xffffffff;
|
||||
uintb encoding = format.getEncoding(f);
|
||||
--
|
||||
2.32.1 (Apple Git-133)
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
From 773dda85b84a03c8795e27f1df87e6024bdb208a Mon Sep 17 00:00:00 2001
|
||||
From: Alex Cameron <asc@tetsuo.sh>
|
||||
Date: Wed, 3 Aug 2022 20:01:18 +1000
|
||||
Subject: [PATCH] Use `stroull` instead of `stroul` to parse address offsets
|
||||
|
||||
---
|
||||
Ghidra/Features/Decompiler/src/decompile/cpp/space.cc | 7 ++++++-
|
||||
1 file changed, 6 insertions(+), 1 deletion(-)
|
||||
|
||||
diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/space.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/space.cc
|
||||
index c51e58560..c5cc7541d 100644
|
||||
--- a/Ghidra/Features/Decompiler/src/decompile/cpp/space.cc
|
||||
+++ b/Ghidra/Features/Decompiler/src/decompile/cpp/space.cc
|
||||
@@ -16,6 +16,8 @@
|
||||
#include "space.hh"
|
||||
#include "translate.hh"
|
||||
|
||||
+#include <climits>
|
||||
+
|
||||
AttributeId ATTRIB_BASE = AttributeId("base",89);
|
||||
AttributeId ATTRIB_DEADCODEDELAY = AttributeId("deadcodedelay",90);
|
||||
AttributeId ATTRIB_DELAY = AttributeId("delay", 91);
|
||||
@@ -268,7 +270,10 @@ uintb AddrSpace::read(const string &s,int4 &size) const
|
||||
}
|
||||
}
|
||||
catch(LowlevelError &err) { // Name doesn't exist
|
||||
- offset = strtoul(s.c_str(),&tmpdata,0);
|
||||
+ offset = strtoull(s.c_str(),&tmpdata,0);
|
||||
+ if (offset == ULLONG_MAX) {
|
||||
+ throw LowlevelError("Offset outside of valid range");
|
||||
+ }
|
||||
offset = addressToByte(offset,wordsize);
|
||||
enddata = (const char *) tmpdata;
|
||||
if (enddata - s.c_str() == s.size()) { // If no size or offset override
|
||||
--
|
||||
2.32.1 (Apple Git-133)
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
# Ghidra Patches
|
||||
|
||||
This directory contains small patches that should not affect any deployed Ghidra sleigh functionality from its original intent.
|
||||
This directory contains small patches that do not affect any deployed Ghidra sleigh functionality from its original intent unless otherwise specified.
|
||||
|
||||
These patches primarily support packaging and testing, or fixing critical issues that prevent building for one reason or another.
|
||||
|
||||
|
||||
@@ -0,0 +1,137 @@
|
||||
From 143296b212e6c3c8bc8cc1e0d88511f5bbc858ff Mon Sep 17 00:00:00 2001
|
||||
From: Eric Kilmer <eric.d.kilmer@gmail.com>
|
||||
Date: Thu, 28 Jul 2022 09:20:03 -0400
|
||||
Subject: [PATCH] Add include guards to decompiler C++ headers
|
||||
|
||||
---
|
||||
Ghidra/Features/Decompiler/src/decompile/cpp/bfd_arch.hh | 5 +++++
|
||||
Ghidra/Features/Decompiler/src/decompile/cpp/graph.hh | 6 ++++++
|
||||
Ghidra/Features/Decompiler/src/decompile/cpp/ifaceterm.hh | 5 +++++
|
||||
Ghidra/Features/Decompiler/src/decompile/cpp/raw_arch.hh | 5 +++++
|
||||
.../Features/Decompiler/src/decompile/cpp/slgh_compile.hh | 5 +++++
|
||||
Ghidra/Features/Decompiler/src/decompile/cpp/xml_arch.hh | 6 ++++++
|
||||
6 files changed, 32 insertions(+)
|
||||
|
||||
diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/bfd_arch.hh b/Ghidra/Features/Decompiler/src/decompile/cpp/bfd_arch.hh
|
||||
index 9d1f21d04..4f5c8ac2b 100644
|
||||
--- a/Ghidra/Features/Decompiler/src/decompile/cpp/bfd_arch.hh
|
||||
+++ b/Ghidra/Features/Decompiler/src/decompile/cpp/bfd_arch.hh
|
||||
@@ -17,6 +17,9 @@
|
||||
/// \file bfd_arch.hh
|
||||
/// \brief Specific implementation of Architecture using GNU BFD libraries
|
||||
|
||||
+#ifndef __BFD_ARCH__
|
||||
+#define __BFD_ARCH__
|
||||
+
|
||||
#include "sleigh_arch.hh"
|
||||
#include "loadimage_bfd.hh"
|
||||
|
||||
@@ -45,3 +48,5 @@ class BfdArchitecture : public SleighArchitecture {
|
||||
BfdArchitecture(const string &fname,const string &targ,ostream *estream); ///< Constructor
|
||||
virtual ~BfdArchitecture(void) {}
|
||||
};
|
||||
+
|
||||
+#endif
|
||||
diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/graph.hh b/Ghidra/Features/Decompiler/src/decompile/cpp/graph.hh
|
||||
index 364a5258d..edd6ce865 100644
|
||||
--- a/Ghidra/Features/Decompiler/src/decompile/cpp/graph.hh
|
||||
+++ b/Ghidra/Features/Decompiler/src/decompile/cpp/graph.hh
|
||||
@@ -14,8 +14,14 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
+
|
||||
+#ifndef __GRAPH__
|
||||
+#define __GRAPH__
|
||||
+
|
||||
#include "funcdata.hh"
|
||||
|
||||
extern void dump_dataflow_graph(Funcdata &data,ostream &s);
|
||||
extern void dump_controlflow_graph(const string &name,const BlockGraph &graph,ostream &s);
|
||||
extern void dump_dom_graph(const string &name,const BlockGraph &graph,ostream &s);
|
||||
+
|
||||
+#endif
|
||||
diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/ifaceterm.hh b/Ghidra/Features/Decompiler/src/decompile/cpp/ifaceterm.hh
|
||||
index 3ca912dd6..0b70d8b22 100644
|
||||
--- a/Ghidra/Features/Decompiler/src/decompile/cpp/ifaceterm.hh
|
||||
+++ b/Ghidra/Features/Decompiler/src/decompile/cpp/ifaceterm.hh
|
||||
@@ -16,6 +16,9 @@
|
||||
/// \file ifaceterm.hh
|
||||
/// \brief Add some terminal capabilities to the command-line interface (IfaceStatus)
|
||||
|
||||
+#ifndef __IFACE_TERM__
|
||||
+#define __IFACE_TERM__
|
||||
+
|
||||
#include "interface.hh"
|
||||
|
||||
#ifdef __TERMINAL__
|
||||
@@ -48,3 +51,5 @@ class IfaceTerm : public IfaceStatus {
|
||||
virtual void popScript(void);
|
||||
virtual bool isStreamFinished(void) const;
|
||||
};
|
||||
+
|
||||
+#endif
|
||||
diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/raw_arch.hh b/Ghidra/Features/Decompiler/src/decompile/cpp/raw_arch.hh
|
||||
index 7457a6303..a99fcbcd8 100644
|
||||
--- a/Ghidra/Features/Decompiler/src/decompile/cpp/raw_arch.hh
|
||||
+++ b/Ghidra/Features/Decompiler/src/decompile/cpp/raw_arch.hh
|
||||
@@ -15,6 +15,10 @@
|
||||
*/
|
||||
/// \file raw_arch.hh
|
||||
/// \brief Bare bones capability for treating a file as a raw executable image
|
||||
+
|
||||
+#ifndef __RAW_ARCH__
|
||||
+#define __RAW_ARCH__
|
||||
+
|
||||
#include "sleigh_arch.hh"
|
||||
#include "loadimage.hh"
|
||||
|
||||
@@ -44,3 +48,4 @@ class RawBinaryArchitecture : public SleighArchitecture {
|
||||
virtual ~RawBinaryArchitecture(void) {}
|
||||
};
|
||||
|
||||
+#endif
|
||||
diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/slgh_compile.hh b/Ghidra/Features/Decompiler/src/decompile/cpp/slgh_compile.hh
|
||||
index edb19aed3..78c8ad21c 100644
|
||||
--- a/Ghidra/Features/Decompiler/src/decompile/cpp/slgh_compile.hh
|
||||
+++ b/Ghidra/Features/Decompiler/src/decompile/cpp/slgh_compile.hh
|
||||
@@ -16,6 +16,9 @@
|
||||
/// \file slgh_compile.hh
|
||||
/// \brief High-level control of the sleigh compilation process
|
||||
|
||||
+#ifndef __SLGH_COMPILE__
|
||||
+#define __SLGH_COMPILE__
|
||||
+
|
||||
#include "sleighbase.hh"
|
||||
#include "pcodecompile.hh"
|
||||
#include "filemanage.hh"
|
||||
@@ -446,3 +449,5 @@ class SleighCompile : public SleighBase {
|
||||
|
||||
extern SleighCompile *slgh; ///< A global reference to the SLEIGH compiler accessible to the parse functions
|
||||
extern int yydebug; ///< Debug state for the SLEIGH parse functions
|
||||
+
|
||||
+#endif
|
||||
diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/xml_arch.hh b/Ghidra/Features/Decompiler/src/decompile/cpp/xml_arch.hh
|
||||
index 4d404e6ad..0154582b0 100644
|
||||
--- a/Ghidra/Features/Decompiler/src/decompile/cpp/xml_arch.hh
|
||||
+++ b/Ghidra/Features/Decompiler/src/decompile/cpp/xml_arch.hh
|
||||
@@ -15,6 +15,10 @@
|
||||
*/
|
||||
/// \file xml_arch.hh
|
||||
/// \brief Extension to read executables based on an XML format
|
||||
+
|
||||
+#ifndef __XML_ARCH__
|
||||
+#define __XML_ARCH__
|
||||
+
|
||||
#include "sleigh_arch.hh"
|
||||
#include "loadimage_xml.hh"
|
||||
|
||||
@@ -43,3 +47,5 @@ class XmlArchitecture : public SleighArchitecture {
|
||||
XmlArchitecture(const string &fname,const string &targ,ostream *estream); ///< Constructor
|
||||
virtual ~XmlArchitecture(void) {}
|
||||
};
|
||||
+
|
||||
+#endif
|
||||
--
|
||||
2.37.1
|
||||
|
||||
@@ -0,0 +1,293 @@
|
||||
From 33ff58323d84c0ba57091b5bd408907a7646fd67 Mon Sep 17 00:00:00 2001
|
||||
From: Alex Cameron <asc@tetsuo.sh>
|
||||
Date: Tue, 2 Aug 2022 17:04:19 +1000
|
||||
Subject: [PATCH] Fix UBSAN errors in decompiler
|
||||
|
||||
---
|
||||
.../Decompiler/src/decompile/cpp/address.cc | 4 ++--
|
||||
.../Decompiler/src/decompile/cpp/fspec.cc | 8 ++++++--
|
||||
.../src/decompile/cpp/funcdata_varnode.cc | 8 +++++++-
|
||||
.../Decompiler/src/decompile/cpp/op.cc | 6 +++++-
|
||||
.../Decompiler/src/decompile/cpp/opbehavior.cc | 8 +++++++-
|
||||
.../src/decompile/cpp/pcodecompile.cc | 18 +++++++++++-------
|
||||
.../Decompiler/src/decompile/cpp/ruleaction.cc | 18 ++++++++++++++----
|
||||
.../Decompiler/src/decompile/cpp/semantics.cc | 2 ++
|
||||
.../Decompiler/src/decompile/cpp/semantics.hh | 2 +-
|
||||
.../src/decompile/cpp/slgh_compile.cc | 2 +-
|
||||
.../Decompiler/src/decompile/cpp/slghsymbol.cc | 2 +-
|
||||
.../Decompiler/src/decompile/cpp/type.cc | 2 +-
|
||||
.../src/decompile/unittests/testfloatemu.cc | 2 +-
|
||||
13 files changed, 59 insertions(+), 23 deletions(-)
|
||||
|
||||
diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/address.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/address.cc
|
||||
index bd0d84d50..8fbd393e4 100644
|
||||
--- a/Ghidra/Features/Decompiler/src/decompile/cpp/address.cc
|
||||
+++ b/Ghidra/Features/Decompiler/src/decompile/cpp/address.cc
|
||||
@@ -631,7 +631,7 @@ uintb sign_extend(uintb in,int4 sizein,int4 sizeout)
|
||||
void sign_extend(intb &val,int4 bit)
|
||||
|
||||
{
|
||||
- intb mask = 0;
|
||||
+ uintb mask = 0;
|
||||
mask = (~mask)<<bit;
|
||||
if (((val>>bit)&1)!=0)
|
||||
val |= mask;
|
||||
@@ -645,7 +645,7 @@ void sign_extend(intb &val,int4 bit)
|
||||
void zero_extend(intb &val,int4 bit)
|
||||
|
||||
{
|
||||
- intb mask = 0;
|
||||
+ uintb mask = 0;
|
||||
mask = (~mask)<<bit;
|
||||
mask <<= 1;
|
||||
val &= (~mask);
|
||||
diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/fspec.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/fspec.cc
|
||||
index 89685bd76..54dc2cfc8 100644
|
||||
--- a/Ghidra/Features/Decompiler/src/decompile/cpp/fspec.cc
|
||||
+++ b/Ghidra/Features/Decompiler/src/decompile/cpp/fspec.cc
|
||||
@@ -2468,8 +2468,12 @@ void ProtoModelMerged::restoreXml(const Element *el)
|
||||
foldIn(mymodel);
|
||||
modellist.push_back(mymodel);
|
||||
}
|
||||
- ((ParamListMerged *)input)->finalize();
|
||||
- ((ParamListMerged *)output)->finalize();
|
||||
+ if (input->getType() == ParamList::p_merged) {
|
||||
+ ((ParamListMerged *)input)->finalize();
|
||||
+ }
|
||||
+ if (output->getType() == ParamList::p_merged) {
|
||||
+ ((ParamListMerged *)output)->finalize();
|
||||
+ }
|
||||
}
|
||||
|
||||
void ParameterBasic::setTypeLock(bool val)
|
||||
diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/funcdata_varnode.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/funcdata_varnode.cc
|
||||
index a710d2597..3472e391a 100644
|
||||
--- a/Ghidra/Features/Decompiler/src/decompile/cpp/funcdata_varnode.cc
|
||||
+++ b/Ghidra/Features/Decompiler/src/decompile/cpp/funcdata_varnode.cc
|
||||
@@ -501,7 +501,13 @@ void Funcdata::setHighLevel(void)
|
||||
void Funcdata::transferVarnodeProperties(Varnode *vn,Varnode *newVn,int4 lsbOffset)
|
||||
|
||||
{
|
||||
- uintb newConsume = (vn->getConsume() >> 8*lsbOffset) & calc_mask(newVn->getSize());
|
||||
+ uintb newConsume = vn->getConsume();
|
||||
+ if (8*lsbOffset < sizeof(newConsume)) {
|
||||
+ newConsume >>= 8*lsbOffset;
|
||||
+ } else {
|
||||
+ newConsume = 0;
|
||||
+ }
|
||||
+ newConsume &= calc_mask(newVn->getSize());
|
||||
|
||||
uint4 vnFlags = vn->getFlags() & (Varnode::directwrite|Varnode::addrforce);
|
||||
|
||||
diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/op.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/op.cc
|
||||
index af89c583a..f7086bbf8 100644
|
||||
--- a/Ghidra/Features/Decompiler/src/decompile/cpp/op.cc
|
||||
+++ b/Ghidra/Features/Decompiler/src/decompile/cpp/op.cc
|
||||
@@ -650,7 +650,11 @@ uintb PcodeOp::getNZMaskLocal(bool cliploop) const
|
||||
break;
|
||||
case CPUI_PIECE:
|
||||
resmask = getIn(0)->getNZMask();
|
||||
- resmask <<= 8*getIn(1)->getSize();
|
||||
+ if (8*getIn(1)->getSize() < sizeof(resmask)) {
|
||||
+ resmask <<= 8*getIn(1)->getSize();
|
||||
+ } else {
|
||||
+ resmask = 0;
|
||||
+ }
|
||||
resmask |= getIn(1)->getNZMask();
|
||||
break;
|
||||
case CPUI_INT_MULT:
|
||||
diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/opbehavior.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/opbehavior.cc
|
||||
index 3b84bac6a..3e0c39904 100644
|
||||
--- a/Ghidra/Features/Decompiler/src/decompile/cpp/opbehavior.cc
|
||||
+++ b/Ghidra/Features/Decompiler/src/decompile/cpp/opbehavior.cc
|
||||
@@ -747,7 +747,13 @@ uintb OpBehaviorPiece::evaluateBinary(int4 sizeout,int4 sizein,uintb in1,uintb i
|
||||
uintb OpBehaviorSubpiece::evaluateBinary(int4 sizeout,int4 sizein,uintb in1,uintb in2) const
|
||||
|
||||
{
|
||||
- uintb res = (in1>>(in2*8)) & calc_mask(sizeout);
|
||||
+ uintb res = in1;
|
||||
+ if ((in2*8) < sizeof(in1)) {
|
||||
+ res >>= (in2*8);
|
||||
+ } else {
|
||||
+ res = 0;
|
||||
+ }
|
||||
+ res &= calc_mask(sizeout);
|
||||
return res;
|
||||
}
|
||||
|
||||
diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/pcodecompile.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/pcodecompile.cc
|
||||
index 7927becec..4987e37ec 100644
|
||||
--- a/Ghidra/Features/Decompiler/src/decompile/cpp/pcodecompile.cc
|
||||
+++ b/Ghidra/Features/Decompiler/src/decompile/cpp/pcodecompile.cc
|
||||
@@ -622,8 +622,10 @@ vector<OpTpl *> *PcodeCompile::assignBitRange(VarnodeTpl *vn,uint4 bitoffset,uin
|
||||
uint4 smallsize = (numbits+7)/8; // Size of input (output of rhs)
|
||||
bool shiftneeded = (bitoffset != 0);
|
||||
bool zextneeded = true;
|
||||
- uintb mask = (uintb)2;
|
||||
- mask = ~(((mask<<(numbits-1))-1) << bitoffset);
|
||||
+ uintb mask = 0;
|
||||
+ const int4 masknumbits = sizeof(mask) * 8;
|
||||
+ if (numbits - 1 < masknumbits && bitoffset < masknumbits)
|
||||
+ mask = ~(((static_cast<uintb>(2) << (numbits - 1)) - 1) << bitoffset);
|
||||
|
||||
if (vn->getSize().getType()==ConstTpl::real) {
|
||||
// If we know the size of the bitranged varnode, we can
|
||||
@@ -727,9 +729,6 @@ ExprTree *PcodeCompile::createBitRange(SpecificSymbol *sym,uint4 bitoffset,uint4
|
||||
}
|
||||
}
|
||||
|
||||
- uintb mask = (uintb)2;
|
||||
- mask = ((mask<<(numbits-1))-1);
|
||||
-
|
||||
if (truncneeded && ((bitoffset % 8)==0)) {
|
||||
truncshift = bitoffset/8;
|
||||
bitoffset = 0;
|
||||
@@ -752,8 +751,13 @@ ExprTree *PcodeCompile::createBitRange(SpecificSymbol *sym,uint4 bitoffset,uint4
|
||||
appendOp(CPUI_INT_RIGHT,res,bitoffset,4);
|
||||
if (truncneeded)
|
||||
appendOp(CPUI_SUBPIECE,res,truncshift,4);
|
||||
- if (maskneeded)
|
||||
- appendOp(CPUI_INT_AND,res,mask,finalsize);
|
||||
+ if (maskneeded) {
|
||||
+ uintb mask = 0;
|
||||
+ if (numbits - 1 < sizeof(mask) * 8)
|
||||
+ mask = static_cast<uintb>(2) << (numbits - 1);
|
||||
+ --mask;
|
||||
+ appendOp(CPUI_INT_AND, res, mask, finalsize);
|
||||
+ }
|
||||
force_size(res->outvn,ConstTpl(ConstTpl::real,finalsize),*res->ops);
|
||||
return res;
|
||||
}
|
||||
diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/ruleaction.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/ruleaction.cc
|
||||
index 2a5d92040..d65ae2918 100644
|
||||
--- a/Ghidra/Features/Decompiler/src/decompile/cpp/ruleaction.cc
|
||||
+++ b/Ghidra/Features/Decompiler/src/decompile/cpp/ruleaction.cc
|
||||
@@ -974,7 +974,12 @@ int4 RulePullsubIndirect::applyOp(PcodeOp *op,Funcdata &data)
|
||||
Varnode *outvn = op->getOut();
|
||||
if (outvn->isPrecisLo()||outvn->isPrecisHi()) return 0; // Don't pull apart double precision object
|
||||
|
||||
- uintb consume = calc_mask(newSize) << 8 * minByte;
|
||||
+ uintb consume = calc_mask(newSize);
|
||||
+ if (8 * minByte < sizeof(consume)) {
|
||||
+ consume <<= 8 * minByte;
|
||||
+ } else {
|
||||
+ consume = 0;
|
||||
+ }
|
||||
consume = ~consume;
|
||||
if ((consume & indir->getIn(0)->getConsume())!=0) return 0;
|
||||
|
||||
@@ -6767,8 +6772,9 @@ int4 RulePtrsubCharConstant::applyOp(PcodeOp *op,Funcdata &data)
|
||||
{
|
||||
Varnode *sb = op->getIn(0);
|
||||
if (sb->getType()->getMetatype() != TYPE_PTR) return 0;
|
||||
- TypeSpacebase *sbtype = (TypeSpacebase *)((TypePointer *)sb->getType())->getPtrTo();
|
||||
- if (sbtype->getMetatype() != TYPE_SPACEBASE) return 0;
|
||||
+ Datatype *sbTypePtr = ((TypePointer *)sb->getType())->getPtrTo();
|
||||
+ if (sbTypePtr->getMetatype() != TYPE_SPACEBASE) return 0;
|
||||
+ TypeSpacebase *sbtype = (TypeSpacebase *)sbTypePtr;
|
||||
Varnode *vn1 = op->getIn(1);
|
||||
if (!vn1->isConstant()) return 0;
|
||||
Varnode *outvn = op->getOut();
|
||||
@@ -7781,7 +7787,11 @@ int4 RuleSubvarSubpiece::applyOp(PcodeOp *op,Funcdata &data)
|
||||
Varnode *outvn = op->getOut();
|
||||
int4 flowsize = outvn->getSize();
|
||||
uintb mask = calc_mask( flowsize );
|
||||
- mask <<= 8*((int4)op->getIn(1)->getOffset());
|
||||
+ if (8*((int4)op->getIn(1)->getOffset()) < sizeof(mask)) {
|
||||
+ mask <<= 8*((int4)op->getIn(1)->getOffset());
|
||||
+ } else {
|
||||
+ mask = 0;
|
||||
+ }
|
||||
bool aggressive = outvn->isPtrFlow();
|
||||
if (!aggressive) {
|
||||
if ((vn->getConsume() & mask) != vn->getConsume()) return 0;
|
||||
diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/semantics.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/semantics.cc
|
||||
index f8c1580a8..8ae5ff293 100644
|
||||
--- a/Ghidra/Features/Decompiler/src/decompile/cpp/semantics.cc
|
||||
+++ b/Ghidra/Features/Decompiler/src/decompile/cpp/semantics.cc
|
||||
@@ -20,6 +20,7 @@ ConstTpl::ConstTpl(const_type tp)
|
||||
|
||||
{ // Constructor for relative jump constants and uniques
|
||||
type = tp;
|
||||
+ select = v_space;
|
||||
}
|
||||
|
||||
ConstTpl::ConstTpl(const_type tp,uintb val)
|
||||
@@ -54,6 +55,7 @@ ConstTpl::ConstTpl(AddrSpace *sid)
|
||||
{
|
||||
type = spaceid;
|
||||
value.spaceid = sid;
|
||||
+ select = v_space;
|
||||
}
|
||||
|
||||
bool ConstTpl::isConstSpace(void) const
|
||||
diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/semantics.hh b/Ghidra/Features/Decompiler/src/decompile/cpp/semantics.hh
|
||||
index dccf0437d..f7f598667 100644
|
||||
--- a/Ghidra/Features/Decompiler/src/decompile/cpp/semantics.hh
|
||||
+++ b/Ghidra/Features/Decompiler/src/decompile/cpp/semantics.hh
|
||||
@@ -46,7 +46,7 @@ private:
|
||||
static void printHandleSelector(ostream &s,v_field val);
|
||||
static v_field readHandleSelector(const string &name);
|
||||
public:
|
||||
- ConstTpl(void) { type = real; value_real = 0; }
|
||||
+ ConstTpl(void) { type = real; value_real = 0; select = v_space; }
|
||||
ConstTpl(const ConstTpl &op2) {
|
||||
type=op2.type; value=op2.value; value_real=op2.value_real; select=op2.select; }
|
||||
ConstTpl(const_type tp,uintb val);
|
||||
diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/slgh_compile.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/slgh_compile.cc
|
||||
index 40d775b2d..5535d4108 100644
|
||||
--- a/Ghidra/Features/Decompiler/src/decompile/cpp/slgh_compile.cc
|
||||
+++ b/Ghidra/Features/Decompiler/src/decompile/cpp/slgh_compile.cc
|
||||
@@ -2150,8 +2150,8 @@ string SleighCompile::checkSymbols(SymbolScope *scope)
|
||||
ostringstream msg;
|
||||
SymbolTree::const_iterator iter;
|
||||
for(iter=scope->begin();iter!=scope->end();++iter) {
|
||||
+ if ((*iter)->getType() != SleighSymbol::label_symbol) continue;
|
||||
LabelSymbol *sym = (LabelSymbol *)*iter;
|
||||
- if (sym->getType() != SleighSymbol::label_symbol) continue;
|
||||
if (sym->getRefCount() == 0)
|
||||
msg << " Label <" << sym->getName() << "> was placed but not used" << endl;
|
||||
else if (!sym->isPlaced())
|
||||
diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/slghsymbol.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/slghsymbol.cc
|
||||
index 5f4a8fe32..50bc33b8b 100644
|
||||
--- a/Ghidra/Features/Decompiler/src/decompile/cpp/slghsymbol.cc
|
||||
+++ b/Ghidra/Features/Decompiler/src/decompile/cpp/slghsymbol.cc
|
||||
@@ -2499,7 +2499,7 @@ void ContextOp::restoreXml(const Element *el,SleighBase *trans)
|
||||
const List &list(el->getChildren());
|
||||
List::const_iterator iter;
|
||||
iter = list.begin();
|
||||
- patexp = (PatternValue *)PatternExpression::restoreExpression(*iter,trans);
|
||||
+ patexp = PatternExpression::restoreExpression(*iter,trans);
|
||||
patexp->layClaim();
|
||||
}
|
||||
|
||||
diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/type.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/type.cc
|
||||
index 75b74d465..f478f19a4 100644
|
||||
--- a/Ghidra/Features/Decompiler/src/decompile/cpp/type.cc
|
||||
+++ b/Ghidra/Features/Decompiler/src/decompile/cpp/type.cc
|
||||
@@ -2392,8 +2392,8 @@ void TypeFactory::recalcPointerSubmeta(Datatype *base,sub_metatype sub)
|
||||
top.submeta = sub; // Search on the incorrect submeta
|
||||
iter = tree.lower_bound(&top);
|
||||
while(iter != tree.end()) {
|
||||
+ if ((*iter)->getMetatype() != TYPE_PTR) break;
|
||||
TypePointer *ptr = (TypePointer *)*iter;
|
||||
- if (ptr->getMetatype() != TYPE_PTR) break;
|
||||
if (ptr->ptrto != base) break;
|
||||
++iter;
|
||||
if (ptr->submeta == sub) {
|
||||
diff --git a/Ghidra/Features/Decompiler/src/decompile/unittests/testfloatemu.cc b/Ghidra/Features/Decompiler/src/decompile/unittests/testfloatemu.cc
|
||||
index ab99382a3..67d92c573 100644
|
||||
--- a/Ghidra/Features/Decompiler/src/decompile/unittests/testfloatemu.cc
|
||||
+++ b/Ghidra/Features/Decompiler/src/decompile/unittests/testfloatemu.cc
|
||||
@@ -338,7 +338,7 @@ TEST(float_opTrunc_to_int) {
|
||||
|
||||
for(float f:float_test_values) {
|
||||
// avoid undefined behavior
|
||||
- if((int64_t)f > std::numeric_limits<int>::max() || (int64_t)f < std::numeric_limits<int>::min())
|
||||
+ if(f > std::numeric_limits<int>::max() || f < std::numeric_limits<int>::min() || std::isnan(f))
|
||||
continue;
|
||||
uintb true_result = ((uintb)(int32_t)f) & 0xffffffff;
|
||||
uintb encoding = format.getEncoding(f);
|
||||
--
|
||||
2.32.1 (Apple Git-133)
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
From b719ae7f3716b303ec0c3d8c79e7d55c7e7cbfdf Mon Sep 17 00:00:00 2001
|
||||
From: Alex Cameron <asc@tetsuo.sh>
|
||||
Date: Wed, 3 Aug 2022 20:39:30 +1000
|
||||
Subject: [PATCH] Use `stroull` instead of `stroul` to parse address offsets
|
||||
|
||||
---
|
||||
Ghidra/Features/Decompiler/src/decompile/cpp/space.cc | 7 ++++++-
|
||||
1 file changed, 6 insertions(+), 1 deletion(-)
|
||||
|
||||
diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/space.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/space.cc
|
||||
index 5f07edf8e..b86c9beae 100644
|
||||
--- a/Ghidra/Features/Decompiler/src/decompile/cpp/space.cc
|
||||
+++ b/Ghidra/Features/Decompiler/src/decompile/cpp/space.cc
|
||||
@@ -16,6 +16,8 @@
|
||||
#include "space.hh"
|
||||
#include "translate.hh"
|
||||
|
||||
+#include <climits>
|
||||
+
|
||||
/// Calculate \e highest based on \e addressSize, and \e wordsize.
|
||||
/// This also calculates the default pointerLowerBound
|
||||
void AddrSpace::calcScaleMask(void)
|
||||
@@ -260,7 +262,10 @@ uintb AddrSpace::read(const string &s,int4 &size) const
|
||||
}
|
||||
}
|
||||
catch(LowlevelError &err) { // Name doesn't exist
|
||||
- offset = strtoul(s.c_str(),&tmpdata,0);
|
||||
+ offset = strtoull(s.c_str(),&tmpdata,0);
|
||||
+ if (offset == ULLONG_MAX) {
|
||||
+ throw LowlevelError("Offset outside of valid range");
|
||||
+ }
|
||||
offset = addressToByte(offset,wordsize);
|
||||
enddata = (const char *) tmpdata;
|
||||
if (enddata - s.c_str() == s.size()) { // If no size or offset override
|
||||
--
|
||||
2.32.1 (Apple Git-133)
|
||||
|
||||
@@ -52,7 +52,9 @@ set(spec_file_list
|
||||
"${ghidrasource_SOURCE_DIR}/Ghidra/Processors/HCS08/data/languages/HC05.slaspec"
|
||||
"${ghidrasource_SOURCE_DIR}/Ghidra/Processors/HCS08/data/languages/HC08.slaspec"
|
||||
"${ghidrasource_SOURCE_DIR}/Ghidra/Processors/HCS08/data/languages/HCS08.slaspec"
|
||||
"${ghidrasource_SOURCE_DIR}/Ghidra/Processors/HCS12/data/languages/HC12.slaspec"
|
||||
"${ghidrasource_SOURCE_DIR}/Ghidra/Processors/HCS12/data/languages/HCS12.slaspec"
|
||||
"${ghidrasource_SOURCE_DIR}/Ghidra/Processors/HCS12/data/languages/HCS12X.slaspec"
|
||||
"${ghidrasource_SOURCE_DIR}/Ghidra/Processors/JVM/data/languages/JVM.slaspec"
|
||||
"${ghidrasource_SOURCE_DIR}/Ghidra/Processors/M8C/data/languages/m8c.slaspec"
|
||||
"${ghidrasource_SOURCE_DIR}/Ghidra/Processors/MC6800/data/languages/6805.slaspec"
|
||||
@@ -82,6 +84,8 @@ set(spec_file_list
|
||||
"${ghidrasource_SOURCE_DIR}/Ghidra/Processors/PowerPC/data/languages/ppc_32_4xx_be.slaspec"
|
||||
"${ghidrasource_SOURCE_DIR}/Ghidra/Processors/PowerPC/data/languages/ppc_32_4xx_le.slaspec"
|
||||
"${ghidrasource_SOURCE_DIR}/Ghidra/Processors/PowerPC/data/languages/ppc_32_be.slaspec"
|
||||
"${ghidrasource_SOURCE_DIR}/Ghidra/Processors/PowerPC/data/languages/ppc_32_e500_be.slaspec"
|
||||
"${ghidrasource_SOURCE_DIR}/Ghidra/Processors/PowerPC/data/languages/ppc_32_e500_le.slaspec"
|
||||
"${ghidrasource_SOURCE_DIR}/Ghidra/Processors/PowerPC/data/languages/ppc_32_le.slaspec"
|
||||
"${ghidrasource_SOURCE_DIR}/Ghidra/Processors/PowerPC/data/languages/ppc_32_quicciii_be.slaspec"
|
||||
"${ghidrasource_SOURCE_DIR}/Ghidra/Processors/PowerPC/data/languages/ppc_32_quicciii_le.slaspec"
|
||||
|
||||
@@ -1,42 +1,53 @@
|
||||
# ---- Setup Ghidra Source code ----
|
||||
|
||||
# Set up Ghidra repo human-readable version settings
|
||||
set(sleigh_GHIDRA_RELEASE_TYPE "stable" CACHE
|
||||
STRING "Ghidra release type to use. 'HEAD' is used for active development purposes."
|
||||
set(sleigh_RELEASE_TYPE "stable" CACHE
|
||||
STRING "Release type to use. 'HEAD' is used for active development purposes."
|
||||
)
|
||||
|
||||
# This is just helper for CMake UIs. CMake does not enforce that the value matches one of those listed.
|
||||
set_property(CACHE sleigh_GHIDRA_RELEASE_TYPE PROPERTY STRINGS "stable" "HEAD")
|
||||
set_property(CACHE sleigh_RELEASE_TYPE PROPERTY STRINGS "stable" "HEAD")
|
||||
|
||||
# **** Setup pinned git info ****
|
||||
|
||||
# Ghidra pinned stable version commit
|
||||
set(ghidra_version "10.1.4")
|
||||
set(ghidra_git_tag "Ghidra_10.1.4_build")
|
||||
set(ghidra_version "10.1.5")
|
||||
set(ghidra_git_tag "Ghidra_${ghidra_version}_build")
|
||||
set(ghidra_shallow TRUE)
|
||||
|
||||
# pinned stable patches list
|
||||
set(ghidra_patches
|
||||
PATCH_COMMAND git am --ignore-space-change --ignore-whitespace --no-gpg-sign
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/patches/stable/0001-Small-improvements-to-C-decompiler-testing-from-CLI.patch"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/patches/stable/0002-Add-include-guards-to-decompiler-C-headers.patch"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/patches/stable/0003-Fix-UBSAN-errors-in-decompiler.patch"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/patches/stable/0004-Use-stroull-instead-of-stroul-to-parse-address-offse.patch"
|
||||
)
|
||||
|
||||
# Ghidra pinned commits used for pinning last known working HEAD commit
|
||||
if("${sleigh_GHIDRA_RELEASE_TYPE}" STREQUAL HEAD)
|
||||
if("${sleigh_RELEASE_TYPE}" STREQUAL "HEAD")
|
||||
# TODO: Try to remember to look at Ghidra/application.properties
|
||||
# TODO: CMake only likes numeric characters in the version string....
|
||||
set(ghidra_head_version "10.2")
|
||||
set(ghidra_version "${ghidra_head_version}")
|
||||
set(ghidra_head_git_tag "7a30cefebb91ddb25a6c4030e67001202fd20936")
|
||||
set(ghidra_head_git_tag "cef30890ec3611434c28bc0dd0bff0cae5a753b8")
|
||||
set(ghidra_git_tag "${ghidra_head_git_tag}")
|
||||
set(ghidra_shallow FALSE)
|
||||
set(ghidra_patches
|
||||
PATCH_COMMAND git am --ignore-space-change --ignore-whitespace --no-gpg-sign
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/patches/HEAD/0001-Small-improvements-to-C-decompiler-testing-from-CLI.patch"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/patches/HEAD/0002-Initialize-ID-lookup-tables-to-fix-sleighexample.patch"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/patches/HEAD/0003-Add-include-guards-to-decompiler-C-headers.patch"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/patches/HEAD/0004-Fix-UBSAN-errors-in-decompiler.patch"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/patches/HEAD/0005-Use-stroull-instead-of-stroul-to-parse-address-offse.patch"
|
||||
)
|
||||
string(SUBSTRING "${ghidra_git_tag}" 0 7 ghidra_short_commit)
|
||||
else()
|
||||
set(ghidra_short_commit "${ghidra_git_tag}")
|
||||
endif()
|
||||
|
||||
list(APPEND ghidra_patches ${sleigh_ADDITIONAL_PATCHES})
|
||||
|
||||
message(STATUS "Using Ghidra version ${ghidra_version} at git ref ${ghidra_short_commit}")
|
||||
|
||||
include(FetchContent)
|
||||
@@ -58,6 +69,7 @@ message(STATUS "Ghidra source located at '${ghidrasource_SOURCE_DIR}'")
|
||||
|
||||
# Sanity check on Ghidra source code checkout
|
||||
set(library_root "${ghidrasource_SOURCE_DIR}/Ghidra/Features/Decompiler/src/decompile/cpp")
|
||||
|
||||
if(NOT EXISTS "${library_root}/sleigh.hh")
|
||||
message(FATAL_ERROR "The Ghidra source directory has not been initialized correctly. Could not find '${library_root}'")
|
||||
endif()
|
||||
|
||||
@@ -22,6 +22,8 @@ configure_file(
|
||||
# the source code for watching a git repository.
|
||||
set(PRE_CONFIGURE_FILE "${CMAKE_CURRENT_LIST_DIR}/Version.cpp.in")
|
||||
set(POST_CONFIGURE_FILE "${CMAKE_CURRENT_BINARY_DIR}/Version.cpp")
|
||||
set(GIT_STATE_FILE "${CMAKE_CURRENT_BINARY_DIR}/git-state-sleigh")
|
||||
set(GIT_WORKING_DIR "${PROJECT_SOURCE_DIR}")
|
||||
set(GIT_FAIL_IF_NONZERO_EXIT OFF)
|
||||
include("${PROJECT_SOURCE_DIR}/cmake/git_watcher.cmake")
|
||||
|
||||
|
||||
@@ -257,6 +257,10 @@ int main(int argc, char *argv[]) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
// Put together SLEIGH components
|
||||
#ifdef sleigh_RELEASE_IS_HEAD
|
||||
AttributeId::initialize();
|
||||
ElementId::initialize();
|
||||
#endif
|
||||
InMemoryLoadImage load_image(addr);
|
||||
ContextInternal ctx;
|
||||
Sleigh engine(&load_image, &ctx);
|
||||
@@ -296,6 +300,22 @@ int main(int argc, char *argv[]) {
|
||||
// void Architecture::parseProcessorConfig(DocumentStorage &store)
|
||||
const Element *el = storage.getTag("processor_spec");
|
||||
if (el) {
|
||||
#ifdef sleigh_RELEASE_IS_HEAD
|
||||
XmlDecode decoder(&engine, el);
|
||||
uint4 elemId = decoder.openElement(ELEM_PROCESSOR_SPEC);
|
||||
for(;;) {
|
||||
uint4 subId = decoder.peekElement();
|
||||
if (subId == 0) break;
|
||||
else if (subId == ELEM_CONTEXT_DATA) {
|
||||
ctx.decodeFromSpec(decoder);
|
||||
break;
|
||||
} else {
|
||||
decoder.openElement();
|
||||
decoder.closeElementSkipping(subId);
|
||||
}
|
||||
}
|
||||
decoder.closeElement(elemId);
|
||||
#else
|
||||
const List &list(el->getChildren());
|
||||
for (List::const_iterator iter = list.begin(); iter != list.end(); ++iter) {
|
||||
const string &elname((*iter)->getName());
|
||||
@@ -304,7 +324,9 @@ int main(int argc, char *argv[]) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
// In order to parse and validate the byte string properly, we need to get the
|
||||
// address size from SLEIGH. Therefore this needs to happen after
|
||||
// initialization.
|
||||
|
||||
Reference in New Issue
Block a user