I can feel some *RTFM* in your response ? :D
No matter, I'm on the point to find it
No matter, I'm on the point to find it
A forum for reverse engineering, OS internals and malware analysis
Tigzy wrote:I can feel some *RTFM* in your response ? :DYes probably :)
No matter, I'm on the point to find it
int ror(unsigned int value, int places)
{
int x = value;
for (int i = 0 ; i < places ; i++)
{
int rmb = x & 0x00000001; // right most bit (save)
x = x >> 1; // shift on right 1 bit
if (rmb == 1) // push the rmb on left
{
x = x | 0x80; // 0b10000000
}
}
return x;
}
bool decryptMBR (byte* bufferIN, byte* bufferOUT, int key, int offset)
{
//Copy first part
memcpy(&bufferOUT[0], &bufferIN[0], offset);
// decrypt second part
int keyInit = key;
for (int i = 0 ; i < keyInit ; i++)
{
// Only 8 first bits
int count = key & 0xFF;
// Dec key
key--;
// apply ror
bufferOUT[offset] = ror(bufferIN[offset], count);
offset++;
}
return true;
//seg000:001E mov cx, 147h
//seg000:0021 mov bp, 62Ah
//seg000:0024
//seg000:0024 loc_24:
//seg000:0024 ror byte ptr [bp+0], cl
//seg000:0027 inc bp
//seg000:0028 loop loc_24
}
Tigzy wrote: Here's the code :There is no need in this function. Just use _rotr intrinsic.
Code: Select allint ror(unsigned int value, int places) { int x = value; for (int i = 0 ; i < places ; i++) { int rmb = x & 0x00000001; // right most bit (save) x = x >> 1; // shift on right 1 bit if (rmb == 1) // push the rmb on left { x = x | 0x80; // 0b10000000 } } return x; }
Tigzy wrote:Is this an ASM function?C run-time
Tigzy wrote:Ok :/I'd like to point to 2 things:
Fortunately it was a basic function...
unsigned int ror ( unsigned int value, unsigned int shift )
{
return ( value >> ( shift % 32 ) ) | ( value << ( 32 - ( shift % 32 ) ) );
}
1. You implementation is really awful because ofI don't doubt of that. This is quite new for me.
a) you don't need to rotate "places" times, "places" mod 32 is plentyYes. the mod 32 is implemented by design in my code. Not perfect I must admit, but functional.