Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
JesseB0rn authored Aug 30, 2020
1 parent 0572310 commit 001f73b
Show file tree
Hide file tree
Showing 27 changed files with 535 additions and 0 deletions.
8 changes: 8 additions & 0 deletions CCModule/MQTTModule.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#import <ControlCenterUIKit/CCUIToggleModule.h>

@interface MQTTModule : CCUIToggleModule
{
BOOL _selected;
}

@end
13 changes: 13 additions & 0 deletions CCModule/MQTTModule.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#import "MQTTModule.h"

@implementation MQTTModule

- (UIImage *)iconGlyph {
return [UIImage imageNamed:@"ModuleIcon" inBundle:[NSBundle bundleForClass:[self class]] compatibleWithTraitCollection:nil];
}

- (void)setSelected:(BOOL)selected {
[[NSNotificationCenter defaultCenter] postNotificationName:@"ch.jesseb0rn.mqttmodule.run" object:nil];
}

@end
16 changes: 16 additions & 0 deletions CCModule/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
include $(THEOS)/makefiles/common.mk

export TARGET = iphone:clang::11.0
export ARCHS = arm64

BUNDLE_NAME = MQTTModule
MQTTModule_BUNDLE_EXTENSION = bundle
MQTTModule_FILES = MQTTModule.m
MQTTModule_PRIVATE_FRAMEWORKS = ControlCenterUIKit
MQTTModule_FRAMEWORKS = UIKit
MQTTModule_INSTALL_PATH = /Library/ControlCenter/Bundles/

after-install::
install.exec "killall -9 SpringBoard"

include $(THEOS_MAKE_PATH)/bundle.mk
54 changes: 54 additions & 0 deletions CCModule/Resources/Info.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?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>CFBundleName</key>
<string>MQTTModule</string>
<key>CFBundleExecutable</key>
<string>MQTTModule</string>
<key>CFBundleIdentifier</key>
<string>ch.jesseb0rn.mqttmodule</string>
<key>CFBundleDevelopmentRegion</key>
<string>English</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundlePackageType</key>
<string>BNDL</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleVersion</key>
<string>1</string>
<key>MinimumOSVersion</key>
<string>7.0</string>
<key>UIDeviceFamily</key>
<array>
<integer>1</integer>
<integer>2</integer>
</array>
<key>NSPrincipalClass</key>
<string>MQTTModule</string>
<key>CFBundleSupportedPlatforms</key>
<array>
<string>iPhoneOS</string>
</array>
<key>CCSGetModuleSizeAtRuntime</key>
<false/>
<key>CCSModuleSize</key>
<dict>
<key>Portrait</key>
<dict>
<key>Height</key>
<integer>1</integer>
<key>Width</key>
<integer>1</integer>
</dict>
<key>Landscape</key>
<dict>
<key>Height</key>
<integer>1</integer>
<key>Width</key>
<integer>1</integer>
</dict>
</dict>
</dict>
</plist>
Binary file added CCModule/Resources/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added CCModule/Resources/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added CCModule/Resources/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added CCModule/Resources/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 14 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
THEOS = /var/theos #Theos directory
ARCHS = arm64 arm64e #A11+ support
TARGET = iphone:clang::11.0 #min ios11, latest sdk

#seems to cause problems, only use for release builds
#PACKAGE_VERSION = 1.0.1

include $(THEOS)/makefiles/common.mk

TWEAK_NAME = MQTTModule
MQTTModule_CFLAGS = -fobjc-arc

SUBPROJECTS += CCModule Tweak mqttmoduleprefs mqttmoduled #load all subprojects
include $(THEOS_MAKE_PATH)/aggregate.mk
14 changes: 14 additions & 0 deletions Tweak/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
INSTALL_TARGET_PROCESSES = SpringBoard

ARCHS = arm64 arm64e
include $(THEOS)/makefiles/common.mk

TWEAK_NAME = Tweak

Tweak_FILES = Tweak.xm
Tweak_CFLAGS = -fobjc-arc

Tweak_FRAMEWORKS = UIKit
Tweak_PRIVATE_FRAMEWORKS = ControlCenterUIKit

include $(THEOS_MAKE_PATH)/tweak.mk
1 change: 1 addition & 0 deletions Tweak/Tweak.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{ Filter = { Bundles = ( "com.apple.springboard" ); }; }
81 changes: 81 additions & 0 deletions Tweak/Tweak.xm
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
#import <string.h>
#import <dlfcn.h>
#import "../headers/NSTask.h"
#define FLAG_PLATFORMIZE (1 << 1)

@interface CCUIModuleCollectionViewController : UIViewController
- (void)viewDidLoad;
- (void)dealloc;
- (void)startCommandModule:(NSNotification *)notification;
@end

