Skip to content

Instantly share code, notes, and snippets.

@notareverser
Last active November 11, 2022 14:44
Show Gist options
  • Save notareverser/95e5f650f07d1106691bc0e92826ee2e to your computer and use it in GitHub Desktop.
Save notareverser/95e5f650f07d1106691bc0e92826ee2e to your computer and use it in GitHub Desktop.
Snippets of Python to help out with reversing
import operator
def compileTime(data):
from struct import unpack_from as suf
if data[0:2] == b'\x4d\x5a':
peOffset = suf("<H",data,0x3c)[0]
if data[peOffset:peOffset+4] == b'\x50\x45\0\0':
return suf("<L",data,peOffset+8)[0]
return None
def rotateImpl(invalue, numbits, preshift, postshift, maxbits = 32):
mask = 2**maxbits-1
s1 = preshift((invalue & mask), (numbits%maxbits))
s2 = postshift(invalue, (maxbits-(numbits%maxbits)))&mask
return (s1 | s2)&mask
def ror(invalue, numbits, maxbits = 32):
return rotateImpl(invalue, numbits, operator.rshift, operator.lshift, maxbits)
def rol(invalue, numbits, maxbits = 32):
return rotateImpl(invalue, numbits, operator.lshift, operator.rshift, maxbits)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment