shellcode - What Does Assembly Instruction Shift Do? -


i came across pretty interesting article demonstrated how remove nullbyte characters shellcode. among techniques used, assembly instructions shl , shr seemed occupy rather important role in code.

i realize assembly instructions mov $0x3b, %rax , mov $59, %rax each generate machine code instructions 48 c7 c0 3b 00 00 00. cope this, author instead uses mov $0x1111113b, %rax fill register system call number, generates instead machine code 48 c7 c0 3b 11 11 11, removes nullbytes.

unfortunately, code still doesn't execute because syscall treats 3b 11 11 11 illegal instruction, or causes code seg fault. author did shift %rax , forth 56 bytes commands

shl $0x38, %rax  shr $0x38, %rax 

after shift, code executes perfectly. want know how shift instructions fixes 48 c7 c0 3b 11 11 11 issue, , somehow makes %rax proper , syscall'able. know shl/shr shifts bits left , right, meaning shifting left moves bits higher bits, , shifting right makes them lower again, because binary read right left. how @ change code , make executable? doesn't shifting , forth change nothing, putting shifted bits in beginning?

my theory shifting bits away leaves behind zeros. still don't see how shifting %rax forward , fixes solution, because wouldn't bring 11 11 11 section anyway?

anyways, thought interesting had never seen shift operands before today. in advance.

shifting lossy operation - if bits shifted outside of register, disappear. (sometimes 1 of them stored in carry flag, that's not important here.) see http://en.wikibooks.org/wiki/x86_assembly/shift_and_rotate#logical_shift_instructions .

the shift left (shl) operation this:

0x000000001111113b << 0x38 = 0x3b00000000000000

the 0x111111 part have occupied bit 64, 65, 66 etc., %rax 64-bit register, bits vanish. then, logical shift right (shr) operation this:

0x3b00000000000000 >> 0x38 = 0x000000000000003b

giving number want. , that's there it.


Popular posts from this blog

c# - ODP.NET Oracle.ManagedDataAccess causes ORA-12537 network session end of file -

matlab - Compression and Decompression of ECG Signal using HUFFMAN ALGORITHM -

utf 8 - split utf-8 string into bytes in python -