Rizin
unix-like reverse engineering framework and cli tools
scanlzma.c File Reference
#include <stdlib.h>
#include <stdio.h>
#include <string.h>

Go to the source code of this file.

Macros

#define BUFSIZE   4096
 

Functions

int find_lzma_header (unsigned char *buf)
 
int main (int argc, char *argv[])
 

Macro Definition Documentation

◆ BUFSIZE

#define BUFSIZE   4096

Definition at line 44 of file scanlzma.c.

Function Documentation

◆ find_lzma_header()

int find_lzma_header ( unsigned char *  buf)

Definition at line 46 of file scanlzma.c.

46  {
47  return (buf[0] < 0xE1
48  && buf[0] == 0x5d
49  && buf[4] < 0x20
50  && (memcmp (buf + 10 , "\x00\x00\x00", 3) == 0
51  || (memcmp (buf + 5, "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF", 8) == 0)));
52 }
voidpf void * buf
Definition: ioapi.h:138

Referenced by main().

◆ main()

int main ( int  argc,
char *  argv[] 
)

Definition at line 54 of file scanlzma.c.

54  {
55  unsigned char buf[BUFSIZE];
56  int ret, i, numlzma, blocks=0;
57 
58  if (argc != 2) {
59  printf("usage: %s numlzma < infile | lzma -c -d > outfile\n"
60  "where numlzma is index of lzma file to extract, starting from zero.\n",
61  argv[0]);
62  exit(1);
63  }
64  numlzma = atoi(argv[1]);
65 
66  for (;;) {
67  /* Read data. */
68  ret = fread(buf, BUFSIZE, 1, stdin);
69  if (ret != 1)
70  break;
71 
72  /* Scan for signature. */
73  for (i = 0; i<BUFSIZE-23; i++) {
74  if (find_lzma_header(buf+i) && numlzma-- <= 0) {
75  fwrite(buf+i, (BUFSIZE-i), 1, stdout);
76  for (;;) {
77  int ch;
78  ch = getchar();
79  if (ch == EOF)
80  exit(0);
81  putchar(ch);
82  }
83  }
84  }
85  blocks++;
86  }
87  return 1;
88 }
lzma_index ** i
Definition: index.h:629
_Use_decl_annotations_ int __cdecl printf(const char *const _Format,...)
Definition: cs_driver.c:93
static static fork const void static count static fd const char const char static newpath char char argv
Definition: sflib.h:40
int find_lzma_header(unsigned char *buf)
Definition: scanlzma.c:46
#define BUFSIZE
Definition: scanlzma.c:44
uint64_t blocks
Definition: list.c:104

References argv, blocks, BUFSIZE, test-lz4-list::exit, find_lzma_header(), i, and printf().