File size: 7,312 Bytes
08fedc0
cacf2b7
2c55bb6
b955ca1
08fedc0
7308fb9
536fde5
 
08fedc0
7308fb9
 
aa62017
7308fb9
aa62017
 
f406c8a
77bd6a8
536fde5
 
 
 
 
 
 
 
 
08fedc0
3116465
78a1e59
000c947
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8f0cd8c
 
 
 
 
 
 
 
 
 
 
 
 
 
573f369
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ca32878
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8f0cd8c
3116465
02ecf35
08fedc0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
import gradio as gr
import spaces
import torch
from transformers import AutoTokenizer, AutoModelForCausalLM

model_path = 'LLM4Binary/llm4decompile-9b-v2' # V2 Model
tokenizer = AutoTokenizer.from_pretrained(model_path)
model = AutoModelForCausalLM.from_pretrained(model_path, torch_dtype=torch.bfloat16).cuda()

description = f"""
# LLM4Decompile 9B V2

This is a space for testing the [LLM4Decompile 9B V2 model](https://huggingface.co/LLM4Binary/llm4decompile-9b-v2).  It expects to be given a decompiled function output by Ghidra.  I simply copy and paste from the Ghidra GUI, but this is not the method recommended by the official model page, which could influence performance.  I am not affiliated with the authors.
"""

@spaces.GPU(duration=120)
def predict(input_asm):
    before = f"# This is the assembly code:\n"#prompt
    after = "\n# What is the source code?\n"#prompt
    input_prompt = before+input_asm.strip()+after
    
    inputs = tokenizer(input_prompt, return_tensors="pt").to(model.device)
    with torch.no_grad():
        outputs = model.generate(**inputs, max_new_tokens=2048)### max length to 4096, max new tokens should be below the range
    c_func_decompile = tokenizer.decode(outputs[0][len(inputs[0]):-1])
    return c_func_decompile

