How to change the program path in Ghidra - ghidra

I have a Ghidra project with an imported binary file, which was created on computer A, then I want to move this project to Computer B. However, the path of the binary file isn't the same as A. How do I change the path setting in Ghidra?
Edited:
Error Message (Black blocks are the original path in computer A.)

It seems that Ghidra uses the information from currentProgram.getExecutablePath() which takes the value from the options stored with the binary information inside the project:
Code snippet from ghidra.program.database.ProgramDB#getExecutablePath:
#Override
public String getExecutablePath() {
String path = null;
Options pl = getOptions(PROGRAM_INFO);
path = pl.getString(EXECUTABLE_PATH, UNKNOWN);
return path == null ? UNKNOWN : path;
}
#Override
public void setExecutablePath(String path) {
Options pl = getOptions(PROGRAM_INFO);
pl.setString(EXECUTABLE_PATH, path);
changed = true;
}
To change this you should be able to simply use the corresponding setExecutablePath method, e.g. by running
currentProgram.setExecutablePath("/new/path/to/binary.elf")
inside the Python REPL.

Related

TDirectory::GetFiles listing ignoring case on iOS (FMX, C++)

The code below lists files that have extension .cfg and it works fine on Win32. But, on iOS if i have a file that a user named with caps for the extension (e.g. test.CFG) then i miss it. I found this post using Delphi that might work using TDirectory::TFilterPredicate but i don't know how to implement in C++Builder.
TStringDynArray list;
TSearchOption searchOption;
UnicodeString DocsPath;
int lenDocsFolder;
DocsPath = System::Ioutils::TPath::GetDocumentsPath();
lenDocsFolder = DocsPath.Length();
searchOption = TSearchOption::soTopDirectoryOnly;
try
{
list = TDirectory::GetFiles(DocsPath, "*.cfg", searchOption);
}
catch (...)
{
ShowMessage("Incorrect path or search mask");
return;
}
I suppose i can just run a *.cfg block of code followed by a *.CFG but i'm hoping there is a cleaner approach.
Sorry, but I'm not used to C++. But this applies to both C++ and Delphi.
You are calling:
TDirectory.GetFiles(
const Path, SearchPattern: string;
const SearchOption: TSearchOption): TStringDynArray;
If you instead call this overloaded version:
TDirectory.GetFiles(
const Path, SearchPattern: string;
const SearchOption: TSearchOption;
const Predicate: TFilterPredicate): TStringDynArray;
you should be able to get what you need.
The TFilterPredicate type is defined as:
TFilterPredicate = reference to function(
const Path: string;
const SearchRec: TSearchRec): Boolean;
and should be the correct way to override the way files are matched.
I tried the Using a Lambda Expression from the link Remy posted in comment. I got an E2188 Expression syntaxerror until i disabled the classic Borland compiler. The code works great for simple predicate (on both Win32 and iOS).
String ext(".cfg");
files = TDirectory::GetFiles(CalcPath,
[ext](const String Path, const System::Sysutils::TSearchRec &SearchRec) -> bool
{
return ExtractFileExt(SearchRec.Name) == ext;
});
Now, how do i modify the extension string to return results for both .cfg and .CFG at same time?
String ext(".cfg"); // works fine
String ext(".cfg;.CFG"); // finds nothing

javers: Identify or avoid duplicate diff results

