{"record":{"id":"da2f16fa3e69e50e","repo":"NationalSecurityAgency/ghidra","slug":"could-not-get-md5-on-file-da2f16","errorCode":null,"errorMessage":"Could not get MD5 on file: ","messagePattern":"Could not get MD5 on file: ","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"Ghidra/Features/BSim/ghidra_scripts/GenerateSignatures.py","lineNumber":29,"sourceCode":"# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n##\n#Generate signatures for every function in the current program and write them to an XML file in a user-specified directory\n#@category BSim.Python\n#@runtime Jython\n\nimport java.lang.System as System\nimport java.io.File as File\nimport ghidra.features.bsim.query.FunctionDatabase as FunctionDatabase\nimport ghidra.features.bsim.query.GenSignatures as GenSignatures\nimport java.io.FileWriter as FileWriter\n\ndef run():\n    md5String = currentProgram.getExecutableMD5()\n    if (md5String is None) or (len(md5String) < 10):\n        raise IOException(\"Could not get MD5 on file: \" + currentProgram.getName())\n    basename = \"sigs_\" + md5String\n    System.setProperty(\"ghidra.output\",basename)\n    workingDir = askDirectory(\"GenerateSignatures:\", \"Working Directory\")\n    if not workingDir.isDirectory():\n        popup(\"Must select a working directory\")\n        return\n    outfile = File(workingDir,basename)\n    vectorFactory = FunctionDatabase.generateLSHVectorFactory()\n    gensig = GenSignatures(True)\n    templateName = askString(\"GenerateSignatures:\", \"Database template\", \"medium_nosize\")\n    config = FunctionDatabase.loadConfigurationTemplate(templateName)\n    vectorFactory.set(config.weightfactory, config.idflookup, config.info.settings)\n    gensig.setVectorFactory(vectorFactory)\n    gensig.addExecutableCategories(config.info.execats)\n    gensig.addFunctionTags(config.info.functionTags)\n    gensig.addDateColumnName(config.info.dateColumnName)\n    repo = \"ghidra://localhost/\" + state.getProject().getName()\n    path = GenSignatures.getPathFromDomainFile(currentProgram)","sourceCodeStart":11,"sourceCodeEnd":47,"githubUrl":"https://github.com/NationalSecurityAgency/ghidra/blob/d5f144c24d6bc53c9cbf4448c6d11143e7696206/Ghidra/Features/BSim/ghidra_scripts/GenerateSignatures.py#L11-L47","documentation":"The Jython/Python variant of GenerateSignatures performs the same MD5 check: if currentProgram.getExecutableMD5() is None or has length < 10, it raises IOException. The logic is identical to the Java version but expressed in Jython. This is the Python-script entry point for BSim signature generation.","triggerScenarios":"Running GenerateSignatures.py in the Ghidra Jython script engine where currentProgram.getExecutableMD5() returns None or a string shorter than 10 characters.","commonSituations":"Same as the Java variant: unanalyzed program, synthetic program, corrupted program database, or re-imported listing without MD5 metadata. Python users may additionally hit this if they run the script on a program object that hasn't been fully loaded into the current Ghidra tool context.","solutions":["Run auto-analysis on the current program so the MD5 is computed.","Re-import the original binary to populate the MD5 during import.","Prefer the Java GenerateSignatures.java script if Jython interop issues are suspected.","Check the program metadata via the Ghidra GUI (Program > Program Information) to confirm the MD5 field is populated."],"exampleFix":"# before\nif (md5String is None) or (len(md5String) < 10):\n    raise IOException(\"Could not get MD5 on file: \" + currentProgram.getName())\n#\n# after — guard with a user-friendly popup\nif (md5String is None) or (len(md5String) < 10):\n    popup(\"Program has no MD5. Run auto-analysis or re-import first.\")\n    return","handlingStrategy":"validation","validationCode":"md5String = currentProgram.getExecutableMD5()\nif md5String is None or len(md5String) < 10:\n    popup(\"Program has no MD5. Run auto-analysis or re-import the binary first.\")\n    return","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Run auto-analysis before executing BSim Python scripts.","Verify MD5 is populated via the Program Information dialog.","Prefer the Java GenerateSignatures script for better error handling if Jython interop is unreliable.","Add a guard popup at the top of run() to avoid opaque exceptions."],"tags":["bsim","signatures","md5","jython","python","program-metadata"],"backgroundTag":null,"analyzedSha":"d5f144c24d6bc53c9cbf4448c6d11143e7696206","analyzedAt":"2026-08-14T01:00:57.564Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}