Views
No views yet

Qwen/Qwen2.5-Coder-7B-Instruct. It was fine-tuned with QLoRA to generate
conservative semantic JSON patches from IDA/Hex-Rays-style pseudocode.sub_401000, a1, v3, casts, pointer
offsets, and weak type information.1ReCopilot: Reverse Engineering Copilot in Binary Analysis
2arXiv: 2505.16366
3https://arxiv.org/abs/2505.163661open-source C/C++ source
2-> debug build with DWARF/symbols
3-> stripped binary
4-> IDA/Hex-Rays pseudocode export
5-> ground-truth extraction from debug metadata
6-> supervised fine-tuning JSONL1{
2 "function": {
3 "ea": "0x401230",
4 "old_name": "sub_401230",
5 "suggested_name": "aes_cbc_encrypt_buffer",
6 "confidence": 0.88,
7 "reason": "Matched stripped decompiler function to debug-symbol ground truth at the same address."
8 },
9 "arguments": [
10 {
11 "old_name": "a1",
12 "new_name": "ctx",
13 "type": "struct AES_ctx *",
14 "confidence": 0.82
15 }
16 ],
17 "locals": [],
18 "structs": [],
19 "comments": [],
20 "warnings": []
21}1<TASK>recover_semantic_patch</TASK>
2<TARGET>
3EA: 0x401230
4Name: sub_401230
5Pseudocode:
6...
7</TARGET>
8<EVIDENCE>
9Strings: [...]
10Callees: [...]
11Callers: [...]
12Imports: [...]
13Offset accesses: [...]
14Data flow: [...]
15</EVIDENCE>
16<SCHEMA>
17{"function":{"ea":"0x401230","old_name":"sub_401230","suggested_name":"","confidence":0.0,"reason":""},"arguments":[],"locals":[],"structs":[],"comments":[],"warnings":[]}
18</SCHEMA>
19Return only valid JSON. Be conservative. Do not invent facts.1from peft import PeftModel
2from transformers import AutoModelForCausalLM, AutoTokenizer, BitsAndBytesConfig
3
4base = "Qwen/Qwen2.5-Coder-7B-Instruct"
5adapter = "Keowu/monare-re-qwen25-coder-7b"
6
7quant_config = BitsAndBytesConfig(load_in_4bit=True)
8
9tokenizer = AutoTokenizer.from_pretrained(base, trust_remote_code=True)
10
11model = AutoModelForCausalLM.from_pretrained(
12 base,
13 device_map="auto",
14 quantization_config=quant_config,
15 trust_remote_code=True,
16)
17
18model = PeftModel.from_pretrained(model, adapter)
19model.eval()
20
21import torch
22
23messages = [
24 {
25 "role": "system",
26 "content": """You are a reverse engineering assistant specialized in IDA
27 Hex-Rays pseudocode. Return only valid JSON. Be conservative."""
28 },
29 {
30 "role": "user",
31 "content": """
32 <TASK>recover_semantic_patch</TASK>
33 <TARGET>
34 EA: 0x401230
35 Name: sub_401230
36 Pseudocode:
37 int __fastcall sub_401230(__int64 a1, char *a2, unsigned int a3)
38 {
39 FILE *v3;
40 int result;
41
42 v3 = fopen(a2, "rb");
43 if (!v3)
44 return -1;
45 result = fread((void *)(a1 + 32), 1u, a3, v3);
46 fclose(v3);
47 *(_DWORD *)(a1 + 16) = result;
48 return result;
49 }
50 </TARGET>
51 <EVIDENCE>
52 Strings: ["rb"]
53 Callees: [{"name":"fopen"},{"name":"fread"},{"name":"fclose"}]
54 Callers: []
55 Imports: ["fopen","fread","fclose"]
56 Offset accesses: ["a1 + 32","a1 + 16"]
57 Data flow: []
58 </EVIDENCE>
59 <SCHEMA>
60 {"function":
61 {"ea":"0x401230","old_name":"sub_401230","suggested_name":"","confidence":0.0,
62 "reason":""},"arguments":[],"locals":[],"structs":[],"comments":[],"warnings":
63 []}
64 </SCHEMA>
65 Return only valid JSON. Be conservative. Do not invent facts."""
66 }
67 ]
68
69inputs = tokenizer.apply_chat_template(
70 messages,
71 tokenize=True,
72 add_generation_prompt=True,
73 return_tensors="pt",
74).to(model.device)
75
76with torch.no_grad():
77 outputs = model.generate(
78 input_ids=inputs,
79 max_new_tokens=512,
80 temperature=0.1,
81 do_sample=False,
82 eos_token_id=tokenizer.eos_token_id,
83 )
84
85print(tokenizer.decode(outputs[0][inputs.shape[-1]:], skip_special_tokens=True))