Skip to content

Instantly share code, notes, and snippets.

@Moligaloo
Created October 10, 2012 09:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Moligaloo/3864372 to your computer and use it in GitHub Desktop.
Save Moligaloo/3864372 to your computer and use it in GitHub Desktop.
Make a hook demo
#import <UIKit/UIKit.h>
#import "substrate.h"
static IMP original_UIApplication_openURL;
static BOOL replace_UIApplication_openURL(UIApplication *self, SEL cmd, NSURL *url)
{
UIAlertView *view = [[UIAlertView alloc]
initWithTitle:@""
message:@"hello"
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[view show];
[view release];
original_UIApplication_openURL(self, cmd, url);
}
__attribute__((constructor))
static void initialize()
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
MSHookMessageEx([UIApplication class],
@selector(openURL:),
(IMP)replace_UIApplication_openURL,
(IMP *)&original_UIApplication_openURL);
[pool release];
}
Filter = {
Bundles = (com.apple.MobileSMS);
};
DEVPATH=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer
CC = $(DEVPATH)/usr/bin/llvm-gcc-4.2
LD = $(CC)
## SDK版本
SDKVER = 6.0
MIN_REQUIRED_VERSION=40000
## iPhone SDK路径
IPHONESDK = $(DEVPATH)/SDKs/iPhoneOS$(SDKVER).sdk
## include 路径
INCPATH += -isysroot $(IPHONESDK)
## 编译开关
CFLAGS += $(INCPATH) \
-arch armv7 \
-pipe \
-Wno-trigraphs \
-fpascal-strings \
-Wreturn-type \
-Wunused-variable \
-D__IPHONE_OS_VERSION_MIN_REQUIRED=$(MIN_REQUIRED_VERSION) \
-O2 \
-fobjc-abi-version=2 \
-fobjc-legacy-dispatch
CFLAGS += -F"$(IPHONESDK)/System/Library/Frameworks"
CFLAGS += -F"$(IPHONESDK)/System/Library/PrivateFrameworks"
CFLAGS += -g
## 标准库或者框架的设置
LDFLAGS= -arch armv7 \
-liconv \
-lobjc \
-lsqlite3 \
-lz.1 \
-isysroot $(IPHONESDK) \
-framework Foundation \
-framework UIKit \
-framework CoreFoundation \
-framework CoreData \
-framework CoreGraphics\
-framework AppSupport \
-framework AudioToolbox \
-framework CoreAudio \
-framework WebCore \
-framework Preferences \
-framework GraphicsServices \
-framework IOKit \
-framework CFNetwork \
-framework AVFoundation \
-framework CoreVideo \
-framework CoreMedia \
-framework QuartzCore \
-framework AddressBook \
-framework iTunesStore \
-framework AssetsLibrary \
-multiply_defined suppress \
-undefined dynamic_lookup \
-dynamiclib \
-dead_strip \
-no_dead_strip_inits_and_terms \
-Wall \
-Werror \
-lsubstrate \
-mthumb \
-mthumb-interwork \
# -marm \
# -mno-thumb \
-fobjc-exceptions \
-DUSE_SYSTEM_MALLOC=1 \
-fno-exceptions \
-fno-rtti \
-fno-common -ffast-math -fno-threadsafe-statics \
-O2 \
#-s \
-lstdc++.6 \
-install_name /Library/MobileSubstrate/DynamicLibraries/HookDemo.dylib
LDFLAGS+=-L"$(IPHONESDK)/usr/lib"
LDFLAGS+=-F"$(IPHONESDK)/System/Library/Frameworks"
LDFLAGS+=-F"$(IPHONESDK)/System/Library/PrivateFrameworks"
LDFLAGS+=-L.
OBJS = hookdemo.o
TARGET=HookDemo.dylib
all: $(TARGET)
$(TARGET): $(OBJS)
$(LD) $(LDFLAGS) -o $@ $^
%.o: %.m
$(CC) -c $(CFLAGS) $< -o $@
%.o: %.mm
$(CC) -c $(CFLAGS) $< -o $@
%.o: %.c
$(CC) -c $(CFLAGS) $< -o $@
clean:
@rm -f $(OBJS) $(TARGET)
rebuild:
@make clean
@make
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment