Skip to content

Instantly share code, notes, and snippets.

@lukele
Created January 16, 2017 22:18
Show Gist options
  • Save lukele/1cfbcf20c926030db9999b3e83602532 to your computer and use it in GitHub Desktop.
Save lukele/1cfbcf20c926030db9999b3e83602532 to your computer and use it in GitHub Desktop.
appendDataForMimePart:toData:withPartData:
char -[MCMessageGenerator appendDataForMimePart:toData:withPartData:](void * self, void * _cmd, void * arg2, void * arg3, void * arg4) {
rsi = _cmd;
var_40 = self;
r15 = _objc_retain;
r12 = [arg2 retain];
var_48 = [arg3 retain];
r14 = [arg4 retain];
r15 = _objc_msgSend;
rbx = [[r14 objectForKey:r12] retain];
if ([rbx isKindOfClass:[MCMimePart class]] != 0x0) {
var_30 = rbx;
r13 = [rbx retain];
rdi = r12;
r12 = _objc_release;
rax = [rdi release];
var_60 = r14;
r14 = [r14 objectForKey:r13];
rax = [r13 release];
rbx = [r14 retain];
r12 = var_30;
}
else {
var_60 = r14;
}
r14 = var_48;
if (rbx != 0x0) {
r15 = _objc_msgSend;
rax = [r14 length];
rax = [rbx length];
rax = [r14 appendData:rbx];
}
r15 = _objc_msgSend;
var_78 = rbx;
var_70 = @"multipart";
rbx = [r12 isType:@"multipart" subtype:0x0];
rcx = [[r12 firstChildPart] retain];
r15 = 0x1;
r13 = var_60;
if ((rbx != 0x0) || (rcx != 0x0)) goto loc_48a08;
loc_48d82:
rbx = _objc_release;
rax = [var_78 release];
rax = [r13 release];
rax = [r14 release];
rax = [r12 release];
rax = r15 & 0xff;
rbx = stack[2042];
r12 = stack[2043];
r13 = stack[2044];
r14 = stack[2045];
r15 = stack[2046];
rsp = rsp + 0x98;
rbp = stack[2047];
return rax;
loc_48a08:
rax = 0x0;
var_30 = rax;
if (rbx != 0x0) {
rbx = _objc_msgSend;
r14 = [[r12 bodyParameterForKey:@"boundary"] retain];
var_30 = [[r14 dataUsingEncoding:0x1 allowLossyConversion:0x1] retain];
rax = [r14 release];
rcx = rcx;
}
var_80 = r12;
if (rcx == 0x0) goto loc_48cff;
loc_48a7b:
var_68 = rax;
goto loc_48a7f;
loc_48a7f:
var_38 = rcx;
rdx = rcx;
r14 = [[r13 objectForKey:rdx] retain];
r12 = _objc_msgSend;
if (r14 != 0x0) {
r12 = _objc_msgSend;
if ([r14 isKindOfClass:[MCMimePart class]] == 0x0) {
rbx = [var_38 retain];
rax = [r14 release];
r14 = rbx;
}
}
else {
rbx = [var_38 retain];
rax = [r14 release];
r14 = rbx;
}
rbx = var_30;
r15 = var_48;
if (rbx == 0x0) goto loc_48c6a;
loc_48afc:
r12 = _objc_msgSend;
var_50 = [MCMutableMessageHeaders new];
rax = [r15 appendCString:"\n--"];
rax = [r15 appendData:rbx];
rax = [r15 appendBytes:"\n" length:0x1];
if ([r14 isType:@"multipart" subtype:0x0] != 0x0) goto loc_48c05;
loc_48b6c:
rdx = r14;
rax = [var_60 objectForKey:rdx];
rax = [rax retain];
if (rax == 0x0) goto loc_48b92;
loc_48b8d:
rdi = rax;
goto loc_48bff;
loc_48bff:
rax = [rdi release];
goto loc_48c05;
loc_48c05:
r12 = _objc_msgSend;
rax = [var_40 _appendHeadersForMimePart:r14 toHeaders:var_50];
rbx = [[var_50 encodedHeadersIncludingFromSpace:0x0, var_50] retain];
r14 = r14;
rax = [r15 appendData:rbx, var_50];
rdi = rbx;
rbx = _objc_release;
rax = [rdi release];
rax = [var_50 release];
r13 = var_60;
rbx = var_30;
goto loc_48c6a;
loc_48c6a:
if ([var_40 appendDataForMimePart:r14 toData:r15 withPartData:r13] == 0x0) goto loc_48d5a;
loc_48c8c:
r15 = r13;
r13 = 0x0;
var_30 = rbx;
rdi = 0x0;
r12 = var_38;
if (rbx != 0x0) {
rax = [r12 nextSiblingPart];
rax = [rax retain];
var_68 = rax;
r13 = 0x1;
rdi = rax;
}
rbx = [rdi retain];
rax = [r12 release];
if (r13 != 0x0) {
rax = [var_68 release];
}
rax = [r14 release];
rcx = rbx;
r13 = r15;
if (rbx != 0x0) goto loc_48a7f;
loc_48cff:
r12 = var_30;
r14 = var_48;
rbx = _objc_msgSend;
if (r12 != 0x0) {
rbx = _objc_msgSend;
rax = [r14 appendCString:"\n--"];
rax = [r14 appendData:r12];
rax = [r14 appendCString:"--\n"];
}
rax = [r12 release];
r12 = var_80;
r15 = 0x1;
goto loc_48d82;
loc_48d5a:
rdi = r14;
r14 = _objc_release;
rax = [rdi release];
rax = [rbx release];
rax = [var_38 release];
r14 = var_48;
r15 = 0x0;
r12 = var_80;
goto loc_48d82;
loc_48b92:
rax = [r14 range];
if (rdx == 0x0) goto loc_48c05;
loc_48ba7:
r12 = _objc_msgSend;
rbx = [NSString alloc];
rax = [r14 range];
rax = 0x0;
rbx = [rbx initWithFormat:@"%lu", rdx];
rax = [var_50 setHeader:rbx forKey:@"x-apple-content-length"];
rdi = rbx;
goto loc_48bff;
}
- (BOOL)MAAppendDataForMimePart:(id)mimePart toData:(NSMutableData *)messageData withPartData:(NSMapTable *)partData {
// BOOL ret = [self MAAppendDataForMimePart:mimePart toData:messageData withPartData:partData];
// return ret;
// arg2 == r13 == mimePart
// arg4 == partData
// arg3 == var_80 == toData
id mimePartOrDataForMimePart = [partData objectForKey:mimePart];
NSData *dataForMimePart = mimePartOrDataForMimePart;
if([mimePartOrDataForMimePart isKindOfClass:[MCMimePart class]]) {
mimePart = mimePartOrDataForMimePart;
dataForMimePart = [partData objectForKey:dataForMimePart];
}
if(dataForMimePart) {
[messageData appendData:dataForMimePart];
}
BOOL isMultipart = [mimePart isType:@"multipart" subtype:nil];
MCMimePart *firstChildPart = [mimePart firstChildPart];
BOOL success = YES;
if(isMultipart || firstChildPart) {
NSData *boundaryData = nil;
if(isMultipart) {
NSString *boundary = [mimePart bodyParameterForKey:@"boundary"];
boundaryData = [boundary dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
if(!firstChildPart) {
success = YES;
if(boundaryData) {
[messageData appendCString:"\n--"];
[messageData appendData:boundaryData];
[messageData appendCString:"--\n"];
// r13 = var_E0;
// r14 = var_E8; is currently dataForMimePart I believe.
return success;
}
}
else {
// var40 == firstChildPart
id firstChildDataOrMimePart = [partData objectForKey:firstChildPart];
if(!firstChildDataOrMimePart || ![firstChildDataOrMimePart isKindOfClass:[MCMimePart class]]) {
firstChildDataOrMimePart = firstChildPart;
}
if(boundaryData) {
MCMutableMessageHeaders *messageHeaders = [MCMutableMessageHeaders new];
[messageData appendCString:"\n--"];
[messageData appendData:boundaryData];
[messageData appendBytes:"\n" length:1];
NSInteger bodyDataLength = [firstChildDataOrMimePart encodedBodyDataLength];
if(![firstChildDataOrMimePart isType:@"multipart" subtype:nil]) {
NSData *bodyData = [partData objectForKey:firstChildDataOrMimePart];
if(bodyDataLength != 0 && !bodyData) {
NSString *contentLength = [[NSString alloc] initWithFormat:@"%lu", bodyDataLength];
[messageHeaders setHeader:contentLength forKey:@"x-apple-content-length"];
}
}
[mailself _appendHeadersForMimePart:firstChildDataOrMimePart toHeaders:messageHeaders];
NSData *encodedHeaders = [messageHeaders encodedHeadersIncludingFromSpace:NO];
[messageData appendData:encodedHeaders];
}
success = [mailself appendDataForMimePart:firstChildDataOrMimePart toData:messageData withPartData:partData];
if(!success)
return NO;
MCMimePart *nextSiblingPart = nil;
if(boundaryData) {
nextSiblingPart = [firstChildPart nextSiblingPart];
success = YES;
}
if(nextSiblingPart) {
firstChildPart = nextSiblingPart;
firstChildDataOrMimePart = [partData objectForKey:firstChildPart];
if(!firstChildDataOrMimePart || ![firstChildDataOrMimePart isKindOfClass:[MCMimePart class]]) {
firstChildDataOrMimePart = firstChildPart;
}
if(boundaryData) {
MCMutableMessageHeaders *messageHeaders = [MCMutableMessageHeaders new];
[messageData appendCString:"\n--"];
[messageData appendData:boundaryData];
[messageData appendBytes:"\n" length:1];
NSInteger bodyDataLength = [firstChildDataOrMimePart encodedBodyDataLength];
if(![firstChildDataOrMimePart isType:@"multipart" subtype:nil]) {
NSData *bodyData = [partData objectForKey:firstChildDataOrMimePart];
if(bodyDataLength != 0 && !bodyData) {
NSString *contentLength = [[NSString alloc] initWithFormat:@"%lu", bodyDataLength];
[messageHeaders setHeader:contentLength forKey:@"x-apple-content-length"];
}
}
[mailself _appendHeadersForMimePart:firstChildDataOrMimePart toHeaders:messageHeaders];
NSData *encodedHeaders = [messageHeaders encodedHeadersIncludingFromSpace:NO];
[messageData appendData:encodedHeaders];
}
success = [mailself appendDataForMimePart:firstChildDataOrMimePart toData:messageData withPartData:partData];
if(!success)
return NO;
if(boundaryData) {
nextSiblingPart = [firstChildPart nextSiblingPart];
success = YES;
}
if(!nextSiblingPart) {
success = YES;
if(boundaryData) {
[messageData appendCString:"\n--"];
[messageData appendData:boundaryData];
[messageData appendCString:"--\n"];
}
return success;
}
}
}
}
}
return success;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment