Open mfaerevaag opened 7 years ago
Yep, in bap.1.3 it is even more visible:
$ bap-mc "c000ff" --show-bil --arch=X86 --show-insn=asm --x86-lifter=legacy
rolb $0xff, (%eax)
{
orig_count1 := 0x1F
mem := mem
with [EAX] <- mem[EAX] << orig_count1 | mem[EAX] >> 8 - orig_count1
if (orig_count1 = 0) {
CF := CF
}
else {
CF := low:1[mem[EAX]]
}
if (orig_count1 = 0) {
OF := OF
}
else {
if (orig_count1 = 1) {
OF := CF ^ high:1[mem[EAX]]
}
else {
OF := unknown[OF undefined after rotate of more then 1 bit]:u1
}
}
}
Description
When executing instructions
rol
andror
, the count is sometimes calculated without taking the correct mod size, where size is the operand size.According to manual, the correct semantics for calculating count:
tempCOUNT ← (COUNT & COUNTMASK) MOD SIZE
Reference: Ref. Intel 64 and IA-32 Architecture Software Developer's Manual Vol. 2B 4-519
Affected instructions:
NOTE: All combinations of prefixes and operands are omitted.
Reproduction guide
Instruction:
Input:
Observed output:
Expected output:
orig_count1
is calculated with taking mod of operator size (8).Rappel
A more specific example done in Rappel using the same instruction as above, with
[EAX]
set to0xfd
.According to manual, the correct calculation of
tempCount
should be((0xff & 0x1f) % 8)
, which equals7
.In the BIL output showed above, count is calculated to
0xff & 0x1f
, which is incorrect.System Info
OS:
BAP: