Package: smartbytes
Aboutsmartbytes makes byte parsing not painful*insertI can't believe it's not Python 2!on image*InstallationPyPi# pip3 install smartbytesManualThe only requirement for smartbytes is any version ofpython3.$ git clone https://github.com/Arinerron/smartbytes.git
$ cd smartbytes

# sudo python3 setup.py installDocumentationThe best way to document is to just give you a ton of cool examples.>>>fromsmartbytesimport*# you can easily concat values to build smartbytes objects>>>smartbytes('hello world')b'hello world'>>>smartbytes('hello')+0x20+smartbytes('world')b'hello world'>>>smartbytes('hello')+' '+b'world'b'hello world'# you can search for strings easily>>>withopen('/usr/lib/libc-2.31.so','rb')asf:...contents=f.read()...>>>smartbytes(contents)['/bin/sh\x00']# find offset of /bin/sh string in libc1618243# smartbytes works with iters>>>smartbytes(range(10))b'\x00\x01\x02\x03\x04\x05\x06\x07\x08\t'>>>smartbytes(range(10))+range(10)b'\x00\x01\x02\x03\x04\x05\x06\x07\x08\t\x00\x01\x02\x03\x04\x05\x06\x07\x08\t'# it can flatten arrays out too>>>smartbytes([(2,3),4],[5,(((3,5),),)])b'\x02\x03\x04\x05\x03\x05'# there are some cool functions to make your smartbytes usable>>>value=smartbytes(range(100))>>>valueb'\x00\x01\x02\x03\x04\x05\x06\x07\x08\t\n\x0b\x0c\r\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f!"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abc'>>>str(value)'\x00\x01\x02\x03\x04\x05\x06\x07\x08\t\n\x0b\x0c\r\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f!"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abc'>>>value.hex()b'000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f60616263'>>>print(value.hexdump())000102030405060708090a0b0c0d0e0f................101112131415161718191a1b1c1d1e1f................202122232425262728292a2b2c2d2e2f!"#$%&'()*+,-./303132333435363738393a3b3c3d3e3f0123456789:;<=>?404142434445464748494a4b4c4d4e4f@ABCDEFGHIJKLMNO505152535455565758595a5b5c5d5e5fPQRSTUVWXYZ[\]^_60616263`abc# any operation you can do on a str or bytes object, you can do on a smartbytes object too>>>value=smartbytes('hello world')>>>value.reverse()b'dlrow olleh'>>>value.upper()b'hello world'>>>value.ljust(20)b'hello world\x00\x00\x00\x00\x00\x00\x00\x00\x00'>>>value.rjust(20)b'\x00\x00\x00\x00\x00\x00\x00\x00\x00hello world'>>>value.split(' ')[b'hello',b'world']>>>value.endswith('world')True>>>value.startswith(b'hello')True>>>value.contains(0x20)# 0x20 is the ' ' character!True>>>0x20invalueTrue>>>value[1]b'e'>>>value['e']1>>>len(value)11# ...with even more functionality than both str and bytes!>>>value.chunks(2)[b'he',b'll',b'o ',b'wo',b'rl',b'd']>>>value.chunks(4)[b'hell',b'o wo',b'rld']# you can also append many types to it and it will handle it properly>>>value=smartbytes()>>>value+='hello'>>>value+=0x20>>>value+=b'world'>>>value+=smartbytes('!')>>>valueb'hello world!'>>>value*4b'hello world!hello world!hello world!hello world!'# it comes with pwntools-like packing functions# NOTE: endianness can be specified using kwarg endian (e.g. endian='big')>>>p8(0x12)b'\x12'>>>p16(0xaa)b'\xaa'>>>p32(0xdead)b'\x00\x00\xad\xde'>>>p64(0xdeadbeef)b'\x00\x00\x00\x00\x00\x00\xef\xbe\xad\xde'# ...but it can also do packing and unpacking without fixed sizes>>>p(0xdeadbeef)b'\xde\xad\xbe\xef'>>>u('what does this look like when unpacked')15202366010688944152837236994529002040902519784461806602639909313811909172211576228574618980# smartbytes even works with pwntools!>>>fromsmartbytesimport*>>>frompwnimport*>>>p=process('cat')[+]Startinglocalprocess'/usr/bin/cat':pid1470268>>>line=smartbytes(b'robert',0x20,'is')+0x20+b'an'+smartbytes(' ','arch',0x20,'user btw')>>>lineb'robert is an arch user btw'>>>p.sendline(line)