//preference vars
NSString * host;
NSInteger port;
NSString *topic;
NSString *msg;
NSInteger qos;

static NSString *bundleIdentifier = @"ch.jesseb0rn.mqttprefs";
static NSMutableDictionary *settings;

%group ios13
%hook CCUIModuleCollectionViewController
- (void)viewDidLoad {
%orig;
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(publishMqtt:) name:@"ch.jesseb0rn.mqttmodule.run" object:nil];
}

- (void)dealloc {
%orig;
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
%new
- (void)publishMqtt:(NSNotification *)notification { //this method is run upon receiving the notification that the user invoked my tweak

UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"MQTTModule" message: [NSString stringWithFormat:@"/usr/bin/mqtt %@ %ld %@ %@ %ld", host, port, topic, msg, qos] preferredStyle:UIAlertControllerStyleAlert];


[self presentViewController:alert animated:YES completion:^{
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^(void) { //must dispatch_async so the UI doesn't freeze while the script is running

NSTask* task = [[NSTask alloc] init];
[task setLaunchPath:@"/usr/bin/mqttmoduled"];
[task setArguments: @[[NSString stringWithFormat:@"%@", host], [NSString stringWithFormat:@"%ld", port], [NSString stringWithFormat:@"%@", topic], [NSString stringWithFormat:@"%@", msg], [NSString stringWithFormat:@"%ld", qos]]];
[task launch];

while ([task isRunning]) {
[[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:2.0]];
}

dispatch_sync(dispatch_get_main_queue(), ^{ //once the script is finished, update the UI
[alert dismissViewControllerAnimated:YES completion:nil];
});
});
}];
}
%end
%end

%ctor {

CFArrayRef keyList = CFPreferencesCopyKeyList((CFStringRef)bundleIdentifier, kCFPreferencesCurrentUser, kCFPreferencesAnyHost);
if (keyList) {
settings = (NSMutableDictionary *)CFBridgingRelease(CFPreferencesCopyMultiple(keyList, (CFStringRef)bundleIdentifier, kCFPreferencesCurrentUser, kCFPreferencesAnyHost));
CFRelease(keyList);
} else {
settings = nil;
}
if (!settings) {
settings = [[NSMutableDictionary alloc] initWithContentsOfFile:[NSString stringWithFormat:@"/var/mobile/Library/Preferences/ch.jesseb0rn.mqttprefs.plist"]];
}

host = [settings valueForKey:@"host"];
port = [[settings valueForKey:@"port"] integerValue];
topic = [settings valueForKey:@"topic"];
msg = [settings valueForKey:@"msg"];
qos = [[settings valueForKey:@"qos"] integerValue];

%init(ios13);

}
58 changes: 58 additions & 0 deletions headers/NSTask.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
@class NSURL, NSArray, NSDictionary;

@interface NSTask : NSObject

@property (copy) NSURL * executableURL;
@property (copy) NSArray * arguments;
@property (copy) NSDictionary * environment;
@property (copy) NSURL * currentDirectoryURL;
@property (retain) id standardInput;
@property (retain) id standardOutput;
@property (retain) id standardError;
@property (readonly) int processIdentifier;
@property (getter=isRunning,readonly) BOOL running;
@property (readonly) int terminationStatus;
@property (readonly) long long terminationReason;
@property (copy) id terminationHandler;
@property (assign) long long qualityOfService;
+(id)currentTaskDictionary;
+(id)launchedTaskWithDictionary:(id)arg1 ;
+(id)launchedTaskWithLaunchPath:(id)arg1 arguments:(id)arg2 ;
+(id)launchedTaskWithExecutableURL:(id)arg1 arguments:(id)arg2 error:(out id*)arg3 terminationHandler:(/*^block*/id)arg4 ;
+(id)allocWithZone:(NSZone*)arg1 ;
-(void)waitUntilExit;
-(NSURL *)executableURL;
-(id)currentDirectoryPath;
-(void)setArguments:(NSArray *)arg1 ;
-(void)setCurrentDirectoryPath:(id)arg1 ;
-(id)launchPath;
-(void)setLaunchPath:(id)arg1 ;
-(int)terminationStatus;
-(long long)terminationReason;
-(void)launch;
-(BOOL)launchAndReturnError:(id*)arg1 ;
-(void)setCurrentDirectoryURL:(NSURL *)arg1 ;
-(NSURL *)currentDirectoryURL;
-(void)setExecutableURL:(NSURL *)arg1 ;
-(void)interrupt;
-(long long)suspendCount;
-(void)setStandardInput:(id)arg1 ;
-(void)setStandardOutput:(id)arg1 ;
-(void)setStandardError:(id)arg1 ;
-(id)standardInput;
-(id)standardOutput;
-(id)standardError;
-(id)init;
-(NSDictionary *)environment;
-(BOOL)isRunning;
-(BOOL)suspend;
-(BOOL)resume;
-(void)setEnvironment:(NSDictionary *)arg1 ;
-(void)setQualityOfService:(long long)arg1 ;
-(void)setTerminationHandler:(id)arg1 ;
-(int)processIdentifier;
-(id)terminationHandler;
-(long long)qualityOfService;
-(void)terminate;
-(NSArray *)arguments;
@end
9 changes: 9 additions & 0 deletions layout/DEBIAN/control
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
Package: ch.jesseb0rn.mqttmodule
Name: MQTTModule
Depends: mobilesubstrate, com.opa334.ccsupport, ch.jesseb0rn.mqtt
Version: 1.0.2
Architecture: iphoneos-arm
Description: Send a MQTT message from your CC
Maintainer: jesseb0rn
Author: jesseb0rn
Section: Control Center Modules
6 changes: 6 additions & 0 deletions layout/DEBIAN/postinst
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash

