コード例 #1
0
ファイル: zzip-file.c プロジェクト: brock7/TianLong
/**                                                        
 * This function will => open(2) a real/zipped file
 *
 * It has some magic functionality builtin - it will first try to open
 * the given <em>filename</em> as a normal file. If it does not
 * exist, the given path to the filename (if any) is split into
 * its directory-part and the file-part. A ".zip" extension is
 * then added to the directory-part to create the name of a
 * zip-archive. That zip-archive (if it exists) is being searched
 * for the file-part, and if found a zzip-handle is returned. 
 * 
 * Note that if the file is found in the normal fs-directory the
 * returned structure is mostly empty and the => zzip_read call will
 * use the libc => read to obtain data. Otherwise a => zzip_file_open 
 * is performed and any error mapped to => errno(3).
 * 
 * There was a possibility to transfer zziplib-specific openmodes
 * through o_flags but you should please not use them anymore and
 * look into => zzip_open_ext_io to submit them down. This function
 * is shallow in that it just extracts the zzipflags and calls <ul><li><code>
 * zzip_open_ext_io(filename, o_flags, zzipflags|0664, 0, 0) </code></li></ul>
 * you must stop using this extra functionality (not well known
 * anyway) since zzip_open might be later usable to open files
 * for writing in which case the _EXTRAFLAGS will get in conflict.
 *
 * compare with  => open(2) and => zzip_fopen
 */
ZZIP_FILE*
zzip_open(zzip_char_t* filename, int o_flags)
{
    /* backward compatibility */
    int o_modes = 0664;
    if (o_flags & ZZIP_CASEINSENSITIVE) 
    {  o_flags ^= ZZIP_CASEINSENSITIVE; o_modes |= ZZIP_CASELESS; }
    if (o_flags & ZZIP_IGNOREPATH) 
    {  o_flags ^= ZZIP_IGNOREPATH;      o_modes |= ZZIP_NOPATHS; }
    return zzip_open_ext_io(filename, o_flags, o_modes, 0, 0);
}
コード例 #2
0
ファイル: Psar.c プロジェクト: pavel-demin/lua-player-plus
PSAR_ENTRY *LPP_PsarDecoder_getEntry(const char *filename)
{
    if(!initialized) return NULL;
    zzip_strings_t ext[] = {"", 0};

    ZZIP_FILE *fd = zzip_open_ext_io(filename, O_RDONLY | (0x0), ZZIP_ONLYZIP, ext, &psar_handlers);
    if(fd == NULL)
    {
        #ifdef DEBUG
        dwrite_output("Function %s Line %d : Cannot open the file '%s' for read.\n", __FUNCTION__, __LINE__, filename);
        #endif
        return NULL;
    }

    PSAR_ENTRY *entry = (PSAR_ENTRY*)malloc(sizeof(PSAR_ENTRY));
    if(!entry)
    {
        #ifdef DEBUG
        dwrite_output("Function %s Line %d : Cannot allocate 'entry' to memory.\n", __FUNCTION__, __LINE__);
        #endif
        zzip_close(fd);
        return NULL;
    }

    memset(entry, 0, sizeof(PSAR_ENTRY));

    zzip_seek(fd, 0, SEEK_END);
    entry->len = zzip_tell(fd);
    zzip_rewind(fd);

    if(entry->len <= 0)
    {
        free(entry);
        zzip_fclose(fd);
        #ifdef DEBUG
        dwrite_output("Function %s Line %d : file len is lower than zero.\n", __FUNCTION__, __LINE__);
        #endif
        return NULL;
    }

    entry->data = (u8*)malloc(entry->len);
    zzip_fread(entry->data, 1, entry->len, fd);
    zzip_fclose(fd);

    return(entry);
}
コード例 #3
0
ファイル: luazip.c プロジェクト: msva/luazip
static int zip_openfile (lua_State *L) {
  ZZIP_FILE** inf;

  const char * ext2[LUAZIP_MAX_EXTENSIONS+1];
  zzip_strings_t *ext = ext2;

  const char *filename = luaL_checkstring(L, 1);
  /*const char *mode = luaL_optstring(L, 2, "r");*/

  inf = newinternalfile(L);

  if (lua_isstring(L, 2))
  {
    /* creates a table with the string as the first and only (numerical) element */
    lua_newtable(L);
    lua_pushvalue(L, 2);
    lua_rawseti(L, -2, 1);

    /* replaces the string by the table with the string inside */
    lua_replace(L, 2);
  }
  
  if (lua_istable(L, 2))
  {
    unsigned i, m, n;

    /* how many extension were specified? */
#if LUA_VERSION_NUM < 501
    n = luaL_getn(L, 2);
#else
    n = lua_rawlen(L, 2);
#endif

    if (n > LUAZIP_MAX_EXTENSIONS)
    {
      luaL_error(L, "too many extensions specified");
    }

    for (i = 0, m = 0; i < n; i++)
    {
      lua_rawgeti(L, 2, i+1);
      if (lua_isstring(L, -1))
      {
        /* luazip specifies "zip" as the extension, but zziplib expects ".zip" */
        lua_pushstring(L, ".");
        lua_insert(L, -2);
        lua_concat(L, 2);

        ext2[m] = lua_tostring(L, -1);
        m++;
      }
      lua_pop(L, 1);
    }
    ext2[m] = 0;

    *inf = zzip_open_ext_io(filename, 0, 0664, ext, 0);
  }
  else
  {
    *inf = zzip_open(filename, 0);
  }

  if (*inf)
    return 1;

  lua_pushnil(L);
  lua_pushfstring(L, "could not open file `%s'", filename);
  return 2;
}
コード例 #4
0
int 
main (int argc, char* argv[])
{
    if (argc <= 1 || argc > 3)
    {
        printf (usage);
        exit (0);
    }

    if (strlen(argv[1]) > 128) {
        fprintf(stderr, "Please provide a filename shorter than 128 chars.\n");
        exit(1);
    }

    /* obfuscate the file */
    {
        int ch;
        FILE* fin;
        FILE* fout;
        fin  = fopen(argv[1], "rb");
        if (!fin) {
            fprintf(stderr, "Can't open input file \"%s\"\n", argv[1]);
            exit(1);
        }
        fout = fopen((argc == 2) ? "obfuscated" : "obfuscated.dat", "wb");
        if (!fout) {
            fprintf(stderr, "Can't open output file \"obfuscated\"\n");
            exit(1);
        }
        while ((ch = fgetc(fin)) != EOF) {
            ch ^= 0x55;
            fputc(ch, fout);
        }
        fclose(fout);
        fclose(fin);
    }

    /* install our I/O hander */
    zzip_init_io(&our_handlers, 0);
    our_handlers.read = &our_read;

    {
#       define argn 2
        ZZIP_FILE* fp;
        char name[256];
        if (argc == 3) {
            sprintf(name, "obfuscated/%s", argv[argn]);
        } else {
            sprintf(name, "obfuscated");
        }
        fp = zzip_open_ext_io (name, O_RDONLY|O_BINARY, ZZIP_PREFERZIP,
			       our_fileext, &our_handlers);

        if (! fp)
        {
            perror (name);
            exit(1);
        }else{
            char buf[17];
            int n;

        /* read chunks of 16 bytes into buf and print them to stdout */
            while (0 < (n = zzip_read(fp, buf, 16)))
            {
                buf[n] = '\0';
#             ifdef STDOUT_FILENO
                write (STDOUT_FILENO, buf, n);
#             else
                fwrite (buf, 1, n, stdout);
#             endif
            }

            if (n == -1) 
                perror (argv[argn]);
        }
    }
    
    return 0;
}