cy_p

cycript -p /var/root/utils.cy > /dev/null; cycript -p $1;

Posted by kunnan on July 1, 2018

前言

cy 高级用法:加载自己的脚本

加载自己的脚本

以下这种方法可能会导致脚本多次加载(多次注入)

  • cycript.sh

    source cycript.sh;cyc appname
    
    cyc () { cycript -p $1 /var/root/utils.cy > /dev/null; cycript -p $1; }
    
    • utils1.cy

      function pviews(){
      	return UIApp.keyWindow.recursiveDescription().toString();
      };
          
      function pvcs(){
      	return [[[UIWindow keyWindow] rootViewController] _printHierarchy].toString();
      };
          
      function printIvars(a){ 
      	var x={}; 
      	for(i in *a){ 
      		try{ 
      			x[i] = (*a)[i]; 
      		}catch(e){
          
      		} 
      	} 
      	return x; 
      };
           
      function printMethods(className, isa) {
      	var count = new new Type("I");
      	var classObj = (isa != undefined) ? objc_getClass(className).constructor : objc_getClass(className);
      	var methods = class_copyMethodList(classObj, count);
      	var methodsArray = [];
      	for(var i = 0; i < *count; i++) {
      		var method = methods[i];
      		methodsArray.push({selector:method_getName(method), implementation:method_getImplementation(method)});
      	}
      	free(methods);
      	return methodsArray;
      };
      

方式2: 使用 @import 脚本相对路径

  • @import

    @import com.kn.utils;
    pviews()
    
  • utils.cy: /usr/lib/cycript0.9/com/kn/utils.cy

    (function(utils) {
    	var c = utils.constants = {};
      
    	c.pviews = function(){
    		return UIApp.keyWindow.recursiveDescription().toString();
    	};
      
    	c.pvcs = function(){
    		return [[[UIWindow keyWindow] rootViewController] _printHierarchy].toString();
    	};
      
    	c.rp = function(target){
    		var result = "" + target.toString();
    		while(target.nextResponder){
    			result += "\n" + target.nextResponder.toString();
    			target = target.nextResponder;
    		}
    		return result;
    	};
      
    	for(var k in utils.constants) {
    		Cycript.all[k] = utils.constants[k];
    	}
    })(exports);
    

See Also

/Users/devzkn/bin//knpost cy_p cycript -p /var/root/utils.cy > /dev/null; -t Cycript
#原来""的参数,需要自己加上""

转载请注明: > cy_p