[Lib] LOVEE [Love Encryption] Encrypt lua files & Images

Showcase your libraries, tools and other projects that help your fellow love users.
azin
Prole
Posts: 26
Joined: Sat Sep 12, 2009 9:39 pm

[Lib] LOVEE [Love Encryption] Encrypt lua files & Images

Post by azin »

So the other day i lost one of my love2d projects, but had only a .exe packed version of it. A few modifications and coding later i was able to make a tool that could extract the .love/.zip resource from the .exe and found out that i could extract the resources from any love2d .exe so i didn't feel safe and decided to code an encryption library. I won't be releasing that tool since i don't think developers would like that including myself lol.

If you use this library i suggest that you make a backup of your files since i only coded the encryption for one way there is no decrypt option. There are 3 total options for the encryption library, Obfuscator, Obfuscator + Encryption, and Encryption. with this library you can also load an encrypted image using the IMGEncrypt tool.

Some pointers if you Obfuscate your code you must change the data = {} array name and in the loadFile(MyDataArrayName, key) to load it.
For encrypted images love.graphics.newImage(imgData) always stays the same, but you can assign the image variable name and call the draw later on.

The IMGEncrypt tool should only be used for small-medium images nothing crazy like a background/wallpaper image it might work, but will either cause the application to hang or take a long time to encrypt.

Functions to load the encrypted files:

Code: Select all

Obfuscated code load:
love.filesystem.load("myEncryptedFile.lua")()
loadFile(dataArrayName, key)
	
Encrypted code load:
d=getData("myfile.lua", key)
loadData(d)
	
Obfuscated image load:
love.filesystem.load("encrypted_image.png")()
loadIMG(imgArrayName)
image = love.graphics.newImage(imgData)

Basic Set-up

Code: Select all

require("LOVEE")

init() --Initiate the encryption lib

function love.load()
love.filesystem.load("MYencryptedIMAGE.png")()
loadIMG(MyImage)
image = love.graphics.newImage(imgData)
end

function love.update(dt)

end

function love.draw()
love.graphics.draw(image, 0, 0)
end
LOVEE Lib:
https://www.mediafire.com/?l8h2vgm665ftmya

IMGEncrypt tool:
http://www.mediafire.com/download/262p5 ... ncrypt.exe

LOVEE Encryption site:
http://elovee.tk

Encrypted Example w/ Original unencrypted lua file: (Just use the keys w, a, s, d to move the image)
https://www.mediafire.com/?kp1qo21ly0azuo8
User avatar
Duster
Prole
Posts: 32
Joined: Fri Dec 19, 2014 8:34 pm
Location: Ontario, Canada

Re: [Lib] LOVEE [Love Encryption] Encrypt lua files & Images

Post by Duster »

azin wrote: i was able to make a tool that could extract the .love/.zip resource from the .exe
You can view the source by simply changing .exe to .love or .zip, no tool required.
User avatar
zorg
Party member
Posts: 3465
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: [Lib] LOVEE [Love Encryption]

Post by zorg »

azin wrote:So the other day i lost one of my love2d projects, but had only a .exe packed version of it. A few modifications and coding later i was able to make a tool that could extract the .love/.zip resource from the .exe and found out that i could extract the resources from any love2d .exe
Or alternatively, you just rename the .exe to .zip and open it; yes, you only append your love (which is a zip archive) to the love executable, on windows anyway; other os-es just share the .love file itself.
azin wrote:so i didn't feel safe and decided to code an encryption library.
It won't help stopping people from looking at the code.
azin wrote:I won't be releasing that tool since i don't think developers would like that including myself lol.
(If by that tool, you refer to the one you used to get the love file out of the executable,) Most OS-es have unzip and file renaming functionalities anyway.
azin wrote:If you use this library i suggest that you make a backup of your files since i only coded the encryption for one way there is no decrypt option.
Then the game itself would not run, since löve itself wouldn't understand the obfuscated/encrypted data; besides, there's no true one-way encryption that works without losing part of the original data (hash functions)
azin wrote:Some pointers if you Obfuscate your code you must change the data = {} array name and in the loadFile(MyDataArrayName, key) to load it.
Since i didn't see you define loadFile anywhere, i assume it's inside the init.lua you create with LOVEE.lua's init function, which is probably not encrypted.
Me and my stuff :3True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
azin
Prole
Posts: 26
Joined: Sat Sep 12, 2009 9:39 pm

Re: [Lib] LOVEE [Love Encryption] Encrypt lua files & Images

Post by azin »

