GP-3054: Preventing relative file paths from ending up in an FSRL

This commit is contained in:
Ryan Kurtz 2023-03-09 11:09:01 -05:00
parent 6275b13b5c
commit c5584599c0
3 changed files with 18 additions and 17 deletions

View file

@ -212,10 +212,10 @@ public class AnalyzeHeadless implements GhidraLaunchable {
options.setPropertiesFileDirectories(args[++argi]);
}
else if (checkArgument("-import", args, argi)) {
File inputFile = new File(args[++argi]);
File inputFile = new File(args[++argi]).getAbsoluteFile();
if (!inputFile.isDirectory() && !inputFile.isFile()) {
throw new InvalidInputException(
inputFile.getAbsolutePath() + " is not a valid directory or file.");
inputFile + " is not a valid directory or file.");
}
HeadlessAnalyzer.checkValidFilename(inputFile);
@ -234,10 +234,10 @@ public class AnalyzeHeadless implements GhidraLaunchable {
break;
}
File otherFile = new File(nextArg);
File otherFile = new File(nextArg).getAbsoluteFile();
if (!otherFile.isFile() && !otherFile.isDirectory()) {
throw new InvalidInputException(
otherFile.getAbsolutePath() + " is not a valid directory or file.");
otherFile + " is not a valid directory or file.");
}
HeadlessAnalyzer.checkValidFilename(otherFile);

View file

@ -115,13 +115,17 @@ public class LocalFileSystem implements GFileSystem, GFileHashProvider {
/**
* Converts a {@link File} into a {@link FSRL}.
* <p>
* NOTE: The given {@link File}'s absolute path will be used.
*
* @param f {@link File}
* @return {@link FSRL}
* @param f The {@link File} to convert to an {@link FSRL}
* @return The {@link FSRL}
*/
public FSRL getLocalFSRL(File f) {
return fsFSRL
.withPath(FSUtilities.appendPath("/", FilenameUtils.separatorsToUnix(f.getPath())));
// We prepend a "/" to ensure that Windows-style paths (i.e. C:\) start with a "/". For
// unix-style paths, this redundant "/" will be dropped.
return fsFSRL.withPath(
FSUtilities.appendPath("/", FilenameUtils.separatorsToUnix(f.getAbsolutePath())));
}
@Override

View file

@ -43,7 +43,6 @@ import ghidra.program.model.symbol.*;
import ghidra.program.model.util.CodeUnitInsertionException;
import ghidra.program.util.AddressEvaluator;
import ghidra.program.util.string.*;
import ghidra.util.Conv;
import ghidra.util.ascii.AsciiCharSetRecognizer;
import ghidra.util.datastruct.Accumulator;
import ghidra.util.datastruct.ListAccumulator;
@ -154,16 +153,14 @@ public class FlatProgramAPI {
}
/**
* Returns the path to the program's executable file.
* Returns the {@link File} that the program was originally imported from. It does not
* necessarily still exist on the file system.
* <p>
* For example, <code>c:\temp\test.exe</code>.
* @return path to program's executable file
* @return the {@link File} that the program was originally imported from
*/
public final File getProgramFile() {
File f = new File(currentProgram.getExecutablePath());
if (f.exists()) {
return f;
}
return null;
return new File(currentProgram.getExecutablePath());
}
/**
@ -1915,7 +1912,7 @@ public class FlatProgramAPI {
* @return a new address with the specified offset in the default address space
*/
public final Address toAddr(int offset) {
return toAddr(offset & Conv.INT_MASK);
return toAddr(Integer.toUnsignedLong(offset));
}
/**