diff options
author | Elliott Hughes <enh@google.com> | 2018-07-24 11:39:42 -0700 |
---|---|---|
committer | Rob Landley <rob@landley.net> | 2018-08-04 11:09:20 -0500 |
commit | 65c743f97a738fd3a6f97a0b759bb8a4da964c58 (patch) | |
tree | 6057b95d9498234291ef4fda5152c60ec4d29712 | |
parent | 4b6c9d20f7274e20aca8301734b7da31310d9628 (diff) | |
download | toybox-65c743f97a738fd3a6f97a0b759bb8a4da964c58.tar.gz |
file: slightly improve .class, add .dex.
-rw-r--r-- | tests/file.test | 12 | ||||
-rw-r--r-- | toys/posix/file.c | 10 |
2 files changed, 14 insertions, 8 deletions
diff --git a/tests/file.test b/tests/file.test index 93805569..2d8f04b6 100644 --- a/tests/file.test +++ b/tests/file.test @@ -10,6 +10,7 @@ echo "#! /bin/bash" > bash.script2 echo "#! /usr/bin/env python" > env.python.script echo "Hello, world!" > ascii echo "cafebabe000000310000" | xxd -r -p > java.class +echo "6465780a3033350038ca8f6ce910f94e" | xxd -r -p > android.dex ln -s java.class symlink testing "empty" "file empty" "empty: empty\n" "" "" @@ -17,15 +18,16 @@ testing "bash.script" "file bash.script" "bash.script: /bin/bash script\n" "" "" testing "bash.script with spaces" "file bash.script2" "bash.script2: /bin/bash script\n" "" "" testing "env python script" "file env.python.script" "env.python.script: python script\n" "" "" testing "ascii" "file ascii" "ascii: ASCII text\n" "" "" -testing "java class" "file java.class" "java.class: Java class file, version 49.0\n" "" "" +testing "java class" "file java.class" "java.class: Java class file, version 49.0 (Java 1.5)\n" "" "" +testing "Android .dex" "file android.dex" "android.dex: Android dex file, version 035\n" "" "" testing "symlink" "file symlink" "symlink: symbolic link\n" "" "" testing "symlink -h" "file -h symlink" "symlink: symbolic link\n" "" "" -testing "symlink -L" "file -L symlink" "symlink: Java class file, version 49.0\n" "" "" +testing "symlink -L" "file -L symlink" "symlink: Java class file, version 49.0 (Java 1.5)\n" "" "" -testing "- pipe" "cat java.class | file -" "-: Java class file, version 49.0\n" "" "" -testing "- redirect" "file - <java.class" "-: Java class file, version 49.0\n" "" "" +testing "- pipe" "cat java.class | file -" "-: Java class file, version 49.0 (Java 1.5)\n" "" "" +testing "- redirect" "file - <java.class" "-: Java class file, version 49.0 (Java 1.5)\n" "" "" testing "/dev/zero" "file /dev/zero" "/dev/zero: character special\n" "" "" testing "- </dev/zero" "file - </dev/zero" "-: data\n" "" "" -rm empty bash.script bash.script2 env.python.script ascii java.class +rm empty bash.script bash.script2 env.python.script ascii java.class android.dex diff --git a/toys/posix/file.c b/toys/posix/file.c index 715c3e86..333869cd 100644 --- a/toys/posix/file.c +++ b/toys/posix/file.c @@ -244,10 +244,14 @@ static void do_regular_file(int fd, char *name) // TODO: parsing JPEG for width/height is harder than GIF or PNG. else if (len>32 && !memcmp(toybuf, "\xff\xd8", 2)) xputs("JPEG image data"); - // https://docs.oracle.com/javase/specs/jvms/se7/html/jvms-4.html + // https://en.wikipedia.org/wiki/Java_class_file#General_layout else if (len>8 && strstart(&s, "\xca\xfe\xba\xbe")) - xprintf("Java class file, version %d.%d\n", - (int)peek_be(s+2, 2), (int)peek_be(s, 2)); + xprintf("Java class file, version %d.%d (Java 1.%d)\n", + (int)peek_be(s+2, 2), (int)peek_be(s, 2), (int)peek_be(s+2, 2)-44); + + // https://source.android.com/devices/tech/dalvik/dex-format#dex-file-magic + else if (len>8 && strstart(&s, "dex\n") && s[3] == 0) + xprintf("Android dex file, version %s\n", s); // https://people.freebsd.org/~kientzle/libarchive/man/cpio.5.txt // the lengths for cpio are size of header + 9 bytes, since any valid |