You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
When using the p-code emulator to run the instruction RCR RCX, 0x2, where RCX = 2, the CF flag is not set as expected. The same happens when overflow occurs on the left side when using RCL.
ROR and ROL set the flag as expected, and rotating using RCR and RCL by 1 works correctly since this is a special case in the SLEIGH.
To Reproduce
Run the below RotateTest.java script.
See that CF is still zero, even though it should contain the 1 that overflowed off the right.
Expected behavior CF should be set correctly.
Environment (please complete the following information):
OS: Pop_OS 22.04
Java Version: 18.0.2-ea
Ghidra Version: 11.0.3
Ghidra Origin: Official GitHub distro
Additional context
RotateTest.java
importghidra.app.plugin.assembler.*;
importghidra.app.plugin.processors.sleigh.SleighLanguage;
importghidra.app.script.GhidraScript;
importghidra.pcode.emu.PcodeEmulator;
importghidra.pcode.emu.PcodeThread;
importghidra.pcode.exec.*;
importghidra.pcode.exec.PcodeExecutorStatePiece.Reason;
importghidra.pcode.utils.Utils;
importghidra.program.model.address.Address;
importghidra.program.model.address.AddressSpace;
importghidra.program.model.lang.LanguageID;
importghidra.util.NumericUtilities;
publicclassRotateTestextendsGhidraScript {
privateSleighLanguagelanguage;
privatePcodeEmulatoremulator;
@Overrideprotectedvoidrun() throwsException {
/* * Create an emulator and start a thread */language = (SleighLanguage) getLanguage(newLanguageID("x86:LE:64:default"));
emulator = newPcodeEmulator(language);
PcodeThread<byte[]> thread = emulator.newThread();
// The emulator composes the full library for each threadPcodeUseropLibrary<byte[]> library = thread.getUseropLibrary();
AddressSpacedyn = language.getDefaultSpace();
/* * Assemble a little test program and write it into the emulator */Addressentry = dyn.getAddress(0x00400000);
Assemblerasm = Assemblers.getAssembler(language);
AssemblyBufferbuffer = newAssemblyBuffer(asm, entry);
buffer.assemble("RCR RCX, 0x2");
byte[] code = buffer.getBytes();
println(NumericUtilities.convertBytesToString(code));
emulator.getSharedState().setVar(dyn, entry.getOffset(), code.length, true, code);
/* * Initialize other parts of the emulator and thread state. */PcodePrograminit = SleighProgramCompiler.compileProgram(language, "init", String.format(""" RCX = 0x2; RIP = 0x%s; RSP = 0x00001000; """, entry), library);
thread.getExecutor().execute(init, library);
thread.overrideContextWithDefault();
thread.reInitialize();
thread.stepInstruction(1);
/* * Inspect the machine. You can always do this by accessing the state directly, but for * anything other than simple variables, you may find compiling an expression more * convenient. */println("CF = " +
Utils.bytesToLong(thread.getState().getVar(language.getRegister("CF"), Reason.INSPECT),
1, language.isBigEndian()));
println("RCX = " + Utils.bytesToLong(
SleighProgramCompiler.compileExpression(language, "RCX").evaluate(thread.getExecutor()),
8, language.isBigEndian()));
}
}
The text was updated successfully, but these errors were encountered:
Describe the bug
When using the p-code emulator to run the instruction
RCR RCX, 0x2
, whereRCX = 2
, theCF
flag is not set as expected. The same happens when overflow occurs on the left side when usingRCL
.ROR
andROL
set the flag as expected, and rotating usingRCR
andRCL
by 1 works correctly since this is a special case in the SLEIGH.To Reproduce
RotateTest.java
script.CF
is still zero, even though it should contain the 1 that overflowed off the right.Expected behavior
CF
should be set correctly.Environment (please complete the following information):
Additional context
RotateTest.java
The text was updated successfully, but these errors were encountered: