Sure Juapillo, just don't forget that a 0 represents the first byte in both my examples (LongToByte( 31320, 0 )
Code:
BYTE LongToByte( DWORD dwValue, int nCount ) {
BYTE ret;
ret = (dwValue >> (nCount*8)) & 0xFF;
return ret;
}
I guess you could just add a -1 if you want to use LongToByte( 31320, 1 ); where 1 is the first byte:
Code:
BYTE LongToByte( DWORD dwValue, int nCount ) {
BYTE ret;
ret = (dwValue >> ((nCount-1)*8)) & 0xFF;
return ret;
}
About ASM I'm not sure since I can't try it atm. You could probably just add a sub command:
Code:
LongToByte proc szValue:DWORD,nCount:DWORD
lea eax,szValue ; Set eax to the address of szValue
sub nCount,1 ; Since people are lazy, subtract 1 from nCount which makes 1 the least possible action
add eax,nCount ; We add nCount to eax (if nCount is 1 we will return the first byte of the dword)
movzx eax,byte ptr [eax] ; We move a byte into the 32-bit register using movzx. eax will now hold the correct byte
ret ; Return eax which holds the correct byte to the application calling this function
LongToByte endp
It all just seems so unecessary to force the computer to do another command just because people rather write 1 instead of 0.