Skip to content

Commit

Permalink
Merge pull request #199 from gdt050579/dissasm_view
Browse files Browse the repository at this point in the history
Dissasm view more updates
  • Loading branch information
rzaharia authored Jan 6, 2024
2 parents bfb8be2 + 462b44b commit 3881132
Show file tree
Hide file tree
Showing 12 changed files with 382 additions and 501 deletions.
3 changes: 2 additions & 1 deletion GViewCore/src/App/GViewApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ void GView::App::Run()
}
bool GView::App::ResetConfiguration()
{
IniObject ini;
IniObject ini = {};
ini.CreateFromFile(GetAppSettingsFile());

// for AppCUI
AppCUI::Application::UpdateAppCUISettings(ini, true);
Expand Down
5 changes: 2 additions & 3 deletions GViewCore/src/View/DissasmViewer/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
target_sources(
GViewCore PRIVATE
DissasmViewer.hpp
Config.hpp
Config.cpp
GoToDialog.cpp
Instance.cpp
Expand All @@ -10,11 +11,9 @@ target_sources(
DissasmProperties.cpp
DissasmKeyEvents.cpp
DissasmX86.cpp
CommentDataWindow.cpp
SingleSelectionDataWindow.cpp
AdvancedSelection.hpp
AdvancedSelection.cpp
DissasmDataTypes.hpp
DissasmDataTypes.cpp
DissasmKeys.hpp
DissasmKeys.cpp
)
38 changes: 15 additions & 23 deletions GViewCore/src/View/DissasmViewer/Config.cpp
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
#include "DissasmViewer.hpp"
#include "Config.hpp"

using namespace GView::View::DissasmViewer;
using namespace AppCUI::Input;
using namespace AppCUI::Graphics;
using AppCUI::Graphics::Color;

void Config::Update(IniSection sect)
void Config::Update(AppCUI::Utils::IniSection sect)
{
sect.UpdateValue("AddNewType", Key::F5, true);
sect.UpdateValue("ShowFileContentKey", Key::F9, true);
for (const auto& cmd : AllKeyboardCommands) {
sect.UpdateValue(cmd.get().Caption, cmd.get().Key, true);
}

sect.UpdateValue("ShowFileContent", true, true);
sect.UpdateValue("AsmExportToFile", Key::F8, true);
sect.UpdateValue("DeepScanDissasmOnStart", false, true);
}
void Config::Initialize()
Expand Down Expand Up @@ -38,30 +41,19 @@ void Config::Initialize()

bool foundSettings = false;
auto ini = AppCUI::Application::GetAppSettings();
if (ini)
{
if (ini) {
auto sect = ini->GetSection("DissasmView");
if (sect.Exists())
{
this->Keys.AddNewType = sect.GetValue("AddNewType").ToKey(Key::F6);
this->Keys.ShowFileContentKey = sect.GetValue("ShowFileContentKey").ToKey(Key::F9);
this->Keys.ExportAsmToFile = sect.GetValue("AsmExportToFile").ToKey(Key::F8);
this->Keys.JumpBack = sect.GetValue("JumpBack").ToKey(Key::Ctrl | Key::Q);
this->Keys.JumpForward = sect.GetValue("JumpForward").ToKey(Key::Ctrl | Key::E);
this->Keys.DissasmGotoEntrypoint = sect.GetValue("Entrypoint").ToKey(Key::F2);
if (sect.Exists()) {
for (auto& cmd : AllKeyboardCommands) {
cmd.get().Key = sect.GetValue(cmd.get().Caption).ToKey(cmd.get().Key);
}

this->ShowFileContent = sect.GetValue("ShowFileContent").ToBool(true);
this->EnableDeepScanDissasmOnStart = sect.GetValue("DeepScanDissasmOnStart").ToBool(false);
foundSettings = true;
}
}
if (!foundSettings)
{
this->Keys.AddNewType = Key::F6;
this->Keys.ShowFileContentKey = Key::F9;
this->Keys.ExportAsmToFile = Key::F8;
this->Keys.JumpBack = Key::Ctrl | Key::Q;
this->Keys.JumpForward = Key::Ctrl | Key::E;
this->Keys.DissasmGotoEntrypoint = Key::F2;
if (!foundSettings) {
this->ShowFileContent = true;
this->EnableDeepScanDissasmOnStart = false;
}
Expand Down
110 changes: 110 additions & 0 deletions GViewCore/src/View/DissasmViewer/Config.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
#pragma once

#include <AppCUI/include/AppCUI.hpp>
#include <array>
using AppCUI::uint32;
constexpr uint32 COMMAND_ADD_NEW_TYPE = 100;
constexpr uint32 COMMAND_ADD_SHOW_FILE_CONTENT = 101;
constexpr uint32 COMMAND_EXPORT_ASM_FILE = 102;
constexpr uint32 COMMAND_JUMP_BACK = 103;
constexpr uint32 COMMAND_JUMP_FORWARD = 104;
constexpr uint32 COMMAND_DISSAM_GOTO_ENTRYPOINT = 105;
constexpr uint32 COMMAND_ADD_OR_EDIT_COMMENT = 106;
constexpr uint32 COMMAND_REMOVE_COMMENT = 107;

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_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;

namespace GView
{
namespace View
{
namespace DissasmViewer
{
using namespace AppCUI;

struct Config {
struct {
Graphics::ColorPair Normal;
Graphics::ColorPair Highlight;
Graphics::ColorPair HighlightCursorLine;
Graphics::ColorPair Inactive;
Graphics::ColorPair Cursor;
Graphics::ColorPair Line;
Graphics::ColorPair Selection;
Graphics::ColorPair OutsideZone;
Graphics::ColorPair StructureColor;
Graphics::ColorPair DataTypeColor;
Graphics::ColorPair AsmOffsetColor; // 0xsomthing
Graphics::ColorPair AsmIrrelevantInstructionColor; // int3
Graphics::ColorPair AsmWorkRegisterColor; // eax, ebx,ecx, edx
Graphics::ColorPair AsmStackRegisterColor; // ebp, edi, esi
Graphics::ColorPair AsmCompareInstructionColor; // test, cmp
Graphics::ColorPair AsmFunctionColor; // ret call
Graphics::ColorPair AsmLocationInstruction; // dword ptr[ ]
Graphics::ColorPair AsmJumpInstruction; // jmp
Graphics::ColorPair AsmComment; // comments added by user
Graphics::ColorPair AsmDefaultColor; // rest of things
Graphics::ColorPair AsmTitleColor;
Graphics::ColorPair AsmTitleColumnColor;
} Colors;

struct DissasmCommand {
Input::Key Key;
const char* Caption;
const char* Explanation;
uint32 CommandId;
};

// Command Bar keys
inline static DissasmCommand AddNewTypeCommand = { Input::Key::F6, "AddNewType", "Add new data type", COMMAND_ADD_NEW_TYPE };
inline static DissasmCommand ShowOrHideFileContentCommand = {
Input::Key::F9, "ShowOrHideFileContent", "Show or hide file content", COMMAND_ADD_SHOW_FILE_CONTENT
};
inline static DissasmCommand AsmExportFileContentCommand = {
Input::Key::F8, "AsmExportToFile", "Export ASM content to file", COMMAND_EXPORT_ASM_FILE
};
inline static DissasmCommand JumpBackCommand = { Input::Key::Ctrl | Input::Key::Q, "JumpBack", "Jump to previous location", COMMAND_JUMP_BACK };
inline static DissasmCommand JumpForwardCommand = {
Input::Key::Ctrl | Input::Key::E, "JumpForward", "Jump to a forward location", COMMAND_JUMP_FORWARD
};
inline static DissasmCommand GotoEntrypointCommand = {
Input::Key::F2, "GoToEntrypoint", "Go to the entry point of the dissasm zone", COMMAND_DISSAM_GOTO_ENTRYPOINT
};

inline static std::array<std::reference_wrapper<DissasmCommand>, 6> CommandBarCommands = {
AddNewTypeCommand, ShowOrHideFileContentCommand, AsmExportFileContentCommand, JumpBackCommand, JumpForwardCommand, GotoEntrypointCommand
};

// Other keys
inline static DissasmCommand AddOrEditCommentCommand = { Input::Key::C, "AddOrEditComment", "Add or edit comments", COMMAND_ADD_OR_EDIT_COMMENT };
inline static DissasmCommand RemoveCommentCommand = { Input::Key::Delete, "RemoveComment", "Remove comment", COMMAND_REMOVE_COMMENT };
inline static DissasmCommand RenameLabelCommand = { Input::Key::N, "RenameLabel", "Rename label or function", COMMAND_REMOVE_COMMENT };

inline static std::array<std::reference_wrapper<DissasmCommand>, 3> KeyDownCommands = { AddOrEditCommentCommand,
RemoveCommentCommand,
RenameLabelCommand };

inline static std::array<std::reference_wrapper<DissasmCommand>, 8> AllKeyboardCommands = {
AddNewTypeCommand, ShowOrHideFileContentCommand, AsmExportFileContentCommand, JumpBackCommand,
JumpForwardCommand, GotoEntrypointCommand, AddOrEditCommentCommand, RemoveCommentCommand
};
bool Loaded;

bool ShowFileContent;
bool EnableDeepScanDissasmOnStart;
static void Update(AppCUI::Utils::IniSection sect);
void Initialize();
};
} // namespace DissasmViewer
} // namespace View
} // namespace GView
Loading

0 comments on commit 3881132

Please sign in to comment.