XlogicX
XlogicX
s
Too Hi
gh Level
DEF CON 25
XlogicX
...or the drinking game replaces 'cyber' with 'assembly is too high level'
Shoutz
●
KRT_c0c4!n3 (art)
●
Fat Cat Fab Lab (where I hack)
●
NYC2600 (who I friend)
●
DC201 (Because DEF CON)
Deck at http://xlogicx.net/?p=515
I eventually try to teach myself Z80 assembly. This is
because I already had a TI-82 and already tried
some sweet games programmed in assembly.
The first program I made was an example program
that clears the screen. My first attempt to make my
own program cleared the memory. This was
unintended...
I then formally learn Assembly for the M68HC11
microcontroller in school. I don't even remember if
we had a textbook, but we did have the Motorola
manual. This manual listed all of the instructions with
the machine code next to the instruction.
I had a lot of fun with this architecture. Inspired by
Godel Escher Bach, I attempted to create a program
that replicated itself into the next area of memory and
executed itself. I learned the importance of needing
to understand the abstraction layer of machine code
in order to pull this off. Also, the assembly language
and machine code for this architecture was relatively
one to one.
Propeller Assembl
y
●
m2elf.pl – Converts machine code to ELF
executable
●
Irasm – Like nasmshell.rb (but does the stuff
that this talk explains
●
It’s also not a shell, it’s an assembler written in
Ruby
●
ADD AL, imm8
●
Adding an 8-bit value to the 8-bit AL
register
●
0x04 is opcode for 'ADD AL' followed by
byte to add
●
INC, 32-bit Register
●
Increments a 32 bit register
●
These registers come in the following
order:
●
EAX, ECX, EDX, EBX, ESP, EBP, ESI, EDI
●
MOV r8, imm8
●
Move a byte into an 8-bit register
●
These registers come in the following order:
●
AL, CL, DL, BL, AH, CH, DH, BH
●
The entire value is 16 bits
●
The two halves make up 8 bits (07 and 09)
●
Being that the values are converting from
base 1
●
The two halves need to be from 00-09
●
Even though 0A-FF are valid 8 bit values
●
0709 moved into the 16 bit register (ax)
●
AAD performed
●
The ‘A’ (al/ah/ax/eax) register now contains
004f
●
The AAD mnemonic is interpreted by all
assemblers to mean adjust ASCII (base
10) values. To adjust values in another
number base, the instruction must be hand
coded in machine code (D5 imm8)
23 in hexadecimal is 0x17
Let's do base2
●
Remember base 10, we were limited to 00-09?
●
What happens when we use the values in the 0A-FF
range?
●
Do you know what base 1 or even base 0 means?
●
Neither do I, so what happens?
●
AL = AL + (AH * base)
●
Where:
●
AL is the last 2 bytes of input
●
AH is the first 2 bytes of input
●
Base defaults to 10 (but we can machine
hack that)
●
All of these are optional
●
Examples:
●
[eax + ebx * 2]
●
[ebx + 0x33]
●
[ecx * 8 + 0x11223344]
●
[0x33]
When you line this up, you get 0x8B for the SIB byte.
• Consider [ecx * 1]
●
Encoding for SIB requires more bytes
• If there is no base register already:
●
Assemblers will convert a scaled by '1' register
as a base. So:
●
[ecx]
I love nasm
TEST r32,r/m32
I like this one. This slide is saying that you can write
something in assembly like: TEST EAX, [EAX]
●
5-3=8
●
3 - 5 = -2
●
5 AND 3 = 1
●
3 AND 5 = 1
●
SAL = Shift Arithmetic Left
●
Does the same thing as Shift Left
(SHL)
●
Therefore, everything is SHL
Challenge accepted!
This is us in assembly attempting to write an
instruction that uses bswap on a 16 bit register:
BSWAP AX
In red, the 000 means INC and the 001 means DEC.
The difference to the 2 instruction is just one bit.
Self Modi
fyi
ng Code Demo
IRASM:
Interactive Redundant ASeMbler
●
m2elf.pl –interactive
●
https://github.com/XlogicX/m2elf
●
Irasm
●
https://github.com/XlogicX/irasm
●
My Blog
●
xlogicx.net
●
Twitter
●
@XlogicX