Skip to content

Commit

Permalink
fixed GhidraTest
Browse files Browse the repository at this point in the history
  • Loading branch information
morbitzer committed Dec 12, 2024
1 parent 3bfe2fc commit 2558fb5
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ abstract class Expression : Statement(), HasType {
}

/** Each Expression also has a MemoryAddress. */
var memoryAddress = mutableSetOf<MemoryAddress>()
var memoryAddress = mutableSetOf<Node>()

override fun toString(): String {
return ToStringBuilder(this, TO_STRING_STYLE)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,8 @@ class PointsToPass(ctx: TranslationContext) : EOGStarterPass(ctx, orderDependenc
is Expression -> {
val newMemoryValues = value.elements.second.elements
val newMemoryAddresses =
value.elements.first.elements.filterIsInstance<MemoryAddress>()
value.elements.first.elements
as Collection<Node> /*.filterIsInstance<MemoryAddress>()*/
if (newMemoryValues.isNotEmpty()) {
key.prevDFG.clear()
key.prevDFG.addAll(newMemoryValues)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -326,9 +326,7 @@ class PointsToPassTest {
// Line 51
assertEquals(1, saLine51.memoryAddress.size)
assertEquals(
(saLine51.base as? Reference)
?.memoryAddress
?.firstOrNull()
((saLine51.base as? Reference)?.memoryAddress?.firstOrNull() as? MemoryAddress)
?.fieldAddresses
?.filter { it.key == saLine51.refersTo?.name.toString() }
?.entries
Expand All @@ -343,9 +341,7 @@ class PointsToPassTest {
// Line 52
assertEquals(1, sbLine52.memoryAddress.size)
assertEquals(
(sbLine52.base as? Reference)
?.memoryAddress
?.firstOrNull()
((sbLine52.base as? Reference)?.memoryAddress?.firstOrNull() as? MemoryAddress)
?.fieldAddresses
?.filter { it.key == sbLine52.refersTo?.name.toString() }
?.entries
Expand All @@ -360,9 +356,7 @@ class PointsToPassTest {
// Line 53
assertEquals(1, saLine53.memoryAddress.size)
assertEquals(
(saLine53.base as? Reference)
?.memoryAddress
?.firstOrNull()
((saLine53.base as? Reference)?.memoryAddress?.firstOrNull() as? MemoryAddress)
?.fieldAddresses
?.filter { it.key == saLine53.refersTo?.name.toString() }
?.entries
Expand All @@ -376,9 +370,7 @@ class PointsToPassTest {

assertEquals(1, sbLine53.memoryAddress.size)
assertEquals(
(sbLine53.base as? Reference)
?.memoryAddress
?.firstOrNull()
((sbLine53.base as? Reference)?.memoryAddress?.firstOrNull() as? MemoryAddress)
?.fieldAddresses
?.filter { it.key == sbLine53.refersTo?.name.toString() }
?.entries
Expand Down Expand Up @@ -459,8 +451,14 @@ class PointsToPassTest {

// Line 66
assertEquals(1, n0Line66.memoryAddress.size)
assertTrue(n0Line66.arrayExpression.memoryAddress.first() is MemoryAddress)
assertEquals(
n0Line66.arrayExpression.memoryAddress.first().fieldAddresses["0"]?.first(),
(n0Line66.arrayExpression.memoryAddress
.filterIsInstance<MemoryAddress>()
.firstOrNull()
?.fieldAddresses
?.get("0")
?.first() as MemoryAddress),
n0Line66.memoryAddress.first()
)
assertEquals(1, n0Line66.prevDFG.size)
Expand All @@ -469,7 +467,12 @@ class PointsToPassTest {
// Line 67
assertEquals(1, n0Line67.memoryAddress.size)
assertEquals(
n0Line67.arrayExpression.memoryAddress.first().fieldAddresses["0"]?.first(),
(n0Line67.arrayExpression.memoryAddress
.filterIsInstance<MemoryAddress>()
.firstOrNull()
?.fieldAddresses
?.get("0")
?.first() as MemoryAddress),
n0Line67.memoryAddress.first()
)
assertEquals(1, n0Line67.prevDFG.size)
Expand All @@ -478,7 +481,12 @@ class PointsToPassTest {
// Line 68
assertEquals(1, n0Line68.memoryAddress.size)
assertEquals(
n0Line68.arrayExpression.memoryAddress.first().fieldAddresses["0"]?.first(),
(n0Line68.arrayExpression.memoryAddress
.filterIsInstance<MemoryAddress>()
.firstOrNull()
?.fieldAddresses
?.get("0")
?.first() as MemoryAddress),
n0Line68.memoryAddress.first()
)
assertEquals(1, n0Line68.prevDFG.size)
Expand All @@ -487,7 +495,12 @@ class PointsToPassTest {
// Line 71
assertEquals(1, niLine71.memoryAddress.size)
assertEquals(
niLine71.arrayExpression.memoryAddress.first().fieldAddresses["i"]?.first(),
(niLine71.arrayExpression.memoryAddress
.filterIsInstance<MemoryAddress>()
.firstOrNull()
?.fieldAddresses
?.get("i")
?.first() as MemoryAddress),
niLine71.memoryAddress.first()
)
assertEquals(1, niLine71.prevDFG.size)
Expand All @@ -496,7 +509,12 @@ class PointsToPassTest {
// Line 75
assertEquals(1, njLine75.memoryAddress.size)
assertEquals(
njLine75.arrayExpression.memoryAddress.first().fieldAddresses["j"]?.first(),
(njLine75.arrayExpression.memoryAddress
.filterIsInstance<MemoryAddress>()
.firstOrNull()
?.fieldAddresses
?.get("j")
?.first() as MemoryAddress),
njLine75.memoryAddress.first()
)
// TODO: What are our expections for njLine75.prevDFG? I think null is fine, since we
Expand Down

0 comments on commit 2558fb5

Please sign in to comment.