Home:ALL Converter>Hexcode generator in python

Hexcode generator in python

Ask Time:2014-03-19T04:31:39         Author:user1090614

Json Formatter

I am trying to generate a hexcode generator in python for an assigment in school.

I would like to bruteforce the address space, however, I am not able to construct real hexcodes in python.

my script:

 for j in range(0, 100):
       var = "\\x%x" % j
       newpath = "\xa0\xf4\xff"+var
       print newpath

The bytecodes "\xa0\xf4\xff" gets printed correctly - as proper hexcodes. However, my bruteforcer is not able to generate real hexcodes but only strings "\xab" etc. How do I generate real hexcodes: Essentially, I would like to generate the entire address space of a 32-bit machine.

EDIT: More specifically, by looking at some arbitrary output you can see the last "hexcode" is not considered a hexcode, but rather a string:

 ���\x5d
 ���\x5e
 ���\x5f
 ���\x60
 ���\x61
 ���\x62
 ���\x63

Author:user1090614,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/22490391/hexcode-generator-in-python
Ronny Andersson :

Hex is just a different representation of a number. It is using base 16 instead of base 10 which is what we are normally used to.\n\nWith that in mind, any number is can be represented as a hex number:\n\nfor i in range(0, 0x20):\n print \"0x%08X\" %i\n\n\nthe output is\n\n0x00000000\n0x00000001\n0x00000002\n0x00000003\n...\n0x0000000E\n0x0000000F\n0x00000010\n0x00000011\n...\n\n\nBy using %X in the print statement we say \"interpret as base 16\". You can also specify a number in its hex representation, as I did in the range(0, 0x20) statement. \n\nThe reason that you see the printout of \"\\xa0\\xf4\\xff\" is because python cannot substitute the values in that string into characters and prints the next best thing, a string representation of the number. Do not confuse an array of four bytes with its 32 bit word representation or its four character string representation, it's the same thing!\n\nI would recommend you to play around with the built in functions ord(), hex() and chr() to get a feeling for how things work. Example:\n\nprint ord('a')\nprint hex(10)\nprint chr(97)\n\n\noutput:\n\n97\n0xa\na\n",
2014-03-18T20:57:37
yy