Permalink
Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
31 lines (22 sloc) 1.03 KB
from __future__ import print_function # PEP 3105
# max bits > 0 == width of the value in bits (e.g., int_16 -> 16)
# Rotate left: 0b1001 --> 0b0011
rol = lambda val, r_bits, max_bits: \
(val << r_bits%max_bits) & (2**max_bits-1) | \
((val & (2**max_bits-1)) >> (max_bits-(r_bits%max_bits)))
# Rotate right: 0b1001 --> 0b1100
ror = lambda val, r_bits, max_bits: \
((val & (2**max_bits-1)) >> r_bits%max_bits) | \
(val << (max_bits-(r_bits%max_bits)) & (2**max_bits-1))
max_bits = 8 # For fun, try 2, 17 or other arbitrary (positive!) values
shellcode = ["32", "62", "0A", "3A", "DB", "9A", "42", "2A", "62", "62", "1A", "7A", "22", "2A", "69", "4A", "9A", "72", "A2", "69", "52", "AA", "9A", "A2", "69", "32", "7A", "92", "69", "2A", "C2", "82", "62", "7A", "4A", "A2", "9A", "EB"
]
final = ""
for i in shellcode:
value = "0x" + i
value = int(value,16)
#print (value)
newval = rol(value, 5, max_bits)
print("0x%08x << 0x05 --> 0x%08x" % (value, newval))
final = final + chr(newval)
print(final)