Views
No views yet

1from transformers import AutoTokenizer, AutoModelForCausalLM
2import torch
3
4model_path = 'LLM4Binary/llm4decompile-1.3b-v1.5' # V1.5 Model
5tokenizer = AutoTokenizer.from_pretrained(model_path)
6model = AutoModelForCausalLM.from_pretrained(model_path,torch_dtype=torch.bfloat16).cuda()
7
8from transformers import AutoTokenizer, AutoModelForCausalLM
9import torch
10import os
11
12asm_func = """
13char * func0(char **param_1,int param_2)
14
15{
16 char **ppcVar1;
17 char *__s;
18 size_t sVar2;
19 int iVar3;
20 char *pcVar4;
21
22 pcVar4 = "";
23 if (0 < param_2) {
24 iVar3 = 0;
25 ppcVar1 = param_1 + (ulong)(param_2 - 1) + 1;
26 do {
27 __s = *param_1;
28 sVar2 = strlen(__s);
29 if (iVar3 < (int)sVar2) {
30 pcVar4 = __s;
31 iVar3 = (int)sVar2;
32 }
33 param_1 = param_1 + 1;
34 } while (param_1 != ppcVar1);
35 }
36 return pcVar4;
37}
38"""
39
40before = f"# This is the assembly code:\n"#prompt
41after = "\n# What is the source code?\n"#prompt
42asm_func = before+asm_func.strip()+after
43model_path = "Neo111x/falcon3-decompiler-3b"
44tokenizer = AutoTokenizer.from_pretrained(model_path)
45model = AutoModelForCausalLM.from_pretrained(model_path, torch_dtype="auto", device_map="auto").to("cuda:0")
46
47inputs = tokenizer(asm_func, return_tensors="pt").to("cuda:0")
48with torch.no_grad():
49 outputs = model.generate(**inputs, max_new_tokens=2048)### max length to 4096, max new tokens should be below the range
50c_func_decompile = tokenizer.decode(outputs[0][len(inputs[0]):-1])
51
52# Note only decompile one function, where the original file may contain multiple functions
53
54print(f'decompiled function:\n{c_func_decompile}')