mirror of
https://github.com/file/file.git
synced 2024-11-23 09:56:30 +08:00
Support android vdex files from Kvist, Hkan:
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
This commit is contained in:
parent
3810fb8881
commit
603c5a7987
@ -1,6 +1,6 @@
|
|||||||
|
|
||||||
#------------------------------------------------------------
|
#------------------------------------------------------------
|
||||||
# $File: android,v 1.16 2019/11/15 21:03:14 christos Exp $
|
# $File: android,v 1.17 2020/11/21 15:57:07 christos Exp $
|
||||||
# Various android related magic entries
|
# Various android related magic entries
|
||||||
#------------------------------------------------------------
|
#------------------------------------------------------------
|
||||||
|
|
||||||
@ -188,3 +188,22 @@
|
|||||||
0 lelong 0xd0b5b1c4 Android cryptfs footer
|
0 lelong 0xd0b5b1c4 Android cryptfs footer
|
||||||
>4 leshort x \b, version: %d
|
>4 leshort x \b, version: %d
|
||||||
>6 leshort x \b.%d
|
>6 leshort x \b.%d
|
||||||
|
|
||||||
|
# Android Vdex format
|
||||||
|
# From https://android.googlesource.com/\
|
||||||
|
# platform/art/+/master/runtime/vdex_file.h
|
||||||
|
0 string vdex Android vdex file,
|
||||||
|
>4 string >000 verifier deps version: %s,
|
||||||
|
>8 string >000 dex section version: %s,
|
||||||
|
>12 lelong >0 number of dex files: %d,
|
||||||
|
>16 lelong >0 verifier deps size: %d
|
||||||
|
|
||||||
|
# Android Vdex format, dexfile is currently being updated
|
||||||
|
# by android system
|
||||||
|
# From https://android.googlesource.com/\
|
||||||
|
# platform/art/+/master/dex2oat/dex2oat.cc
|
||||||
|
0 string wdex Android vdex file, being processed by dex2oat,
|
||||||
|
>4 string >000 verifier deps version: %s,
|
||||||
|
>8 string >000 dex section version: %s,
|
||||||
|
>12 lelong >0 number of dex files: %d,
|
||||||
|
>16 lelong >0 verifier deps size: %d
|
||||||
|
1
tests/android-vdex-1.result
Normal file
1
tests/android-vdex-1.result
Normal file
@ -0,0 +1 @@
|
|||||||
|
Android vdex file, verifier deps version: 021, dex section version: 002, number of dex files: 4, verifier deps size: 106328
|
BIN
tests/android-vdex-1.testfile
Normal file
BIN
tests/android-vdex-1.testfile
Normal file
Binary file not shown.
1
tests/android-vdex-2.result
Normal file
1
tests/android-vdex-2.result
Normal file
@ -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
|
BIN
tests/android-vdex-2.testfile
Normal file
BIN
tests/android-vdex-2.testfile
Normal file
Binary file not shown.
87
tests/test.c
87
tests/test.c
@ -28,14 +28,19 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <errno.h>
|
||||||
|
|
||||||
#include "magic.h"
|
#include "magic.h"
|
||||||
|
|
||||||
|
static const char *prog;
|
||||||
|
|
||||||
static void *
|
static void *
|
||||||
xrealloc(void *p, size_t n)
|
xrealloc(void *p, size_t n)
|
||||||
{
|
{
|
||||||
p = realloc(p, n);
|
p = realloc(p, n);
|
||||||
if (p == NULL) {
|
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);
|
exit(10);
|
||||||
}
|
}
|
||||||
return p;
|
return p;
|
||||||
@ -50,7 +55,7 @@ slurp(FILE *fp, size_t *final_len)
|
|||||||
|
|
||||||
for (c = getc(fp); c != EOF; c = getc(fp)) {
|
for (c = getc(fp); c != EOF; c = getc(fp)) {
|
||||||
if (s == l + len) {
|
if (s == l + len) {
|
||||||
l = (char *)xrealloc(l, len * 2);
|
l = xrealloc(l, len * 2);
|
||||||
len *= 2;
|
len *= 2;
|
||||||
}
|
}
|
||||||
*s++ = c;
|
*s++ = c;
|
||||||
@ -69,47 +74,63 @@ main(int argc, char **argv)
|
|||||||
{
|
{
|
||||||
struct magic_set *ms;
|
struct magic_set *ms;
|
||||||
const char *result;
|
const char *result;
|
||||||
|
size_t result_len, desired_len;
|
||||||
char *desired;
|
char *desired;
|
||||||
size_t desired_len;
|
int i, e = EXIT_FAILURE;
|
||||||
int i;
|
|
||||||
FILE *fp;
|
FILE *fp;
|
||||||
|
|
||||||
|
|
||||||
|
prog = strrchr(argv[0], '/');
|
||||||
|
if (prog)
|
||||||
|
prog++;
|
||||||
|
else
|
||||||
|
prog = argv[0];
|
||||||
|
|
||||||
ms = magic_open(MAGIC_NONE);
|
ms = magic_open(MAGIC_NONE);
|
||||||
if (ms == NULL) {
|
if (ms == NULL) {
|
||||||
(void)fprintf(stderr, "ERROR opening MAGIC_NONE: out of memory\n");
|
(void)fprintf(stderr, "%s: ERROR opening MAGIC_NONE: %s\n",
|
||||||
return 10;
|
prog, strerror(errno));
|
||||||
|
return e;
|
||||||
}
|
}
|
||||||
if (magic_load(ms, NULL) == -1) {
|
if (magic_load(ms, NULL) == -1) {
|
||||||
(void)fprintf(stderr, "ERROR loading with NULL file: %s\n",
|
(void)fprintf(stderr, "%s: ERROR loading with NULL file: %s\n",
|
||||||
magic_error(ms));
|
prog, magic_error(ms));
|
||||||
return 11;
|
goto bad;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (argc > 1) {
|
if (argc == 1) {
|
||||||
if (argc != 3) {
|
e = 0;
|
||||||
(void)fprintf(stderr, "Usage: test TEST-FILE RESULT\n");
|
goto bad;
|
||||||
} 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 != 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);
|
magic_close(ms);
|
||||||
return 0;
|
return e;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user