Thread: Random CRC works "kinda"

  1. #1
    Registered User
    Join Date
    Aug 2009
    Posts
    8

    Random CRC works "kinda"

    Ok so I been browsing the web and asking for help and I got some help and this is what we have come up with. The goal to write random bytes in my DLL file, each time i load it. However it only randomizes the DLL crc 1 time.

    The .exe file is the one that reads out the DLL bytes and then writes over certain area randomly, but I dunno why it is only random crc 1 time..

    Heres the code.

    in the DLL.

    Code:
    
    
    Been trying to figure it out for days now, no luck.

    Again first run of the exe. the dll randomizes the crc, 2nd time and 3rd and so on, nothing even though its still writing..

    ty
    Last edited by RedRover; 08-26-2009 at 01:18 PM.

  2. #2
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    There are at least two problems here. First of all, string literals are pointers, so SIZEOF_STAMP(UNIQUE_STAMP_BEGIN) == sizeof( char* ). Second, a PRNG is deterministic - seed it with some number N and it will generate the same values every time. In this case, you're attempting to initialize it with itself, meaning N never changes.

  3. #3
    Registered User
    Join Date
    Aug 2009
    Posts
    8
    Quote Originally Posted by Sebastiani View Post
    There are at least two problems here. First of all, string literals are pointers, so SIZEOF_STAMP(UNIQUE_STAMP_BEGIN) == sizeof( char* ). Second, a PRNG is deterministic - seed it with some number N and it will generate the same values every time. In this case, you're attempting to initialize it with itself, meaning N never changes.
    PRNG you mean the rand() ?

    What 'N' are you talking about.

  4. #4
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    >> PRNG you mean the rand() ?

    Yes, as in psuedo-random number generator.

    >> What 'N' are you talking about.

    The number you pass to srand(). For example, this program will always generate the same numbers (when compiled with the same rand() implementation):

    Code:
    int main( void )
    {
    	srand( 3114 );
    	for( ;; )
    	{	
    		printf( "%d\n", rand( ) );
    	}	
    	return 0;
    }
    In other words, you're initializing rand with rand, so the result is the same every time. Does that make sense?

  5. #5
    Registered User
    Join Date
    Aug 2009
    Posts
    8
    Ah I see, so how can I create purely random outcomes then.

  6. #6
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    Strictly speaking, PRNG's don't generate random sequences (hence "psuedo"). Anyway, the standard approach is to use time(NULL) as the seed.

  7. #7
    Registered User
    Join Date
    Aug 2009
    Posts
    8
    Works perfect! Awesome man, I thought the problem was way more complicated. After my week of hell you fixed it with that.

  8. #8
    Registered User
    Join Date
    Aug 2009
    Posts
    8
    I dont know if you can answer this or not, but for some reason when my file is 600 kb , this works, but if I pack / encrypt it so people cannot break my software protection, this fails, and gives a runtime error at the assert line.

    After packing its nearly 1.6 mb.

    If its packed does it become unreadable? I mean, so we wont find our signature string.


    http://i29.tinypic.com/10emv6s.png
    Last edited by RedRover; 08-26-2009 at 03:19 AM.

  9. #9
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    Well naturally, if it's encrypted it's going to have to be decoded before the check can be made.

  10. #10
    Registered User
    Join Date
    Aug 2009
    Posts
    8
    Right, so I guess the only way to go is without encrypting it.

  11. #11
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    I don't actually get how the copy protection works, though. Could you elaborate on that?

  12. #12
    Registered User
    Join Date
    Aug 2009
    Posts
    8
    What do you mean the copy protection, do you mean the software protection to prevent people from sending the application out to their friends and their friends from being able to use it?

    If thats what you mean, the protection just checks for a computers hardware information as the program is locked to certain computers, and the information is hardcoded into the application. I know it sucks, but for my skill level theres not much of a choice.

    And thats why I need to encrypt, so people cant easily get these HWIDs and then use it to fake their own in a patched copy.
    Last edited by RedRover; 08-26-2009 at 03:35 AM.

  13. #13
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    Right, the software protection scheme you're going for.

  14. #14
    Registered User
    Join Date
    Aug 2009
    Posts
    8
    Edited my post above

  15. #15
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    Ok, I see. Well at the very least you could use a simple XOR encryption (with 0xff, perhaps) scheme to make the data less obvious. Another (but slightly more extreme) approach would be to issue a unique ID (and embed that value) in the application, and require that the user connects to a network, sending the ID and HW info, at which point you could simply compare the information with what you have in a database. It's not bulletproof, either, but a bit more robust, anyway (if not somewhat intrusive).

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Generating random letters
    By ominub in forum C Programming
    Replies: 6
    Last Post: 04-29-2009, 01:12 AM
  2. random numbers
    By mesmer in forum C Programming
    Replies: 4
    Last Post: 10-24-2008, 01:22 PM
  3. How do I restart a random number sequence.
    By jeffski in forum C Programming
    Replies: 6
    Last Post: 05-29-2003, 02:40 PM
  4. Generate random numbers in Lucky7 project using C#
    By Grayson_Peddie in forum C# Programming
    Replies: 1
    Last Post: 04-11-2003, 11:03 PM
  5. Best way to generate a random double?
    By The V. in forum C Programming
    Replies: 3
    Last Post: 10-16-2001, 04:11 PM