I didn't know by renaming the .exe file we could take a look at the source that's interesting.

When you use the encode function at http://elovee.tk the encoded code comes out for example:

data = {"100", "101", "102"}

to be able to load this data into our game we must use love.filesystem.load("myfile.lua") then use the function loadFile(array, key)

once we use the love.filesystem.load()() we use loadFile(data, key) to decrypt and load the data.

so lets change the data = {} array name to msg

msg = {"104", "101", "108", "108", "111", "0"}

to use this Obfuscated code we do this:

Code: Select all

function love.load()
love.filesystem.load("myEncryptedFile.lua")()
loadFile(msg, key)
end
This also applies to the IMGEncrypt tool once it encrypts the image we have to open the image with notepad and where the array name "img = {" we change it so we can load other items to decrypt.

This is just an example on how to load it, the msg code above won't do anything.

If you take a look at the example that i provided above you would have a better understanding of how the files are loaded and used. the encrypted image open it with notepad and it has it's own assign array name "weezing"

and we load that image with this code"

Code: Select all

function love.load()
love.filesystem.load("enc_weezing.png")()
loadIMG(weezing) --The image array name, open the image with notepad and you will see this variable
weezing_img = love.graphics.newImage(imgData)
end

function love.update(dt)
end

function love.draw()
love.graphics.draw(weezing_img, x, y)
end
Then the game itself would not run, since löve itself wouldn't understand the obfuscated/encrypted data; besides, there's no true one-way encryption that works without losing part of the original data (hash functions)
Yes Love does not understand the Obfuscated/Encrypted code, but once you init() the library and use it's functions loadFile(array, key), loadData(data), loadIMG(array) it de-Obfuscated/decrypt the code making it readable for Love.
User avatar
zorg
Party member
Posts: 3465
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: [Lib] LOVEE [Love Encryption] Encrypt lua files & Images

Post by zorg »

azin wrote:but once you init() the library and use it's functions loadFile(array, key), loadData(data), loadIMG(array) it de-Obfuscated/decrypt the code making it readable for Love.
That creates a file called init.lua in the users' save directories; from then on, one can edit the functions inside it so that after decryption, the files are saved to the same place as well. (And as you demonstrated yourself, one can uncomment the love.filesystem.remove("init.lua") line from your lib, so it remains in that folder.)

If i haven't convinced you yet, i'll try to actually accomplish this, in a short while. :)
Me and my stuff :3True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
azin
Prole
Posts: 26
Joined: Sat Sep 12, 2009 9:39 pm

Re: [Lib] LOVEE [Love Encryption] Encrypt lua files & Images

Post by azin »

yeah i know it isn't the best method, the only secured way that i know of would to modify the love source to make this a much better solution
User avatar
Positive07
Party member
Posts: 1014
Joined: Sun Aug 12, 2012 4:34 pm
Location: Argentina

Re: [Lib] LOVEE [Love Encryption] Encrypt lua files & Images

Post by Positive07 »

Believe me, it's impossible, the best method I could think of as the best way to attempt this is having a key used to read a password protected zip, and store that key inside LÖVE's source code, then you would need some way to hide or obfuscate that key so that after compile it is not stored as a string, I would try to make the key repetitive and weird if possible, maybe base64 or something like that so that even with a hex editor it wouldn't be noticeable. Even then brute force or disassembling the exe would be all that is needed to break through

Your attempt is cr*p sorry, it is REALLY easy to un-encrypt your code, I just need to take your exe, rename it to zip, extract that into a folder (lets say "test") then just modify your lib so that all the files are saved to the save folder, run that with LÖVE, enjoy your source code!

Your best protection is LAW! Just put copyright and if someone tries to steal your property sue them. But believe me, no-one will try to still your game, you aren't making the next AAA game, winner of prices, or something like that.
for i, person in ipairs(everybody) do
[tab]if not person.obey then person:setObey(true) end
end
love.system.openURL(github.com/pablomayobre)
Atton
Prole
Posts: 15
Joined: Mon Aug 26, 2013 1:38 pm

Re: [Lib] LOVEE [Love Encryption] Encrypt lua files & Images

Post by Atton »

Try this.

Code: Select all

void encodeXtea(unsigned int* v, unsigned int* w, unsigned int* k) {
    register unsigned int v0=v[0], v1=v[1], i, sum=0;
    register unsigned int delta=0x9E3779B9;
    for(i=0; i<32; i++) {
       v0 += (((v1 << 4) ^ (v1 >> 5)) + v1) ^ (sum + k[sum & 3]);
        sum += delta;
        v1 += (((v0 << 4) ^ (v0 >> 5)) + v0) ^ (sum + k[(sum>>11) & 3]);
    }
    w[0]=v0; w[1]=v1;
}

