Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
.git
.github
.vs
.vscode
bin/
obj/
Debug/
Release/
publish/
publish-net8.0/
*.sln.user
*.suo
*.user
*.pdb
*.xml
*.ps1
build-beaengine-32/
build-beaengine-64/
build64/
beaengine/
deb-root/
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,5 @@ publish-netcoreapp*/
publish-net*/
launchSettings.json
*.user
*.skill
pr_body.md
7 changes: 6 additions & 1 deletion De4DotCommon.props
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,13 @@
<DisableOutOfProcTaskHost>true</DisableOutOfProcTaskHost>
<DnlibVersion>4.5.0</DnlibVersion>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)' == 'Release'">
<PropertyGroup Condition="'$(Configuration)' == 'Release' And '$(De4DotNetFramework)' != 'true'">
<SelfContained>true</SelfContained>
</PropertyGroup>

<!-- Enable compiling .NET Framework 4.8 targets natively on Linux/macOS using standard .NET SDK -->
<ItemGroup Condition=" '$(De4DotNetFramework)' == 'true' ">
<PackageReference Include="Microsoft.NETFramework.ReferenceAssemblies" Version="1.0.3" PrivateAssets="All" />
</ItemGroup>

</Project>
79 changes: 79 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
# ==============================================================================
# STAGE 1: Build BeaEngine (Native Library for ConfuserEx control flow cleaning)
# ==============================================================================
FROM ubuntu:22.04 AS beaengine-builder
ENV DEBIAN_FRONTEND=noninteractive

RUN apt-get update && apt-get install -y \
git \
cmake \
build-essential \
&& rm -rf /var/lib/apt/lists/*

WORKDIR /src
RUN git clone --depth 1 --branch v5.3.0 https://github.com/BeaEngine/beaengine.git

RUN cmake -S beaengine -B build64 \
-DoptBUILD_DLL=ON \
-DoptHAS_OPTIMIZED=ON \
-DoptHAS_SYMBOLS=OFF

RUN cmake --build build64

# Dynamically locate and move the compiled .so to a standardized path
RUN mkdir -p /app && \
SO_FILE=$(find build64 -name "libBeaEngine*.so" | head -n 1) && \
if [ -n "$SO_FILE" ]; then cp "$SO_FILE" /app/libBeaEngine.so; else echo "Error: libBeaEngine.so not found!" && exit 1; fi

# ==============================================================================
# STAGE 2: Build de4dotEx (.NET 8.0 Cross-Platform Release)
# ==============================================================================
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS dotnet-builder
WORKDIR /src

# Copy all files to build
COPY . .

# Publish both de4dot and the de4dot.mcp server targeting net8.0
RUN dotnet publish -c Release -f net8.0 -o /app/publish/de4dot de4dot/de4dot.csproj
RUN dotnet publish -c Release -f net8.0 -o /app/publish/mcp de4dot.mcp/de4dot.mcp.csproj
RUN rm -rf /app/publish/**/*.pdb /app/publish/**/*.xml

# ==============================================================================
# STAGE 3: Final Runtime Image (.NET 8.0 on Ubuntu / Runtime)
# ==============================================================================
FROM mcr.microsoft.com/dotnet/runtime:8.0 AS runtime
WORKDIR /app

