Checking Operand Equality

12 views
Skip to first unread message

Mohammad Ewais

unread,
Sep 16, 2021, 11:45:31 AM9/16/21
to DynamoRIO Users
Hi,

During BB instrumentation, I am looking for patterns like the following:
ADDSS XMM1, MEM
MOVSS MEM, XMM1

And I basically want to make sure that:
- The XMM register being used as the destination of the first instruction is the same as the source of the second
- The MEM address being used as the second source of the first instruction is also the same as the destination of the second instruction
- If other instructions come in between these two, that they don't read from XMM1. or write to MEM.

Checking that the XMM register is the same is easy enough to do using opnd_get_reg. But making sure MEM is the same involves reserving two registers for use with drutil_insert_get_mem_addr. For my purposes, and the fact that I will be checking multiple instructions, this could potentially cause a significant performance drop.

My questions is very simple. Will simply checking the equality of opnd_t work? Instead of comparing the registers or memory addresses?

Thanks

John Galea

unread,
Sep 16, 2021, 12:40:55 PM9/16/21
to DynamoRIO Users
Hi,

It depends on what you want to do.

If you just want to compare memory operands strictly on static information, such as registers, offsets and scales, then this can be achieved at instrumentation-time.

On the other hand, if you want to compare actual memory addresses, which are ultimately computed dynamically, then you need to insert code that does such comparisons at runtime.

Cheers,
John

Mohammad Ewais

unread,
Sep 16, 2021, 12:57:15 PM9/16/21
to DynamoRIO Users
I see. Thanks a lot. Static checking is fine for my case. 

I was just worried that opnd_t may have other information pertaining to, for example, the instructions they're in, which of course would cause an equality check to fail. Since we have no knowledge/documentation of the opnd_t type.

Anyway, thanks a lot.

Derek Bruening

unread,
Sep 16, 2021, 5:26:03 PM9/16/21
to dynamor...@googlegroups.com
Note that you should use opnd_same() rather than memcmp or something to compare equality.

--
You received this message because you are subscribed to the Google Groups "DynamoRIO Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to dynamorio-use...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/dynamorio-users/fcda4e0a-e789-4397-8be1-d6187181fc83n%40googlegroups.com.

Mohammad Ewais

unread,
Sep 17, 2021, 12:44:04 AM9/17/21
to DynamoRIO Users
Thanks for the information, I didn't notice those in the API.
Reply all
Reply to author
Forward
0 new messages