美文网首页
iOS逆向课程笔记(七)

iOS逆向课程笔记(七)

作者: handsome5 | 来源:发表于2017-09-21 21:11 被阅读49次

    9.Deb包介绍

    官网:http://www.debian.org/doc/debian-policy/

    deb包本质是一个压缩包文件。里面包含一些特定的目录和文件。安装过程就是dpkg程序按照指定的规则去拷贝文件和执行脚本。

    dpkg -c  xxxx.deb //查看deb包的目录结构
    
    
    • DEBIAN目录
      存放control文件、及安装和卸载时需要执行的脚本等

      • control文件导出。。
         //deb包的名字,卸载和查询包信息都用这个名字
          Package: com.iosre.myfirstreproject
      
          //工程名字(产品名字)
          Name: MyFirstReProject
      
          //依赖包(可以指定多个,用','分割)
          Depends: mobilesubstrate, firmware  (>=8.0)
      
          //deb包版本号
          Version: 1.0.1
      
          //描述软件所支持的平台架构
          Architecture: iphoneos-arm
      
          //deb包简介
          Description: My first reproject!
      
          //deb包维护人和联系方式
          Maintainer: luz<1048056374@qq.com>
      
          //软件作者
          Author: luz
      
          //deb包归属类别
          Section: Tweaks
      
          //软件主页
          Homepage: https://www.baidu.com
      
      • 脚本文件
        preinst
        在Deb包文件解包之前,将会运行该脚本。许多“preinst”脚本的任务是停止作用于待升级软件包的服务,直到软件包安装或升级完成。
        
        postinst
        该脚本的主要任务是完成安装包时的配置工作。许多“postinst”脚本负责执行有关命令为新安装或升级的软件重启服务。
        
        prerm
        该脚本负责停止与软件包相关联的daemon服务。它在删除软件包关联文件之前执行。
        
        postrm
        该脚本负责修改软件包链接或文件关联,或删除由它创建的文件。
        
    • dpkg打包时会复制当前目录下layout目录下的所有文件和目录
      这些文件和目录会镜像到目标设备上(layout相对于设备的根目录)

      //发布时的Makefile
      DEBUG = 0
      THEOS_DEVICE_IP = 10.171.4.22 
      ARCHS = armv7 arm64 
      TARGET = iphone:latest:8.0  
      include $(THEOS)/makefiles/common.mk
      
      TWEAK_NAME = MyFirstReProject
      MyFirstReProject_FILES = Tweak.xm
      MyFirstReProject_FRAMEWORKS = UIKit 
      include $(THEOS_MAKE_PATH)/tweak.mk
      
      clean::
          rm -rf ./packages/* 
      before-package::
          cp ./script/postinst ./.theos/_/DEBIAN/
          cp ./script/postrm ./.theos/_/DEBIAN/  
      

    10. 常见Logos语法介绍

    维基百科:http://iphonedevwiki.net/index.php/Logos

    10.1 Block-level
    • %hook
      指定需要hook的class,必须以%end结尾。可以被%group包含

      %hook SBApplicationController
      -(void)uninstallApplication:(SBApplication *)application {
          NSLog(@"Hey, we're hooking uninstallApplication:!");
          %orig; // Call the original implementation of this method
          return;
      }
      %end
      
    • %group
      该指令用于将%hook分组,便于代码管理及按条件初始化分组,必须以%end结尾。
      一个%group可以包含多个%hook,所有不属于某个自定义group的%hook会被隐式归类到%group_ungrouped中。

      %group iOS8
      %hook IOS8_SPECIFIC_CLASS
          // your code here
      %end // end hook
      %end // end group ios8
      
      %group iOS9
      %hook IOS9_SPECIFIC_CLASS
          // your code here
      %end // end hook
      %end // end group ios9
      
      %ctor {
          if (kCFCoreFoundationVersionNumber > 1200) {
              %init(iOS9);
          } else {
              %init(iOS8);
          }
      }
      
    • %new
      在%hook内部使用,给一个现有class添加新函数,功能与class_addMethod相同。
      注: Objective-C的category与class_addMethod的区别: 前者是静态的而后者是动态的。

      %hook SBApplicationController
      -(void)uninstallApplication:(SBApplication *)application {
          NSLog(@"Hey, we're hooking uninstallApplication:!");
          %orig; // Call the original implementation of this method
          return;
      }
      
      %new
      - (void)namespaceNewMethod
      {
      NSLog(@"We've added a new method to SpringBoard.");
      }
      %end
      
    10.2 Top level
    • %ctor
      tweak的构造函数,完成初始化工作;如果不显示定义,Theos会自动生成一个%ctor,并在其中调用%init(_ungrouped)。

    • %dtor
      tweak的构造函数,完成收尾。如果不显示定义,Theos会自动生成一个%dtor。

    10.3 Function level
    • %init
      该指令用于初始化某个%group,必须在%hook或%ctor内调用;如果带参数,则初始化指定的group,如果不带参数,则初始化_ungrouped.
      注: 切记,只有调用了%ini,对应的%group才能起作用!
      ···
      %ctor {
      if (kCFCoreFoundationVersionNumber > 1200) %init(iOS9);
      else %init(iOS8);
      }
      ···

    • %c
      该指令的作用等同于objc_getClass或NSClassFromString,即动态获取一个类的定义,在%hook或%ctor内使用 。

      %hook SpringBoard
      - (void)_menuButtonDown:(id)down
      {
      %orig;
      SBScreenShotter *shotter = [%c(SBScreenShotter) sharedInstance];
      [shotter saveScreenshot:YES]; 
      }
      %end@
      
    • %log
      该指令在%hook内部使用,将函数的类名、参数等信息写入syslog,可以%log([(),…..])的格式追加其他打印信息。

    • %orig
      该指令在%hook内部使用,执行被hook的函数的原始代码;也可以用%orig更改原始函数的参数。

    //练习
    @interface SBScreenshotter: NSObject
    + (id)sharedInstance;
    - (void)saveScreenshot: (BOOL)arg1;
    @end
    
    @interface SpringBoard
    + (void)_AutoScreenSave2;
    - (void)_AutoScreenSave;
    @end
    
    %hook SpringBoard 
    -  (void)applicationDidFinishLaunching:(id)application 
    { 
        %orig; 
        UIAlertView *alert = [[UIAlertView alloc]  
        initWithTitle:@"Hello,Tanzhou!" 
        message:nil 
        delegate:self cancelButtonTitle:@"OK"
        otherButtonTitles:nil]; 
        [alert show]; 
    }
    
    %new
    - (void)_AutoScreenSave
    {
        NSLog(@"instance method");
        SBScreenShotter *shotter = [%c(SBScreenShotter) sharedInstance];
        [shotter saveScreenshot:YES]; 
    }
    
    %new
    + (void)_AutoScreenSave2
    {
        NSLog(@"class method");
        SBScreenShotter *shotter = [%c(SBScreenShotter) sharedInstance];
        [shotter saveScreenshot:YES]; 
    }
    
    - (void)_menuButtonDown:(id)down  
    {  
        //SBScreenShotter *shotter = [%c(SBScreenShotter) sharedInstance];
        //[shotter saveScreenshot:YES];
        //[self _AutoScreenSave]; 
        [%c(SpringBoard) _AutoScreenSave2];
        NSLog(@"x=%d, y=%d", 10, 20);
        %log((NSString *)@"iOSRE", (NSString *)@"Debug");  
        %orig; // call the original _menuButtonDown:
    }
    %end
    
    %hook SBLockScreenDateViewController
    - (void)setCustomSubtitleText:(id)arg1 withColor:(id)arg2
    {
    /*
       NSDate *date=[NSDate date];
       NSDateFormatter *format1=[[NSDateFormatter alloc]init];
       [format1 setDateFormat:@"yyyy/MM/dd HH:mm:ss"];   
       NSString *str1=[format1 stringFromDate:date];
    */
       struct tm *loctime;
       char timeBuf[1024] = {0};
       time_t now = time(NULL);
       loctime = localtime(&now);
       strftime(timeBuf, 30, "[%Y/%m/%d %H:%M:%S]", loctime);
       %orig([NSString stringWithUTF8String:timeBuf],arg2);   
    }
    %end
    
    
    /*
    %group HookTest
    %hook SpringBoard
    - (void)_lockButtonDown:(struct __IOHIDEvent *)arg1 fromSource:(int)arg2
    {
      NSLog(@"_lockButtonDown");
    }
    
    - (void)_lockButtonUp:(struct __IOHIDEvent *)arg1 fromSource:(int)arg2
    {
      NSLog(@"_lockButtonUp");
    }
    
    - (void)powerDownCanceled:(id)arg1
    {
      NSLog(@"powerDownCanceled");
      %orig;
    }
    
    - (void)powerDown
    {
      NSLog(@"powerDown");
    }  
    
    - (void)powerDownRequested:(id)arg1
    {
      NSLog(@"powerDownRequested");
    }
    %end
    %end
    */
    
    %ctor
    {
      %init(_ungrouped);
      //%init(HookTest);
    }
    
    

    相关文章

      网友评论

          本文标题:iOS逆向课程笔记(七)

          本文链接:https://www.haomeiwen.com/subject/tpgcsxtx.html