예제 #1
0
 def test_generateSubnumbers_2lenB(self):
     data = NumberMask(0x1, 4)
     subList = data.generateSubnumbers(3, 0)
     #         print "ret list:", subList
     self.assertEqual(subList,
                      set([SubNumber(0x1, 3, 0),
                           SubNumber(0x1, 4, 0)]))
예제 #2
0
    def findPolysXOR(self,
                     data1,
                     crc1,
                     data2,
                     crc2,
                     dataSize,
                     crcSize,
                     searchRange=0):
        xorData = data1 ^ data2
        xorCRC = crc1 ^ crc2
        if self.progress:
            print "Checking {:X} {:X} xor {:X} {:X} = {:X} {:X}, {} {}".format(
                data1, crc1, data2, crc2, xorData, xorCRC, dataSize, crcSize)

        xorMask = NumberMask(xorData, dataSize)
        crcMask = NumberMask(xorCRC, crcSize)

        retList = []

        subList = xorMask.generateSubnumbers(xorMask.dataSize - searchRange, 0)
        listLen = len(subList)
        ind = 0
        for sub in subList:
            ind += 1
            #             print "Checking subnumber {}".format(sub)
            if self.progress:
                #print "Checking substring {:X}".format(sub.dataNum)
                flush_string("{}/{} checking substring {}\n".format(
                    ind, listLen, sub))

            subMask = sub.toNumberMask()

            #TODO: what is initReg and xorVal for self.crcProc???

            crcList = []
            crcList += self._findBruteForcePoly(subMask, crcMask, False)
            crcList += self._findBruteForcePoly(subMask, crcMask, True)

            polyList = []  # List[ PolyKey ]
            for item in crcList:
                polyList.append(item.getPolyKey())

            polyList += self._findBruteForcePolyReverse(subMask, crcMask)

            if len(polyList) < 1:
                continue
            for key in polyList:
                key.dataPos = sub.pos
                key.dataLen = sub.size
            retList += polyList
#             print "Found sub:", subRet, sub

#         if self.progress:
#             sys.stdout.write("\r")
#             sys.stdout.flush()

        return retList
예제 #3
0
 def test_generateSubnumbers_2pos(self):
     data = NumberMask(0x9, 4)
     subList = data.generateSubnumbers(maxPos=0)
     #         print "ret list:", subList
     self.assertEqual(
         subList,
         set([
             SubNumber(0x1, 1, 0),
             SubNumber(0x1, 2, 0),
             SubNumber(0x1, 3, 0),
             SubNumber(0x9, 4, 0)
         ]))
예제 #4
0
 def test_generateSubnumbers_1(self):
     data = NumberMask(0xF, 4)
     subList = data.generateSubnumbers()
     #         print "ret list:", subList
     self.assertEqual(
         subList,
         set([
             SubNumber(0x1, 1, 0),
             SubNumber(0x3, 2, 0),
             SubNumber(0x7, 3, 0),
             SubNumber(0xF, 4, 0)
         ]))
예제 #5
0
 def test_generateSubnumbers_2(self):
     data = NumberMask(0x9, 4)
     subList = data.generateSubnumbers()
     #         print "ret list:", subList
     self.assertEqual(
         subList,
         set([
             SubNumber(0x0, 1, 1),
             SubNumber(0x0, 2, 1),
             SubNumber(0x1, 1, 0),
             SubNumber(0x1, 2, 0),
             SubNumber(0x1, 3, 0),
             SubNumber(0x2, 2, 2),
             SubNumber(0x4, 3, 1),
             SubNumber(0x9, 4, 0)
         ]))
예제 #6
0
 def test_generateSubnumbers_sufix(self):
     data = NumberMask(0xABCD, 16)
     subList = data.generateSubnumbers(12, 4)
     #         print "ret list:", subList
     self.assertIn(SubNumber(0xABC, 12, 4), subList)
예제 #7
0
 def test_generateSubnumbers_zero(self):
     data = NumberMask(0xF, 0)
     subList = data.generateSubnumbers()
     self.assertEqual(subList, set([]))