Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,10 @@
#import <UIFoundation/NSWordMLReader.h>
#import <UIFoundation/NSWordMLWriter.h>

extern const char *UIArchiveHeaderIdentifier;
extern const uint32_t UIMaximumCompatibleFormatVersion;
extern const uint32_t UICurrentCoderVersion;

void* CFArrayCreateWithNonRetainedObjectsFromNSArray(void);
void* CFDictionaryCreateWithNonRetainedValuesFromNSDictionary(void);
void* NSConvertGlyphsToPackedGlyphs(void);
Expand All @@ -150,7 +154,7 @@ void* UIAppendBytesForValueToData(void);
void* UIAppendVInt32ToData(void);
void* UIArrayByKeepingObjectsInSet(void);
void* UICreateOrderedAndStrippedCoderValues(void);
void* UIDataLooksLikeNibArchive(void);
BOOL UIDataLooksLikeNibArchive(NSData *data);
void* UIDistanceBetweenPointAndRect(void);
void* UIFixedByteLengthForType(void);
void* UINibArchiveIndexFromNumber(void);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@

#include <Foundation/Foundation.h>

@interface UINibDecoder : NSObject
@interface UINibDecoder : NSCoder

- (instancetype) initForReadingWithData: (NSData *) data;

@end
30 changes: 26 additions & 4 deletions src/private-frameworks/UIFoundation/src/UIFoundation.m
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,14 @@
along with Darling. If not, see <http://www.gnu.org/licenses/>.
*/


#include <UIFoundation/UIFoundation.h>
#include <stdlib.h>
#include <stdio.h>

const char *UIArchiveHeaderIdentifier = "NIBArchive";
const uint32_t UIMaximumCompatibleFormatVersion = 1;
const uint32_t UICurrentCoderVersion = 10;

static int verbose = 0;

__attribute__((constructor))
Expand Down Expand Up @@ -95,10 +98,29 @@ static void initme(void) {
return NULL;
}

void* UIDataLooksLikeNibArchive(void)
BOOL UIDataLooksLikeNibArchive(NSData *data)
{
if (verbose) puts("STUB: UIDataLooksLikeNibArchive called");
return NULL;
char headerIdentifier[11];
[data getBytes: headerIdentifier length: 10];
headerIdentifier[10] = '\0';

if (strcmp(headerIdentifier, UIArchiveHeaderIdentifier) != 0) {
return FALSE;
}

const uint32_t formatVersion = *((uint32_t *)[[data subdataWithRange: NSMakeRange(10, sizeof(uint32_t))] bytes]);

if (formatVersion > UIMaximumCompatibleFormatVersion) {
return FALSE;
}

const uint32_t coderVersion = *((uint32_t *)[[data subdataWithRange: NSMakeRange(14, sizeof(uint32_t))] bytes]);

if (coderVersion != UICurrentCoderVersion) {
return FALSE;
}

return TRUE;
}

void* UIDistanceBetweenPointAndRect(void)
Expand Down
75 changes: 71 additions & 4 deletions src/private-frameworks/UIFoundation/src/UINibDecoder.m
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,81 @@

@implementation UINibDecoder

- (NSMethodSignature *)methodSignatureForSelector:(SEL)aSelector
- (instancetype) initForReadingWithData: (NSData *) data
{
return [NSMethodSignature signatureWithObjCTypes: "v@:"];
printf("STUB %s\n", __PRETTY_FUNCTION__);
return self;
}

- (void)forwardInvocation:(NSInvocation *)anInvocation
- (BOOL) containsValueForKey: (NSString *) key
{
NSLog(@"Stub called: %@ in %@", NSStringFromSelector([anInvocation selector]), [self class]);
printf("STUB %s\n", __PRETTY_FUNCTION__);
return NO;
}

- (void) decodeValueOfObjCType: (const char *) type at: (void *) data
{
printf("STUB %s\n", __PRETTY_FUNCTION__);
}

- (NSData *) decodeDataObject
{
printf("STUB %s\n", __PRETTY_FUNCTION__);
return nil;
}

- (id) decodeObjectForKey: (NSString *) key
{
printf("STUB %s\n", __PRETTY_FUNCTION__);
return nil;
}

- (BOOL) decodeBoolForKey: (NSString *) key
{
printf("STUB %s\n", __PRETTY_FUNCTION__);
return NO;
}

- (int) decodeIntForKey:(NSString *) key
{
printf("STUB %s\n", __PRETTY_FUNCTION__);
return 0;
}

- (int32_t) decodeInt32ForKey:(NSString *) key
{
printf("STUB %s\n", __PRETTY_FUNCTION__);
return 0;
}

- (int64_t) decodeInt64ForKey:(NSString *) key
{
printf("STUB %s\n", __PRETTY_FUNCTION__);
return 0;
}

- (float) decodeFloatForKey:(NSString *) key
{
printf("STUB %s\n", __PRETTY_FUNCTION__);
return 0.0f;
}

- (double) decodeDoubleForKey:(NSString *) key
{
printf("STUB %s\n", __PRETTY_FUNCTION__);
return 0.0;
}

- (const uint8_t *) decodeBytesForKey: (NSString *) key returnedLength: (NSUInteger *) len
{
printf("STUB %s\n", __PRETTY_FUNCTION__);
return NULL;
}

- (NSInteger) versionForClassName: (NSString *) className
{
printf("STUB %s\n", __PRETTY_FUNCTION__);
return 0;
}

@end