I am having difficulty converting the code below to Python's 3.4 version, the purpose of this code is to encode and decode hexes in order to create shellcodes .
import binascii, sys, time
RED = '3[31m'
WHITE = '3[37m'
RESET = '3[0;0m'
def main():
print("shellcode hex encode decoder")
print("programmer : gunslinger_ <yudha.gunslinger[at]gmail.com>")
print "what do you want to do ? %sencode%s / %sdecode%s" % (RED, RESET, WHITE, RESET)
q = raw_input("=> ")
if q == "encode":
inputtype = raw_input("Please input data : ")
print "shellcode => ",
for encoded in inputtype:
print "\b\x"+encoded.encode("hex"),
sys.stdout.flush()
time.sleep(0.5)
print RESET
elif q == "decode":
inputtype = raw_input("Please input data : ")
cleaninput = inputtype.replace("\x","")
print "hex => ",cleaninput
print "plaintext => ",
print "\b"+cleaninput.decode("hex")
else:
print "wrong answer ! your choice is %sencode%s or %sdecode%s" % (RED, RESET, WHITE, RESET)
sys.exit(1)
if __name__ == '__main__':
main()
This part did not understand:
print "what do you want to do ? %sencode%s / %sdecode%s" % (RED, RESET, WHITE, RESET)
Surely he defined the colors above, and %sencode%s / %sdecode%s
how does this work? From what I understand it made a %s
, at the beginning and end of the words encode and decode and call with the colors.
q = raw_input("=> ")
Has the variable and this =>
defined something specific in Python 2?
In this part below I understand some parts but not all if someone explains me better I am grateful.
inputtype = raw_input("Please input data : ")
print "shellcode => ",
for encoded in inputtype:
print "\b\x"+encoded.encode("hex"),
sys.stdout.flush()
time.sleep(0.5)
Thank you guys.