logo

deblob

remove binary executables from a directory git clone https://hacktivis.me/git/deblob.git
commit: 8d3c3d22c6be60664d7936ef47a0b9eae70ea778
parent 15bde5a73e23bbc182c7901c2662c3092fd41988
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date:   Fri, 30 Sep 2022 00:49:32 +0200

Add support for Portable Executable files

Diffstat:

MMakefile6+++++-
Mdeblob.19++++++---
Mmain.ha7+++++--
Atest/fixtures/hello.cs11+++++++++++
Atest/fixtures/hello.exe0
Atest/fixtures/hello.exe.license3+++
6 files changed, 30 insertions(+), 6 deletions(-)

diff --git a/Makefile b/Makefile @@ -7,13 +7,14 @@ MANDIR ?= $(PREFIX)/share/man AR ?= ar CC ?= cc +MCS ?= mcs # Mono C Sharp compiler HARE ?= hare HAREFLAGS ?= CFLAGS ?= -Os -s MANDOC ?= mandoc EXE = deblob -TEST_BLOBS = test/fixtures/hello test/fixtures/hello.a test/fixtures/hello.o +TEST_BLOBS = test/fixtures/hello test/fixtures/hello.a test/fixtures/hello.o test/fixtures/hello.exe all: $(EXE) @@ -33,6 +34,9 @@ test/fixtures/hello.o: test/fixtures/hello.c test/fixtures/hello: test/fixtures/hello.c $(CC) $(CFLAGS) -o $@ test/fixtures/hello.c +test/fixtures/hello.exe: test/fixtures/hello.cs + $(MCS) test/fixtures/hello.cs + .PHONY: test test: all $(TEST_BLOBS) rm -fr test/check_dir-fixtures diff --git a/deblob.1 b/deblob.1 @@ -35,10 +35,11 @@ Directory to be scanned rather than the current working directory on execution. Blobs scanned against are the following: .Bl -dash -compact .It -ELF files by the magic-header +Executable and Linking Format (ELF) files .It +Unix .Xr ar 1 -files by the magic-header +files .It x86 IBM PC BIOS Option Rom .It @@ -46,7 +47,9 @@ Erlang BEAM files .It Java Class files .It -Python 2.7 & 3.8/3.9/3.10 bytecode files (typically *.pyc) +Python 2.7 & 3.8/3.9/3.10 bytecode files, typically *.pyc +.It +Portable Executable (PE) files, typically *.exe and *.dll .El .Sh EXAMPLES The following code block show how it is intended to be used in Gentoo's diff --git a/main.ha b/main.ha @@ -20,6 +20,7 @@ const magic: [_][]u8 = [ [0x55, 0xAA], // IBM PC BIOS ROM ['F', 'O', 'R', '1'], // Erlang BEAM [0xCA, 0xFE, 0xBA, 0xBE], // Java Class File & Mach-O Executable + ['M', 'Z', 0x90, 0x00, 0x03, 0x00, 0x00, 0x00], // Partial MSDOS stub header (ECMA-335 Common Language Infrastructure) // Python *.pyc bytecode magic numbers (defined in importlib/_bootstrap_external.py) [0x03, 0xF3, '\r', '\n'], // (62211i little-endian) Python 2.7 [0x55, 0x0D, '\r', '\n'], // (3413i litte-endian) Python 3.8 @@ -52,9 +53,11 @@ fn is_blob(filename: str) (bool | fs::error | io::error) = { const tests = [ ("test/fixtures/hello.1", false), ("test/fixtures/hello.c", false), + ("test/fixtures/hello.cs", false), ("test/fixtures/hello", true), ("test/fixtures/hello.o", true), ("test/fixtures/hello.a", true), + ("test/fixtures/hello.exe", true), ("test/fixtures/Elixir.Hex.API.Auth.beam", true), //("test/fixtures/option.rom", true), ("test/fixtures/FirstRepeatingElement.class", true), @@ -159,7 +162,7 @@ fn check_dir(dirname: str) (void | errors::invalid) = { case let e: fs::error => fmt::fatalf("os::readdir({}): {}", dirname, fs::strerror(e)); }; - assert(len(files_before) == 14); + assert(len(files_before) == 17); const ret = check_dir(dirname); assert(ret is void); @@ -170,7 +173,7 @@ fn check_dir(dirname: str) (void | errors::invalid) = { case let e: fs::error => fmt::fatalf("os::readdir({}): {}", dirname, fs::strerror(e)); }; - assert(len(files_after) == 9); + assert(len(files_after) == 11); }; export fn main() void = { diff --git a/test/fixtures/hello.cs b/test/fixtures/hello.cs @@ -0,0 +1,11 @@ +// SPDX-FileCopyrightText: 2019-2022 deblob Authors <https://hacktivis.me/projects/deblob> +// SPDX-License-Identifier: BSD-3-Clause +using System; + +class Program +{ + static void Main() + { + Console.WriteLine("Hello, world!"); + } +} diff --git a/test/fixtures/hello.exe b/test/fixtures/hello.exe Binary files differ. diff --git a/test/fixtures/hello.exe.license b/test/fixtures/hello.exe.license @@ -0,0 +1,3 @@ +SPDX-FileCopyrightText: 2019-2022 deblob Authors <https://hacktivis.me/projects/deblob> +SPDX-License-Identifier: BSD-3-Clause +Source-File: hello.cs