summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Nikias Bassen2017-06-18 04:10:57 +0200
committerGravatar Nikias Bassen2017-06-18 04:10:57 +0200
commit835d84b678d23f92622445f5bf142c2bf52a7e9b (patch)
tree42f0d40b3ebf985fe2a6d7e76829c9c0b6a95c5a
parent53fede06af98e24e26939127fcc71c6acfaf4c12 (diff)
downloadlibimobiledevice-835d84b678d23f92622445f5bf142c2bf52a7e9b.tar.gz
libimobiledevice-835d84b678d23f92622445f5bf142c2bf52a7e9b.tar.bz2
idevicescreenshot: Detect screenshot image format to determine file extension
-rw-r--r--tools/idevicescreenshot.c20
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) {