-
Website
http://www.matasano.com/log -
Original page
http://www.matasano.com/log/1084/ruby-for-pentesters-1-use-modules-for-lists-of-constants/ -
Subscribe
All Comments -
Community
-
Top Commenters
-
Press Controls
3 comments · 2 points
-
ChrisMtso
12 comments · 1 points
-
Eric Monti
11 comments · 1 points
-
StatlerAndWaldorf
12 comments · 3 points
-
Dave G.
7 comments · 1 points
-
-
Popular Threads
Just wanted to let you know :)
I <3 Ruby
http://labs.mudynamics.com/2007/01/03/enums-str...
def __new__(cls, clsname, clsbases, clsdict):
clsdict['to_value_hash'] = clsdict
clsdict['to_name_hash'] = dict([ (y, x) for x, y in clsdict.iteritems() if x.isupper() ])
return type.__new__(cls, clsname, clsbases, clsdict)
class EFlags:
__metaclass__ = Flags
CARRY = (1<< 0)
X0 = (1<< 1)
PARITY = (1<< 2)
# ...
VINT = (1<< 19)
VINTPENDING = (1<< 20)
CPUID = (1<< 21)
if __name__ == '__main__':
print 'CARRY', EFlags.CARRY
print 'CPUID', EFlags.to_value_hash['CPUID']
print EFlags.to_name_hash[1 << 19]
---8<---
class MetaEnum(type):
def __new__(cls, name, bases, classdict):
classdict['to_name_hash'] = \
dict([(enum, val) for enum, val in classdict.iteritems()
if not enum.startswith('__')])
classdict['to_value_hash'] = \
dict([(val, enum) for enum, val in classdict['to_name_hash'].iteritems()])
return type.__new__(cls, name, bases, classdict)
class EFlags(object):
__metaclass__ = MetaEnum
CARRY = (1<< 0)
X0 = (1<< 1)
PARITY = (1<< 2)
# ...
VINT = (1<< 19)
VINTPENDING = (1<< 20)
CPUID = (1<< 21)
EFlags.to_name_hash['VINT'] # 524288
EFlags.to_value_hash[1 << 19] # 'VINT'
---8<---
Oh, I used 2 dicts. So I got 2x0 = 0 credit :'(
class C:
pass
C.a = 0
C.b = 1
C.__dict__
{'a': 0, '__module__': '__main__', 'b': 1, '__doc__': None}
http://flgr.0x42.net/code/enum.rb
The main benefit being that inspection of an enum member (wherever it appears) will show you the name instead of the value.
Perl has Net::RawIP to help
Python has scapy
Ruby has scruby
C has libnet and libdnet
Python is prob the best IDA Pro automation language (IdaRub has not been updated in forever). Python also is handy for the Immunity debugger. And a bunch of other good RE tools are in python.
Python and Ruby do not have libwhisker so perl has to stick around.
Just use what works and learn them all like i had to.....
peace out.