Skip to content

Instantly share code, notes, and snippets.

View mattstevens's full-sized avatar

Matt Stevens mattstevens

View GitHub Profile
@mattstevens
mattstevens / AppStoreReceipt.h
Created October 19, 2011 02:04
An insecure but simple method of validating Mac App Store receipts using only Security.framework.
#import <Cocoa/Cocoa.h>
BOOL VerifyAppStoreReceipt();
BOOL VerifyAppStoreReceiptData(NSData *data);
NSURL *BackupReceiptURL();
void BackupAppStoreReceipt();
NSData *MACAddressData();
NSDictionary *DictionaryFromAppStoreReceipt(NSData *fullData);
@mattstevens
mattstevens / gist:4400775
Last active March 9, 2022 12:53
Resizing an NSImage on retina Macs for output as a 1x image
NSImage *computerImage = [NSImage imageNamed:NSImageNameComputer];
NSInteger size = 256;
NSBitmapImageRep *rep = [[NSBitmapImageRep alloc]
initWithBitmapDataPlanes:NULL
pixelsWide:size
pixelsHigh:size
bitsPerSample:8
samplesPerPixel:4
hasAlpha:YES
@mattstevens
mattstevens / gist:5608445
Created May 19, 2013 18:04
Setting subject and email address for NSSharingServiceNameComposeEmail via private API
NSSharingService *service = [NSSharingService sharingServiceNamed:NSSharingServiceNameComposeEmail];
NSDictionary *parameters = @{
@"NSSharingServiceParametersDefaultSubjectKey": @"Lo, a subject!",
@"NSSharingServiceParametersDefaultRecipientsKey": @[@"someone@somewhere.com"]
};
[service setValue:parameters forKey:@"parameters"];
[service performWithItems:@[@"Woo, private API."]];
@mattstevens
mattstevens / gist:989296
Created May 24, 2011 18:15
Monitoring for IP address changes
#import "NetworkMonitor.h"
NSString *NetworkConfigurationDidChangeNotification = @"NetworkConfigurationDidChangeNotification";
void storeCallback(SCDynamicStoreRef store, CFArrayRef changedKeys, void *info) {
[(NetworkMonitor *)info update];
}
@implementation NetworkMonitor
@mattstevens
mattstevens / filter.cpp
Last active December 22, 2015 00:48
Quick and dirty ZNC filter to stop people from crashing clients (no longer needed as of 10.8.5)
#include <znc/Modules.h>
using namespace std;
static const char evil[] = { (char)0xd8, (char)0xb3, 0 };
class CFilterMod : public CModule {
public:
MODCONSTRUCTOR(CFilterMod) {
}
@mattstevens
mattstevens / embedded_resource.m
Last active December 20, 2015 20:08
Access embedded resource in command line tool
#import <Foundation/Foundation.h>
#import <mach-o/dyld.h>
#import <mach-o/getsect.h>
#import <mach-o/ldsyms.h>
// Embed via other linker flags: -sectcreate __TEXT test $(PROJECT_DIR)/test.txt
// Names are limited to 16 characters.
NSData *MSEmbeddedResourceDataWithName(NSString *name) {
unsigned long size = 0;
uint8_t *data = getsectiondata(&_mh_execute_header, "__TEXT", [name UTF8String], &size);
@mattstevens
mattstevens / GoogleTests.h
Created June 2, 2013 04:36
Google Test integration for an Xcode unit test target
#import <SenTestingKit/SenTestingKit.h>
@interface GoogleTests : SenTestCase
@end
@mattstevens
mattstevens / gist:5623680
Last active December 17, 2015 14:19
Check for existence of a custom icon
- (BOOL)fileHasCustomIcon:(NSString *)path {
struct FinderInfoAttrBuf {
u_int32_t length;
FileInfo fileInfo;
ExtendedFileInfo extendedFileInfo;
} __attribute__((aligned(4), packed));
struct attrlist attrList = {};
struct FinderInfoAttrBuf attrBuf = {};
attrList.bitmapcount = ATTR_BIT_MAP_COUNT;
@mattstevens
mattstevens / gist:4948153
Last active December 13, 2015 17:28
Clear recent documents list
LSSharedFileListRef recentDocsList = LSSharedFileListCreate(NULL, kLSSharedFileListRecentDocumentItems, NULL);
LSSharedFileListRemoveAllItems(recentDocsList);
CFRelease(recentDocsList);
@mattstevens
mattstevens / gist:eb758f55cb2898b670a5
Created November 8, 2015 17:25
Filter breakpoint on frame module
(lldb) b NSLog
Breakpoint 2: 2 locations.
(lldb) breakpoint command add -s python -o "return (frame.GetThread().GetFrameAtIndex(1).GetModule().GetFileSpec().GetFilename() == 'UIKit')"