Rizin
unix-like reverse engineering framework and cli tools
zip_source_file_win32.h File Reference
#include <windows.h>
#include <aclapi.h>
#include <stdlib.h>
#include "zipint.h"
#include "zip_source_file.h"

Go to the source code of this file.

Classes

struct  zip_win32_file_operations
 

Macros

#define _WIN32_WINNT   0x0501
 

Typedefs

typedef struct zip_win32_file_operations zip_win32_file_operations_t
 

Functions

void _zip_win32_op_close (zip_source_file_context_t *ctx)
 
zip_int64_t _zip_win32_op_read (zip_source_file_context_t *ctx, void *buf, zip_uint64_t len)
 
bool _zip_win32_op_seek (zip_source_file_context_t *ctx, void *f, zip_int64_t offset, int whence)
 
zip_int64_t _zip_win32_op_tell (zip_source_file_context_t *ctx, void *f)
 
bool _zip_filetime_to_time_t (FILETIME ft, time_t *t)
 
int _zip_win32_error_to_errno (DWORD win32err)
 

Variables

zip_source_file_operations_t _zip_source_file_win32_named_ops
 

Macro Definition Documentation

◆ _WIN32_WINNT

#define _WIN32_WINNT   0x0501

Definition at line 39 of file zip_source_file_win32.h.

Typedef Documentation

◆ zip_win32_file_operations_t

Function Documentation

◆ _zip_filetime_to_time_t()

bool _zip_filetime_to_time_t ( FILETIME  ft,
time_t t 
)

Definition at line 213 of file zip_source_file_win32.c.

213  {
214  /*
215  Inspired by http://stackoverflow.com/questions/6161776/convert-windows-filetime-to-second-in-unix-linux
216  */
217  const zip_int64_t WINDOWS_TICK = 10000000LL;
218  const zip_int64_t SEC_TO_UNIX_EPOCH = 11644473600LL;
219  ULARGE_INTEGER li;
220  zip_int64_t secs;
221  time_t temp;
222 
223  li.LowPart = ft.dwLowDateTime;
224  li.HighPart = ft.dwHighDateTime;
225  secs = (li.QuadPart / WINDOWS_TICK - SEC_TO_UNIX_EPOCH);
226 
227  temp = (time_t)secs;
228  if (secs != (zip_int64_t)temp) {
229  return false;
230  }
231 
232  *t = temp;
233  return true;
234 }
int time_t
Definition: sftypes.h:66
int64_t zip_int64_t
Definition: zipconf.h:38

Referenced by _zip_stat_win32(), and _zip_win32_named_op_stat().

◆ _zip_win32_error_to_errno()

int _zip_win32_error_to_errno ( DWORD  win32err)

Definition at line 153 of file zip_source_file_win32.c.

153  {
154  /* Note: This list isn't exhaustive, but should cover common cases. */
155  switch (win32err) {
156  case ERROR_INVALID_PARAMETER:
157  return EINVAL;
158  case ERROR_FILE_NOT_FOUND:
159  case ERROR_PATH_NOT_FOUND:
160  return ENOENT;
161  case ERROR_INVALID_HANDLE:
162  return EBADF;
163  case ERROR_ACCESS_DENIED:
164  return EACCES;
165  case ERROR_FILE_EXISTS:
166  return EEXIST;
167  case ERROR_TOO_MANY_OPEN_FILES:
168  return EMFILE;
169  case ERROR_DISK_FULL:
170  return ENOSPC;
171  default:
172  return 10000 + win32err;
173  }
174 }
#define ENOENT
Definition: sftypes.h:112
#define ENOSPC
Definition: sftypes.h:138
#define EEXIST
Definition: sftypes.h:127
#define EINVAL
Definition: sftypes.h:132
#define EMFILE
Definition: sftypes.h:134
#define EACCES
Definition: sftypes.h:123
#define EBADF
Definition: sftypes.h:119

References EACCES, EBADF, EEXIST, EINVAL, EMFILE, ENOENT, and ENOSPC.

