3

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

经过长时间的凝视后,我做了这样的事情。

-(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 的回复。但不清楚他是否在不越狱设备的情况下实现了这一目标。

是否可以不越狱设备?

提前感谢您的帮助。

4

0 回答 0