Giter VIP home page Giter VIP logo

locationspoofer's Introduction

LocationSpoofer

Note:
Currently you should make sure to initialize a c-logger instance (console logging is sufficient e.g logger_initConsoleLogger(nil)) before attempting to use the library. I'll try to change this in the future.

Description

This package provides a simple wrapper around libimobiledevice and some internal Apple APIs in CoreSimulator to allow spoofing the location of iOS devices or iPhoneSimulator devices. To use the SimulatorDevice API inside a sandboxed application make sure to add your application to the app group "com.apple.CoreSimulator".

Structure

There are two main classes: IOSDevice and SimualtorDevice. Use the IOSDevice class if you want to interact with real devices. Use SimualtorDevice when interacting with the iPhoneSimulator. Both classes conform to the Device interface. For simple location spoofing cases you can use these classes directly. The Device interface defines all necessary functions to set and reset the current location.

For more complex location manipulation this packages includes the LocationSpoofer class. This class is initialized with a device instance and allows you to automatically update the location based on specific criteria.

List devices

You can either list all available devices using:

let iosDevices: [Device] = IOSDevice.availableDevices
let simDevices: [Device] = SimulatorDevice.availableDevices

or you can listen for new devices. To start/stop the listening process use:

IOSDevice.startGeneratingDeviceNotifications()
SimulatorDevice.startGeneratingDeviceNotifications()
...
// If you don't need updates anymore
IOSDevice.stopGeneratingDeviceNotifications()
SimulatorDevice.stopGeneratingDeviceNotifications()

To respond to the notifications, register a notification observer and bind it to a function:

// You can also use: .DeviceChanged, .DevicePaired or .DeviceDisconnected
NotificationCenter.default.addObserver(self, selector: #selector(deviceConnected), name: .DeviceConnected, object: nil)

@objc func deviceConnected(_ notification: Notification) {
	let device = notification.userInfo?["device"] as? Device
	...
}

Location change

You can then directly interact with the device. You can change the current location by using:

// Change the location
let destination = CLLocationCoordinate2D(latitude: 1000, longitude: 1000)
device.simulateLocation(destination)

// Stop spoofing
device.disableSimulation()

LocationSpoofer

To initialize a LocationSpoofer instance use:

let spoofer = LocationSpoofer(device)
// Configure some basic parameters
spoofer.heading = 90       // degree
spoofer.speed = 5          // m/s
spoofer.moveType = .drive  

The LocationSpoofer has three different movement states:
1. manual: Manually set the location
2. auto: Move in the direction of heading
3. navigation(route: NavigationRoute): Follow a route

Each movement state can toggle between automatic updates and manual updates. Depending on the move state automatic updates behave differently.

moveState manual update behaviour auto update behaviour supports setLocation
manual move in the direction of heading with speed periodically, randomly move when no user input is provided to fake GPS uncertainty yes
auto move in the direction of heading with speed automatically move in the direction of heading with speed no
navigation(route: NavigationRoute) follow along the route coordinates automatically follow along the route coordinates no
Manual update

To manually perform the move action, set the moveState and call the move function. When updating manually, manual and auto behave almost the same. The only difference is, that you can use setLocation to explicitly set a new location, when the moveState is set to manual.

// Move in the direction of heading with a specific speed
spoofer.moveState = .auto
spoofer.move()

// This behaves the same as in auto
spoofer.moveState = .manual
spoofer.move() 

// Manually change the location to a specific coordinate
let destination = CLLocationCoordinate2D(latitude: 1000, longitude: 1000)
spoofer.setLocation(destination)

// Define a navigation
let route: [CLLocationCoordinate2D] = [...]
spoofer.moveState = .navigation(route: NavigationRoute(route)) 
// Move to the first coordinate
spoofer.move()
// Wait
sleep(1)
// Move to the second coordinate
spoofer.move()
Automatic update

With automatic updates, LocationSpoofer will periodically update the location for you. To activate auto update in manual or auto state LocationSpoofer will need a current location. Therefore always set a previous location with setLocation before trying to activate auto update in one of these states.

// Define a navigation
let route: [CLLocationCoordinate2D] = [...]
spoofer.moveState = .navigation(route: NavigationRoute(route)) 
// Automatically update the location based on speed and the device responds time
// to follow along the route.
spoofer.startAutoUpdate()
...
// Stop the automatic update
spoofer.stopAutoUpdate()


// You can still set a new location or call move when in auto update mode with
// manual moveState. This auto update in manual state will just randomly, 
// slightly change your location, if you do not provide any input.
spoofer.moveState = .manual
spoofer.startAutoUpdate()
Delegate

To get informed about location changes performed by LocationSpoofer you can implement the LocationSpooferDelegate. It provides the following methods:

// MoveType
func willChangeMoveType(spoofer: LocationSpoofer, toMoveType: MoveType)
func didChangeMoveType(spoofer: LocationSpoofer, fromMoveType: MoveType)
// MoveState
func willChangeMoveState(spoofer: LocationSpoofer, toMoveState: MoveState)
func didChangeMoveState(spoofer: LocationSpoofer, fromMoveState: MoveState)
// Auto update
func willChangeAutoUpdate(spoofer: LocationSpoofer, toValue: Bool)
func didChangeAutoUpdate(spoofer: LocationSpoofer, fromValue: Bool)
// Location (nil in case of a location reset)
func willChangeLocation(spoofer: LocationSpoofer, toCoordinate: CLLocationCoordinate2D?)
func didChangeLocation(spoofer: LocationSpoofer, toCoordinate: CLLocationCoordinate2D?)
func errorChangingLocation(spoofer: LocationSpoofer, toCoordinate: CLLocationCoordinate2D?)

locationspoofer's People

Contributors

schlaubischlump avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

locationspoofer's Issues

[Feature] Add functions to interact with DeveloperMode

Is your feature request related to a problem? Please describe.
Currently the user has to download and install XCode just to enable DeveloperMode. It would be nice to enable DeveloperMode without user interaction.

Describe the solution you'd like
Libimobiledevice is able to access an service to enable and read DeveloperMode without user interaction. There is a prototype implementation at: https://gist.github.com/nikias/262bd709c1651e0139eb9e3a2e2d33f4

Some additional info:

#define DEV_ACTION_REVEAL 0 // 0 = reveal toggle in settings
#define DEV_ACTION_ENABLE 1 // 1 = enable developer mode (only if no passcode is set)
#define DEV_ACTION_PROMPT 2 // 2 = answers developer mode enable prompt post-restart

if you just wanna reveal toggle in settings app just send action 0
with action 1 it ll enable and restart device
once device is back from restart we need to either send action 2 or manually accept to popup to enable developer mode

also DeveloperModeStatus works perfectly fine every time

[BUG] Random crash

There is a crash which occurs very very seldom. If a device is disconnected, while the connected message is being constructed, the product info might be nil. Trying to create the string of e.g the device name will crash, since the pointer is nil.

Currently I have no good idea how to fix this, since the pointer is always not optional.

No library found for imobiledevice, plist and usbmuxd

For the targets imobiledevice, plist and usbmuxd, I get the error "While building for iOS, no library for this platform was found in '/Users/user/Library/Developer/Xcode/DerivedData/Spoof-gocdkddfnvevivasvqhjcuxpqzrv/SourcePackages/artifacts/locationspoofer/imobiledevice.xcframework'."

[BUG] Crashes when trying to use the project

The project is only useable when c-logger is successfully initialized. Put this line somewhere a the start of your program before using LocationSpoofer:

import CLogger

logger_initConsoleLogger(nil)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.