Skip to content

Commit

Permalink
feature: 图片解码
Browse files Browse the repository at this point in the history
  • Loading branch information
FantasticLBP committed Jul 20, 2024
1 parent 1b97d22 commit 9497ee9
Show file tree
Hide file tree
Showing 36 changed files with 1,078 additions and 337 deletions.
59 changes: 57 additions & 2 deletions AppHook/HookProtector.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include <sys/cdefs.h>
#import <dlfcn.h>
#import <sys/sysctl.h>
#import <sys/syscall.h>

enum {
ePtAttachDeprecated __deprecated_enum_msg("PT_ATTACH is deprecated. See PT_ATTACHEXC") = 10
Expand Down Expand Up @@ -48,6 +49,7 @@ __END_DECLS

typedef int (*ptrace_ptr_t)(int _request, pid_t _pid, caddr_t _addr, int _data);
typedef int (*sysctl_ptr_t)(int *name, u_int namelen, void *info, size_t *infosize, void *newInfo, size_t newInfoSize);
typedef int (*syscall_ptr_t)(int, ...);

static __attribute__((always_inline)) void quit_process () {
#ifdef __arm64__
Expand Down Expand Up @@ -178,8 +180,8 @@ void disable_gdb_via_hidden_sysctl(void) {
});
dispatch_resume(timer);
}

