Skip to content

Commit

Permalink
Merge pull request #220 from gdt050579/dissasm_view
Browse files Browse the repository at this point in the history
Dissasm view added collapsible zones
  • Loading branch information
rzaharia authored Jan 31, 2024
2 parents 90bcbaf + f263840 commit 03cb1e1
Show file tree
Hide file tree
Showing 14 changed files with 1,506 additions and 330 deletions.
90 changes: 54 additions & 36 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,15 @@ message("CMAKE_SYSTEM_PROCESSOR => ${CMAKE_SYSTEM_PROCESSOR}")
message("CMAKE_HOST_SYSTEM_PROCESSOR => ${CMAKE_HOST_SYSTEM_PROCESSOR}")
message("CMAKE_C_COMPILER_ARCHITECTURE_ID => ${CMAKE_C_COMPILER_ARCHITECTURE_ID}")

project(GView VERSION 1.0)
option(ENABLE_TESTS "Enable tests" OFF)
set(CURRENT_PROJECT_NAME GView)
if (${ENABLE_TESTS})
message("ENALBED TESTING")
enable_testing()
set(CURRENT_PROJECT_NAME GViewTesting)
endif()

project(${CURRENT_PROJECT_NAME} VERSION 1.0)

include(CheckIPOSupported)
check_ipo_supported(RESULT supported OUTPUT error)
Expand All @@ -32,6 +40,7 @@ set(GVIEW_VERSION ${CMAKE_MATCH_1})
message("${PROJECT_NAME} version: ${GVIEW_VERSION}")

set(CMAKE_MODULE_PATH "${CMAKE_MODULE_PATH};${CMAKE_CURRENT_SOURCE_DIR}/cmake")
include(core_testing)

set_property(GLOBAL PROPERTY USE_FOLDERS ON)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
Expand All @@ -46,13 +55,17 @@ if (CMAKE_BUILD_TYPE STREQUAL "Debug")
set(DEBUG_BUILD 1)
endif()

if(NOT DEFINED GVIEW_BINARIES_OUT_DIR)
set(GVIEW_BINARIES_OUT_DIR "${CMAKE_SOURCE_DIR}/bin/${CMAKE_BUILD_TYPE}")
endif()

string(TOUPPER ${CMAKE_BUILD_TYPE} UPPER_BUILD_TYPE)
if (NOT MSVC)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/../bin/${CMAKE_BUILD_TYPE}")
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/../bin/${CMAKE_BUILD_TYPE}")
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${GVIEW_BINARIES_OUT_DIR})
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${GVIEW_BINARIES_OUT_DIR})
endif()
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/../bin/${CMAKE_BUILD_TYPE}")
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG "${CMAKE_BINARY_DIR}/../bin/${CMAKE_BUILD_TYPE}")
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE "${CMAKE_BINARY_DIR}/../bin/${CMAKE_BUILD_TYPE}")
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${GVIEW_BINARIES_OUT_DIR})
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_${UPPER_BUILD_TYPE} "${GVIEW_BINARIES_OUT_DIR}")

if (MSVC)
add_definitions(-DBUILD_FOR_WINDOWS)
Expand Down Expand Up @@ -126,7 +139,10 @@ add_subdirectory(3rdPartyLibs/LLVMDemangle)

add_subdirectory(AppCUI)
add_subdirectory(GViewCore)
add_subdirectory(GView)

if(NOT DEFINED CMAKE_TESTING_ENABLED)
add_subdirectory(GView)
endif()

if (APPLE)
if (CMAKE_GENERATOR STREQUAL "Xcode")
Expand All @@ -140,35 +156,37 @@ if (APPLE)
endif()
endif()

# Types supported by GView
add_subdirectory(Types/PE)
add_subdirectory(Types/ICO)
add_subdirectory(Types/CSV)
add_subdirectory(Types/BMP)
add_subdirectory(Types/MACHO)
add_subdirectory(Types/ISO)
add_subdirectory(Types/PREFETCH)
add_subdirectory(Types/MAM)
add_subdirectory(Types/LNK)
add_subdirectory(Types/JOB)
add_subdirectory(Types/PCAP)
add_subdirectory(Types/ELF)
add_subdirectory(Types/JT)
add_subdirectory(Types/INI)
add_subdirectory(Types/CPP)
add_subdirectory(Types/JSON)
add_subdirectory(Types/VBA)
add_subdirectory(Types/JS)
add_subdirectory(Types/PYEXTRACTOR)
add_subdirectory(Types/ZIP)
add_subdirectory(Types/SQLite)


