Example #1
0
 def test_bytelen(self):
     test1 = -16
     test1_res = 2
     self.assertEqual(bytelen(test1), test1_res)
     test2 = 1
     test2_res = 1
     self.assertEqual(bytelen(test2), test2_res)
     test3 = 15
     test3_res = 1
     self.assertEqual(bytelen(test3), test3_res)
Example #2
0
 def test_bytelen(self):
     test1 = -16
     test1_res = 2
     self.assertEqual(bytelen(test1), test1_res)
     test2 = 1
     test2_res = 1
     self.assertEqual(bytelen(test2), test2_res)
     test3 = 15
     test3_res = 1
     self.assertEqual(bytelen(test3), test3_res)
Example #3
0
def printdetails(target): # TODO: Fix this fugly method
    '''
    Prints details about a target
    '''
    term.info('The target module contains the following signatures:')
    term.separator()
    print('\tVersions:\t' + ', '.join(target['versions']).rstrip(', '))
    print('\tArchitectures:\t' + ', '
          .join(target['architectures']).rstrip(', '))
    for signature in target['signatures']:
        offsets = '\n\t\tOffsets:\t'
        for offset in signature['offsets']:
            offsets += hex(offset)
            if not offset is signature['offsets'][-1]: offsets += ', '
        print(offsets)
        sig = '\t\tSignature:\t0x'
        ioffs = 0
        patch = 0
        poffs = 0
        for chunk in signature['chunks']:
            diff = chunk['internaloffset'] - util.bytelen(chunk['chunk']) - 1 - ioffs
            sig += '__' * diff
            ioffs = chunk['internaloffset']
            sig += '{0:x}'.format(chunk['chunk'])
            try:
                patch = chunk['patch']
                poffs = chunk['patchoffset']
            except KeyError: pass
        print(sig)
        print('\t\tPatch:\t\t{0:#x}'.format(patch))
        print('\t\tPatch offset:\t{0:#x}'.format(poffs))
        
    term.separator()
Example #4
0
def siglen(l):
    '''
    Accepts dicts with key 'internaloffset', and calculates the length of the 
    total signature in number of bytes
    '''
    index = value = 0
    for i in range(len(l)):
        if l[i]['internaloffset'] > value:
            value = l[i]['internaloffset']
            index = i
    # Must decrement bytelen with one since byte positions start at zero
    return util.bytelen(l[index]['chunk']) - 1 + value