Search code examples
assemblybinary-logic

Properties of binary logic?


Are there any properties of binary logic that I should know about?

For example,

  • if x AND 3 == 0, that means x is divisible by 4.
  • (0 - x) AND 3, is the distance a value is away from 4n. i.e. (0 - 5) AND 3 = 3 and 5 + 3 = 8 which is divisible by 4

Are there any other properties that I need to familiarize myself with to excel in reverse code engineering?

Where can I find them? And is there any advice one could give me to increase my knowledge?


Solution

  • Well, there's a few ;)

    People often use binary logic short-cuts since they map to efficient computer instructions - processors are based on binary logic after all.

    Things like De Morgan's laws are probably more useful when programming in higher level languages, but are applicable in assembly as well. When it comes to reverse engineering, overall familiarity with the processor is most important, since the compiler can add a lot of tricky code that you may have to step through/etc to understand.

    I would recommend learning to program a microprocessor first, personally. Something like PIC or AVR (Arduino).

    Also the first example is due to how binary works - make sure you are familiar with this (and hexadecimal representation also).

    The second is best explained through the ring of integers mod 2 ^ 2. All unsinged arithmetic corresponds to operations in the ring of integers mod 2 ^ n, such as 32 bit unsigned ints corresponding to Z mod 2^32.