static __attribute__((always_inline)) void anti_debug() {
static __attribute__((always_inline)) void anti_debug(void) {
#ifdef __arm64__
__asm__("mov X0, #31\n"
"mov X1, #0\n"
Expand All @@ -192,4 +194,57 @@ static __attribute__((always_inline)) void anti_debug() {
#endif
}

void disable_gdb_via_syscall (void) {
syscall(SYS_ptrace, PT_DENY_ATTACH, 0, 0);
}

bool isInDebugModeViaHiddenSyscall(void) {
unsigned char funcCallerName[] = {
(KEY ^ 's'),
(KEY ^ 'y'),
(KEY ^ 's'),
(KEY ^ 'c'),
(KEY ^ 'a'),
(KEY ^ 'l'),
(KEY ^ 'l'),
(KEY ^ '\0'),
};
unsigned char * callerP = funcCallerName;
//再次异或之后恢复原本的值
while (((*callerP) ^= KEY) != '\0') callerP++;

int name[4];
name[0] = CTL_KERN; // 内核
name[1] = KERN_PROC; // 查询进程
name[2] = KERN_PROC_PID; // 通过进程 ID 来查找
name[3] = getpid(); // 当前进程 ID

struct kinfo_proc info; // 接收查询信息,利用结构体传递引用
size_t infoSize = sizeof(info);
void *handle = dlopen(0, RTLD_GLOBAL | RTLD_NOW);
syscall_ptr_t caller_ptr = dlsym(handle, (const char *)funcCallerName);

if (caller_ptr(SYS_sysctl, name, sizeof(name)/sizeof(*name), &info, &infoSize, 0, 0)) {
dlclose(handle);
return NO;
}
dlclose(handle);
return info.kp_proc.p_flag & P_TRACED;
}

void disable_gdb_via_hidden_syscall (void) {
static dispatch_source_t timer;
timer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0, dispatch_get_global_queue(0, 0));
dispatch_source_set_timer(timer, DISPATCH_TIME_NOW, 1 * NSEC_PER_SEC, 0 * NSEC_PER_SEC);
dispatch_source_set_event_handler(timer, ^{
if (isInDebugModeViaHiddenSyscall()) {
NSLog(@"在调试模式");
quit_process();
} else {
NSLog(@"不在调试模式");
}
});
dispatch_resume(timer);
}

#endif /* HookProtector_h */
2 changes: 2 additions & 0 deletions AppHookProtector/main.m
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ int main(int argc, char * argv[]) {
// disable_gdb_via_hidden_ptrace();
// disable_gdb_via_hidden_sysctl();
anti_debug();
// disable_gdb_via_syscall();
disable_gdb_via_hidden_syscall();
#endif
// Setup code that might create autoreleased objects goes here.
appDelegateClassName = NSStringFromClass([AppDelegate class]);
Expand Down
63 changes: 63 additions & 0 deletions GCDExplore/ViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,71 @@ - (void)viewDidLoad {
// [self testBloakAndQueue];
// dead lock
// dispatch_sync(dispatch_get_main_queue(), nil);
[self testDispatchGroup];
}

- (void)testDispatchGroup {
// D - A,B
dispatch_queue_t group1 = dispatch_group_create();
// E - B,C
dispatch_queue_t group2 = dispatch_group_create();
// F - D,E
dispatch_queue_t group3 = dispatch_group_create();

dispatch_group_enter(group1);
dispatch_async(dispatch_get_global_queue(0, 0), ^{
for (int i = 0; i < 3; i++) {
NSLog(@"A Task");
}
dispatch_group_leave(group1);
});

dispatch_group_enter(group1);
dispatch_group_enter(group2);
dispatch_async(dispatch_get_global_queue(0, 0), ^{
for (int i = 0; i < 3; i++) {
NSLog(@"B Task");
}
dispatch_group_leave(group1);
dispatch_group_enter(group2);
});

dispatch_group_enter(group2);
dispatch_async(dispatch_get_global_queue(0, 0), ^{
for (int i = 0; i < 3; i++) {
NSLog(@"C Task");
}
dispatch_group_leave(group2);
});

dispatch_group_enter(group3);
dispatch_group_notify(group1, dispatch_get_global_queue(0, 0), ^{
dispatch_async(dispatch_get_global_queue(0, 0), ^{
for (int i = 0; i < 3; i++) {
NSLog(@"D Task");
}
dispatch_group_leave(group3);
});
});

dispatch_group_enter(group3);
dispatch_group_notify(group2, dispatch_get_global_queue(0, 0), ^{
dispatch_async(dispatch_get_global_queue(0, 0), ^{
for (int i = 0; i < 3; i++) {
NSLog(@"E Task");
}
dispatch_group_leave(group3);
});
});

dispatch_group_notify(group3, dispatch_get_global_queue(0, 0), ^{
dispatch_async(dispatch_get_global_queue(0, 0), ^{
for (int i = 0; i < 3; i++) {
NSLog(@"F Task");
}
});
});
}

- (void)testDeadLock {
dispatch_queue_t queue = dispatch_queue_create("test", DISPATCH_QUEUE_SERIAL);
Expand Down
15 changes: 15 additions & 0 deletions ImageDecode/AppDelegate.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//
// AppDelegate.h
// ImageDecode
//
// Created by Unix_Kernel on 7/17/24.
// Copyright © 2024 杭城小刘. All rights reserved.
//

#import <UIKit/UIKit.h>

@interface AppDelegate : UIResponder <UIApplicationDelegate>


@end

41 changes: 41 additions & 0 deletions ImageDecode/AppDelegate.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
//
// AppDelegate.m
// ImageDecode
//
// Created by Unix_Kernel on 7/17/24.
// Copyright © 2024 杭城小刘. All rights reserved.
//

#import "AppDelegate.h"

@interface AppDelegate ()

@end

@implementation AppDelegate


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
return YES;
}


#pragma mark - UISceneSession lifecycle


- (UISceneConfiguration *)application:(UIApplication *)application configurationForConnectingSceneSession:(UISceneSession *)connectingSceneSession options:(UISceneConnectionOptions *)options {
// Called when a new scene session is being created.
// Use this method to select a configuration to create the new scene with.
return [[UISceneConfiguration alloc] initWithName:@"Default Configuration" sessionRole:connectingSceneSession.role];
}


- (void)application:(UIApplication *)application didDiscardSceneSessions:(NSSet<UISceneSession *> *)sceneSessions {
// Called when the user discards a scene session.
// If any sessions were discarded while the application was not running, this will be called shortly after application:didFinishLaunchingWithOptions.
// Use this method to release any resources that were specific to the discarded scenes, as they will not return.
}


@end
11 changes: 11 additions & 0 deletions ImageDecode/Assets.xcassets/AccentColor.colorset/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"colors" : [
{
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
13 changes: 13 additions & 0 deletions ImageDecode/Assets.xcassets/AppIcon.appiconset/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"images" : [
{
"idiom" : "universal",
"platform" : "ios",
"size" : "1024x1024"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
6 changes: 6 additions & 0 deletions ImageDecode/Assets.xcassets/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"info" : {
"author" : "xcode",
"version" : 1
}
}
21 changes: 21 additions & 0 deletions ImageDecode/Assets.xcassets/peacock.imageset/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"images" : [
{
"filename" : "peacock-1169961.jpg",
"idiom" : "universal",
"scale" : "1x"
},
{
"idiom" : "universal",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
25 changes: 25 additions & 0 deletions ImageDecode/Base.lproj/LaunchScreen.storyboard
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="13122.16" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" launchScreen="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="01J-lp-oVM">
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="13104.12"/>
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>
<!--View Controller-->
<scene sceneID="EHf-IW-A2E">
<objects>
<viewController id="01J-lp-oVM" sceneMemberID="viewController">
<view key="view" contentMode="scaleToFill" id="Ze5-6b-2t3">
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="backgroundColor" xcode11CocoaTouchSystemColor="systemBackgroundColor" cocoaTouchSystemColor="whiteColor"/>
<viewLayoutGuide key="safeArea" id="6Tk-OE-BBY"/>
</view>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="iYj-Kq-Ea1" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="53" y="375"/>
</scene>
</scenes>
</document>
24 changes: 24 additions & 0 deletions ImageDecode/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="13122.16" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="BYZ-38-t0r">
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="13104.12"/>
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>
<!--View Controller-->
<scene sceneID="tne-QT-ifu">
<objects>
<viewController id="BYZ-38-t0r" customClass="ViewController" customModuleProvider="" sceneMemberID="viewController">
<view key="view" contentMode="scaleToFill" id="8bC-Xf-vdC">
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="backgroundColor" xcode11CocoaTouchSystemColor="systemBackgroundColor" cocoaTouchSystemColor="whiteColor"/>
<viewLayoutGuide key="safeArea" id="6Tk-OE-BBY"/>
</view>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="dkx-z0-nzr" sceneMemberID="firstResponder"/>
</objects>
</scene>
</scenes>
</document>
25 changes: 25 additions & 0 deletions ImageDecode/Info.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>UIApplicationSceneManifest</key>
<dict>
<key>UIApplicationSupportsMultipleScenes</key>
<false/>
<key>UISceneConfigurations</key>
<dict>
<key>UIWindowSceneSessionRoleApplication</key>
<array>
<dict>
<key>UISceneConfigurationName</key>
<string>Default Configuration</string>
<key>UISceneDelegateClassName</key>
<string>SceneDelegate</string>
<key>UISceneStoryboardFile</key>
<string>Main</string>
</dict>
</array>
</dict>
</dict>
</dict>
</plist>
16 changes: 16 additions & 0 deletions ImageDecode/SceneDelegate.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//
// SceneDelegate.h
// ImageDecode
//
// Created by Unix_Kernel on 7/17/24.
// Copyright © 2024 杭城小刘. All rights reserved.
//

#import <UIKit/UIKit.h>

@interface SceneDelegate : UIResponder <UIWindowSceneDelegate>

@property (strong, nonatomic) UIWindow * window;

@end

Loading

0 comments on commit 9497ee9

Please sign in to comment.