CryptDecode with modifier CRYPT_ARCH_ZIP - How to use?

 

The actual question is this. As I understand it, we are talking about packing/unpacking zip array. It's mega useful thing, but I can't use it, CryptDecode function stubbornly gives zero result on test zip archive:

//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
  {
//---
   uchar array[];
   uchar key[]={0};
   uchar result[];
   int handle = FileOpen("link.zip", FILE_READ|FILE_BIN|FILE_COMMON);
   FileReadArray(handle, array);
   FileClose(handle);
   int d = CryptDecode(CRYPT_ARCH_ZIP, array, key, result);
   printf(GetLastError());
   printf("Read totals: " + (string)ArraySize(array));
  }

Maybe something else must be specified as a key, or I've got wrong idea about CRYPT_ARCH_ZIP modifier value. In any case, the documentation doesn't contain an example of the function, which makes it difficult to understand how it works. The GetLastError function writes 4001 - Unexpected Internal Error.

 
C-4:

The actual question is this. As I understand it, we are talking about packing/unpacking zip array. It's mega useful thing, but I can't use it, CryptDecode function stubbornly gives zero result on test zip archive:

Maybe something else must be specified as a key, or I've got wrong idea about CRYPT_ARCH_ZIP modifier value. In any case, there is no example of how to use the function in the documentation, which makes it much more difficult to understand how it works. The GetLastError function writes 4001 - Unexpected Internal Error.

wrong approach
 
sanyooooook:
not the right approach
More details if you can.
 

A ZIP archive is a whole structure, but the function archives/unarchives an array, i.e. only an array ready for unarchiving should be placed there.

Roughly speaking, it unarchives only the output of the archiving function.

 
C-4:
More details if you can.
Or what in
link.zip
has been created by the archive function?
 
sanyooooook:

A ZIP archive is a whole structure, but the function archives/unarchives an array, i.e. only an array ready for unarchiving should be placed there.

Roughly speaking, it unarchives only the output of the archiving function.

Got it. MQ style. The main thing though is to decrypt the zip. Doesn't anyone happen to have a library for working with zip archives in MQL?
 
sanyooooook:
or what in
was created by the archive function?
Nah, it says zero. CryptDecode decodes zip. Tried to create a zip archive - CryptEncode's responses don't match those of the regular archivers. CryptEncode's zipped file is much shorter, which indirectly confirms your theory!
 
here is a description of the file structure http://blog2k.ru/archives/3391
Описание формата ZIP файла
  • 2014.05.29
  • Евгений Жирнов (jirnov@gmail.com)
  • blog2k.ru
ZIP файл состоит из трех областей: сжатые/несжатые данные, (последовательность структур Local File Header, сами данные и необязательных Data descriptor)центральный каталог (последовательность структур Central directory file header)описание центрального каталога (End of central directory record) С начала файла идет набор из Local File Header...
 
C-4:
Nope, it says zero. CryptDecode decodes zip. I tried to create a zip archive, CryptEncode and normal archivers didn't match. CryptEncode makes the zipped file much shorter, which indirectly confirms your theory!

It's not a theory, it's just that they're used to having everything ready to go in the archiver,

I foolishly thought it would unzip files made with a normal archiver.

 

The problem is that I can't find the byte array occurrences given by CryptEncode in the regular zip archive.

The file is the same. So in a classic zip archive, there should be a byte-array corresponding to the CryptEncode byte-array

 
C-4:

The problem is that I can't find the byte array occurrences given by CryptEncode in a normal zip archive.

), so you're looking in the wrong way.
Reason: