Jump to content

[Help/Tweak]How to hook the ASIdentifierManager (using NSClassFromString)?


Go to solution Solved by youngzzzzzzz,

7 posts in this topic

Recommended Posts

Posted (edited)

Edited 25/5

it's been solved.

I added the AdSupport framework to the makefile in the tweak project and done.
:)

 

 

I want to change the idfa value (like what PMP doing) and try to write some hooking codes.

//target codes #1

#import <AdSupport/AdSupport.h>
- (NSString *)idfaString {
    
    NSBundle *adSupportBundle = [NSBundle bundleWithPath:@"/System/Library/Frameworks/AdSupport.framework"];
    [adSupportBundle load];
    
    if (adSupportBundle == nil) {
        return @"";
    }
    else{
        
        Class asIdentifierMClass = NSClassFromString(@"ASIdentifierManager");
        
        if(asIdentifierMClass == nil){
            return @"";
        }
        else{
            
            //for no arc
            //ASIdentifierManager *asIM = [[[asIdentifierMClass alloc] init] autorelease];
            //for arc
            ASIdentifierManager *asIM = [[asIdentifierMClass alloc] init];
            
            if (asIM == nil) {
                return @"";
            }
            else{
                
                if(asIM.advertisingTrackingEnabled){
                    return [asIM.advertisingIdentifier UUIDString]; //target value
                }
                else{
                    return [asIM.advertisingIdentifier UUIDString];//target value
                }
            }
        }
    }
}

Tweak.xm


#import <AdSupport/ASIdentifierManager.h>
#import <AdSupport/AdSupport.h>

%hook ASIdentifierManager

-(NSUUID*)advertisingIdentifier
{
    %log;
    NSUUID *x = [[NSUUID alloc] initWithUUIDString:@"11111111-1111-1111-1111-111111111111"];
    return x;
}

%end

unfortunately , it doesnt works.

So I took another try,

//target codes #2

#import <AdSupport/AdSupport.h>
- (NSString *)idfaString {
            ASIdentifierManager *aim = [[ASIdentifierManager alloc] init];
            if (aim != nil) {
                if (aim.isAdvertisingTrackingEnabled) {
                    return [[aim advertisingIdentifier] UUIDString];
                }else{
                    return @"";
                }
            }
    return @"";
}

and it works!

 

I want to know why target codes #1 didn't work and how to make it work.

Updated by youngzzzzzzz
Posted (edited)

I cant help u, im a total newb :(:sad:

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

jk,

Im not sure, but i dont see how u can load a Framework as a Bundle, a Bundle requires Info.plist among other things, which framework doesnt have, if not,

You should try NSLogging before returning @"" then checking syslog to see what happened

Updated by RickHaks
Posted

I cant help u, im a total newb :(:sad:

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

jk,

Im not sure, but i dont see how u can load a Framework as a Bundle, a Bundle requires Info.plist among other things, which framework doesnt have, if not,

You should try NSLogging before returning @"" then checking syslog to see what happened

 

Mmm..the syslog show:

<Warning>: MS:Warning: nil class argument for selector advertisingIdentifier

I thought it could not hook the function while using the Bundle to new the Class.


Maybe NSUUID is deprecated

But code No.2 works.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
  • Create New...

Important Information

We would like to place cookies on your device to help make this website better. The website cannot give you the best user experience without cookies. You can accept or decline our cookies. You may also adjust your cookie settings. Privacy Policy - Guidelines