March 1, 2013 by globz
While working on a remote file downloader in Assembly I had to convert a url to push instructions so here’s a little bit of python magic :
In the above screenshot you can see that only 4 commands are needed to create push instructions.
After reversing and encoding a url, simply use the following command to create your push instructions :
for item in map(,,.join, zip(*[iter(rev_hex)]*8)) :
print "push 0x" +item
This function returns a list of tuples, where the i-th tuple contains the i-th element from each of the argument sequences or iterables. The returned list is truncated in length to the length of the shortest argument sequence. When there are multiple arguments which are all of the same length, zip() is similar to map() with an initial argument of None. With a single sequence argument, it returns a list of 1-tuples. With no arguments, it returns an empty list.
The left-to-right evaluation order of the iterables is guaranteed. This makes possible an idiom for clustering a data series into n-length groups using zip(*[iter(s)]*n).
Now its time to print the items and append “push 0x” at the start of each tuples which will return our push instructions!
Sorry, comments are closed.