# Generic plugins supported by GView
add_subdirectory(GenericPlugins/CharacterTable)
add_subdirectory(GenericPlugins/Hashes)
add_subdirectory(GenericPlugins/SyncCompare)
add_subdirectory(GenericPlugins/DropperStrings)
if(NOT DEFINED CMAKE_TESTING_ENABLED)
# Types supported by GView
add_subdirectory(Types/PE)
add_subdirectory(Types/ICO)
add_subdirectory(Types/CSV)
add_subdirectory(Types/BMP)
add_subdirectory(Types/MACHO)
add_subdirectory(Types/ISO)
add_subdirectory(Types/PREFETCH)
add_subdirectory(Types/MAM)
add_subdirectory(Types/LNK)
add_subdirectory(Types/JOB)
add_subdirectory(Types/PCAP)
add_subdirectory(Types/ELF)
add_subdirectory(Types/JT)
add_subdirectory(Types/INI)
add_subdirectory(Types/CPP)
add_subdirectory(Types/JSON)
add_subdirectory(Types/VBA)
add_subdirectory(Types/JS)
add_subdirectory(Types/PYEXTRACTOR)
add_subdirectory(Types/ZIP)
add_subdirectory(Types/SQLite)


# Generic plugins supported by GView
add_subdirectory(GenericPlugins/CharacterTable)
add_subdirectory(GenericPlugins/Hashes)
add_subdirectory(GenericPlugins/SyncCompare)
add_subdirectory(GenericPlugins/DropperStrings)
endif()

if (APPLE)
set_property(TARGET "${PROJECT_NAME}" PROPERTY INSTALL_RPATH "@loader_path")
Expand Down
38 changes: 38 additions & 0 deletions CMakePresets.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"version": 6,
"cmakeMinimumRequired": {
"major": 3,
"minor": 22,
"patch": 0
},
"configurePresets": [
{
"name": "debug",
"displayName": "Debug config",
"description": "debug",
"binaryDir": "${sourceDir}/build/debug",
"cacheVariables": {
"DCMAKE_BUILD_TYPE": {
"type": "STRING",
"value": "DEBUG"
}
}
},
{
"name": "testing",
"displayName": "Testing config",
"description": "Testing config",
"binaryDir": "${sourceDir}/build/testing",
"cacheVariables": {
"DCMAKE_BUILD_TYPE": {
"type": "STRING",
"value": "DEBUG"
},
"ENABLE_TESTS": {
"type": "BOOL",
"value": true
}
}
}
]
}
15 changes: 14 additions & 1 deletion GViewCore/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,20 @@ cmake_minimum_required(VERSION 3.13)
project(GViewCore VERSION 1.0)

set_property(GLOBAL PROPERTY USE_FOLDERS ON)
add_library(${PROJECT_NAME} SHARED)

if(NOT DEFINED CMAKE_TESTING_ENABLED)
add_library(${PROJECT_NAME} SHARED)
else()
add_executable(${PROJECT_NAME})

find_package(Catch2 CONFIG REQUIRED)
target_link_libraries(${PROJECT_NAME} PRIVATE Catch2::Catch2WithMain) # Catch2::Catch2

include(CTest)
include(Catch)
catch_discover_tests(${PROJECT_NAME})
endif()

set_target_properties(${PROJECT_NAME} PROPERTIES PREFIX "lib")
target_compile_definitions(${PROJECT_NAME} PRIVATE -DBUILD_AS_DYNAMIC_LIB)
target_compile_definitions(${PROJECT_NAME} PRIVATE -DCORE_EXPORTABLE)
Expand Down
5 changes: 4 additions & 1 deletion GViewCore/src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,7 @@ add_subdirectory(ZLIB)
add_subdirectory(Dissasembly)
add_subdirectory(ZIP)
add_subdirectory(SQLite3)
target_sources(GViewCore PRIVATE main.cpp)

if(NOT DEFINED CMAKE_TESTING_ENABLED)
target_sources(GViewCore PRIVATE main.cpp)
endif()
7 changes: 5 additions & 2 deletions GViewCore/src/View/DissasmViewer/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,13 @@ target_sources(
UserDefinedTypes.cpp
DissasmProperties.cpp
DissasmKeyEvents.cpp
DissasmX86.cpp
DissasmX86.hpp
DissasmX86.cpp
SingleSelectionDataWindow.cpp
AdvancedSelection.hpp
AdvancedSelection.cpp
DissasmDataTypes.hpp
DissasmDataTypes.cpp
)
)

add_testing_sources(GViewCore tests_dissasmviewer.cpp)
36 changes: 28 additions & 8 deletions GViewCore/src/View/DissasmViewer/Config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,35 @@ constexpr uint32 COMMAND_AVAILABLE_KEYS = 108;

using AppCUI::int32;
// TODO: reenable
constexpr int32 RIGHT_CLICK_MENU_CMD_NEW = 0;
constexpr int32 RIGHT_CLICK_MENU_CMD_EDIT = 1;
constexpr int32 RIGHT_CLICK_MENU_CMD_DELETE = 2;
constexpr int32 RIGHT_CLICK_MENU_CMD_NEW_STRUCTURE = 0;
constexpr int32 RIGHT_CLICK_MENU_CMD_EDIT_STRUCTURE = 1;
constexpr int32 RIGHT_CLICK_MENU_CMD_DELETE_STRUCTURE = 2;

