Source

simpliFiRE.IDAscope / idascope / core / structures / CryptoSignatureHit.py

#!/usr/bin/python
########################################################################
# Copyright (c) 2012
# Daniel Plohmann <daniel.plohmann<at>gmail<dot>com>
# Alexander Hanel <alexander.hanel<at>gmail<dot>com>
# All rights reserved.
########################################################################
#
#  This file is part of IDAscope
#
#  IDAscope is free software: you can redistribute it and/or modify it
#  under the terms of the GNU General Public License as published by
#  the Free Software Foundation, either version 3 of the License, or
#  (at your option) any later version.
#
#  This program is distributed in the hope that it will be useful, but
#  WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
#  General Public License for more details.
#
#  You should have received a copy of the GNU General Public License
#  along with this program.  If not, see
#  <http://www.gnu.org/licenses/>.
#
########################################################################

class CryptoSignatureHit():
    """
    This class is an information container for a signature match as generated by I{CryptoIdentifier}.
    """

    def __init__(self, start_address, names, match):
        self.start_address = start_address
        self.signature_names = names
        self.matched_signature = match
        # code refs are tuples (int, boolean)
        # int designates the src of the ref
        # boolean designates if it is an in-code reference, e.g. within a mov/push instruction or similar
        self.code_refs_to = []

    def __str__(self):
        """
        Convenience function.
        @return: a nice string representation for this object
        """
        return "0x%x (%d): %s" % (self.start_address, len(self.matched_signature), ", ".join(self.signature_names))

    def __lt__(self, other):
        """
        Convenience function for ordering.
        @param other: another I{CryptoSignatureHit}
        @type other: I{CryptoSignatureHit}
        @return: less if start addres is less than of the other
        """
        return self.start_address < other.start_address