View Full Version : Random Data
Maze
April 21st, 2009, 17:13
At any point in assembly code, is there any way to generate/get random numbers and/or letters ?
I have limited space in an installation program that unpacks some files.
During the unpacking I can find/replace a server check.
Instead of replacing the server domain name with something static, I'd like to replace the domain with some random number&letters.
Thanks!
squidge
April 22nd, 2009, 07:15
Try mutilating GetTickCount()'s result, thats going to be pretty random unless of course you run the program at the exact same tick count after bootup every time

Maze
April 22nd, 2009, 14:53
Can I access it in memory ?
RDTSC or reading 0x7ffe0004 ?
squidge
April 22nd, 2009, 16:27
Sure, RDTSC will work, or you can import GetTickCount from kernel32 dll. They give you different data, but since you don't care about it, RDTSC will be the easiest (as long as TSD in CR4 isn't set, I believe).
darawk
April 22nd, 2009, 20:15
IBM has a library called truerand which extracts entropy from the oscillations between the CPU and motherboard clock crystals and then runs it through an entropy purification algorithm to generate what is essentially truly random bits. I'm not sure how important the randomness is in whatever you're doing, but it doesn't get much more random than that.
fuex
April 25th, 2009, 09:35
If you don't need highly random numbers (i.e, for cryptography), a simple "Linear congruential generator" may be suitable.
http://en.wikipedia.org/wiki/Linear_congruential_generator ("http://en.wikipedia.org/wiki/Linear_congruential_generator")
You could just have a look at the source code of some rand() implementations in some libraries (like libc) and try to do exactly the same.
For the seed, use GetTickCount.
Powered by vBulletin® Version 4.2.2 Copyright © 2018 vBulletin Solutions, Inc. All rights reserved.