binary autonomy Notes - ipatch/theairportwiki GitHub Wiki

General CS Knowledge

1 - represents the presence of a voltage in a circuit
0 - represents the lack of a voltage in a circuit

binary - is a base-2 numeral system.

Fun Fact 01 - All odd numbers have the lowest bit set to 1

Overview of how a binary is constructed

source code -> compiler -> object files -> linker -> binary

Structure of a binary

There are three types of segments - is used for initialized data.

  • .text
  • .bss block sorted by symbol - uninitialized data
  • .data

Definitions

  • .text - is mapped as read-only.
  • .bss and .data - are mapped as writable, reserved for global variables.
  • .bss - contains uninitialized data
  • .data - contains static initialized data.
  • .text - holds the program instructions.

The Stack

  • stack - the stack is a contiguous area of physical memory for storing various parts of a binary.
  • stack frame - a place on the stack that stores each function of a program.
  • top of the stack - is lowest numerical address
  • strings - variables defined with string are stored in global variables not the stack
  • POP - take whatever’s on the stack and put it into a register.
  • CALL - pushes the next instruction on the stack, changing the value stored in EIP
  • MOV - move from register to register, and register to memory, and memory to register

CPU

  • Registers

Registers - small volatile memory storage areas built into the processor.

  • ESP extended stack pointer - points to the top of the stack. lowest numerical address
  • FLAGS - special one bit registers.
  • EAX - Stores function return values.
  • EBX - base pointer to the data section.
  • ECX - Counter for string and loop operations.
  • EDX - I/O pointer

Trivia

The 8086 was Intel’s first 16-bit CPU.

CPU Architecture Design

  • Intel x86 CISC - Complex Instruction Set Computer
  • ARM RISC - Reduced Instruction Set Computer

RISC generally has more registers

Endianess

Little Endian - stores the lowest part of a number in the lowest part of the address space.

Memory

memory can only be addressed in multiples of the word size and is measured in bytes.
words - generally 4 bytes or 32 bits.
Every byte of memory in the computer has its own unique address.
code segment - an area of memory where machine instructions are stored.
ASLR - Address Space Layout Randomization

Assembly

Two ASM Syntax Flavors 🍦

  • Intel: destination <- source
  • ATT: source -> destination

Examples

  • movl %eax, location - moves data into a memory location
  • movl location, %ebx - moves data into a register
  • Placing the $ sign before a label name takes the memory address of the variable and not the value.

Example

movl $location, %edi

  • Instructions
    • NOP Null Operation - in Intel architecture is one byte long and translates to 0x90 in machine code.
    • CMP is actually a subtract SUB of two values.

😮 Only 14 assembly instructions account for 90% of code.

More Trivia

The one byte NOP instruction is an alias mnemonic for the XCHG EAX, EAX instruction.

Operating Systems

protected mode OS - divides the memory in user and kernel space.

High Level - C - to low level ASM

goto in C translates to JMP in assembly.

TODO

  • check and see if ELF stands for executing linking file
⚠️ **GitHub.com Fallback** ⚠️