mirror of
https://github.com/StikDebug/StikDebug.git
synced 2026-10-16 12:30:29 +00:00
* Change default UPLOAD_IPA value to 'false' * Part 1 of the great debloat * Remove Mini Tools, adopt native alerts in StikJITApp, and update HomeView UI * Refactor views to use native SwiftUI alerts instead of CustomErrorView * Update ProfileView to use minimal List UI style with native alerts * Fix up homeview * Squash: Redesign HomeView, remove Feature Flags, enable all tabs, refactor alerts, and updates - Redesign HomeView to a simpler style with 'Enable JIT' action. - Remove 'Help & Info' and 'Quick Launch' from Home. - Fix DDI false positive by starting heartbeat on HomeView appear. - Restore robust DDI checks and update app name to 'StikDebug'. - Remove FeatureFlags and Beta tags; enable 'profiles', 'processes', 'location' tabs by default. - Remove 'Devices' tab; add 'Target Device IP' field in Settings. - Hardcode 'Settings' tab to 4th position. - Refactor 'SettingsView' tab customization to be reorder-only. - Remove 'Appearance' theme section from Settings. - Refactor custom error cards to use native SwiftUI/UIKit alerts across the app (HomeView, ConsoleLogsView, ProfileView, etc). - Restore JS callback support and script execution logic in HomeView. - Add necessary Color extensions. - Update project version to 3.0.0. * Clean up: Remove In-App Purchases, update checker, and unused IPA installer code * delete more bloat * fix build issue * Remove widget to save on App IDs * Attempt heartbeat restart when Enable JIT button is pressed * Get rid of PIP * Update Tab Naming * remove more bloat * final changes for today * Remove unused packages * UX Improvements * revert bundle id * Update README.md * remove old idevice * add updated idevice * Fix ddi false positive errors and add templates for GitHub stuff * Remove more unused stuff. * Fix links and update README content * Update compatibility table in README.md * Improve performance of console logs * Remove old code * Change default UPLOAD_IPA value to 'true' * remove the welcome sheet * import support for .mobiledevicepair * Add back LC JIT stuff * Fix heartbeat issues with LC JIT * update the build yml for nightly stuff * Update README.md * Update README.md * Update GitHub Actions workflow for IPA build * Update GitHub Actions workflow for nightly builds * Add URL scheme to kill tasks stikjit://kill-process?pid=1234 * fix build issues * Added App Intents * Unify the error handling style across the app
160 lines
5.2 KiB
C
160 lines
5.2 KiB
C
//
|
|
// location_simulation.c
|
|
// StikDebug
|
|
//
|
|
// Created by Stephen on 8/3/25.
|
|
//
|
|
|
|
#include "location_simulation.h"
|
|
#include "idevice.h"
|
|
#include <arpa/inet.h>
|
|
#include <netinet/in.h>
|
|
#include <string.h>
|
|
#include <stdlib.h>
|
|
#include <stdio.h>
|
|
|
|
static IdevicePairingFile *g_pairing = NULL;
|
|
static IdeviceProviderHandle *g_provider = NULL;
|
|
static CoreDeviceProxyHandle *g_core_device = NULL;
|
|
static AdapterHandle *g_adapter = NULL;
|
|
static RsdHandshakeHandle *g_handshake = NULL;
|
|
static RemoteServerHandle *g_remote_server = NULL;
|
|
static LocationSimulationHandle *g_location_sim = NULL;
|
|
|
|
static void cleanup_on_error(void) {
|
|
if (g_location_sim) { location_simulation_free(g_location_sim); g_location_sim = NULL; }
|
|
if (g_remote_server) { remote_server_free(g_remote_server); g_remote_server = NULL; }
|
|
if (g_handshake) { rsd_handshake_free(g_handshake); g_handshake = NULL; }
|
|
if (g_adapter) { adapter_free(g_adapter); g_adapter = NULL; }
|
|
if (g_core_device) { core_device_proxy_free(g_core_device); g_core_device = NULL; }
|
|
if (g_provider) { idevice_provider_free(g_provider); g_provider = NULL; }
|
|
if (g_pairing) { idevice_pairing_file_free(g_pairing); g_pairing = NULL; }
|
|
}
|
|
|
|
int simulate_location(const char *device_ip,
|
|
double latitude,
|
|
double longitude,
|
|
const char *pairing_file)
|
|
{
|
|
IdeviceFfiError *err = NULL;
|
|
|
|
if (g_location_sim) {
|
|
if ((err = location_simulation_set(g_location_sim, latitude, longitude))) {
|
|
idevice_error_free(err);
|
|
cleanup_on_error();
|
|
} else {
|
|
return IPA_OK;
|
|
}
|
|
}
|
|
|
|
struct sockaddr_in addr = { .sin_family = AF_INET,
|
|
.sin_port = htons(LOCKDOWN_PORT) };
|
|
if (inet_pton(AF_INET, device_ip, &addr.sin_addr) != 1) {
|
|
return IPA_ERR_INVALID_IP;
|
|
}
|
|
|
|
if (g_pairing) {
|
|
idevice_pairing_file_free(g_pairing);
|
|
g_pairing = NULL;
|
|
}
|
|
|
|
if ((err = idevice_pairing_file_read(pairing_file, &g_pairing))) {
|
|
idevice_error_free(err);
|
|
return IPA_ERR_PAIRING_READ;
|
|
}
|
|
|
|
if ((err = idevice_tcp_provider_new((struct sockaddr *)&addr,
|
|
g_pairing,
|
|
"LocationSimCLI",
|
|
&g_provider)))
|
|
{
|
|
idevice_error_free(err);
|
|
cleanup_on_error();
|
|
return IPA_ERR_PROVIDER_CREATE;
|
|
}
|
|
|
|
if ((err = core_device_proxy_connect(g_provider, &g_core_device))) {
|
|
idevice_error_free(err);
|
|
cleanup_on_error();
|
|
return IPA_ERR_CORE_DEVICE;
|
|
}
|
|
idevice_provider_free(g_provider);
|
|
g_provider = NULL;
|
|
|
|
uint16_t rsd_port;
|
|
if ((err = core_device_proxy_get_server_rsd_port(g_core_device,
|
|
&rsd_port)))
|
|
{
|
|
idevice_error_free(err);
|
|
cleanup_on_error();
|
|
return IPA_ERR_RSD_PORT;
|
|
}
|
|
|
|
if ((err = core_device_proxy_create_tcp_adapter(g_core_device,
|
|
&g_adapter)))
|
|
{
|
|
idevice_error_free(err);
|
|
cleanup_on_error();
|
|
return IPA_ERR_ADAPTER_CREATE;
|
|
}
|
|
// core_device_proxy_create_tcp_adapter takes ownership of g_core_device
|
|
// (Rust moves it into the adapter). Null the pointer so cleanup_on_error
|
|
// does not attempt a second free.
|
|
g_core_device = NULL;
|
|
|
|
AdapterStreamHandle *stream = NULL;
|
|
if ((err = adapter_connect(g_adapter, rsd_port, (ReadWriteOpaque **)&stream))) {
|
|
idevice_error_free(err);
|
|
cleanup_on_error();
|
|
return IPA_ERR_STREAM;
|
|
}
|
|
|
|
if ((err = rsd_handshake_new((ReadWriteOpaque *)stream, &g_handshake))) {
|
|
idevice_error_free(err);
|
|
adapter_stream_close(stream);
|
|
cleanup_on_error();
|
|
return IPA_ERR_HANDSHAKE;
|
|
}
|
|
|
|
if ((err = remote_server_connect_rsd(g_adapter,
|
|
g_handshake,
|
|
&g_remote_server)))
|
|
{
|
|
idevice_error_free(err);
|
|
cleanup_on_error();
|
|
return IPA_ERR_REMOTE_SERVER;
|
|
}
|
|
// remote_server_connect_rsd takes ownership of g_adapter and g_handshake.
|
|
g_adapter = NULL;
|
|
g_handshake = NULL;
|
|
|
|
if ((err = location_simulation_new(g_remote_server,
|
|
&g_location_sim))) {
|
|
idevice_error_free(err);
|
|
cleanup_on_error();
|
|
return IPA_ERR_LOCATION_SIM;
|
|
}
|
|
// location_simulation_new takes ownership of g_remote_server.
|
|
g_remote_server = NULL;
|
|
|
|
if ((err = location_simulation_set(g_location_sim,
|
|
latitude,
|
|
longitude))) {
|
|
idevice_error_free(err);
|
|
cleanup_on_error();
|
|
return IPA_ERR_LOCATION_SET;
|
|
}
|
|
|
|
return IPA_OK;
|
|
}
|
|
|
|
int clear_simulated_location(void)
|
|
{
|
|
IdeviceFfiError *err = NULL;
|
|
if (!g_location_sim) return IPA_ERR_LOCATION_CLEAR;
|
|
|
|
err = location_simulation_clear(g_location_sim);
|
|
cleanup_on_error();
|
|
|
|
return err ? IPA_ERR_LOCATION_CLEAR : IPA_OK;
|
|
}
|