-
Notifications
You must be signed in to change notification settings - Fork 494
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
123 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
HowTo -- Helpful Stuff | ||
====================== | ||
|
||
My main resource for reverse engineering UICollection is [https://github.com/steipete/iOS6-Runtime-Headers](https://github.com/steipete/iOS6-Runtime-Headers). | ||
|
||
// For debugging purposes only | ||
``` objective-c | ||
#ifdef DEBUG | ||
NSString *_PSPDFPrintIvars(id obj, NSMutableSet *recursiveSet); | ||
void PSPDFPrintIvars(id obj, BOOL printRecursive) { | ||
NSString *ivarString = _PSPDFPrintIvars(obj, printRecursive ? [NSMutableSet set] : nil); | ||
NSLog(@"%@", ivarString); | ||
} | ||
|
||
NSMutableDictionary *_PSDPFConvertIvarsToDictionary(Class class, id obj); | ||
NSMutableDictionary *_PSDPFConvertIvarsToDictionary(Class class, id obj) { | ||
NSMutableDictionary *dict = [NSMutableDictionary dictionary]; | ||
unsigned int ivarCount; | ||
Ivar *ivars = class_copyIvarList(class, &ivarCount); | ||
for (int i = 0; i < ivarCount; i++) { | ||
NSString *name = @(ivar_getName(ivars[i])); | ||
id value; | ||
@try { value = [obj valueForKey:name]; } | ||
@catch (NSException *exception) { | ||
value = [exception reason]; | ||
} | ||
value = value ?: [NSNull null]; | ||
[dict setObject:value forKey:name]; | ||
} | ||
free(ivars); | ||
return dict; | ||
} | ||
|
||
NSString *_PSPDFPrintIvars(id obj, NSMutableSet *recursiveSet) { | ||
NSMutableString *string = [NSMutableString string]; | ||
[recursiveSet addObject:obj]; | ||
|
||
// query ivar list | ||
NSMutableSet *ivarDictionaries = [NSMutableSet set]; | ||
NSMutableDictionary *dict = _PSDPFConvertIvarsToDictionary([obj class], obj); | ||
Class superClass = class_getSuperclass([obj class]); | ||
while(superClass && ![superClass isEqual:[NSObject class]]) { | ||
NSDictionary *superClassIvarDict = _PSDPFConvertIvarsToDictionary(superClass, obj); | ||
if ([superClassIvarDict count]) { | ||
dict[NSStringFromClass(superClass)] = superClassIvarDict; | ||
|
||
if ([NSStringFromClass(superClass) hasPrefix:@"UICollection"] || [NSStringFromClass(superClass) hasPrefix:@"_UI"]) { | ||
[ivarDictionaries addObject:superClassIvarDict]; | ||
} | ||
} | ||
superClass = class_getSuperclass(superClass); | ||
} | ||
if ([dict count]) { | ||
[string appendFormat:@"<%@= %@>", NSStringFromClass([obj class]), [dict description]]; | ||
} | ||
// dig deeper if recursive is enabled | ||
if (recursiveSet) { | ||
[dict enumerateKeysAndObjectsUsingBlock:^(id key, id dictObj, BOOL *stop) { | ||
if ([ivarDictionaries containsObject:dictObj]) { | ||
[dictObj enumerateKeysAndObjectsUsingBlock:^(id key, id dictObj, BOOL *stop) { | ||
|
||
if (![recursiveSet containsObject:dictObj] && (![dictObj isKindOfClass:[NSDictionary class]] || [dictObj count] > 0) && ![dictObj isKindOfClass:[NSSet set]] && ![dictObj isKindOfClass:NSClassFromString(@"NSConcreteValue")]) { | ||
if ([[dictObj class] conformsToProtocol:@protocol(NSFastEnumeration)]) { | ||
for (id anObj in dictObj) { | ||
[string appendString:_PSPDFPrintIvars(anObj, recursiveSet)]; | ||
} | ||
}else { | ||
[string appendString:_PSPDFPrintIvars(dictObj, recursiveSet)]; | ||
} | ||
} | ||
}]; | ||
}else { | ||
if (![recursiveSet containsObject:dictObj] && (![dictObj isKindOfClass:[NSDictionary class]] || [dictObj count] > 0) && ![dictObj isKindOfClass:[NSSet set]] && ![dictObj isKindOfClass:NSClassFromString(@"NSConcreteValue")]) { | ||
if ([[dictObj class] conformsToProtocol:@protocol(NSFastEnumeration)]) { | ||
for (id anObj in dictObj) { | ||
[string appendString:_PSPDFPrintIvars(anObj, recursiveSet)]; | ||
} | ||
}else { | ||
[string appendString:_PSPDFPrintIvars(dictObj, recursiveSet)]; | ||
} | ||
} | ||
} | ||
}]; | ||
} | ||
|
||
// custom stuff (e.g. get a id * variable that's not KVO compliant) | ||
if([NSStringFromClass([obj class]) isEqualToString:@"UICollectionViewData"]) { | ||
id *outvalue; | ||
object_getInstanceVariable(obj, "_globalItems", (void **)&outvalue); | ||
NSLog(@"done"); | ||
} | ||
return string; | ||
} | ||
#endif | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
Copyright (c) 2012 Peter Steinberger <steipete@gmail.com> | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is furnished | ||
to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters