Mini-Filter intercept drag & drop file(s) to disk? - c++

I am developing a mini-filter to intercept files and get the name of files which are dragged & dropped to a specific disk and get the file names.
If I drag & drop a file, I can get this file name and intercept it successfully (That's mean this file is not created on disk).
If I drag & drop multiple files, I can only get the first file name and other is not. But when I open the disk, I don't see any file here (That's mean Mini-Filter intercept them successfully). So I can not get the file names (except the first file)
I intercept drag & drop by redirect them:
Get file name by FltGetFileNameInformation() then FltParseFileNameInformation()
Split it two part
First is: \Device\HarddiskVolume1\folder\
Second is: file.ext
Append a file name for first part: \Device\HarddiskVolume1\folder\new_file.ext
Intercept create on disk
Release this buffer: Data->Iopb->TargetFileObject->FileName.Buffer
Assign first part to Data->Iopb->TargetFileObject->FileName
Set this: Data->Iopb->TargetFileObject->RelatedFileObject = NULL;
Data->IoStatus.Information = IO_REPARSE;
Data->IoStatus.Status = STATUS_REPARSE;
return FLT_PREOP_SUCCESS_NO_CALLBACK;
Above code can only intercept all files and get the first file name.
How can I do to intercept each file when I drag & drop multiple file?

I found myself that:
Get file name from Data->Iopb->TargetFileObject->FileName
Slipt it two part: file path and file name
Change file name to a redirect file name
Delete redirect file name. This step can be run before step #1
If redirect file name is not exist, It return STATUS_OBJECT_NAME_NOT_FOUND (0xC0000034). It is not problem for system.
If redirect file name is exist. It is OK.

Make sure you check the simrep sample from Microsoft they show you how to properly do this.
I would not base my assumption that Drag&Drop has a correspondence in the kernel and in the file-system. It can be implemented in user-mode in many ways especially if you are doing it on the same volume. It can be as simple as a rename. Also keep in mind hard-links and symboliclinks and alternate data streams.
Good luck.

Related

QT resources doesn't work

I'm writing a program that is supposed to work on the other computer, so I need to have my .txt files with it.
I have created a QT resource file and added one .txt file, then I used it in three windows. It worked perfectly fine until I added another .txt file to resource that is being used in only one window.
So I have users.txt file from which I am logging to program and managing users accounts and I have cars.txt which is a database for cars.
QFile text(":konta/users.txt");
text.open(QIODevice::ReadOnly | QIODevice::Text);
QTextStream wczytaj(&text);
This part works but in the next window
QFile text(":konta/users.txt");
text.open(QIODevice::ReadOnly);
QTextStream wczytaj(&text);
This part doesn't work, I have function which checks if file is open and if it exists, and they returns that it exists but is not open.
and now the newest window:
QFile baza(":/auta/cars.txt");
baza.open(QIODevice::Append | QIODevice::Text);
QTextStream zapisz(&baza);
if(!baza.exists()){QMessageBox::warning(this,"Uwaga","Baza nie została odnaleziona");}
else if(!baza.isOpen()){QMessageBox::warning(this,"Uwaga","Baza nie została otworzona");}
Same issue here, the file exists but is not opened. It's weird that it works in one window. Before I added the second .txt file, all the cases worked (except the third part of the code which didn't exist at that time). I didn't change anything in those files or functions.
I should also add that if I give them full path to the file C/folder/folder/file.txt, it works with no problems, but I need it to work on other computers as well, so it's not good for me.
I suppose that problem may be with currents path. When you start your application from Qt Designer current path is ../ (parent of the current directory). When your start your application directly default path is ./ (current directory where your .exe is). You may use this code to get universal path to default directory:
QString path = QApplication::applicationDirPath() % "/";
By the way you may use QFileDialog class to let you user choose files manually. And it is better to use SqLite for storing you users, cars etc. than text files. Qt provides in-built support for SqLite - it it fast and easy to use.

csv file not creating in a directory

