├── AppList.h ├── .clang-format ├── docs ├── preview1.PNG ├── preview2.PNG └── preview3.PNG ├── Resources ├── AppIcon20x20@2x.png ├── AppIcon20x20@3x.png ├── AppIcon29x29@2x.png ├── AppIcon29x29@3x.png ├── AppIcon40x40@2x.png ├── AppIcon40x40@3x.png ├── AppIcon60x60@2x.png ├── AppIcon60x60@3x.png ├── AppIcon76x76@2x.png └── Info.plist ├── .gitignore ├── thirdparty ├── TDFileManagerViewController.h ├── TDUtils.h ├── 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 │ │ ├── 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 ├── LSApplicationProxy+AltList.h ├── TDFileManagerViewController.m ├── TDUtils.m └── LSApplicationProxy+AltList.m ├── control ├── main.m ├── AppDelegate.h ├── RootViewController.h ├── AppDuplicator.h ├── AppDelegate.m ├── entitlements.plist ├── README.md ├── LICENSE ├── Makefile ├── AppList.m ├── AppDuplicator.m └── RootViewController.m /AppList.h: -------------------------------------------------------------------------------- 1 | #import 2 | 3 | NSArray *appList(void); -------------------------------------------------------------------------------- /.clang-format: -------------------------------------------------------------------------------- 1 | BasedOnStyle: Google 2 | IndentWidth: 4 3 | TabWidth: 4 4 | UseTab: Never 5 | -------------------------------------------------------------------------------- /docs/preview1.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BreakOnCrash/TrollAppDuplicator/HEAD/docs/preview1.PNG -------------------------------------------------------------------------------- /docs/preview2.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BreakOnCrash/TrollAppDuplicator/HEAD/docs/preview2.PNG -------------------------------------------------------------------------------- /docs/preview3.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BreakOnCrash/TrollAppDuplicator/HEAD/docs/preview3.PNG -------------------------------------------------------------------------------- /Resources/AppIcon20x20@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BreakOnCrash/TrollAppDuplicator/HEAD/Resources/AppIcon20x20@2x.png -------------------------------------------------------------------------------- /Resources/AppIcon20x20@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BreakOnCrash/TrollAppDuplicator/HEAD/Resources/AppIcon20x20@3x.png -------------------------------------------------------------------------------- /Resources/AppIcon29x29@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BreakOnCrash/TrollAppDuplicator/HEAD/Resources/AppIcon29x29@2x.png -------------------------------------------------------------------------------- /Resources/AppIcon29x29@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BreakOnCrash/TrollAppDuplicator/HEAD/Resources/AppIcon29x29@3x.png -------------------------------------------------------------------------------- /Resources/AppIcon40x40@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BreakOnCrash/TrollAppDuplicator/HEAD/Resources/AppIcon40x40@2x.png -------------------------------------------------------------------------------- /Resources/AppIcon40x40@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BreakOnCrash/TrollAppDuplicator/HEAD/Resources/AppIcon40x40@3x.png -------------------------------------------------------------------------------- /Resources/AppIcon60x60@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BreakOnCrash/TrollAppDuplicator/HEAD/Resources/AppIcon60x60@2x.png -------------------------------------------------------------------------------- /Resources/AppIcon60x60@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BreakOnCrash/TrollAppDuplicator/HEAD/Resources/AppIcon60x60@3x.png -------------------------------------------------------------------------------- /Resources/AppIcon76x76@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BreakOnCrash/TrollAppDuplicator/HEAD/Resources/AppIcon76x76@2x.png -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .theos/ 2 | packages/ 3 | .DS_Store 4 | 5 | packages/ 6 | Payload/ 7 | TrollAppDuplicator.tipa 8 | 9 | # clangd 10 | .vscode/ 11 | .cache/ 12 | compile_commands.json -------------------------------------------------------------------------------- /thirdparty/TDFileManagerViewController.h: -------------------------------------------------------------------------------- 1 | #import 2 | 3 | @interface TDFileManagerViewController : UITableViewController 4 | 5 | @property(nonatomic, strong) NSArray *fileList; 6 | 7 | @end -------------------------------------------------------------------------------- /control: -------------------------------------------------------------------------------- 1 | Package: com.zznq.trollappduplicator 2 | Name: TrollAppDuplicator 3 | Version: 1.2.1 4 | Architecture: iphoneos-arm 5 | Description: iOS App duplicator for TrollStore 6 | Maintainer: 巴斯.zznQ 7 | Author: 巴斯.zznQ 8 | Section: Utilities 9 | -------------------------------------------------------------------------------- /main.m: -------------------------------------------------------------------------------- 1 | #import 2 | #import "AppDelegate.h" 3 | 4 | int main(int argc, char *argv[]) { 5 | @autoreleasepool { 6 | return UIApplicationMain(argc, argv, nil, NSStringFromClass(AppDelegate.class)); 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /AppDelegate.h: -------------------------------------------------------------------------------- 1 | #import 2 | 3 | @interface AppDelegate : UIResponder 4 | 5 | @property(nonatomic, strong) UIWindow *window; 6 | @property(nonatomic, strong) UINavigationController *rootViewController; 7 | 8 | @end 9 | -------------------------------------------------------------------------------- /RootViewController.h: -------------------------------------------------------------------------------- 1 | #import "AppDuplicator.h" 2 | #import 3 | 4 | @interface RootViewController : UITableViewController 5 | 6 | @property(nonatomic, strong) NSArray *apps; 7 | @property(nonatomic, strong) AppDuplicator *duplicator; 8 | 9 | @end 10 | -------------------------------------------------------------------------------- /AppDuplicator.h: -------------------------------------------------------------------------------- 1 | #import 2 | 3 | @interface AppDuplicator : NSObject 4 | 5 | - (NSString *)duplicateAppWithBundleID:(NSString *)appDirectory 6 | bundleID:(NSString *)bundleID 7 | name:(NSString *)name; 8 | 9 | - (BOOL)copyDirectoryFromPath:(NSString *)srcPath toPath:(NSString *)dstPath; 10 | @end -------------------------------------------------------------------------------- /thirdparty/TDUtils.h: -------------------------------------------------------------------------------- 1 | #import 2 | #import 3 | 4 | @interface UIImage (Private) 5 | + (UIImage *)_applicationIconImageForBundleIdentifier:(NSString *)bundleIdentifier 6 | format:(NSUInteger)format 7 | scale:(CGFloat)scale; 8 | @end 9 | 10 | NSUInteger iconFormat(void); 11 | NSString *docPath(void); 12 | NSArray *duplicatedFileList(void); 13 | BOOL isArchitectureEncrypted(FILE *binary, uint32_t offset); 14 | BOOL isBinaryEncrypted(NSString *path); -------------------------------------------------------------------------------- /AppDelegate.m: -------------------------------------------------------------------------------- 1 | #import "AppDelegate.h" 2 | #import "RootViewController.h" 3 | 4 | @implementation AppDelegate 5 | 6 | - (BOOL)application:(UIApplication *)application 7 | didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { 8 | _window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds]; 9 | _rootViewController = [[UINavigationController alloc] 10 | initWithRootViewController:[[RootViewController alloc] init]]; 11 | _window.rootViewController = _rootViewController; 12 | [_window makeKeyAndVisible]; 13 | return YES; 14 | } 15 | 16 | @end 17 | -------------------------------------------------------------------------------- /entitlements.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | platform-application 6 | 7 | application-identifier 8 | com.zznq.trollappduplicator 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.security.storage.AppBundles 16 | 17 | 18 | -------------------------------------------------------------------------------- /thirdparty/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 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # TrollAppDuplicator 2 | iOS App duplicator for TrollStore 3 | 4 | [now-on-havoc]: https://havoc.app/package/appduplicator 5 | 6 | [][now-on-havoc] [][now-on-havoc] 7 | 8 | 9 | ## Preview 10 | 11 | 12 | 13 | ## How to use 14 | 15 | 1. Download and install TrollAppDuplicator. 16 | 2. Choose app you want to duplicate. 17 | 3. Once finished duplicating, you can get the .ipa file from inside the app. 18 | 4. Install the duplicated ipa. 19 | 20 | ## Credits / Thanks 21 | [TrollDecrypt](https://github.com/donato-fiore/TrollDecrypt) by fiore 22 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2024 BreakOnCrash 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /thirdparty/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 */ -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | ARCHS = arm64 2 | 3 | TARGET := iphone:clang:latest:latest 4 | INSTALL_TARGET_PROCESSES = TrollAppDuplicator 5 | 6 | include $(THEOS)/makefiles/common.mk 7 | 8 | APPLICATION_NAME = TrollAppDuplicator 9 | 10 | TrollAppDuplicator_FILES = thirdparty/SSZipArchive/minizip/unzip.c thirdparty/SSZipArchive/minizip/crypt.c thirdparty/SSZipArchive/minizip/ioapi_buf.c thirdparty/SSZipArchive/minizip/ioapi_mem.c thirdparty/SSZipArchive/minizip/ioapi.c thirdparty/SSZipArchive/minizip/minishared.c thirdparty/SSZipArchive/minizip/zip.c thirdparty/SSZipArchive/minizip/aes/aes_ni.c thirdparty/SSZipArchive/minizip/aes/aescrypt.c thirdparty/SSZipArchive/minizip/aes/aeskey.c thirdparty/SSZipArchive/minizip/aes/aestab.c thirdparty/SSZipArchive/minizip/aes/fileenc.c thirdparty/SSZipArchive/minizip/aes/hmac.c thirdparty/SSZipArchive/minizip/aes/prng.c thirdparty/SSZipArchive/minizip/aes/pwd2key.c thirdparty/SSZipArchive/minizip/aes/sha1.c thirdparty/SSZipArchive/SSZipArchive.m 11 | TrollAppDuplicator_FILES += main.m AppDelegate.m AppList.m RootViewController.m AppDuplicator.m thirdparty/TDUtils.m thirdparty/LSApplicationProxy+AltList.m thirdparty/TDFileManagerViewController.m 12 | TrollAppDuplicator_FRAMEWORKS = UIKit CoreGraphics MobileCoreServices 13 | TrollAppDuplicator_CFLAGS = -fobjc-arc 14 | 15 | include $(THEOS_MAKE_PATH)/application.mk 16 | 17 | after-stage:: 18 | mkdir -p $(THEOS_STAGING_DIR)/Payload 19 | ldid -Sentitlements.plist $(THEOS_STAGING_DIR)/Applications/TrollAppDuplicator.app/TrollAppDuplicator 20 | cp -a $(THEOS_STAGING_DIR)/Applications/* $(THEOS_STAGING_DIR)/Payload 21 | mv $(THEOS_STAGING_DIR)/Payload . 22 | zip -q -r TrollAppDuplicator.tipa Payload 23 | rm -rf Payload -------------------------------------------------------------------------------- /thirdparty/LSApplicationProxy+AltList.h: -------------------------------------------------------------------------------- 1 | // @https://github.com/donato-fiore/TrollDecrypt/blob/main/LSApplicationProxy%2BAltList.h 2 | #import 3 | #import 4 | 5 | @interface LSApplicationRecord : NSObject 6 | @property(nonatomic, readonly) NSArray *appTags; // 'hidden' 7 | @property(getter=isLaunchProhibited, readonly) BOOL launchProhibited; 8 | @end 9 | 10 | @interface LSApplicationProxy (Additions) 11 | @property(readonly, nonatomic) NSString *shortVersionString; 12 | @property(nonatomic, readonly) NSString *localizedName; 13 | @property(nonatomic, readonly) NSString *applicationType; // (User/System) 14 | @property(nonatomic, readonly) NSArray *appTags; // 'hidden' 15 | @property(getter=isLaunchProhibited, nonatomic, readonly) BOOL launchProhibited; 16 | + (instancetype)applicationProxyForIdentifier:(NSString *)identifier; 17 | - (LSApplicationRecord *)correspondingApplicationRecord; 18 | @end 19 | 20 | @interface LSApplicationWorkspace (Additions) 21 | - (void)addObserver:(id)arg1; 22 | - (void)removeObserver:(id)arg1; 23 | - (void)enumerateApplicationsOfType:(NSUInteger)type block:(void (^)(LSApplicationProxy *))block; 24 | @end 25 | 26 | @interface LSApplicationProxy (AltList) 27 | - (BOOL)atl_isSystemApplication; 28 | - (BOOL)atl_isUserApplication; 29 | - (BOOL)atl_isHidden; 30 | - (NSString *)atl_fastDisplayName; 31 | - (NSString *)atl_nameToDisplay; 32 | - (NSString *)atl_shortVersionString; 33 | @property(nonatomic, readonly) NSString *atl_bundleIdentifier; 34 | @end 35 | 36 | @interface LSApplicationWorkspace (AltList) 37 | - (NSArray *)atl_allInstalledApplications; 38 | @end -------------------------------------------------------------------------------- /thirdparty/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 | -------------------------------------------------------------------------------- /AppList.m: -------------------------------------------------------------------------------- 1 | #import "AppList.h" 2 | #import "thirdparty/LSApplicationProxy+AltList.h" 3 | 4 | NSArray *appList(void) { 5 | NSMutableArray *apps = [NSMutableArray array]; 6 | 7 | NSArray *installedApplications = 8 | [[LSApplicationWorkspace defaultWorkspace] atl_allInstalledApplications]; 9 | [installedApplications 10 | enumerateObjectsUsingBlock:^(LSApplicationProxy *proxy, NSUInteger idx, BOOL *stop) { 11 | if ([proxy atl_isHidden]) return; 12 | 13 | NSString *bundleID = bundleID = [proxy atl_bundleIdentifier]; 14 | 15 | if (![proxy.applicationType isEqualToString:@"User"]) { 16 | if ([bundleID hasPrefix:@"com.apple."]) return; 17 | if ([bundleID hasPrefix:@"com.opa334."]) return; 18 | if ([bundleID isEqualToString:@"com.zznq.trollappduplicator"]) return; 19 | } 20 | 21 | NSURL *appURL = [proxy performSelector:@selector(bundleURL)]; 22 | if (![appURL.path hasPrefix:@"/private/var/containers/Bundle/Application/"]) return; 23 | 24 | NSString *path = appURL.path; 25 | NSString *name = [proxy atl_nameToDisplay]; 26 | NSString *version = [proxy atl_shortVersionString]; 27 | 28 | if (!bundleID || !name || !version || !path) return; 29 | 30 | NSDictionary *item = 31 | @{@"bundleID" : bundleID, @"name" : name, @"path" : path, @"version" : version}; 32 | 33 | [apps addObject:item]; 34 | }]; 35 | 36 | NSSortDescriptor *descriptor = 37 | [[NSSortDescriptor alloc] initWithKey:@"name" 38 | ascending:YES 39 | selector:@selector(localizedCaseInsensitiveCompare:)]; 40 | [apps sortUsingDescriptors:@[ descriptor ]]; 41 | 42 | return [apps copy]; 43 | } 44 | -------------------------------------------------------------------------------- /Resources/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleExecutable 6 | TrollAppDuplicator 7 | CFBundleIcons 8 | 9 | CFBundlePrimaryIcon 10 | 11 | CFBundleIconFiles 12 | 13 | AppIcon29x29 14 | AppIcon40x40 15 | AppIcon60x60 16 | 17 | UIPrerenderedIcon 18 | 19 | 20 | 21 | CFBundleIcons~ipad 22 | 23 | CFBundlePrimaryIcon 24 | 25 | CFBundleIconFiles 26 | 27 | AppIcon29x29 28 | AppIcon40x40 29 | AppIcon60x60 30 | AppIcon76x76 31 | 32 | UIPrerenderedIcon 33 | 34 | 35 | 36 | CFBundleIdentifier 37 | com.zznq.trollappduplicator 38 | CFBundleInfoDictionaryVersion 39 | 6.0 40 | CFBundlePackageType 41 | APPL 42 | CFBundleSignature 43 | ???? 44 | CFBundleSupportedPlatforms 45 | 46 | iPhoneOS 47 | 48 | CFBundleVersion 49 | 1.2.1 50 | LSRequiresIPhoneOS 51 | 52 | UIDeviceFamily 53 | 54 | 1 55 | 2 56 | 57 | UIRequiredDeviceCapabilities 58 | 59 | armv7 60 | 61 | UILaunchStoryboardName 62 | LaunchScreen 63 | UISupportedInterfaceOrientations 64 | 65 | UIInterfaceOrientationPortrait 66 | 67 | UISupportedInterfaceOrientations~ipad 68 | 69 | UIInterfaceOrientationPortrait 70 | 71 | 72 | 73 | -------------------------------------------------------------------------------- /thirdparty/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 | -------------------------------------------------------------------------------- /thirdparty/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 | -------------------------------------------------------------------------------- /thirdparty/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 | -------------------------------------------------------------------------------- /thirdparty/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 | -------------------------------------------------------------------------------- /thirdparty/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 | -------------------------------------------------------------------------------- /thirdparty/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 | -------------------------------------------------------------------------------- /AppDuplicator.m: -------------------------------------------------------------------------------- 1 | #import "AppDuplicator.h" 2 | #import "thirdparty/SSZipArchive/SSZipArchive.h" 3 | #import "thirdparty/TDUtils.h" 4 | 5 | @implementation AppDuplicator 6 | 7 | - (NSString *)duplicateAppWithBundleID:(NSString *)appDirectory 8 | bundleID:(NSString *)bundleID 9 | name:(NSString *)name { 10 | uint32_t num = arc4random_uniform(99999) + 1; 11 | bundleID = [NSString stringWithFormat:@"%@.%u", bundleID, num]; 12 | 13 | NSString *tmpPath = [docPath() stringByAppendingPathComponent:bundleID]; 14 | NSString *zipDir = [NSString stringWithFormat:@"%@/ipa", tmpPath]; 15 | NSString *dstAppPath = 16 | [NSString stringWithFormat:@"%@/Payload/%@", zipDir, [appDirectory lastPathComponent]]; 17 | if (![self copyDirectoryFromPath:appDirectory toPath:dstAppPath]) { 18 | NSLog(@"Failed to copy Application directory."); 19 | return nil; 20 | } 21 | 22 | NSString *infoPlistPath = [dstAppPath stringByAppendingPathComponent:@"Info.plist"]; 23 | NSMutableDictionary *infoPlist = 24 | [NSMutableDictionary dictionaryWithContentsOfFile:infoPlistPath]; 25 | if (!infoPlist) { 26 | NSLog(@"Failed to read Info.plist file."); 27 | return nil; 28 | } 29 | 30 | infoPlist[@"CFBundleDisplayName"] = name; 31 | infoPlist[@"CFBundleIdentifier"] = bundleID; 32 | 33 | BOOL success = [infoPlist writeToFile:infoPlistPath atomically:YES]; 34 | if (!success) { 35 | NSLog(@"Failed to write modified Info.plist file."); 36 | return nil; 37 | } 38 | 39 | NSString *IPAFile = 40 | [NSString stringWithFormat:@"%@/%@_%@_duplicated.ipa", docPath(), bundleID, name]; 41 | @try { 42 | BOOL success = [SSZipArchive createZipFileAtPath:IPAFile 43 | withContentsOfDirectory:zipDir 44 | keepParentDirectory:NO 45 | compressionLevel:1 46 | password:nil 47 | AES:NO 48 | progressHandler:nil]; 49 | return success ? IPAFile : nil; 50 | } @catch (NSException *e) { 51 | NSLog(@"[appduplicator] BAAAAAAAARF during ZIP operation!!! , %@", e); 52 | return nil; 53 | } 54 | } 55 | 56 | - (BOOL)copyDirectoryFromPath:(NSString *)srcPath toPath:(NSString *)dstPath { 57 | NSFileManager *fileManager = [NSFileManager defaultManager]; 58 | BOOL isDirectory; 59 | if (![fileManager fileExistsAtPath:srcPath isDirectory:&isDirectory] || !isDirectory) { 60 | return NO; 61 | } 62 | 63 | [fileManager removeItemAtPath:dstPath error:nil]; 64 | 65 | if (![fileManager createDirectoryAtPath:dstPath 66 | withIntermediateDirectories:YES 67 | attributes:nil 68 | error:nil]) { 69 | return NO; 70 | } 71 | 72 | NSArray *contents = [fileManager contentsOfDirectoryAtPath:srcPath error:nil]; 73 | if (!contents) { 74 | return NO; 75 | } 76 | 77 | for (NSString *item in contents) { 78 | NSString *sourceItemPath = [srcPath stringByAppendingPathComponent:item]; 79 | NSString *destinationItemPath = [dstPath stringByAppendingPathComponent:item]; 80 | if (![fileManager copyItemAtPath:sourceItemPath toPath:destinationItemPath error:nil]) { 81 | return NO; 82 | } 83 | } 84 | 85 | return YES; 86 | } 87 | 88 | @end 89 | -------------------------------------------------------------------------------- /thirdparty/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 | -------------------------------------------------------------------------------- /thirdparty/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 | -------------------------------------------------------------------------------- /thirdparty/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 = @"Duplicated IPAs"; 10 | self.fileList = duplicatedFileList(); 11 | 12 | self.navigationItem.rightBarButtonItem = 13 | [[UIBarButtonItem alloc] initWithTitle:@"Done" 14 | style:UIBarButtonItemStyleDone 15 | target:self 16 | action:@selector(done)]; 17 | } 18 | 19 | - (void)refresh { 20 | self.fileList = duplicatedFileList(); 21 | [self.tableView reloadData]; 22 | } 23 | 24 | - (void)done { 25 | [self dismissViewControllerAnimated:YES completion:nil]; 26 | } 27 | 28 | - (NSInteger)numberOfSelectionsInTableView:(UITableView *)tableView { 29 | return 1; 30 | } 31 | 32 | - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { 33 | return self.fileList.count; 34 | } 35 | 36 | - (UITableViewCell *)tableView:(UITableView *)tableView 37 | cellForRowAtIndexPath:(NSIndexPath *)indexPath { 38 | static NSString *cellIdentifier = @"FileCell"; 39 | UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier]; 40 | 41 | if (!cell) { 42 | cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle 43 | reuseIdentifier:cellIdentifier]; 44 | } 45 | 46 | NSString *path = [docPath() stringByAppendingPathComponent:self.fileList[indexPath.row]]; 47 | NSDictionary *attributes = [[NSFileManager defaultManager] attributesOfItemAtPath:path 48 | error:nil]; 49 | NSDate *date = attributes[NSFileModificationDate]; 50 | NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; 51 | [dateFormatter setDateFormat:@"MMM d, yyyy h:mm a"]; 52 | 53 | NSNumber *fileSize = attributes[NSFileSize]; 54 | 55 | cell.textLabel.text = self.fileList[indexPath.row]; 56 | cell.detailTextLabel.text = [dateFormatter stringFromDate:date]; 57 | cell.detailTextLabel.textColor = [UIColor systemGray2Color]; 58 | cell.imageView.image = [UIImage systemImageNamed:@"doc.fill"]; 59 | 60 | UILabel *label = [[UILabel alloc] init]; 61 | label.text = [NSString stringWithFormat:@"%.2f MB", [fileSize doubleValue] / 1000000.0f]; 62 | label.textColor = [UIColor systemGray2Color]; 63 | label.font = [UIFont systemFontOfSize:12.0f]; 64 | [label sizeToFit]; 65 | label.textAlignment = NSTextAlignmentCenter; 66 | cell.accessoryView = label; 67 | 68 | return cell; 69 | } 70 | 71 | - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { 72 | return 65.0f; 73 | } 74 | 75 | - (bool)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath { 76 | return YES; 77 | } 78 | 79 | - (UISwipeActionsConfiguration *)tableView:(UITableView *)tableView 80 | trailingSwipeActionsConfigurationForRowAtIndexPath:(NSIndexPath *)indexPath { 81 | UIContextualAction *deleteAction = [UIContextualAction 82 | contextualActionWithStyle:UIContextualActionStyleDestructive 83 | title:@"Delete" 84 | handler:^(UIContextualAction *action, UIView *sourceView, 85 | void (^completionHandler)(BOOL)) { 86 | NSString *file = self.fileList[indexPath.row]; 87 | NSString *path = [docPath() stringByAppendingPathComponent:file]; 88 | [[NSFileManager defaultManager] removeItemAtPath:path error:nil]; 89 | [self refresh]; 90 | }]; 91 | 92 | UISwipeActionsConfiguration *swipeActions = 93 | [UISwipeActionsConfiguration configurationWithActions:@[ deleteAction ]]; 94 | return swipeActions; 95 | } 96 | 97 | - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { 98 | NSString *file = self.fileList[indexPath.row]; 99 | NSString *path = [docPath() stringByAppendingPathComponent:file]; 100 | NSURL *url = [NSURL fileURLWithPath:path]; 101 | 102 | UIActivityViewController *activityViewController = 103 | [[UIActivityViewController alloc] initWithActivityItems:@[ url ] applicationActivities:nil]; 104 | [self presentViewController:activityViewController animated:YES completion:nil]; 105 | 106 | [tableView deselectRowAtIndexPath:indexPath animated:YES]; 107 | } 108 | 109 | @end -------------------------------------------------------------------------------- /thirdparty/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 | -------------------------------------------------------------------------------- /thirdparty/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 | -------------------------------------------------------------------------------- /thirdparty/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 | -------------------------------------------------------------------------------- /thirdparty/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 | -------------------------------------------------------------------------------- /thirdparty/TDUtils.m: -------------------------------------------------------------------------------- 1 | #import "TDUtils.h" 2 | #include 3 | #import 4 | #import 5 | #import "LSApplicationProxy+AltList.h" 6 | 7 | NSUInteger iconFormat(void) { 8 | return (UIDevice.currentDevice.userInterfaceIdiom == UIUserInterfaceIdiomPad) ? 8 : 10; 9 | } 10 | 11 | NSString *docPath(void) { 12 | NSError *error = nil; 13 | [[NSFileManager defaultManager] 14 | createDirectoryAtPath:@"/var/mobile/Library/TrollAppDuplicator/duplicated" 15 | withIntermediateDirectories:YES 16 | attributes:nil 17 | error:&error]; 18 | if (error != nil) { 19 | NSLog(@"[TrollAppDuplicator] error creating directory: %@", error); 20 | } 21 | 22 | return @"/var/mobile/Library/TrollAppDuplicator/duplicated"; 23 | } 24 | 25 | NSArray *duplicatedFileList(void) { 26 | NSMutableArray *files = [NSMutableArray array]; 27 | NSMutableArray *fileNames = [NSMutableArray array]; 28 | 29 | // iterate through all files in the Documents directory 30 | NSFileManager *fileManager = [NSFileManager defaultManager]; 31 | NSDirectoryEnumerator *directoryEnumerator = [fileManager enumeratorAtPath:docPath()]; 32 | 33 | NSString *file; 34 | while (file = [directoryEnumerator nextObject]) { 35 | if ([[file pathExtension] isEqualToString:@"ipa"]) { 36 | NSString *filePath = 37 | [[docPath() stringByAppendingPathComponent:file] stringByStandardizingPath]; 38 | 39 | NSDictionary *fileAttributes = [fileManager attributesOfItemAtPath:filePath error:nil]; 40 | NSDate *modificationDate = fileAttributes[NSFileModificationDate]; 41 | 42 | NSDictionary *fileInfo = @{@"fileName" : file, @"modificationDate" : modificationDate}; 43 | [files addObject:fileInfo]; 44 | } 45 | } 46 | 47 | // Sort the array based on modification date 48 | NSArray *sortedFiles = [files sortedArrayUsingComparator:^NSComparisonResult(id obj1, id obj2) { 49 | NSDate *date1 = [obj1 objectForKey:@"modificationDate"]; 50 | NSDate *date2 = [obj2 objectForKey:@"modificationDate"]; 51 | return [date2 compare:date1]; 52 | }]; 53 | 54 | // Get the file names from the sorted array 55 | for (NSDictionary *fileInfo in sortedFiles) { 56 | [fileNames addObject:[fileInfo objectForKey:@"fileName"]]; 57 | } 58 | 59 | return [fileNames copy]; 60 | } 61 | 62 | BOOL isArchitectureEncrypted(FILE *binary, uint32_t offset) { 63 | fseek(binary, offset, SEEK_SET); 64 | 65 | // 读取 mach_header 的前四个字节以确定是 32 位还是 64 位 66 | uint32_t magic; 67 | fread(&magic, sizeof(uint32_t), 1, binary); 68 | 69 | if (magic != MH_MAGIC && magic != MH_CIGAM && magic != MH_MAGIC_64 && magic != MH_CIGAM_64) { 70 | return NO; // 非有效的 Mach-O 文件 71 | } 72 | BOOL is64Bit = (magic == MH_MAGIC_64 || magic == MH_CIGAM_64); 73 | 74 | if (is64Bit) { 75 | struct mach_header_64 header; 76 | fseek(binary, offset, SEEK_SET); 77 | fread(&header, sizeof(struct mach_header_64), 1, binary); 78 | fseek(binary, offset + sizeof(struct mach_header_64), SEEK_SET); 79 | } else { 80 | struct mach_header header; 81 | fseek(binary, offset, SEEK_SET); 82 | fread(&header, sizeof(struct mach_header), 1, binary); 83 | fseek(binary, offset + sizeof(struct mach_header), SEEK_SET); 84 | } 85 | 86 | struct load_command lc; 87 | for (uint32_t i = 0; i < (is64Bit ? ((struct mach_header_64 *)(&magic))->ncmds 88 | : ((struct mach_header *)(&magic))->ncmds); 89 | i++) { 90 | fread(&lc, sizeof(struct load_command), 1, binary); 91 | 92 | if (lc.cmd == LC_ENCRYPTION_INFO_64 && is64Bit) { 93 | struct encryption_info_command_64 encryptCmd; 94 | fseek(binary, -sizeof(struct load_command), SEEK_CUR); 95 | fread(&encryptCmd, sizeof(struct encryption_info_command_64), 1, binary); 96 | return encryptCmd.cryptid != 0; 97 | } else if (lc.cmd == LC_ENCRYPTION_INFO && !is64Bit) { 98 | struct encryption_info_command encryptCmd; 99 | fseek(binary, -sizeof(struct load_command), SEEK_CUR); 100 | fread(&encryptCmd, sizeof(struct encryption_info_command), 1, binary); 101 | return encryptCmd.cryptid != 0; 102 | } 103 | 104 | fseek(binary, lc.cmdsize - sizeof(struct load_command), SEEK_CUR); 105 | } 106 | 107 | return NO; 108 | } 109 | 110 | BOOL isBinaryEncrypted(NSString *path) { 111 | FILE *binary = fopen([path fileSystemRepresentation], "rb"); 112 | if (!binary) return NO; 113 | 114 | struct fat_header fatHeader; 115 | fread(&fatHeader, sizeof(struct fat_header), 1, binary); 116 | 117 | if (fatHeader.magic == FAT_MAGIC || fatHeader.magic == FAT_CIGAM) { 118 | uint32_t nfat_arch = OSSwapBigToHostInt32(fatHeader.nfat_arch); 119 | if (nfat_arch > 1) { 120 | struct fat_arch arch; 121 | fread(&arch, sizeof(struct fat_arch), 1, binary); 122 | uint32_t offset = OSSwapBigToHostInt32(arch.offset); 123 | if (isArchitectureEncrypted(binary, offset)) { 124 | fclose(binary); 125 | return YES; 126 | } 127 | } 128 | } else { 129 | // Not a FAT binary, check as regular Mach-O 130 | if (isArchitectureEncrypted(binary, 0)) { 131 | fclose(binary); 132 | return YES; 133 | } 134 | } 135 | 136 | fclose(binary); 137 | return NO; 138 | } -------------------------------------------------------------------------------- /thirdparty/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 | -------------------------------------------------------------------------------- /thirdparty/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 | -------------------------------------------------------------------------------- /thirdparty/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 | -------------------------------------------------------------------------------- /thirdparty/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 | -------------------------------------------------------------------------------- /thirdparty/LSApplicationProxy+AltList.m: -------------------------------------------------------------------------------- 1 | #import 2 | #import "LSApplicationProxy+AltList.h" 3 | 4 | @implementation LSApplicationProxy (AltList) 5 | 6 | - (BOOL)atl_isSystemApplication { 7 | return [self.applicationType isEqualToString:@"System"] && ![self atl_isHidden]; 8 | } 9 | 10 | - (BOOL)atl_isUserApplication { 11 | return [self.applicationType isEqualToString:@"User"] && ![self atl_isHidden]; 12 | } 13 | 14 | // the tag " hidden " is also valid, so we need to check if any strings contain 15 | // "hidden" instead 16 | BOOL tagArrayContainsTag(NSArray *tagArr, NSString *tag) { 17 | if (!tagArr || !tag) return NO; 18 | 19 | __block BOOL found = NO; 20 | 21 | [tagArr enumerateObjectsUsingBlock:^(NSString *tagToCheck, NSUInteger idx, BOOL *stop) { 22 | if (![tagToCheck isKindOfClass:[NSString class]]) { 23 | return; 24 | } 25 | 26 | if ([tagToCheck rangeOfString:tag options:0].location != NSNotFound) { 27 | found = YES; 28 | *stop = YES; 29 | } 30 | }]; 31 | 32 | return found; 33 | } 34 | 35 | // always returns NO on iOS 7 36 | - (BOOL)atl_isHidden { 37 | NSArray *appTags; 38 | NSArray *recordAppTags; 39 | NSArray *sbAppTags; 40 | 41 | BOOL launchProhibited = NO; 42 | 43 | if ([self respondsToSelector:@selector(correspondingApplicationRecord)]) { 44 | // On iOS 14, self.appTags is always empty but the application record still 45 | // has the correct ones 46 | LSApplicationRecord *record = [self correspondingApplicationRecord]; 47 | recordAppTags = record.appTags; 48 | launchProhibited = record.launchProhibited; 49 | } 50 | if ([self respondsToSelector:@selector(appTags)]) { 51 | appTags = self.appTags; 52 | } 53 | if (!launchProhibited && [self respondsToSelector:@selector(isLaunchProhibited)]) { 54 | launchProhibited = self.launchProhibited; 55 | } 56 | 57 | NSURL *bundleURL = self.bundleURL; 58 | if (bundleURL && [bundleURL checkResourceIsReachableAndReturnError:nil]) { 59 | NSBundle *bundle = [NSBundle bundleWithURL:bundleURL]; 60 | sbAppTags = [bundle objectForInfoDictionaryKey:@"SBAppTags"]; 61 | } 62 | 63 | BOOL isWebApplication = ([self.atl_bundleIdentifier rangeOfString:@"com.apple.webapp" 64 | options:NSCaseInsensitiveSearch] 65 | .location != NSNotFound); 66 | return tagArrayContainsTag(appTags, @"hidden") || 67 | tagArrayContainsTag(recordAppTags, @"hidden") || 68 | tagArrayContainsTag(sbAppTags, @"hidden") || isWebApplication || launchProhibited; 69 | } 70 | 71 | // Getting the display name is slow (up to 2ms) because it uses an IPC call 72 | // this stacks up if you do it for every single application 73 | // This method provides a faster way (around 0.5ms) to get the display name 74 | // This reduces the overall time needed to sort the applications from ~230 to 75 | // ~120ms on my test device 76 | - (NSString *)atl_fastDisplayName { 77 | NSString *cachedDisplayName = [self valueForKey:@"_localizedName"]; 78 | if (cachedDisplayName && ![cachedDisplayName isEqualToString:@""]) { 79 | return cachedDisplayName; 80 | } 81 | 82 | NSString *localizedName; 83 | 84 | NSURL *bundleURL = self.bundleURL; 85 | if (!bundleURL || ![bundleURL checkResourceIsReachableAndReturnError:nil]) { 86 | localizedName = self.localizedName; 87 | } else { 88 | NSBundle *bundle = [NSBundle bundleWithURL:bundleURL]; 89 | 90 | localizedName = [bundle objectForInfoDictionaryKey:@"CFBundleDisplayName"]; 91 | if (![localizedName isKindOfClass:[NSString class]]) localizedName = nil; 92 | if (!localizedName || [localizedName isEqualToString:@""]) { 93 | localizedName = [bundle objectForInfoDictionaryKey:@"CFBundleName"]; 94 | if (![localizedName isKindOfClass:[NSString class]]) localizedName = nil; 95 | if (!localizedName || [localizedName isEqualToString:@""]) { 96 | localizedName = [bundle objectForInfoDictionaryKey:@"CFBundleExecutable"]; 97 | if (![localizedName isKindOfClass:[NSString class]]) localizedName = nil; 98 | if (!localizedName || [localizedName isEqualToString:@""]) { 99 | // last possible fallback: use slow IPC call 100 | localizedName = self.localizedName; 101 | } 102 | } 103 | } 104 | } 105 | 106 | [self setValue:localizedName forKey:@"_localizedName"]; 107 | return localizedName; 108 | } 109 | 110 | - (NSString *)atl_nameToDisplay { 111 | NSString *localizedName = [self atl_fastDisplayName]; 112 | 113 | if ([self.atl_bundleIdentifier rangeOfString:@"carplay" options:NSCaseInsensitiveSearch] 114 | .location != NSNotFound) { 115 | if ([localizedName rangeOfString:@"carplay" 116 | options:NSCaseInsensitiveSearch 117 | range:NSMakeRange(0, localizedName.length) 118 | locale:[NSLocale currentLocale]] 119 | .location == NSNotFound) { 120 | return [localizedName stringByAppendingString:@" (CarPlay)"]; 121 | } 122 | } 123 | 124 | return localizedName; 125 | } 126 | 127 | - (id)atl_bundleIdentifier { 128 | // iOS 8-14 129 | if ([self respondsToSelector:@selector(bundleIdentifier)]) { 130 | return [self bundleIdentifier]; 131 | } 132 | // iOS 7 133 | else { 134 | return [self applicationIdentifier]; 135 | } 136 | } 137 | 138 | - (NSString *)atl_shortVersionString { 139 | NSString *version = self.shortVersionString; 140 | if (version == nil || [version isEqualToString:@""]) { 141 | version = @"1.0"; 142 | } 143 | 144 | return version; 145 | } 146 | 147 | @end 148 | 149 | @implementation LSApplicationWorkspace (AltList) 150 | 151 | - (NSArray *)atl_allInstalledApplications { 152 | if (![self respondsToSelector:@selector(enumerateApplicationsOfType:block:)]) { 153 | return [self allInstalledApplications]; 154 | } 155 | 156 | NSMutableArray *installedApplications = [NSMutableArray new]; 157 | [self enumerateApplicationsOfType:0 158 | block:^(LSApplicationProxy *appProxy) { 159 | [installedApplications addObject:appProxy]; 160 | }]; 161 | [self enumerateApplicationsOfType:1 162 | block:^(LSApplicationProxy *appProxy) { 163 | [installedApplications addObject:appProxy]; 164 | }]; 165 | return installedApplications; 166 | } 167 | 168 | @end -------------------------------------------------------------------------------- /thirdparty/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 | -------------------------------------------------------------------------------- /thirdparty/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 | -------------------------------------------------------------------------------- /thirdparty/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 | -------------------------------------------------------------------------------- /RootViewController.m: -------------------------------------------------------------------------------- 1 | #import "RootViewController.h" 2 | #import "AppDuplicator.h" 3 | #import "AppList.h" 4 | #import "thirdparty/TDFileManagerViewController.h" 5 | #import "thirdparty/TDUtils.h" 6 | 7 | @implementation RootViewController 8 | 9 | - (void)loadView { 10 | [super loadView]; 11 | 12 | self.apps = appList(); 13 | self.duplicator = [[AppDuplicator alloc] init]; 14 | self.title = @"TrollAppDuplicator"; 15 | self.navigationController.navigationBar.prefersLargeTitles = YES; 16 | self.navigationItem.leftBarButtonItem = 17 | [[UIBarButtonItem alloc] initWithImage:[UIImage systemImageNamed:@"folder"] 18 | style:UIBarButtonItemStylePlain 19 | target:self 20 | action:@selector(openDocs:)]; 21 | self.navigationItem.rightBarButtonItem = 22 | [[UIBarButtonItem alloc] initWithImage:[UIImage systemImageNamed:@"info.circle"] 23 | style:UIBarButtonItemStylePlain 24 | target:self 25 | action:@selector(about:)]; 26 | 27 | UIRefreshControl *refreshControl = [[UIRefreshControl alloc] init]; 28 | [refreshControl addTarget:self action:@selector(refreshApps:) forControlEvents:UIControlEventValueChanged]; 29 | self.refreshControl = refreshControl; 30 | } 31 | 32 | - (void)openDocs:(id)sender { 33 | TDFileManagerViewController *fmVC = [[TDFileManagerViewController alloc] init]; 34 | UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:fmVC]; 35 | [self presentViewController:navController animated:YES completion:nil]; 36 | } 37 | 38 | - (void)about:(id)sender { 39 | UIAlertController *alert = 40 | [UIAlertController alertControllerWithTitle:@"TrollAppDuplicator" 41 | message:@"by zznQ\n" 42 | @"Inspired by TrollDecrypt(fiore)\n" 43 | preferredStyle:UIAlertControllerStyleAlert]; 44 | [alert addAction:[UIAlertAction actionWithTitle:@"Dismiss" 45 | style:UIAlertActionStyleCancel 46 | handler:nil]]; 47 | [self presentViewController:alert animated:YES completion:nil]; 48 | } 49 | 50 | - (void)refreshApps:(UIRefreshControl *)refreshControl { 51 | self.apps = appList(); 52 | [self.tableView reloadData]; 53 | [refreshControl endRefreshing]; 54 | } 55 | 56 | #pragma mark - Table view data source 57 | 58 | - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { 59 | return 1; 60 | } 61 | 62 | - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { 63 | return self.apps.count; 64 | } 65 | 66 | - (UITableViewCell *)tableView:(UITableView *)tableView 67 | cellForRowAtIndexPath:(NSIndexPath *)indexPath { 68 | static NSString *cellIdentifier = @"AppCell"; 69 | 70 | UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier]; 71 | if (cell == nil) 72 | cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle 73 | reuseIdentifier:cellIdentifier]; 74 | 75 | NSDictionary *app = self.apps[indexPath.row]; 76 | cell.textLabel.text = app[@"name"]; 77 | cell.detailTextLabel.text = 78 | [NSString stringWithFormat:@"%@ • %@", app[@"version"], app[@"bundleID"]]; 79 | cell.imageView.image = 80 | [UIImage _applicationIconImageForBundleIdentifier:app[@"bundleID"] 81 | format:iconFormat() 82 | scale:[UIScreen mainScreen].scale]; 83 | UILabel *tag = [[UILabel alloc] initWithFrame:CGRectMake(0, 0,50, 20)]; 84 | tag.textColor = [UIColor whiteColor]; 85 | tag.textAlignment = NSTextAlignmentCenter; 86 | tag.font = [UIFont systemFontOfSize:8]; 87 | tag.layer.cornerRadius = 10; 88 | tag.layer.masksToBounds = YES; 89 | 90 | 91 | if ([[app objectForKey:@"encrypted"] boolValue]){ 92 | tag.text = @"encrypted"; 93 | tag.textColor = [UIColor whiteColor]; 94 | tag.backgroundColor = [UIColor redColor]; // 设置背景颜色 95 | }else{ 96 | tag.text = @"decrypted"; 97 | tag.textColor = [UIColor blackColor]; 98 | tag.backgroundColor = [UIColor greenColor]; // 设置背景颜色 99 | } 100 | 101 | cell.accessoryView = tag; 102 | 103 | return cell; 104 | } 105 | 106 | - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { 107 | return 80.0f; 108 | } 109 | 110 | #pragma mark - Table view delegate 111 | 112 | - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { 113 | UIAlertController *alert; 114 | NSDictionary *app = self.apps[indexPath.row]; 115 | 116 | if ([[app objectForKey:@"encrypted"] boolValue]){ 117 | alert = [UIAlertController alertControllerWithTitle:@"Warning" 118 | message:[NSString stringWithFormat:@"The app must be decrypted first."] 119 | preferredStyle:UIAlertControllerStyleAlert]; 120 | }else{ 121 | alert = [UIAlertController alertControllerWithTitle:@"Duplicate" 122 | message:[NSString stringWithFormat:@"Duplicate %@?\n" 123 | @"Enter the name of the application here", app[@"name"]] 124 | preferredStyle:UIAlertControllerStyleAlert]; 125 | // 输入分身应用的名称 126 | [alert addTextFieldWithConfigurationHandler:^(UITextField *textField) { 127 | textField.text = app[@"name"]; 128 | }]; 129 | 130 | UIAlertAction *duplicate = [UIAlertAction actionWithTitle:@"Yes" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) { 131 | // 获取分身应用的名称 132 | NSString *appName = alert.textFields.firstObject.text; 133 | 134 | UIAlertController *loadingAlert = [UIAlertController alertControllerWithTitle:@"Duplicating" 135 | message:@"Please wait, this will take a few seconds..." 136 | preferredStyle:UIAlertControllerStyleAlert]; 137 | [self presentViewController:loadingAlert animated:YES completion:nil]; 138 | dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ 139 | NSString *ipa = [self.duplicator duplicateAppWithBundleID:app[@"path"] bundleID:app[@"bundleID"] name:appName]; 140 | // 切换回主线程更新 UI 141 | dispatch_async(dispatch_get_main_queue(), ^{ 142 | [loadingAlert dismissViewControllerAnimated:YES completion:^{ 143 | UIAlertController *completionAlert = [UIAlertController alertControllerWithTitle: @"Duplication Complete!" 144 | message:[NSString stringWithFormat: @"IPA file saved " @"to:\n%@", ipa] 145 | preferredStyle: UIAlertControllerStyleAlert]; 146 | [completionAlert addAction:[UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:nil]]; 147 | [self presentViewController: completionAlert animated:YES completion:nil]; 148 | }]; 149 | }); 150 | }); 151 | }]; 152 | 153 | [alert addAction:duplicate]; 154 | } 155 | 156 | UIAlertAction *cancel = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:nil]; 157 | [alert addAction:cancel]; 158 | 159 | [self presentViewController:alert animated:YES completion:nil]; 160 | [tableView deselectRowAtIndexPath:indexPath animated:YES]; 161 | } 162 | 163 | @end 164 | -------------------------------------------------------------------------------- /thirdparty/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 | -------------------------------------------------------------------------------- /thirdparty/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 | -------------------------------------------------------------------------------- /thirdparty/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 | -------------------------------------------------------------------------------- /thirdparty/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 | -------------------------------------------------------------------------------- /thirdparty/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 | -------------------------------------------------------------------------------- /thirdparty/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 | -------------------------------------------------------------------------------- /thirdparty/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 | -------------------------------------------------------------------------------- /thirdparty/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 | --------------------------------------------------------------------------------