New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
PPC Big-endian VLE instruction emulation error #4392
Comments
I found a similar issue #3428 I tried to set VLE register to 1 for the region, but it doesn't help. The same error from ghidra.app.emulator import EmulatorHelper
from ghidra.app.emulator import EmulatorHelper
from ghidra.program.model.symbol import SymbolUtilities
from ghidra.program.model.lang import RegisterValue
from java.math import BigInteger
def getAddress(offset):
return currentProgram.getAddressFactory().getDefaultAddressSpace().getAddress(offset)
def getSymbolAddress(symbolName):
symbol = SymbolUtilities.getLabelOrFunctionSymbol(currentProgram, symbolName, None)
if (symbol != None):
return symbol.getAddress()
else:
raise("Failed to locate label: {}".format(symbolName))
vleReg = currentProgram.language.getRegister("vle")
value = RegisterValue(vleReg, BigInteger.ONE)
loadedMemory = currentProgram.getMemory().getLoadedAndInitializedAddressSet()
#print("addr",loadedMemory.getMinAddress(),loadedMemory.getMaxAddress())
currentProgram.getProgramContext().setRegisterValue(getAddress(0x0), getAddress(0x50), value)
emuHelper = EmulatorHelper(currentProgram)
codeStart=0x0
codeStop=0x6
emuHelper.writeRegister(emuHelper.getPCRegister(), codeStart)
while monitor.isCancelled() is False:
executionAddress = emuHelper.getExecutionAddress()
if (executionAddress == getAddress(codeStop)):
print("Emulation complete.")
break
print("Address: 0x{} ({})".format(executionAddress, getInstructionAt(executionAddress)))
success = emuHelper.step(monitor)
if (success == False):
lastError = emuHelper.getLastError()
print("Emulation Error: '{}'".format(lastError))
break
emuHelper.dispose() The error emu-error.py> Running...
Address: 0x00000000 (se_mflr r0)
Address: 0x00000002 (se_bl 0x00000010)
Address: 0x00000010 (se_mflr r0)
Emulation Error: 'Instruction decode failed (Unable to resolve constructor at 00000010), PC=00000010'
emu-error.py> Finished! |
I'm still looking into this, but I can get the python script to run without error by adding a call to from ghidra.app.emulator import EmulatorHelper
from ghidra.program.model.symbol import SymbolUtilities
from ghidra.program.model.symbol import SymbolUtilities
from ghidra.program.model.lang import RegisterValue
from java.math import BigInteger
def getAddress(offset):
return currentProgram.getAddressFactory().getDefaultAddressSpace().getAddress(offset)
def getSymbolAddress(symbolName):
symbol = SymbolUtilities.getLabelOrFunctionSymbol(currentProgram, symbolName, None)
if (symbol != None):
return symbol.getAddress()
else:
raise("Failed to locate label: {}".format(symbolName))
emuHelper = EmulatorHelper(currentProgram)
codeStart=0x0
codeStop=0x6
emuHelper.writeRegister(emuHelper.getPCRegister(), codeStart)
while monitor.isCancelled() is False:
executionAddress = emuHelper.getExecutionAddress()
if (executionAddress == getAddress(codeStop)):
print("Emulation complete.")
break
try:
vleReg = currentProgram.language.getRegister("vle")
emuHelper.setContextRegister(vleReg,BigInteger.ONE)
print("Address: 0x{} ({})".format(executionAddress, getInstructionAt(executionAddress)))
except:
raise
success = emuHelper.step(monitor)
if (success == False):
lastError = emuHelper.getLastError()
print("Emulation Error: '{}'".format(lastError))
break
# Cleanup resources and release hold on currentProgram
emuHelper.dispose() Alternatively, replacing the |
The issue here is that the emulator is not properly setting the seedContext in the disassembler. To correct it, we need to modify Emulate.java with this:
Emulator.java with this:
and modify your script to either rely on the context in the program listing:
or you can just manually set the
Either way, I'll get the changes to the emulator incorporated so these steps work out of the box. |
Describe the bug
Error during emulation of code PPC Big-endian VLE, Ghidra can't emulate the instruction after branch "se_mflr r0"
To Reproduce
- In CodeBrowser press F12 on address 0x0 (Disassemble PPC VLE)
Environment (please complete the following information):
Additional context
The text was updated successfully, but these errors were encountered: