3

I want to simulate touch events system wide in ios non-jailbreak device. of-course this app is not meant for appstore.

after a long goggling i did something like this.

-(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;

}

I am not able to see any desired output. please guide me what I am doing wrong here.

I tried to add framework given by KennyTM but its showing architecture problem. so linked dynamically.

Some how i checked George Aguirre reply in this link Simulating System Wide Touch Events on iOS. but not clear whether he is achieving this without jailbreaking the device.

Is is possible with out jailbreak the device?

Advance thanks for your help.

Community
  • 1
  • 1
Jayant Dash
  • 91
  • 1
  • 6

0 Answers0