Exemplo n.º 1
0
def getFuncHash(f):
    if DEBUG > 0:
        print("DEBUG: processing: %s at %s" % (f.getName(), f.getEntryPoint()))
    fname = "%s@%s" % (f.getName(), f.getEntryPoint())
    serv = FidService()
    fhash = serv.hashFunction(f)
    if not fhash:
        #print("%s at %s: null function error"%(f.getName(),f.getEntryPoint()))
        return "***"
    else:
        #return fhash.toString()
        # Some values will be negative. Make them positive.
        return hex(fhash.getFullHash() & 0xffffffffffffffff)[2:-1]
Exemplo n.º 2
0
def generate_function_ids():
    # type (None) -> tuple (str, str, str)
    functions = fm.getFunctions(True)
    for function in functions:
        try:
            function_id = (FidService().hashFunction(function).toString().
                           encode("utf-8").split(":")[1].split("(")[0].strip())
        except:
            pass
        else:
            yield (function.getName(), function.getEntryPoint(),
                   "0x" + function_id)
Exemplo n.º 3
0
def generate_function_id_hash(db):
    # type (FunctionIdDb) -> None
    fn = getFunctionContaining(currentAddress)
    fn_address = fn.getBody().getMinAddress()
    try:
        function_id = (
            FidService()
            .hashFunction(fn)
            .toString()
            .encode("utf-8")
            .split(":")[1]
            .split("(")[0]
            .strip()
        )
    except:
        print(
            "[!] Cannot generate a FunctionID hash from function %s @ %s"
            % (fn_address, fn.getName())
        )
    else:
        db.update_database([{"0x" + function_id: fn.getName()}])
Exemplo n.º 4
0
    def _static_functions(
            self) -> List["ghidra.program.database.function.FunctionDB"]:
        """
        Obtains the static functions defined by the FID service.
        """
        from ghidra.feature.fid.service import FidService

        fid = FidService()
        language = self._program.getLanguage()
        if not fid.canProcess(language):
            return []

        service = fid.openFidQueryService(language, False)
        try:
            results = fid.processProgram(self._program, service,
                                         fid.getDefaultScoreThreshold(),
                                         self._monitor)
            return [result.function for result in results]
        finally:
            service.close()
Exemplo n.º 5
0
# Gets the hash of the current function. Useful for function matching.

# DISCLAIMER: This is meant to be an example. You likely want to use this process in your own script

#@category Tate.AutoScripts

from ghidra.feature.fid.service import FidService

fs = FidService()

func = getFunctionAt(currentAddress)

hashs = fs.hashFunction(func)

print(
    "\nFull Hash: {}, \nCode Units used to get fullhash: {}, \nAdditional Code Units: {}, \nSpecificHash: {}\n"
).format(hex(hashs.getFullHash()), hex(hashs.getCodeUnitSize()),
         hex(hashs.getSpecificHashAdditionalSize()),
         hex(hashs.getSpecificHash()))