Skip to content

Commit

Permalink
Refactoring
Browse files Browse the repository at this point in the history
Update CI (add aarch64)
Update README
  • Loading branch information
VHSgunzo committed Nov 21, 2024
1 parent 2ded3dd commit 372d062
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 43 deletions.
4 changes: 2 additions & 2 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
[build]
# target = "x86_64-pc-windows-gnu"
target = "x86_64-unknown-linux-musl"
rustflags = ["-C", "target-feature=+crt-static", "-Z", "remap-cwd-prefix="]
rustflags = ["-Z", "remap-cwd-prefix="]

[unstable]
build-std = ["std", "panic_abort"]
build-std-features = ["panic_immediate_abort"]
build-std-features = ["panic_immediate_abort"]
Binary file added .github/sstrip
Binary file not shown.
46 changes: 33 additions & 13 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,39 @@ jobs:
override: true
target: x86_64-unknown-linux-musl

- name: Build
run: >
sudo bash -c 'apt update && apt install upx binutils gcc-mingw-w64 musl-tools -y';
rustup component add rust-src --toolchain nightly;
cargo build --release;
strip -s -R .comment -R .gnu.version --strip-unneeded target/x86_64-unknown-linux-musl/release/ulexec;
upx --force -9 --best target/x86_64-unknown-linux-musl/release/ulexec -o target/x86_64-unknown-linux-musl/release/ulexec-upx;
cp target/x86_64-unknown-linux-musl/release/{ulexec,ulexec-upx} . ;
echo Windows;
rustup target add x86_64-pc-windows-gnu;
cargo build --release --target x86_64-pc-windows-gnu;
upx --force -9 --best target/x86_64-pc-windows-gnu/release/ulexec.exe -o target/x86_64-pc-windows-gnu/release/ulexec-upx.exe;
cp target/x86_64-pc-windows-gnu/release/{ulexec,ulexec-upx}.exe . ;
- name: Install deps
run: |
sudo bash -c 'apt update && apt install upx binutils gcc-mingw-w64 musl-tools -y'
rustup component add rust-src --toolchain nightly
cargo install cross
- name: Build x86_64
run: |
cargo clean
cargo build --release
mv target/x86_64-unknown-linux-musl/release/ulexec ulexec-x86_64
- name: Build aarch64
run: |
cargo clean
cross build --release --target aarch64-unknown-linux-musl
mv target/aarch64-unknown-linux-musl/release/ulexec ulexec-aarch64
# https://github.com/aunali1/super-strip
- name: Strip
run: |
"${{ github.workspace }}/.github/sstrip" ulexec-*
- name: UPX
run: |
ls ulexec-*|xargs -I {} upx -9 --best {} -o {}-upx
- name: Build x86_64 windows
run: |
cargo clean
cargo build --release --target x86_64-pc-windows-gnu
mv target/x86_64-pc-windows-gnu/release/ulexec.exe ulexec-x86_64.exe
upx --force -9 --best ulexec-x86_64.exe -o ulexec-x86_64-upx.exe
# - name: Build archlinux package
# uses: countstarlight/arch-makepkg-action@master
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "ulexec"
version = "0.1.2"
version = "0.1.3"
edition = "2021"
license = "MIT"
readme = "README.md"
Expand Down
2 changes: 1 addition & 1 deletion PKGBUILD
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Maintainer: VHSgunzo <vhsgunzo.github.io>
pkgname='ulexec-bin'
binname="${pkgname%-bin}"
pkgver='0.1.2'
pkgver='0.1.3'
pkgrel='1'
pkgdesc='A tool for loading and executing PE on Windows and ELF on Linux from memory'
arch=("x86_64")
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ rustup component add rust-src --toolchain nightly
```
* **Compile the Linux binary (musl required)**
```
rustup target add x86_64-unknown-linux-musl
rustup target add $(uname -m)-unknown-linux-musl
cargo build --release
./target/x86_64-unknown-linux-musl/release/ulexec ~~help
./target/$(uname -m)-unknown-linux-musl/release/ulexec ~~help
```
* **Compile the Windows binary (mingw-w64-gcc required)**
```
Expand Down
42 changes: 18 additions & 24 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ struct Args {
exec_args: Vec<String>,
}

impl Default for Args {
fn default() -> Self {
impl Args {
fn new() -> Self {
Args {
url: None,
file: None,
Expand All @@ -50,15 +50,12 @@ impl Default for Args {
}
}

fn get_env_var(env_var: &str) -> String {
let mut ret = "".to_string();
if let Ok(res) = env::var(env_var) { ret = res };
ret
fn get_env_var(var: &str) -> String {
env::var(var).unwrap_or("".into())
}

fn unset_env_vars_with_prefix(prefix: &str) {
let current_vars = env::vars();
for (key, _value) in current_vars {
for (key, _) in env::vars() {
if key.starts_with(prefix) {
env::remove_var(key);
}
Expand All @@ -67,7 +64,7 @@ fn unset_env_vars_with_prefix(prefix: &str) {

fn parse_args() -> Args {
let env_args: Vec<String> = env::args().skip(1).collect();
let mut args = Args::default();
let mut args = Args::new();

let mut i = 0;
while i < env_args.len() {
Expand Down Expand Up @@ -141,12 +138,10 @@ fn parse_args() -> Args {
let var = get_env_var("ULEXEC_URL");
if !var.is_empty() {
args.url = Some(var)
} else {
if !args.exec_args.is_empty() {
let arg = &args.exec_args[0];
if arg.starts_with("http://") || arg.starts_with("https://") {
args.url = Some(args.exec_args.remove(0));
}
} else if !args.exec_args.is_empty() {
let arg = &args.exec_args[0];
if arg.starts_with("http://") || arg.starts_with("https://") {
args.url = Some(args.exec_args.remove(0));
}
}
}
Expand Down Expand Up @@ -212,7 +207,7 @@ fn main() {
#[cfg(target_os = "windows")]
{
if is_child {
args = Args::default();
args = Args::new();
args.stdin = true;
args.exec_args = env::args().skip(1).collect();
} else {
Expand Down Expand Up @@ -252,13 +247,12 @@ fn main() {
.build()
.unwrap();

let req: RequestBuilder;
let url = args.url.as_ref().unwrap();
if args.post {
req = client.post(url)
let req: RequestBuilder = if args.post {
client.post(url)
} else {
req = client.get(url)
}
client.get(url)
};
match req.send() {
Ok(data) => {
exec_file = data.bytes().unwrap().to_vec()
Expand Down Expand Up @@ -329,8 +323,8 @@ fn main() {
use nix::sys::memfd::{memfd_create, MemFdCreateFlag};


fn is_pie(bytes: &Vec<u8>) -> bool {
match Elf::parse(&bytes) {
fn is_pie(bytes: &[u8]) -> bool {
match Elf::parse(bytes) {
Ok(elf) => {
elf.program_headers.iter()
.find(|h| h.p_type == program_header::PT_LOAD)
Expand Down Expand Up @@ -450,7 +444,7 @@ fn main() {
let memfd_raw = memfd.as_raw_fd();

file_path = PathBuf::from(
format!("/proc/self/fd/{}", memfd_raw.to_string())
format!("/proc/self/fd/{memfd_raw}")
);

if let Err(err) = write(memfd, &exec_file) {
Expand Down

0 comments on commit 372d062

Please sign in to comment.