constexpr int32 RIGHT_CLICK_MENU_CMD_COLLAPSE = 3;
constexpr int32 RIGHT_CLICK_ADD_COMMENT = 4;
constexpr int32 RIGHT_CLICK_REMOVE_COMMENT = 5;
constexpr int32 RIGHT_CLICK_DISSASM_ADD_ZONE = 6;
constexpr int32 RIGHT_CLICK_DISSASM_REMOVE_ZONE = 7;
constexpr int32 RIGHT_CLICK_MENU_CMD_NEW_COLLAPSE_ZONE = 3;
constexpr int32 RIGHT_CLICK_DISSASM_REMOVE_COLLAPSE_ZONE = 4;
constexpr int32 RIGHT_CLICK_ADD_COMMENT = 5;
constexpr int32 RIGHT_CLICK_REMOVE_COMMENT = 6;
constexpr int32 RIGHT_CLICK_CLEAR_SELECTION = 7;
constexpr int32 RIGHT_CLICK_DISSASM_COLLAPSE_ZONE = 8;
constexpr int32 RIGHT_CLICK_DISSASM_EXPAND_ZONE = 9;

static struct {
int commandID;
std::string_view text;
// Input::Key shortcutKey = Input::Key::None;
AppCUI::Controls::ItemHandle handle = AppCUI::Controls::InvalidItemHandle;
} RIGHT_CLICK_MENU_COMMANDS[] = {
/*{ RIGHT_CLICK_MENU_CMD_NEW_STRUCTURE, "New structure" },
{ RIGHT_CLICK_MENU_CMD_EDIT_STRUCTURE, "Edit structure" },
{ RIGHT_CLICK_MENU_CMD_DELETE_STRUCTURE, "Delete structure" },*/
{ RIGHT_CLICK_MENU_CMD_NEW_COLLAPSE_ZONE, "Add collapse zone" },
{ RIGHT_CLICK_DISSASM_REMOVE_COLLAPSE_ZONE, "Remove collapse zone" },
{ RIGHT_CLICK_DISSASM_COLLAPSE_ZONE, "Collapse zone" },
{ RIGHT_CLICK_DISSASM_EXPAND_ZONE, "Expand zone" },
{ RIGHT_CLICK_ADD_COMMENT, "Add comment" },
{ RIGHT_CLICK_REMOVE_COMMENT, "Remove comment" },
{ RIGHT_CLICK_CLEAR_SELECTION, "Clear selections" },
};

namespace GView
{
Expand Down
26 changes: 19 additions & 7 deletions GViewCore/src/View/DissasmViewer/DissasmKeyEvents.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,9 @@ bool Instance::OnKeyEvent(AppCUI::Input::Key keyCode, char16 charCode)
case Key::Enter:
OpenCurrentSelection();
return true;
case Key::X:
CommandExecuteCollapsibleZoneOperation(CollapsibleZoneOperation::Add);
return true;
}

if (keyCode == Config::AddOrEditCommentCommand.Key) {
Expand Down Expand Up @@ -283,23 +286,32 @@ bool Instance::OnEvent(Reference<Control>, Event eventType, int ID)
config.ShowFileContent = !config.ShowFileContent;
this->RecomputeDissasmZones();
return true;
case RIGHT_CLICK_MENU_CMD_COLLAPSE:
AddNewCollapsibleZone();
return true;
// case RIGHT_CLICK_MENU_CMD_NEW_COLLAPSE_ZONE:
// AddNewCollapsibleTextZone();
// return true;
case RIGHT_CLICK_ADD_COMMENT:
AddComment();
return true;
case RIGHT_CLICK_REMOVE_COMMENT:
RemoveComment();
return true;
case RIGHT_CLICK_CLEAR_SELECTION:
selection.Clear();
return true;
case COMMAND_EXPORT_ASM_FILE:
CommandExportAsmFile();
return true;
case RIGHT_CLICK_DISSASM_ADD_ZONE:
CommandDissasmAddZone();
case RIGHT_CLICK_MENU_CMD_NEW_COLLAPSE_ZONE:
CommandExecuteCollapsibleZoneOperation(CollapsibleZoneOperation::Add);
return true;
case RIGHT_CLICK_DISSASM_REMOVE_COLLAPSE_ZONE:
CommandExecuteCollapsibleZoneOperation(CollapsibleZoneOperation::Remove);
return true;
case RIGHT_CLICK_DISSASM_EXPAND_ZONE:
CommandExecuteCollapsibleZoneOperation(CollapsibleZoneOperation::Expand);
return true;
case RIGHT_CLICK_DISSASM_REMOVE_ZONE:
CommandDissasmRemoveZone();
case RIGHT_CLICK_DISSASM_COLLAPSE_ZONE:
CommandExecuteCollapsibleZoneOperation(CollapsibleZoneOperation::Collapse);
return true;
case COMMAND_JUMP_BACK: {
if (const auto [canJump, location] = jumps_holder.JumpBack(); canJump)
Expand Down
Loading

0 comments on commit 03cb1e1

Please sign in to comment.