Referenced by _zip_stat_win32(), _zip_win32_named_op_commit_write(), _zip_win32_named_op_create_temp_output(), _zip_win32_named_op_remove(), _zip_win32_named_op_stat(), _zip_win32_named_op_write(), _zip_win32_op_read(), _zip_win32_op_seek(), _zip_win32_op_tell(), and win32_named_open().

◆ _zip_win32_op_close()

void _zip_win32_op_close ( zip_source_file_context_t ctx)

Definition at line 82 of file zip_source_file_win32.c.

82  {
83  CloseHandle((HANDLE)ctx->f);
84 }
DWORD * HANDLE

References HANDLE.

◆ _zip_win32_op_read()

zip_int64_t _zip_win32_op_read ( zip_source_file_context_t ctx,
void *  buf,
zip_uint64_t  len 
)

Definition at line 88 of file zip_source_file_win32.c.

88  {
89  DWORD i;
90 
91  /* TODO: cap len to "DWORD_MAX" */
92  if (!ReadFile((HANDLE)ctx->f, buf, (DWORD)len, &i, NULL)) {
94  return -1;
95  }
96 
97  return (zip_int64_t)i;
98 }
size_t len
Definition: 6502dis.c:15
lzma_index ** i
Definition: index.h:629
#define NULL
Definition: cris-opc.c:27
voidpf void * buf
Definition: ioapi.h:138
ZIP_EXTERN void zip_error_set(zip_error_t *_Nullable, int, int)
Definition: zip_error.c:126
#define ZIP_ER_READ
Definition: zip.h:110
zip_error_t * error
DWORD
int _zip_win32_error_to_errno(DWORD win32err)

References _zip_win32_error_to_errno(), DWORD, ctx::error, HANDLE, i, len, NULL, ZIP_ER_READ, and zip_error_set().

◆ _zip_win32_op_seek()

bool _zip_win32_op_seek ( zip_source_file_context_t ctx,
void *  f,
zip_int64_t  offset,
int  whence 
)

Definition at line 102 of file zip_source_file_win32.c.

102  {
103  LARGE_INTEGER li;
104  DWORD method;
105 
106  switch (whence) {
107  case SEEK_SET:
108  method = FILE_BEGIN;
109  break;
110  case SEEK_END:
111  method = FILE_END;
112  break;
113  case SEEK_CUR:
114  method = FILE_CURRENT;
115  break;
116  default:
118  return false;
119  }
120 
121  li.QuadPart = (LONGLONG)offset;
122  if (!SetFilePointerEx((HANDLE)f, li, NULL, method)) {
124  return false;
125  }
126 
127  return true;
128 }
voidpf uLong offset
Definition: ioapi.h:144
#define ZIP_ER_SEEK
Definition: zip.h:109
#define f(i)
Definition: sha256.c:46
#define SEEK_SET
Definition: zip.c:88
#define SEEK_CUR
Definition: zip.c:80
#define SEEK_END
Definition: zip.c:84

References _zip_win32_error_to_errno(), DWORD, EINVAL, ctx::error, f, HANDLE, NULL, SEEK_CUR, SEEK_END, SEEK_SET, ZIP_ER_SEEK, and zip_error_set().

◆ _zip_win32_op_tell()

zip_int64_t _zip_win32_op_tell ( zip_source_file_context_t ctx,
void *  f 
)

Definition at line 138 of file zip_source_file_win32.c.

138  {
139  LARGE_INTEGER zero;
140  LARGE_INTEGER new_offset;
141 
142  zero.QuadPart = 0;
143  if (!SetFilePointerEx((HANDLE)f, zero, &new_offset, FILE_CURRENT)) {
145  return -1;
146  }
147 
148  return (zip_int64_t)new_offset.QuadPart;
149 }

References _zip_win32_error_to_errno(), ctx::error, f, HANDLE, ZIP_ER_SEEK, and zip_error_set().

Variable Documentation

◆ _zip_source_file_win32_named_ops

zip_source_file_operations_t _zip_source_file_win32_named_ops
extern