More work to make zip plugin work

This commit is contained in:
pancake 2013-11-14 23:22:56 +01:00
parent c1dd901413
commit 30ebc8b8b3
20 changed files with 271 additions and 289 deletions

View File

@ -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

View File

@ -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);

View File

@ -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>

View File

@ -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

View File

@ -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

View File

@ -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;

View File

@ -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;
} }

View File

@ -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);

View File

@ -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>
@ -34,10 +34,6 @@ static RIOZipConstURI ZIP_URIS[] = {
{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)){
@ -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];
@ -348,15 +343,13 @@ static RIODesc *r_io_zip_open(RIO *io, const char *file, int rw, int mode) {
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;
} }
@ -365,31 +358,28 @@ static RIODesc *r_io_zip_open(RIO *io, const char *file, int rw, int mode) {
//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);
return result;
} }
if (zip_uri)
free(zip_uri);
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;
@ -416,9 +406,9 @@ static ut64 r_io_zip_lseek(RIO *io, RIODesc *fd, ut64 offset, int whence) {
return 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){ static int r_io_zip_read(RIO *io, RIODesc *fd, ut8 *buf, int count){
RIOZipFileObj *zip_file_obj = NULL; RIOZipFileObj *zip_file_obj = NULL;
if (fd == NULL || fd->data == NULL || buf == NULL) if (fd == NULL || fd->data == NULL || buf == NULL)
return -1; return -1;
@ -428,9 +418,9 @@ static int r_io_zip_read(RIO *io, RIODesc *fd, ut8 *buf, int count){
io->off = zip_file_obj->b->length; io->off = zip_file_obj->b->length;
return r_buf_read_at(zip_file_obj->b, io->off, buf, count); 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){ static int r_io_zip_write(RIO *io, RIODesc *fd, const ut8 *buf, int count){
RIOZipFileObj *zip_file_obj = NULL; RIOZipFileObj *zip_file_obj = NULL;
if (fd == NULL || fd->data == NULL || buf == NULL) if (fd == NULL || fd->data == NULL || buf == NULL)
return -1; return -1;
@ -442,9 +432,9 @@ static int r_io_zip_write(RIO *io, RIODesc *fd, const ut8 *buf, int count){
zip_file_obj->modified = 1; zip_file_obj->modified = 1;
return r_buf_write_at(zip_file_obj->b, io->off, buf, count); return r_buf_write_at(zip_file_obj->b, io->off, buf, count);
} }
static int r_io_zip_close(RIODesc *fd){ static int r_io_zip_close(RIODesc *fd){
RIOZipFileObj *zip_file_obj = NULL; RIOZipFileObj *zip_file_obj = NULL;
//eprintf("Am I called 2x?\n"); //eprintf("Am I called 2x?\n");
// this api will be called multiple times :/ // this api will be called multiple times :/
@ -455,13 +445,13 @@ static int r_io_zip_close(RIODesc *fd){
r_io_zip_free_zipfileobj(zip_file_obj); r_io_zip_free_zipfileobj(zip_file_obj);
zip_file_obj = fd->data = NULL; zip_file_obj = fd->data = NULL;
return 0; return 0;
} }
RIOZipFileObj* r_io_zip_alloc_zipfileobj(const char *archivename, const char *filename, ut32 flags, int mode, int rw){ RIOZipFileObj* r_io_zip_alloc_zipfileobj(const char *archivename, const char *filename, ut32 flags, int mode, int rw){
ut64 i, num_entries; ut64 i, num_entries;
struct zip_stat sb; struct zip_stat sb;
struct zip * zipArch = r_io_zip_open_archive(archivename, flags, mode, rw); struct zip * zipArch = r_io_zip_open_archive(archivename, flags, mode, rw);
@ -492,10 +482,10 @@ RIOZipFileObj* r_io_zip_alloc_zipfileobj(const char *archivename, const char *fi
return zipFileObj; 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 *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; RIOZipFileObj *zip_file_obj = NULL;
zip_file_obj = malloc(sizeof(RIOZipFileObj)); zip_file_obj = malloc(sizeof(RIOZipFileObj));
@ -507,7 +497,7 @@ RIOZipFileObj *r_io_zip_create_new_file(const char *archivename, const char *fil
zip_file_obj->b = r_buf_new(); zip_file_obj->b = r_buf_new();
zip_file_obj->name = sb == NULL ? strdup(filename) : strdup(sb->name); zip_file_obj->name = sb == NULL ? strdup(filename) : strdup(sb->name);
zip_file_obj->entry = sb == NULL ? -1 : sb->index; zip_file_obj->entry = sb == NULL ? -1 : sb->index;
zip_file_obj->fd = random() & 0xFFFF;; zip_file_obj->fd = r_num_rand (0xFFFF);
zip_file_obj->mode = mode; zip_file_obj->mode = mode;
zip_file_obj->rw = rw; zip_file_obj->rw = rw;
@ -515,13 +505,13 @@ RIOZipFileObj *r_io_zip_create_new_file(const char *archivename, const char *fil
return zip_file_obj; return zip_file_obj;
} }
static int r_io_zip_plugin_open(RIO *io, const char *file) { static int r_io_zip_plugin_open(RIO *io, const char *file) {
return (io && file) && (r_io_zip_check_uri(file)); return (io && file) && (r_io_zip_check_uri(file));
} }
struct r_io_plugin_t r_io_plugin_zip = { struct r_io_plugin_t r_io_plugin_zip = {
.name = "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/", .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, .open = r_io_zip_open,
@ -533,11 +523,11 @@ struct r_io_plugin_t r_io_plugin_zip = {
.system = NULL, .system = NULL,
.debug = NULL, .debug = NULL,
.init = r_io_zip_init .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

View File

@ -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}

View File

@ -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;

View File

@ -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

View File

@ -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}

View File

@ -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" {

View File

@ -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

View File

@ -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,10 +13,9 @@ 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
@ -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}

View File

@ -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

View File

@ -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);

View File

@ -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;

View File

@ -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 ../