diff options
-rw-r--r-- | src/common.c | 21 | ||||
-rw-r--r-- | src/common.h | 2 |
2 files changed, 23 insertions, 0 deletions
diff --git a/src/common.c b/src/common.c index 8e76697..57f465a 100644 --- a/src/common.c +++ b/src/common.c @@ -108,3 +108,24 @@ void print_progress_bar(double progress) { if(progress == 100) info("\n"); fflush(stdout); } + +#define GET_RAND(min, max) ((rand() % (max - min)) + min) + +char *generate_guid() +{ + char *guid = (char *) malloc(sizeof(char) * 37); + const char *chars = "ABCDEF0123456789"; + srand(time(NULL)); + int i = 0; + + for (i = 0; i < 36; i++) { + if (i == 8 || i == 13 || i == 18 || i == 23) { + guid[i] = '-'; + continue; + } else { + guid[i] = chars[GET_RAND(0, 16)]; + } + } + guid[36] = '\0'; + return guid; +} diff --git a/src/common.h b/src/common.h index b6873a2..5568930 100644 --- a/src/common.h +++ b/src/common.h @@ -171,6 +171,8 @@ void print_progress_bar(double progress); int read_file(const char* filename, void** data, size_t* size); int write_file(const char* filename, const void* data, size_t size); +char *generate_guid(); + extern struct idevicerestore_client_t* idevicerestore; #ifdef __cplusplus |