mNo edit summary |
No edit summary |
||
Line 9: | Line 9: | ||
// Standard C types | // Standard C types | ||
var IMP = new Type("^?"), SEL = new Type(":"), unsigned = new Type("I"); | var IMP = new Type("^?"), SEL = new Type(":"), unsigned = new Type("I"); | ||
var int8_t = char, int16_t = short, int32_t = long, int64_t = new Type("q"); | var int8_t = char, int16_t = short, int32_t = long, int64_t = new Type("q"); | ||
var uint8_t = new Type("C"), uint16_t = new Type("S"), uint32_t = new Type("L"), uint64_t = new Type("Q"); | var uint8_t = new Type("C"), uint16_t = new Type("S"), uint32_t = new Type("L"), uint64_t = new Type("Q"); | ||
Line 17: | Line 16: | ||
var size_t = NSUInteger, intptr_t = NSInteger; | var size_t = NSUInteger, intptr_t = NSInteger; | ||
var BOOL = char, bool = new Type("B"); | var BOOL = char, bool = new Type("B"); | ||
var mach_port_t = int, pid_t = int32_t; | |||
// Usage: dlfun("notify_post", "I*") | // Usage: dlfun("notify_post", "I*") | ||
function dlfun(fn, encoding) { | function dlfun(fn, encoding, altname) { var f = new Functor(dlsym(RTLD_DEFAULT, fn), encoding); if (f) this[altname || fn] = f; return f; } | ||
// MobileSubstrate | // MobileSubstrate | ||
Line 25: | Line 25: | ||
dlfun("MSHookMessage", "^?#:^?*"); | dlfun("MSHookMessage", "^?#:^?*"); | ||
dlfun("MSHookFunction", "v^v^v^^v"); | dlfun("MSHookFunction", "v^v^v^^v"); | ||
dlfun("_Z8MSLogHexPKvmPKc", "v^vL*", "MSLogHex"); | |||
// Declare a struct | // Declare a struct | ||
Line 37: | Line 38: | ||
return new Type(typestr.join("")); | return new Type(typestr.join("")); | ||
} | } | ||
// Hack! | |||
function quit() { MSHookFunction(dlsym(RTLD_DEFAULT, "readline"), new Functor(function(x){return null;}, "**"), null); } | |||
</source> | </source> |
Revision as of 08:47, 8 November 2009
// Standard C functions
function CGPointMake(x, y) { return {x:x, y:y}; }
function CGSizeMake(w, h) { return {width:w, height:h}; }
function CGRectMake(x, y, w, h) { return {origin:CGPointMake(x,y), size:CGSizeMake(w, h)}; }
function NSMakeRange(loc, len) { return {location:loc, length:len}; }
var CFRangeMake = NSMakeRange;
// Standard C types
var IMP = new Type("^?"), SEL = new Type(":"), unsigned = new Type("I");
var int8_t = char, int16_t = short, int32_t = long, int64_t = new Type("q");
var uint8_t = new Type("C"), uint16_t = new Type("S"), uint32_t = new Type("L"), uint64_t = new Type("Q");
var SInt8 = int8_t, SInt16 = int16_t, SInt32 = int32_t, SInt64 = int64_t;
var UInt8 = uint8_t, UInt16 = uint16_t, UInt32 = uint32_t, UInt64 = uint64_t;
var unichar = int16_t, UniChar = int16_t, wchar_t = int32_t;
var size_t = NSUInteger, intptr_t = NSInteger;
var BOOL = char, bool = new Type("B");
var mach_port_t = int, pid_t = int32_t;
// Usage: dlfun("notify_post", "I*")
function dlfun(fn, encoding, altname) { var f = new Functor(dlsym(RTLD_DEFAULT, fn), encoding); if (f) this[altname || fn] = f; return f; }
// MobileSubstrate
dlfun("MSHookMessageEx", "v#:^?^^?");
dlfun("MSHookMessage", "^?#:^?*");
dlfun("MSHookFunction", "v^v^v^^v");
dlfun("_Z8MSLogHexPKvmPKc", "v^vL*", "MSLogHex");
// Declare a struct
// e.g. var CGSize = struct(CGFloat, CGFloat);
function struct(n) {
var typestr = ["{?="];
for (var i = 0; i < arguments.length; ++ i) {
var arg = arguments[i];
typestr.push(arguments[i].toString());
}
typestr.push("}");
return new Type(typestr.join(""));
}
// Hack!
function quit() { MSHookFunction(dlsym(RTLD_DEFAULT, "readline"), new Functor(function(x){return null;}, "**"), null); }