## ### # IP: GHIDRA # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. ## # Use the decompiler to generate signatures for the function at the current address, then dump the # signature hashes and debug information to the console # @category: BSim.python import ghidra.app.decompiler.tracking.DecompInterfaceTracking as DecompInterfaceTracking import ghidra.app.decompiler.DecompileOptions as DecompileOptions import generic.lsh.vector.WeightedLSHCosineVectorFactory as WeightedLSHCosineVectorFactory import ghidra.query.GenSignatures as GenSignatures import ghidra.xml.NonThreadedXmlPullParserImpl as NonThreadedXmlPullParserImpl import ghidra.util.xml.SpecXmlUtils as SpecXmlUtils def processFunction(func): decompiler = DecompInterfaceTracking() options = DecompileOptions() decompiler.setOptions(options) decompiler.toggleSyntaxTree(False) decompiler.setSignatureSettings(getSettings()) if not decompiler.openProgram(currentProgram): print "Unable to initialize the Decompiler interface!" print "%s" % decompiler.getLastMessage() return language = currentProgram.getLanguage() sigres = decompiler.debugSignatures(func,10,None) for i,res in enumerate(sigres): buf = java.lang.StringBuffer() sigres.get(i).printRaw(language,buf) print "%s" % buf.toString() decompiler.closeProgram() decompiler.dispose() def getSettings(): vectorFactory = WeightedLSHCosineVectorFactory() id = currentProgram.getLanguageID() defaultWeightsFile = GenSignatures.getWeightsFile(id,id) input = defaultWeightsFile.getInputStream() parser = NonThreadedXmlPullParserImpl(input,"Vector weights parser", SpecXmlUtils.getXmlHandler(),False) vectorFactory.readWeights(parser) input.close() return vectorFactory.getSettings() func = currentProgram.getFunctionManager().getFunctionContaining(currentAddress) if func is None: print "no function at current address" else: processFunction(func)