def chunkit(num):
"""
retun list of 2 byte numbers
0x12345678 = 0x78, 0x56, 0x34, 0x12
"""
a = (num & 0xff000000) >> 24
b = (num & 0x00ff0000) >> 16
c = (num & 0x0000ff00) >> 8
d = (num & 0x000000ff)
return [d,c,b,a]
Showing posts with label python. Show all posts
Showing posts with label python. Show all posts
2008-02-27
fun with masking and shifts
2007-09-11
Hello Python
Hello Python, this is derived from "Ruby in 20 Minutes"1
Enter the python interpreter.
---------------------------------
Define a function that says 'hello world'.
>>> def h():
... print "hello world"
...
>>> h()
hello world
Define a slightly more complex function that says hello to the passed name.
>>> def h(name):
... print "Hello %s!" % name
...
>>> h('Guido')
Hello Guido!
Define a function that says hello to the world, or to the passed name.
>>> def h(name = 'World'):
... print "Hello %s!" % name
...
>>> h()
Hello World!
>>> h('Guido')
Hello Guido!
If we want our object to remember our name, we would use a class. Enter the 'Greeter' class.
>>> class Greeter:
... def __init__(self, name = "World"):
... self.name = name
... def say_hi(self):
... print "Hello %s!" % self.name
... def say_bye(self):
... print "Goodbye %s. Please come again." % self.name
...
>>> g = Greeter('Guido')
>>> g.say_hi()
Hello Guido!
>>> g.say_bye()
Goodbye Guido. Please come again.
>>> g.name
'Guido'
>>>g.name = 'Syn'
>>> g.say_hi()
Hello Syn!
Now for fun lets write a 'MegaGreeter' that can handle multiple names.
>>> class MegaGreeter:
... def __init__(self, name = "World"):
... self.name = name
... def say_hi(self):
... if isinstance(self.name, list) or isinstance(self.name, tuple):
... for i in self.name:
... print "Hello %s!" % i
... else:
... print "Hello %s!" % self.name
... def say_bye(self):
... if isinstance(self.name, list) or isinstance(self.name, tuple):
... print "Goodbye %s. Please come again!" % ", ".join(self.name)
... else:
... print "Goodbye %s. Please come again!" % self.name
...
>>> mg = MegaGreeter(['Guido', 'Syn', 'Ninja'])
>>> mg.say_hi()
Hello Guido!
Hello Syn!
Hello Ninja!
>>> mg.say_bye()
Goodbye Guido, Syn, Ninja. Please come again!
>>> mg = MegaGreeter()
>>> mg.say_hi()
Hello World!
>>> mg.say_bye()
Goodbye World. Please come again!
>>> dir(MegaGreeter)
['__doc__', '__init__', '__module__', 'say_bye', 'say_hi']
2007-06-22
simple python stuff
$ ./maps.py -h
Usage: ./maps.py [-h --help] [-s --specify=arg] [-t --automatic]
Mandatory arguments to long options are mandatory for short options too.
-s --specify=ARGUMENT print specified argument
-a --automatic print predefined
-h --help display this help and exit
$ ./maps.py -a
I like Yahoo maps
$ ./maps.py --automatic
I like Yahoo maps
$ ./maps.py -s amazon
I like amazon maps
$ ./maps.py -s google
Google maps is the BEST!
True that, DOUBLE TRUE!
2007-04-17
borker.py
Silly little script to modify a file.
$ cat Xorg.0.logborker.py
<...>
Markers: (--) probed, (**) from config file, (==) default setting,
(++) from command line, (!!) notice, (II) informational,
(WW) warning, (EE) error, (NI) not implemented, (??) unknown.
<...>
$ borker.py Xorg.0.log
bork bork bork
$ cat Xorg.0.log
<...>
bork: (--) bork, (**) bork bork bork, (==) bork bork,
(++) bork bork bork, (!!) bork, (bork) bork,
(bork) bork, (bork) bork, (bork) bork bork, (??) bork.
<...>
2007-04-10
python command line hex calculator
This is a _really_ simple command line hex calculator. Mostly just learning more python.
ccalc.py
$ ccalc.py 0xa+5
15 0xf 0o17 0b1111
$ ccalc.py 0xa + 5
15 0xf 0o17 0b1111
ccalc.py
2007-04-09
wwmii
I recently switched from ion3 to wmii for a change. I really enjoy it. Among other things, you can use whatever programming language you like to customize your setup.
I wrote a python script to give me a little more status for my system. Here is what it does.
status.py
I wrote a python script to give me a little more status for my system. Here is what it does.
$ status.py
--{ *AC* 99% + 81% on + 0.70 0.52 0.45 + N/A 00 + Mon 2007-04-09 11:45:23 MST }--
2007-03-16
simple python brute force script
This is a simple python script to brute force a buffer.
#!/usr/bin/python
# simple buffer brute force tool
# syndrowm 2007-03-16
import sys
import os
def usage():
print 'Usage: %s <program> [lower] [higher]' % sys.argv[0]
sys.exit(0)
if len(sys.argv) - 1 < 1:
usage()
try:
program = sys.argv[1]
lower = int(sys.argv[2])
higher = int(sys.argv[3])
higher = higher + 1
except:
print 'Using default range 1 100'
lower = 1
higher = 101
if (os.access(program, os.X_OK)) != 1:
print '%s does not exist' % program
usage()
n = range(lower,higher)
for x in n:
b = "A"*x
#print x, b
e = os.system('%s %s' % (program, b))
if e != 0:
if e == 139:
print x, e, "Segmentation fault \m/:(|)\m/"
else:
print x, e, "Unknown"
...
dsl@0[exploitmes]$ brute.py
Usage: brute.py[lower] [higher]
dsl@0[exploitmes]$ brute.py ./01_exploitme01 256 290
268 139 Segmentation fault \m/:(|)\m/
269 139 Segmentation fault \m/:(|)\m/
2007-02-20
user input in python
#!/usr/bin/env python
import sys
min = 1
if len(sys.argv) - 1 < 1:
while 1:
num = raw_input("Please enter something: ")
if len(num) > 0:
break
else:
num = sys.argv[1]
print "You entered:", num
Subscribe to:
Posts (Atom)