void TeaEncode ( const std::string& str, const std::string& key, std::string* out )
{
    unsigned int v[2];
    unsigned int w[2];
    unsigned int k[4];
    unsigned int keybuffer [ 4 ];

    // Clear buffers
    memset ( v, 0, sizeof(v) );
    memset ( w, 0, sizeof(w) );
    memset ( k, 0, sizeof(k) );
    memset ( keybuffer, 0, sizeof(keybuffer) );
    out->clear ();

    // Process the key
    int len = key.length ();
    if ( len > 16 )
        len = 16;
    memcpy ( keybuffer, key.c_str(), len );
    for ( int i = 0; i < 4; ++i )
        k[i] = keybuffer[i];

    // Copy the input string to a buffer of size multiple of 4
    int strbuflen = str.length ();
    if ( strbuflen == 0 )
        return;
    if ( (strbuflen % 4) > 0 )
        strbuflen += 4 - (strbuflen % 4);
    unsigned char* strbuf = new unsigned char [ strbuflen ];
    memset ( strbuf, 0, strbuflen );
    memcpy ( strbuf, str.c_str(), str.length() );

    // Encode it!
    v[1] = 0;
    for ( int i = 0; i < strbuflen; i += 4 )
    {
        v[0] = *(unsigned int*)&strbuf[i];

        encodeXtea ( &v[0], &w[0], &k[0] );
        out->append ( (char*)&w[0], 4 );

        v[1] = w[1];
    }
    out->append ( (char*)&v[1], 4 );

    delete [] strbuf;
}



void decodeXtea(unsigned int* v, unsigned int* w, unsigned int* k) {
    register unsigned int v0=v[0], v1=v[1], i, sum=0xC6EF3720;
    register unsigned int delta=0x9E3779B9;
    for(i=0; i<32; i++) {
        v1 -= (((v0 << 4) ^ (v0 >> 5)) + v0) ^ (sum + k[(sum>>11) & 3]);
        sum -= delta;
        v0 -= (((v1 << 4) ^ (v1 >> 5)) + v1) ^ (sum + k[sum & 3]);
    }
    w[0]=v0; w[1]=v1;
}

void TeaDecode ( const std::string& str, const std::string& key, std::string* out )
{
    unsigned int v[2];
    unsigned int w[2];
    unsigned int k[4];
    unsigned int keybuffer [ 4 ];

    // Clear buffers
    memset ( v, 0, sizeof(v) );
    memset ( w, 0, sizeof(w) );
    memset ( k, 0, sizeof(k) );
    memset ( keybuffer, 0, sizeof(keybuffer) );
    out->clear ();

    // Count the number of passes that we need
    int numBlocks = str.length() / 4;
    int numPasses = numBlocks - 1;

    if ( numPasses <= 0 )
        return;

    // Process the key
    int len = key.length ();
    if ( len > 16 )
        len = 16;
    memcpy ( keybuffer, key.c_str(), len );
    for ( int i = 0; i < 4; ++i )
        k[i] = keybuffer[i];

    // Create a temporary buffer to store the result
    unsigned char* buffer = new unsigned char [ numPasses * 4 + 4 ];
    memset ( buffer, 0, numPasses * 4 + 4 );

    // Decode it!
    const char* p = str.c_str();
    v[1] = *(unsigned int*)&p[numPasses * 4];
    for ( int i = 0; i < numPasses; ++i )
    {
        v[0] = *(unsigned int*)&p[(numPasses-i-1)*4];
        decodeXtea ( &v[0], &w[0], &k[0] );
        *(unsigned int*)&buffer[(numPasses-i-1)*4] = w[0];
        v[1] = w[1];
    }

    out->assign ( (char *)buffer, numPasses*4 );
    delete [] buffer;
}


// Use xor for the key and xor it on the key it's self.
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: [Lib] LOVEE [Love Encryption] Encrypt lua files & Images

Post by Robin »

Atton wrote:Try this.
What's the name of that algorithm?
Help us help you: attach a .love.
User avatar
Azhukar
Party member
Posts: 478
Joined: Fri Oct 26, 2012 11:54 am

Re: [Lib] LOVEE [Love Encryption] Encrypt lua files & Images

Post by Azhukar »

Robin wrote:What's the name of that algorithm?
A few seconds of googling reveal "TEA algorithm".
Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 4 guests