/* * This file is part of libsamsung-ipc. * * Copyright (C) 2023 Denis 'GNUtoo' Carikli * * libsamsung-ipc is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 2 of the License, or * (at your option) any later version. * * libsamsung-ipc is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with libsamsung-ipc. If not, see . */ #include #include #include #include #include #include #include #include #include void usage(char *progname) { printf("Usage:\n"); printf("\t%s FILE command # %s\n", basename(progname), "Get bruteforce command."); printf("\t%s FILE bruteforce # %s\n", basename(progname), "Get bruteforce command."); printf("\t%s list-supported # %s\n", basename(progname), "List supported devices/EFS."); printf("\t%s --help # %s\n", basename(progname), "Print this help."); } int print_byte(int fd, off_t base, uint8_t offset) { off_t file_offset; ssize_t rd; char buf[1]; int rc; bzero(&buf, sizeof(buf)); file_offset = lseek(fd, base + offset, SEEK_SET); if (file_offset == -1) { int err = errno; printf("%s: lseek: %s\n", __func__, strerror(err)); return EX_OSERR; } do { rd = read(fd, &buf, 1); if (rd == -1) { int err = errno; printf("%s: read: %s\n", __func__, strerror(err)); return EX_OSERR; } } while (rd != 1); rc = printf("%02x", buf[0] & 0xff); if (rc < 0) { int err = errno; printf("%s: printf: %s\n", __func__, strerror(err)); return EX_OSERR; } return 0; } off_t field_offset(unsigned field_nr) { if (field_nr == 0) return 0x18146e; else if (field_nr == 1) return 0x18148e; else if (field_nr == 2) return 0x1814ce; else if (field_nr == 3) return 0x1814fe; else return 0; } int cmd_list_supported(void) { printf("Supported devices:\n\t%s\n", "Galaxy S II (GT-I9100)"); return 0; } int cmd_command(char* nv_data_path, int field_nr) { int fd; int rc; int i; off_t base; base = field_offset(field_nr); if (base == 0) { printf("%s: invalid field_offset: 0\n", __func__); return EX_SOFTWARE; } fd = open(nv_data_path, O_RDONLY); if (fd == -1) { printf("%s: open: %s\n", __func__, strerror(errno)); return EX_NOINPUT; } printf("hashcat -m 110 --hex-salt -a 3 "); for (i=0; i<20 ; i++) { rc = print_byte(fd, base, i); if (rc) return rc; } rc = printf(":0000000000000000 ?d?d?d?d?d?d?d?d --show" " | " "cut -d : -f 3\n"); if (rc == -1) { printf("%s: printf: %s\n", __func__, strerror(errno)); return EX_OSERR; } rc = close (fd); if (fd == -1) { printf("%s: close: %s\n", __func__, strerror(errno)); return EX_OSERR; } return 0; } int cmd_bruteforce() { return 0; } int main(int argc, char * const argv[]) { if (argc == 4 && !strcmp(argv[2], "command")) { char *endptr; int field_nr = 0; field_nr = strtol(argv[3], &endptr, 10); if (errno != 0) { usage(argv[0]); return EX_USAGE; } if (!(argv[3][0] != '\0' && *endptr == '\0')) { usage(argv[0]); return EX_USAGE; } return cmd_command(argv[1], field_nr); } else if (argc == 4 && !strcmp(argv[2], "bruteforce")) { char *endptr; int field_nr = 0; field_nr = strtol(argv[3], &endptr, 10); if (errno != 0) { usage(argv[0]); return EX_USAGE; } if (!(argv[3][0] != '\0' && *endptr == '\0')) { usage(argv[0]); return EX_USAGE; } return cmd_bruteforce(argv[1], field_nr); } else if (argc == 2 && !strcmp(argv[1], "list-supported")) { return cmd_list_supported(); } else if (argc == 2 && !strcmp(argv[1], "--help")) { usage(argv[0]); return 0; } else { usage(argv[0]); return EX_USAGE; } }