88import docking .action .DockingAction ;
99import docking .action .MenuData ;
1010import docking .action .ToolBarData ;
11+ import ghidra .program .model .listing .Program ;
12+ import ghidra .program .model .symbol .Namespace ;
1113import ghidra .program .model .symbol .SourceType ;
14+ import ghidra .program .model .symbol .SymbolTable ;
1215import ghidra .util .HTMLUtilities ;
1316import ghidra .util .Msg ;
1417import resources .ResourceManager ;
@@ -32,6 +35,31 @@ protected boolean shouldImportEntry(ComparisonTableModel.Entry e) {
3235 return false ;
3336 }
3437
38+ private Namespace getOrCreateNamespace (Program program , String namespacePath ) throws Exception {
39+
40+ SymbolTable symbolTable = program .getSymbolTable ();
41+ Namespace currentNamespace = program .getGlobalNamespace ();
42+
43+ if (namespacePath == null || namespacePath .isEmpty ()) {
44+ return currentNamespace ;
45+ }
46+
47+ String [] namespaces = namespacePath .split ("::" );
48+ for (String namespaceName : namespaces ) {
49+ ghidra .program .model .symbol .Namespace nextNamespace = symbolTable .getNamespace (
50+ namespaceName , currentNamespace );
51+
52+ if (nextNamespace == null ) {
53+ nextNamespace = symbolTable .createNameSpace (
54+ currentNamespace , namespaceName , SourceType .IMPORTED );
55+ }
56+
57+ currentNamespace = nextNamespace ;
58+ }
59+
60+ return currentNamespace ;
61+ }
62+
3563 @ Override
3664 public void actionPerformed (ActionContext arg0 ) {
3765 int trans = plugin .program .startTransaction ("Rename functions" );
@@ -46,7 +74,24 @@ public void actionPerformed(ActionContext arg0) {
4674 Exception exp = null ;
4775 try {
4876 transformation = e .primaryFunctionSymbol .getName () + " -> " + e .secondaryFunctionName ;
49- e .primaryFunctionSymbol .setName (e .secondaryFunctionName , SourceType .IMPORTED );
77+
78+ if (e .secondaryFunctionName .contains ("::" )) {
79+ String [] parts = e .secondaryFunctionName .split ("::" );
80+ String methodName = parts [parts .length - 1 ];
81+
82+ StringBuilder namespacePath = new StringBuilder ();
83+ for (int i = 0 ; i < parts .length - 1 ; i ++) {
84+ if (i > 0 ) namespacePath .append ("::" );
85+ namespacePath .append (parts [i ]);
86+ }
87+
88+ Namespace namespace = getOrCreateNamespace (plugin .program , namespacePath .toString ());
89+
90+ e .primaryFunctionSymbol .setNameAndNamespace (methodName , namespace , SourceType .IMPORTED );
91+ } else {
92+ e .primaryFunctionSymbol .setName (e .secondaryFunctionName , SourceType .IMPORTED );
93+ }
94+
5095 e .do_import = false ;
5196 } catch (Exception ex ) {
5297 exp = ex ;
0 commit comments