{"record":{"id":"e34a4401519ca693","repo":"NationalSecurityAgency/ghidra","slug":"could-not-get-md5-on-file","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.java","lineNumber":38,"sourceCode":"import java.io.*;\nimport java.util.Iterator;\n\nimport generic.lsh.vector.LSHVectorFactory;\nimport ghidra.app.script.GhidraScript;\nimport ghidra.features.bsim.query.FunctionDatabase;\nimport ghidra.features.bsim.query.GenSignatures;\nimport ghidra.features.bsim.query.client.Configuration;\nimport ghidra.features.bsim.query.description.DescriptionManager;\nimport ghidra.program.model.listing.Function;\nimport ghidra.program.model.listing.FunctionManager;\n\npublic class GenerateSignatures extends GhidraScript {\n\n\t@Override\n\tpublic void run() throws Exception {\n\t\tfinal String md5string = currentProgram.getExecutableMD5();\n\t\tif ((md5string == null) || (md5string.length() < 10)) {\n\t\t\tthrow new IOException(\"Could not get MD5 on file: \" + currentProgram.getName());\n\t\t}\n\t\tfinal String basename = \"sigs_\" + md5string;\n\t\tSystem.setProperty(\"ghidra.output\", basename); // Inform parallel controller of output name\n\t\tFile file = null;\n\t\t// This form of askString will work for both standalone execution or for parallel\n\t\tfinal File workingdir = askDirectory(\"GenerateSignatures:\", \"Working directory\");\n\t\tif (!workingdir.isDirectory()) {\n\t\t\tpopup(\"Must select a working directory!\");\n\t\t\treturn;\n\t\t}\n\t\tfile = new File(workingdir, basename);\n\n\t\tfinal LSHVectorFactory vectorFactory = FunctionDatabase.generateLSHVectorFactory();\n\t\tfinal GenSignatures gensig = new GenSignatures(true);\n\t\ttry {\n\t\t\tfinal String templatename =\n\t\t\t\taskString(\"GenerateSignatures:\", \"Database template\", \"medium_nosize\");\n\t\t\tfinal Configuration config = FunctionDatabase.loadConfigurationTemplate(templatename);","sourceCodeStart":20,"sourceCodeEnd":56,"githubUrl":"https://github.com/NationalSecurityAgency/ghidra/blob/d5f144c24d6bc53c9cbf4448c6d11143e7696206/Ghidra/Features/BSim/ghidra_scripts/GenerateSignatures.java#L20-L56","documentation":"GenerateSignatures GhidraScript checks currentProgram.getExecutableMD5(); if null or shorter than 10 characters it throws IOException because signature generation requires a valid MD5 to name and key the output. Without the MD5 the BSim signature file cannot be reliably associated with the program.","triggerScenarios":"Running GenerateSignatures.run() where currentProgram.getExecutableMD5() returns null or a string with length < 10. This happens before any signature generation or file I/O.","commonSituations":"The program was imported but never analyzed (MD5 computed during import/analysis); the program file was created from a synthetic/empty binary that has no meaningful hash; the program database is corrupted and the MD5 field is missing; the program was imported from a format that doesn't populate the MD5 metadata.","solutions":["Run auto-analysis on the program first (Analysis > Auto Analyze) so the MD5 and other metadata are computed and stored.","Re-import the original binary file so the importer computes the MD5 during import.","Verify the program is backed by a real binary and not a synthetic/empty program created in the listing editor.","If the binary is legitimately hash-less, populate the MD5 programmatically via program.setExecutableMD5() before running the script."],"exampleFix":"// before\nString md5string = currentProgram.getExecutableMD5();\nif ((md5string == null) || (md5string.length() < 10)) {\n    throw new IOException(\"Could not get MD5 on file: \" + currentProgram.getName());\n}\n//\n// after — ensure MD5 exists before running the script\nString md5string = currentProgram.getExecutableMD5();\nif (md5string == null || md5string.length() < 10) {\n    popup(\"Program has no MD5. Run auto-analysis or re-import the binary first.\");\n    return;\n}","handlingStrategy":"validation","validationCode":"String md5 = currentProgram.getExecutableMD5();\nif (md5 == null || md5.length() < 10) {\n    popup(\"This program has no MD5 hash. Run auto-analysis or re-import the binary before generating signatures.\");\n    return;\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always run auto-analysis before BSim signature generation scripts.","Re-import binaries from their original files to ensure MD5 metadata is populated.","Check program metadata (Program > Program Information) for the MD5 field before scripting.","Guard the script entry point with an MD5 presence check and a user-friendly message."],"tags":["bsim","signatures","md5","ghidra-script","program-metadata"],"backgroundTag":null,"analyzedSha":"d5f144c24d6bc53c9cbf4448c6d11143e7696206","analyzedAt":"2026-08-14T01:00:57.564Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}