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
CFLAGS+=-Wall -DCORELIB
LDFLAGS+=$(STOP)/zip/librz.a
include ../socket/deps.mk

View File

@ -29,7 +29,6 @@ R_API ut64 r_io_desc_size(RIO *io, RIODesc *desc){
return sz;
}
R_API RIODesc *r_io_desc_new(RIOPlugin *plugin, int fd, const char *name, int flags, int mode, void *data) {
int i;
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 <string.h>

View File

@ -24,4 +24,4 @@ endif
${TARGET_IODBG}: ${OBJ_IODBG}
${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_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__ || \
__NetBSD__ || __KFBSD__ || __OpenBSD__
#define DEBUGGER_SUPPORTED 1

View File

@ -54,7 +54,12 @@ static RIODesc *__open(RIO *io, const char *file, int rw, int mode) {
free (riog);
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);
#endif
}
eprintf ("gdb.io.open: Cannot connect to host.\n");
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;
} else eprintf ("Connected to: %s at port %s\n", ptr, port);
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;
}

View File

@ -90,9 +90,11 @@ static RIODesc *__open(struct r_io_t *io, const char *pathname, int rw, int mode
return NULL;
}
}
if (mal->buf != NULL)
return r_io_desc_new (&r_io_plugin_malloc, mal->fd,
pathname, rw, mode, mal);
if (mal->buf != NULL) {
RETURN_IO_DESC_NEW(&r_io_plugin_malloc, mal->fd, 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,
mal->size);
free (mal);

View File

@ -1,6 +1,6 @@
/* radare - LGPL - Copyright 2012-2013 - pancake
io_zip.c rewrite: Adam Pridgen <dso@rice.edu || adam.pridgen@thecoverofnight.com>
*/
*/
#include <r_io.h>
#include <r_lib.h>
@ -28,16 +28,12 @@ typedef struct r_io_zip_uri_const_t {
char *URI = "://";
static RIOZipConstURI ZIP_URIS[] = {
{"zip://", 6},
{"apk://", 6},
{"jar://", 6},
{NULL, 0}
{"zip://", 6},
{"apk://", 6},
{"jar://", 6},
{NULL, 0}
};
typedef struct r_io_zip_file_obj_t{
char * name;
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_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);
RIODesc *check_zip_file_open(RIO *io, const char* filename);
int r_io_zip_has_uri_substr(const char *file);
int r_io_zip_check_uri(const char *file);
int r_io_zip_check_file(const char *file);
static int r_io_zip_has_uri_substr(const char *file);
static int r_io_zip_check_uri(const char *file);
static int r_io_zip_check_file(const char *file);
int r_io_zip_open_zip_file(RIOZipFileObj * zipFileObj);
@ -86,12 +82,11 @@ static int r_io_zip_init(RIO *io) {
return R_TRUE;
}
int r_io_zip_has_uri_substr(const char *file){
static int r_io_zip_has_uri_substr(const char *file){
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 i = 0;
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){
int zip_errorp;
struct zip * zipArch = NULL;
if(!archivename)
return zipArch;
struct zip * zipArch = NULL;
zipArch = zip_open(archivename, flags, &zip_errorp);
if(!archivename)
return zipArch;
zipArch = zip_open(archivename, flags, &zip_errorp);
if (!zipArch){
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;
ut8 buf[10];
@ -169,18 +164,18 @@ int r_io_zip_slurp_file(RIOZipFileObj *zip_file_obj){
struct zip_stat sb;
//eprintf("Slurping file");
if (zip_file_obj && zip_file_obj->entry != -1){
zFile = zip_fopen_index(zipArch, zip_file_obj->entry, 0);
if(!zip_file_obj->b){
zip_file_obj->b = r_buf_new();
}
zip_stat_init(&sb);
if(zFile && zip_file_obj->b && !zip_stat_index(zipArch, zip_file_obj->entry, 0, &sb) ){
ut8 *buf = malloc(sb.size);
memset(buf, 0, sb.size);
if (buf){
zip_fread(zFile, 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){
files = r_list_new();
num_entries = zip_get_num_files(zipArch);
for (i=0; i < num_entries; i++){
char *name = NULL;
zip_stat_init(&sb );
zip_stat_index(zipArch, i, 0, &sb );
for (i=0; i < num_entries; i++){
char *name = NULL;
zip_stat_init(&sb );
zip_stat_index(zipArch, i, 0, &sb );
//eprintf("Comparing %s == %s = %d\n", sb.name, filename, strcmp(sb.name, filename));
name = strdup(sb.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 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);
if (!zipArch){
return result;
}
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 (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);
if (s && zip_file_obj->entry != -1){
if (zip_replace(zipArch, zip_file_obj->entry, s) == 0)
result = R_TRUE;
}else if (s && zip_file_obj->name){
if(zip_add(zipArch, zip_file_obj->name, s) == 0){
zip_file_obj->entry = zip_name_locate(zipArch, zip_file_obj->name, 0);
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;
filename_in_zipfile = strstr(zip_filename, "//");
if (filename_in_zipfile && filename_in_zipfile[2]){
// 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("No file was given. Here's a dump to help you decide:\n");
files = r_io_zip_get_files(zip_filename, 0, mode, rw );
if(files){
ut64 i = 0;
int i = 0;
r_list_foreach_safe(files, iter, iter_tmp, name){
eprintf("\t %d) %s\n", i++, name);
if (name)
free(name);
r_list_delete(files, iter);
free (name);
r_list_delete (files, iter);
}
r_list_free(files);
r_list_free (files);
}
return result;
}
//eprintf("After parsing the given uri: %s\n", file);
//eprintf("Zip filename the given uri: %s\n", zip_filename);
//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);
if (zipFileObj && zipFileObj->entry == -1){
eprintf("Warning: File did not exist, creating a new one.\n");
}
zipFileObj = r_io_zip_alloc_zipfileobj (zip_filename,
filename_in_zipfile, ZIP_CREATE, mode, rw);
if (zipFileObj && zipFileObj->entry == -1)
eprintf ("Warning: File did not exist, creating a new one.\n");
if(zipFileObj){
if (zipFileObj) {
zipFileObj->io_backref = io;
result = r_io_desc_new(&r_io_plugin_zip, zipFileObj->fd, zipFileObj->name, rw, mode, zipFileObj);
}
if (!result){
eprintf("Failed to open the archive %s and file %s\n", zip_filename, filename_in_zipfile);
if (zipFileObj)
free(zipFileObj);
if (!result) {
eprintf ("Failed to open the archive %s and file %s\n",
zip_filename, filename_in_zipfile);
free (zipFileObj);
}
if (zip_uri)
free(zip_uri);
free (zip_uri);
return result;
}
}
static ut64 r_io_zip_lseek(RIO *io, RIODesc *fd, ut64 offset, int whence) {
RIOZipFileObj *zip_file_obj;
static ut64 r_io_zip_lseek(RIO *io, RIODesc *fd, ut64 offset, int whence) {
RIOZipFileObj *zip_file_obj;
ut64 seek_val = 0;
if (fd == NULL || fd->data == NULL)
return -1;
ut64 seek_val = 0;
if (fd == NULL || fd->data == NULL)
return -1;
zip_file_obj = fd->data;
zip_file_obj = fd->data;
seek_val = zip_file_obj->b->cur;
switch (whence) {
seek_val = zip_file_obj->b->cur;
switch (whence) {
case SEEK_SET:
seek_val = zip_file_obj->b->length < offset ? zip_file_obj->b->length : offset;
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;
zip_file_obj->b->cur = io->off = seek_val;
return seek_val;
case SEEK_END:
seek_val = zip_file_obj->b->length;
zip_file_obj->b->cur = io->off = 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){
zipFileObj = r_io_zip_create_new_file(archivename, filename, NULL, flags, mode, rw);
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);
}
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) {
RIOZipFileObj *zip_file_obj = NULL;
zip_file_obj = malloc(sizeof(RIOZipFileObj));
if (zip_file_obj)
memset(zip_file_obj, 0, sizeof(RIOZipFileObj));
if (zip_file_obj->b->length < io->off)
io->off = zip_file_obj->b->length;
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 = random() & 0xFFFF;;
zip_file_obj->mode = mode;
zip_file_obj->rw = rw;
zip_file_obj->flags = flags;
zip_file_obj->modified = 1;
return r_buf_write_at(zip_file_obj->b, io->off, buf, count);
}
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,
.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
};
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;
}
}
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
struct r_lib_struct_t radare_plugin = {
.type = R_LIB_TYPE_IO,
.data = &r_io_plugin_zip
};
struct r_lib_struct_t radare_plugin = {
.type = R_LIB_TYPE_IO,
.data = &r_io_plugin_zip
};
#endif

View File

@ -3,74 +3,19 @@ OBJ_ZIP=io_zip.o
STATIC_OBJ+=${OBJ_ZIP}
TARGET_ZIP=io_zip.${EXT_SO}
ALL_TARGETS+=${TARGET_ZIP}
CFLAGS+=-I../../shlr/zip/include
CFLAGS+=-I../../shlr/zip/include
ifeq (${WITHPIC},0)
LINKFLAGS+=../../util/libr_util.a
LINKFLAGS+=../../lib/libr_lib.a
LINKFLAGS+=../../io/libr_io.a
LINKFLAGS+=../../../shlr/zip/libr_zip.a
else
LINKFLAGS+=-L../../lib -lr_lib
LINKFLAGS+=-L../../util -lr_util
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
# 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}
@echo ${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) {
int size = 64, i;
if (num&0xff00000000) size = 64;
if (num>>32) size = 64;
else if (num&0xff000000) size = 32;
else if (num&0xff0000) size = 24;
else if (num&0xff00) size = 16;

View File

@ -2,7 +2,7 @@ include ../config-user.mk
include ../mk/${COMPILER}.mk
HOST_CC?=gcc
MODS=udis86 java tcc zip/zlib zip/zip
MODS=udis86 java tcc zip
URL=git://github.com/radare/sdb
PWD=$(shell pwd)
SDB_CONFIG=${PWD}/sdb-config.mk

View File

@ -1,12 +1,20 @@
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}:
${MAKE} -C zlib
LIBAR=librz.a
librz.a: libr_zip.a
${CC_AR} zlib/*.o zip/*.o
libr_zip.a: libr_z.a
${MAKE} -C zip
libr_z.a:
${MAKE} -C zlib
clean:
${MAKE} -C zlib clean
${MAKE} -C zip clean
rm *.a *.${SOEXT}
rm -f *.a *.${EXT_SO}

View File

@ -36,15 +36,18 @@
#ifndef ZIP_EXTERN
#ifdef _WIN32
#define ZIP_EXTERN __declspec(dllimport)
#elif defined(__GNUC__) && __GNUC__ >= 4
#define ZIP_EXTERN __attribute__ ((visibility ("default")))
#else
#define ZIP_EXTERN
#endif
#if 0
# ifndef ZIP_EXTERN
# ifdef _WIN32
# define ZIP_EXTERN __declspec(dllimport)
# elif defined(__GNUC__) && __GNUC__ >= 4
# define ZIP_EXTERN __attribute__ ((visibility ("default")))
# else
# define ZIP_EXTERN
# endif
# endif
#endif
#define ZIP_EXTERN extern
#ifdef __cplusplus
extern "C" {

View File

@ -80,6 +80,7 @@ extern z_const char * const z_errmsg[10]; /* indexed by 2-zlib_error */
/* target dependencies */
#if 0
#if defined(MSDOS) || (defined(WINDOWS) && !defined(WIN32))
# define OS_CODE 0x00
# ifndef Z_SOLO
@ -96,6 +97,7 @@ extern z_const char * const z_errmsg[10]; /* indexed by 2-zlib_error */
# endif
# endif
#endif
#endif
#ifdef AMIGA
# define OS_CODE 0x01

View File

@ -1,10 +1,10 @@
include ../../../config-user.mk
include ../../../libr/config.mk
include ../../../mk/${COMPILER}.mk
## XXX this comes from config.mk?
ifeq (${OSTYPE},darwin)
SOEXT=dylib
SOVER=${SOEXT}
SOVER=${EXT_SO}
LDFLAGS+=-dynamic
LDFLAGS_SHARED?=-fPIC -shared
#ifeq (${ARCH},i386)
@ -13,14 +13,13 @@ LDFLAGS_SHARED?=-fPIC -shared
#endif
else
SOVERSION=0
SOEXT=so
SOVER=${SOEXT}
SOVER=${EXT_SO}
LDFLAGS_SHARED?=-fPIC -shared
LDFLAGS_SHARED+=-Wl,-soname,libr_zip.${SOEXT}
LDFLAGS_SHARED+=-Wl,-soname,libr_zip.${EXT_SO}
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_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 \
@ -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_unchange_archive.o zip_unchange_data.o zip_utf-8.o
#OFILES=libr_zip.a $(OBJS)
OFILES=$(OBJS)
#CFLAGS+=-g -ggdb -fPIC
CFLAGS+=-fPIC
CFLAGS+=-I../../libr/include -I../include/
LDFLAGS+=-L../../../libr/util -L../ -lr_z
CFLAGS+=-fPIC -Wall
LDFLAGS+=-L../../../libr/util
LINKFLAGS=../libr_z.a
#LDFLAGS=-shared
SOEXT?=dylib
EXT_SO?=dylib
LIBNAME=libr_zip.${SOVER}
all: ${LIBNAME} libr_zip.a
${LIBNAME}: ${OBJS}
ifneq ($(SILENT),)
@echo LIB ${LIBNAME}
endif
${CC} ${LDFLAGS} $(LDFLAGS_SHARED) -o $@ ${OBJS}
cp ${LIBNAME} ../
${CC} ${LDFLAGS} $(LDFLAGS_SHARED) -o $@ ${OBJS} ${LINKFLAGS}
cp -f ${LIBNAME} ../
LIBAR=libr_zip.a
libr_zip.a: ${OFILES}
${AR} q libr_zip.a ${OFILES}
${CC_AR} ${OFILES}
${RANLIB} libr_zip.a
cp libr_zip.a ../
cp -f libr_zip.a ../
clean:
rm -f ${LIBNAME} *.o *.a *.d *.dylib *.so
rm -f ../${LIBNAME} ../*.o ../*.a ../*.d ../*.dylib ../*.so
rm -f ${LIBNAME} *.o *.a *.d *.${EXT_SO}
rm -f ../${LIBNAME} ../*.o ../*.a ../*.d ../*.${EXT_SO}

View File

@ -5,6 +5,9 @@
*/
/* #undef HAVE_DECL_TZNAME */
#define ftello ftell
#define fseeko fseek
/* Define to 1 if you have the <dlfcn.h> header file. */
#define HAVE_DLFCN_H 1
@ -72,7 +75,9 @@
#define HAVE_STRING_H 1
/* 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 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);
}
#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) {
_zip_error_set(&za->error, ZIP_ER_TMPOPEN, errno);
free(temp);
return NULL;
}
#endif
if ((tfp=fdopen(tfd, "r+b")) == NULL) {
_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 time_t last_mod = 0;
#undef HAVE_STRUCT_TM_TM_ZONE
if (last_mod == 0) {
#ifdef HAVE_STRUCT_TM_TM_ZONE
time_t now;

View File

@ -1,10 +1,17 @@
include ../../../config-user.mk
include ../../../libr/config.mk
include ../../../mk/${COMPILER}.mk
ifeq (${OSTYPE},windows)
EXT_SO=dll
SOVER=${EXT_SO}
LDFLAGS+=-shared
LDFLAGS_SHARED?=-fPIC -shared
else
ifeq (${OSTYPE},darwin)
SOEXT=dylib
SOVER=${SOEXT}
EXT_SO=dylib
SOVER=${EXT_SO}
LDFLAGS+=-dynamic
LDFLAGS_SHARED?=-fPIC -shared
# ifeq (${ARCH},i386)
@ -13,10 +20,11 @@ LDFLAGS_SHARED?=-fPIC -shared
# endif
else
SOVERSION=0
SOEXT=so
SOVER=${SOEXT}
EXT_SO=so
SOVER=${EXT_SO}
LDFLAGS_SHARED?=-fPIC -shared
LDFLAGS_SHARED+=-Wl,-soname,libr_z.${SOEXT}
LDFLAGS_SHARED+=-Wl,-soname,libr_z.${EXT_SO}
endif
endif
OBJS = adler32.o crc32.o deflate.o infback.o \
@ -31,6 +39,7 @@ CFLAGS+=-fPIC -Wall
CFLAGS+=-I../../libr/include -I../include/
#LDFLAGS+=-L../../../libr/util
LIBNAME=libr_z.${SOVER}
LIBAR=libr_z.a
all: ${LIBNAME} libr_z.a
@ -42,7 +51,7 @@ endif
cp ${LIBNAME} ../
libr_z.a: ${OFILES}
${AR} q libr_z.a ${OFILES}
${CC_AR} ${OFILES}
${RANLIB} libr_z.a
cp libr_z.a ../