Skip to content

Commit

Permalink
Closes #202, dissasm view now all labels can be renamed
Browse files Browse the repository at this point in the history
  • Loading branch information
rzaharia committed Jan 6, 2024
1 parent 2628660 commit 462b44b
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 17 deletions.
2 changes: 1 addition & 1 deletion GViewCore/src/View/DissasmViewer/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ target_sources(
DissasmProperties.cpp
DissasmKeyEvents.cpp
DissasmX86.cpp
CommentDataWindow.cpp
SingleSelectionDataWindow.cpp
AdvancedSelection.hpp
AdvancedSelection.cpp
DissasmDataTypes.hpp
Expand Down
5 changes: 4 additions & 1 deletion GViewCore/src/View/DissasmViewer/Config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,11 @@ namespace View
// 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>, 2> KeyDownCommands = { AddOrEditCommentCommand, RemoveCommentCommand };
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,
Expand Down
5 changes: 5 additions & 0 deletions GViewCore/src/View/DissasmViewer/DissasmKeyEvents.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,11 @@ bool Instance::OnKeyEvent(AppCUI::Input::Key keyCode, char16 charCode)
return true;
}

if (keyCode == Config::RenameLabelCommand.Key) {
RenameLabel();
return true;
}

return ViewControl::OnKeyEvent(select ? (keyCode | Key::Shift) : keyCode, charCode);
}

Expand Down
7 changes: 4 additions & 3 deletions GViewCore/src/View/DissasmViewer/DissasmViewer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,7 @@ namespace View
void AddNewCollapsibleZone();
void AddComment();
void RemoveComment();
void RenameLabel();
void CommandExportAsmFile();
void ProcessSpaceKey(bool goToEntryPoint = false);
void CommandDissasmAddZone();
Expand Down Expand Up @@ -553,15 +554,15 @@ namespace View
virtual const vector<Property> GetPropertiesList() override;
}; // Instance

class CommentDataWindow : public Window
class SingleLineEditWindow : public Window
{
std::string data;
Reference<TextField> commentTextField;
Reference<TextField> textField;

void Validate();

public:
CommentDataWindow(std::string initialComment);
SingleLineEditWindow(std::string initialText,const char* title);
virtual bool OnEvent(Reference<Control>, Event eventType, int ID) override;
inline std::string GetResult() const
{
Expand Down
47 changes: 46 additions & 1 deletion GViewCore/src/View/DissasmViewer/Instance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ void Instance::AddComment()
convertedZone->comments.HasComment(startingLine, foundComment);

selection.Clear();
CommentDataWindow dlg(foundComment);
SingleLineEditWindow dlg(foundComment,"Add Comment");
if (dlg.Show() == Dialogs::Result::Ok) {
convertedZone->comments.AddOrUpdateComment(startingLine, dlg.GetResult());
}
Expand Down Expand Up @@ -312,6 +312,51 @@ void Instance::RemoveComment()
convertedZone->comments.RemoveComment(startingLine);
}

void Instance::RenameLabel()
{
const uint64 offsetStart = Cursor.GetOffset(Layout.textSize);
const uint64 offsetEnd = offsetStart + 1;

const auto zonesFound = GetZonesIndexesFromPosition(offsetStart, offsetEnd);
if (zonesFound.empty() || zonesFound.size() != 1) {
Dialogs::MessageBox::ShowNotification("Warning", "Please make a selection on a dissasm zone!");
return;
}

const auto& zone = settings->parseZones[zonesFound[0].zoneIndex];
if (zone->zoneType != DissasmParseZoneType::DissasmCodeParseZone) {
Dialogs::MessageBox::ShowNotification("Warning", "Please make a selection on a dissasm zone!");
return;
}

uint32 startingLine = zonesFound[0].startingLine;
if (startingLine == 0 || startingLine == 1) {
Dialogs::MessageBox::ShowNotification("Warning", "Please add comment inside the region, not on the title!");
return;
}
startingLine--;

const auto convertedZone = static_cast<DissasmCodeZone*>(zone.get());
startingLine = startingLine - 1;

// TODO: improve, add searching function to search inside types for the current annotation
auto& annotations = convertedZone->types.back().get().annotations;
auto it = annotations.find(startingLine);
if (it == annotations.end()) {
Dialogs::MessageBox::ShowNotification("Warning", "That line cannot pe renamed!");
return;
}

selection.Clear();
SingleLineEditWindow dlg(it->second.first, "Edit label");
if (dlg.Show() == Dialogs::Result::Ok) {
const auto res = dlg.GetResult();
if (!res.empty())
it->second.first = res;
}
convertedZone->asmPreCacheData.Clear();
}

bool Instance::PrepareDrawLineInfo(DrawLineInfo& dli)
{
if (dli.recomputeOffsets) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,32 +5,32 @@ using namespace GView::View::DissasmViewer;
constexpr int32 BTN_ID_OK = 1;
constexpr int32 BTN_ID_CANCEL = 2;

void CommentDataWindow::Validate()
void SingleLineEditWindow::Validate()
{
LocalString<128> tmp;
if (commentTextField->GetText().IsEmpty())
if (textField->GetText().IsEmpty())
{
Dialogs::MessageBox::ShowError("Error", "Please write something in the comment section !");
commentTextField->SetFocus();
textField->SetFocus();
}
data = commentTextField->GetText();
data = textField->GetText();
Exit(Dialogs::Result::Ok);
}

CommentDataWindow::CommentDataWindow(std::string initialComment) : Window("Add comment", "d:c,w:60,h:7", WindowFlags::ProcessReturn)
SingleLineEditWindow::SingleLineEditWindow(std::string initialText, const char* title) : Window(title, "d:c,w:60,h:7", WindowFlags::ProcessReturn)
{
data = initialComment;
Factory::Label::Create(this, "&Comment", "x:1,y:1,w:8");
commentTextField = Factory::TextField::Create(this, initialComment, "x:10,y:1,w:46");
commentTextField->SetHotKey('C');
data = initialText;
Factory::Label::Create(this, "&Text", "x:1,y:1,w:8");
textField = Factory::TextField::Create(this, initialText, "x:10,y:1,w:46");
textField->SetHotKey('T');

Factory::Button::Create(this, "&OK", "l:16,b:0,w:13", BTN_ID_OK);
Factory::Button::Create(this, "&Cancel", "l:31,b:0,w:13", BTN_ID_CANCEL);

commentTextField->SetFocus();
textField->SetFocus();
}

bool CommentDataWindow::OnEvent(Reference<Control>, Event eventType, int ID)
bool SingleLineEditWindow::OnEvent(Reference<Control>, Event eventType, int ID)
{
if (eventType == Event::ButtonClicked)
{
Expand Down

0 comments on commit 462b44b

Please sign in to comment.