Rizin
unix-like reverse engineering framework and cli tools
cabrip.c File Reference
#include <stdio.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <mspack.h>
#include "mspack/macros.h"

Go to the source code of this file.

Macros

#define BUF_SIZE   (1024*4096)
 

Functions

void rip (char *fname, off_t offset, unsigned int length)
 
int main (int argc, char *argv[])
 

Variables

char buf [BUF_SIZE]
 

Macro Definition Documentation

◆ BUF_SIZE

#define BUF_SIZE   (1024*4096)

Definition at line 15 of file cabrip.c.

Function Documentation

◆ main()

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

Definition at line 64 of file cabrip.c.

64  {
65  struct mscab_decompressor *cabd;
66  struct mscabd_cabinet *cab, *c;
67  int err;
68 
70  if (err) return 0;
71 
74  for (argv++; *argv; argv++) {
75  if ((cab = cabd->search(cabd, *argv))) {
76  for (c = cab; c; c = c->next) {
77  rip(*argv, c->base_offset, c->length);
78  }
79  cabd->close(cabd, cab);
80  }
81  }
83  }
84  return 0;
85 }
static bool err
Definition: armass.c:435
#define MSPACK_SYS_SELFTEST(result)
Definition: mspack.h:191
#define MSCABD_PARAM_SALVAGE
Definition: mspack.h:943
struct mscab_decompressor * cabd
Definition: cabextract.c:126
void rip(char *fname, off_t offset, unsigned int length)
Definition: cabrip.c:18
#define NULL
Definition: cris-opc.c:27
void mspack_destroy_cab_decompressor(struct mscab_decompressor *base)
Definition: cabd.c:173
struct mscab_decompressor * mspack_create_cab_decompressor(struct mspack_system *sys)
Definition: cabd.c:140
static static fork const void static count static fd const char const char static newpath char char argv
Definition: sflib.h:40
#define c(i)
Definition: sha256.c:43
struct mscabd_cabinet *(* search)(struct mscab_decompressor *self, const char *filename)
Definition: mspack.h:1047
void(* close)(struct mscab_decompressor *self, struct mscabd_cabinet *cab)
Definition: mspack.h:1010
int(* set_param)(struct mscab_decompressor *self, int param, int value)
Definition: mspack.h:1164

References argv, c, cabd, mscab_decompressor::close, err, MSCABD_PARAM_SALVAGE, mspack_create_cab_decompressor(), mspack_destroy_cab_decompressor(), MSPACK_SYS_SELFTEST, NULL, rip(), mscab_decompressor::search, and mscab_decompressor::set_param.

◆ rip()

void rip ( char *  fname,
off_t  offset,
unsigned int  length 
)

Definition at line 18 of file cabrip.c.

18  {
19  static unsigned int counter = 1;
20  struct stat st_buf;
21  char outname[13];
22  FILE *in = NULL, *out = NULL;
23 
24  /* find an unused output filename */
25  do {
26  snprintf(outname, 13, "%08u.cab", counter++);
27  } while (stat(outname, &st_buf) == 0);
28 
29  printf("ripping %s offset %" LD " length %u to %s\n",
30  fname, offset, length, outname);
31 
32  if (!(in = fopen(fname, "rb"))) {
33  perror(fname);
34  goto cleanup;
35  }
36  if (!(out = fopen(outname, "wb"))) {
37  perror(outname);
38  goto cleanup;
39  }
40  if (fseek(in, offset, SEEK_SET)) {
41  fprintf(stderr, "%s: can't seek to cab offset %"LD"\n", fname, offset);
42  goto cleanup;
43  }
44  while (length) {
45  size_t run = (length > BUF_SIZE) ? BUF_SIZE : length;
46  size_t actual = fread(&buf[0], 1, run, in);
47  if (actual < run) {
48  fprintf(stderr, "%s: file %u bytes shorter than expected\n",
49  fname, length - (unsigned int)(run - actual));
50  length = run = actual;
51  }
52  if (fwrite(&buf[0], 1, run, out) != run) {
53  perror(outname);
54  break;
55  }
56  length -= run;
57  }
58 
59 cleanup:
60  if (in) fclose(in);
61  if (out) fclose(out);
62 }
const lzma_allocator const uint8_t * in
Definition: block.h:527
const lzma_allocator const uint8_t size_t uint8_t * out
Definition: block.h:528
#define BUF_SIZE
Definition: cabrip.c:15
_Use_decl_annotations_ int __cdecl printf(const char *const _Format,...)
Definition: cs_driver.c:93
static static sync static getppid static getegid const char static filename char static len const char char static bufsiz static mask static vfork const void static prot static getpgrp const char static swapflags static arg static fd static protocol static who struct sockaddr static addrlen static backlog struct timeval struct timezone static tz const struct iovec static count static mode const void const struct sockaddr static tolen const char static pathname void static offset struct stat static buf void long static basep static whence static length const void static len static semflg const void static shmflg const struct timespec struct timespec static rem const char static group const void length
Definition: sflib.h:133
void cleanup(void)
Definition: enough.c:244
voidpf uLong offset
Definition: ioapi.h:144
voidpf void * buf
Definition: ioapi.h:138
snprintf
Definition: kernel.h:364
#define LD
Definition: macros.h:27
static stat
Definition: sflib.h:131
string FILE
Definition: benchmark.py:21
static int run(int i, const char *arg)
Definition: rz-bb.c:19
Definition: sftypes.h:80
int64_t counter
Definition: main.c:4
#define SEEK_SET
Definition: zip.c:88

References BUF_SIZE, cleanup(), counter, benchmark::FILE, create_tags_rz::fname, in, LD, length, NULL, out, printf(), run(), SEEK_SET, snprintf, and stat.

Referenced by main(), parse_thread(), rz_test_run_asm_test(), and subvar().

Variable Documentation

◆ buf

char buf[BUF_SIZE]

Definition at line 16 of file cabrip.c.