demo = gr.Interface(fn=predict,
                    description=description,
                    examples=["""undefined4 func0(float param_1,long param_2,int param_3)
{
  int local_28;
  int local_24;
  
  local_24 = 0;
  do {
    local_28 = local_24;
    if (param_3 <= local_24) {
      return 0;
    }
    while (local_28 = local_28 + 1, local_28 < param_3) {
      if ((double)((ulong)(double)(*(float *)(param_2 + (long)local_24 * 4) -
                                  *(float *)(param_2 + (long)local_28 * 4)) &
                  SUB168(_DAT_00402010,0)) < (double)param_1) {
        return 1;
      }
    }
    local_24 = local_24 + 1;
  } while( true );
}""","""
undefined8 __cdecl FUN_004025f0(byte *param_1,int param_2)

{
  do {
    *param_1 = ~*param_1;
    *param_1 = *param_1 - 0x37;
    *param_1 = *param_1 + 1;
    param_1 = param_1 + 1;
    param_2 = param_2 + -1;
  } while (param_2 != 0);
  return 0x3632000137;
}

""","""
void __thiscall FUN_00404f30(void *this,char param_1,uint param_2)

{
  char *pcVar1;
  
  if ((param_1 != '\0') && (0xf < *(uint *)((int)this + 0x18))) {
    pcVar1 = *(char **)((int)this + 4);
    if (param_2 != 0) {
      std::_Traits_helper::copy_s<>((char *)((int)this + 4),0x10,pcVar1,param_2);
    }
    FUN_00405320(pcVar1);
  }
  *(undefined4 *)((int)this + 0x18) = 0xf;
  std::basic_string<>::_Eos((basic_string<> *)this,param_2);
  return;
}

""","""
char __thiscall
FUN_008a28f0(void *param_1_00,FMOD_VECTOR *param_1,undefined4 ****param_2,undefined4 param_3,
            undefined4 param_4,float param_5)

{
  char cVar1;
  undefined4 uVar2;
  undefined4 ****ppppuVar3;
  char *unaff_EBX;
  FMOD_VECTOR *pFVar4;
  char *pcVar5;
  undefined4 uVar6;
  FMOD_VECTOR *local_a8;
  undefined4 ***local_a4;
  undefined4 local_a0;
  uint uStack_90;
  basic_string<> abStack_8c [4];
  basic_string<> local_88 [28];
  basic_string<> abStack_6c [4];
  undefined4 ***apppuStack_68 [5];
  uint local_54 [8];
  basic_string<> abStack_34 [28];
  void *local_18;
  int iStack_14;
  undefined4 uStack_10;
  void *pvStack_c;
  undefined *puStack_8;
  undefined4 uStack_4;
  
  uStack_4 = 0xffffffff;
  puStack_8 = &LAB_009a39d4;
  pvStack_c = ExceptionList;
  if (param_1 == (FMOD_VECTOR *)0x0) {
    if (param_1_00 != (void *)0x0) {
      ExceptionList = &pvStack_c;
      std::basic_string<>::~basic_string<>((basic_string<> *)((int)param_1_00 + 4));
                    /* WARNING: Subroutine does not return */
      operator_delete(param_1_00);
    }
    cVar1 = '\0';
  }
  else {
    if (param_1_00 == (void *)0x0) {
      ExceptionList = &pvStack_c;
      if (0.1 < param_5) {
        ExceptionList = &pvStack_c;
        FUN_00736f20();
        FUN_008a0dc0();
        FMOD::Event::setCallback
                  ((_func_FMOD_RESULT_FMOD_EVENT_ptr_FMOD_EVENT_CALLBACKTYPE_void_ptr_void_ptr_void_ ptr
                    *)param_1,&LAB_008a0fb0);
      }
    }
    else {
      ExceptionList = &pvStack_c;
      uVar2 = FUN_00736f20();
      uVar6 = 1;
      pcVar5 = 
      "Manager::PlaySoundEvent(); attempting to register FMOD callback for 2D one-shot Event.";
      *(undefined4 *)((int)param_1_00 + 0x24) = uVar2;
      FMOD::Event::setCallback
                ((_func_FMOD_RESULT_FMOD_EVENT_ptr_FMOD_EVENT_CALLBACKTYPE_void_ptr_void_ptr_void_pt r
                  *)param_1,&LAB_008a0fe0);
      FUN_008a0a60(param_1_00,pcVar5,uVar6);
    }
    uVar2 = 0;
    local_a8 = param_1;
    local_a4 = param_2;
    local_a0 = param_3;
    FMOD::Event::set3DAttributes(param_1,(FMOD_VECTOR *)&local_a8,(FMOD_VECTOR *)0x0);
    cVar1 = FUN_008a0a60("Manager::PlaySoundEvent(); attempting to set 3D attributes for a 3D one-sh ot Event."
                         ,1,uVar2);
    if (cVar1 == '\0') {
      uVar2 = 0;
      FMOD::Event::getInfo((int *)param_1,(char **)0x0,(FMOD_EVENT_INFO *)&stack0xffffff4c);
      std::basic_string<>::basic_string<>(local_88,unaff_EBX);
      uStack_10 = 4;
      uVar2 = std::operator+<>(abStack_34,
                               "Manager::PlaySoundEvent: unable to set3DAttributes for sound event ( "
                               ,local_88,uVar2);
      uStack_10._0_1_ = 5;
      std::operator+<>(abStack_6c,uVar2,&DAT_00aa30ec);
      uStack_10._0_1_ = 7;
      std::basic_string<>::~basic_string<>(abStack_34);
      if (local_54[0] < 0x10) {
        apppuStack_68[0] = apppuStack_68;
      }
      FUN_008a0b10(apppuStack_68[0]);
      uStack_10 = CONCAT31(uStack_10._1_3_,4);
      std::basic_string<>::~basic_string<>(abStack_6c);
      uStack_10 = 0xffffffff;
      std::basic_string<>::~basic_string<>(local_88);
      cVar1 = '\0';
    }
    else {
      pFVar4 = param_1;
      FMOD::Event::start();
      cVar1 = FUN_008a0a60("Manager::PlaySoundEvent(); attempting to play 3D one-shot Event.",1,
                           pFVar4);
      if (cVar1 == '\0') {
        uVar2 = 0;
        FMOD::Event::getInfo((int *)param_1,(char **)0x0,(FMOD_EVENT_INFO *)&stack0xffffff4c);
        std::basic_string<>::basic_string<>((basic_string<> *)local_54,unaff_EBX);
        iStack_14 = 0;
        uVar2 = std::operator+<>(abStack_8c,"Manager::PlaySoundEvent: Failed to start sound event ("
                                 ,local_54,uVar2);
        iStack_14._0_1_ = 1;
        std::operator+<>(&local_a8,uVar2,&DAT_00aa30ec);
        iStack_14._0_1_ = 3;
        std::basic_string<>::~basic_string<>(abStack_8c);
        ppppuVar3 = (undefined4 ****)local_a4;
        if (uStack_90 < 0x10) {
          ppppuVar3 = &local_a4;
        }
        FUN_008a0b10(ppppuVar3);
        iStack_14 = (uint)iStack_14._1_3_ << 8;
        std::basic_string<>::~basic_string<>((basic_string<> *)&local_a8);
        iStack_14 = 0xffffffff;
        std::basic_string<>::~basic_string<>((basic_string<> *)local_54);
        cVar1 = '\0';
      }
      else if (0.1 < (float)param_2) {
        FUN_00736f20();
        FUN_008a0dc0();
      }
    }
  }
  ExceptionList = local_18;
  return cVar1;
}

"""],
                    inputs="text", outputs="text")
demo.queue()
demo.launch()