logo

deblob

remove binary executables from a directory git clone https://hacktivis.me/git/deblob.git
commit: 33b5cab3c8d3dc208cec7bfe8da85e790cf9c611
parent 9f519629b20042a02e547c310d95d958776573f0
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date:   Mon,  1 Aug 2022 10:12:36 +0200

Add support for Java class files

Changed the way magic headers are stored because "\xCA\xFE\xBA\xBE"
corresponds to [U+00CA, U+00FE, U+00BA, U+00BE].
And the real 0xCAFEBABE isn't valid UTF-8, which it shouldn't even need to be.

FirstRepeatingElement.class is from <https://bae.st/objects/873a9ede-7995-4c38-b64a-0d49d2c0e98c>

Diffstat:

ALICENSES/WTFPL.txt11+++++++++++
Mmain.ha22++++++++++++----------
Atest/fixtures/FirstRepeatingElement.class0
Atest/fixtures/FirstRepeatingElement.class.license2++
4 files changed, 25 insertions(+), 10 deletions(-)

diff --git a/LICENSES/WTFPL.txt b/LICENSES/WTFPL.txt @@ -0,0 +1,11 @@ +DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE +Version 2, December 2004 + +Copyright (C) 2004 Sam Hocevar <sam@hocevar.net> + +Everyone is permitted to copy and distribute verbatim or modified copies of this license document, and changing it is allowed as long as the name is changed. + +DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE +TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. You just DO WHAT THE FUCK YOU WANT TO. diff --git a/main.ha b/main.ha @@ -14,12 +14,13 @@ use strings; let excludes: []str = []; let noop: bool = false; -def ELF: str = "\x7FELF"; -def UNIX_AR: str = "!<arch>\n"; -def PC_BIOS_ROM: str = "\x55\xAA"; -def ERL_BEAM: str = "FOR1"; - -const magic: [_]str = [ELF, UNIX_AR, PC_BIOS_ROM, ERL_BEAM]; +let magic: [_][]u8 = [ + [0x7F, 'E', 'L', 'F'], // ELF + ['!', '<', 'a', 'r', 'c', 'h', '>', '\n'], // Unix ar(1) + [0x55, 0xAA], // IBM PC BIOS ROM + ['F', 'O', 'R', '1'], // Erlang BEAM + [0xCA, 0xFE, 0xBA, 0xBE], // Java Class File & Mach-O Executable +]; fn is_blob(filename: str) (bool | fs::error | io::error) = { static let buffer: [512]u8 = [0...]; @@ -33,8 +34,8 @@ fn is_blob(filename: str) (bool | fs::error | io::error) = { }; for (let i = 0z; i < len(magic); i += 1) { - const magic = strings::toutf8(magic[i]); - if (bytes::hasprefix(buffer, magic)) { + assert(len(magic[i]) > 0); + if (bytes::hasprefix(buffer, magic[i])) { return true; }; }; @@ -51,6 +52,7 @@ fn is_blob(filename: str) (bool | fs::error | io::error) = { ("test/fixtures/hello.a", true), ("test/fixtures/Elixir.Hex.API.Auth.beam", true), //("test/fixtures/option.rom", true), + ("test/fixtures/FirstRepeatingElement.class", true), ("test/fixtures/empty", false), ]; @@ -152,7 +154,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) == 10); + assert(len(files_before) == 12); const ret = check_dir(dirname); assert(ret is void); @@ -163,7 +165,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) == 6); + assert(len(files_after) == 7); }; export fn main() void = { diff --git a/test/fixtures/FirstRepeatingElement.class b/test/fixtures/FirstRepeatingElement.class Binary files differ. diff --git a/test/fixtures/FirstRepeatingElement.class.license b/test/fixtures/FirstRepeatingElement.class.license @@ -0,0 +1,2 @@ +SPDX-FileCopyrightText: 2022 xianc78 <https://bae.st/users/xianc78> +SPDX-License-Identifier: WTFPL