├── .gitignore ├── COPYING ├── ExeIconReader ├── Base.lproj │ └── MainMenu.xib ├── EIExeIconView.h ├── EIExeIconView.m ├── EIMainWindowDelegate.h ├── EIMainWindowDelegate.m ├── EIVersionInfoTableDataSource.h ├── EIVersionInfoTableDataSource.m ├── EXEIconReader-Info.plist ├── EXEIconReader.xcodeproj │ ├── .LSOverride │ ├── project.pbxproj │ └── project.xcworkspace │ │ └── contents.xcworkspacedata ├── EXEIconReaderAppDelegate.h ├── EXEIconReaderAppDelegate.m ├── EXEIconReader_Prefix.pch ├── en.lproj │ └── InfoPlist.strings └── main.m ├── MicrosoftBinaries ├── GeneratePreviewForURL.m ├── GenerateThumbnailForURL.m ├── Info.plist ├── MicrosoftBinaries_Prefix.pch ├── PackageResources │ └── Scripts │ │ └── postinstall ├── PreviewTemplateMojave.html ├── QLWindowsApps.xcodeproj │ ├── project.pbxproj │ ├── project.xcworkspace │ │ └── contents.xcworkspacedata │ └── xcshareddata │ │ └── xcschemes │ │ └── QLWindowsApps.xcscheme ├── Utils.h ├── Utils.m ├── en.lproj │ └── VersioninfoNames.strings ├── it.lproj │ └── VersioninfoNames.strings └── main.c ├── OSXIcotools ├── OSXIcotools.xcodeproj │ └── project.pbxproj ├── OSXIcotools │ ├── EIExeFile.h │ ├── EIExeFile.m │ ├── EIVersionInfo.h │ ├── EIVersionInfo.m │ ├── OSXIcotools-Prefix.pch │ └── config.h ├── common │ ├── intutil.c │ ├── intutil.h │ ├── log.c │ └── log.h ├── icotool │ ├── win32-endian.c │ ├── win32-endian.h │ └── win32.h ├── lib │ ├── basename-lgpl.c │ ├── basename.c │ ├── byteswap.h │ ├── dirname-lgpl.c │ ├── dirname.c │ ├── dirname.h │ ├── dosname.h │ ├── gettext.h │ ├── minmax.h │ ├── xalloc-die.c │ ├── xalloc-oversized.h │ ├── xalloc.h │ ├── xasprintf.c │ ├── xmalloc.c │ ├── xsize.c │ ├── xsize.h │ ├── xstrndup.c │ ├── xstrndup.h │ ├── xvasprintf.c │ └── xvasprintf.h └── wrestool │ ├── extract.c │ ├── extract.h │ ├── fileread.c │ ├── fileread.h │ ├── osxwres.h │ ├── osxwres.m │ ├── restable.c │ ├── restable.h │ ├── restypes.c │ ├── restypes.h │ ├── wrestool.c │ └── wrestool.h ├── PackageResources ├── Distribution.xml └── Resources │ ├── gpl-3.0-standalone.html │ └── welcome.rtf ├── QLWindowsApps.xcworkspace ├── contents.xcworkspacedata └── xcshareddata │ ├── IDEWorkspaceChecks.plist │ └── WorkspaceSettings.xcsettings ├── README.md ├── WindowsAppsImporter ├── PackageResources │ └── Scripts │ │ └── postinstall ├── WindowsAppsImporter.xcodeproj │ ├── project.pbxproj │ ├── project.xcworkspace │ │ └── contents.xcworkspacedata │ └── xcshareddata │ │ └── xcschemes │ │ └── WindowsAppsImporter.xcscheme └── WindowsAppsImporter │ ├── GetMetadataForFile.m │ ├── Info.plist │ ├── en.lproj │ └── schema.strings │ ├── main.c │ └── schema.xml └── makepackage.sh /.gitignore: -------------------------------------------------------------------------------- 1 | # Xcode 2 | .DS_Store 3 | */build/* 4 | *.pbxuser 5 | !default.pbxuser 6 | *.mode1v3 7 | !default.mode1v3 8 | *.mode2v3 9 | !default.mode2v3 10 | *.perspectivev3 11 | !default.perspectivev3 12 | xcuserdata 13 | profile 14 | *.moved-aside 15 | DerivedData 16 | .idea/ 17 | *.hmap 18 | .com.apple.timemachine.supported 19 | testing_samples 20 | *.pkg 21 | build 22 | MicrosoftBinaries/style_tests 23 | -------------------------------------------------------------------------------- /ExeIconReader/EIExeIconView.h: -------------------------------------------------------------------------------- 1 | /* EIView.h 2 | * 3 | * Copyright (C) 2012 Daniele Cattaneo 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #import 20 | 21 | @class EIExeFile; 22 | 23 | 24 | @interface EIExeIconView : NSImageView { 25 | EIExeFile *exf; 26 | } 27 | 28 | - (void)setImageFromExe:(NSURL *)exefile; 29 | - (EIExeFile *)exeFile; 30 | 31 | @end 32 | -------------------------------------------------------------------------------- /ExeIconReader/EIExeIconView.m: -------------------------------------------------------------------------------- 1 | /* EIView.m 2 | * 3 | * Copyright (C) 2012 Daniele Cattaneo 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #import "EIExeIconView.h" 20 | #import "EIExeFile.h" 21 | #import "EIVersionInfo.h" 22 | #import "EIMainWindowDelegate.h" 23 | 24 | 25 | @implementation EIExeIconView 26 | 27 | 28 | - (void)setImageFromExe:(NSURL *)exefile 29 | { 30 | NSImage *icoImage; 31 | NSError *err; 32 | 33 | exf = [[EIExeFile alloc] initWithExeFileURL:exefile error:&err]; 34 | 35 | if (exf) { 36 | icoImage = [exf icon]; 37 | [self setImage:icoImage]; 38 | } else { 39 | [[self window] presentError:err]; 40 | } 41 | 42 | [self sendAction:[self action] to:[self target]]; 43 | } 44 | 45 | 46 | - (EIExeFile *)exeFile 47 | { 48 | return exf; 49 | } 50 | 51 | 52 | - (NSDragOperation)draggingEntered:(id )sender 53 | { 54 | if ((NSDragOperationGeneric & [sender draggingSourceOperationMask]) == NSDragOperationGeneric) 55 | return NSDragOperationCopy; 56 | else 57 | return NSDragOperationNone; 58 | } 59 | 60 | 61 | - (BOOL)performDragOperation:(id )sender 62 | { 63 | NSPasteboard *pboard; 64 | NSURL* finderUrl; 65 | 66 | pboard = [sender draggingPasteboard]; 67 | finderUrl = [NSURL URLFromPasteboard:pboard]; 68 | if (finderUrl == nil) return NO; 69 | 70 | [self setImageFromExe:finderUrl]; 71 | 72 | return YES; 73 | } 74 | 75 | 76 | @end 77 | -------------------------------------------------------------------------------- /ExeIconReader/EIMainWindowDelegate.h: -------------------------------------------------------------------------------- 1 | /* EIMainWindowDelegate.h 2 | * 3 | * Copyright (C) 2012 Daniele Cattaneo 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #import 20 | 21 | 22 | @interface EIMainWindowDelegate : NSObject { 23 | IBOutlet NSApplication *app; 24 | IBOutlet NSTableView *tableView; 25 | IBOutlet NSImageView *imageView; 26 | } 27 | 28 | - (BOOL)windowShouldClose:(id)sender; 29 | - (IBAction)takeExeFileValueFrom:(id)sender; 30 | 31 | @end 32 | -------------------------------------------------------------------------------- /ExeIconReader/EIMainWindowDelegate.m: -------------------------------------------------------------------------------- 1 | /* EIMainWindowDelegate.m 2 | * 3 | * Copyright (C) 2012 Daniele Cattaneo 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #import "EIMainWindowDelegate.h" 20 | #import "EIExeFile.h" 21 | #import "EIExeIconView.h" 22 | #import "EIVersionInfoTableDataSource.h" 23 | 24 | 25 | @implementation EIMainWindowDelegate 26 | 27 | 28 | - (BOOL)windowShouldClose:(id)sender 29 | { 30 | [app terminate:self]; 31 | return YES; 32 | } 33 | 34 | 35 | - (void)takeExeFileValueFrom:(id)sender 36 | { 37 | EIVersionInfoTableDataSource *ds; 38 | EIExeFile *exf; 39 | NSWorkspace *ws; 40 | 41 | exf = [sender exeFile]; 42 | 43 | ws = [NSWorkspace sharedWorkspace]; 44 | [ws setIcon:[imageView image] forFile:[[exf url] path] options:0]; 45 | [NSApp setApplicationIconImage:[imageView image]]; 46 | 47 | ds = [tableView dataSource]; 48 | [ds loadFromEIExeFile:exf]; 49 | [tableView reloadData]; 50 | } 51 | 52 | 53 | @end 54 | -------------------------------------------------------------------------------- /ExeIconReader/EIVersionInfoTableDataSource.h: -------------------------------------------------------------------------------- 1 | /* EIVersioninfoTableDS.h 2 | * 3 | * Copyright (C) 2012 Daniele Cattaneo 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #import 20 | #import "EIExeFile.h" 21 | 22 | 23 | @interface EIVersionInfoTableDataSource : NSObject { 24 | NSMutableArray* list; 25 | } 26 | 27 | - init; 28 | 29 | - (NSInteger)numberOfRowsInTableView:(NSTableView *)aTableView; 30 | - (id)tableView:(NSTableView *)aTableView objectValueForTableColumn:(NSTableColumn *)aTableColumn row:(NSInteger)rowIndex; 31 | 32 | - (void)loadFromVersionInfo:(EIVersionInfo*)vir; 33 | - (void)loadFromEIExeFile:(EIExeFile*)exfile; 34 | 35 | @end 36 | -------------------------------------------------------------------------------- /ExeIconReader/EIVersionInfoTableDataSource.m: -------------------------------------------------------------------------------- 1 | /* EIVersioninfoTableDS.m 2 | * 3 | * Copyright (C) 2012 Daniele Cattaneo 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #import "EIVersionInfoTableDataSource.h" 20 | #import "EIVersionInfo.h" 21 | 22 | 23 | @implementation EIVersionInfoTableDataSource 24 | 25 | 26 | - init 27 | { 28 | self = [super init]; 29 | list = nil; 30 | return self; 31 | } 32 | 33 | 34 | - (NSInteger)numberOfRowsInTableView:(NSTableView *)aTableView 35 | { 36 | return [list count]; 37 | } 38 | 39 | 40 | - (id)tableView:(NSTableView *)aTableView objectValueForTableColumn:(NSTableColumn *)aTableColumn row:(NSInteger)rowIndex 41 | { 42 | return [list objectAtIndex:rowIndex]; 43 | } 44 | 45 | 46 | - (void)loadFromVersionInfo:(EIVersionInfo*)vir 47 | { 48 | NSArray *resSrch; 49 | NSString *node, *keyPath, *value; 50 | 51 | list = [[NSMutableArray alloc] init]; 52 | 53 | resSrch = [vir querySubNodesUnder:@"\\StringFileInfo\\*" error:NULL]; 54 | 55 | for (node in resSrch) { 56 | keyPath = [NSString stringWithFormat:@"\\StringFileInfo\\*\\%@", node]; 57 | value = [vir queryStringValue:keyPath error:NULL]; 58 | if (value) 59 | [list addObject:[NSString stringWithFormat:@"%@: %@", node, value]]; 60 | } 61 | } 62 | 63 | 64 | - (void)loadFromEIExeFile:(EIExeFile*)exfile 65 | { 66 | [self loadFromVersionInfo:[exfile versionInfo]]; 67 | } 68 | 69 | 70 | @end 71 | -------------------------------------------------------------------------------- /ExeIconReader/EXEIconReader-Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBuildDate 6 | Sun Oct 19 18:15:32 CEST 2014 7 | CFBundleDevelopmentRegion 8 | English 9 | CFBundleExecutable 10 | ${EXECUTABLE_NAME} 11 | CFBundleIconFile 12 | 13 | CFBundleIdentifier 14 | $(PRODUCT_BUNDLE_IDENTIFIER) 15 | CFBundleInfoDictionaryVersion 16 | 6.0 17 | CFBundleName 18 | ${PRODUCT_NAME} 19 | CFBundlePackageType 20 | APPL 21 | CFBundleShortVersionString 22 | 0.2.0 23 | CFBundleSignature 24 | ???? 25 | CFBundleVersion 26 | 363 27 | LSMinimumSystemVersion 28 | ${MACOSX_DEPLOYMENT_TARGET} 29 | NSMainNibFile 30 | MainMenu 31 | NSPrincipalClass 32 | NSApplication 33 | 34 | 35 | -------------------------------------------------------------------------------- /ExeIconReader/EXEIconReader.xcodeproj/.LSOverride: -------------------------------------------------------------------------------- 1 | /Applications/Xcode.app -------------------------------------------------------------------------------- /ExeIconReader/EXEIconReader.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /ExeIconReader/EXEIconReaderAppDelegate.h: -------------------------------------------------------------------------------- 1 | /* EXEIconReaderAppDelegate.h 2 | * 3 | * Copyright (C) 2012 Daniele Cattaneo 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #import 20 | #import "EIExeIconView.h" 21 | 22 | 23 | @interface EXEIconReaderAppDelegate : NSObject 24 | 25 | @end 26 | -------------------------------------------------------------------------------- /ExeIconReader/EXEIconReaderAppDelegate.m: -------------------------------------------------------------------------------- 1 | /* EXEIconReaderAppDelegate.m 2 | * 3 | * Copyright (C) 2012 Daniele Cattaneo 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #import "EXEIconReaderAppDelegate.h" 20 | 21 | 22 | @implementation EXEIconReaderAppDelegate 23 | 24 | 25 | - (void)applicationDidFinishLaunching:(NSNotification *)aNotification 26 | { 27 | 28 | } 29 | 30 | 31 | @end 32 | -------------------------------------------------------------------------------- /ExeIconReader/EXEIconReader_Prefix.pch: -------------------------------------------------------------------------------- 1 | // 2 | // Prefix header for all source files of the 'EXEIconReader' target in the 'EXEIconReader' project 3 | // 4 | 5 | #ifdef __OBJC__ 6 | #import 7 | #endif 8 | 9 | -------------------------------------------------------------------------------- /ExeIconReader/en.lproj/InfoPlist.strings: -------------------------------------------------------------------------------- 1 | /* Localized versions of Info.plist keys */ 2 | 3 | -------------------------------------------------------------------------------- /ExeIconReader/main.m: -------------------------------------------------------------------------------- 1 | /* main.m 2 | * 3 | * Copyright (C) 2012 Daniele Cattaneo 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #import 20 | 21 | int main(int argc, char *argv[]) 22 | { 23 | return NSApplicationMain(argc, (const char **) argv); 24 | } 25 | -------------------------------------------------------------------------------- /MicrosoftBinaries/GeneratePreviewForURL.m: -------------------------------------------------------------------------------- 1 | /* GeneratePreviewForURL.m 2 | * 3 | * Copyright (C) 2012 Daniele Cattaneo 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | 20 | #include 21 | #include 22 | #include 23 | #import 24 | #import "EIExeFile.h" 25 | #import "EIVersionInfo.h" 26 | #import "Utils.h" 27 | 28 | 29 | NSString *QWAEscapeStringForHtml(NSString *str) 30 | { 31 | NSMutableString *res = [[NSMutableString alloc] init]; 32 | NSScanner *scan = [NSScanner scannerWithString:str]; 33 | NSCharacterSet *safe = [NSCharacterSet alphanumericCharacterSet]; 34 | [scan setCharactersToBeSkipped:nil]; 35 | 36 | while (![scan isAtEnd]) { 37 | NSString *tmp; 38 | if ([scan scanCharactersFromSet:safe intoString:&tmp]) 39 | [res appendString:tmp]; 40 | if ([scan scanUpToCharactersFromSet:safe intoString:&tmp]) { 41 | NSInteger n = [tmp length]; 42 | for (NSInteger i = 0; i < n; i++) { 43 | [res appendFormat:@"&#x%X;", [tmp characterAtIndex:i]]; 44 | } 45 | } 46 | } 47 | return [res copy]; 48 | } 49 | 50 | 51 | NSString *QWAGetTemplate(void) 52 | { 53 | NSBundle *mbundle; 54 | NSString *csspath; 55 | 56 | mbundle = [NSBundle bundleWithIdentifier:@"com.danielecattaneo.qlgenerator.qlwindowsapps"]; 57 | 58 | NSString *name = [QWAUserDefaults() objectForKey:@"StyleName"]; 59 | if ([name isKindOfClass:[NSString class]]) 60 | csspath = [mbundle pathForResource:name ofType:@"html"]; 61 | 62 | if (csspath == nil) { 63 | csspath = [mbundle pathForResource:@"PreviewTemplateMojave" ofType:@"html"]; 64 | } 65 | 66 | return [NSString stringWithContentsOfFile:csspath encoding:NSUTF8StringEncoding error:nil]; 67 | } 68 | 69 | 70 | NSString *QWAHTMLVersionInfoForExeFile(EIExeFile *exeFile) 71 | { 72 | NSMutableString *html; 73 | EIVersionInfo *vir; 74 | NSString* queryHeader; 75 | NSArray *resSrch; 76 | NSBundle *mbundle; 77 | NSString *value, *node, *vpath; 78 | 79 | mbundle = [NSBundle bundleWithIdentifier:@"com.danielecattaneo.qlgenerator.qlwindowsapps"]; 80 | html = [@"" mutableCopy]; 81 | vir = [exeFile versionInfo]; 82 | if (!vir) return @""; 83 | 84 | queryHeader = @"\\StringFileInfo\\*"; 85 | resSrch = [vir querySubNodesUnder:queryHeader error:NULL]; 86 | if (!resSrch) return @""; 87 | 88 | for (node in resSrch) { 89 | vpath = [NSString stringWithFormat:@"%@\\%@", queryHeader, node]; 90 | value = [vir queryStringValue:vpath error:NULL]; 91 | if (!value) continue; 92 | 93 | [html appendString:@""]; 94 | NSString *tmp = NSLocalizedStringFromTableInBundle(node, @"VersioninfoNames", mbundle, nil); 95 | [html appendString:QWAEscapeStringForHtml(tmp)]; 96 | [html appendString:@""]; 97 | [html appendString:QWAEscapeStringForHtml(value)]; 98 | [html appendString:@""]; 99 | } 100 | 101 | [html appendString:@""]; 102 | return html; 103 | } 104 | 105 | 106 | NSString *QWAGetImageSrcForExeFile(EIExeFile *exeFile, CFStringRef contentTypeUTI, NSURL *url) 107 | { 108 | NSData *image; 109 | NSString *mimetype; 110 | 111 | if (UTTypeEqual(contentTypeUTI, (CFStringRef)@"com.microsoft.windows-executable")) { 112 | image = [exeFile iconData]; 113 | mimetype = @"image/x-icon"; 114 | } 115 | if (!image) { 116 | NSImage *icon = [[NSWorkspace sharedWorkspace] iconForFile:[url path]]; 117 | NSRect proposedRect = NSMakeRect(0, 0, 512, 512); 118 | CGImageRef cgimg = [icon CGImageForProposedRect:&proposedRect context:NULL hints:nil]; 119 | NSBitmapImageRep *imgrep = [[NSBitmapImageRep alloc] initWithCGImage:cgimg]; 120 | image = [imgrep representationUsingType:NSBitmapImageFileTypePNG properties:@{}]; 121 | mimetype = @"image/png"; 122 | } 123 | NSString *base64 = [image base64EncodedStringWithOptions:0]; 124 | return [NSString stringWithFormat:@"data:%@;base64,%@", mimetype, base64]; 125 | } 126 | 127 | 128 | void QWAReplaceHtmlPlaceholders(NSMutableString *html, NSDictionary *ph) 129 | { 130 | NSRegularExpression *phregex, *nameregex; 131 | NSArray *phres, *nameres; 132 | 133 | phregex = [NSRegularExpression regularExpressionWithPattern: 134 | @"" options:0 error:nil]; 135 | nameregex = [NSRegularExpression regularExpressionWithPattern: 136 | @"@([A-Z]+)@" options:0 error:nil]; 137 | 138 | phres = [phregex matchesInString:html options:0 range:NSMakeRange(0, html.length)]; 139 | for (NSTextCheckingResult *phi in [phres reverseObjectEnumerator]) { 140 | NSRange crange = [phi rangeAtIndex:1]; 141 | NSMutableString *tag = [[html substringWithRange:crange] mutableCopy]; 142 | 143 | nameres = [nameregex matchesInString:tag options:0 range:NSMakeRange(0, tag.length)]; 144 | for (NSTextCheckingResult *name in [nameres reverseObjectEnumerator]) { 145 | NSRange nrange = [name rangeAtIndex:1]; 146 | NSString *repl = [ph objectForKey:[tag substringWithRange:nrange]]; 147 | if (repl) 148 | [tag replaceCharactersInRange:name.range withString:repl]; 149 | } 150 | 151 | [html replaceCharactersInRange:phi.range withString:tag]; 152 | } 153 | } 154 | 155 | 156 | void QWAGeneratePreviewForURL(QLPreviewRequestRef preview, NSURL *url, CFStringRef contentTypeUTI) 157 | { 158 | EIExeFile *exeFile; 159 | NSMutableString *html; 160 | NSDictionary *props; 161 | NSMutableDictionary *elem; 162 | NSString *icon; 163 | 164 | exeFile = [[EIExeFile alloc] initWithExeFileURL:url error:nil]; 165 | if (!exeFile) return; 166 | if (QLPreviewRequestIsCancelled(preview)) return; 167 | 168 | html = [QWAGetTemplate() mutableCopy]; 169 | elem = [NSMutableDictionary dictionary]; 170 | if (QLPreviewRequestIsCancelled(preview)) return; 171 | 172 | /* Icon */ 173 | icon = QWAGetImageSrcForExeFile(exeFile, contentTypeUTI, url); 174 | [elem setObject:icon forKey:@"ICON"]; 175 | if (QLPreviewRequestIsCancelled(preview)) return; 176 | 177 | /* File name and 16-bit badge */ 178 | [elem setObject:[NSString stringWithFormat:@"%d bit", [exeFile bitness]] forKey:@"BADGE"]; 179 | [elem setObject:QWAEscapeStringForHtml([url lastPathComponent]) forKey:@"NAME"]; 180 | 181 | /* Version info */ 182 | [elem setObject:QWAHTMLVersionInfoForExeFile(exeFile) forKey:@"TABLEBODY"]; 183 | 184 | /* Generate HTML */ 185 | QWAReplaceHtmlPlaceholders(html, elem); 186 | 187 | props = @{(NSString *)kQLPreviewPropertyTextEncodingNameKey : @"UTF-8", 188 | (NSString *)kQLPreviewPropertyMIMETypeKey : @"text/html"}; 189 | 190 | QLPreviewRequestSetDataRepresentation(preview, 191 | (__bridge CFDataRef)[html dataUsingEncoding:NSUTF8StringEncoding], kUTTypeHTML, 192 | (__bridge CFDictionaryRef)props); 193 | } 194 | 195 | 196 | /* ----------------------------------------------------------------------------- 197 | Generate a preview for file 198 | 199 | This function's job is to create preview for designated file 200 | ----------------------------------------------------------------------------- */ 201 | 202 | OSStatus GeneratePreviewForURL(void *thisInterface, QLPreviewRequestRef preview, 203 | CFURLRef url, CFStringRef contentTypeUTI, CFDictionaryRef options) 204 | { 205 | @autoreleasepool { 206 | QWAGeneratePreviewForURL(preview, (__bridge NSURL*)url, contentTypeUTI); 207 | } 208 | return noErr; 209 | } 210 | 211 | 212 | void CancelPreviewGeneration(void* thisInterface, QLPreviewRequestRef preview) 213 | { 214 | // implement only if supported 215 | } 216 | 217 | -------------------------------------------------------------------------------- /MicrosoftBinaries/GenerateThumbnailForURL.m: -------------------------------------------------------------------------------- 1 | /* GenerateThumbnailForURL.m 2 | * 3 | * Copyright (C) 2012 Daniele Cattaneo 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #include 20 | #include 21 | #include 22 | #import 23 | #import "EIExeFile.h" 24 | #import "Utils.h" 25 | 26 | 27 | #define MAX_NETWORK_PREVIEW ((1024*1024*5)) 28 | 29 | 30 | BOOL QWAIsFileOnNetworkDrive(NSURL *url) 31 | { 32 | NSURL *volume; 33 | NSNumber *local; 34 | 35 | if (![url getResourceValue:&volume forKey:NSURLVolumeURLKey error:nil]) 36 | return NO; 37 | 38 | if (![volume getResourceValue:&local forKey:NSURLVolumeIsLocalKey error:nil]) 39 | return NO; 40 | 41 | return ![local boolValue]; 42 | } 43 | 44 | 45 | void QWAGenerateThumbnailForURL(QLThumbnailRequestRef thumbnail, 46 | NSURL *url, CFStringRef contentTypeUTI, CGSize maxSize) 47 | { 48 | NSNumber *fsize; 49 | EIExeFile *exeFile; 50 | 51 | //No icon for DLLs 52 | if (!UTTypeEqual(contentTypeUTI, (CFStringRef)@"com.microsoft.windows-executable")) 53 | return; 54 | 55 | if (QWAIsFileOnNetworkDrive(url)) { 56 | if ([url getResourceValue:&fsize forKey:NSURLFileSizeKey error:nil]) { 57 | if ([fsize compare:@(MAX_NETWORK_PREVIEW)] == NSOrderedDescending) { 58 | NSLog(@"Canceled thumbnail of %@ because file is big and not local.", url); 59 | return; 60 | } 61 | } 62 | } 63 | 64 | exeFile = [[EIExeFile alloc] initWithExeFileURL:url error:nil]; 65 | if (!exeFile) return; 66 | if (QLThumbnailRequestIsCancelled(thumbnail)) return; 67 | 68 | NSData *iconData = [exeFile iconData]; 69 | if (!iconData) return; 70 | if (QLThumbnailRequestIsCancelled(thumbnail)) return; 71 | 72 | NSString *flavorKey; 73 | if (@available(macOS 10.15, *)) { 74 | flavorKey = (__bridge NSString *)kQLThumbnailPropertyIconFlavorKey_10_15; 75 | } else { 76 | flavorKey = (__bridge NSString *)kQLThumbnailPropertyIconFlavorKey_10_5; 77 | } 78 | 79 | CFDictionaryRef properties = (__bridge CFDictionaryRef)@{ 80 | flavorKey: @(kQLThumbnailIconPlainFlavor)}; 81 | QLThumbnailRequestSetImageWithData(thumbnail, (__bridge CFDataRef)iconData, properties); 82 | } 83 | 84 | 85 | /* ----------------------------------------------------------------------------- 86 | Generate a thumbnail for file 87 | 88 | This function's job is to create thumbnail for designated file as fast as possible 89 | ----------------------------------------------------------------------------- */ 90 | 91 | OSStatus GenerateThumbnailForURL(void *thisInterface, QLThumbnailRequestRef thumbnail, 92 | CFURLRef url, CFStringRef contentTypeUTI, CFDictionaryRef options, CGSize maxSize) 93 | { 94 | 95 | @autoreleasepool { 96 | QWAGenerateThumbnailForURL(thumbnail, (__bridge NSURL*)url, contentTypeUTI, maxSize); 97 | } 98 | return noErr; 99 | } 100 | 101 | 102 | void CancelThumbnailGeneration(void* thisInterface, QLThumbnailRequestRef thumbnail) 103 | { 104 | // implement only if supported 105 | } 106 | -------------------------------------------------------------------------------- /MicrosoftBinaries/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | English 7 | CFBundleDocumentTypes 8 | 9 | 10 | CFBundleTypeRole 11 | QLGenerator 12 | LSItemContentTypes 13 | 14 | com.microsoft.windows-executable 15 | com.microsoft.windows-dynamic-link-library 16 | 17 | 18 | 19 | CFBundleExecutable 20 | ${EXECUTABLE_NAME} 21 | CFBundleIdentifier 22 | $(PRODUCT_BUNDLE_IDENTIFIER) 23 | CFBundleInfoDictionaryVersion 24 | 6.0 25 | CFBundleName 26 | ${PRODUCT_NAME} 27 | CFBundleShortVersionString 28 | $(MARKETING_VERSION) 29 | CFBundleVersion 30 | 489 31 | CFPlugInDynamicRegisterFunction 32 | 33 | CFPlugInDynamicRegistration 34 | NO 35 | CFPlugInFactories 36 | 37 | D6780F7F-96D6-4CA0-9AB9-8542403043B6 38 | QuickLookGeneratorPluginFactory 39 | 40 | CFPlugInTypes 41 | 42 | 5E2D9680-5022-40FA-B806-43349622E5B9 43 | 44 | D6780F7F-96D6-4CA0-9AB9-8542403043B6 45 | 46 | 47 | CFPlugInUnloadFunction 48 | 49 | QLNeedsToBeRunInMainThread 50 | 51 | QLPreviewHeight 52 | 265 53 | QLPreviewWidth 54 | 795 55 | QLSupportsConcurrentRequests 56 | 57 | QLThumbnailMinimumSize 58 | 8 59 | 60 | 61 | -------------------------------------------------------------------------------- /MicrosoftBinaries/MicrosoftBinaries_Prefix.pch: -------------------------------------------------------------------------------- 1 | /* MicrosoftBinaries_Prefix.pch 2 | * 3 | * Copyright (C) 2012 Daniele Cattaneo 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #ifdef __OBJC__ 20 | #import 21 | #endif 22 | -------------------------------------------------------------------------------- /MicrosoftBinaries/PackageResources/Scripts/postinstall: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | /usr/bin/qlmanage -r 3 | /usr/bin/qlmanage -r cache 4 | exit 0 5 | -------------------------------------------------------------------------------- /MicrosoftBinaries/PreviewTemplateMojave.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 98 | 99 | 100 |
101 |
102 |
103 |
104 |

