在iOS中模拟System Wide Touch事件而不会越狱设备

时间:2012-11-16 11:27:32

标签: ios

我想在ios非越狱设备中模拟系统范围内的触摸事件。当然这个应用程序不适用于appstore。

经过长时间的瞪眼,我做了类似的事情。

-(void) SimulateTouchEvent
{
    float x = ((arc4random()%RAND_MAX)/(RAND_MAX*1.0))*(320.0-1.0)+1.0;
    float y = ((arc4random()%RAND_MAX)/(RAND_MAX*1.0))*(480.0-1.0)+1.0;
    static int click = 0;
    void *lib = dlopen(GSSERVPATH, RTLD_LAZY);
    uint64_t (*GSCurrentEventTimestamp)() = (uint64_t(*)())dlsym(lib, "GSCurrentEventTimestamp");
    mach_port_t (*GSGetPurpleApplicationPort)() = (mach_port_t(*)())dlsym(lib, "GSGetPurpleApplicationPort");
    //  void GSSendEvent(const GSEventRecord* record, mach_port_t port);
    void (*GSSendEvent)(const GSEventRecord* record, mach_port_t port) = (void(*)(const GSEventRecord* record, mach_port_t port)) dlsym(lib, "GSSendEvent");
    //void GSSendSystemEvent(const GSEventRecord* record);
    void (*GSSendSystemEvent)(const GSEventRecord* record) = (void(*)(const GSEventRecord* record)) dlsym(lib, "GSSendSystemEvent");

    static int prev_click = 5;

    CGPoint location = {x, y};

    // structure of touch GSEvent
    struct GSTouchEvent 
    {
        GSEventRecord record;
        GSHandInfo    handInfo;
    } * event = (struct GSTouchEvent*) &touchEvent;
    bzero(touchEvent, sizeof(touchEvent));

    // set up GSEvent
    event->record.type = kGSEventHand;
    event->record.windowLocation = location;
    event->record.timestamp = GSCurrentEventTimestamp();
    event->record.infoSize = sizeof(GSHandInfo) + sizeof(GSEventRecord /*GSPathInfo*/);
    event->handInfo.type = (GSHandInfoType)click; //getHandInfoType(prev_click, click);

    event->handInfo._0x44 = 0x1;
    event->handInfo._0x48 = 0x1;        

    event->handInfo.pathInfosCount = 1;
    bzero(&event->handInfo.pathInfos[0], sizeof(GSPathInfo));
    event->handInfo.pathInfos[0].pathIndex     = 2; //1;
    event->handInfo.pathInfos[0].pathIdentity  = 2;
    event->handInfo.pathInfos[0].pathProximity = click ? 0x02 /*0x03*/ : 0x01 /*0x00*/;
    event->handInfo.pathInfos[0].pathLocation  = location;

    // send GSEvent
    //sendGSEvent( (GSEventRecord*) event, location);    
    //mach_port_t pPort = GSGetPurpleApplicationPort();
    //GSSendEvent((GSEventRecord*) event, pPort);
    GSSendSystemEvent(&event->record);


    prev_click ^= click;
    click ^= prev_click;
    prev_click ^= click;

}

我无法看到任何所需的输出。请指导我在这里做错了什么。

我尝试添加KennyTM给出的框架,但显示架构问题。如此动态联系。

我如何通过此链接Simulating System Wide Touch Events on iOS查看George Aguirre的回复。但不清楚他是否在没有越狱设备的情况下实现这一目标。

可以越狱设备吗?

感谢您的帮助。

0 个答案:

没有答案