Hi I am using SWFKit to load in data from an encrypted .zip file which is generated after our application is shipped. There is one caveat however: the data cannot be written disk. So using the LiteUnzip example I found on the boards here, I made the following bit of code:
Code:
struct {
long dwLowDateTime;
long dwHighDateTime;
} FILETIME;
struct {
long Index;
long Attributes;
FILETIME AccessTime;
FILETIME CreateTime;
FILETIME ModifyTime;
long CompressedSize;
long UncompressedSize;
char Name[260];
} zipEntry;
/*
Error Codes
These are the standard error codes for LiteUnzip functions
*/
/*
var ZR_OK= 0; // Success
// The following come from general system stuff (e.g. files not openable)
var ZR_NOFILE= 1; // Can't create/open the file
var ZR_NOALLOC= 2; // Failed to allocate memory
var ZR_WRITE= 3; // A general error writing to the file
var ZR_NOTFOUND= 4; // Can't find the specified file in the zip
var ZR_MORE= 5; // There's still more data to be unzipped
var ZR_CORRUPT= 6; // The zipfile is corrupt or not a zipfile
var ZR_READ= 7; // An error reading the file
var ZR_NOTSUPPORTED=8; // The entry is in a format that can't be decompressed by this Unzip add-on
// The following come from mistakes on the part of the caller
var ZR_ARGS= 9; // Bad arguments passed
var ZR_NOTMMAP= 10; // Tried to ZipGetMemory, but that only works on mmap zipfiles, which yours wasn't
var ZR_MEMSIZE= 11; // The memory-buffer size is too small
var ZR_FAILED= 12; // Already failed when you called this function
var ZR_ENDED= 13; // The zip creation has already been closed
var ZR_MISSIZE= 14; // The source file size turned out mistaken
var ZR_ZMODE= 15; // Tried to mix creating/opening a zip
// The following come from bugs within the zip library itself
var ZR_SEEK= 16; // trying to seek in an unseekable file
var ZR_NOCHANGE= 17; // changed its mind on storage, but not allowed
var ZR_FLATE= 18; // An error in the de/inflation code
var ZR_PASSWORD= 19; // Password is incorrect
*/
var unLiteZip = getAppDir() + "LiteUnzip.dll" ;//getAdditionalFile("LiteUnzip.dll");
dllimport unLiteZip stdcall long UnzipOpenFileA(long*, String, String);
dllimport unLiteZip stdcall long UnzipGetItemA(long, zipEntry*) ;
dllimport unLiteZip stdcall long UnzipGetItemW(long, zipEntry*) ;
dllimport unLiteZip stdcall long UnzipItemToFileA(long, String, zipEntry*);
dllimport unLiteZip stdcall long UnzipItemToBuffer(long, char*, long, zipEntry*);
dllimport unLiteZip stdcall long UnzipFindItemA(long, zipEntry*, Boolean);
dllimport unLiteZip stdcall long UnzipClose(long) ;
function unzip(archivename, filename, password, resultarray)
{
var archivepath = "";
var resultcode =0;
var obj = new Object;
obj.value = 0;
archivepath = getAppDir() + archivename;
resultcode = UnzipOpenFileA(obj, archivepath , password);
if (resultcode != 0)
{
Dialogs.msgBox("UnzipOpenFile - " + resultcode);
return resultcode;
}
var handle = obj.value;
var ze = new Struct(zipEntry);
var parsedfilename = false;
ze.Index = 0;
//ze.Name = filename;
obj.value = ze;
while (UnzipGetItemA(handle,obj)==0)
{
var name=new String(obj.value.Name);
var filenametest=new String(filename);
var name_array = name.split("\\");
name=new String(name_array.slice(-1));
if (filenametest==name)
{
parsedfilename=true;
break;
}
ze.Index += 1;
obj.value = ze;
obj.value.Name="";
continue;
}
if (!parsedfilename)
{
return 4;
}
var buffer = new StringStream;
var bufferref = new Object;
bufferref.value = buffer;
buffer.length=obj.value.UncompressedSize;
buffer.putPos =0;
Dialogs.msgBox("handle = '"+handle+"' length="+buffer.length+" name="+obj.value.Name );
resultcode = UnzipItemToBuffer(handle, bufferref, buffer.length, obj);
buffer.saveToFile("c:\\bufferout.dat");
if (resultcode != 0)
{
Dialogs.msgBox("UnzipItemToFileBufferPtr - "+resultcode+" len="+buffer.length);
UnzipClose(handle);
return resultcode;
}
UnzipClose(handle);
// If there was no error then we return the contents of the file.
return buffer.read(buffer.length);
}
The problem is that when I am reading in data from UnzipItemToBuffer, I get the error "5" which is the what LiteUnzip tells you there are subsequent reads to make to read in all the compressed data. The size of buffer is correct, (in my case I am reading in the entire compressed entry,) not surprisingly all the data in the test output file "c:\bufferout.dat" is 0's. Thus my guess is I am somehow defining the function wrong, or incorrectly specifying the buffer reference.