Skip to content

Commit

Permalink
[General] Starting template to compile into a tweak
Browse files Browse the repository at this point in the history
  • Loading branch information
leptos-null committed Aug 20, 2024
1 parent 6835c5f commit ea32991
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[submodule "ClassDumpRuntime"]
path = ClassDumpRuntime
url = git@github.com:leptos-null/ClassDumpRuntime.git
url = https://github.com/leptos-null/ClassDumpRuntime.git
1 change: 1 addition & 0 deletions ClassDumpTweak.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{ Filter = { Bundles = ( "com.apple.springboard" ); }; }
15 changes: 7 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
TARGET := iphone:clang:latest:8.0
INSTALL_TARGET_PROCESSES := SpringBoard
ARCHS := arm64

include $(THEOS)/makefiles/common.mk

TOOL_NAME = classdumpctl
TWEAK_NAME = ClassDumpTweak

classdumpctl_FILES = Sources/classdumpctl/main.m
classdumpctl_FILES += $(wildcard ClassDumpRuntime/Sources/ClassDumpRuntime/ClassDump/*/*.m)
classdumpctl_FILES += $(wildcard ClassDumpRuntime/Sources/ClassDumpRuntime/ClassDump/*/*/*.m)
ClassDumpTweak_FILES = Tweak.x
ClassDumpTweak_FILES += $(wildcard ClassDumpRuntime/Sources/ClassDumpRuntime/ClassDump/*/*.m)
ClassDumpTweak_FILES += $(wildcard ClassDumpRuntime/Sources/ClassDumpRuntime/ClassDump/*/*/*.m)

classdumpctl_CFLAGS = -fobjc-arc -I ClassDumpRuntime/Sources/ClassDumpRuntime/include
classdumpctl_CODESIGN_FLAGS = -Sentitlements.plist
classdumpctl_INSTALL_PATH = /usr/local/bin
ClassDumpTweak_CFLAGS = -fobjc-arc -I ClassDumpRuntime/Sources/ClassDumpRuntime/include

include $(THEOS_MAKE_PATH)/tool.mk
include $(THEOS_MAKE_PATH)/tweak.mk
37 changes: 37 additions & 0 deletions Tweak.x
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#import <Foundation/Foundation.h>
#import <ClassDump/ClassDump.h>

static CDClassModel *safelyGenerateModelForClass(Class const cls, IMP const blankIMP) {
Method const initializeMthd = class_getClassMethod(cls, @selector(initialize));
method_setImplementation(initializeMthd, blankIMP);

return [CDClassModel modelWithClass:cls];
}

static void dumpHeader(NSString *requestImage, NSString *outputDir) {
IMP const blankIMP = imp_implementationWithBlock(^{ }); // returns void, takes no parameters

CDGenerationOptions *const generationOptions = [CDGenerationOptions new];
generationOptions.stripSynthesized = YES;

unsigned int classCount = 0;
const char **classNames = objc_copyClassNamesForImage(requestImage.fileSystemRepresentation, &classCount);
for (unsigned int classIndex = 0; classIndex < classCount; classIndex++) {
Class const cls = objc_getClass(classNames[classIndex]);
CDClassModel *model = safelyGenerateModelForClass(cls, blankIMP);
CDSemanticString *semanticString = [model semanticLinesWithOptions:generationOptions];
NSString *lines = [semanticString string];
NSString *headerName = [NSStringFromClass(cls) stringByAppendingPathExtension:@"h"];

NSString *headerPath = [outputDir stringByAppendingPathComponent:headerName];

NSError *writeError = nil;
if (![lines writeToFile:headerPath atomically:NO encoding:NSUTF8StringEncoding error:&writeError]) {
NSLog(@"writeToFileError: %@", writeError);
}
}
}

%ctor {
dumpHeader(@"TODO", @"TODO");
}

0 comments on commit ea32991

Please sign in to comment.