Rizin
unix-like reverse engineering framework and cli tools
fseek.c File Reference
#include <stdlib.h>
#include "zip.h"

Go to the source code of this file.

Macros

#define USAGE   "usage: %s archive index offset\n"
 

Functions

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

Variables

const char * progname
 

Macro Definition Documentation

◆ USAGE

#define USAGE   "usage: %s archive index offset\n"

Definition at line 39 of file fseek.c.

Function Documentation

◆ main()

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

Definition at line 42 of file fseek.c.

42  {
43  int ze;
44  zip_t *z;
45  zip_file_t *zf;
46  char *archive;
48  zip_uint64_t index;
49  char b[1024];
50 
51  progname = argv[0];
52 
53  if (argc != 4) {
54  fprintf(stderr, USAGE, progname);
55  return 1;
56  }
57 
58  archive = argv[1];
59  index = strtoull(argv[2], NULL, 10);
60  offset = (zip_int64_t)strtoull(argv[3], NULL, 10);
61 
62  if ((z = zip_open(archive, 0, &ze)) == NULL) {
65  fprintf(stderr, "%s: can't open zip archive '%s': %s\n", progname, archive, zip_error_strerror(&error));
67  return 1;
68  }
69 
70  if ((zf = zip_fopen_index(z, index, 0)) == NULL) {
71  fprintf(stderr, "%s: can't open file in archive '%s': %s\n", progname, archive, zip_error_strerror(zip_file_get_error(zf)));
72  zip_close(z);
73  return 1;
74  }
75 
76  if (zip_fseek(zf, offset, SEEK_SET) < 0) {
77  fprintf(stderr, "%s: zip_fseek failed: %s\n", progname, zip_error_strerror(zip_file_get_error(zf)));
78  zip_fclose(zf);
79  zip_close(z);
80  return 1;
81  }
82 
83  while ((n = zip_fread(zf, b, sizeof(b))) > 0) {
84  printf("%.*s", (int)n, b);
85  }
86  if (n < 0) {
87  fprintf(stderr, "%s: zip_fread failed: %s\n", progname, zip_error_strerror(zip_file_get_error(zf)));
88  zip_fclose(zf);
89  zip_close(z);
90  return 1;
91  }
92 
93  if (zip_fclose(zf) == -1) {
94  fprintf(stderr, "%s: can't close zip archive entry %" PRIu64 " in '%s': %s\n", progname, index, archive, zip_strerror(z));
95  return 1;
96  }
97 
98  if (zip_close(z) == -1) {
99  fprintf(stderr, "%s: can't close zip archive '%s': %s\n", progname, archive, zip_strerror(z));
100  return 1;
101  }
102 
103  return 0;
104 }
#define NULL
Definition: cris-opc.c:27
_Use_decl_annotations_ int __cdecl printf(const char *const _Format,...)
Definition: cs_driver.c:93
#define USAGE
Definition: fseek.c:39
const char * progname
Definition: fseek.c:38
voidpf uLong offset
Definition: ioapi.h:144
#define PRIu64
Definition: macros.h:18
ZIP_EXTERN void zip_error_init_with_code(zip_error_t *_Nonnull, int)
Definition: zip_error.c:66
ZIP_EXTERN int zip_fclose(zip_file_t *_Nonnull)
Definition: zip_fclose.c:41
ZIP_EXTERN zip_int8_t zip_fseek(zip_file_t *_Nonnull, zip_int64_t, int)
Definition: zip_fseek.c:38
ZIP_EXTERN zip_int64_t zip_fread(zip_file_t *_Nonnull, void *_Nonnull, zip_uint64_t)
Definition: zip_fread.c:39
ZIP_EXTERN int zip_close(zip_t *_Nonnull)
Definition: zip_close.c:52
ZIP_EXTERN void zip_error_fini(zip_error_t *_Nonnull)
Definition: zip_error.c:52
ZIP_EXTERN zip_error_t *_Nonnull zip_file_get_error(zip_file_t *_Nonnull)
Definition: zip_error_get.c:52
ZIP_EXTERN zip_t *_Nullable zip_open(const char *_Nonnull, int, int *_Nullable)
Definition: zip_open.c:54
ZIP_EXTERN const char *_Nonnull zip_error_strerror(zip_error_t *_Nonnull)
ZIP_EXTERN zip_file_t *_Nullable zip_fopen_index(zip_t *_Nonnull, zip_uint64_t, zip_flags_t)
ZIP_EXTERN const char *_Nonnull zip_strerror(zip_t *_Nonnull)
Definition: zip_strerror.c:39
static static fork const void static count static fd const char const char static newpath char char argv
Definition: sflib.h:40
int n
Definition: mipsasm.c:19
#define b(i)
Definition: sha256.c:42
Definition: zipcmp.c:60
Definition: zip.h:284
Definition: zipint.h:278
void error(const char *msg)
Definition: untgz.c:593
#define SEEK_SET
Definition: zip.c:88
uint64_t zip_uint64_t
Definition: zipconf.h:39
int64_t zip_int64_t
Definition: zipconf.h:38

References argv, b, error(), n, NULL, printf(), PRIu64, progname, SEEK_SET, USAGE, zip_close(), zip_error_fini(), zip_error_init_with_code(), zip_error_strerror(), zip_fclose(), zip_file_get_error(), zip_fopen_index(), zip_fread(), zip_fseek(), zip_open(), and zip_strerror().

Variable Documentation

◆ progname

const char* progname

Definition at line 38 of file fseek.c.

Referenced by main().