/* * Trevor's utility to decode a GSM OTA file. * * Copyright (C) 2003 Trevor Man * * This program 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. * * This program 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 this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include int main(int argc, char *argv[]) { FILE *fp; int temp; int count; int height; int width; int bpp; fprintf(stderr, "Trevor's SMS OTA file decoder v1.0 - Copyright 2003 - Trevor Man\n"); if (argc != 2) { fprintf(stderr, "Syntax: %s picture.ota\n", argv[0]); return -1; } if ((fp = fopen(argv[1], "rb")) == NULL) { fprintf(stderr, "Unable to open %s\n", argv[1]); return -1; } if (fgetc(fp) != 0) { fprintf(stderr, "Invalid file format\n"); } width = fgetc(fp); height = fgetc(fp); bpp = fgetc(fp); fprintf(stderr, "Image dimensions: %dx%d@%dbpp\n", width, height, bpp); if ((width == 0) || (height == 0)) { fprintf(stderr, "Invalid image size.\n"); return -1; } if (bpp != 1) { fprintf(stderr, "Unsupported bit depth (%d). Only 1-bit images supported.\n", bpp); return -1; } for (count = 0; count < (height * width); count += 8) { if ((temp = fgetc(fp)) == -1) temp = 0x00; fprintf(stdout, "%c%c%c%c%c%c%c%c", temp & 0x80 ? '#' : ' ', temp & 0x40 ? '#' : ' ', temp & 0x20 ? '#' : ' ', temp & 0x10 ? '#' : ' ', temp & 0x08 ? '#' : ' ', temp & 0x04 ? '#' : ' ', temp & 0x02 ? '#' : ' ', temp & 0x01 ? '#' : ' '); if ((count > 0) && ((count + 8) % width == 0)) fprintf(stdout, "\n"); } fclose(fp); return 0; }