mirror of
https://github.com/NohamR/RMHook-Win.git
synced 2026-05-25 12:27:12 +00:00
Refactor hook.cpp: cache URLs & improve safety
This commit is contained in:
@@ -142,69 +142,55 @@ QNetworkReply* __fastcall hookedCreateRequest(
|
|||||||
QNetworkAccessManager* self,
|
QNetworkAccessManager* self,
|
||||||
QNetworkAccessManager::Operation op,
|
QNetworkAccessManager::Operation op,
|
||||||
const QNetworkRequest& req,
|
const QNetworkRequest& req,
|
||||||
QIODevice* outgoingData
|
QIODevice* outgoingData)
|
||||||
)
|
|
||||||
{
|
{
|
||||||
const QString host = req.url().host();
|
const QUrl url = req.url();
|
||||||
|
const QString host = url.host();
|
||||||
|
|
||||||
if (shouldPatchURL(host)) {
|
if (shouldPatchURL(host)) {
|
||||||
QNetworkRequest newReq(req);
|
QNetworkRequest newReq(req);
|
||||||
QUrl newUrl = req.url();
|
QUrl newUrl = url;
|
||||||
newUrl.setHost(QString::fromStdString(gConfiguredHost));
|
newUrl.setHost(QString::fromStdString(gConfiguredHost));
|
||||||
newUrl.setPort(gConfiguredPort);
|
newUrl.setPort(gConfiguredPort);
|
||||||
newReq.setUrl(newUrl);
|
newReq.setUrl(newUrl);
|
||||||
|
|
||||||
Log("[HTTP PATCHED] " + host.toStdString() + " -> " + newUrl.toString().toStdString());
|
Log("[HTTP PATCHED] " + host.toStdString() + " -> " + newUrl.toString().toStdString());
|
||||||
|
return originalCreateRequest ? originalCreateRequest(self, op, newReq, outgoingData) : nullptr;
|
||||||
if (originalCreateRequest) {
|
|
||||||
return originalCreateRequest(self, op, newReq, outgoingData);
|
|
||||||
}
|
|
||||||
return nullptr;
|
|
||||||
}
|
}
|
||||||
|
return originalCreateRequest ? originalCreateRequest(self, op, req, outgoingData) : nullptr;
|
||||||
if (originalCreateRequest) {
|
|
||||||
return originalCreateRequest(self, op, req, outgoingData);
|
|
||||||
}
|
|
||||||
return nullptr;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void __fastcall hookedWebSocketOpen(
|
void __fastcall hookedWebSocketOpen(
|
||||||
QWebSocket* self,
|
QWebSocket* self,
|
||||||
const QNetworkRequest& req
|
const QNetworkRequest& req)
|
||||||
)
|
|
||||||
{
|
{
|
||||||
if (!originalWebSocketOpen) {
|
if (!originalWebSocketOpen) return;
|
||||||
return;
|
|
||||||
}
|
const QUrl url = req.url();
|
||||||
|
const QString host = url.host();
|
||||||
|
|
||||||
const QString host = req.url().host();
|
|
||||||
if (shouldPatchURL(host)) {
|
if (shouldPatchURL(host)) {
|
||||||
QUrl newUrl = req.url();
|
QUrl newUrl = url;
|
||||||
newUrl.setHost(QString::fromStdString(gConfiguredHost));
|
newUrl.setHost(QString::fromStdString(gConfiguredHost));
|
||||||
newUrl.setPort(gConfiguredPort);
|
newUrl.setPort(gConfiguredPort);
|
||||||
|
|
||||||
QNetworkRequest newReq(req);
|
QNetworkRequest newReq(req);
|
||||||
newReq.setUrl(newUrl);
|
newReq.setUrl(newUrl);
|
||||||
|
|
||||||
Log("[WS PATCHED] " + host.toStdString() + " -> " + newUrl.toString().toStdString());
|
Log("[WS PATCHED] " + host.toStdString() + " -> " + newUrl.toString().toStdString());
|
||||||
|
|
||||||
originalWebSocketOpen(self, newReq);
|
originalWebSocketOpen(self, newReq);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
originalWebSocketOpen(self, req);
|
originalWebSocketOpen(self, req);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void* ResolveExport(HMODULE module, const char* symbol)
|
void* ResolveExport(HMODULE module, const char* symbol)
|
||||||
{
|
{
|
||||||
|
if (!symbol) return nullptr;
|
||||||
void* addr = (void*)GetProcAddress(module, symbol);
|
void* addr = (void*)GetProcAddress(module, symbol);
|
||||||
|
|
||||||
if (!addr)
|
if (!addr)
|
||||||
{
|
{
|
||||||
Log("[ERROR] Failed to resolve symbol");
|
Log(std::string("[ERROR] Failed to resolve symbol: ") + symbol);
|
||||||
Log(symbol);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return addr;
|
return addr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user