@@ -2442,35 +2442,6 @@ void lift_rcr(IRBuilder<>& builder, ZydisDisassembledInstruction& instruction) {
2442
2442
printvalue (splitResult) printvalue (of) printvalue (cf)
2443
2443
}
2444
2444
2445
- void lift_idiv2 (IRBuilder<>& builder,
2446
- ZydisDisassembledInstruction& instruction) {
2447
- LLVMContext& context = builder.getContext ();
2448
- auto src = instruction.operands [0 ];
2449
- auto dividend = GetRegisterValue (builder, ZYDIS_REGISTER_AX);
2450
-
2451
- Value* divisor = GetOperandValue (builder, src, src.size );
2452
- divisor =
2453
- builder.CreateSExt (divisor, Type::getIntNTy (context, src.size * 2 ));
2454
- dividend = builder.CreateSExtOrTrunc (dividend, divisor->getType ());
2455
- Value* remainder = builder.CreateSRem (dividend, divisor);
2456
- Value* quotient = builder.CreateSDiv (dividend, divisor);
2457
-
2458
- SetRegisterValue (
2459
- builder, ZYDIS_REGISTER_AL,
2460
- createZExtOrTruncFolder (builder, quotient,
2461
- Type::getIntNTy (context, src.size )));
2462
-
2463
- SetRegisterValue (
2464
- builder, ZYDIS_REGISTER_AH,
2465
- createZExtOrTruncFolder (builder, remainder,
2466
- Type::getIntNTy (context, src.size )));
2467
-
2468
- printvalue (remainder);
2469
- printvalue (quotient);
2470
- printvalue (divisor);
2471
- printvalue (dividend);
2472
- }
2473
-
2474
2445
void lift_div (IRBuilder<>& builder,
2475
2446
ZydisDisassembledInstruction& instruction) {
2476
2447
@@ -2563,7 +2534,29 @@ void lift_rcr(IRBuilder<>& builder, ZydisDisassembledInstruction& instruction) {
2563
2534
LLVMContext& context = builder.getContext ();
2564
2535
auto src = instruction.operands [0 ];
2565
2536
if (src.size == 8 ) {
2566
- lift_idiv2 (builder, instruction);
2537
+ auto dividend = GetRegisterValue (builder, ZYDIS_REGISTER_AX);
2538
+
2539
+ Value* divisor = GetOperandValue (builder, src, src.size );
2540
+ divisor =
2541
+ builder.CreateSExt (divisor, Type::getIntNTy (context, src.size * 2 ));
2542
+ dividend = builder.CreateSExtOrTrunc (dividend, divisor->getType ());
2543
+ Value* remainder = builder.CreateSRem (dividend, divisor);
2544
+ Value* quotient = builder.CreateSDiv (dividend, divisor);
2545
+
2546
+ SetRegisterValue (
2547
+ builder, ZYDIS_REGISTER_AL,
2548
+ createZExtOrTruncFolder (builder, quotient,
2549
+ Type::getIntNTy (context, src.size )));
2550
+
2551
+ SetRegisterValue (
2552
+ builder, ZYDIS_REGISTER_AH,
2553
+ createZExtOrTruncFolder (builder, remainder,
2554
+ Type::getIntNTy (context, src.size )));
2555
+
2556
+ printvalue (remainder);
2557
+ printvalue (quotient);
2558
+ printvalue (divisor);
2559
+ printvalue (dividend);
2567
2560
return ;
2568
2561
}
2569
2562
auto dividendLowop = instruction.operands [1 ]; // eax
@@ -2872,7 +2865,7 @@ void lift_rcr(IRBuilder<>& builder, ZydisDisassembledInstruction& instruction) {
2872
2865
SetOperandValue (builder, dest, result);
2873
2866
}
2874
2867
2875
- void lift_inc_dec (IRBuilder<>& builder,
2868
+ void lift_inc (IRBuilder<>& builder,
2876
2869
ZydisDisassembledInstruction& instruction) {
2877
2870
auto operand = instruction.operands [0 ];
2878
2871
@@ -2883,30 +2876,55 @@ void lift_rcr(IRBuilder<>& builder, ZydisDisassembledInstruction& instruction) {
2883
2876
Value* of;
2884
2877
// The CF flag is not affected. The OF, SF, ZF, AF, and PF flags are set
2885
2878
// according to the result.
2886
- if (instruction.info .mnemonic == ZYDIS_MNEMONIC_INC) {
2887
- // treat it as add r, 1 for flags
2888
- result = createAddFolder (builder, Lvalue, one,
2889
- " inc-" + to_string (instruction.runtime_address ) +
2890
- " -" );
2891
- of = computeOverflowFlagAdd (builder, Lvalue, one, result);
2879
+ // treat it as add r, 1 for flags
2880
+ result = createAddFolder (builder, Lvalue, one,
2881
+ " inc-" + to_string (instruction.runtime_address ) +
2882
+ " -" );
2883
+ of = computeOverflowFlagAdd (builder, Lvalue, one, result);
2892
2884
2893
- } else {
2894
- // treat it as sub r, 1 for flags
2895
- result = createSubFolder (builder, Lvalue, one,
2896
- " dec-" + to_string (instruction.runtime_address ) +
2897
- " -" );
2898
- of = computeOverflowFlagSub (builder, Lvalue, one, result);
2899
- }
2900
2885
2901
- printvalue (Lvalue) printvalue (result)
2886
+ printvalue (Lvalue) printvalue (result);
2887
+
2888
+ Value* sf = computeSignFlag (builder, result);
2889
+ Value* zf = computeZeroFlag (builder, result);
2890
+ Value* pf = computeParityFlag (builder, result);
2891
+
2892
+ printvalue (sf);
2893
+
2894
+ setFlag (builder, FLAG_OF, of);
2895
+ setFlag (builder, FLAG_SF, sf);
2896
+ setFlag (builder, FLAG_ZF, zf);
2897
+ setFlag (builder, FLAG_PF, pf);
2898
+ SetOperandValue (builder, operand, result);
2899
+ }
2900
+
2901
+
2902
+ void lift_dec (IRBuilder<>& builder,
2903
+ ZydisDisassembledInstruction& instruction) {
2904
+ auto operand = instruction.operands [0 ];
2905
+
2906
+ Value* Lvalue = GetOperandValue (builder, operand, operand.size );
2907
+
2908
+ Value* one = ConstantInt::get (Lvalue->getType (), 1 , true );
2909
+ Value* result;
2910
+ Value* of;
2911
+ // The CF flag is not affected. The OF, SF, ZF, AF, and PF flags are set
2912
+ // according to the result.
2913
+ // treat it as sub r, 1 for flags
2914
+ result = createSubFolder (builder, Lvalue, one,
2915
+ " dec-" + to_string (instruction.runtime_address ) +
2916
+ " -" );
2917
+ of = computeOverflowFlagSub (builder, Lvalue, one, result);
2918
+
2919
+ printvalue (Lvalue) printvalue (result);
2902
2920
2903
- Value* sf = computeSignFlag (builder, result);
2921
+ Value* sf = computeSignFlag (builder, result);
2904
2922
Value* zf = computeZeroFlag (builder, result);
2905
2923
Value* pf = computeParityFlag (builder, result);
2906
2924
2907
- printvalue (sf)
2925
+ printvalue (sf);
2908
2926
2909
- setFlag (builder, FLAG_OF, of);
2927
+ setFlag (builder, FLAG_OF, of);
2910
2928
setFlag (builder, FLAG_SF, sf);
2911
2929
setFlag (builder, FLAG_ZF, zf);
2912
2930
setFlag (builder, FLAG_PF, pf);
@@ -4259,9 +4277,13 @@ void liftInstructionSemantics(IRBuilder<>& builder,
4259
4277
arithmeticsAndLogical::lift_lea (builder, instruction);
4260
4278
break ;
4261
4279
}
4262
- case ZYDIS_MNEMONIC_INC:
4280
+ case ZYDIS_MNEMONIC_INC: {
4281
+ arithmeticsAndLogical::lift_inc (builder, instruction);
4282
+ break ;
4283
+ }
4284
+
4263
4285
case ZYDIS_MNEMONIC_DEC: {
4264
- arithmeticsAndLogical::lift_inc_dec (builder, instruction);
4286
+ arithmeticsAndLogical::lift_dec (builder, instruction);
4265
4287
break ;
4266
4288
}
4267
4289
0 commit comments