Miscellaneous Ghidra script tweaks

No behavioural changes.
This commit is contained in:
KeybadeBlox 2026-02-18 18:18:24 -05:00
parent c020c2e247
commit 3c4f0e72b8
3 changed files with 15 additions and 13 deletions

View file

@ -4,6 +4,7 @@
import ghidra.app.script.GhidraScript;
import ghidra.app.services.DataTypeQueryService;
import ghidra.app.util.NamespaceUtils;
import ghidra.program.model.address.Address;
import ghidra.program.model.data.ArrayDataType;
import ghidra.program.model.data.DataType;
@ -27,7 +28,7 @@ import java.util.List;
import java.util.Optional;
public class EnhancedImport extends GhidraScript{
public class EnhancedImport extends GhidraScript {
@Override
public void run() throws Exception {
final FileReader in = new FileReader(askFile("Select input file", "OK"));
@ -86,16 +87,17 @@ public class EnhancedImport extends GhidraScript{
/* Creates namespaces from the given name, returning the deepest one
Returns null if the qualified name is in the global namespace.
*/
final String[] parts = qualifiedName.split("::");
if (parts.length < 2) return null;
final String[] names = Arrays.copyOfRange(parts, 0, parts.length - 1);
Namespace ns = null;
for (final String name : names) ns = createNamespace(ns, name);
return ns;
return qualifiedName.contains("::") ?
NamespaceUtils.createNamespaceHierarchy(
qualifiedName.substring( // Cut off symbol name
0,
qualifiedName.length() - "::".length() -
unqualified(qualifiedName).length()
),
null,
currentProgram,
SourceType.USER_DEFINED
) : null;
}
private Optional<DataType> makeType(final String type) throws Exception {