I came around a piece of malware which i am analyzing and have found that it uses some kind of math to randomly selecting a register for a specific instruction
Which i don't understand how this operation is calculated depend on what?
Here is an example of what i mean
let's say that i wanted to randomly pick up a register for the instruction
ADD DWORD PTR DS:[0],EAX
We know the opcode for this instruction is 01 05 00 00 00 00
The bold number represents the register for this instruction
05 == EAX 0D == ECX
To better explain this here is the instruction with all the registers
0041580B 0105 00000000 ADD DWORD PTR DS:[0],EAX
00415811 010D 00000000 ADD DWORD PTR DS:[0],ECX
00415817 0115 00000000 ADD DWORD PTR DS:[0],EDX
0041581D 011D 00000000 ADD DWORD PTR DS:[0],EBX
00415823 0125 00000000 ADD DWORD PTR DS:[0],ESP
00415829 012D 00000000 ADD DWORD PTR DS:[0],EBP
0041582F 0135 00000000 ADD DWORD PTR DS:[0],ESI
00415835 013D 00000000 ADD DWORD PTR DS:[0],EDI
The malware uses a register index starting from 0 (EAX) till 7 (EDI)
The number is get SHLed first with the number 3 then it is ORed with 5 to get the right register opcode. So my question is how the author came to the conclusion of that?
I would say that SHL REG,3 equals REG*8 that is the number of max registers? but why do we need to OR it with 05? is it because the starting opcode of this instruction is 05?
Does anybody have a better explanation for this? or any hint words for a better comprehend?