Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] Location heading on Simulator #175

Closed
Wouter01 opened this issue Jul 24, 2023 · 6 comments
Closed

[Feature] Location heading on Simulator #175

Wouter01 opened this issue Jul 24, 2023 · 6 comments
Labels
enhancement New feature or request

Comments

@Wouter01
Copy link

Is your feature request related to a problem? Please describe.
Currently, spoofing a path works with LocationSimulator on an iOS simulator. However, location heading doesn't seem to update, and is always pointing to north.

Describe the solution you'd like
I did some research myself and turns out it's possible to get an accurate (simulated) heading with the simctl tool (for example, using xcrun simctl location <deviceid> start --distance=10 --speed=20 37.629538,-122.395733 40.628083,-80,768254). This tool also uses CoreSimulator, so I went to have a look there and there are some additional useful methods there:

- (BOOL)_startLocationSimulationWithDistance:(double)arg1 interval:(double)arg2 speed:(double)arg3 waypoints:(id)arg4 error:(id*)arg5;
- (id)availableLocationScenarios;
- (BOOL)clearSimulatedLocationWithError:(id*)arg1;
- (BOOL)setLocationScenario:(id)arg1 error:(id*)arg2;
- (BOOL)setLocationScenarioWithPath:(id)arg1 error:(id*)arg2;
- (BOOL)setLocationWithLatitude:(double)arg1 andLongitude:(double)arg2 error:(id*)arg3;
- (BOOL)startLocationSimulationWithDistance:(double)arg1 speed:(double)arg2 waypoints:(id)arg3 error:(id*)arg4;
- (BOOL)startLocationSimulationWithInterval:(double)arg1 speed:(double)arg2 waypoints:(id)arg3 error:(id*)arg4;

I did some digging in hopper and got this working with the following arguments:

public func simulatePath(waypoints: [CLLocationCoordinate2D]) throws {
    let waypoints = waypoints.map { [$0.latitude, $0.longitude] }.flatMap { $0 }
    
    try self.wrapper.device().startLocationSimulation(withDistance: 10, speed: 20, waypoints: waypoints)
}

This achieves the same functionality as the LocationSpoofer class, tracking speed and other things itself. I wonder if such a thing could live in the app? The main issue I'm thinking of is that you don't know when a simulation has ended, and that it isn't available on physical devices afaik.

@Wouter01 Wouter01 added the enhancement New feature or request label Jul 24, 2023
@Schlaubischlump
Copy link
Owner

Schlaubischlump commented Jul 24, 2023

Hi @Wouter01,

As you have figured out, there are a couple of more CoreSimulator methods one can use. I decided against using them primarily for the reason you pointed out as well (feature parity between iOS and iPhoneSimulator).

Just for my clarification:
Are we talking about the heading not being displayed in LocationSimulator or are we talking about the speed and course properties of a CLLocation object ?

Since I got all the information about previous and next locations I should be able to just calculate the direction you are currently heading to and update the UI or do I miss something here ?
Regarding the missing information of a CLLocation object, there is probably not much I can do...

Edit: Is this maybe the same feature request as #172 ?

@Wouter01
Copy link
Author

Apologies if the issue was not clear. The issue I'm having is that the heading isn't updated in the iOS simulator. This seems to happen because the heading is updated internally in CoreSimulator by comparing with the previous location, but it doesn't seem to work if you set the location point by point. It indeed seems to be related to #172, but that issue was not completely clear to me

@Schlaubischlump
Copy link
Owner

Schlaubischlump commented Jul 24, 2023

Alright got you.

Looking at the disassembled source code of CoreSimulator reveals the following:

The following is called internally when calling setLocationWithLatitude:

float ___69-[SimDevice(SimLocation) setLocationWithLatitude:andLongitude:error:]_block_invoke(int arg0, int arg1, int arg2, int arg3) {
    xmm0 = *(arg0 + 0x20);
    _host_support_mig_set_location_lat_lon(arg1, arg2, arg3, arg3, r8, r9);
    return xmm0;
}

This is called internally when using startLocationSimulationWithDistance:

int ___94-[SimDevice(SimLocation) _startLocationSimulationWithDistance:interval:speed:waypoints:error:]_block_invoke(int arg0, int arg1, int arg2, int arg3) {
    _obj_to_wire(*(arg0 + 0x20), &var_40, &var_38, 0x0);
    rbx = _host_support_mig_set_location_waypoints(arg1, var_40, var_38, arg2, arg3, r9);
    free(var_40);
    rax = rbx;
    return rax;
}

I'll try to look deeper into it. Maybe this _host_support_mig_set_location_waypoints somehow sets the heading, while _host_support_mig_set_location_lat_lon does not.

Edit: Hard to say what _host_support_mig_set_location_waypoints is actually doing. It is just sending some messages to the XPC service and it is not clear what any of them are doing. But I still think somewhere inside of this method the heading must be updated...

@Wouter01
Copy link
Author

Thanks for looking into this. I stumbled on this too, as most of the things are hard to discover. I had the xpc service crash multiple times during my testings. If I discover something new I’ll let you know

@Wouter01
Copy link
Author

Wouter01 commented Jul 25, 2023

I have no clue what happened, but it seems to be working fine now with LocationSimulator. I have no clue why it's working now, as it wasn't for the past few days. (I have updated to 13.5 this morning, and Xcode did reconfigure afterwards, but I doubt that has anything to do with it)

@Schlaubischlump
Copy link
Owner

Interesting... This is really strange. Let me know if you figure out why it suddenly started working.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants