mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2025-10-03 09:49:23 +02:00
GP-0 revised PseudoDisassembler.setTargetContextForDisassembly method
for improved reuse
This commit is contained in:
parent
f78ab92fc5
commit
258f8ad44e
6 changed files with 40 additions and 31 deletions
|
@ -15,8 +15,8 @@
|
||||||
*/
|
*/
|
||||||
package ghidra.app.plugin.core.analysis;
|
package ghidra.app.plugin.core.analysis;
|
||||||
|
|
||||||
import ghidra.app.cmd.function.*;
|
|
||||||
import ghidra.app.cmd.disassemble.DisassembleCommand;
|
import ghidra.app.cmd.disassemble.DisassembleCommand;
|
||||||
|
import ghidra.app.cmd.function.*;
|
||||||
import ghidra.app.services.AnalysisPriority;
|
import ghidra.app.services.AnalysisPriority;
|
||||||
import ghidra.app.util.PseudoDisassembler;
|
import ghidra.app.util.PseudoDisassembler;
|
||||||
import ghidra.program.model.address.*;
|
import ghidra.program.model.address.*;
|
||||||
|
@ -387,7 +387,7 @@ public class ConstantPropagationContextEvaluator extends ContextEvaluatorAdapter
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// if nothing defined here, disassemble
|
// if nothing defined here, disassemble
|
||||||
address = PseudoDisassembler.setTargeContextForDisassembly(program, address);
|
address = PseudoDisassembler.setTargetContextForDisassembly(program, address);
|
||||||
DisassembleCommand cmd = new DisassembleCommand(address, null, true);
|
DisassembleCommand cmd = new DisassembleCommand(address, null, true);
|
||||||
cmd.applyTo(program, monitor);
|
cmd.applyTo(program, monitor);
|
||||||
}
|
}
|
||||||
|
|
|
@ -200,7 +200,7 @@ public class AddressTableAnalyzer extends AbstractAnalyzer {
|
||||||
for (Address addr : validCodeList) {
|
for (Address addr : validCodeList) {
|
||||||
// set target context correctly. Target address will get
|
// set target context correctly. Target address will get
|
||||||
// aligned in DisassembleCmd
|
// aligned in DisassembleCmd
|
||||||
PseudoDisassembler.setTargeContextForDisassembly(program, addr);
|
PseudoDisassembler.setTargetContextForDisassembly(program, addr);
|
||||||
|
|
||||||
// even though they are valid code, don't do them if
|
// even though they are valid code, don't do them if
|
||||||
// there is already code there.
|
// there is already code there.
|
||||||
|
|
|
@ -352,7 +352,7 @@ public class EntryPointAnalyzer extends AbstractAnalyzer {
|
||||||
if (value instanceof Address) {
|
if (value instanceof Address) {
|
||||||
Address codeLoc = (Address) value;
|
Address codeLoc = (Address) value;
|
||||||
if (codeLoc.getOffset() != 0) {
|
if (codeLoc.getOffset() != 0) {
|
||||||
PseudoDisassembler.setTargeContextForDisassembly(program, codeLoc);
|
PseudoDisassembler.setTargetContextForDisassembly(program, codeLoc);
|
||||||
// align if necessary
|
// align if necessary
|
||||||
int instructionAlignment = program.getLanguage().getInstructionAlignment();
|
int instructionAlignment = program.getLanguage().getInstructionAlignment();
|
||||||
if (codeLoc.getOffset() % instructionAlignment != 0) {
|
if (codeLoc.getOffset() % instructionAlignment != 0) {
|
||||||
|
|
|
@ -387,7 +387,7 @@ public class DemangledFunction extends DemangledObject {
|
||||||
// the function to the correct address.
|
// the function to the correct address.
|
||||||
|
|
||||||
if (address.isMemoryAddress()) {
|
if (address.isMemoryAddress()) {
|
||||||
address = PseudoDisassembler.setTargeContextForDisassembly(program, address);
|
address = PseudoDisassembler.setTargetContextForDisassembly(program, address);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!passesPreconditions(program, address)) {
|
if (!passesPreconditions(program, address)) {
|
||||||
|
|
|
@ -328,7 +328,8 @@ public class EHDataTypeUtilities {
|
||||||
PseudoDisassembler.getNormalizedDisassemblyAddress(program, functionAddress);
|
PseudoDisassembler.getNormalizedDisassemblyAddress(program, functionAddress);
|
||||||
Instruction inst = listing.getInstructionAt(normalizedFunctionAddress);
|
Instruction inst = listing.getInstructionAt(normalizedFunctionAddress);
|
||||||
if (inst == null) {
|
if (inst == null) {
|
||||||
functionAddress = PseudoDisassembler.setTargeContextForDisassembly(program, functionAddress);
|
functionAddress =
|
||||||
|
PseudoDisassembler.setTargetContextForDisassembly(program, functionAddress);
|
||||||
DisassembleCommand cmd = new DisassembleCommand(functionAddress, null, true);
|
DisassembleCommand cmd = new DisassembleCommand(functionAddress, null, true);
|
||||||
if (!cmd.applyTo(program) || cmd.getDisassembledAddressSet().isEmpty()) {
|
if (!cmd.applyTo(program) || cmd.getDisassembledAddressSet().isEmpty()) {
|
||||||
Msg.error(EHDataTypeUtilities.class, "Failed to disassemble at " + functionAddress);
|
Msg.error(EHDataTypeUtilities.class, "Failed to disassemble at " + functionAddress);
|
||||||
|
|
|
@ -424,9 +424,8 @@ public class PseudoDisassembler {
|
||||||
AddressSet body = new AddressSet();
|
AddressSet body = new AddressSet();
|
||||||
AddressSet instrStarts = new AddressSet();
|
AddressSet instrStarts = new AddressSet();
|
||||||
|
|
||||||
if (hasLowBitCodeModeInAddrValues(program)) {
|
entryPoint = setTargetContextForDisassembly(procContext, entryPoint);
|
||||||
entryPoint = setTargeContextForDisassembly(procContext, entryPoint);
|
|
||||||
}
|
|
||||||
Address target = entryPoint;
|
Address target = entryPoint;
|
||||||
|
|
||||||
ArrayList<Address> targetList = new ArrayList<>(); // list of valid targets
|
ArrayList<Address> targetList = new ArrayList<>(); // list of valid targets
|
||||||
|
@ -662,9 +661,8 @@ public class PseudoDisassembler {
|
||||||
AddressSet instrStarts = new AddressSet();
|
AddressSet instrStarts = new AddressSet();
|
||||||
AddressSetView execSet = memory.getExecuteSet();
|
AddressSetView execSet = memory.getExecuteSet();
|
||||||
|
|
||||||
if (hasLowBitCodeModeInAddrValues(program)) {
|
entryPoint = setTargetContextForDisassembly(procContext, entryPoint);
|
||||||
entryPoint = setTargeContextForDisassembly(procContext, entryPoint);
|
|
||||||
}
|
|
||||||
Address target = entryPoint;
|
Address target = entryPoint;
|
||||||
|
|
||||||
ArrayList<Address> targetList = new ArrayList<>(); // list of valid targets
|
ArrayList<Address> targetList = new ArrayList<>(); // list of valid targets
|
||||||
|
@ -1078,25 +1076,29 @@ public class PseudoDisassembler {
|
||||||
* @param addr the raw address
|
* @param addr the raw address
|
||||||
* @return the correct address to disassemble at if it needs to be aligned
|
* @return the correct address to disassemble at if it needs to be aligned
|
||||||
*/
|
*/
|
||||||
public static Address setTargeContextForDisassembly(Program program, Address addr) {
|
public static Address setTargetContextForDisassembly(Program program, Address addr) {
|
||||||
if (!addr.isMemoryAddress()) {
|
if (!addr.isMemoryAddress()) {
|
||||||
Msg.error(PseudoDisassembler.class,
|
Msg.error(PseudoDisassembler.class,
|
||||||
"Invalid attempt to adjust disassembler context at " + addr.toString(true));
|
"Invalid attempt to adjust disassembler context at " + addr.toString(true));
|
||||||
return addr;
|
return addr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
long offset = addr.getOffset();
|
||||||
|
if ((offset & 1) == 0) {
|
||||||
|
return addr;
|
||||||
|
}
|
||||||
|
|
||||||
Register lowBitCodeMode = program.getRegister(LOW_BIT_CODE_MODE_REGISTER_NAME);
|
Register lowBitCodeMode = program.getRegister(LOW_BIT_CODE_MODE_REGISTER_NAME);
|
||||||
if (lowBitCodeMode == null) {
|
if (lowBitCodeMode == null) {
|
||||||
return addr;
|
return addr;
|
||||||
}
|
}
|
||||||
long offset = addr.getOffset();
|
|
||||||
if ((offset & 1) == 1) {
|
addr = addr.getNewAddress(addr.getOffset() & ~0x1);
|
||||||
addr = addr.getNewAddress(addr.getOffset() & ~0x1);
|
try {
|
||||||
try {
|
program.getProgramContext().setValue(lowBitCodeMode, addr, addr, BigInteger.ONE);
|
||||||
program.getProgramContext().setValue(lowBitCodeMode, addr, addr, BigInteger.ONE);
|
}
|
||||||
}
|
catch (ContextChangeException e) {
|
||||||
catch (ContextChangeException e) {
|
// shouldn't happen
|
||||||
// shouldn't happen
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return addr;
|
return addr;
|
||||||
}
|
}
|
||||||
|
@ -1111,23 +1113,29 @@ public class PseudoDisassembler {
|
||||||
* @return the correct disassembly location if the address needed to be adjusted.
|
* @return the correct disassembly location if the address needed to be adjusted.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public Address setTargeContextForDisassembly(PseudoDisassemblerContext procContext,
|
public static Address setTargetContextForDisassembly(DisassemblerContext procContext,
|
||||||
Address addr) {
|
Address addr) {
|
||||||
if (!addr.isMemoryAddress()) {
|
if (!addr.isMemoryAddress()) {
|
||||||
Msg.error(this,
|
Msg.error(PseudoDisassembler.class,
|
||||||
"Invalid attempt to adjust disassembler context at " + addr.toString(true));
|
"Invalid attempt to adjust disassembler context at " + addr.toString(true));
|
||||||
return addr;
|
return addr;
|
||||||
}
|
}
|
||||||
Register lowBitCodeMode = program.getRegister(LOW_BIT_CODE_MODE_REGISTER_NAME);
|
|
||||||
|
long offset = addr.getOffset();
|
||||||
|
if ((offset & 1) == 0) {
|
||||||
|
return addr;
|
||||||
|
}
|
||||||
|
|
||||||
|
Register lowBitCodeMode = procContext.getRegister(LOW_BIT_CODE_MODE_REGISTER_NAME);
|
||||||
if (lowBitCodeMode == null) {
|
if (lowBitCodeMode == null) {
|
||||||
return addr;
|
return addr;
|
||||||
}
|
}
|
||||||
long offset = addr.getOffset();
|
|
||||||
if ((offset & 1) == 1) {
|
// Set context and revise addr (clear lsb of offset)
|
||||||
addr = addr.getNewAddress(addr.getOffset() & ~0x1);
|
addr = addr.getNewAddress(addr.getOffset() & ~0x1);
|
||||||
procContext.setValue(lowBitCodeMode, addr, BigInteger.ONE);
|
RegisterValue val = new RegisterValue(lowBitCodeMode, BigInteger.ONE);
|
||||||
}
|
procContext.setFutureRegisterValue(addr, val);
|
||||||
return addr.getNewAddress(addr.getOffset() & ~0x1);
|
return addr;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue