Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
k0tayan committed Nov 12, 2023
0 parents commit 307e168
Show file tree
Hide file tree
Showing 29 changed files with 2,436 additions and 0 deletions.
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
.theos
.DS_Store
._*

packages

package-lock.json
package.json
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2023 PurplePalette

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
24 changes: 24 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
FINALPACKAGE = 1
THEOS_PACKAGE_SCHEME = rootless
TARGET := iphone:clang:latest:7.0
INSTALL_TARGET_PROCESSES = SpringBoard
ARCHS = arm64

include $(THEOS)/makefiles/common.mk

TWEAK_NAME = libfaketouch

libfaketouch_FILES = Tweak.x \
Source/CGGeometry-KIFAdditions.m \
Source/IOHIDEvent+KIF.m \
Source/MyPTFakeMetaTouch.m \
Source/UIApplication-KIFAdditions.m \
Source/UIEvent+KIFAdditions.m \
Source/UITouch-KIFAdditions.m \
Source/UIView-KIFAdditions.m \
Source/UIWindow-KIFAdditions.m

libfaketouch_FRAMEWORKS = CoreGraphics QuartzCore UIKit IOKit
libfaketouch_CFLAGS = -fobjc-arc

include $(THEOS_MAKE_PATH)/tweak.mk
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# libfaketouch

Made some edits to PTFakeTouch.

* Changed class name to MyPTFakeTouch
* This allows you to use it at the same time as PTFakeTouch provided by PlayCover.
* Added simulateTouch function
* Made it easier to call dynamically from Frida etc.

## Thanks

* [TSFakeTouch](https://github.com/HenryQuan/TSFakeTouch) by HenryQuan
* [PTFakeTouch](https://github.com/Ret70/PTFakeTouch) by Ret70
18 changes: 18 additions & 0 deletions Source/CGGeometry-KIFAdditions.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//
// CGGeometry-KIFAdditions.h
// KIF
//
// Created by Eric Firestone on 5/22/11.
// Licensed to Square, Inc. under one or more contributor license agreements.
// See the LICENSE file distributed with this work for the terms under
// which Square, Inc. licenses this file to you.

#import <CoreGraphics/CGGeometry.h>

CG_INLINE CGPoint CGPointCenteredInRect(CGRect bounds) {
return CGPointMake(bounds.origin.x + bounds.size.width * 0.5f, bounds.origin.y + bounds.size.height * 0.5f);
}

CG_INLINE CGPoint CGPointMidPoint(CGPoint point1, CGPoint point2) {
return CGPointMake((point1.x + point2.x) / 2.0f, (point1.y + point2.y) / 2.0f);
}
11 changes: 11 additions & 0 deletions Source/CGGeometry-KIFAdditions.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
//
// CGGeometry-KIFAdditions.m
// KIF
//
// Created by Eric Firestone on 5/22/11.
// Licensed to Square, Inc. under one or more contributor license agreements.
// See the LICENSE file distributed with this work for the terms under
// which Square, Inc. licenses this file to you.

#import "CGGeometry-KIFAdditions.h"

33 changes: 33 additions & 0 deletions Source/FixCategoryBug.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
//
// FixCategoryBug.h
// FakeTouch
//
// Created by PugaTang on 16/4/7.
// Copyright © 2016年 PugaTang. All rights reserved.
//

#ifndef MainLib_FixCategoryBug_h
#define MainLib_FixCategoryBug_h

#define __kw_to_string_1(x) #x
#define __kw_to_string(x) __kw_to_string_1(x)

// 需要在有category的头文件中调用,例如 KW_FIX_CATEGORY_BUG_H(NSString_Extented)
#define KW_FIX_CATEGORY_BUG_H(name) \
@interface KW_FIX_CATEGORY_BUG_##name : NSObject \
+(void)print; \
@end

// 需要在有category的源文件中调用,例如 KW_FIX_CATEGORY_BUG_M(NSString_Extented)
#define KW_FIX_CATEGORY_BUG_M(name) \
@implementation KW_FIX_CATEGORY_BUG_##name \
+ (void)print { \
NSLog(@"[Enable]"); \
} \
@end \


// 在target中启用这个宏,其实就是调用下category中定义的类的print方法。
#define KW_ENABLE_CATEGORY(name) [KW_FIX_CATEGORY_BUG_##name print]

#endif
11 changes: 11 additions & 0 deletions Source/IOHIDEvent+KIF.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
//
// IOHIDEvent+KIF.h
// testAnything
//
// Created by PugaTang on 16/4/1.
// Copyright © 2016年 PugaTang. All rights reserved.
//


typedef struct __IOHIDEvent * IOHIDEventRef;
IOHIDEventRef kif_IOHIDEventWithTouches(NSArray *touches) CF_RETURNS_RETAINED;
180 changes: 180 additions & 0 deletions Source/IOHIDEvent+KIF.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,180 @@
//
// IOHIDEvent+KIF.m
// testAnything
//
// Created by PugaTang on 16/4/1.
// Copyright © 2016年 PugaTang. All rights reserved.
//

#import <UIKit/UIKit.h>
#import "IOHIDEvent+KIF.h"
#import <mach/mach_time.h>
#define IOHIDEventFieldBase(type) (type << 16)
#ifdef __LP64__
typedef double IOHIDFloat;
#else
typedef float IOHIDFloat;
#endif
typedef UInt32 IOOptionBits;
typedef uint32_t IOHIDDigitizerTransducerType;
typedef uint32_t IOHIDEventField;
typedef uint32_t IOHIDEventType;

void IOHIDEventAppendEvent(IOHIDEventRef event, IOHIDEventRef childEvent);
void IOHIDEventSetIntegerValue(IOHIDEventRef event, IOHIDEventField field, int value);
void IOHIDEventSetSenderID(IOHIDEventRef event, uint64_t sender);

enum {
kIOHIDDigitizerTransducerTypeStylus = 0,
kIOHIDDigitizerTransducerTypePuck,
kIOHIDDigitizerTransducerTypeFinger,
kIOHIDDigitizerTransducerTypeHand
};
enum {
kIOHIDEventTypeNULL, // 0
kIOHIDEventTypeVendorDefined,
kIOHIDEventTypeButton,
kIOHIDEventTypeKeyboard,
kIOHIDEventTypeTranslation,
kIOHIDEventTypeRotation, // 5
kIOHIDEventTypeScroll,
kIOHIDEventTypeScale,
kIOHIDEventTypeZoom,
kIOHIDEventTypeVelocity,
kIOHIDEventTypeOrientation, // 10
kIOHIDEventTypeDigitizer,
kIOHIDEventTypeAmbientLightSensor,
kIOHIDEventTypeAccelerometer,
kIOHIDEventTypeProximity,
kIOHIDEventTypeTemperature, // 15
kIOHIDEventTypeNavigationSwipe,
kIOHIDEventTypePointer,
kIOHIDEventTypeProgress,
kIOHIDEventTypeMultiAxisPointer,
kIOHIDEventTypeGyro, // 20
kIOHIDEventTypeCompass,
kIOHIDEventTypeZoomToggle,
kIOHIDEventTypeDockSwipe, // just like kIOHIDEventTypeNavigationSwipe, but intended for consumption by Dock
kIOHIDEventTypeSymbolicHotKey,
kIOHIDEventTypePower, // 25
kIOHIDEventTypeLED,
kIOHIDEventTypeFluidTouchGesture, // This will eventually superseed Navagation and Dock swipes
kIOHIDEventTypeBoundaryScroll,
kIOHIDEventTypeBiometric,
kIOHIDEventTypeUnicode, // 30
kIOHIDEventTypeAtmosphericPressure,
kIOHIDEventTypeUndefined,
kIOHIDEventTypeCount, // This should always be last
// DEPRECATED:
kIOHIDEventTypeSwipe = kIOHIDEventTypeNavigationSwipe,
kIOHIDEventTypeMouse = kIOHIDEventTypePointer
};
enum {
kIOHIDDigitizerEventRange = 0x00000001,
kIOHIDDigitizerEventTouch = 0x00000002,
kIOHIDDigitizerEventPosition = 0x00000004,
kIOHIDDigitizerEventStop = 0x00000008,
kIOHIDDigitizerEventPeak = 0x00000010,
kIOHIDDigitizerEventIdentity = 0x00000020,
kIOHIDDigitizerEventAttribute = 0x00000040,
kIOHIDDigitizerEventCancel = 0x00000080,
kIOHIDDigitizerEventStart = 0x00000100,
kIOHIDDigitizerEventResting = 0x00000200,
kIOHIDDigitizerEventSwipeUp = 0x01000000,
kIOHIDDigitizerEventSwipeDown = 0x02000000,
kIOHIDDigitizerEventSwipeLeft = 0x04000000,
kIOHIDDigitizerEventSwipeRight = 0x08000000,
kIOHIDDigitizerEventSwipeMask = 0xFF000000,
};
enum {
kIOHIDEventFieldDigitizerX = IOHIDEventFieldBase(kIOHIDEventTypeDigitizer),
kIOHIDEventFieldDigitizerY,
kIOHIDEventFieldDigitizerZ,
kIOHIDEventFieldDigitizerButtonMask,
kIOHIDEventFieldDigitizerType,
kIOHIDEventFieldDigitizerIndex,
kIOHIDEventFieldDigitizerIdentity,
kIOHIDEventFieldDigitizerEventMask,
kIOHIDEventFieldDigitizerRange,
kIOHIDEventFieldDigitizerTouch,
kIOHIDEventFieldDigitizerPressure,
kIOHIDEventFieldDigitizerAuxiliaryPressure, //BarrelPressure
kIOHIDEventFieldDigitizerTwist,
kIOHIDEventFieldDigitizerTiltX,
kIOHIDEventFieldDigitizerTiltY,
kIOHIDEventFieldDigitizerAltitude,
kIOHIDEventFieldDigitizerAzimuth,
kIOHIDEventFieldDigitizerQuality,
kIOHIDEventFieldDigitizerDensity,
kIOHIDEventFieldDigitizerIrregularity,
kIOHIDEventFieldDigitizerMajorRadius,
kIOHIDEventFieldDigitizerMinorRadius,
kIOHIDEventFieldDigitizerCollection,
kIOHIDEventFieldDigitizerCollectionChord,
kIOHIDEventFieldDigitizerChildEventMask,
kIOHIDEventFieldDigitizerIsDisplayIntegrated,
kIOHIDEventFieldDigitizerQualityRadiiAccuracy,
};
IOHIDEventRef IOHIDEventCreateDigitizerEvent(CFAllocatorRef allocator, AbsoluteTime timeStamp, IOHIDDigitizerTransducerType type,
uint32_t index, uint32_t identity, uint32_t eventMask, uint32_t buttonMask,
IOHIDFloat x, IOHIDFloat y, IOHIDFloat z, IOHIDFloat tipPressure, IOHIDFloat barrelPressure,
Boolean range, Boolean touch, IOOptionBits options);
IOHIDEventRef IOHIDEventCreateDigitizerFingerEventWithQuality(CFAllocatorRef allocator, AbsoluteTime timeStamp,
uint32_t index, uint32_t identity, uint32_t eventMask,
IOHIDFloat x, IOHIDFloat y, IOHIDFloat z, IOHIDFloat tipPressure, IOHIDFloat twist,
IOHIDFloat minorRadius, IOHIDFloat majorRadius, IOHIDFloat quality, IOHIDFloat density, IOHIDFloat irregularity,
Boolean range, Boolean touch, IOOptionBits options);



IOHIDEventRef kif_IOHIDEventWithTouches(NSArray *touches) {
uint64_t abTime = mach_absolute_time();
AbsoluteTime timeStamp;
timeStamp.hi = (UInt32)(abTime >> 32);
timeStamp.lo = (UInt32)(abTime);
IOHIDEventRef handEvent = IOHIDEventCreateDigitizerEvent(kCFAllocatorDefault, // allocator 内存分配器
timeStamp, // timestamp 时间戳
kIOHIDDigitizerTransducerTypeHand, // type
0, // index
0, // identity
kIOHIDDigitizerEventTouch, // eventMask
0, // buttonMask
0, // x
0, // y
0, // z
0, // tipPressure
0, // barrelPressure
0, // range
true, // touch
0); // options
IOHIDEventSetIntegerValue(handEvent, kIOHIDEventFieldDigitizerIsDisplayIntegrated, true);
for (UITouch *touch in touches)
{
uint32_t eventMask = (touch.phase == UITouchPhaseMoved) ? kIOHIDDigitizerEventPosition : (kIOHIDDigitizerEventRange | kIOHIDDigitizerEventTouch);
uint32_t isTouching = (touch.phase == UITouchPhaseEnded) ? 0 : 1;
CGPoint touchLocation = [touch locationInView:touch.window];
IOHIDEventRef fingerEvent = IOHIDEventCreateDigitizerFingerEventWithQuality(kCFAllocatorDefault, // allocator
timeStamp, // timestamp
(UInt32)[touches indexOfObject:touch] + 1, //index
2, // identity
eventMask, // eventMask
(IOHIDFloat)touchLocation.x, // x
(IOHIDFloat)touchLocation.y, // y
0.0, // z
0, // tipPressure
0, // twist
5.0, // minor radius
5.0, // major radius
1.0, // quality
1.0, // density
1.0, // irregularity
(IOHIDFloat)isTouching, // range
(IOHIDFloat)isTouching, // touch
0); // options
IOHIDEventSetIntegerValue(fingerEvent, kIOHIDEventFieldDigitizerIsDisplayIntegrated, 1);
IOHIDEventAppendEvent(handEvent, fingerEvent);
CFRelease(fingerEvent);
}
return handEvent;
}

18 changes: 18 additions & 0 deletions Source/LoadableCategory.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//
// LoadableCategory.h
// KIF
//
// Created by Karl Stenerud on 7/16/11.
// Licensed to Square, Inc. under one or more contributor license agreements.
// See the LICENSE file distributed with this work for the terms under
// which Square, Inc. licenses this file to you.

/** Make all categories in the current file loadable without using -load-all.
*
* Normally, compilers will skip linking files that contain only categories.
* Adding a call to this macro adds a dummy class, which causes the linker
* to add the file.
*
* @param UNIQUE_NAME A globally unique name.
*/
#define MAKE_CATEGORIES_LOADABLE(UNIQUE_NAME) @interface FORCELOAD_##UNIQUE_NAME : NSObject @end @implementation FORCELOAD_##UNIQUE_NAME @end
33 changes: 33 additions & 0 deletions Source/MyPTFakeMetaTouch.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Edited by PurplePalette on 2023/11/12.
// Copyright © 2023年 PurplePalette. All rights reserved.
//
// PTFakeMetaTouch.h
// PTFakeTouch
//
// Created by PugaTang on 16/4/20.
// Copyright © 2016年 PugaTang. All rights reserved.
//

#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>

@interface MyPTFakeMetaTouch : NSObject
/**
* Fake a touch event 构造一个触屏基础操作
*
* @param pointId 触屏操作的序列号
* @param point 操作的目的位置
* @param phase 操作的类别
*
* @return pointId 返回操作的序列号
*/
+ (NSInteger)fakeTouchId:(NSInteger)pointId AtPoint:(CGPoint)point withTouchPhase:(UITouchPhase)phase;
/**
* Get a not used pointId 获取一个没有使用过的触屏序列号
*
* @return pointId 返回序列号
*/
+ (NSInteger)getAvailablePointId;
+ (void)simulateTouch:(int)touchType x:(int)x y:(int)y identifier:(int)identifier;

@end
Loading

0 comments on commit 307e168

Please sign in to comment.