|
18 | 18 | import java.io.File; |
19 | 19 | import java.io.FileWriter; |
20 | 20 | import java.io.IOException; |
21 | | - |
22 | 21 | import ghidra.app.cmd.function.CreateFunctionCmd; |
23 | 22 | import ghidra.app.services.AbstractAnalyzer; |
24 | 23 | import ghidra.app.services.AnalyzerType; |
25 | 24 | import ghidra.app.util.importer.MessageLog; |
26 | 25 | import ghidra.framework.options.Options; |
27 | 26 | import ghidra.program.model.address.Address; |
28 | 27 | import ghidra.program.model.address.AddressSetView; |
29 | | -import ghidra.program.model.data.StringDataType; |
30 | 28 | import ghidra.program.model.listing.Data; |
31 | 29 | import ghidra.program.model.listing.Function; |
32 | 30 | import ghidra.program.model.listing.Listing; |
| 31 | +import ghidra.program.model.listing.Parameter; |
| 32 | +import ghidra.program.model.listing.ParameterImpl; |
33 | 33 | import ghidra.program.model.listing.Program; |
34 | 34 | import ghidra.program.model.mem.Memory; |
35 | 35 | import ghidra.program.model.mem.MemoryAccessException; |
|
40 | 40 | import ghidra.util.exception.DuplicateNameException; |
41 | 41 | import ghidra.util.exception.InvalidInputException; |
42 | 42 | import ghidra.util.task.TaskMonitor; |
43 | | -import ghidra.program.model.lang.LanguageID; |
| 43 | +import ghidra.program.model.data.*; |
44 | 44 |
|
45 | 45 | /** |
46 | 46 | * TODO: Provide class-level documentation that describes what this analyzer does. |
@@ -130,6 +130,7 @@ public boolean added(Program program, AddressSetView set, TaskMonitor monitor, M |
130 | 130 | } |
131 | 131 |
|
132 | 132 | rename_function(program, monitor, func_addr_value, func_name); |
| 133 | + modify_function(program, func_addr_value, args); |
133 | 134 | }catch(Exception e) { |
134 | 135 | log.appendException(e); |
135 | 136 | } |
@@ -213,4 +214,31 @@ void rename_function(Program program, TaskMonitor monitor, long func_addr_value, |
213 | 214 | } |
214 | 215 | func.setName(func_name, SourceType.ANALYSIS); |
215 | 216 | } |
| 217 | + |
| 218 | + void modify_function(Program program, long func_addr_value, int args_num) { |
| 219 | + Address func_addr=program.getAddressFactory().getDefaultAddressSpace().getAddress(func_addr_value); |
| 220 | + Function func=program.getFunctionManager().getFunctionAt(func_addr); |
| 221 | + if(func==null) { |
| 222 | + return; |
| 223 | + } |
| 224 | + if(func.getParameterCount()==args_num/get_pointer_size(program)) { |
| 225 | + return; |
| 226 | + } |
| 227 | + |
| 228 | + try { |
| 229 | + for(int i=func.getAutoParameterCount();i<args_num/get_pointer_size(program);i++) { |
| 230 | + ParameterImpl param=null; |
| 231 | + if(get_pointer_size(program)==8) { |
| 232 | + param=new ParameterImpl(String.format("param_%d", i+1), new Undefined8DataType(), func.getProgram()); |
| 233 | + }else { |
| 234 | + param=new ParameterImpl(String.format("param_%d", i+1), new Undefined4DataType(), func.getProgram()); |
| 235 | + } |
| 236 | + func.addParameter(param, SourceType.USER_DEFINED); |
| 237 | + } |
| 238 | + for(int i=func.getAutoParameterCount();i>args_num/get_pointer_size(program);i--) { |
| 239 | + func.removeParameter(i-1); |
| 240 | + } |
| 241 | + }catch(Exception e) { |
| 242 | + } |
| 243 | + } |
216 | 244 | } |
0 commit comments