Just wondering if there is any APIs that will let a .NET program write to a partition without entering kernel mode. I am developing an OS and just want to write a quick program on windows so I can add files to a partition shared with VMware. If I had the time I would write actual drivers for it, but I just want something to make something quick. I remember seeing a .NET program for modding Xbox games that could read and write directly to FatX Formatted USB flashdrives.
Try something like "\\?\Device\Harddisk0\Partition1" as path.
Related
I want to prevent executable being copied to another PC and thus i need to somehow save information inside my EXE file about that it was already used somewhere else on another PC.
Can i embed small piece of information like user's hard drive number into my EXE file so this information would be available when this EXE is copied to another PC?
I thought maybe there is a way to read and write to some resource file embedded in an EXE file but i presume that resource file is read only and if so is there is a place inside EXE file where i could keep information which i need?
You're fighting an uphill battle this way. It's possible to create a home-grown licensing scheme but be prepared to do a lot of work (I did it, so I speak from first-hand experience). Just some problems to solve:
If the hard drive fails and needs to be replaced, your user won't be able to use the program. Every time this happens, you'll get a support call with an angry user.
If the user runs your program inside a virtual machine, the hard drive serial number won't be unique - anyone can clone the virtual machine and now your program can be run on another machine.
Hard drive serial numbers can be changed - they don't come directly from the hardware.
What if the hard drive is a removable drive? Your user can run your program from a removable drive and then keep moving it to different machines.
Even if you get it done, how do you protect the license information from being modified?
If you really want to license your product, look at existing licensing products - they're not cheap but they already did the (considerable amount of) work that's necessary to have any kind of reliability.
Even if you only want to have minimal protection, consider this: you'll have to do a lot of work to get even minimal security of your secret token (whatever that is). If its security is minimal, then what's the point of you even doing all that work? If all you do is force people to put in a meaningless serial number, you'll just annoy your honest customers. If anyone wants to steal something that's not well protected, they will steal it. All a 'simple' protection scheme does is annoys your users and gives you a false sense of protection.
I ended up using Reprise RLM - I'm not associated with this company but I had a good experience with their sales and support people and their product worked well in the testing scenarios.
Ok, I analyzed all the variants that were proposed and decided that in my case it will be better to develop my own copy-protection system, due to the reason that I am an indie developer and not going to work with extra large applications.
Just in case, somebody faces to the same issue - here is the algorithm (well, one of them):
User starts APP1.EXE
APP1.EXE reads itself to some variable and adds HDD serial number to the end of it, e.g. HDD serial number - when you add something to the end it does not break EXE file and you do not have to worry about PE headers
Unfortunately, EXE cannot save itself in runtime so it saves its copy called APP2.EXE with the information about HDD
When APP2.EXE is saved APP1.EXE starts it as a separate process via Process.Start() and terminates itself
Now APP2.EXE is running and has the same content as APP1.EXE + HDD serial number so we simply write all bytes from APP2.EXE back to APP1.EXE, close current process and start APP1.EXE again
From now on APP1.EXE is running and have all needed information about current HDD so each time user starts APP1.EXE it compares HDD number at the end of its content with the actual one on user's PC, if they differ - terminate the process
Delete APP2.EXE so that user would not realize how these files exchange information about his HDD.
Useful info about self-deleting EXE can be found here :
http://www.catch22.net/tuts/self-deleting-executables
http://buffernow.com/selfdelete-executable-in-c/
P. S. I know that it is like a huge hole of security (I will not mention all of them) but implementation of this algorithm took just 20 lines of code in C# and was moved to a separate DLL which I can use everywhere and it works. There is NO any registration in the algorithm above and user can simply take this app and use it and I am sure that ~ 80% of them will not realize how this app is protected from copying.
Link to implementation : https://bitbucket.org/artemiusgreat/examples/src/ef7b60142277?at=master
I work in a call center and we need to use a lot of web based tools and work with a lot of information. They way we need to work is not efficient, so I made myself a couple of C# Windows Application to make my work a bit easier.
The problem is that those computers a locked en secured in a very high level. Almost all website's are blocked, we can't use USB drives to get data on the pc, the only way to get data to my account at work is to mail it compressed in a 7z file. We can't install software, drivers etc. I luckily have write access to the program data folder to save some data. But the only way I can store data is to put it all in .txt files. I've tried a lot of standalone databases but I'm also limited in space because we've got 30MB. So a standalone version of xampp (or similar software) is almost 40 MB so I can't use it.
Does anybody know I type of database to store my data is (mostly text and integers)? I prefer a single file which i can drop in the program data folder. I prefer it also to get the data in the same way like getting it from a database, dataset or something similar.
You may want to look into Infobright Community Edition which can give you incredible compression ratios on average from 40:1. Infobright is exactly like mysql and very compact.
Disclaimer: the author is affiliated with Infobright.
Let's say I have a file: test.txt and I save it on my harddisk.
Is there a way to determine on what (physical) spot the file is saved on the hard disk?
For example on vector 12 on track 10 of the hard disk.
I don't know if I got the terminology right of the above, but I hope you get what I mean.
I want to write of program wheer the user can point to a file and the program will find out where the file is on the HDD. Something like the old defrag (it's Windows ;) ) where it shows what parts of the disk is in use.
What is this called and can it be achieved? (I'm not looking for code (although exmaples are ok ofc), but rather whether it is possible)
P.S. The client will be Windows 7 (so think NTFS if it matters).
I'm pretty sure that doing that sort of low-level disk i/o in managed code is going to be...difficult, at best. Here's somebody that's done something like it:
http://codebrainz.ca/index.php/2010/05/23/low-level-disk-io-in-managed-net/
Anything you write to do something like this has to be hardware-dependent: unless you know what hardware you're talking to, you've got no idea how it physically stores data (e.g., a USB memory stick has neither platters, tracks nor sectors, nor does it spin. Yet, for all intents and purposes, it appears to be a disk).
Normally, you'd write some sort of device driver to accomplish this. This link
http://en.wikibooks.org/wiki/Windows_Programming/Device_Driver_Introduction
might help.
In Jeffrey Wall's WebLog you will find Defrag API C# wrappers. His GetFileMap method sems to come close to what you need.
It is possible from C++, so with a little interoping, you should be fine.
Look up FSCTL_GET_RETRIEVAL_POINTERS in the MSDN to get you started.
Would it be possible to create a program (.NET preferably) to create a virtual drive letter, but when it is read, written to, or browsed an independent program deals with what is returned?
Although you could do it by mapping a drive to a TCP server, webDAV or something like that, I'm wondering if it could be done with internal links.
This would be used for protected storage. The program does stream encryption and decryption of all the files in the drive (as they're read by all kinds of programs) if the program has had a password put into it.
What you're talking about is a storage device driver, which is how programs such as Daemon Tools and TrueCrypt accomplish such "virtual" drives.
You may not have to delve into the kernel to accomplish this, though. Microsoft supply a Windows User-Mode Driver Framework, which is designed to simplify the development of certain common Windows driver types. From what I can tell, you should be able to develop a virtual storage driver using the user-mode driver framework. As long as you're not directly interacting with hardware (like a kernel-mode device driver does), you should be fine. However, you won't be able to do this in C#. You'd probably have to use C, though you might get away with C++.
PowerShell already supports something like this with its Provider model. Certificate store, Active Directory, IIS configuration, SharePoint, ... are all made to look file system like, using the same commands to query and update.
This is at the heart of PowerShell. $foo is the value of variable foo, ${c:\foo.txt} is the content of file C:\foo.txt but used just like a variable. Equally dir HKLM:\Software lists the child keys of that registry key.
You can write you own providers.
There is an open source program, WinCDEmu that can mount an ISO image to a virtual drive. I suppose you'll be able to examine the sources to figure out how to provide a virtual drive that does what you want. The project is written in C++.
It is based on BazisLib, which is a framework for simplifying windows driver development.
On Ubuntu linux, when you watch a flash video, it gets saved temporarily in the /tmp as flv files while the video buffers. I use vlc to directly play these files.
Currently, I have scripted a shortcut that directly scans and opens the latest file in /tmp with vlc, when clicked.
But, I want to program a Java application that will continually monitor this /tmp directory for any new flv files, and open it in vlc automatically. I know I can use Runtime.exec() to open the VLC application with the flv files. But, I DO NOT want to run a while(true) loop (with sleep) to scan for files.
How can I make use of Event Handling (Java or any other language) on Linux to complete this task?
Edit:
I am also wondering if Java is the right way to approach this. As someone suggested below, Python and QT seem more appropriate.
For Python, use pyinotify: http://trac.dbzteam.org/pyinotify. It's a simple, standalone library; there's no need for an ugly Qt dependency for this.
Have you seen JNotify ? It's a Java library that uses OS-specific code to listen for filesystem events.
I wouldn't rule out polling the file system, however, unless you're dealing with a huge number of files/directories.
In Linux there something called FAM (File Alteration Monitor) which does a better job than the sleep/poll thing.
There's a python package for it as well: Python FAM
It is probably going to be a lot less to depend on than for example QT.
I would recommend Qt and Python.
I've used PyQt for a similar project before. Qt has a file system watcher that monitors directories and files for updates, which trigger events that you can catch and do stuff (like open vlc).
QFileSystemWatcher
If this is something you just want to always run in the background, Qt also has a feature that allows you to run your program in the System Tray. This is what I did, and just added a menu or two to make modifications.
QSystemTrayIcon
For Python, you can try this this, I find it simpler than pyinotify.