Function Encryption/Decryption

Jul 7, 2012 at 5:31am
I saw some sample on some site but i can't seems to make it to work.

1
2
3
4
5
6
for(unsigned char* p = __START; p < __FINISH; p++)
{ p[0] = p[0] ^ key; }
__START:
MessageBoxA(NULL, "HELLO", NULL, MB_OK);
__FINISH:
return 0;


Does anyone have some working example that works much like above sample?

Thanks.
Jul 7, 2012 at 8:40am
That's a simple XOR. What do you mean you can't make it work?
Jul 7, 2012 at 1:41pm
Just wondering why the leading underscores in you variable names? There is normally no need for this.

Have you initialised __START, and __FINISH?

You have labels, __START: and __FINISH: this implies you are using goto's somewhere, which is very bad practice. Also why are the label names the same as your 2 variables? I wonder if there is some confusion about the use of the for loop.


Jul 8, 2012 at 1:21am
@kbw

I know its a simple XOR but when i compile the sample, i got compilation error...

@TheIdeasMan

As i stated above, that's the sample i got from other site, it just a sample on how to crypt a function/code, once on runtime, the function/code will be decrypted and can be use by our program.

The coder of that sample did mention its just a sample and he didn't test it but that show how it should look like. He had a working code but he didn't want to post it =\
Last edited on Jul 8, 2012 at 1:22am
Jul 8, 2012 at 2:11am
That code is going to encrypt the correct assembly and turn it into gibberish. The machine will then try to run that gibberish and then who knows what? If you want to encrypt parts of the executable, they would already have to be encrypted so that code can then decrypt it. I'm not entirely sure how one would go about encrypting specific parts of an exe like that... easily at least. You could put the sensitive code into a separate exe, then encrypt that and ship it with a second exe that decrypts then runs the first exe. You could use DLLs too.
Jul 8, 2012 at 7:11am
@ModShop

Well, i just want to see a working function/code encryption/decryption so i could learn from it. There is an application/protector which has a function to encrypt/decrypt code on runtime. This method will work as an anti tempering so it would make RE a bit confusing.

Anyway thanks for all of the responses :)
Jul 8, 2012 at 9:52am
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#include <iostream>
#include <string>

std::string encode(const std::string &in, const char key = 'A')
{
        std::string out("", in.size());

        for (size_t i = 0; i != in.size(); ++i)
                out[i] = in[i] ^ key;

        return out;
}

int main()
{
        std::string in;
        std::cin >> in;

        std::string en = encode(in);
        std::string de = encode(en);

        std::cout << "in string: " << in << std::endl;
        std::cout << "encoded string: " << en << std::endl;
        std::cout << "decoded string: " << de << std::endl;

        return 0;
}
Topic archived. No new replies allowed.