Created
December 21, 2016 20:27
-
-
Save itszn/5c6030addaecd041af522a77975e986d to your computer and use it in GitHub Desktop.
Super fast hex encoding
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from timeit import timeit | |
from ctypes import * | |
''' | |
libc = CDLL('libc.so.6') | |
libc.mprotect(0x400000,0x1000,7) | |
s = "e810000000303132333435363738394142434445465b803f007437c6065c48ffc6c6067848ffc68a074825ff00000048c1e8044801d88a00880648ffc68a074883e00f4801d88a00880648ffc648ffc7ebc4c3".decode('hex') | |
#s = "\xc3" | |
libc.memcpy(0x400000, c_char_p(s),len(s)) | |
fd = CFUNCTYPE(c_int, c_char_p, c_char_p) | |
f = fd(0x400000) | |
binarystring = "A"*1000 | |
a = lambda: (lambda out: (out,f(c_char_p(binarystring),c_char_p(out)))[0])("B"*(len(binarystring)*4)) | |
print timeit(stmt=a, number=10000) | |
''' | |
binarystring = "A"*1000 | |
# One liner | |
a = (lambda libc, sc: (lambda fd: (lambda: (lambda out: (out,fd(0x400000)(c_char_p(binarystring),c_char_p(out)))[0])("B"*(len(binarystring)*4))))((libc.mprotect(0x400000,0x1000,7), libc.memcpy(0x400000, c_char_p(sc),len(sc)), CFUNCTYPE(c_int, c_char_p, c_char_p))[2]))(CDLL('libc.so.6'), 'e810000000303132333435363738394142434445465b803f007437c6065c48ffc6c6067848ffc68a074825ff00000048c1e8044801d88a00880648ffc68a074883e00f4801d88a00880648ffc648ffc7ebc4c3'.decode('hex')) | |
print a() | |
print timeit(stmt=a, number=10000) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment