{"data":{"slug":"albertan017-llm4decompile","name":"LLM4Decompile","tagline":"Decompiling Binary Code with Large Language Models","github_url":"https://github.com/albertan017/LLM4Decompile","owner":"albertan017","repo":"LLM4Decompile","owner_avatar_url":"https://avatars.githubusercontent.com/u/142430876?v=4","primary_language":"Python","stars":6965,"forks":546,"topics":["binary","decompile","large-language-models","reverse-engineering"],"archived":false,"github_pushed_at":"2026-02-12T03:02:03+00:00","maintenance_label":"Slowing","stars_delta_30d":205,"url":"https://www.graphcanon.com/tools/albertan017-llm4decompile","markdown_url":"https://www.graphcanon.com/tools/albertan017-llm4decompile.md","api_url":"https://www.graphcanon.com/api/graphcanon/tools/albertan017-llm4decompile","graph_url":"https://www.graphcanon.com/api/graphcanon/graph?tool=albertan017-llm4decompile","description":"Reverse Engineering: Decompiling Binary Code with Large Language Models","homepage_url":"https://aclanthology.org/2024.emnlp-main.203","license":"MIT","open_issues":46,"watchers":79,"ai_summary":"A tool that uses large language models to reverse engineer binary code into assembly instructions and potentially source code.","readme_excerpt":"## Quick Start\n\n\n\n**Setup:** Please use the script below to install the necessary environment.\n```\ngit clone https://github.com/albertan017/LLM4Decompile.git\ncd LLM4Decompile\nconda create -n 'llm4decompile' python=3.9 -y\nconda activate llm4decompile\npip install -r requirements.txt\n```\n\nHere is an example of how to use our model (Revised for V1.5. For previous models, please check the corresponding model page at HF).\nNote: **Replace the \"func0\" with the function name you want to decompile**.\n\n**Preprocessing:** Compile the C code into binary, and disassemble the binary into assembly instructions.\n```python\nimport subprocess\nimport os\nfunc_name = 'func0'\nOPT = [\"O0\", \"O1\", \"O2\", \"O3\"]\nfileName = 'samples/sample' #'path/to/file'\nfor opt_state in OPT:\n    output_file = fileName +'_' + opt_state\n    input_file = fileName+'.c'\n    compile_command = f'gcc -o {output_file}.o {input_file} -{opt_state} -lm'#compile the code with GCC on Linux\n    subprocess.run(compile_command, shell=True, check=True)\n    compile_command = f'objdump -d {output_file}.o > {output_file}.s'#disassemble the binary file into assembly instructions\n    subprocess.run(compile_command, shell=True, check=True)\n    \n    input_asm = ''\n    with open(output_file+'.s') as f:#asm file\n        asm= f.read()\n        if '<'+func_name+'>:' not in asm: #IMPORTANT replace func0 with the function name\n            raise ValueError(\"compile fails\")\n        asm = '<'+func_name+'>:' + asm.split('<'+func_name+'>:')[-1].split('\\n\\n')[0] #IMPORTANT replace func0 with the function name\n        asm_clean = \"\"\n        asm_sp = asm.split(\"\\n\")\n        for tmp in asm_sp:\n            if len(tmp.split(\"\\t\"))<3 and '00' in tmp:\n                continue\n            idx = min(\n                len(tmp.split(\"\\t\")) - 1, 2\n            )\n            tmp_asm = \"\\t\".join(tmp.split(\"\\t\")[idx:])  # remove the binary code\n            tmp_asm = tmp_asm.split(\"#\")[0].strip()  # remove the comments\n            asm_clean += tmp_asm + \"\\n\"\n    input_asm = asm_clean.strip()\n    before = f\"# This is the assembly code:\\n\"#prompt\n    after = \"\\n# What is the source code?\\n\"#prompt\n    input_asm_prompt = before+input_asm.strip()+after\n    with open(fileName +'_' + opt_state +'.asm','w',encoding='utf-8') as f:\n        f.write(input_asm_prompt)\n```\n\nAssembly instructions should be in the format:\n\n<FUNCTION_NAME>:\\nOPERATIONS\\nOPERATIONS\\n\n\nTypical assembly instructions may look like this:\n```\n<func0>:\nendbr64\nlea    (%rdi,%rsi,1),%eax\nretq\n```\n\n\n**Decompilation:** Use LLM4Decompile to translate the assembly instructions into C:\n```python\nfrom transformers import AutoTokenizer, AutoModelForCausalLM\nimport torch\n\nmodel_path = 'LLM4Binary/llm4decompile-6.7b-v1.5' # V1.5 Model\ntokenizer = AutoTokenizer.from_pretrained(model_path)\nmodel = AutoModelForCausalLM.from_pretrained(model_path,torch_dtype=torch.bfloat16).cuda()\n\nwith open(fileName +'_' + OPT[0] +'.asm','r') as f:#optimization level O0\n    asm_func = f.read()\ninputs = tokenizer(asm_func, return_tensors=\"pt\").to(model.device)\nwith torch.no_grad():\n    outputs = model.generate(**inputs, max_new_tokens=2048)### max length to 4096, max new tokens should be below the range\nc_func_decompile = tokenizer.decode(outputs[0][len(inputs[0]):-1])\n\nwith open(fileName +'.c','r') as f:#original file\n    func = f.read()\n\nprint(f'original function:\\n{func}')# Note we only decompile one function, where the original file may contain multiple functions\nprint(f'decompiled function:\\n{c_func_decompile}')\n```\n\n---\n\n# build docker\ndocker build -t llm4decompile .\n\n---\n\n# run docker with GPU\ndocker run --gpus all -it --name llm4decompile llm4decompile /bin/bash\n\n---\n\n## License\nThis code repository is licensed under the MIT and DeepSeek License.","github_created_at":"2024-02-28T03:16:44+00:00","created_at":"2026-07-07T17:34:33.339574+00:00","updated_at":"2026-08-17T12:00:56.824146+00:00","categories":[{"slug":"llm-frameworks","name":"LLM Frameworks","url":"https://www.graphcanon.com/categories/llm-frameworks","markdown_url":"https://www.graphcanon.com/categories/llm-frameworks.md","api_url":"https://www.graphcanon.com/api/graphcanon/categories/llm-frameworks"}],"tags":[{"slug":"binary","name":"binary"},{"slug":"decompile","name":"decompile"},{"slug":"large-language-models","name":"large language models"},{"slug":"reverse-engineering","name":"reverse-engineering"}],"trust":{"provenance":{"is_fork":false,"github_id":764418725,"owner_type":"User","methodology":"github_public_v1","parent_repo":null,"near_duplicate_slugs":[]},"computed_at":"2026-08-17T12:00:55.930Z","maintenance":{"label":"Slowing","score":36,"methodology":"github_public_v1","releases_90d":0,"days_since_push":186,"last_release_at":null,"stars_delta_30d":205,"open_issues_delta_30d":0},"security_summary":{"status":"findings","scanner":"osv@v1","low_count":41,"high_count":0,"last_scan_at":"2026-07-11T11:03:34.008Z","medium_count":0,"scan_profile":"deps","critical_count":0}},"capability_facts":{"scan":{"source":"repo_scan","observed_at":"2026-08-17T12:00:56.426Z"},"deploy":{"source":"dockerfile:Dockerfile","self_host":true,"observed_at":"2026-08-17T12:00:56.426Z","managed_saas":false},"languages":{"value":["python"],"source":"github.language","observed_at":"2026-08-17T12:00:56.426Z"},"has_docker":{"value":true,"source":"dockerfile:Dockerfile","observed_at":"2026-08-17T12:00:56.426Z"},"license_spdx":{"value":"MIT","source":"github.license","observed_at":"2026-08-17T12:00:56.426Z"}},"decision_facts":{"hosting":null,"pricing":{"model":"freemium","summary":"The tool itself is open-source under the MIT license, but using it effectively may require access to specific large language models that could have associated costs."},"requirements":{"notes":["Requires a GPU for optimal performance with the specified model."],"min_ram_gb":16,"requires_docker":false},"constraints":{"min_ram_gb":16,"pricing_model":"freemium","requires_docker":false},"when_to_use":["When you need a tool that leverages advanced language models for decompiling binaries more effectively than traditional methods.","If your project involves working with x86 or similar architectures where the conversion from assembly to higher-level languages is critical."],"when_not_to_use":["Avoid this tool if you require high precision in recreating exact source code, especially for heavily optimized binaries that lose contextual information during compilation.","Do not use LLM4Decompile when working with less common architectures (e.g., RISC-V) unless explicitly supported or tested by the model."],"source":"enrich:decision_facts","observed_at":"2026-07-12T15:19:09.540Z"},"constraint_facets":{"min_ram_gb":16,"pricing_model":"freemium","requires_docker":false},"decision_summary":[{"label":"Pricing","value":"freemium - The tool itself is open-source under the MIT license, but using it effectively may require access to specific large language models that could have associated costs."},{"label":"Requirements","value":"Min 16 GB RAM; Requires a GPU for optimal performance with the specified model."},{"label":"Adopt for","value":"LLM4Decompile uses large language models to reverse engineer binary code into assembly instructions and potentially source code."}]}}