|
35 | 35 | import ghidra.program.model.mem.MemoryAccessException; |
36 | 36 | import ghidra.program.model.mem.MemoryBlock; |
37 | 37 | import ghidra.program.model.symbol.SourceType; |
| 38 | +import ghidra.program.model.util.CodeUnitInsertionException; |
38 | 39 | import ghidra.util.exception.CancelledException; |
| 40 | +import ghidra.util.exception.DuplicateNameException; |
| 41 | +import ghidra.util.exception.InvalidInputException; |
39 | 42 | import ghidra.util.task.TaskMonitor; |
40 | 43 | import ghidra.program.model.lang.LanguageID; |
41 | 44 |
|
@@ -116,35 +119,22 @@ public boolean added(Program program, AddressSetView set, TaskMonitor monitor, M |
116 | 119 | func_info_offset=memory.getInt(func_list_base.add(i*pointer_size*2+pointer_size)); |
117 | 120 | } |
118 | 121 | long func_entry_value=memory.getInt(base.add(func_info_offset)); |
119 | | - |
120 | 122 | func_name_offset=memory.getInt(base.add(func_info_offset+pointer_size)); |
121 | | - |
122 | | - Listing listing=program.getListing(); |
123 | | - |
124 | | - Data func_name_data=listing.getDefinedDataAt(base.add(func_name_offset)); |
125 | | - if(func_name_data==null) { |
126 | | - func_name_data=listing.createData(base.add(func_name_offset), new StringDataType()); |
127 | | - }else if(!func_name_data.getDataType().isEquivalent((new StringDataType()))) { |
128 | | - log.appendMsg("The type of func name data is not String"); |
129 | | - continue; |
130 | | - } |
131 | | - |
132 | 123 | args=memory.getInt(base.add(func_info_offset+pointer_size+4)); |
133 | 124 |
|
134 | 125 | if(func_addr_value!=func_entry_value) |
135 | 126 | { |
136 | | - log.appendMsg(String.format("wrong func addr %x %x", func_addr_value, func_entry_value)); |
| 127 | + log.appendMsg(String.format("Wrong func addr %x %x", func_addr_value, func_entry_value)); |
137 | 128 | continue; |
138 | 129 | } |
139 | | - Address func_addr=program.getAddressFactory().getDefaultAddressSpace().getAddress(func_addr_value); |
140 | | - Function func=program.getFunctionManager().getFunctionAt(func_addr); |
141 | | - String func_name=(String)func_name_data.getValue(); |
142 | | - if(func==null) { |
143 | | - CreateFunctionCmd cmd=new CreateFunctionCmd(func_name, func_addr, null, SourceType.ANALYSIS); |
144 | | - cmd.applyTo(program, monitor); |
| 130 | + |
| 131 | + String func_name=create_function_name_data(program, base.add(func_name_offset)); |
| 132 | + if(func_name==null) { |
| 133 | + log.appendMsg("The type of func name data is not String"); |
145 | 134 | continue; |
146 | 135 | } |
147 | | - func.setName(func_name, SourceType.ANALYSIS); |
| 136 | + |
| 137 | + rename_function(program, monitor, func_addr_value, func_name); |
148 | 138 | }catch(Exception e) { |
149 | 139 | log.appendException(e); |
150 | 140 | } |
@@ -183,4 +173,26 @@ Address get_gopclntab(Program program, TaskMonitor monitor) { |
183 | 173 |
|
184 | 174 | return find; |
185 | 175 | } |
| 176 | + |
| 177 | + String create_function_name_data(Program program, Address address) throws CodeUnitInsertionException { |
| 178 | + Listing listing=program.getListing(); |
| 179 | + Data func_name_data=listing.getDefinedDataAt(address); |
| 180 | + if(func_name_data==null) { |
| 181 | + func_name_data=listing.createData(address, new StringDataType()); |
| 182 | + }else if(!func_name_data.getDataType().isEquivalent((new StringDataType()))) { |
| 183 | + return null; |
| 184 | + } |
| 185 | + return (String)func_name_data.getValue(); |
| 186 | + } |
| 187 | + |
| 188 | + void rename_function(Program program, TaskMonitor monitor, long func_addr_value, String func_name) throws DuplicateNameException, InvalidInputException { |
| 189 | + Address func_addr=program.getAddressFactory().getDefaultAddressSpace().getAddress(func_addr_value); |
| 190 | + Function func=program.getFunctionManager().getFunctionAt(func_addr); |
| 191 | + if(func==null) { |
| 192 | + CreateFunctionCmd cmd=new CreateFunctionCmd(func_name, func_addr, null, SourceType.ANALYSIS); |
| 193 | + cmd.applyTo(program, monitor); |
| 194 | + return; |
| 195 | + } |
| 196 | + func.setName(func_name, SourceType.ANALYSIS); |
| 197 | + } |
186 | 198 | } |
0 commit comments