I am comparing two objects containing a list of objects,using JaVers v3.0.0. The objects I am comparing differ in the contents of the list, for example an object is removed from the list.
I am getting two change objects when I perform this comparison: one ListChange and one ObjectRemoved.
When presenting the result, I need to make sure that the same change is not presented twice. I am having a hard time figuring out how to either identify or avoid these duplicates that I am getting. I have tried using GlobalID but I end up parsing strings which does not feel entirely safe. I have also tried skipping ListChange or ObjectRemoved from my presentation, but that presents problems when I also have a ListChange of a list of values, or an ObjectRemoved for an object that is not in a list.
#Test
public void javersDuplicateDiffResult() {
MyMainObj objA = new MyMainObj(Arrays.asList(new MyListedObj("hello"), new MyListedObj("world")));
MyMainObj objB = new MyMainObj(Arrays.asList(new MyListedObj("hello")));
Javers javers = JaversBuilder.javers()
.withListCompareAlgorithm(ListCompareAlgorithm.LEVENSHTEIN_DISTANCE)
.build();
Diff res = javers.compare(objA, objB);
System.out.println(res);
Assert.assertEquals(1, res.getChanges().size());
}
class MyMainObj {
private List<MyListedObj> theObjectList;
public MyMainObj(List<MyListedObj> anObjectList) {
this.theObjectList = anObjectList;
}
}
class MyListedObj {
private String theText;
public MyListedObj(String aText) {
this.theText = aText;
}
}
Here is the output from running the example code above:
Diff:
1. ObjectRemoved{globalId:'org.example.TestJavers$MyMainObj/#theObjectList/1'}
2. ListChange{globalId:'org.example.TestJavers$MyMainObj/', property:'theObjectList', containerChanges:[(1).removed:'org.example.TestJavers$MyListedObj#2aece37d']}
java.lang.AssertionError:
Expected :1
Actual :2
In JaVers, ObjectRemoved informs you that an object disappeared from an object graph on the left. While ListChange->ValueRemoved is the PropertyChange and informs about concrete place in the object graph where the change occurred.
These two changes concerns the same object (removed one) but are not duplicates.
For example:
Class A {
List<B> listOfB
B bRef
}
If you compare:
def b1 = new B()
javers.compare( new A(listOfB:[b1], bRef:b1), new A(listOfB:[], bRef:null) )
You will have three changes:
b1 ObjectRemoved (general information)
b1 ListChange->ValueRemoved on listOfB property (specific place in the object graph)
ValueChanged from b1 to null on bRef property (another specific place in the object graph)
What I can suggest you is simply ignoring ObjectRemoved changes and relying only on PropertyChanges (ListChange, ValueChange ...)
As far as I know, there is no way to achieve this in Javers. I solved a similar problem by filtering out the duplicate differences based on path of the change. Here is how
Identify the path of the change (List Change or Value Change)
You will have to write code to generate the path
If the path is subpath path of Object Removed or Value Removed then ignore it
In your case,
Diff1: ObjectRemoved path: theObjectList/1
Diff2: ValueRemoved path: theObjectList/1/MyListedObj#2aece37d
You can discard Diff2 because the path is a subpath of a removed object.
the ValueRemoved path is built by concatenating ListChange path with the Value Change path

C++(Visual Studio 2012): Copying a function's parameter char* to a dynamically allocated one

I have this structure defined and a class in my project. It is a class that holds id numbers generated by GetIdUsingThisString(char *), which is a function that loads a texture file into GPU and returns an id(OpenGL).
The problem is, when I try to read a specific file, the program crashes. When I run this program in VS with debugging it works fine, but running .exe crashes the program(or running without debugging from MSVS). By using just-n-time debugger I have found out that, for num of that specific file, Master[num].name actually contains "\x5" added(concatenation) at the end of the file path, and this is only generated for this one file. Nothing out of this method could do it, and I also use this type of slash / in paths, not \ .
struct WIndex{
char* name;
int id;
};
class Test_Class
{
public:
Test_Class(void);
int AddTex(char* path);
struct WIndex* Master;
TextureClass* tex;
//some other stuff...
};
Constructor:
Test_Class::Test_Class(void)
{
num=0;
Master=(WIndex*)malloc(1*sizeof(WIndex));
Master[0].name=(char*)malloc(strlen("Default")*sizeof(char));
strcpy(Master[0].name,"Default");
Master[0].id=GetIdUsingThisString(Master[0].name);
}
Adding a new texture:(The bug)
int Test_Class::AddTex(char* path)
{
num++;
Master=(WIndex*)realloc(Master,(num+1)*sizeof(WIndex));
Master[num].name=(char*)malloc(strlen(path)*sizeof(char));
strcpy(Master[num].name,path);<---HERE
Master[num].id=GetIdUsingThisString(path);
return Master[num].id;
}
At runtime, calling AddTex with this file would have path with the right value, while Master[num].name will show this modified value after strcpy(added "\x5").
Question:
Is there something wrong with copying(strcpy) to a dynamically allocated string? If i use char name[255] as a part of the WIndex structure, everything works fine.
More info:
This exact file is called "flat blanc.tga". If I put it in a folder where I intended it to be, fread in GetIdUsingThisString throws corrupted heap errors. If I put it in a different folder it is ok. If I change it's name to anything else, it's ok again. If I put a different file and give it that same name, it is ok too(!!!). I need the program to be bug free of this kind of things because I won't know which textures will be loaded(if I knew I could simply replace them).
Master[num].name=(char*)malloc(strlen(path)*sizeof(char));
Should be
Master[num].name=(char*)malloc( (strlen(path)+1) * sizeof(char));
There was not place for the terminating NULL character
From http://www.cplusplus.com/reference/cstring/strcpy/:
Copies the C string pointed by source into the array pointed by
destination, including the terminating null character (and
stopping at that point).
The same happens here:
Master[0].name=(char*)malloc(strlen("Default")*sizeof(char));
strcpy(Master[0].name,"Default");
Based on the definitions (below) - you should use strlen(string)+1 for malloc.
A C string is as long as the number of characters between the beginning of the string and the terminating null character (without including the terminating null character itself).
The strcpy() function shall copy the string pointed to by s2 (including the terminating null byte)
Also see discussions in How to allocate the array before calling strcpy?

Which files are ignored as input by mapper?

I'm chaining multiple MapReduce jobs and want to pass along/store some meta information (e.g. configuration or name of original input) with the results. At least the file "_SUCCESS" and also anything in the directory "_logs" seams to be ignored.
Are there any filename patterns which are by default ignored by the InputReader? Or is this just a fixed limited list?
The FileInputFormat uses the following hiddenFileFilter by default:
private static final PathFilter hiddenFileFilter = new PathFilter(){
public boolean accept(Path p){
String name = p.getName();
return !name.startsWith("_") && !name.startsWith(".");
}
};
So if you uses any FileInputFormat (such as TextInputFormat, KeyValueTextInputFormat, SequenceFileInputFormat), the hidden files (the file name starts with "_" or ".") will be ignored.
You can use FileInputFormat.setInputPathFilter to set your custom PathFilter. Remember that the hiddenFileFilter is always active.

Get enclosing IJavaElement

I am working with the selections within the Eclipse source code editor. I defined a key-binding that gets me the "text" at the current caret position. I managed to parse the current caret position to an IJavaElement
private void processEditorSelection(IEditorPart part, ITextSelection selection) {
IEditorInput editorInput = ((IEditorPart) part).getEditorInput();
final ITypeRoot root = (ITypeRoot) JavaUI.getEditorInputJavaElement(editorInput);
if (root != null) {
int offset = (selection).getOffset();
IJavaElement[] codeSelect = root.codeSelect(offset, 0);
if (codeSelect.length > 0) {
//codeSelect[0...n] are my resolved elements at the current caret pos.
}
What I did not managed to figure out yet is, how to resolve the enclosing type. for instance:
public void do() {
System.out.println("it");
}
If the caret is on the System.out, I obtain an JavaElement of the system out call, but I am actually interested in the enclosing method. Does anyone know how to ask Eclipse for the enclosing type? Like what is the compilation unit or method my current carret position is enclosed in?
Thanks for an answer
You are looking to do something like this:
ITypeRoot root = (ITypeRoot) JavaUI.getEditorInputJavaElement(editorInput);
IJavaElement elt = root.getElementAt(caretPosition);
This will find the enclosing element, which may be an IField, IMethod, or ICompilationUnit. To get the enclosing type, call this:
IType type = (IType) elt.getAncestor(IJavaElement.TYPE);
This method returns null if there is no enclosing type.

Resources