105 |
106 |
107 |
108 |
109 |
110 |
111 |
112 |
113 | 114 |
115 |
116 | 117 | 118 | -------------------------------------------------------------------------------- /MicrosoftBinaries/QLWindowsApps.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /MicrosoftBinaries/QLWindowsApps.xcodeproj/xcshareddata/xcschemes/QLWindowsApps.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 32 | 33 | 43 | 46 | 47 | 48 | 54 | 55 | 56 | 57 | 63 | 64 | 66 | 67 | 70 | 71 | 72 | -------------------------------------------------------------------------------- /MicrosoftBinaries/Utils.h: -------------------------------------------------------------------------------- 1 | /* Utils.h 2 | * 3 | * Copyright (C) 2016 Daniele Cattaneo 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #import 20 | 21 | 22 | /* Undocumented thumbnail properties 23 | * Credit to @Marginal */ 24 | 25 | extern const CFStringRef kQLThumbnailPropertyIconFlavorKey_10_5; 26 | extern const CFStringRef kQLThumbnailPropertyIconFlavorKey_10_15; 27 | 28 | typedef NS_ENUM(NSInteger, QLThumbnailIconFlavor) 29 | { 30 | kQLThumbnailIconPlainFlavor = 0, 31 | kQLThumbnailIconShadowFlavor = 1, 32 | kQLThumbnailIconBookFlavor = 2, 33 | kQLThumbnailIconMovieFlavor = 3, 34 | kQLThumbnailIconAddressFlavor = 4, 35 | kQLThumbnailIconImageFlavor = 5, 36 | kQLThumbnailIconGlossFlavor = 6, 37 | kQLThumbnailIconSlideFlavor = 7, 38 | kQLThumbnailIconSquareFlavor = 8, 39 | kQLThumbnailIconBorderFlavor = 9, 40 | // = 10, 41 | kQLThumbnailIconCalendarFlavor = 11, 42 | kQLThumbnailIconPatternFlavor = 12, 43 | }; 44 | 45 | 46 | NSUserDefaults *QWAUserDefaults(void); 47 | 48 | 49 | -------------------------------------------------------------------------------- /MicrosoftBinaries/Utils.m: -------------------------------------------------------------------------------- 1 | /* Utils.m 2 | * 3 | * Copyright (C) 2016 Daniele Cattaneo 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #import "Utils.h" 20 | 21 | 22 | const CFStringRef kQLThumbnailPropertyIconFlavorKey_10_5 = CFSTR("IconFlavor"); 23 | const CFStringRef kQLThumbnailPropertyIconFlavorKey_10_15 = CFSTR("icon"); 24 | 25 | 26 | NSUserDefaults *QWAUserDefaults() 27 | { 28 | static NSUserDefaults *pluginDefaults; 29 | static dispatch_once_t pluginDefaultsOt; 30 | 31 | dispatch_once(&pluginDefaultsOt, ^{ 32 | pluginDefaults = [[NSUserDefaults alloc] 33 | initWithSuiteName:@"com.danielecattaneo.qlgenerator.qlwindowsapps"]; 34 | }); 35 | return pluginDefaults; 36 | } 37 | 38 | -------------------------------------------------------------------------------- /MicrosoftBinaries/en.lproj/VersioninfoNames.strings: -------------------------------------------------------------------------------- 1 | /* VersioninfoNames.strings 2 | * 3 | * Copyright (C) 2012 Daniele Cattaneo 4 | * 5 | * You should have received a copy of the GNU General Public License 6 | * along with this program. If not, see . 7 | */ 8 | 9 | "Comments" = "Comments"; 10 | "CompanyName" = "Company Name"; 11 | "FileDescription" = "File Description"; 12 | "FileVersion" = "File Version"; 13 | "InternalName" = "Internal Name"; 14 | "LegalCopyright" = "Legal Copyright"; 15 | "LegalTrademarks" = "Legal Trademarks"; 16 | "OriginalFilename" = "Original Filename"; 17 | "PrivateBuild" = "Private Build"; 18 | "ProductName" = "Product Name"; 19 | "ProductVersion" = "Product Version"; 20 | "SpecialBuild" = "Special Build"; 21 | -------------------------------------------------------------------------------- /MicrosoftBinaries/it.lproj/VersioninfoNames.strings: -------------------------------------------------------------------------------- 1 | /* VersioninfoNames.strings 2 | * 3 | * Copyright (C) 2012 Daniele Cattaneo 4 | * 5 | * You should have received a copy of the GNU General Public License 6 | * along with this program. If not, see . 7 | */ 8 | 9 | "Comments" = "Commenti"; 10 | "CompanyName" = "Produttore"; 11 | "FileDescription" = "Descrizione File"; 12 | "FileVersion" = "Versione File"; 13 | "InternalName" = "Nome Interno"; 14 | "LegalCopyright" = "Copyright Legale"; 15 | "LegalTrademarks" = "Marchi Registrati"; 16 | "OriginalFilename" = "Nome originale del file"; 17 | "PrivateBuild" = "Build Privata"; 18 | "ProductName" = "Nome Prodotto"; 19 | "ProductVersion" = "Versione Prodotto"; 20 | "SpecialBuild" = "Build Speciale"; 21 | 22 | -------------------------------------------------------------------------------- /MicrosoftBinaries/main.c: -------------------------------------------------------------------------------- 1 | //============================================================================== 2 | // 3 | // DO NO MODIFY THE CONTENT OF THIS FILE 4 | // 5 | // This file contains the generic CFPlug-in code necessary for your generator 6 | // To complete your generator implement the function in GenerateThumbnailForURL/GeneratePreviewForURL.c 7 | // 8 | //============================================================================== 9 | 10 | 11 | 12 | 13 | 14 | 15 | #include 16 | #include 17 | #include 18 | #include 19 | 20 | // ----------------------------------------------------------------------------- 21 | // constants 22 | // ----------------------------------------------------------------------------- 23 | 24 | // Don't modify this line 25 | #define PLUGIN_ID "D6780F7F-96D6-4CA0-9AB9-8542403043B6" 26 | 27 | // 28 | // Below is the generic glue code for all plug-ins. 29 | // 30 | // You should not have to modify this code aside from changing 31 | // names if you decide to change the names defined in the Info.plist 32 | // 33 | 34 | 35 | // ----------------------------------------------------------------------------- 36 | // typedefs 37 | // ----------------------------------------------------------------------------- 38 | 39 | // The thumbnail generation function to be implemented in GenerateThumbnailForURL.c 40 | OSStatus GenerateThumbnailForURL(void *thisInterface, QLThumbnailRequestRef thumbnail, CFURLRef url, CFStringRef contentTypeUTI, CFDictionaryRef options, CGSize maxSize); 41 | void CancelThumbnailGeneration(void* thisInterface, QLThumbnailRequestRef thumbnail); 42 | 43 | // The preview generation function to be implemented in GeneratePreviewForURL.c 44 | OSStatus GeneratePreviewForURL(void *thisInterface, QLPreviewRequestRef preview, CFURLRef url, CFStringRef contentTypeUTI, CFDictionaryRef options); 45 | void CancelPreviewGeneration(void *thisInterface, QLPreviewRequestRef preview); 46 | 47 | // The layout for an instance of QuickLookGeneratorPlugIn 48 | typedef struct __QuickLookGeneratorPluginType 49 | { 50 | void *conduitInterface; 51 | CFUUIDRef factoryID; 52 | UInt32 refCount; 53 | } QuickLookGeneratorPluginType; 54 | 55 | // ----------------------------------------------------------------------------- 56 | // prototypes 57 | // ----------------------------------------------------------------------------- 58 | // Forward declaration for the IUnknown implementation. 59 | // 60 | 61 | QuickLookGeneratorPluginType *AllocQuickLookGeneratorPluginType(CFUUIDRef inFactoryID); 62 | void DeallocQuickLookGeneratorPluginType(QuickLookGeneratorPluginType *thisInstance); 63 | HRESULT QuickLookGeneratorQueryInterface(void *thisInstance,REFIID iid,LPVOID *ppv); 64 | void *QuickLookGeneratorPluginFactory(CFAllocatorRef allocator,CFUUIDRef typeID); 65 | ULONG QuickLookGeneratorPluginAddRef(void *thisInstance); 66 | ULONG QuickLookGeneratorPluginRelease(void *thisInstance); 67 | 68 | // ----------------------------------------------------------------------------- 69 | // myInterfaceFtbl definition 70 | // ----------------------------------------------------------------------------- 71 | // The QLGeneratorInterfaceStruct function table. 72 | // 73 | static QLGeneratorInterfaceStruct myInterfaceFtbl = { 74 | NULL, 75 | QuickLookGeneratorQueryInterface, 76 | QuickLookGeneratorPluginAddRef, 77 | QuickLookGeneratorPluginRelease, 78 | NULL, 79 | NULL, 80 | NULL, 81 | NULL 82 | }; 83 | 84 | 85 | // ----------------------------------------------------------------------------- 86 | // AllocQuickLookGeneratorPluginType 87 | // ----------------------------------------------------------------------------- 88 | // Utility function that allocates a new instance. 89 | // You can do some initial setup for the generator here if you wish 90 | // like allocating globals etc... 91 | // 92 | QuickLookGeneratorPluginType *AllocQuickLookGeneratorPluginType(CFUUIDRef inFactoryID) 93 | { 94 | QuickLookGeneratorPluginType *theNewInstance; 95 | 96 | theNewInstance = (QuickLookGeneratorPluginType *)malloc(sizeof(QuickLookGeneratorPluginType)); 97 | memset(theNewInstance,0,sizeof(QuickLookGeneratorPluginType)); 98 | 99 | /* Point to the function table Malloc enough to store the stuff and copy the filler from myInterfaceFtbl over */ 100 | theNewInstance->conduitInterface = malloc(sizeof(QLGeneratorInterfaceStruct)); 101 | memcpy(theNewInstance->conduitInterface,&myInterfaceFtbl,sizeof(QLGeneratorInterfaceStruct)); 102 | 103 | /* Retain and keep an open instance refcount for each factory. */ 104 | theNewInstance->factoryID = CFRetain(inFactoryID); 105 | CFPlugInAddInstanceForFactory(inFactoryID); 106 | 107 | /* This function returns the IUnknown interface so set the refCount to one. */ 108 | theNewInstance->refCount = 1; 109 | return theNewInstance; 110 | } 111 | 112 | // ----------------------------------------------------------------------------- 113 | // DeallocQuickLookGeneratorPluginType 114 | // ----------------------------------------------------------------------------- 115 | // Utility function that deallocates the instance when 116 | // the refCount goes to zero. 117 | // In the current implementation generator interfaces are never deallocated 118 | // but implement this as this might change in the future 119 | // 120 | void DeallocQuickLookGeneratorPluginType(QuickLookGeneratorPluginType *thisInstance) 121 | { 122 | CFUUIDRef theFactoryID; 123 | 124 | theFactoryID = thisInstance->factoryID; 125 | /* Free the conduitInterface table up */ 126 | free(thisInstance->conduitInterface); 127 | 128 | /* Free the instance structure */ 129 | free(thisInstance); 130 | if (theFactoryID){ 131 | CFPlugInRemoveInstanceForFactory(theFactoryID); 132 | CFRelease(theFactoryID); 133 | } 134 | } 135 | 136 | // ----------------------------------------------------------------------------- 137 | // QuickLookGeneratorQueryInterface 138 | // ----------------------------------------------------------------------------- 139 | // Implementation of the IUnknown QueryInterface function. 140 | // 141 | HRESULT QuickLookGeneratorQueryInterface(void *thisInstance,REFIID iid,LPVOID *ppv) 142 | { 143 | CFUUIDRef interfaceID; 144 | 145 | interfaceID = CFUUIDCreateFromUUIDBytes(kCFAllocatorDefault,iid); 146 | 147 | if (CFEqual(interfaceID,kQLGeneratorCallbacksInterfaceID)){ 148 | /* If the Right interface was requested, bump the ref count, 149 | * set the ppv parameter equal to the instance, and 150 | * return good status. 151 | */ 152 | ((QLGeneratorInterfaceStruct *)((QuickLookGeneratorPluginType *)thisInstance)->conduitInterface)->GenerateThumbnailForURL = GenerateThumbnailForURL; 153 | ((QLGeneratorInterfaceStruct *)((QuickLookGeneratorPluginType *)thisInstance)->conduitInterface)->CancelThumbnailGeneration = CancelThumbnailGeneration; 154 | ((QLGeneratorInterfaceStruct *)((QuickLookGeneratorPluginType *)thisInstance)->conduitInterface)->GeneratePreviewForURL = GeneratePreviewForURL; 155 | ((QLGeneratorInterfaceStruct *)((QuickLookGeneratorPluginType *)thisInstance)->conduitInterface)->CancelPreviewGeneration = CancelPreviewGeneration; 156 | ((QLGeneratorInterfaceStruct *)((QuickLookGeneratorPluginType*)thisInstance)->conduitInterface)->AddRef(thisInstance); 157 | *ppv = thisInstance; 158 | CFRelease(interfaceID); 159 | return S_OK; 160 | }else{ 161 | /* Requested interface unknown, bail with error. */ 162 | *ppv = NULL; 163 | CFRelease(interfaceID); 164 | return E_NOINTERFACE; 165 | } 166 | } 167 | 168 | // ----------------------------------------------------------------------------- 169 | // QuickLookGeneratorPluginAddRef 170 | // ----------------------------------------------------------------------------- 171 | // Implementation of reference counting for this type. Whenever an interface 172 | // is requested, bump the refCount for the instance. NOTE: returning the 173 | // refcount is a convention but is not required so don't rely on it. 174 | // 175 | ULONG QuickLookGeneratorPluginAddRef(void *thisInstance) 176 | { 177 | ((QuickLookGeneratorPluginType *)thisInstance )->refCount += 1; 178 | return ((QuickLookGeneratorPluginType*) thisInstance)->refCount; 179 | } 180 | 181 | // ----------------------------------------------------------------------------- 182 | // QuickLookGeneratorPluginRelease 183 | // ----------------------------------------------------------------------------- 184 | // When an interface is released, decrement the refCount. 185 | // If the refCount goes to zero, deallocate the instance. 186 | // 187 | ULONG QuickLookGeneratorPluginRelease(void *thisInstance) 188 | { 189 | ((QuickLookGeneratorPluginType*)thisInstance)->refCount -= 1; 190 | if (((QuickLookGeneratorPluginType*)thisInstance)->refCount == 0){ 191 | DeallocQuickLookGeneratorPluginType((QuickLookGeneratorPluginType*)thisInstance ); 192 | return 0; 193 | }else{ 194 | return ((QuickLookGeneratorPluginType*) thisInstance )->refCount; 195 | } 196 | } 197 | 198 | // ----------------------------------------------------------------------------- 199 | // QuickLookGeneratorPluginFactory 200 | // ----------------------------------------------------------------------------- 201 | void *QuickLookGeneratorPluginFactory(CFAllocatorRef allocator,CFUUIDRef typeID) 202 | { 203 | QuickLookGeneratorPluginType *result; 204 | CFUUIDRef uuid; 205 | 206 | /* If correct type is being requested, allocate an 207 | * instance of kQLGeneratorTypeID and return the IUnknown interface. 208 | */ 209 | if (CFEqual(typeID,kQLGeneratorTypeID)){ 210 | uuid = CFUUIDCreateFromString(kCFAllocatorDefault,CFSTR(PLUGIN_ID)); 211 | result = AllocQuickLookGeneratorPluginType(uuid); 212 | CFRelease(uuid); 213 | return result; 214 | } 215 | /* If the requested type is incorrect, return NULL. */ 216 | return NULL; 217 | } 218 | 219 | -------------------------------------------------------------------------------- /OSXIcotools/OSXIcotools/EIExeFile.h: -------------------------------------------------------------------------------- 1 | /* EIExeFile.h - Class tasked of representing a windows exe or dll and 2 | * its resource contents. 3 | * 4 | * Copyright (C) 2012-13 Daniele Cattaneo 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | #import 21 | #include "restypes.h" 22 | #include "osxwres.h" 23 | 24 | 25 | @class EIVersionInfo; 26 | 27 | 28 | @interface EIExeFile : NSObject { 29 | WinLibrary *fl; 30 | NSURL *url; 31 | } 32 | 33 | - (instancetype)initWithExeFileURL:(NSURL *)exeFile error:(NSError **)err; 34 | - (void)dealloc; 35 | 36 | - (NSImage *)icon; 37 | - (NSData *)iconData; 38 | - (EIVersionInfo *)versionInfo; 39 | - (NSURL *)url; 40 | - (int)bitness; 41 | 42 | @end 43 | -------------------------------------------------------------------------------- /OSXIcotools/OSXIcotools/EIExeFile.m: -------------------------------------------------------------------------------- 1 | /* EIExeFile.m - Class tasked of representing a windows exe or dll and 2 | * its resource contents. 3 | * 4 | * Copyright (C) 2012-13 Daniele Cattaneo 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | #import "EIExeFile.h" 21 | #import "EIVersionInfo.h" 22 | #include 23 | #include "wrestool.h" 24 | 25 | 26 | #ifdef DEBUG 27 | # define EILog(...) NSLog(__VA_ARGS__) 28 | #else 29 | # define EILog(...) 30 | #endif 31 | 32 | 33 | @implementation EIExeFile 34 | 35 | 36 | - (instancetype)initWithExeFileURL:(NSURL *)exeFile error:(NSError **)oerr 37 | { 38 | self = [super init]; 39 | if (!self) return nil; 40 | 41 | wres_error err; 42 | fl = new_winlibrary_from_file([exeFile fileSystemRepresentation], &err); 43 | if (!fl) { 44 | if (oerr) 45 | *oerr = nserror_from_wreserror(err); 46 | return nil; 47 | } 48 | 49 | return self; 50 | } 51 | 52 | 53 | - (void)logError:(wres_error)err 54 | { 55 | if (!fl) 56 | NSLog(@"%s", wres_strerr(err)); 57 | else if (err == WRES_ERROR_RESNOTFOUND) 58 | EILog(@"%s: %s", fl->name, wres_strerr(err)); 59 | else 60 | NSLog(@"%s: %s", fl->name, wres_strerr(err)); 61 | } 62 | 63 | 64 | - (NSData *)iconData 65 | { 66 | wres_error err; 67 | NSData *icodata = get_resource_data(fl, "14", NULL, NULL, &err); 68 | 69 | if (!icodata) { 70 | [self logError:err]; 71 | return nil; 72 | } 73 | return icodata; 74 | } 75 | 76 | 77 | - (NSImage*)icon 78 | { 79 | NSData *icodata = [self iconData]; 80 | if (!icodata) 81 | return nil; 82 | 83 | return [[NSImage alloc] initWithData:icodata]; 84 | } 85 | 86 | 87 | - (EIVersionInfo *)versionInfo 88 | { 89 | wres_error err; 90 | uint32_t sysLocale; 91 | NSString *localeIdent; 92 | char sysLocaleStr[64]; 93 | 94 | localeIdent = [[NSLocale currentLocale] localeIdentifier]; 95 | sysLocale = [NSLocale windowsLocaleCodeFromLocaleIdentifier:localeIdent]; 96 | 97 | sprintf(sysLocaleStr, "%d", sysLocale); 98 | //try with the current selected locale in the OS 99 | NSData *verdata = get_resource_data(fl, "16", NULL, sysLocaleStr, NULL); 100 | if (!verdata) { 101 | //if failure, try the en-US locale (the majority of apps, if they're not neutral, use this) 102 | verdata = get_resource_data(fl, "16", NULL, "1033", NULL); 103 | if (!verdata) { 104 | //else, pick the first locale we find, and go with it. 105 | verdata = get_resource_data(fl, "16", NULL, NULL, &err); 106 | if (!verdata) { 107 | [self logError:err]; 108 | return nil; 109 | } 110 | } 111 | } 112 | 113 | return [[EIVersionInfo alloc] initWithData:verdata is16Bit:(fl->binary_type == NE_BINARY)]; 114 | } 115 | 116 | 117 | - (NSURL *)url 118 | { 119 | return url; 120 | } 121 | 122 | 123 | - (int)bitness 124 | { 125 | static const int bitnesses[] = {16, 32, 64}; 126 | return bitnesses[fl->binary_type]; 127 | } 128 | 129 | 130 | - (void)dealloc 131 | { 132 | if (fl) 133 | free_winlibrary(fl); 134 | } 135 | 136 | 137 | @end 138 | -------------------------------------------------------------------------------- /OSXIcotools/OSXIcotools/EIVersionInfo.h: -------------------------------------------------------------------------------- 1 | /* EIVersionInfoReader.h - Class used to interpret VERSIONINFO structures 2 | * 3 | * Copyright (C) 2012-13 Daniele Cattaneo 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #import 20 | 21 | typedef enum { 22 | EIV_NOERR = 0, 23 | EIV_UNKNOWNNODE = 1, 24 | EIV_WRONGFORMAT = 2, 25 | EIV_WRONGDATA = 3 26 | } EIVERSION_ERR; 27 | 28 | 29 | @interface EIVersionInfo : NSObject { 30 | NSData* gBlock; 31 | BOOL win16Block; 32 | } 33 | 34 | - (instancetype)initWithData:(NSData *)myBlock is16Bit:(BOOL)win16; 35 | 36 | - (BOOL)is16bit; 37 | - (NSData *)data; 38 | 39 | - (NSData*)queryValue:(NSString*)subBlock error:(EIVERSION_ERR*)err; 40 | - (NSString *)queryStringValue:(NSString *)subBlock error:(EIVERSION_ERR *)err; 41 | - (NSArray*)querySubNodesUnder:(NSString*)subBlock error:(EIVERSION_ERR*)err; 42 | 43 | @end 44 | 45 | 46 | -------------------------------------------------------------------------------- /OSXIcotools/OSXIcotools/EIVersionInfo.m: -------------------------------------------------------------------------------- 1 | /* EIVersionInfoReader.m - Class used to interpret VERSIONINFO structures 2 | * 3 | * Copyright (C) 2012-13 Daniele Cattaneo 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | /* Thanks to Raymond Chen (MSFT) for the useful insight on the VERSIONINFO resource format. 20 | * http://blogs.msdn.com/b/oldnewthing/archive/2006/12/22/1348663.aspx (kludge) 21 | * http://blogs.msdn.com/b/oldnewthing/archive/2006/12/21/1340571.aspx (32 bit) 22 | * http://blogs.msdn.com/b/oldnewthing/archive/2006/12/20/1332035.aspx (16 bit) 23 | */ 24 | 25 | /* Note: -stringWithCharacters:length: in NSString (like 26 | * CFStringCreateWithCharacters, which is the function that actually does 27 | * the job under the hood) does NOT take a number of characters as length 28 | * parameter (as the documentation claims), but a number of CODE POINTS 29 | * (bytes / 2). */ 30 | 31 | #import "EIVersionInfo.h" 32 | 33 | 34 | #define PAD_TO_32BIT(x) (((void*)((x)) + ((4 - ((intptr_t)((x)) % 4)) % 4))) 35 | #define ERR_RET(x) {*err = ((x)); return nil;} 36 | #define CHECK_PTR(b, x, e) {if ((void*)(x) < (b) || (e) < (void*)(x)) ERR_RET(EIV_WRONGFORMAT);} 37 | 38 | 39 | typedef struct { 40 | int16_t cbNode; //Size of the node (a node includes its children) 41 | int16_t cbData; //Size of the data in the node 42 | int16_t wType; //1 if the node contains a string 43 | } VERSIONNODE_HEADER; 44 | 45 | typedef struct { 46 | int16_t cbNode; //Size of the node (a node includes its children) 47 | int16_t cbData; //Size of the data in the node 48 | } VERSIONNODE16_HEADER; 49 | 50 | 51 | /* Returns a number of code points */ 52 | int EIUTF16CheckedStringLen(const unichar* string, const unichar *maxptr, BOOL expectTerm) 53 | { 54 | const unichar *initial; 55 | 56 | for (initial = string; ((void*)string) + 1 < (void*)maxptr; string++) 57 | if (*string == '\0') 58 | return (int)(string - initial); 59 | return expectTerm ? -1 : (int)(string - initial); 60 | } 61 | 62 | 63 | int EICheckedStringLen(const char *str, const char *maxptr, BOOL expectTerm) 64 | { 65 | const char *initial; 66 | 67 | for (initial = str; str < maxptr; str++) 68 | if (*str == '\0') 69 | return (int)(str - initial); 70 | return expectTerm ? -1 : (int)(str - initial); 71 | } 72 | 73 | 74 | NSArray *EIRequestFromString(NSString *subBlock) 75 | { 76 | NSArray *request; 77 | NSString *tmp; 78 | 79 | if ([subBlock isEqual:@"\\"]) { 80 | request = [NSArray arrayWithObject:@"VS_VERSION_INFO"]; 81 | } else { 82 | tmp = [@"VS_VERSION_INFO" stringByAppendingString:subBlock]; 83 | request = [tmp componentsSeparatedByString:@"\\"]; 84 | } 85 | return request; 86 | } 87 | 88 | 89 | const VERSIONNODE_HEADER *EIResTreeIterateChildren32(NSData *block, EIVERSION_ERR *err, 90 | void (^callb)(BOOL *stop, NSString *name, const void *dataptr)) 91 | { 92 | BOOL found; 93 | const void *bb, *be; 94 | const VERSIONNODE_HEADER *vnh; 95 | const unichar *wszName; 96 | const void *dataptr; 97 | ssize_t nameLen; 98 | NSString *nodeName; 99 | 100 | vnh = bb = [block bytes]; 101 | be = bb + [block length]; 102 | *err = EIV_NOERR; 103 | 104 | wszName = (unichar *)(vnh + 1); 105 | 106 | found = NO; 107 | while ((void*)vnh < be) { 108 | nameLen = EIUTF16CheckedStringLen(wszName, be, YES); 109 | if (nameLen < 0) 110 | ERR_RET(EIV_WRONGFORMAT); 111 | 112 | nodeName = [NSString stringWithCharacters:wszName length:nameLen]; 113 | dataptr = PAD_TO_32BIT((void*)(wszName + nameLen + 1)); 114 | 115 | callb(&found, nodeName, dataptr); 116 | if (found) 117 | return vnh; 118 | 119 | vnh = PAD_TO_32BIT((void*)vnh + vnh->cbNode); 120 | wszName = (const unichar*)(vnh + 1); 121 | } 122 | return NULL; 123 | } 124 | 125 | 126 | NSData *EIResTreeRead32(NSArray *path, int level, NSData *block, 127 | EIVERSION_ERR *err, BOOL getChildren) 128 | { 129 | const VERSIONNODE_HEADER *vnh; 130 | ssize_t subtreeLen; 131 | const void __block *dataptr; 132 | const void *nextptr; 133 | NSString *nodeToRead; 134 | NSData *nodeData; 135 | 136 | nodeToRead = [path objectAtIndex:level]; 137 | vnh = EIResTreeIterateChildren32(block, err, ^(BOOL *stop, NSString *name, const void *dp) { 138 | dataptr = dp; 139 | *stop = [name caseInsensitiveCompare:nodeToRead] == NSOrderedSame || 140 | [@"*" isEqual:nodeToRead]; 141 | }); 142 | if (*err) 143 | return NULL; 144 | if (!vnh) 145 | ERR_RET(EIV_UNKNOWNNODE); 146 | 147 | nextptr = PAD_TO_32BIT(dataptr + vnh->cbData); //pointer to first child node 148 | subtreeLen = ((void*)vnh + vnh->cbNode) - nextptr; 149 | 150 | CHECK_PTR([block bytes], nextptr + subtreeLen - 1, [block bytes] + [block length]); 151 | 152 | /* If we're at the node we want to return, return it */ 153 | if ([path count] == level + 1) { 154 | if (getChildren) { 155 | return [NSData dataWithBytes:nextptr length:subtreeLen]; 156 | } else { 157 | /* Right after the transition to Unicode version strings many resource 158 | * compilers had a bug where the cbData is interpreted as a character 159 | * count, not as a byte count as it should be.*/ 160 | if (vnh->wType == 1 && level == 3) 161 | if (nextptr - (void*)vnh < vnh->cbNode) 162 | return [NSData dataWithBytes:dataptr length:vnh->cbData * 2]; 163 | return [NSData dataWithBytes:dataptr length:vnh->cbData]; 164 | } 165 | } 166 | 167 | /* Otherwise recurse into this node's children */ 168 | nodeData = [NSData dataWithBytesNoCopy:(void*)nextptr length:subtreeLen freeWhenDone:NO]; 169 | return EIResTreeRead32(path, level+1, nodeData, err, getChildren); 170 | } 171 | 172 | 173 | const VERSIONNODE16_HEADER *EIResTreeIterateChildren16(NSData *block, EIVERSION_ERR *err, 174 | void (^callb)(BOOL *stop, NSString *name, const void *dataptr)) 175 | { 176 | BOOL found; 177 | const void *bb, *be; 178 | const VERSIONNODE16_HEADER *vnh; 179 | const char *wszName; 180 | ssize_t sl; 181 | const void *dataptr; 182 | NSString *nodeName; 183 | 184 | vnh = bb = [block bytes]; 185 | be = bb + [block length]; 186 | *err = EIV_NOERR; 187 | 188 | wszName = (char*)(vnh + 1); 189 | 190 | found = NO; 191 | while ((void*)vnh < be) { 192 | sl = EICheckedStringLen(wszName, be, YES); 193 | if (sl < 0) 194 | ERR_RET(EIV_WRONGFORMAT); 195 | 196 | nodeName = [NSString stringWithCString:wszName encoding:NSWindowsCP1252StringEncoding]; 197 | dataptr = PAD_TO_32BIT(wszName + [nodeName length] + 1); 198 | 199 | callb(&found, nodeName, dataptr); 200 | if (found) 201 | return vnh; 202 | 203 | vnh = PAD_TO_32BIT((void*)vnh + vnh->cbNode); 204 | wszName = (const char*)(vnh + 1); 205 | } 206 | return NULL; 207 | } 208 | 209 | 210 | NSData *EIResTreeRead16(NSArray *path, int level, NSData* block, 211 | EIVERSION_ERR *err, BOOL getChildren) 212 | { 213 | const VERSIONNODE16_HEADER *vnh; 214 | ssize_t subtreeLen; 215 | const void __block *dataptr; 216 | const void *nextptr; 217 | NSString *nodeToRead; 218 | NSData *nodeData; 219 | 220 | nodeToRead = [path objectAtIndex:level]; 221 | 222 | vnh = EIResTreeIterateChildren16(block, err, ^(BOOL *stop, NSString *name, const void *dp) { 223 | dataptr = dp; 224 | *stop = [name caseInsensitiveCompare:nodeToRead] == NSOrderedSame || 225 | [@"*" isEqual:nodeToRead]; 226 | }); 227 | if (*err) 228 | return NULL; 229 | if (!vnh) 230 | ERR_RET(EIV_UNKNOWNNODE); 231 | 232 | nextptr = PAD_TO_32BIT(dataptr + vnh->cbData); //pointer to first child node 233 | subtreeLen = ((void*)vnh + vnh->cbNode) - nextptr; 234 | 235 | CHECK_PTR([block bytes], nextptr + subtreeLen - 1, [block bytes] + [block length]); 236 | 237 | /* If we're at the node we want to return, return it */ 238 | if ([path count] == level + 1) { 239 | if (getChildren) 240 | return [NSData dataWithBytes:nextptr length:subtreeLen]; 241 | return [NSData dataWithBytes:dataptr length:vnh->cbData]; 242 | } 243 | 244 | /* Otherwise recurse into this node's children */ 245 | nodeData = [NSData dataWithBytesNoCopy:(void*)nextptr length:subtreeLen freeWhenDone:NO]; 246 | return EIResTreeRead16(path, level+1, nodeData, err, getChildren); 247 | } 248 | 249 | 250 | @implementation EIVersionInfo 251 | 252 | 253 | - (instancetype)initWithData:(NSData *)myBlock is16Bit:(BOOL)win16 254 | { 255 | gBlock = myBlock; 256 | win16Block = win16; 257 | return [super init]; 258 | } 259 | 260 | 261 | - (BOOL)is16bit 262 | { 263 | return win16Block; 264 | } 265 | 266 | 267 | - (NSData *)data 268 | { 269 | return gBlock; 270 | } 271 | 272 | 273 | - (NSString *)queryStringValue:(NSString *)subBlock error:(EIVERSION_ERR *)err 274 | { 275 | NSData *raw; 276 | const void *bytes; 277 | int l; 278 | 279 | raw = [self queryValue:subBlock error:err]; 280 | if (!raw) 281 | return nil; 282 | bytes = [raw bytes]; 283 | 284 | if (win16Block) { 285 | l = EICheckedStringLen(bytes, (const char *)(bytes + [raw length]), NO); 286 | return [[NSString alloc] initWithBytes:bytes length:l 287 | encoding:NSWindowsCP1252StringEncoding]; 288 | } 289 | 290 | l = EIUTF16CheckedStringLen(bytes, (const unichar *)(bytes + [raw length]), NO); 291 | return [NSString stringWithCharacters:bytes length:l]; 292 | } 293 | 294 | 295 | // Like VerQueryValue(pBlock, lpSubBlock, lplpBuffer, puLen); 296 | - (NSData *)queryValue:(NSString *)subBlock error:(EIVERSION_ERR *)err 297 | { 298 | NSData *res; 299 | EIVERSION_ERR rerr = EIV_NOERR; 300 | 301 | if (win16Block) 302 | res = EIResTreeRead16(EIRequestFromString(subBlock), 0, gBlock, &rerr, NO); 303 | else 304 | res = EIResTreeRead32(EIRequestFromString(subBlock), 0, gBlock, &rerr, NO); 305 | if (!res && err) 306 | *err = rerr; 307 | return res; 308 | } 309 | 310 | 311 | - (NSArray *)querySubNodesUnder:(NSString *)subBlock error:(EIVERSION_ERR *)err 312 | { 313 | NSArray *res; 314 | EIVERSION_ERR rerr = EIV_NOERR; 315 | 316 | if (win16Block) 317 | res = [self _query16BitSubNodesUnder:subBlock error:&rerr]; 318 | else 319 | res = [self _query32BitSubNodesUnder:subBlock error:&rerr]; 320 | if (!res && err) 321 | *err = rerr; 322 | return res; 323 | } 324 | 325 | 326 | - (NSArray *)_query16BitSubNodesUnder:(NSString *)subBlock error:(EIVERSION_ERR *)err 327 | { 328 | NSData *queryNode; 329 | NSMutableArray *nodeArray; 330 | 331 | queryNode = EIResTreeRead16(EIRequestFromString(subBlock), 0, gBlock, err, YES); 332 | if (*err) 333 | return nil; 334 | 335 | nodeArray = [NSMutableArray array]; 336 | EIResTreeIterateChildren16(queryNode, err, ^(BOOL *stop, NSString *name, const void *dataptr) { 337 | [nodeArray addObject:name]; 338 | }); 339 | if (*err) 340 | return nil; 341 | 342 | return [nodeArray copy]; 343 | } 344 | 345 | 346 | - (NSArray *)_query32BitSubNodesUnder:(NSString *)subBlock error:(EIVERSION_ERR *)err 347 | { 348 | NSData *queryNode; 349 | NSMutableArray *nodeArray; 350 | 351 | queryNode = EIResTreeRead32(EIRequestFromString(subBlock), 0, gBlock, err, YES); 352 | if (*err) 353 | return nil; 354 | 355 | nodeArray = [NSMutableArray array]; 356 | EIResTreeIterateChildren32(queryNode, err, ^(BOOL *stop, NSString *name, const void *dataptr) { 357 | [nodeArray addObject:name]; 358 | }); 359 | if (*err) 360 | return nil; 361 | 362 | return [nodeArray copy]; 363 | } 364 | 365 | 366 | @end 367 | -------------------------------------------------------------------------------- /OSXIcotools/OSXIcotools/OSXIcotools-Prefix.pch: -------------------------------------------------------------------------------- 1 | // 2 | // Prefix header for all source files of the 'OSXIcotools' target in the 'OSXIcotools' project 3 | // 4 | 5 | #ifdef __OBJC__ 6 | #import 7 | #endif 8 | 9 | -------------------------------------------------------------------------------- /OSXIcotools/common/intutil.c: -------------------------------------------------------------------------------- 1 | /* intutil.c - Integer utility functions. 2 | * 3 | * Copyright (C) 2001 Oskar Liljeblad 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #include 20 | #include /* Gnulib/C99 */ 21 | #include /* Gnulib/C89 */ 22 | #include /* Gnulib/? */ 23 | #include "intutil.h" /* common */ 24 | 25 | /* These are probably used very seldom, so they are disabled. */ 26 | #if 0 27 | INT_STR_FUNC(uintptr_str, uintptr_t, PRIuPTR); 28 | INT_STR_FUNC(intptr_str, intptr_t, PRIiPTR); 29 | INT_STR_FUNC(uintmax_str, uintmax_t, PRIuMAX); 30 | INT_STR_FUNC(intmax_str, intmax_t, PRIiMAX); 31 | INT_STR_FUNC(uintptr_octstr, uintptr_t, PRIoPTR); 32 | INT_STR_FUNC(uintmax_octstr, uintmax_t, PRIoMAX); 33 | INT_STR_FUNC(uint64_octstr, uint64_t, PRIo64); 34 | INT_STR_FUNC(uint32_octstr, uint32_t, PRIo32); 35 | INT_STR_FUNC(uint16_octstr, uint16_t, PRIo16); 36 | INT_STR_FUNC(uint8_octstr, uint8_t, PRIo8); 37 | INT_STR_FUNC(uintptr_hexstr, uintptr_t, PRIxPTR); 38 | INT_STR_FUNC(uintmax_hexstr, uintmax_t, PRIxMAX); 39 | INT_STR_FUNC(uint64_hexstr, uint64_t, PRIx64); 40 | INT_STR_FUNC(uint32_hexstr, uint32_t, PRIx32); 41 | INT_STR_FUNC(uint16_hexstr, uint16_t, PRIx16); 42 | INT_STR_FUNC(uint8_hexstr, uint8_t, PRIx8); 43 | INT_STR_FUNC(uintptr_hexustr, uintptr_t, PRIXPTR); 44 | INT_STR_FUNC(uintmax_hexustr, uintmax_t, PRIXMAX); 45 | INT_STR_FUNC(uint64_hexustr, uint64_t, PRIX64); 46 | INT_STR_FUNC(uint32_hexustr, uint32_t, PRIX32); 47 | INT_STR_FUNC(uint16_hexustr, uint16_t, PRIX16); 48 | INT_STR_FUNC(uint8_hexustr, uint8_t, PRIX8); 49 | #endif 50 | 51 | bool 52 | parse_int8(const char *instr, int8_t *outint) 53 | { 54 | int8_t value = 0; 55 | 56 | if (*instr == '-') { 57 | if (instr[1] == '\0') 58 | return false; 59 | for (instr++; *instr != '\0'; instr++) { 60 | int8_t c = *instr - '0'; 61 | if (c < 0 || c > 9) 62 | return false; 63 | if (value < INT8_MIN/10 || (value == INT8_MIN/10 && c > -(INT8_MIN%10))) 64 | return false; 65 | value = value*10 - c; 66 | } 67 | } else { 68 | if (*instr == '\0') 69 | return false; 70 | for (; *instr != '\0'; instr++) { 71 | int8_t c = *instr - '0'; 72 | if (c < 0 || c > 9) 73 | return false; 74 | if (value > INT8_MAX/10 || (value == INT8_MAX/10 && c > INT8_MAX%10)) 75 | return false; 76 | value = value*10 + c; 77 | } 78 | } 79 | *outint = value; 80 | 81 | return true; 82 | } 83 | 84 | bool 85 | parse_int16(const char *instr, int16_t *outint) 86 | { 87 | int16_t value = 0; 88 | 89 | if (*instr == '-') { 90 | if (instr[1] == '\0') 91 | return false; 92 | for (instr++; *instr != '\0'; instr++) { 93 | int8_t c = *instr - '0'; 94 | if (c < 0 || c > 9) 95 | return false; 96 | if (value < INT16_MIN/10 || (value == INT16_MIN/10 && c > -(INT16_MIN%10))) 97 | return false; 98 | value = value*10 - c; 99 | } 100 | } else { 101 | if (*instr == '\0') 102 | return false; 103 | for (; *instr != '\0'; instr++) { 104 | int8_t c = *instr - '0'; 105 | if (c < 0 || c > 9) 106 | return false; 107 | if (value > INT16_MAX/10 || (value == INT16_MAX/10 && c > INT16_MAX%10)) 108 | return false; 109 | value = value*10 + c; 110 | } 111 | } 112 | *outint = value; 113 | 114 | return true; 115 | } 116 | 117 | bool 118 | parse_int32(const char *instr, int32_t *outint) 119 | { 120 | int32_t value = 0; 121 | 122 | if (*instr == '-') { 123 | if (instr[1] == '\0') 124 | return false; 125 | for (instr++; *instr != '\0'; instr++) { 126 | int8_t c = *instr - '0'; 127 | if (c < 0 || c > 9) 128 | return false; 129 | if (value < INT32_MIN/10L || (value == INT32_MIN/10L && c > -(INT32_MIN%10L))) 130 | return false; 131 | value = value*10L - c; 132 | } 133 | } else { 134 | if (*instr == '\0') 135 | return false; 136 | for (; *instr != '\0'; instr++) { 137 | int8_t c = *instr - '0'; 138 | if (c < 0 || c > 9) 139 | return false; 140 | if (value > INT32_MAX/10L || (value == INT32_MAX/10L && c > INT32_MAX%10L)) 141 | return false; 142 | value = value*10L + c; 143 | } 144 | } 145 | *outint = value; 146 | 147 | return true; 148 | } 149 | 150 | bool 151 | parse_int64(const char *instr, int64_t *outint) 152 | { 153 | int64_t value = 0; 154 | 155 | if (*instr == '-') { 156 | if (instr[1] == '\0') 157 | return false; 158 | for (instr++; *instr != '\0'; instr++) { 159 | int8_t c = *instr - '0'; 160 | if (c < 0 || c > 9) 161 | return false; 162 | if (value < INT64_MIN/10LL || (value == INT64_MIN/10LL && c > -(INT64_MIN%10LL))) 163 | return false; 164 | value = value*10LL - c; 165 | } 166 | } else { 167 | if (*instr == '\0') 168 | return false; 169 | for (; *instr != '\0'; instr++) { 170 | int8_t c = *instr - '0'; 171 | if (c < 0 || c > 9) 172 | return false; 173 | if (value > INT64_MAX/10LL || (value == INT64_MAX/10LL && c > INT64_MAX%10LL)) 174 | return false; 175 | value = value*10LL + c; 176 | } 177 | } 178 | *outint = value; 179 | 180 | return true; 181 | } 182 | 183 | bool 184 | parse_uint8(const char *instr, uint8_t *outint) 185 | { 186 | uint8_t value = 0; 187 | 188 | for (; *instr != '\0'; instr++) { 189 | uint8_t c = *instr - '0'; 190 | if (c > 9) 191 | return false; 192 | if (value > UINT8_MAX/10 || (value == UINT8_MAX/10 && c > UINT8_MAX%10)) 193 | return false; 194 | value = value*10 + c; 195 | } 196 | *outint = value; 197 | 198 | return true; 199 | } 200 | 201 | bool 202 | parse_uint16(const char *instr, uint16_t *outint) 203 | { 204 | uint16_t value = 0; 205 | 206 | for (; *instr != '\0'; instr++) { 207 | uint8_t c = *instr - '0'; 208 | if (c > 9) 209 | return false; 210 | if (value > UINT16_MAX/10 || (value == UINT16_MAX/10 && c > UINT16_MAX%10)) 211 | return false; 212 | value = value*10 + c; 213 | } 214 | *outint = value; 215 | 216 | return true; 217 | } 218 | 219 | bool 220 | parse_uint32(const char *instr, uint32_t *outint) 221 | { 222 | uint32_t value = 0; 223 | 224 | for (; *instr != '\0'; instr++) { 225 | uint8_t c = *instr - '0'; 226 | if (c > 9) 227 | return false; 228 | if (value > UINT32_MAX/10L || (value == UINT32_MAX/10L && c > UINT32_MAX%10)) 229 | return false; 230 | value = value*10L + c; 231 | } 232 | *outint = value; 233 | 234 | return true; 235 | } 236 | 237 | bool 238 | parse_uint64(const char *instr, uint64_t *outint) 239 | { 240 | uint64_t value = 0; 241 | 242 | for (; *instr != '\0'; instr++) { 243 | uint8_t c = *instr - '0'; 244 | if (c > 9) 245 | return false; 246 | if (value > UINT64_MAX/10LL || (value == UINT64_MAX/10LL && c > UINT64_MAX%10LL)) 247 | return false; 248 | value = value*10LL + c; 249 | } 250 | *outint = value; 251 | 252 | return true; 253 | } 254 | -------------------------------------------------------------------------------- /OSXIcotools/common/intutil.h: -------------------------------------------------------------------------------- 1 | /* intutil.c - Integer utility functions. 2 | * 3 | * Copyright (C) 2001 Oskar Liljeblad 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #ifndef COMMON_INTUTIL_H 20 | #define COMMON_INTUTIL_H 21 | 22 | #include /* Gnulib/C99/POSIX */ 23 | #include /* Gnulib/C99/POSIX */ 24 | 25 | bool parse_int8(const char *instr, int8_t *outint); 26 | bool parse_int16(const char *instr, int16_t *outint); 27 | bool parse_int32(const char *instr, int32_t *outint); 28 | bool parse_int64(const char *instr, int64_t *outint); 29 | bool parse_uint8(const char *instr, uint8_t *outint); 30 | bool parse_uint16(const char *instr, uint16_t *outint); 31 | bool parse_uint32(const char *instr, uint32_t *outint); 32 | bool parse_uint64(const char *instr, uint64_t *outint); 33 | 34 | #endif 35 | -------------------------------------------------------------------------------- /OSXIcotools/common/log.c: -------------------------------------------------------------------------------- 1 | /* log.c - Messaging routines. 2 | * 3 | * Copyright (C) 2017 Daniele Cattaneo 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #include 20 | #include 21 | #include "log.h" 22 | 23 | 24 | void log_msg(int level, const char *msg, ...) 25 | { 26 | va_list ap; 27 | 28 | #ifdef DEBUG 29 | int minlev = LOG_LEVEL_DEBUG; 30 | #else 31 | int minlev = LOG_LEVEL_CRITICAL; 32 | #endif 33 | 34 | if (level >= minlev) { 35 | va_start(ap, msg); 36 | vfprintf(stderr, msg, ap); 37 | va_end(ap); 38 | } 39 | } 40 | 41 | -------------------------------------------------------------------------------- /OSXIcotools/common/log.h: -------------------------------------------------------------------------------- 1 | /* log.h - Messaging routines. 2 | * 3 | * Copyright (C) 2017 Daniele Cattaneo 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #ifndef LOG_H 20 | #define LOG_H 21 | 22 | #define LOG_LEVEL_DEBUG (0) 23 | #define LOG_LEVEL_CRITICAL (1) 24 | 25 | void log_msg(int level, const char *msg, ...); 26 | 27 | #define dbg_log(...) log_msg(LOG_LEVEL_DEBUG, __VA_ARGS__) 28 | #define crit_log(...) log_msg(LOG_LEVEL_NORMAL, __VA_ARGS__) 29 | 30 | #endif 31 | -------------------------------------------------------------------------------- /OSXIcotools/icotool/win32-endian.c: -------------------------------------------------------------------------------- 1 | /* win32-endian.c - Correcting endian-ness of data loaded to memory 2 | * 3 | * Copyright (C) 1998 Oskar Liljeblad 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #include 20 | #include "win32-endian.h" 21 | 22 | #include /* Gnulib */ 23 | #define BSWAP16(x) ((x) = bswap_16(x)) 24 | #define BSWAP32(x) ((x) = bswap_32(x)) 25 | 26 | #if WORDS_BIGENDIAN 27 | 28 | void 29 | fix_win32_cursor_icon_file_dir_endian(Win32CursorIconFileDir *obj) 30 | { 31 | BSWAP16(obj->reserved); 32 | BSWAP16(obj->type); 33 | BSWAP16(obj->count); 34 | } 35 | 36 | void 37 | fix_win32_bitmap_info_header_endian(Win32BitmapInfoHeader *obj) 38 | { 39 | BSWAP32(obj->size); 40 | BSWAP32(obj->width); 41 | BSWAP32(obj->height); 42 | BSWAP16(obj->planes); 43 | BSWAP16(obj->bit_count); 44 | BSWAP32(obj->compression); 45 | BSWAP32(obj->size_image); 46 | BSWAP32(obj->x_pels_per_meter); 47 | BSWAP32(obj->y_pels_per_meter); 48 | BSWAP32(obj->clr_used); 49 | BSWAP32(obj->clr_important); 50 | } 51 | 52 | void 53 | fix_win32_cursor_icon_file_dir_entry_endian(Win32CursorIconFileDirEntry *obj) 54 | { 55 | BSWAP16(obj->hotspot_x); 56 | BSWAP16(obj->hotspot_y); 57 | BSWAP32(obj->dib_size); 58 | BSWAP32(obj->dib_offset); 59 | } 60 | 61 | void 62 | fix_win32_image_section_header(Win32ImageSectionHeader *obj) 63 | { 64 | BSWAP32(obj->misc.physical_address); 65 | BSWAP32(obj->virtual_address); 66 | BSWAP32(obj->size_of_raw_data); 67 | BSWAP32(obj->pointer_to_raw_data); 68 | BSWAP32(obj->pointer_to_relocations); 69 | BSWAP32(obj->pointer_to_linenumbers); 70 | BSWAP16(obj->number_of_relocations); 71 | BSWAP16(obj->number_of_linenumbers); 72 | BSWAP32(obj->characteristics); 73 | } 74 | 75 | void 76 | fix_os2_image_header_endian(OS2ImageHeader *obj) 77 | { 78 | BSWAP16(obj->magic); 79 | BSWAP16(obj->enttab); 80 | BSWAP16(obj->cbenttab); 81 | BSWAP32(obj->crc); 82 | BSWAP16(obj->flags); 83 | BSWAP16(obj->autodata); 84 | BSWAP16(obj->heap); 85 | BSWAP16(obj->stack); 86 | BSWAP32(obj->csip); 87 | BSWAP32(obj->sssp); 88 | BSWAP16(obj->cseg); 89 | BSWAP16(obj->cmod); 90 | BSWAP16(obj->cbnrestab); 91 | BSWAP16(obj->segtab); 92 | BSWAP16(obj->rsrctab); 93 | BSWAP16(obj->restab); 94 | BSWAP16(obj->modtab); 95 | BSWAP16(obj->imptab); 96 | BSWAP32(obj->nrestab); 97 | BSWAP16(obj->cmovent); 98 | BSWAP16(obj->align); 99 | BSWAP16(obj->cres); 100 | BSWAP16(obj->fastload_offset); 101 | BSWAP16(obj->fastload_length); 102 | BSWAP16(obj->swaparea); 103 | BSWAP16(obj->expver); 104 | } 105 | 106 | /* fix_win32_image_header_endian: 107 | * NOTE: This assumes that the optional header is always available. 108 | */ 109 | void 110 | fix_win32_image_header_endian(Win32ImageNTHeaders *obj) 111 | { 112 | BSWAP32(obj->signature); 113 | BSWAP16(obj->file_header.machine); 114 | BSWAP16(obj->file_header.number_of_sections); 115 | BSWAP32(obj->file_header.time_date_stamp); 116 | BSWAP32(obj->file_header.pointer_to_symbol_table); 117 | BSWAP32(obj->file_header.number_of_symbols); 118 | BSWAP16(obj->file_header.size_of_optional_header); 119 | BSWAP16(obj->file_header.characteristics); 120 | BSWAP16(obj->optional_header.magic); 121 | BSWAP32(obj->optional_header.size_of_code); 122 | BSWAP32(obj->optional_header.size_of_initialized_data); 123 | BSWAP32(obj->optional_header.size_of_uninitialized_data); 124 | BSWAP32(obj->optional_header.address_of_entry_point); 125 | BSWAP32(obj->optional_header.base_of_code); 126 | BSWAP32(obj->optional_header.base_of_data); 127 | BSWAP32(obj->optional_header.image_base); 128 | BSWAP32(obj->optional_header.section_alignment); 129 | BSWAP32(obj->optional_header.file_alignment); 130 | BSWAP16(obj->optional_header.major_operating_system_version); 131 | BSWAP16(obj->optional_header.minor_operating_system_version); 132 | BSWAP16(obj->optional_header.major_image_version); 133 | BSWAP16(obj->optional_header.minor_image_version); 134 | BSWAP16(obj->optional_header.major_subsystem_version); 135 | BSWAP16(obj->optional_header.minor_subsystem_version); 136 | BSWAP32(obj->optional_header.win32_version_value); 137 | BSWAP32(obj->optional_header.size_of_image); 138 | BSWAP32(obj->optional_header.size_of_headers); 139 | BSWAP32(obj->optional_header.checksum); 140 | BSWAP16(obj->optional_header.subsystem); 141 | BSWAP16(obj->optional_header.dll_characteristics); 142 | BSWAP32(obj->optional_header.size_of_stack_reserve); 143 | BSWAP32(obj->optional_header.size_of_stack_commit); 144 | BSWAP32(obj->optional_header.size_of_heap_reserve); 145 | BSWAP32(obj->optional_header.size_of_heap_commit); 146 | BSWAP32(obj->optional_header.loader_flags); 147 | BSWAP32(obj->optional_header.number_of_rva_and_sizes); 148 | } 149 | 150 | void 151 | fix_win32_image_data_directory(Win32ImageDataDirectory *obj) 152 | { 153 | BSWAP32(obj->virtual_address); 154 | BSWAP32(obj->size); 155 | } 156 | 157 | #endif /* WORDS_BIGENDIAN */ 158 | -------------------------------------------------------------------------------- /OSXIcotools/icotool/win32-endian.h: -------------------------------------------------------------------------------- 1 | /* win32-endian.h - Correcting endian-ness of data loaded to memory 2 | * 3 | * Copyright (C) 1998 Oskar Liljeblad 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #ifndef WIN32_ENDIAN_H 20 | #define WIN32_ENDIAN_H 21 | 22 | #include "win32.h" 23 | 24 | #if WORDS_BIGENDIAN 25 | 26 | void fix_win32_cursor_icon_file_dir_endian(Win32CursorIconFileDir *obj); 27 | void fix_win32_bitmap_info_header_endian(Win32BitmapInfoHeader *obj); 28 | void fix_win32_cursor_icon_file_dir_entry_endian(Win32CursorIconFileDirEntry *obj); 29 | void fix_win32_image_data_directory(Win32ImageDataDirectory *obj); 30 | void fix_os2_image_header_endian(OS2ImageHeader *obj); 31 | void fix_win32_image_section_header(Win32ImageSectionHeader *obj); 32 | void fix_win32_image_header_endian(Win32ImageNTHeaders *obj); 33 | 34 | #else 35 | 36 | #define fix_win32_bitmap_info_header_endian(x) 37 | #define fix_win32_cursor_icon_file_dir_endian(x) 38 | #define fix_win32_cursor_icon_file_dir_entry_endian(x) 39 | #define fix_win32_image_data_directory(x) 40 | #define fix_os2_image_header_endian(x) 41 | #define fix_win32_image_section_header(x) 42 | #define fix_win32_image_header_endian(x) 43 | 44 | #endif /* WORDS_BIGENDIAN */ 45 | 46 | #endif /* WIN32_ENDIAN_H */ 47 | -------------------------------------------------------------------------------- /OSXIcotools/icotool/win32.h: -------------------------------------------------------------------------------- 1 | /* win32.h - Common definitions for win32 objects 2 | * 3 | * Copyright (C) 1998 Oskar Liljeblad 4 | * Copyright (C) 2012 Daniele Cattaneo 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | #ifndef WIN32_H 21 | #define WIN32_H 22 | 23 | #include /* POSIX/Gnulib */ 24 | 25 | #define PACKED __attribute__ ((packed)) 26 | #pragma pack(1) 27 | 28 | typedef struct { 29 | uint8_t width; 30 | uint8_t height; 31 | uint8_t color_count; 32 | uint8_t reserved; 33 | } Win32IconResDir; 34 | 35 | typedef struct { 36 | uint16_t width; 37 | uint16_t height; 38 | } Win32CursorDir; 39 | 40 | typedef struct PACKED { 41 | union { 42 | Win32IconResDir icon; 43 | Win32CursorDir cursor; 44 | } res_info; 45 | uint16_t plane_count; 46 | uint16_t bit_count; 47 | uint32_t bytes_in_res; 48 | uint16_t res_id; 49 | } Win32CursorIconDirEntry; 50 | 51 | typedef struct PACKED { 52 | uint16_t reserved; 53 | uint16_t type; 54 | uint16_t count; 55 | Win32CursorIconDirEntry entries[0]; 56 | } Win32CursorIconDir; 57 | 58 | typedef struct { 59 | uint8_t width; 60 | uint8_t height; 61 | uint8_t color_count; 62 | uint8_t reserved; 63 | uint16_t hotspot_x; /* hotspot_x for cursors, planes for icons */ 64 | uint16_t hotspot_y; /* hotspot_y for cursors, bit_count for icons */ 65 | uint32_t dib_size; 66 | uint32_t dib_offset; 67 | } Win32CursorIconFileDirEntry; 68 | 69 | typedef struct { 70 | uint16_t reserved; 71 | uint16_t type; 72 | uint16_t count; 73 | Win32CursorIconFileDirEntry entries[0]; 74 | } Win32CursorIconFileDir; 75 | 76 | typedef struct { 77 | uint32_t size; 78 | int32_t width; 79 | int32_t height; 80 | uint16_t planes; 81 | uint16_t bit_count; 82 | uint32_t compression; 83 | uint32_t size_image; 84 | int32_t x_pels_per_meter; 85 | int32_t y_pels_per_meter; 86 | uint32_t clr_used; 87 | uint32_t clr_important; 88 | } Win32BitmapInfoHeader; 89 | 90 | /* compression */ 91 | #define BI_RGB 0 92 | #define BI_RLE8 1 93 | #define BI_RLE4 2 94 | #define BI_BITFIELDS 3 95 | #define BI_JPEG 4 96 | #define BI_PNG 5 97 | 98 | typedef struct { 99 | uint8_t blue; 100 | uint8_t green; 101 | uint8_t red; 102 | uint8_t reserved; 103 | } Win32RGBQuad; 104 | 105 | #define IMAGE_NUMBEROF_DIRECTORY_ENTRIES 16 106 | #define IMAGE_SIZEOF_SHORT_NAME 8 107 | 108 | #define IMAGE_RESOURCE_NAME_IS_STRING 0x80000000 109 | #define IMAGE_RESOURCE_DATA_IS_DIRECTORY 0x80000000 110 | 111 | #define PE_HEADER(module) \ 112 | ((Win32ImageNTHeaders*)((uint8_t *)(module) + \ 113 | (((DOSImageHeader*)(module))->lfanew))) 114 | 115 | #define MZ_HEADER(x) ((DOSImageHeader *)(x)) 116 | #define NE_HEADER(x) ((OS2ImageHeader *)PE_HEADER(x)) 117 | 118 | #define PE_SECTIONS(module) \ 119 | ((Win32ImageSectionHeader *)((uint8_t *) &PE_HEADER(module)->optional_header + \ 120 | PE_HEADER(module)->file_header.size_of_optional_header)) 121 | 122 | #define IMAGE_DOS_SIGNATURE 0x5A4D /* MZ */ 123 | #define IMAGE_OS2_SIGNATURE 0x454E /* NE */ 124 | #define IMAGE_OS2_SIGNATURE_LE 0x454C /* LE */ 125 | #define IMAGE_OS2_SIGNATURE_LX 0x584C /* LX */ 126 | #define IMAGE_VXD_SIGNATURE 0x454C /* LE */ 127 | #define IMAGE_NT_SIGNATURE 0x00004550 /* PE00 */ 128 | 129 | #define OPTIONAL_MAGIC_PE32 0x010b 130 | #define OPTIONAL_MAGIC_PE32_64 0x020b 131 | 132 | #define IMAGE_SCN_CNT_CODE 0x00000020 133 | #define IMAGE_SCN_CNT_INITIALIZED_DATA 0x00000040 134 | #define IMAGE_SCN_CNT_UNINITIALIZED_DATA 0x00000080 135 | 136 | #define IMAGE_DIRECTORY_ENTRY_EXPORT 0 137 | #define IMAGE_DIRECTORY_ENTRY_IMPORT 1 138 | #define IMAGE_DIRECTORY_ENTRY_RESOURCE 2 139 | #define IMAGE_DIRECTORY_ENTRY_EXCEPTION 3 140 | #define IMAGE_DIRECTORY_ENTRY_SECURITY 4 141 | #define IMAGE_DIRECTORY_ENTRY_BASERELOC 5 142 | #define IMAGE_DIRECTORY_ENTRY_DEBUG 6 143 | #define IMAGE_DIRECTORY_ENTRY_COPYRIGHT 7 144 | #define IMAGE_DIRECTORY_ENTRY_GLOBALPTR 8 /* (MIPS GP) */ 145 | #define IMAGE_DIRECTORY_ENTRY_TLS 9 146 | #define IMAGE_DIRECTORY_ENTRY_LOAD_CONFIG 10 147 | #define IMAGE_DIRECTORY_ENTRY_BOUND_IMPORT 11 148 | #define IMAGE_DIRECTORY_ENTRY_IAT 12 /* Import Address Table */ 149 | #define IMAGE_DIRECTORY_ENTRY_DELAY_IMPORT 13 150 | #define IMAGE_DIRECTORY_ENTRY_COM_DESCRIPTOR 14 151 | 152 | #define RT_CURSOR 1 153 | #define RT_BITMAP 2 154 | #define RT_ICON 3 155 | #define RT_MENU 4 156 | #define RT_DIALOG 5 157 | #define RT_STRING 6 158 | #define RT_FONTDIR 7 159 | #define RT_FONT 8 160 | #define RT_ACCELERATOR 9 161 | #define RT_RCDATA 10 162 | #define RT_MESSAGELIST 11 163 | #define RT_GROUP_CURSOR 12 164 | #define RT_GROUP_ICON 14 165 | #define RT_VERSION 16 166 | 167 | typedef struct { 168 | union { 169 | struct { 170 | #if BITFIELDS_BIGENDIAN 171 | unsigned name_is_string:1; 172 | unsigned name_offset:31; 173 | #else 174 | unsigned name_offset:31; 175 | unsigned name_is_string:1; 176 | #endif 177 | } s1; 178 | uint32_t name; 179 | struct { 180 | #if WORDS_BIGENDIAN 181 | uint16_t __pad; 182 | uint16_t id; 183 | #else 184 | uint16_t id; 185 | uint16_t __pad; 186 | #endif 187 | } s2; 188 | } u1; 189 | union { 190 | uint32_t offset_to_data; 191 | struct { 192 | #if BITFIELDS_BIGENDIAN 193 | unsigned data_is_directory:1; 194 | unsigned offset_to_directory:31; 195 | #else 196 | unsigned offset_to_directory:31; 197 | unsigned data_is_directory:1; 198 | #endif 199 | } s; 200 | } u2; 201 | } Win32ImageResourceDirectoryEntry; 202 | 203 | typedef struct { 204 | uint16_t type_id; 205 | uint16_t count; 206 | uint32_t reserved; 207 | } Win16NETypeInfo; 208 | 209 | typedef struct { 210 | uint16_t offset; 211 | uint16_t length; 212 | uint16_t flags; 213 | uint16_t id; 214 | uint16_t handle; 215 | uint16_t usage; 216 | } Win16NENameInfo; 217 | 218 | typedef struct { 219 | uint16_t magic; 220 | uint8_t ver; 221 | uint8_t rev; 222 | uint16_t enttab; 223 | uint16_t cbenttab; 224 | int32_t crc; 225 | uint16_t flags; 226 | uint16_t autodata; 227 | uint16_t heap; 228 | uint16_t stack; 229 | uint32_t csip; 230 | uint32_t sssp; 231 | uint16_t cseg; 232 | uint16_t cmod; 233 | uint16_t cbnrestab; 234 | uint16_t segtab; 235 | uint16_t rsrctab; 236 | uint16_t restab; 237 | uint16_t modtab; 238 | uint16_t imptab; 239 | uint32_t nrestab; 240 | uint16_t cmovent; 241 | uint16_t align; 242 | uint16_t cres; 243 | uint8_t exetyp; 244 | uint8_t flagsothers; 245 | uint16_t fastload_offset; 246 | uint16_t fastload_length; 247 | uint16_t swaparea; 248 | uint16_t expver; 249 | } OS2ImageHeader; 250 | 251 | typedef struct { 252 | uint16_t magic; 253 | uint16_t cblp; 254 | uint16_t cp; 255 | uint16_t crlc; 256 | uint16_t cparhdr; 257 | uint16_t minalloc; 258 | uint16_t maxalloc; 259 | uint16_t ss; 260 | uint16_t sp; 261 | uint16_t csum; 262 | uint16_t ip; 263 | uint16_t cs; 264 | uint16_t lfarlc; 265 | uint16_t ovno; 266 | uint16_t res[4]; 267 | uint16_t oemid; 268 | uint16_t oeminfo; 269 | uint16_t res2[10]; 270 | uint32_t lfanew; 271 | } DOSImageHeader; 272 | 273 | typedef struct { 274 | uint16_t machine; 275 | uint16_t number_of_sections; 276 | uint32_t time_date_stamp; 277 | uint32_t pointer_to_symbol_table; 278 | uint32_t number_of_symbols; 279 | uint16_t size_of_optional_header; 280 | uint16_t characteristics; 281 | } Win32ImageFileHeader; 282 | 283 | typedef struct { 284 | uint32_t virtual_address; 285 | uint32_t size; 286 | } Win32ImageDataDirectory; 287 | 288 | typedef struct { 289 | uint16_t magic; 290 | uint8_t major_linker_version; 291 | uint8_t minor_linker_version; 292 | uint32_t size_of_code; 293 | uint32_t size_of_initialized_data; 294 | uint32_t size_of_uninitialized_data; 295 | uint32_t address_of_entry_point; 296 | uint32_t base_of_code; 297 | uint32_t base_of_data; 298 | uint32_t image_base; 299 | uint32_t section_alignment; 300 | uint32_t file_alignment; 301 | uint16_t major_operating_system_version; 302 | uint16_t minor_operating_system_version; 303 | uint16_t major_image_version; 304 | uint16_t minor_image_version; 305 | uint16_t major_subsystem_version; 306 | uint16_t minor_subsystem_version; 307 | uint32_t win32_version_value; 308 | uint32_t size_of_image; 309 | uint32_t size_of_headers; 310 | uint32_t checksum; 311 | uint16_t subsystem; 312 | uint16_t dll_characteristics; 313 | uint32_t size_of_stack_reserve; 314 | uint32_t size_of_stack_commit; 315 | uint32_t size_of_heap_reserve; 316 | uint32_t size_of_heap_commit; 317 | uint32_t loader_flags; 318 | uint32_t number_of_rva_and_sizes; 319 | Win32ImageDataDirectory data_directory[IMAGE_NUMBEROF_DIRECTORY_ENTRIES]; 320 | } Win32ImageOptionalHeader; 321 | 322 | typedef struct { 323 | uint16_t magic; 324 | uint8_t major_linker_version; 325 | uint8_t minor_linker_version; 326 | uint32_t size_of_code; 327 | uint32_t size_of_initialized_data; 328 | uint32_t size_of_uninitialized_data; 329 | uint32_t address_of_entry_point; 330 | uint32_t base_of_code; 331 | uint64_t image_base; 332 | uint32_t section_alignment; 333 | uint32_t file_alignment; 334 | uint16_t major_operating_system_version; 335 | uint16_t minor_operating_system_version; 336 | uint16_t major_image_version; 337 | uint16_t minor_image_version; 338 | uint16_t major_subsystem_version; 339 | uint16_t minor_subsystem_version; 340 | uint32_t win32_version_value; 341 | uint32_t size_of_image; 342 | uint32_t size_of_headers; 343 | uint32_t checksum; 344 | uint16_t subsystem; 345 | uint16_t dll_characteristics; 346 | uint64_t size_of_stack_reserve; 347 | uint64_t size_of_stack_commit; 348 | uint64_t size_of_heap_reserve; 349 | uint64_t size_of_heap_commit; 350 | uint32_t loader_flags; 351 | uint32_t number_of_rva_and_sizes; 352 | Win32ImageDataDirectory data_directory[IMAGE_NUMBEROF_DIRECTORY_ENTRIES]; 353 | } PE32plusImageOptionalHeader; 354 | 355 | typedef struct { 356 | uint32_t signature; 357 | Win32ImageFileHeader file_header; 358 | Win32ImageOptionalHeader optional_header; 359 | } Win32ImageNTHeaders; 360 | 361 | typedef struct { 362 | uint32_t signature; 363 | Win32ImageFileHeader file_header; 364 | PE32plusImageOptionalHeader optional_header; 365 | } PE32plusImageNTHeaders; 366 | 367 | typedef struct { 368 | uint8_t name[IMAGE_SIZEOF_SHORT_NAME]; 369 | union { 370 | uint32_t physical_address; 371 | uint32_t virtual_size; 372 | } misc; 373 | uint32_t virtual_address; 374 | uint32_t size_of_raw_data; 375 | uint32_t pointer_to_raw_data; 376 | uint32_t pointer_to_relocations; 377 | uint32_t pointer_to_linenumbers; 378 | uint16_t number_of_relocations; 379 | uint16_t number_of_linenumbers; 380 | uint32_t characteristics; 381 | } Win32ImageSectionHeader; 382 | 383 | typedef struct { 384 | uint32_t offset_to_data; 385 | uint32_t size; 386 | uint32_t code_page; 387 | uint32_t resource_handle; 388 | } Win32ImageResourceDataEntry; 389 | 390 | typedef struct { 391 | uint32_t characteristics; 392 | uint32_t time_date_stamp; 393 | uint16_t major_version; 394 | uint16_t minor_version; 395 | uint16_t number_of_named_entries; 396 | uint16_t number_of_id_entries; 397 | } Win32ImageResourceDirectory; 398 | 399 | #pragma pack() 400 | 401 | #endif /* WIN32_H */ 402 | -------------------------------------------------------------------------------- /OSXIcotools/lib/basename-lgpl.c: -------------------------------------------------------------------------------- 1 | /* basename.c -- return the last element in a file name 2 | 3 | Copyright (C) 1990, 1998-2001, 2003-2006, 2009-2018 Free Software 4 | Foundation, Inc. 5 | 6 | This program is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation; either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with this program. If not, see . */ 18 | 19 | #include 20 | 21 | #include "dirname.h" 22 | 23 | #include 24 | 25 | /* Return the address of the last file name component of NAME. If 26 | NAME has no relative file name components because it is a file 27 | system root, return the empty string. */ 28 | 29 | char * 30 | last_component (char const *name) 31 | { 32 | char const *base = name + FILE_SYSTEM_PREFIX_LEN (name); 33 | char const *p; 34 | bool saw_slash = false; 35 | 36 | while (ISSLASH (*base)) 37 | base++; 38 | 39 | for (p = base; *p; p++) 40 | { 41 | if (ISSLASH (*p)) 42 | saw_slash = true; 43 | else if (saw_slash) 44 | { 45 | base = p; 46 | saw_slash = false; 47 | } 48 | } 49 | 50 | return (char *) base; 51 | } 52 | 53 | /* Return the length of the basename NAME. Typically NAME is the 54 | value returned by base_name or last_component. Act like strlen 55 | (NAME), except omit all trailing slashes. */ 56 | 57 | size_t 58 | base_len (char const *name) 59 | { 60 | size_t len; 61 | size_t prefix_len = FILE_SYSTEM_PREFIX_LEN (name); 62 | 63 | for (len = strlen (name); 1 < len && ISSLASH (name[len - 1]); len--) 64 | continue; 65 | 66 | if (DOUBLE_SLASH_IS_DISTINCT_ROOT && len == 1 67 | && ISSLASH (name[0]) && ISSLASH (name[1]) && ! name[2]) 68 | return 2; 69 | 70 | if (FILE_SYSTEM_DRIVE_PREFIX_CAN_BE_RELATIVE && prefix_len 71 | && len == prefix_len && ISSLASH (name[prefix_len])) 72 | return prefix_len + 1; 73 | 74 | return len; 75 | } 76 | -------------------------------------------------------------------------------- /OSXIcotools/lib/basename.c: -------------------------------------------------------------------------------- 1 | /* basename.c -- return the last element in a file name 2 | 3 | Copyright (C) 1990, 1998-2001, 2003-2006, 2009-2018 Free Software 4 | Foundation, Inc. 5 | 6 | This program is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation; either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with this program. If not, see . */ 18 | 19 | #include 20 | 21 | #include "dirname.h" 22 | 23 | #include 24 | #include "xalloc.h" 25 | #include "xstrndup.h" 26 | 27 | char * 28 | base_name (char const *name) 29 | { 30 | char const *base = last_component (name); 31 | size_t length; 32 | 33 | /* If there is no last component, then name is a file system root or the 34 | empty string. */ 35 | if (! *base) 36 | return xstrndup (name, base_len (name)); 37 | 38 | /* Collapse a sequence of trailing slashes into one. */ 39 | length = base_len (base); 40 | if (ISSLASH (base[length])) 41 | length++; 42 | 43 | /* On systems with drive letters, "a/b:c" must return "./b:c" rather 44 | than "b:c" to avoid confusion with a drive letter. On systems 45 | with pure POSIX semantics, this is not an issue. */ 46 | if (FILE_SYSTEM_PREFIX_LEN (base)) 47 | { 48 | char *p = xmalloc (length + 3); 49 | p[0] = '.'; 50 | p[1] = '/'; 51 | memcpy (p + 2, base, length); 52 | p[length + 2] = '\0'; 53 | return p; 54 | } 55 | 56 | /* Finally, copy the basename. */ 57 | return xstrndup (base, length); 58 | } 59 | -------------------------------------------------------------------------------- /OSXIcotools/lib/byteswap.h: -------------------------------------------------------------------------------- 1 | /* DO NOT EDIT! GENERATED AUTOMATICALLY! */ 2 | /* byteswap.h - Byte swapping 3 | Copyright (C) 2005, 2007, 2009-2012 Free Software Foundation, Inc. 4 | Written by Oskar Liljeblad , 2005. 5 | 6 | This program is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation; either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with this program. If not, see . */ 18 | 19 | #ifndef _GL_BYTESWAP_H 20 | #define _GL_BYTESWAP_H 21 | 22 | /* Given an unsigned 16-bit argument X, return the value corresponding to 23 | X with reversed byte order. */ 24 | #define bswap_16(x) ((((x) & 0x00FF) << 8) | \ 25 | (((x) & 0xFF00) >> 8)) 26 | 27 | /* Given an unsigned 32-bit argument X, return the value corresponding to 28 | X with reversed byte order. */ 29 | #define bswap_32(x) ((((x) & 0x000000FF) << 24) | \ 30 | (((x) & 0x0000FF00) << 8) | \ 31 | (((x) & 0x00FF0000) >> 8) | \ 32 | (((x) & 0xFF000000) >> 24)) 33 | 34 | /* Given an unsigned 64-bit argument X, return the value corresponding to 35 | X with reversed byte order. */ 36 | #define bswap_64(x) ((((x) & 0x00000000000000FFULL) << 56) | \ 37 | (((x) & 0x000000000000FF00ULL) << 40) | \ 38 | (((x) & 0x0000000000FF0000ULL) << 24) | \ 39 | (((x) & 0x00000000FF000000ULL) << 8) | \ 40 | (((x) & 0x000000FF00000000ULL) >> 8) | \ 41 | (((x) & 0x0000FF0000000000ULL) >> 24) | \ 42 | (((x) & 0x00FF000000000000ULL) >> 40) | \ 43 | (((x) & 0xFF00000000000000ULL) >> 56)) 44 | 45 | #endif /* _GL_BYTESWAP_H */ 46 | -------------------------------------------------------------------------------- /OSXIcotools/lib/dirname-lgpl.c: -------------------------------------------------------------------------------- 1 | /* dirname.c -- return all but the last element in a file name 2 | 3 | Copyright (C) 1990, 1998, 2000-2001, 2003-2006, 2009-2018 Free Software 4 | Foundation, Inc. 5 | 6 | This program is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation; either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with this program. If not, see . */ 18 | 19 | #include 20 | 21 | #include "dirname.h" 22 | 23 | #include 24 | #include 25 | 26 | /* Return the length of the prefix of FILE that will be used by 27 | dir_name. If FILE is in the working directory, this returns zero 28 | even though 'dir_name (FILE)' will return ".". Works properly even 29 | if there are trailing slashes (by effectively ignoring them). */ 30 | 31 | size_t 32 | dir_len (char const *file) 33 | { 34 | size_t prefix_length = FILE_SYSTEM_PREFIX_LEN (file); 35 | size_t length; 36 | 37 | /* Advance prefix_length beyond important leading slashes. */ 38 | prefix_length += (prefix_length != 0 39 | ? (FILE_SYSTEM_DRIVE_PREFIX_CAN_BE_RELATIVE 40 | && ISSLASH (file[prefix_length])) 41 | : (ISSLASH (file[0]) 42 | ? ((DOUBLE_SLASH_IS_DISTINCT_ROOT 43 | && ISSLASH (file[1]) && ! ISSLASH (file[2]) 44 | ? 2 : 1)) 45 | : 0)); 46 | 47 | /* Strip the basename and any redundant slashes before it. */ 48 | for (length = last_component (file) - file; 49 | prefix_length < length; length--) 50 | if (! ISSLASH (file[length - 1])) 51 | break; 52 | return length; 53 | } 54 | 55 | 56 | /* In general, we can't use the builtin 'dirname' function if available, 57 | since it has different meanings in different environments. 58 | In some environments the builtin 'dirname' modifies its argument. 59 | 60 | Return the leading directories part of FILE, allocated with malloc. 61 | Works properly even if there are trailing slashes (by effectively 62 | ignoring them). Return NULL on failure. 63 | 64 | If lstat (FILE) would succeed, then { chdir (dir_name (FILE)); 65 | lstat (base_name (FILE)); } will access the same file. Likewise, 66 | if the sequence { chdir (dir_name (FILE)); 67 | rename (base_name (FILE), "foo"); } succeeds, you have renamed FILE 68 | to "foo" in the same directory FILE was in. */ 69 | 70 | char * 71 | mdir_name (char const *file) 72 | { 73 | size_t length = dir_len (file); 74 | bool append_dot = (length == 0 75 | || (FILE_SYSTEM_DRIVE_PREFIX_CAN_BE_RELATIVE 76 | && length == FILE_SYSTEM_PREFIX_LEN (file) 77 | && file[2] != '\0' && ! ISSLASH (file[2]))); 78 | char *dir = malloc (length + append_dot + 1); 79 | if (!dir) 80 | return NULL; 81 | memcpy (dir, file, length); 82 | if (append_dot) 83 | dir[length++] = '.'; 84 | dir[length] = '\0'; 85 | return dir; 86 | } 87 | -------------------------------------------------------------------------------- /OSXIcotools/lib/dirname.c: -------------------------------------------------------------------------------- 1 | /* dirname.c -- return all but the last element in a file name 2 | 3 | Copyright (C) 1990, 1998, 2000-2001, 2003-2006, 2009-2018 Free Software 4 | Foundation, Inc. 5 | 6 | This program is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation; either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with this program. If not, see . */ 18 | 19 | #include 20 | 21 | #include "dirname.h" 22 | 23 | #include 24 | #include 25 | #include "xalloc.h" 26 | 27 | /* Just like mdir_name (dirname-lgpl.c), except, rather than 28 | returning NULL upon malloc failure, here, we report the 29 | "memory exhausted" condition and exit. */ 30 | 31 | char * 32 | dir_name (char const *file) 33 | { 34 | char *result = mdir_name (file); 35 | if (!result) 36 | xalloc_die (); 37 | return result; 38 | } 39 | -------------------------------------------------------------------------------- /OSXIcotools/lib/dirname.h: -------------------------------------------------------------------------------- 1 | /* Take file names apart into directory and base names. 2 | 3 | Copyright (C) 1998, 2001, 2003-2006, 2009-2018 Free Software Foundation, 4 | Inc. 5 | 6 | This program is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation; either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with this program. If not, see . */ 18 | 19 | #ifndef DIRNAME_H_ 20 | # define DIRNAME_H_ 1 21 | 22 | # include 23 | # include 24 | # include "dosname.h" 25 | 26 | # ifndef DIRECTORY_SEPARATOR 27 | # define DIRECTORY_SEPARATOR '/' 28 | # endif 29 | 30 | # ifndef DOUBLE_SLASH_IS_DISTINCT_ROOT 31 | # define DOUBLE_SLASH_IS_DISTINCT_ROOT 0 32 | # endif 33 | 34 | #ifdef __cplusplus 35 | extern "C" { 36 | #endif 37 | 38 | # if GNULIB_DIRNAME 39 | char *base_name (char const *file); 40 | char *dir_name (char const *file); 41 | # endif 42 | 43 | char *mdir_name (char const *file); 44 | size_t base_len (char const *file) _GL_ATTRIBUTE_PURE; 45 | size_t dir_len (char const *file) _GL_ATTRIBUTE_PURE; 46 | char *last_component (char const *file) _GL_ATTRIBUTE_PURE; 47 | 48 | bool strip_trailing_slashes (char *file); 49 | 50 | #ifdef __cplusplus 51 | } /* extern "C" */ 52 | #endif 53 | 54 | #endif /* not DIRNAME_H_ */ 55 | -------------------------------------------------------------------------------- /OSXIcotools/lib/dosname.h: -------------------------------------------------------------------------------- 1 | /* File names on MS-DOS/Windows systems. 2 | 3 | Copyright (C) 2000-2001, 2004-2006, 2009-2018 Free Software Foundation, Inc. 4 | 5 | This program is free software: you can redistribute it and/or modify 6 | it under the terms of the GNU General Public License as published by 7 | the Free Software Foundation; either version 3 of the License, or 8 | (at your option) any later version. 9 | 10 | This program is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU General Public License for more details. 14 | 15 | You should have received a copy of the GNU General Public License 16 | along with this program. If not, see . 17 | 18 | From Paul Eggert and Jim Meyering. */ 19 | 20 | #ifndef _DOSNAME_H 21 | #define _DOSNAME_H 22 | 23 | #if (defined _WIN32 || defined __WIN32__ || \ 24 | defined __MSDOS__ || defined __CYGWIN__ || \ 25 | defined __EMX__ || defined __DJGPP__) 26 | /* This internal macro assumes ASCII, but all hosts that support drive 27 | letters use ASCII. */ 28 | # define _IS_DRIVE_LETTER(C) (((unsigned int) (C) | ('a' - 'A')) - 'a' \ 29 | <= 'z' - 'a') 30 | # define FILE_SYSTEM_PREFIX_LEN(Filename) \ 31 | (_IS_DRIVE_LETTER ((Filename)[0]) && (Filename)[1] == ':' ? 2 : 0) 32 | # ifndef __CYGWIN__ 33 | # define FILE_SYSTEM_DRIVE_PREFIX_CAN_BE_RELATIVE 1 34 | # endif 35 | # define ISSLASH(C) ((C) == '/' || (C) == '\\') 36 | #else 37 | # define FILE_SYSTEM_PREFIX_LEN(Filename) 0 38 | # define ISSLASH(C) ((C) == '/') 39 | #endif 40 | 41 | #ifndef FILE_SYSTEM_DRIVE_PREFIX_CAN_BE_RELATIVE 42 | # define FILE_SYSTEM_DRIVE_PREFIX_CAN_BE_RELATIVE 0 43 | #endif 44 | 45 | #if FILE_SYSTEM_DRIVE_PREFIX_CAN_BE_RELATIVE 46 | # define IS_ABSOLUTE_FILE_NAME(F) ISSLASH ((F)[FILE_SYSTEM_PREFIX_LEN (F)]) 47 | # else 48 | # define IS_ABSOLUTE_FILE_NAME(F) \ 49 | (ISSLASH ((F)[0]) || FILE_SYSTEM_PREFIX_LEN (F) != 0) 50 | #endif 51 | #define IS_RELATIVE_FILE_NAME(F) (! IS_ABSOLUTE_FILE_NAME (F)) 52 | 53 | #endif /* DOSNAME_H_ */ 54 | -------------------------------------------------------------------------------- /OSXIcotools/lib/gettext.h: -------------------------------------------------------------------------------- 1 | /* Convenience header for conditional use of GNU . 2 | Copyright (C) 1995-1998, 2000-2002, 2004-2006, 2009-2018 Free Software 3 | Foundation, Inc. 4 | 5 | This program is free software; you can redistribute it and/or modify 6 | it under the terms of the GNU General Public License as published by 7 | the Free Software Foundation; either version 3, or (at your option) 8 | any later version. 9 | 10 | This program is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU General Public License for more details. 14 | 15 | You should have received a copy of the GNU General Public License along 16 | with this program; if not, see . */ 17 | 18 | #ifndef _LIBGETTEXT_H 19 | #define _LIBGETTEXT_H 1 20 | 21 | /* NLS can be disabled through the configure --disable-nls option 22 | or through "#define ENABLE NLS 0" before including this file. */ 23 | #if defined ENABLE_NLS && ENABLE_NLS 24 | 25 | /* Get declarations of GNU message catalog functions. */ 26 | # include 27 | 28 | /* You can set the DEFAULT_TEXT_DOMAIN macro to specify the domain used by 29 | the gettext() and ngettext() macros. This is an alternative to calling 30 | textdomain(), and is useful for libraries. */ 31 | # ifdef DEFAULT_TEXT_DOMAIN 32 | # undef gettext 33 | # define gettext(Msgid) \ 34 | dgettext (DEFAULT_TEXT_DOMAIN, Msgid) 35 | # undef ngettext 36 | # define ngettext(Msgid1, Msgid2, N) \ 37 | dngettext (DEFAULT_TEXT_DOMAIN, Msgid1, Msgid2, N) 38 | # endif 39 | 40 | #else 41 | 42 | /* Solaris /usr/include/locale.h includes /usr/include/libintl.h, which 43 | chokes if dcgettext is defined as a macro. So include it now, to make 44 | later inclusions of a NOP. We don't include 45 | as well because people using "gettext.h" will not include , 46 | and also including would fail on SunOS 4, whereas 47 | is OK. */ 48 | #if defined(__sun) 49 | # include 50 | #endif 51 | 52 | /* Many header files from the libstdc++ coming with g++ 3.3 or newer include 53 | , which chokes if dcgettext is defined as a macro. So include 54 | it now, to make later inclusions of a NOP. */ 55 | #if defined(__cplusplus) && defined(__GNUG__) && (__GNUC__ >= 3) 56 | # include 57 | # if (__GLIBC__ >= 2 && !defined __UCLIBC__) || _GLIBCXX_HAVE_LIBINTL_H 58 | # include 59 | # endif 60 | #endif 61 | 62 | /* Disabled NLS. 63 | The casts to 'const char *' serve the purpose of producing warnings 64 | for invalid uses of the value returned from these functions. 65 | On pre-ANSI systems without 'const', the config.h file is supposed to 66 | contain "#define const". */ 67 | # undef gettext 68 | # define gettext(Msgid) ((const char *) (Msgid)) 69 | # undef dgettext 70 | # define dgettext(Domainname, Msgid) ((void) (Domainname), gettext (Msgid)) 71 | # undef dcgettext 72 | # define dcgettext(Domainname, Msgid, Category) \ 73 | ((void) (Category), dgettext (Domainname, Msgid)) 74 | # undef ngettext 75 | # define ngettext(Msgid1, Msgid2, N) \ 76 | ((N) == 1 \ 77 | ? ((void) (Msgid2), (const char *) (Msgid1)) \ 78 | : ((void) (Msgid1), (const char *) (Msgid2))) 79 | # undef dngettext 80 | # define dngettext(Domainname, Msgid1, Msgid2, N) \ 81 | ((void) (Domainname), ngettext (Msgid1, Msgid2, N)) 82 | # undef dcngettext 83 | # define dcngettext(Domainname, Msgid1, Msgid2, N, Category) \ 84 | ((void) (Category), dngettext (Domainname, Msgid1, Msgid2, N)) 85 | # undef textdomain 86 | # define textdomain(Domainname) ((const char *) (Domainname)) 87 | # undef bindtextdomain 88 | # define bindtextdomain(Domainname, Dirname) \ 89 | ((void) (Domainname), (const char *) (Dirname)) 90 | # undef bind_textdomain_codeset 91 | # define bind_textdomain_codeset(Domainname, Codeset) \ 92 | ((void) (Domainname), (const char *) (Codeset)) 93 | 94 | #endif 95 | 96 | /* Prefer gnulib's setlocale override over libintl's setlocale override. */ 97 | #ifdef GNULIB_defined_setlocale 98 | # undef setlocale 99 | # define setlocale rpl_setlocale 100 | #endif 101 | 102 | /* A pseudo function call that serves as a marker for the automated 103 | extraction of messages, but does not call gettext(). The run-time 104 | translation is done at a different place in the code. 105 | The argument, String, should be a literal string. Concatenated strings 106 | and other string expressions won't work. 107 | The macro's expansion is not parenthesized, so that it is suitable as 108 | initializer for static 'char[]' or 'const char[]' variables. */ 109 | #define gettext_noop(String) String 110 | 111 | /* The separator between msgctxt and msgid in a .mo file. */ 112 | #define GETTEXT_CONTEXT_GLUE "\004" 113 | 114 | /* Pseudo function calls, taking a MSGCTXT and a MSGID instead of just a 115 | MSGID. MSGCTXT and MSGID must be string literals. MSGCTXT should be 116 | short and rarely need to change. 117 | The letter 'p' stands for 'particular' or 'special'. */ 118 | #ifdef DEFAULT_TEXT_DOMAIN 119 | # define pgettext(Msgctxt, Msgid) \ 120 | pgettext_aux (DEFAULT_TEXT_DOMAIN, Msgctxt GETTEXT_CONTEXT_GLUE Msgid, Msgid, LC_MESSAGES) 121 | #else 122 | # define pgettext(Msgctxt, Msgid) \ 123 | pgettext_aux (NULL, Msgctxt GETTEXT_CONTEXT_GLUE Msgid, Msgid, LC_MESSAGES) 124 | #endif 125 | #define dpgettext(Domainname, Msgctxt, Msgid) \ 126 | pgettext_aux (Domainname, Msgctxt GETTEXT_CONTEXT_GLUE Msgid, Msgid, LC_MESSAGES) 127 | #define dcpgettext(Domainname, Msgctxt, Msgid, Category) \ 128 | pgettext_aux (Domainname, Msgctxt GETTEXT_CONTEXT_GLUE Msgid, Msgid, Category) 129 | #ifdef DEFAULT_TEXT_DOMAIN 130 | # define npgettext(Msgctxt, Msgid, MsgidPlural, N) \ 131 | npgettext_aux (DEFAULT_TEXT_DOMAIN, Msgctxt GETTEXT_CONTEXT_GLUE Msgid, Msgid, MsgidPlural, N, LC_MESSAGES) 132 | #else 133 | # define npgettext(Msgctxt, Msgid, MsgidPlural, N) \ 134 | npgettext_aux (NULL, Msgctxt GETTEXT_CONTEXT_GLUE Msgid, Msgid, MsgidPlural, N, LC_MESSAGES) 135 | #endif 136 | #define dnpgettext(Domainname, Msgctxt, Msgid, MsgidPlural, N) \ 137 | npgettext_aux (Domainname, Msgctxt GETTEXT_CONTEXT_GLUE Msgid, Msgid, MsgidPlural, N, LC_MESSAGES) 138 | #define dcnpgettext(Domainname, Msgctxt, Msgid, MsgidPlural, N, Category) \ 139 | npgettext_aux (Domainname, Msgctxt GETTEXT_CONTEXT_GLUE Msgid, Msgid, MsgidPlural, N, Category) 140 | 141 | #ifdef __GNUC__ 142 | __inline 143 | #else 144 | #ifdef __cplusplus 145 | inline 146 | #endif 147 | #endif 148 | static const char * 149 | pgettext_aux (const char *domain, 150 | const char *msg_ctxt_id, const char *msgid, 151 | int category) 152 | { 153 | const char *translation = dcgettext (domain, msg_ctxt_id, category); 154 | if (translation == msg_ctxt_id) 155 | return msgid; 156 | else 157 | return translation; 158 | } 159 | 160 | #ifdef __GNUC__ 161 | __inline 162 | #else 163 | #ifdef __cplusplus 164 | inline 165 | #endif 166 | #endif 167 | static const char * 168 | npgettext_aux (const char *domain, 169 | const char *msg_ctxt_id, const char *msgid, 170 | const char *msgid_plural, unsigned long int n, 171 | int category) 172 | { 173 | const char *translation = 174 | dcngettext (domain, msg_ctxt_id, msgid_plural, n, category); 175 | if (translation == msg_ctxt_id || translation == msgid_plural) 176 | return (n == 1 ? msgid : msgid_plural); 177 | else 178 | return translation; 179 | } 180 | 181 | /* The same thing extended for non-constant arguments. Here MSGCTXT and MSGID 182 | can be arbitrary expressions. But for string literals these macros are 183 | less efficient than those above. */ 184 | 185 | #include 186 | 187 | #if (((__GNUC__ >= 3 || __GNUG__ >= 2) && !defined __STRICT_ANSI__) \ 188 | /* || __STDC_VERSION__ == 199901L 189 | || (__STDC_VERSION__ >= 201112L && !defined __STDC_NO_VLA__) */ ) 190 | # define _LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS 1 191 | #else 192 | # define _LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS 0 193 | #endif 194 | 195 | #if !_LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS 196 | #include 197 | #endif 198 | 199 | #define pgettext_expr(Msgctxt, Msgid) \ 200 | dcpgettext_expr (NULL, Msgctxt, Msgid, LC_MESSAGES) 201 | #define dpgettext_expr(Domainname, Msgctxt, Msgid) \ 202 | dcpgettext_expr (Domainname, Msgctxt, Msgid, LC_MESSAGES) 203 | 204 | #ifdef __GNUC__ 205 | __inline 206 | #else 207 | #ifdef __cplusplus 208 | inline 209 | #endif 210 | #endif 211 | static const char * 212 | dcpgettext_expr (const char *domain, 213 | const char *msgctxt, const char *msgid, 214 | int category) 215 | { 216 | size_t msgctxt_len = strlen (msgctxt) + 1; 217 | size_t msgid_len = strlen (msgid) + 1; 218 | const char *translation; 219 | #if _LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS 220 | char msg_ctxt_id[msgctxt_len + msgid_len]; 221 | #else 222 | char buf[1024]; 223 | char *msg_ctxt_id = 224 | (msgctxt_len + msgid_len <= sizeof (buf) 225 | ? buf 226 | : (char *) malloc (msgctxt_len + msgid_len)); 227 | if (msg_ctxt_id != NULL) 228 | #endif 229 | { 230 | int found_translation; 231 | memcpy (msg_ctxt_id, msgctxt, msgctxt_len - 1); 232 | msg_ctxt_id[msgctxt_len - 1] = '\004'; 233 | memcpy (msg_ctxt_id + msgctxt_len, msgid, msgid_len); 234 | translation = dcgettext (domain, msg_ctxt_id, category); 235 | found_translation = (translation != msg_ctxt_id); 236 | #if !_LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS 237 | if (msg_ctxt_id != buf) 238 | free (msg_ctxt_id); 239 | #endif 240 | if (found_translation) 241 | return translation; 242 | } 243 | return msgid; 244 | } 245 | 246 | #define npgettext_expr(Msgctxt, Msgid, MsgidPlural, N) \ 247 | dcnpgettext_expr (NULL, Msgctxt, Msgid, MsgidPlural, N, LC_MESSAGES) 248 | #define dnpgettext_expr(Domainname, Msgctxt, Msgid, MsgidPlural, N) \ 249 | dcnpgettext_expr (Domainname, Msgctxt, Msgid, MsgidPlural, N, LC_MESSAGES) 250 | 251 | #ifdef __GNUC__ 252 | __inline 253 | #else 254 | #ifdef __cplusplus 255 | inline 256 | #endif 257 | #endif 258 | static const char * 259 | dcnpgettext_expr (const char *domain, 260 | const char *msgctxt, const char *msgid, 261 | const char *msgid_plural, unsigned long int n, 262 | int category) 263 | { 264 | size_t msgctxt_len = strlen (msgctxt) + 1; 265 | size_t msgid_len = strlen (msgid) + 1; 266 | const char *translation; 267 | #if _LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS 268 | char msg_ctxt_id[msgctxt_len + msgid_len]; 269 | #else 270 | char buf[1024]; 271 | char *msg_ctxt_id = 272 | (msgctxt_len + msgid_len <= sizeof (buf) 273 | ? buf 274 | : (char *) malloc (msgctxt_len + msgid_len)); 275 | if (msg_ctxt_id != NULL) 276 | #endif 277 | { 278 | int found_translation; 279 | memcpy (msg_ctxt_id, msgctxt, msgctxt_len - 1); 280 | msg_ctxt_id[msgctxt_len - 1] = '\004'; 281 | memcpy (msg_ctxt_id + msgctxt_len, msgid, msgid_len); 282 | translation = dcngettext (domain, msg_ctxt_id, msgid_plural, n, category); 283 | found_translation = !(translation == msg_ctxt_id || translation == msgid_plural); 284 | #if !_LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS 285 | if (msg_ctxt_id != buf) 286 | free (msg_ctxt_id); 287 | #endif 288 | if (found_translation) 289 | return translation; 290 | } 291 | return (n == 1 ? msgid : msgid_plural); 292 | } 293 | 294 | #endif /* _LIBGETTEXT_H */ 295 | -------------------------------------------------------------------------------- /OSXIcotools/lib/minmax.h: -------------------------------------------------------------------------------- 1 | /* MIN, MAX macros. 2 | Copyright (C) 1995, 1998, 2001, 2003, 2005, 2009-2018 Free Software 3 | Foundation, Inc. 4 | 5 | This program is free software; you can redistribute it and/or modify 6 | it under the terms of the GNU General Public License as published by 7 | the Free Software Foundation; either version 3, or (at your option) 8 | any later version. 9 | 10 | This program is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU General Public License for more details. 14 | 15 | You should have received a copy of the GNU General Public License 16 | along with this program; if not, see . */ 17 | 18 | #ifndef _MINMAX_H 19 | #define _MINMAX_H 20 | 21 | /* Note: MIN, MAX are also defined in on some systems 22 | (glibc, IRIX, HP-UX, OSF/1). Therefore you might get warnings about 23 | MIN, MAX macro redefinitions on some systems; the workaround is to 24 | #include this file as the last one among the #include list. */ 25 | 26 | /* Before we define the following symbols we get the file 27 | since otherwise we get redefinitions on some systems if is 28 | included after this file. Likewise for . 29 | If more than one of these system headers define MIN and MAX, pick just 30 | one of the headers (because the definitions most likely are the same). */ 31 | #if HAVE_MINMAX_IN_LIMITS_H 32 | # include 33 | #elif HAVE_MINMAX_IN_SYS_PARAM_H 34 | # include 35 | #endif 36 | 37 | /* Note: MIN and MAX should be used with two arguments of the 38 | same type. They might not return the minimum and maximum of their two 39 | arguments, if the arguments have different types or have unusual 40 | floating-point values. For example, on a typical host with 32-bit 'int', 41 | 64-bit 'long long', and 64-bit IEEE 754 'double' types: 42 | 43 | MAX (-1, 2147483648) returns 4294967295. 44 | MAX (9007199254740992.0, 9007199254740993) returns 9007199254740992.0. 45 | MAX (NaN, 0.0) returns 0.0. 46 | MAX (+0.0, -0.0) returns -0.0. 47 | 48 | and in each case the answer is in some sense bogus. */ 49 | 50 | /* MAX(a,b) returns the maximum of A and B. */ 51 | #ifndef MAX 52 | # define MAX(a,b) ((a) > (b) ? (a) : (b)) 53 | #endif 54 | 55 | /* MIN(a,b) returns the minimum of A and B. */ 56 | #ifndef MIN 57 | # define MIN(a,b) ((a) < (b) ? (a) : (b)) 58 | #endif 59 | 60 | #endif /* _MINMAX_H */ 61 | -------------------------------------------------------------------------------- /OSXIcotools/lib/xalloc-die.c: -------------------------------------------------------------------------------- 1 | /* Report a memory allocation failure and exit. 2 | 3 | Copyright (C) 1997-2000, 2002-2004, 2006, 2009-2018 Free Software 4 | Foundation, Inc. 5 | 6 | This program is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation; either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with this program. If not, see . */ 18 | 19 | #include 20 | #include 21 | #include "xalloc.h" 22 | 23 | #include 24 | 25 | #include "gettext.h" 26 | #define _(msgid) gettext (msgid) 27 | 28 | void 29 | xalloc_die (void) 30 | { 31 | fprintf(stderr, "memory exhausted"); 32 | 33 | /* _Noreturn cannot be given to error, since it may return if 34 | its first argument is 0. To help compilers understand the 35 | xalloc_die does not return, call abort. Also, the abort is a 36 | safety feature if exit_failure is 0 (which shouldn't happen). */ 37 | abort (); 38 | } 39 | -------------------------------------------------------------------------------- /OSXIcotools/lib/xalloc-oversized.h: -------------------------------------------------------------------------------- 1 | /* xalloc-oversized.h -- memory allocation size checking 2 | 3 | Copyright (C) 1990-2000, 2003-2004, 2006-2018 Free Software Foundation, Inc. 4 | 5 | This program is free software: you can redistribute it and/or modify 6 | it under the terms of the GNU General Public License as published by 7 | the Free Software Foundation; either version 3 of the License, or 8 | (at your option) any later version. 9 | 10 | This program is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU General Public License for more details. 14 | 15 | You should have received a copy of the GNU General Public License 16 | along with this program. If not, see . */ 17 | 18 | #ifndef XALLOC_OVERSIZED_H_ 19 | #define XALLOC_OVERSIZED_H_ 20 | 21 | #include 22 | #include 23 | 24 | /* True if N * S would overflow in a size_t calculation, 25 | or would generate a value larger than PTRDIFF_MAX. 26 | This expands to a constant expression if N and S are both constants. 27 | By gnulib convention, SIZE_MAX represents overflow in size 28 | calculations, so the conservative size_t-based dividend to use here 29 | is SIZE_MAX - 1. */ 30 | #define __xalloc_oversized(n, s) \ 31 | ((size_t) (PTRDIFF_MAX < SIZE_MAX ? PTRDIFF_MAX : SIZE_MAX - 1) / (s) < (n)) 32 | 33 | #if PTRDIFF_MAX < SIZE_MAX 34 | typedef ptrdiff_t __xalloc_count_type; 35 | #else 36 | typedef size_t __xalloc_count_type; 37 | #endif 38 | 39 | /* Return 1 if an array of N objects, each of size S, cannot exist 40 | reliably due to size or ptrdiff_t arithmetic overflow. S must be 41 | positive and N must be nonnegative. This is a macro, not a 42 | function, so that it works correctly even when SIZE_MAX < N. */ 43 | 44 | #if 7 <= __GNUC__ 45 | # define xalloc_oversized(n, s) \ 46 | __builtin_mul_overflow_p (n, s, (__xalloc_count_type) 1) 47 | #elif 5 <= __GNUC__ && !defined __ICC && !__STRICT_ANSI__ 48 | # define xalloc_oversized(n, s) \ 49 | (__builtin_constant_p (n) && __builtin_constant_p (s) \ 50 | ? __xalloc_oversized (n, s) \ 51 | : ({ __xalloc_count_type __xalloc_count; \ 52 | __builtin_mul_overflow (n, s, &__xalloc_count); })) 53 | 54 | /* Other compilers use integer division; this may be slower but is 55 | more portable. */ 56 | #else 57 | # define xalloc_oversized(n, s) __xalloc_oversized (n, s) 58 | #endif 59 | 60 | #endif /* !XALLOC_OVERSIZED_H_ */ 61 | -------------------------------------------------------------------------------- /OSXIcotools/lib/xalloc.h: -------------------------------------------------------------------------------- 1 | /* xalloc.h -- malloc with out-of-memory checking 2 | 3 | Copyright (C) 1990-2000, 2003-2004, 2006-2018 Free Software Foundation, Inc. 4 | 5 | This program is free software: you can redistribute it and/or modify 6 | it under the terms of the GNU General Public License as published by 7 | the Free Software Foundation; either version 3 of the License, or 8 | (at your option) any later version. 9 | 10 | This program is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU General Public License for more details. 14 | 15 | You should have received a copy of the GNU General Public License 16 | along with this program. If not, see . */ 17 | 18 | #ifndef XALLOC_H_ 19 | #define XALLOC_H_ 20 | 21 | #include 22 | #include 23 | 24 | #include "xalloc-oversized.h" 25 | 26 | #ifndef _GL_INLINE_HEADER_BEGIN 27 | #error "Please include config.h first." 28 | #endif 29 | _GL_INLINE_HEADER_BEGIN 30 | #ifndef XALLOC_INLINE 31 | # define XALLOC_INLINE _GL_INLINE 32 | #endif 33 | 34 | #ifdef __cplusplus 35 | extern "C" { 36 | #endif 37 | 38 | 39 | #if __GNUC__ >= 3 40 | # define _GL_ATTRIBUTE_MALLOC __attribute__ ((__malloc__)) 41 | #else 42 | # define _GL_ATTRIBUTE_MALLOC 43 | #endif 44 | 45 | #if ! defined __clang__ && \ 46 | (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)) 47 | # define _GL_ATTRIBUTE_ALLOC_SIZE(args) __attribute__ ((__alloc_size__ args)) 48 | #else 49 | # define _GL_ATTRIBUTE_ALLOC_SIZE(args) 50 | #endif 51 | 52 | /* This function is always triggered when memory is exhausted. 53 | It must be defined by the application, either explicitly 54 | or by using gnulib's xalloc-die module. This is the 55 | function to call when one wants the program to die because of a 56 | memory allocation failure. */ 57 | extern _Noreturn void xalloc_die (void); 58 | 59 | void *xmalloc (size_t s) 60 | _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_ALLOC_SIZE ((1)); 61 | void *xzalloc (size_t s) 62 | _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_ALLOC_SIZE ((1)); 63 | void *xcalloc (size_t n, size_t s) 64 | _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_ALLOC_SIZE ((1, 2)); 65 | void *xrealloc (void *p, size_t s) 66 | _GL_ATTRIBUTE_ALLOC_SIZE ((2)); 67 | void *x2realloc (void *p, size_t *pn); 68 | void *xmemdup (void const *p, size_t s) 69 | _GL_ATTRIBUTE_ALLOC_SIZE ((2)); 70 | char *xstrdup (char const *str) 71 | _GL_ATTRIBUTE_MALLOC; 72 | 73 | /* In the following macros, T must be an elementary or structure/union or 74 | typedef'ed type, or a pointer to such a type. To apply one of the 75 | following macros to a function pointer or array type, you need to typedef 76 | it first and use the typedef name. */ 77 | 78 | /* Allocate an object of type T dynamically, with error checking. */ 79 | /* extern t *XMALLOC (typename t); */ 80 | #define XMALLOC(t) ((t *) xmalloc (sizeof (t))) 81 | 82 | /* Allocate memory for N elements of type T, with error checking. */ 83 | /* extern t *XNMALLOC (size_t n, typename t); */ 84 | #define XNMALLOC(n, t) \ 85 | ((t *) (sizeof (t) == 1 ? xmalloc (n) : xnmalloc (n, sizeof (t)))) 86 | 87 | /* Allocate an object of type T dynamically, with error checking, 88 | and zero it. */ 89 | /* extern t *XZALLOC (typename t); */ 90 | #define XZALLOC(t) ((t *) xzalloc (sizeof (t))) 91 | 92 | /* Allocate memory for N elements of type T, with error checking, 93 | and zero it. */ 94 | /* extern t *XCALLOC (size_t n, typename t); */ 95 | #define XCALLOC(n, t) \ 96 | ((t *) (sizeof (t) == 1 ? xzalloc (n) : xcalloc (n, sizeof (t)))) 97 | 98 | 99 | /* Allocate an array of N objects, each with S bytes of memory, 100 | dynamically, with error checking. S must be nonzero. */ 101 | 102 | XALLOC_INLINE void *xnmalloc (size_t n, size_t s) 103 | _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_ALLOC_SIZE ((1, 2)); 104 | XALLOC_INLINE void * 105 | xnmalloc (size_t n, size_t s) 106 | { 107 | if (xalloc_oversized (n, s)) 108 | xalloc_die (); 109 | return xmalloc (n * s); 110 | } 111 | 112 | /* Change the size of an allocated block of memory P to an array of N 113 | objects each of S bytes, with error checking. S must be nonzero. */ 114 | 115 | XALLOC_INLINE void *xnrealloc (void *p, size_t n, size_t s) 116 | _GL_ATTRIBUTE_ALLOC_SIZE ((2, 3)); 117 | XALLOC_INLINE void * 118 | xnrealloc (void *p, size_t n, size_t s) 119 | { 120 | if (xalloc_oversized (n, s)) 121 | xalloc_die (); 122 | return xrealloc (p, n * s); 123 | } 124 | 125 | /* If P is null, allocate a block of at least *PN such objects; 126 | otherwise, reallocate P so that it contains more than *PN objects 127 | each of S bytes. S must be nonzero. Set *PN to the new number of 128 | objects, and return the pointer to the new block. *PN is never set 129 | to zero, and the returned pointer is never null. 130 | 131 | Repeated reallocations are guaranteed to make progress, either by 132 | allocating an initial block with a nonzero size, or by allocating a 133 | larger block. 134 | 135 | In the following implementation, nonzero sizes are increased by a 136 | factor of approximately 1.5 so that repeated reallocations have 137 | O(N) overall cost rather than O(N**2) cost, but the 138 | specification for this function does not guarantee that rate. 139 | 140 | Here is an example of use: 141 | 142 | int *p = NULL; 143 | size_t used = 0; 144 | size_t allocated = 0; 145 | 146 | void 147 | append_int (int value) 148 | { 149 | if (used == allocated) 150 | p = x2nrealloc (p, &allocated, sizeof *p); 151 | p[used++] = value; 152 | } 153 | 154 | This causes x2nrealloc to allocate a block of some nonzero size the 155 | first time it is called. 156 | 157 | To have finer-grained control over the initial size, set *PN to a 158 | nonzero value before calling this function with P == NULL. For 159 | example: 160 | 161 | int *p = NULL; 162 | size_t used = 0; 163 | size_t allocated = 0; 164 | size_t allocated1 = 1000; 165 | 166 | void 167 | append_int (int value) 168 | { 169 | if (used == allocated) 170 | { 171 | p = x2nrealloc (p, &allocated1, sizeof *p); 172 | allocated = allocated1; 173 | } 174 | p[used++] = value; 175 | } 176 | 177 | */ 178 | 179 | XALLOC_INLINE void * 180 | x2nrealloc (void *p, size_t *pn, size_t s) 181 | { 182 | size_t n = *pn; 183 | 184 | if (! p) 185 | { 186 | if (! n) 187 | { 188 | /* The approximate size to use for initial small allocation 189 | requests, when the invoking code specifies an old size of 190 | zero. This is the largest "small" request for the GNU C 191 | library malloc. */ 192 | enum { DEFAULT_MXFAST = 64 * sizeof (size_t) / 4 }; 193 | 194 | n = DEFAULT_MXFAST / s; 195 | n += !n; 196 | } 197 | if (xalloc_oversized (n, s)) 198 | xalloc_die (); 199 | } 200 | else 201 | { 202 | /* Set N = floor (1.5 * N) + 1 so that progress is made even if N == 0. 203 | Check for overflow, so that N * S stays in both ptrdiff_t and 204 | size_t range. The check may be slightly conservative, but an 205 | exact check isn't worth the trouble. */ 206 | if ((PTRDIFF_MAX < SIZE_MAX ? PTRDIFF_MAX : SIZE_MAX) / 3 * 2 / s 207 | <= n) 208 | xalloc_die (); 209 | n += n / 2 + 1; 210 | } 211 | 212 | *pn = n; 213 | return xrealloc (p, n * s); 214 | } 215 | 216 | /* Return a pointer to a new buffer of N bytes. This is like xmalloc, 217 | except it returns char *. */ 218 | 219 | XALLOC_INLINE char *xcharalloc (size_t n) 220 | _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_ALLOC_SIZE ((1)); 221 | XALLOC_INLINE char * 222 | xcharalloc (size_t n) 223 | { 224 | return XNMALLOC (n, char); 225 | } 226 | 227 | #ifdef __cplusplus 228 | } 229 | 230 | /* C++ does not allow conversions from void * to other pointer types 231 | without a cast. Use templates to work around the problem when 232 | possible. */ 233 | 234 | template inline T * 235 | xrealloc (T *p, size_t s) 236 | { 237 | return (T *) xrealloc ((void *) p, s); 238 | } 239 | 240 | template inline T * 241 | xnrealloc (T *p, size_t n, size_t s) 242 | { 243 | return (T *) xnrealloc ((void *) p, n, s); 244 | } 245 | 246 | template inline T * 247 | x2realloc (T *p, size_t *pn) 248 | { 249 | return (T *) x2realloc ((void *) p, pn); 250 | } 251 | 252 | template inline T * 253 | x2nrealloc (T *p, size_t *pn, size_t s) 254 | { 255 | return (T *) x2nrealloc ((void *) p, pn, s); 256 | } 257 | 258 | template inline T * 259 | xmemdup (T const *p, size_t s) 260 | { 261 | return (T *) xmemdup ((void const *) p, s); 262 | } 263 | 264 | #endif 265 | 266 | _GL_INLINE_HEADER_END 267 | 268 | #endif /* !XALLOC_H_ */ 269 | -------------------------------------------------------------------------------- /OSXIcotools/lib/xasprintf.c: -------------------------------------------------------------------------------- 1 | /* vasprintf and asprintf with out-of-memory checking. 2 | Copyright (C) 1999, 2002-2004, 2006, 2009-2018 Free Software Foundation, 3 | Inc. 4 | 5 | This program is free software: you can redistribute it and/or modify 6 | it under the terms of the GNU General Public License as published by 7 | the Free Software Foundation; either version 3 of the License, or 8 | (at your option) any later version. 9 | 10 | This program is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU General Public License for more details. 14 | 15 | You should have received a copy of the GNU General Public License 16 | along with this program. If not, see . */ 17 | 18 | #include 19 | 20 | /* Specification. */ 21 | #include "xvasprintf.h" 22 | 23 | char * 24 | xasprintf (const char *format, ...) 25 | { 26 | va_list args; 27 | char *result; 28 | 29 | va_start (args, format); 30 | result = xvasprintf (format, args); 31 | va_end (args); 32 | 33 | return result; 34 | } 35 | -------------------------------------------------------------------------------- /OSXIcotools/lib/xmalloc.c: -------------------------------------------------------------------------------- 1 | /* xmalloc.c -- malloc with out of memory checking 2 | 3 | Copyright (C) 1990-2000, 2002-2006, 2008-2018 Free Software Foundation, Inc. 4 | 5 | This program is free software: you can redistribute it and/or modify 6 | it under the terms of the GNU General Public License as published by 7 | the Free Software Foundation; either version 3 of the License, or 8 | (at your option) any later version. 9 | 10 | This program is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU General Public License for more details. 14 | 15 | You should have received a copy of the GNU General Public License 16 | along with this program. If not, see . */ 17 | 18 | #include 19 | 20 | #define XALLOC_INLINE _GL_EXTERN_INLINE 21 | 22 | #include "xalloc.h" 23 | 24 | #include 25 | #include 26 | 27 | /* 1 if calloc is known to be compatible with GNU calloc. This 28 | matters if we are not also using the calloc module, which defines 29 | HAVE_CALLOC_GNU and supports the GNU API even on non-GNU platforms. */ 30 | #if defined HAVE_CALLOC_GNU || (defined __GLIBC__ && !defined __UCLIBC__) 31 | enum { HAVE_GNU_CALLOC = 1 }; 32 | #else 33 | enum { HAVE_GNU_CALLOC = 0 }; 34 | #endif 35 | 36 | /* Allocate N bytes of memory dynamically, with error checking. */ 37 | 38 | void * 39 | xmalloc (size_t n) 40 | { 41 | void *p = malloc (n); 42 | if (!p && n != 0) 43 | xalloc_die (); 44 | return p; 45 | } 46 | 47 | /* Change the size of an allocated block of memory P to N bytes, 48 | with error checking. */ 49 | 50 | void * 51 | xrealloc (void *p, size_t n) 52 | { 53 | if (!n && p) 54 | { 55 | /* The GNU and C99 realloc behaviors disagree here. Act like 56 | GNU, even if the underlying realloc is C99. */ 57 | free (p); 58 | return NULL; 59 | } 60 | 61 | p = realloc (p, n); 62 | if (!p && n) 63 | xalloc_die (); 64 | return p; 65 | } 66 | 67 | /* If P is null, allocate a block of at least *PN bytes; otherwise, 68 | reallocate P so that it contains more than *PN bytes. *PN must be 69 | nonzero unless P is null. Set *PN to the new block's size, and 70 | return the pointer to the new block. *PN is never set to zero, and 71 | the returned pointer is never null. */ 72 | 73 | void * 74 | x2realloc (void *p, size_t *pn) 75 | { 76 | return x2nrealloc (p, pn, 1); 77 | } 78 | 79 | /* Allocate S bytes of zeroed memory dynamically, with error checking. 80 | There's no need for xnzalloc (N, S), since it would be equivalent 81 | to xcalloc (N, S). */ 82 | 83 | void * 84 | xzalloc (size_t s) 85 | { 86 | return memset (xmalloc (s), 0, s); 87 | } 88 | 89 | /* Allocate zeroed memory for N elements of S bytes, with error 90 | checking. S must be nonzero. */ 91 | 92 | void * 93 | xcalloc (size_t n, size_t s) 94 | { 95 | void *p; 96 | /* Test for overflow, since objects with size greater than 97 | PTRDIFF_MAX cause pointer subtraction to go awry. Omit size-zero 98 | tests if HAVE_GNU_CALLOC, since GNU calloc never returns NULL if 99 | successful. */ 100 | if (xalloc_oversized (n, s) 101 | || (! (p = calloc (n, s)) && (HAVE_GNU_CALLOC || n != 0))) 102 | xalloc_die (); 103 | return p; 104 | } 105 | 106 | /* Clone an object P of size S, with error checking. There's no need 107 | for xnmemdup (P, N, S), since xmemdup (P, N * S) works without any 108 | need for an arithmetic overflow check. */ 109 | 110 | void * 111 | xmemdup (void const *p, size_t s) 112 | { 113 | return memcpy (xmalloc (s), p, s); 114 | } 115 | 116 | /* Clone STRING. */ 117 | 118 | char * 119 | xstrdup (char const *string) 120 | { 121 | return xmemdup (string, strlen (string) + 1); 122 | } 123 | -------------------------------------------------------------------------------- /OSXIcotools/lib/xsize.c: -------------------------------------------------------------------------------- 1 | #include 2 | #define XSIZE_INLINE _GL_EXTERN_INLINE 3 | #include "xsize.h" 4 | -------------------------------------------------------------------------------- /OSXIcotools/lib/xsize.h: -------------------------------------------------------------------------------- 1 | /* xsize.h -- Checked size_t computations. 2 | 3 | Copyright (C) 2003, 2008-2018 Free Software Foundation, Inc. 4 | 5 | This program is free software; you can redistribute it and/or modify 6 | it under the terms of the GNU General Public License as published by 7 | the Free Software Foundation; either version 3, or (at your option) 8 | any later version. 9 | 10 | This program is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU General Public License for more details. 14 | 15 | You should have received a copy of the GNU General Public License 16 | along with this program; if not, see . */ 17 | 18 | #ifndef _XSIZE_H 19 | #define _XSIZE_H 20 | 21 | /* Get size_t. */ 22 | #include 23 | 24 | /* Get SIZE_MAX. */ 25 | #include 26 | #if HAVE_STDINT_H 27 | # include 28 | #endif 29 | 30 | #ifndef _GL_INLINE_HEADER_BEGIN 31 | #error "Please include config.h first." 32 | #endif 33 | _GL_INLINE_HEADER_BEGIN 34 | #ifndef XSIZE_INLINE 35 | # define XSIZE_INLINE _GL_INLINE 36 | #endif 37 | 38 | /* The size of memory objects is often computed through expressions of 39 | type size_t. Example: 40 | void* p = malloc (header_size + n * element_size). 41 | These computations can lead to overflow. When this happens, malloc() 42 | returns a piece of memory that is way too small, and the program then 43 | crashes while attempting to fill the memory. 44 | To avoid this, the functions and macros in this file check for overflow. 45 | The convention is that SIZE_MAX represents overflow. 46 | malloc (SIZE_MAX) is not guaranteed to fail -- think of a malloc 47 | implementation that uses mmap --, it's recommended to use size_overflow_p() 48 | or size_in_bounds_p() before invoking malloc(). 49 | The example thus becomes: 50 | size_t size = xsum (header_size, xtimes (n, element_size)); 51 | void *p = (size_in_bounds_p (size) ? malloc (size) : NULL); 52 | */ 53 | 54 | /* Convert an arbitrary value >= 0 to type size_t. */ 55 | #define xcast_size_t(N) \ 56 | ((N) <= SIZE_MAX ? (size_t) (N) : SIZE_MAX) 57 | 58 | /* Sum of two sizes, with overflow check. */ 59 | XSIZE_INLINE size_t 60 | #if __GNUC__ >= 3 61 | __attribute__ ((__pure__)) 62 | #endif 63 | xsum (size_t size1, size_t size2) 64 | { 65 | size_t sum = size1 + size2; 66 | return (sum >= size1 ? sum : SIZE_MAX); 67 | } 68 | 69 | /* Sum of three sizes, with overflow check. */ 70 | XSIZE_INLINE size_t 71 | #if __GNUC__ >= 3 72 | __attribute__ ((__pure__)) 73 | #endif 74 | xsum3 (size_t size1, size_t size2, size_t size3) 75 | { 76 | return xsum (xsum (size1, size2), size3); 77 | } 78 | 79 | /* Sum of four sizes, with overflow check. */ 80 | XSIZE_INLINE size_t 81 | #if __GNUC__ >= 3 82 | __attribute__ ((__pure__)) 83 | #endif 84 | xsum4 (size_t size1, size_t size2, size_t size3, size_t size4) 85 | { 86 | return xsum (xsum (xsum (size1, size2), size3), size4); 87 | } 88 | 89 | /* Maximum of two sizes, with overflow check. */ 90 | XSIZE_INLINE size_t 91 | #if __GNUC__ >= 3 92 | __attribute__ ((__pure__)) 93 | #endif 94 | xmax (size_t size1, size_t size2) 95 | { 96 | /* No explicit check is needed here, because for any n: 97 | max (SIZE_MAX, n) == SIZE_MAX and max (n, SIZE_MAX) == SIZE_MAX. */ 98 | return (size1 >= size2 ? size1 : size2); 99 | } 100 | 101 | /* Multiplication of a count with an element size, with overflow check. 102 | The count must be >= 0 and the element size must be > 0. 103 | This is a macro, not a function, so that it works correctly even 104 | when N is of a wider type and N > SIZE_MAX. */ 105 | #define xtimes(N, ELSIZE) \ 106 | ((N) <= SIZE_MAX / (ELSIZE) ? (size_t) (N) * (ELSIZE) : SIZE_MAX) 107 | 108 | /* Check for overflow. */ 109 | #define size_overflow_p(SIZE) \ 110 | ((SIZE) == SIZE_MAX) 111 | /* Check against overflow. */ 112 | #define size_in_bounds_p(SIZE) \ 113 | ((SIZE) != SIZE_MAX) 114 | 115 | _GL_INLINE_HEADER_END 116 | 117 | #endif /* _XSIZE_H */ 118 | -------------------------------------------------------------------------------- /OSXIcotools/lib/xstrndup.c: -------------------------------------------------------------------------------- 1 | /* Duplicate a bounded initial segment of a string, with out-of-memory 2 | checking. 3 | Copyright (C) 2003, 2006-2007, 2009-2018 Free Software Foundation, Inc. 4 | 5 | This program is free software: you can redistribute it and/or modify 6 | it under the terms of the GNU General Public License as published by 7 | the Free Software Foundation; either version 3 of the License, or 8 | (at your option) any later version. 9 | 10 | This program is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU General Public License for more details. 14 | 15 | You should have received a copy of the GNU General Public License 16 | along with this program. If not, see . */ 17 | 18 | #include 19 | 20 | /* Specification. */ 21 | #include "xstrndup.h" 22 | 23 | #include 24 | #include "xalloc.h" 25 | 26 | /* Return a newly allocated copy of at most N bytes of STRING. 27 | In other words, return a copy of the initial segment of length N of 28 | STRING. */ 29 | char * 30 | xstrndup (const char *string, size_t n) 31 | { 32 | char *s = strndup (string, n); 33 | if (! s) 34 | xalloc_die (); 35 | return s; 36 | } 37 | -------------------------------------------------------------------------------- /OSXIcotools/lib/xstrndup.h: -------------------------------------------------------------------------------- 1 | /* Duplicate a bounded initial segment of a string, with out-of-memory 2 | checking. 3 | Copyright (C) 2003, 2009-2018 Free Software Foundation, Inc. 4 | 5 | This program is free software: you can redistribute it and/or modify 6 | it under the terms of the GNU General Public License as published by 7 | the Free Software Foundation; either version 3 of the License, or 8 | (at your option) any later version. 9 | 10 | This program is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU General Public License for more details. 14 | 15 | You should have received a copy of the GNU General Public License 16 | along with this program. If not, see . */ 17 | 18 | #include 19 | 20 | /* Return a newly allocated copy of at most N bytes of STRING. 21 | In other words, return a copy of the initial segment of length N of 22 | STRING. */ 23 | extern char *xstrndup (const char *string, size_t n); 24 | -------------------------------------------------------------------------------- /OSXIcotools/lib/xvasprintf.c: -------------------------------------------------------------------------------- 1 | /* vasprintf and asprintf with out-of-memory checking. 2 | Copyright (C) 1999, 2002-2004, 2006-2018 Free Software Foundation, Inc. 3 | 4 | This program is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation; either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program. If not, see . */ 16 | 17 | #include 18 | 19 | /* Specification. */ 20 | #include "xvasprintf.h" 21 | 22 | #include 23 | #include 24 | #include 25 | #include 26 | 27 | #include "xalloc.h" 28 | 29 | /* Checked size_t computations. */ 30 | #include "xsize.h" 31 | 32 | static char * 33 | xstrcat (size_t argcount, va_list args) 34 | { 35 | char *result; 36 | va_list ap; 37 | size_t totalsize; 38 | size_t i; 39 | char *p; 40 | 41 | /* Determine the total size. */ 42 | totalsize = 0; 43 | va_copy (ap, args); 44 | for (i = argcount; i > 0; i--) 45 | { 46 | const char *next = va_arg (ap, const char *); 47 | totalsize = xsum (totalsize, strlen (next)); 48 | } 49 | va_end (ap); 50 | 51 | /* Test for overflow in the summing pass above or in (totalsize + 1) below. 52 | Also, don't return a string longer than INT_MAX, for consistency with 53 | vasprintf(). */ 54 | if (totalsize == SIZE_MAX || totalsize > INT_MAX) 55 | { 56 | errno = EOVERFLOW; 57 | return NULL; 58 | } 59 | 60 | /* Allocate and fill the result string. */ 61 | result = XNMALLOC (totalsize + 1, char); 62 | p = result; 63 | for (i = argcount; i > 0; i--) 64 | { 65 | const char *next = va_arg (args, const char *); 66 | size_t len = strlen (next); 67 | memcpy (p, next, len); 68 | p += len; 69 | } 70 | *p = '\0'; 71 | 72 | return result; 73 | } 74 | 75 | char * 76 | xvasprintf (const char *format, va_list args) 77 | { 78 | char *result; 79 | 80 | /* Recognize the special case format = "%s...%s". It is a frequently used 81 | idiom for string concatenation and needs to be fast. We don't want to 82 | have a separate function xstrcat() for this purpose. */ 83 | { 84 | size_t argcount = 0; 85 | const char *f; 86 | 87 | for (f = format;;) 88 | { 89 | if (*f == '\0') 90 | /* Recognized the special case of string concatenation. */ 91 | return xstrcat (argcount, args); 92 | if (*f != '%') 93 | break; 94 | f++; 95 | if (*f != 's') 96 | break; 97 | f++; 98 | argcount++; 99 | } 100 | } 101 | 102 | if (vasprintf (&result, format, args) < 0) 103 | { 104 | if (errno == ENOMEM) 105 | xalloc_die (); 106 | return NULL; 107 | } 108 | 109 | return result; 110 | } 111 | -------------------------------------------------------------------------------- /OSXIcotools/lib/xvasprintf.h: -------------------------------------------------------------------------------- 1 | /* vasprintf and asprintf with out-of-memory checking. 2 | Copyright (C) 2002-2004, 2006-2018 Free Software Foundation, Inc. 3 | 4 | This program is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation; either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program. If not, see . */ 16 | 17 | #ifndef _XVASPRINTF_H 18 | #define _XVASPRINTF_H 19 | 20 | /* Get va_list. */ 21 | #include 22 | 23 | /* The __attribute__ feature is available in gcc versions 2.5 and later. 24 | The __-protected variants of the attributes 'format' and 'printf' are 25 | accepted by gcc versions 2.6.4 (effectively 2.7) and later. 26 | We enable _GL_ATTRIBUTE_FORMAT only if these are supported too, because 27 | gnulib and libintl do '#define printf __printf__' when they override 28 | the 'printf' function. */ 29 | #if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 7) 30 | # define _GL_ATTRIBUTE_FORMAT(spec) __attribute__ ((__format__ spec)) 31 | #else 32 | # define _GL_ATTRIBUTE_FORMAT(spec) /* empty */ 33 | #endif 34 | 35 | #ifdef __cplusplus 36 | extern "C" { 37 | #endif 38 | 39 | /* Write formatted output to a string dynamically allocated with malloc(), 40 | and return it. Upon [ENOMEM] memory allocation error, call xalloc_die. 41 | On some other error 42 | - [EOVERFLOW] resulting string length is > INT_MAX, 43 | - [EINVAL] invalid format string, 44 | - [EILSEQ] error during conversion between wide and multibyte characters, 45 | return NULL. */ 46 | extern char *xasprintf (const char *format, ...) 47 | _GL_ATTRIBUTE_FORMAT ((__printf__, 1, 2)); 48 | extern char *xvasprintf (const char *format, va_list args) 49 | _GL_ATTRIBUTE_FORMAT ((__printf__, 1, 0)); 50 | 51 | #ifdef __cplusplus 52 | } 53 | #endif 54 | 55 | #endif /* _XVASPRINTF_H */ 56 | -------------------------------------------------------------------------------- /OSXIcotools/wrestool/extract.h: -------------------------------------------------------------------------------- 1 | /* extract.h 2 | * 3 | * Copyright (C) 1998 Oskar Liljeblad 4 | * Copyright (C) 2017 Daniele Cattaneo 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | #ifndef EXTRACT_H 21 | #define EXTRACT_H 22 | 23 | #include "wrestool.h" 24 | 25 | 26 | void *extract_resource(WinLibrary *, WinResource *, size_t *, bool *, char *, char *, bool, wres_error *); 27 | 28 | 29 | #endif /* extract_h */ 30 | -------------------------------------------------------------------------------- /OSXIcotools/wrestool/fileread.c: -------------------------------------------------------------------------------- 1 | /* fileread.c - Offset checking routines for file reading 2 | * 3 | * Copyright (C) 1998 Oskar Liljeblad 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #include 20 | #include /* C89 */ 21 | #include /* C89 */ 22 | #include /* C89 */ 23 | #include /* POSIX/Gnulib */ 24 | #include 25 | #include "gettext.h" /* Gnulib */ 26 | #define _(s) gettext(s) 27 | #define N_(s) gettext_noop(s) 28 | #include "fileread.h" 29 | #include "win32.h" 30 | #include "xalloc.h" /* Gnulib */ 31 | #include "minmax.h" /* Gnulib */ 32 | 33 | 34 | static off_t calc_vma_size (WinLibrary *); 35 | static wres_error load_ne_library(WinLibrary *); 36 | static wres_error load_pe_library(WinLibrary *); 37 | 38 | 39 | /* Check whether access to a PE_SECTIONS is allowed */ 40 | #define BAD_PE_SECTIONS(fi, module) ( \ 41 | BAD_POINTER(fi, PE_HEADER(module)->optional_header) || \ 42 | BAD_POINTER(fi, PE_HEADER(module)->file_header.number_of_sections) || \ 43 | BAD_OFFSET(fi, ((void*)PE_SECTIONS(module)), sizeof(Win32ImageSectionHeader) \ 44 | * PE_HEADER(module)->file_header.number_of_sections)) 45 | 46 | #define RETURN_IF_BAD_PE_SECTIONS(fi, ret, module) do { \ 47 | if (BAD_PE_SECTIONS(fi, module)) { \ 48 | return (ret); \ 49 | } \ 50 | } while(0) 51 | 52 | 53 | /* check_offset: 54 | * Check if a chunk of data (determined by offset and size) 55 | * is within the bounds of the WinLibrary file. 56 | * Usually not called directly. 57 | */ 58 | bool 59 | check_offset(const char *memory, size_t total_size, const char *name, const void *offset, size_t size) 60 | { 61 | const char* memory_end = memory + total_size; 62 | const char* block = (const char*) offset; 63 | const char* block_end = block + size; 64 | 65 | /*debug("check_offset: size=%x vs %x offset=%x size=%x\n", 66 | need_size, total_size, (char *) offset - memory, size);*/ 67 | 68 | if (((memory > memory_end) || (block > block_end)) 69 | || (block < memory) || (block >= memory_end) || (block_end > memory_end)) 70 | return false; 71 | 72 | return true; 73 | } 74 | 75 | 76 | 77 | /* load_library: 78 | * 79 | * Read header and get resource directory offset in a Windows library 80 | * (AKA module). 81 | */ 82 | wres_error load_library(WinLibrary *fi) 83 | { 84 | fseek(fi->file, 0, SEEK_END); 85 | fi->total_size = ftello(fi->file); 86 | fseek(fi->file, 0, SEEK_SET); 87 | if (fi->total_size == -1) 88 | return -errno; 89 | if (fi->total_size == 0) 90 | return WRES_ERROR_WRONGFORMAT; 91 | 92 | /* read all of file */ 93 | fi->memory = mmap(NULL, fi->total_size, PROT_READ | PROT_WRITE, MAP_FILE | MAP_PRIVATE, fileno(fi->file), 0); 94 | if (fi->memory == MAP_FAILED) 95 | return -errno; 96 | 97 | /* check for DOS header signature `MZ' */ 98 | RETURN_IF_BAD_POINTER(fi, WRES_ERROR_WRONGFORMAT, MZ_HEADER(fi->memory)->magic); 99 | if (MZ_HEADER(fi->memory)->magic == IMAGE_DOS_SIGNATURE) { 100 | RETURN_IF_BAD_POINTER(fi, WRES_ERROR_WRONGFORMAT, *MZ_HEADER(fi->memory)); 101 | DOSImageHeader *mz_header = MZ_HEADER(fi->memory); 102 | 103 | RETURN_IF_BAD_POINTER(fi, WRES_ERROR_WRONGFORMAT, mz_header->lfanew); 104 | if (mz_header->lfanew < sizeof (DOSImageHeader)) 105 | return WRES_ERROR_WRONGFORMAT; 106 | 107 | /* falls through */ 108 | } 109 | 110 | /* check for OS2/Win16 header signature `NE' */ 111 | RETURN_IF_BAD_POINTER(fi, WRES_ERROR_WRONGFORMAT, NE_HEADER(fi->memory)->magic); 112 | if (NE_HEADER(fi->memory)->magic == IMAGE_OS2_SIGNATURE) { 113 | RETURN_IF_BAD_POINTER(fi, WRES_ERROR_WRONGFORMAT, *NE_HEADER(fi->memory)); 114 | return load_ne_library(fi); 115 | } 116 | 117 | /* check for NT header signature `PE' */ 118 | RETURN_IF_BAD_POINTER(fi, WRES_ERROR_WRONGFORMAT, PE_HEADER(fi->memory)->signature); 119 | if (PE_HEADER(fi->memory)->signature == IMAGE_NT_SIGNATURE) { 120 | RETURN_IF_BAD_POINTER(fi, WRES_ERROR_WRONGFORMAT, *PE_HEADER(fi->memory)); 121 | return load_pe_library(fi); 122 | } 123 | 124 | /* other (unknown) header signature was found */ 125 | return WRES_ERROR_WRONGFORMAT; 126 | } 127 | 128 | 129 | /* calc_vma_size: 130 | * Calculate the total amount of memory needed for a 32-bit Windows 131 | * module. Returns -1 if file was too small. 132 | */ 133 | static off_t 134 | calc_vma_size (WinLibrary *fi) 135 | { 136 | Win32ImageSectionHeader *seg; 137 | size_t c, segcount, size; 138 | 139 | size = 0; 140 | RETURN_IF_BAD_POINTER(fi, -1, PE_HEADER(fi->memory)->file_header.number_of_sections); 141 | segcount = PE_HEADER(fi->memory)->file_header.number_of_sections; 142 | 143 | /* If there are no segments, just process file like it is. 144 | * This is (probably) not the right thing to do, but problems 145 | * will be delt with later anyway. 146 | */ 147 | if (segcount == 0) 148 | return fi->total_size; 149 | 150 | RETURN_IF_BAD_PE_SECTIONS(fi, -1, fi->memory); 151 | seg = PE_SECTIONS(fi->memory); 152 | RETURN_IF_BAD_POINTER(fi, -1, *seg); 153 | 154 | for (c = 0 ; c < segcount ; c++) { 155 | RETURN_IF_BAD_POINTER(fi, 0, *seg); 156 | 157 | size = MAX(size, seg->virtual_address + seg->size_of_raw_data); 158 | /* Pecoff 8.2 pag 24: VirtualSize is The total size of the section when 159 | loaded into memory. If this value is greater than SizeOfRawData, the se- 160 | ction is zero-padded. This field is valid only for executable images and 161 | should be set to zero for object files. */ 162 | size = MAX(size, seg->virtual_address + seg->misc.virtual_size); 163 | seg++; 164 | } 165 | 166 | return size; 167 | } 168 | 169 | 170 | static wres_error load_ne_library(WinLibrary *fi) 171 | { 172 | OS2ImageHeader *header = NE_HEADER(fi->memory); 173 | uint16_t *alignshift; 174 | 175 | RETURN_IF_BAD_POINTER(fi, WRES_ERROR_PREMATUREEND, header->rsrctab); 176 | RETURN_IF_BAD_POINTER(fi, WRES_ERROR_PREMATUREEND, header->restab); 177 | fi->binary_type = NE_BINARY; 178 | 179 | if (!(header->rsrctab >= header->restab)) { 180 | alignshift = (uint16_t *) ((uint8_t *) NE_HEADER(fi->memory) + header->rsrctab); 181 | fi->first_resource = ((uint8_t *) alignshift) + sizeof(uint16_t); 182 | RETURN_IF_BAD_POINTER(fi, WRES_ERROR_PREMATUREEND, *(Win16NETypeInfo *) fi->first_resource); 183 | } else { 184 | /* no resources */ 185 | fi->first_resource = NULL; 186 | } 187 | 188 | return WRES_ERROR_NONE; 189 | } 190 | 191 | 192 | static wres_error load_pe_library(WinLibrary *fi) 193 | { 194 | WinLibrary fi_new = *fi; 195 | 196 | /* allocate new memory */ 197 | fi_new.total_size = calc_vma_size(fi); 198 | if (fi_new.total_size <= 0) /* calc_vma_size has reported error */ 199 | return WRES_ERROR_WRONGFORMAT; 200 | 201 | fi_new.memory = mmap(NULL, fi_new.total_size, PROT_READ | PROT_WRITE, MAP_ANON | MAP_PRIVATE, -1, 0); 202 | if (fi_new.memory == MAP_FAILED) 203 | return -errno; 204 | 205 | wres_error err = WRES_ERROR_PREMATUREEND; 206 | 207 | /* relocate memory, start from last section */ 208 | Win32ImageNTHeaders *pe_header = PE_HEADER(fi->memory); 209 | if (BAD_PE_SECTIONS(fi, fi->memory)) 210 | goto fail; 211 | PE32plusImageNTHeaders *peplus_header = (PE32plusImageNTHeaders*)pe_header; 212 | IF_BAD_POINTER(fi, pe_header->optional_header.magic) 213 | goto fail; 214 | 215 | Win32ImageDataDirectory *dir; 216 | if (pe_header->optional_header.magic == OPTIONAL_MAGIC_PE32_64) { /* PE32+ */ 217 | /* find resource directory */ 218 | fi_new.binary_type = PEPLUS_BINARY; 219 | IF_BAD_POINTER(fi, peplus_header->optional_header.data_directory[IMAGE_DIRECTORY_ENTRY_RESOURCE]) 220 | goto fail; 221 | 222 | dir = peplus_header->optional_header.data_directory + IMAGE_DIRECTORY_ENTRY_RESOURCE; 223 | } else if (pe_header->optional_header.magic == OPTIONAL_MAGIC_PE32) { /* PE32 */ 224 | /* find resource directory */ 225 | fi_new.binary_type = PE_BINARY; 226 | IF_BAD_POINTER(fi, pe_header->optional_header.data_directory[IMAGE_DIRECTORY_ENTRY_RESOURCE]) 227 | goto fail; 228 | 229 | dir = pe_header->optional_header.data_directory + IMAGE_DIRECTORY_ENTRY_RESOURCE; 230 | } else { 231 | err = WRES_ERROR_WRONGFORMAT; 232 | goto fail; 233 | } 234 | 235 | if (dir->size > 0) { 236 | int d; 237 | Win32ImageSectionHeader *pe_sections = PE_SECTIONS(fi->memory); 238 | /* we don't need to do OFFSET checking for the sections. 239 | * calc_vma_size has already done that */ 240 | for (d = pe_header->file_header.number_of_sections - 1; d >= 0 ; d--) { 241 | Win32ImageSectionHeader *pe_sec = pe_sections + d; 242 | 243 | void *dest = fi_new.memory + pe_sec->virtual_address; 244 | off_t size = pe_sec->size_of_raw_data; 245 | off_t offset = pe_sec->pointer_to_raw_data; 246 | 247 | if (pe_sec->characteristics & IMAGE_SCN_CNT_UNINITIALIZED_DATA) 248 | continue; 249 | 250 | /* Protect against memory moves overwriting the section table */ 251 | if ((uint8_t*)(fi->memory + pe_sec->virtual_address) < 252 | (uint8_t*)(pe_sections + pe_header->file_header.number_of_sections)) { 253 | err = WRES_ERROR_INVALIDSECLAYOUT; 254 | goto fail; 255 | } 256 | 257 | /* do not load sections we are not interested in */ 258 | if ((pe_sec->virtual_address < dir->virtual_address && 259 | pe_sec->virtual_address + pe_sec->size_of_raw_data <= dir->virtual_address) || 260 | (pe_sec->virtual_address >= dir->virtual_address + dir->size)) 261 | continue; 262 | 263 | IF_BAD_OFFSET(&fi_new, dest, size) 264 | goto fail; 265 | IF_BAD_OFFSET(fi, fi->memory + offset, size) 266 | goto fail; 267 | 268 | void *res = mmap(dest, size, 269 | PROT_READ | PROT_WRITE, MAP_FILE | MAP_FIXED | MAP_PRIVATE, 270 | fileno(fi_new.file), offset); 271 | if (res == MAP_FAILED) { 272 | /* As in PE files there is no requirement for sections in the file 273 | * to be aligned in the same way as they are required to be aligned 274 | * in memory, this code path will be hit very frequently */ 275 | memcpy(dest, fi->memory + offset, size); 276 | } 277 | } 278 | 279 | fi_new.first_resource = ((uint8_t *)fi_new.memory) + dir->virtual_address; 280 | } else { 281 | /* no resources */ 282 | fi_new.first_resource = NULL; 283 | } 284 | 285 | munmap(fi->memory, fi->total_size); 286 | *fi = fi_new; 287 | return WRES_ERROR_NONE; 288 | 289 | fail: 290 | munmap(fi_new.memory, fi_new.total_size); 291 | return err; 292 | } 293 | 294 | 295 | void unload_library(WinLibrary *fi) 296 | { 297 | munmap(fi->memory, fi->total_size); 298 | } 299 | 300 | 301 | 302 | -------------------------------------------------------------------------------- /OSXIcotools/wrestool/fileread.h: -------------------------------------------------------------------------------- 1 | /* fileread.h - Offset checking routines for file reading 2 | * 3 | * Copyright (C) 1998 Oskar Liljeblad 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #ifndef FILEREAD_H 20 | #define FILEREAD_H 21 | 22 | #include /* POSIX/Gnulib */ 23 | #include "wrestool.h" 24 | 25 | #define BAD_POINTER(fi, x) \ 26 | (!check_offset((fi)->memory, (fi)->total_size, (fi)->name, &(x), sizeof(x))) 27 | #define BAD_OFFSET(fi, x, s) \ 28 | (!check_offset((fi)->memory, (fi)->total_size, (fi)->name, (x), (s))) 29 | 30 | #define IF_BAD_POINTER(fi, x) \ 31 | if (BAD_POINTER(fi, x)) 32 | #define IF_BAD_OFFSET(fi, x, s) \ 33 | if (BAD_OFFSET(fi, x, s)) 34 | 35 | #define RETURN_IF_BAD_POINTER(fi, r, x) \ 36 | IF_BAD_POINTER(fi, x) { \ 37 | /*printf("bad_pointer in %s:%d\n", __FILE__, __LINE__);*/ \ 38 | return (r); \ 39 | } 40 | #define RETURN_IF_BAD_OFFSET(fi, r, x, s) \ 41 | IF_BAD_OFFSET(fi, x, s) { \ 42 | /*printf("bad_offset in %s:%d\n", __FILE__, __LINE__);*/ \ 43 | return (r); \ 44 | } 45 | 46 | #define RET_NULL_AND_SET_ERR_IF_BAD_POINTER(fi, err, x) \ 47 | IF_BAD_POINTER(fi, x) { \ 48 | /*printf("bad_pointer in %s:%d\n", __FILE__, __LINE__);*/ \ 49 | if (err) *(err) = WRES_ERROR_PREMATUREEND; \ 50 | return NULL; \ 51 | } 52 | #define RET_NULL_AND_SET_ERR_IF_BAD_OFFSET(fi, err, x, s) \ 53 | IF_BAD_OFFSET(fi, x, s) { \ 54 | /*printf("bad_offset in %s:%d\n", __FILE__, __LINE__);*/ \ 55 | if (err) *(err) = WRES_ERROR_PREMATUREEND; \ 56 | return NULL; \ 57 | } 58 | 59 | wres_error load_library(WinLibrary *); 60 | void unload_library(WinLibrary *); 61 | bool check_offset(const char *, size_t, const char *, const void *, size_t); 62 | 63 | #endif 64 | -------------------------------------------------------------------------------- /OSXIcotools/wrestool/osxwres.h: -------------------------------------------------------------------------------- 1 | /* osxwres.h - wrestool bridge for Mac OS X 2 | * 3 | * Copyright (C) 1998 Oskar Liljeblad 4 | * Copyright (C) 2012 Daniele Cattaneo 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | #ifndef OSXWRES_H 21 | #define OSXWRES_H 22 | 23 | #include "wrestool.h" 24 | #include "restable.h" 25 | #include "fileread.h" 26 | 27 | 28 | extern NSString const *EIIcotoolsErrorDomain; 29 | 30 | 31 | NSData *get_resource_data (WinLibrary *, char *, char *, char *, wres_error *); 32 | NSError *nserror_from_wreserror(wres_error err); 33 | 34 | #endif 35 | -------------------------------------------------------------------------------- /OSXIcotools/wrestool/osxwres.m: -------------------------------------------------------------------------------- 1 | /* osxwres.m - wrestool bridge for Mac OS X 2 | * 3 | * Copyright (C) 1998 Oskar Liljeblad 4 | * Copyright (C) 2012 Daniele Cattaneo 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | #import 21 | #include "osxwres.h" 22 | #include "restypes.h" 23 | #include "restable.h" 24 | #include "extract.h" 25 | 26 | 27 | NSString *EIIcotoolsErrorDomain = @"EIErrorDomain"; 28 | 29 | 30 | NSData *get_resource_data(WinLibrary *fi, char *type, char *name, char *lang, wres_error *err) 31 | { 32 | int level; 33 | size_t size; 34 | bool free_it; 35 | void *memory; 36 | WinResource* wr; 37 | NSData *icoData; 38 | 39 | if (type == NULL) type = ""; 40 | if (name == NULL) name = ""; 41 | if (lang == NULL) lang = ""; 42 | 43 | wr = find_resource(fi, type, name, lang, &level, err); 44 | if (!wr) 45 | return NULL; 46 | 47 | memory = extract_resource(fi, wr, &size, &free_it, type, lang, false, err); 48 | if (!memory) 49 | return NULL; 50 | 51 | if (free_it) { 52 | icoData = [[NSData alloc] initWithBytesNoCopy:memory length:size freeWhenDone:YES]; 53 | } else { 54 | icoData = [[NSData alloc] initWithBytes:memory length:size]; 55 | } 56 | return icoData; 57 | } 58 | 59 | 60 | NSError *nserror_from_wreserror(wres_error err) 61 | { 62 | if (err >= WRES_ERROR_ERRNO_FIRST && WRES_ERROR_ERRNO_LAST >= err) { 63 | return [NSError errorWithDomain:NSPOSIXErrorDomain code:-err userInfo:nil]; 64 | } 65 | NSString *desc = [NSString stringWithUTF8String:wres_strerr(err)]; 66 | return [NSError errorWithDomain:EIIcotoolsErrorDomain code:err userInfo:@{NSDebugDescriptionErrorKey: desc}]; 67 | } 68 | 69 | 70 | -------------------------------------------------------------------------------- /OSXIcotools/wrestool/restable.h: -------------------------------------------------------------------------------- 1 | /* restable.h - Decoding PE and NE resource tables 2 | * 3 | * Copyright (C) 1998 Oskar Liljeblad 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #ifndef RESTABLE_H 20 | #define RESTABLE_H 21 | 22 | #include "common/intutil.h" 23 | #include "wrestool.h" 24 | 25 | 26 | typedef void (*DoResourceCallback) (WinLibrary *, WinResource *, WinResource *, WinResource *, WinResource *); 27 | wres_error do_resources (WinLibrary *, const char *, const char *, const char *, DoResourceCallback); 28 | void print_resources_callback (WinLibrary *, WinResource *, WinResource *, WinResource *, WinResource *); 29 | 30 | WinResource *list_resources(WinLibrary *, WinResource *, int *, wres_error *); 31 | WinResource *find_resource(WinLibrary *, const char *, const char *, const char *, int *, wres_error *); 32 | void *get_resource_entry(WinLibrary *, WinResource *, size_t *, wres_error *); 33 | 34 | 35 | #endif 36 | -------------------------------------------------------------------------------- /OSXIcotools/wrestool/restypes.c: -------------------------------------------------------------------------------- 1 | /* restypes.c - Resource type exchange functions for wrestool 2 | * 3 | * Copyright (C) 1998 Oskar Liljeblad 4 | * Copyright (C) 2012, 2016 Daniele Cattaneo 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | #include "restypes.h" 21 | #include "wrestool.h" 22 | 23 | 24 | static const char *res_types[] = { 25 | /* 0x01: */ 26 | "cursor", "bitmap", "icon", "menu", "dialog", "string", 27 | "fontdir", "font", "accelerator", "rcdata", "messagelist", 28 | "group_cursor", NULL, "group_icon", NULL, 29 | /* the following are not defined in winbase.h, but found in wrc. */ 30 | /* 0x10: */ 31 | "version", "dlginclude", NULL, "plugplay", "vxd", 32 | "anicursor", "aniicon" 33 | }; 34 | #define RES_TYPE_COUNT (sizeof(res_types)/sizeof(char *)) 35 | 36 | /* res_type_id_to_string: 37 | * Translate a numeric resource type to it's corresponding string type. 38 | * (For informative-ness.) 39 | */ 40 | const char *res_type_id_to_string (int id) 41 | { 42 | if (id == 241) 43 | return "toolbar"; 44 | if (id > 0 && id <= RES_TYPE_COUNT) 45 | return res_types[id-1]; 46 | return NULL; 47 | } 48 | 49 | /* res_type_string_to_id: 50 | * Translate a resource type string to integer. 51 | * (Used to convert the --type option.) 52 | */ 53 | const char *res_type_string_to_id (char *type) 54 | { 55 | static const char *res_type_ids[] = { 56 | "-1", "-2", "-3", "-4", "-5", "-6", "-7", "-8", "-9", "-10", 57 | "-11", "-12", NULL, "-14", NULL, "-16", "-17", NULL, "-19", 58 | "-20", "-21", "-22" 59 | }; 60 | int c; 61 | 62 | if (type == NULL) 63 | return NULL; 64 | 65 | for (c = 0 ; c < RES_TYPE_COUNT ; c++) { 66 | if (res_types[c] != NULL && !strcasecmp(type, res_types[c])) 67 | return res_type_ids[c]; 68 | } 69 | 70 | return type; 71 | } 72 | -------------------------------------------------------------------------------- /OSXIcotools/wrestool/restypes.h: -------------------------------------------------------------------------------- 1 | /* restypes.h - Resource type exchange functions for wrestool 2 | * 3 | * Copyright (C) 1998 Oskar Liljeblad 4 | * Copyright (C) 2012 Daniele Cattaneo 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | #ifndef RESTYPES_H 21 | #define RESTYPES_H 22 | 23 | const char *res_type_id_to_string (int); 24 | const char *res_type_string_to_id (char *); 25 | 26 | #endif 27 | -------------------------------------------------------------------------------- /OSXIcotools/wrestool/wrestool.c: -------------------------------------------------------------------------------- 1 | /* wrestool.h - Common definitions for wrestool 2 | * 3 | * Copyright (C) 1998 Oskar Liljeblad 4 | * Copyright (C) 2012 Daniele Cattaneo 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | #include 21 | #include "fileread.h" 22 | #include "wrestool.h" 23 | 24 | 25 | WinLibrary *new_winlibrary_from_file(const char *fn, wres_error *err) 26 | { 27 | WinLibrary *fl = calloc(sizeof(WinLibrary), 1); 28 | 29 | fl->name = strdup(fn); 30 | if (!fl->name) { 31 | if (err) *err = WRES_ERROR_OUTOFMEMORY; 32 | free(fl); 33 | return NULL; 34 | } 35 | 36 | /* open file */ 37 | fl->file = fopen(fl->name, "rb"); 38 | if (fl->file == NULL) { 39 | if (err) *err = -errno; 40 | free(fl->name); 41 | free(fl); 42 | return NULL; 43 | } 44 | 45 | /* identify file and find resource table */ 46 | wres_error e; 47 | if ((e = load_library(fl))) { 48 | /* error reported by load_library */ 49 | free_winlibrary(fl); 50 | if (err) *err = e; 51 | return NULL; 52 | } 53 | 54 | return fl; 55 | } 56 | 57 | 58 | void free_winlibrary(WinLibrary *fl) 59 | { 60 | unload_library(fl); 61 | if (fl->file) 62 | fclose(fl->file); 63 | free(fl->name); 64 | } 65 | 66 | 67 | const char *wres_strerr(wres_error err) 68 | { 69 | if (err < WRES_ERROR_FIRST || WRES_ERROR_LAST < err) 70 | return "unknown error code"; 71 | 72 | if (err >= WRES_ERROR_ERRNO_FIRST && WRES_ERROR_ERRNO_LAST >= err) 73 | return strerror(-err); 74 | const char *errors[] = { 75 | "no error", /* WRES_ERROR_NONE */ 76 | "unknown error", /* WRES_ERROR_UNKNOWN */ 77 | "out of memory", /* WRES_ERROR_OUTOFMEMORY */ 78 | "suitable resource not found", /* WRES_ERROR_RESNOTFOUND */ 79 | "not a PE or NE executable", /* WRES_ERROR_WRONGFORMAT */ 80 | "no resource directory found", /* WRES_ERROR_NORESDIR */ 81 | "corrupt file, premature end", /* WRES_ERROR_PREMATUREEND */ 82 | "no resources found", /* WRES_ERROR_NORESOURCES */ 83 | "invalid resource table", /* WRES_ERROR_INVALIDRESTABLE */ 84 | "invalid function argument", /* WRES_ERROR_INVALIDPARAM */ 85 | "unsupported resource type", /* WRES_ERROR_UNSUPPRESTYPE */ 86 | "invalid section layout", /* WRES_ERROR_INVALIDSECLAYOUT */ 87 | "invalid bitmap data", /* WRES_ERROR_INVALIDDIB */ 88 | }; 89 | return errors[err]; 90 | } 91 | 92 | -------------------------------------------------------------------------------- /OSXIcotools/wrestool/wrestool.h: -------------------------------------------------------------------------------- 1 | /* wrestool.h - Common definitions for wrestool 2 | * 3 | * Copyright (C) 1998 Oskar Liljeblad 4 | * Copyright (C) 2012 Daniele Cattaneo 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | #ifndef WRESTOOL_H 21 | #define WRESTOOL_H 22 | 23 | #include 24 | #include /* POSIX */ 25 | #include /* C89 */ 26 | #include /* C89 */ 27 | #include /* C89 */ 28 | #include /* POSIX/Gnulib */ 29 | #include /* C89 */ 30 | #include /* C89 */ 31 | #include /* GNU Libc/Gnulib */ 32 | 33 | 34 | #define NE_BINARY 0 35 | #define PE_BINARY 1 36 | #define PEPLUS_BINARY 2 37 | 38 | typedef struct _WinLibrary { 39 | char *name; 40 | FILE *file; 41 | char *memory; 42 | uint8_t *first_resource; 43 | int binary_type; 44 | off_t total_size; 45 | } WinLibrary; 46 | 47 | typedef struct _WinResource { 48 | char id[256]; 49 | void *this; 50 | void *children; 51 | int level; 52 | bool numeric_id; 53 | bool is_directory; 54 | } WinResource; 55 | 56 | #define WINRES_ID_MAXLEN (256) 57 | 58 | 59 | typedef int wres_error; 60 | enum { 61 | WRES_ERROR_ERRNO_FIRST = -ELAST, 62 | WRES_ERROR_ERRNO_LAST = -1, 63 | WRES_ERROR_NONE = 0, 64 | WRES_ERROR_UNKNOWN, 65 | WRES_ERROR_OUTOFMEMORY, 66 | WRES_ERROR_RESNOTFOUND, 67 | WRES_ERROR_WRONGFORMAT, 68 | WRES_ERROR_NORESDIR, 69 | WRES_ERROR_PREMATUREEND, 70 | WRES_ERROR_NORESOURCES, 71 | WRES_ERROR_INVALIDRESTABLE, 72 | WRES_ERROR_INVALIDPARAM, 73 | WRES_ERROR_UNSUPPRESTYPE, 74 | WRES_ERROR_INVALIDSECLAYOUT, 75 | WRES_ERROR_INVALIDDIB, 76 | 77 | WRES_ERROR_END, 78 | WRES_ERROR_FIRST = WRES_ERROR_ERRNO_FIRST, 79 | WRES_ERROR_LAST = WRES_ERROR_END-1, 80 | }; 81 | 82 | 83 | WinLibrary *new_winlibrary_from_file(const char *fn, wres_error *); 84 | void free_winlibrary(WinLibrary *fl); 85 | const char *wres_strerr(wres_error); 86 | 87 | 88 | #endif 89 | -------------------------------------------------------------------------------- /PackageResources/Distribution.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | QLWindowsApps 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | QLWindowsApps.pkg 21 | WindowsAppsImporter.pkg 22 | 23 | -------------------------------------------------------------------------------- /PackageResources/Resources/welcome.rtf: -------------------------------------------------------------------------------- 1 | {\rtf1\ansi\ansicpg1252\cocoartf2706 2 | \cocoatextscaling0\cocoaplatform0{\fonttbl\f0\fswiss\fcharset0 Helvetica-Bold;\f1\fswiss\fcharset0 Helvetica;} 3 | {\colortbl;\red255\green255\blue255;} 4 | {\*\expandedcolortbl;;} 5 | {\*\listtable{\list\listtemplateid1\listhybrid{\listlevel\levelnfc23\levelnfcn23\leveljc0\leveljcn0\levelfollow0\levelstartat1\levelspace360\levelindent0{\*\levelmarker \{disc\}}{\leveltext\leveltemplateid1\'01\uc0\u8226 ;}{\levelnumbers;}\fi-360\li720\lin720 }{\listname ;}\listid1}} 6 | {\*\listoverridetable{\listoverride\listid1\listoverridecount0\ls1}} 7 | \paperw11900\paperh16840\margl1440\margr1440\vieww9320\viewh10880\viewkind0 8 | \pard\tx566\tx1133\tx1700\tx2267\tx2834\tx3401\tx3968\tx4535\tx5102\tx5669\tx6236\tx6803\pardirnatural\partightenfactor0 9 | 10 | \f0\b\fs24 \cf0 QLWindowsApps 11 | \f1\b0 includes a QuickLook Plugin and a Spotlight importer for Microsoft Windows DLL and EXE files, intended as companions to Wine on macOS. It is based on a modified version of icoutils by Oskar Liljeblad and Frank Richter.\ 12 | \pard\tx566\tx1133\tx1700\tx2267\tx2834\tx3401\tx3968\tx4535\tx5102\tx5669\tx6236\tx6803\sb200\sa100\pardirnatural\partightenfactor0 13 | 14 | \f0\b\fs36 \cf0 Features 15 | \f1\b0\fs24 \ 16 | \pard\tx220\tx494\tx686\tx720\tx1133\tx1700\tx2267\tx2834\tx3401\tx3968\tx4535\tx5102\tx5669\tx6236\tx6803\li498\fi-499\pardirnatural\partightenfactor0 17 | \ls1\ilvl0\cf0 {\listtext \uc0\u8226 }EXEs and DLLs can be Quick-Looked in the Finder and their properties (version info and bitness) will be visible to Spotlight.\ 18 | {\listtext \uc0\u8226 }EXEs will have an icon just like native apps.\ 19 | {\listtext \uc0\u8226 }Supports 16-bit, 32-bit and 64-bit EXEs and DLLs.\ 20 | {\listtext \uc0\u8226 }Shows all the embedded version info, localized in the current language if localizations are available.\ 21 | {\listtext \uc0\u8226 }It refuses to read big executables (>32 MB) over a network share (yes, this is a feature).\ 22 | \pard\tx566\tx1133\tx1700\tx2267\tx2834\tx3401\tx3968\tx4535\tx5102\tx5669\tx6236\tx6803\sb100\sa60\pardirnatural\partightenfactor0 23 | 24 | \f0\b\fs28 \cf0 Supported OS X versions 25 | \f1\b0 \ 26 | \pard\tx566\tx1133\tx1700\tx2267\tx2834\tx3401\tx3968\tx4535\tx5102\tx5669\tx6236\tx6803\pardirnatural\partightenfactor0 27 | 28 | \fs24 \cf0 QLWindowsApps 1.3.3 works on macOS High Sierra and later,\ 29 | and was tested up to macOS Ventura.\ 30 | \ 31 | If you are using a macOS version older than High Sierra, you can download\ 32 | QLWindowsApps 1.3.2, which works on OS X Mavericks and later, or\ 33 | QLWindowsApps 1.0.2, which works on Mac OS X Leopard and later.} -------------------------------------------------------------------------------- /QLWindowsApps.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 9 | 10 | 12 | 13 | 15 | 16 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /QLWindowsApps.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /QLWindowsApps.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | QLWindowsApps 2 | ============= 3 | 4 | **QLWindowsApps** includes a QuickLook Plugin and a Spotlight importer 5 | for Microsoft Windows DLL and EXE files, intended as companions to Wine on 6 | macOS. It is based on a modified version of 7 | [icoutils](http://www.nongnu.org/icoutils/) by Oskar Liljeblad and Frank Richter. 8 | 9 | 10 | Features 11 | -------- 12 | 13 | - EXEs and DLLs can be Quick-Looked in the Finder and their properties 14 | (version info and bitness) will be visible to Spotlight. 15 | - EXEs will have an icon just like native apps. 16 | - Supports 16-bit, 32-bit and 64-bit EXEs and DLLs. 17 | - Shows all the embedded version info, localized in the current language if 18 | localizations are available. 19 | - It refuses to read big executables (>32 MB) over a network share (yes, this 20 | is a feature). 21 | 22 | ### Supported OS X versions 23 | 24 | QLWindowsApps 1.3.3 works on macOS High Sierra and later, 25 | and was tested up to macOS Ventura. 26 | 27 | If you are using a macOS version older than High Sierra, you can download 28 | QLWindowsApps 1.3.2, which works on OS X Mavericks and later, or 29 | QLWindowsApps 1.0.2, which works on Mac OS X Leopard and later. 30 | 31 | 32 | Known Issues 33 | ------------ 34 | 35 | ### 16-bit binary support 36 | 37 | The icoutils webpage states: "There is no relocation support for 38 | 16-bit (NE) binaries." Fortunately, relocatable 16-bit binaries seem to be 39 | quite uncommon. 40 | 41 | For some reason, even when the binary is non-relocatable, icoutils chokes a bit 42 | on 16 bit resources, even when it extracts them fine. 43 | 44 | 45 | Warning for releases before 1.3.0 46 | --------------------------------- 47 | 48 | In versions before 1.3.0, QLWindowsApps used to modify the custom icon of EXE 49 | files in order to hide the frame added to the icon by QuickLook. But from 50 | version 1.3.0, QLWindowsApps uses a private QuickLook API to hide the icon frame 51 | without the need to modify the file. 52 | 53 | It is possible to disable changing the icon of files in older versions of 54 | QLWindowsApps by executing the following command in Terminal.app: 55 | 56 | ```Shell 57 | defaults write com.danielecattaneo.qlgenerator.qlwindowsapps DisableIconChange 1 58 | ``` 59 | 60 | 61 | Copyright & License 62 | ------------------- 63 | 64 | The icoutils are copyright (c) 1998 Oskar Liljeblad. 65 | QLWindowsApps is copyright (c) 2012-2019 Daniele Cattaneo. 66 | 67 | This program is free software: you can redistribute it and/or modify it under 68 | the terms of the GNU General Public License as published by the Free Software 69 | Foundation, either version 3 of the License, or (at your option) any later 70 | version. 71 | 72 | This program is distributed in the hope that it will be useful, but WITHOUT ANY 73 | WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 74 | PARTICULAR PURPOSE. See the GNU General Public License for more details. 75 | 76 | You should have received a copy of the GNU General Public License along with 77 | this program. If not, see [http://www.gnu.org/licenses/](http://www.gnu.org/licenses/). 78 | 79 | 80 | -------------------------------------------------------------------------------- /WindowsAppsImporter/PackageResources/Scripts/postinstall: -------------------------------------------------------------------------------- 1 | #!/bin/bash -x 2 | whoami 3 | macosv=($(sw_vers -productVersion | sed 's/\./ /g')) 4 | echo macos version ${macosv[*]} 5 | if [[ ${macosv[1]} -gt 12 ]]; then 6 | com='/usr/bin/mdutil -r ' 7 | run_as_root=1 8 | else 9 | com='/usr/bin/mdimport -d3 -r ' 10 | run_as_root=0 11 | fi 12 | if [[ ( "$EUID" -eq 0 ) && ( "$run_as_root" -eq 0 ) ]]; then 13 | su $USER -c "${com}$2/Library/Spotlight/WindowsAppsImporter.mdimporter; echo returned \$?"; 14 | else 15 | ${com}$2/Library/Spotlight/WindowsAppsImporter.mdimporter 16 | echo returned $?; 17 | fi 18 | exit 0 19 | -------------------------------------------------------------------------------- /WindowsAppsImporter/WindowsAppsImporter.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /WindowsAppsImporter/WindowsAppsImporter.xcodeproj/xcshareddata/xcschemes/WindowsAppsImporter.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 32 | 33 | 43 | 44 | 50 | 51 | 52 | 53 | 59 | 60 | 66 | 67 | 68 | 69 | 71 | 72 | 75 | 76 | 77 | -------------------------------------------------------------------------------- /WindowsAppsImporter/WindowsAppsImporter/GetMetadataForFile.m: -------------------------------------------------------------------------------- 1 | // 2 | // GetMetadataForFile.m 3 | // WindowsAppsImporter 4 | // 5 | // Created by Daniele Cattaneo on 16/12/17. 6 | // Copyright © 2017 danielecattaneo. All rights reserved. 7 | // 8 | 9 | #include 10 | #import 11 | #import "EIExeFile.h" 12 | #import "EIVersionInfo.h" 13 | 14 | 15 | Boolean GetMetadataForFile(void *thisInterface, CFMutableDictionaryRef attributes, CFStringRef contentTypeUTI, CFStringRef pathToFile); 16 | 17 | 18 | BOOL EIMetadataForFile(NSURL *url, NSMutableDictionary *attr) 19 | { 20 | static NSSet *recognizedTags; 21 | static dispatch_once_t onceToken; 22 | dispatch_once(&onceToken, ^{ 23 | recognizedTags = [NSSet setWithArray:@[ 24 | @"com_danielecattaneo_windowsappsimporter_companyname", 25 | @"com_danielecattaneo_windowsappsimporter_filedescription", 26 | @"com_danielecattaneo_windowsappsimporter_fileversion", 27 | @"com_danielecattaneo_windowsappsimporter_internalname", 28 | @"com_danielecattaneo_windowsappsimporter_legaltrademarks", 29 | @"com_danielecattaneo_windowsappsimporter_originalfilename", 30 | @"com_danielecattaneo_windowsappsimporter_privatebuild", 31 | @"com_danielecattaneo_windowsappsimporter_productname"]]; 32 | }); 33 | 34 | EIExeFile *f = [[EIExeFile alloc] initWithExeFileURL:url error:nil]; 35 | if (!f) 36 | return NO; 37 | 38 | NSString *fmt = [NSString stringWithFormat:@"%d bit", [f bitness]]; 39 | [attr setObject:fmt forKey:@"com_danielecattaneo_windowsappsimporter_binaryformat"]; 40 | 41 | EIVersionInfo *vir = [f versionInfo]; 42 | if (vir) { 43 | NSString *queryHeader = @"\\StringFileInfo\\*"; 44 | NSArray *resSrch = [vir querySubNodesUnder:queryHeader error:NULL]; 45 | 46 | if (resSrch) { 47 | for (NSString *node in resSrch) { 48 | NSString *vpath = [NSString stringWithFormat:@"%@\\%@", queryHeader, node]; 49 | NSString *value = [vir queryStringValue:vpath error:NULL]; 50 | if (!value || [@"" isEqual:value]) 51 | continue; 52 | 53 | NSString *destkey; 54 | if ([node isEqual:@"Comments"]) 55 | destkey = (NSString *)kMDItemComment; 56 | else if ([node isEqual:@"LegalCopyright"]) 57 | destkey = (NSString *)kMDItemCopyright; 58 | else { 59 | NSString *test = [@"com_danielecattaneo_windowsappsimporter_" stringByAppendingString:[node lowercaseString]]; 60 | if ([recognizedTags containsObject:test]) 61 | destkey = test; 62 | } 63 | 64 | if (destkey) 65 | [attr setObject:value forKey:destkey]; 66 | } 67 | } 68 | } 69 | 70 | return YES; 71 | } 72 | 73 | 74 | //============================================================================== 75 | // 76 | // Get metadata attributes from document files 77 | // 78 | // The purpose of this function is to extract useful information from the 79 | // file formats for your document, and set the values into the attribute 80 | // dictionary for Spotlight to include. 81 | // 82 | //============================================================================== 83 | 84 | Boolean GetMetadataForFile(void *thisInterface, CFMutableDictionaryRef attributes, CFStringRef contentTypeUTI, CFStringRef pathToFile) 85 | { 86 | Boolean res; 87 | 88 | @autoreleasepool { 89 | NSMutableDictionary *attr = (__bridge NSMutableDictionary *)(attributes); 90 | NSURL *url = [[NSURL alloc] initFileURLWithPath:(__bridge NSString * _Nonnull)(pathToFile)]; 91 | res = EIMetadataForFile(url, attr); 92 | } 93 | return res; 94 | } 95 | -------------------------------------------------------------------------------- /WindowsAppsImporter/WindowsAppsImporter/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | $(DEVELOPMENT_LANGUAGE) 7 | CFBundleDocumentTypes 8 | 9 | 10 | CFBundleTypeRole 11 | MDImporter 12 | LSItemContentTypes 13 | 14 | com.microsoft.windows-executable 15 | com.microsoft.windows-dynamic-link-library 16 | 17 | 18 | 19 | CFBundleExecutable 20 | $(EXECUTABLE_NAME) 21 | CFBundleIdentifier 22 | $(PRODUCT_BUNDLE_IDENTIFIER) 23 | CFBundleInfoDictionaryVersion 24 | 6.0 25 | CFBundleName 26 | $(PRODUCT_NAME) 27 | CFBundleShortVersionString 28 | $(MARKETING_VERSION) 29 | CFBundleVersion 30 | 1 31 | CFPlugInDynamicRegisterFunction 32 | 33 | CFPlugInDynamicRegistration 34 | NO 35 | CFPlugInFactories 36 | 37 | 46E20E4E-60FC-45B0-9D58-860F882A7CBF 38 | MetadataImporterPluginFactory 39 | 40 | CFPlugInTypes 41 | 42 | 8B08C4BF-415B-11D8-B3F9-0003936726FC 43 | 44 | 46E20E4E-60FC-45B0-9D58-860F882A7CBF 45 | 46 | 47 | CFPlugInUnloadFunction 48 | 49 | LSMinimumSystemVersion 50 | $(MACOSX_DEPLOYMENT_TARGET) 51 | NSHumanReadableCopyright 52 | Copyright © 2017 Daniele Cattaneo. All rights reserved. 53 | 54 | 55 | -------------------------------------------------------------------------------- /WindowsAppsImporter/WindowsAppsImporter/en.lproj/schema.strings: -------------------------------------------------------------------------------- 1 | /* 2 | schema.strings 3 | WindowsAppsImporter 4 | 5 | Created by Daniele Cattaneo on 18/12/17. 6 | Copyright © 2017 danielecattaneo. All rights reserved. 7 | */ 8 | 9 | "com_danielecattaneo_windowsappsimporter_binaryformat" = "Binary Format"; 10 | "com_danielecattaneo_windowsappsimporter_companyname" = "Company Name"; 11 | "com_danielecattaneo_windowsappsimporter_filedescription" = "File Description"; 12 | "com_danielecattaneo_windowsappsimporter_fileversion" = "File Version"; 13 | "com_danielecattaneo_windowsappsimporter_internalname" = "Internal Name"; 14 | "com_danielecattaneo_windowsappsimporter_legaltrademarks" = "Legal Trademarks"; 15 | "com_danielecattaneo_windowsappsimporter_originalfilename" = "Original Filename"; 16 | "com_danielecattaneo_windowsappsimporter_privatebuild" = "Private Build"; 17 | "com_danielecattaneo_windowsappsimporter_productname" = "Product Name"; 18 | "com_danielecattaneo_windowsappsimporter_specialbuild" = "Special Build"; 19 | -------------------------------------------------------------------------------- /WindowsAppsImporter/WindowsAppsImporter/main.c: -------------------------------------------------------------------------------- 1 | // 2 | // main.c 3 | // WindowsAppsImporter 4 | // 5 | // Created by Daniele Cattaneo on 16/12/17. 6 | // Copyright © 2017 danielecattaneo. All rights reserved. 7 | // 8 | 9 | 10 | 11 | 12 | 13 | //============================================================================== 14 | // 15 | // DO NO MODIFY THE CONTENT OF THIS FILE 16 | // 17 | // This file contains the generic CFPlug-in code necessary for your importer 18 | // To complete your importer implement the function in GetMetadataForFile.c 19 | // 20 | //============================================================================== 21 | 22 | 23 | 24 | 25 | 26 | #import 27 | #import 28 | #import 29 | 30 | // ----------------------------------------------------------------------------- 31 | // constants 32 | // ----------------------------------------------------------------------------- 33 | 34 | 35 | #define PLUGIN_ID "A458F311-3DAA-422C-8FD6-6A63DD47D0EA" 36 | 37 | // 38 | // Below is the generic glue code for all plug-ins. 39 | // 40 | // You should not have to modify this code aside from changing 41 | // names if you decide to change the names defined in the Info.plist 42 | // 43 | 44 | 45 | // ----------------------------------------------------------------------------- 46 | // typedefs 47 | // ----------------------------------------------------------------------------- 48 | 49 | // The import function to be implemented in GetMetadataForFile.c 50 | Boolean GetMetadataForFile(void *thisInterface, 51 | CFMutableDictionaryRef attributes, 52 | CFStringRef contentTypeUTI, 53 | CFStringRef pathToFile); 54 | 55 | // The layout for an instance of MetaDataImporterPlugIn 56 | typedef struct __MetadataImporterPluginType 57 | { 58 | MDImporterInterfaceStruct *conduitInterface; 59 | CFUUIDRef factoryID; 60 | UInt32 refCount; 61 | } MetadataImporterPluginType; 62 | 63 | // ----------------------------------------------------------------------------- 64 | // prototypes 65 | // ----------------------------------------------------------------------------- 66 | // Forward declaration for the IUnknown implementation. 67 | // 68 | 69 | MetadataImporterPluginType *AllocMetadataImporterPluginType(CFUUIDRef inFactoryID); 70 | void DeallocMetadataImporterPluginType(MetadataImporterPluginType *thisInstance); 71 | HRESULT MetadataImporterQueryInterface(void *thisInstance,REFIID iid,LPVOID *ppv); 72 | void *MetadataImporterPluginFactory(CFAllocatorRef allocator,CFUUIDRef typeID); 73 | ULONG MetadataImporterPluginAddRef(void *thisInstance); 74 | ULONG MetadataImporterPluginRelease(void *thisInstance); 75 | // ----------------------------------------------------------------------------- 76 | // testInterfaceFtbl definition 77 | // ----------------------------------------------------------------------------- 78 | // The TestInterface function table. 79 | // 80 | 81 | static MDImporterInterfaceStruct testInterfaceFtbl = { 82 | NULL, 83 | MetadataImporterQueryInterface, 84 | MetadataImporterPluginAddRef, 85 | MetadataImporterPluginRelease, 86 | GetMetadataForFile 87 | }; 88 | 89 | 90 | // ----------------------------------------------------------------------------- 91 | // AllocMetadataImporterPluginType 92 | // ----------------------------------------------------------------------------- 93 | // Utility function that allocates a new instance. 94 | // You can do some initial setup for the importer here if you wish 95 | // like allocating globals etc... 96 | // 97 | MetadataImporterPluginType *AllocMetadataImporterPluginType(CFUUIDRef inFactoryID) 98 | { 99 | MetadataImporterPluginType *theNewInstance; 100 | 101 | theNewInstance = (MetadataImporterPluginType *)malloc(sizeof(MetadataImporterPluginType)); 102 | memset(theNewInstance,0,sizeof(MetadataImporterPluginType)); 103 | 104 | /* Point to the function table */ 105 | theNewInstance->conduitInterface = &testInterfaceFtbl; 106 | 107 | /* Retain and keep an open instance refcount for each factory. */ 108 | theNewInstance->factoryID = CFRetain(inFactoryID); 109 | CFPlugInAddInstanceForFactory(inFactoryID); 110 | 111 | /* This function returns the IUnknown interface so set the refCount to one. */ 112 | theNewInstance->refCount = 1; 113 | return theNewInstance; 114 | } 115 | 116 | // ----------------------------------------------------------------------------- 117 | // DeallocWindowsAppsImporterMDImporterPluginType 118 | // ----------------------------------------------------------------------------- 119 | // Utility function that deallocates the instance when 120 | // the refCount goes to zero. 121 | // In the current implementation importer interfaces are never deallocated 122 | // but implement this as this might change in the future 123 | // 124 | void DeallocMetadataImporterPluginType(MetadataImporterPluginType *thisInstance) 125 | { 126 | CFUUIDRef theFactoryID; 127 | 128 | theFactoryID = thisInstance->factoryID; 129 | free(thisInstance); 130 | if (theFactoryID){ 131 | CFPlugInRemoveInstanceForFactory(theFactoryID); 132 | CFRelease(theFactoryID); 133 | } 134 | } 135 | 136 | // ----------------------------------------------------------------------------- 137 | // MetadataImporterQueryInterface 138 | // ----------------------------------------------------------------------------- 139 | // Implementation of the IUnknown QueryInterface function. 140 | // 141 | HRESULT MetadataImporterQueryInterface(void *thisInstance,REFIID iid,LPVOID *ppv) 142 | { 143 | CFUUIDRef interfaceID; 144 | 145 | interfaceID = CFUUIDCreateFromUUIDBytes(kCFAllocatorDefault,iid); 146 | 147 | if (CFEqual(interfaceID,kMDImporterInterfaceID)){ 148 | /* If the Right interface was requested, bump the ref count, 149 | * set the ppv parameter equal to the instance, and 150 | * return good status. 151 | */ 152 | ((MetadataImporterPluginType*)thisInstance)->conduitInterface->AddRef(thisInstance); 153 | *ppv = thisInstance; 154 | CFRelease(interfaceID); 155 | return S_OK; 156 | }else{ 157 | if (CFEqual(interfaceID,IUnknownUUID)){ 158 | /* If the IUnknown interface was requested, same as above. */ 159 | ((MetadataImporterPluginType*)thisInstance )->conduitInterface->AddRef(thisInstance); 160 | *ppv = thisInstance; 161 | CFRelease(interfaceID); 162 | return S_OK; 163 | }else{ 164 | /* Requested interface unknown, bail with error. */ 165 | *ppv = NULL; 166 | CFRelease(interfaceID); 167 | return E_NOINTERFACE; 168 | } 169 | } 170 | } 171 | 172 | // ----------------------------------------------------------------------------- 173 | // MetadataImporterPluginAddRef 174 | // ----------------------------------------------------------------------------- 175 | // Implementation of reference counting for this type. Whenever an interface 176 | // is requested, bump the refCount for the instance. NOTE: returning the 177 | // refcount is a convention but is not required so don't rely on it. 178 | // 179 | ULONG MetadataImporterPluginAddRef(void *thisInstance) 180 | { 181 | ((MetadataImporterPluginType *)thisInstance )->refCount += 1; 182 | return ((MetadataImporterPluginType*) thisInstance)->refCount; 183 | } 184 | 185 | // ----------------------------------------------------------------------------- 186 | // SampleCMPluginRelease 187 | // ----------------------------------------------------------------------------- 188 | // When an interface is released, decrement the refCount. 189 | // If the refCount goes to zero, deallocate the instance. 190 | // 191 | ULONG MetadataImporterPluginRelease(void *thisInstance) 192 | { 193 | ((MetadataImporterPluginType*)thisInstance)->refCount -= 1; 194 | if (((MetadataImporterPluginType*)thisInstance)->refCount == 0){ 195 | DeallocMetadataImporterPluginType((MetadataImporterPluginType*)thisInstance ); 196 | return 0; 197 | }else{ 198 | return ((MetadataImporterPluginType*) thisInstance )->refCount; 199 | } 200 | } 201 | 202 | // ----------------------------------------------------------------------------- 203 | // WindowsAppsImporterMDImporterPluginFactory 204 | // ----------------------------------------------------------------------------- 205 | // Implementation of the factory function for this type. 206 | // 207 | void *MetadataImporterPluginFactory(CFAllocatorRef allocator,CFUUIDRef typeID) 208 | { 209 | MetadataImporterPluginType *result; 210 | CFUUIDRef uuid; 211 | 212 | /* If correct type is being requested, allocate an 213 | * instance of TestType and return the IUnknown interface. 214 | */ 215 | if (CFEqual(typeID,kMDImporterTypeID)){ 216 | uuid = CFUUIDCreateFromString(kCFAllocatorDefault,CFSTR(PLUGIN_ID)); 217 | result = AllocMetadataImporterPluginType(uuid); 218 | CFRelease(uuid); 219 | return result; 220 | } 221 | /* If the requested type is incorrect, return NULL. */ 222 | return NULL; 223 | } 224 | 225 | -------------------------------------------------------------------------------- /WindowsAppsImporter/WindowsAppsImporter/schema.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | kMDItemCopyright 25 | kMDItemComment 26 | com_danielecattaneo_windowsappsimporter_binaryformat 27 | com_danielecattaneo_windowsappsimporter_companyname 28 | com_danielecattaneo_windowsappsimporter_filedescription 29 | com_danielecattaneo_windowsappsimporter_fileversion 30 | com_danielecattaneo_windowsappsimporter_internalname 31 | com_danielecattaneo_windowsappsimporter_legaltrademarks 32 | com_danielecattaneo_windowsappsimporter_originalfilename 33 | com_danielecattaneo_windowsappsimporter_privatebuild 34 | com_danielecattaneo_windowsappsimporter_productname 35 | com_danielecattaneo_windowsappsimporter_specialbuild 36 | 37 | 38 | kMDItemCopyright 39 | kMDItemComment 40 | com_danielecattaneo_windowsappsimporter_binaryformat 41 | com_danielecattaneo_windowsappsimporter_companyname 42 | com_danielecattaneo_windowsappsimporter_filedescription 43 | com_danielecattaneo_windowsappsimporter_fileversion 44 | com_danielecattaneo_windowsappsimporter_internalname 45 | com_danielecattaneo_windowsappsimporter_legaltrademarks 46 | com_danielecattaneo_windowsappsimporter_originalfilename 47 | com_danielecattaneo_windowsappsimporter_privatebuild 48 | com_danielecattaneo_windowsappsimporter_productname 49 | 50 | 51 | 52 | 53 | 54 | kMDItemCopyright 55 | kMDItemComment 56 | com_danielecattaneo_windowsappsimporter_binaryformat 57 | com_danielecattaneo_windowsappsimporter_companyname 58 | com_danielecattaneo_windowsappsimporter_filedescription 59 | com_danielecattaneo_windowsappsimporter_fileversion 60 | com_danielecattaneo_windowsappsimporter_internalname 61 | com_danielecattaneo_windowsappsimporter_legaltrademarks 62 | com_danielecattaneo_windowsappsimporter_originalfilename 63 | com_danielecattaneo_windowsappsimporter_privatebuild 64 | com_danielecattaneo_windowsappsimporter_productname 65 | 66 | 67 | kMDItemCopyright 68 | kMDItemComment 69 | com_danielecattaneo_windowsappsimporter_binaryformat 70 | com_danielecattaneo_windowsappsimporter_companyname 71 | com_danielecattaneo_windowsappsimporter_filedescription 72 | com_danielecattaneo_windowsappsimporter_fileversion 73 | com_danielecattaneo_windowsappsimporter_internalname 74 | com_danielecattaneo_windowsappsimporter_legaltrademarks 75 | com_danielecattaneo_windowsappsimporter_originalfilename 76 | com_danielecattaneo_windowsappsimporter_privatebuild 77 | com_danielecattaneo_windowsappsimporter_productname 78 | 79 | 80 | 81 | 82 | -------------------------------------------------------------------------------- /makepackage.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # Script to make an installable package of the plugin. 4 | # 5 | # Uses xcodebuild, pkgbuild and productbuild. 6 | # 7 | 8 | 9 | recreate_dir() { 10 | if test -d "$1"; then 11 | sudo chmod -R u+w "$1" 12 | sudo rm -rf "$1" 13 | fi 14 | mkdir -p "$1"/Root 15 | } 16 | 17 | # Create a clean install directory... 18 | recreate_dir build/Package-qlwindowsapps 19 | recreate_dir build/Package-WindowsAppsImporter 20 | 21 | # Install into this directory... 22 | xcodebuild -workspace "$PWD/QLWindowsApps.xcworkspace" \ 23 | -scheme QLWindowsApps \ 24 | -configuration Release \ 25 | install \ 26 | DSTROOT="$PWD/build/Package-qlwindowsapps/Root" 27 | xcodebuild -workspace "$PWD/QLWindowsApps.xcworkspace" \ 28 | -scheme WindowsAppsImporter \ 29 | -configuration Release \ 30 | install \ 31 | DSTROOT="$PWD/build/Package-WindowsAppsImporter/Root" 32 | 33 | # Extract the version number from the project... 34 | ver=$(git describe | sed 's/release_//') 35 | if [[ ! ( $? -eq 0 ) ]]; then 36 | ver=$(/usr/libexec/PlistBuddy -c "Print:CFBundleShortVersionString" "MicrosoftBinaries/Info.plist") 37 | fi 38 | 39 | # Make the package with pkgbuild and the product distribution with productbuild... 40 | echo pkgbuild... 41 | pkgbuild --identifier com.danielecattaneo.qlgenerator.qlwindowsapps \ 42 | --version "$ver" \ 43 | --root build/Package-qlwindowsapps/Root \ 44 | --scripts ./MicrosoftBinaries/PackageResources/Scripts \ 45 | "./QLWindowsApps.pkg" 46 | pkgbuild --identifier com.danielecattaneo.WindowsAppsImporter \ 47 | --version "$ver" \ 48 | --root build/Package-WindowsAppsImporter/Root \ 49 | --scripts ./WindowsAppsImporter/PackageResources/Scripts \ 50 | "./WindowsAppsImporter.pkg" 51 | productbuild --distribution ./PackageResources/Distribution.xml \ 52 | --resources ./PackageResources/Resources \ 53 | --package-path ./ \ 54 | "./QLWindowsApps-$ver.pkg" 55 | rm ./QLWindowsApps.pkg 56 | rm ./WindowsAppsImporter.pkg 57 | --------------------------------------------------------------------------------