diff options
author | Nikias Bassen | 2017-06-18 04:10:57 +0200 |
---|---|---|
committer | Nikias Bassen | 2017-06-18 04:10:57 +0200 |
commit | 835d84b678d23f92622445f5bf142c2bf52a7e9b (patch) | |
tree | 42f0d40b3ebf985fe2a6d7e76829c9c0b6a95c5a /tools | |
parent | 53fede06af98e24e26939127fcc71c6acfaf4c12 (diff) | |
download | libimobiledevice-835d84b678d23f92622445f5bf142c2bf52a7e9b.tar.gz libimobiledevice-835d84b678d23f92622445f5bf142c2bf52a7e9b.tar.bz2 |
idevicescreenshot: Detect screenshot image format to determine file extension
Diffstat (limited to 'tools')
-rw-r--r-- | tools/idevicescreenshot.c | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/tools/idevicescreenshot.c b/tools/idevicescreenshot.c index da229e2..74acdf6 100644 --- a/tools/idevicescreenshot.c +++ b/tools/idevicescreenshot.c @@ -99,12 +99,22 @@ int main(int argc, char **argv) } else { char *imgdata = NULL; uint64_t imgsize = 0; - if (!filename) { - time_t now = time(NULL); - filename = (char*)malloc(36); - strftime(filename, 36, "screenshot-%Y-%m-%d-%H-%M-%S.tiff", gmtime(&now)); - } if (screenshotr_take_screenshot(shotr, &imgdata, &imgsize) == SCREENSHOTR_E_SUCCESS) { + if (!filename) { + const char *fileext = NULL; + if (memcmp(imgdata, "\x89PNG", 4) == 0) { + fileext = ".png"; + } else if (memcmp(imgdata, "MM\x00*", 4) == 0) { + fileext = ".tiff"; + } else { + printf("WARNING: screenshot data has unexpected image format.\n"); + fileext = ".dat"; + } + time_t now = time(NULL); + filename = (char*)malloc(36); + size_t pos = strftime(filename, 36, "screenshot-%Y-%m-%d-%H-%M-%S", gmtime(&now)); + sprintf(filename+pos, "%s", fileext); + } FILE *f = fopen(filename, "wb"); if (f) { if (fwrite(imgdata, 1, (size_t)imgsize, f) == (size_t)imgsize) { |