Skip to content

Commit

Permalink
Merge pull request #242 from gdt050579/dissasm_view
Browse files Browse the repository at this point in the history
Dissasm view added collapsible zones now fully working
  • Loading branch information
rzaharia authored Mar 3, 2024
2 parents 481bc41 + 22a8320 commit f46db08
Show file tree
Hide file tree
Showing 5 changed files with 778 additions and 272 deletions.
2 changes: 1 addition & 1 deletion GViewCore/src/View/DissasmViewer/DissasmKeyEvents.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ void Instance::OnMousePressed(int x, int y, Input::MouseButton button, Input::Ke
} else if (mpInfo.location == MouseLocation::Outside && !MyLine.buttons.empty()) {
for (const auto& btn : MyLine.buttons)
if (btn.x == x && btn.y == y) {
ChangeZoneCollapseState(btn.zone);
ChangeZoneCollapseState(btn.zone, btn.y - 1); // 1 for the initial empty line
break;
}
}
Expand Down
43 changes: 29 additions & 14 deletions GViewCore/src/View/DissasmViewer/DissasmViewer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,9 @@ namespace View
uint8 lineArrowToDraw;
const void* mapping;

bool shouldAddButton;
bool isZoneCollapsed;

uint32 GetLineSize() const
{
return size * 2 + op_str_size;
Expand All @@ -167,6 +170,8 @@ namespace View
mapping = other.mapping;
memcpy(bytes, other.bytes, sizeof(bytes));
memcpy(mnemonic, other.mnemonic, CS_MNEMONIC_SIZE);
shouldAddButton = other.shouldAddButton;
isZoneCollapsed = false;
}
DissasmAsmPreCacheLine(const DissasmAsmPreCacheLine& other)
{
Expand All @@ -180,6 +185,8 @@ namespace View
mapping = other.mapping;
memcpy(bytes, other.bytes, sizeof(bytes));
memcpy(mnemonic, other.mnemonic, CS_MNEMONIC_SIZE);
shouldAddButton = other.shouldAddButton;
isZoneCollapsed = false;
}
bool TryGetDataFromAnnotations(const DissasmCodeInternalType& currentType, uint32 lineToSearch, struct DrawLineInfo* dli = nullptr);
bool TryGetDataFromInsn(DissasmInsnExtractLineParams& params);
Expand Down Expand Up @@ -266,18 +273,13 @@ namespace View
}

void AnnounceCallInstruction(struct DissasmCodeZone* zone, const AsmFunctionDetails* functionDetails);

bool PopulateAsmPreCacheData(
Config& config,
Reference<GView::Object> obj,
const Pointer<struct SettingsData>& settings,
struct AsmData& asmData,
struct DrawLineInfo& dli,
DissasmCodeZone* zone,
uint32 startingLine,
uint32 linesToPrepare);
};

struct DissasmCodeRemovableZoneDetails
{
DissasmCodeInternalType* zone;
DissasmCodeInternalType* parent;
uint32 zoneIndex;
};
struct DissasmCodeInternalType {
std::string name;
uint32 indexZoneStart;
Expand Down Expand Up @@ -332,6 +334,8 @@ namespace View
}
bool CanAddNewZone(uint32 zoneLineStart, uint32 zoneLineEnd) const;
bool AddNewZone(uint32 zoneLineStart, uint32 zoneLineEnd);
DissasmCodeRemovableZoneDetails GetRemoveZoneCollapsibleDetails(uint32 zoneLine,uint32 depthLevel = 0);
bool RemoveCollapsibleZone(uint32 zoneLine, DissasmCodeRemovableZoneDetails removableDetails);
};

struct DissasmComments {
Expand All @@ -353,7 +357,13 @@ namespace View
uint32 visibleRows;
};

struct InternalTypeNewLevelChangeData {
bool hasName;
bool isCollapsed;
};

struct DissasmCodeZone : public ParseZone {
enum class CollapseExpandType : uint8 { Collapse, Expand, NegateCurrentState };
uint32 lastDrawnLine; // optimization not to recompute buffer every time
uint32 lastClosestLine;
uint32 offsetCacheMaxLine;
Expand All @@ -375,18 +385,23 @@ namespace View
DissasmComments comments;
int internalArchitecture; // used for dissasm libraries
bool isInit;
bool changedLevel;
InternalTypeNewLevelChangeData newLevelChangeData;

void ResetZoneCaching();
bool AddCollapsibleZone(uint32 zoneLineStart, uint32 zoneLineEnd);
bool CanAddNewZone(uint32 zoneLineStart, uint32 zoneLineEnd) const
{
if (zoneLineStart > zoneLineEnd || zoneLineEnd > dissasmType.indexZoneEnd)
return false;
return dissasmType.CanAddNewZone(zoneLineStart, zoneLineEnd);
}
bool CollapseOrExtendZone(uint32 zoneLine, bool collapse);
bool CollapseOrExtendZone(uint32 zoneLine, CollapseExpandType collapse, int32& difference);
bool RemoveCollapsibleZone(uint32 zoneLine);
bool InitZone(DissasmCodeZoneInitData& initData);
void ReachZoneLine(uint32 line);
bool ResetTypesReferenceList();
bool TryRenameLine(uint32 line);
DissasmAsmPreCacheLine GetCurrentAsmLine(uint32 currentLine, Reference<GView::Object> obj, DissasmInsnExtractLineParams* params);
};

Expand Down Expand Up @@ -589,8 +604,8 @@ namespace View
bool DrawDissasmX86AndX64CodeZone(DrawLineInfo& dli, DissasmCodeZone* zone);
bool PrepareDrawLineInfo(DrawLineInfo& dli);

void RegisterStructureCollapseButton(DrawLineInfo& dli, SpecialChars c, ParseZone* zone);
void ChangeZoneCollapseState(ParseZone* zoneToChange);
void RegisterStructureCollapseButton(uint32 screenLine, SpecialChars c, ParseZone* zone);
void ChangeZoneCollapseState(ParseZone* zoneToChange, uint32 line);

void AddStringToChars(DrawLineInfo& dli, ColorPair pair, const char* fmt, ...);
void AddStringToChars(DrawLineInfo& dli, ColorPair pair, string_view stringToAdd);
Expand Down
Loading

0 comments on commit f46db08

Please sign in to comment.