Skip to content

Commit

Permalink
dissasm added more tests #231
Browse files Browse the repository at this point in the history
collapsible blocks are now deletable #215
  • Loading branch information
rzaharia committed Mar 2, 2024
1 parent 137821b commit 22a8320
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 12 deletions.
15 changes: 10 additions & 5 deletions GViewCore/src/View/DissasmViewer/DissasmX86.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1728,6 +1728,7 @@ bool DissasmCodeZone::ResetTypesReferenceList()
lastReachedLine = static_cast<uint32>(-1);
types.emplace_back(dissasmType);
levels.push_back(0);
ResetZoneCaching();
return true;
}

Expand Down Expand Up @@ -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;
}
Expand Down
75 changes: 68 additions & 7 deletions GViewCore/src/View/DissasmViewer/tests_dissasmviewer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,6 @@ class DissasmTestInstance

TEST_CASE("DissasmFunctions", "[Dissasm]")
{
return;
uint64 value = 0;
REQUIRE(!CheckExtractInsnHexValue("mov eax, 0x1234", value, 5));

Expand Down Expand Up @@ -536,7 +535,6 @@ TEST_CASE("DissasmFunctions", "[Dissasm]")

TEST_CASE("AddAndCollapseCollapsibleZones", "[Dissasm]")
{
return;
DissasmTestInstance dissasmInstance(exampleTest1BinaryCode, exampleTest1BinaryCodeSize);

uint32 zoneEndingIndex = 4572;
Expand Down Expand Up @@ -590,7 +588,6 @@ TEST_CASE("AddAndCollapseCollapsibleZones", "[Dissasm]")

TEST_CASE("AddAndCollapseCollapsibleZones2", "[Dissasm]")
{
return;
DissasmTestInstance dissasmInstance(exampleTest1BinaryCode, exampleTest1BinaryCodeSize);
uint32 zoneEndingIndex = 4572;

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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"));
Expand All @@ -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"));
}
}

0 comments on commit 22a8320

Please sign in to comment.