首页
社区
课程
招聘
[原创] 一个动画功能的逆向
发表于: 2013-12-13 21:17 8255

[原创] 一个动画功能的逆向

2013-12-13 21:17
8255
项目中实现一个功能,不是太好,就有了这番功夫。
零零碎碎花了好几天时间,动画效果搞定了!作个笔记吧。好些陌生指令,边看ida,边查的.虽然没什么难的, 但也还想记录下来,就写这里吧!

_text:00045458 ; HomeCoverViewController - (void)jumpAnimationFromCenter:(struct CGPoint) toCenter:(struct CGPoint) target:(id) duration:(float)
__text:00045458 ; Attributes: bp-based frame
__text:00045458
__text:00045458 ; void __cdecl -[HomeCoverViewController jumpAnimationFromCenter:toCenter:target:duration:](struct HomeCoverViewController *self, SEL, struct CGPoint, struct CGPoint, id, float)
__text:00045458 __HomeCoverViewController_jumpAnimationFromCenter_toCenter_target_duration__
__text:00045458                                         ; DATA XREF: __objc_const:00589FE8o
__text:00045458
__text:00045458 var_24          = -0x24      //var 之类就是方法中的变量
__text:00045458 var_20          = -0x20  
__text:00045458 var_1C          = -0x1C
__text:00045458 var_18          = -0x18
__text:00045458 arg_0           =  8              //arg_0-argc_c  分别依次就FromCenter,toCenter target,duration 4 个参数
__text:00045458 arg_4           =  0xC
__text:00045458 arg_8           =  0x10
__text:00045458 arg_C           =  0x14
__text:00045458
__text:00045458                 PUSH            {R4-R7,LR}   
__text:0004545A                 ADD             R7, SP, #0xC
__text:0004545C                 PUSH.W          {R8,R10,R11}
__text:00045460                 SUB.W           R4, SP, #0x30
__text:00045464                 BIC.W           R4, R4, #0xF    //清空低4位指令
__text:00045468                 MOV             SP, R4
__text:0004546A                 VST1.64         {D8-D11}, [R4@128]!   //保存浮点寄存器
__text:0004546E                 VST1.64         {D12-D13}, [R4@128]
__text:00045472                 SUB             SP, SP, #0x10
__text:00045474                 MOV             R5, R0
__text:00045476                 LDR             R0, [R7,#arg_8]
__text:00045478                 STR             R5, [SP,#0x28+var_1C]  
__text:0004547A                 MOV             R4, R3
__text:0004547C                 MOV             R8, R2
__text:0004547E                 BLX.W           _objc_retain
__text:00045482                 STR             R0, [SP,#0x28+var_20]
__text:00045484                 MOV             R0, #(selRef_view - 0x45490) ; selRef_view
__text:0004548C                 ADD             R0, PC ; selRef_view
__text:0004548E                 LDR             R1, [R0] ; "view"
__text:00045490                 MOV             R0, R5
__text:00045492                 BLX.W           _objc_msgSend
__text:00045496                 MOV             R7, R7
__text:00045498                 BLX.W           _objc_retainAutoreleasedReturnValue
__text:0004549C                 MOV             R5, R0
__text:0004549E                 MOV             R0, #(selRef_layer - 0x454AA) ; selRef_layer
__text:000454A6                 ADD             R0, PC ; selRef_layer
__text:000454A8                 LDR             R1, [R0] ; "layer"
__text:000454AA                 MOV             R0, R5
__text:000454AC                 BLX.W           _objc_msgSend
__text:000454B0                 MOV             R7, R7
__text:000454B2                 BLX.W           _objc_retainAutoreleasedReturnValue   
__text:000454B6                 STR             R0, [SP,#0x28+var_24]
__text:000454B8                 MOV             R0, R5
__text:000454BA                 BLX.W           _objc_release
__text:000454BE                 MOV             R0, #(selRef_begin - 0x454D2) ; selRef_begin
__text:000454C6                 MOV             R5, #(classRef_CATransaction - 0x454D4) ; classRef_CATransaction
__text:000454CE                 ADD             R0, PC ; selRef_begin
__text:000454D0                 ADD             R5, PC ; classRef_CATransaction
__text:000454D2                 LDR             R1, [R0] ; "begin"
__text:000454D4                 LDR             R0, [R5] ; _OBJC_CLASS_$_CATransaction
__text:000454D6                 BLX.W           _objc_msgSend
__text:000454DA                 MOV             R0, #(selRef_numberWithFloat_ - 0x454EE) ; selRef_numberWithFloat_
__text:000454E2                 MOV             R2, #(classRef_NSNumber - 0x454F0) ; classRef_NSNumber
__text:000454EA                 ADD             R0, PC ; selRef_numberWithFloat_
__text:000454EC                 ADD             R2, PC ; classRef_NSNumber
__text:000454EE                 LDR             R5, [R5] ; _OBJC_CLASS_$_CATransaction
__text:000454F0                 LDR             R1, [R0] ; "numberWithFloat:"
__text:000454F2                 LDR             R0, [R2] ; _OBJC_CLASS_$_NSNumber
__text:000454F4                 LDR             R2, [R7,#arg_C]
__text:000454F6                 BLX.W           _objc_msgSend
__text:000454FA                 MOV             R7, R7
__text:000454FC                 BLX.W           _objc_retainAutoreleasedReturnValue
__text:00045500                 MOV             R6, R0
__text:00045502                 MOV             R0, #(_kCATransactionAnimationDuration_ptr - 0x45512) ; _kCATransactionAnimationDuration_ptr
__text:0004550A                 MOVW            R1, #(:lower16:(selRef_setValue_forKey_ - 0x45518))
__text:0004550E                 ADD             R0, PC ; _kCATransactionAnimationDuration_ptr
__text:00045510                 MOVT.W          R1, #(:upper16:(selRef_setValue_forKey_ - 0x45518))
__text:00045514                 ADD             R1, PC ; selRef_setValue_forKey_
__text:00045516                 MOV             R2, R6
__text:00045518                 LDR             R0, [R0] ; _kCATransactionAnimationDuration
__text:0004551A                 LDR             R1, [R1] ; "setValue:forKey:"
__text:0004551C                 LDR             R3, [R0]
__text:0004551E                 MOV             R0, R5
__text:00045520                 BLX.W           _objc_msgSend
__text:00045524                 MOV             R0, R6
__text:00045526                 BLX.W           _objc_release
__text:0004552A                 MOVW            R0, #(:lower16:(selRef_arrayWithCapacity_ - 0x45542))   //lower ,up之类基本就是传递一个,指针的前半,后半部分
__text:0004552E                 MOV.W           R10, #0x3C
__text:00045532                 MOVT.W          R0, #(:upper16:(selRef_arrayWithCapacity_ - 0x45542))
__text:00045536                 MOV             R2, #(classRef_NSMutableArray - 0x45544) ; classRef_NSMutableArray
__text:0004553E                 ADD             R0, PC ; selRef_arrayWithCapacity_
__text:00045540                 ADD             R2, PC ; classRef_NSMutableArray
__text:00045542                 LDR             R1, [R0] ; "arrayWithCapacity:"
__text:00045544                 LDR             R0, [R2] ; _OBJC_CLASS_$_NSMutableArray
__text:00045546                 MOVS            R2, #0x3C
__text:00045548                 BLX.W           _objc_msgSend
__text:0004554C                 MOV             R7, R7
__text:0004554E                 BLX.W           _objc_retainAutoreleasedReturnValue
__text:00045552                 MOVW            R1, #(:lower16:(selRef_addObject_ - 0x45562))
__text:00045556                 LDR             R2, [R7,#arg_4]
__text:00045558                 MOVT.W          R1, #(:upper16:(selRef_addObject_ - 0x45562))
__text:0004555C                 MOV             R6, R0
__text:0004555E                 ADD             R1, PC ; selRef_addObject_
__text:00045560                 MOV             R0, #(selRef_valueWithCGPoint_ - 0x4557E) ; selRef_valueWithCGPoint_
__text:00045568                 VMOV            D8, R8, R8
__text:0004556C                 LDR.W           R11, [R1] ; "addObject:"
__text:00045570                 VMOV            D9, R4, R4
__text:00045574                 LDR             R1, [R7,#arg_0]
__text:00045576                 VMOV            D17, R2, R2
__text:0004557A                 ADD             R0, PC ; selRef_valueWithCGPoint_
__text:0004557C                 VSUB.F32        D11, D17, D9
__text:00045580                 VMOV.I32        D10, #0x80
__text:00045584                 VLDR            S26, =0.016949
__text:00045588                 VMOV            D16, R1, R1
__text:0004558C                 LDR             R5, [R0] ; "valueWithCGPoint:"
__text:0004558E                 VSUB.F32        D12, D16, D8
__text:00045592
__text:00045592 loc_45592                               ; CODE XREF: -[HomeCoverView
_text:00045592                 VMOV            R4, S20
__text:00045596                 MOV             R0, R4
__text:00045598                 BL              sub_221980      // 这里面才是计算位置计算
__text:0004559C                 MOV             R8, R0
__text:0004559E                 MOV             R0, R4
__text:000455A0                 BL              sub_221980
__text:000455A4                 VMOV            D16, R0, R0
__text:000455A8                 MOVW            R0, #(:lower16:(classRef_NSValue - 0x455BC))
__text:000455AC                 VMOV            D17, R8, R8
__text:000455B0                 MOVT.W          R0, #(:upper16:(classRef_NSValue - 0x455BC))
__text:000455B4                 VMUL.F32        D16, D11, D16
__text:000455B8                 ADD             R0, PC ; classRef_NSValue
__text:000455BA                 VMUL.F32        D17, D12, D17
__text:000455BE                 MOV             R1, R5
__text:000455C0                 LDR             R0, [R0] ; _OBJC_CLASS_$_NSValue
__text:000455C2                 VADD.F32        D1, D9, D16    //D1 就是对应S0,D1 中低有效部位就是S2 ,因为这些寄存器,是公用,相互映射的 寄存器之间的映射如下所示:
        •        S<2n> 映射到 D<n> 的最低有效半部
        •        S<2n+1> 映射到 D<n> 的最高有效半部
        •        D<2n> 映射到 Q<n> 的最低有效半部
        •        D<2n+1> 映射到 Q<n> 的最高有效半部
__text:000455C6                 VADD.F32        D0, D8, D17
__text:000455CA                 VMOV            R3, S2   
__text:000455CE                 VMOV            R2, S0
__text:000455D2                 BLX.W           _objc_msgSend            //这里其实 就是上面计算 新的位置后,存入NSNumber ,r2 就是X值,r3 就是Y值
__text:000455D6                 MOV             R7, R7
__text:000455D8                 BLX.W           _objc_retainAutoreleasedReturnValue  //对应 autorelease
__text:000455DC                 MOV             R4, R0
__text:000455DE                 MOV             R0, R6
__text:000455E0                 MOV             R1, R11
__text:000455E2                 MOV             R2, R4
__text:000455E4                 BLX.W           _objc_msgSend          // 数组 addObject
__text:000455E8                 MOV             R0, R4
__text:000455EA                 BLX.W           _objc_release
__text:000455EE                 VADD.F32        D10, D10, D13       //D13 其实就是 1/60,每跑一次循环加一次
__text:000455F2                 SUBS.W          R10, R10, #1          //R10 就是循环控制变量,R10就是代表计算的那帧
__text:000455F6                 BNE             loc_45592
__text:000455F8                 MOV             R0, #(selRef_animationWithKeyPath_ - 0x4560C) ; selRef_animationWithKeyPath_
__text:00045600                 MOV             R2, #(classRef_CAKeyframeAnimation - 0x4560E) ; classRef_CAKeyframeAnimation
__text:00045608                 ADD             R0, PC ; selRef_animationWithKeyPath_
__text:0004560A                 ADD             R2, PC ; classRef_CAKeyframeAnimation
__text:0004560C                 LDR             R1, [R0] ; "animationWithKeyPath:"
__text:0004560E                 LDR             R0, [R2] ; _OBJC_CLASS_$_CAKeyframeAnimation
__text:00045610                 MOV             R2, #(cfstr_Position_1 - 0x4561C) ; "position"
__text:00045618                 ADD             R2, PC  ; "position"
__text:0004561A                 BLX.W           _objc_msgSend  
__text:0004561E                 MOV             R7, R7
__text:00045620                 BLX.W           _objc_retainAutoreleasedReturnValue
__text:00045624                 MOV             R5, R0
__text:00045626                 MOV             R0, #(selRef_setValues_ - 0x45634) ; selRef_setValues_  
__text:0004562E                 MOV             R2, R6
__text:00045630                 ADD             R0, PC ; selRef_setValues_
__text:00045632                 LDR             R1, [R0] ; "setValues:"        //设置动画帧
__text:00045634                 MOV             R0, R5
__text:00045636                 BLX.W           _objc_msgSend
__text:0004563A                 MOV             R0, #(selRef_setDelegate_ - 0x4564A) ; selRef_setDelegate_
__text:00045642                 LDR.W           R8, [SP,#0x28+var_20]
__text:00045646                 ADD             R0, PC ; selRef_setDelegate_
__text:00045648                 CMP.W           R8, #0
__text:0004564C                 LDR             R1, [R0] ; "setDelegate:"
__text:0004564E                 MOV             R0, R5
__text:00045650                 BEQ             loc_4565C
__text:00045652                 MOV             R2, R8
__text:00045654                 BLX.W           _objc_msgSend                    //设置委托
__text:00045658                 LDR             R4, [SP,#0x28+var_1C]
__text:0004565A                 B               loc_45664
__text:0004565C ; ---------------------------------------------------------------------------
__text:0004565C
__text:0004565C loc_4565C                               ; CODE XREF: -[HomeCoverViewController jumpAnimationFromCenter:toCenter:target:duration:]+1F8j
__text:0004565C                 LDR             R4, [SP,#0x28+var_1C]
__text:0004565E                 MOV             R2, R4
__text:00045660                 BLX.W           _objc_msgSend
__text:00045664
__text:00045664 loc_45664                               ; CODE XREF: -[HomeCoverViewController jumpAnimationFromCenter:toCenter:target:duration:]+202j
__text:00045664                 MOVW            R0, #(:lower16:(selRef_addAnimation_forKey_ - 0x45676))
__text:00045668                 MOV             R2, R5
__text:0004566A                 MOVT.W          R0, #(:upper16:(selRef_addAnimation_forKey_ - 0x45676))
__text:0004566E                 MOVW            R3, #(:lower16:(cfstr_Backtohomevi_1 - 0x45680)) ; "backToHomeView"
__text:00045672                 ADD             R0, PC ; selRef_addAnimation_forKey_
__text:00045674                 MOVT.W          R3, #(:upper16:(cfstr_Backtohomevi_1 - 0x45680)) ; "backToHomeView"
__text:00045678                 LDR.W           R10, [SP,#0x28+var_24]
__text:0004567C                 ADD             R3, PC  ; "backToHomeView"
__text:0004567E                 LDR             R1, [R0] ; "addAnimation:forKey:"
__text:00045680                 MOV             R0, R10
__text:00045682                 BLX.W           _objc_msgSend
__text:00045686                 MOV             R0, #(selRef_commit - 0x45692) ; selRef_commit  //
__text:0004568E                 ADD             R0, PC ; selRef_commit
__text:00045690                 LDR             R1, [R0] ; "commit"
__text:00045692                 MOV             R0, #(classRef_CATransaction - 0x4569E) ; classRef_CATransaction
__text:0004569A                 ADD             R0, PC ; classRef_CATransaction
__text:0004569C                 LDR             R0, [R0] ; _OBJC_CLASS_$_CATransaction
__text:0004569E                 BLX.W           _objc_msgSend
__text:000456A2                 MOV             R0, #(selRef_coverImageView - 0x456AE) ; selRef_coverImageView
__text:000456AA                 ADD             R0, PC ; selRef_coverImageView
__text:000456AC                 LDR             R1, [R0] ; "coverImageView"
__text:000456AE                 MOV             R0, R4
__text:000456B0                 BLX.W           _objc_msgSend
__text:000456B4                 MOV             R7, R7
__text:000456B6                 BLX.W           _objc_retainAutoreleasedReturnValue
__text:000456BA                 MOV             R4, R0
__text:000456BC                 MOV             R0, #(selRef_setCenter_ - 0x456CA) ; selRef_setCenter_
__text:000456C4                 LDR             R2, [R7,#arg_0]
__text:000456C6                 ADD             R0, PC ; selRef_setCenter_
__text:000456C8                 LDR             R3, [R7,#arg_4]
__text:000456CA                 LDR             R1, [R0] ; "setCenter:"
__text:000456CC                 MOV             R0, R4
__text:000456CE                 BLX.W           _objc_msgSend
__text:000456D2                 MOV             R0, R4
__text:000456D4                 BLX.W           _objc_release
__text:000456D8                 MOV             R0, R5
__text:000456DA                 BLX.W           _objc_release
__text:000456DE                 MOV             R0, R6
__text:000456E0                 BLX.W           _objc_release
__text:000456E4                 MOV             R0, R10
__text:000456E6                 BLX.W           _objc_release
__text:000456EA                 ADD             R4, SP, #0x28+var_18
__text:000456EC                 MOV             R0, R8
__text:000456EE                 VLD1.64         {D8-D11}, [R4@128]!
__text:000456F2                 VLD1.64         {D12-D13}, [R4@128]
__text:000456F6                 SUB.W           R4, R7, #-var_18
__text:000456FA                 MOV             SP, R4
__text:000456FC                 POP.W           {R8,R10,R11}
__text:00045700                 POP.W           {R4-R7,LR}
__text:00045704                 B.W             j__objc_release
__text:00045704 ; End of function -[HomeCoverViewController jumpAnimationFromCenter:toCenter:target:duration:]

__text:00221980 sub_221980                              ; CODE XREF: -[HomeCoverViewController jumpAnimationFromCenter:toCenter:target:duration:]+140p
__text:00221980                                         ; -[HomeCoverViewController jumpAnimationFromCenter:toCenter:target:duration:]+148p

//下面就是上面红色部分的计算方法,传人r0 参数
__text:00221980                 VMOV            D0, R0, R0              
__text:00221984                 VLDR            D17, =0.363636364  //将常数加载
__text:00221988                 VCVT.F64.F32    D16, S0               // 单精度 浮点数 转双浮点数
__text:0022198C                 VCMPE.F64       D16, D17            // 参数 与D17 比较,其实就是动画的前0.363636364 的计算方法
__text:00221990                 VMRS            APSR_nzcv, FPSCR  // 从浮点处理寄存器,赋值到  APSR(Application Program Status Register).)
__text:00221994                 BPL             loc_2219A4               //BPL  就是结果为正就调整,PL应该就是Plus
__text:00221996                 VLDR            D17, =7.5625            
__text:0022199A                 VMUL.F64        D17, D16, D17    // D17 = D17*D16;
__text:0022199E                 VMUL.F64        D16, D16, D17   // D16 = D16*D17  相当于:D16 = 7.5625*D16*D16; 下面也就是类似代码
__text:002219A2                 B               loc_221A10
__text:002219A4 ; ---------------------------------------------------------------------------
__text:002219A4
__text:002219A4 loc_2219A4                              ; CODE XREF: sub_221980+14j
__text:002219A4                 VLDR            D17, =0.727272727
__text:002219A8                 VCMPE.F64       D16, D17
__text:002219AC                 VMRS            APSR_nzcv, FPSCR
__text:002219B0                 BPL             loc_2219CC
__text:002219B2                 VLDR            D17, =-0.545454545
__text:002219B6                 VADD.F64        D16, D16, D17
__text:002219BA                 VLDR            D17, =3.63
__text:002219BE                 VMUL.F64        D17, D16, D17
__text:002219C2                 VMUL.F64        D16, D16, D17
__text:002219C6                 VLDR            D17, =0.84
__text:002219CA                 B               loc_221A0C
__text:002219CC ; ---------------------------------------------------------------------------
__text:002219CC
__text:002219CC loc_2219CC                              ; CODE XREF: sub_221980+30j
__text:002219CC                 VLDR            D17, =0.9
__text:002219D0                 VCMPE.F64       D16, D17
__text:002219D4                 VMRS            APSR_nzcv, FPSCR
__text:002219D8                 BPL             loc_2219F4
__text:002219DA                 VLDR            D17, =-0.818181818
__text:002219DE                 VADD.F64        D16, D16, D17
__text:002219E2                 VLDR            D17, =7.5625
__text:002219E6                 VMUL.F64        D17, D16, D17
__text:002219EA                 VMUL.F64        D16, D16, D17
__text:002219EE                 VMOV.F64        D17, #0.9375
__text:002219F2                 B               loc_221A0C
__text:002219F4 ; ---------------------------------------------------------------------------
__text:002219F4
__text:002219F4 loc_2219F4                              ; CODE XREF: sub_221980+58j
__text:002219F4                 VLDR            D17, =-0.954545455
__text:002219F8                 VADD.F64        D16, D16, D17
__text:002219FC                 VLDR            D17, =7.5625
__text:00221A00                 VMUL.F64        D17, D16, D17
__text:00221A04                 VMUL.F64        D16, D16, D17
__text:00221A08                 VLDR            D17, =0.984375
__text:00221A0C
__text:00221A0C loc_221A0C                              ; CODE XREF: sub_221980+4Aj
__text:00221A0C                                         ; sub_221980+72j
__text:00221A0C                 VADD.F64        D16, D16, D17
__text:00221A10
__text:00221A10 loc_221A10                              ; CODE XREF: sub_221980+22j
__text:00221A10                 VCVT.F32.F64    S0, D16
__text:00221A14                 VMOV            R0, S0       //将计算结果放R0中
__text:00221A18                 BX              LR               //计算完毕,返回
__text:00221A18 ; End of function sub_221980

最后模拟了一份自由落体的,反弹的代码:

   [CATransaction begin];
    [CATransaction setValue:[NSNumber numberWithFloat:0.8] forKey:kCATransactionAnimationDuration];
   
    NSMutableArray *array = [NSMutableArray arrayWithCapacity:60];
   
    self.posArray = [NSMutableArray array];
    for(int i = 1;i<=60;i++)
    {
        float rate = i/60.0;
        float yoffset = 0.0;
        if(rate <0.3636364)
        {
            yoffset = i*i/(60*60)*7.5625;
        }
        else if(rate < 0.7272727)
        {
            yoffset = (i/60.0 - 0.545454545)*(i/60.0 -0.545454545)*3.63 + 0.84;
        }
        else if(rate < 0.9)
        {
            yoffset = (i/60.0 -0.818181818)*(i/60.0 -0.818181818)*7.5625 + 0.9375;
        }
        else
        {
            yoffset = (i/60.0 - 0.954545455)*(i/60.0 - 0.954545455)*7.5625 + 0.984375;
        }
        
        yoffset = (230 - self.imageView.center.y)*yoffset +self.imageView.center.y;
        NSString *numberStr = [NSString stringWithFormat:@"%f",yoffset];
        
        [self.posArray addObject:numberStr];
    }
   
    for(int i = 0;i<60;i++)
    {
        NSString *highStr = [self.posArray objectAtIndex:i];
        float h = [highStr floatValue];
        [array addObject:[NSValue valueWithCGPoint:CGPointMake(160, h)]];
    }
   
    CAKeyframeAnimation *anim = [CAKeyframeAnimation animationWithKeyPath:@"position"];
   
    [anim setValues:array];
   
    anim.delegate = self;
   
    [self.imageView.layer addAnimation:anim forKey:@"positon"];
   
    [CATransaction commit];
   
    self.imageView.center = CGPointMake(160, 230);

[培训]《安卓高级研修班(网课)》月薪三万计划,掌握调试、分析还原ollvm、vmp的方法,定制art虚拟机自动化脱壳的方法

收藏
免费 0
支持
分享
最新回复 (1)
雪    币: 458
活跃值: (306)
能力值: ( LV12,RANK:400 )
在线值:
发帖
回帖
粉丝
2
占个位置 ,空了慢慢看。
2013-12-13 22:00
0
游客
登录 | 注册 方可回帖
返回
//