More work to make zip plugin work
This commit is contained in:
parent
c1dd901413
commit
30ebc8b8b3
|
@ -7,6 +7,7 @@ OBJS=${STATIC_OBJS}
|
||||||
OBJS+=io.o plugin.o map.o section.o desc.o cache.o undo.o buffer.o
|
OBJS+=io.o plugin.o map.o section.o desc.o cache.o undo.o buffer.o
|
||||||
|
|
||||||
CFLAGS+=-Wall -DCORELIB
|
CFLAGS+=-Wall -DCORELIB
|
||||||
|
LDFLAGS+=$(STOP)/zip/librz.a
|
||||||
|
|
||||||
include ../socket/deps.mk
|
include ../socket/deps.mk
|
||||||
|
|
||||||
|
|
|
@ -29,7 +29,6 @@ R_API ut64 r_io_desc_size(RIO *io, RIODesc *desc){
|
||||||
return sz;
|
return sz;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
R_API RIODesc *r_io_desc_new(RIOPlugin *plugin, int fd, const char *name, int flags, int mode, void *data) {
|
R_API RIODesc *r_io_desc_new(RIOPlugin *plugin, int fd, const char *name, int flags, int mode, void *data) {
|
||||||
int i;
|
int i;
|
||||||
RIODesc *desc = R_NEW (RIODesc);
|
RIODesc *desc = R_NEW (RIODesc);
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
/* radare - LGPL - Copyright 2008-2012 - pancake */
|
/* radare - LGPL - Copyright 2008-2013 - pancake */
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
|
@ -24,4 +24,4 @@ endif
|
||||||
|
|
||||||
${TARGET_IODBG}: ${OBJ_IODBG}
|
${TARGET_IODBG}: ${OBJ_IODBG}
|
||||||
${CC} $(call libname,io_debug) ${CFLAGS} ${LDFLAGS_LIB} \
|
${CC} $(call libname,io_debug) ${CFLAGS} ${LDFLAGS_LIB} \
|
||||||
${LINKFLAGS} ${LDFLAGS_LINKPATH}.. -L.. -lr_io ${OBJ_IODBG}
|
${LINKFLAGS} ${LDFLAGS_LINKPATH}.. ${OBJ_IODBG} -L.. -lr_io
|
||||||
|
|
|
@ -5,6 +5,10 @@
|
||||||
#include <r_util.h>
|
#include <r_util.h>
|
||||||
#include <r_debug.h> /* only used for BSD PTRACE redefinitions */
|
#include <r_debug.h> /* only used for BSD PTRACE redefinitions */
|
||||||
|
|
||||||
|
#define r_io_redirect(io,file) \
|
||||||
|
free (io->redirect); \
|
||||||
|
io->redirect = file? strdup (file): NULL
|
||||||
|
|
||||||
#if __linux__ || __APPLE__ || __WINDOWS__ || \
|
#if __linux__ || __APPLE__ || __WINDOWS__ || \
|
||||||
__NetBSD__ || __KFBSD__ || __OpenBSD__
|
__NetBSD__ || __KFBSD__ || __OpenBSD__
|
||||||
#define DEBUGGER_SUPPORTED 1
|
#define DEBUGGER_SUPPORTED 1
|
||||||
|
|
|
@ -54,7 +54,12 @@ static RIODesc *__open(RIO *io, const char *file, int rw, int mode) {
|
||||||
free (riog);
|
free (riog);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
#if __WINDOWS__
|
||||||
|
// XXX: bypass lazylinking
|
||||||
|
RETURN_IO_DESC_NEW (&r_io_plugin_gdb, _fd->fd, file, rw, mode, riog);
|
||||||
|
#else
|
||||||
return r_io_desc_new (&r_io_plugin_gdb, _fd->fd, file, rw, mode, riog);
|
return r_io_desc_new (&r_io_plugin_gdb, _fd->fd, file, rw, mode, riog);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
eprintf ("gdb.io.open: Cannot connect to host.\n");
|
eprintf ("gdb.io.open: Cannot connect to host.\n");
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
|
@ -97,7 +97,8 @@ static RIODesc *haret__open(struct r_io_t *io, const char *pathname, int rw, int
|
||||||
return NULL;
|
return NULL;
|
||||||
} else eprintf ("Connected to: %s at port %s\n", ptr, port);
|
} else eprintf ("Connected to: %s at port %s\n", ptr, port);
|
||||||
haret_wait_until_prompt (s);
|
haret_wait_until_prompt (s);
|
||||||
return r_io_desc_new (&r_io_plugin_haret, s->fd, pathname, rw, mode, (void*)s);
|
//return r_io_desc_new (&r_io_plugin_haret, s->fd, pathname, rw, mode, (void*)s);
|
||||||
|
RETURN_IO_DESC_NEW (&r_io_plugin_haret, s->fd, pathname, rw, mode, (void*)s);
|
||||||
}
|
}
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
|
@ -90,9 +90,11 @@ static RIODesc *__open(struct r_io_t *io, const char *pathname, int rw, int mode
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (mal->buf != NULL)
|
if (mal->buf != NULL) {
|
||||||
return r_io_desc_new (&r_io_plugin_malloc, mal->fd,
|
RETURN_IO_DESC_NEW(&r_io_plugin_malloc, mal->fd, pathname, rw, mode,mal);
|
||||||
pathname, rw, mode, mal);
|
|
||||||
|
//return r_io_desc_new (&r_io_plugin_malloc, mal->fd, pathname, rw, mode, mal);
|
||||||
|
}
|
||||||
eprintf ("Cannot allocate (%s) %d bytes\n", pathname+9,
|
eprintf ("Cannot allocate (%s) %d bytes\n", pathname+9,
|
||||||
mal->size);
|
mal->size);
|
||||||
free (mal);
|
free (mal);
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
/* radare - LGPL - Copyright 2012-2013 - pancake
|
/* radare - LGPL - Copyright 2012-2013 - pancake
|
||||||
io_zip.c rewrite: Adam Pridgen <dso@rice.edu || adam.pridgen@thecoverofnight.com>
|
io_zip.c rewrite: Adam Pridgen <dso@rice.edu || adam.pridgen@thecoverofnight.com>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <r_io.h>
|
#include <r_io.h>
|
||||||
#include <r_lib.h>
|
#include <r_lib.h>
|
||||||
|
@ -28,16 +28,12 @@ typedef struct r_io_zip_uri_const_t {
|
||||||
char *URI = "://";
|
char *URI = "://";
|
||||||
|
|
||||||
static RIOZipConstURI ZIP_URIS[] = {
|
static RIOZipConstURI ZIP_URIS[] = {
|
||||||
{"zip://", 6},
|
{"zip://", 6},
|
||||||
{"apk://", 6},
|
{"apk://", 6},
|
||||||
{"jar://", 6},
|
{"jar://", 6},
|
||||||
{NULL, 0}
|
{NULL, 0}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
typedef struct r_io_zip_file_obj_t{
|
typedef struct r_io_zip_file_obj_t{
|
||||||
char * name;
|
char * name;
|
||||||
char * archivename;
|
char * archivename;
|
||||||
|
@ -56,7 +52,7 @@ typedef struct r_io_zip_file_obj_t{
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
RList * r_io_zip_get_files(char *archivename, ut32 flags, int mode, int rw);
|
RList *r_io_zip_get_files(char *archivename, ut32 flags, int mode, int rw);
|
||||||
|
|
||||||
static int r_io_zip_init();
|
static int r_io_zip_init();
|
||||||
static int r_io_zip_plugin_open(RIO *io, const char *file);
|
static int r_io_zip_plugin_open(RIO *io, const char *file);
|
||||||
|
@ -65,9 +61,9 @@ static RIODesc * r_io_zip_open(RIO *io, const char *file, int rw, int mode);
|
||||||
int r_io_zip_slurp_file(RIOZipFileObj *zip_file_obj);
|
int r_io_zip_slurp_file(RIOZipFileObj *zip_file_obj);
|
||||||
RIODesc *check_zip_file_open(RIO *io, const char* filename);
|
RIODesc *check_zip_file_open(RIO *io, const char* filename);
|
||||||
|
|
||||||
int r_io_zip_has_uri_substr(const char *file);
|
static int r_io_zip_has_uri_substr(const char *file);
|
||||||
int r_io_zip_check_uri(const char *file);
|
static int r_io_zip_check_uri(const char *file);
|
||||||
int r_io_zip_check_file(const char *file);
|
static int r_io_zip_check_file(const char *file);
|
||||||
|
|
||||||
|
|
||||||
int r_io_zip_open_zip_file(RIOZipFileObj * zipFileObj);
|
int r_io_zip_open_zip_file(RIOZipFileObj * zipFileObj);
|
||||||
|
@ -86,12 +82,11 @@ static int r_io_zip_init(RIO *io) {
|
||||||
return R_TRUE;
|
return R_TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int r_io_zip_has_uri_substr(const char *file){
|
||||||
int r_io_zip_has_uri_substr(const char *file){
|
|
||||||
return (file && strstr(file, URI));
|
return (file && strstr(file, URI));
|
||||||
}
|
}
|
||||||
|
|
||||||
int r_io_zip_check_uri(const char *file){
|
static int r_io_zip_check_uri(const char *file){
|
||||||
int result = R_FALSE;
|
int result = R_FALSE;
|
||||||
int i = 0;
|
int i = 0;
|
||||||
if (r_io_zip_has_uri_substr(file)){
|
if (r_io_zip_has_uri_substr(file)){
|
||||||
|
@ -116,12 +111,12 @@ int r_io_zip_open_zip_file(RIOZipFileObj * zipFileObj){
|
||||||
|
|
||||||
struct zip * r_io_zip_open_archive(const char *archivename, ut32 flags, int mode, int rw){
|
struct zip * r_io_zip_open_archive(const char *archivename, ut32 flags, int mode, int rw){
|
||||||
int zip_errorp;
|
int zip_errorp;
|
||||||
struct zip * zipArch = NULL;
|
struct zip * zipArch = NULL;
|
||||||
|
|
||||||
if(!archivename)
|
|
||||||
return zipArch;
|
|
||||||
|
|
||||||
zipArch = zip_open(archivename, flags, &zip_errorp);
|
if(!archivename)
|
||||||
|
return zipArch;
|
||||||
|
|
||||||
|
zipArch = zip_open(archivename, flags, &zip_errorp);
|
||||||
if (!zipArch){
|
if (!zipArch){
|
||||||
|
|
||||||
if( zip_errorp == ZIP_ER_INVAL){
|
if( zip_errorp == ZIP_ER_INVAL){
|
||||||
|
@ -145,7 +140,7 @@ struct zip * r_io_zip_open_archive(const char *archivename, ut32 flags, int mode
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int r_io_zip_check_file(const char *file){
|
static int r_io_zip_check_file(const char *file){
|
||||||
int result = R_FALSE;
|
int result = R_FALSE;
|
||||||
ut8 buf[10];
|
ut8 buf[10];
|
||||||
|
|
||||||
|
@ -169,18 +164,18 @@ int r_io_zip_slurp_file(RIOZipFileObj *zip_file_obj){
|
||||||
struct zip_stat sb;
|
struct zip_stat sb;
|
||||||
//eprintf("Slurping file");
|
//eprintf("Slurping file");
|
||||||
if (zip_file_obj && zip_file_obj->entry != -1){
|
if (zip_file_obj && zip_file_obj->entry != -1){
|
||||||
|
|
||||||
zFile = zip_fopen_index(zipArch, zip_file_obj->entry, 0);
|
zFile = zip_fopen_index(zipArch, zip_file_obj->entry, 0);
|
||||||
if(!zip_file_obj->b){
|
if(!zip_file_obj->b){
|
||||||
zip_file_obj->b = r_buf_new();
|
zip_file_obj->b = r_buf_new();
|
||||||
}
|
}
|
||||||
zip_stat_init(&sb);
|
zip_stat_init(&sb);
|
||||||
|
|
||||||
if(zFile && zip_file_obj->b && !zip_stat_index(zipArch, zip_file_obj->entry, 0, &sb) ){
|
if(zFile && zip_file_obj->b && !zip_stat_index(zipArch, zip_file_obj->entry, 0, &sb) ){
|
||||||
|
|
||||||
ut8 *buf = malloc(sb.size);
|
ut8 *buf = malloc(sb.size);
|
||||||
memset(buf, 0, sb.size);
|
memset(buf, 0, sb.size);
|
||||||
|
|
||||||
if (buf){
|
if (buf){
|
||||||
zip_fread(zFile, buf, sb.size);
|
zip_fread(zFile, buf, sb.size);
|
||||||
r_buf_set_bytes(zip_file_obj->b, buf, sb.size);
|
r_buf_set_bytes(zip_file_obj->b, buf, sb.size);
|
||||||
|
@ -212,11 +207,11 @@ RList * r_io_zip_get_files(char *archivename, ut32 flags, int mode, int rw){
|
||||||
if (zipArch){
|
if (zipArch){
|
||||||
files = r_list_new();
|
files = r_list_new();
|
||||||
num_entries = zip_get_num_files(zipArch);
|
num_entries = zip_get_num_files(zipArch);
|
||||||
|
|
||||||
for (i=0; i < num_entries; i++){
|
for (i=0; i < num_entries; i++){
|
||||||
char *name = NULL;
|
char *name = NULL;
|
||||||
zip_stat_init(&sb );
|
zip_stat_init(&sb );
|
||||||
zip_stat_index(zipArch, i, 0, &sb );
|
zip_stat_index(zipArch, i, 0, &sb );
|
||||||
//eprintf("Comparing %s == %s = %d\n", sb.name, filename, strcmp(sb.name, filename));
|
//eprintf("Comparing %s == %s = %d\n", sb.name, filename, strcmp(sb.name, filename));
|
||||||
name = strdup(sb.name);
|
name = strdup(sb.name);
|
||||||
if (name){
|
if (name){
|
||||||
|
@ -234,23 +229,23 @@ RList * r_io_zip_get_files(char *archivename, ut32 flags, int mode, int rw){
|
||||||
int r_io_zip_flush_file(RIOZipFileObj *zip_file_obj){
|
int r_io_zip_flush_file(RIOZipFileObj *zip_file_obj){
|
||||||
|
|
||||||
int result = R_FALSE;
|
int result = R_FALSE;
|
||||||
struct zip * zipArch = r_io_zip_open_archive(zip_file_obj->archivename, zip_file_obj->flags, zip_file_obj->mode, zip_file_obj->rw);
|
struct zip * zipArch = r_io_zip_open_archive(zip_file_obj->archivename, zip_file_obj->flags, zip_file_obj->mode, zip_file_obj->rw);
|
||||||
|
|
||||||
if (!zipArch){
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (zip_file_obj){
|
if (!zipArch){
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (zip_file_obj){
|
||||||
struct zip_source *s = zip_source_buffer(zipArch, zip_file_obj->b, zip_file_obj->b->length, 0);
|
struct zip_source *s = zip_source_buffer(zipArch, zip_file_obj->b, zip_file_obj->b->length, 0);
|
||||||
if (s && zip_file_obj->entry != -1){
|
if (s && zip_file_obj->entry != -1){
|
||||||
|
|
||||||
if (zip_replace(zipArch, zip_file_obj->entry, s) == 0)
|
if (zip_replace(zipArch, zip_file_obj->entry, s) == 0)
|
||||||
result = R_TRUE;
|
result = R_TRUE;
|
||||||
|
|
||||||
}else if (s && zip_file_obj->name){
|
}else if (s && zip_file_obj->name){
|
||||||
|
|
||||||
if(zip_add(zipArch, zip_file_obj->name, s) == 0){
|
if(zip_add(zipArch, zip_file_obj->name, s) == 0){
|
||||||
|
|
||||||
zip_file_obj->entry = zip_name_locate(zipArch, zip_file_obj->name, 0);
|
zip_file_obj->entry = zip_name_locate(zipArch, zip_file_obj->name, 0);
|
||||||
result = R_TRUE;
|
result = R_TRUE;
|
||||||
}
|
}
|
||||||
|
@ -318,7 +313,7 @@ static RIODesc *r_io_zip_open(RIO *io, const char *file, int rw, int mode) {
|
||||||
*zip_filename++ = 0;
|
*zip_filename++ = 0;
|
||||||
}
|
}
|
||||||
*zip_filename++ = 0;
|
*zip_filename++ = 0;
|
||||||
|
|
||||||
filename_in_zipfile = strstr(zip_filename, "//");
|
filename_in_zipfile = strstr(zip_filename, "//");
|
||||||
if (filename_in_zipfile && filename_in_zipfile[2]){
|
if (filename_in_zipfile && filename_in_zipfile[2]){
|
||||||
// null terminating uri to filename here.
|
// null terminating uri to filename here.
|
||||||
|
@ -346,61 +341,56 @@ static RIODesc *r_io_zip_open(RIO *io, const char *file, int rw, int mode) {
|
||||||
eprintf("usage: zip:///path/to/archive//filepath\n");
|
eprintf("usage: zip:///path/to/archive//filepath\n");
|
||||||
eprintf("No file was given. Here's a dump to help you decide:\n");
|
eprintf("No file was given. Here's a dump to help you decide:\n");
|
||||||
files = r_io_zip_get_files(zip_filename, 0, mode, rw );
|
files = r_io_zip_get_files(zip_filename, 0, mode, rw );
|
||||||
|
|
||||||
if(files){
|
if(files){
|
||||||
ut64 i = 0;
|
int i = 0;
|
||||||
r_list_foreach_safe(files, iter, iter_tmp, name){
|
r_list_foreach_safe(files, iter, iter_tmp, name){
|
||||||
eprintf("\t %d) %s\n", i++, name);
|
eprintf("\t %d) %s\n", i++, name);
|
||||||
if (name)
|
free (name);
|
||||||
free(name);
|
r_list_delete (files, iter);
|
||||||
|
|
||||||
r_list_delete(files, iter);
|
|
||||||
}
|
}
|
||||||
r_list_free(files);
|
r_list_free (files);
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
//eprintf("After parsing the given uri: %s\n", file);
|
//eprintf("After parsing the given uri: %s\n", file);
|
||||||
//eprintf("Zip filename the given uri: %s\n", zip_filename);
|
//eprintf("Zip filename the given uri: %s\n", zip_filename);
|
||||||
//eprintf("File in the zip: %s\n", filename_in_zipfile);
|
//eprintf("File in the zip: %s\n", filename_in_zipfile);
|
||||||
|
|
||||||
zipFileObj = r_io_zip_alloc_zipfileobj(zip_filename, filename_in_zipfile, ZIP_CREATE, mode, rw);
|
zipFileObj = r_io_zip_alloc_zipfileobj (zip_filename,
|
||||||
if (zipFileObj && zipFileObj->entry == -1){
|
filename_in_zipfile, ZIP_CREATE, mode, rw);
|
||||||
eprintf("Warning: File did not exist, creating a new one.\n");
|
if (zipFileObj && zipFileObj->entry == -1)
|
||||||
}
|
eprintf ("Warning: File did not exist, creating a new one.\n");
|
||||||
|
|
||||||
if(zipFileObj){
|
if (zipFileObj) {
|
||||||
zipFileObj->io_backref = io;
|
zipFileObj->io_backref = io;
|
||||||
result = r_io_desc_new(&r_io_plugin_zip, zipFileObj->fd, zipFileObj->name, rw, mode, zipFileObj);
|
result = r_io_desc_new(&r_io_plugin_zip, zipFileObj->fd, zipFileObj->name, rw, mode, zipFileObj);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!result){
|
if (!result) {
|
||||||
eprintf("Failed to open the archive %s and file %s\n", zip_filename, filename_in_zipfile);
|
eprintf ("Failed to open the archive %s and file %s\n",
|
||||||
if (zipFileObj)
|
zip_filename, filename_in_zipfile);
|
||||||
free(zipFileObj);
|
free (zipFileObj);
|
||||||
}
|
}
|
||||||
|
free (zip_uri);
|
||||||
if (zip_uri)
|
|
||||||
free(zip_uri);
|
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static ut64 r_io_zip_lseek(RIO *io, RIODesc *fd, ut64 offset, int whence) {
|
static ut64 r_io_zip_lseek(RIO *io, RIODesc *fd, ut64 offset, int whence) {
|
||||||
RIOZipFileObj *zip_file_obj;
|
RIOZipFileObj *zip_file_obj;
|
||||||
|
|
||||||
ut64 seek_val = 0;
|
ut64 seek_val = 0;
|
||||||
if (fd == NULL || fd->data == NULL)
|
if (fd == NULL || fd->data == NULL)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
zip_file_obj = fd->data;
|
zip_file_obj = fd->data;
|
||||||
|
|
||||||
seek_val = zip_file_obj->b->cur;
|
seek_val = zip_file_obj->b->cur;
|
||||||
|
|
||||||
switch (whence) {
|
switch (whence) {
|
||||||
case SEEK_SET:
|
case SEEK_SET:
|
||||||
seek_val = zip_file_obj->b->length < offset ? zip_file_obj->b->length : offset;
|
seek_val = zip_file_obj->b->length < offset ? zip_file_obj->b->length : offset;
|
||||||
zip_file_obj->b->cur = io->off = seek_val;
|
zip_file_obj->b->cur = io->off = seek_val;
|
||||||
|
@ -409,135 +399,135 @@ static ut64 r_io_zip_lseek(RIO *io, RIODesc *fd, ut64 offset, int whence) {
|
||||||
seek_val = zip_file_obj->b->length < offset + zip_file_obj->b->cur ? zip_file_obj->b->length : offset + zip_file_obj->b->cur;
|
seek_val = zip_file_obj->b->length < offset + zip_file_obj->b->cur ? zip_file_obj->b->length : offset + zip_file_obj->b->cur;
|
||||||
zip_file_obj->b->cur = io->off = seek_val;
|
zip_file_obj->b->cur = io->off = seek_val;
|
||||||
return seek_val;
|
return seek_val;
|
||||||
|
|
||||||
case SEEK_END:
|
case SEEK_END:
|
||||||
seek_val = zip_file_obj->b->length;
|
seek_val = zip_file_obj->b->length;
|
||||||
zip_file_obj->b->cur = io->off = seek_val;
|
zip_file_obj->b->cur = io->off = seek_val;
|
||||||
return seek_val;
|
return seek_val;
|
||||||
}
|
|
||||||
return seek_val;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int r_io_zip_read(RIO *io, RIODesc *fd, ut8 *buf, int count){
|
|
||||||
RIOZipFileObj *zip_file_obj = NULL;
|
|
||||||
if (fd == NULL || fd->data == NULL || buf == NULL)
|
|
||||||
return -1;
|
|
||||||
|
|
||||||
zip_file_obj = fd->data;
|
|
||||||
if (zip_file_obj->b->length < io->off)
|
|
||||||
io->off = zip_file_obj->b->length;
|
|
||||||
|
|
||||||
return r_buf_read_at(zip_file_obj->b, io->off, buf, count);
|
|
||||||
}
|
|
||||||
|
|
||||||
static int r_io_zip_write(RIO *io, RIODesc *fd, const ut8 *buf, int count){
|
|
||||||
RIOZipFileObj *zip_file_obj = NULL;
|
|
||||||
if (fd == NULL || fd->data == NULL || buf == NULL)
|
|
||||||
return -1;
|
|
||||||
zip_file_obj = fd->data;
|
|
||||||
|
|
||||||
|
|
||||||
if (zip_file_obj->b->length < io->off)
|
|
||||||
io->off = zip_file_obj->b->length;
|
|
||||||
|
|
||||||
zip_file_obj->modified = 1;
|
|
||||||
return r_buf_write_at(zip_file_obj->b, io->off, buf, count);
|
|
||||||
}
|
|
||||||
|
|
||||||
static int r_io_zip_close(RIODesc *fd){
|
|
||||||
RIOZipFileObj *zip_file_obj = NULL;
|
|
||||||
//eprintf("Am I called 2x?\n");
|
|
||||||
// this api will be called multiple times :/
|
|
||||||
if (fd == NULL || fd->data)
|
|
||||||
return -1;
|
|
||||||
|
|
||||||
zip_file_obj = fd->data;
|
|
||||||
r_io_zip_free_zipfileobj(zip_file_obj);
|
|
||||||
zip_file_obj = fd->data = NULL;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
RIOZipFileObj* r_io_zip_alloc_zipfileobj(const char *archivename, const char *filename, ut32 flags, int mode, int rw){
|
|
||||||
ut64 i, num_entries;
|
|
||||||
struct zip_stat sb;
|
|
||||||
struct zip * zipArch = r_io_zip_open_archive(archivename, flags, mode, rw);
|
|
||||||
RIOZipFileObj *zipFileObj = NULL;
|
|
||||||
if (!zipArch)
|
|
||||||
return zipFileObj;
|
|
||||||
num_entries = zip_get_num_files(zipArch);
|
|
||||||
|
|
||||||
for (i=0; i < num_entries; i++){
|
|
||||||
|
|
||||||
zip_stat_init(&sb );
|
|
||||||
zip_stat_index(zipArch, i, 0, &sb );
|
|
||||||
//eprintf("Comparing %s == %s = %d\n", sb.name, filename, strcmp(sb.name, filename));
|
|
||||||
if (strcmp(sb.name, filename) == 0){
|
|
||||||
|
|
||||||
zipFileObj = r_io_zip_create_new_file(archivename, filename, &sb, flags, mode, rw);
|
|
||||||
r_io_zip_slurp_file(zipFileObj);
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
return seek_val;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!zipFileObj){
|
static int r_io_zip_read(RIO *io, RIODesc *fd, ut8 *buf, int count){
|
||||||
zipFileObj = r_io_zip_create_new_file(archivename, filename, NULL, flags, mode, rw);
|
RIOZipFileObj *zip_file_obj = NULL;
|
||||||
|
if (fd == NULL || fd->data == NULL || buf == NULL)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
zip_file_obj = fd->data;
|
||||||
|
if (zip_file_obj->b->length < io->off)
|
||||||
|
io->off = zip_file_obj->b->length;
|
||||||
|
|
||||||
|
return r_buf_read_at(zip_file_obj->b, io->off, buf, count);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (zipArch)
|
|
||||||
zip_close(zipArch);
|
|
||||||
|
|
||||||
|
|
||||||
return zipFileObj;
|
static int r_io_zip_write(RIO *io, RIODesc *fd, const ut8 *buf, int count){
|
||||||
}
|
RIOZipFileObj *zip_file_obj = NULL;
|
||||||
|
if (fd == NULL || fd->data == NULL || buf == NULL)
|
||||||
|
return -1;
|
||||||
|
zip_file_obj = fd->data;
|
||||||
|
|
||||||
|
|
||||||
RIOZipFileObj *r_io_zip_create_new_file(const char *archivename, const char *filename, struct zip_stat *sb, ut32 flags, int mode, int rw) {
|
if (zip_file_obj->b->length < io->off)
|
||||||
RIOZipFileObj *zip_file_obj = NULL;
|
io->off = zip_file_obj->b->length;
|
||||||
|
|
||||||
zip_file_obj = malloc(sizeof(RIOZipFileObj));
|
|
||||||
if (zip_file_obj)
|
|
||||||
memset(zip_file_obj, 0, sizeof(RIOZipFileObj));
|
|
||||||
|
|
||||||
|
|
||||||
zip_file_obj->archivename = strdup(archivename);
|
zip_file_obj->modified = 1;
|
||||||
zip_file_obj->b = r_buf_new();
|
return r_buf_write_at(zip_file_obj->b, io->off, buf, count);
|
||||||
zip_file_obj->name = sb == NULL ? strdup(filename) : strdup(sb->name);
|
}
|
||||||
zip_file_obj->entry = sb == NULL ? -1 : sb->index;
|
|
||||||
zip_file_obj->fd = random() & 0xFFFF;;
|
|
||||||
|
|
||||||
zip_file_obj->mode = mode;
|
|
||||||
zip_file_obj->rw = rw;
|
|
||||||
zip_file_obj->flags = flags;
|
|
||||||
|
|
||||||
return zip_file_obj;
|
static int r_io_zip_close(RIODesc *fd){
|
||||||
|
RIOZipFileObj *zip_file_obj = NULL;
|
||||||
|
//eprintf("Am I called 2x?\n");
|
||||||
|
// this api will be called multiple times :/
|
||||||
|
if (fd == NULL || fd->data)
|
||||||
|
return -1;
|
||||||
|
|
||||||
}
|
zip_file_obj = fd->data;
|
||||||
|
r_io_zip_free_zipfileobj(zip_file_obj);
|
||||||
|
zip_file_obj = fd->data = NULL;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
static int r_io_zip_plugin_open(RIO *io, const char *file) {
|
|
||||||
return (io && file) && (r_io_zip_check_uri(file));
|
|
||||||
}
|
|
||||||
|
|
||||||
struct r_io_plugin_t r_io_plugin_zip = {
|
|
||||||
.name = "zip",
|
|
||||||
.desc = "Open zip files apk://foo.apk//MANIFEST or zip://foo.apk//theclass/fun.class, and show files with: zip://foo.apk/",
|
|
||||||
.open = r_io_zip_open,
|
RIOZipFileObj* r_io_zip_alloc_zipfileobj(const char *archivename, const char *filename, ut32 flags, int mode, int rw){
|
||||||
.write = r_io_zip_write,
|
ut64 i, num_entries;
|
||||||
.read = r_io_zip_read,
|
struct zip_stat sb;
|
||||||
.close = r_io_zip_close,
|
struct zip * zipArch = r_io_zip_open_archive(archivename, flags, mode, rw);
|
||||||
.lseek = r_io_zip_lseek,
|
RIOZipFileObj *zipFileObj = NULL;
|
||||||
.plugin_open = r_io_zip_plugin_open,
|
if (!zipArch)
|
||||||
.system = NULL,
|
return zipFileObj;
|
||||||
.debug = NULL,
|
num_entries = zip_get_num_files(zipArch);
|
||||||
.init = r_io_zip_init
|
|
||||||
};
|
for (i=0; i < num_entries; i++){
|
||||||
|
|
||||||
|
zip_stat_init(&sb );
|
||||||
|
zip_stat_index(zipArch, i, 0, &sb );
|
||||||
|
//eprintf("Comparing %s == %s = %d\n", sb.name, filename, strcmp(sb.name, filename));
|
||||||
|
if (strcmp(sb.name, filename) == 0){
|
||||||
|
|
||||||
|
zipFileObj = r_io_zip_create_new_file(archivename, filename, &sb, flags, mode, rw);
|
||||||
|
r_io_zip_slurp_file(zipFileObj);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!zipFileObj){
|
||||||
|
zipFileObj = r_io_zip_create_new_file(archivename, filename, NULL, flags, mode, rw);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (zipArch)
|
||||||
|
zip_close(zipArch);
|
||||||
|
|
||||||
|
|
||||||
|
return zipFileObj;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
RIOZipFileObj *r_io_zip_create_new_file(const char *archivename, const char *filename, struct zip_stat *sb, ut32 flags, int mode, int rw) {
|
||||||
|
RIOZipFileObj *zip_file_obj = NULL;
|
||||||
|
|
||||||
|
zip_file_obj = malloc(sizeof(RIOZipFileObj));
|
||||||
|
if (zip_file_obj)
|
||||||
|
memset(zip_file_obj, 0, sizeof(RIOZipFileObj));
|
||||||
|
|
||||||
|
|
||||||
|
zip_file_obj->archivename = strdup(archivename);
|
||||||
|
zip_file_obj->b = r_buf_new();
|
||||||
|
zip_file_obj->name = sb == NULL ? strdup(filename) : strdup(sb->name);
|
||||||
|
zip_file_obj->entry = sb == NULL ? -1 : sb->index;
|
||||||
|
zip_file_obj->fd = r_num_rand (0xFFFF);
|
||||||
|
|
||||||
|
zip_file_obj->mode = mode;
|
||||||
|
zip_file_obj->rw = rw;
|
||||||
|
zip_file_obj->flags = flags;
|
||||||
|
|
||||||
|
return zip_file_obj;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
static int r_io_zip_plugin_open(RIO *io, const char *file) {
|
||||||
|
return (io && file) && (r_io_zip_check_uri(file));
|
||||||
|
}
|
||||||
|
|
||||||
|
struct r_io_plugin_t r_io_plugin_zip = {
|
||||||
|
.name = "zip",
|
||||||
|
.desc = "Open zip files apk://foo.apk//MANIFEST or zip://foo.apk//theclass/fun.class, and show files with: zip://foo.apk/",
|
||||||
|
.open = r_io_zip_open,
|
||||||
|
.write = r_io_zip_write,
|
||||||
|
.read = r_io_zip_read,
|
||||||
|
.close = r_io_zip_close,
|
||||||
|
.lseek = r_io_zip_lseek,
|
||||||
|
.plugin_open = r_io_zip_plugin_open,
|
||||||
|
.system = NULL,
|
||||||
|
.debug = NULL,
|
||||||
|
.init = r_io_zip_init
|
||||||
|
};
|
||||||
|
|
||||||
#ifndef CORELIB
|
#ifndef CORELIB
|
||||||
struct r_lib_struct_t radare_plugin = {
|
struct r_lib_struct_t radare_plugin = {
|
||||||
.type = R_LIB_TYPE_IO,
|
.type = R_LIB_TYPE_IO,
|
||||||
.data = &r_io_plugin_zip
|
.data = &r_io_plugin_zip
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -3,74 +3,19 @@ OBJ_ZIP=io_zip.o
|
||||||
STATIC_OBJ+=${OBJ_ZIP}
|
STATIC_OBJ+=${OBJ_ZIP}
|
||||||
TARGET_ZIP=io_zip.${EXT_SO}
|
TARGET_ZIP=io_zip.${EXT_SO}
|
||||||
ALL_TARGETS+=${TARGET_ZIP}
|
ALL_TARGETS+=${TARGET_ZIP}
|
||||||
CFLAGS+=-I../../shlr/zip/include
|
|
||||||
|
|
||||||
|
CFLAGS+=-I../../shlr/zip/include
|
||||||
|
|
||||||
ifeq (${WITHPIC},0)
|
ifeq (${WITHPIC},0)
|
||||||
LINKFLAGS+=../../util/libr_util.a
|
LINKFLAGS+=../../util/libr_util.a
|
||||||
LINKFLAGS+=../../lib/libr_lib.a
|
LINKFLAGS+=../../lib/libr_lib.a
|
||||||
LINKFLAGS+=../../io/libr_io.a
|
LINKFLAGS+=../../io/libr_io.a
|
||||||
LINKFLAGS+=../../../shlr/zip/libr_zip.a
|
|
||||||
else
|
else
|
||||||
LINKFLAGS+=-L../../lib -lr_lib
|
LINKFLAGS+=-L../../lib -lr_lib
|
||||||
LINKFLAGS+=-L../../util -lr_util
|
LINKFLAGS+=-L../../util -lr_util
|
||||||
LINKFLAGS+=-L.. -L../../lib -lr_lib -lr_io
|
LINKFLAGS+=-L.. -L../../lib -lr_lib -lr_io
|
||||||
LINKFLAGS+=../../../shlr/zip/libr_zip.a
|
|
||||||
# XXX libr_zip is not installed so it fails at runtime
|
|
||||||
#LINKFLAGS+=-L../../../shlr/zip/ -lr_zip
|
|
||||||
endif
|
endif
|
||||||
# TODO Merge!
|
|
||||||
LDFLAGS+=$(LTOP)/../shlr/zip/libr_zip.a
|
|
||||||
LDFLAGS+=$(LTOP)/../shlr/zip/libr_z.a
|
|
||||||
|
|
||||||
ZIPOBJS=${OBJ_ZIP}
|
|
||||||
|
|
||||||
# TODO: use make addprefix here
|
|
||||||
#ZIPFILES=zip_add.o ...
|
|
||||||
#ZIPOBJS+=$(addprefix ../../../shlr/zip/zip/, $ZIPFILES)
|
|
||||||
ZIPOBJS+= ../../../shlr/zip/zip/zip_add.o ../../../shlr/zip/zip/zip_add_dir.o
|
|
||||||
ZIPOBJS+= ../../../shlr/zip/zip/zip_add_entry.o ../../../shlr/zip/zip/zip_close.o
|
|
||||||
ZIPOBJS+=../../../shlr/zip/zip/zip_delete.o ../../../shlr/zip/zip/zip_dir_add.o
|
|
||||||
ZIPOBJS+=../../../shlr/zip/zip/zip_dirent.o ../../../shlr/zip/zip/zip_discard.o
|
|
||||||
ZIPOBJS+=../../../shlr/zip/zip/zip_entry.o ../../../shlr/zip/zip/zip_err_str.o
|
|
||||||
ZIPOBJS+=../../../shlr/zip/zip/zip_error.o ../../../shlr/zip/zip/zip_error_clear.o
|
|
||||||
ZIPOBJS+=../../../shlr/zip/zip/zip_error_get.o ../../../shlr/zip/zip/zip_error_get_sys_type.o
|
|
||||||
ZIPOBJS+=../../../shlr/zip/zip/zip_error_strerror.o ../../../shlr/zip/zip/zip_error_to_str.o
|
|
||||||
ZIPOBJS+=../../../shlr/zip/zip/zip_extra_field.o ../../../shlr/zip/zip/zip_extra_field_api.o
|
|
||||||
ZIPOBJS+=../../../shlr/zip/zip/zip_fclose.o ../../../shlr/zip/zip/zip_fdopen.o
|
|
||||||
ZIPOBJS+=../../../shlr/zip/zip/zip_file_add.o ../../../shlr/zip/zip/zip_file_error_clear.o
|
|
||||||
ZIPOBJS+=../../../shlr/zip/zip/zip_file_error_get.o ../../../shlr/zip/zip/zip_file_get_comment.o
|
|
||||||
ZIPOBJS+=../../../shlr/zip/zip/zip_file_get_offset.o ../../../shlr/zip/zip/zip_file_rename.o
|
|
||||||
ZIPOBJS+=../../../shlr/zip/zip/zip_file_replace.o ../../../shlr/zip/zip/zip_file_set_comment.o
|
|
||||||
ZIPOBJS+=../../../shlr/zip/zip/zip_file_strerror.o ../../../shlr/zip/zip/zip_filerange_crc.o
|
|
||||||
ZIPOBJS+=../../../shlr/zip/zip/zip_fopen.o ../../../shlr/zip/zip/zip_fopen_encrypted.o
|
|
||||||
ZIPOBJS+=../../../shlr/zip/zip/zip_fopen_index.o ../../../shlr/zip/zip/zip_fopen_index_encrypted.o
|
|
||||||
ZIPOBJS+=../../../shlr/zip/zip/zip_fread.o ../../../shlr/zip/zip/zip_get_archive_comment.o
|
|
||||||
ZIPOBJS+=../../../shlr/zip/zip/zip_get_archive_flag.o ../../../shlr/zip/zip/zip_get_compression_implementation.o
|
|
||||||
ZIPOBJS+=../../../shlr/zip/zip/zip_get_encryption_implementation.o ../../../shlr/zip/zip/zip_get_file_comment.o
|
|
||||||
ZIPOBJS+=../../../shlr/zip/zip/zip_get_num_entries.o ../../../shlr/zip/zip/zip_get_num_files.o
|
|
||||||
ZIPOBJS+=../../../shlr/zip/zip/zip_get_name.o ../../../shlr/zip/zip/zip_memdup.o
|
|
||||||
ZIPOBJS+=../../../shlr/zip/zip/zip_name_locate.o ../../../shlr/zip/zip/zip_new.o
|
|
||||||
ZIPOBJS+=../../../shlr/zip/zip/zip_open.o ../../../shlr/zip/zip/zip_rename.o
|
|
||||||
ZIPOBJS+=../../../shlr/zip/zip/zip_replace.o ../../../shlr/zip/zip/zip_set_archive_comment.o
|
|
||||||
ZIPOBJS+=../../../shlr/zip/zip/zip_set_archive_flag.o ../../../shlr/zip/zip/zip_set_default_password.o
|
|
||||||
ZIPOBJS+=../../../shlr/zip/zip/zip_set_file_comment.o ../../../shlr/zip/zip/zip_set_file_compression.o
|
|
||||||
ZIPOBJS+=../../../shlr/zip/zip/zip_set_name.o ../../../shlr/zip/zip/zip_source_buffer.o
|
|
||||||
ZIPOBJS+=../../../shlr/zip/zip/zip_source_close.o ../../../shlr/zip/zip/zip_source_crc.o
|
|
||||||
ZIPOBJS+=../../../shlr/zip/zip/zip_source_deflate.o ../../../shlr/zip/zip/zip_source_error.o
|
|
||||||
ZIPOBJS+=../../../shlr/zip/zip/zip_source_file.o ../../../shlr/zip/zip/zip_source_filep.o
|
|
||||||
ZIPOBJS+=../../../shlr/zip/zip/zip_source_free.o ../../../shlr/zip/zip/zip_source_function.o
|
|
||||||
ZIPOBJS+=../../../shlr/zip/zip/zip_source_layered.o ../../../shlr/zip/zip/zip_source_open.o
|
|
||||||
ZIPOBJS+=../../../shlr/zip/zip/zip_source_pkware.o ../../../shlr/zip/zip/zip_source_pop.o
|
|
||||||
ZIPOBJS+=../../../shlr/zip/zip/zip_source_read.o ../../../shlr/zip/zip/zip_source_stat.o
|
|
||||||
ZIPOBJS+=../../../shlr/zip/zip/zip_source_window.o ../../../shlr/zip/zip/zip_source_zip.o
|
|
||||||
ZIPOBJS+=../../../shlr/zip/zip/zip_source_zip_new.o ../../../shlr/zip/zip/zip_stat.o
|
|
||||||
ZIPOBJS+=../../../shlr/zip/zip/zip_stat_index.o ../../../shlr/zip/zip/zip_stat_init.o
|
|
||||||
ZIPOBJS+=../../../shlr/zip/zip/zip_strerror.o ../../../shlr/zip/zip/zip_string.o
|
|
||||||
ZIPOBJS+=../../../shlr/zip/zip/zip_unchange.o ../../../shlr/zip/zip/zip_unchange_all.o
|
|
||||||
ZIPOBJS+=../../../shlr/zip/zip/zip_unchange_archive.o ../../../shlr/zip/zip/zip_unchange_data.o
|
|
||||||
ZIPOBJS+=../../../shlr/zip/zip/zip_utf-8.o
|
|
||||||
|
|
||||||
${TARGET_ZIP}: ${OBJ_ZIP}
|
${TARGET_ZIP}: ${OBJ_ZIP}
|
||||||
@echo ${LINKFLAGS}
|
|
||||||
${CC_LIB} $(call libname,io_zip) ${CFLAGS} -o ${TARGET_ZIP} ${OBJS} ${LINKFLAGS}
|
${CC_LIB} $(call libname,io_zip) ${CFLAGS} -o ${TARGET_ZIP} ${OBJS} ${LINKFLAGS}
|
||||||
|
# ${LDFLAGS}
|
||||||
|
|
|
@ -288,7 +288,7 @@ R_API double r_num_get_float(struct r_num_t *num, const char *str) {
|
||||||
R_API int r_num_to_bits (char *out, ut64 num) {
|
R_API int r_num_to_bits (char *out, ut64 num) {
|
||||||
int size = 64, i;
|
int size = 64, i;
|
||||||
|
|
||||||
if (num&0xff00000000) size = 64;
|
if (num>>32) size = 64;
|
||||||
else if (num&0xff000000) size = 32;
|
else if (num&0xff000000) size = 32;
|
||||||
else if (num&0xff0000) size = 24;
|
else if (num&0xff0000) size = 24;
|
||||||
else if (num&0xff00) size = 16;
|
else if (num&0xff00) size = 16;
|
||||||
|
|
|
@ -2,7 +2,7 @@ include ../config-user.mk
|
||||||
include ../mk/${COMPILER}.mk
|
include ../mk/${COMPILER}.mk
|
||||||
|
|
||||||
HOST_CC?=gcc
|
HOST_CC?=gcc
|
||||||
MODS=udis86 java tcc zip/zlib zip/zip
|
MODS=udis86 java tcc zip
|
||||||
URL=git://github.com/radare/sdb
|
URL=git://github.com/radare/sdb
|
||||||
PWD=$(shell pwd)
|
PWD=$(shell pwd)
|
||||||
SDB_CONFIG=${PWD}/sdb-config.mk
|
SDB_CONFIG=${PWD}/sdb-config.mk
|
||||||
|
|
|
@ -1,12 +1,20 @@
|
||||||
include ../../config-user.mk
|
include ../../config-user.mk
|
||||||
|
include ../../libr/config.mk
|
||||||
|
include ../../mk/${COMPILER}.mk
|
||||||
|
|
||||||
all: libr_zip.a libr_zip.${SOEXT}
|
all: librz.a
|
||||||
|
|
||||||
libr_zip.a libr_zip.${SOEXT}:
|
LIBAR=librz.a
|
||||||
${MAKE} -C zlib
|
librz.a: libr_zip.a
|
||||||
|
${CC_AR} zlib/*.o zip/*.o
|
||||||
|
|
||||||
|
libr_zip.a: libr_z.a
|
||||||
${MAKE} -C zip
|
${MAKE} -C zip
|
||||||
|
|
||||||
|
libr_z.a:
|
||||||
|
${MAKE} -C zlib
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
${MAKE} -C zlib clean
|
${MAKE} -C zlib clean
|
||||||
${MAKE} -C zip clean
|
${MAKE} -C zip clean
|
||||||
rm *.a *.${SOEXT}
|
rm -f *.a *.${EXT_SO}
|
||||||
|
|
|
@ -36,15 +36,18 @@
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#ifndef ZIP_EXTERN
|
#if 0
|
||||||
#ifdef _WIN32
|
# ifndef ZIP_EXTERN
|
||||||
#define ZIP_EXTERN __declspec(dllimport)
|
# ifdef _WIN32
|
||||||
#elif defined(__GNUC__) && __GNUC__ >= 4
|
# define ZIP_EXTERN __declspec(dllimport)
|
||||||
#define ZIP_EXTERN __attribute__ ((visibility ("default")))
|
# elif defined(__GNUC__) && __GNUC__ >= 4
|
||||||
#else
|
# define ZIP_EXTERN __attribute__ ((visibility ("default")))
|
||||||
#define ZIP_EXTERN
|
# else
|
||||||
#endif
|
# define ZIP_EXTERN
|
||||||
|
# endif
|
||||||
|
# endif
|
||||||
#endif
|
#endif
|
||||||
|
#define ZIP_EXTERN extern
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
|
|
|
@ -80,6 +80,7 @@ extern z_const char * const z_errmsg[10]; /* indexed by 2-zlib_error */
|
||||||
|
|
||||||
/* target dependencies */
|
/* target dependencies */
|
||||||
|
|
||||||
|
#if 0
|
||||||
#if defined(MSDOS) || (defined(WINDOWS) && !defined(WIN32))
|
#if defined(MSDOS) || (defined(WINDOWS) && !defined(WIN32))
|
||||||
# define OS_CODE 0x00
|
# define OS_CODE 0x00
|
||||||
# ifndef Z_SOLO
|
# ifndef Z_SOLO
|
||||||
|
@ -96,6 +97,7 @@ extern z_const char * const z_errmsg[10]; /* indexed by 2-zlib_error */
|
||||||
# endif
|
# endif
|
||||||
# endif
|
# endif
|
||||||
#endif
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef AMIGA
|
#ifdef AMIGA
|
||||||
# define OS_CODE 0x01
|
# define OS_CODE 0x01
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
include ../../../config-user.mk
|
include ../../../config-user.mk
|
||||||
|
include ../../../libr/config.mk
|
||||||
include ../../../mk/${COMPILER}.mk
|
include ../../../mk/${COMPILER}.mk
|
||||||
|
|
||||||
|
## XXX this comes from config.mk?
|
||||||
ifeq (${OSTYPE},darwin)
|
ifeq (${OSTYPE},darwin)
|
||||||
SOEXT=dylib
|
SOVER=${EXT_SO}
|
||||||
SOVER=${SOEXT}
|
|
||||||
LDFLAGS+=-dynamic
|
LDFLAGS+=-dynamic
|
||||||
LDFLAGS_SHARED?=-fPIC -shared
|
LDFLAGS_SHARED?=-fPIC -shared
|
||||||
#ifeq (${ARCH},i386)
|
#ifeq (${ARCH},i386)
|
||||||
|
@ -13,14 +13,13 @@ LDFLAGS_SHARED?=-fPIC -shared
|
||||||
#endif
|
#endif
|
||||||
else
|
else
|
||||||
SOVERSION=0
|
SOVERSION=0
|
||||||
SOEXT=so
|
SOVER=${EXT_SO}
|
||||||
SOVER=${SOEXT}
|
|
||||||
LDFLAGS_SHARED?=-fPIC -shared
|
LDFLAGS_SHARED?=-fPIC -shared
|
||||||
LDFLAGS_SHARED+=-Wl,-soname,libr_zip.${SOEXT}
|
LDFLAGS_SHARED+=-Wl,-soname,libr_zip.${EXT_SO}
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
|
||||||
OBJS= zip_add.o zip_add_dir.o zip_add_entry.o \
|
OBJS= zip_add.o zip_add_dir.o zip_add_entry.o \
|
||||||
zip_close.o zip_delete.o zip_dir_add.o zip_dirent.o \
|
zip_close.o zip_delete.o zip_dir_add.o zip_dirent.o \
|
||||||
zip_discard.o zip_entry.o zip_err_str.o zip_error.o \
|
zip_discard.o zip_entry.o zip_err_str.o zip_error.o \
|
||||||
zip_error_clear.o zip_error_get.o zip_error_get_sys_type.o \
|
zip_error_clear.o zip_error_get.o zip_error_get_sys_type.o \
|
||||||
|
@ -51,36 +50,36 @@ OBJS= zip_add.o zip_add_dir.o zip_add_entry.o \
|
||||||
zip_string.o zip_unchange.o zip_unchange_all.o \
|
zip_string.o zip_unchange.o zip_unchange_all.o \
|
||||||
zip_unchange_archive.o zip_unchange_data.o zip_utf-8.o
|
zip_unchange_archive.o zip_unchange_data.o zip_utf-8.o
|
||||||
|
|
||||||
|
|
||||||
#OFILES=libr_zip.a $(OBJS)
|
#OFILES=libr_zip.a $(OBJS)
|
||||||
OFILES=$(OBJS)
|
OFILES=$(OBJS)
|
||||||
|
|
||||||
#CFLAGS+=-g -ggdb -fPIC
|
#CFLAGS+=-g -ggdb -fPIC
|
||||||
CFLAGS+=-fPIC
|
CFLAGS+=-fPIC
|
||||||
CFLAGS+=-I../../libr/include -I../include/
|
CFLAGS+=-I../../libr/include -I../include/
|
||||||
LDFLAGS+=-L../../../libr/util -L../ -lr_z
|
|
||||||
|
|
||||||
CFLAGS+=-fPIC -Wall
|
CFLAGS+=-fPIC -Wall
|
||||||
|
LDFLAGS+=-L../../../libr/util
|
||||||
|
LINKFLAGS=../libr_z.a
|
||||||
#LDFLAGS=-shared
|
#LDFLAGS=-shared
|
||||||
SOEXT?=dylib
|
EXT_SO?=dylib
|
||||||
LIBNAME=libr_zip.${SOVER}
|
LIBNAME=libr_zip.${SOVER}
|
||||||
|
|
||||||
all: ${LIBNAME} libr_zip.a
|
all: ${LIBNAME} libr_zip.a
|
||||||
|
|
||||||
|
|
||||||
${LIBNAME}: ${OBJS}
|
${LIBNAME}: ${OBJS}
|
||||||
ifneq ($(SILENT),)
|
ifneq ($(SILENT),)
|
||||||
@echo LIB ${LIBNAME}
|
@echo LIB ${LIBNAME}
|
||||||
endif
|
endif
|
||||||
${CC} ${LDFLAGS} $(LDFLAGS_SHARED) -o $@ ${OBJS}
|
${CC} ${LDFLAGS} $(LDFLAGS_SHARED) -o $@ ${OBJS} ${LINKFLAGS}
|
||||||
cp ${LIBNAME} ../
|
cp -f ${LIBNAME} ../
|
||||||
|
|
||||||
|
LIBAR=libr_zip.a
|
||||||
|
|
||||||
libr_zip.a: ${OFILES}
|
libr_zip.a: ${OFILES}
|
||||||
${AR} q libr_zip.a ${OFILES}
|
${CC_AR} ${OFILES}
|
||||||
${RANLIB} libr_zip.a
|
${RANLIB} libr_zip.a
|
||||||
cp libr_zip.a ../
|
cp -f libr_zip.a ../
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -f ${LIBNAME} *.o *.a *.d *.dylib *.so
|
rm -f ${LIBNAME} *.o *.a *.d *.${EXT_SO}
|
||||||
rm -f ../${LIBNAME} ../*.o ../*.a ../*.d ../*.dylib ../*.so
|
rm -f ../${LIBNAME} ../*.o ../*.a ../*.d ../*.${EXT_SO}
|
||||||
|
|
||||||
|
|
|
@ -5,6 +5,9 @@
|
||||||
*/
|
*/
|
||||||
/* #undef HAVE_DECL_TZNAME */
|
/* #undef HAVE_DECL_TZNAME */
|
||||||
|
|
||||||
|
#define ftello ftell
|
||||||
|
#define fseeko fseek
|
||||||
|
|
||||||
/* Define to 1 if you have the <dlfcn.h> header file. */
|
/* Define to 1 if you have the <dlfcn.h> header file. */
|
||||||
#define HAVE_DLFCN_H 1
|
#define HAVE_DLFCN_H 1
|
||||||
|
|
||||||
|
@ -72,7 +75,9 @@
|
||||||
#define HAVE_STRING_H 1
|
#define HAVE_STRING_H 1
|
||||||
|
|
||||||
/* Define to 1 if `tm_zone' is a member of `struct tm'. */
|
/* Define to 1 if `tm_zone' is a member of `struct tm'. */
|
||||||
#define HAVE_STRUCT_TM_TM_ZONE 1
|
// #define HAVE_STRUCT_TM_TM_ZONE 1
|
||||||
|
// doesnt exists on w32
|
||||||
|
#undef HAVE_STRUCT_TM_TM_ZONE
|
||||||
|
|
||||||
/* Define to 1 if you have the <sys/stat.h> header file. */
|
/* Define to 1 if you have the <sys/stat.h> header file. */
|
||||||
#define HAVE_SYS_STAT_H 1
|
#define HAVE_SYS_STAT_H 1
|
||||||
|
|
|
@ -610,11 +610,19 @@ _zip_create_temp_output(struct zip *za, FILE **outp)
|
||||||
sprintf(temp, "%s.XXXXXX", za->zn);
|
sprintf(temp, "%s.XXXXXX", za->zn);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if _WIN32 || __MINGW32__
|
||||||
|
if ((tfd=open(temp, O_RDWR|O_CREAT, 0644)) == -1) {
|
||||||
|
_zip_error_set(&za->error, ZIP_ER_TMPOPEN, errno);
|
||||||
|
free(temp);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
#else
|
||||||
if ((tfd=mkstemp(temp)) == -1) {
|
if ((tfd=mkstemp(temp)) == -1) {
|
||||||
_zip_error_set(&za->error, ZIP_ER_TMPOPEN, errno);
|
_zip_error_set(&za->error, ZIP_ER_TMPOPEN, errno);
|
||||||
free(temp);
|
free(temp);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
if ((tfp=fdopen(tfd, "r+b")) == NULL) {
|
if ((tfp=fdopen(tfd, "r+b")) == NULL) {
|
||||||
_zip_error_set(&za->error, ZIP_ER_TMPOPEN, errno);
|
_zip_error_set(&za->error, ZIP_ER_TMPOPEN, errno);
|
||||||
|
|
|
@ -578,6 +578,7 @@ _zip_dirent_torrent_normalize(struct zip_dirent *de)
|
||||||
static struct tm torrenttime;
|
static struct tm torrenttime;
|
||||||
static time_t last_mod = 0;
|
static time_t last_mod = 0;
|
||||||
|
|
||||||
|
#undef HAVE_STRUCT_TM_TM_ZONE
|
||||||
if (last_mod == 0) {
|
if (last_mod == 0) {
|
||||||
#ifdef HAVE_STRUCT_TM_TM_ZONE
|
#ifdef HAVE_STRUCT_TM_TM_ZONE
|
||||||
time_t now;
|
time_t now;
|
||||||
|
|
|
@ -1,10 +1,17 @@
|
||||||
include ../../../config-user.mk
|
include ../../../config-user.mk
|
||||||
|
include ../../../libr/config.mk
|
||||||
include ../../../mk/${COMPILER}.mk
|
include ../../../mk/${COMPILER}.mk
|
||||||
|
|
||||||
|
|
||||||
|
ifeq (${OSTYPE},windows)
|
||||||
|
EXT_SO=dll
|
||||||
|
SOVER=${EXT_SO}
|
||||||
|
LDFLAGS+=-shared
|
||||||
|
LDFLAGS_SHARED?=-fPIC -shared
|
||||||
|
else
|
||||||
ifeq (${OSTYPE},darwin)
|
ifeq (${OSTYPE},darwin)
|
||||||
SOEXT=dylib
|
EXT_SO=dylib
|
||||||
SOVER=${SOEXT}
|
SOVER=${EXT_SO}
|
||||||
LDFLAGS+=-dynamic
|
LDFLAGS+=-dynamic
|
||||||
LDFLAGS_SHARED?=-fPIC -shared
|
LDFLAGS_SHARED?=-fPIC -shared
|
||||||
# ifeq (${ARCH},i386)
|
# ifeq (${ARCH},i386)
|
||||||
|
@ -13,10 +20,11 @@ LDFLAGS_SHARED?=-fPIC -shared
|
||||||
# endif
|
# endif
|
||||||
else
|
else
|
||||||
SOVERSION=0
|
SOVERSION=0
|
||||||
SOEXT=so
|
EXT_SO=so
|
||||||
SOVER=${SOEXT}
|
SOVER=${EXT_SO}
|
||||||
LDFLAGS_SHARED?=-fPIC -shared
|
LDFLAGS_SHARED?=-fPIC -shared
|
||||||
LDFLAGS_SHARED+=-Wl,-soname,libr_z.${SOEXT}
|
LDFLAGS_SHARED+=-Wl,-soname,libr_z.${EXT_SO}
|
||||||
|
endif
|
||||||
endif
|
endif
|
||||||
|
|
||||||
OBJS = adler32.o crc32.o deflate.o infback.o \
|
OBJS = adler32.o crc32.o deflate.o infback.o \
|
||||||
|
@ -31,6 +39,7 @@ CFLAGS+=-fPIC -Wall
|
||||||
CFLAGS+=-I../../libr/include -I../include/
|
CFLAGS+=-I../../libr/include -I../include/
|
||||||
#LDFLAGS+=-L../../../libr/util
|
#LDFLAGS+=-L../../../libr/util
|
||||||
LIBNAME=libr_z.${SOVER}
|
LIBNAME=libr_z.${SOVER}
|
||||||
|
LIBAR=libr_z.a
|
||||||
|
|
||||||
all: ${LIBNAME} libr_z.a
|
all: ${LIBNAME} libr_z.a
|
||||||
|
|
||||||
|
@ -42,7 +51,7 @@ endif
|
||||||
cp ${LIBNAME} ../
|
cp ${LIBNAME} ../
|
||||||
|
|
||||||
libr_z.a: ${OFILES}
|
libr_z.a: ${OFILES}
|
||||||
${AR} q libr_z.a ${OFILES}
|
${CC_AR} ${OFILES}
|
||||||
${RANLIB} libr_z.a
|
${RANLIB} libr_z.a
|
||||||
cp libr_z.a ../
|
cp libr_z.a ../
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue