示例#1
0
 def swizzleUrl(self, url, includeToken=False):
     m = re.Search("^\w+:\/\/.+?(\/.+)", url)
     newUrl = m and m.group(1) or None
     return self.buildUrl(newUrl or url, includeToken)
示例#2
0
    def discover(self,
                 lowball=1,
                 debug=None,
                 length=30,
                 IdentSyncWord=False,
                 ISWsensitivity=4,
                 ISWminpreamble=2,
                 SyncWordMatchList=None,
                 Search=None,
                 RegExpSearch=None):
        '''
        discover() sets lowball mode to the mode requested (length too), and begins to dump packets to the screen.  
                press <enter> to quit, and your radio config will be set back to its original configuration.

            lowball             - lowball level of choosing (see help on lowball)
            debug               - sets _debug to this setting if not None.  
            length              - arbitrary length of bytes we want to see per pseudopacket. (should be enough to identify interesting packets, but not too long)
            IdentSyncWord       - look for preamble in each packet and determine possible sync-words in use
            SyncWordMatchList   - attempt to find *these* sync words (provide a list)
            Search              - byte string to search through each received packet for (real bytes, not hex repr)
            RegExpSearch        - regular expression to search through received bytes (not the hex repr that is printed)

        if IdentSyncWord == True (or SyncWordMatchList != None), returns a dict of unique possible SyncWords identified along with the number of times seen.
        '''
        retval = {}
        oldebug = self._debug

        if SyncWordMatchList != None:
            IdentSyncWord = True

        if IdentSyncWord:
            if lowball <= 1:
                print "Entering Discover mode and searching for possible SyncWords..."
                if SyncWordMatchList != None:
                    print "  seeking one of: %s" % repr(
                        [hex(x) for x in SyncWordMatchList])

            else:
                print "-- lowball too high -- ignoring request to IdentSyncWord"
                print "Entering Discover mode..."
                IdentSyncWord = False

        self.lowball(level=lowball, length=length)
        if debug is not None:
            self._debug = debug

        if Search is not None:
            print "Search:", repr(Search)

        if RegExpSearch is not None:
            print "RegExpSearch:", repr(RegExpSearch)

        print "(press Enter to quit)"
        while not keystop():

            try:
                y, t = self.RFrecv()
                yhex = y.encode('hex')

                print "(%5.3f) Received:  %s" % (t, yhex)
                if RegExpSearch is not None:
                    ynext = y
                    for loop in range(8):
                        if (re.Search(RegExpSearch, ynext) is not None):
                            print "    REG EXP SEARCH SUCCESS:", RegExpSearch
                        ynext = bits.shiftString(ynext, 1)

                if Search is not None:
                    ynext = y
                    for loop in range(8):
                        if (Search in ynext):
                            print "    SEARCH SUCCESS:", Search
                        ynext = bits.shiftString(ynext, 1)

                if IdentSyncWord:
                    #if lowball == 1:
                    #    y = '\xaa\xaa' + y

                    poss = bits.findSyncWord(y, ISWsensitivity, ISWminpreamble)
                    if len(poss):
                        print "  possible Sync Dwords: %s" % repr(
                            [hex(x) for x in poss])
                        for dw in poss:
                            lst = retval.get(dw, 0)
                            lst += 1
                            retval[dw] = lst

                    if SyncWordMatchList is not None:
                        for x in poss:
                            if x in SyncWordMatchList:
                                print "MATCH WITH KNOWN SYNC WORD:" + hex(x)

            except ChipconUsbTimeoutException:
                pass
            except KeyboardInterrupt:
                print "Please press <enter> to stop"

        sys.stdin.read(1)
        self._debug = oldebug
        self.lowballRestore()
        print "Exiting Discover mode..."

        if len(retval) == 0:
            return

        printSyncWords(retval)
        return retval