Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/patch'
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanmkurtz committed Jun 7, 2022
2 parents 04da5d1 + d2b3236 commit 805bba9
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,7 @@ public void optionsChanged(Options options, Program program) {

@Override
public boolean added(Program program, AddressSetView addressSet, TaskMonitor monitor,
MessageLog log)
throws CancelledException {
MessageLog log) throws CancelledException {

monitor.initialize(addressSet.getNumAddresses());

Expand Down Expand Up @@ -143,8 +142,7 @@ public boolean added(Program program, AddressSetView addressSet, TaskMonitor mon
* @param monitor - monitor
* @param doLaterSet - set of functions that were put off until later
*/
private void processDoLaterSet(Program program, TaskMonitor monitor,
Set<Address> doLaterSet) {
private void processDoLaterSet(Program program, TaskMonitor monitor, Set<Address> doLaterSet) {
// nothing to do
if (doLaterSet.isEmpty()) {
return;
Expand Down Expand Up @@ -232,10 +230,8 @@ private void fixDummyFunctionBodies(Program program, TaskMonitor monitor,
// find all functions that jumped to this one, and re-create them
while (referencesTo.hasNext()) {
Reference reference = referencesTo.next();
Function func =
program.getFunctionManager()
.getFunctionContaining(
reference.getFromAddress());
Function func = program.getFunctionManager()
.getFunctionContaining(reference.getFromAddress());
if (func != null) {
recreateFunctionSet.add(func.getEntryPoint());
}
Expand All @@ -262,8 +258,8 @@ private void fixDummyFunctionBodies(Program program, TaskMonitor monitor,
}
}

private void checkDoLaterSet(Program program, TaskMonitor monitor,
Set<Address> doLaterSet) throws CancelledException {
private void checkDoLaterSet(Program program, TaskMonitor monitor, Set<Address> doLaterSet)
throws CancelledException {
PseudoDisassembler pdis = new PseudoDisassembler(program);
pdis.setRespectExecuteFlag(respectExecuteFlags);
Listing listing = program.getListing();
Expand Down Expand Up @@ -300,6 +296,8 @@ private void moveSuspectSymbolsToDoLaterSet(Program program, TaskMonitor monitor
Listing listing = program.getListing();
SymbolTable symbolTable = program.getSymbolTable();

Set<Address> indirectSet = new HashSet();

Iterator<Address> iter = doNowSet.iterator();
while (iter.hasNext()) {
Address entry = iter.next();
Expand Down Expand Up @@ -327,7 +325,10 @@ else if (isLanguageDefinedEntry(program, entry)) {
// check for an address
if (isLanguageDefinedEntryPointer(program, entry)) {
// put down an address if it is
layDownCodePointer(program, doLaterSet, entry);
Address newLoc = layDownCodePointer(program, entry);
if (newLoc != null) {
indirectSet.add(newLoc);
}
iter.remove();
}
}
Expand All @@ -336,31 +337,34 @@ else if (!isLanguageDefinedEntry(program, entry) && !pdis.isValidSubroutine(entr
iter.remove();
}
}

// add any language defined pointers back into the do now set
doNowSet.addAll(indirectSet);
}

private void layDownCodePointer(Program program, Set<Address> doLaterSet, Address entry) {
private Address layDownCodePointer(Program program, Address entry) {
int defaultPointerSize = program.getDefaultPointerSize();
try {
Data data =
program.getListing()
.createData(entry,
PointerDataType.getPointer(null, defaultPointerSize));
Data data = program.getListing()
.createData(entry, PointerDataType.getPointer(null, defaultPointerSize));
Object value = data.getValue();
if (value instanceof Address) {
Address codeLoc = (Address) value;
// align if necessary
int instructionAlignment = program.getLanguage().getInstructionAlignment();
if (codeLoc.getOffset() % instructionAlignment != 0) {
codeLoc = codeLoc.subtract(codeLoc.getOffset() % instructionAlignment);
}
if (codeLoc.getOffset() != 0) {
doLaterSet.add(codeLoc);
PseudoDisassembler.setTargeContextForDisassembly(program, codeLoc);
// align if necessary
int instructionAlignment = program.getLanguage().getInstructionAlignment();
if (codeLoc.getOffset() % instructionAlignment != 0) {
codeLoc = codeLoc.subtract(codeLoc.getOffset() % instructionAlignment);
}
return codeLoc;
}
}
}
catch (CodeUnitInsertionException e) {
// couldn't create
}
return null;
}

private int addExternalSymbolsToSet(Program program, AddressSetView addressSet,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3101,7 +3101,8 @@ private void processSectionHeaders(TaskMonitor monitor) throws CancelledExceptio
if (type != ElfSectionHeaderConstants.SHT_NULL &&
(includeOtherBlocks || elfSectionToLoad.isAlloc())) {
long fileOffset = elfSectionToLoad.getOffset();
if (fileOffset < 0 || fileOffset >= fileBytes.getSize()) {
if (type != ElfSectionHeaderConstants.SHT_NOBITS &&
(fileOffset < 0 || fileOffset >= fileBytes.getSize())) {
log("Skipping section [" + elfSectionToLoad.getNameAsString() +
"] with invalid file offset");
continue;
Expand Down

0 comments on commit 805bba9

Please sign in to comment.