Upload 7 files
#1
by alejandrarr - opened
- Dockerfile +58 -0
- LICENSE +21 -0
- LICENSE-MODEL +91 -0
- README.md +221 -0
- e.py +9 -0
- requirements-docker.txt +4 -0
- requirements.txt +6 -0
Dockerfile
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# PyTorch base image with CUDA, cuDNN, and PyTorch preinstalled
|
| 2 |
+
FROM pytorch/pytorch:2.7.1-cuda12.8-cudnn9-runtime
|
| 3 |
+
|
| 4 |
+
# Set working directory
|
| 5 |
+
WORKDIR /app
|
| 6 |
+
|
| 7 |
+
ARG GHIDRA_VERSION=11.0.3
|
| 8 |
+
ARG GHIDRA_BUILD_DATE=20240410
|
| 9 |
+
ARG GHIDRA_NAME=ghidra_${GHIDRA_VERSION}_PUBLIC
|
| 10 |
+
|
| 11 |
+
ENV DEBIAN_FRONTEND=noninteractive
|
| 12 |
+
ENV GHIDRA_DIR=/app/ghidra/${GHIDRA_NAME}
|
| 13 |
+
ENV CONDA_ENV_NAME=llm4decompile
|
| 14 |
+
|
| 15 |
+
# Install system packages
|
| 16 |
+
RUN apt-get update \
|
| 17 |
+
&& apt-get install -y --no-install-recommends \
|
| 18 |
+
wget ca-certificates unzip git curl bzip2 build-essential vim \
|
| 19 |
+
openjdk-17-jdk-headless tzdata libxext6 libxrender1 libxtst6 libxi6 \
|
| 20 |
+
&& rm -rf /var/lib/apt/lists/*
|
| 21 |
+
|
| 22 |
+
# Install Ghidra
|
| 23 |
+
RUN wget -q https://github.com/NationalSecurityAgency/ghidra/releases/download/Ghidra_${GHIDRA_VERSION}_build/${GHIDRA_NAME}_${GHIDRA_BUILD_DATE}.zip -O /tmp/ghidra.zip \
|
| 24 |
+
&& unzip /tmp/ghidra.zip -d /app/ghidra \
|
| 25 |
+
&& rm /tmp/ghidra.zip
|
| 26 |
+
|
| 27 |
+
# Add Ghidra to PATH
|
| 28 |
+
ENV PATH=${GHIDRA_DIR}:$PATH
|
| 29 |
+
|
| 30 |
+
# Create conda environment from base
|
| 31 |
+
RUN conda create -n ${CONDA_ENV_NAME} --clone base && conda clean -a -y
|
| 32 |
+
|
| 33 |
+
# Copy dependency file
|
| 34 |
+
COPY requirements-docker.txt .
|
| 35 |
+
|
| 36 |
+
# Install pip dependencies in the new conda environment
|
| 37 |
+
RUN . /opt/conda/etc/profile.d/conda.sh && \
|
| 38 |
+
conda activate ${CONDA_ENV_NAME} && \
|
| 39 |
+
pip install --no-cache-dir -r requirements-docker.txt && \
|
| 40 |
+
conda clean -a -y
|
| 41 |
+
|
| 42 |
+
# Copy source code
|
| 43 |
+
COPY . .
|
| 44 |
+
|
| 45 |
+
# Add conda environment activation to bashrc
|
| 46 |
+
RUN echo ". /opt/conda/etc/profile.d/conda.sh" >> /etc/bash.bashrc && \
|
| 47 |
+
echo "if [[ \$- == *i* ]]; then conda activate ${CONDA_ENV_NAME}; fi" >> /etc/bash.bashrc
|
| 48 |
+
|
| 49 |
+
# Create entrypoint script to activate conda environment
|
| 50 |
+
RUN echo '#!/bin/bash\n\
|
| 51 |
+
source /opt/conda/etc/profile.d/conda.sh\n\
|
| 52 |
+
conda activate llm4decompile\n\
|
| 53 |
+
exec "$@"' > /entrypoint.sh \
|
| 54 |
+
&& chmod +x /entrypoint.sh
|
| 55 |
+
|
| 56 |
+
# Set container entrypoint
|
| 57 |
+
ENTRYPOINT ["/entrypoint.sh"]
|
| 58 |
+
SHELL ["/bin/bash"]
|
LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
MIT License
|
| 2 |
+
|
| 3 |
+
Copyright (c) 2024 albertan017
|
| 4 |
+
|
| 5 |
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
| 6 |
+
of this software and associated documentation files (the "Software"), to deal
|
| 7 |
+
in the Software without restriction, including without limitation the rights
|
| 8 |
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
| 9 |
+
copies of the Software, and to permit persons to whom the Software is
|
| 10 |
+
furnished to do so, subject to the following conditions:
|
| 11 |
+
|
| 12 |
+
The above copyright notice and this permission notice shall be included in all
|
| 13 |
+
copies or substantial portions of the Software.
|
| 14 |
+
|
| 15 |
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
| 16 |
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
| 17 |
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
| 18 |
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
| 19 |
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
| 20 |
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
| 21 |
+
SOFTWARE.
|
LICENSE-MODEL
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
DEEPSEEK LICENSE AGREEMENT
|
| 2 |
+
|
| 3 |
+
Version 1.0, 23 October 2023
|
| 4 |
+
|
| 5 |
+
Copyright (c) 2023 DeepSeek
|
| 6 |
+
|
| 7 |
+
Section I: PREAMBLE
|
| 8 |
+
|
| 9 |
+
Large generative models are being widely adopted and used, and have the potential to transform the way individuals conceive and benefit from AI or ML technologies.
|
| 10 |
+
|
| 11 |
+
Notwithstanding the current and potential benefits that these artifacts can bring to society at large, there are also concerns about potential misuses of them, either due to their technical limitations or ethical considerations.
|
| 12 |
+
|
| 13 |
+
In short, this license strives for both the open and responsible downstream use of the accompanying model. When it comes to the open character, we took inspiration from open source permissive licenses regarding the grant of IP rights. Referring to the downstream responsible use, we added use-based restrictions not permitting the use of the model in very specific scenarios, in order for the licensor to be able to enforce the license in case potential misuses of the Model may occur. At the same time, we strive to promote open and responsible research on generative models for content generation.
|
| 14 |
+
|
| 15 |
+
Even though downstream derivative versions of the model could be released under different licensing terms, the latter will always have to include - at minimum - the same use-based restrictions as the ones in the original license (this license). We believe in the intersection between open and responsible AI development; thus, this agreement aims to strike a balance between both in order to enable responsible open-science in the field of AI.
|
| 16 |
+
|
| 17 |
+
This License governs the use of the model (and its derivatives) and is informed by the model card associated with the model.
|
| 18 |
+
|
| 19 |
+
NOW THEREFORE, You and DeepSeek agree as follows:
|
| 20 |
+
|
| 21 |
+
1. Definitions
|
| 22 |
+
"License" means the terms and conditions for use, reproduction, and Distribution as defined in this document.
|
| 23 |
+
"Data" means a collection of information and/or content extracted from the dataset used with the Model, including to train, pretrain, or otherwise evaluate the Model. The Data is not licensed under this License.
|
| 24 |
+
"Output" means the results of operating a Model as embodied in informational content resulting therefrom.
|
| 25 |
+
"Model" means any accompanying machine-learning based assemblies (including checkpoints), consisting of learnt weights, parameters (including optimizer states), corresponding to the model architecture as embodied in the Complementary Material, that have been trained or tuned, in whole or in part on the Data, using the Complementary Material.
|
| 26 |
+
"Derivatives of the Model" means all modifications to the Model, works based on the Model, or any other model which is created or initialized by transfer of patterns of the weights, parameters, activations or output of the Model, to the other model, in order to cause the other model to perform similarly to the Model, including - but not limited to - distillation methods entailing the use of intermediate data representations or methods based on the generation of synthetic data by the Model for training the other model.
|
| 27 |
+
"Complementary Material" means the accompanying source code and scripts used to define, run, load, benchmark or evaluate the Model, and used to prepare data for training or evaluation, if any. This includes any accompanying documentation, tutorials, examples, etc, if any.
|
| 28 |
+
"Distribution" means any transmission, reproduction, publication or other sharing of the Model or Derivatives of the Model to a third party, including providing the Model as a hosted service made available by electronic or other remote means - e.g. API-based or web access.
|
| 29 |
+
"DeepSeek" (or "we") means Beijing DeepSeek Artificial Intelligence Fundamental Technology Research Co., Ltd., Hangzhou DeepSeek Artificial Intelligence Fundamental Technology Research Co., Ltd. and/or any of their affiliates.
|
| 30 |
+
"You" (or "Your") means an individual or Legal Entity exercising permissions granted by this License and/or making use of the Model for whichever purpose and in any field of use, including usage of the Model in an end-use application - e.g. chatbot, translator, etc.
|
| 31 |
+
"Third Parties" means individuals or legal entities that are not under common control with DeepSeek or You.
|
| 32 |
+
|
| 33 |
+
Section II: INTELLECTUAL PROPERTY RIGHTS
|
| 34 |
+
|
| 35 |
+
Both copyright and patent grants apply to the Model, Derivatives of the Model and Complementary Material. The Model and Derivatives of the Model are subject to additional terms as described in Section III.
|
| 36 |
+
|
| 37 |
+
2. Grant of Copyright License. Subject to the terms and conditions of this License, DeepSeek hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare, publicly display, publicly perform, sublicense, and distribute the Complementary Material, the Model, and Derivatives of the Model.
|
| 38 |
+
|
| 39 |
+
3. Grant of Patent License. Subject to the terms and conditions of this License and where and as applicable, DeepSeek hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this paragraph) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Model and the Complementary Material, where such license applies only to those patent claims licensable by DeepSeek that are necessarily infringed by its contribution(s). If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Model and/or Complementary Material constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for the Model and/or works shall terminate as of the date such litigation is asserted or filed.
|
| 40 |
+
|
| 41 |
+
|
| 42 |
+
Section III: CONDITIONS OF USAGE, DISTRIBUTION AND REDISTRIBUTION
|
| 43 |
+
|
| 44 |
+
4. Distribution and Redistribution. You may host for Third Party remote access purposes (e.g. software-as-a-service), reproduce and distribute copies of the Model or Derivatives of the Model thereof in any medium, with or without modifications, provided that You meet the following conditions:
|
| 45 |
+
a. Use-based restrictions as referenced in paragraph 5 MUST be included as an enforceable provision by You in any type of legal agreement (e.g. a license) governing the use and/or distribution of the Model or Derivatives of the Model, and You shall give notice to subsequent users You Distribute to, that the Model or Derivatives of the Model are subject to paragraph 5. This provision does not apply to the use of Complementary Material.
|
| 46 |
+
b. You must give any Third Party recipients of the Model or Derivatives of the Model a copy of this License;
|
| 47 |
+
c. You must cause any modified files to carry prominent notices stating that You changed the files;
|
| 48 |
+
d. You must retain all copyright, patent, trademark, and attribution notices excluding those notices that do not pertain to any part of the Model, Derivatives of the Model.
|
| 49 |
+
e. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions - respecting paragraph 4.a. – for use, reproduction, or Distribution of Your modifications, or for any such Derivatives of the Model as a whole, provided Your use, reproduction, and Distribution of the Model otherwise complies with the conditions stated in this License.
|
| 50 |
+
|
| 51 |
+
5. Use-based restrictions. The restrictions set forth in Attachment A are considered Use-based restrictions. Therefore You cannot use the Model and the Derivatives of the Model for the specified restricted uses. You may use the Model subject to this License, including only for lawful purposes and in accordance with the License. Use may include creating any content with, finetuning, updating, running, training, evaluating and/or reparametrizing the Model. You shall require all of Your users who use the Model or a Derivative of the Model to comply with the terms of this paragraph (paragraph 5).
|
| 52 |
+
|
| 53 |
+
6. The Output You Generate. Except as set forth herein, DeepSeek claims no rights in the Output You generate using the Model. You are accountable for the Output you generate and its subsequent uses. No use of the output can contravene any provision as stated in the License.
|
| 54 |
+
|
| 55 |
+
Section IV: OTHER PROVISIONS
|
| 56 |
+
|
| 57 |
+
7. Updates and Runtime Restrictions. To the maximum extent permitted by law, DeepSeek reserves the right to restrict (remotely or otherwise) usage of the Model in violation of this License.
|
| 58 |
+
|
| 59 |
+
8. Trademarks and related. Nothing in this License permits You to make use of DeepSeek’ trademarks, trade names, logos or to otherwise suggest endorsement or misrepresent the relationship between the parties; and any rights not expressly granted herein are reserved by DeepSeek.
|
| 60 |
+
|
| 61 |
+
9. Personal information, IP rights and related. This Model may contain personal information and works with IP rights. You commit to complying with applicable laws and regulations in the handling of personal information and the use of such works. Please note that DeepSeek's license granted to you to use the Model does not imply that you have obtained a legitimate basis for processing the related information or works. As an independent personal information processor and IP rights user, you need to ensure full compliance with relevant legal and regulatory requirements when handling personal information and works with IP rights that may be contained in the Model, and are willing to assume solely any risks and consequences that may arise from that.
|
| 62 |
+
|
| 63 |
+
10. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, DeepSeek provides the Model and the Complementary Material on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Model, Derivatives of the Model, and the Complementary Material and assume any risks associated with Your exercise of permissions under this License.
|
| 64 |
+
|
| 65 |
+
11. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall DeepSeek be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Model and the Complementary Material (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if DeepSeek has been advised of the possibility of such damages.
|
| 66 |
+
|
| 67 |
+
12. Accepting Warranty or Additional Liability. While redistributing the Model, Derivatives of the Model and the Complementary Material thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of DeepSeek, and only if You agree to indemnify, defend, and hold DeepSeek harmless for any liability incurred by, or claims asserted against, DeepSeek by reason of your accepting any such warranty or additional liability.
|
| 68 |
+
|
| 69 |
+
13. If any provision of this License is held to be invalid, illegal or unenforceable, the remaining provisions shall be unaffected thereby and remain valid as if such provision had not been set forth herein.
|
| 70 |
+
|
| 71 |
+
14. Governing Law and Jurisdiction. This agreement will be governed and construed under PRC laws without regard to choice of law principles, and the UN Convention on Contracts for the International Sale of Goods does not apply to this agreement. The courts located in the domicile of Hangzhou DeepSeek Artificial Intelligence Fundamental Technology Research Co., Ltd. shall have exclusive jurisdiction of any dispute arising out of this agreement.
|
| 72 |
+
|
| 73 |
+
END OF TERMS AND CONDITIONS
|
| 74 |
+
|
| 75 |
+
Attachment A
|
| 76 |
+
|
| 77 |
+
Use Restrictions
|
| 78 |
+
|
| 79 |
+
You agree not to use the Model or Derivatives of the Model:
|
| 80 |
+
|
| 81 |
+
- In any way that violates any applicable national or international law or regulation or infringes upon the lawful rights and interests of any third party;
|
| 82 |
+
- For military use in any way;
|
| 83 |
+
- For the purpose of exploiting, harming or attempting to exploit or harm minors in any way;
|
| 84 |
+
- To generate or disseminate verifiably false information and/or content with the purpose of harming others;
|
| 85 |
+
- To generate or disseminate inappropriate content subject to applicable regulatory requirements;
|
| 86 |
+
- To generate or disseminate personal identifiable information without due authorization or for unreasonable use;
|
| 87 |
+
- To defame, disparage or otherwise harass others;
|
| 88 |
+
- For fully automated decision making that adversely impacts an individual’s legal rights or otherwise creates or modifies a binding, enforceable obligation;
|
| 89 |
+
- For any use intended to or which has the effect of discriminating against or harming individuals or groups based on online or offline social behavior or known or predicted personal or personality characteristics;
|
| 90 |
+
- To exploit any of the vulnerabilities of a specific group of persons based on their age, social, physical or mental characteristics, in order to materially distort the behavior of a person pertaining to that group in a manner that causes or is likely to cause that person or another person physical or psychological harm;
|
| 91 |
+
- For any use intended to or which has the effect of discriminating against individuals or groups based on legally protected characteristics or categories.
|
README.md
ADDED
|
@@ -0,0 +1,221 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
<p align="center">
|
| 3 |
+
<picture>
|
| 4 |
+
<source media="(prefers-color-scheme: dark)" srcset="https://github.com/albertan017/LLM4Decompile/blob/main/samples/logo-dark.png">
|
| 5 |
+
<img alt="LLM4Decompile" src="https://github.com/albertan017/LLM4Decompile/blob/main/samples/logo-light.png" width=55%>
|
| 6 |
+
</picture>
|
| 7 |
+
</p>
|
| 8 |
+
|
| 9 |
+
<p align="left">
|
| 10 |
+
📊 <a href="#evaluation">Results</a>
|
| 11 |
+
| 🤗 <a href="#models">Models</a>
|
| 12 |
+
| 🚀 <a href="#quick-start">Quick Start</a>
|
| 13 |
+
| 📚 <a href="#humaneval-decompile">HumanEval-Decompile</a>
|
| 14 |
+
| 📎 <a href="#citation">Citation</a>
|
| 15 |
+
| 📝 <a href="https://arxiv.org/abs/2403.05286">Paper</a>
|
| 16 |
+
| 🖥️ <a href="https://colab.research.google.com/drive/1X5TuUKuNuksGJZz6Cc83KKI0ATBP9q7r?usp=sharing">Colab</a>
|
| 17 |
+
| ▶️ <a href="https://www.youtube.com/watch?v=x7knF3Z1yLk">YouTube</a>
|
| 18 |
+
</p>
|
| 19 |
+
|
| 20 |
+
Reverse Engineering: Decompiling Binary Code with Large Language Models
|
| 21 |
+
|
| 22 |
+
[](https://trendshift.io/repositories/8664)
|
| 23 |
+
|
| 24 |
+
## Updates
|
| 25 |
+
* [2025-10-04]: Release SK²Decompile: LLM-based Two-Phase Binary Decompilation from Skeleton to Skin. Phase 1 Structure Recovery (Skeleton): Transform binary/pseudo-code into obfuscated intermediate representations 🤗 [HF Link](https://huggingface.co/LLM4Binary/sk2decompile-struct-6.7b). Phase 2 Identifier Naming (Skin): Generate human-readable source code with meaningful identifiers 🤗 [HF Link](https://huggingface.co/LLM4Binary/sk2decompile-ident-6.7).
|
| 26 |
+
* [2025-05-20]: Release [decompile-bench](https://huggingface.co/collections/LLM4Binary/decompile-bench-68259091c8d49d0ebd5efda9), contains two million binary-source function pairs for training, and 70K function pairs for evaluation. Please refer to the [decompile-bench](https://github.com/albertan017/LLM4Decompile/tree/main/decompile-bench) folder for details.
|
| 27 |
+
* [2024-10-17]: Release [decompile-ghidra-100k](https://huggingface.co/datasets/LLM4Binary/decompile-ghidra-100k), a subset of 100k training samples (25k per optimization level). We provide a [training script](https://github.com/albertan017/LLM4Decompile/blob/main/train/README.md) that runs in ~3.5 hours on a single A100 40G GPU. It achieves a 0.26 re-executability rate, with a total cost of under $20 for quick replication of LLM4Decompile.
|
| 28 |
+
* [2024-09-26]: Update a [Colab notebook](https://colab.research.google.com/drive/1X5TuUKuNuksGJZz6Cc83KKI0ATBP9q7r?usp=sharing) to demonstrate the usage of the LLM4Decompile model, including examples for the LLM4Decompile-End and LLM4Decompile-Ref models.
|
| 29 |
+
* [2024-09-23]: Release [LLM4Decompile-9B-v2](https://huggingface.co/LLM4Binary/llm4decompile-9b-v2), fine-tuned based on [Yi-Coder-9B](https://huggingface.co/01-ai/Yi-Coder-9B), achieved a re-executability rate of **0.6494** on the Decompile benchmark.
|
| 30 |
+
* [2024-06-19]: Release [V2](https://huggingface.co/LLM4Binary/llm4decompile-6.7b-v2) series (LLM4Decompile-Ref). V2 (1.3B-22B), building upon **Ghidra**, are trained on 2 billion tokens to **refine** the decompiled pseudo-code from Ghidra. The 22B-V2 version outperforms the 6.7B-V1.5 by an additional 40.1%. Please check the [ghidra folder](https://github.com/albertan017/LLM4Decompile/tree/main/ghidra) for details.
|
| 31 |
+
* [2024-05-13]: Release [V1.5](https://huggingface.co/LLM4Binary/llm4decompile-6.7b-v1.5) series (LLM4Decompile-End, directly decompile binary using LLM). V1.5 are trained with a larger dataset (15B tokens) and a maximum token **length of 4,096**, with remarkable performance (over **100% improvement**) compared to the previous model.
|
| 32 |
+
* [2024-03-16]: Add [llm4decompile-6.7b-uo](https://huggingface.co/arise-sustech/llm4decompile-6.7b-uo) model which is trained without prior knowledge of the optimization levels (O0~O3), the average re-executability is around 0.219, performs the best in our models.
|
| 33 |
+
|
| 34 |
+
## About
|
| 35 |
+
* **LLM4Decompile** is the pioneering open-source large language model dedicated to decompilation. Its current version supports decompiling Linux x86_64 binaries, ranging from GCC's O0 to O3 optimization levels, into human-readable C source code. Our team is committed to expanding this tool's capabilities, with ongoing efforts to incorporate a broader range of architectures and configurations.
|
| 36 |
+
* **LLM4Decompile-End** focuses on decompiling the binary directly. **LLM4Decompile-Ref** refines the pseudo-code decompiled by Ghidra.
|
| 37 |
+
|
| 38 |
+
## Evaluation
|
| 39 |
+
|
| 40 |
+
### Framework
|
| 41 |
+
<p align="center">
|
| 42 |
+
<img src="https://github.com/albertan017/LLM4Decompile/blob/main/samples/compile-decompile.png" alt="image" width="400" height="auto">
|
| 43 |
+
</p>
|
| 44 |
+
|
| 45 |
+
During compilation, the Preprocessor processes the source code (SRC) to eliminate comments and expand macros or includes. The cleaned code is then forwarded to the Compiler, which converts it into assembly code (ASM). This ASM is transformed into binary code (0s and 1s) by the Assembler. The Linker finalizes the process by linking function calls to create an executable file. Decompilation, on the other hand, involves converting binary code back into a source file. LLMs, being trained on text, lack the ability to process binary data directly. Therefore, binaries must be disassembled by ```Objdump``` into assembly language (ASM) first. It should be noted that binary and disassembled ASM are equivalent, they can be interconverted, and thus we refer to them interchangeably. Finally, the loss is computed between the decompiled code and source code to guide the training. To assess the quality of the decompiled code (SRC'), it is tested for its functionality through test assertions (re-executability).
|
| 46 |
+
|
| 47 |
+
### Metrics
|
| 48 |
+
* **Re-executability** evaluates whether the decompiled code can execute properly and pass all the predefined test cases.
|
| 49 |
+
|
| 50 |
+
### Benchmarks
|
| 51 |
+
* **HumanEval-Decompile** A collection of 164 C functions that exclusively rely on **standard** C libraries.
|
| 52 |
+
* **ExeBench** A collection of 2,621 functions drawn from **real** projects, each utilizing user-defined functions, structures, and macros.
|
| 53 |
+
|
| 54 |
+
|
| 55 |
+
### Results
|
| 56 |
+
|
| 57 |
+
<p align="center">
|
| 58 |
+
<img src="https://github.com/albertan017/LLM4Decompile/blob/main/samples/results_end_final.png" alt="results" width="800" height="auto">
|
| 59 |
+
</p>
|
| 60 |
+
|
| 61 |
+
<p align="center">
|
| 62 |
+
<img src="https://github.com/albertan017/LLM4Decompile/blob/main/samples/results_refine_final.png" alt="image" width="800" height="auto">
|
| 63 |
+
</p>
|
| 64 |
+
|
| 65 |
+
## Models
|
| 66 |
+
Our LLM4Decompile includes models with sizes between 1.3 billion and 33 billion parameters, and we have made these models available on Hugging Face.
|
| 67 |
+
|
| 68 |
+
| Model | Checkpoint | Size | Re-executability | Note |
|
| 69 |
+
|-----------------------|-------------------------------------------------------------------|------|---------------------|----------------------|
|
| 70 |
+
| **llm4decompile-1.3b-v1.5**| 🤗 [HF Link](https://huggingface.co/LLM4Binary/llm4decompile-1.3b-v1.5) | 1.3B | **27.3%** | Note 3 |
|
| 71 |
+
| **llm4decompile-6.7b-v1.5**| 🤗 [HF Link](https://huggingface.co/LLM4Binary/llm4decompile-6.7b-v1.5) | 6.7B | **45.4%** | Note 3 |
|
| 72 |
+
| **llm4decompile-1.3b-v2**| 🤗 [HF Link](https://huggingface.co/LLM4Binary/llm4decompile-1.3b-v2) | 1.3B | **46.0%** | Note 4 |
|
| 73 |
+
| **llm4decompile-6.7b-v2**| 🤗 [HF Link](https://huggingface.co/LLM4Binary/llm4decompile-6.7b-v2) | 6.7B | **52.7%** | Note 4 |
|
| 74 |
+
| **llm4decompile-9b-v2**| 🤗 [HF Link](https://huggingface.co/LLM4Binary/llm4decompile-9b-v2) | 9B | **64.9%** | Note 4 |
|
| 75 |
+
| **llm4decompile-22b-v2**| 🤗 [HF Link](https://huggingface.co/LLM4Binary/llm4decompile-22b-v2) | 22B | **63.6%** | Note 4 |
|
| 76 |
+
|
| 77 |
+
Note 3: V1.5 series are trained with a larger dataset (15B tokens) and a maximum token size of 4,096, with remarkable performance (over 100% improvement) compared to the previous model.
|
| 78 |
+
|
| 79 |
+
Note 4: V2 series are built upon **Ghidra** and trained on 2 billion tokens to **refine** the decompiled pseudo-code from Ghidra. Check [ghidra folder](https://github.com/albertan017/LLM4Decompile/tree/main/ghidra) for details.
|
| 80 |
+
|
| 81 |
+
## Quick Start
|
| 82 |
+
|
| 83 |
+
[](https://colab.research.google.com/drive/1X5TuUKuNuksGJZz6Cc83KKI0ATBP9q7r?usp=sharing)
|
| 84 |
+
|
| 85 |
+
**Setup:** Please use the script below to install the necessary environment.
|
| 86 |
+
```
|
| 87 |
+
git clone https://github.com/albertan017/LLM4Decompile.git
|
| 88 |
+
cd LLM4Decompile
|
| 89 |
+
conda create -n 'llm4decompile' python=3.9 -y
|
| 90 |
+
conda activate llm4decompile
|
| 91 |
+
pip install -r requirements.txt
|
| 92 |
+
```
|
| 93 |
+
|
| 94 |
+
Here is an example of how to use our model (Revised for V1.5. For previous models, please check the corresponding model page at HF).
|
| 95 |
+
Note: **Replace the "func0" with the function name you want to decompile**.
|
| 96 |
+
|
| 97 |
+
**Preprocessing:** Compile the C code into binary, and disassemble the binary into assembly instructions.
|
| 98 |
+
```python
|
| 99 |
+
import subprocess
|
| 100 |
+
import os
|
| 101 |
+
func_name = 'func0'
|
| 102 |
+
OPT = ["O0", "O1", "O2", "O3"]
|
| 103 |
+
fileName = 'samples/sample' #'path/to/file'
|
| 104 |
+
for opt_state in OPT:
|
| 105 |
+
output_file = fileName +'_' + opt_state
|
| 106 |
+
input_file = fileName+'.c'
|
| 107 |
+
compile_command = f'gcc -o {output_file}.o {input_file} -{opt_state} -lm'#compile the code with GCC on Linux
|
| 108 |
+
subprocess.run(compile_command, shell=True, check=True)
|
| 109 |
+
compile_command = f'objdump -d {output_file}.o > {output_file}.s'#disassemble the binary file into assembly instructions
|
| 110 |
+
subprocess.run(compile_command, shell=True, check=True)
|
| 111 |
+
|
| 112 |
+
input_asm = ''
|
| 113 |
+
with open(output_file+'.s') as f:#asm file
|
| 114 |
+
asm= f.read()
|
| 115 |
+
if '<'+func_name+'>:' not in asm: #IMPORTANT replace func0 with the function name
|
| 116 |
+
raise ValueError("compile fails")
|
| 117 |
+
asm = '<'+func_name+'>:' + asm.split('<'+func_name+'>:')[-1].split('\n\n')[0] #IMPORTANT replace func0 with the function name
|
| 118 |
+
asm_clean = ""
|
| 119 |
+
asm_sp = asm.split("\n")
|
| 120 |
+
for tmp in asm_sp:
|
| 121 |
+
if len(tmp.split("\t"))<3 and '00' in tmp:
|
| 122 |
+
continue
|
| 123 |
+
idx = min(
|
| 124 |
+
len(tmp.split("\t")) - 1, 2
|
| 125 |
+
)
|
| 126 |
+
tmp_asm = "\t".join(tmp.split("\t")[idx:]) # remove the binary code
|
| 127 |
+
tmp_asm = tmp_asm.split("#")[0].strip() # remove the comments
|
| 128 |
+
asm_clean += tmp_asm + "\n"
|
| 129 |
+
input_asm = asm_clean.strip()
|
| 130 |
+
before = f"# This is the assembly code:\n"#prompt
|
| 131 |
+
after = "\n# What is the source code?\n"#prompt
|
| 132 |
+
input_asm_prompt = before+input_asm.strip()+after
|
| 133 |
+
with open(fileName +'_' + opt_state +'.asm','w',encoding='utf-8') as f:
|
| 134 |
+
f.write(input_asm_prompt)
|
| 135 |
+
```
|
| 136 |
+
|
| 137 |
+
Assembly instructions should be in the format:
|
| 138 |
+
|
| 139 |
+
<FUNCTION_NAME>:\nOPERATIONS\nOPERATIONS\n
|
| 140 |
+
|
| 141 |
+
Typical assembly instructions may look like this:
|
| 142 |
+
```
|
| 143 |
+
<func0>:
|
| 144 |
+
endbr64
|
| 145 |
+
lea (%rdi,%rsi,1),%eax
|
| 146 |
+
retq
|
| 147 |
+
```
|
| 148 |
+
|
| 149 |
+
|
| 150 |
+
**Decompilation:** Use LLM4Decompile to translate the assembly instructions into C:
|
| 151 |
+
```python
|
| 152 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM
|
| 153 |
+
import torch
|
| 154 |
+
|
| 155 |
+
model_path = 'LLM4Binary/llm4decompile-6.7b-v1.5' # V1.5 Model
|
| 156 |
+
tokenizer = AutoTokenizer.from_pretrained(model_path)
|
| 157 |
+
model = AutoModelForCausalLM.from_pretrained(model_path,torch_dtype=torch.bfloat16).cuda()
|
| 158 |
+
|
| 159 |
+
with open(fileName +'_' + OPT[0] +'.asm','r') as f:#optimization level O0
|
| 160 |
+
asm_func = f.read()
|
| 161 |
+
inputs = tokenizer(asm_func, return_tensors="pt").to(model.device)
|
| 162 |
+
with torch.no_grad():
|
| 163 |
+
outputs = model.generate(**inputs, max_new_tokens=2048)### max length to 4096, max new tokens should be below the range
|
| 164 |
+
c_func_decompile = tokenizer.decode(outputs[0][len(inputs[0]):-1])
|
| 165 |
+
|
| 166 |
+
with open(fileName +'.c','r') as f:#original file
|
| 167 |
+
func = f.read()
|
| 168 |
+
|
| 169 |
+
print(f'original function:\n{func}')# Note we only decompile one function, where the original file may contain multiple functions
|
| 170 |
+
print(f'decompiled function:\n{c_func_decompile}')
|
| 171 |
+
```
|
| 172 |
+
|
| 173 |
+
### Docker setup
|
| 174 |
+
|
| 175 |
+
```
|
| 176 |
+
# build docker
|
| 177 |
+
docker build -t llm4decompile .
|
| 178 |
+
|
| 179 |
+
# run docker with GPU
|
| 180 |
+
docker run --gpus all -it --name llm4decompile llm4decompile /bin/bash
|
| 181 |
+
|
| 182 |
+
# run demo.py (choose a model suitable for your resources before running)
|
| 183 |
+
cd ghidra
|
| 184 |
+
python demo.py
|
| 185 |
+
```
|
| 186 |
+
|
| 187 |
+
## HumanEval-Decompile
|
| 188 |
+
Data are stored in ``llm4decompile/decompile-eval/decompile-eval-executable-gcc-obj.json``, using JSON list format. There are 164*4 (O0, O1, O2, O3) samples, each with five keys:
|
| 189 |
+
|
| 190 |
+
* ``task_id``: indicates the ID of the problem.
|
| 191 |
+
* ``type``: the optimization stage, is one of [O0, O1, O2, O3].
|
| 192 |
+
* ``c_func``: C solution for HumanEval problem.
|
| 193 |
+
* ``c_test``: C test assertions.
|
| 194 |
+
* ``input_asm_prompt``: assembly instructions with prompts, can be derived as in our [preprocessing example](https://github.com/albertan017/LLM4Decompile?tab=readme-ov-file#quick-start).
|
| 195 |
+
|
| 196 |
+
Please check the [evaluation scripts](https://github.com/albertan017/LLM4Decompile/tree/main/evaluation).
|
| 197 |
+
|
| 198 |
+
## On Going
|
| 199 |
+
* Larger training dataset with the cleaning process. (done:2024.05.13)
|
| 200 |
+
* Support for popular languages/platforms and settings.
|
| 201 |
+
* Support for executable binaries. (done:2024.05.13)
|
| 202 |
+
* Integration with decompilation tools (e.g., Ghidra, Rizin)
|
| 203 |
+
|
| 204 |
+
## License
|
| 205 |
+
This code repository is licensed under the MIT and DeepSeek License.
|
| 206 |
+
|
| 207 |
+
## Citation
|
| 208 |
+
```
|
| 209 |
+
@misc{tan2024llm4decompile,
|
| 210 |
+
title={LLM4Decompile: Decompiling Binary Code with Large Language Models},
|
| 211 |
+
author={Hanzhuo Tan and Qi Luo and Jing Li and Yuqun Zhang},
|
| 212 |
+
year={2024},
|
| 213 |
+
eprint={2403.05286},
|
| 214 |
+
archivePrefix={arXiv},
|
| 215 |
+
primaryClass={cs.PL}
|
| 216 |
+
}
|
| 217 |
+
```
|
| 218 |
+
|
| 219 |
+
## Star History
|
| 220 |
+
|
| 221 |
+
[](https://star-history.com/#albertan017/LLM4Decompile&Timeline)
|
e.py
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from llama_cpp import Llama
|
| 2 |
+
|
| 3 |
+
llm = Llama.from_pretrained(
|
| 4 |
+
repo_id="tensorblock/llm4decompile-6.7b-v2-GGUF",
|
| 5 |
+
filename="llm4decompile-6.7b-v2-Q2_K.gguf",
|
| 6 |
+
)
|
| 7 |
+
Copy llm.create_chat_completion(
|
| 8 |
+
messages = "No input example has been defined for this model task."
|
| 9 |
+
)
|
requirements-docker.txt
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Required for running demo.py
|
| 2 |
+
tqdm
|
| 3 |
+
numpy==1.23.3
|
| 4 |
+
transformers==4.55.3
|
requirements.txt
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
tqdm
|
| 2 |
+
loguru
|
| 3 |
+
tqdm
|
| 4 |
+
text_generation
|
| 5 |
+
vllm==0.4.0
|
| 6 |
+
numpy==1.23.3
|