├── ApkProtection ├── .cproject ├── .gitignore ├── .project ├── .settings │ └── org.eclipse.cdt.managedbuilder.core.prefs └── src │ ├── ApkProtection.cpp │ ├── utils │ ├── ApkFile.cpp │ ├── ApkFile.h │ ├── AxmlParser.c │ └── AxmlParser.h │ └── zlib │ ├── ioapi.c │ ├── ioapi.h │ ├── libz.a │ ├── unzip.c │ ├── unzip.h │ ├── zconf.h │ └── zlib.h └── README.md /ApkProtection/.cproject: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 34 | 35 | 36 | 37 | 41 | 42 | 43 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 86 | 87 | 88 | 89 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | -------------------------------------------------------------------------------- /ApkProtection/.gitignore: -------------------------------------------------------------------------------- 1 | /Debug/ 2 | -------------------------------------------------------------------------------- /ApkProtection/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | ApkProtection 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.cdt.managedbuilder.core.genmakebuilder 10 | clean,full,incremental, 11 | 12 | 13 | 14 | 15 | org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder 16 | full,incremental, 17 | 18 | 19 | 20 | 21 | 22 | org.eclipse.cdt.core.cnature 23 | org.eclipse.cdt.core.ccnature 24 | org.eclipse.cdt.managedbuilder.core.managedBuildNature 25 | org.eclipse.cdt.managedbuilder.core.ScannerConfigNature 26 | 27 | 28 | -------------------------------------------------------------------------------- /ApkProtection/.settings/org.eclipse.cdt.managedbuilder.core.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.mingw.exe.debug.108337525/CPATH/delimiter=; 3 | environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.mingw.exe.debug.108337525/CPATH/operation=remove 4 | environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.mingw.exe.debug.108337525/CPLUS_INCLUDE_PATH/delimiter=; 5 | environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.mingw.exe.debug.108337525/CPLUS_INCLUDE_PATH/operation=remove 6 | environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.mingw.exe.debug.108337525/C_INCLUDE_PATH/delimiter=; 7 | environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.mingw.exe.debug.108337525/C_INCLUDE_PATH/operation=remove 8 | environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.mingw.exe.debug.108337525/append=true 9 | environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.mingw.exe.debug.108337525/appendContributed=true 10 | environment/buildEnvironmentLibrary/cdt.managedbuild.config.gnu.mingw.exe.debug.108337525/LIBRARY_PATH/delimiter=; 11 | environment/buildEnvironmentLibrary/cdt.managedbuild.config.gnu.mingw.exe.debug.108337525/LIBRARY_PATH/operation=remove 12 | environment/buildEnvironmentLibrary/cdt.managedbuild.config.gnu.mingw.exe.debug.108337525/append=true 13 | environment/buildEnvironmentLibrary/cdt.managedbuild.config.gnu.mingw.exe.debug.108337525/appendContributed=true 14 | -------------------------------------------------------------------------------- /ApkProtection/src/ApkProtection.cpp: -------------------------------------------------------------------------------- 1 | //============================================================================ 2 | // Name : ApkProtection.cpp 3 | // Author : maxzhang 4 | // Version : 5 | // Copyright : Your copyright notice 6 | // Description : Hello World in C++, Ansi-style 7 | //============================================================================ 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include "utils/ApkFile.h" 13 | using namespace std; 14 | 15 | int main(int argc, char *argv[]) { 16 | if (argc <= 1) { 17 | puts("pls input apk file"); 18 | return 0; 19 | } 20 | string path = string(argv[1]); 21 | ApkFile apk(path); 22 | try{ 23 | apk.unzip(); 24 | }catch (char* e) { 25 | cout<<"error:"< 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include "AxmlParser.h" 17 | using namespace std; 18 | 19 | const string ANDROIDMANIFEST_XML = "AndroidManifest.xml"; 20 | const string SHELL_APPLICATION = "org.javazjf.apkshell.ShellApplication"; 21 | 22 | int mkdir_r(const char *path) { 23 | if (path == NULL) { 24 | return -1; 25 | } 26 | char *temp = strdup(path); 27 | char *pos = temp; 28 | 29 | /* 去掉开头的 './' 或 '/' */ 30 | if (strncmp(temp, "/", 1) == 0) { 31 | pos += 1; 32 | } else if (strncmp(temp, "./", 2) == 0) { 33 | pos += 2; 34 | } 35 | /* 循环创建目录 */ 36 | for (; *pos != '\0'; ++pos) { 37 | if (*pos == '/') { 38 | *pos = '\0'; 39 | mkdir(temp); 40 | printf("for %s\n", temp); 41 | *pos = '/'; 42 | } 43 | } 44 | /* 如果最后一级目录不是以'/'结尾, 45 | 遇到'\0'就中止循环, 46 | 不会创建最后一级目录 */ 47 | if (*(pos - 1) != '/') { 48 | printf("if %s\n", temp); 49 | mkdir(temp); 50 | } 51 | free(temp); 52 | return 0; 53 | } 54 | 55 | ApkFile::ApkFile(string path) { 56 | this->mApkFilePath = path; 57 | this->mUncompressPath = string(""); 58 | } 59 | 60 | void ApkFile::unzip() { 61 | char *dir; 62 | dir = getcwd(NULL, 0); 63 | cout << "Current Working Directory:" << dir << ",Apk File:" 64 | << this->mApkFilePath << endl; 65 | int loc = this->mApkFilePath.find_last_of("/"); 66 | int dot = this->mApkFilePath.find_last_of("."); 67 | if (loc == -1) { 68 | this->mUncompressPath += this->mApkFilePath.substr(0, 69 | this->mApkFilePath.length() - 4); 70 | } else { 71 | this->mUncompressPath += this->mApkFilePath.substr(0, loc + 1); 72 | this->mUncompressPath += this->mApkFilePath.substr(loc + 1, 73 | dot - loc - 1); 74 | } 75 | char dos_cmd[256]; 76 | strcpy(dos_cmd, this->mUncompressPath.c_str()); 77 | _mkdir(dos_cmd); 78 | 79 | unzFile uf = NULL; 80 | unzFile data[1024 * 100]; 81 | unz_global_info64 gi; 82 | unz_file_info64 FileInfo; 83 | //打开zip文件 84 | uf = unzOpen64(this->mApkFilePath.c_str()); 85 | int result = unzGetGlobalInfo64(uf, &gi); 86 | if (result != UNZ_OK) 87 | cout << "get global info error!" << endl; 88 | char fileName[256]; 89 | int i = 0; 90 | string subDir, subFile; 91 | //循环解压缩文件 92 | for (i = 0; i < gi.number_entry; ++i) { 93 | if (unzGetCurrentFileInfo64(uf, &FileInfo, fileName, 256, NULL, 0, NULL, 94 | 0) != UNZ_OK) 95 | printf("%s", "error"); 96 | if (!(FileInfo.external_fa & 0x10)) { //文件,否则为目录 97 | string cfile = string(fileName); 98 | int loc = cfile.find_last_of("/"); 99 | if (loc == -1) { 100 | subDir = this->mUncompressPath; 101 | subFile = this->mUncompressPath + "/" + cfile; 102 | } else { 103 | subDir = this->mUncompressPath + "/" + cfile.substr(0, loc); 104 | subFile = this->mUncompressPath + "/" + cfile; 105 | } 106 | strcpy(dos_cmd, subDir.c_str()); 107 | if (_access(dos_cmd, 0) == -1) { 108 | mkdir_r(dos_cmd); 109 | } 110 | 111 | //打开文件 112 | result = unzOpenCurrentFile(uf);/* 无密码 */ 113 | //读取内容 114 | strcpy(fileName, subFile.c_str()); 115 | FILE* destFile = fopen(fileName, "wb"); 116 | int size = 0; 117 | while ((size = unzReadCurrentFile(uf, data, sizeof(data))) != 0) { 118 | fwrite(data, 1, size, destFile); 119 | } 120 | fclose(destFile); 121 | } else { 122 | printf("d:%s\n", fileName); 123 | } 124 | //关闭当前文件 125 | unzCloseCurrentFile(uf); 126 | 127 | //出错 128 | if (i < gi.number_entry - 1 && unzGoToNextFile(uf) != UNZ_OK) { 129 | cout << "error!" << endl; 130 | } 131 | } 132 | //关闭流 133 | unzClose(uf); 134 | } 135 | 136 | void ApkFile::decodeAndroidManifest() { 137 | string manifest = this->mUncompressPath + "/" + ANDROIDMANIFEST_XML; 138 | FILE *fp; 139 | char *inbuf; 140 | size_t insize; 141 | char *outbuf; 142 | size_t outsize; 143 | int ret; 144 | fp = fopen(manifest.c_str(), "rb"); 145 | if (fp == NULL) { 146 | cout << "AndroidManifest.xml not found!!" << endl; 147 | return; 148 | } 149 | fseek(fp, 0, SEEK_END); 150 | insize = ftell(fp); 151 | fseek(fp, 0, SEEK_SET); 152 | 153 | inbuf = (char *) malloc(insize * sizeof(char)); 154 | if (inbuf == NULL) { 155 | fprintf(stderr, "Error: init file buffer.\n"); 156 | fclose(fp); 157 | return; 158 | } 159 | 160 | ret = fread(inbuf, 1, insize, fp); 161 | if (ret != insize) { 162 | fprintf(stderr, "Error: read file.\n"); 163 | free(inbuf); 164 | fclose(fp); 165 | return; 166 | } 167 | 168 | ret = AxmlToXml(&outbuf, &outsize, inbuf, insize); 169 | 170 | free(inbuf); 171 | fclose(fp); 172 | 173 | if (ret == 0) { 174 | FILE *fout; 175 | string out_path = this->mUncompressPath + "/" + ANDROIDMANIFEST_XML 176 | + "_bak"; 177 | fout = fopen(out_path.c_str(), "w"); 178 | fprintf(fout, outbuf); 179 | fclose(fout); 180 | } 181 | 182 | free(outbuf); 183 | } 184 | 185 | void ApkFile::modifyApplication() { 186 | string manifest_decoded = this->mUncompressPath + "/" + ANDROIDMANIFEST_XML 187 | + "_bak"; 188 | string manifest_decoded_modify = this->mUncompressPath + "/" + ANDROIDMANIFEST_XML 189 | + "_m"; 190 | ifstream infile(manifest_decoded.c_str()); 191 | ofstream otfile; 192 | otfile.open(manifest_decoded_modify.c_str()); 193 | string temp; 194 | unsigned int loc = 0; 195 | unsigned int end = 0; 196 | while(getline(infile,temp)){ 197 | loc = temp.find("mUncompressPath; 220 | } 221 | 222 | -------------------------------------------------------------------------------- /ApkProtection/src/utils/ApkFile.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ApkFile.h 3 | * 4 | * Created on: 2015年3月30日 5 | * Author: zhangjianfa 6 | */ 7 | 8 | #ifndef UTILS_APKFILE_H_ 9 | #define UTILS_APKFILE_H_ 10 | #include 11 | using namespace std; 12 | 13 | class ApkFile{ 14 | private: 15 | string mApkFilePath; 16 | string mUncompressPath; 17 | public: 18 | ApkFile(string path); 19 | void unzip(); 20 | void decodeAndroidManifest(); 21 | void modifyApplication(); 22 | string getUncompressPath(); 23 | }; 24 | 25 | #endif /* UTILS_APKFILE_H_ */ 26 | -------------------------------------------------------------------------------- /ApkProtection/src/utils/AxmlParser.c: -------------------------------------------------------------------------------- 1 | /* AXML Parser 2 | * https://github.com/claudxiao/AndTools 3 | * Claud Xiao 4 | */ 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | #ifdef _WIN32 /* Windows */ 13 | 14 | #pragma warning(disable:4996) 15 | 16 | #ifndef snprintf 17 | #define snprintf _snprintf 18 | #endif 19 | 20 | #endif /* _WIN32 */ 21 | 22 | #include "AxmlParser.h" 23 | 24 | /* chunks' magic numbers */ 25 | enum{ 26 | CHUNK_HEAD = 0x00080003, 27 | 28 | CHUNK_STRING = 0x001c0001, 29 | CHUNK_RESOURCE = 0x00080180, 30 | 31 | CHUNK_STARTNS = 0x00100100, 32 | CHUNK_ENDNS = 0x00100101, 33 | CHUNK_STARTTAG = 0x00100102, 34 | CHUNK_ENDTAG = 0x00100103, 35 | CHUNK_TEXT = 0x00100104, 36 | }; 37 | 38 | /* attributes' types */ 39 | enum{ 40 | ATTR_NULL = 0, 41 | ATTR_REFERENCE = 1, 42 | ATTR_ATTRIBUTE = 2, 43 | ATTR_STRING = 3, 44 | ATTR_FLOAT = 4, 45 | ATTR_DIMENSION = 5, 46 | ATTR_FRACTION = 6, 47 | 48 | ATTR_FIRSTINT = 16, 49 | 50 | ATTR_DEC = 16, 51 | ATTR_HEX = 17, 52 | ATTR_BOOLEAN = 18, 53 | 54 | ATTR_FIRSTCOLOR = 28, 55 | ATTR_ARGB8 = 28, 56 | ATTR_RGB8 = 29, 57 | ATTR_ARGB4 = 30, 58 | ATTR_RGB4 = 31, 59 | ATTR_LASTCOLOR = 31, 60 | 61 | ATTR_LASTINT = 31, 62 | }; 63 | 64 | /* string table */ 65 | typedef struct{ 66 | uint32_t count; /* count of all strings */ 67 | uint32_t *offsets; /* each string's offset in raw data block */ 68 | 69 | unsigned char *data; /* raw data block, contains all strings encoded by UTF-16LE */ 70 | size_t len; /* length of raw data block */ 71 | 72 | unsigned char **strings;/* string table, point to strings encoded by UTF-8 */ 73 | } StringTable_t; 74 | 75 | /* attribute structure within tag */ 76 | typedef struct{ 77 | uint32_t uri; /* uri of its namespace */ 78 | uint32_t name; 79 | uint32_t string; /* attribute value if type == ATTR_STRING */ 80 | uint32_t type; /* attribute type, == ATTR_* */ 81 | uint32_t data; /* attribute value, encoded on type */ 82 | } Attribute_t; 83 | 84 | typedef struct AttrStack_t{ 85 | Attribute_t *list; /* attributes of current tag */ 86 | uint32_t count; /* count of these attributes */ 87 | struct AttrStack_t *next; 88 | } AttrStack_t; 89 | 90 | /* namespace record */ 91 | typedef struct NsRecord{ 92 | uint32_t prefix; 93 | uint32_t uri; 94 | struct NsRecord *next; /* yes, it's a single linked list */ 95 | } NsRecord_t; 96 | 97 | /* a parser, also a axml parser handle for user */ 98 | typedef struct { 99 | unsigned char *buf; /* origin raw data, to be parsed */ 100 | size_t size; /* size of raw data */ 101 | size_t cur; /* current parsing position in raw data */ 102 | 103 | StringTable_t *st; 104 | 105 | NsRecord_t *nsList; 106 | int nsNew; /* if a new namespace coming */ 107 | 108 | uint32_t tagName; /* current tag's name */ 109 | uint32_t tagUri; /* current tag's namespace's uri */ 110 | uint32_t text; /* when tag is text, its content */ 111 | 112 | AttrStack_t *attr; /* attributes */ 113 | } Parser_t; 114 | 115 | /* get a 4-byte integer, and mark as parsed */ 116 | /* uses byte oprations to avoid little or big-endian conflict */ 117 | static uint32_t 118 | GetInt32(Parser_t *ap) 119 | { 120 | uint32_t value = 0; 121 | unsigned char *p = ap->buf + ap->cur; 122 | value = p[0] | p[1]<<8 | p[2]<<16 | p[3]<<24; 123 | ap->cur += 4; 124 | return value; 125 | } 126 | 127 | static void 128 | CopyData(Parser_t *ap, unsigned char * to, size_t size) 129 | { 130 | memcpy(to, ap->buf + ap->cur, size); 131 | ap->cur += size; 132 | return; 133 | } 134 | 135 | /* skip some uknown of useless fields, don't parse them */ 136 | static void 137 | SkipInt32(Parser_t *ap, size_t num) 138 | { 139 | ap->cur += 4 * num; 140 | return; 141 | } 142 | 143 | /* if no more byte need to be parsed */ 144 | static int 145 | NoMoreData(Parser_t *ap) 146 | { 147 | return ap->cur >= ap->size; 148 | } 149 | 150 | static int 151 | ParseHeadChunk(Parser_t *ap) 152 | { 153 | /* file magic */ 154 | if(GetInt32(ap) != CHUNK_HEAD) 155 | { 156 | fprintf(stderr, "Error: not valid AXML file.\n"); 157 | return -1; 158 | } 159 | 160 | /* file size */ 161 | if(GetInt32(ap) != ap->size) 162 | { 163 | fprintf(stderr, "Error: not complete file.\n"); 164 | return -1; 165 | } 166 | 167 | return 0; 168 | } 169 | 170 | static int 171 | ParseStringChunk(Parser_t *ap) 172 | { 173 | uint32_t chunkSize; 174 | 175 | uint32_t styleCount; 176 | uint32_t stringOffset; 177 | uint32_t styleOffset; 178 | 179 | size_t i; 180 | 181 | /* chunk type */ 182 | if(GetInt32(ap) != CHUNK_STRING) 183 | { 184 | fprintf(stderr, "Error: not valid string chunk.\n"); 185 | return -1; 186 | } 187 | 188 | /* chunk size */ 189 | chunkSize = GetInt32(ap); 190 | 191 | /* count of strings */ 192 | ap->st->count = GetInt32(ap); 193 | 194 | /* count of styles */ 195 | styleCount = GetInt32(ap); 196 | 197 | /* unknown field */ 198 | SkipInt32(ap, 1); 199 | 200 | /* offset of string raw data in chunk */ 201 | stringOffset = GetInt32(ap); 202 | 203 | /* offset of style w=raw data in chunk */ 204 | styleOffset = GetInt32(ap); 205 | 206 | /* strings' offsets table */ 207 | ap->st->offsets = (uint32_t *)malloc(ap->st->count * sizeof(uint32_t)); 208 | if(ap->st->offsets == NULL) 209 | { 210 | fprintf(stderr, "Error: init strings' offsets table.\n"); 211 | return -1; 212 | } 213 | 214 | for(i = 0; i < ap->st->count; i++) 215 | ap->st->offsets[i] = GetInt32(ap); 216 | 217 | /* init string table */ 218 | ap->st->strings = (unsigned char **)malloc(ap->st->count * sizeof(unsigned char *)); 219 | if(ap->st->strings == NULL) 220 | { 221 | fprintf(stderr, "Error: init string table.\n"); 222 | free(ap->st->offsets); 223 | ap->st->offsets = NULL; 224 | return -1; 225 | } 226 | for(i = 0; i < ap->st->count; i++) 227 | ap->st->strings[i] = NULL; 228 | 229 | /* skip style offset table */ 230 | if(styleCount != 0) 231 | SkipInt32(ap, styleCount); 232 | 233 | /* save string raw data */ 234 | ap->st->len = (styleOffset ? styleOffset : chunkSize) - stringOffset; 235 | ap->st->data = (unsigned char *)malloc(ap->st->len); 236 | if(ap->st->data == NULL) 237 | { 238 | fprintf(stderr, "Error: init string raw data.\n"); 239 | free(ap->st->strings); 240 | ap->st->strings = NULL; 241 | free(ap->st->offsets); 242 | ap->st->offsets = NULL; 243 | return -1; 244 | } 245 | 246 | CopyData(ap, ap->st->data, ap->st->len); 247 | 248 | /* skip style raw data */ 249 | if(styleOffset != 0) 250 | SkipInt32(ap, (chunkSize-styleOffset)/4); 251 | 252 | return 0; 253 | } 254 | 255 | static int 256 | ParseResourceChunk(Parser_t *ap) 257 | { 258 | uint32_t chunkSize; 259 | 260 | /* chunk type */ 261 | if(GetInt32(ap) != CHUNK_RESOURCE) 262 | { 263 | fprintf(stderr, "Error: not valid resource chunk.\n"); 264 | return -1; 265 | } 266 | 267 | /* chunk size */ 268 | chunkSize = GetInt32(ap); 269 | if(chunkSize % 4 != 0) 270 | { 271 | fprintf(stderr, "Error: not valid resource chunk.\n"); 272 | return -1; 273 | } 274 | 275 | /* skip res id table */ 276 | SkipInt32(ap, chunkSize/4-2); 277 | 278 | return 0; 279 | } 280 | 281 | void * 282 | AxmlOpen(char *buffer, size_t size) 283 | { 284 | Parser_t *ap; 285 | 286 | if(buffer == NULL) 287 | { 288 | fprintf(stderr, "Error: AxmlOpen get an invalid parameter.\n"); 289 | return NULL; 290 | } 291 | 292 | ap = (Parser_t *)malloc(sizeof(Parser_t)); 293 | if(ap == NULL) 294 | { 295 | fprintf(stderr, "Error: init parser.\n"); 296 | return NULL; 297 | } 298 | 299 | /* init parser */ 300 | ap->buf = (unsigned char *)buffer; 301 | ap->size = size; 302 | ap->cur = 0; 303 | 304 | ap->nsList = NULL; 305 | ap->nsNew = 0; 306 | 307 | ap->attr = NULL; 308 | 309 | ap->tagName = (uint32_t)(-1); 310 | ap->tagUri = (uint32_t)(-1); 311 | ap->text = (uint32_t)(-1); 312 | 313 | ap->st = (StringTable_t *)malloc(sizeof(StringTable_t)); 314 | if(ap->st == NULL) 315 | { 316 | fprintf(stderr, "Error: init string table struct.\n"); 317 | free(ap); 318 | return NULL; 319 | } 320 | 321 | /* parse first three chunks */ 322 | if( ParseHeadChunk(ap) != 0 || 323 | ParseStringChunk(ap) != 0 || 324 | ParseResourceChunk(ap) != 0 ) 325 | { 326 | free(ap->st); 327 | free(ap); 328 | return NULL; 329 | } 330 | 331 | return (void *)ap; 332 | } 333 | 334 | int 335 | AxmlClose(void *axml) 336 | { 337 | Parser_t *ap; 338 | uint32_t i; 339 | 340 | if(axml == NULL) 341 | { 342 | fprintf(stderr, "Error: AxmlClose get an invalid parameter.\n"); 343 | return -1; 344 | } 345 | 346 | ap = (Parser_t *)axml; 347 | 348 | if(ap->st->data) 349 | free(ap->st->data); 350 | 351 | if(ap->st->strings) 352 | { 353 | for(i = 0; i < ap->st->count; i++) 354 | if(ap->st->strings[i]) 355 | free(ap->st->strings[i]); 356 | free(ap->st->strings); 357 | } 358 | 359 | if(ap->st->offsets) 360 | free(ap->st->offsets); 361 | 362 | if(ap->st) 363 | free(ap->st); 364 | 365 | if(ap) 366 | free(ap); 367 | 368 | return 0; 369 | } 370 | 371 | AxmlEvent_t 372 | AxmlNext(void *axml) 373 | { 374 | static AxmlEvent_t event = -1; 375 | 376 | Parser_t *ap; 377 | uint32_t chunkType; 378 | 379 | /* when init */ 380 | if(event == -1) 381 | { 382 | event = AE_STARTDOC; 383 | return event; 384 | } 385 | 386 | ap = (Parser_t *)axml; 387 | 388 | /* when buffer ends */ 389 | if(NoMoreData(ap)) 390 | event = AE_ENDDOC; 391 | 392 | if(event == AE_ENDDOC) 393 | return event; 394 | 395 | /* common chunk head */ 396 | chunkType = GetInt32(ap); 397 | SkipInt32(ap, 1); /* chunk size, unused */ 398 | SkipInt32(ap, 1); /* line number, unused */ 399 | SkipInt32(ap, 1); /* unknown field */ 400 | 401 | if(chunkType == CHUNK_STARTTAG) 402 | { 403 | uint32_t i; 404 | AttrStack_t *attr; 405 | 406 | attr = (AttrStack_t *)malloc(sizeof(AttrStack_t)); 407 | if(attr == NULL) 408 | { 409 | fprintf(stderr, "Error: init attribute.\n"); 410 | return AE_ERROR; 411 | } 412 | 413 | ap->tagUri = GetInt32(ap); 414 | ap->tagName = GetInt32(ap); 415 | SkipInt32(ap, 1); /* flags, unknown usage */ 416 | 417 | attr->count = GetInt32(ap) & 0x0000ffff; 418 | SkipInt32(ap, 1); /* classAttribute, unknown usage */ 419 | 420 | attr->list = (Attribute_t *)malloc( 421 | attr->count * sizeof(Attribute_t)); 422 | if(attr->list == NULL) 423 | { 424 | fprintf(stderr, "Error: init attribute list.\n"); 425 | free(attr); 426 | return AE_ERROR; 427 | } 428 | 429 | /* attribute list */ 430 | for(i = 0; i < attr->count; i++) 431 | { 432 | attr->list[i].uri = GetInt32(ap); 433 | attr->list[i].name = GetInt32(ap); 434 | attr->list[i].string = GetInt32(ap); 435 | /* note: type must >> 24 */ 436 | attr->list[i].type = GetInt32(ap) >> 24; 437 | attr->list[i].data = GetInt32(ap); 438 | } 439 | 440 | attr->next = ap->attr; 441 | ap->attr = attr; 442 | 443 | event = AE_STARTTAG; 444 | } 445 | else if(chunkType == CHUNK_ENDTAG) 446 | { 447 | AttrStack_t *attr; 448 | 449 | ap->tagUri = GetInt32(ap); 450 | ap->tagName = GetInt32(ap); 451 | 452 | if(ap->attr != NULL) 453 | { 454 | attr = ap->attr; 455 | ap->attr = ap->attr->next; 456 | 457 | free(attr->list); 458 | free(attr); 459 | } 460 | 461 | event = AE_ENDTAG; 462 | } 463 | else if(chunkType == CHUNK_STARTNS) 464 | { 465 | NsRecord_t *ns = (NsRecord_t *)malloc(sizeof(NsRecord_t)); 466 | if(ns == NULL) 467 | { 468 | fprintf(stderr, "Error: init namespace.\n"); 469 | return AE_ERROR; 470 | } 471 | 472 | ns->prefix = GetInt32(ap); 473 | ns->uri = GetInt32(ap); 474 | 475 | ns->next = ap->nsList; 476 | ap->nsList = ns; 477 | /* get a new namespace */ 478 | ap->nsNew = 1; 479 | 480 | /* note this recursion rather than return a event*/ 481 | return AxmlNext(ap); 482 | } 483 | else if(chunkType == CHUNK_ENDNS) 484 | { 485 | NsRecord_t *ns = ap->nsList; 486 | if(ns == NULL) 487 | { 488 | fprintf(stderr, "Error: end a namespace.\n"); 489 | return AE_ERROR; 490 | } 491 | 492 | SkipInt32(ap, 1); /* ended prefix */ 493 | SkipInt32(ap, 1); /* ended uri */ 494 | 495 | ap->nsList = ns->next; 496 | free(ns); 497 | 498 | /* note this recursion rather than return a event*/ 499 | return AxmlNext(ap); 500 | } 501 | else if(chunkType == CHUNK_TEXT) 502 | { 503 | ap->text = GetInt32(ap); 504 | SkipInt32(ap, 2); /* unknown fields */ 505 | event = AE_TEXT; 506 | } 507 | else 508 | { 509 | event = AE_ERROR; 510 | } 511 | 512 | return event; 513 | } 514 | 515 | /** \brief Convert UTF-16LE string into UTF-8 string 516 | * 517 | * You must call this function with to=NULL firstly to get UTF-8 size; 518 | * then you should alloc enough memory to the string; 519 | * at last call this function again to convert actually. 520 | * \param to Pointer to target UTF-8 string 521 | * \param from Pointer to source UTF-16LE string 522 | * \param nch Count of UTF-16LE characters, including terminal zero 523 | * \retval -1 Converting error. 524 | * \retval positive Bytes of UTF-8 string, including terminal zero. 525 | */ 526 | static size_t 527 | UTF16LEtoUTF8(unsigned char *to, unsigned char *from, size_t nch) 528 | { 529 | size_t total = 0; 530 | while(nch > 0) 531 | { 532 | uint32_t ucs4; 533 | size_t count; 534 | 535 | /* utf-16le -> ucs-4, defined in RFC 2781 */ 536 | ucs4 = from[0] + (from[1]<<8); 537 | from += 2; 538 | nch--; 539 | if(ucs4 < 0xd800 || ucs4 > 0xdfff) 540 | { 541 | ; 542 | } 543 | else if(ucs4 >= 0xd800 && ucs4 <= 0xdbff) 544 | { 545 | unsigned int ext; 546 | if(nch <= 0) 547 | return -1; 548 | ext = from[0] + (from[1]<<8); 549 | from += 2; 550 | nch--; 551 | if(ext < 0xdc00 || ext >0xdfff) 552 | return -1; 553 | ucs4 = ((ucs4 & 0x3ff)<<10) + (ext & 0x3ff) + 0x10000; 554 | } 555 | else 556 | { 557 | return -1; 558 | } 559 | 560 | /* ucs-4 -> utf-8, defined in RFC 2279 */ 561 | if(ucs4 < 0x80) count = 1; 562 | else if(ucs4 < 0x800) count = 2; 563 | else if(ucs4 < 0x10000) count = 3; 564 | else if(ucs4 < 0x200000) count = 4; 565 | else if(ucs4 < 0x4000000) count = 5; 566 | else if(ucs4 < 0x80000000) count = 6; 567 | else return 0; 568 | 569 | total += count; 570 | if(to == NULL) 571 | continue; 572 | 573 | switch(count) 574 | { 575 | case 6: to[5] = 0x80 | (ucs4 & 0x3f); ucs4 >>= 6; ucs4 |= 0x4000000; 576 | case 5: to[4] = 0x80 | (ucs4 & 0x3f); ucs4 >>= 6; ucs4 |= 0x200000; 577 | case 4: to[3] = 0x80 | (ucs4 & 0x3f); ucs4 >>= 6; ucs4 |= 0x10000; 578 | case 3: to[2] = 0x80 | (ucs4 & 0x3f); ucs4 >>= 6; ucs4 |= 0x800; 579 | case 2: to[1] = 0x80 | (ucs4 & 0x3f); ucs4 >>= 6; ucs4 |= 0xc0; 580 | case 1: to[0] = ucs4; break; 581 | } 582 | to += count; 583 | } 584 | if(to != NULL) 585 | to[0] = '\0'; 586 | return total+1; 587 | } 588 | 589 | static char * 590 | GetString(Parser_t *ap, uint32_t id) 591 | { 592 | static char *emptyString = ""; 593 | 594 | unsigned char *offset; 595 | uint16_t chNum; 596 | size_t size; 597 | 598 | /* out of index range */ 599 | if(id >= ap->st->count) 600 | return emptyString; 601 | 602 | /* already parsed, directly use previous result */ 603 | if(ap->st->strings[id] != NULL) 604 | return (char *)(ap->st->strings[id]); 605 | 606 | /* point to string's raw data */ 607 | offset = ap->st->data + ap->st->offsets[id]; 608 | 609 | /* its first 2 bytes is string's characters count */ 610 | chNum = *(uint16_t *)offset; 611 | 612 | size = UTF16LEtoUTF8(NULL, offset+2, (size_t)chNum); 613 | if(size == (size_t)-1) 614 | return emptyString; 615 | ap->st->strings[id] = (unsigned char *)malloc(size); 616 | if(ap->st->strings[id] == NULL) 617 | return emptyString; 618 | 619 | UTF16LEtoUTF8(ap->st->strings[id], offset+2, (size_t)chNum); 620 | 621 | return (char *)(ap->st->strings[id]); 622 | } 623 | 624 | char * 625 | AxmlGetTagName(void *axml) 626 | { 627 | Parser_t *ap; 628 | ap = (Parser_t *)axml; 629 | return GetString(ap, ap->tagName); 630 | } 631 | 632 | char * 633 | AxmlGetTagPrefix(void *axml) 634 | { 635 | Parser_t *ap; 636 | NsRecord_t *ns; 637 | uint32_t nodePrefix = 0xffffffff; 638 | 639 | ap = (Parser_t *)axml; 640 | 641 | for(ns = ap->nsList; ns != NULL; ns = ns->next) 642 | { 643 | if(ns->uri == ap->tagUri) 644 | nodePrefix = ns->prefix; 645 | } 646 | 647 | /* mention that when index out of range, GetString() returns empty string */ 648 | return GetString(ap, nodePrefix); 649 | } 650 | 651 | char * 652 | AxmlGetText(void *axml) 653 | { 654 | Parser_t *ap; 655 | ap = (Parser_t *)axml; 656 | return GetString(ap, ap->text); 657 | } 658 | 659 | uint32_t 660 | AxmlGetAttrCount(void *axml) 661 | { 662 | Parser_t *ap; 663 | ap = (Parser_t *)axml; 664 | return ap->attr->count; 665 | } 666 | 667 | char * 668 | AxmlGetAttrPrefix(void *axml, uint32_t i) 669 | { 670 | Parser_t *ap; 671 | NsRecord_t *ns; 672 | uint32_t prefix = 0xffffffff; 673 | uint32_t uri; 674 | 675 | ap = (Parser_t *)axml; 676 | uri = ap->attr->list[i].uri; 677 | 678 | for(ns = ap->nsList; ns != NULL; ns = ns->next) 679 | { 680 | if(ns->uri == uri) 681 | prefix = ns->prefix; 682 | } 683 | 684 | return GetString(ap, prefix); 685 | } 686 | 687 | char * 688 | AxmlGetAttrName(void *axml, uint32_t i) 689 | { 690 | Parser_t *ap; 691 | ap = (Parser_t *)axml; 692 | return GetString(ap, ap->attr->list[i].name); 693 | } 694 | 695 | char * 696 | AxmlGetAttrValue(void *axml, uint32_t i) 697 | { 698 | static float RadixTable[] = {0.00390625f, 3.051758E-005f, 1.192093E-007f, 4.656613E-010f}; 699 | static char *DimemsionTable[] = {"px", "dip", "sp", "pt", "in", "mm", "", ""}; 700 | static char *FractionTable[] = {"%", "%p", "", "", "", "", "", ""}; 701 | 702 | Parser_t *ap; 703 | uint32_t type; 704 | uint32_t data; 705 | char *buf; 706 | 707 | ap = (Parser_t *)axml; 708 | type = ap->attr->list[i].type; 709 | 710 | if(type == ATTR_STRING) 711 | { 712 | char *str; 713 | str = GetString(ap, ap->attr->list[i].string); 714 | 715 | /* free by user */ 716 | buf = (char *)malloc(strlen(str)+1); 717 | 718 | memset(buf, 0, strlen(str)+1); 719 | strncpy(buf, str, strlen(str)); 720 | 721 | return buf; 722 | } 723 | 724 | data = ap->attr->list[i].data; 725 | 726 | /* free by user */ 727 | buf = (char *)malloc(32); 728 | memset(buf, 0 ,32); 729 | 730 | if(type == ATTR_NULL) 731 | { 732 | ; 733 | } 734 | else if(type == ATTR_REFERENCE) 735 | { 736 | if(data>>24 == 1) 737 | snprintf(buf, 18, "@android:%08X", data); 738 | else 739 | snprintf(buf, 10, "@%08X", data); 740 | } 741 | else if(type == ATTR_ATTRIBUTE) 742 | { 743 | if(data>>24 == 1) 744 | snprintf(buf, 18, "?android:%08x", data); 745 | else 746 | snprintf(buf, 10, "?%08X", data); 747 | } 748 | else if(type == ATTR_FLOAT) 749 | { 750 | snprintf(buf, 20, "%g", *(float *)&data); 751 | } 752 | else if(type == ATTR_DIMENSION) 753 | { 754 | snprintf(buf, 20, "%f%s", 755 | (float)(data & 0xffffff00) * RadixTable[(data >> 4) & 0x03], 756 | DimemsionTable[data & 0x0f] ); 757 | } 758 | else if(type == ATTR_FRACTION) 759 | { 760 | snprintf(buf, 20, "%f%s", 761 | (float)(data & 0xffffff00) * RadixTable[(data >> 4) & 0x03], 762 | FractionTable[data & 0x0f] ); 763 | } 764 | else if(type == ATTR_HEX) 765 | { 766 | snprintf(buf, 11, "0x%08x", data); 767 | } 768 | else if(type == ATTR_BOOLEAN) 769 | { 770 | if(data == 0) 771 | strncpy(buf, "false", 32); 772 | else 773 | strncpy(buf, "true", 32); 774 | } 775 | else if(type >= ATTR_FIRSTCOLOR && type <= ATTR_LASTCOLOR) 776 | { 777 | snprintf(buf, 10, "#%08x", data); 778 | } 779 | else if(type >= ATTR_FIRSTINT && type <= ATTR_LASTINT) 780 | { 781 | snprintf(buf, 32, "%d", data); 782 | } 783 | else 784 | { 785 | snprintf(buf, 32, "<0x%x, type 0x%02x>", data, type); 786 | } 787 | 788 | return buf; 789 | } 790 | 791 | int 792 | AxmlNewNamespace(void *axml) 793 | { 794 | Parser_t *ap; 795 | ap = (Parser_t *)axml; 796 | if(ap->nsNew == 0) 797 | return 0; 798 | else 799 | { 800 | ap->nsNew = 0; 801 | return 1; 802 | } 803 | } 804 | 805 | char * 806 | AxmlGetNsPrefix(void *axml) 807 | { 808 | Parser_t *ap; 809 | ap = (Parser_t *)axml; 810 | return GetString(ap, ap->nsList->prefix); 811 | } 812 | 813 | char * 814 | AxmlGetNsUri(void *axml) 815 | { 816 | Parser_t *ap; 817 | ap = (Parser_t *)axml; 818 | return GetString(ap, ap->nsList->uri); 819 | } 820 | 821 | typedef struct{ 822 | char *data; 823 | size_t size; 824 | size_t cur; 825 | } Buff_t; 826 | 827 | static int 828 | InitBuff(Buff_t *buf) 829 | { 830 | if(buf == NULL) 831 | return -1; 832 | buf->size = 32*1024; 833 | buf->data = (char *)malloc(buf->size); 834 | if(buf->data == NULL) 835 | { 836 | fprintf(stderr, "Error: init buffer.\n"); 837 | return -1; 838 | } 839 | buf->cur = 0; 840 | return 0; 841 | } 842 | 843 | static int 844 | PrintToBuff(Buff_t *buf, size_t maxlen, const char *format, ...) 845 | { 846 | va_list ap; 847 | size_t len; 848 | 849 | if(maxlen >= buf->size - buf->cur) 850 | { 851 | buf->size += 32*1024; 852 | buf->data = (char *)realloc(buf->data, buf->size); 853 | if(buf->data == NULL) 854 | { 855 | fprintf(stderr, "Error: realloc buffer.\n"); 856 | return -1; 857 | } 858 | } 859 | 860 | va_start(ap, format); 861 | vsnprintf(buf->data + buf->cur, buf->size - buf->cur, format, ap); 862 | va_end(ap); 863 | 864 | len = strlen(buf->data + buf->cur); 865 | if(len > maxlen) 866 | { 867 | fprintf(stderr, "Error: length more than expected.\n"); 868 | return -1; 869 | } 870 | buf->cur += len; 871 | return 0; 872 | } 873 | 874 | int 875 | AxmlToXml(char **outbuf, size_t *outsize, char *inbuf, size_t insize) 876 | { 877 | void *axml; 878 | AxmlEvent_t event; 879 | Buff_t buf; 880 | 881 | int tabCnt = 0; 882 | 883 | if(InitBuff(&buf) != 0) 884 | return -1; 885 | 886 | axml = AxmlOpen(inbuf, insize); 887 | if(axml == NULL) 888 | return -1; 889 | 890 | while((event = AxmlNext(axml)) != AE_ENDDOC) 891 | { 892 | char *prefix; 893 | char *name; 894 | char *value; 895 | uint32_t i, n; 896 | 897 | switch(event){ 898 | case AE_STARTDOC: 899 | PrintToBuff(&buf, 50, "\n"); 900 | break; 901 | 902 | case AE_STARTTAG: 903 | PrintToBuff(&buf, tabCnt*4+1, "%*s", tabCnt*4, ""); 904 | tabCnt++; 905 | 906 | prefix = AxmlGetTagPrefix(axml); 907 | name = AxmlGetTagName(axml); 908 | if(strlen(prefix) != 0) 909 | PrintToBuff(&buf, strlen(prefix)+strlen(name)+5, "<%s:%s ", prefix, name); 910 | else 911 | PrintToBuff(&buf, strlen(name)+3, "<%s ", name); 912 | 913 | if(AxmlNewNamespace(axml)) 914 | { 915 | prefix = AxmlGetNsPrefix(axml); 916 | name = AxmlGetNsUri(axml); 917 | PrintToBuff(&buf, strlen(prefix)+strlen(name)+12, "xmlns:%s=\"%s\" ", prefix, name); 918 | } 919 | 920 | n = AxmlGetAttrCount(axml); 921 | for(i = 0; i < n; i++) 922 | { 923 | prefix = AxmlGetAttrPrefix(axml, i); 924 | name = AxmlGetAttrName(axml, i); 925 | value = AxmlGetAttrValue(axml, i); 926 | 927 | if(strlen(prefix) != 0) 928 | PrintToBuff(&buf, strlen(prefix)+strlen(name)+strlen(value)+8, 929 | "%s:%s=\"%s\" ", prefix, name, value); 930 | else 931 | PrintToBuff(&buf, strlen(name)+strlen(value)+6, "%s=\"%s\" ", name, value); 932 | 933 | /* must manually free attribute value here */ 934 | free(value); 935 | } 936 | 937 | PrintToBuff(&buf, 3, ">\n"); 938 | break; 939 | 940 | case AE_ENDTAG: 941 | --tabCnt; 942 | PrintToBuff(&buf, tabCnt*4+1, "%*s", tabCnt*4, ""); 943 | 944 | prefix = AxmlGetTagPrefix(axml); 945 | name = AxmlGetTagName(axml); 946 | if(strlen(prefix) != 0) 947 | PrintToBuff(&buf, strlen(prefix)+strlen(name)+7, "\n", prefix, name); 948 | else 949 | PrintToBuff(&buf, strlen(name)+5, "\n", name); 950 | break; 951 | 952 | case AE_TEXT: 953 | name = AxmlGetText(axml); 954 | PrintToBuff(&buf, strlen(name)+2, "%s\n", name); 955 | break; 956 | 957 | case AE_ERROR: 958 | fprintf(stderr, "Error: AxmlNext() returns a AE_ERROR event.\n"); 959 | AxmlClose(axml); 960 | return -1; 961 | break; 962 | 963 | default: 964 | break; 965 | } 966 | } 967 | 968 | AxmlClose(axml); 969 | 970 | (*outbuf) = buf.data; 971 | (*outsize) = buf.cur; 972 | 973 | return 0; 974 | } 975 | -------------------------------------------------------------------------------- /ApkProtection/src/utils/AxmlParser.h: -------------------------------------------------------------------------------- 1 | /* AXML Parser 2 | * https://github.com/claudxiao/AndTools 3 | * Claud Xiao 4 | */ 5 | #ifndef AXMLPARSER_H 6 | #define AXMLPARSER_H 7 | 8 | #include 9 | 10 | typedef enum{ 11 | AE_STARTDOC = 0, 12 | AE_ENDDOC, 13 | AE_STARTTAG, 14 | AE_ENDTAG, 15 | AE_TEXT, 16 | AE_ERROR, 17 | } AxmlEvent_t; 18 | 19 | #ifdef __cplusplus 20 | #if __cplusplus 21 | extern "C" { 22 | #endif 23 | #endif 24 | 25 | void *AxmlOpen(char *buffer, size_t size); 26 | 27 | AxmlEvent_t AxmlNext(void *axml); 28 | 29 | char *AxmlGetTagPrefix(void *axml); 30 | char *AxmlGetTagName(void *axml); 31 | 32 | int AxmlNewNamespace(void *axml); 33 | char *AxmlGetNsPrefix(void *axml); 34 | char *AxmlGetNsUri(void *axml); 35 | 36 | uint32_t AxmlGetAttrCount(void *axml); 37 | char *AxmlGetAttrPrefix(void *axml, uint32_t i); 38 | char *AxmlGetAttrName(void *axml, uint32_t i); 39 | char *AxmlGetAttrValue(void *axml, uint32_t i); 40 | 41 | char *AxmlGetText(void *axml); 42 | 43 | int AxmlClose(void *axml); 44 | 45 | int AxmlToXml(char **outbuf, size_t *outsize, char *inbuf, size_t insize); 46 | 47 | #ifdef __cplusplus 48 | #if __cplusplus 49 | }; 50 | #endif 51 | #endif 52 | 53 | #endif 54 | -------------------------------------------------------------------------------- /ApkProtection/src/zlib/ioapi.c: -------------------------------------------------------------------------------- 1 | /* ioapi.h -- IO base function header for compress/uncompress .zip 2 | part of the MiniZip project - ( http://www.winimage.com/zLibDll/minizip.html ) 3 | 4 | Copyright (C) 1998-2010 Gilles Vollant (minizip) ( http://www.winimage.com/zLibDll/minizip.html ) 5 | 6 | Modifications for Zip64 support 7 | Copyright (C) 2009-2010 Mathias Svensson ( http://result42.com ) 8 | 9 | For more info read MiniZip_info.txt 10 | 11 | */ 12 | 13 | #if defined(_WIN32) && (!(defined(_CRT_SECURE_NO_WARNINGS))) 14 | #define _CRT_SECURE_NO_WARNINGS 15 | #endif 16 | 17 | #if defined(__APPLE__) || defined(IOAPI_NO_64) 18 | // In darwin and perhaps other BSD variants off_t is a 64 bit value, hence no need for specific 64 bit functions 19 | #define FOPEN_FUNC(filename, mode) fopen(filename, mode) 20 | #define FTELLO_FUNC(stream) ftello(stream) 21 | #define FSEEKO_FUNC(stream, offset, origin) fseeko(stream, offset, origin) 22 | #else 23 | #define FOPEN_FUNC(filename, mode) fopen64(filename, mode) 24 | #define FTELLO_FUNC(stream) ftello64(stream) 25 | #define FSEEKO_FUNC(stream, offset, origin) fseeko64(stream, offset, origin) 26 | #endif 27 | 28 | 29 | #include "ioapi.h" 30 | 31 | voidpf call_zopen64 (const zlib_filefunc64_32_def* pfilefunc,const void*filename,int mode) 32 | { 33 | if (pfilefunc->zfile_func64.zopen64_file != NULL) 34 | return (*(pfilefunc->zfile_func64.zopen64_file)) (pfilefunc->zfile_func64.opaque,filename,mode); 35 | else 36 | { 37 | return (*(pfilefunc->zopen32_file))(pfilefunc->zfile_func64.opaque,(const char*)filename,mode); 38 | } 39 | } 40 | 41 | long call_zseek64 (const zlib_filefunc64_32_def* pfilefunc,voidpf filestream, ZPOS64_T offset, int origin) 42 | { 43 | if (pfilefunc->zfile_func64.zseek64_file != NULL) 44 | return (*(pfilefunc->zfile_func64.zseek64_file)) (pfilefunc->zfile_func64.opaque,filestream,offset,origin); 45 | else 46 | { 47 | uLong offsetTruncated = (uLong)offset; 48 | if (offsetTruncated != offset) 49 | return -1; 50 | else 51 | return (*(pfilefunc->zseek32_file))(pfilefunc->zfile_func64.opaque,filestream,offsetTruncated,origin); 52 | } 53 | } 54 | 55 | ZPOS64_T call_ztell64 (const zlib_filefunc64_32_def* pfilefunc,voidpf filestream) 56 | { 57 | if (pfilefunc->zfile_func64.zseek64_file != NULL) 58 | return (*(pfilefunc->zfile_func64.ztell64_file)) (pfilefunc->zfile_func64.opaque,filestream); 59 | else 60 | { 61 | uLong tell_uLong = (*(pfilefunc->ztell32_file))(pfilefunc->zfile_func64.opaque,filestream); 62 | if ((tell_uLong) == MAXU32) 63 | return (ZPOS64_T)-1; 64 | else 65 | return tell_uLong; 66 | } 67 | } 68 | 69 | void fill_zlib_filefunc64_32_def_from_filefunc32(zlib_filefunc64_32_def* p_filefunc64_32,const zlib_filefunc_def* p_filefunc32) 70 | { 71 | p_filefunc64_32->zfile_func64.zopen64_file = NULL; 72 | p_filefunc64_32->zopen32_file = p_filefunc32->zopen_file; 73 | p_filefunc64_32->zfile_func64.zerror_file = p_filefunc32->zerror_file; 74 | p_filefunc64_32->zfile_func64.zread_file = p_filefunc32->zread_file; 75 | p_filefunc64_32->zfile_func64.zwrite_file = p_filefunc32->zwrite_file; 76 | p_filefunc64_32->zfile_func64.ztell64_file = NULL; 77 | p_filefunc64_32->zfile_func64.zseek64_file = NULL; 78 | p_filefunc64_32->zfile_func64.zclose_file = p_filefunc32->zclose_file; 79 | p_filefunc64_32->zfile_func64.zerror_file = p_filefunc32->zerror_file; 80 | p_filefunc64_32->zfile_func64.opaque = p_filefunc32->opaque; 81 | p_filefunc64_32->zseek32_file = p_filefunc32->zseek_file; 82 | p_filefunc64_32->ztell32_file = p_filefunc32->ztell_file; 83 | } 84 | 85 | 86 | 87 | static voidpf ZCALLBACK fopen_file_func OF((voidpf opaque, const char* filename, int mode)); 88 | static uLong ZCALLBACK fread_file_func OF((voidpf opaque, voidpf stream, void* buf, uLong size)); 89 | static uLong ZCALLBACK fwrite_file_func OF((voidpf opaque, voidpf stream, const void* buf,uLong size)); 90 | static ZPOS64_T ZCALLBACK ftell64_file_func OF((voidpf opaque, voidpf stream)); 91 | static long ZCALLBACK fseek64_file_func OF((voidpf opaque, voidpf stream, ZPOS64_T offset, int origin)); 92 | static int ZCALLBACK fclose_file_func OF((voidpf opaque, voidpf stream)); 93 | static int ZCALLBACK ferror_file_func OF((voidpf opaque, voidpf stream)); 94 | 95 | static voidpf ZCALLBACK fopen_file_func (voidpf opaque, const char* filename, int mode) 96 | { 97 | FILE* file = NULL; 98 | const char* mode_fopen = NULL; 99 | if ((mode & ZLIB_FILEFUNC_MODE_READWRITEFILTER)==ZLIB_FILEFUNC_MODE_READ) 100 | mode_fopen = "rb"; 101 | else 102 | if (mode & ZLIB_FILEFUNC_MODE_EXISTING) 103 | mode_fopen = "r+b"; 104 | else 105 | if (mode & ZLIB_FILEFUNC_MODE_CREATE) 106 | mode_fopen = "wb"; 107 | 108 | if ((filename!=NULL) && (mode_fopen != NULL)) 109 | file = fopen(filename, mode_fopen); 110 | return file; 111 | } 112 | 113 | static voidpf ZCALLBACK fopen64_file_func (voidpf opaque, const void* filename, int mode) 114 | { 115 | FILE* file = NULL; 116 | const char* mode_fopen = NULL; 117 | if ((mode & ZLIB_FILEFUNC_MODE_READWRITEFILTER)==ZLIB_FILEFUNC_MODE_READ) 118 | mode_fopen = "rb"; 119 | else 120 | if (mode & ZLIB_FILEFUNC_MODE_EXISTING) 121 | mode_fopen = "r+b"; 122 | else 123 | if (mode & ZLIB_FILEFUNC_MODE_CREATE) 124 | mode_fopen = "wb"; 125 | 126 | if ((filename!=NULL) && (mode_fopen != NULL)) 127 | file = FOPEN_FUNC((const char*)filename, mode_fopen); 128 | return file; 129 | } 130 | 131 | 132 | static uLong ZCALLBACK fread_file_func (voidpf opaque, voidpf stream, void* buf, uLong size) 133 | { 134 | uLong ret; 135 | ret = (uLong)fread(buf, 1, (size_t)size, (FILE *)stream); 136 | return ret; 137 | } 138 | 139 | static uLong ZCALLBACK fwrite_file_func (voidpf opaque, voidpf stream, const void* buf, uLong size) 140 | { 141 | uLong ret; 142 | ret = (uLong)fwrite(buf, 1, (size_t)size, (FILE *)stream); 143 | return ret; 144 | } 145 | 146 | static long ZCALLBACK ftell_file_func (voidpf opaque, voidpf stream) 147 | { 148 | long ret; 149 | ret = ftell((FILE *)stream); 150 | return ret; 151 | } 152 | 153 | 154 | static ZPOS64_T ZCALLBACK ftell64_file_func (voidpf opaque, voidpf stream) 155 | { 156 | ZPOS64_T ret; 157 | ret = FTELLO_FUNC((FILE *)stream); 158 | return ret; 159 | } 160 | 161 | static long ZCALLBACK fseek_file_func (voidpf opaque, voidpf stream, uLong offset, int origin) 162 | { 163 | int fseek_origin=0; 164 | long ret; 165 | switch (origin) 166 | { 167 | case ZLIB_FILEFUNC_SEEK_CUR : 168 | fseek_origin = SEEK_CUR; 169 | break; 170 | case ZLIB_FILEFUNC_SEEK_END : 171 | fseek_origin = SEEK_END; 172 | break; 173 | case ZLIB_FILEFUNC_SEEK_SET : 174 | fseek_origin = SEEK_SET; 175 | break; 176 | default: return -1; 177 | } 178 | ret = 0; 179 | if (fseek((FILE *)stream, offset, fseek_origin) != 0) 180 | ret = -1; 181 | return ret; 182 | } 183 | 184 | static long ZCALLBACK fseek64_file_func (voidpf opaque, voidpf stream, ZPOS64_T offset, int origin) 185 | { 186 | int fseek_origin=0; 187 | long ret; 188 | switch (origin) 189 | { 190 | case ZLIB_FILEFUNC_SEEK_CUR : 191 | fseek_origin = SEEK_CUR; 192 | break; 193 | case ZLIB_FILEFUNC_SEEK_END : 194 | fseek_origin = SEEK_END; 195 | break; 196 | case ZLIB_FILEFUNC_SEEK_SET : 197 | fseek_origin = SEEK_SET; 198 | break; 199 | default: return -1; 200 | } 201 | ret = 0; 202 | 203 | if(FSEEKO_FUNC((FILE *)stream, offset, fseek_origin) != 0) 204 | ret = -1; 205 | 206 | return ret; 207 | } 208 | 209 | 210 | static int ZCALLBACK fclose_file_func (voidpf opaque, voidpf stream) 211 | { 212 | int ret; 213 | ret = fclose((FILE *)stream); 214 | return ret; 215 | } 216 | 217 | static int ZCALLBACK ferror_file_func (voidpf opaque, voidpf stream) 218 | { 219 | int ret; 220 | ret = ferror((FILE *)stream); 221 | return ret; 222 | } 223 | 224 | void fill_fopen_filefunc (pzlib_filefunc_def) 225 | zlib_filefunc_def* pzlib_filefunc_def; 226 | { 227 | pzlib_filefunc_def->zopen_file = fopen_file_func; 228 | pzlib_filefunc_def->zread_file = fread_file_func; 229 | pzlib_filefunc_def->zwrite_file = fwrite_file_func; 230 | pzlib_filefunc_def->ztell_file = ftell_file_func; 231 | pzlib_filefunc_def->zseek_file = fseek_file_func; 232 | pzlib_filefunc_def->zclose_file = fclose_file_func; 233 | pzlib_filefunc_def->zerror_file = ferror_file_func; 234 | pzlib_filefunc_def->opaque = NULL; 235 | } 236 | 237 | void fill_fopen64_filefunc (zlib_filefunc64_def* pzlib_filefunc_def) 238 | { 239 | pzlib_filefunc_def->zopen64_file = fopen64_file_func; 240 | pzlib_filefunc_def->zread_file = fread_file_func; 241 | pzlib_filefunc_def->zwrite_file = fwrite_file_func; 242 | pzlib_filefunc_def->ztell64_file = ftell64_file_func; 243 | pzlib_filefunc_def->zseek64_file = fseek64_file_func; 244 | pzlib_filefunc_def->zclose_file = fclose_file_func; 245 | pzlib_filefunc_def->zerror_file = ferror_file_func; 246 | pzlib_filefunc_def->opaque = NULL; 247 | } 248 | -------------------------------------------------------------------------------- /ApkProtection/src/zlib/ioapi.h: -------------------------------------------------------------------------------- 1 | /* ioapi.h -- IO base function header for compress/uncompress .zip 2 | part of the MiniZip project - ( http://www.winimage.com/zLibDll/minizip.html ) 3 | 4 | Copyright (C) 1998-2010 Gilles Vollant (minizip) ( http://www.winimage.com/zLibDll/minizip.html ) 5 | 6 | Modifications for Zip64 support 7 | Copyright (C) 2009-2010 Mathias Svensson ( http://result42.com ) 8 | 9 | For more info read MiniZip_info.txt 10 | 11 | Changes 12 | 13 | Oct-2009 - Defined ZPOS64_T to fpos_t on windows and u_int64_t on linux. (might need to find a better why for this) 14 | Oct-2009 - Change to fseeko64, ftello64 and fopen64 so large files would work on linux. 15 | More if/def section may be needed to support other platforms 16 | Oct-2009 - Defined fxxxx64 calls to normal fopen/ftell/fseek so they would compile on windows. 17 | (but you should use iowin32.c for windows instead) 18 | 19 | */ 20 | 21 | #ifndef _ZLIBIOAPI64_H 22 | #define _ZLIBIOAPI64_H 23 | 24 | #if (!defined(_WIN32)) && (!defined(WIN32)) && (!defined(__APPLE__)) 25 | 26 | // Linux needs this to support file operation on files larger then 4+GB 27 | // But might need better if/def to select just the platforms that needs them. 28 | 29 | #ifndef __USE_FILE_OFFSET64 30 | #define __USE_FILE_OFFSET64 31 | #endif 32 | #ifndef __USE_LARGEFILE64 33 | #define __USE_LARGEFILE64 34 | #endif 35 | #ifndef _LARGEFILE64_SOURCE 36 | #define _LARGEFILE64_SOURCE 37 | #endif 38 | #ifndef _FILE_OFFSET_BIT 39 | #define _FILE_OFFSET_BIT 64 40 | #endif 41 | 42 | #endif 43 | 44 | #include 45 | #include 46 | #include "zlib.h" 47 | 48 | #if defined(USE_FILE32API) 49 | #define fopen64 fopen 50 | #define ftello64 ftell 51 | #define fseeko64 fseek 52 | #else 53 | #ifdef __FreeBSD__ 54 | #define fopen64 fopen 55 | #define ftello64 ftello 56 | #define fseeko64 fseeko 57 | #endif 58 | #ifdef _MSC_VER 59 | #define fopen64 fopen 60 | #if (_MSC_VER >= 1400) && (!(defined(NO_MSCVER_FILE64_FUNC))) 61 | #define ftello64 _ftelli64 62 | #define fseeko64 _fseeki64 63 | #else // old MSC 64 | #define ftello64 ftell 65 | #define fseeko64 fseek 66 | #endif 67 | #endif 68 | #endif 69 | 70 | /* 71 | #ifndef ZPOS64_T 72 | #ifdef _WIN32 73 | #define ZPOS64_T fpos_t 74 | #else 75 | #include 76 | #define ZPOS64_T uint64_t 77 | #endif 78 | #endif 79 | */ 80 | 81 | #ifdef HAVE_MINIZIP64_CONF_H 82 | #include "mz64conf.h" 83 | #endif 84 | 85 | /* a type choosen by DEFINE */ 86 | #ifdef HAVE_64BIT_INT_CUSTOM 87 | typedef 64BIT_INT_CUSTOM_TYPE ZPOS64_T; 88 | #else 89 | #ifdef HAS_STDINT_H 90 | #include "stdint.h" 91 | typedef uint64_t ZPOS64_T; 92 | #else 93 | 94 | /* Maximum unsigned 32-bit value used as placeholder for zip64 */ 95 | #define MAXU32 0xffffffff 96 | 97 | #if defined(_MSC_VER) || defined(__BORLANDC__) 98 | typedef unsigned __int64 ZPOS64_T; 99 | #else 100 | typedef unsigned long long int ZPOS64_T; 101 | #endif 102 | #endif 103 | #endif 104 | 105 | 106 | 107 | #ifdef __cplusplus 108 | extern "C" { 109 | #endif 110 | 111 | 112 | #define ZLIB_FILEFUNC_SEEK_CUR (1) 113 | #define ZLIB_FILEFUNC_SEEK_END (2) 114 | #define ZLIB_FILEFUNC_SEEK_SET (0) 115 | 116 | #define ZLIB_FILEFUNC_MODE_READ (1) 117 | #define ZLIB_FILEFUNC_MODE_WRITE (2) 118 | #define ZLIB_FILEFUNC_MODE_READWRITEFILTER (3) 119 | 120 | #define ZLIB_FILEFUNC_MODE_EXISTING (4) 121 | #define ZLIB_FILEFUNC_MODE_CREATE (8) 122 | 123 | 124 | #ifndef ZCALLBACK 125 | #if (defined(WIN32) || defined(_WIN32) || defined (WINDOWS) || defined (_WINDOWS)) && defined(CALLBACK) && defined (USEWINDOWS_CALLBACK) 126 | #define ZCALLBACK CALLBACK 127 | #else 128 | #define ZCALLBACK 129 | #endif 130 | #endif 131 | 132 | 133 | 134 | 135 | typedef voidpf (ZCALLBACK *open_file_func) OF((voidpf opaque, const char* filename, int mode)); 136 | typedef uLong (ZCALLBACK *read_file_func) OF((voidpf opaque, voidpf stream, void* buf, uLong size)); 137 | typedef uLong (ZCALLBACK *write_file_func) OF((voidpf opaque, voidpf stream, const void* buf, uLong size)); 138 | typedef int (ZCALLBACK *close_file_func) OF((voidpf opaque, voidpf stream)); 139 | typedef int (ZCALLBACK *testerror_file_func) OF((voidpf opaque, voidpf stream)); 140 | 141 | typedef long (ZCALLBACK *tell_file_func) OF((voidpf opaque, voidpf stream)); 142 | typedef long (ZCALLBACK *seek_file_func) OF((voidpf opaque, voidpf stream, uLong offset, int origin)); 143 | 144 | 145 | /* here is the "old" 32 bits structure structure */ 146 | typedef struct zlib_filefunc_def_s 147 | { 148 | open_file_func zopen_file; 149 | read_file_func zread_file; 150 | write_file_func zwrite_file; 151 | tell_file_func ztell_file; 152 | seek_file_func zseek_file; 153 | close_file_func zclose_file; 154 | testerror_file_func zerror_file; 155 | voidpf opaque; 156 | } zlib_filefunc_def; 157 | 158 | typedef ZPOS64_T (ZCALLBACK *tell64_file_func) OF((voidpf opaque, voidpf stream)); 159 | typedef long (ZCALLBACK *seek64_file_func) OF((voidpf opaque, voidpf stream, ZPOS64_T offset, int origin)); 160 | typedef voidpf (ZCALLBACK *open64_file_func) OF((voidpf opaque, const void* filename, int mode)); 161 | 162 | typedef struct zlib_filefunc64_def_s 163 | { 164 | open64_file_func zopen64_file; 165 | read_file_func zread_file; 166 | write_file_func zwrite_file; 167 | tell64_file_func ztell64_file; 168 | seek64_file_func zseek64_file; 169 | close_file_func zclose_file; 170 | testerror_file_func zerror_file; 171 | voidpf opaque; 172 | } zlib_filefunc64_def; 173 | 174 | void fill_fopen64_filefunc OF((zlib_filefunc64_def* pzlib_filefunc_def)); 175 | void fill_fopen_filefunc OF((zlib_filefunc_def* pzlib_filefunc_def)); 176 | 177 | /* now internal definition, only for zip.c and unzip.h */ 178 | typedef struct zlib_filefunc64_32_def_s 179 | { 180 | zlib_filefunc64_def zfile_func64; 181 | open_file_func zopen32_file; 182 | tell_file_func ztell32_file; 183 | seek_file_func zseek32_file; 184 | } zlib_filefunc64_32_def; 185 | 186 | 187 | #define ZREAD64(filefunc,filestream,buf,size) ((*((filefunc).zfile_func64.zread_file)) ((filefunc).zfile_func64.opaque,filestream,buf,size)) 188 | #define ZWRITE64(filefunc,filestream,buf,size) ((*((filefunc).zfile_func64.zwrite_file)) ((filefunc).zfile_func64.opaque,filestream,buf,size)) 189 | //#define ZTELL64(filefunc,filestream) ((*((filefunc).ztell64_file)) ((filefunc).opaque,filestream)) 190 | //#define ZSEEK64(filefunc,filestream,pos,mode) ((*((filefunc).zseek64_file)) ((filefunc).opaque,filestream,pos,mode)) 191 | #define ZCLOSE64(filefunc,filestream) ((*((filefunc).zfile_func64.zclose_file)) ((filefunc).zfile_func64.opaque,filestream)) 192 | #define ZERROR64(filefunc,filestream) ((*((filefunc).zfile_func64.zerror_file)) ((filefunc).zfile_func64.opaque,filestream)) 193 | 194 | voidpf call_zopen64 OF((const zlib_filefunc64_32_def* pfilefunc,const void*filename,int mode)); 195 | long call_zseek64 OF((const zlib_filefunc64_32_def* pfilefunc,voidpf filestream, ZPOS64_T offset, int origin)); 196 | ZPOS64_T call_ztell64 OF((const zlib_filefunc64_32_def* pfilefunc,voidpf filestream)); 197 | 198 | void fill_zlib_filefunc64_32_def_from_filefunc32(zlib_filefunc64_32_def* p_filefunc64_32,const zlib_filefunc_def* p_filefunc32); 199 | 200 | #define ZOPEN64(filefunc,filename,mode) (call_zopen64((&(filefunc)),(filename),(mode))) 201 | #define ZTELL64(filefunc,filestream) (call_ztell64((&(filefunc)),(filestream))) 202 | #define ZSEEK64(filefunc,filestream,pos,mode) (call_zseek64((&(filefunc)),(filestream),(pos),(mode))) 203 | 204 | #ifdef __cplusplus 205 | } 206 | #endif 207 | 208 | #endif 209 | -------------------------------------------------------------------------------- /ApkProtection/src/zlib/libz.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/javazjf/CSApkShellProject/0a586534c97bf75f25196fd63eadd1fb93f74b90/ApkProtection/src/zlib/libz.a -------------------------------------------------------------------------------- /ApkProtection/src/zlib/unzip.c: -------------------------------------------------------------------------------- 1 | /* unzip.c -- IO for uncompress .zip files using zlib 2 | Version 1.1, February 14h, 2010 3 | part of the MiniZip project - ( http://www.winimage.com/zLibDll/minizip.html ) 4 | 5 | Copyright (C) 1998-2010 Gilles Vollant (minizip) ( http://www.winimage.com/zLibDll/minizip.html ) 6 | 7 | Modifications of Unzip for Zip64 8 | Copyright (C) 2007-2008 Even Rouault 9 | 10 | Modifications for Zip64 support on both zip and unzip 11 | Copyright (C) 2009-2010 Mathias Svensson ( http://result42.com ) 12 | 13 | For more info read MiniZip_info.txt 14 | 15 | 16 | ------------------------------------------------------------------------------------ 17 | Decryption code comes from crypt.c by Info-ZIP but has been greatly reduced in terms of 18 | compatibility with older software. The following is from the original crypt.c. 19 | Code woven in by Terry Thorsen 1/2003. 20 | 21 | Copyright (c) 1990-2000 Info-ZIP. All rights reserved. 22 | 23 | See the accompanying file LICENSE, version 2000-Apr-09 or later 24 | (the contents of which are also included in zip.h) for terms of use. 25 | If, for some reason, all these files are missing, the Info-ZIP license 26 | also may be found at: ftp://ftp.info-zip.org/pub/infozip/license.html 27 | 28 | crypt.c (full version) by Info-ZIP. Last revised: [see crypt.h] 29 | 30 | The encryption/decryption parts of this source code (as opposed to the 31 | non-echoing password parts) were originally written in Europe. The 32 | whole source package can be freely distributed, including from the USA. 33 | (Prior to January 2000, re-export from the US was a violation of US law.) 34 | 35 | This encryption code is a direct transcription of the algorithm from 36 | Roger Schlafly, described by Phil Katz in the file appnote.txt. This 37 | file (appnote.txt) is distributed with the PKZIP program (even in the 38 | version without encryption capabilities). 39 | 40 | ------------------------------------------------------------------------------------ 41 | 42 | Changes in unzip.c 43 | 44 | 2007-2008 - Even Rouault - Addition of cpl_unzGetCurrentFileZStreamPos 45 | 2007-2008 - Even Rouault - Decoration of symbol names unz* -> cpl_unz* 46 | 2007-2008 - Even Rouault - Remove old C style function prototypes 47 | 2007-2008 - Even Rouault - Add unzip support for ZIP64 48 | 49 | Copyright (C) 2007-2008 Even Rouault 50 | 51 | 52 | Oct-2009 - Mathias Svensson - Removed cpl_* from symbol names (Even Rouault added them but since this is now moved to a new project (minizip64) I renamed them again). 53 | Oct-2009 - Mathias Svensson - Fixed problem if uncompressed size was > 4G and compressed size was <4G 54 | should only read the compressed/uncompressed size from the Zip64 format if 55 | the size from normal header was 0xFFFFFFFF 56 | Oct-2009 - Mathias Svensson - Applied some bug fixes from paches recived from Gilles Vollant 57 | Oct-2009 - Mathias Svensson - Applied support to unzip files with compression mathod BZIP2 (bzip2 lib is required) 58 | Patch created by Daniel Borca 59 | 60 | Jan-2010 - back to unzip and minizip 1.0 name scheme, with compatibility layer 61 | 62 | Copyright (C) 1998 - 2010 Gilles Vollant, Even Rouault, Mathias Svensson 63 | 64 | */ 65 | 66 | 67 | #include 68 | #include 69 | #include 70 | 71 | #ifndef NOUNCRYPT 72 | #define NOUNCRYPT 73 | #endif 74 | 75 | #include "zlib.h" 76 | #include "unzip.h" 77 | 78 | #ifdef STDC 79 | # include 80 | # include 81 | # include 82 | #endif 83 | #ifdef NO_ERRNO_H 84 | extern int errno; 85 | #else 86 | # include 87 | #endif 88 | 89 | 90 | #ifndef local 91 | # define local static 92 | #endif 93 | /* compile with -Dlocal if your debugger can't find static symbols */ 94 | 95 | 96 | #ifndef CASESENSITIVITYDEFAULT_NO 97 | # if !defined(unix) && !defined(CASESENSITIVITYDEFAULT_YES) 98 | # define CASESENSITIVITYDEFAULT_NO 99 | # endif 100 | #endif 101 | 102 | 103 | #ifndef UNZ_BUFSIZE 104 | #define UNZ_BUFSIZE (16384) 105 | #endif 106 | 107 | #ifndef UNZ_MAXFILENAMEINZIP 108 | #define UNZ_MAXFILENAMEINZIP (256) 109 | #endif 110 | 111 | #ifndef ALLOC 112 | # define ALLOC(size) (malloc(size)) 113 | #endif 114 | #ifndef TRYFREE 115 | # define TRYFREE(p) {if (p) free(p);} 116 | #endif 117 | 118 | #define SIZECENTRALDIRITEM (0x2e) 119 | #define SIZEZIPLOCALHEADER (0x1e) 120 | 121 | 122 | const char unz_copyright[] = 123 | " unzip 1.01 Copyright 1998-2004 Gilles Vollant - http://www.winimage.com/zLibDll"; 124 | 125 | /* unz_file_info_interntal contain internal info about a file in zipfile*/ 126 | typedef struct unz_file_info64_internal_s 127 | { 128 | ZPOS64_T offset_curfile;/* relative offset of local header 8 bytes */ 129 | } unz_file_info64_internal; 130 | 131 | 132 | /* file_in_zip_read_info_s contain internal information about a file in zipfile, 133 | when reading and decompress it */ 134 | typedef struct 135 | { 136 | char *read_buffer; /* internal buffer for compressed data */ 137 | z_stream stream; /* zLib stream structure for inflate */ 138 | 139 | #ifdef HAVE_BZIP2 140 | bz_stream bstream; /* bzLib stream structure for bziped */ 141 | #endif 142 | 143 | ZPOS64_T pos_in_zipfile; /* position in byte on the zipfile, for fseek*/ 144 | uLong stream_initialised; /* flag set if stream structure is initialised*/ 145 | 146 | ZPOS64_T offset_local_extrafield;/* offset of the local extra field */ 147 | uInt size_local_extrafield;/* size of the local extra field */ 148 | ZPOS64_T pos_local_extrafield; /* position in the local extra field in read*/ 149 | ZPOS64_T total_out_64; 150 | 151 | uLong crc32; /* crc32 of all data uncompressed */ 152 | uLong crc32_wait; /* crc32 we must obtain after decompress all */ 153 | ZPOS64_T rest_read_compressed; /* number of byte to be decompressed */ 154 | ZPOS64_T rest_read_uncompressed;/*number of byte to be obtained after decomp*/ 155 | zlib_filefunc64_32_def z_filefunc; 156 | voidpf filestream; /* io structore of the zipfile */ 157 | uLong compression_method; /* compression method (0==store) */ 158 | ZPOS64_T byte_before_the_zipfile;/* byte before the zipfile, (>0 for sfx)*/ 159 | int raw; 160 | } file_in_zip64_read_info_s; 161 | 162 | 163 | /* unz64_s contain internal information about the zipfile 164 | */ 165 | typedef struct 166 | { 167 | zlib_filefunc64_32_def z_filefunc; 168 | int is64bitOpenFunction; 169 | voidpf filestream; /* io structore of the zipfile */ 170 | unz_global_info64 gi; /* public global information */ 171 | ZPOS64_T byte_before_the_zipfile;/* byte before the zipfile, (>0 for sfx)*/ 172 | ZPOS64_T num_file; /* number of the current file in the zipfile*/ 173 | ZPOS64_T pos_in_central_dir; /* pos of the current file in the central dir*/ 174 | ZPOS64_T current_file_ok; /* flag about the usability of the current file*/ 175 | ZPOS64_T central_pos; /* position of the beginning of the central dir*/ 176 | 177 | ZPOS64_T size_central_dir; /* size of the central directory */ 178 | ZPOS64_T offset_central_dir; /* offset of start of central directory with 179 | respect to the starting disk number */ 180 | 181 | unz_file_info64 cur_file_info; /* public info about the current file in zip*/ 182 | unz_file_info64_internal cur_file_info_internal; /* private info about it*/ 183 | file_in_zip64_read_info_s* pfile_in_zip_read; /* structure about the current 184 | file if we are decompressing it */ 185 | int encrypted; 186 | 187 | int isZip64; 188 | 189 | # ifndef NOUNCRYPT 190 | unsigned long keys[3]; /* keys defining the pseudo-random sequence */ 191 | const z_crc_t* pcrc_32_tab; 192 | # endif 193 | } unz64_s; 194 | 195 | 196 | #ifndef NOUNCRYPT 197 | #include "crypt.h" 198 | #endif 199 | 200 | /* =========================================================================== 201 | Read a byte from a gz_stream; update next_in and avail_in. Return EOF 202 | for end of file. 203 | IN assertion: the stream s has been sucessfully opened for reading. 204 | */ 205 | 206 | 207 | local int unz64local_getByte OF(( 208 | const zlib_filefunc64_32_def* pzlib_filefunc_def, 209 | voidpf filestream, 210 | int *pi)); 211 | 212 | local int unz64local_getByte(const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream, int *pi) 213 | { 214 | unsigned char c; 215 | int err = (int)ZREAD64(*pzlib_filefunc_def,filestream,&c,1); 216 | if (err==1) 217 | { 218 | *pi = (int)c; 219 | return UNZ_OK; 220 | } 221 | else 222 | { 223 | if (ZERROR64(*pzlib_filefunc_def,filestream)) 224 | return UNZ_ERRNO; 225 | else 226 | return UNZ_EOF; 227 | } 228 | } 229 | 230 | 231 | /* =========================================================================== 232 | Reads a long in LSB order from the given gz_stream. Sets 233 | */ 234 | local int unz64local_getShort OF(( 235 | const zlib_filefunc64_32_def* pzlib_filefunc_def, 236 | voidpf filestream, 237 | uLong *pX)); 238 | 239 | local int unz64local_getShort (const zlib_filefunc64_32_def* pzlib_filefunc_def, 240 | voidpf filestream, 241 | uLong *pX) 242 | { 243 | uLong x ; 244 | int i = 0; 245 | int err; 246 | 247 | err = unz64local_getByte(pzlib_filefunc_def,filestream,&i); 248 | x = (uLong)i; 249 | 250 | if (err==UNZ_OK) 251 | err = unz64local_getByte(pzlib_filefunc_def,filestream,&i); 252 | x |= ((uLong)i)<<8; 253 | 254 | if (err==UNZ_OK) 255 | *pX = x; 256 | else 257 | *pX = 0; 258 | return err; 259 | } 260 | 261 | local int unz64local_getLong OF(( 262 | const zlib_filefunc64_32_def* pzlib_filefunc_def, 263 | voidpf filestream, 264 | uLong *pX)); 265 | 266 | local int unz64local_getLong (const zlib_filefunc64_32_def* pzlib_filefunc_def, 267 | voidpf filestream, 268 | uLong *pX) 269 | { 270 | uLong x ; 271 | int i = 0; 272 | int err; 273 | 274 | err = unz64local_getByte(pzlib_filefunc_def,filestream,&i); 275 | x = (uLong)i; 276 | 277 | if (err==UNZ_OK) 278 | err = unz64local_getByte(pzlib_filefunc_def,filestream,&i); 279 | x |= ((uLong)i)<<8; 280 | 281 | if (err==UNZ_OK) 282 | err = unz64local_getByte(pzlib_filefunc_def,filestream,&i); 283 | x |= ((uLong)i)<<16; 284 | 285 | if (err==UNZ_OK) 286 | err = unz64local_getByte(pzlib_filefunc_def,filestream,&i); 287 | x += ((uLong)i)<<24; 288 | 289 | if (err==UNZ_OK) 290 | *pX = x; 291 | else 292 | *pX = 0; 293 | return err; 294 | } 295 | 296 | local int unz64local_getLong64 OF(( 297 | const zlib_filefunc64_32_def* pzlib_filefunc_def, 298 | voidpf filestream, 299 | ZPOS64_T *pX)); 300 | 301 | 302 | local int unz64local_getLong64 (const zlib_filefunc64_32_def* pzlib_filefunc_def, 303 | voidpf filestream, 304 | ZPOS64_T *pX) 305 | { 306 | ZPOS64_T x ; 307 | int i = 0; 308 | int err; 309 | 310 | err = unz64local_getByte(pzlib_filefunc_def,filestream,&i); 311 | x = (ZPOS64_T)i; 312 | 313 | if (err==UNZ_OK) 314 | err = unz64local_getByte(pzlib_filefunc_def,filestream,&i); 315 | x |= ((ZPOS64_T)i)<<8; 316 | 317 | if (err==UNZ_OK) 318 | err = unz64local_getByte(pzlib_filefunc_def,filestream,&i); 319 | x |= ((ZPOS64_T)i)<<16; 320 | 321 | if (err==UNZ_OK) 322 | err = unz64local_getByte(pzlib_filefunc_def,filestream,&i); 323 | x |= ((ZPOS64_T)i)<<24; 324 | 325 | if (err==UNZ_OK) 326 | err = unz64local_getByte(pzlib_filefunc_def,filestream,&i); 327 | x |= ((ZPOS64_T)i)<<32; 328 | 329 | if (err==UNZ_OK) 330 | err = unz64local_getByte(pzlib_filefunc_def,filestream,&i); 331 | x |= ((ZPOS64_T)i)<<40; 332 | 333 | if (err==UNZ_OK) 334 | err = unz64local_getByte(pzlib_filefunc_def,filestream,&i); 335 | x |= ((ZPOS64_T)i)<<48; 336 | 337 | if (err==UNZ_OK) 338 | err = unz64local_getByte(pzlib_filefunc_def,filestream,&i); 339 | x |= ((ZPOS64_T)i)<<56; 340 | 341 | if (err==UNZ_OK) 342 | *pX = x; 343 | else 344 | *pX = 0; 345 | return err; 346 | } 347 | 348 | /* My own strcmpi / strcasecmp */ 349 | local int strcmpcasenosensitive_internal (const char* fileName1, const char* fileName2) 350 | { 351 | for (;;) 352 | { 353 | char c1=*(fileName1++); 354 | char c2=*(fileName2++); 355 | if ((c1>='a') && (c1<='z')) 356 | c1 -= 0x20; 357 | if ((c2>='a') && (c2<='z')) 358 | c2 -= 0x20; 359 | if (c1=='\0') 360 | return ((c2=='\0') ? 0 : -1); 361 | if (c2=='\0') 362 | return 1; 363 | if (c1c2) 366 | return 1; 367 | } 368 | } 369 | 370 | 371 | #ifdef CASESENSITIVITYDEFAULT_NO 372 | #define CASESENSITIVITYDEFAULTVALUE 2 373 | #else 374 | #define CASESENSITIVITYDEFAULTVALUE 1 375 | #endif 376 | 377 | #ifndef STRCMPCASENOSENTIVEFUNCTION 378 | #define STRCMPCASENOSENTIVEFUNCTION strcmpcasenosensitive_internal 379 | #endif 380 | 381 | /* 382 | Compare two filename (fileName1,fileName2). 383 | If iCaseSenisivity = 1, comparision is case sensitivity (like strcmp) 384 | If iCaseSenisivity = 2, comparision is not case sensitivity (like strcmpi 385 | or strcasecmp) 386 | If iCaseSenisivity = 0, case sensitivity is defaut of your operating system 387 | (like 1 on Unix, 2 on Windows) 388 | 389 | */ 390 | extern int ZEXPORT unzStringFileNameCompare (const char* fileName1, 391 | const char* fileName2, 392 | int iCaseSensitivity) 393 | 394 | { 395 | if (iCaseSensitivity==0) 396 | iCaseSensitivity=CASESENSITIVITYDEFAULTVALUE; 397 | 398 | if (iCaseSensitivity==1) 399 | return strcmp(fileName1,fileName2); 400 | 401 | return STRCMPCASENOSENTIVEFUNCTION(fileName1,fileName2); 402 | } 403 | 404 | #ifndef BUFREADCOMMENT 405 | #define BUFREADCOMMENT (0x400) 406 | #endif 407 | 408 | /* 409 | Locate the Central directory of a zipfile (at the end, just before 410 | the global comment) 411 | */ 412 | local ZPOS64_T unz64local_SearchCentralDir OF((const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream)); 413 | local ZPOS64_T unz64local_SearchCentralDir(const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream) 414 | { 415 | unsigned char* buf; 416 | ZPOS64_T uSizeFile; 417 | ZPOS64_T uBackRead; 418 | ZPOS64_T uMaxBack=0xffff; /* maximum size of global comment */ 419 | ZPOS64_T uPosFound=0; 420 | 421 | if (ZSEEK64(*pzlib_filefunc_def,filestream,0,ZLIB_FILEFUNC_SEEK_END) != 0) 422 | return 0; 423 | 424 | 425 | uSizeFile = ZTELL64(*pzlib_filefunc_def,filestream); 426 | 427 | if (uMaxBack>uSizeFile) 428 | uMaxBack = uSizeFile; 429 | 430 | buf = (unsigned char*)ALLOC(BUFREADCOMMENT+4); 431 | if (buf==NULL) 432 | return 0; 433 | 434 | uBackRead = 4; 435 | while (uBackReaduMaxBack) 441 | uBackRead = uMaxBack; 442 | else 443 | uBackRead+=BUFREADCOMMENT; 444 | uReadPos = uSizeFile-uBackRead ; 445 | 446 | uReadSize = ((BUFREADCOMMENT+4) < (uSizeFile-uReadPos)) ? 447 | (BUFREADCOMMENT+4) : (uLong)(uSizeFile-uReadPos); 448 | if (ZSEEK64(*pzlib_filefunc_def,filestream,uReadPos,ZLIB_FILEFUNC_SEEK_SET)!=0) 449 | break; 450 | 451 | if (ZREAD64(*pzlib_filefunc_def,filestream,buf,uReadSize)!=uReadSize) 452 | break; 453 | 454 | for (i=(int)uReadSize-3; (i--)>0;) 455 | if (((*(buf+i))==0x50) && ((*(buf+i+1))==0x4b) && 456 | ((*(buf+i+2))==0x05) && ((*(buf+i+3))==0x06)) 457 | { 458 | uPosFound = uReadPos+i; 459 | break; 460 | } 461 | 462 | if (uPosFound!=0) 463 | break; 464 | } 465 | TRYFREE(buf); 466 | return uPosFound; 467 | } 468 | 469 | 470 | /* 471 | Locate the Central directory 64 of a zipfile (at the end, just before 472 | the global comment) 473 | */ 474 | local ZPOS64_T unz64local_SearchCentralDir64 OF(( 475 | const zlib_filefunc64_32_def* pzlib_filefunc_def, 476 | voidpf filestream)); 477 | 478 | local ZPOS64_T unz64local_SearchCentralDir64(const zlib_filefunc64_32_def* pzlib_filefunc_def, 479 | voidpf filestream) 480 | { 481 | unsigned char* buf; 482 | ZPOS64_T uSizeFile; 483 | ZPOS64_T uBackRead; 484 | ZPOS64_T uMaxBack=0xffff; /* maximum size of global comment */ 485 | ZPOS64_T uPosFound=0; 486 | uLong uL; 487 | ZPOS64_T relativeOffset; 488 | 489 | if (ZSEEK64(*pzlib_filefunc_def,filestream,0,ZLIB_FILEFUNC_SEEK_END) != 0) 490 | return 0; 491 | 492 | 493 | uSizeFile = ZTELL64(*pzlib_filefunc_def,filestream); 494 | 495 | if (uMaxBack>uSizeFile) 496 | uMaxBack = uSizeFile; 497 | 498 | buf = (unsigned char*)ALLOC(BUFREADCOMMENT+4); 499 | if (buf==NULL) 500 | return 0; 501 | 502 | uBackRead = 4; 503 | while (uBackReaduMaxBack) 509 | uBackRead = uMaxBack; 510 | else 511 | uBackRead+=BUFREADCOMMENT; 512 | uReadPos = uSizeFile-uBackRead ; 513 | 514 | uReadSize = ((BUFREADCOMMENT+4) < (uSizeFile-uReadPos)) ? 515 | (BUFREADCOMMENT+4) : (uLong)(uSizeFile-uReadPos); 516 | if (ZSEEK64(*pzlib_filefunc_def,filestream,uReadPos,ZLIB_FILEFUNC_SEEK_SET)!=0) 517 | break; 518 | 519 | if (ZREAD64(*pzlib_filefunc_def,filestream,buf,uReadSize)!=uReadSize) 520 | break; 521 | 522 | for (i=(int)uReadSize-3; (i--)>0;) 523 | if (((*(buf+i))==0x50) && ((*(buf+i+1))==0x4b) && 524 | ((*(buf+i+2))==0x06) && ((*(buf+i+3))==0x07)) 525 | { 526 | uPosFound = uReadPos+i; 527 | break; 528 | } 529 | 530 | if (uPosFound!=0) 531 | break; 532 | } 533 | TRYFREE(buf); 534 | if (uPosFound == 0) 535 | return 0; 536 | 537 | /* Zip64 end of central directory locator */ 538 | if (ZSEEK64(*pzlib_filefunc_def,filestream, uPosFound,ZLIB_FILEFUNC_SEEK_SET)!=0) 539 | return 0; 540 | 541 | /* the signature, already checked */ 542 | if (unz64local_getLong(pzlib_filefunc_def,filestream,&uL)!=UNZ_OK) 543 | return 0; 544 | 545 | /* number of the disk with the start of the zip64 end of central directory */ 546 | if (unz64local_getLong(pzlib_filefunc_def,filestream,&uL)!=UNZ_OK) 547 | return 0; 548 | if (uL != 0) 549 | return 0; 550 | 551 | /* relative offset of the zip64 end of central directory record */ 552 | if (unz64local_getLong64(pzlib_filefunc_def,filestream,&relativeOffset)!=UNZ_OK) 553 | return 0; 554 | 555 | /* total number of disks */ 556 | if (unz64local_getLong(pzlib_filefunc_def,filestream,&uL)!=UNZ_OK) 557 | return 0; 558 | if (uL != 1) 559 | return 0; 560 | 561 | /* Goto end of central directory record */ 562 | if (ZSEEK64(*pzlib_filefunc_def,filestream, relativeOffset,ZLIB_FILEFUNC_SEEK_SET)!=0) 563 | return 0; 564 | 565 | /* the signature */ 566 | if (unz64local_getLong(pzlib_filefunc_def,filestream,&uL)!=UNZ_OK) 567 | return 0; 568 | 569 | if (uL != 0x06064b50) 570 | return 0; 571 | 572 | return relativeOffset; 573 | } 574 | 575 | /* 576 | Open a Zip file. path contain the full pathname (by example, 577 | on a Windows NT computer "c:\\test\\zlib114.zip" or on an Unix computer 578 | "zlib/zlib114.zip". 579 | If the zipfile cannot be opened (file doesn't exist or in not valid), the 580 | return value is NULL. 581 | Else, the return value is a unzFile Handle, usable with other function 582 | of this unzip package. 583 | */ 584 | local unzFile unzOpenInternal (const void *path, 585 | zlib_filefunc64_32_def* pzlib_filefunc64_32_def, 586 | int is64bitOpenFunction) 587 | { 588 | unz64_s us; 589 | unz64_s *s; 590 | ZPOS64_T central_pos; 591 | uLong uL; 592 | 593 | uLong number_disk; /* number of the current dist, used for 594 | spaning ZIP, unsupported, always 0*/ 595 | uLong number_disk_with_CD; /* number the the disk with central dir, used 596 | for spaning ZIP, unsupported, always 0*/ 597 | ZPOS64_T number_entry_CD; /* total number of entries in 598 | the central dir 599 | (same than number_entry on nospan) */ 600 | 601 | int err=UNZ_OK; 602 | 603 | if (unz_copyright[0]!=' ') 604 | return NULL; 605 | 606 | us.z_filefunc.zseek32_file = NULL; 607 | us.z_filefunc.ztell32_file = NULL; 608 | if (pzlib_filefunc64_32_def==NULL) 609 | fill_fopen64_filefunc(&us.z_filefunc.zfile_func64); 610 | else 611 | us.z_filefunc = *pzlib_filefunc64_32_def; 612 | us.is64bitOpenFunction = is64bitOpenFunction; 613 | 614 | 615 | 616 | us.filestream = ZOPEN64(us.z_filefunc, 617 | path, 618 | ZLIB_FILEFUNC_MODE_READ | 619 | ZLIB_FILEFUNC_MODE_EXISTING); 620 | if (us.filestream==NULL) 621 | return NULL; 622 | 623 | central_pos = unz64local_SearchCentralDir64(&us.z_filefunc,us.filestream); 624 | if (central_pos) 625 | { 626 | uLong uS; 627 | ZPOS64_T uL64; 628 | 629 | us.isZip64 = 1; 630 | 631 | if (ZSEEK64(us.z_filefunc, us.filestream, 632 | central_pos,ZLIB_FILEFUNC_SEEK_SET)!=0) 633 | err=UNZ_ERRNO; 634 | 635 | /* the signature, already checked */ 636 | if (unz64local_getLong(&us.z_filefunc, us.filestream,&uL)!=UNZ_OK) 637 | err=UNZ_ERRNO; 638 | 639 | /* size of zip64 end of central directory record */ 640 | if (unz64local_getLong64(&us.z_filefunc, us.filestream,&uL64)!=UNZ_OK) 641 | err=UNZ_ERRNO; 642 | 643 | /* version made by */ 644 | if (unz64local_getShort(&us.z_filefunc, us.filestream,&uS)!=UNZ_OK) 645 | err=UNZ_ERRNO; 646 | 647 | /* version needed to extract */ 648 | if (unz64local_getShort(&us.z_filefunc, us.filestream,&uS)!=UNZ_OK) 649 | err=UNZ_ERRNO; 650 | 651 | /* number of this disk */ 652 | if (unz64local_getLong(&us.z_filefunc, us.filestream,&number_disk)!=UNZ_OK) 653 | err=UNZ_ERRNO; 654 | 655 | /* number of the disk with the start of the central directory */ 656 | if (unz64local_getLong(&us.z_filefunc, us.filestream,&number_disk_with_CD)!=UNZ_OK) 657 | err=UNZ_ERRNO; 658 | 659 | /* total number of entries in the central directory on this disk */ 660 | if (unz64local_getLong64(&us.z_filefunc, us.filestream,&us.gi.number_entry)!=UNZ_OK) 661 | err=UNZ_ERRNO; 662 | 663 | /* total number of entries in the central directory */ 664 | if (unz64local_getLong64(&us.z_filefunc, us.filestream,&number_entry_CD)!=UNZ_OK) 665 | err=UNZ_ERRNO; 666 | 667 | if ((number_entry_CD!=us.gi.number_entry) || 668 | (number_disk_with_CD!=0) || 669 | (number_disk!=0)) 670 | err=UNZ_BADZIPFILE; 671 | 672 | /* size of the central directory */ 673 | if (unz64local_getLong64(&us.z_filefunc, us.filestream,&us.size_central_dir)!=UNZ_OK) 674 | err=UNZ_ERRNO; 675 | 676 | /* offset of start of central directory with respect to the 677 | starting disk number */ 678 | if (unz64local_getLong64(&us.z_filefunc, us.filestream,&us.offset_central_dir)!=UNZ_OK) 679 | err=UNZ_ERRNO; 680 | 681 | us.gi.size_comment = 0; 682 | } 683 | else 684 | { 685 | central_pos = unz64local_SearchCentralDir(&us.z_filefunc,us.filestream); 686 | if (central_pos==0) 687 | err=UNZ_ERRNO; 688 | 689 | us.isZip64 = 0; 690 | 691 | if (ZSEEK64(us.z_filefunc, us.filestream, 692 | central_pos,ZLIB_FILEFUNC_SEEK_SET)!=0) 693 | err=UNZ_ERRNO; 694 | 695 | /* the signature, already checked */ 696 | if (unz64local_getLong(&us.z_filefunc, us.filestream,&uL)!=UNZ_OK) 697 | err=UNZ_ERRNO; 698 | 699 | /* number of this disk */ 700 | if (unz64local_getShort(&us.z_filefunc, us.filestream,&number_disk)!=UNZ_OK) 701 | err=UNZ_ERRNO; 702 | 703 | /* number of the disk with the start of the central directory */ 704 | if (unz64local_getShort(&us.z_filefunc, us.filestream,&number_disk_with_CD)!=UNZ_OK) 705 | err=UNZ_ERRNO; 706 | 707 | /* total number of entries in the central dir on this disk */ 708 | if (unz64local_getShort(&us.z_filefunc, us.filestream,&uL)!=UNZ_OK) 709 | err=UNZ_ERRNO; 710 | us.gi.number_entry = uL; 711 | 712 | /* total number of entries in the central dir */ 713 | if (unz64local_getShort(&us.z_filefunc, us.filestream,&uL)!=UNZ_OK) 714 | err=UNZ_ERRNO; 715 | number_entry_CD = uL; 716 | 717 | if ((number_entry_CD!=us.gi.number_entry) || 718 | (number_disk_with_CD!=0) || 719 | (number_disk!=0)) 720 | err=UNZ_BADZIPFILE; 721 | 722 | /* size of the central directory */ 723 | if (unz64local_getLong(&us.z_filefunc, us.filestream,&uL)!=UNZ_OK) 724 | err=UNZ_ERRNO; 725 | us.size_central_dir = uL; 726 | 727 | /* offset of start of central directory with respect to the 728 | starting disk number */ 729 | if (unz64local_getLong(&us.z_filefunc, us.filestream,&uL)!=UNZ_OK) 730 | err=UNZ_ERRNO; 731 | us.offset_central_dir = uL; 732 | 733 | /* zipfile comment length */ 734 | if (unz64local_getShort(&us.z_filefunc, us.filestream,&us.gi.size_comment)!=UNZ_OK) 735 | err=UNZ_ERRNO; 736 | } 737 | 738 | if ((central_pospfile_in_zip_read!=NULL) 816 | unzCloseCurrentFile(file); 817 | 818 | ZCLOSE64(s->z_filefunc, s->filestream); 819 | TRYFREE(s); 820 | return UNZ_OK; 821 | } 822 | 823 | 824 | /* 825 | Write info about the ZipFile in the *pglobal_info structure. 826 | No preparation of the structure is needed 827 | return UNZ_OK if there is no problem. */ 828 | extern int ZEXPORT unzGetGlobalInfo64 (unzFile file, unz_global_info64* pglobal_info) 829 | { 830 | unz64_s* s; 831 | if (file==NULL) 832 | return UNZ_PARAMERROR; 833 | s=(unz64_s*)file; 834 | *pglobal_info=s->gi; 835 | return UNZ_OK; 836 | } 837 | 838 | extern int ZEXPORT unzGetGlobalInfo (unzFile file, unz_global_info* pglobal_info32) 839 | { 840 | unz64_s* s; 841 | if (file==NULL) 842 | return UNZ_PARAMERROR; 843 | s=(unz64_s*)file; 844 | /* to do : check if number_entry is not truncated */ 845 | pglobal_info32->number_entry = (uLong)s->gi.number_entry; 846 | pglobal_info32->size_comment = s->gi.size_comment; 847 | return UNZ_OK; 848 | } 849 | /* 850 | Translate date/time from Dos format to tm_unz (readable more easilty) 851 | */ 852 | local void unz64local_DosDateToTmuDate (ZPOS64_T ulDosDate, tm_unz* ptm) 853 | { 854 | ZPOS64_T uDate; 855 | uDate = (ZPOS64_T)(ulDosDate>>16); 856 | ptm->tm_mday = (uInt)(uDate&0x1f) ; 857 | ptm->tm_mon = (uInt)((((uDate)&0x1E0)/0x20)-1) ; 858 | ptm->tm_year = (uInt)(((uDate&0x0FE00)/0x0200)+1980) ; 859 | 860 | ptm->tm_hour = (uInt) ((ulDosDate &0xF800)/0x800); 861 | ptm->tm_min = (uInt) ((ulDosDate&0x7E0)/0x20) ; 862 | ptm->tm_sec = (uInt) (2*(ulDosDate&0x1f)) ; 863 | } 864 | 865 | /* 866 | Get Info about the current file in the zipfile, with internal only info 867 | */ 868 | local int unz64local_GetCurrentFileInfoInternal OF((unzFile file, 869 | unz_file_info64 *pfile_info, 870 | unz_file_info64_internal 871 | *pfile_info_internal, 872 | char *szFileName, 873 | uLong fileNameBufferSize, 874 | void *extraField, 875 | uLong extraFieldBufferSize, 876 | char *szComment, 877 | uLong commentBufferSize)); 878 | 879 | local int unz64local_GetCurrentFileInfoInternal (unzFile file, 880 | unz_file_info64 *pfile_info, 881 | unz_file_info64_internal 882 | *pfile_info_internal, 883 | char *szFileName, 884 | uLong fileNameBufferSize, 885 | void *extraField, 886 | uLong extraFieldBufferSize, 887 | char *szComment, 888 | uLong commentBufferSize) 889 | { 890 | unz64_s* s; 891 | unz_file_info64 file_info; 892 | unz_file_info64_internal file_info_internal; 893 | int err=UNZ_OK; 894 | uLong uMagic; 895 | long lSeek=0; 896 | uLong uL; 897 | 898 | if (file==NULL) 899 | return UNZ_PARAMERROR; 900 | s=(unz64_s*)file; 901 | if (ZSEEK64(s->z_filefunc, s->filestream, 902 | s->pos_in_central_dir+s->byte_before_the_zipfile, 903 | ZLIB_FILEFUNC_SEEK_SET)!=0) 904 | err=UNZ_ERRNO; 905 | 906 | 907 | /* we check the magic */ 908 | if (err==UNZ_OK) 909 | { 910 | if (unz64local_getLong(&s->z_filefunc, s->filestream,&uMagic) != UNZ_OK) 911 | err=UNZ_ERRNO; 912 | else if (uMagic!=0x02014b50) 913 | err=UNZ_BADZIPFILE; 914 | } 915 | 916 | if (unz64local_getShort(&s->z_filefunc, s->filestream,&file_info.version) != UNZ_OK) 917 | err=UNZ_ERRNO; 918 | 919 | if (unz64local_getShort(&s->z_filefunc, s->filestream,&file_info.version_needed) != UNZ_OK) 920 | err=UNZ_ERRNO; 921 | 922 | if (unz64local_getShort(&s->z_filefunc, s->filestream,&file_info.flag) != UNZ_OK) 923 | err=UNZ_ERRNO; 924 | 925 | if (unz64local_getShort(&s->z_filefunc, s->filestream,&file_info.compression_method) != UNZ_OK) 926 | err=UNZ_ERRNO; 927 | 928 | if (unz64local_getLong(&s->z_filefunc, s->filestream,&file_info.dosDate) != UNZ_OK) 929 | err=UNZ_ERRNO; 930 | 931 | unz64local_DosDateToTmuDate(file_info.dosDate,&file_info.tmu_date); 932 | 933 | if (unz64local_getLong(&s->z_filefunc, s->filestream,&file_info.crc) != UNZ_OK) 934 | err=UNZ_ERRNO; 935 | 936 | if (unz64local_getLong(&s->z_filefunc, s->filestream,&uL) != UNZ_OK) 937 | err=UNZ_ERRNO; 938 | file_info.compressed_size = uL; 939 | 940 | if (unz64local_getLong(&s->z_filefunc, s->filestream,&uL) != UNZ_OK) 941 | err=UNZ_ERRNO; 942 | file_info.uncompressed_size = uL; 943 | 944 | if (unz64local_getShort(&s->z_filefunc, s->filestream,&file_info.size_filename) != UNZ_OK) 945 | err=UNZ_ERRNO; 946 | 947 | if (unz64local_getShort(&s->z_filefunc, s->filestream,&file_info.size_file_extra) != UNZ_OK) 948 | err=UNZ_ERRNO; 949 | 950 | if (unz64local_getShort(&s->z_filefunc, s->filestream,&file_info.size_file_comment) != UNZ_OK) 951 | err=UNZ_ERRNO; 952 | 953 | if (unz64local_getShort(&s->z_filefunc, s->filestream,&file_info.disk_num_start) != UNZ_OK) 954 | err=UNZ_ERRNO; 955 | 956 | if (unz64local_getShort(&s->z_filefunc, s->filestream,&file_info.internal_fa) != UNZ_OK) 957 | err=UNZ_ERRNO; 958 | 959 | if (unz64local_getLong(&s->z_filefunc, s->filestream,&file_info.external_fa) != UNZ_OK) 960 | err=UNZ_ERRNO; 961 | 962 | // relative offset of local header 963 | if (unz64local_getLong(&s->z_filefunc, s->filestream,&uL) != UNZ_OK) 964 | err=UNZ_ERRNO; 965 | file_info_internal.offset_curfile = uL; 966 | 967 | lSeek+=file_info.size_filename; 968 | if ((err==UNZ_OK) && (szFileName!=NULL)) 969 | { 970 | uLong uSizeRead ; 971 | if (file_info.size_filename0) && (fileNameBufferSize>0)) 980 | if (ZREAD64(s->z_filefunc, s->filestream,szFileName,uSizeRead)!=uSizeRead) 981 | err=UNZ_ERRNO; 982 | lSeek -= uSizeRead; 983 | } 984 | 985 | // Read extrafield 986 | if ((err==UNZ_OK) && (extraField!=NULL)) 987 | { 988 | ZPOS64_T uSizeRead ; 989 | if (file_info.size_file_extraz_filefunc, s->filestream,lSeek,ZLIB_FILEFUNC_SEEK_CUR)==0) 997 | lSeek=0; 998 | else 999 | err=UNZ_ERRNO; 1000 | } 1001 | 1002 | if ((file_info.size_file_extra>0) && (extraFieldBufferSize>0)) 1003 | if (ZREAD64(s->z_filefunc, s->filestream,extraField,(uLong)uSizeRead)!=uSizeRead) 1004 | err=UNZ_ERRNO; 1005 | 1006 | lSeek += file_info.size_file_extra - (uLong)uSizeRead; 1007 | } 1008 | else 1009 | lSeek += file_info.size_file_extra; 1010 | 1011 | 1012 | if ((err==UNZ_OK) && (file_info.size_file_extra != 0)) 1013 | { 1014 | uLong acc = 0; 1015 | 1016 | // since lSeek now points to after the extra field we need to move back 1017 | lSeek -= file_info.size_file_extra; 1018 | 1019 | if (lSeek!=0) 1020 | { 1021 | if (ZSEEK64(s->z_filefunc, s->filestream,lSeek,ZLIB_FILEFUNC_SEEK_CUR)==0) 1022 | lSeek=0; 1023 | else 1024 | err=UNZ_ERRNO; 1025 | } 1026 | 1027 | while(acc < file_info.size_file_extra) 1028 | { 1029 | uLong headerId; 1030 | uLong dataSize; 1031 | 1032 | if (unz64local_getShort(&s->z_filefunc, s->filestream,&headerId) != UNZ_OK) 1033 | err=UNZ_ERRNO; 1034 | 1035 | if (unz64local_getShort(&s->z_filefunc, s->filestream,&dataSize) != UNZ_OK) 1036 | err=UNZ_ERRNO; 1037 | 1038 | /* ZIP64 extra fields */ 1039 | if (headerId == 0x0001) 1040 | { 1041 | uLong uL; 1042 | 1043 | if(file_info.uncompressed_size == MAXU32) 1044 | { 1045 | if (unz64local_getLong64(&s->z_filefunc, s->filestream,&file_info.uncompressed_size) != UNZ_OK) 1046 | err=UNZ_ERRNO; 1047 | } 1048 | 1049 | if(file_info.compressed_size == MAXU32) 1050 | { 1051 | if (unz64local_getLong64(&s->z_filefunc, s->filestream,&file_info.compressed_size) != UNZ_OK) 1052 | err=UNZ_ERRNO; 1053 | } 1054 | 1055 | if(file_info_internal.offset_curfile == MAXU32) 1056 | { 1057 | /* Relative Header offset */ 1058 | if (unz64local_getLong64(&s->z_filefunc, s->filestream,&file_info_internal.offset_curfile) != UNZ_OK) 1059 | err=UNZ_ERRNO; 1060 | } 1061 | 1062 | if(file_info.disk_num_start == MAXU32) 1063 | { 1064 | /* Disk Start Number */ 1065 | if (unz64local_getLong(&s->z_filefunc, s->filestream,&uL) != UNZ_OK) 1066 | err=UNZ_ERRNO; 1067 | } 1068 | 1069 | } 1070 | else 1071 | { 1072 | if (ZSEEK64(s->z_filefunc, s->filestream,dataSize,ZLIB_FILEFUNC_SEEK_CUR)!=0) 1073 | err=UNZ_ERRNO; 1074 | } 1075 | 1076 | acc += 2 + 2 + dataSize; 1077 | } 1078 | } 1079 | 1080 | if ((err==UNZ_OK) && (szComment!=NULL)) 1081 | { 1082 | uLong uSizeRead ; 1083 | if (file_info.size_file_commentz_filefunc, s->filestream,lSeek,ZLIB_FILEFUNC_SEEK_CUR)==0) 1094 | lSeek=0; 1095 | else 1096 | err=UNZ_ERRNO; 1097 | } 1098 | 1099 | if ((file_info.size_file_comment>0) && (commentBufferSize>0)) 1100 | if (ZREAD64(s->z_filefunc, s->filestream,szComment,uSizeRead)!=uSizeRead) 1101 | err=UNZ_ERRNO; 1102 | lSeek+=file_info.size_file_comment - uSizeRead; 1103 | } 1104 | else 1105 | lSeek+=file_info.size_file_comment; 1106 | 1107 | 1108 | if ((err==UNZ_OK) && (pfile_info!=NULL)) 1109 | *pfile_info=file_info; 1110 | 1111 | if ((err==UNZ_OK) && (pfile_info_internal!=NULL)) 1112 | *pfile_info_internal=file_info_internal; 1113 | 1114 | return err; 1115 | } 1116 | 1117 | 1118 | 1119 | /* 1120 | Write info about the ZipFile in the *pglobal_info structure. 1121 | No preparation of the structure is needed 1122 | return UNZ_OK if there is no problem. 1123 | */ 1124 | extern int ZEXPORT unzGetCurrentFileInfo64 (unzFile file, 1125 | unz_file_info64 * pfile_info, 1126 | char * szFileName, uLong fileNameBufferSize, 1127 | void *extraField, uLong extraFieldBufferSize, 1128 | char* szComment, uLong commentBufferSize) 1129 | { 1130 | return unz64local_GetCurrentFileInfoInternal(file,pfile_info,NULL, 1131 | szFileName,fileNameBufferSize, 1132 | extraField,extraFieldBufferSize, 1133 | szComment,commentBufferSize); 1134 | } 1135 | 1136 | extern int ZEXPORT unzGetCurrentFileInfo (unzFile file, 1137 | unz_file_info * pfile_info, 1138 | char * szFileName, uLong fileNameBufferSize, 1139 | void *extraField, uLong extraFieldBufferSize, 1140 | char* szComment, uLong commentBufferSize) 1141 | { 1142 | int err; 1143 | unz_file_info64 file_info64; 1144 | err = unz64local_GetCurrentFileInfoInternal(file,&file_info64,NULL, 1145 | szFileName,fileNameBufferSize, 1146 | extraField,extraFieldBufferSize, 1147 | szComment,commentBufferSize); 1148 | if ((err==UNZ_OK) && (pfile_info != NULL)) 1149 | { 1150 | pfile_info->version = file_info64.version; 1151 | pfile_info->version_needed = file_info64.version_needed; 1152 | pfile_info->flag = file_info64.flag; 1153 | pfile_info->compression_method = file_info64.compression_method; 1154 | pfile_info->dosDate = file_info64.dosDate; 1155 | pfile_info->crc = file_info64.crc; 1156 | 1157 | pfile_info->size_filename = file_info64.size_filename; 1158 | pfile_info->size_file_extra = file_info64.size_file_extra; 1159 | pfile_info->size_file_comment = file_info64.size_file_comment; 1160 | 1161 | pfile_info->disk_num_start = file_info64.disk_num_start; 1162 | pfile_info->internal_fa = file_info64.internal_fa; 1163 | pfile_info->external_fa = file_info64.external_fa; 1164 | 1165 | pfile_info->tmu_date = file_info64.tmu_date, 1166 | 1167 | 1168 | pfile_info->compressed_size = (uLong)file_info64.compressed_size; 1169 | pfile_info->uncompressed_size = (uLong)file_info64.uncompressed_size; 1170 | 1171 | } 1172 | return err; 1173 | } 1174 | /* 1175 | Set the current file of the zipfile to the first file. 1176 | return UNZ_OK if there is no problem 1177 | */ 1178 | extern int ZEXPORT unzGoToFirstFile (unzFile file) 1179 | { 1180 | int err=UNZ_OK; 1181 | unz64_s* s; 1182 | if (file==NULL) 1183 | return UNZ_PARAMERROR; 1184 | s=(unz64_s*)file; 1185 | s->pos_in_central_dir=s->offset_central_dir; 1186 | s->num_file=0; 1187 | err=unz64local_GetCurrentFileInfoInternal(file,&s->cur_file_info, 1188 | &s->cur_file_info_internal, 1189 | NULL,0,NULL,0,NULL,0); 1190 | s->current_file_ok = (err == UNZ_OK); 1191 | return err; 1192 | } 1193 | 1194 | /* 1195 | Set the current file of the zipfile to the next file. 1196 | return UNZ_OK if there is no problem 1197 | return UNZ_END_OF_LIST_OF_FILE if the actual file was the latest. 1198 | */ 1199 | extern int ZEXPORT unzGoToNextFile (unzFile file) 1200 | { 1201 | unz64_s* s; 1202 | int err; 1203 | 1204 | if (file==NULL) 1205 | return UNZ_PARAMERROR; 1206 | s=(unz64_s*)file; 1207 | if (!s->current_file_ok) 1208 | return UNZ_END_OF_LIST_OF_FILE; 1209 | if (s->gi.number_entry != 0xffff) /* 2^16 files overflow hack */ 1210 | if (s->num_file+1==s->gi.number_entry) 1211 | return UNZ_END_OF_LIST_OF_FILE; 1212 | 1213 | s->pos_in_central_dir += SIZECENTRALDIRITEM + s->cur_file_info.size_filename + 1214 | s->cur_file_info.size_file_extra + s->cur_file_info.size_file_comment ; 1215 | s->num_file++; 1216 | err = unz64local_GetCurrentFileInfoInternal(file,&s->cur_file_info, 1217 | &s->cur_file_info_internal, 1218 | NULL,0,NULL,0,NULL,0); 1219 | s->current_file_ok = (err == UNZ_OK); 1220 | return err; 1221 | } 1222 | 1223 | 1224 | /* 1225 | Try locate the file szFileName in the zipfile. 1226 | For the iCaseSensitivity signification, see unzStringFileNameCompare 1227 | 1228 | return value : 1229 | UNZ_OK if the file is found. It becomes the current file. 1230 | UNZ_END_OF_LIST_OF_FILE if the file is not found 1231 | */ 1232 | extern int ZEXPORT unzLocateFile (unzFile file, const char *szFileName, int iCaseSensitivity) 1233 | { 1234 | unz64_s* s; 1235 | int err; 1236 | 1237 | /* We remember the 'current' position in the file so that we can jump 1238 | * back there if we fail. 1239 | */ 1240 | unz_file_info64 cur_file_infoSaved; 1241 | unz_file_info64_internal cur_file_info_internalSaved; 1242 | ZPOS64_T num_fileSaved; 1243 | ZPOS64_T pos_in_central_dirSaved; 1244 | 1245 | 1246 | if (file==NULL) 1247 | return UNZ_PARAMERROR; 1248 | 1249 | if (strlen(szFileName)>=UNZ_MAXFILENAMEINZIP) 1250 | return UNZ_PARAMERROR; 1251 | 1252 | s=(unz64_s*)file; 1253 | if (!s->current_file_ok) 1254 | return UNZ_END_OF_LIST_OF_FILE; 1255 | 1256 | /* Save the current state */ 1257 | num_fileSaved = s->num_file; 1258 | pos_in_central_dirSaved = s->pos_in_central_dir; 1259 | cur_file_infoSaved = s->cur_file_info; 1260 | cur_file_info_internalSaved = s->cur_file_info_internal; 1261 | 1262 | err = unzGoToFirstFile(file); 1263 | 1264 | while (err == UNZ_OK) 1265 | { 1266 | char szCurrentFileName[UNZ_MAXFILENAMEINZIP+1]; 1267 | err = unzGetCurrentFileInfo64(file,NULL, 1268 | szCurrentFileName,sizeof(szCurrentFileName)-1, 1269 | NULL,0,NULL,0); 1270 | if (err == UNZ_OK) 1271 | { 1272 | if (unzStringFileNameCompare(szCurrentFileName, 1273 | szFileName,iCaseSensitivity)==0) 1274 | return UNZ_OK; 1275 | err = unzGoToNextFile(file); 1276 | } 1277 | } 1278 | 1279 | /* We failed, so restore the state of the 'current file' to where we 1280 | * were. 1281 | */ 1282 | s->num_file = num_fileSaved ; 1283 | s->pos_in_central_dir = pos_in_central_dirSaved ; 1284 | s->cur_file_info = cur_file_infoSaved; 1285 | s->cur_file_info_internal = cur_file_info_internalSaved; 1286 | return err; 1287 | } 1288 | 1289 | 1290 | /* 1291 | /////////////////////////////////////////// 1292 | // Contributed by Ryan Haksi (mailto://cryogen@infoserve.net) 1293 | // I need random access 1294 | // 1295 | // Further optimization could be realized by adding an ability 1296 | // to cache the directory in memory. The goal being a single 1297 | // comprehensive file read to put the file I need in a memory. 1298 | */ 1299 | 1300 | /* 1301 | typedef struct unz_file_pos_s 1302 | { 1303 | ZPOS64_T pos_in_zip_directory; // offset in file 1304 | ZPOS64_T num_of_file; // # of file 1305 | } unz_file_pos; 1306 | */ 1307 | 1308 | extern int ZEXPORT unzGetFilePos64(unzFile file, unz64_file_pos* file_pos) 1309 | { 1310 | unz64_s* s; 1311 | 1312 | if (file==NULL || file_pos==NULL) 1313 | return UNZ_PARAMERROR; 1314 | s=(unz64_s*)file; 1315 | if (!s->current_file_ok) 1316 | return UNZ_END_OF_LIST_OF_FILE; 1317 | 1318 | file_pos->pos_in_zip_directory = s->pos_in_central_dir; 1319 | file_pos->num_of_file = s->num_file; 1320 | 1321 | return UNZ_OK; 1322 | } 1323 | 1324 | extern int ZEXPORT unzGetFilePos( 1325 | unzFile file, 1326 | unz_file_pos* file_pos) 1327 | { 1328 | unz64_file_pos file_pos64; 1329 | int err = unzGetFilePos64(file,&file_pos64); 1330 | if (err==UNZ_OK) 1331 | { 1332 | file_pos->pos_in_zip_directory = (uLong)file_pos64.pos_in_zip_directory; 1333 | file_pos->num_of_file = (uLong)file_pos64.num_of_file; 1334 | } 1335 | return err; 1336 | } 1337 | 1338 | extern int ZEXPORT unzGoToFilePos64(unzFile file, const unz64_file_pos* file_pos) 1339 | { 1340 | unz64_s* s; 1341 | int err; 1342 | 1343 | if (file==NULL || file_pos==NULL) 1344 | return UNZ_PARAMERROR; 1345 | s=(unz64_s*)file; 1346 | 1347 | /* jump to the right spot */ 1348 | s->pos_in_central_dir = file_pos->pos_in_zip_directory; 1349 | s->num_file = file_pos->num_of_file; 1350 | 1351 | /* set the current file */ 1352 | err = unz64local_GetCurrentFileInfoInternal(file,&s->cur_file_info, 1353 | &s->cur_file_info_internal, 1354 | NULL,0,NULL,0,NULL,0); 1355 | /* return results */ 1356 | s->current_file_ok = (err == UNZ_OK); 1357 | return err; 1358 | } 1359 | 1360 | extern int ZEXPORT unzGoToFilePos( 1361 | unzFile file, 1362 | unz_file_pos* file_pos) 1363 | { 1364 | unz64_file_pos file_pos64; 1365 | if (file_pos == NULL) 1366 | return UNZ_PARAMERROR; 1367 | 1368 | file_pos64.pos_in_zip_directory = file_pos->pos_in_zip_directory; 1369 | file_pos64.num_of_file = file_pos->num_of_file; 1370 | return unzGoToFilePos64(file,&file_pos64); 1371 | } 1372 | 1373 | /* 1374 | // Unzip Helper Functions - should be here? 1375 | /////////////////////////////////////////// 1376 | */ 1377 | 1378 | /* 1379 | Read the local header of the current zipfile 1380 | Check the coherency of the local header and info in the end of central 1381 | directory about this file 1382 | store in *piSizeVar the size of extra info in local header 1383 | (filename and size of extra field data) 1384 | */ 1385 | local int unz64local_CheckCurrentFileCoherencyHeader (unz64_s* s, uInt* piSizeVar, 1386 | ZPOS64_T * poffset_local_extrafield, 1387 | uInt * psize_local_extrafield) 1388 | { 1389 | uLong uMagic,uData,uFlags; 1390 | uLong size_filename; 1391 | uLong size_extra_field; 1392 | int err=UNZ_OK; 1393 | 1394 | *piSizeVar = 0; 1395 | *poffset_local_extrafield = 0; 1396 | *psize_local_extrafield = 0; 1397 | 1398 | if (ZSEEK64(s->z_filefunc, s->filestream,s->cur_file_info_internal.offset_curfile + 1399 | s->byte_before_the_zipfile,ZLIB_FILEFUNC_SEEK_SET)!=0) 1400 | return UNZ_ERRNO; 1401 | 1402 | 1403 | if (err==UNZ_OK) 1404 | { 1405 | if (unz64local_getLong(&s->z_filefunc, s->filestream,&uMagic) != UNZ_OK) 1406 | err=UNZ_ERRNO; 1407 | else if (uMagic!=0x04034b50) 1408 | err=UNZ_BADZIPFILE; 1409 | } 1410 | 1411 | if (unz64local_getShort(&s->z_filefunc, s->filestream,&uData) != UNZ_OK) 1412 | err=UNZ_ERRNO; 1413 | /* 1414 | else if ((err==UNZ_OK) && (uData!=s->cur_file_info.wVersion)) 1415 | err=UNZ_BADZIPFILE; 1416 | */ 1417 | if (unz64local_getShort(&s->z_filefunc, s->filestream,&uFlags) != UNZ_OK) 1418 | err=UNZ_ERRNO; 1419 | 1420 | if (unz64local_getShort(&s->z_filefunc, s->filestream,&uData) != UNZ_OK) 1421 | err=UNZ_ERRNO; 1422 | else if ((err==UNZ_OK) && (uData!=s->cur_file_info.compression_method)) 1423 | err=UNZ_BADZIPFILE; 1424 | 1425 | if ((err==UNZ_OK) && (s->cur_file_info.compression_method!=0) && 1426 | /* #ifdef HAVE_BZIP2 */ 1427 | (s->cur_file_info.compression_method!=Z_BZIP2ED) && 1428 | /* #endif */ 1429 | (s->cur_file_info.compression_method!=Z_DEFLATED)) 1430 | err=UNZ_BADZIPFILE; 1431 | 1432 | if (unz64local_getLong(&s->z_filefunc, s->filestream,&uData) != UNZ_OK) /* date/time */ 1433 | err=UNZ_ERRNO; 1434 | 1435 | if (unz64local_getLong(&s->z_filefunc, s->filestream,&uData) != UNZ_OK) /* crc */ 1436 | err=UNZ_ERRNO; 1437 | else if ((err==UNZ_OK) && (uData!=s->cur_file_info.crc) && ((uFlags & 8)==0)) 1438 | err=UNZ_BADZIPFILE; 1439 | 1440 | if (unz64local_getLong(&s->z_filefunc, s->filestream,&uData) != UNZ_OK) /* size compr */ 1441 | err=UNZ_ERRNO; 1442 | else if (uData != 0xFFFFFFFF && (err==UNZ_OK) && (uData!=s->cur_file_info.compressed_size) && ((uFlags & 8)==0)) 1443 | err=UNZ_BADZIPFILE; 1444 | 1445 | if (unz64local_getLong(&s->z_filefunc, s->filestream,&uData) != UNZ_OK) /* size uncompr */ 1446 | err=UNZ_ERRNO; 1447 | else if (uData != 0xFFFFFFFF && (err==UNZ_OK) && (uData!=s->cur_file_info.uncompressed_size) && ((uFlags & 8)==0)) 1448 | err=UNZ_BADZIPFILE; 1449 | 1450 | if (unz64local_getShort(&s->z_filefunc, s->filestream,&size_filename) != UNZ_OK) 1451 | err=UNZ_ERRNO; 1452 | else if ((err==UNZ_OK) && (size_filename!=s->cur_file_info.size_filename)) 1453 | err=UNZ_BADZIPFILE; 1454 | 1455 | *piSizeVar += (uInt)size_filename; 1456 | 1457 | if (unz64local_getShort(&s->z_filefunc, s->filestream,&size_extra_field) != UNZ_OK) 1458 | err=UNZ_ERRNO; 1459 | *poffset_local_extrafield= s->cur_file_info_internal.offset_curfile + 1460 | SIZEZIPLOCALHEADER + size_filename; 1461 | *psize_local_extrafield = (uInt)size_extra_field; 1462 | 1463 | *piSizeVar += (uInt)size_extra_field; 1464 | 1465 | return err; 1466 | } 1467 | 1468 | /* 1469 | Open for reading data the current file in the zipfile. 1470 | If there is no error and the file is opened, the return value is UNZ_OK. 1471 | */ 1472 | extern int ZEXPORT unzOpenCurrentFile3 (unzFile file, int* method, 1473 | int* level, int raw, const char* password) 1474 | { 1475 | int err=UNZ_OK; 1476 | uInt iSizeVar; 1477 | unz64_s* s; 1478 | file_in_zip64_read_info_s* pfile_in_zip_read_info; 1479 | ZPOS64_T offset_local_extrafield; /* offset of the local extra field */ 1480 | uInt size_local_extrafield; /* size of the local extra field */ 1481 | # ifndef NOUNCRYPT 1482 | char source[12]; 1483 | # else 1484 | if (password != NULL) 1485 | return UNZ_PARAMERROR; 1486 | # endif 1487 | 1488 | if (file==NULL) 1489 | return UNZ_PARAMERROR; 1490 | s=(unz64_s*)file; 1491 | if (!s->current_file_ok) 1492 | return UNZ_PARAMERROR; 1493 | 1494 | if (s->pfile_in_zip_read != NULL) 1495 | unzCloseCurrentFile(file); 1496 | 1497 | if (unz64local_CheckCurrentFileCoherencyHeader(s,&iSizeVar, &offset_local_extrafield,&size_local_extrafield)!=UNZ_OK) 1498 | return UNZ_BADZIPFILE; 1499 | 1500 | pfile_in_zip_read_info = (file_in_zip64_read_info_s*)ALLOC(sizeof(file_in_zip64_read_info_s)); 1501 | if (pfile_in_zip_read_info==NULL) 1502 | return UNZ_INTERNALERROR; 1503 | 1504 | pfile_in_zip_read_info->read_buffer=(char*)ALLOC(UNZ_BUFSIZE); 1505 | pfile_in_zip_read_info->offset_local_extrafield = offset_local_extrafield; 1506 | pfile_in_zip_read_info->size_local_extrafield = size_local_extrafield; 1507 | pfile_in_zip_read_info->pos_local_extrafield=0; 1508 | pfile_in_zip_read_info->raw=raw; 1509 | 1510 | if (pfile_in_zip_read_info->read_buffer==NULL) 1511 | { 1512 | TRYFREE(pfile_in_zip_read_info); 1513 | return UNZ_INTERNALERROR; 1514 | } 1515 | 1516 | pfile_in_zip_read_info->stream_initialised=0; 1517 | 1518 | if (method!=NULL) 1519 | *method = (int)s->cur_file_info.compression_method; 1520 | 1521 | if (level!=NULL) 1522 | { 1523 | *level = 6; 1524 | switch (s->cur_file_info.flag & 0x06) 1525 | { 1526 | case 6 : *level = 1; break; 1527 | case 4 : *level = 2; break; 1528 | case 2 : *level = 9; break; 1529 | } 1530 | } 1531 | 1532 | if ((s->cur_file_info.compression_method!=0) && 1533 | /* #ifdef HAVE_BZIP2 */ 1534 | (s->cur_file_info.compression_method!=Z_BZIP2ED) && 1535 | /* #endif */ 1536 | (s->cur_file_info.compression_method!=Z_DEFLATED)) 1537 | 1538 | err=UNZ_BADZIPFILE; 1539 | 1540 | pfile_in_zip_read_info->crc32_wait=s->cur_file_info.crc; 1541 | pfile_in_zip_read_info->crc32=0; 1542 | pfile_in_zip_read_info->total_out_64=0; 1543 | pfile_in_zip_read_info->compression_method = s->cur_file_info.compression_method; 1544 | pfile_in_zip_read_info->filestream=s->filestream; 1545 | pfile_in_zip_read_info->z_filefunc=s->z_filefunc; 1546 | pfile_in_zip_read_info->byte_before_the_zipfile=s->byte_before_the_zipfile; 1547 | 1548 | pfile_in_zip_read_info->stream.total_out = 0; 1549 | 1550 | if ((s->cur_file_info.compression_method==Z_BZIP2ED) && (!raw)) 1551 | { 1552 | #ifdef HAVE_BZIP2 1553 | pfile_in_zip_read_info->bstream.bzalloc = (void *(*) (void *, int, int))0; 1554 | pfile_in_zip_read_info->bstream.bzfree = (free_func)0; 1555 | pfile_in_zip_read_info->bstream.opaque = (voidpf)0; 1556 | pfile_in_zip_read_info->bstream.state = (voidpf)0; 1557 | 1558 | pfile_in_zip_read_info->stream.zalloc = (alloc_func)0; 1559 | pfile_in_zip_read_info->stream.zfree = (free_func)0; 1560 | pfile_in_zip_read_info->stream.opaque = (voidpf)0; 1561 | pfile_in_zip_read_info->stream.next_in = (voidpf)0; 1562 | pfile_in_zip_read_info->stream.avail_in = 0; 1563 | 1564 | err=BZ2_bzDecompressInit(&pfile_in_zip_read_info->bstream, 0, 0); 1565 | if (err == Z_OK) 1566 | pfile_in_zip_read_info->stream_initialised=Z_BZIP2ED; 1567 | else 1568 | { 1569 | TRYFREE(pfile_in_zip_read_info); 1570 | return err; 1571 | } 1572 | #else 1573 | pfile_in_zip_read_info->raw=1; 1574 | #endif 1575 | } 1576 | else if ((s->cur_file_info.compression_method==Z_DEFLATED) && (!raw)) 1577 | { 1578 | pfile_in_zip_read_info->stream.zalloc = (alloc_func)0; 1579 | pfile_in_zip_read_info->stream.zfree = (free_func)0; 1580 | pfile_in_zip_read_info->stream.opaque = (voidpf)0; 1581 | pfile_in_zip_read_info->stream.next_in = 0; 1582 | pfile_in_zip_read_info->stream.avail_in = 0; 1583 | 1584 | err=inflateInit2(&pfile_in_zip_read_info->stream, -MAX_WBITS); 1585 | if (err == Z_OK) 1586 | pfile_in_zip_read_info->stream_initialised=Z_DEFLATED; 1587 | else 1588 | { 1589 | TRYFREE(pfile_in_zip_read_info); 1590 | return err; 1591 | } 1592 | /* windowBits is passed < 0 to tell that there is no zlib header. 1593 | * Note that in this case inflate *requires* an extra "dummy" byte 1594 | * after the compressed stream in order to complete decompression and 1595 | * return Z_STREAM_END. 1596 | * In unzip, i don't wait absolutely Z_STREAM_END because I known the 1597 | * size of both compressed and uncompressed data 1598 | */ 1599 | } 1600 | pfile_in_zip_read_info->rest_read_compressed = 1601 | s->cur_file_info.compressed_size ; 1602 | pfile_in_zip_read_info->rest_read_uncompressed = 1603 | s->cur_file_info.uncompressed_size ; 1604 | 1605 | 1606 | pfile_in_zip_read_info->pos_in_zipfile = 1607 | s->cur_file_info_internal.offset_curfile + SIZEZIPLOCALHEADER + 1608 | iSizeVar; 1609 | 1610 | pfile_in_zip_read_info->stream.avail_in = (uInt)0; 1611 | 1612 | s->pfile_in_zip_read = pfile_in_zip_read_info; 1613 | s->encrypted = 0; 1614 | 1615 | # ifndef NOUNCRYPT 1616 | if (password != NULL) 1617 | { 1618 | int i; 1619 | s->pcrc_32_tab = get_crc_table(); 1620 | init_keys(password,s->keys,s->pcrc_32_tab); 1621 | if (ZSEEK64(s->z_filefunc, s->filestream, 1622 | s->pfile_in_zip_read->pos_in_zipfile + 1623 | s->pfile_in_zip_read->byte_before_the_zipfile, 1624 | SEEK_SET)!=0) 1625 | return UNZ_INTERNALERROR; 1626 | if(ZREAD64(s->z_filefunc, s->filestream,source, 12)<12) 1627 | return UNZ_INTERNALERROR; 1628 | 1629 | for (i = 0; i<12; i++) 1630 | zdecode(s->keys,s->pcrc_32_tab,source[i]); 1631 | 1632 | s->pfile_in_zip_read->pos_in_zipfile+=12; 1633 | s->encrypted=1; 1634 | } 1635 | # endif 1636 | 1637 | 1638 | return UNZ_OK; 1639 | } 1640 | 1641 | extern int ZEXPORT unzOpenCurrentFile (unzFile file) 1642 | { 1643 | return unzOpenCurrentFile3(file, NULL, NULL, 0, NULL); 1644 | } 1645 | 1646 | extern int ZEXPORT unzOpenCurrentFilePassword (unzFile file, const char* password) 1647 | { 1648 | return unzOpenCurrentFile3(file, NULL, NULL, 0, password); 1649 | } 1650 | 1651 | extern int ZEXPORT unzOpenCurrentFile2 (unzFile file, int* method, int* level, int raw) 1652 | { 1653 | return unzOpenCurrentFile3(file, method, level, raw, NULL); 1654 | } 1655 | 1656 | /** Addition for GDAL : START */ 1657 | 1658 | extern ZPOS64_T ZEXPORT unzGetCurrentFileZStreamPos64( unzFile file) 1659 | { 1660 | unz64_s* s; 1661 | file_in_zip64_read_info_s* pfile_in_zip_read_info; 1662 | s=(unz64_s*)file; 1663 | if (file==NULL) 1664 | return 0; //UNZ_PARAMERROR; 1665 | pfile_in_zip_read_info=s->pfile_in_zip_read; 1666 | if (pfile_in_zip_read_info==NULL) 1667 | return 0; //UNZ_PARAMERROR; 1668 | return pfile_in_zip_read_info->pos_in_zipfile + 1669 | pfile_in_zip_read_info->byte_before_the_zipfile; 1670 | } 1671 | 1672 | /** Addition for GDAL : END */ 1673 | 1674 | /* 1675 | Read bytes from the current file. 1676 | buf contain buffer where data must be copied 1677 | len the size of buf. 1678 | 1679 | return the number of byte copied if somes bytes are copied 1680 | return 0 if the end of file was reached 1681 | return <0 with error code if there is an error 1682 | (UNZ_ERRNO for IO error, or zLib error for uncompress error) 1683 | */ 1684 | extern int ZEXPORT unzReadCurrentFile (unzFile file, voidp buf, unsigned len) 1685 | { 1686 | int err=UNZ_OK; 1687 | uInt iRead = 0; 1688 | unz64_s* s; 1689 | file_in_zip64_read_info_s* pfile_in_zip_read_info; 1690 | if (file==NULL) 1691 | return UNZ_PARAMERROR; 1692 | s=(unz64_s*)file; 1693 | pfile_in_zip_read_info=s->pfile_in_zip_read; 1694 | 1695 | if (pfile_in_zip_read_info==NULL) 1696 | return UNZ_PARAMERROR; 1697 | 1698 | 1699 | if (pfile_in_zip_read_info->read_buffer == NULL) 1700 | return UNZ_END_OF_LIST_OF_FILE; 1701 | if (len==0) 1702 | return 0; 1703 | 1704 | pfile_in_zip_read_info->stream.next_out = (Bytef*)buf; 1705 | 1706 | pfile_in_zip_read_info->stream.avail_out = (uInt)len; 1707 | 1708 | if ((len>pfile_in_zip_read_info->rest_read_uncompressed) && 1709 | (!(pfile_in_zip_read_info->raw))) 1710 | pfile_in_zip_read_info->stream.avail_out = 1711 | (uInt)pfile_in_zip_read_info->rest_read_uncompressed; 1712 | 1713 | if ((len>pfile_in_zip_read_info->rest_read_compressed+ 1714 | pfile_in_zip_read_info->stream.avail_in) && 1715 | (pfile_in_zip_read_info->raw)) 1716 | pfile_in_zip_read_info->stream.avail_out = 1717 | (uInt)pfile_in_zip_read_info->rest_read_compressed+ 1718 | pfile_in_zip_read_info->stream.avail_in; 1719 | 1720 | while (pfile_in_zip_read_info->stream.avail_out>0) 1721 | { 1722 | if ((pfile_in_zip_read_info->stream.avail_in==0) && 1723 | (pfile_in_zip_read_info->rest_read_compressed>0)) 1724 | { 1725 | uInt uReadThis = UNZ_BUFSIZE; 1726 | if (pfile_in_zip_read_info->rest_read_compressedrest_read_compressed; 1728 | if (uReadThis == 0) 1729 | return UNZ_EOF; 1730 | if (ZSEEK64(pfile_in_zip_read_info->z_filefunc, 1731 | pfile_in_zip_read_info->filestream, 1732 | pfile_in_zip_read_info->pos_in_zipfile + 1733 | pfile_in_zip_read_info->byte_before_the_zipfile, 1734 | ZLIB_FILEFUNC_SEEK_SET)!=0) 1735 | return UNZ_ERRNO; 1736 | if (ZREAD64(pfile_in_zip_read_info->z_filefunc, 1737 | pfile_in_zip_read_info->filestream, 1738 | pfile_in_zip_read_info->read_buffer, 1739 | uReadThis)!=uReadThis) 1740 | return UNZ_ERRNO; 1741 | 1742 | 1743 | # ifndef NOUNCRYPT 1744 | if(s->encrypted) 1745 | { 1746 | uInt i; 1747 | for(i=0;iread_buffer[i] = 1749 | zdecode(s->keys,s->pcrc_32_tab, 1750 | pfile_in_zip_read_info->read_buffer[i]); 1751 | } 1752 | # endif 1753 | 1754 | 1755 | pfile_in_zip_read_info->pos_in_zipfile += uReadThis; 1756 | 1757 | pfile_in_zip_read_info->rest_read_compressed-=uReadThis; 1758 | 1759 | pfile_in_zip_read_info->stream.next_in = 1760 | (Bytef*)pfile_in_zip_read_info->read_buffer; 1761 | pfile_in_zip_read_info->stream.avail_in = (uInt)uReadThis; 1762 | } 1763 | 1764 | if ((pfile_in_zip_read_info->compression_method==0) || (pfile_in_zip_read_info->raw)) 1765 | { 1766 | uInt uDoCopy,i ; 1767 | 1768 | if ((pfile_in_zip_read_info->stream.avail_in == 0) && 1769 | (pfile_in_zip_read_info->rest_read_compressed == 0)) 1770 | return (iRead==0) ? UNZ_EOF : iRead; 1771 | 1772 | if (pfile_in_zip_read_info->stream.avail_out < 1773 | pfile_in_zip_read_info->stream.avail_in) 1774 | uDoCopy = pfile_in_zip_read_info->stream.avail_out ; 1775 | else 1776 | uDoCopy = pfile_in_zip_read_info->stream.avail_in ; 1777 | 1778 | for (i=0;istream.next_out+i) = 1780 | *(pfile_in_zip_read_info->stream.next_in+i); 1781 | 1782 | pfile_in_zip_read_info->total_out_64 = pfile_in_zip_read_info->total_out_64 + uDoCopy; 1783 | 1784 | pfile_in_zip_read_info->crc32 = crc32(pfile_in_zip_read_info->crc32, 1785 | pfile_in_zip_read_info->stream.next_out, 1786 | uDoCopy); 1787 | pfile_in_zip_read_info->rest_read_uncompressed-=uDoCopy; 1788 | pfile_in_zip_read_info->stream.avail_in -= uDoCopy; 1789 | pfile_in_zip_read_info->stream.avail_out -= uDoCopy; 1790 | pfile_in_zip_read_info->stream.next_out += uDoCopy; 1791 | pfile_in_zip_read_info->stream.next_in += uDoCopy; 1792 | pfile_in_zip_read_info->stream.total_out += uDoCopy; 1793 | iRead += uDoCopy; 1794 | } 1795 | else if (pfile_in_zip_read_info->compression_method==Z_BZIP2ED) 1796 | { 1797 | #ifdef HAVE_BZIP2 1798 | uLong uTotalOutBefore,uTotalOutAfter; 1799 | const Bytef *bufBefore; 1800 | uLong uOutThis; 1801 | 1802 | pfile_in_zip_read_info->bstream.next_in = (char*)pfile_in_zip_read_info->stream.next_in; 1803 | pfile_in_zip_read_info->bstream.avail_in = pfile_in_zip_read_info->stream.avail_in; 1804 | pfile_in_zip_read_info->bstream.total_in_lo32 = pfile_in_zip_read_info->stream.total_in; 1805 | pfile_in_zip_read_info->bstream.total_in_hi32 = 0; 1806 | pfile_in_zip_read_info->bstream.next_out = (char*)pfile_in_zip_read_info->stream.next_out; 1807 | pfile_in_zip_read_info->bstream.avail_out = pfile_in_zip_read_info->stream.avail_out; 1808 | pfile_in_zip_read_info->bstream.total_out_lo32 = pfile_in_zip_read_info->stream.total_out; 1809 | pfile_in_zip_read_info->bstream.total_out_hi32 = 0; 1810 | 1811 | uTotalOutBefore = pfile_in_zip_read_info->bstream.total_out_lo32; 1812 | bufBefore = (const Bytef *)pfile_in_zip_read_info->bstream.next_out; 1813 | 1814 | err=BZ2_bzDecompress(&pfile_in_zip_read_info->bstream); 1815 | 1816 | uTotalOutAfter = pfile_in_zip_read_info->bstream.total_out_lo32; 1817 | uOutThis = uTotalOutAfter-uTotalOutBefore; 1818 | 1819 | pfile_in_zip_read_info->total_out_64 = pfile_in_zip_read_info->total_out_64 + uOutThis; 1820 | 1821 | pfile_in_zip_read_info->crc32 = crc32(pfile_in_zip_read_info->crc32,bufBefore, (uInt)(uOutThis)); 1822 | pfile_in_zip_read_info->rest_read_uncompressed -= uOutThis; 1823 | iRead += (uInt)(uTotalOutAfter - uTotalOutBefore); 1824 | 1825 | pfile_in_zip_read_info->stream.next_in = (Bytef*)pfile_in_zip_read_info->bstream.next_in; 1826 | pfile_in_zip_read_info->stream.avail_in = pfile_in_zip_read_info->bstream.avail_in; 1827 | pfile_in_zip_read_info->stream.total_in = pfile_in_zip_read_info->bstream.total_in_lo32; 1828 | pfile_in_zip_read_info->stream.next_out = (Bytef*)pfile_in_zip_read_info->bstream.next_out; 1829 | pfile_in_zip_read_info->stream.avail_out = pfile_in_zip_read_info->bstream.avail_out; 1830 | pfile_in_zip_read_info->stream.total_out = pfile_in_zip_read_info->bstream.total_out_lo32; 1831 | 1832 | if (err==BZ_STREAM_END) 1833 | return (iRead==0) ? UNZ_EOF : iRead; 1834 | if (err!=BZ_OK) 1835 | break; 1836 | #endif 1837 | } // end Z_BZIP2ED 1838 | else 1839 | { 1840 | ZPOS64_T uTotalOutBefore,uTotalOutAfter; 1841 | const Bytef *bufBefore; 1842 | ZPOS64_T uOutThis; 1843 | int flush=Z_SYNC_FLUSH; 1844 | 1845 | uTotalOutBefore = pfile_in_zip_read_info->stream.total_out; 1846 | bufBefore = pfile_in_zip_read_info->stream.next_out; 1847 | 1848 | /* 1849 | if ((pfile_in_zip_read_info->rest_read_uncompressed == 1850 | pfile_in_zip_read_info->stream.avail_out) && 1851 | (pfile_in_zip_read_info->rest_read_compressed == 0)) 1852 | flush = Z_FINISH; 1853 | */ 1854 | err=inflate(&pfile_in_zip_read_info->stream,flush); 1855 | 1856 | if ((err>=0) && (pfile_in_zip_read_info->stream.msg!=NULL)) 1857 | err = Z_DATA_ERROR; 1858 | 1859 | uTotalOutAfter = pfile_in_zip_read_info->stream.total_out; 1860 | uOutThis = uTotalOutAfter-uTotalOutBefore; 1861 | 1862 | pfile_in_zip_read_info->total_out_64 = pfile_in_zip_read_info->total_out_64 + uOutThis; 1863 | 1864 | pfile_in_zip_read_info->crc32 = 1865 | crc32(pfile_in_zip_read_info->crc32,bufBefore, 1866 | (uInt)(uOutThis)); 1867 | 1868 | pfile_in_zip_read_info->rest_read_uncompressed -= 1869 | uOutThis; 1870 | 1871 | iRead += (uInt)(uTotalOutAfter - uTotalOutBefore); 1872 | 1873 | if (err==Z_STREAM_END) 1874 | return (iRead==0) ? UNZ_EOF : iRead; 1875 | if (err!=Z_OK) 1876 | break; 1877 | } 1878 | } 1879 | 1880 | if (err==Z_OK) 1881 | return iRead; 1882 | return err; 1883 | } 1884 | 1885 | 1886 | /* 1887 | Give the current position in uncompressed data 1888 | */ 1889 | extern z_off_t ZEXPORT unztell (unzFile file) 1890 | { 1891 | unz64_s* s; 1892 | file_in_zip64_read_info_s* pfile_in_zip_read_info; 1893 | if (file==NULL) 1894 | return UNZ_PARAMERROR; 1895 | s=(unz64_s*)file; 1896 | pfile_in_zip_read_info=s->pfile_in_zip_read; 1897 | 1898 | if (pfile_in_zip_read_info==NULL) 1899 | return UNZ_PARAMERROR; 1900 | 1901 | return (z_off_t)pfile_in_zip_read_info->stream.total_out; 1902 | } 1903 | 1904 | extern ZPOS64_T ZEXPORT unztell64 (unzFile file) 1905 | { 1906 | 1907 | unz64_s* s; 1908 | file_in_zip64_read_info_s* pfile_in_zip_read_info; 1909 | if (file==NULL) 1910 | return (ZPOS64_T)-1; 1911 | s=(unz64_s*)file; 1912 | pfile_in_zip_read_info=s->pfile_in_zip_read; 1913 | 1914 | if (pfile_in_zip_read_info==NULL) 1915 | return (ZPOS64_T)-1; 1916 | 1917 | return pfile_in_zip_read_info->total_out_64; 1918 | } 1919 | 1920 | 1921 | /* 1922 | return 1 if the end of file was reached, 0 elsewhere 1923 | */ 1924 | extern int ZEXPORT unzeof (unzFile file) 1925 | { 1926 | unz64_s* s; 1927 | file_in_zip64_read_info_s* pfile_in_zip_read_info; 1928 | if (file==NULL) 1929 | return UNZ_PARAMERROR; 1930 | s=(unz64_s*)file; 1931 | pfile_in_zip_read_info=s->pfile_in_zip_read; 1932 | 1933 | if (pfile_in_zip_read_info==NULL) 1934 | return UNZ_PARAMERROR; 1935 | 1936 | if (pfile_in_zip_read_info->rest_read_uncompressed == 0) 1937 | return 1; 1938 | else 1939 | return 0; 1940 | } 1941 | 1942 | 1943 | 1944 | /* 1945 | Read extra field from the current file (opened by unzOpenCurrentFile) 1946 | This is the local-header version of the extra field (sometimes, there is 1947 | more info in the local-header version than in the central-header) 1948 | 1949 | if buf==NULL, it return the size of the local extra field that can be read 1950 | 1951 | if buf!=NULL, len is the size of the buffer, the extra header is copied in 1952 | buf. 1953 | the return value is the number of bytes copied in buf, or (if <0) 1954 | the error code 1955 | */ 1956 | extern int ZEXPORT unzGetLocalExtrafield (unzFile file, voidp buf, unsigned len) 1957 | { 1958 | unz64_s* s; 1959 | file_in_zip64_read_info_s* pfile_in_zip_read_info; 1960 | uInt read_now; 1961 | ZPOS64_T size_to_read; 1962 | 1963 | if (file==NULL) 1964 | return UNZ_PARAMERROR; 1965 | s=(unz64_s*)file; 1966 | pfile_in_zip_read_info=s->pfile_in_zip_read; 1967 | 1968 | if (pfile_in_zip_read_info==NULL) 1969 | return UNZ_PARAMERROR; 1970 | 1971 | size_to_read = (pfile_in_zip_read_info->size_local_extrafield - 1972 | pfile_in_zip_read_info->pos_local_extrafield); 1973 | 1974 | if (buf==NULL) 1975 | return (int)size_to_read; 1976 | 1977 | if (len>size_to_read) 1978 | read_now = (uInt)size_to_read; 1979 | else 1980 | read_now = (uInt)len ; 1981 | 1982 | if (read_now==0) 1983 | return 0; 1984 | 1985 | if (ZSEEK64(pfile_in_zip_read_info->z_filefunc, 1986 | pfile_in_zip_read_info->filestream, 1987 | pfile_in_zip_read_info->offset_local_extrafield + 1988 | pfile_in_zip_read_info->pos_local_extrafield, 1989 | ZLIB_FILEFUNC_SEEK_SET)!=0) 1990 | return UNZ_ERRNO; 1991 | 1992 | if (ZREAD64(pfile_in_zip_read_info->z_filefunc, 1993 | pfile_in_zip_read_info->filestream, 1994 | buf,read_now)!=read_now) 1995 | return UNZ_ERRNO; 1996 | 1997 | return (int)read_now; 1998 | } 1999 | 2000 | /* 2001 | Close the file in zip opened with unzOpenCurrentFile 2002 | Return UNZ_CRCERROR if all the file was read but the CRC is not good 2003 | */ 2004 | extern int ZEXPORT unzCloseCurrentFile (unzFile file) 2005 | { 2006 | int err=UNZ_OK; 2007 | 2008 | unz64_s* s; 2009 | file_in_zip64_read_info_s* pfile_in_zip_read_info; 2010 | if (file==NULL) 2011 | return UNZ_PARAMERROR; 2012 | s=(unz64_s*)file; 2013 | pfile_in_zip_read_info=s->pfile_in_zip_read; 2014 | 2015 | if (pfile_in_zip_read_info==NULL) 2016 | return UNZ_PARAMERROR; 2017 | 2018 | 2019 | if ((pfile_in_zip_read_info->rest_read_uncompressed == 0) && 2020 | (!pfile_in_zip_read_info->raw)) 2021 | { 2022 | if (pfile_in_zip_read_info->crc32 != pfile_in_zip_read_info->crc32_wait) 2023 | err=UNZ_CRCERROR; 2024 | } 2025 | 2026 | 2027 | TRYFREE(pfile_in_zip_read_info->read_buffer); 2028 | pfile_in_zip_read_info->read_buffer = NULL; 2029 | if (pfile_in_zip_read_info->stream_initialised == Z_DEFLATED) 2030 | inflateEnd(&pfile_in_zip_read_info->stream); 2031 | #ifdef HAVE_BZIP2 2032 | else if (pfile_in_zip_read_info->stream_initialised == Z_BZIP2ED) 2033 | BZ2_bzDecompressEnd(&pfile_in_zip_read_info->bstream); 2034 | #endif 2035 | 2036 | 2037 | pfile_in_zip_read_info->stream_initialised = 0; 2038 | TRYFREE(pfile_in_zip_read_info); 2039 | 2040 | s->pfile_in_zip_read=NULL; 2041 | 2042 | return err; 2043 | } 2044 | 2045 | 2046 | /* 2047 | Get the global comment string of the ZipFile, in the szComment buffer. 2048 | uSizeBuf is the size of the szComment buffer. 2049 | return the number of byte copied or an error code <0 2050 | */ 2051 | extern int ZEXPORT unzGetGlobalComment (unzFile file, char * szComment, uLong uSizeBuf) 2052 | { 2053 | unz64_s* s; 2054 | uLong uReadThis ; 2055 | if (file==NULL) 2056 | return (int)UNZ_PARAMERROR; 2057 | s=(unz64_s*)file; 2058 | 2059 | uReadThis = uSizeBuf; 2060 | if (uReadThis>s->gi.size_comment) 2061 | uReadThis = s->gi.size_comment; 2062 | 2063 | if (ZSEEK64(s->z_filefunc,s->filestream,s->central_pos+22,ZLIB_FILEFUNC_SEEK_SET)!=0) 2064 | return UNZ_ERRNO; 2065 | 2066 | if (uReadThis>0) 2067 | { 2068 | *szComment='\0'; 2069 | if (ZREAD64(s->z_filefunc,s->filestream,szComment,uReadThis)!=uReadThis) 2070 | return UNZ_ERRNO; 2071 | } 2072 | 2073 | if ((szComment != NULL) && (uSizeBuf > s->gi.size_comment)) 2074 | *(szComment+s->gi.size_comment)='\0'; 2075 | return (int)uReadThis; 2076 | } 2077 | 2078 | /* Additions by RX '2004 */ 2079 | extern ZPOS64_T ZEXPORT unzGetOffset64(unzFile file) 2080 | { 2081 | unz64_s* s; 2082 | 2083 | if (file==NULL) 2084 | return 0; //UNZ_PARAMERROR; 2085 | s=(unz64_s*)file; 2086 | if (!s->current_file_ok) 2087 | return 0; 2088 | if (s->gi.number_entry != 0 && s->gi.number_entry != 0xffff) 2089 | if (s->num_file==s->gi.number_entry) 2090 | return 0; 2091 | return s->pos_in_central_dir; 2092 | } 2093 | 2094 | extern uLong ZEXPORT unzGetOffset (unzFile file) 2095 | { 2096 | ZPOS64_T offset64; 2097 | 2098 | if (file==NULL) 2099 | return 0; //UNZ_PARAMERROR; 2100 | offset64 = unzGetOffset64(file); 2101 | return (uLong)offset64; 2102 | } 2103 | 2104 | extern int ZEXPORT unzSetOffset64(unzFile file, ZPOS64_T pos) 2105 | { 2106 | unz64_s* s; 2107 | int err; 2108 | 2109 | if (file==NULL) 2110 | return UNZ_PARAMERROR; 2111 | s=(unz64_s*)file; 2112 | 2113 | s->pos_in_central_dir = pos; 2114 | s->num_file = s->gi.number_entry; /* hack */ 2115 | err = unz64local_GetCurrentFileInfoInternal(file,&s->cur_file_info, 2116 | &s->cur_file_info_internal, 2117 | NULL,0,NULL,0,NULL,0); 2118 | s->current_file_ok = (err == UNZ_OK); 2119 | return err; 2120 | } 2121 | 2122 | extern int ZEXPORT unzSetOffset (unzFile file, uLong pos) 2123 | { 2124 | return unzSetOffset64(file,pos); 2125 | } 2126 | -------------------------------------------------------------------------------- /ApkProtection/src/zlib/unzip.h: -------------------------------------------------------------------------------- 1 | /* unzip.h -- IO for uncompress .zip files using zlib 2 | Version 1.1, February 14h, 2010 3 | part of the MiniZip project - ( http://www.winimage.com/zLibDll/minizip.html ) 4 | 5 | Copyright (C) 1998-2010 Gilles Vollant (minizip) ( http://www.winimage.com/zLibDll/minizip.html ) 6 | 7 | Modifications of Unzip for Zip64 8 | Copyright (C) 2007-2008 Even Rouault 9 | 10 | Modifications for Zip64 support on both zip and unzip 11 | Copyright (C) 2009-2010 Mathias Svensson ( http://result42.com ) 12 | 13 | For more info read MiniZip_info.txt 14 | 15 | --------------------------------------------------------------------------------- 16 | 17 | Condition of use and distribution are the same than zlib : 18 | 19 | This software is provided 'as-is', without any express or implied 20 | warranty. In no event will the authors be held liable for any damages 21 | arising from the use of this software. 22 | 23 | Permission is granted to anyone to use this software for any purpose, 24 | including commercial applications, and to alter it and redistribute it 25 | freely, subject to the following restrictions: 26 | 27 | 1. The origin of this software must not be misrepresented; you must not 28 | claim that you wrote the original software. If you use this software 29 | in a product, an acknowledgment in the product documentation would be 30 | appreciated but is not required. 31 | 2. Altered source versions must be plainly marked as such, and must not be 32 | misrepresented as being the original software. 33 | 3. This notice may not be removed or altered from any source distribution. 34 | 35 | --------------------------------------------------------------------------------- 36 | 37 | Changes 38 | 39 | See header of unzip64.c 40 | 41 | */ 42 | 43 | #ifndef _unz64_H 44 | #define _unz64_H 45 | 46 | #ifdef __cplusplus 47 | extern "C" { 48 | #endif 49 | 50 | #ifndef _ZLIB_H 51 | #include "zlib.h" 52 | #endif 53 | 54 | #ifndef _ZLIBIOAPI_H 55 | #include "ioapi.h" 56 | #endif 57 | 58 | #ifdef HAVE_BZIP2 59 | #include "bzlib.h" 60 | #endif 61 | 62 | #define Z_BZIP2ED 12 63 | 64 | #if defined(STRICTUNZIP) || defined(STRICTZIPUNZIP) 65 | /* like the STRICT of WIN32, we define a pointer that cannot be converted 66 | from (void*) without cast */ 67 | typedef struct TagunzFile__ { int unused; } unzFile__; 68 | typedef unzFile__ *unzFile; 69 | #else 70 | typedef voidp unzFile; 71 | #endif 72 | 73 | 74 | #define UNZ_OK (0) 75 | #define UNZ_END_OF_LIST_OF_FILE (-100) 76 | #define UNZ_ERRNO (Z_ERRNO) 77 | #define UNZ_EOF (0) 78 | #define UNZ_PARAMERROR (-102) 79 | #define UNZ_BADZIPFILE (-103) 80 | #define UNZ_INTERNALERROR (-104) 81 | #define UNZ_CRCERROR (-105) 82 | 83 | /* tm_unz contain date/time info */ 84 | typedef struct tm_unz_s 85 | { 86 | uInt tm_sec; /* seconds after the minute - [0,59] */ 87 | uInt tm_min; /* minutes after the hour - [0,59] */ 88 | uInt tm_hour; /* hours since midnight - [0,23] */ 89 | uInt tm_mday; /* day of the month - [1,31] */ 90 | uInt tm_mon; /* months since January - [0,11] */ 91 | uInt tm_year; /* years - [1980..2044] */ 92 | } tm_unz; 93 | 94 | /* unz_global_info structure contain global data about the ZIPfile 95 | These data comes from the end of central dir */ 96 | typedef struct unz_global_info64_s 97 | { 98 | ZPOS64_T number_entry; /* total number of entries in 99 | the central dir on this disk */ 100 | uLong size_comment; /* size of the global comment of the zipfile */ 101 | } unz_global_info64; 102 | 103 | typedef struct unz_global_info_s 104 | { 105 | uLong number_entry; /* total number of entries in 106 | the central dir on this disk */ 107 | uLong size_comment; /* size of the global comment of the zipfile */ 108 | } unz_global_info; 109 | 110 | /* unz_file_info contain information about a file in the zipfile */ 111 | typedef struct unz_file_info64_s 112 | { 113 | uLong version; /* version made by 2 bytes */ 114 | uLong version_needed; /* version needed to extract 2 bytes */ 115 | uLong flag; /* general purpose bit flag 2 bytes */ 116 | uLong compression_method; /* compression method 2 bytes */ 117 | uLong dosDate; /* last mod file date in Dos fmt 4 bytes */ 118 | uLong crc; /* crc-32 4 bytes */ 119 | ZPOS64_T compressed_size; /* compressed size 8 bytes */ 120 | ZPOS64_T uncompressed_size; /* uncompressed size 8 bytes */ 121 | uLong size_filename; /* filename length 2 bytes */ 122 | uLong size_file_extra; /* extra field length 2 bytes */ 123 | uLong size_file_comment; /* file comment length 2 bytes */ 124 | 125 | uLong disk_num_start; /* disk number start 2 bytes */ 126 | uLong internal_fa; /* internal file attributes 2 bytes */ 127 | uLong external_fa; /* external file attributes 4 bytes */ 128 | 129 | tm_unz tmu_date; 130 | } unz_file_info64; 131 | 132 | typedef struct unz_file_info_s 133 | { 134 | uLong version; /* version made by 2 bytes */ 135 | uLong version_needed; /* version needed to extract 2 bytes */ 136 | uLong flag; /* general purpose bit flag 2 bytes */ 137 | uLong compression_method; /* compression method 2 bytes */ 138 | uLong dosDate; /* last mod file date in Dos fmt 4 bytes */ 139 | uLong crc; /* crc-32 4 bytes */ 140 | uLong compressed_size; /* compressed size 4 bytes */ 141 | uLong uncompressed_size; /* uncompressed size 4 bytes */ 142 | uLong size_filename; /* filename length 2 bytes */ 143 | uLong size_file_extra; /* extra field length 2 bytes */ 144 | uLong size_file_comment; /* file comment length 2 bytes */ 145 | 146 | uLong disk_num_start; /* disk number start 2 bytes */ 147 | uLong internal_fa; /* internal file attributes 2 bytes */ 148 | uLong external_fa; /* external file attributes 4 bytes */ 149 | 150 | tm_unz tmu_date; 151 | } unz_file_info; 152 | 153 | extern int ZEXPORT unzStringFileNameCompare OF ((const char* fileName1, 154 | const char* fileName2, 155 | int iCaseSensitivity)); 156 | /* 157 | Compare two filename (fileName1,fileName2). 158 | If iCaseSenisivity = 1, comparision is case sensitivity (like strcmp) 159 | If iCaseSenisivity = 2, comparision is not case sensitivity (like strcmpi 160 | or strcasecmp) 161 | If iCaseSenisivity = 0, case sensitivity is defaut of your operating system 162 | (like 1 on Unix, 2 on Windows) 163 | */ 164 | 165 | 166 | extern unzFile ZEXPORT unzOpen OF((const char *path)); 167 | extern unzFile ZEXPORT unzOpen64 OF((const void *path)); 168 | /* 169 | Open a Zip file. path contain the full pathname (by example, 170 | on a Windows XP computer "c:\\zlib\\zlib113.zip" or on an Unix computer 171 | "zlib/zlib113.zip". 172 | If the zipfile cannot be opened (file don't exist or in not valid), the 173 | return value is NULL. 174 | Else, the return value is a unzFile Handle, usable with other function 175 | of this unzip package. 176 | the "64" function take a const void* pointer, because the path is just the 177 | value passed to the open64_file_func callback. 178 | Under Windows, if UNICODE is defined, using fill_fopen64_filefunc, the path 179 | is a pointer to a wide unicode string (LPCTSTR is LPCWSTR), so const char* 180 | does not describe the reality 181 | */ 182 | 183 | 184 | extern unzFile ZEXPORT unzOpen2 OF((const char *path, 185 | zlib_filefunc_def* pzlib_filefunc_def)); 186 | /* 187 | Open a Zip file, like unzOpen, but provide a set of file low level API 188 | for read/write the zip file (see ioapi.h) 189 | */ 190 | 191 | extern unzFile ZEXPORT unzOpen2_64 OF((const void *path, 192 | zlib_filefunc64_def* pzlib_filefunc_def)); 193 | /* 194 | Open a Zip file, like unz64Open, but provide a set of file low level API 195 | for read/write the zip file (see ioapi.h) 196 | */ 197 | 198 | extern int ZEXPORT unzClose OF((unzFile file)); 199 | /* 200 | Close a ZipFile opened with unzOpen. 201 | If there is files inside the .Zip opened with unzOpenCurrentFile (see later), 202 | these files MUST be closed with unzCloseCurrentFile before call unzClose. 203 | return UNZ_OK if there is no problem. */ 204 | 205 | extern int ZEXPORT unzGetGlobalInfo OF((unzFile file, 206 | unz_global_info *pglobal_info)); 207 | 208 | extern int ZEXPORT unzGetGlobalInfo64 OF((unzFile file, 209 | unz_global_info64 *pglobal_info)); 210 | /* 211 | Write info about the ZipFile in the *pglobal_info structure. 212 | No preparation of the structure is needed 213 | return UNZ_OK if there is no problem. */ 214 | 215 | 216 | extern int ZEXPORT unzGetGlobalComment OF((unzFile file, 217 | char *szComment, 218 | uLong uSizeBuf)); 219 | /* 220 | Get the global comment string of the ZipFile, in the szComment buffer. 221 | uSizeBuf is the size of the szComment buffer. 222 | return the number of byte copied or an error code <0 223 | */ 224 | 225 | 226 | /***************************************************************************/ 227 | /* Unzip package allow you browse the directory of the zipfile */ 228 | 229 | extern int ZEXPORT unzGoToFirstFile OF((unzFile file)); 230 | /* 231 | Set the current file of the zipfile to the first file. 232 | return UNZ_OK if there is no problem 233 | */ 234 | 235 | extern int ZEXPORT unzGoToNextFile OF((unzFile file)); 236 | /* 237 | Set the current file of the zipfile to the next file. 238 | return UNZ_OK if there is no problem 239 | return UNZ_END_OF_LIST_OF_FILE if the actual file was the latest. 240 | */ 241 | 242 | extern int ZEXPORT unzLocateFile OF((unzFile file, 243 | const char *szFileName, 244 | int iCaseSensitivity)); 245 | /* 246 | Try locate the file szFileName in the zipfile. 247 | For the iCaseSensitivity signification, see unzStringFileNameCompare 248 | 249 | return value : 250 | UNZ_OK if the file is found. It becomes the current file. 251 | UNZ_END_OF_LIST_OF_FILE if the file is not found 252 | */ 253 | 254 | 255 | /* ****************************************** */ 256 | /* Ryan supplied functions */ 257 | /* unz_file_info contain information about a file in the zipfile */ 258 | typedef struct unz_file_pos_s 259 | { 260 | uLong pos_in_zip_directory; /* offset in zip file directory */ 261 | uLong num_of_file; /* # of file */ 262 | } unz_file_pos; 263 | 264 | extern int ZEXPORT unzGetFilePos( 265 | unzFile file, 266 | unz_file_pos* file_pos); 267 | 268 | extern int ZEXPORT unzGoToFilePos( 269 | unzFile file, 270 | unz_file_pos* file_pos); 271 | 272 | typedef struct unz64_file_pos_s 273 | { 274 | ZPOS64_T pos_in_zip_directory; /* offset in zip file directory */ 275 | ZPOS64_T num_of_file; /* # of file */ 276 | } unz64_file_pos; 277 | 278 | extern int ZEXPORT unzGetFilePos64( 279 | unzFile file, 280 | unz64_file_pos* file_pos); 281 | 282 | extern int ZEXPORT unzGoToFilePos64( 283 | unzFile file, 284 | const unz64_file_pos* file_pos); 285 | 286 | /* ****************************************** */ 287 | 288 | extern int ZEXPORT unzGetCurrentFileInfo64 OF((unzFile file, 289 | unz_file_info64 *pfile_info, 290 | char *szFileName, 291 | uLong fileNameBufferSize, 292 | void *extraField, 293 | uLong extraFieldBufferSize, 294 | char *szComment, 295 | uLong commentBufferSize)); 296 | 297 | extern int ZEXPORT unzGetCurrentFileInfo OF((unzFile file, 298 | unz_file_info *pfile_info, 299 | char *szFileName, 300 | uLong fileNameBufferSize, 301 | void *extraField, 302 | uLong extraFieldBufferSize, 303 | char *szComment, 304 | uLong commentBufferSize)); 305 | /* 306 | Get Info about the current file 307 | if pfile_info!=NULL, the *pfile_info structure will contain somes info about 308 | the current file 309 | if szFileName!=NULL, the filemane string will be copied in szFileName 310 | (fileNameBufferSize is the size of the buffer) 311 | if extraField!=NULL, the extra field information will be copied in extraField 312 | (extraFieldBufferSize is the size of the buffer). 313 | This is the Central-header version of the extra field 314 | if szComment!=NULL, the comment string of the file will be copied in szComment 315 | (commentBufferSize is the size of the buffer) 316 | */ 317 | 318 | 319 | /** Addition for GDAL : START */ 320 | 321 | extern ZPOS64_T ZEXPORT unzGetCurrentFileZStreamPos64 OF((unzFile file)); 322 | 323 | /** Addition for GDAL : END */ 324 | 325 | 326 | /***************************************************************************/ 327 | /* for reading the content of the current zipfile, you can open it, read data 328 | from it, and close it (you can close it before reading all the file) 329 | */ 330 | 331 | extern int ZEXPORT unzOpenCurrentFile OF((unzFile file)); 332 | /* 333 | Open for reading data the current file in the zipfile. 334 | If there is no error, the return value is UNZ_OK. 335 | */ 336 | 337 | extern int ZEXPORT unzOpenCurrentFilePassword OF((unzFile file, 338 | const char* password)); 339 | /* 340 | Open for reading data the current file in the zipfile. 341 | password is a crypting password 342 | If there is no error, the return value is UNZ_OK. 343 | */ 344 | 345 | extern int ZEXPORT unzOpenCurrentFile2 OF((unzFile file, 346 | int* method, 347 | int* level, 348 | int raw)); 349 | /* 350 | Same than unzOpenCurrentFile, but open for read raw the file (not uncompress) 351 | if raw==1 352 | *method will receive method of compression, *level will receive level of 353 | compression 354 | note : you can set level parameter as NULL (if you did not want known level, 355 | but you CANNOT set method parameter as NULL 356 | */ 357 | 358 | extern int ZEXPORT unzOpenCurrentFile3 OF((unzFile file, 359 | int* method, 360 | int* level, 361 | int raw, 362 | const char* password)); 363 | /* 364 | Same than unzOpenCurrentFile, but open for read raw the file (not uncompress) 365 | if raw==1 366 | *method will receive method of compression, *level will receive level of 367 | compression 368 | note : you can set level parameter as NULL (if you did not want known level, 369 | but you CANNOT set method parameter as NULL 370 | */ 371 | 372 | 373 | extern int ZEXPORT unzCloseCurrentFile OF((unzFile file)); 374 | /* 375 | Close the file in zip opened with unzOpenCurrentFile 376 | Return UNZ_CRCERROR if all the file was read but the CRC is not good 377 | */ 378 | 379 | extern int ZEXPORT unzReadCurrentFile OF((unzFile file, 380 | voidp buf, 381 | unsigned len)); 382 | /* 383 | Read bytes from the current file (opened by unzOpenCurrentFile) 384 | buf contain buffer where data must be copied 385 | len the size of buf. 386 | 387 | return the number of byte copied if somes bytes are copied 388 | return 0 if the end of file was reached 389 | return <0 with error code if there is an error 390 | (UNZ_ERRNO for IO error, or zLib error for uncompress error) 391 | */ 392 | 393 | extern z_off_t ZEXPORT unztell OF((unzFile file)); 394 | 395 | extern ZPOS64_T ZEXPORT unztell64 OF((unzFile file)); 396 | /* 397 | Give the current position in uncompressed data 398 | */ 399 | 400 | extern int ZEXPORT unzeof OF((unzFile file)); 401 | /* 402 | return 1 if the end of file was reached, 0 elsewhere 403 | */ 404 | 405 | extern int ZEXPORT unzGetLocalExtrafield OF((unzFile file, 406 | voidp buf, 407 | unsigned len)); 408 | /* 409 | Read extra field from the current file (opened by unzOpenCurrentFile) 410 | This is the local-header version of the extra field (sometimes, there is 411 | more info in the local-header version than in the central-header) 412 | 413 | if buf==NULL, it return the size of the local extra field 414 | 415 | if buf!=NULL, len is the size of the buffer, the extra header is copied in 416 | buf. 417 | the return value is the number of bytes copied in buf, or (if <0) 418 | the error code 419 | */ 420 | 421 | /***************************************************************************/ 422 | 423 | /* Get the current file offset */ 424 | extern ZPOS64_T ZEXPORT unzGetOffset64 (unzFile file); 425 | extern uLong ZEXPORT unzGetOffset (unzFile file); 426 | 427 | /* Set the current file offset */ 428 | extern int ZEXPORT unzSetOffset64 (unzFile file, ZPOS64_T pos); 429 | extern int ZEXPORT unzSetOffset (unzFile file, uLong pos); 430 | 431 | 432 | 433 | #ifdef __cplusplus 434 | } 435 | #endif 436 | 437 | #endif /* _unz64_H */ 438 | -------------------------------------------------------------------------------- /ApkProtection/src/zlib/zconf.h: -------------------------------------------------------------------------------- 1 | /* zconf.h -- configuration of the zlib compression library 2 | * Copyright (C) 1995-2013 Jean-loup Gailly. 3 | * For conditions of distribution and use, see copyright notice in zlib.h 4 | */ 5 | 6 | /* @(#) $Id$ */ 7 | 8 | #ifndef ZCONF_H 9 | #define ZCONF_H 10 | 11 | /* 12 | * If you *really* need a unique prefix for all types and library functions, 13 | * compile with -DZ_PREFIX. The "standard" zlib should be compiled without it. 14 | * Even better than compiling with -DZ_PREFIX would be to use configure to set 15 | * this permanently in zconf.h using "./configure --zprefix". 16 | */ 17 | #ifdef Z_PREFIX /* may be set to #if 1 by ./configure */ 18 | # define Z_PREFIX_SET 19 | 20 | /* all linked symbols */ 21 | # define _dist_code z__dist_code 22 | # define _length_code z__length_code 23 | # define _tr_align z__tr_align 24 | # define _tr_flush_bits z__tr_flush_bits 25 | # define _tr_flush_block z__tr_flush_block 26 | # define _tr_init z__tr_init 27 | # define _tr_stored_block z__tr_stored_block 28 | # define _tr_tally z__tr_tally 29 | # define adler32 z_adler32 30 | # define adler32_combine z_adler32_combine 31 | # define adler32_combine64 z_adler32_combine64 32 | # ifndef Z_SOLO 33 | # define compress z_compress 34 | # define compress2 z_compress2 35 | # define compressBound z_compressBound 36 | # endif 37 | # define crc32 z_crc32 38 | # define crc32_combine z_crc32_combine 39 | # define crc32_combine64 z_crc32_combine64 40 | # define deflate z_deflate 41 | # define deflateBound z_deflateBound 42 | # define deflateCopy z_deflateCopy 43 | # define deflateEnd z_deflateEnd 44 | # define deflateInit2_ z_deflateInit2_ 45 | # define deflateInit_ z_deflateInit_ 46 | # define deflateParams z_deflateParams 47 | # define deflatePending z_deflatePending 48 | # define deflatePrime z_deflatePrime 49 | # define deflateReset z_deflateReset 50 | # define deflateResetKeep z_deflateResetKeep 51 | # define deflateSetDictionary z_deflateSetDictionary 52 | # define deflateSetHeader z_deflateSetHeader 53 | # define deflateTune z_deflateTune 54 | # define deflate_copyright z_deflate_copyright 55 | # define get_crc_table z_get_crc_table 56 | # ifndef Z_SOLO 57 | # define gz_error z_gz_error 58 | # define gz_intmax z_gz_intmax 59 | # define gz_strwinerror z_gz_strwinerror 60 | # define gzbuffer z_gzbuffer 61 | # define gzclearerr z_gzclearerr 62 | # define gzclose z_gzclose 63 | # define gzclose_r z_gzclose_r 64 | # define gzclose_w z_gzclose_w 65 | # define gzdirect z_gzdirect 66 | # define gzdopen z_gzdopen 67 | # define gzeof z_gzeof 68 | # define gzerror z_gzerror 69 | # define gzflush z_gzflush 70 | # define gzgetc z_gzgetc 71 | # define gzgetc_ z_gzgetc_ 72 | # define gzgets z_gzgets 73 | # define gzoffset z_gzoffset 74 | # define gzoffset64 z_gzoffset64 75 | # define gzopen z_gzopen 76 | # define gzopen64 z_gzopen64 77 | # ifdef _WIN32 78 | # define gzopen_w z_gzopen_w 79 | # endif 80 | # define gzprintf z_gzprintf 81 | # define gzvprintf z_gzvprintf 82 | # define gzputc z_gzputc 83 | # define gzputs z_gzputs 84 | # define gzread z_gzread 85 | # define gzrewind z_gzrewind 86 | # define gzseek z_gzseek 87 | # define gzseek64 z_gzseek64 88 | # define gzsetparams z_gzsetparams 89 | # define gztell z_gztell 90 | # define gztell64 z_gztell64 91 | # define gzungetc z_gzungetc 92 | # define gzwrite z_gzwrite 93 | # endif 94 | # define inflate z_inflate 95 | # define inflateBack z_inflateBack 96 | # define inflateBackEnd z_inflateBackEnd 97 | # define inflateBackInit_ z_inflateBackInit_ 98 | # define inflateCopy z_inflateCopy 99 | # define inflateEnd z_inflateEnd 100 | # define inflateGetHeader z_inflateGetHeader 101 | # define inflateInit2_ z_inflateInit2_ 102 | # define inflateInit_ z_inflateInit_ 103 | # define inflateMark z_inflateMark 104 | # define inflatePrime z_inflatePrime 105 | # define inflateReset z_inflateReset 106 | # define inflateReset2 z_inflateReset2 107 | # define inflateSetDictionary z_inflateSetDictionary 108 | # define inflateGetDictionary z_inflateGetDictionary 109 | # define inflateSync z_inflateSync 110 | # define inflateSyncPoint z_inflateSyncPoint 111 | # define inflateUndermine z_inflateUndermine 112 | # define inflateResetKeep z_inflateResetKeep 113 | # define inflate_copyright z_inflate_copyright 114 | # define inflate_fast z_inflate_fast 115 | # define inflate_table z_inflate_table 116 | # ifndef Z_SOLO 117 | # define uncompress z_uncompress 118 | # endif 119 | # define zError z_zError 120 | # ifndef Z_SOLO 121 | # define zcalloc z_zcalloc 122 | # define zcfree z_zcfree 123 | # endif 124 | # define zlibCompileFlags z_zlibCompileFlags 125 | # define zlibVersion z_zlibVersion 126 | 127 | /* all zlib typedefs in zlib.h and zconf.h */ 128 | # define Byte z_Byte 129 | # define Bytef z_Bytef 130 | # define alloc_func z_alloc_func 131 | # define charf z_charf 132 | # define free_func z_free_func 133 | # ifndef Z_SOLO 134 | # define gzFile z_gzFile 135 | # endif 136 | # define gz_header z_gz_header 137 | # define gz_headerp z_gz_headerp 138 | # define in_func z_in_func 139 | # define intf z_intf 140 | # define out_func z_out_func 141 | # define uInt z_uInt 142 | # define uIntf z_uIntf 143 | # define uLong z_uLong 144 | # define uLongf z_uLongf 145 | # define voidp z_voidp 146 | # define voidpc z_voidpc 147 | # define voidpf z_voidpf 148 | 149 | /* all zlib structs in zlib.h and zconf.h */ 150 | # define gz_header_s z_gz_header_s 151 | # define internal_state z_internal_state 152 | 153 | #endif 154 | 155 | #if defined(__MSDOS__) && !defined(MSDOS) 156 | # define MSDOS 157 | #endif 158 | #if (defined(OS_2) || defined(__OS2__)) && !defined(OS2) 159 | # define OS2 160 | #endif 161 | #if defined(_WINDOWS) && !defined(WINDOWS) 162 | # define WINDOWS 163 | #endif 164 | #if defined(_WIN32) || defined(_WIN32_WCE) || defined(__WIN32__) 165 | # ifndef WIN32 166 | # define WIN32 167 | # endif 168 | #endif 169 | #if (defined(MSDOS) || defined(OS2) || defined(WINDOWS)) && !defined(WIN32) 170 | # if !defined(__GNUC__) && !defined(__FLAT__) && !defined(__386__) 171 | # ifndef SYS16BIT 172 | # define SYS16BIT 173 | # endif 174 | # endif 175 | #endif 176 | 177 | /* 178 | * Compile with -DMAXSEG_64K if the alloc function cannot allocate more 179 | * than 64k bytes at a time (needed on systems with 16-bit int). 180 | */ 181 | #ifdef SYS16BIT 182 | # define MAXSEG_64K 183 | #endif 184 | #ifdef MSDOS 185 | # define UNALIGNED_OK 186 | #endif 187 | 188 | #ifdef __STDC_VERSION__ 189 | # ifndef STDC 190 | # define STDC 191 | # endif 192 | # if __STDC_VERSION__ >= 199901L 193 | # ifndef STDC99 194 | # define STDC99 195 | # endif 196 | # endif 197 | #endif 198 | #if !defined(STDC) && (defined(__STDC__) || defined(__cplusplus)) 199 | # define STDC 200 | #endif 201 | #if !defined(STDC) && (defined(__GNUC__) || defined(__BORLANDC__)) 202 | # define STDC 203 | #endif 204 | #if !defined(STDC) && (defined(MSDOS) || defined(WINDOWS) || defined(WIN32)) 205 | # define STDC 206 | #endif 207 | #if !defined(STDC) && (defined(OS2) || defined(__HOS_AIX__)) 208 | # define STDC 209 | #endif 210 | 211 | #if defined(__OS400__) && !defined(STDC) /* iSeries (formerly AS/400). */ 212 | # define STDC 213 | #endif 214 | 215 | #ifndef STDC 216 | # ifndef const /* cannot use !defined(STDC) && !defined(const) on Mac */ 217 | # define const /* note: need a more gentle solution here */ 218 | # endif 219 | #endif 220 | 221 | #if defined(ZLIB_CONST) && !defined(z_const) 222 | # define z_const const 223 | #else 224 | # define z_const 225 | #endif 226 | 227 | /* Some Mac compilers merge all .h files incorrectly: */ 228 | #if defined(__MWERKS__)||defined(applec)||defined(THINK_C)||defined(__SC__) 229 | # define NO_DUMMY_DECL 230 | #endif 231 | 232 | /* Maximum value for memLevel in deflateInit2 */ 233 | #ifndef MAX_MEM_LEVEL 234 | # ifdef MAXSEG_64K 235 | # define MAX_MEM_LEVEL 8 236 | # else 237 | # define MAX_MEM_LEVEL 9 238 | # endif 239 | #endif 240 | 241 | /* Maximum value for windowBits in deflateInit2 and inflateInit2. 242 | * WARNING: reducing MAX_WBITS makes minigzip unable to extract .gz files 243 | * created by gzip. (Files created by minigzip can still be extracted by 244 | * gzip.) 245 | */ 246 | #ifndef MAX_WBITS 247 | # define MAX_WBITS 15 /* 32K LZ77 window */ 248 | #endif 249 | 250 | /* The memory requirements for deflate are (in bytes): 251 | (1 << (windowBits+2)) + (1 << (memLevel+9)) 252 | that is: 128K for windowBits=15 + 128K for memLevel = 8 (default values) 253 | plus a few kilobytes for small objects. For example, if you want to reduce 254 | the default memory requirements from 256K to 128K, compile with 255 | make CFLAGS="-O -DMAX_WBITS=14 -DMAX_MEM_LEVEL=7" 256 | Of course this will generally degrade compression (there's no free lunch). 257 | 258 | The memory requirements for inflate are (in bytes) 1 << windowBits 259 | that is, 32K for windowBits=15 (default value) plus a few kilobytes 260 | for small objects. 261 | */ 262 | 263 | /* Type declarations */ 264 | 265 | #ifndef OF /* function prototypes */ 266 | # ifdef STDC 267 | # define OF(args) args 268 | # else 269 | # define OF(args) () 270 | # endif 271 | #endif 272 | 273 | #ifndef Z_ARG /* function prototypes for stdarg */ 274 | # if defined(STDC) || defined(Z_HAVE_STDARG_H) 275 | # define Z_ARG(args) args 276 | # else 277 | # define Z_ARG(args) () 278 | # endif 279 | #endif 280 | 281 | /* The following definitions for FAR are needed only for MSDOS mixed 282 | * model programming (small or medium model with some far allocations). 283 | * This was tested only with MSC; for other MSDOS compilers you may have 284 | * to define NO_MEMCPY in zutil.h. If you don't need the mixed model, 285 | * just define FAR to be empty. 286 | */ 287 | #ifdef SYS16BIT 288 | # if defined(M_I86SM) || defined(M_I86MM) 289 | /* MSC small or medium model */ 290 | # define SMALL_MEDIUM 291 | # ifdef _MSC_VER 292 | # define FAR _far 293 | # else 294 | # define FAR far 295 | # endif 296 | # endif 297 | # if (defined(__SMALL__) || defined(__MEDIUM__)) 298 | /* Turbo C small or medium model */ 299 | # define SMALL_MEDIUM 300 | # ifdef __BORLANDC__ 301 | # define FAR _far 302 | # else 303 | # define FAR far 304 | # endif 305 | # endif 306 | #endif 307 | 308 | #if defined(WINDOWS) || defined(WIN32) 309 | /* If building or using zlib as a DLL, define ZLIB_DLL. 310 | * This is not mandatory, but it offers a little performance increase. 311 | */ 312 | # ifdef ZLIB_DLL 313 | # if defined(WIN32) && (!defined(__BORLANDC__) || (__BORLANDC__ >= 0x500)) 314 | # ifdef ZLIB_INTERNAL 315 | # define ZEXTERN extern __declspec(dllexport) 316 | # else 317 | # define ZEXTERN extern __declspec(dllimport) 318 | # endif 319 | # endif 320 | # endif /* ZLIB_DLL */ 321 | /* If building or using zlib with the WINAPI/WINAPIV calling convention, 322 | * define ZLIB_WINAPI. 323 | * Caution: the standard ZLIB1.DLL is NOT compiled using ZLIB_WINAPI. 324 | */ 325 | # ifdef ZLIB_WINAPI 326 | # ifdef FAR 327 | # undef FAR 328 | # endif 329 | # include 330 | /* No need for _export, use ZLIB.DEF instead. */ 331 | /* For complete Windows compatibility, use WINAPI, not __stdcall. */ 332 | # define ZEXPORT WINAPI 333 | # ifdef WIN32 334 | # define ZEXPORTVA WINAPIV 335 | # else 336 | # define ZEXPORTVA FAR CDECL 337 | # endif 338 | # endif 339 | #endif 340 | 341 | #if defined (__BEOS__) 342 | # ifdef ZLIB_DLL 343 | # ifdef ZLIB_INTERNAL 344 | # define ZEXPORT __declspec(dllexport) 345 | # define ZEXPORTVA __declspec(dllexport) 346 | # else 347 | # define ZEXPORT __declspec(dllimport) 348 | # define ZEXPORTVA __declspec(dllimport) 349 | # endif 350 | # endif 351 | #endif 352 | 353 | #ifndef ZEXTERN 354 | # define ZEXTERN extern 355 | #endif 356 | #ifndef ZEXPORT 357 | # define ZEXPORT 358 | #endif 359 | #ifndef ZEXPORTVA 360 | # define ZEXPORTVA 361 | #endif 362 | 363 | #ifndef FAR 364 | # define FAR 365 | #endif 366 | 367 | #if !defined(__MACTYPES__) 368 | typedef unsigned char Byte; /* 8 bits */ 369 | #endif 370 | typedef unsigned int uInt; /* 16 bits or more */ 371 | typedef unsigned long uLong; /* 32 bits or more */ 372 | 373 | #ifdef SMALL_MEDIUM 374 | /* Borland C/C++ and some old MSC versions ignore FAR inside typedef */ 375 | # define Bytef Byte FAR 376 | #else 377 | typedef Byte FAR Bytef; 378 | #endif 379 | typedef char FAR charf; 380 | typedef int FAR intf; 381 | typedef uInt FAR uIntf; 382 | typedef uLong FAR uLongf; 383 | 384 | #ifdef STDC 385 | typedef void const *voidpc; 386 | typedef void FAR *voidpf; 387 | typedef void *voidp; 388 | #else 389 | typedef Byte const *voidpc; 390 | typedef Byte FAR *voidpf; 391 | typedef Byte *voidp; 392 | #endif 393 | 394 | #if !defined(Z_U4) && !defined(Z_SOLO) && defined(STDC) 395 | # include 396 | # if (UINT_MAX == 0xffffffffUL) 397 | # define Z_U4 unsigned 398 | # elif (ULONG_MAX == 0xffffffffUL) 399 | # define Z_U4 unsigned long 400 | # elif (USHRT_MAX == 0xffffffffUL) 401 | # define Z_U4 unsigned short 402 | # endif 403 | #endif 404 | 405 | #ifdef Z_U4 406 | typedef Z_U4 z_crc_t; 407 | #else 408 | typedef unsigned long z_crc_t; 409 | #endif 410 | 411 | #ifdef HAVE_UNISTD_H /* may be set to #if 1 by ./configure */ 412 | # define Z_HAVE_UNISTD_H 413 | #endif 414 | 415 | #ifdef HAVE_STDARG_H /* may be set to #if 1 by ./configure */ 416 | # define Z_HAVE_STDARG_H 417 | #endif 418 | 419 | #ifdef STDC 420 | # ifndef Z_SOLO 421 | # include /* for off_t */ 422 | # endif 423 | #endif 424 | 425 | #if defined(STDC) || defined(Z_HAVE_STDARG_H) 426 | # ifndef Z_SOLO 427 | # include /* for va_list */ 428 | # endif 429 | #endif 430 | 431 | #ifdef _WIN32 432 | # ifndef Z_SOLO 433 | # include /* for wchar_t */ 434 | # endif 435 | #endif 436 | 437 | /* a little trick to accommodate both "#define _LARGEFILE64_SOURCE" and 438 | * "#define _LARGEFILE64_SOURCE 1" as requesting 64-bit operations, (even 439 | * though the former does not conform to the LFS document), but considering 440 | * both "#undef _LARGEFILE64_SOURCE" and "#define _LARGEFILE64_SOURCE 0" as 441 | * equivalently requesting no 64-bit operations 442 | */ 443 | #if defined(_LARGEFILE64_SOURCE) && -_LARGEFILE64_SOURCE - -1 == 1 444 | # undef _LARGEFILE64_SOURCE 445 | #endif 446 | 447 | #if defined(__WATCOMC__) && !defined(Z_HAVE_UNISTD_H) 448 | # define Z_HAVE_UNISTD_H 449 | #endif 450 | #ifndef Z_SOLO 451 | # if defined(Z_HAVE_UNISTD_H) || defined(_LARGEFILE64_SOURCE) 452 | # include /* for SEEK_*, off_t, and _LFS64_LARGEFILE */ 453 | # ifdef VMS 454 | # include /* for off_t */ 455 | # endif 456 | # ifndef z_off_t 457 | # define z_off_t off_t 458 | # endif 459 | # endif 460 | #endif 461 | 462 | #if defined(_LFS64_LARGEFILE) && _LFS64_LARGEFILE-0 463 | # define Z_LFS64 464 | #endif 465 | 466 | #if defined(_LARGEFILE64_SOURCE) && defined(Z_LFS64) 467 | # define Z_LARGE64 468 | #endif 469 | 470 | #if defined(_FILE_OFFSET_BITS) && _FILE_OFFSET_BITS-0 == 64 && defined(Z_LFS64) 471 | # define Z_WANT64 472 | #endif 473 | 474 | #if !defined(SEEK_SET) && !defined(Z_SOLO) 475 | # define SEEK_SET 0 /* Seek from beginning of file. */ 476 | # define SEEK_CUR 1 /* Seek from current position. */ 477 | # define SEEK_END 2 /* Set file pointer to EOF plus "offset" */ 478 | #endif 479 | 480 | #ifndef z_off_t 481 | # define z_off_t long 482 | #endif 483 | 484 | #if !defined(_WIN32) && defined(Z_LARGE64) 485 | # define z_off64_t off64_t 486 | #else 487 | # if defined(_WIN32) && !defined(__GNUC__) && !defined(Z_SOLO) 488 | # define z_off64_t __int64 489 | # else 490 | # define z_off64_t z_off_t 491 | # endif 492 | #endif 493 | 494 | /* MVS linker does not support external names larger than 8 bytes */ 495 | #if defined(__MVS__) 496 | #pragma map(deflateInit_,"DEIN") 497 | #pragma map(deflateInit2_,"DEIN2") 498 | #pragma map(deflateEnd,"DEEND") 499 | #pragma map(deflateBound,"DEBND") 500 | #pragma map(inflateInit_,"ININ") 501 | #pragma map(inflateInit2_,"ININ2") 502 | #pragma map(inflateEnd,"INEND") 503 | #pragma map(inflateSync,"INSY") 504 | #pragma map(inflateSetDictionary,"INSEDI") 505 | #pragma map(compressBound,"CMBND") 506 | #pragma map(inflate_table,"INTABL") 507 | #pragma map(inflate_fast,"INFA") 508 | #pragma map(inflate_copyright,"INCOPY") 509 | #endif 510 | 511 | #endif /* ZCONF_H */ 512 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # CSApkShellProject 2 | 为Apk加壳项目,防止二次打包,代码反编译 3 | --------------------------------------------------------------------------------