From e2ec9e39b467f6dbf39bae509b392419e6e0d07d Mon Sep 17 00:00:00 2001 From: dev747368 <48332326+dev747368@users.noreply.github.com> Date: Wed, 3 Jul 2019 17:38:56 -0400 Subject: [PATCH] GT-2970 tweak Flat api javadoc and fix usage of deprecated number stuff --- .../program/flatapi/FlatProgramAPI.java | 61 ++++++++++--------- 1 file changed, 32 insertions(+), 29 deletions(-) diff --git a/Ghidra/Features/Base/src/main/java/ghidra/program/flatapi/FlatProgramAPI.java b/Ghidra/Features/Base/src/main/java/ghidra/program/flatapi/FlatProgramAPI.java index 2173e269c3..3fd74f1a4a 100644 --- a/Ghidra/Features/Base/src/main/java/ghidra/program/flatapi/FlatProgramAPI.java +++ b/Ghidra/Features/Base/src/main/java/ghidra/program/flatapi/FlatProgramAPI.java @@ -49,21 +49,22 @@ import ghidra.util.datastruct.ListAccumulator; import ghidra.util.exception.*; import ghidra.util.search.memory.*; import ghidra.util.task.TaskMonitor; -import ghidra.util.task.TaskMonitorAdapter; /** * This class is a flattened version of the Program API. - *
+ *

* NOTE: - * 1) NO METHODS SHOULD EVER BE REMOVED FROM THIS CLASS. - * 2) NO METHOD SIGNATURES SHOULD EVER BE CHANGED IN THIS CLASS. - *
+ *

    + *
  1. NO METHODS SHOULD EVER BE REMOVED FROM THIS CLASS. + *
  2. NO METHOD SIGNATURES SHOULD EVER BE CHANGED IN THIS CLASS. + *
+ *

* This class is used by GhidraScript. - *
+ *

* Changing this class will break user scripts. - *
+ *

* That is bad. Don't do that. - *
+ *

*/ public class FlatProgramAPI { public static final int MAX_REFERENCES_TO = 0x1000; @@ -86,7 +87,7 @@ public class FlatProgramAPI { * @param program the program */ public FlatProgramAPI(Program program) { - this(program, TaskMonitorAdapter.DUMMY_MONITOR); + this(program, TaskMonitor.DUMMY); } /** @@ -1918,8 +1919,7 @@ public class FlatProgramAPI { */ public final float getFloat(Address address) throws MemoryAccessException { int bits = currentProgram.getMemory().getInt(address); - Float fl = new Float(Float.intBitsToFloat(bits)); - return fl.floatValue(); + return Float.intBitsToFloat(bits); } /** @@ -1941,8 +1941,7 @@ public class FlatProgramAPI { */ public final double getDouble(Address address) throws MemoryAccessException { long bits = currentProgram.getMemory().getLong(address); - Double db = new Double(Double.longBitsToDouble(bits)); - return db.doubleValue(); + return Double.longBitsToDouble(bits); } /** @@ -2401,14 +2400,20 @@ public class FlatProgramAPI { } /** - * Saves the changes to the specified program. + * Saves changes to the specified program. + *

* If the program does not already exist in the current project - * then it will be saved into a project folder structures specified in the path. - * If path is NULL or unable to be created, the program will be saved into the root folder. - * If a program already exists with the specified - * name, then a time stamp will be appended to the name to make it unique. + * then it will be saved into a project folder path specified by the path parameter. + *

+ * If path is NULL, the program will be saved into the root folder. If parts of the path are + * missing, they will be created if possible. + *

+ * If a program already exists with the specified name, then a time stamp will be appended + * to the name to make it unique. + *

* @param program the program to save - * @param path the project folder path to save the program into + * @param path list of string path elements (starting at the root of the project) that specify + * the project folder to save the program info. Example: { "folder1", "subfolder2", "finalfolder" } * @throws Exception */ public void saveProgram(Program program, List path) throws Exception { @@ -2431,18 +2436,16 @@ public class FlatProgramAPI { } DomainFolder folder = getProjectRootFolder(); if (path != null) { - for (int i = 0; i < path.size(); ++i) { - if (path.get(i) == null || path.get(i).length() == 0) { + for (String folderName : path) { + if (folderName == null || folderName.isEmpty()) { continue; } - if (i < path.size()) { - DomainFolder existingFolder = folder.getFolder(path.get(i)); - if (existingFolder == null) { - folder = folder.createFolder(path.get(i)); - } - else { - folder = existingFolder; - } + DomainFolder existingFolder = folder.getFolder(folderName); + if (existingFolder == null) { + folder = folder.createFolder(folderName); + } + else { + folder = existingFolder; } } }