chown root:wheel /usr/bin/mqttmoduled
chmod +s /usr/bin/mqttmoduled

exit 0
11 changes: 11 additions & 0 deletions mqttmoduled/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
include $(THEOS)/makefiles/common.mk

TOOL_NAME = mqttmoduled

mqttmoduled_FILES = main.m
mqttmoduled_CFLAGS = -fobjc-arc

mqttmoduled_CODESIGN_FLAGS = -Sent.xml


include $(THEOS_MAKE_PATH)/tool.mk
10 changes: 10 additions & 0 deletions mqttmoduled/ent.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>platform-application</key>
<true/>
<key>com.apple.private.security.no-container</key>
<true/>

</dict>
</plist>
28 changes: 28 additions & 0 deletions mqttmoduled/main.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#include <stdio.h>
#import "../headers/NSTask.h"

int main(int argc, char *argv[], char *envp[]) {

NSString * host = [NSString stringWithUTF8String:argv[1]];
NSInteger port = 1883;
port = strtol(argv[2], NULL, 10);
NSString *topic = [NSString stringWithUTF8String:argv[3]];
NSString *msg = [NSString stringWithUTF8String:argv[4]];
NSInteger qos = 0;
qos = strtol(argv[5], NULL, 10);
setuid(0); //make us root
setgid(0);
if (getuid() != 0) { //Check for root permissions
printf("root accsess denied");
}
NSTask *task = [[NSTask alloc] init];
task.launchPath = @"/usr/bin/mqtt";
[task setArguments: @[[NSString stringWithFormat:@"%@", host], [NSString stringWithFormat:@"%ld", port], [NSString stringWithFormat:@"%@", topic], [NSString stringWithFormat:@"%@", msg], [NSString stringWithFormat:@"%ld", qos]]];
[task launch];

while ([task isRunning]) { //Wait for task to finnish
[[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:0.5]];
}

return 0;
}
15 changes: 15 additions & 0 deletions mqttmoduleprefs/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
include $(THEOS)/makefiles/common.mk
ARCHS = arm64 arm64e
BUNDLE_NAME = mqttmoduleprefs

mqttmoduleprefs_FILES = jmpRootListController.m
mqttmoduleprefs_INSTALL_PATH = /Library/PreferenceBundles
mqttmoduleprefs_FRAMEWORKS = UIKit
mqttmoduleprefs_PRIVATE_FRAMEWORKS = Preferences
mqttmoduleprefs_CFLAGS = -fobjc-arc

include $(THEOS_MAKE_PATH)/bundle.mk

internal-stage::
$(ECHO_NOTHING)mkdir -p $(THEOS_STAGING_DIR)/Library/PreferenceLoader/Preferences$(ECHO_END)
$(ECHO_NOTHING)cp entry.plist $(THEOS_STAGING_DIR)/Library/PreferenceLoader/Preferences/mqttmoduleprefs.plist$(ECHO_END)
24 changes: 24 additions & 0 deletions mqttmoduleprefs/Resources/Info.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?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>CFBundleDevelopmentRegion</key>
<string>English</string>
<key>CFBundleExecutable</key>
<string>mqttmoduleprefs</string>
<key>CFBundleIdentifier</key>
<string>ch.jesseb0rn.mqttprefs</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundlePackageType</key>
<string>BNDL</string>
<key>CFBundleShortVersionString</key>
<string>1.0.0</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>1.0</string>
<key>NSPrincipalClass</key>
<string>jmpRootListController</string>
</dict>
</plist>
Loading

0 comments on commit 001f73b

Please sign in to comment.