MCPcopy Create free account
hub / github.com/connorjaydunn/BinaryShield / x86ArithmeticHandler

Function x86ArithmeticHandler

src/vm.cpp:199–322  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

197 }
198
199 bool x86ArithmeticHandler(Instruction* instruction, ZydisMnemonic operation, bool storeOutput)
200 {
201 std::vector<ZydisDecodedOperand> operandInfo = instruction->getOperandInfo();
202
203 switch (operandInfo[0].type)
204 {
205 case ZYDIS_OPERAND_TYPE_REGISTER:
206 {
207 switch (operandInfo[1].type)
208 {
209 case ZYDIS_OPERAND_TYPE_REGISTER:
210 {
211 emitPushRegister(instruction, operandInfo[0].reg.value, operandInfo[0].size);
212 emitPushRegister(instruction, operandInfo[1].reg.value, operandInfo[0].size);
213 emitArithmetic(instruction, operation, operandInfo[0].size);
214 emitPopRegister(instruction, ZYDIS_REGISTER_RFLAGS, 64);
215 if (storeOutput)
216 {
217 if (operandInfo[0].size == 32)
218 zeroRegister(instruction, operandInfo[0].reg.value);
219 emitPopRegister(instruction, operandInfo[0].reg.value, operandInfo[0].size);
220 }
221 else
222 {
223 emitPopRegister(instruction, R0, operandInfo[0].size);
224 }
225 return 1;
226 }
227 case ZYDIS_OPERAND_TYPE_IMMEDIATE:
228 emitPushRegister(instruction, operandInfo[0].reg.value, operandInfo[0].size);
229 emitPushImmediate(instruction, operandInfo[1].imm.value.s, operandInfo[0].size);
230 emitArithmetic(instruction, operation, operandInfo[0].size);
231 emitPopRegister(instruction, ZYDIS_REGISTER_RFLAGS, 64);
232 if (storeOutput)
233 {
234 if (operandInfo[0].size == 32)
235 zeroRegister(instruction, operandInfo[0].reg.value);
236 emitPopRegister(instruction, operandInfo[0].reg.value, operandInfo[0].size);
237 }
238 else
239 {
240 emitPopRegister(instruction, R0, operandInfo[0].size);
241 }
242 return 1;
243 case ZYDIS_OPERAND_TYPE_MEMORY:
244 {
245 calculateEffectiveAddress(instruction, operandInfo[1].mem);
246 emitRead(instruction, operandInfo[0].size);
247 emitPushRegister(instruction, operandInfo[0].reg.value, operandInfo[0].size);
248 emitArithmetic(instruction, operation, operandInfo[0].size);
249 emitPopRegister(instruction, ZYDIS_REGISTER_RFLAGS, 64);
250
251 if (storeOutput)
252 {
253 if (operandInfo[0].size == 32)
254 zeroRegister(instruction, operandInfo[0].reg.value);
255 emitPopRegister(instruction, operandInfo[0].reg.value, operandInfo[0].size);
256 }

Callers 3

x86CmpHandlerFunction · 0.85
x86TestHandlerFunction · 0.85

Calls 9

emitPushRegisterFunction · 0.85
emitArithmeticFunction · 0.85
emitPopRegisterFunction · 0.85
zeroRegisterFunction · 0.85
emitPushImmediateFunction · 0.85
emitReadFunction · 0.85
emitWriteFunction · 0.85
getOperandInfoMethod · 0.80

Tested by

no test coverage detected