|
| 1 | +# Cross Compile Rust-Programs using Docker |
| 2 | + |
| 3 | +## Prerequisites |
| 4 | + |
| 5 | +* Docker |
| 6 | + |
| 7 | +## Steps |
| 8 | + |
| 9 | +I have created an Dockerfile in my main branch of [Rust-for-Malware-Development](https://github.com/Whitecat18/Rust-for-Malware-Development.git). lets build our image |
| 10 | + |
| 11 | + |
| 12 | +``` |
| 13 | +docker build . -t windows_compile |
| 14 | +``` |
| 15 | + |
| 16 | +> ⚠️ : This build takes upto 3 GB Space |
| 17 | +
|
| 18 | +Next run the container in the following project Directory ! |
| 19 | + |
| 20 | +Once you’ve created the image, then you can run the container by executing the following command: |
| 21 | + |
| 22 | +``` |
| 23 | +docker run --rm -v ‘your-pwd’:/app rust_cross_compile/windows |
| 24 | +``` |
| 25 | + |
| 26 | +The -rm option will remove the container when the command completes. The -v command allows you to persist data after a container has existed by linking your container storage with your local machine. Replace ‘your-pwd’ with the absolute path to your Rust directory |
| 27 | + |
| 28 | +Example i have compiled [EDRChecker](https://github.com/Whitecat18/Rust-for-Malware-Development/tree/main/EDRChecker) and executed on my Virtual Machine. |
| 29 | + |
| 30 | + |
| 31 | + |
| 32 | + |
| 33 | + |
| 34 | + |
| 35 | +## Modifying Dockerfile |
| 36 | + |
| 37 | +Here is the Default version of Rust Container |
| 38 | +``` |
| 39 | +FROM rust:latest |
| 40 | +
|
| 41 | +RUN apt update ; apt upgrade -y |
| 42 | +RUN apt install -y g++-mingw-w64-x86-64 |
| 43 | +
|
| 44 | +RUN rustup target add x86_64-pc-windows-gnu |
| 45 | +RUN rustup toolchain install stable-x86_64-pc-windows-gnu |
| 46 | +
|
| 47 | +WORKDIR /app |
| 48 | +
|
| 49 | +CMD ["cargo", "build", "--target", "x86_64-pc-windows-gnu"] |
| 50 | +``` |
| 51 | + |
| 52 | +For **--release** you can modify the Dockerfile as Follows |
| 53 | + |
| 54 | +``` |
| 55 | +FROM rust:latest |
| 56 | +
|
| 57 | +RUN apt update ; apt upgrade -y |
| 58 | +RUN apt install -y g++-mingw-w64-x86-64 |
| 59 | +
|
| 60 | +RUN rustup target add x86_64-pc-windows-gnu |
| 61 | +RUN rustup toolchain install stable-x86_64-pc-windows-gnu |
| 62 | +
|
| 63 | +WORKDIR /app |
| 64 | +
|
| 65 | +CMD ["cargo", "build", "--target", "x86_64-pc-windows-gnu", "--release"] |
| 66 | +``` |
| 67 | + |
| 68 | +Here is the Image: |
| 69 | + |
| 70 | + |
| 71 | + |
| 72 | + |
| 73 | + |
| 74 | +THE PATH WHERE IT COMPILES AND KEEPS BINARY FILES: |
| 75 | + |
| 76 | + |
| 77 | + |
0 commit comments