1 /* SPDX-License-Identifier: GPL-2.0-or-later */
4 scanlzma, scan for lzma compressed data in stdin and echo it to stdout.
5 Copyright (C) 2006 Timo Lindfors
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
20 $ wget http://www.wifi-shop.cz/Files/produkty/wa2204/wa2204av1.4.1.zip
21 $ unzip wa2204av1.4.1.zip
22 $ gcc scanlzma.c -o scanlzma -Wall
23 $ ./scanlzma 0 < WA2204-FW1.4.1/linux-1.4.bin | lzma -c -d | strings | grep -i "copyright"
24 UpdateDD version 2.5, Copyright (C) 2005 Philipp Benner.
25 Copyright (C) 2005 Philipp Benner.
26 Copyright (C) 2005 Philipp Benner.
27 mawk 1.3%s%s %s, Copyright (C) Michael D. Brennan
28 # Copyright (C) 1998, 1999, 2001 Henry Spencer.
34 /* LZMA compressed file format */
35 /* --------------------------- */
36 /* Offset Size Description */
37 /* 0 1 Special LZMA properties for compressed data */
38 /* 1 4 Dictionary size (little endian) */
39 /* 5 8 Uncompressed size (little endian). -1 means unknown size */
40 /* 13 Compressed data */
48 int find_lzma_header(unsigned char *buf
) {
52 && (memcmp (buf
+ 10 , "\x00\x00\x00", 3) == 0
53 || (memcmp (buf
+ 5, "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF", 8) == 0)));
56 int main(int argc
, char *argv
[]) {
57 unsigned char buf
[BUFSIZE
];
58 int ret
, i
, numlzma
, blocks
=0;
61 printf("usage: %s numlzma < infile | lzma -c -d > outfile\n"
62 "where numlzma is index of lzma file to extract, starting from zero.\n",
66 numlzma
= atoi(argv
[1]);
70 ret
= fread(buf
, BUFSIZE
, 1, stdin
);
74 /* Scan for signature. */
75 for (i
= 0; i
<BUFSIZE
-23; i
++) {
76 if (find_lzma_header(buf
+i
) && numlzma
-- <= 0) {
77 fwrite(buf
+i
, (BUFSIZE
-i
), 1, stdout
);