diff options
author | Christos Zoulas <christos@zoulas.com> | 2020-11-21 15:57:07 +0000 |
---|---|---|
committer | Christos Zoulas <christos@zoulas.com> | 2020-11-21 15:57:07 +0000 |
commit | 603c5a7987481c4a1d86cc08a90cce8e5cb0f4a3 (patch) | |
tree | da3bb9c59ff594987f889c4625eff29ca8881dc6 /tests | |
parent | 3810fb8881131bae5b4c4c2acb0b5464b35ff1ea (diff) | |
download | file-git-603c5a7987481c4a1d86cc08a90cce8e5cb0f4a3.tar.gz |
Support android vdex files from Kvist, HÃ¥kan:
A vdex file contains information used by ART (Android Runtime).
Some more information for the interested:
https://source.android.com/devices/tech/dalvik/configure
https://source.android.com/devices/tech/dalvik
Diffstat (limited to 'tests')
-rw-r--r-- | tests/android-vdex-1.result | 1 | ||||
-rw-r--r-- | tests/android-vdex-1.testfile | bin | 0 -> 20 bytes | |||
-rw-r--r-- | tests/android-vdex-2.result | 1 | ||||
-rw-r--r-- | tests/android-vdex-2.testfile | bin | 0 -> 20 bytes | |||
-rw-r--r-- | tests/test.c | 87 |
5 files changed, 56 insertions, 33 deletions
diff --git a/tests/android-vdex-1.result b/tests/android-vdex-1.result new file mode 100644 index 00000000..2a4ef6d6 --- /dev/null +++ b/tests/android-vdex-1.result @@ -0,0 +1 @@ +Android vdex file, verifier deps version: 021, dex section version: 002, number of dex files: 4, verifier deps size: 106328
\ No newline at end of file diff --git a/tests/android-vdex-1.testfile b/tests/android-vdex-1.testfile Binary files differnew file mode 100644 index 00000000..25f4f06e --- /dev/null +++ b/tests/android-vdex-1.testfile diff --git a/tests/android-vdex-2.result b/tests/android-vdex-2.result new file mode 100644 index 00000000..498ae97c --- /dev/null +++ b/tests/android-vdex-2.result @@ -0,0 +1 @@ +Android vdex file, being processed by dex2oat, verifier deps version: 019, dex section version: 002, number of dex files: 1, verifier deps size: 1016
\ No newline at end of file diff --git a/tests/android-vdex-2.testfile b/tests/android-vdex-2.testfile Binary files differnew file mode 100644 index 00000000..7e7761d7 --- /dev/null +++ b/tests/android-vdex-2.testfile diff --git a/tests/test.c b/tests/test.c index 502522f9..f6b377d9 100644 --- a/tests/test.c +++ b/tests/test.c @@ -28,14 +28,19 @@ #include <stdio.h> #include <stdlib.h> #include <string.h> +#include <errno.h> + #include "magic.h" +static const char *prog; + static void * xrealloc(void *p, size_t n) { p = realloc(p, n); if (p == NULL) { - (void)fprintf(stderr, "ERROR slurping file: out of memory\n"); + (void)fprintf(stderr, "%s ERROR slurping file: %s\n", + prog, strerror(errno)); exit(10); } return p; @@ -50,7 +55,7 @@ slurp(FILE *fp, size_t *final_len) for (c = getc(fp); c != EOF; c = getc(fp)) { if (s == l + len) { - l = (char *)xrealloc(l, len * 2); + l = xrealloc(l, len * 2); len *= 2; } *s++ = c; @@ -69,47 +74,63 @@ main(int argc, char **argv) { struct magic_set *ms; const char *result; + size_t result_len, desired_len; char *desired; - size_t desired_len; - int i; + int i, e = EXIT_FAILURE; FILE *fp; + + prog = strrchr(argv[0], '/'); + if (prog) + prog++; + else + prog = argv[0]; + ms = magic_open(MAGIC_NONE); if (ms == NULL) { - (void)fprintf(stderr, "ERROR opening MAGIC_NONE: out of memory\n"); - return 10; + (void)fprintf(stderr, "%s: ERROR opening MAGIC_NONE: %s\n", + prog, strerror(errno)); + return e; } if (magic_load(ms, NULL) == -1) { - (void)fprintf(stderr, "ERROR loading with NULL file: %s\n", - magic_error(ms)); - return 11; + (void)fprintf(stderr, "%s: ERROR loading with NULL file: %s\n", + prog, magic_error(ms)); + goto bad; } - if (argc > 1) { - if (argc != 3) { - (void)fprintf(stderr, "Usage: test TEST-FILE RESULT\n"); - } else { - if ((result = magic_file(ms, argv[1])) == NULL) { - (void)fprintf(stderr, "ERROR loading file %s: %s\n", argv[1], magic_error(ms)); - return 12; - } else { - fp = fopen(argv[2], "r"); - if (fp == NULL) { - (void)fprintf(stderr, "ERROR opening `%s': ", argv[2]); - perror(NULL); - return 13; - } - desired = slurp(fp, &desired_len); - fclose(fp); - (void)printf("%s: %s\n", argv[1], result); - if (strcmp(result, desired) != 0) { - (void)fprintf(stderr, "Error: result was\n%s\nexpected:\n%s\n", result, desired); - return 1; - } - } - } + if (argc == 1) { + e = 0; + goto bad; } + if (argc != 3) { + (void)fprintf(stderr, "Usage: %s TEST-FILE RESULT\n", prog); + magic_close(ms); + goto bad; + } + if ((result = magic_file(ms, argv[1])) == NULL) { + (void)fprintf(stderr, "%s: ERROR loading file %s: %s\n", + prog, argv[1], magic_error(ms)); + goto bad; + } + fp = fopen(argv[2], "r"); + if (fp == NULL) { + (void)fprintf(stderr, "%s: ERROR opening `%s': %s", + prog, argv[2], strerror(errno)); + goto bad; + } + desired = slurp(fp, &desired_len); + fclose(fp); + (void)printf("%s: %s\n", argv[1], result); + if (strcmp(result, desired) != 0) { + result_len = strlen(result); + (void)fprintf(stderr, "%s: ERROR: result was (len %zu)\n%s\n" + "expected (len %zu)\n%s\n", prog, result_len, result, + desired_len, desired); + goto bad; + } + e = 0; +bad: magic_close(ms); - return 0; + return e; } |