From 79c4de2a0f32604f0ae6a4e4845bdac8f44b6e81 Mon Sep 17 00:00:00 2001 From: "dn337t@gmail.com" Date: Wed, 20 Jun 2012 15:07:30 +0000 Subject: [PATCH] made tools/findbits.py importable as a Python module --- tools/findbits.py | 72 +++++++++++++++++++++++++---------------------- 1 file changed, 38 insertions(+), 34 deletions(-) diff --git a/tools/findbits.py b/tools/findbits.py index f5d2dbd6..03e0c4e0 100755 --- a/tools/findbits.py +++ b/tools/findbits.py @@ -75,39 +75,43 @@ def domatch(number,binary): print ' Reverse: (%s)' % reversed, search(inverted,reversed) -if(len(sys.argv) < 3): - print - print '\t'+sys.argv[0] + ' - Search bitstream for a known number' - print - print 'Usage: ' + sys.argv[0] + ' ' - print - print '\tNUMBER will be converted to it\'s BINARY equivalent for all valid' - print '\tinstances of BINARY, OCTAL, DECIMAL and HEX, and the bitstream' - print '\tand it\'s inverse will be searched for a pattern match. Note that' - print '\tNUMBER must be specified in BINARY to match leading zeros.' - print - print 'Example:' - print - print '\tfindbits.py 73 0110010101110011' - print - os._exit(True) +def main(): + if(len(sys.argv) < 3): + print + print '\t'+sys.argv[0] + ' - Search bitstream for a known number' + print + print 'Usage: ' + sys.argv[0] + ' ' + print + print '\tNUMBER will be converted to it\'s BINARY equivalent for all valid' + print '\tinstances of BINARY, OCTAL, DECIMAL and HEX, and the bitstream' + print '\tand it\'s inverse will be searched for a pattern match. Note that' + print '\tNUMBER must be specified in BINARY to match leading zeros.' + print + print 'Example:' + print + print '\tfindbits.py 73 0110010101110011' + print + os._exit(True) -bases= { - 2:'BINARY', - 8:'OCTAL', - 10:'DECIMAL', - 16:'HEX', - } + bases= { + 2:'BINARY', + 8:'OCTAL', + 10:'DECIMAL', + 16:'HEX', + } -for base in 2,8,10,16: - try: - number= int(sys.argv[1],base) - print - print 'Trying', bases[base] - # do BINARY as specified to preserve leading zeros - if base == 2: - domatch(sys.argv[1],sys.argv[2]) - else: - domatch(binstring(number),sys.argv[2]) - except: - continue + for base in 2,8,10,16: + try: + number= int(sys.argv[1],base) + print + print 'Trying', bases[base] + # do BINARY as specified to preserve leading zeros + if base == 2: + domatch(sys.argv[1],sys.argv[2]) + else: + domatch(binstring(number),sys.argv[2]) + except: + continue + +if __name__ == '__main__': + main() -- 2.39.5