# Install native dependencies required for execution (e.g. globalization, bash)
RUN apt-get update && apt-get install -y \
libicu-dev \
bash \
&& rm -rf /var/lib/apt/lists/*

# Copy de4dot and MCP published folders
COPY --from=dotnet-builder /app/publish/de4dot ./de4dot
COPY --from=dotnet-builder /app/publish/mcp ./mcp

# Copy compiled libBeaEngine.so from Stage 1 standardized path to system libraries & register
COPY --from=beaengine-builder /app/libBeaEngine.so /usr/local/lib/libBeaEngine.so
RUN ldconfig

# Create symlinks for global accessibility
RUN ln -s /app/de4dot/de4dot /usr/local/bin/de4dot && \
ln -s /app/mcp/de4dot.mcp /usr/local/bin/de4dot-mcp

# Create a unified entrypoint script inside the final image
RUN printf '#!/bin/bash\n\
if [ "$1" = "--mcp" ] || [ "$1" = "-mcp" ]; then\n\
shift\n\
exec /app/mcp/de4dot.mcp "$@"\n\
else\n\
exec /app/de4dot/de4dot "$@"\n\
fi\n' > /app/entrypoint.sh && chmod +x /app/entrypoint.sh

# Expose HTTP port 8080 (for MCP Web API mode)
EXPOSE 8080

ENTRYPOINT ["/app/entrypoint.sh"]
CMD ["--help"]
78 changes: 78 additions & 0 deletions Dockerfile.wine
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
# ==============================================================================
# STAGE 1: Build the .NET Framework 4.8 Targets natively on Linux
# ==============================================================================
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS dotnet-framework-builder
WORKDIR /src

# Copy all files
COPY . .

# Compile de4dot.netframework.sln targeting net48 in Release mode
# Disable RuntimeIdentifierInference and ValidateExecutableRuntimeIdentifier to bypass architecture compatibility checks on ARM64 hosts
RUN dotnet build -c Release \
-p:SolutionName=de4dot.netframework \
-p:RuntimeIdentifierInference=false \
-p:ValidateExecutableRuntimeIdentifier=false \
de4dot.netframework.sln

# ==============================================================================
# STAGE 2: Package into Headless Wine Runtime Environment
# ==============================================================================
FROM ubuntu:22.04
ENV DEBIAN_FRONTEND=noninteractive

# Install dependencies, 32-bit architecture, and Wine from standard Ubuntu repositories
# On ARM64 (Apple Silicon Mac), we restrict standard mirrors to arm64 to prevent apt-get update 404 failures on i386 lists.
RUN ARCH=$(dpkg --print-architecture) && \
if [ "$ARCH" = "arm64" ]; then sed -i 's/^deb /deb [arch=arm64] /g' /etc/apt/sources.list; fi && \
dpkg --add-architecture i386 && \
apt-get update && apt-get install -y \
software-properties-common \
wget \
gnupg2 \
cabextract \
xvfb \
unzip \
wine64 \
wine \
&& rm -rf /var/lib/apt/lists/*

# Install winetricks
RUN wget -O /usr/local/bin/winetricks https://raw.githubusercontent.com/Winetricks/winetricks/master/src/winetricks && \
chmod +x /usr/local/bin/winetricks

# Configure wine environment
ENV WINEARCH=win64
ENV WINEPREFIX=/root/.wine
ENV DISPLAY=:0

# Pre-download official Wine Mono MSI into Wine's global shared directory.
# During wineboot -u, Wine will automatically find and register this package.
RUN mkdir -p /usr/share/wine/mono && \
wget -q -O /usr/share/wine/mono/wine-mono-7.0.0-x86.msi https://dl.winehq.org/wine/wine-mono/7.0.0/wine-mono-7.0.0-x86.msi

# Initialize wine prefix silently using Xvfb
RUN Xvfb :0 -screen 0 1024x768x16 & \
sleep 2 && \
wineboot -u && \
wineserver -w

# Set working directory inside the Wine prefix or a dedicated folder
WORKDIR /app

# Copy the compiled .NET 4.8 targets directly from Stage 1 (dotnet-framework-builder)
COPY --from=dotnet-framework-builder /src/Release/net48/ .

# Create helper script to launch de4dot through Wine in a virtual frame buffer
RUN echo '#!/bin/bash\n\
# Launch virtual framebuffer silently in the background if not already running\n\
Xvfb :0 -screen 0 1024x768x16 >/dev/null 2>&1 & \n\
sleep 1\n\
wine /app/de4dot.exe "$@"' > /usr/local/bin/de4dot && \
chmod +x /usr/local/bin/de4dot

# Define default volume for binaries to deobfuscate
VOLUME ["/work"]
WORKDIR /work

ENTRYPOINT ["de4dot"]
Loading