Cycript是一个理解Objective-C语法的javascript解释器,这意味着我们能够在一个命令中用Objective-C或者javascript,甚至2者兼用。它能够挂钩正在运行的进程,能够在运行时修改应用的很多东西。
Cycript的官网在http://www.cycript.org/。在iOS越狱设备上,默认就有这个工具。命令行输入cycript
control+D
,来退出Cydia.
iPhone:~ root# ps aux |grep 'Moon'
mobile 898 0.0 3.9 695764 40544 ?? Us 7:57PM 0:56.90 /var/mobile/Containers/Bundle/Application/B2FF1603-3201-465C-BDC1-CB7626FAC26E/Moon.app/Moon
root 1170 0.0 0.0 536256 440 s000 S+ 9:40AM 0:00.01 grep Moon
iPhone:~ root# cycript -p 898
cy# UIApp
#"<UIApplication: 0x17583560>"
如果知道了一个对象在内存中的地址,可以通过#
操作符来获取这个对象。
devzkndeMacBook-Pro:~ devzkn$ scp /Users/devzkn/Downloads/cycript_0.9.594/cycript iphone150:/usr/bin
devzkndeMacBook-Pro:~ devzkn$ scp /Users/devzkn/Downloads/cycript_0.9.594/Cycript.lib/* iphone150:/usr/bin/Cycript.lib
@import com.kn.utils;
pviews()
这种方法可能会导致脚本多次加载(多次注入)
source cycript.sh;cyc appname
cyc () { cycript -p $1 /var/root/utils.cy > /dev/null; cycript -p $1; }
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;
};
(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);