The directory is correctly located but csv file is not created in that folder.
Code used to create a folder:
self.directory = os.path.join('Admins/'+name+'/')
os.makedirs(self.directory)
Code:
wfile = open(str(self.directory) + '/' + 'SALES.CSV', 'a+')
error:
no 'SALES.CSV' found
If you are going to rely on os.path.join() you might want to use it the way it is intended :
os.path.join(p1, p2, p3)
Without any slashes. You might also want to use
with open(os.path.join(self.directory, "SALES.CSV"), 'a+') as wfile:
# Process the file as you like, it will close itself afterwards
Mind trying this and letting us know the results?
Edit : just realised something.
You are using 'a+' which means you open the file in 'append' mode. But since you just created the directory, I suspect the file doesn't exist in the first place. If you want to open one anyway, just replace 'a+' with 'w'.

Recovering Files on Windows and C

Well this time I'm trying to write a program in C which recover deleted files from a disk, it could be an external disk, I have an idea than i had used before on linux, it is to open the disk as a kind of file and scaning the Headers and file footers of everything within the disk, the point is I'm not sure if there's allow on windows to open a disk as an File, basiclly I have the logic how to develope this program, but I'm not sure how to implement it on windows, anybody can give me a hand with this?.
The code I used on linux to open a disk as a file was:
Edit: That was a sample of what I was using guys, it's just to give you an idea of what I was doing, the correct syntax I used was the next:
direccion = ui->linea->text().toLatin1().constData();
f = fopen(direccion,"rb");
I used QT creator on linux, and direccion variable was a TextField value which contained the file path of the disk through a button function that open a QFileDialog...
could I use it in windows as well?
Thank you before hand..
"The code I used on linux to open a disk as a file was:"
File *f = fopen("E:\", "rb");
I seriously doubt you ever got this code working on any linux system (or windows either).
You'll need to escape the backslash path delimiter, if it's presented in any string literal:
FILE* f = fopen("E:\\", "rb");
// ^
Also all that filesystem path style you are presenting to access a particular disk, is about accessing a windows file path/disk.
No linux file system has notion about drive characters, and the file path delimiter value used is '/', not '\\'.
To recover deleted files, you can't use fopen or fstream::open because the file was deleted. Check the return value from the function or test the stream state.
The way to recover deleted files is:
Get the Master File Table as raw data.
Search for the record containing a string similar to the deleted
filename.
Change the entry in the Master File Table to "undeleted".
Write the Master File Table back to the drive.
The above usually requires platform specific API, which is different on Linux and Windows platforms.

Using Firefox website information in C++ program

I am trying to extract information from "about:plugins" website when you use Firefox web browser. I want to be able to use the contents of the website in my C++ program. Only way I know how to use content from another location is reading from a file.
What I am trying to do is read the file name and file path for each plugin from about:plugin'
Not sure if I could send this information to a file and then read it from there, but that seems like double work since if it output to file, I could just read it from there.
Needed to know how to extract information from the Firefox website in order to be used in a C++ program.
Just parse the pluginreg.dat file, you can find it in:
C:\Users\xxxxxxx\AppData\Roaming\Mozilla\Firefox\Profiles\xxxxxx.default
To obtain the AppData
char cAppData[MAX_PATH];
if(SHGetSpecialFolderPathA(NULL, cAppData, CSIDL_APPDATA, false))
{
// To obtain the profile name, parse the profiles.ini file in the folder
// ...AppData\Roaming\Mozilla\Firefox
// ...
}

CreateHardLink and CreateSymbolicLink Win32 Functions

I am completing a project to create dummy file systems for backup testing and need to develop a method of creating a Hardlinks and Softlinks within the structures.
The CreateHardLink and CreateSymbolicLink functions in windows.h receive file location and names based upon the current working directory.
The source code now changes directory, but those two functions do not successfully execute.
wstring hltarg;
hltarg = L"sym";
hltarg += ExistingFileName;
CreateHardLinkW(hltarg.c_str(), ExistingFileName.c_str(), NULL)
where hltarg concatenates the existing file name to the end of sym.
Because I moved my working directory to my target directory, neither of these strings contains a full path, but rather just the target file names.
Any advice on a different route to take rather than changing current directory?
The application will need to be portable so no hard references to file paths can be made, although desired file paths will be provided.