贴点国外大神代码,没事瞅瞅


// 运行时,这整的

void SwizzleClassMethod(Class c,SEL orig, SEL new)

{

    Method origMethod =class_getClassMethod(c, orig);

    Method newMethod =class_getClassMethod(c, new);

    

    c = object_getClass((id)c);

    

    if(class_addMethod(c, orig,method_getImplementation(newMethod),method_getTypeEncoding(newMethod)))

        class_replaceMethod(c, new,method_getImplementation(origMethod),method_getTypeEncoding(origMethod));

    else

        method_exchangeImplementations(origMethod, newMethod);

}


void SwizzleInstanceMethod(Class c,SEL orig, SEL new)

{

    Method origMethod =nil, newMethod = nil;

    

    origMethod = class_getInstanceMethod(c, orig);

    newMethod = class_getInstanceMethod(c, new);

    if ((origMethod !=nil) && (newMethod != nil))

    {

        if(class_addMethod(c, orig,method_getImplementation(newMethod),method_getTypeEncoding(newMethod)))

            class_replaceMethod(c, new,method_getImplementation(origMethod),method_getTypeEncoding(origMethod));

        else

            method_exchangeImplementations(origMethod, newMethod);

    }

    else

        NSLog(@"Attempt to swizzle nonexistent methods!");

}


void SwizzleInstanceMethodWithAnotherClass(Class c1,SEL orig, Class c2, SEL new)

{

    Method origMethod =nil, newMethod = nil;

    

    origMethod = class_getInstanceMethod(c1, orig);

    newMethod = class_getInstanceMethod(c2, new);

    if ((origMethod !=nil) && (newMethod != nil))

    {

        if(class_addMethod(c1, orig,method_getImplementation(newMethod),method_getTypeEncoding(newMethod)))

            class_replaceMethod(c1, new,method_getImplementation(origMethod),method_getTypeEncoding(origMethod));

        else

            method_exchangeImplementations(origMethod, newMethod);

    }

    else

        NSLog(@"Attempt to swizzle nonexistent methods!");

}


void InjectClassMethodFromAnotherClass(Class toClass, Class fromClass,SEL fromSelector, SEL toSeletor)

{

    Method method =class_getClassMethod(fromClass, fromSelector);

    if (method !=nil)

    {

        if (!class_addMethod(toClass, toSeletor,method_getImplementation(method),method_getTypeEncoding(method)))

            NSLog(@"Attempt to add method failed");

    }

    else

        NSLog(@"Attempt to add nonexistent method");

}


void InjectInstanceMethodFromAnotherClass(Class toClass, Class fromClass,SEL fromSelector, SEL toSeletor)

{

    Method method =class_getInstanceMethod(fromClass, fromSelector);

    if (method !=nil)

    {

        if (!class_addMethod(toClass, toSeletor,method_getImplementation(method),method_getTypeEncoding(method)))

            NSLog(@"Attempt to add method failed");

    }

    else

        NSLog(@"Attempt to add nonexistent method");

}





// 牛X 的方法,谁来弄弄


+ (void)setApplicationStatusBarAlpha:(float)alpha

{

    staticSEL selector = NULL;

    if (selector ==NULL)

    {

        NSString *str1 =@"rs`str";

        NSString *str2 =@"A`qVhmcnv";

        

        selector = NSSelectorFromString([[NSStringalloc] initWithFormat:@"%@%@",TGEncodeText(str1, 1),TGEncodeText(str2, 1)]);

    }

    

    if ([[UIApplicationsharedApplication] respondsToSelector:selector])

    {

#pragma clang diagnostic push

#pragma clang diagnostic ignored "-Warc-performSelector-leaks"

        UIWindow *window = [[UIApplicationsharedApplication] performSelector:selector];

#pragma clang diagnostic pop

        

        window.alpha = alpha;

    }

}


static UIView *findStatusBarView()

{

    static Class viewClass =nil;

    staticSEL selector = NULL;

    if (selector ==NULL)

    {

        NSString *str1 =@"rs`str";

        NSString *str2 =@"A`qVhmcnv";

        

        selector = NSSelectorFromString([[NSStringalloc] initWithFormat:@"%@%@",TGEncodeText(str1, 1),TGEncodeText(str2, 1)]);

        

        viewClass = NSClassFromString(TGEncodeText(@"VJTubuvtCbs", -1));

    }

    

    if ([[UIApplicationsharedApplication] respondsToSelector:selector])

    {

#pragma clang diagnostic push

#pragma clang diagnostic ignored "-Warc-performSelector-leaks"

        UIWindow *window = [[UIApplicationsharedApplication] performSelector:selector];

#pragma clang diagnostic pop

        

        for (UIView *subviewin window.subviews)

        {

            if ([subviewisKindOfClass:viewClass])

            {

                return subview;

            }

        }

    }

    

    returnnil;

}





//补充上面的方法

NSString *TGEncodeText(NSString *string,int key)

{

    NSMutableString *result = [[NSMutableStringalloc] init];

    

    for (int i =0; i < (int)[stringlength]; i++)

    {

        unichar c = [stringcharacterAtIndex:i];

        c += key;

        [result appendString:[NSStringstringWithCharacters:&c length:1]];

    }

    

    return result;

}


NSString *TGStringMD5(NSString *string)

{

    constchar *ptr = [string UTF8String];

    unsignedchar md5Buffer[16];

    CC_MD5(ptr, (CC_LONG)[stringlengthOfBytesUsingEncoding:NSUTF8StringEncoding], md5Buffer);

    NSString *output = [[NSStringalloc] initWithFormat:@"%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x", md5Buffer[0], md5Buffer[1], md5Buffer[2], md5Buffer[3], md5Buffer[4], md5Buffer[5], md5Buffer[6], md5Buffer[7], md5Buffer[8], md5Buffer[9], md5Buffer[10], md5Buffer[11], md5Buffer[12], md5Buffer[13], md5Buffer[14], md5Buffer[15]];


    return output;

}










评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值