Pierre-Hugues Husson | f181109 | 2018-04-10 18:33:33 +0200 | [diff] [blame] | 1 | #include <stdio.h> |
| 2 | #include <sys/types.h> |
| 3 | #include <sys/stat.h> |
| 4 | #include <fcntl.h> |
| 5 | #include <stdint.h> |
| 6 | #include <unistd.h> |
| 7 | #include <stdlib.h> |
| 8 | #include <string.h> |
| 9 | |
| 10 | int main(int argc, char **argv) { |
| 11 | if(argc!=3) { |
| 12 | fprintf(stderr, "Usage: %s <bootimg> <android|spl>\n", argv[0]); |
| 13 | exit(-1); |
| 14 | } |
| 15 | int fd = open(argv[1], O_RDONLY); |
| 16 | lseek(fd, 11*4, SEEK_SET); |
| 17 | uint32_t val = 0; |
| 18 | read(fd, &val, sizeof(val)); |
| 19 | int android = val >> 11; |
| 20 | int a = android >> 14; |
| 21 | int b = (android >> 7) & 0x7f; |
| 22 | int c = android & 0x7f; |
| 23 | |
| 24 | int spl = val & 0x7ff; |
| 25 | int y = 2000 + (spl >> 4); |
| 26 | int m = spl & 0xf; |
| 27 | |
| 28 | fprintf(stderr, "Android: %d.%d.%d\n", a, b, c); |
| 29 | fprintf(stderr, "SPL: %d-%d-01\n", y, m); |
| 30 | |
| 31 | if(strcmp(argv[2], "android") == 0) { |
| 32 | printf("%d.%d.%d", a, b, c); |
| 33 | } else if(strcmp(argv[2], "spl") == 0) { |
| 34 | printf("%04d-%02d-%02d", y, m, 1); |
| 35 | } |
| 36 | |
| 37 | return 0; |
| 38 | } |