Masm32 SDK description, downloads and other helpful links
Message to All Guests

Main Menu

Random string generator function

Started by hutch--, October 26, 2020, 12:47:21 PM

Previous topic - Next topic


I had a use for this recently, it was for making Window class names obscure and different each time an app starts. It is also useful for registering private messages.

    PM_CHANNEL1 = RegisterWindowMessage(randstr(128))
    szClassName  = randstr(64)

What you end up with is an ugly pile of binary crap that is different each time the app starts.

' ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

FUNCTION randstr(ByVal ccnt as DWORD) as STRING


    LOCAL var as DWORD
    LOCAL cnt as DWORD

    ! rdtsc
    ! bswap eax
    ! mov var, eax

    randomize var

    src$ = ""

    cnt = 0
    ! mov esi, ccnt

    src$ = src$ + chr$(rnd(0,255))
    ! add cnt, 1
    ! cmp cnt, esi
    ! jne lbl

    FUNCTION = src$


' ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤


hi hutch
why did you make the random number range between 0 and 255 ? , I assume that's what rnd(0,255) does?
I would have restricted the range between 32 and 127
your function works quite well, it was simple to translate to FreeBasic :)


Hi Jack,

Wider range (0 to 255) has more variation, I tested it with all lower case but including all of the ASCII range made the output even messier which is exactly what I wanted. Makes finding a window class string or a private message string even harder to perform.