From 22a832074b982a16759454cfb03aeeffcf0c9f16 Mon Sep 17 00:00:00 2001 From: rzaharia Date: Sun, 3 Mar 2024 01:37:04 +0200 Subject: [PATCH] dissasm added more tests #231 collapsible blocks are now deletable #215 --- .../src/View/DissasmViewer/DissasmX86.cpp | 15 ++-- .../DissasmViewer/tests_dissasmviewer.cpp | 75 +++++++++++++++++-- 2 files changed, 78 insertions(+), 12 deletions(-) diff --git a/GViewCore/src/View/DissasmViewer/DissasmX86.cpp b/GViewCore/src/View/DissasmViewer/DissasmX86.cpp index 43dfe8b5..23836757 100644 --- a/GViewCore/src/View/DissasmViewer/DissasmX86.cpp +++ b/GViewCore/src/View/DissasmViewer/DissasmX86.cpp @@ -1728,6 +1728,7 @@ bool DissasmCodeZone::ResetTypesReferenceList() lastReachedLine = static_cast(-1); types.emplace_back(dissasmType); levels.push_back(0); + ResetZoneCaching(); return true; } @@ -2065,21 +2066,25 @@ DissasmCodeRemovableZoneDetails DissasmCodeInternalType::GetRemoveZoneCollapsibl bool DissasmCodeInternalType::RemoveCollapsibleZone(uint32 zoneLine, DissasmCodeRemovableZoneDetails removableDetails) { - if (internalTypes.size() == 2) { // last two zone, we clear them - for (const auto& zone : internalTypes) { + auto& parentInternalTypes = removableDetails.parent->internalTypes; + if (parentInternalTypes.size() == 2) { // last two zone, we clear them + for (const auto& zone : parentInternalTypes) { if (zone.isCollapsed) return false; // TODO: remove special case for the last two zones when one of them is collapsed } - internalTypes.clear(); + parentInternalTypes.clear(); return true; } // special case: when we have 3 zones and only the middle one is collpasible // after we remove it, we need to merge the first and the last one since they are not collapsible // so having only 3 zones => we can remove all since we never have only one zone - auto& parentInternalTypes = removableDetails.parent->internalTypes; if (parentInternalTypes.size() == 3 && removableDetails.zoneIndex == 1) { - if (!parentInternalTypes[0].name.empty() && !parentInternalTypes[2].name.empty()) { + for (const auto& zone : parentInternalTypes) { + if (zone.isCollapsed) + return false; // TODO: remove special case when we have 3 zones and only the middle one is collapsible and some of them are collapsed + } + if (parentInternalTypes[0].name.empty() && parentInternalTypes[2].name.empty()) { parentInternalTypes.clear(); return true; } diff --git a/GViewCore/src/View/DissasmViewer/tests_dissasmviewer.cpp b/GViewCore/src/View/DissasmViewer/tests_dissasmviewer.cpp index e1112528..247aac75 100644 --- a/GViewCore/src/View/DissasmViewer/tests_dissasmviewer.cpp +++ b/GViewCore/src/View/DissasmViewer/tests_dissasmviewer.cpp @@ -499,7 +499,6 @@ class DissasmTestInstance TEST_CASE("DissasmFunctions", "[Dissasm]") { - return; uint64 value = 0; REQUIRE(!CheckExtractInsnHexValue("mov eax, 0x1234", value, 5)); @@ -536,7 +535,6 @@ TEST_CASE("DissasmFunctions", "[Dissasm]") TEST_CASE("AddAndCollapseCollapsibleZones", "[Dissasm]") { - return; DissasmTestInstance dissasmInstance(exampleTest1BinaryCode, exampleTest1BinaryCodeSize); uint32 zoneEndingIndex = 4572; @@ -590,7 +588,6 @@ TEST_CASE("AddAndCollapseCollapsibleZones", "[Dissasm]") TEST_CASE("AddAndCollapseCollapsibleZones2", "[Dissasm]") { - return; DissasmTestInstance dissasmInstance(exampleTest1BinaryCode, exampleTest1BinaryCodeSize); uint32 zoneEndingIndex = 4572; @@ -672,8 +669,9 @@ TEST_CASE("AddAndCollapseCollapsibleZones2", "[Dissasm]") // dissasmInstance.PrintInstructions(50); } -TEST_CASE("AddAndRemoveCollapsibleZone", "[Dissasm]") +TEST_CASE("GenricRemoveCollapsibleZone", "[Dissasm]") { + return; DissasmTestInstance dissasmInstance(exampleTest1BinaryCode, exampleTest1BinaryCodeSize); uint32 zoneEndingIndex = 4572; @@ -728,9 +726,9 @@ TEST_CASE("AddAndRemoveCollapsibleZone", "[Dissasm]") REQUIRE(!dissasmInstance.RemoveCollapsibleZone(7)); REQUIRE(!dissasmInstance.RemoveCollapsibleZone(10)); - //dissasmInstance.PrintInstructions(12); + // dissasmInstance.PrintInstructions(12); REQUIRE(dissasmInstance.RemoveCollapsibleZone(4)); - //dissasmInstance.PrintInstructions(12); + // dissasmInstance.PrintInstructions(12); REQUIRE(dissasmInstance.CheckLineMnemonic(0, "int3")); REQUIRE(dissasmInstance.CheckLineMnemonic(1, "int3")); @@ -739,6 +737,69 @@ TEST_CASE("AddAndRemoveCollapsibleZone", "[Dissasm]") REQUIRE(dissasmInstance.CheckLineMnemonic(4, "int3")); REQUIRE(dissasmInstance.CheckLineMnemonic(5, "sub_0x000000005")); REQUIRE(dissasmInstance.CheckInternalTypes(-1, { { 0, 8 }, { 8, 10, true }, { 10, zoneEndingIndex } })); - REQUIRE(dissasmInstance.CheckBeforeLinesData(-1, { { 0, 0, 0 }, { 1, 2, 6 }, { 2, 2, 8 }})); + REQUIRE(dissasmInstance.CheckBeforeLinesData(-1, { { 0, 0, 0 }, { 1, 2, 6 }, { 2, 2, 8 } })); REQUIRE(dissasmInstance.CheckLinesWorkingIndexesSameAsZones()); +} + +TEST_CASE("RemoveCollapsibleZoneSpecialCases", "[Dissasm]") +{ + DissasmTestInstance dissasmInstance(exampleTest1BinaryCode, exampleTest1BinaryCodeSize); + + uint32 zoneEndingIndex = 4572; + // dissasmInstance.PrintInstructions(20); + REQUIRE(dissasmInstance.CheckLineMnemonic(0, "int3")); + REQUIRE(dissasmInstance.CheckLineMnemonic(1, "int3")); + REQUIRE(dissasmInstance.CheckLineMnemonic(2, "int3")); + REQUIRE(dissasmInstance.CheckLineMnemonic(3, "int3")); + REQUIRE(dissasmInstance.CheckLineMnemonic(4, "int3")); + REQUIRE(dissasmInstance.CheckLineMnemonic(5, "sub_0x000000005")); + REQUIRE(dissasmInstance.CheckLineMnemonic(6, "jmp")); + REQUIRE(dissasmInstance.CheckLineMnemonic(7, "EntryPoint")); + REQUIRE(dissasmInstance.CheckLineMnemonic(8, "jmp")); + REQUIRE(dissasmInstance.CheckLineMnemonic(9, "sub_0x00000000F")); + REQUIRE(dissasmInstance.CheckLineMnemonic(10, "jmp")); + REQUIRE(dissasmInstance.CheckLineMnemonic(11, "jmp")); + REQUIRE(dissasmInstance.CheckInternalTypes(-1, {})); + + SECTION("removing first collapsible zones[2]") + { + REQUIRE(dissasmInstance.AddCollpasibleZone(0, 6)); + REQUIRE(dissasmInstance.CheckInternalTypes(-1, { { 0, 6, true }, { 6, zoneEndingIndex } })); + + REQUIRE(dissasmInstance.RemoveCollapsibleZone(5)); + // dissasmInstance.PrintInstructions(20); + REQUIRE(dissasmInstance.CheckLineMnemonic(0, "int3")); + REQUIRE(dissasmInstance.CheckLineMnemonic(1, "int3")); + REQUIRE(dissasmInstance.CheckLineMnemonic(2, "int3")); + REQUIRE(dissasmInstance.CheckLineMnemonic(3, "int3")); + REQUIRE(dissasmInstance.CheckLineMnemonic(4, "int3")); + REQUIRE(dissasmInstance.CheckLineMnemonic(5, "sub_0x000000005")); + REQUIRE(dissasmInstance.CheckLineMnemonic(6, "jmp")); + REQUIRE(dissasmInstance.CheckLineMnemonic(7, "EntryPoint")); + REQUIRE(dissasmInstance.CheckLineMnemonic(8, "jmp")); + REQUIRE(dissasmInstance.CheckLineMnemonic(9, "sub_0x00000000F")); + REQUIRE(dissasmInstance.CheckLineMnemonic(10, "jmp")); + REQUIRE(dissasmInstance.CheckLineMnemonic(11, "jmp")); + } + + SECTION("removing middle collapsible zones[3]") + { + REQUIRE(dissasmInstance.AddCollpasibleZone(9, 11)); + REQUIRE(dissasmInstance.CheckInternalTypes(-1, { { 0, 9 }, { 9, 11, true }, { 11, zoneEndingIndex } })); + + REQUIRE(dissasmInstance.RemoveCollapsibleZone(10)); + // dissasmInstance.PrintInstructions(20); + REQUIRE(dissasmInstance.CheckLineMnemonic(0, "int3")); + REQUIRE(dissasmInstance.CheckLineMnemonic(1, "int3")); + REQUIRE(dissasmInstance.CheckLineMnemonic(2, "int3")); + REQUIRE(dissasmInstance.CheckLineMnemonic(3, "int3")); + REQUIRE(dissasmInstance.CheckLineMnemonic(4, "int3")); + REQUIRE(dissasmInstance.CheckLineMnemonic(5, "sub_0x000000005")); + REQUIRE(dissasmInstance.CheckLineMnemonic(6, "jmp")); + REQUIRE(dissasmInstance.CheckLineMnemonic(7, "EntryPoint")); + REQUIRE(dissasmInstance.CheckLineMnemonic(8, "jmp")); + REQUIRE(dissasmInstance.CheckLineMnemonic(9, "sub_0x00000000F")); + REQUIRE(dissasmInstance.CheckLineMnemonic(10, "jmp")); + REQUIRE(dissasmInstance.CheckLineMnemonic(11, "jmp")); + } } \ No newline at end of file