I've been looking into centralising my computer game saves to make it easier to backup and restore as well as putting them up on the cloud via dropbox but there in so may places that it makes it quite difficult. I noticed the Windows 7 and Vista now support Symbolic links so I've been playing around with that but I was wonder the follow:
Is it possible (code example or a point in the right direction) for an application (vb.net or C++) to spoof a file or folder?
E.g. Application A (a game like Diablo III or Civilization V) attempts to read or right from file A (the game save), application B (the save repository) detects this read/write request and pipes the request through itself preforming the request on file B (the actual game save in another location). Application A is in no way altered and treats the file normally.
Note: I realise there are many simple ways of preforming the same task in essence such as monitoring the use of Application A or periodically checking file A and copying it if it has been altered since the last check etc but all these methods have draw backs and less interested in making it work than if it is possible.
It is entirely possible to do this through a file system filter driver. For information about these, take a look here:
http://msdn.microsoft.com/en-us/windows/hardware/gg462968
Filter drivers can hook into CreateFile operations and redirect the create to a different place if you want, but they are much harder to write as compared to normal applications. They run in kernel mode and must obey the limitations of drivers.
You can "fake" special folders, like control panel does, but I don't think you can create anything accessible/writeable (in an easy way). I might be wrong though. I had the same idea once too (as a compatibility step for some company stuff), but couldn't find anything supporting an easy way to do it. It seems like it might be easier to be done on Unix systems (but that's obviously no option here). Also, I wouldn't expect any nice or easy solutions for .net.
Only approach I could think about right now, would be highjacking the according API calls (e.g. FileOpen) to reroute/manipipulate them (similar to what root kits do), but I wouldn't say that's a good idea, considering it might be detected as possible malware or cheats by things like punkbuster or antivirus solutions.
Yes or no depending on (using your terms) the level of abstraction that Application A is using.
If Application A is performing a CreateFile wto start access and passing a fixed filesystem path then Application B would need to emulate a file system and do so in the kernel.
On the other hand if Application A were to user HTTP with RESTful URLs then the HTTP server could answer all requests from files or by dynamically creating the content.
So the question can only be answered in specific by knowing the details of Application A.
Related
I'm working on a GUI desktop application that should run natively on Windows, Mac OS X and Linux. What is the preferred way to store preferences in a cross-platform application? I'm using C++, but the question (and its answers) should be valid for any natively compiled language. (Solutions for dynamic languages and Java can be seen here.)
My research so far tells me, that there are at least two strategies:
(A) Use the OS-specific API preferences functions.
(B) Store the preferences in a file within an appropriate (OS-specific) folder.
Let's consider method (A): I assume NSUserDefaults is the correct method for Mac OS X. On Windows systems, I'd write to the registry via RegOpenKeyEx. But there arise some questions: Is there any comparable and portable Linux API for that? Is writing to the Windows registry really a future-proof solution?
To keep things simple, I'm inclined to follow method (B). Thus I just have OS-specific code to get the appropriate directory where I can store my data in a format of my choice. On Windows, I've learned SHGetFolderPath (or SHGetKnownFolderPath for recent Windows systems) and CSIDL_LOCAL_APPDATA is the way to go. On Macs, the NSSearchPathForDirectoriesInDomains API call should do the same; it's an Objective-C API though making things more complicated. Finally, for the Linux version using getenv("HOME") (and getpwuid() as a fallback solution) seems to be recommend.
To summarize my questions:
1. Are there any patterns considered as best-practice for this task?
2. Is there any C++ class abstracting all the dirty things like finding the correct folder away out there? (I came across QSetting, but I'm using FLTK and I don't want to change my GUI toolkit.)
Edit:
By "preferences" I mean data that may be changed by the application and the user, e.g. a list of recent files, the preferred window size and so on.
Since z80crew says he's using Fltk in his project, I think the best way to store small amounts of user data is through the Fltk Fl_Preferences class. (http://www.fltk.org/doc-1.3/classFl__Preferences.html).
That way, you don't have to care about where the user data is actually stored in the filesystem. You just create a Fl_Preferences object identified by the name of the application and its vendor (e.g., "CoolApp" and "AuthorOfCoolApp") and Fltk stores the data somewhere.
Under Linux, the preferences are stored in ~/.fltk/{vendor}/{application}.prefs where {vendor} and {application} are the same strings you've passed the constructor of Fl_Preferences. But you aren't supposed to worry about that.
I'm also developing a set of cross-platform plugins and did exactly what you describe in method (B):
Find the proper folder using platform specific code.
Write the preferences to that folder with cross-platform code.
I would also note that:
Using the Windows registry is very limited and problematic. I try to avoid that as much as possible.
Lately apple has a new song: that you should not access the ~/Library/Preferences folder directly but rather use their API for saving preferences value. In effect this turns the preferences into registry like mechanism. I very much resent this approach.
I do not know of any library that implements finding the currect folder in cross-platform manner. Such function is not very hard to write using SHGetKnownFolderPath and NSSearchPathForDirectoriesInDomains, as you described.
Hei there, I'm not experienced at all in C++ as I need to start learning year the next year at my university, though, I've been creating a browser based game and I'm looking for someone to transform it into pc app.
Though, I'm wondering how to make that application send a http request via POST to a file on my webserver with the username / pw.
After all the tutotials I've been reading, I concluded that none worth spending my time with, because they all based on own database, and I'm looking for one that connects to a maestro server and requests the data from there.
This may not be the answer you are looking for, but you may consider two alternatives to a more pure C++ application.
If you already have a working browser game, try to take that same code and put the html/javascript/whatever in a file and give the file a ".hta" extention. It basically opens inside a browser to run your files, but it acts more like an application from the user's viewpoint. (And, as much as I hate Windows, they're pretty fun to create if I may say so). However, your source code with this option is easily read because it can be renamed to a text file (or html file).
You could use Visual C++ (or VB.net, which you have tagged to the question, as well as "Visual" C#) to create an application which mostly consists of a browser view. It could be a "standalone" application (however would rely completely on the .Net framework - may or may not be what you want) that basically accomplishes the same as the option above, but adds that you can "hide" your files inside your application.
Using the two above alternatives, you could make an application relatively quickly that would load your files, which I assume you have already created. Note that neither of the above alternatives will work on anything other than Windows OS's.
If the two above alternatives are not what you want, or if you have questions about either one, I'd be glad to attempt to help.
I've been able to find a friend that would do it in Delphi because I wouldn't want users to download net framework just for this ap.
So the program that would fit most for any apps is Delphi Prism XE (even if it's an addon of Visual Studio)
I have been tasked with the creation of a desktop application within some very rigid constrains. The first version of the application was quite small, only intended for some specific tasks, but it seems like the application was quite liked, so I've been asked to improve it a lot.
The initial app I created was made as a hta with heavy doses of javascript and jquery, using a XML to store information (through MSXML2.3.0), but the increased amount of data makes me think it won't be able to keep up with the requirements, so I wanted to remake the application on a more solid base. Of course, I'd rather keep the interface more or less consistent with what I've already shown, and I'd prefer not having to rewrite all the code.
The restrictions are as follows:
-Desktop application. I cannot develop a web application, as not a single target computer has a solid internet connection.
-No need of installation (copying and pasting the folder should work, and should keep all the data consistent).
-Should be relatively multi plataform. The only information I have about the target machines is that all of them have a windows XP OS or newer, a MS Office 2003 suite or newer, and some kind of PDF reader.
-Should be able to embed and show different file types, such as diferent image formats, pdfs, and office documents. That said, for office documents, as long as I can link to the document and open it by instanciating a common MS Word/Excel/wathever app, it should be good enough, although interoperativity with the suite would be great.
I've been searching through the net, and I've found some interesting options, but I'm not sure about them.
On one side, I think XML won't be able to keep up, although I suppose I could make it work if I distribute the data through several xml files. I've been reading about open source embedded databases, such as SQLite, and it looks like this could work.
On the other side, I feel like the hta basis I'm using isn't going to work that well if the application keeps growing. I've checked lots of alternatives, but all of them give me some problems.
Cappuccino or Chromeless looks like good ideas, but both of them require a certain degree of HTML5, which is something I can't be sure the machine's browser will support enough. Also, NativeHost for Cappuccino seems to work only on Mac OSX. Xul looks interesting, but unusable.
Another option I've found is porting the app to Qt, but I don't know how hard would be porting the app to Qts, and it looks like I can only use the ActiveX needed for the embedding of MS Office applications with a proprietary license. Although that's comparatively less important, but I'm sure in the future I'll want to include those features.
That's how I stand. Do you think keeping the hta + XML architecture (or any variation thereof) could still work? Do any of the alternatives I've mentioned be viable? Do you know any other alternative?
I'm looking to create a "driver" I guess for a custom file system on physical disk for Windows. I don't exactly know the best way to explain it, but the device already has proper drivers and everything like that for Windows to communicate with it, but what I want to happen is for the user to be able to plug the device in to their PC, have it show up in My Computer, and give them full support for browsing the device.
I realize it's probably a little scary thinking about someone who doesn't know the basics of doing something like this even asking the question, but I already have classes and everything constructed for reading it within my own app... I just want everything to be more centralized and without more work from the end user. Does anyone have a good guide for creating a project like this?
The closest thing I know of to what I understand from your description is an installable file system, like the Ext2 installable file system that allows Windows computers to work with
Linux originating ext2 (and to a certain degree ext3) filesystems.
Maybe that can serve as a starting point for your investigations.
As an alternative approach there's the Shell extension which is a lot less complicated than the IFS. The now-defunct GMail shell extension used that approach, and even though it's become nonfunctional due to changes in GMail, it can still serve as inspiration.
Your options are:
Create a kernel mode file system driver. 9-12 months of work for experienced developer.
Use a framework and do everything in user mode. A couple of weeks of work to get the prototype working. The only drawback of this approach is that it's slower, than kernel-mode driver. You can play with Dokan mentioned above, or you can use our Callback File System for commercial-grade development.
I think you need to look through the Windows Driver Kit documentation (and related subjects) to figure out exactly what you're looking to create.
If you're intending to rely on the drivers that already exist, i.e. you don't need to actually execute your code in kernel land to communicate with it, I would recommend you take a look at FUSE for windows Dokan
If you indeed need to run in kernel space, and communicate directly with the hardware, you probably want to download windows DDK (driver development kit). Keep in mind that drivers for communicating with a block device and filesystems are separated, and it sound like you're talking about the filesystem itself. I believe that anything you run in kernel space will not have access to the c++ runtime, which means you can only use a subset of c++ for kernel drivers.
I have a program that is using a configuration file.
I would like to tie the configuration file to the PC, so copying the file on another PC with the same configuration won't work.
I know that Windows Activation Mecanism is monitoring hardware to detect changes and that it can tolerates some minor changes to the hardware.
Is there any library that can help me doing that?
My other option is to use WMI to get Hardware configuration and to program my own tolerance mecanism.
Thanks a lot,
Nicolas
Microsoft Software Licensing and Protection Services has functionality to bind a license to hardware. It might be worth looking into. Here's a blog posting that might be of interest to you as well.
If you wish to restrict the use of data to a particular PC you'll have to implement this yourself, or find a third-party solution that can do this. There are no general Windows API's that offer this functionality.
You'll need to define what you currently call a "machine."
If I replace the CPU, memory, and hard drive, is it still the same computer? Network adaptor, video card?
What defines a machine?
There are many, many licensing libraries out there to do this for you, but almost all are for pay (because, ostensibly, you'd only ever want to protect commercial software this way). Check out what RSA, Verisign, and even microsoft have to offer. The windows API does not expose this, ostensibly to prevent hacking.
Alternately, do it yourself. It's not hard to do, the difficult part is defining what you believe a machine to be.
If you decide to track 5 things (HD, Network card, Video card, motherboard, memory sticks) and you allow 3 changes before requiring a new license, then users can duplicate the hard drive, take out two of the above, put them in a new machine, replace them with new parts in the old machine and run your program on the two separate PCs.
So it does require some thought.
-Adam
If the machine has a network card you could always check its mac address. This is supposed to be unique and checking it as part of the program's startup routine should guarantee that it only works in one machine at a time... even if you remove the network card and put it another machine it will then only work in that machine. This will prevent network card upgrades though.
Maybe you could just keep something in the registry? Like the last modification timestamp for this file - if there's no entry in the registry or the timestamps do not match then fall back to defaults - would that work? (there's more then one way to skin a cat ;) )