commit: b4e0c68e57a2de335d3cf05af26bc9825457af11
parent 1c1692f6d8330ff9f7a691da5f699c1b1508380b
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date: Sun, 24 Sep 2023 12:27:55 +0200
Add support for Java Archive (JAR) files
Diffstat:
6 files changed, 20 insertions(+), 6 deletions(-)
diff --git a/.reuse/dep5 b/.reuse/dep5
@@ -3,6 +3,6 @@ Upstream-Name: deblob
Upstream-Contact: deblob Authors <https://hacktivis.me/projects/deblob>
Source: https://hacktivis.me/projects/deblob
-Files: test/fixtures/pyc/*.pyc test/fixtures/pickle/*.pickle test/fixtures/hello.luac* test/fixtures/hello.class test/fixtures/hello.nqp.moarvm test/fixtures/hello.pir.pbc test/fixtures/perl_storage.pst test/fixtures/hello.beam test/fixtures/empty.dtb test/fixtures/hello-chez.so test/fixtures/hello.n test/fixtures/hello-ocaml.* test/fixtures/compiled/hello-racket_rkt.zo test/fixtures/hello.elc test/fixtures/hello.cnut
+Files: test/fixtures/pyc/*.pyc test/fixtures/pickle/*.pickle test/fixtures/hello.luac* test/fixtures/hello.class test/fixtures/hello.jar test/fixtures/hello.nqp.moarvm test/fixtures/hello.pir.pbc test/fixtures/perl_storage.pst test/fixtures/hello.beam test/fixtures/empty.dtb test/fixtures/hello-chez.so test/fixtures/hello.n test/fixtures/hello-ocaml.* test/fixtures/compiled/hello-racket_rkt.zo test/fixtures/hello.elc test/fixtures/hello.cnut
Copyright: 2019-2022 deblob Authors <https://hacktivis.me/projects/deblob>
License: BSD-3-Clause
diff --git a/deblob.1 b/deblob.1
@@ -1,6 +1,6 @@
.\" SPDX-FileCopyrightText: 2019-2023 deblob Authors <https://hacktivis.me/projects/deblob>
.\" SPDX-License-Identifier: BSD-3-Clause
-.Dd 2023-02-21
+.Dd 2023-09-24
.Dt DEBLOB 1
.Os
.Sh NAME
@@ -45,7 +45,7 @@ x86 IBM PC BIOS Option Rom
.It
Erlang BEAM files
.It
-Java Class files
+Java Class files and Archives (JAR)
.It
Python 2.7 & 3.8/3.9/3.10/3.11 bytecode files, typically
.Sq *.pyc
diff --git a/main.ha b/main.ha
@@ -74,6 +74,8 @@ const magic: [_][]u8 = [
const dos_magic: []u8 = ['M', 'Z'];
const pe_magic: []u8 = ['P', 'E', 0x00, 0x00];
const racket: []u8 = ['r', 'a', 'c', 'k', 'e', 't'];
+const zip: []u8 = ['P', 'K', 0x03, 0x04];
+const jar: []u8 = [0xFE, 0xCA, 0, 0];
fn is_blob(filename: str) (bool | fs::error | io::error) = {
static let buffer: [4096]u8 = [0...];
@@ -122,6 +124,12 @@ fn is_blob(filename: str) (bool | fs::error | io::error) = {
};
};
+ if (bytes::hasprefix(buffer, zip)) {
+ if(bytes::equal(jar, buffer[0x27..0x2B])) {
+ return true;
+ };
+ };
+
return false;
};
@@ -161,6 +169,7 @@ fn is_blob(filename: str) (bool | fs::error | io::error) = {
(true, "test/fixtures/hello.cnut"),
(true, "test/fixtures/hello.elc"),
(true, "test/fixtures/hello.exe"),
+ (true, "test/fixtures/hello.jar"),
(true, "test/fixtures/hello.luac53"),
(true, "test/fixtures/hello.luac54"),
(true, "test/fixtures/hello.n"),
@@ -274,7 +283,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) == 56);
+ assert(len(files_before) == 57);
const ret = check_dir(dirname);
assert(ret is void);
diff --git a/test/fixtures/Makefile b/test/fixtures/Makefile
@@ -6,6 +6,7 @@ CC ?= cc
MCS ?= mcs # Mono C Sharp compiler
CFLAGS ?= -Os -s
JAVAC ?= javac
+JAR ?= jar
NQP ?= nqp
PARROT ?= parrot
PERL ?= perl
@@ -18,7 +19,7 @@ EMACS ?= emacs
SQUIRREL ?= squirrel3
NONBUNDLED_BLOBS = hello hello.a hello.o
-TEST_BLOBS = $(NONBUNDLED_BLOBS) hello.exe hello.luac53 hello.luac54 hello.wasm hello.class hello.nqp.moarvm hello.pir.pbc perl_storage.pst hello.beam empty.dtb hello-chez.so hello.n hello-ocaml.cmo hello-ocaml.cma hello-ocaml.cmx hello-ocaml.cmxa compiled/hello-racket_rkt.zo hello.elc hello.cnut
+TEST_BLOBS = $(NONBUNDLED_BLOBS) hello.exe hello.luac53 hello.luac54 hello.wasm hello.class hello.jar hello.nqp.moarvm hello.pir.pbc perl_storage.pst hello.beam empty.dtb hello-chez.so hello.n hello-ocaml.cmo hello-ocaml.cma hello-ocaml.cmx hello-ocaml.cmxa compiled/hello-racket_rkt.zo hello.elc hello.cnut
base: $(NONBUNDLED_BLOBS)
@@ -56,6 +57,9 @@ hello.wasm: hello.wat
hello.class: hello.java
$(JAVAC) hello.java
+hello.jar: hello.class
+ $(JAR) cf $@ hello.class
+
hello.nqp.moarvm: hello.nqp
$(NQP) --target mbc --output=$@ hello.nqp
diff --git a/test/fixtures/README.md b/test/fixtures/README.md
@@ -6,7 +6,8 @@ Dependencies:
- `luac5.3` from Lua 5.3
- `luac5.4` from Lua 5.4
- wasm assembler, default one is `wat2wasm` from [wabt](https://github.com/WebAssembly/wabt)
-- Java Development Kit, defaults to `javac`. Any version should work, including early bootstrap with jamvm 1.5+
+- Java Compiler, defaults to `javac`. Any version should work, including early bootstrap with jamvm 1.5+
+- Java Archive tool aka `jar(1)`, defaults to `jar`. Note that `fastjar` doesn't properly generates the file but OpenJDK 8+ does up to at least OpenJDK 20.
- [NQP](https://github.com/Raku/nqp) aka Not Quite Perl
- [Parrot](http://www.parrot.org/)
- Perl5
diff --git a/test/fixtures/hello.jar b/test/fixtures/hello.jar
Binary files differ.