ChenPingAn74 commited on
Commit
f25288a
·
verified ·
1 Parent(s): 082b1e3

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +0 -91
README.md CHANGED
@@ -1,91 +0,0 @@
1
- ---
2
- license: mit
3
- ---
4
-
5
- <h1 align="center">OpTrans: Enhancing Binary Code Similarity Detection with Function Inlining Re-Optimization</h1>
6
-
7
- <h4 align="center">
8
- <p>
9
- <a href=#about>About</a> |
10
- <a href=#intuition>Intuition</a> |
11
- <a href=#quickstart>QuickStart</a> |
12
- <p>
13
- </h4>
14
-
15
- ## About
16
-
17
- OpTrans (Re-Optimization Transformer), is an innovative framework fuses binary code optimization techniques with the transformer model for BCSD. By OpTrans employs an algorithm based on binary program analysis to determine which functions should be inlined, followed by binary rewriting techniques to effectuate re-optimization on binaries. Our goal is to provide an effective tool for researchers and practitioners in binary code similarity detection, with our models accessible on the Hugging Face Model Hub.
18
-
19
-
20
- ## Intuition
21
-
22
- This document will present how function inlining optimization improve binary code similarity detection.
23
-
24
- Function Faust_next in sc3-plugins-HOAEncLebedev501.so compiled with -O0 (sc3-plugins-HOAEncLebedev501.so-O0.i64)
25
- ![O0](./Intuition/O0.jpg)
26
-
27
- Function Faust_next in sc3-plugins-HOAEncLebedev501.so compiled with -O3 (sc3-plugins-HOAEncLebedev501.so-O3.i64)
28
- ![O3](./Intuition/O3.jpg)
29
-
30
- Function Faust_next in sc3-plugins-HOAEncLebedev501.so compiled with -O0 and processed by function inlining optimization (sc3-plugins-HOAEncLebedev501.so-O0-inline.i64)
31
- ![O0-inline](./Intuition/O0-inline.jpg)
32
-
33
-
34
- ## QuickStart
35
-
36
- This document will help you set up and start using the OpTrans model for embedding generation.
37
-
38
-
39
- ### Requirements
40
- - Python 3.6 or higher
41
- - [PyTorch](https://pytorch.org/get-started/locally/)
42
- - [Transformers library](https://huggingface.co/docs/transformers/installation)
43
- - A CUDA-enabled GPU is highly recommended for faster processing.
44
-
45
- Ensure you have Python and PyTorch installed on your system. Then, install the Transformers library using pip:
46
- ```bash
47
- pip install transformers
48
- ```
49
-
50
- ### Preparing Tokenizers and Models
51
- Import necessary libraries and initialize the model and tokenizers:
52
- ```python
53
- import torch
54
- from transformers import AutoModel, AutoTokenizer
55
-
56
- device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
57
-
58
- tokenizer = AutoTokenizer.from_pretrained("sandspeare/optrans", trust_remote_code=True)
59
- encoder = AutoModel.from_pretrained("sandspeare/optrans", trust_remote_code=True).to(device)
60
- tokenizer.pad_token = tokenizer.unk_token
61
- ```
62
-
63
- ### Example Use Cases
64
- **Function inlining optimization for BCSD**
65
-
66
- 1. Load your binary code dataset. For demonstration, we use a pickle file containing binary code snippets for similarity compare.
67
-
68
- ```python
69
- with open("./CaseStudy/casestudy.json") as fp:
70
- data = json.load(fp)
71
- ```
72
-
73
- 2. Encode the binary code.
74
-
75
- ```python
76
- asm_O0 = tokenizer([data["O0"]], padding=True, return_tensors="pt").to(device)
77
- asm_embedding_O0 = encoder(**asm_O0)
78
-
79
- asm_O0_inline = tokenizer([data["O0_inline"]], padding=True, return_tensors="pt").to(device)
80
- asm_embedding_O0_inline = encoder(**asm_O0_inline)
81
-
82
- asm_O3 = tokenizer([data["O3"]], padding=True, return_tensors="pt").to(device)
83
- asm_embedding_O3 = encoder(**asm_O3)
84
- ```
85
-
86
- 3. Perform similarity comparison:
87
-
88
- ```python
89
- sim_O0vsO3 = torch.mm(asm_embedding_O0, asm_embedding_O3.T).squeeze() / 0.07
90
- sim_O0_inlinevsO3 = torch.mm(asm_embedding_O0_inline, asm_embedding_O3.T).squeeze() / 0.07
91
- ```