summaryrefslogtreecommitdiffstats
path: root/extra-functions.c
diff options
context:
space:
mode:
authorDees_Troy <dees_troy@teamw.in>2012-09-11 16:27:01 +0200
committerDees_Troy <dees_troy@teamw.in>2012-09-11 16:27:49 +0200
commitfdf5fcc34416ff1d859acec2a61780bd8f13ece5 (patch)
tree82d22873ff53679f595cd58f4a8428f561692e31 /extra-functions.c
parentZip install works again (diff)
downloadandroid_bootable_recovery-fdf5fcc34416ff1d859acec2a61780bd8f13ece5.tar
android_bootable_recovery-fdf5fcc34416ff1d859acec2a61780bd8f13ece5.tar.gz
android_bootable_recovery-fdf5fcc34416ff1d859acec2a61780bd8f13ece5.tar.bz2
android_bootable_recovery-fdf5fcc34416ff1d859acec2a61780bd8f13ece5.tar.lz
android_bootable_recovery-fdf5fcc34416ff1d859acec2a61780bd8f13ece5.tar.xz
android_bootable_recovery-fdf5fcc34416ff1d859acec2a61780bd8f13ece5.tar.zst
android_bootable_recovery-fdf5fcc34416ff1d859acec2a61780bd8f13ece5.zip
Diffstat (limited to '')
-rw-r--r--extra-functions.c118
1 files changed, 0 insertions, 118 deletions
diff --git a/extra-functions.c b/extra-functions.c
index 4b03bc963..8a2e9ce9c 100644
--- a/extra-functions.c
+++ b/extra-functions.c
@@ -222,124 +222,6 @@ int __pclose(FILE *iop) {
return (pid == -1 ? -1 : pstat);
}
-char* sanitize_device_id(char* id) {
- const char* whitelist ="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890-._";
- char* c = id;
- char* str = (int*) calloc(50, sizeof *id);
- while (*c)
- {
- if (strchr(whitelist, *c))
- {
- strncat(str, c, 1);
- }
- c++;
- }
- return str;
-}
-
-#define CMDLINE_SERIALNO "androidboot.serialno="
-#define CMDLINE_SERIALNO_LEN (strlen(CMDLINE_SERIALNO))
-#define CPUINFO_SERIALNO "Serial"
-#define CPUINFO_SERIALNO_LEN (strlen(CPUINFO_SERIALNO))
-#define CPUINFO_HARDWARE "Hardware"
-#define CPUINFO_HARDWARE_LEN (strlen(CPUINFO_HARDWARE))
-
-void get_device_id() {
- FILE *fp;
- char line[2048];
- char hardware_id[32];
- char* token;
- char* new_device_id;
-
- // Assign a blank device_id to start with
- device_id[0] = 0;
-
- // First, try the cmdline to see if the serial number was supplied
- fp = fopen("/proc/cmdline", "rt");
- if (fp != NULL)
- {
- // First step, read the line. For cmdline, it's one long line
- fgets(line, sizeof(line), fp);
- fclose(fp);
-
- // Now, let's tokenize the string
- token = strtok(line, " ");
-
- // Let's walk through the line, looking for the CMDLINE_SERIALNO token
- while (token)
- {
- // We don't need to verify the length of token, because if it's too short, it will mismatch CMDLINE_SERIALNO at the NULL
- if (memcmp(token, CMDLINE_SERIALNO, CMDLINE_SERIALNO_LEN) == 0)
- {
- // We found the serial number!
- strcpy(device_id, token + CMDLINE_SERIALNO_LEN);
- new_device_id = sanitize_device_id(device_id);
- strcpy(device_id, new_device_id);
- free(new_device_id);
- return;
- }
- token = strtok(NULL, " ");
- }
- }
-
- // Now we'll try cpuinfo for a serial number
- fp = fopen("/proc/cpuinfo", "rt");
- if (fp != NULL)
- {
- while (fgets(line, sizeof(line), fp) != NULL) { // First step, read the line.
- if (memcmp(line, CPUINFO_SERIALNO, CPUINFO_SERIALNO_LEN) == 0) // check the beginning of the line for "Serial"
- {
- // We found the serial number!
- token = line + CPUINFO_SERIALNO_LEN; // skip past "Serial"
- while ((*token > 0 && *token <= 32 ) || *token == ':') token++; // skip over all spaces and the colon
- if (*token != 0) {
- token[30] = 0;
- if (token[strlen(token)-1] == 10) { // checking for endline chars and dropping them from the end of the string if needed
- memset(device_id, 0, sizeof(device_id));
- strncpy(device_id, token, strlen(token) - 1);
- } else {
- strcpy(device_id, token);
- }
- LOGI("=> serial from cpuinfo: '%s'\n", device_id);
- fclose(fp);
- new_device_id = sanitize_device_id(device_id);
- strcpy(device_id, new_device_id);
- free(new_device_id);
- return;
- }
- } else if (memcmp(line, CPUINFO_HARDWARE, CPUINFO_HARDWARE_LEN) == 0) {// We're also going to look for the hardware line in cpuinfo and save it for later in case we don't find the device ID
- // We found the hardware ID
- token = line + CPUINFO_HARDWARE_LEN; // skip past "Hardware"
- while ((*token > 0 && *token <= 32 ) || *token == ':') token++; // skip over all spaces and the colon
- if (*token != 0) {
- token[30] = 0;
- if (token[strlen(token)-1] == 10) { // checking for endline chars and dropping them from the end of the string if needed
- memset(hardware_id, 0, sizeof(hardware_id));
- strncpy(hardware_id, token, strlen(token) - 1);
- } else {
- strcpy(hardware_id, token);
- }
- LOGI("=> hardware id from cpuinfo: '%s'\n", hardware_id);
- }
- }
- }
- fclose(fp);
- }
-
- if (hardware_id[0] != 0) {
- LOGW("\nusing hardware id for device id: '%s'\n", hardware_id);
- strcpy(device_id, hardware_id);
- new_device_id = sanitize_device_id(device_id);
- strcpy(device_id, new_device_id);
- free(new_device_id);
- return;
- }
-
- strcpy(device_id, "serialno");
- LOGE("=> device id not found, using '%s'.", device_id);
- return;
-}
-
char* get_path (char* path) {
char *s;