Skip to content

Instantly share code, notes, and snippets.

@rainyx
Created September 1, 2021 04:00
Show Gist options
  • Save rainyx/12c899f2441f8d2728f834742699ab55 to your computer and use it in GitHub Desktop.
Save rainyx/12c899f2441f8d2728f834742699ab55 to your computer and use it in GitHub Desktop.
GoogleEarthPro HTTP Proxy Plugin. Compile and inject via DYLD_INSERT_LIBRARIES.
//
// main.cpp
// GoogleEarthHttpProxy
//
// Created by admin on 2021/4/22.
//
#include <stdio.h>
#include <Foundation/Foundation.h>
#import <mach-o/dyld.h>
#include <dlfcn.h>
#include <string>
#include "substrate.h"
using namespace std;
#define QT_NETWORK_FRAMEWORK "/Applications/Google Earth Pro.app/Contents/Frameworks/QtNetwork.framework/Versions/Current/QtNetwork"
#define QT_CORE_FRAMEWORK "/Applications/Google Earth Pro.app/Contents/Frameworks/QtCore.framework/Versions/Current/QtCore"
typedef void *(*QNetworkProxy_ctor_T)(void *_this, int32_t type, void *host_name, int16_t port, void *user, void *password);
typedef void *(*QString_fromNSString_T)(void *_this, NSString *str);
typedef void *(*QNetworkAccessManager_setProxy_T)(void *_this, void *proxy);
static QNetworkProxy_ctor_T QNetworkProxy_ctor = nullptr;
static QString_fromNSString_T QString_fromNSString = nullptr;
static QNetworkAccessManager_setProxy_T QNetworkAccessManager_setProxy = nullptr;
void (*orig_QNetworkAccessManager_ctor)(void *_this, void *a2);
void my_QNetworkAccessManager_ctor(void *_this, void *a2) {
orig_QNetworkAccessManager_ctor(_this, a2);
NSLog(@"[GE_PROXY] my_QNetworkAccessManager_ctor called");
char qs_host_name[8] = {0};
char qs_user[8] = {0};
char qs_password[8] = {0};
QString_fromNSString(&qs_host_name, @"127.0.0.1");
QString_fromNSString(&qs_user, @"");
QString_fromNSString(&qs_password, @"");
char q_proxy[8] = {0};
QNetworkProxy_ctor(&q_proxy, 3 /* QNetworkProxy::HttpProxy */, qs_host_name, 1087, qs_user, qs_password);
QNetworkAccessManager_setProxy(_this, q_proxy);
}
__attribute__((constructor))
void proxy_entry() {
string image_name = _dyld_get_image_name(0);
if (image_name != "/Applications/Google Earth Pro.app/Contents/MacOS/Google Earth") {
return;
}
void *qt_network = dlopen(QT_NETWORK_FRAMEWORK, RTLD_NOW);
void *qt_core = dlopen(QT_CORE_FRAMEWORK, RTLD_NOW);
QNetworkProxy_ctor = (QNetworkProxy_ctor_T)dlsym(qt_network, "_ZN13QNetworkProxyC2ENS_9ProxyTypeERK7QStringtS3_S3_");
QString_fromNSString = (QString_fromNSString_T)dlsym(qt_core, "_ZN7QString12fromNSStringEPK8NSString");
QNetworkAccessManager_setProxy = (QNetworkAccessManager_setProxy_T)dlsym(qt_network, "_ZN21QNetworkAccessManager8setProxyERK13QNetworkProxy");
MSHookFunction(dlsym(qt_network, "_ZN21QNetworkAccessManagerC2EP7QObject"), (void **)my_QNetworkAccessManager_ctor, (void **)&orig_QNetworkAccessManager_ctor);
NSLog(@"[GE PROXY] initialized.");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment