mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2025-10-04 10:19:23 +02:00
GP-3883 added source file manager
This commit is contained in:
parent
420dd7ce0c
commit
9aeeaa4397
52 changed files with 8432 additions and 306 deletions
|
@ -0,0 +1,63 @@
|
|||
/* ###
|
||||
* IP: GHIDRA
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
// Select and remove a source map entry at the current address.
|
||||
//@category SourceMapping
|
||||
import java.util.*;
|
||||
|
||||
import ghidra.app.script.GhidraScript;
|
||||
import ghidra.features.base.values.GhidraValuesMap;
|
||||
import ghidra.program.model.sourcemap.SourceMapEntry;
|
||||
|
||||
public class RemoveSourceMapEntryScript extends GhidraScript {
|
||||
|
||||
@Override
|
||||
protected void run() throws Exception {
|
||||
if (isRunningHeadless()) {
|
||||
println("This script must be run through the Ghidra GUI");
|
||||
return;
|
||||
}
|
||||
if (currentProgram == null) {
|
||||
popup("This script requires an open program");
|
||||
return;
|
||||
}
|
||||
if (!currentProgram.hasExclusiveAccess()) {
|
||||
popup("Modifying the source map requires exclusive access to the program");
|
||||
return;
|
||||
}
|
||||
List<SourceMapEntry> entries =
|
||||
currentProgram.getSourceFileManager().getSourceMapEntries(currentAddress);
|
||||
if (entries.isEmpty()) {
|
||||
popup("No source map entries at " + currentAddress);
|
||||
return;
|
||||
}
|
||||
|
||||
Map<String, SourceMapEntry> stringToEntry = new HashMap<>();
|
||||
List<String> choices = new ArrayList<>();
|
||||
for (SourceMapEntry entry : entries) {
|
||||
String entryString = entry.toString();
|
||||
stringToEntry.put(entryString, entry);
|
||||
choices.add(entryString);
|
||||
}
|
||||
GhidraValuesMap values = new GhidraValuesMap();
|
||||
String[] choiceArray = choices.toArray(new String[] {});
|
||||
values.defineChoice("Entry", choiceArray[0], choiceArray);
|
||||
askValues("Select SourceMapEntry to remove", null, values);
|
||||
String selectedString = values.getChoice("Entry");
|
||||
SourceMapEntry toDelete = stringToEntry.get(selectedString);
|
||||
currentProgram.getSourceFileManager().removeSourceMapEntry(toDelete);
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue