Skip to content
This repository has been archived by the owner on Nov 22, 2022. It is now read-only.

Commit

Permalink
SigDB. Memory Leak
Browse files Browse the repository at this point in the history
  • Loading branch information
Naville committed Mar 4, 2016
1 parent 13ec75a commit 7bdf270
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 15 deletions.
2 changes: 1 addition & 1 deletion Hooks/APIHooks/libMobileGestalt.xm
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ static void MobileGestaltdyldCallBack(const struct mach_header* mh, intptr_t vma
MSHookFunction(((void*)MSFindSymbol(NULL, "_MGSetAnswer")),(void*)MGSetAnswer, (void**)&old_MGSetAnswer);

}

[name release];
}


Expand Down
4 changes: 2 additions & 2 deletions Hooks/Utils/RuntimeUtils.m
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ +(NSMutableDictionary*)propertyListForClass:(NSString*)className{
}

free(properties);
NSLog(@"Properties %@",returnDictionary);
//NSLog(@"Properties %@",returnDictionary);
return returnDictionary;
}
+(NSMutableDictionary*)ivarForClass:(NSString*)className{
Expand All @@ -57,7 +57,7 @@ +(NSMutableDictionary*)ivarForClass:(NSString*)className{
Ivar currentIvar=IvarList[i];
NSString* IvarName=[NSString stringWithFormat:@"%s",ivar_getName(currentIvar)];
NSString* IvarOffset=[NSString stringWithFormat:@"%lu",(unsigned long)ivar_getOffset(currentIvar)];
NSLog(@"Pffset:%@",IvarOffset);
//NSLog(@"Offset:%@",IvarOffset);
NSDictionary* ivarInfoDict=[NSDictionary dictionaryWithObjectsAndKeys:IvarName,@"Name", IvarOffset,@"Offset",[NSString stringWithUTF8String:ivar_getTypeEncoding(currentIvar)],@"TypeEncoding",nil];
//NSLog(@"iVARinfo:%@",ivarInfoDict);
[returnDict setObject:ivarInfoDict forKey:[NSString stringWithUTF8String:ivar_getName(currentIvar)]];
Expand Down
2 changes: 1 addition & 1 deletion Hooks/Utils/Utils.h
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#import "RuntimeUtils.h"
#import "../SharedDefine.pch"
@interface Utils : NSObject {

}
+(id)sharedManager;
+(NSMutableArray*)classListForSelector:(SEL)Selector;
#ifdef PROTOTYPE
-(NSArray*)possibleClassNameFromSignature:(NSString*)className;
#endif
@property(nonatomic,strong) NSDictionary *signatureDatabase;
@property(nonatomic,strong) NSNumber* MinimumMatchConfidence;
@end
65 changes: 57 additions & 8 deletions Hooks/Utils/Utils.m
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
#import "Utils.h"
#define TotalIvarScore 0.2
#define SuperClassNameMatch 0.2
#define IvarOffsetMatch 0.2
#define IvarTypeEncodingMatch 0.4
#define IvarNameMatch 0.6
@implementation Utils : NSObject
+(id)sharedManager{
static Utils *sharedUtils = nil;
Expand Down Expand Up @@ -37,19 +42,63 @@ +(NSMutableArray*)classListForSelector:(SEL)Selector{
}
#ifdef PROTOTYPE
-(NSArray*)possibleClassNameFromSignature:(NSString*)className{
NSMutableDictionary* MatchedIvarDatabase=[NSMutableDictionary dictionary];

NSMutableDictionary* propDict=[RuntimeUtils propertyListForClass:className];
NSMutableDictionary* methodDict=[RuntimeUtils methodsForClass:className];
NSMutableDictionary* ivarDict=[RuntimeUtils ivarForClass:className];
NSMutableDictionary* protoDict=[RuntimeUtils protocalForClass:className];
for(id key in self.signatureDatabase){
NSString* SuperClass=[NSString stringWithFormat:@"%s",class_getName(class_getSuperclass(objc_getClass(className.UTF8String)))];
for(id key in self.signatureDatabase.allKeys){
NSDictionary* currentSig=[self.signatureDatabase objectForKey:key];
//double Confidence=0.00;
/*
We Use A Mark Based Algorithm To Measure Confidence
Super Class:10%
Protocals:15%
Methods,Properties,IVARS:25% EACH
*/
double Confidence=0.00;
if [[currentSig objectForKey:@"SuperClass"] isEqualToString:SuperClass]{//Superclass Compare
Confidence=Confidence+0.1;
}
double FullMatchScoreForIvar=TotalIvarScore/ivarDict.allKeys.count;
for(id IvarKey in ivarDict.allKeys){//IVAR Names. a.k.a. Keys
NSDictionary* RecordInDB=[[currentSig objectForKey:@"Ivar"] objectForKey:IvarKey];
if (RecordInDB!=nil){//Name Match. Matching Signatures
if([[RecordInDB objectForKey:@"Offset"] isEqualToString:[[ivarDict objectForKey:IvarKey] objectForKey:@"Offset"]){
Confidence=Confidence+FullMatchScoreForIvar*IvarOffsetMatch;
}
if([[RecordInDB objectForKey:@"TypeEncoding"] isEqualToString:[[ivarDict objectForKey:IvarKey] objectForKey:@"TypeEncoding"]){
Confidence=Confidence+FullMatchScoreForIvar*IvarTypeEncodingMatch;
}
if([[RecordInDB objectForKey:@"Name"] isEqualToString:[[ivarDict objectForKey:IvarKey] objectForKey:@"Name"]){
Confidence=Confidence+FullMatchScoreForIvar*IvarNameMatch;
}

}
else{
//Name Didn't Match. Iterate All Records
for (NSString* SigName in [[currentSig objectForKey:@"Ivar"] allKeys]){
NSDictionary* RecordInDB=[[currentSig objectForKey:@"Ivar"] objectForKey:SigName];//One Record in DB
if([[RecordInDB objectForKey:@"Offset"] isEqualToString:[[ivarDict objectForKey:IvarKey] objectForKey:@"Offset"]){
Confidence=Confidence+FullMatchScoreForIvar*IvarOffsetMatch;
}
if([[RecordInDB objectForKey:@"TypeEncoding"] isEqualToString:[[ivarDict objectForKey:IvarKey] objectForKey:@"TypeEncoding"]){
Confidence=Confidence+FullMatchScoreForIvar*IvarTypeEncodingMatch;
}
if([[RecordInDB objectForKey:@"Name"] isEqualToString:[[ivarDict objectForKey:IvarKey] objectForKey:@"Name"]){
Confidence=Confidence+FullMatchScoreForIvar*IvarNameMatch;
}
if(Confidence>self.MinimumMatchConfidence.intValue){
NSArray* oldArray=[MatchedIvarDatabase objectForKey:[ivarDict objectForKey:IvarKey]];//Key is IVAR Name in Binary
[oldArray addObject:[RecordInDB objectForKey:@"Name"]];//Add current Match
[MatchedDatabase setObject:oldArray forKey:[ivarDict objectForKey:IvarKey]];
//Add This To MatchedDatabase

}

}


}
//Insert Other matches Here

}


[currentSig release];
}
Expand Down
6 changes: 4 additions & 2 deletions SignatureDatabase.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
>>Methods:25%:
>>Properties:20%
>>Properties:25%
>>IVARS:20%
Expand All @@ -23,6 +23,8 @@
>>>>For Each Complete Match. 35%/9 is rewarded. Please Note That The Number Of Subject is Used instead of number in database.
>>>>TypeCoding Match:40% ReturnTypeMatch:40% SEL Name Match:20%
>>>>Methods :TypeCoding Match:40% ReturnTypeMatch:40% SEL Name Match:20%
>>>>Properties: Offset Match:20% NameMatch 40% Signature Match 40%
>>>>>So if this method has matching TC and SEL Name,but wrong RT, it will gain (35%/9)*(40%+20%)Point
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
287
291

0 comments on commit 7bdf270

Please sign in to comment.