GP-5995 Corrected default label for circular pointer references

This commit is contained in:
ghidra1 2025-09-17 14:52:14 -04:00
parent a1851c5911
commit dba7f462a2
2 changed files with 53 additions and 3 deletions

View file

@ -4,9 +4,9 @@
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@ -130,6 +130,56 @@ public class SymbolUtilities2Test extends AbstractGhidraHeadedIntegrationTest {
assertEquals("s__CODE_0200", symbol.getName()); assertEquals("s__CODE_0200", symbol.getName());
} }
@Test
public void testDynamicPTRLabel() throws Exception {
// 50 -> 100(pointer) -> 200(pointer) -> 300(pointer) -> 400(byte)XYZ
listing.createData(addr(0x100), PointerDataType.dataType);
listing.createData(addr(0x200), PointerDataType.dataType);
listing.createData(addr(0x300), PointerDataType.dataType);
listing.createData(addr(0x400), ByteDataType.dataType);
symbolTable.createLabel(addr(0x400), "XYZ", SourceType.USER_DEFINED);
refMgr.addMemoryReference(addr(0x50), addr(0x100), RefType.DATA, SourceType.USER_DEFINED,
0);
refMgr.addMemoryReference(addr(0x100), addr(0x200), RefType.DATA, SourceType.USER_DEFINED,
0);
refMgr.addMemoryReference(addr(0x200), addr(0x300), RefType.DATA, SourceType.USER_DEFINED,
0);
refMgr.addMemoryReference(addr(0x300), addr(0x400), RefType.DATA, SourceType.USER_DEFINED,
0);
Symbol symbol = symbolTable.getPrimarySymbol(addr(0x100));
assertEquals("PTR_PTR_CODE_0100", symbol.getName());
symbol = symbolTable.getPrimarySymbol(addr(0x200));
assertEquals("PTR_PTR_CODE_0200", symbol.getName());
symbol = symbolTable.getPrimarySymbol(addr(0x300));
assertEquals("PTR_XYZ_CODE_0300", symbol.getName());
}
@Test
public void testDynamicPTRLOOP1Label() throws Exception {
// 100(pointer) -> 100(pointer)
listing.createData(addr(0x100), PointerDataType.dataType);
refMgr.addMemoryReference(addr(0x100), addr(0x100), RefType.READ, SourceType.USER_DEFINED,
0);
Symbol symbol = symbolTable.getPrimarySymbol(addr(0x100));
assertEquals("PTR_LOOP_CODE_0100", symbol.getName());
}
@Test
public void testDynamicPTRLOOP2Label() throws Exception {
// 100(pointer) -> 200(pointer) -> 100(pointer)
listing.createData(addr(0x100), PointerDataType.dataType);
listing.createData(addr(0x200), PointerDataType.dataType);
refMgr.addMemoryReference(addr(0x100), addr(0x200), RefType.READ, SourceType.USER_DEFINED,
0);
refMgr.addMemoryReference(addr(0x200), addr(0x100), RefType.READ, SourceType.USER_DEFINED,
0);
Symbol symbol = symbolTable.getPrimarySymbol(addr(0x100));
assertEquals("PTR_LOOP_CODE_0100", symbol.getName());
symbol = symbolTable.getPrimarySymbol(addr(0x200));
assertEquals("PTR_LOOP_CODE_0200", symbol.getName());
}
@Test @Test
public void testParseDynamicName() { public void testParseDynamicName() {
assertEquals(addr(0x100), assertEquals(addr(0x100),

View file

@ -259,7 +259,7 @@ public class PointerDataType extends BuiltIn implements Pointer {
while (ref != null && ref.isMemoryReference()) { while (ref != null && ref.isMemoryReference()) {
Address toAddr = ref.getToAddress(); Address toAddr = ref.getToAddress();
if (!refAddrs.add(toAddr)) { if (!refAddrs.add(toAddr)) {
break; return PointerReferenceClassification.LOOP;
} }
if (++depth > 2) { if (++depth > 2) {
return PointerReferenceClassification.DEEP; return PointerReferenceClassification.DEEP;