From 6dda2c122cd7e3132c2872d61804666dc5ce3f51 Mon Sep 17 00:00:00 2001 From: "BITDEFENDER\\vlutas" Date: Sat, 16 Jul 2022 12:21:46 +0300 Subject: [PATCH] Make sure upper 32 bit of a CMOV destination register is cleared to 0 even if the condition is not satisfied --- bdshemu/bdshemu.c | 9 ++++++++- bdshemu_test/bdshemu_test.zip | Bin 78024 -> 78890 bytes bindings/pybddisasm/setup.py | 2 +- inc/version.h | 2 +- 4 files changed, 10 insertions(+), 3 deletions(-) diff --git a/bdshemu/bdshemu.c b/bdshemu/bdshemu.c index 2f30283..6285c44 100644 --- a/bdshemu/bdshemu.c +++ b/bdshemu/bdshemu.c @@ -1882,11 +1882,18 @@ ShemuEmulate( break; case ND_INS_CMOVcc: + GET_OP(Context, 0, &dst); + GET_OP(Context, 1, &src); if (ShemuEvalCondition(Context, Context->Instruction.Condition)) { - GET_OP(Context, 1, &src); SET_OP(Context, 0, &src); } + else + { + // Write back the same value that was already present in destination. This has the side-effect of + // clearing the upper 32 bit in the 64 bit destination register while in long mode. + SET_OP(Context, 0, &dst); + } break; case ND_INS_SETcc: diff --git a/bdshemu_test/bdshemu_test.zip b/bdshemu_test/bdshemu_test.zip index 4eeeaa0b9953e27ba2568ab5cee4ee0aafd270c1..8beccdf772f4a53d3e3ad43c9733b7294af6f230 100644 GIT binary patch delta 906 zcmX@{kY&{imJNIU*E6$-FfcQ4Fg!{85aPzYZA%RU1H&~S76am>#Ny0k{gTw;l6W(d z_~hLDGQGs&T!)zvY^ADt+Z89QHD6I^{By>?nZ?J~SqeXWKL1I?#xKn$F1cu{g!?YG z*#6-wQ?38}-yIj$_Z;n+X>$Em9S38?^0+xS*B)MQl-qFYv|9%Csz%W#T|VWz|8RYN zqp|AEI_-=Wi!FvdAY3YlLNeA4t@r7Fz2;UZ#ket zg`gPI!3JIni>=b;{qT5QGV$)IXHyC%8tFZ~AI0hZG$2gwZh*HKvT>1npJpU6GBC*T zOg2;zsRw(wD7CmWrzCfw-o+iQ?!Vpzt#s?(`TkMbRqn^j6FVMGx75q~D%0MwK5ie~bgA|qL&HRo|$$B{Qa%89otGxv7N7%`al&rYg3 zJM~4ayrfp}^YT*>W^P4dX(25ypB=uhzu3`qSEC|x{oL^Q8_m7E%&&YKB`eaoOc`YF z>&;=imVVtQ_^r?Nul4NbcG{e(b5@dXuj=Bu_3nXf;+EQzColhWDmIB^doNi$S^Dau zw+U)x|3VaOEsA6{ob7i{i%=FV*>yzW+NEa+E@@2?e}iItI+}HYt~ILsTz^WzJl#*? z%Jj|A5<)LZR@WElnz>$^clmC9@39a4Vo3+za2Z&Y|DPKAUO262XY!=Cf!odZ@%^=r zklDzuqFwqv?pm4Xge_CexZ0h$4zo=N-*IM7`{wAqCqEZI(fX>Hv+UWdvkKbV0+pNZ z{JT+>KSQ)xE