mirror of
https://github.com/NohamR/xovi-rmfakecloud.git
synced 2026-05-24 20:01:00 +00:00
Patch URLs conditionally
This commit is contained in:
@@ -16,10 +16,10 @@ extern "C" void _xovi_construct() {
|
|||||||
QSettings extensionConfig(configFile, QSettings::IniFormat);
|
QSettings extensionConfig(configFile, QSettings::IniFormat);
|
||||||
QString newRMFCHostNameQStr = extensionConfig.value("host").toString();
|
QString newRMFCHostNameQStr = extensionConfig.value("host").toString();
|
||||||
if (newRMFCHostNameQStr == "") {
|
if (newRMFCHostNameQStr == "") {
|
||||||
std::cerr << "[" << NAME << "] No host defined in the config file!";
|
std::cerr << "[" << NAME << "] No host defined in the config file!" << std::endl;
|
||||||
abort();
|
abort();
|
||||||
}
|
}
|
||||||
std::cerr << "[" << NAME << "] New host set to: " << newRMFCHostNameQStr.toStdString();
|
std::cerr << "[" << NAME << "] New host set to: " << newRMFCHostNameQStr.toStdString() << std::endl;
|
||||||
newRMFCHostName = newRMFCHostNameQStr;
|
newRMFCHostName = newRMFCHostNameQStr;
|
||||||
bool ok;
|
bool ok;
|
||||||
newRMFCPort = extensionConfig.value("port").toInt(&ok);
|
newRMFCPort = extensionConfig.value("port").toInt(&ok);
|
||||||
@@ -38,8 +38,26 @@ extern "C" void _xovi_construct() {
|
|||||||
config.setCaCertificates(globalCerts);
|
config.setCaCertificates(globalCerts);
|
||||||
QSslConfiguration::setDefaultConfiguration(config);
|
QSslConfiguration::setDefaultConfiguration(config);
|
||||||
} else {
|
} else {
|
||||||
std::cerr << "[" << NAME << "] Failed to open CA file!";
|
std::cerr << "[" << NAME << "] Failed to open CA file!" << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
free(configRoot);
|
free(configRoot);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline bool shouldPatchURL(const QString &host) {
|
||||||
|
return QString(R""""(
|
||||||
|
hwr-production-dot-remarkable-production.appspot.com
|
||||||
|
service-manager-production-dot-remarkable-production.appspot.com
|
||||||
|
local.appspot.com
|
||||||
|
my.remarkable.com
|
||||||
|
ping.remarkable.com
|
||||||
|
internal.cloud.remarkable.com
|
||||||
|
eu.tectonic.remarkable.com
|
||||||
|
backtrace-proxy.cloud.remarkable.engineering
|
||||||
|
dev.ping.remarkable.com
|
||||||
|
dev.tectonic.remarkable.com
|
||||||
|
dev.internal.cloud.remarkable.com
|
||||||
|
eu.internal.tctn.cloud.remarkable.com
|
||||||
|
webapp-prod.cloud.remarkable.engineering
|
||||||
|
)"""").contains(host);
|
||||||
|
}
|
||||||
|
|||||||
@@ -12,6 +12,15 @@ extern "C" QNetworkReply* override$_ZN21QNetworkAccessManager13createRequestENS_
|
|||||||
const QNetworkRequest& req,
|
const QNetworkRequest& req,
|
||||||
QIODevice* outgoingData
|
QIODevice* outgoingData
|
||||||
) {
|
) {
|
||||||
|
using CreateFn = QNetworkReply*(*)(QNetworkAccessManager*,
|
||||||
|
QNetworkAccessManager::Operation,
|
||||||
|
const QNetworkRequest&,
|
||||||
|
QIODevice*);
|
||||||
|
CreateFn orig = reinterpret_cast<CreateFn>(
|
||||||
|
$_ZN21QNetworkAccessManager13createRequestENS_9OperationERK15QNetworkRequestP9QIODevice
|
||||||
|
);
|
||||||
|
|
||||||
|
if(shouldPatchURL(req.url().host())) {
|
||||||
// set new url
|
// set new url
|
||||||
QUrl newUrl = req.url();
|
QUrl newUrl = req.url();
|
||||||
newUrl.setHost(newRMFCHostName);
|
newUrl.setHost(newRMFCHostName);
|
||||||
@@ -21,15 +30,9 @@ extern "C" QNetworkReply* override$_ZN21QNetworkAccessManager13createRequestENS_
|
|||||||
QNetworkRequest newReq(req);
|
QNetworkRequest newReq(req);
|
||||||
newReq.setUrl(newUrl);
|
newReq.setUrl(newUrl);
|
||||||
|
|
||||||
// get original function signature
|
|
||||||
using CreateFn = QNetworkReply*(*)(QNetworkAccessManager*,
|
|
||||||
QNetworkAccessManager::Operation,
|
|
||||||
const QNetworkRequest&,
|
|
||||||
QIODevice*);
|
|
||||||
CreateFn orig = reinterpret_cast<CreateFn>(
|
|
||||||
$_ZN21QNetworkAccessManager13createRequestENS_9OperationERK15QNetworkRequestP9QIODevice
|
|
||||||
);
|
|
||||||
|
|
||||||
// call original function, and return the result
|
// call original function, and return the result
|
||||||
return orig(self, op, newReq, outgoingData);
|
return orig(self, op, newReq, outgoingData);
|
||||||
|
} else {
|
||||||
|
return orig(self, op, req, outgoingData);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,6 +11,13 @@ extern "C" void override$_ZN10QWebSocket4openERK15QNetworkRequest(
|
|||||||
QWebSocket* self,
|
QWebSocket* self,
|
||||||
const QNetworkRequest& req
|
const QNetworkRequest& req
|
||||||
) {
|
) {
|
||||||
|
using CreateFn = void*(*)(QWebSocket*,
|
||||||
|
const QNetworkRequest&);
|
||||||
|
CreateFn orig = reinterpret_cast<CreateFn>(
|
||||||
|
$_ZN10QWebSocket4openERK15QNetworkRequest
|
||||||
|
);
|
||||||
|
|
||||||
|
if(shouldPatchURL(req.url().host())) {
|
||||||
// set new url
|
// set new url
|
||||||
QUrl newUrl = req.url();
|
QUrl newUrl = req.url();
|
||||||
newUrl.setHost(newRMFCHostName);
|
newUrl.setHost(newRMFCHostName);
|
||||||
@@ -20,13 +27,10 @@ extern "C" void override$_ZN10QWebSocket4openERK15QNetworkRequest(
|
|||||||
QNetworkRequest newReq(req);
|
QNetworkRequest newReq(req);
|
||||||
newReq.setUrl(newUrl);
|
newReq.setUrl(newUrl);
|
||||||
|
|
||||||
// get original function signature
|
|
||||||
using CreateFn = void*(*)(QWebSocket*,
|
|
||||||
const QNetworkRequest&);
|
|
||||||
CreateFn orig = reinterpret_cast<CreateFn>(
|
|
||||||
$_ZN10QWebSocket4openERK15QNetworkRequest
|
|
||||||
);
|
|
||||||
|
|
||||||
// call original function, and return the result
|
// call original function, and return the result
|
||||||
orig(self, newReq);
|
orig(self, newReq);
|
||||||
|
} else {
|
||||||
|
orig(self, req);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user