SA-MP Forums Archive
[Tool/Web/Other] Protect your Script - pawn_protect.exe - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Filterscripts (https://sampforum.blast.hk/forumdisplay.php?fid=17)
+---- Forum: Tools and Files (https://sampforum.blast.hk/forumdisplay.php?fid=82)
+---- Thread: [Tool/Web/Other] Protect your Script - pawn_protect.exe (/showthread.php?tid=314468)



Protect your Script - pawn_protect.exe - Gh05t_ - 29.01.2012

Highly Recommended: Backup your gamemode (.pwn file)

What is this?
pawn_protect.exe is an application in which formats your .pwn file to unreadable code in which may only be deciphered through a code from values of 0 - 700. The application seems to be most useful to those whom are extremely 'careful' regarding their script.

Instructions:
1. Download the application.
2. Extract the application to the folder containing your gamemode (.pwn).
3. Execute the application.

How to use? Downloads:
http://www.sendspace.com/file/fzyvru
http://www.mediafire.com/?6p9za3nlo6b4ovv

Source:
Код:
#include <iostream>
#include <windows.h>
#include <stdio.h>
#include <fstream>
using namespace std;

void enc(char * _cEnc, int _shf);
void dec(char * _cDec, int _shf);

void enc(char * _cEnc, int _shf)
{
     for(int i=0; _cEnc[i] != '\0'; ++i)
      _cEnc[i]+=_shf;

}

void dec(char * _cDec, int _shf)
{
     for(int i=0; _cDec[i] != '\0'; ++i)
     _cDec[i]-=_shf;
}

int main (void)
{

    string _input;
    string _filename;
    int _code;

    system("title script_protect.exe");
    cout << "Author: Gh05t\nDate Published: 1/28/12\nVersion: 1.0.0\n\n";

EXECUTE:
    cin >> _input;

    if(_input == "format")
    {
        cout << "Filename: ";
        cin >> _filename;

        string _pwn_filename = _filename + ".pwn"; //append...

        ifstream file(_pwn_filename.c_str());
        if(!file.good())
        {
            cout << "[Error]: " <<"unable to retrieve " << _pwn_filename << "! \n\n";
            file.close();
            goto EXECUTE;
        }
        else
        {
    CODE:
            cout << "Insert a code (values from 0 - 700): ";
            cin >> _code;

            if(_code < 1 || _code > 700)
            {
                cout << "[Error]: invalid code.\n\n";
                goto CODE;
            }

            string _pwn2_filename = _filename + ".pwn2"; //format...
            ofstream _pwn2_filecreate(_pwn2_filename.c_str());

            string _data;
            char _cStr[999999];

            ifstream _file_1;
            _file_1.open(_pwn_filename.c_str());

            ofstream _file_2;
            _file_2.open (_pwn2_filename.c_str());

            cout << "Formatting..." << endl;
            while(_file_1)
            {
                getline(_file_1, _data);
                //cout << _data << endl;
                strcpy(_cStr, _data.c_str()); //to char...
                enc(_cStr, _code);
                _file_2 << _cStr << endl;

            }
            _file_1.close();
            _file_2.close();
            file.close();
            cout << "Formatting completed!\n" << endl;
            remove( _pwn_filename.c_str() );
            goto EXECUTE;
        }
    }

    else if(_input == "access")
    {
        cout << "Filename: ";
        cin >> _filename;
        string _pwn2_filename = _filename + ".pwn2";

        ifstream file(_pwn2_filename.c_str());
        if(!file.good())
        {
            cout << "[Error]: " <<"unable to retrieve " << _pwn2_filename << "! \n\n";
            file.close();
            goto EXECUTE;
        }
        else
        {
    CODE2:
            cout << "Code: ";
            cin >> _code;
            if(_code < 1 || _code > 700)
            {
                cout << "[Error]: invalid code.\n\n";
                goto CODE2;
            }

            string _pwn_filename = _filename + ".pwn";
            ofstream _pwn_filecreate(_pwn_filename.c_str());

            string _data;
            char _cStr[999999];

            ifstream _file_1;
            _file_1.open (_pwn2_filename.c_str());

            ofstream _file_2;
            _file_2.open(_pwn_filename.c_str());

            cout << "Formatting..." << endl;
            while(_file_1)
            {
                getline(_file_1, _data);
                //cout << _data << endl;
                strcpy(_cStr, _data.c_str()); //to char...
                dec(_cStr, _code);
                _file_2 << _cStr << endl;

            }
            _file_1.close();
            _file_2.close();
            file.close();
            cout << "Formatting completed!\n" << endl;
            remove( _pwn2_filename.c_str() );
            goto EXECUTE;

        }
    }

    else if(_input != "format" || _input != "access")
    {
        cout << "[Error]: invalid command(_input)\n\n";
        goto EXECUTE;
    }
    goto EXECUTE;
}
Special Thanks
Kyosaur - Support and help whenever needed.

Note: The source is C++, NOT PAWN related material. I've managed to make it as less redundant though the algorithm in my opinion is completely absurd but is the only way I could have thought of. Some techniques used are frowned upon by myself including some c-style methods, usage of goto etc. If you have any questions, comments, please feel free to post.


Re: Protect your Script - pawn_protect.exe - steki. - 29.01.2012

pawn Код:
void enc(char * _cEnc, int _shf)
{
     for(int i=0; _cEnc[i] != '\0'; ++i)
      _cEnc[i]+=_shf;

}
Seriously?

btw Isn't it:

pawn Код:
void enc(char * _cEnc, int _shf)
{
     for(int i=0; *_cEnc[i] != '\0'; ++i)
      *_cEnc[i]+=_shf;

}



Re: Protect your Script - pawn_protect.exe - Gh05t_ - 29.01.2012

Quote:
Originally Posted by Stewie`
Посмотреть сообщение
pawn Код:
void enc(char * _cEnc, int _shf)
{
     for(int i=0; _cEnc[i] != '\0'; ++i)
      _cEnc[i]+=_shf;

}
Seriously?
What seems to be the issue?


Re: Protect your Script - pawn_protect.exe - steki. - 29.01.2012

I'm saying it's too simple. From now on every guy that sees a file .pwn2 will take the difference between the real EoF and the cripted one and boom. I got the key.

Not to mention that scripts can have characters up to the char limit.


Re: Protect your Script - pawn_protect.exe - Gh05t_ - 29.01.2012

Quote:
Originally Posted by Stewie`
Посмотреть сообщение
btw Isn't it:

pawn Код:
void enc(char * _cEnc, int _shf)
{
     for(int i=0; *_cEnc[i] != '\0'; ++i)
      *_cEnc[i]+=_shf;

}
http://www.cplusplus.com/doc/tutorial/pointers/

Quote:
Originally Posted by Stewie`
Посмотреть сообщение
From now on every guy that sees a file .pwn2 will take the difference between the real EoF and the cripted one and boom. I got the key.
Interesting. Though you aren't the first, I am glad you've made this point. I am now eager to change the encryption method used. You are right, it is basic, but if you don't mind, may YOU please attempt to do what you have stated and get back to me with the results?

Quote:
Originally Posted by Stewie`
Not to mention that scripts can have characters up to the char limit.
I have taken this into consideration when I BEGAN the project. I have done tests on gamemodes such as Raven's Roleplay (containing 83,637) lines of coding. The conversion was pretty quick (about 2-3 seconds if I'm not mistaken).


Re: Protect your Script - pawn_protect.exe - steki. - 29.01.2012

About the last point I mentioned, you're using the buffer structure as char, that means that you're using 8bit of memory per index, that means you have the limit of 255. Any character like г й н х etc would no be parsed correctly, prejudicing the data.

I suggest you you use some cryptography like whirlpool, aes, sha, etc.


Respuesta: Re: Protect your Script - pawn_protect.exe - TheChaoz - 30.01.2012

I'd suggest u to use a better algorithm, or a better method. May blok cipher or stream cipher.

Quote:
Originally Posted by Stewie`
Посмотреть сообщение
I suggest you you use some cryptography like whirlpool, aes, sha, etc.
What for? Whirlpool, aes, sha, and algorithms like that are called one-way, and guess what? (yes!) you can't get the original text from the generated code.


Re: Respuesta: Re: Protect your Script - pawn_protect.exe - Bakr - 30.01.2012

People who get their scripts 'stolen' from someone have made the mistake of uploading it somewhere or physically giving it to someone else. I doubt people who do such will have the capabilities of downloading this (very limited) protective application.


Re: Respuesta: Re: Protect your Script - pawn_protect.exe - Gh05t_ - 30.01.2012

Quote:
Originally Posted by Bakr
Посмотреть сообщение
People who get their scripts 'stolen' from someone have made the mistake of uploading it somewhere or physically giving it to someone else. I doubt people who do such will have the capabilities of downloading this (very limited) protective application.
This is true. Though with detailed instructions given, I don't see how this becomes impossible regardless if their incapable of completing even the simplest of tasks. The application in my opinion doesn't seem to be as "limited" as you or anyone sought out to be. The algorithm or method used in this case, is basic but I have yet to see something like this created and supported. I will change the technique, in the meantime, unless anyone comes up with a method to decrypt an encrypted file with no code, the application will remain at it's current state until I have found a most better method.


Respuesta: Re: Respuesta: Re: Protect your Script - pawn_protect.exe - TheChaoz - 30.01.2012

Quote:
Originally Posted by Gh05t_
Посмотреть сообщение
unless anyone comes up with a method to decrypt an encrypted file with no code, the application will remain at it's current state until I have found a most better method.
Just brute force. Make a loop from 1 To 699 and u know all posible keys, just decript each one with the key, then if a known word like "include" or "public" is founded u got the real key, if not just skin next and try again.
Actually pretty simple to code.