Private
Public Access
1
0

Compare commits

..

2 Commits

Author SHA1 Message Date
James Magahern
40fb964cb3 SendMessage: allows creation of new conversations in addition to replying to guids 2021-07-08 15:35:29 -07:00
James Magahern
d814c2e4f6 Started working on new conversation / address validation 2021-07-08 13:46:10 -07:00
22 changed files with 252 additions and 466 deletions

View File

@@ -3457,7 +3457,6 @@ __attribute__((visibility("default"))) @interface IMService : NSObject { }
- (id)loadUnreadMessagesWithLimit:(unsigned long long)arg1 fallbackToMessagesUpToGUID:(id)arg2;
- (id)loadFrequentRepliesLimit:(unsigned long long)arg1 loadImmediately:(BOOL)arg2;
- (id)loadMessagesBeforeAndAfterGUID:(id)arg1 numberOfMessagesToLoadBeforeGUID:(unsigned long long)arg2 numberOfMessagesToLoadAfterGUID:(unsigned long long)arg3 loadImmediately:(BOOL)arg4;
- (id)loadMessagesBeforeAndAfterGUID:(id)arg1 numberOfMessagesToLoadBeforeGUID:(unsigned long long)arg2 numberOfMessagesToLoadAfterGUID:(unsigned long long)arg3 loadImmediately:(BOOL)arg4 threadIdentifier:(id)tid;
- (id)loadMessagesUpToGUID:(id)arg1 date:(id)arg2 limit:(unsigned long long)arg3 loadImmediately:(BOOL)arg4;
- (id)loadMessagesBeforeDate:(id)arg1 limit:(unsigned long long)arg2 loadImmediately:(BOOL)arg3;
- (id)loadMessagesBeforeDate:(id)arg1 limit:(unsigned long long)arg2;
@@ -4082,6 +4081,38 @@ __attribute__((visibility("default"))) @interface IMService : NSObject { }
@end
// Monterey
#if 0
@interface IMChatRegistry ()
- (IMChat *)chatWithHandle:(IMHandle *)handle;
- (IMChat *)chatWithHandle:(IMHandle *)handle lastAddressedHandle:(NSString *)lastAddressedHandle lastAddressedSIMID:(NSString *)lastAddressedSIMID;
- (IMChat *)chatWithHandles:(NSArray<IMHandle *> *)handles;
- (IMChat *)chatWithHandles:(NSArray<IMHandle *> *)handles lastAddressedHandle:(NSString *)lastAddressedHandle lastAddressedSIMID:(NSString *)lastAddressedSIMID;
- (IMChat *)chatWithHandles:(NSArray<IMHandle *> *)handles displayName:(NSString *)displayName joinedChatsOnly:(BOOL)joinedChatsOnly;
- (IMChat *)chatWithHandles:(NSArray<IMHandle *> *)handles displayName:(NSString *)displayName joinedChatsOnly:(BOOL)joinedChatsOnly lastAddressedHandle:(NSString *)lastAddressedHandle lastAddressedSIMID:(NSString *)lastAddressedSIMID;
- (NSArray<NSString *> *)allGUIDsForChat:(IMChat *)chat;
- (IMChat *)existingChatWithHandle:(IMHandle *)handle;
- (IMChat *)existingChatWithHandle:(IMHandle *)handle allowAlternativeService:(BOOL)allowAlternativeService;
- (IMChat *)existingChatWithHandles:(NSArray<IMHandle *> *)handles;
- (IMChat *)existingChatWithHandles:(NSArray<IMHandle *> *)handles allowAlternativeService:(BOOL)allowAlternativeService;
- (IMChat *)existingChatWithHandles:(NSArray<IMHandle *> *)handles allowAlternativeService:(BOOL)allowAlternativeService groupID:(NSString *)groupID;
- (IMChat *)existingChatWithHandles:(NSArray *)handles allowAlternativeService:(BOOL)allowAlternativeService groupID:(NSString *)groupID displayName:(NSString *)displayName joinedChatsOnly:(BOOL)joinedChatsOnly;
- (IMChat *)existingChatWithPinningIdentifier:(NSString *)pinningIdentifier;
- (IMChat *)existingChatWithDeviceIndependentID:(NSString *)deviceIndependentID;
- (IMChat *)existingChatWithPersonID:(NSString *)personID;
- (IMChat *)existingChatWithDisplayName:(NSString *)displayName;
- (IMChat *)existingChatWithAddresses:(NSArray<NSString *> *)addresses allowAlternativeService:(BOOL)allowAlternativeService bestHandles:(NSArray<IMHandle *> **)outBestHandles;
- (IMChat *)existingChatWithContacts:(NSSet *)contacts bestHandles:(NSArray<IMHandle *> **)outBestHandles;
@end
#endif
@interface IMSimulatedChat : IMChat // <IMSimulatedChatDelegate, IMSimulatedDaemonListener>
{
// id <IMSimulatedChatDelegate> _delegate;

View File

@@ -1898,3 +1898,29 @@ typedef void (^CDUnknownBlockType)(void); // return type and parameters are unkn
- (void)differencesFromArray:(id)arg1 removedIndexes:(id *)arg2 insertedIndexes:(id *)arg3;
@end
extern BOOL IMStringIsEmail (NSString *string);
extern NSString* IMStripFormattingFromAddress (NSString *address);
typedef void(^IMChatCalculateServiceForSendingCompletionBlock) (BOOL allAddressesiMessageCapable,
NSDictionary *availabilityPerRecipient,
BOOL checkedServer,
NSError *error);
extern void IMChatCalculateServiceForSendingNewComposeMaybeForce (NSArray *addresses,
NSString *senderLastAddressedHandle,
NSString *senderLastAddressedSIMID,
BOOL forceMMS,
BOOL hasEmailRecipients,
BOOL lastSentMessageWasNotDelivered,
BOOL conversationWasDowngraded,
BOOL hasConversationHistory,
IMService *previousService,
IMChatCalculateServiceForSendingCompletionBlock completion);
// IDS
extern NSString *IDSCopyIDForPhoneNumber(NSString *phoneNumber);
extern NSString *IDSCopyIDForEmailAddress(NSString *emailAddress);

View File

@@ -745,19 +745,6 @@ struct __va_list_tag {
@end
@interface IMImageUtilities : NSObject
{
}
+ (struct CGImage *)newThumbnailForTargetSize:(struct CGSize)arg1 imageSize:(struct CGSize)arg2 imageSource:(struct CGImageSource *)arg3 atIndex:(unsigned long long)arg4 mode:(long long)arg5 scale:(double)arg6;
+ (struct CGImage *)newThumbnailForTargetSize:(struct CGSize)arg1 imageSize:(struct CGSize)arg2 imageSource:(struct CGImageSource *)arg3 mode:(long long)arg4 scale:(double)arg5;
+ (BOOL)persistCPBitmapWithImage:(struct CGImage *)arg1 url:(id)arg2;
+ (void)sampleImageEdges:(char *)arg1 usingRect:(struct CGRect)arg2 forMostlyWhitePixels:(unsigned long long *)arg3 otherPixels:(unsigned long long *)arg4 bytesPerRow:(long long)arg5;
+ (struct CGSize)imageRefPxSize:(struct CGImage *)arg1;
+ (struct CGSize)imageSourcePxSize:(struct CGImageSource *)arg1;
@end
@interface IMOneTimeCodeUtilities : NSObject
{
}
@@ -1426,17 +1413,6 @@ struct __va_list_tag {
@end
@interface IMImagePreviewGenerator : IMPreviewGenerator <IMPreviewGeneratorProtocol, IMUTITypeInformation>
{
}
+ (struct CGImage *)newThumbnailFillToSize:(struct CGSize)arg1 imagePxSize:(struct CGSize)arg2 imageSource:(struct CGImageSource *)arg3 scale:(double)arg4;
+ (struct CGImage *)newPreviewFromSourceURL:(id)arg1 withPreviewConstraints:(struct IMPreviewConstraints)arg2 error:(id *)arg3;
+ (id)UTITypes;
+ (id)fetchUTITypes;
@end
@interface IMAKAppleIDAuthenticationController : NSObject
{

View File

@@ -81,10 +81,8 @@
CD602062219B68950024D9C5 /* MBIMSendMessageOperation.m in Sources */ = {isa = PBXBuildFile; fileRef = CD602061219B68950024D9C5 /* MBIMSendMessageOperation.m */; };
CD83E156219BE10A00F4CCEA /* hooking.m in Sources */ = {isa = PBXBuildFile; fileRef = CD83E155219BE10A00F4CCEA /* hooking.m */; };
CD83E166219BE91600F4CCEA /* agentHook.m in Sources */ = {isa = PBXBuildFile; fileRef = CD83E165219BE91600F4CCEA /* agentHook.m */; };
CD936A32289B353F0093A1AC /* MBIMErrorResponse.m in Sources */ = {isa = PBXBuildFile; fileRef = CD936A31289B353F0093A1AC /* MBIMErrorResponse.m */; };
CD936A35289B47D60093A1AC /* MBIMVersionOperation.m in Sources */ = {isa = PBXBuildFile; fileRef = CD936A34289B47D50093A1AC /* MBIMVersionOperation.m */; };
CD936A39289B49FC0093A1AC /* MBIMStatusOperation.m in Sources */ = {isa = PBXBuildFile; fileRef = CD936A38289B49FC0093A1AC /* MBIMStatusOperation.m */; };
CDDCF78D283F398C0087ABDF /* MBIMDeleteConversationOperation.m in Sources */ = {isa = PBXBuildFile; fileRef = CDDCF78C283F398C0087ABDF /* MBIMDeleteConversationOperation.m */; };
CDD8C98426977D2A00551AE5 /* MBIMAliasValidationOperation.m in Sources */ = {isa = PBXBuildFile; fileRef = CDD8C98326977D2A00551AE5 /* MBIMAliasValidationOperation.m */; };
CDD8C9862697996800551AE5 /* IDS.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = CDD8C9852697996700551AE5 /* IDS.framework */; };
CDE4556421A3578A0041F5DD /* IMChat+Encoded.m in Sources */ = {isa = PBXBuildFile; fileRef = CDE4556321A3578A0041F5DD /* IMChat+Encoded.m */; };
CDE455A121A365AD0041F5DD /* MBIMMarkOperation.m in Sources */ = {isa = PBXBuildFile; fileRef = CDE455A021A365AD0041F5DD /* MBIMMarkOperation.m */; };
CDE455A421A5308D0041F5DD /* MBIMFetchAttachmentOperation.m in Sources */ = {isa = PBXBuildFile; fileRef = CDE455A321A5308D0041F5DD /* MBIMFetchAttachmentOperation.m */; };
@@ -240,15 +238,9 @@
CD83E161219BE91500F4CCEA /* libagentHook.dylib */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.dylib"; includeInIndex = 0; path = libagentHook.dylib; sourceTree = BUILT_PRODUCTS_DIR; };
CD83E165219BE91600F4CCEA /* agentHook.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = agentHook.m; sourceTree = "<group>"; };
CD83E1B5219BF78E00F4CCEA /* hookAgent.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = hookAgent.sh; sourceTree = "<group>"; };
CD936A2F289B31740093A1AC /* kordophoned-RestrictedEntitlements.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "kordophoned-RestrictedEntitlements.plist"; sourceTree = "<group>"; };
CD936A30289B353F0093A1AC /* MBIMErrorResponse.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MBIMErrorResponse.h; sourceTree = "<group>"; };
CD936A31289B353F0093A1AC /* MBIMErrorResponse.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MBIMErrorResponse.m; sourceTree = "<group>"; };
CD936A33289B47D50093A1AC /* MBIMVersionOperation.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MBIMVersionOperation.h; sourceTree = "<group>"; };
CD936A34289B47D50093A1AC /* MBIMVersionOperation.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MBIMVersionOperation.m; sourceTree = "<group>"; };
CD936A37289B49FC0093A1AC /* MBIMStatusOperation.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MBIMStatusOperation.h; sourceTree = "<group>"; };
CD936A38289B49FC0093A1AC /* MBIMStatusOperation.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MBIMStatusOperation.m; sourceTree = "<group>"; };
CDDCF78B283F398C0087ABDF /* MBIMDeleteConversationOperation.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MBIMDeleteConversationOperation.h; sourceTree = "<group>"; };
CDDCF78C283F398C0087ABDF /* MBIMDeleteConversationOperation.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MBIMDeleteConversationOperation.m; sourceTree = "<group>"; };
CDD8C98226977D2A00551AE5 /* MBIMAliasValidationOperation.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MBIMAliasValidationOperation.h; sourceTree = "<group>"; };
CDD8C98326977D2A00551AE5 /* MBIMAliasValidationOperation.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MBIMAliasValidationOperation.m; sourceTree = "<group>"; };
CDD8C9852697996700551AE5 /* IDS.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = IDS.framework; path = System/Library/PrivateFrameworks/IDS.framework; sourceTree = SDKROOT; };
CDE4556221A3578A0041F5DD /* IMChat+Encoded.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "IMChat+Encoded.h"; sourceTree = "<group>"; };
CDE4556321A3578A0041F5DD /* IMChat+Encoded.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "IMChat+Encoded.m"; sourceTree = "<group>"; };
CDE4559F21A365AD0041F5DD /* MBIMMarkOperation.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MBIMMarkOperation.h; sourceTree = "<group>"; };
@@ -287,6 +279,7 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
CDD8C9862697996800551AE5 /* IDS.framework in Frameworks */,
1A257CCB23A8681200A4A2C8 /* Security.framework in Frameworks */,
1ACFCFDF219EB31400E2C237 /* CocoaHTTPServer.framework in Frameworks */,
1A257CC923A867EF00A4A2C8 /* IMCore.framework in Frameworks */,
@@ -334,6 +327,7 @@
1A0C445E219A45B400F2AC00 /* Frameworks */ = {
isa = PBXGroup;
children = (
CDD8C9852697996700551AE5 /* IDS.framework */,
1A257CCA23A8681200A4A2C8 /* Security.framework */,
1A257CC823A867EF00A4A2C8 /* IMCore.framework */,
);
@@ -366,8 +360,6 @@
1AA43E8E219EBB2D00EDF1A7 /* MBIMJSONDataResponse.m */,
CDE455A521A531ED0041F5DD /* MBIMDataResponse.h */,
CDE455A621A531ED0041F5DD /* MBIMDataResponse.m */,
CD936A30289B353F0093A1AC /* MBIMErrorResponse.h */,
CD936A31289B353F0093A1AC /* MBIMErrorResponse.m */,
1AA43E93219EC38E00EDF1A7 /* MBIMHTTPUtilities.h */,
1AA43E94219EC38E00EDF1A7 /* MBIMHTTPUtilities.m */,
);
@@ -535,30 +527,26 @@
isa = PBXGroup;
children = (
1AA43E90219EBB3400EDF1A7 /* Utilities */,
CD2ECEC0269539100055E302 /* MBIMAuthenticateOperation.h */,
CD2ECEC1269539100055E302 /* MBIMAuthenticateOperation.m */,
CD602054219B5DFD0024D9C5 /* MBIMBridgeOperation.h */,
CD602055219B5DFD0024D9C5 /* MBIMBridgeOperation.m */,
CDD8C98226977D2A00551AE5 /* MBIMAliasValidationOperation.h */,
CDD8C98326977D2A00551AE5 /* MBIMAliasValidationOperation.m */,
CD2ECEC0269539100055E302 /* MBIMAuthenticateOperation.h */,
CD2ECEC1269539100055E302 /* MBIMAuthenticateOperation.m */,
CD60205A219B623F0024D9C5 /* MBIMMessagesListOperation.h */,
CD60205B219B623F0024D9C5 /* MBIMMessagesListOperation.m */,
CD60205D219B674B0024D9C5 /* MBIMConversationListOperation.h */,
CD60205E219B674B0024D9C5 /* MBIMConversationListOperation.m */,
CDDCF78B283F398C0087ABDF /* MBIMDeleteConversationOperation.h */,
CDDCF78C283F398C0087ABDF /* MBIMDeleteConversationOperation.m */,
CDE455A221A5308D0041F5DD /* MBIMFetchAttachmentOperation.h */,
CDE455A321A5308D0041F5DD /* MBIMFetchAttachmentOperation.m */,
CDE4559F21A365AD0041F5DD /* MBIMMarkOperation.h */,
CDE455A021A365AD0041F5DD /* MBIMMarkOperation.m */,
CD60205A219B623F0024D9C5 /* MBIMMessagesListOperation.h */,
CD60205B219B623F0024D9C5 /* MBIMMessagesListOperation.m */,
CD602060219B68950024D9C5 /* MBIMSendMessageOperation.h */,
CD602061219B68950024D9C5 /* MBIMSendMessageOperation.m */,
CD936A37289B49FC0093A1AC /* MBIMStatusOperation.h */,
CD936A38289B49FC0093A1AC /* MBIMStatusOperation.m */,
CD14F19F219FE7D600E7DD22 /* MBIMUpdatePollOperation.h */,
CD14F1A0219FE7D600E7DD22 /* MBIMUpdatePollOperation.m */,
1AD8936C21EFD986009B599A /* MBIMUploadAttachmentOperation.h */,
1AD8936D21EFD986009B599A /* MBIMUploadAttachmentOperation.m */,
CD936A33289B47D50093A1AC /* MBIMVersionOperation.h */,
CD936A34289B47D50093A1AC /* MBIMVersionOperation.m */,
);
path = Operations;
sourceTree = "<group>";
@@ -590,7 +578,6 @@
1A0C446D219A4BCD00F2AC00 /* Bridge */,
CDF62334219A895D00690038 /* main.m */,
1AAB32B221F835BD004A2A72 /* KPServer.pch */,
CD936A2F289B31740093A1AC /* kordophoned-RestrictedEntitlements.plist */,
);
path = kordophone;
sourceTree = "<group>";
@@ -699,7 +686,6 @@
isa = PBXNativeTarget;
buildConfigurationList = CDF62336219A895D00690038 /* Build configuration list for PBXNativeTarget "kordophoned" */;
buildPhases = (
CD936A36289B48930093A1AC /* Compile Version String */,
CDF6232E219A895D00690038 /* Sources */,
CDF6232F219A895D00690038 /* Frameworks */,
CDF62330219A895D00690038 /* CopyFiles */,
@@ -796,24 +782,6 @@
shellPath = /bin/sh;
shellScript = "# Type a script or drag a script file from your workspace to insert its path.\n\nRESULT=$(install_name_tool -delete_rpath $BUILT_PRODUCTS_DIR $BUILT_PRODUCTS_DIR/$EXECUTABLE_NAME 2> /dev/null)\n\ninstall_name_tool -add_rpath $BUILT_PRODUCTS_DIR $BUILT_PRODUCTS_DIR/$EXECUTABLE_NAME\n";
};
CD936A36289B48930093A1AC /* Compile Version String */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputFileListPaths = (
);
inputPaths = (
);
name = "Compile Version String";
outputFileListPaths = (
);
outputPaths = (
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "# Type a script or drag a script file from your workspace to insert its path.\nOUTPUT_FILE=\"$DERIVED_FILE_DIR/MBIMVersion.c\"\nVERSION_STR=`git describe`\n\necho \"const char* MBIMVersion() { return \\\"$VERSION_STR\\\"; }\" > $OUTPUT_FILE\n";
};
/* End PBXShellScriptBuildPhase section */
/* Begin PBXSourcesBuildPhase section */
@@ -877,24 +845,21 @@
CD2ECEC526953F2A0055E302 /* MBIMAuthToken.m in Sources */,
CD83E156219BE10A00F4CCEA /* hooking.m in Sources */,
1AAB32B121F82EB7004A2A72 /* MBIMLogging.m in Sources */,
CDDCF78D283F398C0087ABDF /* MBIMDeleteConversationOperation.m in Sources */,
1AD8936E21EFD986009B599A /* MBIMUploadAttachmentOperation.m in Sources */,
CDF6233A219A8A5600690038 /* MBIMBridge.m in Sources */,
CDF62335219A895D00690038 /* main.m in Sources */,
CD60205C219B623F0024D9C5 /* MBIMMessagesListOperation.m in Sources */,
CDD8C98426977D2A00551AE5 /* MBIMAliasValidationOperation.m in Sources */,
CD14F1AA219FF3B800E7DD22 /* MBIMUpdateQueue.m in Sources */,
CD14F1A4219FF22700E7DD22 /* IMMessageItem+Encoded.m in Sources */,
CD602062219B68950024D9C5 /* MBIMSendMessageOperation.m in Sources */,
CD14F1A1219FE7D600E7DD22 /* MBIMUpdatePollOperation.m in Sources */,
CD936A39289B49FC0093A1AC /* MBIMStatusOperation.m in Sources */,
CDE455A121A365AD0041F5DD /* MBIMMarkOperation.m in Sources */,
CDE455A721A531ED0041F5DD /* MBIMDataResponse.m in Sources */,
CD936A35289B47D60093A1AC /* MBIMVersionOperation.m in Sources */,
CD602056219B5DFD0024D9C5 /* MBIMBridgeOperation.m in Sources */,
CD60205F219B674B0024D9C5 /* MBIMConversationListOperation.m in Sources */,
CDE4556421A3578A0041F5DD /* IMChat+Encoded.m in Sources */,
1AA43E8F219EBB2D00EDF1A7 /* MBIMJSONDataResponse.m in Sources */,
CD936A32289B353F0093A1AC /* MBIMErrorResponse.m in Sources */,
CD2ECEC2269539100055E302 /* MBIMAuthenticateOperation.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
@@ -1163,7 +1128,6 @@
isa = XCBuildConfiguration;
buildSettings = {
CLANG_ENABLE_MODULES = NO;
CODE_SIGN_ENTITLEMENTS = "kordophone/kordophoned-RestrictedEntitlements.plist";
CODE_SIGN_IDENTITY = "-";
CODE_SIGN_STYLE = Automatic;
GCC_PREFIX_HEADER = kordophone/KPServer.pch;

View File

@@ -7,9 +7,6 @@ sudo defaults write /Library/Preferences/com.apple.security.coderequirements Ent
Maybe a better thing to do is to DYLD_PRELOAD `imagent` and swizzle `IMDAuditTokenTaskHasEntitlement` to always return YES.
Included in the project is "kordophoned-RestrictedEntitlements.plist", which contains all necessary restricted entitlements.
On production macOS builds, the kernel will kill kordophoned immediately if it's signed using restricted entitlements, so agent hook is a
better option when running on prod machines. By default, the project is configured to ignore kordophoned-RestrictedEntitlements.plist when building.
## Building/linking
If you get dyld errors running from the command line, use `install_name_tool` to update the @rpath (where @rpath points to where linked Frameworks like GCDWebServer is).

View File

@@ -0,0 +1,17 @@
//
// MBIMAliasValidationOperation.h
// MBIMAliasValidationOperation
//
// Created by James Magahern on 7/8/21.
// Copyright © 2021 James Magahern. All rights reserved.
//
#import "MBIMBridgeOperation.h"
NS_ASSUME_NONNULL_BEGIN
@interface MBIMAliasValidationOperation : MBIMBridgeOperation
@end
NS_ASSUME_NONNULL_END

View File

@@ -0,0 +1,69 @@
//
// MBIMAliasValidationOperation.m
// MBIMAliasValidationOperation
//
// Created by James Magahern on 7/8/21.
// Copyright © 2021 James Magahern. All rights reserved.
//
#import "MBIMAliasValidationOperation.h"
#import "IMCore_ClassDump.h"
#import "IMFoundation_ClassDump.h"
@implementation MBIMAliasValidationOperation
+ (void)load { [super load]; }
+ (NSString *)endpointName
{
return @"validate";
}
- (void)main
{
NSString *address = [self valueForQueryItemWithName:@"address"];
if ([address length] == 0) {
self.serverCompletionBlock([[HTTPErrorResponse alloc] initWithErrorCode:401]);
return;
}
NSString *unformattedAddress = IMStripFormattingFromAddress(address);
BOOL isEmailAddress = IMStringIsEmail(unformattedAddress);
NSString *IDSaddress = isEmailAddress ? IDSCopyIDForEmailAddress(unformattedAddress)
: IDSCopyIDForPhoneNumber(unformattedAddress);
if (!IDSaddress) {
MBIMLogError(@"Could not get IDS address for: %@", unformattedAddress);
self.serverCompletionBlock([[HTTPErrorResponse alloc] initWithErrorCode:401]);
return;
}
__block IMChat *existingChat = nil;
dispatch_sync([[self class] sharedIMAccessQueue], ^{
IMAccount *iMessageAccount = [[IMAccountController sharedInstance] bestAccountForService:[IMServiceImpl iMessageService]];
IMHandle *handle = [iMessageAccount imHandleWithID:unformattedAddress];
if (handle) {
existingChat = [[IMChatRegistry sharedInstance] existingChatForIMHandle:handle];
}
});
IMChatCalculateServiceForSendingNewComposeMaybeForce(
@[ IDSaddress ], nil, nil, NO, isEmailAddress, YES, NO, NO, nil,
^(BOOL allAddressesiMessageCapable, NSDictionary *availabilityPerRecipient, BOOL checkedServer, NSError *error) {
NSMutableDictionary *response = [NSMutableDictionary dictionaryWithDictionary:@{
@"capable" : @(allAddressesiMessageCapable),
@"idsAddress" : IDSaddress,
}];
if ([existingChat guid]) {
[response setObject:[existingChat guid] forKey:@"existingGuid"];
}
self.serverCompletionBlock([MBIMJSONDataResponse responseWithJSONObject:response]);
});
}
@end

View File

@@ -1,17 +0,0 @@
//
// MBIMDeleteConversationOperation.h
// kordophoned
//
// Created by James Magahern on 5/25/22.
// Copyright © 2022 James Magahern. All rights reserved.
//
#import "MBIMBridgeOperation.h"
NS_ASSUME_NONNULL_BEGIN
@interface MBIMDeleteConversationOperation : MBIMBridgeOperation
@end
NS_ASSUME_NONNULL_END

View File

@@ -1,49 +0,0 @@
//
// MBIMDeleteConversationOperation.m
// kordophoned
//
// Created by James Magahern on 5/25/22.
// Copyright © 2022 James Magahern. All rights reserved.
//
#import "MBIMDeleteConversationOperation.h"
#import "IMChat+Encoded.h"
#import "IMCore_ClassDump.h"
@implementation MBIMDeleteConversationOperation
+ (void)load { [super load]; }
+ (NSString *)endpointName
{
return @"delete";
}
- (void)main
{
__block NSObject<HTTPResponse> *response = nil;
do {
NSString *guid = [self valueForQueryItemWithName:@"guid"];
if (!guid) {
MBIMLogInfo(@"No conversation GUID provided.");
response = [[HTTPErrorResponse alloc] initWithErrorCode:500];
break;
}
dispatch_sync([[self class] sharedIMAccessQueue], ^{
IMChat *chat = [[IMChatRegistry sharedInstance] existingChatWithGUID:guid];
if (!chat) {
MBIMLogInfo(@"Chat with guid: %@ not found", guid);
response = [[HTTPErrorResponse alloc] initWithErrorCode:500];
} else {
[chat remove];
}
});
response = [[HTTPErrorResponse alloc] initWithErrorCode:200];
} while (0);
self.serverCompletionBlock(response);
}
@end

View File

@@ -9,17 +9,9 @@
#import "MBIMMessagesListOperation.h"
#import "MBIMHTTPUtilities.h"
#import "IMMessageItem+Encoded.h"
#import "MBIMErrorResponse.h"
#import "IMCore_ClassDump.h"
#define kDefaultMessagesLimit 75
@interface IMChat (MBIMSafeMessagesLoading)
- (void)load:(NSUInteger)number messagesBeforeGUID:(NSString *)beforeMessageGUID;
- (void)load:(NSUInteger)number messagesAfterGUID:(NSString *)afterMessageGUID;
@end
@implementation MBIMMessagesListOperation
+ (void)load { [super load]; }
@@ -33,32 +25,11 @@
{
__block NSObject<HTTPResponse> *response = nil;
do {
// Required parameters
NSString *guid = [self valueForQueryItemWithName:@"guid"];
// Optional
NSString *limitValue = [self valueForQueryItemWithName:@"limit"];
NSDate *beforeDate = nil;
NSString *beforeDateValue = [self valueForQueryItemWithName:@"beforeDate"];
if (beforeDateValue) {
beforeDate = [beforeDateValue ISO8601Date];
if (!beforeDate) {
response = [[MBIMErrorResponse alloc] initWithErrorCode:500 message:@"Unable to decode ISO8601 beforeDate value"];
break;
}
}
NSString *beforeMessageGUID = [self valueForQueryItemWithName:@"beforeMessageGUID"];
NSString *afterMessageGUID = [self valueForQueryItemWithName:@"afterMessageGUID"];
if (beforeMessageGUID && afterMessageGUID) {
response = [[MBIMErrorResponse alloc] initWithErrorCode:500 message:@"Cannot provide both beforeMessageGUID and afterMessageGUID params."];
break;
}
if (!guid) {
response = [[MBIMErrorResponse alloc] initWithErrorCode:500 message:@"No GUID provided."];
MBIMLogInfo(@"No query item provided");
response = [[HTTPErrorResponse alloc] initWithErrorCode:500];
break;
}
@@ -70,35 +41,12 @@
response = [[HTTPErrorResponse alloc] initWithErrorCode:500];
} else {
// Load messages
// (Must be done on main queue for some reason)
dispatch_sync(dispatch_get_main_queue(), ^{
NSUInteger limit = kDefaultMessagesLimit;
if (limitValue) {
limit = [limitValue integerValue];
}
if (beforeMessageGUID) {
[chat load:limit messagesBeforeGUID:beforeMessageGUID];
} else if (afterMessageGUID) {
[chat load:limit messagesAfterGUID:afterMessageGUID];
} else {
[chat loadMessagesBeforeDate:beforeDate limit:limit loadImmediately:YES];
}
[[chat chatItems] enumerateMessagesWithOptions:0 usingBlock:^(IMMessage *message, BOOL *stop) {
// Assume "beforeMessageGUID" is exclusive
if ([[message guid] isEqual:beforeMessageGUID]) {
*stop = YES;
return;
}
// Assume "afterMessageGUID" is exclusive.
if (![[message guid] isEqual:afterMessageGUID]) {
NSDictionary *messageDict = [message mbim_dictionaryRepresentation];
[messages addObject:messageDict];
}
}];
});
[chat loadMessagesBeforeDate:[NSDate date] limit:50 loadImmediately:YES];
[[chat chatItems] enumerateMessagesWithOptions:0 usingBlock:^(IMMessage *message, BOOL *stop) {
NSDictionary *messageDict = [message mbim_dictionaryRepresentation];
[messages addObject:messageDict];
}];
}
});
@@ -109,35 +57,3 @@
}
@end
@implementation IMChat (MBIMSafeMessagesLoading)
- (id)_safe_loadMessagesBeforeAndAfterGUID:(NSString *)messagesGUID numberOfMessagesToLoadBeforeGUID:(NSUInteger)limitBefore numberOfMessagesToLoadAfterGUID:(NSUInteger)limitAfter loadImmediately:(BOOL)loadImmediately
{
if ([self respondsToSelector:@selector(loadMessagesBeforeAndAfterGUID:
numberOfMessagesToLoadBeforeGUID:
numberOfMessagesToLoadAfterGUID:
loadImmediately:threadIdentifier:)]) {
return [self loadMessagesBeforeAndAfterGUID:messagesGUID
numberOfMessagesToLoadBeforeGUID:limitBefore
numberOfMessagesToLoadAfterGUID:limitAfter
loadImmediately:YES threadIdentifier:nil];
} else {
return [self loadMessagesBeforeAndAfterGUID:messagesGUID
numberOfMessagesToLoadBeforeGUID:limitBefore
numberOfMessagesToLoadAfterGUID:limitAfter
loadImmediately:YES];
}
}
- (void)load:(NSUInteger)number messagesBeforeGUID:(NSString *)beforeMessageGUID
{
[self _safe_loadMessagesBeforeAndAfterGUID:beforeMessageGUID numberOfMessagesToLoadBeforeGUID:number numberOfMessagesToLoadAfterGUID:0 loadImmediately:YES];
}
- (void)load:(NSUInteger)number messagesAfterGUID:(NSString *)afterMessageGUID
{
[self _safe_loadMessagesBeforeAndAfterGUID:afterMessageGUID numberOfMessagesToLoadBeforeGUID:0 numberOfMessagesToLoadAfterGUID:number loadImmediately:YES];
}
@end

View File

@@ -19,40 +19,95 @@
return @"sendMessage";
}
- (BOOL)_sendMessage:(NSString *)messageBody toHandles:(NSArray<NSString *> *)handleIDs attachmentGUIDs:(NSArray<NSString *> *)guids
{
__block BOOL result = YES;
dispatch_sync([[self class] sharedIMAccessQueue], ^{
IMAccount *iMessageAccount = [[IMAccountController sharedInstance] bestAccountForService:[IMServiceImpl iMessageService]];
NSMutableArray<IMHandle *> *handles = [NSMutableArray array];
for (NSString *handleID in handleIDs) {
IMHandle *handle = [iMessageAccount imHandleWithID:handleID];
if (handle) {
[handles addObject:handle];
} else {
MBIMLogError(@"MBIMSendMessageOperation: Invalid handle ID: %@", handleID);
}
}
IMChat *chat = nil;
if (handles.count == 1) {
// Single recipient
IMHandle *handle = [handles firstObject];
chat = [[IMChatRegistry sharedInstance] existingChatForIMHandle:handle];
if (chat == nil) {
MBIMLogInfo(@"MBIMSendMessageOperation: Creating chat with handle: %@", handle);
chat = [[IMChatRegistry sharedInstance] chatForIMHandle:handle];
}
} else if (handles.count > 1) {
// Group chat
chat = [[IMChatRegistry sharedInstance] existingChatForIMHandles:handles allowRetargeting:NO groupID:nil displayName:nil joinedChatsOnly:YES];
if (chat == nil) {
MBIMLogInfo(@"MBIMSendMessageOperation: Creating group chat with handles: %@", handles);
chat = [[IMChatRegistry sharedInstance] chatForIMHandles:handles];
}
} else {
// No handles?
result = NO;
}
if (chat) {
result = [self _sendMessage:messageBody toChat:chat attachmentGUIDs:guids];
} else {
result = NO;
}
});
return result;
}
- (BOOL)_sendMessage:(NSString *)messageBody toChatWithGUID:(NSString *)chatGUID attachmentGUIDs:(NSArray<NSString *> *)guids
{
__block BOOL result = YES;
dispatch_sync([[self class] sharedIMAccessQueue], ^{
IMChat *chat = [[IMChatRegistry sharedInstance] existingChatWithGUID:chatGUID];
// TODO: chat might not be an iMessage chat!
IMAccount *iMessageAccount = [[IMAccountController sharedInstance] bestAccountForService:[IMServiceImpl iMessageService]];
IMHandle *senderHandle = [iMessageAccount loginIMHandle];
NSAttributedString *replyAttrString = [[NSAttributedString alloc] initWithString:messageBody];
NSAttributedString *attrStringWithFileTransfers = IMCreateSuperFormatStringWithAppendedFileTransfers(replyAttrString, guids);
IMMessage *reply = [IMMessage fromMeIMHandle:senderHandle
withText:attrStringWithFileTransfers
fileTransferGUIDs:guids
flags:(kIMMessageFinished | kIMMessageIsFromMe)];
for (NSString *guid in [reply fileTransferGUIDs]) {
[[IMFileTransferCenter sharedInstance] assignTransfer:guid toHandle:chat.recipient];
}
if (!chat) {
MBIMLogInfo(@"Chat does not exist: %@", chatGUID);
result = NO;
} else {
[chat sendMessage:reply];
result = [self _sendMessage:messageBody toChat:chat attachmentGUIDs:guids];
}
});
return result;
}
- (BOOL)_sendMessage:(NSString *)messageBody toChat:(IMChat *)chat attachmentGUIDs:(NSArray<NSString *> *)guids
{
dispatch_assert_queue([[self class] sharedIMAccessQueue]);
BOOL result = YES;
// TODO: chat might not be an iMessage chat!
IMAccount *iMessageAccount = [[IMAccountController sharedInstance] bestAccountForService:[IMServiceImpl iMessageService]];
IMHandle *senderHandle = [iMessageAccount loginIMHandle];
NSAttributedString *replyAttrString = [[NSAttributedString alloc] initWithString:messageBody];
NSAttributedString *attrStringWithFileTransfers = IMCreateSuperFormatStringWithAppendedFileTransfers(replyAttrString, guids);
IMMessage *reply = [IMMessage fromMeIMHandle:senderHandle
withText:attrStringWithFileTransfers
fileTransferGUIDs:guids
flags:(kIMMessageFinished | kIMMessageIsFromMe)];
for (NSString *guid in [reply fileTransferGUIDs]) {
[[IMFileTransferCenter sharedInstance] assignTransfer:guid toHandle:chat.recipient];
}
[chat sendMessage:reply];
return result;
}
- (void)main
{
NSObject<HTTPResponse> *response = [[HTTPErrorResponse alloc] initWithErrorCode:500];
@@ -64,9 +119,8 @@
return;
}
NSString *guid = [args objectForKey:@"guid"];
NSString *messageBody = [args objectForKey:@"body"];
if (!guid || !messageBody) {
if (!messageBody) {
self.serverCompletionBlock(response);
return;
}
@@ -76,7 +130,15 @@
transferGUIDs = @[];
}
BOOL result = [self _sendMessage:messageBody toChatWithGUID:guid attachmentGUIDs:transferGUIDs];
BOOL result = NO;
NSString *guid = [args objectForKey:@"guid"];
NSArray<NSString *> *handles = [args objectForKey:@"handles"];
if (guid) {
result = [self _sendMessage:messageBody toChatWithGUID:guid attachmentGUIDs:transferGUIDs];
} else if ([handles count] > 0) {
result = [self _sendMessage:messageBody toHandles:handles attachmentGUIDs:transferGUIDs];
}
if (result) {
response = [[HTTPErrorResponse alloc] initWithErrorCode:200];
}

View File

@@ -1,17 +0,0 @@
//
// MBIMStatusOperation.h
// kordophoned
//
// Created by James Magahern on 8/3/22.
// Copyright © 2022 James Magahern. All rights reserved.
//
#import "MBIMBridgeOperation.h"
NS_ASSUME_NONNULL_BEGIN
@interface MBIMStatusOperation : MBIMBridgeOperation
@end
NS_ASSUME_NONNULL_END

View File

@@ -1,25 +0,0 @@
//
// MBIMStatusOperation.m
// kordophoned
//
// Created by James Magahern on 8/3/22.
// Copyright © 2022 James Magahern. All rights reserved.
//
#import "MBIMStatusOperation.h"
@implementation MBIMStatusOperation
+ (void)load { [super load]; }
+ (NSString *)endpointName
{
return @"status";
}
- (void)main
{
self.serverCompletionBlock([[MBIMDataResponse alloc] initWithData:[@"OK" dataUsingEncoding:NSUTF8StringEncoding]]);
}
@end

View File

@@ -1,17 +0,0 @@
//
// MBIMVersionOperation.h
// kordophoned
//
// Created by James Magahern on 8/3/22.
// Copyright © 2022 James Magahern. All rights reserved.
//
#import "MBIMBridgeOperation.h"
NS_ASSUME_NONNULL_BEGIN
@interface MBIMVersionOperation : MBIMBridgeOperation
@end
NS_ASSUME_NONNULL_END

View File

@@ -1,35 +0,0 @@
//
// MBIMVersionOperation.m
// kordophoned
//
// Created by James Magahern on 8/3/22.
// Copyright © 2022 James Magahern. All rights reserved.
//
#import "MBIMVersionOperation.h"
#import "MBIMErrorResponse.h"
#ifdef __clang_analyzer__
const char* MBIMVersion() {
return "UNKNOWN";
}
#else
#import "MBIMVersion.c"
#endif
@implementation MBIMVersionOperation
+ (void)load { [super load]; }
+ (NSString *)endpointName
{
return @"version";
}
- (void)main
{
NSString *versionString = [NSString stringWithUTF8String:MBIMVersion()];
self.serverCompletionBlock([[MBIMDataResponse alloc] initWithData:[versionString dataUsingEncoding:NSUTF8StringEncoding]]);
}
@end

View File

@@ -19,9 +19,7 @@
if (self) {
_contentType = contentType;
_httpHeaders = [@{
@"Content-Type" : _contentType ?: @"application/octet-stream",
@"Access-Control-Allow-Origin" : @"*", // CORS
@"Access-Control-Allow-Credentials" : @"true"
@"Content-Type" : _contentType ?: @"application/octet-stream"
} mutableCopy];
}

View File

@@ -1,18 +0,0 @@
//
// MBIMErrorResponse.h
// kordophoned
//
// Created by James Magahern on 8/3/22.
// Copyright © 2022 James Magahern. All rights reserved.
//
#import "HTTPDataResponse.h"
NS_ASSUME_NONNULL_BEGIN
@interface MBIMErrorResponse : HTTPDataResponse
- (instancetype)initWithErrorCode:(int)httpErrorCode;
- (instancetype)initWithErrorCode:(int)httpErrorCode message:(NSString *)message;
@end
NS_ASSUME_NONNULL_END

View File

@@ -1,38 +0,0 @@
//
// MBIMErrorResponse.m
// kordophoned
//
// Created by James Magahern on 8/3/22.
// Copyright © 2022 James Magahern. All rights reserved.
//
#import "MBIMErrorResponse.h"
@implementation MBIMErrorResponse {
int _status;
}
- (instancetype)initWithErrorCode:(int)httpErrorCode
{
if (self = [super initWithData:nil]) {
_status = httpErrorCode;
}
return self;
}
- (instancetype)initWithErrorCode:(int)httpErrorCode message:(NSString *)message
{
if (self = [super initWithData:[message dataUsingEncoding:NSUTF8StringEncoding]]) {
_status = httpErrorCode;
}
return self;
}
- (NSInteger)status
{
return _status;
}
@end

View File

@@ -10,13 +10,3 @@
NSString* MBIMWebServerFormatRFC822(NSDate *date);
NSString* MBIMWebServerFormatISO8601(NSDate *date);
@interface NSDate (MBIMWebServerFormat)
- (NSString *)RFC822StringValue;
- (NSString *)ISO8601StringValue;
@end
@interface NSString (MBIMWebServerFormat)
- (NSDate *)RFC822Date;
- (NSDate *)ISO8601Date;
@end

View File

@@ -47,31 +47,3 @@ NSString* MBIMWebServerFormatISO8601(NSDate *date)
return string;
}
@implementation NSDate (MBIMWebServerFormat)
- (NSString *)RFC822StringValue
{
return MBIMWebServerFormatRFC822(self);
}
- (NSString *)ISO8601StringValue
{
return MBIMWebServerFormatISO8601(self);
}
@end
@implementation NSString (MBIMWebServerFormat)
- (NSDate *)RFC822Date
{
return [_dateFormatterRFC822 dateFromString:self];
}
- (NSDate *)ISO8601Date
{
return [_dateFormatterISO8601 dateFromString:self];
}
@end

View File

@@ -1,16 +0,0 @@
<?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>com.apple.imagent</key>
<true/>
<key>com.apple.private.imagent</key>
<true/>
<key>com.apple.private.imcore.imagent</key>
<true/>
<key>com.apple.imagent.av</key>
<true/>
<key>com.apple.imagent.chat</key>
<true/>
</dict>
</plist>

View File

@@ -10,7 +10,7 @@
#import "MBIMBridge.h"
void printUsage()
static void printUsage(void)
{
fprintf(stderr, "Usage: kordophoned [-h] [-s | -c (certificate.p12)] [-a (access control file)\n");
fprintf(stderr, "\t-h \t Show this help message\n");