Search code examples
reverse-engineeringida

The meaning of LOBYTE(some_var) = 0; in IDA HexRays?


I read some info about LOBYTE being a macros to extract low byte, but what I see there is something totally weird. It looks for me like setting value to a function -_- I am not pro reverse engeneer and doing it, because I don't have other options left.

So some algorithm read file byte-by-byte. Somewhere it do

fread(&third_block_first_zero_byte, 1u, 1u, hd6_file_ptr);

then later it do

LOBYTE(third_block_first_zero_byte) = 0;

So... what the hell it do? Extracting low byte from a single byte variable... ouch... that hurts my brain.


Solution

  • The two lines of code are unrelated.

    fread(&third_block_first_zero_byte, 1u, 1u, hd6_file_ptr);
    

    The fread function in this case returns a single element from a file object stream located in memory ('hd6_file_ptr' is a pointer to the stream).

    LOBYTE(third_block_first_zero_byte) = 0;
    

    Above line just retrieves low-order Byte from value currently stored within 'third_block_first_zero_byte' variable & reassigns it value zero.

    Similar query here

    Reference: http://www.cplusplus.com/reference/cstdio/fread/