Unsolved Streaming file content from webserver or something?
-
Back at it again!
Looking for ideas or guides on how I would go about for an example, say I have a dynamic link library that I'm mapping into target processes, I'm currently retrieving the library from disk, but what if i want it to be secure and kept on a server somewhere?
I own multiple servers so that won't be an issue, but what would I need to look into / learn in order to make the process as I have it in my head? safest and easiest way.
I thought of websockets, but that means if the traffic is monitored you can simply find the url and download the file yourself. Perhaps streaming the file into a byte array and then using the data from there? but that still leaves us with the url open for grabs. -
Hi,
Do you mean you would like to somehow download a .dll and use it with your application ?
-
@SGaist said in Streaming file content from webserver or something?:
Hi,
Do you mean you would like to somehow download a .dll and use it with your application ?
Yeah how would i load the dll into memory (store it in a byte array), and how can i download it securely so it cant be stolen
-
Use a file server with login requirements.
-
nice and what do i use in qt to acheive this?
Currently have this code going on:
QBuffer buffer;
buffer.open(QBuffer::ReadWrite);
buffer.write(reply->readAll());now my question is, how can i make sure the buffer stores in binary mode and how can i test by printing it out?
-
Do you mean implement a file server with Qt ?
QBuffer uses a QByteArray internally which is what its name suggest: a byte array so whether you have text or binary doesn't matter at that level, it stores what you got from reply.What is reply by the way ?
-
I'm currently retrieving the library from disk, but what if i want it to be secure and kept on a server somewhere?
I don't understand what/why you're trying to achieve (many users' questions in this forum baffle me!), but just to be clear: you cannot download the content of a
.DLL
file into a program's (data) area and then have it run as code from there! OSes deliberately prevent you from doing this. Windows requires you to (dynamically) load a DLL for execution from a file on disk via::LoadLibrary()
.If you are trying to prevent some kind of copying, I suppose you could download it to a file first and then dynamically load that (and magically delete it on exit, and hope it can't be copied while it's on local disk), but it all seems a bit pointless. If you are the the author of the DLL it would be more usual to put some kind of security into the code, such as requiring the calling program to pass some kind of "token" to it which it checks for before executing its functions.
-
QNetworkAccessManager* m_NetworkMngr = new QNetworkAccessManager();
QNetworkReply *reply = m_NetworkMngr->get(QNetworkRequest(QUrl("http://url.com/file")));but the problem is I'm unable to print the buffer, it doesnt have the data stored in there. but if i print to a file then it works
So what i need to do now is:
QNetworkAccessManager* m_NetworkMngr = new QNetworkAccessManager();
QNetworkReply *reply = m_NetworkMngr->get(QNetworkRequest(QUrl("http://url.com/file)));
QEventLoop loop;
connect(reply, SIGNAL(finished()), &loop, SLOT(quit()));
loop.exec();
QUrl aUrl("http://url.com/file");
QFileInfo fileInfo=aUrl.path();
QFile file2("c:\"+fileInfo.fileName());
file2.open(QIODevice::WriteOnly);
file2.write(reply->readAll());
QBuffer buffer;
buffer.open(QBuffer::ReadWrite);
buffer.write(reply->readAll());
buffer.close();
qDebug() << buffer.buffer();Okay so now it prints the contents of my file, but how can i make sure its in binary mode? is there something i can do to my file before i upload it, i want it to do the equivelant of std::ios::binary
-
@davethedave
If you can "print to a file" then you can "print from buffer". -
Yea, but i want to split the file into an array of bytes which i could do with fstream std::ios::binary, but now i cant..
-
@davethedave
Really don't know what you mean. http://doc.qt.io/qt-5/qiodevice.html#readAll, which is what you're using on yourQNetworkReply
, already returns aQByteArray
, and there's no binary-to-text translation going on. Can't see what you'd do with yourfstream std::ios::binary
which is not just as easy in Qt functions. -
@JonB said in Streaming file content from webserver or something?:
@davethedave
Really don't know what you mean. http://doc.qt.io/qt-5/qiodevice.html#readAll, which is what you're using on yourQNetworkReply
, already returns aQByteArray
, and there's no binary-to-text translation going on. Can't see what you'd do with yourfstream std::ios::binary
which is not just as easy in Qt functions.When i print the buffer its in plain text it should be like
"\0x80\0x90..." -
@davethedave
Having to guess here. Are you talking about the particular way the lineqDebug() << buffer.buffer();
shows its output??
-
Right so its currently showing output in plain text
"Hello world"
how can i print it as an arab of byte / store it -
You can get get the hex values with QByteArray::toHex.