从Qt应用程序获取原始数据包数据 [英] Get raw packet data from Qt application

查看:467
本文介绍了从Qt应用程序获取原始数据包数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一种访问&的方法.篡改了Qt应用程序发送和接收的原始数据包数据,但找不到任何内容.有什么办法吗? 或者,如果不是,则该应用程序至少是一种从QWebView访问数据包数据的方法.

I was searching for a method to access & tamper the raw packet data sent and received by a Qt application but could not find anything. Is there any method? Or if not the application at least a method to access the packet data from a QWebView.

有什么方法可以实现以上两个条件中的任何一个?

Is there any method to achieve any of the above two?

推荐答案

对不起,Sam,我无法使其正常运行.我一直在尝试我能想象得到的一切,但是一切都没有达到预期.

I'm sorry, Sam, I cannot make it work. I've been trying everything I can imagine, but nothing goes as it would have been desired.

让我们简短列出选项以及可以做什么和不能做什么:

Let's make a short list of options and what can and cannot be done:

  • 您可以通过以下方式访问检索到的网页:使用webView->page()->currentFrame()获取QWebFrame,然后访问setContents()setHtml()toHtml()toPlainText()之类的方法.您可以通过这些功能动态更改小部件中显示的网页.

  • You can access the retrieved web page by means of obtaining the QWebFrame with webView->page()->currentFrame() and then accessing to methods like setContents(), setHtml(), toHtml() or toPlainText(). You can, by those functions, change dynamically the web page shown in the widget.

您可以使用replyFinished()插槽中的reply->readAll()方法访问为每个请求接收的原始响应(字节数组).

You can access the raw response (as an array of bytes) received for each request, by means of the method reply->readAll() in the replyFinished() slot.

可以通过覆盖您自己的网络访问管理器中的QNetworkAccessManager::createRequest()方法来拦截请求.在那里,您可以访问URL和请求中发送的标头,并进行更改或取消请求.

It's possible to intercept the requests, by overriding the QNetworkAccessManager::createRequest() method in a network access manager of your own. There you can access the URL and the headers sent in the request and change them or cancel the request.

但是...您想访问请求并为每个请求答复数据.

But... you want to access to the request and replied data for each request.

访问请求很容易,自定义QNetworkAccessManager中对createRequest()方法的覆盖已经对此进行了解释.但是让我们谈谈另一部分:

Access to the request is easy, it's already been explained by the override to the createRequest() method in a custom QNetworkAccessManager. But let's talk about the other part:

  • 对于我所看到的,从请求获得的回复是只读的,并且它无法更改,因为它是硬编码的在QNetworkReply的源代码中.

  • For what I've seen, the reply obtained from the request is read-only and IT CAN'T BE CHANGED, as it's hard-coded in the source code for QNetworkReply.

不能使用 QNetworkReplywriteData()功能,因为它被硬编码为简单地执行return -1 !!!

You cannot use the writeData() function of QNetworkReply, as it is hardcoded to simply do return -1!!!

您可以尝试将自己的QNetworkReply子类化,并在自定义QNetworkAccessManagercreateRequest()方法中将其返回.您必须覆盖功能readAll()bytesAvailable()abort().奇怪的是,仅当向非HTTP目标发出请求时,此方法才有效.我认为QNetworkAccessManager的内部结构会根据所使用的协议(HTTP,FTP等)调用QNetworkReply的不同实现.因此,这在某种意义上有效,但并非我们想要的方式.例如,在某些情况下,可以使用此方法返回预定义的网页.

You can try to subclass a QNetworkReply of your own and return it in the createRequest() method of a custom QNetworkAccessManager. You must override the functions readAll(), bytesAvailable(), and abort(). Curiously, this method works only if the request is made to a non-HTTP destination. I think the internals of QNetworkAccessManager invokes different implementations of the QNetworkReply depending of the protocol used (HTTP, FTP, ...). So this worked in a sense, but not in the way we want. This method can be used to return a predefined web page under certain conditions, for example.

考虑到QNetworkAccessManager::createRequest()必须返回QNetworkReply对象的事实,我看不到允许篡改所复制字节数组的子类的任何组合.它确实受到了很好的保护,您必须重新实现这些类上的所有内容才能实现您的目标.几乎复制并粘贴所有QtNetwork部分的源类并进行自己的实现.

Considering the fact that QNetworkAccessManager::createRequest() must return a QNetworkReply object, I cannot see any combination of subclassing that permits tampering in the replied byte array. It's really well protected and you must reimplement everything on those classes to be able to achieve your goal. Almost copy-paste the source classes of all the QtNetwork part and make your own implementation.

所以我认为答案将是:"不,似乎不能完全按照您的要求完成;只能部分完成".

So I think that the answer would be: "No, it seems that it cannot be done exactly as you ask; only partially".

对不起.

这篇关于从Qt应用程序获取原始数据包数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