tools scripts: fix mix of spaces & tabs

This commit is contained in:
Philippe Teuwen 2019-03-09 10:52:45 +01:00
commit bcb33ca5ef
7 changed files with 214 additions and 214 deletions

View file

@ -25,77 +25,77 @@ import os
# invert binary string
def invert(data):
return ''.join('0' if c == '1' else '1' for c in data)
return ''.join('0' if c == '1' else '1' for c in data)
# do the actual search
def search(target,data):
location = data.find(target)
if location >= 0:
print '*** Match at bit %d:' % location,
print '%s<%s>%s' % (data[:location],target,data[location+len(target):])
else:
print 'Not found'
location = data.find(target)
if location >= 0:
print '*** Match at bit %d:' % location,
print '%s<%s>%s' % (data[:location],target,data[location+len(target):])
else:
print 'Not found'
# convert integer to binary string
def binstring(number):
return bin(number)[2:] if number > 0 else ''
return bin(number)[2:] if number > 0 else ''
# reverse string order
def stringreverse(data):
return data[::-1]
return data[::-1]
# match forward, backward and inverted
def domatch(binary,number):
reversed= stringreverse(number)
inverted= invert(binary)
reversed= stringreverse(number)
inverted= invert(binary)
print ' Forward: (%s)' % number,
search(binary,number)
print ' Reverse: (%s)' % reversed,
search(binary,reversed)
print ' Inverse: (%s)' % inverted
print ' Forward: (%s)' % number,
search(inverted,number)
print ' Reverse: (%s)' % reversed,
search(inverted,reversed)
print ' Forward: (%s)' % number,
search(binary,number)
print ' Reverse: (%s)' % reversed,
search(binary,reversed)
print ' Inverse: (%s)' % inverted
print ' Forward: (%s)' % number,
search(inverted,number)
print ' Reverse: (%s)' % reversed,
search(inverted,reversed)
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] + ' <NUMBER> <BITSTREAM>'
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)
if(len(sys.argv) < 3):
print
print '\t'+sys.argv[0] + ' - Search bitstream for a known number'
print
print 'Usage: ' + sys.argv[0] + ' <NUMBER> <BITSTREAM>'
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, base_name in sorted(bases.iteritems()):
try:
number= int(sys.argv[1],base)
print
print 'Trying', base_name
# 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, base_name in sorted(bases.iteritems()):
try:
number= int(sys.argv[1],base)
print
print 'Trying', base_name
# 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()
main()