换一个姿势写Tweak插件

初始化Tweak插件

/opt/theos/bin/nic.pl

进入创建的插件目录

创建 CmakeLists.txt 文件

cmake_minimum_required(VERSION 3.19)
project(ProcCheck)

set(CMAKE_CXX_STANDARD 14)

include_directories(
        /opt/theos/vendor/include
)

SET(CMAKE_OSX_SYSROOT /opt/theos/sdks/iPhoneOS12.2.sdk)
macro(ADD_FRAMEWORK fwname appname)
    find_library(FRAMEWORK_${fwname}
            NAMES ${fwname}
            PATHS ${CMAKE_OSX_SYSROOT}/System/Library
            PATH_SUFFIXES Frameworks
            NO_DEFAULT_PATH)
    if( ${FRAMEWORK_${fwname}} STREQUAL FRAMEWORK_${fwname}-NOTFOUND)
        MESSAGE(ERROR": Framework ${fwname} not found")
    else()
        TARGET_LINK_LIBRARIES(${appname} ${FRAMEWORK_${fwname}})
        MESSAGE(STATUS"Framework ${fwname} found at ${FRAMEWORK_${fwname}}")
    endif()
endmacro(ADD_FRAMEWORK)

add_executable(ProcCheck main.mm common.h)

ADD_FRAMEWORK(UIKit ${PROJECT_NAME})

目的就是让 clion 能够智能提示

打开 clion ,加载插件目录

  • 新建文件 common.h
#include <substrate.h>
#include <Foundation/Foundation.h>
  • 新建文件 main.mm
#include "common.h"
#include <UIKit/UIKit.h>

MSClassHook(UIDevice)

MSInstanceMessageHook0(NSString *, UIDevice, name) {
    NSString *ret = MSOldCall();
    NSLog(@"UIDevice.name: %@", ret);
    return ret;
}

MSInstanceMessageHook0(NSString *, UIDevice, model) {
    NSString *ret = MSOldCall();
    NSLog(@"UIDevice.model: %@", ret);
    return ret;
}

__attribute__((constructor)) static void init() {
    @autoreleasepool {
        NSLog(@"BundleID: %@", [[NSBundle mainBundle] bundleIdentifier]);
    }
}

当然,不使用 Logos 语法.因为我认为 Logos 语法隐藏了太多细节,一旦出点问题,就比较抓狂.

修改 Makefile

DEBUG = 1

THEOS_DEVICE_IP = localhost
THEOS_DEVICE_PORT = 2222
ARCHS = arm64

TARGET := iphone:clang:latest:13.0
INSTALL_TARGET_PROCESSES = SpringBoard

include $(THEOS)/makefiles/common.mk

TWEAK_NAME = ProcCheck

${TWEAK_NAME}_FILES += main.mm
${TWEAK_NAME}_CFLAGS = -fobjc-arc

${TWEAK_NAME}_OBJCFLAGS += -Wno-deprecated-declarations -Wno-unused-variable -Wno-unused-function
${TWEAK_NAME}_OBJCFLAGS += -Wno-deprecated-declarations -Wno-arc-performSelector-leaks -Wno-visibility

include $(THEOS_MAKE_PATH)/tweak.mk

编译/安装插件

  • 在 Makefile 文件中点击“绿色”小箭头即可执行 make;
  • 在clion的编译配置添加一个 make,参数: package install

总结

很爽!!!虽然没用Logos语法,但也没觉得不舒服.

3 Likes

想当初为了Logos和objc混合写代码操碎了心,被xcode虐的心情低落.
如今完全抛弃Logos和Xcode,使用牛逼的Clion做代码智能提示,效率还是很高的.

分享一定菜鸟经验罢了,没说很牛逼啊.

没Logos支持可能是个问题,大多数人包括我自己应该还是习惯Logos的

真香,我也去尝试下

大哥,我努力搞一个Logos语法插件

加你V了通过下