├── .gitignore ├── Resources ├── AppIcon-1024.png ├── AppIcon-20.png ├── AppIcon-29.png ├── AppIcon-40.png ├── AppIcon-76.png ├── AppIcon60x60.png ├── AppIcon-20@2x.png ├── AppIcon-20@3x.png ├── AppIcon-29@2x.png ├── AppIcon-29@3x.png ├── AppIcon-40@2x.png ├── AppIcon-40@3x.png ├── AppIcon-60@2x.png ├── AppIcon-60@3x.png ├── AppIcon-76@2x.png ├── AppIcon-83.5@2x.png ├── AppIcon76x76~ipad.png └── Info.plist ├── TDRootViewController.h ├── TDFileManagerViewController.h ├── control ├── main.m ├── TDAppDelegate.h ├── TDAppDelegate.m ├── SSZipArchive ├── ZipArchive.h ├── minizip │ ├── minishared.h │ ├── aes │ │ ├── pwd2key.h │ │ ├── sha1.h │ │ ├── aes_ni.h │ │ ├── prng.h │ │ ├── hmac.h │ │ ├── fileenc.h │ │ ├── fileenc.c │ │ ├── brg_endian.h │ │ ├── prng.c │ │ ├── aestab.h │ │ ├── pwd2key.c │ │ ├── brg_types.h │ │ ├── hmac.c │ │ ├── aes.h │ │ ├── sha1.c │ │ ├── aescrypt.c │ │ └── aestab.c │ ├── ioapi_mem.h │ ├── ioapi_buf.h │ ├── crypt.h │ ├── crypt.c │ ├── ioapi_mem.c │ ├── ioapi.h │ ├── minishared.c │ ├── zip.h │ ├── unzip.h │ └── ioapi.c ├── SSZipCommon.h └── SSZipArchive.h ├── TDDumpDecrypted.h ├── README.md ├── Makefile ├── LSApplicationProxy+AltList.h ├── entitlements.plist ├── TDUtils.h ├── TDFileManagerViewController.m ├── LSApplicationProxy+AltList.m └── TDRootViewController.m /.gitignore: -------------------------------------------------------------------------------- 1 | .theos/ 2 | packages/ 3 | *.DS_Store 4 | Payload/ 5 | TrollDecrypt.tipa -------------------------------------------------------------------------------- /Resources/AppIcon-1024.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/donato-fiore/TrollDecrypt/HEAD/Resources/AppIcon-1024.png -------------------------------------------------------------------------------- /Resources/AppIcon-20.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/donato-fiore/TrollDecrypt/HEAD/Resources/AppIcon-20.png -------------------------------------------------------------------------------- /Resources/AppIcon-29.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/donato-fiore/TrollDecrypt/HEAD/Resources/AppIcon-29.png -------------------------------------------------------------------------------- /Resources/AppIcon-40.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/donato-fiore/TrollDecrypt/HEAD/Resources/AppIcon-40.png -------------------------------------------------------------------------------- /Resources/AppIcon-76.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/donato-fiore/TrollDecrypt/HEAD/Resources/AppIcon-76.png -------------------------------------------------------------------------------- /Resources/AppIcon60x60.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/donato-fiore/TrollDecrypt/HEAD/Resources/AppIcon60x60.png -------------------------------------------------------------------------------- /Resources/AppIcon-20@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/donato-fiore/TrollDecrypt/HEAD/Resources/AppIcon-20@2x.png -------------------------------------------------------------------------------- /Resources/AppIcon-20@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/donato-fiore/TrollDecrypt/HEAD/Resources/AppIcon-20@3x.png -------------------------------------------------------------------------------- /Resources/AppIcon-29@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/donato-fiore/TrollDecrypt/HEAD/Resources/AppIcon-29@2x.png -------------------------------------------------------------------------------- /Resources/AppIcon-29@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/donato-fiore/TrollDecrypt/HEAD/Resources/AppIcon-29@3x.png -------------------------------------------------------------------------------- /Resources/AppIcon-40@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/donato-fiore/TrollDecrypt/HEAD/Resources/AppIcon-40@2x.png -------------------------------------------------------------------------------- /Resources/AppIcon-40@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/donato-fiore/TrollDecrypt/HEAD/Resources/AppIcon-40@3x.png -------------------------------------------------------------------------------- /Resources/AppIcon-60@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/donato-fiore/TrollDecrypt/HEAD/Resources/AppIcon-60@2x.png -------------------------------------------------------------------------------- /Resources/AppIcon-60@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/donato-fiore/TrollDecrypt/HEAD/Resources/AppIcon-60@3x.png -------------------------------------------------------------------------------- /Resources/AppIcon-76@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/donato-fiore/TrollDecrypt/HEAD/Resources/AppIcon-76@2x.png -------------------------------------------------------------------------------- /Resources/AppIcon-83.5@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/donato-fiore/TrollDecrypt/HEAD/Resources/AppIcon-83.5@2x.png -------------------------------------------------------------------------------- /Resources/AppIcon76x76~ipad.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/donato-fiore/TrollDecrypt/HEAD/Resources/AppIcon76x76~ipad.png -------------------------------------------------------------------------------- /TDRootViewController.h: -------------------------------------------------------------------------------- 1 | #import 2 | 3 | @interface TDRootViewController : UITableViewController 4 | 5 | @property (nonatomic, strong) NSArray *apps; 6 | 7 | @end 8 | -------------------------------------------------------------------------------- /TDFileManagerViewController.h: -------------------------------------------------------------------------------- 1 | #import 2 | 3 | @interface TDFileManagerViewController : UITableViewController 4 | 5 | @property (nonatomic, strong) NSArray *fileList; 6 | 7 | @end -------------------------------------------------------------------------------- /control: -------------------------------------------------------------------------------- 1 | Package: com.fiore.trolldecrypt 2 | Name: TrollDecrypt 3 | Version: 1.1 4 | Architecture: iphoneos-arm 5 | Description: An awesome application! 6 | Maintainer: fiore 7 | Author: fiore 8 | Section: Utilities 9 | -------------------------------------------------------------------------------- /main.m: -------------------------------------------------------------------------------- 1 | #import 2 | #import "TDAppDelegate.h" 3 | 4 | int main(int argc, char *argv[]) { 5 | @autoreleasepool { 6 | return UIApplicationMain(argc, argv, nil, NSStringFromClass(TDAppDelegate.class)); 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /TDAppDelegate.h: -------------------------------------------------------------------------------- 1 | #import 2 | 3 | @interface TDAppDelegate : UIResponder 4 | 5 | @property (nonatomic, strong) UIWindow *window; 6 | @property (nonatomic, strong) UINavigationController *rootViewController; 7 | 8 | @end 9 | -------------------------------------------------------------------------------- /TDAppDelegate.m: -------------------------------------------------------------------------------- 1 | #import "TDAppDelegate.h" 2 | #import "TDRootViewController.h" 3 | 4 | @implementation TDAppDelegate 5 | 6 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { 7 | _window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds]; 8 | _rootViewController = [[UINavigationController alloc] initWithRootViewController:[[TDRootViewController alloc] init]]; 9 | _window.rootViewController = _rootViewController; 10 | [_window makeKeyAndVisible]; 11 | return YES; 12 | } 13 | 14 | @end 15 | -------------------------------------------------------------------------------- /SSZipArchive/ZipArchive.h: -------------------------------------------------------------------------------- 1 | // 2 | // ZipArchive.h 3 | // ZipArchive 4 | // 5 | // Created by Serhii Mumriak on 12/1/15. 6 | // Copyright © 2015 smumryak. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | //! Project version number for ZipArchive. 12 | FOUNDATION_EXPORT double ZipArchiveVersionNumber; 13 | 14 | //! Project version string for ZipArchive. 15 | FOUNDATION_EXPORT const unsigned char ZipArchiveVersionString[]; 16 | 17 | // In this header, you should import all the public headers of your framework using statements like #import 18 | 19 | #import "SSZipArchive.h" 20 | -------------------------------------------------------------------------------- /TDDumpDecrypted.h: -------------------------------------------------------------------------------- 1 | @interface DumpDecrypted : NSObject { 2 | char decryptedAppPathStr[PATH_MAX]; 3 | char *filename; 4 | char *appDirName; 5 | char *appDirPath; 6 | } 7 | 8 | @property (assign) NSString *appPath; 9 | @property (assign) NSString *docPath; 10 | @property (assign) NSString *appName; 11 | @property (assign) NSString *appVersion; 12 | 13 | - (id)initWithPathToBinary:(NSString *)pathToBinary appName:(NSString *)appName appVersion:(NSString *)appVersion; 14 | - (void)createIPAFile:(pid_t)pid; 15 | - (BOOL)dumpDecryptedImage:(const struct mach_header *)image_mh fileName:(const char *)encryptedImageFilenameStr image:(int)imageNum task:(vm_map_t)targetTask; 16 | - (NSString *)IPAPath; 17 | @end -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # TrollDecrypt 2 | iOS IPA Decrypter for TrollStore 3 | 4 | ## How to use 5 | 1. Download and install TrollDecrypt from [here](https://github.com/donato-fiore/TrollDecrypt/releases) 6 | 2. Choose app you want to decrypt. 7 | 3. Once finished decrypting, you can get the `.ipa` file from inside the app. 8 | 9 | ## How to build 10 | 1. Install [theos](https://theos.dev/docs/installation) 11 | 2. Run the commands below 12 | ``` 13 | git clone https://github.com/donato-fiore/TrollDecrypt.git 14 | cd TrollDecrypt 15 | make package 16 | ``` 17 | 18 | ## Credits / Thanks 19 | - [TrollDecryptor](https://github.com/wh1te4ever/TrollDecryptor) by wh1te4ever 20 | - [dumpdecrypted](https://github.com/stefanesser/dumpdecrypted) by Stefan Esser 21 | - [bfdecrypt](https://github.com/BishopFox/bfdecrypt) by BishopFox 22 | - [opa334](https://github.com/opa334) for some pieces of code 23 | - App Icon by super.user -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | TARGET := iphone:clang:latest:14.0 2 | INSTALL_TARGET_PROCESSES = TrollDecrypt 3 | 4 | GO_EASY_ON_ME = 1 5 | PACKAGE_FORMAT = ipa 6 | 7 | include $(THEOS)/makefiles/common.mk 8 | 9 | APPLICATION_NAME = TrollDecrypt 10 | 11 | TrollDecrypt_FILES = SSZipArchive/minizip/unzip.c SSZipArchive/minizip/crypt.c SSZipArchive/minizip/ioapi_buf.c SSZipArchive/minizip/ioapi_mem.c SSZipArchive/minizip/ioapi.c SSZipArchive/minizip/minishared.c SSZipArchive/minizip/zip.c SSZipArchive/minizip/aes/aes_ni.c SSZipArchive/minizip/aes/aescrypt.c SSZipArchive/minizip/aes/aeskey.c SSZipArchive/minizip/aes/aestab.c SSZipArchive/minizip/aes/fileenc.c SSZipArchive/minizip/aes/hmac.c SSZipArchive/minizip/aes/prng.c SSZipArchive/minizip/aes/pwd2key.c SSZipArchive/minizip/aes/sha1.c SSZipArchive/SSZipArchive.m 12 | TrollDecrypt_FILES += main.m TDAppDelegate.m TDRootViewController.m TDDumpDecrypted.m TDUtils.m TDFileManagerViewController.m LSApplicationProxy+AltList.m 13 | TrollDecrypt_FRAMEWORKS = UIKit CoreGraphics MobileCoreServices 14 | TrollDecrypt_CFLAGS = -fobjc-arc 15 | TrollDecrypt_CODESIGN_FLAGS = -Sentitlements.plist 16 | 17 | include $(THEOS_MAKE_PATH)/application.mk 18 | 19 | after-stage:: 20 | rm -rf Payload 21 | mkdir -p $(THEOS_STAGING_DIR)/Payload 22 | ldid -Sentitlements.plist $(THEOS_STAGING_DIR)/Applications/TrollDecrypt.app/TrollDecrypt 23 | cp -a $(THEOS_STAGING_DIR)/Applications/* $(THEOS_STAGING_DIR)/Payload 24 | mv $(THEOS_STAGING_DIR)/Payload . 25 | zip -q -r TrollDecrypt.tipa Payload 26 | -------------------------------------------------------------------------------- /SSZipArchive/minizip/minishared.h: -------------------------------------------------------------------------------- 1 | #ifndef _MINISHARED_H 2 | #define _MINISHARED_H 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | #ifdef _WIN32 9 | # define MKDIR(d) _mkdir(d) 10 | # define CHDIR(d) _chdir(d) 11 | #else 12 | # define MKDIR(d) mkdir(d, 0775) 13 | # define CHDIR(d) chdir(d) 14 | #endif 15 | 16 | /***************************************************************************/ 17 | 18 | /* Get a file's date and time in dos format */ 19 | uint32_t get_file_date(const char *path, uint32_t *dos_date); 20 | 21 | /* Sets a file's date and time in dos format */ 22 | void change_file_date(const char *path, uint32_t dos_date); 23 | 24 | /* Convert dos date/time format to struct tm */ 25 | int dosdate_to_tm(uint64_t dos_date, struct tm *ptm); 26 | 27 | /* Convert dos date/time format to time_t */ 28 | time_t dosdate_to_time_t(uint64_t dos_date); 29 | 30 | /* Convert struct tm to dos date/time format */ 31 | uint32_t tm_to_dosdate(const struct tm *ptm); 32 | 33 | /* Create a directory and all subdirectories */ 34 | int makedir(const char *newdir); 35 | 36 | /* Check to see if a file exists */ 37 | int check_file_exists(const char *path); 38 | 39 | /* Check to see if a file is over 4GB and needs ZIP64 extension */ 40 | int is_large_file(const char *path); 41 | 42 | /* Print a 64-bit number for compatibility */ 43 | void display_zpos64(uint64_t n, int size_char); 44 | 45 | /***************************************************************************/ 46 | 47 | #ifdef __cplusplus 48 | } 49 | #endif 50 | 51 | #endif /* _MINISHARED_H */ -------------------------------------------------------------------------------- /LSApplicationProxy+AltList.h: -------------------------------------------------------------------------------- 1 | #import 2 | #import 3 | 4 | @interface LSApplicationRecord : NSObject 5 | @property (nonatomic,readonly) NSArray* appTags; // 'hidden' 6 | @property (getter=isLaunchProhibited,readonly) BOOL launchProhibited; 7 | @end 8 | 9 | @interface LSApplicationProxy (Additions) 10 | @property (readonly, nonatomic) NSString *shortVersionString; 11 | @property (nonatomic,readonly) NSString* localizedName; 12 | @property (nonatomic,readonly) NSString* applicationType; // (User/System) 13 | @property (nonatomic,readonly) NSArray* appTags; // 'hidden' 14 | @property (getter=isLaunchProhibited,nonatomic,readonly) BOOL launchProhibited; 15 | + (instancetype)applicationProxyForIdentifier:(NSString*)identifier; 16 | - (LSApplicationRecord*)correspondingApplicationRecord; 17 | @end 18 | 19 | @interface LSApplicationWorkspace (Additions) 20 | - (void)addObserver:(id)arg1; 21 | - (void)removeObserver:(id)arg1; 22 | - (void)enumerateApplicationsOfType:(NSUInteger)type block:(void (^)(LSApplicationProxy*))block; 23 | @end 24 | 25 | @interface LSApplicationProxy (AltList) 26 | - (BOOL)atl_isSystemApplication; 27 | - (BOOL)atl_isUserApplication; 28 | - (BOOL)atl_isHidden; 29 | - (NSString*)atl_fastDisplayName; 30 | - (NSString*)atl_nameToDisplay; 31 | - (NSString*)atl_shortVersionString; 32 | @property (nonatomic,readonly) NSString* atl_bundleIdentifier; 33 | @end 34 | 35 | @interface LSApplicationWorkspace (AltList) 36 | - (NSArray*)atl_allInstalledApplications; 37 | @end -------------------------------------------------------------------------------- /entitlements.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | platform-application 6 | 7 | application-identifier 8 | com.fiore.trolldecrypt 9 | com.apple.security.exception.files.absolute-path.read-write 10 | 11 | / 12 | 13 | com.apple.private.security.no-sandbox 14 | 15 | com.apple.private.persona-mgmt 16 | 17 | com.apple.private.MobileContainerManager.allowed 18 | 19 | com.apple.private.security.container-manager 20 | 21 | com.apple.private.security.storage.AppBundles 22 | 23 | com.apple.private.security.storage.AppDataContainers 24 | 25 | task_for_pid-allow 26 | 27 | get-task-allow 28 | 29 | com.apple.security.get-task-allow 30 | 31 | proc_info-allow 32 | 33 | com.apple.system-task-ports 34 | 35 | com.apple.springboard.launchapplications 36 | 37 | com.apple.security.exception.iokit-user-client-class 38 | 39 | IOUserClient 40 | IOUserServer 41 | RootDomainUserClient 42 | 43 | com.apple.security.iokit-user-client-class 44 | 45 | IOUserClient 46 | IOUserServer 47 | RootDomainUserClient 48 | 49 | 50 | -------------------------------------------------------------------------------- /TDUtils.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | #import 12 | #import 13 | #import 14 | 15 | @interface UIApplication (tweakName) 16 | + (id)sharedApplication; 17 | - (BOOL)launchApplicationWithIdentifier:(id)arg1 suspended:(BOOL)arg2; 18 | @end 19 | 20 | @interface UIImage (Private) 21 | + (UIImage *)_applicationIconImageForBundleIdentifier:(NSString *)bundleIdentifier format:(NSUInteger)format scale:(CGFloat)scale; 22 | @end 23 | 24 | #define PROC_PIDPATHINFO 11 25 | #define PROC_PIDPATHINFO_SIZE (MAXPATHLEN) 26 | #define PROC_PIDPATHINFO_MAXSIZE (4 * MAXPATHLEN) 27 | #define PROC_ALL_PIDS 1 28 | 29 | #ifndef DEBUG 30 | # define NSLog(...) (void)0 31 | #endif 32 | 33 | int proc_pidpath(int pid, void *buffer, uint32_t buffersize); 34 | int proc_listpids(uint32_t type, uint32_t typeinfo, void *buffer, int buffersize); 35 | NSArray *appList(void); 36 | NSUInteger iconFormat(void); 37 | NSArray *sysctl_ps(void); 38 | void decryptApp(NSDictionary *app); 39 | void decryptAppWithPID(pid_t pid); 40 | void bfinject_rocknroll(pid_t pid, NSString *appName, NSString *version); 41 | NSArray *decryptedFileList(void); 42 | NSString *docPath(void); 43 | void fetchLatestTrollDecryptVersion(void (^completionHandler)(NSString *version)); 44 | void github_fetchLatedVersion(NSString *repo, void (^completionHandler)(NSString *latestVersion)); 45 | NSString *trollDecryptVersion(void); -------------------------------------------------------------------------------- /SSZipArchive/minizip/aes/pwd2key.h: -------------------------------------------------------------------------------- 1 | /* 2 | --------------------------------------------------------------------------- 3 | Copyright (c) 1998-2010, Brian Gladman, Worcester, UK. All rights reserved. 4 | 5 | The redistribution and use of this software (with or without changes) 6 | is allowed without the payment of fees or royalties provided that: 7 | 8 | source code distributions include the above copyright notice, this 9 | list of conditions and the following disclaimer; 10 | 11 | binary distributions include the above copyright notice, this list 12 | of conditions and the following disclaimer in their documentation. 13 | 14 | This software is provided 'as is' with no explicit or implied warranties 15 | in respect of its operation, including, but not limited to, correctness 16 | and fitness for purpose. 17 | --------------------------------------------------------------------------- 18 | Issue Date: 20/12/2007 19 | 20 | This is an implementation of RFC2898, which specifies key derivation from 21 | a password and a salt value. 22 | */ 23 | 24 | #ifndef PWD2KEY_H 25 | #define PWD2KEY_H 26 | 27 | #if defined(__cplusplus) 28 | extern "C" 29 | { 30 | #endif 31 | 32 | void derive_key( 33 | const unsigned char pwd[], /* the PASSWORD, and */ 34 | unsigned int pwd_len, /* its length */ 35 | const unsigned char salt[], /* the SALT and its */ 36 | unsigned int salt_len, /* length */ 37 | unsigned int iter, /* the number of iterations */ 38 | unsigned char key[], /* space for the output key */ 39 | unsigned int key_len); /* and its required length */ 40 | 41 | #if defined(__cplusplus) 42 | } 43 | #endif 44 | 45 | #endif 46 | -------------------------------------------------------------------------------- /SSZipArchive/minizip/ioapi_mem.h: -------------------------------------------------------------------------------- 1 | /* ioapi_mem.h -- IO base function header for compress/uncompress .zip 2 | files using zlib + zip or unzip API 3 | 4 | This version of ioapi is designed to access memory rather than files. 5 | We do use a region of memory to put data in to and take it out of. 6 | 7 | Copyright (C) 2012-2017 Nathan Moinvaziri (https://github.com/nmoinvaz/minizip) 8 | (C) 2003 Justin Fletcher 9 | (C) 1998-2003 Gilles Vollant 10 | 11 | This program is distributed under the terms of the same license as zlib. 12 | See the accompanying LICENSE file for the full text of the license. 13 | */ 14 | 15 | #ifndef _IOAPI_MEM_H 16 | #define _IOAPI_MEM_H 17 | 18 | #include 19 | #include 20 | #include 21 | 22 | #include "zlib.h" 23 | #include "ioapi.h" 24 | 25 | #ifdef __cplusplus 26 | extern "C" { 27 | #endif 28 | 29 | voidpf ZCALLBACK fopen_mem_func(voidpf opaque, const char* filename, int mode); 30 | voidpf ZCALLBACK fopendisk_mem_func(voidpf opaque, voidpf stream, uint32_t number_disk, int mode); 31 | uint32_t ZCALLBACK fread_mem_func(voidpf opaque, voidpf stream, void* buf, uint32_t size); 32 | uint32_t ZCALLBACK fwrite_mem_func(voidpf opaque, voidpf stream, const void* buf, uint32_t size); 33 | long ZCALLBACK ftell_mem_func(voidpf opaque, voidpf stream); 34 | long ZCALLBACK fseek_mem_func(voidpf opaque, voidpf stream, uint32_t offset, int origin); 35 | int ZCALLBACK fclose_mem_func(voidpf opaque, voidpf stream); 36 | int ZCALLBACK ferror_mem_func(voidpf opaque, voidpf stream); 37 | 38 | typedef struct ourmemory_s { 39 | char *base; /* Base of the region of memory we're using */ 40 | uint32_t size; /* Size of the region of memory we're using */ 41 | uint32_t limit; /* Furthest we've written */ 42 | uint32_t cur_offset; /* Current offset in the area */ 43 | int grow; /* Growable memory buffer */ 44 | } ourmemory_t; 45 | 46 | void fill_memory_filefunc(zlib_filefunc_def* pzlib_filefunc_def, ourmemory_t *ourmem); 47 | 48 | #ifdef __cplusplus 49 | } 50 | #endif 51 | 52 | #endif 53 | -------------------------------------------------------------------------------- /SSZipArchive/minizip/ioapi_buf.h: -------------------------------------------------------------------------------- 1 | /* ioapi_buf.h -- IO base function header for compress/uncompress .zip 2 | files using zlib + zip or unzip API 3 | 4 | This version of ioapi is designed to buffer IO. 5 | 6 | Copyright (C) 2012-2017 Nathan Moinvaziri 7 | https://github.com/nmoinvaz/minizip 8 | 9 | This program is distributed under the terms of the same license as zlib. 10 | See the accompanying LICENSE file for the full text of the license. 11 | */ 12 | 13 | #ifndef _IOAPI_BUF_H 14 | #define _IOAPI_BUF_H 15 | 16 | #include 17 | #include 18 | #include 19 | 20 | #include "zlib.h" 21 | #include "ioapi.h" 22 | 23 | #ifdef __cplusplus 24 | extern "C" { 25 | #endif 26 | 27 | voidpf ZCALLBACK fopen_buf_func(voidpf opaque, const char* filename, int mode); 28 | voidpf ZCALLBACK fopen64_buf_func(voidpf opaque, const void* filename, int mode); 29 | voidpf ZCALLBACK fopendisk_buf_func(voidpf opaque, voidpf stream_cd, uint32_t number_disk, int mode); 30 | voidpf ZCALLBACK fopendisk64_buf_func(voidpf opaque, voidpf stream_cd, uint32_t number_disk, int mode); 31 | uint32_t ZCALLBACK fread_buf_func(voidpf opaque, voidpf stream, void* buf, uint32_t size); 32 | uint32_t ZCALLBACK fwrite_buf_func(voidpf opaque, voidpf stream, const void* buf, uint32_t size); 33 | long ZCALLBACK ftell_buf_func(voidpf opaque, voidpf stream); 34 | uint64_t ZCALLBACK ftell64_buf_func(voidpf opaque, voidpf stream); 35 | long ZCALLBACK fseek_buf_func(voidpf opaque, voidpf stream, uint32_t offset, int origin); 36 | long ZCALLBACK fseek64_buf_func(voidpf opaque, voidpf stream, uint64_t offset, int origin); 37 | int ZCALLBACK fclose_buf_func(voidpf opaque,voidpf stream); 38 | int ZCALLBACK ferror_buf_func(voidpf opaque,voidpf stream); 39 | 40 | typedef struct ourbuffer_s { 41 | zlib_filefunc_def filefunc; 42 | zlib_filefunc64_def filefunc64; 43 | } ourbuffer_t; 44 | 45 | void fill_buffer_filefunc(zlib_filefunc_def* pzlib_filefunc_def, ourbuffer_t *ourbuf); 46 | void fill_buffer_filefunc64(zlib_filefunc64_def* pzlib_filefunc_def, ourbuffer_t *ourbuf); 47 | 48 | #ifdef __cplusplus 49 | } 50 | #endif 51 | 52 | #endif 53 | -------------------------------------------------------------------------------- /Resources/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleExecutable 6 | TrollDecrypt 7 | CFBundleIcons 8 | 9 | CFBundlePrimaryIcon 10 | 11 | CFBundleIconFiles 12 | 13 | AppIcon-29 14 | AppIcon-40 15 | AppIcon-57 16 | AppIcon-60 17 | 18 | UIPrerenderedIcon 19 | 20 | 21 | 22 | CFBundleIcons~ipad 23 | 24 | CFBundlePrimaryIcon 25 | 26 | CFBundleIconFiles 27 | 28 | AppIcon-29 29 | AppIcon-40 30 | AppIcon-57 31 | AppIcon-60 32 | AppIcon-50 33 | AppIcon-72 34 | AppIcon-76 35 | 36 | UIPrerenderedIcon 37 | 38 | 39 | 40 | CFBundleIdentifier 41 | com.fiore.trolldecrypt 42 | CFBundleInfoDictionaryVersion 43 | 6.0 44 | CFBundlePackageType 45 | APPL 46 | CFBundleSignature 47 | ???? 48 | CFBundleSupportedPlatforms 49 | 50 | iPhoneOS 51 | 52 | CFBundleVersion 53 | 1.1 54 | LSRequiresIPhoneOS 55 | 56 | UIDeviceFamily 57 | 58 | 1 59 | 2 60 | 61 | UIRequiredDeviceCapabilities 62 | 63 | armv7 64 | 65 | UILaunchStoryboardName 66 | LaunchScreen 67 | UISupportedInterfaceOrientations 68 | 69 | UIInterfaceOrientationPortrait 70 | 71 | UISupportedInterfaceOrientations~ipad 72 | 73 | UIInterfaceOrientationPortrait 74 | 75 | 76 | 77 | -------------------------------------------------------------------------------- /SSZipArchive/minizip/crypt.h: -------------------------------------------------------------------------------- 1 | /* crypt.h -- base code for traditional PKWARE encryption 2 | Version 1.2.0, September 16th, 2017 3 | 4 | Copyright (C) 2012-2017 Nathan Moinvaziri 5 | https://github.com/nmoinvaz/minizip 6 | Copyright (C) 1998-2005 Gilles Vollant 7 | Modifications for Info-ZIP crypting 8 | http://www.winimage.com/zLibDll/minizip.html 9 | Copyright (C) 2003 Terry Thorsen 10 | 11 | This code is a modified version of crypting code in Info-ZIP distribution 12 | 13 | Copyright (C) 1990-2000 Info-ZIP. All rights reserved. 14 | 15 | This program is distributed under the terms of the same license as zlib. 16 | See the accompanying LICENSE file for the full text of the license. 17 | */ 18 | 19 | #ifndef _MINICRYPT_H 20 | #define _MINICRYPT_H 21 | 22 | #if ZLIB_VERNUM < 0x1270 23 | typedef unsigned long z_crc_t; 24 | #endif 25 | 26 | #ifdef __cplusplus 27 | extern "C" { 28 | #endif 29 | 30 | #define RAND_HEAD_LEN 12 31 | 32 | /***************************************************************************/ 33 | 34 | #define zdecode(pkeys,pcrc_32_tab,c) \ 35 | (update_keys(pkeys,pcrc_32_tab, c ^= decrypt_byte(pkeys))) 36 | 37 | #define zencode(pkeys,pcrc_32_tab,c,t) \ 38 | (t = decrypt_byte(pkeys), update_keys(pkeys,pcrc_32_tab,c), t^(c)) 39 | 40 | /***************************************************************************/ 41 | 42 | /* Return the next byte in the pseudo-random sequence */ 43 | uint8_t decrypt_byte(uint32_t *pkeys); 44 | 45 | /* Update the encryption keys with the next byte of plain text */ 46 | uint8_t update_keys(uint32_t *pkeys, const z_crc_t *pcrc_32_tab, int32_t c); 47 | 48 | /* Initialize the encryption keys and the random header according to the given password. */ 49 | void init_keys(const char *passwd, uint32_t *pkeys, const z_crc_t *pcrc_32_tab); 50 | 51 | /* Generate cryptographically secure random numbers */ 52 | int cryptrand(unsigned char *buf, unsigned int len); 53 | 54 | /* Create encryption header */ 55 | int crypthead(const char *passwd, uint8_t *buf, int buf_size, uint32_t *pkeys, 56 | const z_crc_t *pcrc_32_tab, uint8_t verify1, uint8_t verify2); 57 | 58 | /***************************************************************************/ 59 | 60 | #ifdef __cplusplus 61 | } 62 | #endif 63 | 64 | #endif 65 | -------------------------------------------------------------------------------- /SSZipArchive/minizip/aes/sha1.h: -------------------------------------------------------------------------------- 1 | /* 2 | --------------------------------------------------------------------------- 3 | Copyright (c) 1998-2010, Brian Gladman, Worcester, UK. All rights reserved. 4 | 5 | The redistribution and use of this software (with or without changes) 6 | is allowed without the payment of fees or royalties provided that: 7 | 8 | source code distributions include the above copyright notice, this 9 | list of conditions and the following disclaimer; 10 | 11 | binary distributions include the above copyright notice, this list 12 | of conditions and the following disclaimer in their documentation. 13 | 14 | This software is provided 'as is' with no explicit or implied warranties 15 | in respect of its operation, including, but not limited to, correctness 16 | and fitness for purpose. 17 | --------------------------------------------------------------------------- 18 | Issue Date: 20/12/2007 19 | */ 20 | 21 | #ifndef _SHA1_H 22 | #define _SHA1_H 23 | 24 | #define SHA_1 25 | 26 | /* define for bit or byte oriented SHA */ 27 | #if 1 28 | # define SHA1_BITS 0 /* byte oriented */ 29 | #else 30 | # define SHA1_BITS 1 /* bit oriented */ 31 | #endif 32 | 33 | #include 34 | #include "brg_types.h" 35 | 36 | #define SHA1_BLOCK_SIZE 64 37 | #define SHA1_DIGEST_SIZE 20 38 | 39 | #if defined(__cplusplus) 40 | extern "C" 41 | { 42 | #endif 43 | 44 | /* type to hold the SHA256 context */ 45 | 46 | typedef struct 47 | { uint32_t count[2]; 48 | uint32_t hash[SHA1_DIGEST_SIZE >> 2]; 49 | uint32_t wbuf[SHA1_BLOCK_SIZE >> 2]; 50 | } sha1_ctx; 51 | 52 | /* Note that these prototypes are the same for both bit and */ 53 | /* byte oriented implementations. However the length fields */ 54 | /* are in bytes or bits as appropriate for the version used */ 55 | /* and bit sequences are input as arrays of bytes in which */ 56 | /* bit sequences run from the most to the least significant */ 57 | /* end of each byte. The value 'len' in sha1_hash for the */ 58 | /* byte oriented version of SHA1 is limited to 2^29 bytes, */ 59 | /* but multiple calls will handle longer data blocks. */ 60 | 61 | VOID_RETURN sha1_compile(sha1_ctx ctx[1]); 62 | 63 | VOID_RETURN sha1_begin(sha1_ctx ctx[1]); 64 | VOID_RETURN sha1_hash(const unsigned char data[], unsigned long len, sha1_ctx ctx[1]); 65 | VOID_RETURN sha1_end(unsigned char hval[], sha1_ctx ctx[1]); 66 | VOID_RETURN sha1(unsigned char hval[], const unsigned char data[], unsigned long len); 67 | 68 | #if defined(__cplusplus) 69 | } 70 | #endif 71 | 72 | #endif 73 | -------------------------------------------------------------------------------- /SSZipArchive/minizip/aes/aes_ni.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 1998-2013, Brian Gladman, Worcester, UK. All rights reserved. 3 | 4 | The redistribution and use of this software (with or without changes) 5 | is allowed without the payment of fees or royalties provided that: 6 | 7 | source code distributions include the above copyright notice, this 8 | list of conditions and the following disclaimer; 9 | 10 | binary distributions include the above copyright notice, this list 11 | of conditions and the following disclaimer in their documentation. 12 | 13 | This software is provided 'as is' with no explicit or implied warranties 14 | in respect of its operation, including, but not limited to, correctness 15 | and fitness for purpose. 16 | --------------------------------------------------------------------------- 17 | Issue Date: 13/11/2013 18 | */ 19 | 20 | #ifndef AES_NI_H 21 | #define AES_NI_H 22 | 23 | #define USE_AES_CONTEXT 24 | 25 | #include "aesopt.h" 26 | 27 | #if defined( USE_INTEL_AES_IF_PRESENT ) 28 | 29 | /* map names in C code to make them internal ('name' -> 'aes_name_i') */ 30 | #define aes_xi(x) aes_ ## x ## _i 31 | 32 | /* map names here to provide the external API ('name' -> 'aes_name') */ 33 | #define aes_ni(x) aes_ ## x 34 | 35 | AES_RETURN aes_ni(encrypt_key128)(const unsigned char *key, aes_encrypt_ctx cx[1]); 36 | AES_RETURN aes_ni(encrypt_key192)(const unsigned char *key, aes_encrypt_ctx cx[1]); 37 | AES_RETURN aes_ni(encrypt_key256)(const unsigned char *key, aes_encrypt_ctx cx[1]); 38 | 39 | AES_RETURN aes_ni(decrypt_key128)(const unsigned char *key, aes_decrypt_ctx cx[1]); 40 | AES_RETURN aes_ni(decrypt_key192)(const unsigned char *key, aes_decrypt_ctx cx[1]); 41 | AES_RETURN aes_ni(decrypt_key256)(const unsigned char *key, aes_decrypt_ctx cx[1]); 42 | 43 | AES_RETURN aes_ni(encrypt)(const unsigned char *in, unsigned char *out, const aes_encrypt_ctx cx[1]); 44 | AES_RETURN aes_ni(decrypt)(const unsigned char *in, unsigned char *out, const aes_decrypt_ctx cx[1]); 45 | 46 | AES_RETURN aes_xi(encrypt_key128)(const unsigned char *key, aes_encrypt_ctx cx[1]); 47 | AES_RETURN aes_xi(encrypt_key192)(const unsigned char *key, aes_encrypt_ctx cx[1]); 48 | AES_RETURN aes_xi(encrypt_key256)(const unsigned char *key, aes_encrypt_ctx cx[1]); 49 | 50 | AES_RETURN aes_xi(decrypt_key128)(const unsigned char *key, aes_decrypt_ctx cx[1]); 51 | AES_RETURN aes_xi(decrypt_key192)(const unsigned char *key, aes_decrypt_ctx cx[1]); 52 | AES_RETURN aes_xi(decrypt_key256)(const unsigned char *key, aes_decrypt_ctx cx[1]); 53 | 54 | AES_RETURN aes_xi(encrypt)(const unsigned char *in, unsigned char *out, const aes_encrypt_ctx cx[1]); 55 | AES_RETURN aes_xi(decrypt)(const unsigned char *in, unsigned char *out, const aes_decrypt_ctx cx[1]); 56 | 57 | #endif 58 | 59 | #endif 60 | -------------------------------------------------------------------------------- /SSZipArchive/minizip/aes/prng.h: -------------------------------------------------------------------------------- 1 | /* 2 | --------------------------------------------------------------------------- 3 | Copyright (c) 2002, Dr Brian Gladman < >, Worcester, UK. 4 | All rights reserved. 5 | 6 | LICENSE TERMS 7 | 8 | The free distribution and use of this software in both source and binary 9 | form is allowed (with or without changes) provided that: 10 | 11 | 1. distributions of this source code include the above copyright 12 | notice, this list of conditions and the following disclaimer; 13 | 14 | 2. distributions in binary form include the above copyright 15 | notice, this list of conditions and the following disclaimer 16 | in the documentation and/or other associated materials; 17 | 18 | 3. the copyright holder's name is not used to endorse products 19 | built using this software without specific written permission. 20 | 21 | ALTERNATIVELY, provided that this notice is retained in full, this product 22 | may be distributed under the terms of the GNU General Public License (GPL), 23 | in which case the provisions of the GPL apply INSTEAD OF those given above. 24 | 25 | DISCLAIMER 26 | 27 | This software is provided 'as is' with no explicit or implied warranties 28 | in respect of its properties, including, but not limited to, correctness 29 | and/or fitness for purpose. 30 | --------------------------------------------------------------------------- 31 | Issue Date: 24/01/2003 32 | 33 | This is the header file for an implementation of a random data pool based on 34 | the use of an external entropy function (inspired by Peter Gutmann's work). 35 | */ 36 | 37 | #ifndef _PRNG_H 38 | #define _PRNG_H 39 | 40 | #include "sha1.h" 41 | 42 | #define PRNG_POOL_LEN 256 /* minimum random pool size */ 43 | #define PRNG_MIN_MIX 20 /* min initial pool mixing iterations */ 44 | 45 | /* ensure that pool length is a multiple of the SHA1 digest size */ 46 | 47 | #define PRNG_POOL_SIZE (SHA1_DIGEST_SIZE * (1 + (PRNG_POOL_LEN - 1) / SHA1_DIGEST_SIZE)) 48 | 49 | #if defined(__cplusplus) 50 | extern "C" 51 | { 52 | #endif 53 | 54 | /* A function for providing entropy is a parameter in the prng_init() */ 55 | /* call. This function has the following form and returns a maximum */ 56 | /* of 'len' bytes of pseudo random data in the buffer 'buf'. It can */ 57 | /* return less than 'len' bytes but will be repeatedly called for more */ 58 | /* data in this case. */ 59 | 60 | typedef int (*prng_entropy_fn)(unsigned char buf[], unsigned int len); 61 | 62 | typedef struct 63 | { unsigned char rbuf[PRNG_POOL_SIZE]; /* the random pool */ 64 | unsigned char obuf[PRNG_POOL_SIZE]; /* pool output buffer */ 65 | unsigned int pos; /* output buffer position */ 66 | prng_entropy_fn entropy; /* entropy function pointer */ 67 | } prng_ctx; 68 | 69 | /* initialise the random stream generator */ 70 | void prng_init(prng_entropy_fn fun, prng_ctx ctx[1]); 71 | 72 | /* obtain random bytes from the generator */ 73 | void prng_rand(unsigned char data[], unsigned int data_len, prng_ctx ctx[1]); 74 | 75 | /* close the random stream generator */ 76 | void prng_end(prng_ctx ctx[1]); 77 | 78 | #if defined(__cplusplus) 79 | } 80 | #endif 81 | 82 | #endif 83 | -------------------------------------------------------------------------------- /SSZipArchive/minizip/aes/hmac.h: -------------------------------------------------------------------------------- 1 | /* 2 | --------------------------------------------------------------------------- 3 | Copyright (c) 1998-2010, Brian Gladman, Worcester, UK. All rights reserved. 4 | 5 | The redistribution and use of this software (with or without changes) 6 | is allowed without the payment of fees or royalties provided that: 7 | 8 | source code distributions include the above copyright notice, this 9 | list of conditions and the following disclaimer; 10 | 11 | binary distributions include the above copyright notice, this list 12 | of conditions and the following disclaimer in their documentation. 13 | 14 | This software is provided 'as is' with no explicit or implied warranties 15 | in respect of its operation, including, but not limited to, correctness 16 | and fitness for purpose. 17 | --------------------------------------------------------------------------- 18 | Issue Date: 20/12/2007 19 | 20 | This is an implementation of HMAC, the FIPS standard keyed hash function 21 | */ 22 | 23 | #ifndef _HMAC2_H 24 | #define _HMAC2_H 25 | 26 | #include 27 | #include 28 | 29 | #if defined(__cplusplus) 30 | extern "C" 31 | { 32 | #endif 33 | 34 | #include "sha1.h" 35 | 36 | #if defined(SHA_224) || defined(SHA_256) || defined(SHA_384) || defined(SHA_512) 37 | #define HMAC_MAX_OUTPUT_SIZE SHA2_MAX_DIGEST_SIZE 38 | #define HMAC_MAX_BLOCK_SIZE SHA2_MAX_BLOCK_SIZE 39 | #else 40 | #define HMAC_MAX_OUTPUT_SIZE SHA1_DIGEST_SIZE 41 | #define HMAC_MAX_BLOCK_SIZE SHA1_BLOCK_SIZE 42 | #endif 43 | 44 | #define HMAC_IN_DATA 0xffffffff 45 | 46 | enum hmac_hash 47 | { 48 | #ifdef SHA_1 49 | HMAC_SHA1, 50 | #endif 51 | #ifdef SHA_224 52 | HMAC_SHA224, 53 | #endif 54 | #ifdef SHA_256 55 | HMAC_SHA256, 56 | #endif 57 | #ifdef SHA_384 58 | HMAC_SHA384, 59 | #endif 60 | #ifdef SHA_512 61 | HMAC_SHA512, 62 | HMAC_SHA512_256, 63 | HMAC_SHA512_224, 64 | HMAC_SHA512_192, 65 | HMAC_SHA512_128 66 | #endif 67 | }; 68 | 69 | typedef VOID_RETURN hf_begin(void*); 70 | typedef VOID_RETURN hf_hash(const void*, unsigned long len, void*); 71 | typedef VOID_RETURN hf_end(void*, void*); 72 | 73 | typedef struct 74 | { hf_begin *f_begin; 75 | hf_hash *f_hash; 76 | hf_end *f_end; 77 | unsigned char key[HMAC_MAX_BLOCK_SIZE]; 78 | union 79 | { 80 | #ifdef SHA_1 81 | sha1_ctx u_sha1; 82 | #endif 83 | #ifdef SHA_224 84 | sha224_ctx u_sha224; 85 | #endif 86 | #ifdef SHA_256 87 | sha256_ctx u_sha256; 88 | #endif 89 | #ifdef SHA_384 90 | sha384_ctx u_sha384; 91 | #endif 92 | #ifdef SHA_512 93 | sha512_ctx u_sha512; 94 | #endif 95 | } sha_ctx[1]; 96 | unsigned long input_len; 97 | unsigned long output_len; 98 | unsigned long klen; 99 | } hmac_ctx; 100 | 101 | /* returns the length of hash digest for the hash used */ 102 | /* mac_len must not be greater than this */ 103 | int hmac_sha_begin(enum hmac_hash hash, hmac_ctx cx[1]); 104 | 105 | int hmac_sha_key(const unsigned char key[], unsigned long key_len, hmac_ctx cx[1]); 106 | 107 | void hmac_sha_data(const unsigned char data[], unsigned long data_len, hmac_ctx cx[1]); 108 | 109 | void hmac_sha_end(unsigned char mac[], unsigned long mac_len, hmac_ctx cx[1]); 110 | 111 | void hmac_sha(enum hmac_hash hash, const unsigned char key[], unsigned long key_len, 112 | const unsigned char data[], unsigned long data_len, 113 | unsigned char mac[], unsigned long mac_len); 114 | 115 | #if defined(__cplusplus) 116 | } 117 | #endif 118 | 119 | #endif 120 | -------------------------------------------------------------------------------- /SSZipArchive/SSZipCommon.h: -------------------------------------------------------------------------------- 1 | #ifndef SSZipCommon 2 | #define SSZipCommon 3 | 4 | /* unz_global_info structure contain global data about the ZIPfile 5 | These data comes from the end of central dir */ 6 | typedef struct unz_global_info64_s 7 | { 8 | uint64_t number_entry; /* total number of entries in the central dir on this disk */ 9 | uint32_t number_disk_with_CD; /* number the the disk with central dir, used for spanning ZIP*/ 10 | uint16_t size_comment; /* size of the global comment of the zipfile */ 11 | } unz_global_info64; 12 | 13 | typedef struct unz_global_info_s 14 | { 15 | uint32_t number_entry; /* total number of entries in the central dir on this disk */ 16 | uint32_t number_disk_with_CD; /* number the the disk with central dir, used for spanning ZIP*/ 17 | uint16_t size_comment; /* size of the global comment of the zipfile */ 18 | } unz_global_info; 19 | 20 | /* unz_file_info contain information about a file in the zipfile */ 21 | /* https://pkware.cachefly.net/webdocs/casestudies/APPNOTE.TXT */ 22 | typedef struct unz_file_info64_s 23 | { 24 | uint16_t version; /* version made by 2 bytes */ 25 | uint16_t version_needed; /* version needed to extract 2 bytes */ 26 | uint16_t flag; /* general purpose bit flag 2 bytes */ 27 | uint16_t compression_method; /* compression method 2 bytes */ 28 | uint32_t dos_date; /* last mod file date in Dos fmt 4 bytes */ 29 | uint32_t crc; /* crc-32 4 bytes */ 30 | uint64_t compressed_size; /* compressed size 8 bytes */ 31 | uint64_t uncompressed_size; /* uncompressed size 8 bytes */ 32 | uint16_t size_filename; /* filename length 2 bytes */ 33 | uint16_t size_file_extra; /* extra field length 2 bytes */ 34 | uint16_t size_file_comment; /* file comment length 2 bytes */ 35 | 36 | uint32_t disk_num_start; /* disk number start 4 bytes */ 37 | uint16_t internal_fa; /* internal file attributes 2 bytes */ 38 | uint32_t external_fa; /* external file attributes 4 bytes */ 39 | 40 | uint64_t disk_offset; 41 | 42 | uint16_t size_file_extra_internal; 43 | } unz_file_info64; 44 | 45 | typedef struct unz_file_info_s 46 | { 47 | uint16_t version; /* version made by 2 bytes */ 48 | uint16_t version_needed; /* version needed to extract 2 bytes */ 49 | uint16_t flag; /* general purpose bit flag 2 bytes */ 50 | uint16_t compression_method; /* compression method 2 bytes */ 51 | uint32_t dos_date; /* last mod file date in Dos fmt 4 bytes */ 52 | uint32_t crc; /* crc-32 4 bytes */ 53 | uint32_t compressed_size; /* compressed size 4 bytes */ 54 | uint32_t uncompressed_size; /* uncompressed size 4 bytes */ 55 | uint16_t size_filename; /* filename length 2 bytes */ 56 | uint16_t size_file_extra; /* extra field length 2 bytes */ 57 | uint16_t size_file_comment; /* file comment length 2 bytes */ 58 | 59 | uint16_t disk_num_start; /* disk number start 2 bytes */ 60 | uint16_t internal_fa; /* internal file attributes 2 bytes */ 61 | uint32_t external_fa; /* external file attributes 4 bytes */ 62 | 63 | uint64_t disk_offset; 64 | } unz_file_info; 65 | 66 | #endif 67 | -------------------------------------------------------------------------------- /TDFileManagerViewController.m: -------------------------------------------------------------------------------- 1 | #import "TDFileManagerViewController.h" 2 | #import "TDUtils.h" 3 | 4 | @implementation TDFileManagerViewController 5 | 6 | - (void)loadView { 7 | [super loadView]; 8 | 9 | self.title = @"Decrypted IPAs"; 10 | self.fileList = decryptedFileList(); 11 | 12 | self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Done" style:UIBarButtonItemStyleDone target:self action:@selector(done)]; 13 | } 14 | 15 | - (void)refresh { 16 | self.fileList = decryptedFileList(); 17 | [self.tableView reloadData]; 18 | } 19 | 20 | - (void)done { 21 | [self dismissViewControllerAnimated:YES completion:nil]; 22 | } 23 | 24 | - (NSInteger)numberOfSelectionsInTableView:(UITableView *)tableView { 25 | return 1; 26 | } 27 | 28 | - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { 29 | return self.fileList.count; 30 | } 31 | 32 | - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 33 | static NSString *cellIdentifier = @"FileCell"; 34 | UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier]; 35 | 36 | if (!cell) { 37 | cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellIdentifier]; 38 | } 39 | 40 | NSString *path = [docPath() stringByAppendingPathComponent:self.fileList[indexPath.row]]; 41 | NSDictionary *attributes = [[NSFileManager defaultManager] attributesOfItemAtPath:path error:nil]; 42 | NSDate *date = attributes[NSFileModificationDate]; 43 | NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; 44 | [dateFormatter setDateFormat:@"MMM d, yyyy h:mm a"]; 45 | 46 | NSNumber *fileSize = attributes[NSFileSize]; 47 | 48 | 49 | cell.textLabel.text = self.fileList[indexPath.row]; 50 | cell.detailTextLabel.text = [dateFormatter stringFromDate:date]; 51 | cell.detailTextLabel.textColor = [UIColor systemGray2Color]; 52 | cell.imageView.image = [UIImage systemImageNamed:@"doc.fill"]; 53 | 54 | UILabel *label = [[UILabel alloc] init]; 55 | label.text = [NSString stringWithFormat:@"%.2f MB", [fileSize doubleValue] / 1000000.0f]; 56 | label.textColor = [UIColor systemGray2Color]; 57 | label.font = [UIFont systemFontOfSize:12.0f]; 58 | [label sizeToFit]; 59 | label.textAlignment = NSTextAlignmentCenter; 60 | cell.accessoryView = label; 61 | 62 | 63 | return cell; 64 | } 65 | 66 | - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { 67 | return 65.0f; 68 | } 69 | 70 | - (bool)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath { 71 | return YES; 72 | } 73 | 74 | - (UISwipeActionsConfiguration *)tableView:(UITableView *)tableView trailingSwipeActionsConfigurationForRowAtIndexPath:(NSIndexPath *)indexPath { 75 | UIContextualAction *deleteAction = [UIContextualAction contextualActionWithStyle:UIContextualActionStyleDestructive title:@"Delete" handler:^(UIContextualAction *action, UIView *sourceView, void (^completionHandler)(BOOL)) { 76 | NSString *file = self.fileList[indexPath.row]; 77 | NSString *path = [docPath() stringByAppendingPathComponent:file]; 78 | [[NSFileManager defaultManager] removeItemAtPath:path error:nil]; 79 | [self refresh]; 80 | }]; 81 | 82 | UISwipeActionsConfiguration *swipeActions = [UISwipeActionsConfiguration configurationWithActions:@[deleteAction]]; 83 | return swipeActions; 84 | } 85 | 86 | - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { 87 | NSString *file = self.fileList[indexPath.row]; 88 | NSString *path = [docPath() stringByAppendingPathComponent:file]; 89 | NSURL *url = [NSURL fileURLWithPath:path]; 90 | 91 | UIActivityViewController *activityViewController = [[UIActivityViewController alloc] initWithActivityItems:@[url] applicationActivities:nil]; 92 | [self presentViewController:activityViewController animated:YES completion:nil]; 93 | 94 | [tableView deselectRowAtIndexPath:indexPath animated:YES]; 95 | } 96 | 97 | @end -------------------------------------------------------------------------------- /SSZipArchive/minizip/aes/fileenc.h: -------------------------------------------------------------------------------- 1 | /* 2 | --------------------------------------------------------------------------- 3 | Copyright (c) 2002, Dr Brian Gladman < >, Worcester, UK. 4 | All rights reserved. 5 | 6 | LICENSE TERMS 7 | 8 | The free distribution and use of this software in both source and binary 9 | form is allowed (with or without changes) provided that: 10 | 11 | 1. distributions of this source code include the above copyright 12 | notice, this list of conditions and the following disclaimer; 13 | 14 | 2. distributions in binary form include the above copyright 15 | notice, this list of conditions and the following disclaimer 16 | in the documentation and/or other associated materials; 17 | 18 | 3. the copyright holder's name is not used to endorse products 19 | built using this software without specific written permission. 20 | 21 | ALTERNATIVELY, provided that this notice is retained in full, this product 22 | may be distributed under the terms of the GNU General Public License (GPL), 23 | in which case the provisions of the GPL apply INSTEAD OF those given above. 24 | 25 | DISCLAIMER 26 | 27 | This software is provided 'as is' with no explicit or implied warranties 28 | in respect of its properties, including, but not limited to, correctness 29 | and/or fitness for purpose. 30 | --------------------------------------------------------------------------- 31 | Issue Date: 24/01/2003 32 | 33 | This file contains the header file for fileenc.c, which implements password 34 | based file encryption and authentication using AES in CTR mode, HMAC-SHA1 35 | authentication and RFC2898 password based key derivation. 36 | */ 37 | 38 | #ifndef _FENC_H 39 | #define _FENC_H 40 | 41 | #include "aes.h" 42 | #include "hmac.h" 43 | #include "pwd2key.h" 44 | 45 | #define PASSWORD_VERIFIER 46 | 47 | #define MAX_KEY_LENGTH 32 48 | #define MAX_PWD_LENGTH 128 49 | #define MAX_SALT_LENGTH 16 50 | #define KEYING_ITERATIONS 1000 51 | 52 | #ifdef PASSWORD_VERIFIER 53 | #define PWD_VER_LENGTH 2 54 | #else 55 | #define PWD_VER_LENGTH 0 56 | #endif 57 | 58 | #define GOOD_RETURN 0 59 | #define PASSWORD_TOO_LONG -100 60 | #define BAD_MODE -101 61 | 62 | /* 63 | Field lengths (in bytes) versus File Encryption Mode (0 < mode < 4) 64 | 65 | Mode Key Salt MAC Overhead 66 | 1 16 8 10 18 67 | 2 24 12 10 22 68 | 3 32 16 10 26 69 | 70 | The following macros assume that the mode value is correct. 71 | */ 72 | 73 | #define KEY_LENGTH(mode) (8 * (mode & 3) + 8) 74 | #define SALT_LENGTH(mode) (4 * (mode & 3) + 4) 75 | #define MAC_LENGTH(mode) (10) 76 | 77 | /* the context for file encryption */ 78 | 79 | #if defined(__cplusplus) 80 | extern "C" 81 | { 82 | #endif 83 | 84 | typedef struct 85 | { unsigned char nonce[AES_BLOCK_SIZE]; /* the CTR nonce */ 86 | unsigned char encr_bfr[AES_BLOCK_SIZE]; /* encrypt buffer */ 87 | aes_encrypt_ctx encr_ctx[1]; /* encryption context */ 88 | hmac_ctx auth_ctx[1]; /* authentication context */ 89 | unsigned int encr_pos; /* block position (enc) */ 90 | unsigned int pwd_len; /* password length */ 91 | unsigned int mode; /* File encryption mode */ 92 | } fcrypt_ctx; 93 | 94 | /* initialise file encryption or decryption */ 95 | 96 | int fcrypt_init( 97 | int mode, /* the mode to be used (input) */ 98 | const unsigned char pwd[], /* the user specified password (input) */ 99 | unsigned int pwd_len, /* the length of the password (input) */ 100 | const unsigned char salt[], /* the salt (input) */ 101 | #ifdef PASSWORD_VERIFIER 102 | unsigned char pwd_ver[PWD_VER_LENGTH], /* 2 byte password verifier (output) */ 103 | #endif 104 | fcrypt_ctx cx[1]); /* the file encryption context (output) */ 105 | 106 | /* perform 'in place' encryption or decryption and authentication */ 107 | 108 | void fcrypt_encrypt(unsigned char data[], unsigned int data_len, fcrypt_ctx cx[1]); 109 | void fcrypt_decrypt(unsigned char data[], unsigned int data_len, fcrypt_ctx cx[1]); 110 | 111 | /* close encryption/decryption and return the MAC value */ 112 | /* the return value is the length of the MAC */ 113 | 114 | int fcrypt_end(unsigned char mac[], /* the MAC value (output) */ 115 | fcrypt_ctx cx[1]); /* the context (input) */ 116 | 117 | #if defined(__cplusplus) 118 | } 119 | #endif 120 | 121 | #endif 122 | -------------------------------------------------------------------------------- /SSZipArchive/minizip/crypt.c: -------------------------------------------------------------------------------- 1 | /* crypt.c -- base code for traditional PKWARE encryption 2 | Version 1.2.0, September 16th, 2017 3 | 4 | Copyright (C) 2012-2017 Nathan Moinvaziri 5 | https://github.com/nmoinvaz/minizip 6 | Copyright (C) 1998-2005 Gilles Vollant 7 | Modifications for Info-ZIP crypting 8 | http://www.winimage.com/zLibDll/minizip.html 9 | Copyright (C) 2003 Terry Thorsen 10 | 11 | This code is a modified version of crypting code in Info-ZIP distribution 12 | 13 | Copyright (C) 1990-2000 Info-ZIP. All rights reserved. 14 | 15 | This program is distributed under the terms of the same license as zlib. 16 | See the accompanying LICENSE file for the full text of the license. 17 | 18 | This encryption code is a direct transcription of the algorithm from 19 | Roger Schlafly, described by Phil Katz in the file appnote.txt. This 20 | file (appnote.txt) is distributed with the PKZIP program (even in the 21 | version without encryption capabilities). 22 | 23 | If you don't need crypting in your application, just define symbols 24 | NOCRYPT and NOUNCRYPT. 25 | */ 26 | 27 | #include 28 | #include 29 | #include 30 | #include 31 | 32 | #ifdef _WIN32 33 | # include 34 | # include 35 | #else 36 | # include 37 | # include 38 | # include 39 | #endif 40 | 41 | #include "zlib.h" 42 | 43 | #include "crypt.h" 44 | 45 | /***************************************************************************/ 46 | 47 | #define CRC32(c, b) ((*(pcrc_32_tab+(((uint32_t)(c) ^ (b)) & 0xff))) ^ ((c) >> 8)) 48 | 49 | /***************************************************************************/ 50 | 51 | uint8_t decrypt_byte(uint32_t *pkeys) 52 | { 53 | unsigned temp; /* POTENTIAL BUG: temp*(temp^1) may overflow in an 54 | * unpredictable manner on 16-bit systems; not a problem 55 | * with any known compiler so far, though */ 56 | 57 | temp = ((uint32_t)(*(pkeys+2)) & 0xffff) | 2; 58 | return (uint8_t)(((temp * (temp ^ 1)) >> 8) & 0xff); 59 | } 60 | 61 | uint8_t update_keys(uint32_t *pkeys, const z_crc_t *pcrc_32_tab, int32_t c) 62 | { 63 | (*(pkeys+0)) = (uint32_t)CRC32((*(pkeys+0)), c); 64 | (*(pkeys+1)) += (*(pkeys+0)) & 0xff; 65 | (*(pkeys+1)) = (*(pkeys+1)) * 134775813L + 1; 66 | { 67 | register int32_t keyshift = (int32_t)((*(pkeys + 1)) >> 24); 68 | (*(pkeys+2)) = (uint32_t)CRC32((*(pkeys+2)), keyshift); 69 | } 70 | return c; 71 | } 72 | 73 | void init_keys(const char *passwd, uint32_t *pkeys, const z_crc_t *pcrc_32_tab) 74 | { 75 | *(pkeys+0) = 305419896L; 76 | *(pkeys+1) = 591751049L; 77 | *(pkeys+2) = 878082192L; 78 | while (*passwd != 0) 79 | { 80 | update_keys(pkeys, pcrc_32_tab, *passwd); 81 | passwd += 1; 82 | } 83 | } 84 | 85 | /***************************************************************************/ 86 | 87 | int cryptrand(unsigned char *buf, unsigned int len) 88 | { 89 | #ifdef _WIN32 90 | HCRYPTPROV provider; 91 | unsigned __int64 pentium_tsc[1]; 92 | int rlen = 0; 93 | int result = 0; 94 | 95 | 96 | if (CryptAcquireContext(&provider, NULL, NULL, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT | CRYPT_SILENT)) 97 | { 98 | result = CryptGenRandom(provider, len, buf); 99 | CryptReleaseContext(provider, 0); 100 | if (result) 101 | return len; 102 | } 103 | 104 | for (rlen = 0; rlen < (int)len; ++rlen) 105 | { 106 | if (rlen % 8 == 0) 107 | QueryPerformanceCounter((LARGE_INTEGER *)pentium_tsc); 108 | buf[rlen] = ((unsigned char*)pentium_tsc)[rlen % 8]; 109 | } 110 | 111 | return rlen; 112 | #else 113 | arc4random_buf(buf, len); 114 | return len; 115 | #endif 116 | } 117 | 118 | int crypthead(const char *passwd, uint8_t *buf, int buf_size, uint32_t *pkeys, 119 | const z_crc_t *pcrc_32_tab, uint8_t verify1, uint8_t verify2) 120 | { 121 | uint8_t n = 0; /* index in random header */ 122 | uint8_t header[RAND_HEAD_LEN-2]; /* random header */ 123 | uint16_t t = 0; /* temporary */ 124 | 125 | if (buf_size < RAND_HEAD_LEN) 126 | return 0; 127 | 128 | init_keys(passwd, pkeys, pcrc_32_tab); 129 | 130 | /* First generate RAND_HEAD_LEN-2 random bytes. */ 131 | cryptrand(header, RAND_HEAD_LEN-2); 132 | 133 | /* Encrypt random header (last two bytes is high word of crc) */ 134 | init_keys(passwd, pkeys, pcrc_32_tab); 135 | 136 | for (n = 0; n < RAND_HEAD_LEN-2; n++) 137 | buf[n] = (uint8_t)zencode(pkeys, pcrc_32_tab, header[n], t); 138 | 139 | buf[n++] = (uint8_t)zencode(pkeys, pcrc_32_tab, verify1, t); 140 | buf[n++] = (uint8_t)zencode(pkeys, pcrc_32_tab, verify2, t); 141 | return n; 142 | } 143 | 144 | /***************************************************************************/ 145 | -------------------------------------------------------------------------------- /SSZipArchive/minizip/aes/fileenc.c: -------------------------------------------------------------------------------- 1 | /* 2 | --------------------------------------------------------------------------- 3 | Copyright (c) 2002, Dr Brian Gladman < >, Worcester, UK. 4 | All rights reserved. 5 | 6 | LICENSE TERMS 7 | 8 | The free distribution and use of this software in both source and binary 9 | form is allowed (with or without changes) provided that: 10 | 11 | 1. distributions of this source code include the above copyright 12 | notice, this list of conditions and the following disclaimer; 13 | 14 | 2. distributions in binary form include the above copyright 15 | notice, this list of conditions and the following disclaimer 16 | in the documentation and/or other associated materials; 17 | 18 | 3. the copyright holder's name is not used to endorse products 19 | built using this software without specific written permission. 20 | 21 | ALTERNATIVELY, provided that this notice is retained in full, this product 22 | may be distributed under the terms of the GNU General Public License (GPL), 23 | in which case the provisions of the GPL apply INSTEAD OF those given above. 24 | 25 | DISCLAIMER 26 | 27 | This software is provided 'as is' with no explicit or implied warranties 28 | in respect of its properties, including, but not limited to, correctness 29 | and/or fitness for purpose. 30 | ------------------------------------------------------------------------- 31 | Issue Date: 24/01/2003 32 | 33 | This file implements password based file encryption and authentication 34 | using AES in CTR mode, HMAC-SHA1 authentication and RFC2898 password 35 | based key derivation. 36 | 37 | */ 38 | 39 | #include 40 | 41 | #include "fileenc.h" 42 | 43 | #if defined(__cplusplus) 44 | extern "C" 45 | { 46 | #endif 47 | 48 | /* subroutine for data encryption/decryption */ 49 | /* this could be speeded up a lot by aligning */ 50 | /* buffers and using 32 bit operations */ 51 | 52 | static void encr_data(unsigned char data[], unsigned long d_len, fcrypt_ctx cx[1]) 53 | { 54 | unsigned int i = 0, pos = cx->encr_pos; 55 | 56 | while (i < d_len) 57 | { 58 | if (pos == AES_BLOCK_SIZE) 59 | { 60 | unsigned int j = 0; 61 | /* increment encryption nonce */ 62 | while (j < 8 && !++cx->nonce[j]) 63 | ++j; 64 | /* encrypt the nonce to form next xor buffer */ 65 | aes_encrypt(cx->nonce, cx->encr_bfr, cx->encr_ctx); 66 | pos = 0; 67 | } 68 | 69 | data[i++] ^= cx->encr_bfr[pos++]; 70 | } 71 | 72 | cx->encr_pos = pos; 73 | } 74 | 75 | int fcrypt_init( 76 | int mode, /* the mode to be used (input) */ 77 | const unsigned char pwd[], /* the user specified password (input) */ 78 | unsigned int pwd_len, /* the length of the password (input) */ 79 | const unsigned char salt[], /* the salt (input) */ 80 | #ifdef PASSWORD_VERIFIER 81 | unsigned char pwd_ver[PWD_VER_LENGTH], /* 2 byte password verifier (output) */ 82 | #endif 83 | fcrypt_ctx cx[1]) /* the file encryption context (output) */ 84 | { unsigned char kbuf[2 * MAX_KEY_LENGTH + PWD_VER_LENGTH]; 85 | 86 | if (pwd_len > MAX_PWD_LENGTH) 87 | return PASSWORD_TOO_LONG; 88 | 89 | if (mode < 1 || mode > 3) 90 | return BAD_MODE; 91 | 92 | cx->mode = mode; 93 | cx->pwd_len = pwd_len; 94 | 95 | /* derive the encryption and authentication keys and the password verifier */ 96 | derive_key(pwd, pwd_len, salt, SALT_LENGTH(mode), KEYING_ITERATIONS, 97 | kbuf, 2 * KEY_LENGTH(mode) + PWD_VER_LENGTH); 98 | 99 | /* initialise the encryption nonce and buffer pos */ 100 | cx->encr_pos = AES_BLOCK_SIZE; 101 | /* if we need a random component in the encryption */ 102 | /* nonce, this is where it would have to be set */ 103 | memset(cx->nonce, 0, AES_BLOCK_SIZE * sizeof(unsigned char)); 104 | 105 | /* initialise for encryption using key 1 */ 106 | aes_encrypt_key(kbuf, KEY_LENGTH(mode), cx->encr_ctx); 107 | 108 | /* initialise for authentication using key 2 */ 109 | hmac_sha_begin(HMAC_SHA1, cx->auth_ctx); 110 | hmac_sha_key(kbuf + KEY_LENGTH(mode), KEY_LENGTH(mode), cx->auth_ctx); 111 | 112 | #ifdef PASSWORD_VERIFIER 113 | memcpy(pwd_ver, kbuf + 2 * KEY_LENGTH(mode), PWD_VER_LENGTH); 114 | #endif 115 | 116 | return GOOD_RETURN; 117 | } 118 | 119 | /* perform 'in place' encryption and authentication */ 120 | 121 | void fcrypt_encrypt(unsigned char data[], unsigned int data_len, fcrypt_ctx cx[1]) 122 | { 123 | encr_data(data, data_len, cx); 124 | hmac_sha_data(data, data_len, cx->auth_ctx); 125 | } 126 | 127 | /* perform 'in place' authentication and decryption */ 128 | 129 | void fcrypt_decrypt(unsigned char data[], unsigned int data_len, fcrypt_ctx cx[1]) 130 | { 131 | hmac_sha_data(data, data_len, cx->auth_ctx); 132 | encr_data(data, data_len, cx); 133 | } 134 | 135 | /* close encryption/decryption and return the MAC value */ 136 | 137 | int fcrypt_end(unsigned char mac[], fcrypt_ctx cx[1]) 138 | { 139 | hmac_sha_end(mac, MAC_LENGTH(cx->mode), cx->auth_ctx); 140 | return MAC_LENGTH(cx->mode); /* return MAC length in bytes */ 141 | } 142 | 143 | #if defined(__cplusplus) 144 | } 145 | #endif 146 | -------------------------------------------------------------------------------- /SSZipArchive/minizip/ioapi_mem.c: -------------------------------------------------------------------------------- 1 | /* ioapi_mem.c -- IO base function header for compress/uncompress .zip 2 | files using zlib + zip or unzip API 3 | 4 | This version of ioapi is designed to access memory rather than files. 5 | We do use a region of memory to put data in to and take it out of. We do 6 | not have auto-extending buffers and do not inform anyone else that the 7 | data has been written. It is really intended for accessing a zip archive 8 | embedded in an application such that I can write an installer with no 9 | external files. Creation of archives has not been attempted, although 10 | parts of the framework are present. 11 | 12 | Based on Unzip ioapi.c version 0.22, May 19th, 2003 13 | 14 | Copyright (C) 2012-2017 Nathan Moinvaziri 15 | https://github.com/nmoinvaz/minizip 16 | Copyright (C) 2003 Justin Fletcher 17 | Copyright (C) 1998-2003 Gilles Vollant 18 | http://www.winimage.com/zLibDll/minizip.html 19 | 20 | This file is under the same license as the Unzip tool it is distributed 21 | with. 22 | */ 23 | 24 | 25 | #include 26 | #include 27 | #include 28 | 29 | #include "zlib.h" 30 | #include "ioapi.h" 31 | 32 | #include "ioapi_mem.h" 33 | 34 | #ifndef IOMEM_BUFFERSIZE 35 | # define IOMEM_BUFFERSIZE (UINT16_MAX) 36 | #endif 37 | 38 | voidpf ZCALLBACK fopen_mem_func(voidpf opaque, ZIP_UNUSED const char *filename, int mode) 39 | { 40 | ourmemory_t *mem = (ourmemory_t *)opaque; 41 | if (mem == NULL) 42 | return NULL; /* Mem structure passed in was null */ 43 | 44 | if (mode & ZLIB_FILEFUNC_MODE_CREATE) 45 | { 46 | if (mem->grow) 47 | { 48 | mem->size = IOMEM_BUFFERSIZE; 49 | mem->base = (char *)malloc(mem->size); 50 | } 51 | 52 | mem->limit = 0; /* When writing we start with 0 bytes written */ 53 | } 54 | else 55 | mem->limit = mem->size; 56 | 57 | mem->cur_offset = 0; 58 | 59 | return mem; 60 | } 61 | 62 | voidpf ZCALLBACK fopendisk_mem_func(ZIP_UNUSED voidpf opaque, ZIP_UNUSED voidpf stream, ZIP_UNUSED uint32_t number_disk, ZIP_UNUSED int mode) 63 | { 64 | /* Not used */ 65 | return NULL; 66 | } 67 | 68 | uint32_t ZCALLBACK fread_mem_func(ZIP_UNUSED voidpf opaque, voidpf stream, void *buf, uint32_t size) 69 | { 70 | ourmemory_t *mem = (ourmemory_t *)stream; 71 | 72 | if (size > mem->size - mem->cur_offset) 73 | size = mem->size - mem->cur_offset; 74 | 75 | memcpy(buf, mem->base + mem->cur_offset, size); 76 | mem->cur_offset += size; 77 | 78 | return size; 79 | } 80 | 81 | uint32_t ZCALLBACK fwrite_mem_func(ZIP_UNUSED voidpf opaque, voidpf stream, const void *buf, uint32_t size) 82 | { 83 | ourmemory_t *mem = (ourmemory_t *)stream; 84 | uint32_t newmemsize = 0; 85 | char *newbase = NULL; 86 | 87 | if (size > mem->size - mem->cur_offset) 88 | { 89 | if (mem->grow) 90 | { 91 | newmemsize = mem->size; 92 | if (size < IOMEM_BUFFERSIZE) 93 | newmemsize += IOMEM_BUFFERSIZE; 94 | else 95 | newmemsize += size; 96 | newbase = (char *)malloc(newmemsize); 97 | memcpy(newbase, mem->base, mem->size); 98 | free(mem->base); 99 | mem->base = newbase; 100 | mem->size = newmemsize; 101 | } 102 | else 103 | size = mem->size - mem->cur_offset; 104 | } 105 | memcpy(mem->base + mem->cur_offset, buf, size); 106 | mem->cur_offset += size; 107 | if (mem->cur_offset > mem->limit) 108 | mem->limit = mem->cur_offset; 109 | 110 | return size; 111 | } 112 | 113 | long ZCALLBACK ftell_mem_func(ZIP_UNUSED voidpf opaque, voidpf stream) 114 | { 115 | ourmemory_t *mem = (ourmemory_t *)stream; 116 | return mem->cur_offset; 117 | } 118 | 119 | long ZCALLBACK fseek_mem_func(ZIP_UNUSED voidpf opaque, voidpf stream, uint32_t offset, int origin) 120 | { 121 | ourmemory_t *mem = (ourmemory_t *)stream; 122 | uint32_t new_pos = 0; 123 | switch (origin) 124 | { 125 | case ZLIB_FILEFUNC_SEEK_CUR: 126 | new_pos = mem->cur_offset + offset; 127 | break; 128 | case ZLIB_FILEFUNC_SEEK_END: 129 | new_pos = mem->limit + offset; 130 | break; 131 | case ZLIB_FILEFUNC_SEEK_SET: 132 | new_pos = offset; 133 | break; 134 | default: 135 | return -1; 136 | } 137 | 138 | if (new_pos > mem->size) 139 | return 1; /* Failed to seek that far */ 140 | mem->cur_offset = new_pos; 141 | return 0; 142 | } 143 | 144 | int ZCALLBACK fclose_mem_func(ZIP_UNUSED voidpf opaque, ZIP_UNUSED voidpf stream) 145 | { 146 | /* Even with grow = 1, caller must always free() memory */ 147 | return 0; 148 | } 149 | 150 | int ZCALLBACK ferror_mem_func(ZIP_UNUSED voidpf opaque, ZIP_UNUSED voidpf stream) 151 | { 152 | /* We never return errors */ 153 | return 0; 154 | } 155 | 156 | void fill_memory_filefunc(zlib_filefunc_def *pzlib_filefunc_def, ourmemory_t *ourmem) 157 | { 158 | pzlib_filefunc_def->zopen_file = fopen_mem_func; 159 | pzlib_filefunc_def->zopendisk_file = fopendisk_mem_func; 160 | pzlib_filefunc_def->zread_file = fread_mem_func; 161 | pzlib_filefunc_def->zwrite_file = fwrite_mem_func; 162 | pzlib_filefunc_def->ztell_file = ftell_mem_func; 163 | pzlib_filefunc_def->zseek_file = fseek_mem_func; 164 | pzlib_filefunc_def->zclose_file = fclose_mem_func; 165 | pzlib_filefunc_def->zerror_file = ferror_mem_func; 166 | pzlib_filefunc_def->opaque = ourmem; 167 | } 168 | -------------------------------------------------------------------------------- /SSZipArchive/minizip/aes/brg_endian.h: -------------------------------------------------------------------------------- 1 | /* 2 | --------------------------------------------------------------------------- 3 | Copyright (c) 1998-2013, Brian Gladman, Worcester, UK. All rights reserved. 4 | 5 | The redistribution and use of this software (with or without changes) 6 | is allowed without the payment of fees or royalties provided that: 7 | 8 | source code distributions include the above copyright notice, this 9 | list of conditions and the following disclaimer; 10 | 11 | binary distributions include the above copyright notice, this list 12 | of conditions and the following disclaimer in their documentation. 13 | 14 | This software is provided 'as is' with no explicit or implied warranties 15 | in respect of its operation, including, but not limited to, correctness 16 | and fitness for purpose. 17 | --------------------------------------------------------------------------- 18 | Issue Date: 20/12/2007 19 | */ 20 | 21 | #ifndef _BRG_ENDIAN_H 22 | #define _BRG_ENDIAN_H 23 | 24 | #define IS_BIG_ENDIAN 4321 /* byte 0 is most significant (mc68k) */ 25 | #define IS_LITTLE_ENDIAN 1234 /* byte 0 is least significant (i386) */ 26 | 27 | /* Include files where endian defines and byteswap functions may reside */ 28 | #if defined( __sun ) 29 | # include 30 | #elif defined( __FreeBSD__ ) || defined( __OpenBSD__ ) || defined( __NetBSD__ ) 31 | # include 32 | #elif defined( BSD ) && ( BSD >= 199103 ) || defined( __APPLE__ ) || \ 33 | defined( __CYGWIN32__ ) || defined( __DJGPP__ ) || defined( __osf__ ) || \ 34 | defined(__pnacl__) 35 | # include 36 | #elif defined( __linux__ ) || defined( __GNUC__ ) || defined( __GNU_LIBRARY__ ) 37 | # if !defined( __MINGW32__ ) && !defined( _AIX ) 38 | # include 39 | # if !defined( __BEOS__ ) 40 | # include 41 | # endif 42 | # endif 43 | #endif 44 | 45 | /* Now attempt to set the define for platform byte order using any */ 46 | /* of the four forms SYMBOL, _SYMBOL, __SYMBOL & __SYMBOL__, which */ 47 | /* seem to encompass most endian symbol definitions */ 48 | 49 | #if defined( BIG_ENDIAN ) && defined( LITTLE_ENDIAN ) 50 | # if defined( BYTE_ORDER ) && BYTE_ORDER == BIG_ENDIAN 51 | # define PLATFORM_BYTE_ORDER IS_BIG_ENDIAN 52 | # elif defined( BYTE_ORDER ) && BYTE_ORDER == LITTLE_ENDIAN 53 | # define PLATFORM_BYTE_ORDER IS_LITTLE_ENDIAN 54 | # endif 55 | #elif defined( BIG_ENDIAN ) 56 | # define PLATFORM_BYTE_ORDER IS_BIG_ENDIAN 57 | #elif defined( LITTLE_ENDIAN ) 58 | # define PLATFORM_BYTE_ORDER IS_LITTLE_ENDIAN 59 | #endif 60 | 61 | #if defined( _BIG_ENDIAN ) && defined( _LITTLE_ENDIAN ) 62 | # if defined( _BYTE_ORDER ) && _BYTE_ORDER == _BIG_ENDIAN 63 | # define PLATFORM_BYTE_ORDER IS_BIG_ENDIAN 64 | # elif defined( _BYTE_ORDER ) && _BYTE_ORDER == _LITTLE_ENDIAN 65 | # define PLATFORM_BYTE_ORDER IS_LITTLE_ENDIAN 66 | # endif 67 | #elif defined( _BIG_ENDIAN ) 68 | # define PLATFORM_BYTE_ORDER IS_BIG_ENDIAN 69 | #elif defined( _LITTLE_ENDIAN ) 70 | # define PLATFORM_BYTE_ORDER IS_LITTLE_ENDIAN 71 | #endif 72 | 73 | #if defined( __BIG_ENDIAN ) && defined( __LITTLE_ENDIAN ) 74 | # if defined( __BYTE_ORDER ) && __BYTE_ORDER == __BIG_ENDIAN 75 | # define PLATFORM_BYTE_ORDER IS_BIG_ENDIAN 76 | # elif defined( __BYTE_ORDER ) && __BYTE_ORDER == __LITTLE_ENDIAN 77 | # define PLATFORM_BYTE_ORDER IS_LITTLE_ENDIAN 78 | # endif 79 | #elif defined( __BIG_ENDIAN ) 80 | # define PLATFORM_BYTE_ORDER IS_BIG_ENDIAN 81 | #elif defined( __LITTLE_ENDIAN ) 82 | # define PLATFORM_BYTE_ORDER IS_LITTLE_ENDIAN 83 | #endif 84 | 85 | #if defined( __BIG_ENDIAN__ ) && defined( __LITTLE_ENDIAN__ ) 86 | # if defined( __BYTE_ORDER__ ) && __BYTE_ORDER__ == __BIG_ENDIAN__ 87 | # define PLATFORM_BYTE_ORDER IS_BIG_ENDIAN 88 | # elif defined( __BYTE_ORDER__ ) && __BYTE_ORDER__ == __LITTLE_ENDIAN__ 89 | # define PLATFORM_BYTE_ORDER IS_LITTLE_ENDIAN 90 | # endif 91 | #elif defined( __BIG_ENDIAN__ ) 92 | # define PLATFORM_BYTE_ORDER IS_BIG_ENDIAN 93 | #elif defined( __LITTLE_ENDIAN__ ) 94 | # define PLATFORM_BYTE_ORDER IS_LITTLE_ENDIAN 95 | #endif 96 | 97 | /* if the platform byte order could not be determined, then try to */ 98 | /* set this define using common machine defines */ 99 | #if !defined(PLATFORM_BYTE_ORDER) 100 | 101 | #if defined( __alpha__ ) || defined( __alpha ) || defined( i386 ) || \ 102 | defined( __i386__ ) || defined( _M_I86 ) || defined( _M_IX86 ) || \ 103 | defined( __OS2__ ) || defined( sun386 ) || defined( __TURBOC__ ) || \ 104 | defined( vax ) || defined( vms ) || defined( VMS ) || \ 105 | defined( __VMS ) || defined( _M_X64 ) 106 | # define PLATFORM_BYTE_ORDER IS_LITTLE_ENDIAN 107 | 108 | #elif defined( AMIGA ) || defined( applec ) || defined( __AS400__ ) || \ 109 | defined( _CRAY ) || defined( __hppa ) || defined( __hp9000 ) || \ 110 | defined( ibm370 ) || defined( mc68000 ) || defined( m68k ) || \ 111 | defined( __MRC__ ) || defined( __MVS__ ) || defined( __MWERKS__ ) || \ 112 | defined( sparc ) || defined( __sparc) || defined( SYMANTEC_C ) || \ 113 | defined( __VOS__ ) || defined( __TIGCC__ ) || defined( __TANDEM ) || \ 114 | defined( THINK_C ) || defined( __VMCMS__ ) || defined( _AIX ) 115 | # define PLATFORM_BYTE_ORDER IS_BIG_ENDIAN 116 | 117 | #elif 0 /* **** EDIT HERE IF NECESSARY **** */ 118 | # define PLATFORM_BYTE_ORDER IS_LITTLE_ENDIAN 119 | #elif 0 /* **** EDIT HERE IF NECESSARY **** */ 120 | # define PLATFORM_BYTE_ORDER IS_BIG_ENDIAN 121 | #else 122 | # error Please edit lines 126 or 128 in brg_endian.h to set the platform byte order 123 | #endif 124 | 125 | #endif 126 | 127 | #endif 128 | -------------------------------------------------------------------------------- /SSZipArchive/minizip/aes/prng.c: -------------------------------------------------------------------------------- 1 | /* 2 | --------------------------------------------------------------------------- 3 | Copyright (c) 2002, Dr Brian Gladman < >, Worcester, UK. 4 | All rights reserved. 5 | 6 | LICENSE TERMS 7 | 8 | The free distribution and use of this software in both source and binary 9 | form is allowed (with or without changes) provided that: 10 | 11 | 1. distributions of this source code include the above copyright 12 | notice, this list of conditions and the following disclaimer; 13 | 14 | 2. distributions in binary form include the above copyright 15 | notice, this list of conditions and the following disclaimer 16 | in the documentation and/or other associated materials; 17 | 18 | 3. the copyright holder's name is not used to endorse products 19 | built using this software without specific written permission. 20 | 21 | ALTERNATIVELY, provided that this notice is retained in full, this product 22 | may be distributed under the terms of the GNU General Public License (GPL), 23 | in which case the provisions of the GPL apply INSTEAD OF those given above. 24 | 25 | DISCLAIMER 26 | 27 | This software is provided 'as is' with no explicit or implied warranties 28 | in respect of its properties, including, but not limited to, correctness 29 | and/or fitness for purpose. 30 | --------------------------------------------------------------------------- 31 | Issue Date: 24/01/2003 32 | 33 | This file implements a random data pool based on the use of an external 34 | entropy function. It is based on the ideas advocated by Peter Gutmann in 35 | his work on pseudo random sequence generators. It is not a 'paranoid' 36 | random sequence generator and no attempt is made to protect the pool 37 | from prying eyes either by memory locking or by techniques to obscure 38 | its location in memory. 39 | */ 40 | 41 | #include 42 | #include "prng.h" 43 | 44 | #if defined(__cplusplus) 45 | extern "C" 46 | { 47 | #endif 48 | 49 | /* mix a random data pool using the SHA1 compression function (as */ 50 | /* suggested by Peter Gutmann in his paper on random pools) */ 51 | 52 | static void prng_mix(unsigned char buf[]) 53 | { unsigned int i, len; 54 | sha1_ctx ctx[1]; 55 | 56 | /*lint -e{663} unusual array to pointer conversion */ 57 | for(i = 0; i < PRNG_POOL_SIZE; i += SHA1_DIGEST_SIZE) 58 | { 59 | /* copy digest size pool block into SHA1 hash block */ 60 | memcpy(ctx->hash, buf + (i ? i : PRNG_POOL_SIZE) 61 | - SHA1_DIGEST_SIZE, SHA1_DIGEST_SIZE); 62 | 63 | /* copy data from pool into the SHA1 data buffer */ 64 | len = PRNG_POOL_SIZE - i; 65 | memcpy(ctx->wbuf, buf + i, (len > SHA1_BLOCK_SIZE ? SHA1_BLOCK_SIZE : len)); 66 | 67 | if(len < SHA1_BLOCK_SIZE) 68 | memcpy(((char*)ctx->wbuf) + len, buf, SHA1_BLOCK_SIZE - len); 69 | 70 | /* compress using the SHA1 compression function */ 71 | sha1_compile(ctx); 72 | 73 | /* put digest size block back into the random pool */ 74 | memcpy(buf + i, ctx->hash, SHA1_DIGEST_SIZE); 75 | } 76 | } 77 | 78 | /* refresh the output buffer and update the random pool by adding */ 79 | /* entropy and remixing */ 80 | 81 | static void update_pool(prng_ctx ctx[1]) 82 | { unsigned int i = 0; 83 | 84 | /* transfer random pool data to the output buffer */ 85 | memcpy(ctx->obuf, ctx->rbuf, PRNG_POOL_SIZE); 86 | 87 | /* enter entropy data into the pool */ 88 | while(i < PRNG_POOL_SIZE) 89 | i += ctx->entropy(ctx->rbuf + i, PRNG_POOL_SIZE - i); 90 | 91 | /* invert and xor the original pool data into the pool */ 92 | for(i = 0; i < PRNG_POOL_SIZE; ++i) 93 | ctx->rbuf[i] ^= ~ctx->obuf[i]; 94 | 95 | /* mix the pool and the output buffer */ 96 | prng_mix(ctx->rbuf); 97 | prng_mix(ctx->obuf); 98 | } 99 | 100 | void prng_init(prng_entropy_fn fun, prng_ctx ctx[1]) 101 | { int i; 102 | 103 | /* clear the buffers and the counter in the context */ 104 | memset(ctx, 0, sizeof(prng_ctx)); 105 | 106 | /* set the pointer to the entropy collection function */ 107 | ctx->entropy = fun; 108 | 109 | /* initialise the random data pool */ 110 | update_pool(ctx); 111 | 112 | /* mix the pool a minimum number of times */ 113 | for(i = 0; i < PRNG_MIN_MIX; ++i) 114 | prng_mix(ctx->rbuf); 115 | 116 | /* update the pool to prime the pool output buffer */ 117 | update_pool(ctx); 118 | } 119 | 120 | /* provide random bytes from the random data pool */ 121 | 122 | void prng_rand(unsigned char data[], unsigned int data_len, prng_ctx ctx[1]) 123 | { unsigned char *rp = data; 124 | unsigned int len, pos = ctx->pos; 125 | 126 | while(data_len) 127 | { 128 | /* transfer 'data_len' bytes (or the number of bytes remaining */ 129 | /* the pool output buffer if less) into the output */ 130 | len = (data_len < PRNG_POOL_SIZE - pos ? data_len : PRNG_POOL_SIZE - pos); 131 | memcpy(rp, ctx->obuf + pos, len); 132 | rp += len; /* update ouput buffer position pointer */ 133 | pos += len; /* update pool output buffer pointer */ 134 | data_len -= len; /* update the remaining data count */ 135 | 136 | /* refresh the random pool if necessary */ 137 | if(pos == PRNG_POOL_SIZE) 138 | { 139 | update_pool(ctx); pos = 0; 140 | } 141 | } 142 | 143 | ctx->pos = pos; 144 | } 145 | 146 | void prng_end(prng_ctx ctx[1]) 147 | { 148 | /* ensure the data in the context is destroyed */ 149 | memset(ctx, 0, sizeof(prng_ctx)); 150 | } 151 | 152 | #if defined(__cplusplus) 153 | } 154 | #endif 155 | 156 | -------------------------------------------------------------------------------- /SSZipArchive/minizip/aes/aestab.h: -------------------------------------------------------------------------------- 1 | /* 2 | --------------------------------------------------------------------------- 3 | Copyright (c) 1998-2013, Brian Gladman, Worcester, UK. All rights reserved. 4 | 5 | The redistribution and use of this software (with or without changes) 6 | is allowed without the payment of fees or royalties provided that: 7 | 8 | source code distributions include the above copyright notice, this 9 | list of conditions and the following disclaimer; 10 | 11 | binary distributions include the above copyright notice, this list 12 | of conditions and the following disclaimer in their documentation. 13 | 14 | This software is provided 'as is' with no explicit or implied warranties 15 | in respect of its operation, including, but not limited to, correctness 16 | and fitness for purpose. 17 | --------------------------------------------------------------------------- 18 | Issue Date: 20/12/2007 19 | 20 | This file contains the code for declaring the tables needed to implement 21 | AES. The file aesopt.h is assumed to be included before this header file. 22 | If there are no global variables, the definitions here can be used to put 23 | the AES tables in a structure so that a pointer can then be added to the 24 | AES context to pass them to the AES routines that need them. If this 25 | facility is used, the calling program has to ensure that this pointer is 26 | managed appropriately. In particular, the value of the t_dec(in,it) item 27 | in the table structure must be set to zero in order to ensure that the 28 | tables are initialised. In practice the three code sequences in aeskey.c 29 | that control the calls to aes_init() and the aes_init() routine itself will 30 | have to be changed for a specific implementation. If global variables are 31 | available it will generally be preferable to use them with the precomputed 32 | STATIC_TABLES option that uses static global tables. 33 | 34 | The following defines can be used to control the way the tables 35 | are defined, initialised and used in embedded environments that 36 | require special features for these purposes 37 | 38 | the 't_dec' construction is used to declare fixed table arrays 39 | the 't_set' construction is used to set fixed table values 40 | the 't_use' construction is used to access fixed table values 41 | 42 | 256 byte tables: 43 | 44 | t_xxx(s,box) => forward S box 45 | t_xxx(i,box) => inverse S box 46 | 47 | 256 32-bit word OR 4 x 256 32-bit word tables: 48 | 49 | t_xxx(f,n) => forward normal round 50 | t_xxx(f,l) => forward last round 51 | t_xxx(i,n) => inverse normal round 52 | t_xxx(i,l) => inverse last round 53 | t_xxx(l,s) => key schedule table 54 | t_xxx(i,m) => key schedule table 55 | 56 | Other variables and tables: 57 | 58 | t_xxx(r,c) => the rcon table 59 | */ 60 | 61 | #if !defined( _AESTAB_H ) 62 | #define _AESTAB_H 63 | 64 | #if defined(__cplusplus) 65 | extern "C" { 66 | #endif 67 | 68 | #define t_dec(m,n) t_##m##n 69 | #define t_set(m,n) t_##m##n 70 | #define t_use(m,n) t_##m##n 71 | 72 | #if defined(STATIC_TABLES) 73 | # if !defined( __GNUC__ ) && (defined( __MSDOS__ ) || defined( __WIN16__ )) 74 | /* make tables far data to avoid using too much DGROUP space (PG) */ 75 | # define CONST const far 76 | # else 77 | # define CONST const 78 | # endif 79 | #else 80 | # define CONST 81 | #endif 82 | 83 | #if defined(DO_TABLES) 84 | # define EXTERN 85 | #else 86 | # define EXTERN extern 87 | #endif 88 | 89 | #if defined(_MSC_VER) && defined(TABLE_ALIGN) 90 | #define ALIGN __declspec(align(TABLE_ALIGN)) 91 | #else 92 | #define ALIGN 93 | #endif 94 | 95 | #if defined( __WATCOMC__ ) && ( __WATCOMC__ >= 1100 ) 96 | # define XP_DIR __cdecl 97 | #else 98 | # define XP_DIR 99 | #endif 100 | 101 | #if defined(DO_TABLES) && defined(STATIC_TABLES) 102 | #define d_1(t,n,b,e) EXTERN ALIGN CONST XP_DIR t n[256] = b(e) 103 | #define d_4(t,n,b,e,f,g,h) EXTERN ALIGN CONST XP_DIR t n[4][256] = { b(e), b(f), b(g), b(h) } 104 | EXTERN ALIGN CONST uint32_t t_dec(r,c)[RC_LENGTH] = rc_data(w0); 105 | #else 106 | #define d_1(t,n,b,e) EXTERN ALIGN CONST XP_DIR t n[256] 107 | #define d_4(t,n,b,e,f,g,h) EXTERN ALIGN CONST XP_DIR t n[4][256] 108 | EXTERN ALIGN CONST uint32_t t_dec(r,c)[RC_LENGTH]; 109 | #endif 110 | 111 | #if defined( SBX_SET ) 112 | d_1(uint8_t, t_dec(s,box), sb_data, h0); 113 | #endif 114 | #if defined( ISB_SET ) 115 | d_1(uint8_t, t_dec(i,box), isb_data, h0); 116 | #endif 117 | 118 | #if defined( FT1_SET ) 119 | d_1(uint32_t, t_dec(f,n), sb_data, u0); 120 | #endif 121 | #if defined( FT4_SET ) 122 | d_4(uint32_t, t_dec(f,n), sb_data, u0, u1, u2, u3); 123 | #endif 124 | 125 | #if defined( FL1_SET ) 126 | d_1(uint32_t, t_dec(f,l), sb_data, w0); 127 | #endif 128 | #if defined( FL4_SET ) 129 | d_4(uint32_t, t_dec(f,l), sb_data, w0, w1, w2, w3); 130 | #endif 131 | 132 | #if defined( IT1_SET ) 133 | d_1(uint32_t, t_dec(i,n), isb_data, v0); 134 | #endif 135 | #if defined( IT4_SET ) 136 | d_4(uint32_t, t_dec(i,n), isb_data, v0, v1, v2, v3); 137 | #endif 138 | 139 | #if defined( IL1_SET ) 140 | d_1(uint32_t, t_dec(i,l), isb_data, w0); 141 | #endif 142 | #if defined( IL4_SET ) 143 | d_4(uint32_t, t_dec(i,l), isb_data, w0, w1, w2, w3); 144 | #endif 145 | 146 | #if defined( LS1_SET ) 147 | #if defined( FL1_SET ) 148 | #undef LS1_SET 149 | #else 150 | d_1(uint32_t, t_dec(l,s), sb_data, w0); 151 | #endif 152 | #endif 153 | 154 | #if defined( LS4_SET ) 155 | #if defined( FL4_SET ) 156 | #undef LS4_SET 157 | #else 158 | d_4(uint32_t, t_dec(l,s), sb_data, w0, w1, w2, w3); 159 | #endif 160 | #endif 161 | 162 | #if defined( IM1_SET ) 163 | d_1(uint32_t, t_dec(i,m), mm_data, v0); 164 | #endif 165 | #if defined( IM4_SET ) 166 | d_4(uint32_t, t_dec(i,m), mm_data, v0, v1, v2, v3); 167 | #endif 168 | 169 | #if defined(__cplusplus) 170 | } 171 | #endif 172 | 173 | #endif 174 | -------------------------------------------------------------------------------- /LSApplicationProxy+AltList.m: -------------------------------------------------------------------------------- 1 | #import 2 | #import "LSApplicationProxy+AltList.h" 3 | 4 | @implementation LSApplicationProxy (AltList) 5 | 6 | - (BOOL)atl_isSystemApplication 7 | { 8 | return [self.applicationType isEqualToString:@"System"] && ![self atl_isHidden]; 9 | } 10 | 11 | - (BOOL)atl_isUserApplication 12 | { 13 | return [self.applicationType isEqualToString:@"User"] && ![self atl_isHidden]; 14 | } 15 | 16 | // the tag " hidden " is also valid, so we need to check if any strings contain "hidden" instead 17 | BOOL tagArrayContainsTag(NSArray* tagArr, NSString* tag) 18 | { 19 | if(!tagArr || !tag) return NO; 20 | 21 | __block BOOL found = NO; 22 | 23 | [tagArr enumerateObjectsUsingBlock:^(NSString* tagToCheck, NSUInteger idx, BOOL* stop) 24 | { 25 | if(![tagToCheck isKindOfClass:[NSString class]]) 26 | { 27 | return; 28 | } 29 | 30 | if([tagToCheck rangeOfString:tag options:0].location != NSNotFound) 31 | { 32 | found = YES; 33 | *stop = YES; 34 | } 35 | }]; 36 | 37 | return found; 38 | } 39 | 40 | // always returns NO on iOS 7 41 | - (BOOL)atl_isHidden 42 | { 43 | NSArray* appTags; 44 | NSArray* recordAppTags; 45 | NSArray* sbAppTags; 46 | 47 | BOOL launchProhibited = NO; 48 | 49 | if([self respondsToSelector:@selector(correspondingApplicationRecord)]) 50 | { 51 | // On iOS 14, self.appTags is always empty but the application record still has the correct ones 52 | LSApplicationRecord* record = [self correspondingApplicationRecord]; 53 | recordAppTags = record.appTags; 54 | launchProhibited = record.launchProhibited; 55 | } 56 | if([self respondsToSelector:@selector(appTags)]) 57 | { 58 | appTags = self.appTags; 59 | } 60 | if(!launchProhibited && [self respondsToSelector:@selector(isLaunchProhibited)]) 61 | { 62 | launchProhibited = self.launchProhibited; 63 | } 64 | 65 | NSURL* bundleURL = self.bundleURL; 66 | if(bundleURL && [bundleURL checkResourceIsReachableAndReturnError:nil]) 67 | { 68 | NSBundle* bundle = [NSBundle bundleWithURL:bundleURL]; 69 | sbAppTags = [bundle objectForInfoDictionaryKey:@"SBAppTags"]; 70 | } 71 | 72 | BOOL isWebApplication = ([self.atl_bundleIdentifier rangeOfString:@"com.apple.webapp" options:NSCaseInsensitiveSearch].location != NSNotFound); 73 | return tagArrayContainsTag(appTags, @"hidden") || tagArrayContainsTag(recordAppTags, @"hidden") || tagArrayContainsTag(sbAppTags, @"hidden") || isWebApplication || launchProhibited; 74 | } 75 | 76 | // Getting the display name is slow (up to 2ms) because it uses an IPC call 77 | // this stacks up if you do it for every single application 78 | // This method provides a faster way (around 0.5ms) to get the display name 79 | // This reduces the overall time needed to sort the applications from ~230 to ~120ms on my test device 80 | - (NSString*)atl_fastDisplayName 81 | { 82 | NSString* cachedDisplayName = [self valueForKey:@"_localizedName"]; 83 | if(cachedDisplayName && ![cachedDisplayName isEqualToString:@""]) 84 | { 85 | return cachedDisplayName; 86 | } 87 | 88 | NSString* localizedName; 89 | 90 | NSURL* bundleURL = self.bundleURL; 91 | if(!bundleURL || ![bundleURL checkResourceIsReachableAndReturnError:nil]) 92 | { 93 | localizedName = self.localizedName; 94 | } 95 | else 96 | { 97 | NSBundle* bundle = [NSBundle bundleWithURL:bundleURL]; 98 | 99 | localizedName = [bundle objectForInfoDictionaryKey:@"CFBundleDisplayName"]; 100 | if(![localizedName isKindOfClass:[NSString class]]) localizedName = nil; 101 | if(!localizedName || [localizedName isEqualToString:@""]) 102 | { 103 | localizedName = [bundle objectForInfoDictionaryKey:@"CFBundleName"]; 104 | if(![localizedName isKindOfClass:[NSString class]]) localizedName = nil; 105 | if(!localizedName || [localizedName isEqualToString:@""]) 106 | { 107 | localizedName = [bundle objectForInfoDictionaryKey:@"CFBundleExecutable"]; 108 | if(![localizedName isKindOfClass:[NSString class]]) localizedName = nil; 109 | if(!localizedName || [localizedName isEqualToString:@""]) 110 | { 111 | //last possible fallback: use slow IPC call 112 | localizedName = self.localizedName; 113 | } 114 | } 115 | } 116 | } 117 | 118 | [self setValue:localizedName forKey:@"_localizedName"]; 119 | return localizedName; 120 | } 121 | 122 | - (NSString*)atl_nameToDisplay 123 | { 124 | NSString* localizedName = [self atl_fastDisplayName]; 125 | 126 | if([self.atl_bundleIdentifier rangeOfString:@"carplay" options:NSCaseInsensitiveSearch].location != NSNotFound) 127 | { 128 | if([localizedName rangeOfString:@"carplay" options:NSCaseInsensitiveSearch range:NSMakeRange(0, localizedName.length) locale:[NSLocale currentLocale]].location == NSNotFound) 129 | { 130 | return [localizedName stringByAppendingString:@" (CarPlay)"]; 131 | } 132 | } 133 | 134 | return localizedName; 135 | } 136 | 137 | -(id)atl_bundleIdentifier 138 | { 139 | // iOS 8-14 140 | if([self respondsToSelector:@selector(bundleIdentifier)]) 141 | { 142 | return [self bundleIdentifier]; 143 | } 144 | // iOS 7 145 | else 146 | { 147 | return [self applicationIdentifier]; 148 | } 149 | } 150 | 151 | - (NSString *)atl_shortVersionString { 152 | NSString *version = self.shortVersionString; 153 | if (version == nil || [version isEqualToString:@""]) { 154 | version = @"1.0"; 155 | } 156 | 157 | return version; 158 | } 159 | 160 | @end 161 | 162 | @implementation LSApplicationWorkspace (AltList) 163 | 164 | - (NSArray*)atl_allInstalledApplications 165 | { 166 | if(![self respondsToSelector:@selector(enumerateApplicationsOfType:block:)]) 167 | { 168 | return [self allInstalledApplications]; 169 | } 170 | 171 | NSMutableArray* installedApplications = [NSMutableArray new]; 172 | [self enumerateApplicationsOfType:0 block:^(LSApplicationProxy* appProxy) 173 | { 174 | [installedApplications addObject:appProxy]; 175 | }]; 176 | [self enumerateApplicationsOfType:1 block:^(LSApplicationProxy* appProxy) 177 | { 178 | [installedApplications addObject:appProxy]; 179 | }]; 180 | return installedApplications; 181 | } 182 | 183 | @end -------------------------------------------------------------------------------- /SSZipArchive/minizip/aes/pwd2key.c: -------------------------------------------------------------------------------- 1 | /* 2 | --------------------------------------------------------------------------- 3 | Copyright (c) 1998-2010, Brian Gladman, Worcester, UK. All rights reserved. 4 | 5 | The redistribution and use of this software (with or without changes) 6 | is allowed without the payment of fees or royalties provided that: 7 | 8 | source code distributions include the above copyright notice, this 9 | list of conditions and the following disclaimer; 10 | 11 | binary distributions include the above copyright notice, this list 12 | of conditions and the following disclaimer in their documentation. 13 | 14 | This software is provided 'as is' with no explicit or implied warranties 15 | in respect of its operation, including, but not limited to, correctness 16 | and fitness for purpose. 17 | --------------------------------------------------------------------------- 18 | Issue Date: 20/12/2007 19 | 20 | This is an implementation of RFC2898, which specifies key derivation from 21 | a password and a salt value. 22 | */ 23 | 24 | #include 25 | #include "hmac.h" 26 | 27 | #if defined(__cplusplus) 28 | extern "C" 29 | { 30 | #endif 31 | 32 | void derive_key(const unsigned char pwd[], /* the PASSWORD */ 33 | unsigned int pwd_len, /* and its length */ 34 | const unsigned char salt[], /* the SALT and its */ 35 | unsigned int salt_len, /* length */ 36 | unsigned int iter, /* the number of iterations */ 37 | unsigned char key[], /* space for the output key */ 38 | unsigned int key_len)/* and its required length */ 39 | { 40 | unsigned int i, j, k, n_blk, h_size; 41 | unsigned char uu[HMAC_MAX_OUTPUT_SIZE], ux[HMAC_MAX_OUTPUT_SIZE]; 42 | hmac_ctx c1[1], c2[1], c3[1]; 43 | 44 | /* set HMAC context (c1) for password */ 45 | h_size = hmac_sha_begin(HMAC_SHA1, c1); 46 | hmac_sha_key(pwd, pwd_len, c1); 47 | 48 | /* set HMAC context (c2) for password and salt */ 49 | memcpy(c2, c1, sizeof(hmac_ctx)); 50 | hmac_sha_data(salt, salt_len, c2); 51 | 52 | /* find the number of SHA blocks in the key */ 53 | n_blk = 1 + (key_len - 1) / h_size; 54 | 55 | for(i = 0; i < n_blk; ++i) /* for each block in key */ 56 | { 57 | /* ux[] holds the running xor value */ 58 | memset(ux, 0, h_size); 59 | 60 | /* set HMAC context (c3) for password and salt */ 61 | memcpy(c3, c2, sizeof(hmac_ctx)); 62 | 63 | /* enter additional data for 1st block into uu */ 64 | uu[0] = (unsigned char)((i + 1) >> 24); 65 | uu[1] = (unsigned char)((i + 1) >> 16); 66 | uu[2] = (unsigned char)((i + 1) >> 8); 67 | uu[3] = (unsigned char)(i + 1); 68 | 69 | /* this is the key mixing iteration */ 70 | for(j = 0, k = 4; j < iter; ++j) 71 | { 72 | /* add previous round data to HMAC */ 73 | hmac_sha_data(uu, k, c3); 74 | 75 | /* obtain HMAC for uu[] */ 76 | hmac_sha_end(uu, h_size, c3); 77 | 78 | /* xor into the running xor block */ 79 | for(k = 0; k < h_size; ++k) 80 | ux[k] ^= uu[k]; 81 | 82 | /* set HMAC context (c3) for password */ 83 | memcpy(c3, c1, sizeof(hmac_ctx)); 84 | } 85 | 86 | /* compile key blocks into the key output */ 87 | j = 0; k = i * h_size; 88 | while(j < h_size && k < key_len) 89 | key[k++] = ux[j++]; 90 | } 91 | } 92 | 93 | #ifdef TEST 94 | 95 | #include 96 | 97 | struct 98 | { unsigned int pwd_len; 99 | unsigned int salt_len; 100 | unsigned int it_count; 101 | unsigned char *pwd; 102 | unsigned char salt[32]; 103 | unsigned char key[32]; 104 | } tests[] = 105 | { 106 | { 8, 4, 5, (unsigned char*)"password", 107 | { 108 | 0x12, 0x34, 0x56, 0x78 109 | }, 110 | { 111 | 0x5c, 0x75, 0xce, 0xf0, 0x1a, 0x96, 0x0d, 0xf7, 112 | 0x4c, 0xb6, 0xb4, 0x9b, 0x9e, 0x38, 0xe6, 0xb5 113 | } 114 | }, 115 | { 8, 8, 5, (unsigned char*)"password", 116 | { 117 | 0x12, 0x34, 0x56, 0x78, 0x78, 0x56, 0x34, 0x12 118 | }, 119 | { 120 | 0xd1, 0xda, 0xa7, 0x86, 0x15, 0xf2, 0x87, 0xe6, 121 | 0xa1, 0xc8, 0xb1, 0x20, 0xd7, 0x06, 0x2a, 0x49 122 | } 123 | }, 124 | { 8, 21, 1, (unsigned char*)"password", 125 | { 126 | "ATHENA.MIT.EDUraeburn" 127 | }, 128 | { 129 | 0xcd, 0xed, 0xb5, 0x28, 0x1b, 0xb2, 0xf8, 0x01, 130 | 0x56, 0x5a, 0x11, 0x22, 0xb2, 0x56, 0x35, 0x15 131 | } 132 | }, 133 | { 8, 21, 2, (unsigned char*)"password", 134 | { 135 | "ATHENA.MIT.EDUraeburn" 136 | }, 137 | { 138 | 0x01, 0xdb, 0xee, 0x7f, 0x4a, 0x9e, 0x24, 0x3e, 139 | 0x98, 0x8b, 0x62, 0xc7, 0x3c, 0xda, 0x93, 0x5d 140 | } 141 | }, 142 | { 8, 21, 1200, (unsigned char*)"password", 143 | { 144 | "ATHENA.MIT.EDUraeburn" 145 | }, 146 | { 147 | 0x5c, 0x08, 0xeb, 0x61, 0xfd, 0xf7, 0x1e, 0x4e, 148 | 0x4e, 0xc3, 0xcf, 0x6b, 0xa1, 0xf5, 0x51, 0x2b 149 | } 150 | } 151 | }; 152 | 153 | int main() 154 | { unsigned int i, j, key_len = 256; 155 | unsigned char key[256]; 156 | 157 | printf("\nTest of RFC2898 Password Based Key Derivation"); 158 | for(i = 0; i < 5; ++i) 159 | { 160 | derive_key(tests[i].pwd, tests[i].pwd_len, tests[i].salt, 161 | tests[i].salt_len, tests[i].it_count, key, key_len); 162 | 163 | printf("\ntest %i: ", i + 1); 164 | printf("key %s", memcmp(tests[i].key, key, 16) ? "is bad" : "is good"); 165 | for(j = 0; j < key_len && j < 64; j += 4) 166 | { 167 | if(j % 16 == 0) 168 | printf("\n"); 169 | printf("0x%02x%02x%02x%02x ", key[j], key[j + 1], key[j + 2], key[j + 3]); 170 | } 171 | printf(j < key_len ? " ... \n" : "\n"); 172 | } 173 | printf("\n"); 174 | return 0; 175 | } 176 | 177 | #if defined(__cplusplus) 178 | } 179 | #endif 180 | 181 | #endif 182 | -------------------------------------------------------------------------------- /TDRootViewController.m: -------------------------------------------------------------------------------- 1 | #import "TDRootViewController.h" 2 | #import "TDFileManagerViewController.h" 3 | #import "TDUtils.h" 4 | 5 | @implementation TDRootViewController 6 | 7 | - (void)loadView { 8 | [super loadView]; 9 | 10 | self.apps = appList(); 11 | self.title = @"TrollDecrypt"; 12 | self.navigationController.navigationBar.prefersLargeTitles = YES; 13 | self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage systemImageNamed:@"info.circle"] style:UIBarButtonItemStylePlain target:self action:@selector(about:)]; 14 | self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage systemImageNamed:@"folder"] style:UIBarButtonItemStylePlain target:self action:@selector(openDocs:)]; 15 | 16 | UIRefreshControl *refreshControl = [[UIRefreshControl alloc] init]; 17 | [refreshControl addTarget:self action:@selector(refreshApps:) forControlEvents:UIControlEventValueChanged]; 18 | self.refreshControl = refreshControl; 19 | } 20 | 21 | - (void)viewDidAppear:(bool)animated { 22 | [super viewDidAppear:animated]; 23 | 24 | fetchLatestTrollDecryptVersion(^(NSString *latestVersion) { 25 | NSString *currentVersion = trollDecryptVersion(); 26 | NSComparisonResult result = [currentVersion compare:latestVersion options:NSNumericSearch]; 27 | NSLog(@"[trolldecrypter] Current version: %@, Latest version: %@", currentVersion, latestVersion); 28 | if (result == NSOrderedAscending) { 29 | dispatch_async(dispatch_get_main_queue(), ^{ 30 | UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Update Available" message:@"An update for TrollDecrypt is available." preferredStyle:UIAlertControllerStyleAlert]; 31 | UIAlertAction *cancel = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:nil]; 32 | UIAlertAction *update = [UIAlertAction actionWithTitle:@"Download" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) { 33 | [[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:@"https://github.com/donato-fiore/TrollDecrypt/releases/latest"]] options:@{} completionHandler:nil]; 34 | }]; 35 | 36 | [alert addAction:update]; 37 | [alert addAction:cancel]; 38 | [self presentViewController:alert animated:YES completion:nil]; 39 | }); 40 | } 41 | }); 42 | } 43 | 44 | - (void)openDocs:(id)sender { 45 | TDFileManagerViewController *fmVC = [[TDFileManagerViewController alloc] init]; 46 | UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:fmVC]; 47 | [self presentViewController:navController animated:YES completion:nil]; 48 | } 49 | 50 | - (void)about:(id)sender { 51 | UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"TrollDecrypt" message:@"by fiore\nIcon by @super.user\nbfdecrypt by @bishopfox\ndumpdecrypted by @i0n1c\nUpdated for TrollStore by @wh1te4ever" preferredStyle:UIAlertControllerStyleAlert]; 52 | [alert addAction:[UIAlertAction actionWithTitle:@"Dismiss" style:UIAlertActionStyleCancel handler:nil]]; 53 | [self presentViewController:alert animated:YES completion:nil]; 54 | } 55 | 56 | - (void)refreshApps:(UIRefreshControl *)refreshControl { 57 | self.apps = appList(); 58 | [self.tableView reloadData]; 59 | [refreshControl endRefreshing]; 60 | } 61 | 62 | - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { 63 | return 1; 64 | } 65 | 66 | - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { 67 | return self.apps.count; 68 | } 69 | 70 | - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 71 | static NSString *cellIdentifier = @"AppCell"; 72 | UITableViewCell *cell; 73 | if (([self.apps count] - 1) != indexPath.row) { 74 | cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier]; 75 | if (cell == nil) cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellIdentifier]; 76 | 77 | NSDictionary *app = self.apps[indexPath.row]; 78 | 79 | cell.textLabel.text = app[@"name"]; 80 | cell.detailTextLabel.text = [NSString stringWithFormat:@"%@ • %@", app[@"version"], app[@"bundleID"]]; 81 | cell.imageView.image = [UIImage _applicationIconImageForBundleIdentifier:app[@"bundleID"] format:iconFormat() scale:[UIScreen mainScreen].scale]; 82 | } else { 83 | cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:nil]; 84 | 85 | cell.textLabel.text = @"Advanced"; 86 | cell.detailTextLabel.text = @"Decrypt app from a specified PID"; 87 | cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; 88 | } 89 | 90 | return cell; 91 | } 92 | 93 | - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { 94 | return 80.0f; 95 | } 96 | 97 | - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { 98 | UIAlertController *alert; 99 | 100 | if (([self.apps count] - 1) != indexPath.row) { 101 | NSDictionary *app = self.apps[indexPath.row]; 102 | 103 | alert = [UIAlertController alertControllerWithTitle:@"Decrypt" message:[NSString stringWithFormat:@"Decrypt %@?", app[@"name"]] preferredStyle:UIAlertControllerStyleAlert]; 104 | UIAlertAction *cancel = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:nil]; 105 | UIAlertAction *decrypt = [UIAlertAction actionWithTitle:@"Yes" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) { 106 | decryptApp(app); 107 | }]; 108 | 109 | [alert addAction:decrypt]; 110 | [alert addAction:cancel]; 111 | } else { 112 | alert = [UIAlertController alertControllerWithTitle:@"Decrypt" message:@"Enter PID to decrypt" preferredStyle:UIAlertControllerStyleAlert]; 113 | [alert addTextFieldWithConfigurationHandler:^(UITextField *textField) { 114 | textField.placeholder = @"PID"; 115 | textField.keyboardType = UIKeyboardTypeNumberPad; 116 | }]; 117 | 118 | UIAlertAction *cancel = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:nil]; 119 | UIAlertAction *decrypt = [UIAlertAction actionWithTitle:@"Decrypt" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) { 120 | NSString *pid = alert.textFields.firstObject.text; 121 | decryptAppWithPID([pid intValue]); 122 | }]; 123 | 124 | [alert addAction:decrypt]; 125 | [alert addAction:cancel]; 126 | } 127 | 128 | [self presentViewController:alert animated:YES completion:nil]; 129 | [tableView deselectRowAtIndexPath:indexPath animated:YES]; 130 | } 131 | 132 | @end -------------------------------------------------------------------------------- /SSZipArchive/minizip/ioapi.h: -------------------------------------------------------------------------------- 1 | /* ioapi.h -- IO base function header for compress/uncompress .zip 2 | part of the MiniZip project 3 | 4 | Copyright (C) 2012-2017 Nathan Moinvaziri 5 | https://github.com/nmoinvaz/minizip 6 | Copyright (C) 2009-2010 Mathias Svensson 7 | Modifications for Zip64 support 8 | http://result42.com 9 | Copyright (C) 1998-2010 Gilles Vollant 10 | http://www.winimage.com/zLibDll/minizip.html 11 | 12 | This program is distributed under the terms of the same license as zlib. 13 | See the accompanying LICENSE file for the full text of the license. 14 | */ 15 | 16 | #ifndef _ZLIBIOAPI64_H 17 | #define _ZLIBIOAPI64_H 18 | 19 | #include 20 | #include 21 | #include 22 | 23 | #include "zlib.h" 24 | 25 | #ifdef __GNUC__ 26 | # define ZIP_UNUSED __attribute__((__unused__)) 27 | #else 28 | # define ZIP_UNUSED 29 | #endif 30 | 31 | #if defined(USE_FILE32API) 32 | # define fopen64 fopen 33 | # define ftello64 ftell 34 | # define fseeko64 fseek 35 | #else 36 | # if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__DragonFly__) || defined(__OpenBSD__) || defined(__APPLE__) || defined(__ANDROID__) 37 | # define fopen64 fopen 38 | # define ftello64 ftello 39 | # define fseeko64 fseeko 40 | # endif 41 | # ifdef _MSC_VER 42 | # define fopen64 fopen 43 | # if (_MSC_VER >= 1400) && (!(defined(NO_MSCVER_FILE64_FUNC))) 44 | # define ftello64 _ftelli64 45 | # define fseeko64 _fseeki64 46 | # else /* old MSC */ 47 | # define ftello64 ftell 48 | # define fseeko64 fseek 49 | # endif 50 | # endif 51 | #endif 52 | 53 | #ifdef __cplusplus 54 | extern "C" { 55 | #endif 56 | 57 | #define ZLIB_FILEFUNC_SEEK_CUR (1) 58 | #define ZLIB_FILEFUNC_SEEK_END (2) 59 | #define ZLIB_FILEFUNC_SEEK_SET (0) 60 | 61 | #define ZLIB_FILEFUNC_MODE_READ (1) 62 | #define ZLIB_FILEFUNC_MODE_WRITE (2) 63 | #define ZLIB_FILEFUNC_MODE_READWRITEFILTER (3) 64 | #define ZLIB_FILEFUNC_MODE_EXISTING (4) 65 | #define ZLIB_FILEFUNC_MODE_CREATE (8) 66 | 67 | #ifndef ZCALLBACK 68 | # if (defined(WIN32) || defined(_WIN32) || defined (WINDOWS) || \ 69 | defined (_WINDOWS)) && defined(CALLBACK) && defined (USEWINDOWS_CALLBACK) 70 | # define ZCALLBACK CALLBACK 71 | # else 72 | # define ZCALLBACK 73 | # endif 74 | #endif 75 | 76 | typedef voidpf (ZCALLBACK *open_file_func) (voidpf opaque, const char *filename, int mode); 77 | typedef voidpf (ZCALLBACK *opendisk_file_func) (voidpf opaque, voidpf stream, uint32_t number_disk, int mode); 78 | typedef uint32_t (ZCALLBACK *read_file_func) (voidpf opaque, voidpf stream, void* buf, uint32_t size); 79 | typedef uint32_t (ZCALLBACK *write_file_func) (voidpf opaque, voidpf stream, const void *buf, uint32_t size); 80 | typedef int (ZCALLBACK *close_file_func) (voidpf opaque, voidpf stream); 81 | typedef int (ZCALLBACK *error_file_func) (voidpf opaque, voidpf stream); 82 | 83 | typedef long (ZCALLBACK *tell_file_func) (voidpf opaque, voidpf stream); 84 | typedef long (ZCALLBACK *seek_file_func) (voidpf opaque, voidpf stream, uint32_t offset, int origin); 85 | 86 | /* here is the "old" 32 bits structure structure */ 87 | typedef struct zlib_filefunc_def_s 88 | { 89 | open_file_func zopen_file; 90 | opendisk_file_func zopendisk_file; 91 | read_file_func zread_file; 92 | write_file_func zwrite_file; 93 | tell_file_func ztell_file; 94 | seek_file_func zseek_file; 95 | close_file_func zclose_file; 96 | error_file_func zerror_file; 97 | voidpf opaque; 98 | } zlib_filefunc_def; 99 | 100 | typedef uint64_t (ZCALLBACK *tell64_file_func) (voidpf opaque, voidpf stream); 101 | typedef long (ZCALLBACK *seek64_file_func) (voidpf opaque, voidpf stream, uint64_t offset, int origin); 102 | typedef voidpf (ZCALLBACK *open64_file_func) (voidpf opaque, const void *filename, int mode); 103 | typedef voidpf (ZCALLBACK *opendisk64_file_func)(voidpf opaque, voidpf stream, uint32_t number_disk, int mode); 104 | 105 | typedef struct zlib_filefunc64_def_s 106 | { 107 | open64_file_func zopen64_file; 108 | opendisk64_file_func zopendisk64_file; 109 | read_file_func zread_file; 110 | write_file_func zwrite_file; 111 | tell64_file_func ztell64_file; 112 | seek64_file_func zseek64_file; 113 | close_file_func zclose_file; 114 | error_file_func zerror_file; 115 | voidpf opaque; 116 | } zlib_filefunc64_def; 117 | 118 | void fill_fopen_filefunc(zlib_filefunc_def *pzlib_filefunc_def); 119 | void fill_fopen64_filefunc(zlib_filefunc64_def *pzlib_filefunc_def); 120 | 121 | /* now internal definition, only for zip.c and unzip.h */ 122 | typedef struct zlib_filefunc64_32_def_s 123 | { 124 | zlib_filefunc64_def zfile_func64; 125 | open_file_func zopen32_file; 126 | opendisk_file_func zopendisk32_file; 127 | tell_file_func ztell32_file; 128 | seek_file_func zseek32_file; 129 | } zlib_filefunc64_32_def; 130 | 131 | #define ZREAD64(filefunc,filestream,buf,size) ((*((filefunc).zfile_func64.zread_file)) ((filefunc).zfile_func64.opaque,filestream,buf,size)) 132 | #define ZWRITE64(filefunc,filestream,buf,size) ((*((filefunc).zfile_func64.zwrite_file)) ((filefunc).zfile_func64.opaque,filestream,buf,size)) 133 | /*#define ZTELL64(filefunc,filestream) ((*((filefunc).ztell64_file)) ((filefunc).opaque,filestream))*/ 134 | /*#define ZSEEK64(filefunc,filestream,pos,mode) ((*((filefunc).zseek64_file)) ((filefunc).opaque,filestream,pos,mode))*/ 135 | #define ZCLOSE64(filefunc,filestream) ((*((filefunc).zfile_func64.zclose_file)) ((filefunc).zfile_func64.opaque,filestream)) 136 | #define ZERROR64(filefunc,filestream) ((*((filefunc).zfile_func64.zerror_file)) ((filefunc).zfile_func64.opaque,filestream)) 137 | 138 | voidpf call_zopen64(const zlib_filefunc64_32_def *pfilefunc,const void*filename, int mode); 139 | voidpf call_zopendisk64(const zlib_filefunc64_32_def *pfilefunc, voidpf filestream, uint32_t number_disk, int mode); 140 | long call_zseek64(const zlib_filefunc64_32_def *pfilefunc, voidpf filestream, uint64_t offset, int origin); 141 | uint64_t call_ztell64(const zlib_filefunc64_32_def *pfilefunc, voidpf filestream); 142 | 143 | void fill_zlib_filefunc64_32_def_from_filefunc32(zlib_filefunc64_32_def *p_filefunc64_32, const zlib_filefunc_def *p_filefunc32); 144 | 145 | #define ZOPEN64(filefunc,filename,mode) (call_zopen64((&(filefunc)),(filename),(mode))) 146 | #define ZOPENDISK64(filefunc,filestream,diskn,mode) (call_zopendisk64((&(filefunc)),(filestream),(diskn),(mode))) 147 | #define ZTELL64(filefunc,filestream) (call_ztell64((&(filefunc)),(filestream))) 148 | #define ZSEEK64(filefunc,filestream,pos,mode) (call_zseek64((&(filefunc)),(filestream),(pos),(mode))) 149 | 150 | #ifdef __cplusplus 151 | } 152 | #endif 153 | 154 | #endif 155 | -------------------------------------------------------------------------------- /SSZipArchive/SSZipArchive.h: -------------------------------------------------------------------------------- 1 | // 2 | // SSZipArchive.h 3 | // SSZipArchive 4 | // 5 | // Created by Sam Soffes on 7/21/10. 6 | // Copyright (c) Sam Soffes 2010-2015. All rights reserved. 7 | // 8 | 9 | #ifndef _SSZIPARCHIVE_H 10 | #define _SSZIPARCHIVE_H 11 | 12 | #import 13 | #include "SSZipCommon.h" 14 | 15 | NS_ASSUME_NONNULL_BEGIN 16 | 17 | extern NSString *const SSZipArchiveErrorDomain; 18 | typedef NS_ENUM(NSInteger, SSZipArchiveErrorCode) { 19 | SSZipArchiveErrorCodeFailedOpenZipFile = -1, 20 | SSZipArchiveErrorCodeFailedOpenFileInZip = -2, 21 | SSZipArchiveErrorCodeFileInfoNotLoadable = -3, 22 | SSZipArchiveErrorCodeFileContentNotReadable = -4, 23 | SSZipArchiveErrorCodeFailedToWriteFile = -5, 24 | SSZipArchiveErrorCodeInvalidArguments = -6, 25 | }; 26 | 27 | @protocol SSZipArchiveDelegate; 28 | 29 | @interface SSZipArchive : NSObject 30 | 31 | // Password check 32 | + (BOOL)isFilePasswordProtectedAtPath:(NSString *)path; 33 | + (BOOL)isPasswordValidForArchiveAtPath:(NSString *)path password:(NSString *)pw error:(NSError * _Nullable * _Nullable)error NS_SWIFT_NOTHROW; 34 | 35 | // Unzip 36 | + (BOOL)unzipFileAtPath:(NSString *)path toDestination:(NSString *)destination; 37 | + (BOOL)unzipFileAtPath:(NSString *)path toDestination:(NSString *)destination delegate:(nullable id)delegate; 38 | 39 | + (BOOL)unzipFileAtPath:(NSString *)path 40 | toDestination:(NSString *)destination 41 | overwrite:(BOOL)overwrite 42 | password:(nullable NSString *)password 43 | error:(NSError * *)error; 44 | 45 | + (BOOL)unzipFileAtPath:(NSString *)path 46 | toDestination:(NSString *)destination 47 | overwrite:(BOOL)overwrite 48 | password:(nullable NSString *)password 49 | error:(NSError * *)error 50 | delegate:(nullable id)delegate NS_REFINED_FOR_SWIFT; 51 | 52 | + (BOOL)unzipFileAtPath:(NSString *)path 53 | toDestination:(NSString *)destination 54 | preserveAttributes:(BOOL)preserveAttributes 55 | overwrite:(BOOL)overwrite 56 | password:(nullable NSString *)password 57 | error:(NSError * *)error 58 | delegate:(nullable id)delegate; 59 | 60 | + (BOOL)unzipFileAtPath:(NSString *)path 61 | toDestination:(NSString *)destination 62 | progressHandler:(void (^_Nullable)(NSString *entry, unz_file_info zipInfo, long entryNumber, long total))progressHandler 63 | completionHandler:(void (^_Nullable)(NSString *path, BOOL succeeded, NSError * _Nullable error))completionHandler; 64 | 65 | + (BOOL)unzipFileAtPath:(NSString *)path 66 | toDestination:(NSString *)destination 67 | overwrite:(BOOL)overwrite 68 | password:(nullable NSString *)password 69 | progressHandler:(void (^_Nullable)(NSString *entry, unz_file_info zipInfo, long entryNumber, long total))progressHandler 70 | completionHandler:(void (^_Nullable)(NSString *path, BOOL succeeded, NSError * _Nullable error))completionHandler; 71 | 72 | + (BOOL)unzipFileAtPath:(NSString *)path 73 | toDestination:(NSString *)destination 74 | preserveAttributes:(BOOL)preserveAttributes 75 | overwrite:(BOOL)overwrite 76 | nestedZipLevel:(NSInteger)nestedZipLevel 77 | password:(nullable NSString *)password 78 | error:(NSError **)error 79 | delegate:(nullable id)delegate 80 | progressHandler:(void (^_Nullable)(NSString *entry, unz_file_info zipInfo, long entryNumber, long total))progressHandler 81 | completionHandler:(void (^_Nullable)(NSString *path, BOOL succeeded, NSError * _Nullable error))completionHandler; 82 | 83 | // Zip 84 | // default compression level is Z_DEFAULT_COMPRESSION (from "zlib.h") 85 | 86 | // without password 87 | + (BOOL)createZipFileAtPath:(NSString *)path withFilesAtPaths:(NSArray *)paths; 88 | + (BOOL)createZipFileAtPath:(NSString *)path withContentsOfDirectory:(NSString *)directoryPath; 89 | 90 | + (BOOL)createZipFileAtPath:(NSString *)path withContentsOfDirectory:(NSString *)directoryPath keepParentDirectory:(BOOL)keepParentDirectory; 91 | 92 | // with optional password, default encryption is AES 93 | // don't use AES if you need compatibility with native macOS unzip and Archive Utility 94 | + (BOOL)createZipFileAtPath:(NSString *)path withFilesAtPaths:(NSArray *)paths withPassword:(nullable NSString *)password; 95 | + (BOOL)createZipFileAtPath:(NSString *)path withContentsOfDirectory:(NSString *)directoryPath withPassword:(nullable NSString *)password; 96 | + (BOOL)createZipFileAtPath:(NSString *)path withContentsOfDirectory:(NSString *)directoryPath keepParentDirectory:(BOOL)keepParentDirectory withPassword:(nullable NSString *)password; 97 | + (BOOL)createZipFileAtPath:(NSString *)path 98 | withContentsOfDirectory:(NSString *)directoryPath 99 | keepParentDirectory:(BOOL)keepParentDirectory 100 | withPassword:(nullable NSString *)password 101 | andProgressHandler:(void(^ _Nullable)(NSUInteger entryNumber, NSUInteger total))progressHandler; 102 | + (BOOL)createZipFileAtPath:(NSString *)path 103 | withContentsOfDirectory:(NSString *)directoryPath 104 | keepParentDirectory:(BOOL)keepParentDirectory 105 | compressionLevel:(int)compressionLevel 106 | password:(nullable NSString *)password 107 | AES:(BOOL)aes 108 | progressHandler:(void(^ _Nullable)(NSUInteger entryNumber, NSUInteger total))progressHandler; 109 | 110 | - (instancetype)init NS_UNAVAILABLE; 111 | - (instancetype)initWithPath:(NSString *)path NS_DESIGNATED_INITIALIZER; 112 | - (BOOL)open; 113 | 114 | /// write empty folder 115 | - (BOOL)writeFolderAtPath:(NSString *)path withFolderName:(NSString *)folderName withPassword:(nullable NSString *)password; 116 | /// write file 117 | - (BOOL)writeFile:(NSString *)path withPassword:(nullable NSString *)password; 118 | - (BOOL)writeFileAtPath:(NSString *)path withFileName:(nullable NSString *)fileName withPassword:(nullable NSString *)password; 119 | - (BOOL)writeFileAtPath:(NSString *)path withFileName:(nullable NSString *)fileName compressionLevel:(int)compressionLevel password:(nullable NSString *)password AES:(BOOL)aes; 120 | /// write data 121 | - (BOOL)writeData:(NSData *)data filename:(nullable NSString *)filename withPassword:(nullable NSString *)password; 122 | - (BOOL)writeData:(NSData *)data filename:(nullable NSString *)filename compressionLevel:(int)compressionLevel password:(nullable NSString *)password AES:(BOOL)aes; 123 | 124 | - (BOOL)close; 125 | 126 | @end 127 | 128 | @protocol SSZipArchiveDelegate 129 | 130 | @optional 131 | 132 | - (void)zipArchiveWillUnzipArchiveAtPath:(NSString *)path zipInfo:(unz_global_info)zipInfo; 133 | - (void)zipArchiveDidUnzipArchiveAtPath:(NSString *)path zipInfo:(unz_global_info)zipInfo unzippedPath:(NSString *)unzippedPath; 134 | 135 | - (BOOL)zipArchiveShouldUnzipFileAtIndex:(NSInteger)fileIndex totalFiles:(NSInteger)totalFiles archivePath:(NSString *)archivePath fileInfo:(unz_file_info)fileInfo; 136 | - (void)zipArchiveWillUnzipFileAtIndex:(NSInteger)fileIndex totalFiles:(NSInteger)totalFiles archivePath:(NSString *)archivePath fileInfo:(unz_file_info)fileInfo; 137 | - (void)zipArchiveDidUnzipFileAtIndex:(NSInteger)fileIndex totalFiles:(NSInteger)totalFiles archivePath:(NSString *)archivePath fileInfo:(unz_file_info)fileInfo; 138 | - (void)zipArchiveDidUnzipFileAtIndex:(NSInteger)fileIndex totalFiles:(NSInteger)totalFiles archivePath:(NSString *)archivePath unzippedFilePath:(NSString *)unzippedFilePath; 139 | 140 | - (void)zipArchiveProgressEvent:(unsigned long long)loaded total:(unsigned long long)total; 141 | 142 | @end 143 | 144 | NS_ASSUME_NONNULL_END 145 | 146 | #endif /* _SSZIPARCHIVE_H */ 147 | -------------------------------------------------------------------------------- /SSZipArchive/minizip/aes/brg_types.h: -------------------------------------------------------------------------------- 1 | /* 2 | --------------------------------------------------------------------------- 3 | Copyright (c) 1998-2013, Brian Gladman, Worcester, UK. All rights reserved. 4 | 5 | The redistribution and use of this software (with or without changes) 6 | is allowed without the payment of fees or royalties provided that: 7 | 8 | source code distributions include the above copyright notice, this 9 | list of conditions and the following disclaimer; 10 | 11 | binary distributions include the above copyright notice, this list 12 | of conditions and the following disclaimer in their documentation. 13 | 14 | This software is provided 'as is' with no explicit or implied warranties 15 | in respect of its operation, including, but not limited to, correctness 16 | and fitness for purpose. 17 | --------------------------------------------------------------------------- 18 | Issue Date: 20/12/2007 19 | 20 | The unsigned integer types defined here are of the form uint_t where 21 | is the length of the type; for example, the unsigned 32-bit type is 22 | 'uint32_t'. These are NOT the same as the 'C99 integer types' that are 23 | defined in the inttypes.h and stdint.h headers since attempts to use these 24 | types have shown that support for them is still highly variable. However, 25 | since the latter are of the form uint_t, a regular expression search 26 | and replace (in VC++ search on 'uint_{:z}t' and replace with 'uint\1_t') 27 | can be used to convert the types used here to the C99 standard types. 28 | */ 29 | 30 | #ifndef _BRG_TYPES_H 31 | #define _BRG_TYPES_H 32 | 33 | #if defined(__cplusplus) 34 | extern "C" { 35 | #endif 36 | 37 | #include 38 | #include 39 | 40 | #if defined( _MSC_VER ) && ( _MSC_VER >= 1300 ) 41 | # include 42 | # define ptrint_t intptr_t 43 | #elif defined( __ECOS__ ) 44 | # define intptr_t unsigned int 45 | # define ptrint_t intptr_t 46 | #elif defined( __GNUC__ ) && ( __GNUC__ >= 3 ) 47 | # define ptrint_t intptr_t 48 | #else 49 | # define ptrint_t int 50 | #endif 51 | 52 | #ifndef BRG_UI32 53 | # define BRG_UI32 54 | # if UINT_MAX == 4294967295u 55 | # define li_32(h) 0x##h##u 56 | # elif ULONG_MAX == 4294967295u 57 | # define li_32(h) 0x##h##ul 58 | # elif defined( _CRAY ) 59 | # error This code needs 32-bit data types, which Cray machines do not provide 60 | # else 61 | # error Please define uint32_t as a 32-bit unsigned integer type in brg_types.h 62 | # endif 63 | #endif 64 | 65 | #ifndef BRG_UI64 66 | # if defined( __BORLANDC__ ) && !defined( __MSDOS__ ) 67 | # define BRG_UI64 68 | # define li_64(h) 0x##h##ui64 69 | # elif defined( _MSC_VER ) && ( _MSC_VER < 1300 ) /* 1300 == VC++ 7.0 */ 70 | # define BRG_UI64 71 | # define li_64(h) 0x##h##ui64 72 | # elif defined( __sun ) && defined( ULONG_MAX ) && ULONG_MAX == 0xfffffffful 73 | # define BRG_UI64 74 | # define li_64(h) 0x##h##ull 75 | # elif defined( __MVS__ ) 76 | # define BRG_UI64 77 | # define li_64(h) 0x##h##ull 78 | # elif defined( UINT_MAX ) && UINT_MAX > 4294967295u 79 | # if UINT_MAX == 18446744073709551615u 80 | # define BRG_UI64 81 | # define li_64(h) 0x##h##u 82 | # endif 83 | # elif defined( ULONG_MAX ) && ULONG_MAX > 4294967295u 84 | # if ULONG_MAX == 18446744073709551615ul 85 | # define BRG_UI64 86 | # define li_64(h) 0x##h##ul 87 | # endif 88 | # elif defined( ULLONG_MAX ) && ULLONG_MAX > 4294967295u 89 | # if ULLONG_MAX == 18446744073709551615ull 90 | # define BRG_UI64 91 | # define li_64(h) 0x##h##ull 92 | # endif 93 | # elif defined( ULONG_LONG_MAX ) && ULONG_LONG_MAX > 4294967295u 94 | # if ULONG_LONG_MAX == 18446744073709551615ull 95 | # define BRG_UI64 96 | # define li_64(h) 0x##h##ull 97 | # endif 98 | # endif 99 | #endif 100 | 101 | #if !defined( BRG_UI64 ) 102 | # if defined( NEED_UINT_64T ) 103 | # error Please define uint64_t as an unsigned 64 bit type in brg_types.h 104 | # endif 105 | #endif 106 | 107 | #ifndef RETURN_VALUES 108 | # define RETURN_VALUES 109 | # if defined( DLL_EXPORT ) 110 | # if defined( _MSC_VER ) || defined ( __INTEL_COMPILER ) 111 | # define VOID_RETURN __declspec( dllexport ) void __stdcall 112 | # define INT_RETURN __declspec( dllexport ) int __stdcall 113 | # elif defined( __GNUC__ ) 114 | # define VOID_RETURN __declspec( __dllexport__ ) void 115 | # define INT_RETURN __declspec( __dllexport__ ) int 116 | # else 117 | # error Use of the DLL is only available on the Microsoft, Intel and GCC compilers 118 | # endif 119 | # elif defined( DLL_IMPORT ) 120 | # if defined( _MSC_VER ) || defined ( __INTEL_COMPILER ) 121 | # define VOID_RETURN __declspec( dllimport ) void __stdcall 122 | # define INT_RETURN __declspec( dllimport ) int __stdcall 123 | # elif defined( __GNUC__ ) 124 | # define VOID_RETURN __declspec( __dllimport__ ) void 125 | # define INT_RETURN __declspec( __dllimport__ ) int 126 | # else 127 | # error Use of the DLL is only available on the Microsoft, Intel and GCC compilers 128 | # endif 129 | # elif defined( __WATCOMC__ ) 130 | # define VOID_RETURN void __cdecl 131 | # define INT_RETURN int __cdecl 132 | # else 133 | # define VOID_RETURN void 134 | # define INT_RETURN int 135 | # endif 136 | #endif 137 | 138 | /* These defines are used to detect and set the memory alignment of pointers. 139 | Note that offsets are in bytes. 140 | 141 | ALIGN_OFFSET(x,n) return the positive or zero offset of 142 | the memory addressed by the pointer 'x' 143 | from an address that is aligned on an 144 | 'n' byte boundary ('n' is a power of 2) 145 | 146 | ALIGN_FLOOR(x,n) return a pointer that points to memory 147 | that is aligned on an 'n' byte boundary 148 | and is not higher than the memory address 149 | pointed to by 'x' ('n' is a power of 2) 150 | 151 | ALIGN_CEIL(x,n) return a pointer that points to memory 152 | that is aligned on an 'n' byte boundary 153 | and is not lower than the memory address 154 | pointed to by 'x' ('n' is a power of 2) 155 | */ 156 | 157 | #define ALIGN_OFFSET(x,n) (((ptrint_t)(x)) & ((n) - 1)) 158 | #define ALIGN_FLOOR(x,n) ((uint8_t*)(x) - ( ((ptrint_t)(x)) & ((n) - 1))) 159 | #define ALIGN_CEIL(x,n) ((uint8_t*)(x) + (-((ptrint_t)(x)) & ((n) - 1))) 160 | 161 | /* These defines are used to declare buffers in a way that allows 162 | faster operations on longer variables to be used. In all these 163 | defines 'size' must be a power of 2 and >= 8. NOTE that the 164 | buffer size is in bytes but the type length is in bits 165 | 166 | UNIT_TYPEDEF(x,size) declares a variable 'x' of length 167 | 'size' bits 168 | 169 | BUFR_TYPEDEF(x,size,bsize) declares a buffer 'x' of length 'bsize' 170 | bytes defined as an array of variables 171 | each of 'size' bits (bsize must be a 172 | multiple of size / 8) 173 | 174 | UNIT_CAST(x,size) casts a variable to a type of 175 | length 'size' bits 176 | 177 | UPTR_CAST(x,size) casts a pointer to a pointer to a 178 | varaiable of length 'size' bits 179 | */ 180 | 181 | #define UI_TYPE(size) uint##size##_t 182 | #define UNIT_TYPEDEF(x,size) typedef UI_TYPE(size) x 183 | #define BUFR_TYPEDEF(x,size,bsize) typedef UI_TYPE(size) x[bsize / (size >> 3)] 184 | #define UNIT_CAST(x,size) ((UI_TYPE(size) )(x)) 185 | #define UPTR_CAST(x,size) ((UI_TYPE(size)*)(x)) 186 | 187 | #if defined(__cplusplus) 188 | } 189 | #endif 190 | 191 | #endif 192 | -------------------------------------------------------------------------------- /SSZipArchive/minizip/aes/hmac.c: -------------------------------------------------------------------------------- 1 | /* 2 | --------------------------------------------------------------------------- 3 | Copyright (c) 1998-2010, Brian Gladman, Worcester, UK. All rights reserved. 4 | 5 | The redistribution and use of this software (with or without changes) 6 | is allowed without the payment of fees or royalties provided that: 7 | 8 | source code distributions include the above copyright notice, this 9 | list of conditions and the following disclaimer; 10 | 11 | binary distributions include the above copyright notice, this list 12 | of conditions and the following disclaimer in their documentation. 13 | 14 | This software is provided 'as is' with no explicit or implied warranties 15 | in respect of its operation, including, but not limited to, correctness 16 | and fitness for purpose. 17 | --------------------------------------------------------------------------- 18 | Issue Date: 20/12/2007 19 | 20 | This is an implementation of HMAC, the FIPS standard keyed hash function 21 | */ 22 | 23 | #include "hmac.h" 24 | 25 | #if defined(__cplusplus) 26 | extern "C" 27 | { 28 | #endif 29 | 30 | /* initialise the HMAC context to zero */ 31 | int hmac_sha_begin(enum hmac_hash hash, hmac_ctx cx[1]) 32 | { 33 | memset(cx, 0, sizeof(hmac_ctx)); 34 | switch(hash) 35 | { 36 | #ifdef SHA_1 37 | case HMAC_SHA1: 38 | cx->f_begin = (hf_begin *)sha1_begin; 39 | cx->f_hash = (hf_hash *)sha1_hash; 40 | cx->f_end = (hf_end *)sha1_end; 41 | cx->input_len = SHA1_BLOCK_SIZE; 42 | cx->output_len = SHA1_DIGEST_SIZE; 43 | break; 44 | #endif 45 | #ifdef SHA_224 46 | case HMAC_SHA224: 47 | cx->f_begin = (hf_begin *)sha224_begin; 48 | cx->f_hash = (hf_hash *)sha224_hash; 49 | cx->f_end = (hf_end *)sha224_end; 50 | cx->input_len = SHA224_BLOCK_SIZE; 51 | cx->output_len = SHA224_DIGEST_SIZE; 52 | break; 53 | #endif 54 | #ifdef SHA_256 55 | case HMAC_SHA256: 56 | cx->f_begin = (hf_begin *)sha256_begin; 57 | cx->f_hash = (hf_hash *)sha256_hash; 58 | cx->f_end = (hf_end *)sha256_end; 59 | cx->input_len = SHA256_BLOCK_SIZE; 60 | cx->output_len = SHA256_DIGEST_SIZE; 61 | break; 62 | #endif 63 | #ifdef SHA_384 64 | case HMAC_SHA384: 65 | cx->f_begin = (hf_begin *)sha384_begin; 66 | cx->f_hash = (hf_hash *)sha384_hash; 67 | cx->f_end = (hf_end *)sha384_end; 68 | cx->input_len = SHA384_BLOCK_SIZE; 69 | cx->output_len = SHA384_DIGEST_SIZE; 70 | break; 71 | #endif 72 | #ifdef SHA_512 73 | case HMAC_SHA512: 74 | cx->f_begin = (hf_begin *)sha512_begin; 75 | cx->f_hash = (hf_hash *)sha512_hash; 76 | cx->f_end = (hf_end *)sha512_end; 77 | cx->input_len = SHA512_BLOCK_SIZE; 78 | cx->output_len = SHA512_DIGEST_SIZE; 79 | break; 80 | case HMAC_SHA512_256: 81 | cx->f_begin = (hf_begin *)sha512_256_begin; 82 | cx->f_hash = (hf_hash *)sha512_256_hash; 83 | cx->f_end = (hf_end *)sha512_256_end; 84 | cx->input_len = SHA512_256_BLOCK_SIZE; 85 | cx->output_len = SHA512_256_DIGEST_SIZE; 86 | break; 87 | case HMAC_SHA512_224: 88 | cx->f_begin = (hf_begin *)sha512_224_begin; 89 | cx->f_hash = (hf_hash *)sha512_224_hash; 90 | cx->f_end = (hf_end *)sha512_224_end; 91 | cx->input_len = SHA512_224_BLOCK_SIZE; 92 | cx->output_len = SHA512_224_DIGEST_SIZE; 93 | break; 94 | case HMAC_SHA512_192: 95 | cx->f_begin = (hf_begin *)sha512_192_begin; 96 | cx->f_hash = (hf_hash *)sha512_192_hash; 97 | cx->f_end = (hf_end *)sha512_192_end; 98 | cx->input_len = SHA512_192_BLOCK_SIZE; 99 | cx->output_len = SHA512_192_DIGEST_SIZE; 100 | break; 101 | case HMAC_SHA512_128: 102 | cx->f_begin = (hf_begin *)sha512_128_begin; 103 | cx->f_hash = (hf_hash *)sha512_128_hash; 104 | cx->f_end = (hf_begin *)sha512_128_end; 105 | cx->input_len = SHA512_128_BLOCK_SIZE; 106 | cx->output_len = SHA512_128_DIGEST_SIZE; 107 | break; 108 | #endif 109 | } 110 | return (int)cx->output_len; 111 | } 112 | 113 | /* input the HMAC key (can be called multiple times) */ 114 | int hmac_sha_key(const unsigned char key[], unsigned long key_len, hmac_ctx cx[1]) 115 | { 116 | if(cx->klen == HMAC_IN_DATA) /* error if further key input */ 117 | return EXIT_FAILURE; /* is attempted in data mode */ 118 | 119 | if(cx->klen + key_len > cx->input_len) /* if the key has to be hashed */ 120 | { 121 | if(cx->klen <= cx->input_len) /* if the hash has not yet been */ 122 | { /* started, initialise it and */ 123 | cx->f_begin(cx->sha_ctx); /* hash stored key characters */ 124 | cx->f_hash(cx->key, cx->klen, cx->sha_ctx); 125 | } 126 | 127 | cx->f_hash(key, key_len, cx->sha_ctx); /* hash long key data into hash */ 128 | } 129 | else /* otherwise store key data */ 130 | memcpy(cx->key + cx->klen, key, key_len); 131 | 132 | cx->klen += key_len; /* update the key length count */ 133 | return EXIT_SUCCESS; 134 | } 135 | 136 | /* input the HMAC data (can be called multiple times) - */ 137 | /* note that this call terminates the key input phase */ 138 | void hmac_sha_data(const unsigned char data[], unsigned long data_len, hmac_ctx cx[1]) 139 | { unsigned int i; 140 | 141 | if(cx->klen != HMAC_IN_DATA) /* if not yet in data phase */ 142 | { 143 | if(cx->klen > cx->input_len) /* if key is being hashed */ 144 | { /* complete the hash and */ 145 | cx->f_end(cx->key, cx->sha_ctx); /* store the result as the */ 146 | cx->klen = cx->output_len; /* key and set new length */ 147 | } 148 | 149 | /* pad the key if necessary */ 150 | memset(cx->key + cx->klen, 0, cx->input_len - cx->klen); 151 | 152 | /* xor ipad into key value */ 153 | for(i = 0; i < (cx->input_len >> 2); ++i) 154 | ((uint32_t*)cx->key)[i] ^= 0x36363636; 155 | 156 | /* and start hash operation */ 157 | cx->f_begin(cx->sha_ctx); 158 | cx->f_hash(cx->key, cx->input_len, cx->sha_ctx); 159 | 160 | /* mark as now in data mode */ 161 | cx->klen = HMAC_IN_DATA; 162 | } 163 | 164 | /* hash the data (if any) */ 165 | if(data_len) 166 | cx->f_hash(data, data_len, cx->sha_ctx); 167 | } 168 | 169 | /* compute and output the MAC value */ 170 | void hmac_sha_end(unsigned char mac[], unsigned long mac_len, hmac_ctx cx[1]) 171 | { unsigned char dig[HMAC_MAX_OUTPUT_SIZE]; 172 | unsigned int i; 173 | 174 | /* if no data has been entered perform a null data phase */ 175 | if(cx->klen != HMAC_IN_DATA) 176 | hmac_sha_data((const unsigned char*)0, 0, cx); 177 | 178 | cx->f_end(dig, cx->sha_ctx); /* complete the inner hash */ 179 | 180 | /* set outer key value using opad and removing ipad */ 181 | for(i = 0; i < (cx->input_len >> 2); ++i) 182 | ((uint32_t*)cx->key)[i] ^= 0x36363636 ^ 0x5c5c5c5c; 183 | 184 | /* perform the outer hash operation */ 185 | cx->f_begin(cx->sha_ctx); 186 | cx->f_hash(cx->key, cx->input_len, cx->sha_ctx); 187 | cx->f_hash(dig, cx->output_len, cx->sha_ctx); 188 | cx->f_end(dig, cx->sha_ctx); 189 | 190 | /* output the hash value */ 191 | for(i = 0; i < mac_len; ++i) 192 | mac[i] = dig[i]; 193 | } 194 | 195 | /* 'do it all in one go' subroutine */ 196 | void hmac_sha(enum hmac_hash hash, const unsigned char key[], unsigned long key_len, 197 | const unsigned char data[], unsigned long data_len, 198 | unsigned char mac[], unsigned long mac_len) 199 | { hmac_ctx cx[1]; 200 | 201 | hmac_sha_begin(hash, cx); 202 | hmac_sha_key(key, key_len, cx); 203 | hmac_sha_data(data, data_len, cx); 204 | hmac_sha_end(mac, mac_len, cx); 205 | } 206 | 207 | #if defined(__cplusplus) 208 | } 209 | #endif 210 | -------------------------------------------------------------------------------- /SSZipArchive/minizip/minishared.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | #include "zlib.h" 10 | #include "ioapi.h" 11 | 12 | #ifdef _WIN32 13 | # include 14 | # include 15 | #else 16 | # include 17 | # include 18 | # include 19 | # include 20 | #endif 21 | 22 | #include "minishared.h" 23 | 24 | #ifdef _WIN32 25 | # define USEWIN32IOAPI 26 | # include "iowin32.h" 27 | #endif 28 | 29 | uint32_t get_file_date(const char *path, uint32_t *dos_date) 30 | { 31 | int ret = 0; 32 | #ifdef _WIN32 33 | FILETIME ftm_local; 34 | HANDLE find = NULL; 35 | WIN32_FIND_DATAA ff32; 36 | 37 | find = FindFirstFileA(path, &ff32); 38 | if (find != INVALID_HANDLE_VALUE) 39 | { 40 | FileTimeToLocalFileTime(&(ff32.ftLastWriteTime), &ftm_local); 41 | FileTimeToDosDateTime(&ftm_local, ((LPWORD)dos_date) + 1, ((LPWORD)dos_date) + 0); 42 | FindClose(find); 43 | ret = 1; 44 | } 45 | #else 46 | struct stat s; 47 | struct tm *filedate = NULL; 48 | time_t tm_t = 0; 49 | 50 | memset(&s, 0, sizeof(s)); 51 | 52 | if (strcmp(path, "-") != 0) 53 | { 54 | size_t len = strlen(path); 55 | char *name = (char *)malloc(len + 1); 56 | strncpy(name, path, len + 1); 57 | name[len] = 0; 58 | if (name[len - 1] == '/') 59 | name[len - 1] = 0; 60 | 61 | /* Not all systems allow stat'ing a file with / appended */ 62 | if (stat(name, &s) == 0) 63 | { 64 | tm_t = s.st_mtime; 65 | ret = 1; 66 | } 67 | free(name); 68 | } 69 | 70 | filedate = localtime(&tm_t); 71 | *dos_date = tm_to_dosdate(filedate); 72 | #endif 73 | return ret; 74 | } 75 | 76 | void change_file_date(const char *path, uint32_t dos_date) 77 | { 78 | #ifdef _WIN32 79 | HANDLE handle = NULL; 80 | FILETIME ftm, ftm_local, ftm_create, ftm_access, ftm_modified; 81 | 82 | handle = CreateFileA(path, GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL); 83 | if (handle != INVALID_HANDLE_VALUE) 84 | { 85 | GetFileTime(handle, &ftm_create, &ftm_access, &ftm_modified); 86 | DosDateTimeToFileTime((WORD)(dos_date >> 16), (WORD)dos_date, &ftm_local); 87 | LocalFileTimeToFileTime(&ftm_local, &ftm); 88 | SetFileTime(handle, &ftm, &ftm_access, &ftm); 89 | CloseHandle(handle); 90 | } 91 | #else 92 | struct utimbuf ut; 93 | ut.actime = ut.modtime = dosdate_to_time_t(dos_date); 94 | utime(path, &ut); 95 | #endif 96 | } 97 | 98 | int invalid_date(const struct tm *ptm) 99 | { 100 | #define datevalue_in_range(min, max, value) ((min) <= (value) && (value) <= (max)) 101 | return (!datevalue_in_range(0, 207, ptm->tm_year) || 102 | !datevalue_in_range(0, 11, ptm->tm_mon) || 103 | !datevalue_in_range(1, 31, ptm->tm_mday) || 104 | !datevalue_in_range(0, 23, ptm->tm_hour) || 105 | !datevalue_in_range(0, 59, ptm->tm_min) || 106 | !datevalue_in_range(0, 59, ptm->tm_sec)); 107 | #undef datevalue_in_range 108 | } 109 | 110 | // Conversion without validation 111 | void dosdate_to_raw_tm(uint64_t dos_date, struct tm *ptm) 112 | { 113 | uint64_t date = (uint64_t)(dos_date >> 16); 114 | 115 | ptm->tm_mday = (uint16_t)(date & 0x1f); 116 | ptm->tm_mon = (uint16_t)(((date & 0x1E0) / 0x20) - 1); 117 | ptm->tm_year = (uint16_t)(((date & 0x0FE00) / 0x0200) + 80); 118 | ptm->tm_hour = (uint16_t)((dos_date & 0xF800) / 0x800); 119 | ptm->tm_min = (uint16_t)((dos_date & 0x7E0) / 0x20); 120 | ptm->tm_sec = (uint16_t)(2 * (dos_date & 0x1f)); 121 | ptm->tm_isdst = -1; 122 | } 123 | 124 | int dosdate_to_tm(uint64_t dos_date, struct tm *ptm) 125 | { 126 | dosdate_to_raw_tm(dos_date, ptm); 127 | 128 | if (invalid_date(ptm)) 129 | { 130 | // Invalid date stored, so don't return it. 131 | memset(ptm, 0, sizeof(struct tm)); 132 | return -1; 133 | } 134 | return 0; 135 | } 136 | 137 | time_t dosdate_to_time_t(uint64_t dos_date) 138 | { 139 | struct tm ptm; 140 | dosdate_to_raw_tm(dos_date, &ptm); 141 | return mktime(&ptm); 142 | } 143 | 144 | uint32_t tm_to_dosdate(const struct tm *ptm) 145 | { 146 | struct tm fixed_tm; 147 | 148 | /* Years supported: 149 | * [00, 79] (assumed to be between 2000 and 2079) 150 | * [80, 207] (assumed to be between 1980 and 2107, typical output of old 151 | software that does 'year-1900' to get a double digit year) 152 | * [1980, 2107] (due to the date format limitations, only years between 1980 and 2107 can be stored.) 153 | */ 154 | 155 | memcpy(&fixed_tm, ptm, sizeof(struct tm)); 156 | if (fixed_tm.tm_year >= 1980) /* range [1980, 2107] */ 157 | fixed_tm.tm_year -= 1980; 158 | else if (fixed_tm.tm_year >= 80) /* range [80, 99] */ 159 | fixed_tm.tm_year -= 80; 160 | else /* range [00, 79] */ 161 | fixed_tm.tm_year += 20; 162 | 163 | if (invalid_date(ptm)) 164 | return 0; 165 | 166 | return (uint32_t)(((fixed_tm.tm_mday) + (32 * (fixed_tm.tm_mon + 1)) + (512 * fixed_tm.tm_year)) << 16) | 167 | ((fixed_tm.tm_sec / 2) + (32 * fixed_tm.tm_min) + (2048 * (uint32_t)fixed_tm.tm_hour)); 168 | } 169 | 170 | int makedir(const char *newdir) 171 | { 172 | char *buffer = NULL; 173 | char *p = NULL; 174 | int len = (int)strlen(newdir); 175 | 176 | if (len <= 0) 177 | return 0; 178 | 179 | buffer = (char*)malloc(len + 1); 180 | if (buffer == NULL) 181 | { 182 | printf("Error allocating memory\n"); 183 | return -1; 184 | } 185 | 186 | strcpy(buffer, newdir); 187 | 188 | if (buffer[len - 1] == '/') 189 | buffer[len - 1] = 0; 190 | 191 | if (MKDIR(buffer) == 0) 192 | { 193 | free(buffer); 194 | return 1; 195 | } 196 | 197 | p = buffer + 1; 198 | while (1) 199 | { 200 | char hold; 201 | while (*p && *p != '\\' && *p != '/') 202 | p++; 203 | hold = *p; 204 | *p = 0; 205 | 206 | if ((MKDIR(buffer) == -1) && (errno == ENOENT)) 207 | { 208 | printf("couldn't create directory %s (%d)\n", buffer, errno); 209 | free(buffer); 210 | return 0; 211 | } 212 | 213 | if (hold == 0) 214 | break; 215 | 216 | *p++ = hold; 217 | } 218 | 219 | free(buffer); 220 | return 1; 221 | } 222 | 223 | FILE *get_file_handle(const char *path) 224 | { 225 | FILE *handle = NULL; 226 | #if defined(WIN32) 227 | wchar_t *pathWide = NULL; 228 | int pathLength = 0; 229 | 230 | pathLength = MultiByteToWideChar(CP_UTF8, 0, path, -1, NULL, 0) + 1; 231 | pathWide = (wchar_t*)calloc(pathLength, sizeof(wchar_t)); 232 | MultiByteToWideChar(CP_UTF8, 0, path, -1, pathWide, pathLength); 233 | handle = _wfopen((const wchar_t*)pathWide, L"rb"); 234 | free(pathWide); 235 | #else 236 | handle = fopen64(path, "rb"); 237 | #endif 238 | 239 | return handle; 240 | } 241 | 242 | int check_file_exists(const char *path) 243 | { 244 | FILE *handle = get_file_handle(path); 245 | if (handle == NULL) 246 | return 0; 247 | fclose(handle); 248 | return 1; 249 | } 250 | 251 | int is_large_file(const char *path) 252 | { 253 | FILE* handle = NULL; 254 | uint64_t pos = 0; 255 | 256 | handle = get_file_handle(path); 257 | if (handle == NULL) 258 | return 0; 259 | 260 | fseeko64(handle, 0, SEEK_END); 261 | pos = ftello64(handle); 262 | fclose(handle); 263 | 264 | printf("file : %s is %lld bytes\n", path, pos); 265 | 266 | return (pos >= UINT32_MAX); 267 | } 268 | 269 | void display_zpos64(uint64_t n, int size_char) 270 | { 271 | /* To avoid compatibility problem we do here the conversion */ 272 | char number[21] = { 0 }; 273 | int offset = 19; 274 | int pos_string = 19; 275 | int size_display_string = 19; 276 | 277 | while (1) 278 | { 279 | number[offset] = (char)((n % 10) + '0'); 280 | if (number[offset] != '0') 281 | pos_string = offset; 282 | n /= 10; 283 | if (offset == 0) 284 | break; 285 | offset--; 286 | } 287 | 288 | size_display_string -= pos_string; 289 | while (size_char-- > size_display_string) 290 | printf(" "); 291 | printf("%s", &number[pos_string]); 292 | } 293 | -------------------------------------------------------------------------------- /SSZipArchive/minizip/aes/aes.h: -------------------------------------------------------------------------------- 1 | /* 2 | --------------------------------------------------------------------------- 3 | Copyright (c) 1998-2013, Brian Gladman, Worcester, UK. All rights reserved. 4 | 5 | The redistribution and use of this software (with or without changes) 6 | is allowed without the payment of fees or royalties provided that: 7 | 8 | source code distributions include the above copyright notice, this 9 | list of conditions and the following disclaimer; 10 | 11 | binary distributions include the above copyright notice, this list 12 | of conditions and the following disclaimer in their documentation. 13 | 14 | This software is provided 'as is' with no explicit or implied warranties 15 | in respect of its operation, including, but not limited to, correctness 16 | and fitness for purpose. 17 | --------------------------------------------------------------------------- 18 | Issue Date: 20/12/2007 19 | 20 | This file contains the definitions required to use AES in C. See aesopt.h 21 | for optimisation details. 22 | */ 23 | 24 | #ifndef _AES_H 25 | #define _AES_H 26 | 27 | #include 28 | 29 | /* This include is used to find 8 & 32 bit unsigned integer types */ 30 | #include "brg_types.h" 31 | 32 | #if defined(__cplusplus) 33 | extern "C" 34 | { 35 | #endif 36 | 37 | #define AES_128 /* if a fast 128 bit key scheduler is needed */ 38 | #define AES_192 /* if a fast 192 bit key scheduler is needed */ 39 | #define AES_256 /* if a fast 256 bit key scheduler is needed */ 40 | #define AES_VAR /* if variable key size scheduler is needed */ 41 | #define AES_MODES /* if support is needed for modes */ 42 | 43 | /* The following must also be set in assembler files if being used */ 44 | 45 | #define AES_ENCRYPT /* if support for encryption is needed */ 46 | #define AES_DECRYPT /* if support for decryption is needed */ 47 | 48 | #define AES_BLOCK_SIZE 16 /* the AES block size in bytes */ 49 | #define N_COLS 4 /* the number of columns in the state */ 50 | 51 | /* The key schedule length is 11, 13 or 15 16-byte blocks for 128, */ 52 | /* 192 or 256-bit keys respectively. That is 176, 208 or 240 bytes */ 53 | /* or 44, 52 or 60 32-bit words. */ 54 | 55 | #if defined( AES_VAR ) || defined( AES_256 ) 56 | #define KS_LENGTH 60 57 | #elif defined( AES_192 ) 58 | #define KS_LENGTH 52 59 | #else 60 | #define KS_LENGTH 44 61 | #endif 62 | 63 | #define AES_RETURN INT_RETURN 64 | 65 | /* the character array 'inf' in the following structures is used */ 66 | /* to hold AES context information. This AES code uses cx->inf.b[0] */ 67 | /* to hold the number of rounds multiplied by 16. The other three */ 68 | /* elements can be used by code that implements additional modes */ 69 | 70 | typedef union 71 | { uint32_t l; 72 | uint8_t b[4]; 73 | } aes_inf; 74 | 75 | #ifdef _MSC_VER 76 | # pragma warning( disable : 4324 ) 77 | #endif 78 | 79 | #if defined(_MSC_VER) && defined(_WIN64) 80 | #define ALIGNED_(x) __declspec(align(x)) 81 | #elif defined(__GNUC__) && defined(__x86_64__) 82 | #define ALIGNED_(x) __attribute__ ((aligned(x))) 83 | #else 84 | #define ALIGNED_(x) 85 | #endif 86 | 87 | typedef struct ALIGNED_(16) 88 | { uint32_t ks[KS_LENGTH]; 89 | aes_inf inf; 90 | } aes_encrypt_ctx; 91 | 92 | typedef struct ALIGNED_(16) 93 | { uint32_t ks[KS_LENGTH]; 94 | aes_inf inf; 95 | } aes_decrypt_ctx; 96 | 97 | #ifdef _MSC_VER 98 | # pragma warning( default : 4324 ) 99 | #endif 100 | 101 | /* This routine must be called before first use if non-static */ 102 | /* tables are being used */ 103 | 104 | AES_RETURN aes_init(void); 105 | 106 | /* Key lengths in the range 16 <= key_len <= 32 are given in bytes, */ 107 | /* those in the range 128 <= key_len <= 256 are given in bits */ 108 | 109 | #if defined( AES_ENCRYPT ) 110 | 111 | #if defined( AES_128 ) || defined( AES_VAR) 112 | AES_RETURN aes_encrypt_key128(const unsigned char *key, aes_encrypt_ctx cx[1]); 113 | #endif 114 | 115 | #if defined( AES_192 ) || defined( AES_VAR) 116 | AES_RETURN aes_encrypt_key192(const unsigned char *key, aes_encrypt_ctx cx[1]); 117 | #endif 118 | 119 | #if defined( AES_256 ) || defined( AES_VAR) 120 | AES_RETURN aes_encrypt_key256(const unsigned char *key, aes_encrypt_ctx cx[1]); 121 | #endif 122 | 123 | #if defined( AES_VAR ) 124 | AES_RETURN aes_encrypt_key(const unsigned char *key, int key_len, aes_encrypt_ctx cx[1]); 125 | #endif 126 | 127 | AES_RETURN aes_encrypt(const unsigned char *in, unsigned char *out, const aes_encrypt_ctx cx[1]); 128 | 129 | #endif 130 | 131 | #if defined( AES_DECRYPT ) 132 | 133 | #if defined( AES_128 ) || defined( AES_VAR) 134 | AES_RETURN aes_decrypt_key128(const unsigned char *key, aes_decrypt_ctx cx[1]); 135 | #endif 136 | 137 | #if defined( AES_192 ) || defined( AES_VAR) 138 | AES_RETURN aes_decrypt_key192(const unsigned char *key, aes_decrypt_ctx cx[1]); 139 | #endif 140 | 141 | #if defined( AES_256 ) || defined( AES_VAR) 142 | AES_RETURN aes_decrypt_key256(const unsigned char *key, aes_decrypt_ctx cx[1]); 143 | #endif 144 | 145 | #if defined( AES_VAR ) 146 | AES_RETURN aes_decrypt_key(const unsigned char *key, int key_len, aes_decrypt_ctx cx[1]); 147 | #endif 148 | 149 | AES_RETURN aes_decrypt(const unsigned char *in, unsigned char *out, const aes_decrypt_ctx cx[1]); 150 | 151 | #endif 152 | 153 | #if defined( AES_MODES ) 154 | 155 | /* Multiple calls to the following subroutines for multiple block */ 156 | /* ECB, CBC, CFB, OFB and CTR mode encryption can be used to handle */ 157 | /* long messages incrementally provided that the context AND the iv */ 158 | /* are preserved between all such calls. For the ECB and CBC modes */ 159 | /* each individual call within a series of incremental calls must */ 160 | /* process only full blocks (i.e. len must be a multiple of 16) but */ 161 | /* the CFB, OFB and CTR mode calls can handle multiple incremental */ 162 | /* calls of any length. Each mode is reset when a new AES key is */ 163 | /* set but ECB needs no reset and CBC can be reset without setting */ 164 | /* a new key by setting a new IV value. To reset CFB, OFB and CTR */ 165 | /* without setting the key, aes_mode_reset() must be called and the */ 166 | /* IV must be set. NOTE: All these calls update the IV on exit so */ 167 | /* this has to be reset if a new operation with the same IV as the */ 168 | /* previous one is required (or decryption follows encryption with */ 169 | /* the same IV array). */ 170 | 171 | AES_RETURN aes_test_alignment_detection(unsigned int n); 172 | 173 | AES_RETURN aes_ecb_encrypt(const unsigned char *ibuf, unsigned char *obuf, 174 | int len, const aes_encrypt_ctx cx[1]); 175 | 176 | AES_RETURN aes_ecb_decrypt(const unsigned char *ibuf, unsigned char *obuf, 177 | int len, const aes_decrypt_ctx cx[1]); 178 | 179 | AES_RETURN aes_cbc_encrypt(const unsigned char *ibuf, unsigned char *obuf, 180 | int len, unsigned char *iv, const aes_encrypt_ctx cx[1]); 181 | 182 | AES_RETURN aes_cbc_decrypt(const unsigned char *ibuf, unsigned char *obuf, 183 | int len, unsigned char *iv, const aes_decrypt_ctx cx[1]); 184 | 185 | AES_RETURN aes_mode_reset(aes_encrypt_ctx cx[1]); 186 | 187 | AES_RETURN aes_cfb_encrypt(const unsigned char *ibuf, unsigned char *obuf, 188 | int len, unsigned char *iv, aes_encrypt_ctx cx[1]); 189 | 190 | AES_RETURN aes_cfb_decrypt(const unsigned char *ibuf, unsigned char *obuf, 191 | int len, unsigned char *iv, aes_encrypt_ctx cx[1]); 192 | 193 | #define aes_ofb_encrypt aes_ofb_crypt 194 | #define aes_ofb_decrypt aes_ofb_crypt 195 | 196 | AES_RETURN aes_ofb_crypt(const unsigned char *ibuf, unsigned char *obuf, 197 | int len, unsigned char *iv, aes_encrypt_ctx cx[1]); 198 | 199 | typedef void cbuf_inc(unsigned char *cbuf); 200 | 201 | #define aes_ctr_encrypt aes_ctr_crypt 202 | #define aes_ctr_decrypt aes_ctr_crypt 203 | 204 | AES_RETURN aes_ctr_crypt(const unsigned char *ibuf, unsigned char *obuf, 205 | int len, unsigned char *cbuf, cbuf_inc ctr_inc, aes_encrypt_ctx cx[1]); 206 | 207 | #endif 208 | 209 | #if 0 210 | # define ADD_AESNI_MODE_CALLS 211 | #endif 212 | 213 | #if 0 && defined( ADD_AESNI_MODE_CALLS ) 214 | # define USE_AES_CONTEXT 215 | #endif 216 | 217 | #ifdef ADD_AESNI_MODE_CALLS 218 | # ifdef USE_AES_CONTEXT 219 | 220 | AES_RETURN aes_CBC_encrypt(const unsigned char *in, 221 | unsigned char *out, 222 | unsigned char ivec[16], 223 | unsigned long length, 224 | const aes_encrypt_ctx cx[1]); 225 | 226 | AES_RETURN aes_CBC_decrypt(const unsigned char *in, 227 | unsigned char *out, 228 | unsigned char ivec[16], 229 | unsigned long length, 230 | const aes_decrypt_ctx cx[1]); 231 | 232 | AES_RETURN AES_CTR_encrypt(const unsigned char *in, 233 | unsigned char *out, 234 | const unsigned char ivec[8], 235 | const unsigned char nonce[4], 236 | unsigned long length, 237 | const aes_encrypt_ctx cx[1]); 238 | 239 | # else 240 | 241 | void aes_CBC_encrypt(const unsigned char *in, 242 | unsigned char *out, 243 | unsigned char ivec[16], 244 | unsigned long length, 245 | unsigned char *key, 246 | int number_of_rounds); 247 | 248 | void aes_CBC_decrypt(const unsigned char *in, 249 | unsigned char *out, 250 | unsigned char ivec[16], 251 | unsigned long length, 252 | unsigned char *key, 253 | int number_of_rounds); 254 | 255 | void AES_CTR_encrypt(const unsigned char *in, 256 | unsigned char *out, 257 | const unsigned char ivec[8], 258 | const unsigned char nonce[4], 259 | unsigned long length, 260 | const unsigned char *key, 261 | int number_of_rounds); 262 | 263 | # endif 264 | #endif 265 | 266 | #if defined(__cplusplus) 267 | } 268 | #endif 269 | 270 | #endif 271 | -------------------------------------------------------------------------------- /SSZipArchive/minizip/aes/sha1.c: -------------------------------------------------------------------------------- 1 | /* 2 | --------------------------------------------------------------------------- 3 | Copyright (c) 1998-2010, Brian Gladman, Worcester, UK. All rights reserved. 4 | 5 | The redistribution and use of this software (with or without changes) 6 | is allowed without the payment of fees or royalties provided that: 7 | 8 | source code distributions include the above copyright notice, this 9 | list of conditions and the following disclaimer; 10 | 11 | binary distributions include the above copyright notice, this list 12 | of conditions and the following disclaimer in their documentation. 13 | 14 | This software is provided 'as is' with no explicit or implied warranties 15 | in respect of its operation, including, but not limited to, correctness 16 | and fitness for purpose. 17 | --------------------------------------------------------------------------- 18 | Issue Date: 20/12/2007 19 | */ 20 | 21 | #include /* for memcpy() etc. */ 22 | 23 | #include "sha1.h" 24 | #include "brg_endian.h" 25 | 26 | #if defined(__cplusplus) 27 | extern "C" 28 | { 29 | #endif 30 | 31 | #if defined( _MSC_VER ) && ( _MSC_VER > 800 ) 32 | #pragma intrinsic(memcpy) 33 | #pragma intrinsic(memset) 34 | #endif 35 | 36 | #if 0 && defined(_MSC_VER) 37 | #define rotl32 _lrotl 38 | #define rotr32 _lrotr 39 | #else 40 | #define rotl32(x,n) (((x) << n) | ((x) >> (32 - n))) 41 | #define rotr32(x,n) (((x) >> n) | ((x) << (32 - n))) 42 | #endif 43 | 44 | #if !defined(bswap_32) 45 | #define bswap_32(x) ((rotr32((x), 24) & 0x00ff00ff) | (rotr32((x), 8) & 0xff00ff00)) 46 | #endif 47 | 48 | #if (PLATFORM_BYTE_ORDER == IS_LITTLE_ENDIAN) 49 | #define SWAP_BYTES 50 | #else 51 | #undef SWAP_BYTES 52 | #endif 53 | 54 | #if defined(SWAP_BYTES) 55 | #define bsw_32(p,n) \ 56 | { int _i = (n); while(_i--) ((uint32_t*)p)[_i] = bswap_32(((uint32_t*)p)[_i]); } 57 | #else 58 | #define bsw_32(p,n) 59 | #endif 60 | 61 | #define SHA1_MASK (SHA1_BLOCK_SIZE - 1) 62 | 63 | #if 0 64 | 65 | #define ch(x,y,z) (((x) & (y)) ^ (~(x) & (z))) 66 | #define parity(x,y,z) ((x) ^ (y) ^ (z)) 67 | #define maj(x,y,z) (((x) & (y)) ^ ((x) & (z)) ^ ((y) & (z))) 68 | 69 | #else /* Discovered by Rich Schroeppel and Colin Plumb */ 70 | 71 | #define ch(x,y,z) ((z) ^ ((x) & ((y) ^ (z)))) 72 | #define parity(x,y,z) ((x) ^ (y) ^ (z)) 73 | #define maj(x,y,z) (((x) & (y)) | ((z) & ((x) ^ (y)))) 74 | 75 | #endif 76 | 77 | /* Compile 64 bytes of hash data into SHA1 context. Note */ 78 | /* that this routine assumes that the byte order in the */ 79 | /* ctx->wbuf[] at this point is in such an order that low */ 80 | /* address bytes in the ORIGINAL byte stream will go in */ 81 | /* this buffer to the high end of 32-bit words on BOTH big */ 82 | /* and little endian systems */ 83 | 84 | #ifdef ARRAY 85 | #define q(v,n) v[n] 86 | #else 87 | #define q(v,n) v##n 88 | #endif 89 | 90 | #ifdef SHA_1 91 | 92 | #define one_cycle(v,a,b,c,d,e,f,k,h) \ 93 | q(v,e) += rotr32(q(v,a),27) + \ 94 | f(q(v,b),q(v,c),q(v,d)) + k + h; \ 95 | q(v,b) = rotr32(q(v,b), 2) 96 | 97 | #define five_cycle(v,f,k,i) \ 98 | one_cycle(v, 0,1,2,3,4, f,k,hf(i )); \ 99 | one_cycle(v, 4,0,1,2,3, f,k,hf(i+1)); \ 100 | one_cycle(v, 3,4,0,1,2, f,k,hf(i+2)); \ 101 | one_cycle(v, 2,3,4,0,1, f,k,hf(i+3)); \ 102 | one_cycle(v, 1,2,3,4,0, f,k,hf(i+4)) 103 | 104 | VOID_RETURN sha1_compile(sha1_ctx ctx[1]) 105 | { uint32_t *w = ctx->wbuf; 106 | 107 | #ifdef ARRAY 108 | uint32_t v[5]; 109 | memcpy(v, ctx->hash, sizeof(ctx->hash)); 110 | #else 111 | uint32_t v0, v1, v2, v3, v4; 112 | v0 = ctx->hash[0]; v1 = ctx->hash[1]; 113 | v2 = ctx->hash[2]; v3 = ctx->hash[3]; 114 | v4 = ctx->hash[4]; 115 | #endif 116 | 117 | #define hf(i) w[i] 118 | 119 | five_cycle(v, ch, 0x5a827999, 0); 120 | five_cycle(v, ch, 0x5a827999, 5); 121 | five_cycle(v, ch, 0x5a827999, 10); 122 | one_cycle(v,0,1,2,3,4, ch, 0x5a827999, hf(15)); \ 123 | 124 | #undef hf 125 | #define hf(i) (w[(i) & 15] = rotl32( \ 126 | w[((i) + 13) & 15] ^ w[((i) + 8) & 15] \ 127 | ^ w[((i) + 2) & 15] ^ w[(i) & 15], 1)) 128 | 129 | one_cycle(v,4,0,1,2,3, ch, 0x5a827999, hf(16)); 130 | one_cycle(v,3,4,0,1,2, ch, 0x5a827999, hf(17)); 131 | one_cycle(v,2,3,4,0,1, ch, 0x5a827999, hf(18)); 132 | one_cycle(v,1,2,3,4,0, ch, 0x5a827999, hf(19)); 133 | 134 | five_cycle(v, parity, 0x6ed9eba1, 20); 135 | five_cycle(v, parity, 0x6ed9eba1, 25); 136 | five_cycle(v, parity, 0x6ed9eba1, 30); 137 | five_cycle(v, parity, 0x6ed9eba1, 35); 138 | 139 | five_cycle(v, maj, 0x8f1bbcdc, 40); 140 | five_cycle(v, maj, 0x8f1bbcdc, 45); 141 | five_cycle(v, maj, 0x8f1bbcdc, 50); 142 | five_cycle(v, maj, 0x8f1bbcdc, 55); 143 | 144 | five_cycle(v, parity, 0xca62c1d6, 60); 145 | five_cycle(v, parity, 0xca62c1d6, 65); 146 | five_cycle(v, parity, 0xca62c1d6, 70); 147 | five_cycle(v, parity, 0xca62c1d6, 75); 148 | 149 | #ifdef ARRAY 150 | ctx->hash[0] += v[0]; ctx->hash[1] += v[1]; 151 | ctx->hash[2] += v[2]; ctx->hash[3] += v[3]; 152 | ctx->hash[4] += v[4]; 153 | #else 154 | ctx->hash[0] += v0; ctx->hash[1] += v1; 155 | ctx->hash[2] += v2; ctx->hash[3] += v3; 156 | ctx->hash[4] += v4; 157 | #endif 158 | } 159 | 160 | VOID_RETURN sha1_begin(sha1_ctx ctx[1]) 161 | { 162 | memset(ctx, 0, sizeof(sha1_ctx)); 163 | ctx->hash[0] = 0x67452301; 164 | ctx->hash[1] = 0xefcdab89; 165 | ctx->hash[2] = 0x98badcfe; 166 | ctx->hash[3] = 0x10325476; 167 | ctx->hash[4] = 0xc3d2e1f0; 168 | } 169 | 170 | /* SHA1 hash data in an array of bytes into hash buffer and */ 171 | /* call the hash_compile function as required. For both the */ 172 | /* bit and byte orientated versions, the block length 'len' */ 173 | /* must not be greater than 2^32 - 1 bits (2^29 - 1 bytes) */ 174 | 175 | VOID_RETURN sha1_hash(const unsigned char data[], unsigned long len, sha1_ctx ctx[1]) 176 | { uint32_t pos = (uint32_t)((ctx->count[0] >> 3) & SHA1_MASK); 177 | const unsigned char *sp = data; 178 | unsigned char *w = (unsigned char*)ctx->wbuf; 179 | #if SHA1_BITS == 1 180 | uint32_t ofs = (ctx->count[0] & 7); 181 | #else 182 | len <<= 3; 183 | #endif 184 | if((ctx->count[0] += len) < len) 185 | ++(ctx->count[1]); 186 | #if SHA1_BITS == 1 187 | if(ofs) /* if not on a byte boundary */ 188 | { 189 | if(ofs + len < 8) /* if no added bytes are needed */ 190 | { 191 | w[pos] |= (*sp >> ofs); 192 | } 193 | else /* otherwise and add bytes */ 194 | { unsigned char part = w[pos]; 195 | 196 | while((int)(ofs + (len -= 8)) >= 0) 197 | { 198 | w[pos++] = part | (*sp >> ofs); 199 | part = *sp++ << (8 - ofs); 200 | if(pos == SHA1_BLOCK_SIZE) 201 | { 202 | bsw_32(w, SHA1_BLOCK_SIZE >> 2); 203 | sha1_compile(ctx); pos = 0; 204 | } 205 | } 206 | 207 | w[pos] = part; 208 | } 209 | } 210 | else /* data is byte aligned */ 211 | #endif 212 | { uint32_t space = SHA1_BLOCK_SIZE - pos; 213 | 214 | while(len >= (space << 3)) 215 | { 216 | memcpy(w + pos, sp, space); 217 | bsw_32(w, SHA1_BLOCK_SIZE >> 2); 218 | sha1_compile(ctx); 219 | sp += space; len -= (space << 3); 220 | space = SHA1_BLOCK_SIZE; pos = 0; 221 | } 222 | memcpy(w + pos, sp, (len + 7 * SHA1_BITS) >> 3); 223 | } 224 | } 225 | 226 | /* SHA1 final padding and digest calculation */ 227 | 228 | VOID_RETURN sha1_end(unsigned char hval[], sha1_ctx ctx[1]) 229 | { uint32_t i = (uint32_t)((ctx->count[0] >> 3) & SHA1_MASK), m1; 230 | 231 | /* put bytes in the buffer in an order in which references to */ 232 | /* 32-bit words will put bytes with lower addresses into the */ 233 | /* top of 32 bit words on BOTH big and little endian machines */ 234 | bsw_32(ctx->wbuf, (i + 3 + SHA1_BITS) >> 2); 235 | 236 | /* we now need to mask valid bytes and add the padding which is */ 237 | /* a single 1 bit and as many zero bits as necessary. Note that */ 238 | /* we can always add the first padding byte here because the */ 239 | /* buffer always has at least one empty slot */ 240 | m1 = (unsigned char)0x80 >> (ctx->count[0] & 7); 241 | ctx->wbuf[i >> 2] &= ((0xffffff00 | (~m1 + 1)) << 8 * (~i & 3)); 242 | ctx->wbuf[i >> 2] |= (m1 << 8 * (~i & 3)); 243 | 244 | /* we need 9 or more empty positions, one for the padding byte */ 245 | /* (above) and eight for the length count. If there is not */ 246 | /* enough space, pad and empty the buffer */ 247 | if(i > SHA1_BLOCK_SIZE - 9) 248 | { 249 | if(i < 60) ctx->wbuf[15] = 0; 250 | sha1_compile(ctx); 251 | i = 0; 252 | } 253 | else /* compute a word index for the empty buffer positions */ 254 | i = (i >> 2) + 1; 255 | 256 | while(i < 14) /* and zero pad all but last two positions */ 257 | ctx->wbuf[i++] = 0; 258 | 259 | /* the following 32-bit length fields are assembled in the */ 260 | /* wrong byte order on little endian machines but this is */ 261 | /* corrected later since they are only ever used as 32-bit */ 262 | /* word values. */ 263 | ctx->wbuf[14] = ctx->count[1]; 264 | ctx->wbuf[15] = ctx->count[0]; 265 | sha1_compile(ctx); 266 | 267 | /* extract the hash value as bytes in case the hash buffer is */ 268 | /* misaligned for 32-bit words */ 269 | for(i = 0; i < SHA1_DIGEST_SIZE; ++i) 270 | hval[i] = ((ctx->hash[i >> 2] >> (8 * (~i & 3))) & 0xff); 271 | } 272 | 273 | VOID_RETURN sha1(unsigned char hval[], const unsigned char data[], unsigned long len) 274 | { sha1_ctx cx[1]; 275 | 276 | sha1_begin(cx); sha1_hash(data, len, cx); sha1_end(hval, cx); 277 | } 278 | 279 | #endif 280 | 281 | #if defined(__cplusplus) 282 | } 283 | #endif 284 | -------------------------------------------------------------------------------- /SSZipArchive/minizip/zip.h: -------------------------------------------------------------------------------- 1 | /* zip.h -- IO on .zip files using zlib 2 | Version 1.2.0, September 16th, 2017 3 | part of the MiniZip project 4 | 5 | Copyright (C) 2012-2017 Nathan Moinvaziri 6 | https://github.com/nmoinvaz/minizip 7 | Copyright (C) 2009-2010 Mathias Svensson 8 | Modifications for Zip64 support 9 | http://result42.com 10 | Copyright (C) 1998-2010 Gilles Vollant 11 | http://www.winimage.com/zLibDll/minizip.html 12 | 13 | This program is distributed under the terms of the same license as zlib. 14 | See the accompanying LICENSE file for the full text of the license. 15 | */ 16 | 17 | #ifndef _ZIP_H 18 | #define _ZIP_H 19 | 20 | #define HAVE_AES 21 | 22 | #ifdef __cplusplus 23 | extern "C" { 24 | #endif 25 | 26 | #ifndef _ZLIB_H 27 | # include "zlib.h" 28 | #endif 29 | 30 | #ifndef _ZLIBIOAPI_H 31 | # include "ioapi.h" 32 | #endif 33 | 34 | #ifdef HAVE_BZIP2 35 | # include "bzlib.h" 36 | #endif 37 | 38 | #define Z_BZIP2ED 12 39 | 40 | #if defined(STRICTZIP) || defined(STRICTZIPUNZIP) 41 | /* like the STRICT of WIN32, we define a pointer that cannot be converted 42 | from (void*) without cast */ 43 | typedef struct TagzipFile__ { int unused; } zip_file__; 44 | typedef zip_file__ *zipFile; 45 | #else 46 | typedef voidp zipFile; 47 | #endif 48 | 49 | #define ZIP_OK (0) 50 | #define ZIP_EOF (0) 51 | #define ZIP_ERRNO (Z_ERRNO) 52 | #define ZIP_PARAMERROR (-102) 53 | #define ZIP_BADZIPFILE (-103) 54 | #define ZIP_INTERNALERROR (-104) 55 | 56 | #ifndef DEF_MEM_LEVEL 57 | # if MAX_MEM_LEVEL >= 8 58 | # define DEF_MEM_LEVEL 8 59 | # else 60 | # define DEF_MEM_LEVEL MAX_MEM_LEVEL 61 | # endif 62 | #endif 63 | 64 | typedef struct 65 | { 66 | uint32_t dos_date; 67 | uint16_t internal_fa; /* internal file attributes 2 bytes */ 68 | uint32_t external_fa; /* external file attributes 4 bytes */ 69 | } zip_fileinfo; 70 | 71 | #define APPEND_STATUS_CREATE (0) 72 | #define APPEND_STATUS_CREATEAFTER (1) 73 | #define APPEND_STATUS_ADDINZIP (2) 74 | 75 | /***************************************************************************/ 76 | /* Writing a zip file */ 77 | 78 | extern zipFile ZEXPORT zipOpen(const char *path, int append); 79 | extern zipFile ZEXPORT zipOpen64(const void *path, int append); 80 | /* Create a zipfile. 81 | 82 | path should contain the full path (by example, on a Windows XP computer 83 | "c:\\zlib\\zlib113.zip" or on an Unix computer "zlib/zlib113.zip". 84 | 85 | return NULL if zipfile cannot be opened 86 | return zipFile handle if no error 87 | 88 | If the file path exist and append == APPEND_STATUS_CREATEAFTER, the zip 89 | will be created at the end of the file. (useful if the file contain a self extractor code) 90 | If the file path exist and append == APPEND_STATUS_ADDINZIP, we will add files in existing 91 | zip (be sure you don't add file that doesn't exist) 92 | 93 | NOTE: There is no delete function into a zipfile. If you want delete file into a zipfile, 94 | you must open a zipfile, and create another. Of course, you can use RAW reading and writing to copy 95 | the file you did not want delete. */ 96 | 97 | extern zipFile ZEXPORT zipOpen2(const char *path, int append, const char **globalcomment, 98 | zlib_filefunc_def *pzlib_filefunc_def); 99 | 100 | extern zipFile ZEXPORT zipOpen2_64(const void *path, int append, const char **globalcomment, 101 | zlib_filefunc64_def *pzlib_filefunc_def); 102 | 103 | extern zipFile ZEXPORT zipOpen3(const char *path, int append, uint64_t disk_size, 104 | const char **globalcomment, zlib_filefunc_def *pzlib_filefunc_def); 105 | /* Same as zipOpen2 but allows specification of spanned zip size */ 106 | 107 | extern zipFile ZEXPORT zipOpen3_64(const void *path, int append, uint64_t disk_size, 108 | const char **globalcomment, zlib_filefunc64_def *pzlib_filefunc_def); 109 | 110 | extern int ZEXPORT zipOpenNewFileInZip(zipFile file, const char *filename, const zip_fileinfo *zipfi, 111 | const void *extrafield_local, uint16_t size_extrafield_local, const void *extrafield_global, 112 | uint16_t size_extrafield_global, const char *comment, uint16_t method, int level); 113 | /* Open a file in the ZIP for writing. 114 | 115 | filename : the filename in zip (if NULL, '-' without quote will be used 116 | *zipfi contain supplemental information 117 | extrafield_local buffer to store the local header extra field data, can be NULL 118 | size_extrafield_local size of extrafield_local buffer 119 | extrafield_global buffer to store the global header extra field data, can be NULL 120 | size_extrafield_global size of extrafield_local buffer 121 | comment buffer for comment string 122 | method contain the compression method (0 for store, Z_DEFLATED for deflate) 123 | level contain the level of compression (can be Z_DEFAULT_COMPRESSION) 124 | zip64 is set to 1 if a zip64 extended information block should be added to the local file header. 125 | this MUST be '1' if the uncompressed size is >= 0xffffffff. */ 126 | 127 | extern int ZEXPORT zipOpenNewFileInZip64(zipFile file, const char *filename, const zip_fileinfo *zipfi, 128 | const void *extrafield_local, uint16_t size_extrafield_local, const void *extrafield_global, 129 | uint16_t size_extrafield_global, const char *comment, uint16_t method, int level, int zip64); 130 | /* Same as zipOpenNewFileInZip with zip64 support */ 131 | 132 | extern int ZEXPORT zipOpenNewFileInZip2(zipFile file, const char *filename, const zip_fileinfo *zipfi, 133 | const void *extrafield_local, uint16_t size_extrafield_local, const void *extrafield_global, 134 | uint16_t size_extrafield_global, const char *comment, uint16_t method, int level, int raw); 135 | /* Same as zipOpenNewFileInZip, except if raw=1, we write raw file */ 136 | 137 | extern int ZEXPORT zipOpenNewFileInZip2_64(zipFile file, const char *filename, const zip_fileinfo *zipfi, 138 | const void *extrafield_local, uint16_t size_extrafield_local, const void *extrafield_global, 139 | uint16_t size_extrafield_global, const char *comment, uint16_t method, int level, int raw, int zip64); 140 | /* Same as zipOpenNewFileInZip3 with zip64 support */ 141 | 142 | extern int ZEXPORT zipOpenNewFileInZip3(zipFile file, const char *filename, const zip_fileinfo *zipfi, 143 | const void *extrafield_local, uint16_t size_extrafield_local, const void *extrafield_global, 144 | uint16_t size_extrafield_global, const char *comment, uint16_t method, int level, int raw, int windowBits, int memLevel, 145 | int strategy, const char *password, ZIP_UNUSED uint32_t crc_for_crypting); 146 | /* Same as zipOpenNewFileInZip2, except 147 | windowBits, memLevel, strategy : see parameter strategy in deflateInit2 148 | password : crypting password (NULL for no crypting) 149 | crc_for_crypting : crc of file to compress (needed for crypting) */ 150 | 151 | extern int ZEXPORT zipOpenNewFileInZip3_64(zipFile file, const char *filename, const zip_fileinfo *zipfi, 152 | const void *extrafield_local, uint16_t size_extrafield_local, const void *extrafield_global, 153 | uint16_t size_extrafield_global, const char *comment, uint16_t method, int level, int raw, int windowBits, int memLevel, 154 | int strategy, const char *password, ZIP_UNUSED uint32_t crc_for_crypting, int zip64); 155 | /* Same as zipOpenNewFileInZip3 with zip64 support */ 156 | 157 | extern int ZEXPORT zipOpenNewFileInZip4(zipFile file, const char *filename, const zip_fileinfo *zipfi, 158 | const void *extrafield_local, uint16_t size_extrafield_local, const void *extrafield_global, 159 | uint16_t size_extrafield_global, const char *comment, uint16_t method, int level, int raw, int windowBits, int memLevel, 160 | int strategy, const char *password, ZIP_UNUSED uint32_t crc_for_crypting, uint16_t version_madeby, uint16_t flag_base); 161 | /* Same as zipOpenNewFileInZip3 except versionMadeBy & flag fields */ 162 | 163 | extern int ZEXPORT zipOpenNewFileInZip4_64(zipFile file, const char *filename, const zip_fileinfo *zipfi, 164 | const void *extrafield_local, uint16_t size_extrafield_local, const void *extrafield_global, 165 | uint16_t size_extrafield_global, const char *comment, uint16_t method, int level, int raw, int windowBits, int memLevel, 166 | int strategy, const char *password, ZIP_UNUSED uint32_t crc_for_crypting, uint16_t version_madeby, uint16_t flag_base, int zip64); 167 | /* Same as zipOpenNewFileInZip4 with zip64 support */ 168 | 169 | extern int ZEXPORT zipOpenNewFileInZip5(zipFile file, 170 | const char *filename, 171 | const zip_fileinfo *zipfi, 172 | const void *extrafield_local, 173 | uint16_t size_extrafield_local, 174 | const void *extrafield_global, 175 | uint16_t size_extrafield_global, 176 | const char *comment, 177 | uint16_t flag_base, 178 | int zip64, 179 | uint16_t method, 180 | int level, 181 | int raw, 182 | int windowBits, 183 | int memLevel, 184 | int strategy, 185 | const char *password, 186 | int aes, 187 | uint16_t version_madeby); 188 | /* Allowing optional aes */ 189 | 190 | extern int ZEXPORT zipWriteInFileInZip(zipFile file, const void *buf, uint32_t len); 191 | /* Write data in the zipfile */ 192 | 193 | extern int ZEXPORT zipCloseFileInZip(zipFile file); 194 | /* Close the current file in the zipfile */ 195 | 196 | extern int ZEXPORT zipCloseFileInZipRaw(zipFile file, uint32_t uncompressed_size, uint32_t crc32); 197 | extern int ZEXPORT zipCloseFileInZipRaw64(zipFile file, uint64_t uncompressed_size, uint32_t crc32); 198 | /* Close the current file in the zipfile, for file opened with parameter raw=1 in zipOpenNewFileInZip2 199 | where raw is compressed data. Parameters uncompressed_size and crc32 are value for the uncompressed data. */ 200 | 201 | extern int ZEXPORT zipClose(zipFile file, const char *global_comment); 202 | /* Close the zipfile */ 203 | 204 | extern int ZEXPORT zipClose_64(zipFile file, const char *global_comment); 205 | 206 | extern int ZEXPORT zipClose2_64(zipFile file, const char *global_comment, uint16_t version_madeby); 207 | /* Same as zipClose_64 except version_madeby field */ 208 | 209 | /***************************************************************************/ 210 | 211 | #ifdef __cplusplus 212 | } 213 | #endif 214 | 215 | #endif /* _ZIP_H */ 216 | -------------------------------------------------------------------------------- /SSZipArchive/minizip/aes/aescrypt.c: -------------------------------------------------------------------------------- 1 | /* 2 | --------------------------------------------------------------------------- 3 | Copyright (c) 1998-2013, Brian Gladman, Worcester, UK. All rights reserved. 4 | 5 | The redistribution and use of this software (with or without changes) 6 | is allowed without the payment of fees or royalties provided that: 7 | 8 | source code distributions include the above copyright notice, this 9 | list of conditions and the following disclaimer; 10 | 11 | binary distributions include the above copyright notice, this list 12 | of conditions and the following disclaimer in their documentation. 13 | 14 | This software is provided 'as is' with no explicit or implied warranties 15 | in respect of its operation, including, but not limited to, correctness 16 | and fitness for purpose. 17 | --------------------------------------------------------------------------- 18 | Issue Date: 20/12/2007 19 | */ 20 | 21 | #include "aesopt.h" 22 | #include "aestab.h" 23 | 24 | #if defined( USE_INTEL_AES_IF_PRESENT ) 25 | # include "aes_ni.h" 26 | #else 27 | /* map names here to provide the external API ('name' -> 'aes_name') */ 28 | # define aes_xi(x) aes_ ## x 29 | #endif 30 | 31 | #if defined(__cplusplus) 32 | extern "C" 33 | { 34 | #endif 35 | 36 | #define si(y,x,k,c) (s(y,c) = word_in(x, c) ^ (k)[c]) 37 | #define so(y,x,c) word_out(y, c, s(x,c)) 38 | 39 | #if defined(ARRAYS) 40 | #define locals(y,x) x[4],y[4] 41 | #else 42 | #define locals(y,x) x##0,x##1,x##2,x##3,y##0,y##1,y##2,y##3 43 | #endif 44 | 45 | #define l_copy(y, x) s(y,0) = s(x,0); s(y,1) = s(x,1); \ 46 | s(y,2) = s(x,2); s(y,3) = s(x,3); 47 | #define state_in(y,x,k) si(y,x,k,0); si(y,x,k,1); si(y,x,k,2); si(y,x,k,3) 48 | #define state_out(y,x) so(y,x,0); so(y,x,1); so(y,x,2); so(y,x,3) 49 | #define round(rm,y,x,k) rm(y,x,k,0); rm(y,x,k,1); rm(y,x,k,2); rm(y,x,k,3) 50 | 51 | #if ( FUNCS_IN_C & ENCRYPTION_IN_C ) 52 | 53 | /* Visual C++ .Net v7.1 provides the fastest encryption code when using 54 | Pentium optimiation with small code but this is poor for decryption 55 | so we need to control this with the following VC++ pragmas 56 | */ 57 | 58 | #if defined( _MSC_VER ) && !defined( _WIN64 ) 59 | #pragma optimize( "s", on ) 60 | #endif 61 | 62 | /* Given the column (c) of the output state variable, the following 63 | macros give the input state variables which are needed in its 64 | computation for each row (r) of the state. All the alternative 65 | macros give the same end values but expand into different ways 66 | of calculating these values. In particular the complex macro 67 | used for dynamically variable block sizes is designed to expand 68 | to a compile time constant whenever possible but will expand to 69 | conditional clauses on some branches (I am grateful to Frank 70 | Yellin for this construction) 71 | */ 72 | 73 | #define fwd_var(x,r,c)\ 74 | ( r == 0 ? ( c == 0 ? s(x,0) : c == 1 ? s(x,1) : c == 2 ? s(x,2) : s(x,3))\ 75 | : r == 1 ? ( c == 0 ? s(x,1) : c == 1 ? s(x,2) : c == 2 ? s(x,3) : s(x,0))\ 76 | : r == 2 ? ( c == 0 ? s(x,2) : c == 1 ? s(x,3) : c == 2 ? s(x,0) : s(x,1))\ 77 | : ( c == 0 ? s(x,3) : c == 1 ? s(x,0) : c == 2 ? s(x,1) : s(x,2))) 78 | 79 | #if defined(FT4_SET) 80 | #undef dec_fmvars 81 | #define fwd_rnd(y,x,k,c) (s(y,c) = (k)[c] ^ four_tables(x,t_use(f,n),fwd_var,rf1,c)) 82 | #elif defined(FT1_SET) 83 | #undef dec_fmvars 84 | #define fwd_rnd(y,x,k,c) (s(y,c) = (k)[c] ^ one_table(x,upr,t_use(f,n),fwd_var,rf1,c)) 85 | #else 86 | #define fwd_rnd(y,x,k,c) (s(y,c) = (k)[c] ^ fwd_mcol(no_table(x,t_use(s,box),fwd_var,rf1,c))) 87 | #endif 88 | 89 | #if defined(FL4_SET) 90 | #define fwd_lrnd(y,x,k,c) (s(y,c) = (k)[c] ^ four_tables(x,t_use(f,l),fwd_var,rf1,c)) 91 | #elif defined(FL1_SET) 92 | #define fwd_lrnd(y,x,k,c) (s(y,c) = (k)[c] ^ one_table(x,ups,t_use(f,l),fwd_var,rf1,c)) 93 | #else 94 | #define fwd_lrnd(y,x,k,c) (s(y,c) = (k)[c] ^ no_table(x,t_use(s,box),fwd_var,rf1,c)) 95 | #endif 96 | 97 | AES_RETURN aes_xi(encrypt)(const unsigned char *in, unsigned char *out, const aes_encrypt_ctx cx[1]) 98 | { uint32_t locals(b0, b1); 99 | const uint32_t *kp; 100 | #if defined( dec_fmvars ) 101 | dec_fmvars; /* declare variables for fwd_mcol() if needed */ 102 | #endif 103 | 104 | if(cx->inf.b[0] != 10 * 16 && cx->inf.b[0] != 12 * 16 && cx->inf.b[0] != 14 * 16) 105 | return EXIT_FAILURE; 106 | 107 | kp = cx->ks; 108 | state_in(b0, in, kp); 109 | 110 | #if (ENC_UNROLL == FULL) 111 | 112 | switch(cx->inf.b[0]) 113 | { 114 | case 14 * 16: 115 | round(fwd_rnd, b1, b0, kp + 1 * N_COLS); 116 | round(fwd_rnd, b0, b1, kp + 2 * N_COLS); 117 | kp += 2 * N_COLS; 118 | case 12 * 16: 119 | round(fwd_rnd, b1, b0, kp + 1 * N_COLS); 120 | round(fwd_rnd, b0, b1, kp + 2 * N_COLS); 121 | kp += 2 * N_COLS; 122 | case 10 * 16: 123 | round(fwd_rnd, b1, b0, kp + 1 * N_COLS); 124 | round(fwd_rnd, b0, b1, kp + 2 * N_COLS); 125 | round(fwd_rnd, b1, b0, kp + 3 * N_COLS); 126 | round(fwd_rnd, b0, b1, kp + 4 * N_COLS); 127 | round(fwd_rnd, b1, b0, kp + 5 * N_COLS); 128 | round(fwd_rnd, b0, b1, kp + 6 * N_COLS); 129 | round(fwd_rnd, b1, b0, kp + 7 * N_COLS); 130 | round(fwd_rnd, b0, b1, kp + 8 * N_COLS); 131 | round(fwd_rnd, b1, b0, kp + 9 * N_COLS); 132 | round(fwd_lrnd, b0, b1, kp +10 * N_COLS); 133 | } 134 | 135 | #else 136 | 137 | #if (ENC_UNROLL == PARTIAL) 138 | { uint32_t rnd; 139 | for(rnd = 0; rnd < (cx->inf.b[0] >> 5) - 1; ++rnd) 140 | { 141 | kp += N_COLS; 142 | round(fwd_rnd, b1, b0, kp); 143 | kp += N_COLS; 144 | round(fwd_rnd, b0, b1, kp); 145 | } 146 | kp += N_COLS; 147 | round(fwd_rnd, b1, b0, kp); 148 | #else 149 | { uint32_t rnd; 150 | for(rnd = 0; rnd < (cx->inf.b[0] >> 4) - 1; ++rnd) 151 | { 152 | kp += N_COLS; 153 | round(fwd_rnd, b1, b0, kp); 154 | l_copy(b0, b1); 155 | } 156 | #endif 157 | kp += N_COLS; 158 | round(fwd_lrnd, b0, b1, kp); 159 | } 160 | #endif 161 | 162 | state_out(out, b0); 163 | return EXIT_SUCCESS; 164 | } 165 | 166 | #endif 167 | 168 | #if ( FUNCS_IN_C & DECRYPTION_IN_C) 169 | 170 | /* Visual C++ .Net v7.1 provides the fastest encryption code when using 171 | Pentium optimiation with small code but this is poor for decryption 172 | so we need to control this with the following VC++ pragmas 173 | */ 174 | 175 | #if defined( _MSC_VER ) && !defined( _WIN64 ) 176 | #pragma optimize( "t", on ) 177 | #endif 178 | 179 | /* Given the column (c) of the output state variable, the following 180 | macros give the input state variables which are needed in its 181 | computation for each row (r) of the state. All the alternative 182 | macros give the same end values but expand into different ways 183 | of calculating these values. In particular the complex macro 184 | used for dynamically variable block sizes is designed to expand 185 | to a compile time constant whenever possible but will expand to 186 | conditional clauses on some branches (I am grateful to Frank 187 | Yellin for this construction) 188 | */ 189 | 190 | #define inv_var(x,r,c)\ 191 | ( r == 0 ? ( c == 0 ? s(x,0) : c == 1 ? s(x,1) : c == 2 ? s(x,2) : s(x,3))\ 192 | : r == 1 ? ( c == 0 ? s(x,3) : c == 1 ? s(x,0) : c == 2 ? s(x,1) : s(x,2))\ 193 | : r == 2 ? ( c == 0 ? s(x,2) : c == 1 ? s(x,3) : c == 2 ? s(x,0) : s(x,1))\ 194 | : ( c == 0 ? s(x,1) : c == 1 ? s(x,2) : c == 2 ? s(x,3) : s(x,0))) 195 | 196 | #if defined(IT4_SET) 197 | #undef dec_imvars 198 | #define inv_rnd(y,x,k,c) (s(y,c) = (k)[c] ^ four_tables(x,t_use(i,n),inv_var,rf1,c)) 199 | #elif defined(IT1_SET) 200 | #undef dec_imvars 201 | #define inv_rnd(y,x,k,c) (s(y,c) = (k)[c] ^ one_table(x,upr,t_use(i,n),inv_var,rf1,c)) 202 | #else 203 | #define inv_rnd(y,x,k,c) (s(y,c) = inv_mcol((k)[c] ^ no_table(x,t_use(i,box),inv_var,rf1,c))) 204 | #endif 205 | 206 | #if defined(IL4_SET) 207 | #define inv_lrnd(y,x,k,c) (s(y,c) = (k)[c] ^ four_tables(x,t_use(i,l),inv_var,rf1,c)) 208 | #elif defined(IL1_SET) 209 | #define inv_lrnd(y,x,k,c) (s(y,c) = (k)[c] ^ one_table(x,ups,t_use(i,l),inv_var,rf1,c)) 210 | #else 211 | #define inv_lrnd(y,x,k,c) (s(y,c) = (k)[c] ^ no_table(x,t_use(i,box),inv_var,rf1,c)) 212 | #endif 213 | 214 | /* This code can work with the decryption key schedule in the */ 215 | /* order that is used for encrytpion (where the 1st decryption */ 216 | /* round key is at the high end ot the schedule) or with a key */ 217 | /* schedule that has been reversed to put the 1st decryption */ 218 | /* round key at the low end of the schedule in memory (when */ 219 | /* AES_REV_DKS is defined) */ 220 | 221 | #ifdef AES_REV_DKS 222 | #define key_ofs 0 223 | #define rnd_key(n) (kp + n * N_COLS) 224 | #else 225 | #define key_ofs 1 226 | #define rnd_key(n) (kp - n * N_COLS) 227 | #endif 228 | 229 | AES_RETURN aes_xi(decrypt)(const unsigned char *in, unsigned char *out, const aes_decrypt_ctx cx[1]) 230 | { uint32_t locals(b0, b1); 231 | #if defined( dec_imvars ) 232 | dec_imvars; /* declare variables for inv_mcol() if needed */ 233 | #endif 234 | const uint32_t *kp; 235 | 236 | if(cx->inf.b[0] != 10 * 16 && cx->inf.b[0] != 12 * 16 && cx->inf.b[0] != 14 * 16) 237 | return EXIT_FAILURE; 238 | 239 | kp = cx->ks + (key_ofs ? (cx->inf.b[0] >> 2) : 0); 240 | state_in(b0, in, kp); 241 | 242 | #if (DEC_UNROLL == FULL) 243 | 244 | kp = cx->ks + (key_ofs ? 0 : (cx->inf.b[0] >> 2)); 245 | switch(cx->inf.b[0]) 246 | { 247 | case 14 * 16: 248 | round(inv_rnd, b1, b0, rnd_key(-13)); 249 | round(inv_rnd, b0, b1, rnd_key(-12)); 250 | case 12 * 16: 251 | round(inv_rnd, b1, b0, rnd_key(-11)); 252 | round(inv_rnd, b0, b1, rnd_key(-10)); 253 | case 10 * 16: 254 | round(inv_rnd, b1, b0, rnd_key(-9)); 255 | round(inv_rnd, b0, b1, rnd_key(-8)); 256 | round(inv_rnd, b1, b0, rnd_key(-7)); 257 | round(inv_rnd, b0, b1, rnd_key(-6)); 258 | round(inv_rnd, b1, b0, rnd_key(-5)); 259 | round(inv_rnd, b0, b1, rnd_key(-4)); 260 | round(inv_rnd, b1, b0, rnd_key(-3)); 261 | round(inv_rnd, b0, b1, rnd_key(-2)); 262 | round(inv_rnd, b1, b0, rnd_key(-1)); 263 | round(inv_lrnd, b0, b1, rnd_key( 0)); 264 | } 265 | 266 | #else 267 | 268 | #if (DEC_UNROLL == PARTIAL) 269 | { uint32_t rnd; 270 | for(rnd = 0; rnd < (cx->inf.b[0] >> 5) - 1; ++rnd) 271 | { 272 | kp = rnd_key(1); 273 | round(inv_rnd, b1, b0, kp); 274 | kp = rnd_key(1); 275 | round(inv_rnd, b0, b1, kp); 276 | } 277 | kp = rnd_key(1); 278 | round(inv_rnd, b1, b0, kp); 279 | #else 280 | { uint32_t rnd; 281 | for(rnd = 0; rnd < (cx->inf.b[0] >> 4) - 1; ++rnd) 282 | { 283 | kp = rnd_key(1); 284 | round(inv_rnd, b1, b0, kp); 285 | l_copy(b0, b1); 286 | } 287 | #endif 288 | kp = rnd_key(1); 289 | round(inv_lrnd, b0, b1, kp); 290 | } 291 | #endif 292 | 293 | state_out(out, b0); 294 | return EXIT_SUCCESS; 295 | } 296 | 297 | #endif 298 | 299 | #if defined(__cplusplus) 300 | } 301 | #endif 302 | -------------------------------------------------------------------------------- /SSZipArchive/minizip/unzip.h: -------------------------------------------------------------------------------- 1 | /* unzip.h -- IO for uncompress .zip files using zlib 2 | Version 1.2.0, September 16th, 2017 3 | part of the MiniZip project 4 | 5 | Copyright (C) 2012-2017 Nathan Moinvaziri 6 | https://github.com/nmoinvaz/minizip 7 | Copyright (C) 2009-2010 Mathias Svensson 8 | Modifications for Zip64 support on both zip and unzip 9 | http://result42.com 10 | Copyright (C) 2007-2008 Even Rouault 11 | Modifications of Unzip for Zip64 12 | Copyright (C) 1998-2010 Gilles Vollant 13 | http://www.winimage.com/zLibDll/minizip.html 14 | 15 | This program is distributed under the terms of the same license as zlib. 16 | See the accompanying LICENSE file for the full text of the license. 17 | */ 18 | 19 | #ifndef _UNZ_H 20 | #define _UNZ_H 21 | 22 | #include "../SSZipCommon.h" 23 | 24 | #define HAVE_AES 25 | 26 | #ifdef __cplusplus 27 | extern "C" { 28 | #endif 29 | 30 | #ifndef _ZLIB_H 31 | #include "zlib.h" 32 | #endif 33 | 34 | #ifndef _ZLIBIOAPI_H 35 | #include "ioapi.h" 36 | #endif 37 | 38 | #ifdef HAVE_BZIP2 39 | #include "bzlib.h" 40 | #endif 41 | 42 | #define Z_BZIP2ED 12 43 | 44 | #if defined(STRICTUNZIP) || defined(STRICTZIPUNZIP) 45 | /* like the STRICT of WIN32, we define a pointer that cannot be converted 46 | from (void*) without cast */ 47 | typedef struct TagunzFile__ { int unused; } unz_file__; 48 | typedef unz_file__ *unzFile; 49 | #else 50 | typedef voidp unzFile; 51 | #endif 52 | 53 | #define UNZ_OK (0) 54 | #define UNZ_END_OF_LIST_OF_FILE (-100) 55 | #define UNZ_ERRNO (Z_ERRNO) 56 | #define UNZ_EOF (0) 57 | #define UNZ_PARAMERROR (-102) 58 | #define UNZ_BADZIPFILE (-103) 59 | #define UNZ_INTERNALERROR (-104) 60 | #define UNZ_CRCERROR (-105) 61 | #define UNZ_BADPASSWORD (-106) 62 | 63 | 64 | /***************************************************************************/ 65 | /* Opening and close a zip file */ 66 | 67 | extern unzFile ZEXPORT unzOpen(const char *path); 68 | extern unzFile ZEXPORT unzOpen64(const void *path); 69 | /* Open a Zip file. 70 | 71 | path should contain the full path (by example, on a Windows XP computer 72 | "c:\\zlib\\zlib113.zip" or on an Unix computer "zlib/zlib113.zip". 73 | return NULL if zipfile cannot be opened or doesn't exist 74 | return unzFile handle if no error 75 | 76 | NOTE: The "64" function take a const void *pointer, because the path is just the value passed to the 77 | open64_file_func callback. Under Windows, if UNICODE is defined, using fill_fopen64_filefunc, the path 78 | is a pointer to a wide unicode string (LPCTSTR is LPCWSTR), so const char *does not describe the reality */ 79 | 80 | extern unzFile ZEXPORT unzOpen2(const char *path, zlib_filefunc_def *pzlib_filefunc_def); 81 | /* Open a Zip file, like unzOpen, but provide a set of file low level API for read/write operations */ 82 | extern unzFile ZEXPORT unzOpen2_64(const void *path, zlib_filefunc64_def *pzlib_filefunc_def); 83 | /* Open a Zip file, like unz64Open, but provide a set of file low level API for read/write 64-bit operations */ 84 | 85 | extern int ZEXPORT unzClose(unzFile file); 86 | /* Close a ZipFile opened with unzOpen. If there is files inside the .Zip opened with unzOpenCurrentFile, 87 | these files MUST be closed with unzipCloseCurrentFile before call unzipClose. 88 | 89 | return UNZ_OK if there is no error */ 90 | 91 | extern int ZEXPORT unzGetGlobalInfo(unzFile file, unz_global_info *pglobal_info); 92 | extern int ZEXPORT unzGetGlobalInfo64(unzFile file, unz_global_info64 *pglobal_info); 93 | /* Write info about the ZipFile in the *pglobal_info structure. 94 | 95 | return UNZ_OK if no error */ 96 | 97 | extern int ZEXPORT unzGetGlobalComment(unzFile file, char *comment, uint16_t comment_size); 98 | /* Get the global comment string of the ZipFile, in the comment buffer. 99 | 100 | uSizeBuf is the size of the szComment buffer. 101 | return the number of byte copied or an error code <0 */ 102 | 103 | extern uint64_t ZEXPORT unzCountEntries(const unzFile file); 104 | 105 | /***************************************************************************/ 106 | /* Reading the content of the current zipfile, you can open it, read data from it, and close it 107 | (you can close it before reading all the file) */ 108 | 109 | extern int ZEXPORT unzOpenCurrentFile(unzFile file); 110 | /* Open for reading data the current file in the zipfile. 111 | 112 | return UNZ_OK if no error */ 113 | 114 | extern int ZEXPORT unzOpenCurrentFilePassword(unzFile file, const char *password); 115 | /* Open for reading data the current file in the zipfile. 116 | password is a crypting password 117 | 118 | return UNZ_OK if no error */ 119 | 120 | extern int ZEXPORT unzOpenCurrentFile2(unzFile file, int *method, int *level, int raw); 121 | /* Same as unzOpenCurrentFile, but open for read raw the file (not uncompress) 122 | if raw==1 *method will receive method of compression, *level will receive level of compression 123 | 124 | NOTE: you can set level parameter as NULL (if you did not want known level, 125 | but you CANNOT set method parameter as NULL */ 126 | 127 | extern int ZEXPORT unzOpenCurrentFile3(unzFile file, int *method, int *level, int raw, const char *password); 128 | /* Same as unzOpenCurrentFile, but takes extra parameter password for encrypted files */ 129 | 130 | extern int ZEXPORT unzReadCurrentFile(unzFile file, voidp buf, uint32_t len); 131 | /* Read bytes from the current file (opened by unzOpenCurrentFile) 132 | buf contain buffer where data must be copied 133 | len the size of buf. 134 | 135 | return the number of byte copied if somes bytes are copied 136 | return 0 if the end of file was reached 137 | return <0 with error code if there is an error (UNZ_ERRNO for IO error, or zLib error for uncompress error) */ 138 | 139 | extern int ZEXPORT unzGetCurrentFileInfo(unzFile file, unz_file_info *pfile_info, char *filename, 140 | uint16_t filename_size, void *extrafield, uint16_t extrafield_size, char *comment, uint16_t comment_size); 141 | extern int ZEXPORT unzGetCurrentFileInfo64(unzFile file, unz_file_info64 *pfile_info, char *filename, 142 | uint16_t filename_size, void *extrafield, uint16_t extrafield_size, char *comment, uint16_t comment_size); 143 | /* Get Info about the current file 144 | 145 | pfile_info if != NULL, the *pfile_info structure will contain somes info about the current file 146 | filename if != NULL, the file name string will be copied in filename 147 | filename_size is the size of the filename buffer 148 | extrafield if != NULL, the extra field information from the central header will be copied in to 149 | extrafield_size is the size of the extraField buffer 150 | comment if != NULL, the comment string of the file will be copied in to 151 | comment_size is the size of the comment buffer */ 152 | 153 | extern int ZEXPORT unzGetLocalExtrafield(unzFile file, voidp buf, uint32_t len); 154 | /* Read extra field from the current file (opened by unzOpenCurrentFile) 155 | This is the local-header version of the extra field (sometimes, there is 156 | more info in the local-header version than in the central-header) 157 | 158 | if buf == NULL, it return the size of the local extra field 159 | if buf != NULL, len is the size of the buffer, the extra header is copied in buf. 160 | 161 | return number of bytes copied in buf, or (if <0) the error code */ 162 | 163 | extern int ZEXPORT unzCloseCurrentFile(unzFile file); 164 | /* Close the file in zip opened with unzOpenCurrentFile 165 | 166 | return UNZ_CRCERROR if all the file was read but the CRC is not good */ 167 | 168 | /***************************************************************************/ 169 | /* Browse the directory of the zipfile */ 170 | 171 | typedef int (*unzFileNameComparer)(unzFile file, const char *filename1, const char *filename2); 172 | typedef int (*unzIteratorFunction)(unzFile file); 173 | typedef int (*unzIteratorFunction2)(unzFile file, unz_file_info64 *pfile_info, char *filename, 174 | uint16_t filename_size, void *extrafield, uint16_t extrafield_size, char *comment, uint16_t comment_size); 175 | 176 | extern int ZEXPORT unzGoToFirstFile(unzFile file); 177 | /* Set the current file of the zipfile to the first file. 178 | 179 | return UNZ_OK if no error */ 180 | 181 | extern int ZEXPORT unzGoToFirstFile2(unzFile file, unz_file_info64 *pfile_info, char *filename, 182 | uint16_t filename_size, void *extrafield, uint16_t extrafield_size, char *comment, uint16_t comment_size); 183 | /* Set the current file of the zipfile to the first file and retrieves the current info on success. 184 | Not as seek intensive as unzGoToFirstFile + unzGetCurrentFileInfo. 185 | 186 | return UNZ_OK if no error */ 187 | 188 | extern int ZEXPORT unzGoToNextFile(unzFile file); 189 | /* Set the current file of the zipfile to the next file. 190 | 191 | return UNZ_OK if no error 192 | return UNZ_END_OF_LIST_OF_FILE if the actual file was the latest */ 193 | 194 | extern int ZEXPORT unzGoToNextFile2(unzFile file, unz_file_info64 *pfile_info, char *filename, 195 | uint16_t filename_size, void *extrafield, uint16_t extrafield_size, char *comment, uint16_t comment_size); 196 | /* Set the current file of the zipfile to the next file and retrieves the current 197 | info on success. Does less seeking around than unzGotoNextFile + unzGetCurrentFileInfo. 198 | 199 | return UNZ_OK if no error 200 | return UNZ_END_OF_LIST_OF_FILE if the actual file was the latest */ 201 | 202 | extern int ZEXPORT unzLocateFile(unzFile file, const char *filename, unzFileNameComparer filename_compare_func); 203 | /* Try locate the file szFileName in the zipfile. For custom filename comparison pass in comparison function. 204 | 205 | return UNZ_OK if the file is found (it becomes the current file) 206 | return UNZ_END_OF_LIST_OF_FILE if the file is not found */ 207 | 208 | /***************************************************************************/ 209 | /* Raw access to zip file */ 210 | 211 | typedef struct unz_file_pos_s 212 | { 213 | uint32_t pos_in_zip_directory; /* offset in zip file directory */ 214 | uint32_t num_of_file; /* # of file */ 215 | } unz_file_pos; 216 | 217 | extern int ZEXPORT unzGetFilePos(unzFile file, unz_file_pos *file_pos); 218 | extern int ZEXPORT unzGoToFilePos(unzFile file, unz_file_pos *file_pos); 219 | 220 | typedef struct unz64_file_pos_s 221 | { 222 | uint64_t pos_in_zip_directory; /* offset in zip file directory */ 223 | uint64_t num_of_file; /* # of file */ 224 | } unz64_file_pos; 225 | 226 | extern int ZEXPORT unzGetFilePos64(unzFile file, unz64_file_pos *file_pos); 227 | extern int ZEXPORT unzGoToFilePos64(unzFile file, const unz64_file_pos *file_pos); 228 | 229 | extern int32_t ZEXPORT unzGetOffset(unzFile file); 230 | extern int64_t ZEXPORT unzGetOffset64(unzFile file); 231 | /* Get the current file offset */ 232 | 233 | extern int ZEXPORT unzSetOffset(unzFile file, uint32_t pos); 234 | extern int ZEXPORT unzSetOffset64(unzFile file, uint64_t pos); 235 | /* Set the current file offset */ 236 | 237 | extern int32_t ZEXPORT unzTell(unzFile file); 238 | extern int64_t ZEXPORT unzTell64(unzFile file); 239 | /* return current position in uncompressed data */ 240 | 241 | extern int ZEXPORT unzSeek(unzFile file, uint32_t offset, int origin); 242 | extern int ZEXPORT unzSeek64(unzFile file, uint64_t offset, int origin); 243 | /* Seek within the uncompressed data if compression method is storage */ 244 | 245 | extern int ZEXPORT unzEndOfFile(unzFile file); 246 | /* return 1 if the end of file was reached, 0 elsewhere */ 247 | 248 | /***************************************************************************/ 249 | 250 | #ifdef __cplusplus 251 | } 252 | #endif 253 | 254 | #endif /* _UNZ_H */ 255 | -------------------------------------------------------------------------------- /SSZipArchive/minizip/ioapi.c: -------------------------------------------------------------------------------- 1 | /* ioapi.c -- IO base function header for compress/uncompress .zip 2 | part of the MiniZip project 3 | 4 | Copyright (C) 2012-2017 Nathan Moinvaziri 5 | https://github.com/nmoinvaz/minizip 6 | Modifications for Zip64 support 7 | Copyright (C) 2009-2010 Mathias Svensson 8 | http://result42.com 9 | Copyright (C) 1998-2010 Gilles Vollant 10 | http://www.winimage.com/zLibDll/minizip.html 11 | 12 | This program is distributed under the terms of the same license as zlib. 13 | See the accompanying LICENSE file for the full text of the license. 14 | */ 15 | 16 | #include 17 | #include 18 | 19 | #if defined unix || defined __APPLE__ 20 | #include 21 | #include 22 | #endif 23 | 24 | #include "ioapi.h" 25 | 26 | #if defined(_WIN32) 27 | # define snprintf _snprintf 28 | #endif 29 | 30 | voidpf call_zopen64(const zlib_filefunc64_32_def *pfilefunc, const void *filename, int mode) 31 | { 32 | if (pfilefunc->zfile_func64.zopen64_file != NULL) 33 | return (*(pfilefunc->zfile_func64.zopen64_file)) (pfilefunc->zfile_func64.opaque, filename, mode); 34 | return (*(pfilefunc->zopen32_file))(pfilefunc->zfile_func64.opaque, (const char*)filename, mode); 35 | } 36 | 37 | voidpf call_zopendisk64(const zlib_filefunc64_32_def *pfilefunc, voidpf filestream, uint32_t number_disk, int mode) 38 | { 39 | if (pfilefunc->zfile_func64.zopendisk64_file != NULL) 40 | return (*(pfilefunc->zfile_func64.zopendisk64_file)) (pfilefunc->zfile_func64.opaque, filestream, number_disk, mode); 41 | return (*(pfilefunc->zopendisk32_file))(pfilefunc->zfile_func64.opaque, filestream, number_disk, mode); 42 | } 43 | 44 | long call_zseek64(const zlib_filefunc64_32_def *pfilefunc, voidpf filestream, uint64_t offset, int origin) 45 | { 46 | uint32_t offset_truncated = 0; 47 | if (pfilefunc->zfile_func64.zseek64_file != NULL) 48 | return (*(pfilefunc->zfile_func64.zseek64_file)) (pfilefunc->zfile_func64.opaque,filestream,offset,origin); 49 | offset_truncated = (uint32_t)offset; 50 | if (offset_truncated != offset) 51 | return -1; 52 | return (*(pfilefunc->zseek32_file))(pfilefunc->zfile_func64.opaque,filestream, offset_truncated, origin); 53 | } 54 | 55 | uint64_t call_ztell64(const zlib_filefunc64_32_def *pfilefunc, voidpf filestream) 56 | { 57 | uint64_t position; 58 | if (pfilefunc->zfile_func64.zseek64_file != NULL) 59 | return (*(pfilefunc->zfile_func64.ztell64_file)) (pfilefunc->zfile_func64.opaque, filestream); 60 | position = (*(pfilefunc->ztell32_file))(pfilefunc->zfile_func64.opaque, filestream); 61 | if ((position) == UINT32_MAX) 62 | return (uint64_t)-1; 63 | return position; 64 | } 65 | 66 | void fill_zlib_filefunc64_32_def_from_filefunc32(zlib_filefunc64_32_def *p_filefunc64_32, const zlib_filefunc_def *p_filefunc32) 67 | { 68 | p_filefunc64_32->zfile_func64.zopen64_file = NULL; 69 | p_filefunc64_32->zfile_func64.zopendisk64_file = NULL; 70 | p_filefunc64_32->zopen32_file = p_filefunc32->zopen_file; 71 | p_filefunc64_32->zopendisk32_file = p_filefunc32->zopendisk_file; 72 | p_filefunc64_32->zfile_func64.zerror_file = p_filefunc32->zerror_file; 73 | p_filefunc64_32->zfile_func64.zread_file = p_filefunc32->zread_file; 74 | p_filefunc64_32->zfile_func64.zwrite_file = p_filefunc32->zwrite_file; 75 | p_filefunc64_32->zfile_func64.ztell64_file = NULL; 76 | p_filefunc64_32->zfile_func64.zseek64_file = NULL; 77 | p_filefunc64_32->zfile_func64.zclose_file = p_filefunc32->zclose_file; 78 | p_filefunc64_32->zfile_func64.zerror_file = p_filefunc32->zerror_file; 79 | p_filefunc64_32->zfile_func64.opaque = p_filefunc32->opaque; 80 | p_filefunc64_32->zseek32_file = p_filefunc32->zseek_file; 81 | p_filefunc64_32->ztell32_file = p_filefunc32->ztell_file; 82 | } 83 | 84 | static voidpf ZCALLBACK fopen_file_func(ZIP_UNUSED voidpf opaque, const char *filename, int mode); 85 | static uint32_t ZCALLBACK fread_file_func(voidpf opaque, voidpf stream, void* buf, uint32_t size); 86 | static uint32_t ZCALLBACK fwrite_file_func(voidpf opaque, voidpf stream, const void *buf, uint32_t size); 87 | static uint64_t ZCALLBACK ftell64_file_func(voidpf opaque, voidpf stream); 88 | static long ZCALLBACK fseek64_file_func(voidpf opaque, voidpf stream, uint64_t offset, int origin); 89 | static int ZCALLBACK fclose_file_func(voidpf opaque, voidpf stream); 90 | static int ZCALLBACK ferror_file_func(voidpf opaque, voidpf stream); 91 | 92 | typedef struct 93 | { 94 | FILE *file; 95 | int filenameLength; 96 | void *filename; 97 | } FILE_IOPOSIX; 98 | 99 | static voidpf file_build_ioposix(FILE *file, const char *filename) 100 | { 101 | FILE_IOPOSIX *ioposix = NULL; 102 | if (file == NULL) 103 | return NULL; 104 | ioposix = (FILE_IOPOSIX*)malloc(sizeof(FILE_IOPOSIX)); 105 | ioposix->file = file; 106 | ioposix->filenameLength = (int)strlen(filename) + 1; 107 | ioposix->filename = (char*)malloc(ioposix->filenameLength * sizeof(char)); 108 | strncpy((char*)ioposix->filename, filename, ioposix->filenameLength); 109 | return (voidpf)ioposix; 110 | } 111 | 112 | static voidpf ZCALLBACK fopen_file_func(ZIP_UNUSED voidpf opaque, const char *filename, int mode) 113 | { 114 | FILE* file = NULL; 115 | const char *mode_fopen = NULL; 116 | if ((mode & ZLIB_FILEFUNC_MODE_READWRITEFILTER) == ZLIB_FILEFUNC_MODE_READ) 117 | mode_fopen = "rb"; 118 | else if (mode & ZLIB_FILEFUNC_MODE_EXISTING) 119 | mode_fopen = "r+b"; 120 | else if (mode & ZLIB_FILEFUNC_MODE_CREATE) 121 | mode_fopen = "wb"; 122 | 123 | if ((filename != NULL) && (mode_fopen != NULL)) 124 | { 125 | file = fopen(filename, mode_fopen); 126 | return file_build_ioposix(file, filename); 127 | } 128 | return file; 129 | } 130 | 131 | static voidpf ZCALLBACK fopen64_file_func(ZIP_UNUSED voidpf opaque, const void *filename, int mode) 132 | { 133 | FILE* file = NULL; 134 | const char *mode_fopen = NULL; 135 | if ((mode & ZLIB_FILEFUNC_MODE_READWRITEFILTER) == ZLIB_FILEFUNC_MODE_READ) 136 | mode_fopen = "rb"; 137 | else if (mode & ZLIB_FILEFUNC_MODE_EXISTING) 138 | mode_fopen = "r+b"; 139 | else if (mode & ZLIB_FILEFUNC_MODE_CREATE) 140 | mode_fopen = "wb"; 141 | 142 | if ((filename != NULL) && (mode_fopen != NULL)) 143 | { 144 | file = fopen64((const char*)filename, mode_fopen); 145 | return file_build_ioposix(file, (const char*)filename); 146 | } 147 | return file; 148 | } 149 | 150 | static voidpf ZCALLBACK fopendisk64_file_func(voidpf opaque, voidpf stream, uint32_t number_disk, int mode) 151 | { 152 | FILE_IOPOSIX *ioposix = NULL; 153 | char *diskFilename = NULL; 154 | voidpf ret = NULL; 155 | int i = 0; 156 | 157 | if (stream == NULL) 158 | return NULL; 159 | ioposix = (FILE_IOPOSIX*)stream; 160 | diskFilename = (char*)malloc(ioposix->filenameLength * sizeof(char)); 161 | strncpy(diskFilename, (const char*)ioposix->filename, ioposix->filenameLength); 162 | for (i = ioposix->filenameLength - 1; i >= 0; i -= 1) 163 | { 164 | if (diskFilename[i] != '.') 165 | continue; 166 | snprintf(&diskFilename[i], ioposix->filenameLength - i, ".z%02u", number_disk + 1); 167 | break; 168 | } 169 | if (i >= 0) 170 | ret = fopen64_file_func(opaque, diskFilename, mode); 171 | free(diskFilename); 172 | return ret; 173 | } 174 | 175 | static voidpf ZCALLBACK fopendisk_file_func(voidpf opaque, voidpf stream, uint32_t number_disk, int mode) 176 | { 177 | FILE_IOPOSIX *ioposix = NULL; 178 | char *diskFilename = NULL; 179 | voidpf ret = NULL; 180 | int i = 0; 181 | 182 | if (stream == NULL) 183 | return NULL; 184 | ioposix = (FILE_IOPOSIX*)stream; 185 | diskFilename = (char*)malloc(ioposix->filenameLength * sizeof(char)); 186 | strncpy(diskFilename, (const char*)ioposix->filename, ioposix->filenameLength); 187 | for (i = ioposix->filenameLength - 1; i >= 0; i -= 1) 188 | { 189 | if (diskFilename[i] != '.') 190 | continue; 191 | snprintf(&diskFilename[i], ioposix->filenameLength - i, ".z%02u", number_disk + 1); 192 | break; 193 | } 194 | if (i >= 0) 195 | ret = fopen_file_func(opaque, diskFilename, mode); 196 | free(diskFilename); 197 | return ret; 198 | } 199 | 200 | static uint32_t ZCALLBACK fread_file_func(ZIP_UNUSED voidpf opaque, voidpf stream, void* buf, uint32_t size) 201 | { 202 | FILE_IOPOSIX *ioposix = NULL; 203 | uint32_t read = (uint32_t)-1; 204 | if (stream == NULL) 205 | return read; 206 | ioposix = (FILE_IOPOSIX*)stream; 207 | read = (uint32_t)fread(buf, 1, (size_t)size, ioposix->file); 208 | return read; 209 | } 210 | 211 | static uint32_t ZCALLBACK fwrite_file_func(ZIP_UNUSED voidpf opaque, voidpf stream, const void *buf, uint32_t size) 212 | { 213 | FILE_IOPOSIX *ioposix = NULL; 214 | uint32_t written = (uint32_t)-1; 215 | if (stream == NULL) 216 | return written; 217 | ioposix = (FILE_IOPOSIX*)stream; 218 | written = (uint32_t)fwrite(buf, 1, (size_t)size, ioposix->file); 219 | return written; 220 | } 221 | 222 | static long ZCALLBACK ftell_file_func(ZIP_UNUSED voidpf opaque, voidpf stream) 223 | { 224 | FILE_IOPOSIX *ioposix = NULL; 225 | long ret = -1; 226 | if (stream == NULL) 227 | return ret; 228 | ioposix = (FILE_IOPOSIX*)stream; 229 | ret = ftell(ioposix->file); 230 | return ret; 231 | } 232 | 233 | static uint64_t ZCALLBACK ftell64_file_func(ZIP_UNUSED voidpf opaque, voidpf stream) 234 | { 235 | FILE_IOPOSIX *ioposix = NULL; 236 | uint64_t ret = (uint64_t)-1; 237 | if (stream == NULL) 238 | return ret; 239 | ioposix = (FILE_IOPOSIX*)stream; 240 | ret = ftello64(ioposix->file); 241 | return ret; 242 | } 243 | 244 | static long ZCALLBACK fseek_file_func(ZIP_UNUSED voidpf opaque, voidpf stream, uint32_t offset, int origin) 245 | { 246 | FILE_IOPOSIX *ioposix = NULL; 247 | int fseek_origin = 0; 248 | long ret = 0; 249 | 250 | if (stream == NULL) 251 | return -1; 252 | ioposix = (FILE_IOPOSIX*)stream; 253 | 254 | switch (origin) 255 | { 256 | case ZLIB_FILEFUNC_SEEK_CUR: 257 | fseek_origin = SEEK_CUR; 258 | break; 259 | case ZLIB_FILEFUNC_SEEK_END: 260 | fseek_origin = SEEK_END; 261 | break; 262 | case ZLIB_FILEFUNC_SEEK_SET: 263 | fseek_origin = SEEK_SET; 264 | break; 265 | default: 266 | return -1; 267 | } 268 | if (fseek(ioposix->file, offset, fseek_origin) != 0) 269 | ret = -1; 270 | return ret; 271 | } 272 | 273 | static long ZCALLBACK fseek64_file_func(ZIP_UNUSED voidpf opaque, voidpf stream, uint64_t offset, int origin) 274 | { 275 | FILE_IOPOSIX *ioposix = NULL; 276 | int fseek_origin = 0; 277 | long ret = 0; 278 | 279 | if (stream == NULL) 280 | return -1; 281 | ioposix = (FILE_IOPOSIX*)stream; 282 | 283 | switch (origin) 284 | { 285 | case ZLIB_FILEFUNC_SEEK_CUR: 286 | fseek_origin = SEEK_CUR; 287 | break; 288 | case ZLIB_FILEFUNC_SEEK_END: 289 | fseek_origin = SEEK_END; 290 | break; 291 | case ZLIB_FILEFUNC_SEEK_SET: 292 | fseek_origin = SEEK_SET; 293 | break; 294 | default: 295 | return -1; 296 | } 297 | 298 | if (fseeko64(ioposix->file, offset, fseek_origin) != 0) 299 | ret = -1; 300 | 301 | return ret; 302 | } 303 | 304 | static int ZCALLBACK fclose_file_func(ZIP_UNUSED voidpf opaque, voidpf stream) 305 | { 306 | FILE_IOPOSIX *ioposix = NULL; 307 | int ret = -1; 308 | if (stream == NULL) 309 | return ret; 310 | ioposix = (FILE_IOPOSIX*)stream; 311 | if (ioposix->filename != NULL) 312 | free(ioposix->filename); 313 | ret = fclose(ioposix->file); 314 | free(ioposix); 315 | return ret; 316 | } 317 | 318 | static int ZCALLBACK ferror_file_func(ZIP_UNUSED voidpf opaque, voidpf stream) 319 | { 320 | FILE_IOPOSIX *ioposix = NULL; 321 | int ret = -1; 322 | if (stream == NULL) 323 | return ret; 324 | ioposix = (FILE_IOPOSIX*)stream; 325 | ret = ferror(ioposix->file); 326 | return ret; 327 | } 328 | 329 | void fill_fopen_filefunc(zlib_filefunc_def *pzlib_filefunc_def) 330 | { 331 | pzlib_filefunc_def->zopen_file = fopen_file_func; 332 | pzlib_filefunc_def->zopendisk_file = fopendisk_file_func; 333 | pzlib_filefunc_def->zread_file = fread_file_func; 334 | pzlib_filefunc_def->zwrite_file = fwrite_file_func; 335 | pzlib_filefunc_def->ztell_file = ftell_file_func; 336 | pzlib_filefunc_def->zseek_file = fseek_file_func; 337 | pzlib_filefunc_def->zclose_file = fclose_file_func; 338 | pzlib_filefunc_def->zerror_file = ferror_file_func; 339 | pzlib_filefunc_def->opaque = NULL; 340 | } 341 | 342 | void fill_fopen64_filefunc(zlib_filefunc64_def *pzlib_filefunc_def) 343 | { 344 | pzlib_filefunc_def->zopen64_file = fopen64_file_func; 345 | pzlib_filefunc_def->zopendisk64_file = fopendisk64_file_func; 346 | pzlib_filefunc_def->zread_file = fread_file_func; 347 | pzlib_filefunc_def->zwrite_file = fwrite_file_func; 348 | pzlib_filefunc_def->ztell64_file = ftell64_file_func; 349 | pzlib_filefunc_def->zseek64_file = fseek64_file_func; 350 | pzlib_filefunc_def->zclose_file = fclose_file_func; 351 | pzlib_filefunc_def->zerror_file = ferror_file_func; 352 | pzlib_filefunc_def->opaque = NULL; 353 | } 354 | -------------------------------------------------------------------------------- /SSZipArchive/minizip/aes/aestab.c: -------------------------------------------------------------------------------- 1 | /* 2 | --------------------------------------------------------------------------- 3 | Copyright (c) 1998-2013, Brian Gladman, Worcester, UK. All rights reserved. 4 | 5 | The redistribution and use of this software (with or without changes) 6 | is allowed without the payment of fees or royalties provided that: 7 | 8 | source code distributions include the above copyright notice, this 9 | list of conditions and the following disclaimer; 10 | 11 | binary distributions include the above copyright notice, this list 12 | of conditions and the following disclaimer in their documentation. 13 | 14 | This software is provided 'as is' with no explicit or implied warranties 15 | in respect of its operation, including, but not limited to, correctness 16 | and fitness for purpose. 17 | --------------------------------------------------------------------------- 18 | Issue Date: 20/12/2007 19 | */ 20 | 21 | #define DO_TABLES 22 | 23 | #include "aes.h" 24 | #include "aesopt.h" 25 | 26 | #if defined(STATIC_TABLES) 27 | 28 | #define sb_data(w) {\ 29 | w(0x63), w(0x7c), w(0x77), w(0x7b), w(0xf2), w(0x6b), w(0x6f), w(0xc5),\ 30 | w(0x30), w(0x01), w(0x67), w(0x2b), w(0xfe), w(0xd7), w(0xab), w(0x76),\ 31 | w(0xca), w(0x82), w(0xc9), w(0x7d), w(0xfa), w(0x59), w(0x47), w(0xf0),\ 32 | w(0xad), w(0xd4), w(0xa2), w(0xaf), w(0x9c), w(0xa4), w(0x72), w(0xc0),\ 33 | w(0xb7), w(0xfd), w(0x93), w(0x26), w(0x36), w(0x3f), w(0xf7), w(0xcc),\ 34 | w(0x34), w(0xa5), w(0xe5), w(0xf1), w(0x71), w(0xd8), w(0x31), w(0x15),\ 35 | w(0x04), w(0xc7), w(0x23), w(0xc3), w(0x18), w(0x96), w(0x05), w(0x9a),\ 36 | w(0x07), w(0x12), w(0x80), w(0xe2), w(0xeb), w(0x27), w(0xb2), w(0x75),\ 37 | w(0x09), w(0x83), w(0x2c), w(0x1a), w(0x1b), w(0x6e), w(0x5a), w(0xa0),\ 38 | w(0x52), w(0x3b), w(0xd6), w(0xb3), w(0x29), w(0xe3), w(0x2f), w(0x84),\ 39 | w(0x53), w(0xd1), w(0x00), w(0xed), w(0x20), w(0xfc), w(0xb1), w(0x5b),\ 40 | w(0x6a), w(0xcb), w(0xbe), w(0x39), w(0x4a), w(0x4c), w(0x58), w(0xcf),\ 41 | w(0xd0), w(0xef), w(0xaa), w(0xfb), w(0x43), w(0x4d), w(0x33), w(0x85),\ 42 | w(0x45), w(0xf9), w(0x02), w(0x7f), w(0x50), w(0x3c), w(0x9f), w(0xa8),\ 43 | w(0x51), w(0xa3), w(0x40), w(0x8f), w(0x92), w(0x9d), w(0x38), w(0xf5),\ 44 | w(0xbc), w(0xb6), w(0xda), w(0x21), w(0x10), w(0xff), w(0xf3), w(0xd2),\ 45 | w(0xcd), w(0x0c), w(0x13), w(0xec), w(0x5f), w(0x97), w(0x44), w(0x17),\ 46 | w(0xc4), w(0xa7), w(0x7e), w(0x3d), w(0x64), w(0x5d), w(0x19), w(0x73),\ 47 | w(0x60), w(0x81), w(0x4f), w(0xdc), w(0x22), w(0x2a), w(0x90), w(0x88),\ 48 | w(0x46), w(0xee), w(0xb8), w(0x14), w(0xde), w(0x5e), w(0x0b), w(0xdb),\ 49 | w(0xe0), w(0x32), w(0x3a), w(0x0a), w(0x49), w(0x06), w(0x24), w(0x5c),\ 50 | w(0xc2), w(0xd3), w(0xac), w(0x62), w(0x91), w(0x95), w(0xe4), w(0x79),\ 51 | w(0xe7), w(0xc8), w(0x37), w(0x6d), w(0x8d), w(0xd5), w(0x4e), w(0xa9),\ 52 | w(0x6c), w(0x56), w(0xf4), w(0xea), w(0x65), w(0x7a), w(0xae), w(0x08),\ 53 | w(0xba), w(0x78), w(0x25), w(0x2e), w(0x1c), w(0xa6), w(0xb4), w(0xc6),\ 54 | w(0xe8), w(0xdd), w(0x74), w(0x1f), w(0x4b), w(0xbd), w(0x8b), w(0x8a),\ 55 | w(0x70), w(0x3e), w(0xb5), w(0x66), w(0x48), w(0x03), w(0xf6), w(0x0e),\ 56 | w(0x61), w(0x35), w(0x57), w(0xb9), w(0x86), w(0xc1), w(0x1d), w(0x9e),\ 57 | w(0xe1), w(0xf8), w(0x98), w(0x11), w(0x69), w(0xd9), w(0x8e), w(0x94),\ 58 | w(0x9b), w(0x1e), w(0x87), w(0xe9), w(0xce), w(0x55), w(0x28), w(0xdf),\ 59 | w(0x8c), w(0xa1), w(0x89), w(0x0d), w(0xbf), w(0xe6), w(0x42), w(0x68),\ 60 | w(0x41), w(0x99), w(0x2d), w(0x0f), w(0xb0), w(0x54), w(0xbb), w(0x16) } 61 | 62 | #define isb_data(w) {\ 63 | w(0x52), w(0x09), w(0x6a), w(0xd5), w(0x30), w(0x36), w(0xa5), w(0x38),\ 64 | w(0xbf), w(0x40), w(0xa3), w(0x9e), w(0x81), w(0xf3), w(0xd7), w(0xfb),\ 65 | w(0x7c), w(0xe3), w(0x39), w(0x82), w(0x9b), w(0x2f), w(0xff), w(0x87),\ 66 | w(0x34), w(0x8e), w(0x43), w(0x44), w(0xc4), w(0xde), w(0xe9), w(0xcb),\ 67 | w(0x54), w(0x7b), w(0x94), w(0x32), w(0xa6), w(0xc2), w(0x23), w(0x3d),\ 68 | w(0xee), w(0x4c), w(0x95), w(0x0b), w(0x42), w(0xfa), w(0xc3), w(0x4e),\ 69 | w(0x08), w(0x2e), w(0xa1), w(0x66), w(0x28), w(0xd9), w(0x24), w(0xb2),\ 70 | w(0x76), w(0x5b), w(0xa2), w(0x49), w(0x6d), w(0x8b), w(0xd1), w(0x25),\ 71 | w(0x72), w(0xf8), w(0xf6), w(0x64), w(0x86), w(0x68), w(0x98), w(0x16),\ 72 | w(0xd4), w(0xa4), w(0x5c), w(0xcc), w(0x5d), w(0x65), w(0xb6), w(0x92),\ 73 | w(0x6c), w(0x70), w(0x48), w(0x50), w(0xfd), w(0xed), w(0xb9), w(0xda),\ 74 | w(0x5e), w(0x15), w(0x46), w(0x57), w(0xa7), w(0x8d), w(0x9d), w(0x84),\ 75 | w(0x90), w(0xd8), w(0xab), w(0x00), w(0x8c), w(0xbc), w(0xd3), w(0x0a),\ 76 | w(0xf7), w(0xe4), w(0x58), w(0x05), w(0xb8), w(0xb3), w(0x45), w(0x06),\ 77 | w(0xd0), w(0x2c), w(0x1e), w(0x8f), w(0xca), w(0x3f), w(0x0f), w(0x02),\ 78 | w(0xc1), w(0xaf), w(0xbd), w(0x03), w(0x01), w(0x13), w(0x8a), w(0x6b),\ 79 | w(0x3a), w(0x91), w(0x11), w(0x41), w(0x4f), w(0x67), w(0xdc), w(0xea),\ 80 | w(0x97), w(0xf2), w(0xcf), w(0xce), w(0xf0), w(0xb4), w(0xe6), w(0x73),\ 81 | w(0x96), w(0xac), w(0x74), w(0x22), w(0xe7), w(0xad), w(0x35), w(0x85),\ 82 | w(0xe2), w(0xf9), w(0x37), w(0xe8), w(0x1c), w(0x75), w(0xdf), w(0x6e),\ 83 | w(0x47), w(0xf1), w(0x1a), w(0x71), w(0x1d), w(0x29), w(0xc5), w(0x89),\ 84 | w(0x6f), w(0xb7), w(0x62), w(0x0e), w(0xaa), w(0x18), w(0xbe), w(0x1b),\ 85 | w(0xfc), w(0x56), w(0x3e), w(0x4b), w(0xc6), w(0xd2), w(0x79), w(0x20),\ 86 | w(0x9a), w(0xdb), w(0xc0), w(0xfe), w(0x78), w(0xcd), w(0x5a), w(0xf4),\ 87 | w(0x1f), w(0xdd), w(0xa8), w(0x33), w(0x88), w(0x07), w(0xc7), w(0x31),\ 88 | w(0xb1), w(0x12), w(0x10), w(0x59), w(0x27), w(0x80), w(0xec), w(0x5f),\ 89 | w(0x60), w(0x51), w(0x7f), w(0xa9), w(0x19), w(0xb5), w(0x4a), w(0x0d),\ 90 | w(0x2d), w(0xe5), w(0x7a), w(0x9f), w(0x93), w(0xc9), w(0x9c), w(0xef),\ 91 | w(0xa0), w(0xe0), w(0x3b), w(0x4d), w(0xae), w(0x2a), w(0xf5), w(0xb0),\ 92 | w(0xc8), w(0xeb), w(0xbb), w(0x3c), w(0x83), w(0x53), w(0x99), w(0x61),\ 93 | w(0x17), w(0x2b), w(0x04), w(0x7e), w(0xba), w(0x77), w(0xd6), w(0x26),\ 94 | w(0xe1), w(0x69), w(0x14), w(0x63), w(0x55), w(0x21), w(0x0c), w(0x7d) } 95 | 96 | #define mm_data(w) {\ 97 | w(0x00), w(0x01), w(0x02), w(0x03), w(0x04), w(0x05), w(0x06), w(0x07),\ 98 | w(0x08), w(0x09), w(0x0a), w(0x0b), w(0x0c), w(0x0d), w(0x0e), w(0x0f),\ 99 | w(0x10), w(0x11), w(0x12), w(0x13), w(0x14), w(0x15), w(0x16), w(0x17),\ 100 | w(0x18), w(0x19), w(0x1a), w(0x1b), w(0x1c), w(0x1d), w(0x1e), w(0x1f),\ 101 | w(0x20), w(0x21), w(0x22), w(0x23), w(0x24), w(0x25), w(0x26), w(0x27),\ 102 | w(0x28), w(0x29), w(0x2a), w(0x2b), w(0x2c), w(0x2d), w(0x2e), w(0x2f),\ 103 | w(0x30), w(0x31), w(0x32), w(0x33), w(0x34), w(0x35), w(0x36), w(0x37),\ 104 | w(0x38), w(0x39), w(0x3a), w(0x3b), w(0x3c), w(0x3d), w(0x3e), w(0x3f),\ 105 | w(0x40), w(0x41), w(0x42), w(0x43), w(0x44), w(0x45), w(0x46), w(0x47),\ 106 | w(0x48), w(0x49), w(0x4a), w(0x4b), w(0x4c), w(0x4d), w(0x4e), w(0x4f),\ 107 | w(0x50), w(0x51), w(0x52), w(0x53), w(0x54), w(0x55), w(0x56), w(0x57),\ 108 | w(0x58), w(0x59), w(0x5a), w(0x5b), w(0x5c), w(0x5d), w(0x5e), w(0x5f),\ 109 | w(0x60), w(0x61), w(0x62), w(0x63), w(0x64), w(0x65), w(0x66), w(0x67),\ 110 | w(0x68), w(0x69), w(0x6a), w(0x6b), w(0x6c), w(0x6d), w(0x6e), w(0x6f),\ 111 | w(0x70), w(0x71), w(0x72), w(0x73), w(0x74), w(0x75), w(0x76), w(0x77),\ 112 | w(0x78), w(0x79), w(0x7a), w(0x7b), w(0x7c), w(0x7d), w(0x7e), w(0x7f),\ 113 | w(0x80), w(0x81), w(0x82), w(0x83), w(0x84), w(0x85), w(0x86), w(0x87),\ 114 | w(0x88), w(0x89), w(0x8a), w(0x8b), w(0x8c), w(0x8d), w(0x8e), w(0x8f),\ 115 | w(0x90), w(0x91), w(0x92), w(0x93), w(0x94), w(0x95), w(0x96), w(0x97),\ 116 | w(0x98), w(0x99), w(0x9a), w(0x9b), w(0x9c), w(0x9d), w(0x9e), w(0x9f),\ 117 | w(0xa0), w(0xa1), w(0xa2), w(0xa3), w(0xa4), w(0xa5), w(0xa6), w(0xa7),\ 118 | w(0xa8), w(0xa9), w(0xaa), w(0xab), w(0xac), w(0xad), w(0xae), w(0xaf),\ 119 | w(0xb0), w(0xb1), w(0xb2), w(0xb3), w(0xb4), w(0xb5), w(0xb6), w(0xb7),\ 120 | w(0xb8), w(0xb9), w(0xba), w(0xbb), w(0xbc), w(0xbd), w(0xbe), w(0xbf),\ 121 | w(0xc0), w(0xc1), w(0xc2), w(0xc3), w(0xc4), w(0xc5), w(0xc6), w(0xc7),\ 122 | w(0xc8), w(0xc9), w(0xca), w(0xcb), w(0xcc), w(0xcd), w(0xce), w(0xcf),\ 123 | w(0xd0), w(0xd1), w(0xd2), w(0xd3), w(0xd4), w(0xd5), w(0xd6), w(0xd7),\ 124 | w(0xd8), w(0xd9), w(0xda), w(0xdb), w(0xdc), w(0xdd), w(0xde), w(0xdf),\ 125 | w(0xe0), w(0xe1), w(0xe2), w(0xe3), w(0xe4), w(0xe5), w(0xe6), w(0xe7),\ 126 | w(0xe8), w(0xe9), w(0xea), w(0xeb), w(0xec), w(0xed), w(0xee), w(0xef),\ 127 | w(0xf0), w(0xf1), w(0xf2), w(0xf3), w(0xf4), w(0xf5), w(0xf6), w(0xf7),\ 128 | w(0xf8), w(0xf9), w(0xfa), w(0xfb), w(0xfc), w(0xfd), w(0xfe), w(0xff) } 129 | 130 | #define rc_data(w) {\ 131 | w(0x01), w(0x02), w(0x04), w(0x08), w(0x10),w(0x20), w(0x40), w(0x80),\ 132 | w(0x1b), w(0x36) } 133 | 134 | #define h0(x) (x) 135 | 136 | #define w0(p) bytes2word(p, 0, 0, 0) 137 | #define w1(p) bytes2word(0, p, 0, 0) 138 | #define w2(p) bytes2word(0, 0, p, 0) 139 | #define w3(p) bytes2word(0, 0, 0, p) 140 | 141 | #define u0(p) bytes2word(f2(p), p, p, f3(p)) 142 | #define u1(p) bytes2word(f3(p), f2(p), p, p) 143 | #define u2(p) bytes2word(p, f3(p), f2(p), p) 144 | #define u3(p) bytes2word(p, p, f3(p), f2(p)) 145 | 146 | #define v0(p) bytes2word(fe(p), f9(p), fd(p), fb(p)) 147 | #define v1(p) bytes2word(fb(p), fe(p), f9(p), fd(p)) 148 | #define v2(p) bytes2word(fd(p), fb(p), fe(p), f9(p)) 149 | #define v3(p) bytes2word(f9(p), fd(p), fb(p), fe(p)) 150 | 151 | #endif 152 | 153 | #if defined(STATIC_TABLES) || !defined(FF_TABLES) 154 | 155 | #define f2(x) ((x<<1) ^ (((x>>7) & 1) * WPOLY)) 156 | #define f4(x) ((x<<2) ^ (((x>>6) & 1) * WPOLY) ^ (((x>>6) & 2) * WPOLY)) 157 | #define f8(x) ((x<<3) ^ (((x>>5) & 1) * WPOLY) ^ (((x>>5) & 2) * WPOLY) \ 158 | ^ (((x>>5) & 4) * WPOLY)) 159 | #define f3(x) (f2(x) ^ x) 160 | #define f9(x) (f8(x) ^ x) 161 | #define fb(x) (f8(x) ^ f2(x) ^ x) 162 | #define fd(x) (f8(x) ^ f4(x) ^ x) 163 | #define fe(x) (f8(x) ^ f4(x) ^ f2(x)) 164 | 165 | #else 166 | 167 | #define f2(x) ((x) ? pow[log[x] + 0x19] : 0) 168 | #define f3(x) ((x) ? pow[log[x] + 0x01] : 0) 169 | #define f9(x) ((x) ? pow[log[x] + 0xc7] : 0) 170 | #define fb(x) ((x) ? pow[log[x] + 0x68] : 0) 171 | #define fd(x) ((x) ? pow[log[x] + 0xee] : 0) 172 | #define fe(x) ((x) ? pow[log[x] + 0xdf] : 0) 173 | 174 | #endif 175 | 176 | #include "aestab.h" 177 | 178 | #if defined(__cplusplus) 179 | extern "C" 180 | { 181 | #endif 182 | 183 | #if defined(STATIC_TABLES) 184 | 185 | /* implemented in case of wrong call for fixed tables */ 186 | 187 | AES_RETURN aes_init(void) 188 | { 189 | return EXIT_SUCCESS; 190 | } 191 | 192 | #else /* Generate the tables for the dynamic table option */ 193 | 194 | #if defined(FF_TABLES) 195 | 196 | #define gf_inv(x) ((x) ? pow[ 255 - log[x]] : 0) 197 | 198 | #else 199 | 200 | /* It will generally be sensible to use tables to compute finite 201 | field multiplies and inverses but where memory is scarse this 202 | code might sometimes be better. But it only has effect during 203 | initialisation so its pretty unimportant in overall terms. 204 | */ 205 | 206 | /* return 2 ^ (n - 1) where n is the bit number of the highest bit 207 | set in x with x in the range 1 < x < 0x00000200. This form is 208 | used so that locals within fi can be bytes rather than words 209 | */ 210 | 211 | static uint8_t hibit(const uint32_t x) 212 | { uint8_t r = (uint8_t)((x >> 1) | (x >> 2)); 213 | 214 | r |= (r >> 2); 215 | r |= (r >> 4); 216 | return (r + 1) >> 1; 217 | } 218 | 219 | /* return the inverse of the finite field element x */ 220 | 221 | static uint8_t gf_inv(const uint8_t x) 222 | { uint8_t p1 = x, p2 = BPOLY, n1 = hibit(x), n2 = 0x80, v1 = 1, v2 = 0; 223 | 224 | if(x < 2) 225 | return x; 226 | 227 | for( ; ; ) 228 | { 229 | if(n1) 230 | while(n2 >= n1) /* divide polynomial p2 by p1 */ 231 | { 232 | n2 /= n1; /* shift smaller polynomial left */ 233 | p2 ^= (p1 * n2) & 0xff; /* and remove from larger one */ 234 | v2 ^= v1 * n2; /* shift accumulated value and */ 235 | n2 = hibit(p2); /* add into result */ 236 | } 237 | else 238 | return v1; 239 | 240 | if(n2) /* repeat with values swapped */ 241 | while(n1 >= n2) 242 | { 243 | n1 /= n2; 244 | p1 ^= p2 * n1; 245 | v1 ^= v2 * n1; 246 | n1 = hibit(p1); 247 | } 248 | else 249 | return v2; 250 | } 251 | } 252 | 253 | #endif 254 | 255 | /* The forward and inverse affine transformations used in the S-box */ 256 | uint8_t fwd_affine(const uint8_t x) 257 | { uint32_t w = x; 258 | w ^= (w << 1) ^ (w << 2) ^ (w << 3) ^ (w << 4); 259 | return 0x63 ^ ((w ^ (w >> 8)) & 0xff); 260 | } 261 | 262 | uint8_t inv_affine(const uint8_t x) 263 | { uint32_t w = x; 264 | w = (w << 1) ^ (w << 3) ^ (w << 6); 265 | return 0x05 ^ ((w ^ (w >> 8)) & 0xff); 266 | } 267 | 268 | static int init = 0; 269 | 270 | AES_RETURN aes_init(void) 271 | { uint32_t i, w; 272 | 273 | #if defined(FF_TABLES) 274 | 275 | uint8_t pow[512], log[256]; 276 | 277 | if(init) 278 | return EXIT_SUCCESS; 279 | /* log and power tables for GF(2^8) finite field with 280 | WPOLY as modular polynomial - the simplest primitive 281 | root is 0x03, used here to generate the tables 282 | */ 283 | 284 | i = 0; w = 1; 285 | do 286 | { 287 | pow[i] = (uint8_t)w; 288 | pow[i + 255] = (uint8_t)w; 289 | log[w] = (uint8_t)i++; 290 | w ^= (w << 1) ^ (w & 0x80 ? WPOLY : 0); 291 | } 292 | while (w != 1); 293 | 294 | #else 295 | if(init) 296 | return EXIT_SUCCESS; 297 | #endif 298 | 299 | for(i = 0, w = 1; i < RC_LENGTH; ++i) 300 | { 301 | t_set(r,c)[i] = bytes2word(w, 0, 0, 0); 302 | w = f2(w); 303 | } 304 | 305 | for(i = 0; i < 256; ++i) 306 | { uint8_t b; 307 | 308 | b = fwd_affine(gf_inv((uint8_t)i)); 309 | w = bytes2word(f2(b), b, b, f3(b)); 310 | 311 | #if defined( SBX_SET ) 312 | t_set(s,box)[i] = b; 313 | #endif 314 | 315 | #if defined( FT1_SET ) /* tables for a normal encryption round */ 316 | t_set(f,n)[i] = w; 317 | #endif 318 | #if defined( FT4_SET ) 319 | t_set(f,n)[0][i] = w; 320 | t_set(f,n)[1][i] = upr(w,1); 321 | t_set(f,n)[2][i] = upr(w,2); 322 | t_set(f,n)[3][i] = upr(w,3); 323 | #endif 324 | w = bytes2word(b, 0, 0, 0); 325 | 326 | #if defined( FL1_SET ) /* tables for last encryption round (may also */ 327 | t_set(f,l)[i] = w; /* be used in the key schedule) */ 328 | #endif 329 | #if defined( FL4_SET ) 330 | t_set(f,l)[0][i] = w; 331 | t_set(f,l)[1][i] = upr(w,1); 332 | t_set(f,l)[2][i] = upr(w,2); 333 | t_set(f,l)[3][i] = upr(w,3); 334 | #endif 335 | 336 | #if defined( LS1_SET ) /* table for key schedule if t_set(f,l) above is*/ 337 | t_set(l,s)[i] = w; /* not of the required form */ 338 | #endif 339 | #if defined( LS4_SET ) 340 | t_set(l,s)[0][i] = w; 341 | t_set(l,s)[1][i] = upr(w,1); 342 | t_set(l,s)[2][i] = upr(w,2); 343 | t_set(l,s)[3][i] = upr(w,3); 344 | #endif 345 | 346 | b = gf_inv(inv_affine((uint8_t)i)); 347 | w = bytes2word(fe(b), f9(b), fd(b), fb(b)); 348 | 349 | #if defined( IM1_SET ) /* tables for the inverse mix column operation */ 350 | t_set(i,m)[b] = w; 351 | #endif 352 | #if defined( IM4_SET ) 353 | t_set(i,m)[0][b] = w; 354 | t_set(i,m)[1][b] = upr(w,1); 355 | t_set(i,m)[2][b] = upr(w,2); 356 | t_set(i,m)[3][b] = upr(w,3); 357 | #endif 358 | 359 | #if defined( ISB_SET ) 360 | t_set(i,box)[i] = b; 361 | #endif 362 | #if defined( IT1_SET ) /* tables for a normal decryption round */ 363 | t_set(i,n)[i] = w; 364 | #endif 365 | #if defined( IT4_SET ) 366 | t_set(i,n)[0][i] = w; 367 | t_set(i,n)[1][i] = upr(w,1); 368 | t_set(i,n)[2][i] = upr(w,2); 369 | t_set(i,n)[3][i] = upr(w,3); 370 | #endif 371 | w = bytes2word(b, 0, 0, 0); 372 | #if defined( IL1_SET ) /* tables for last decryption round */ 373 | t_set(i,l)[i] = w; 374 | #endif 375 | #if defined( IL4_SET ) 376 | t_set(i,l)[0][i] = w; 377 | t_set(i,l)[1][i] = upr(w,1); 378 | t_set(i,l)[2][i] = upr(w,2); 379 | t_set(i,l)[3][i] = upr(w,3); 380 | #endif 381 | } 382 | init = 1; 383 | return EXIT_SUCCESS; 384 | } 385 | 386 | /* 387 | Automatic code initialisation (suggested by by Henrik S. Gaßmann) 388 | based on code provided by Joe Lowe and placed in the public domain at: 389 | http://stackoverflow.com/questions/1113409/attribute-constructor-equivalent-in-vc 390 | */ 391 | 392 | #ifdef _MSC_VER 393 | 394 | #pragma section(".CRT$XCU", read) 395 | 396 | __declspec(allocate(".CRT$XCU")) void (__cdecl *aes_startup)(void) = aes_init; 397 | 398 | #elif defined(__GNUC__) 399 | 400 | static void aes_startup(void) __attribute__((constructor)); 401 | 402 | static void aes_startup(void) 403 | { 404 | aes_init(); 405 | } 406 | 407 | #else 408 | 409 | #pragma message( "dynamic tables must be initialised manually on your system" ) 410 | 411 | #endif 412 | 413 | #endif 414 | 415 | #if defined(__cplusplus) 416 | } 417 | #endif 418 | 419 | --------------------------------------------------------------------------------