News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

examples needed

Started by nrdev, May 28, 2009, 10:19:54 PM

Previous topic - Next topic

Mark Jones

What kind of numbers? ASCII? Literal? Bytes? Words? DWORDs? QWORDs? Floating-point?


.data
    nMyArray    dd 0,1,2,3,4,5,6,7,8,9


Access the value by some index n:


    mov eax,[nMyArray+n*4]


http://www.masm32.com/board/index.php?topic=8286.0
"To deny our impulses... foolish; to revel in them, chaos." MCJ 2003.08

nrdev

The idea of thee array is this: I need two arrays one for the numbers from 0 to 9, adn one for asci characters from a to z. From witch program should random pick  numbers and letters. But I don't know how to do that.

BogdanOntanu

Question: What is the purpose of this program you want to create?

Ambition is a lame excuse for the ones not brave enough to be lazy.
http://www.oby.ro

Jimg

It looks like a password generator to me.  Helps a user create a secure password to use.
Or possible a serial number generator?

.data
mychrs db "0123456789abcdefghijklmnopqrstuvwxyz",0
.code
.
.
.
invoke nrandom,35              ; this is a routine in m32lib, fil=nrand.asm
mov cl,byte ptr mychrs[eax]  ; random character no in cl.

edit:  looks like it has to be 36.  Here's my actual test code that works-

.data
mychrs db "0123456789abcdefghijklmnopqrstuvwxyzX",0
newpass db 200 dup (0)
.code
mov esi,199
lea edi,newpass
.repeat
    invoke nrandom,36              ; this is a routine in m32lib, fil=nrand.asm
    mov cl,byte ptr mychrs[eax]  ; random character no in cl.
    mov [edi],cl
    inc edi
    dec esi
.until zero?
invoke MessageBox,0,addr newpass,0,0
ret   


By the way, your original test program posted above has an error-

.code

      GLOBAL Btn1           dd ?
      GLOBAL Btn2           dd ?
      GLOBAL Btn3           dd ?
      GLOBAL Group1         dd ?
      GLOBAL Group2         dd ?
      GLOBAL Group3         dd ?
      GLOBAL hProgress      dd ?
      GLOBAL hInstance      dd ?
      GLOBAL hIcon          dd ?

      invoke InitCommonControls
      mov hInstance, FUNC(GetModuleHandle,NULL)
      call main
      invoke ExitProcess,eax

; -------------------------------------------------------------------------

start:

main proc

    LOCAL lpArgs:DWORD



You started .code before some data statements.  The code before the start: will never be executed.  It only works because the program starts running at the start: label and falls right into main.

dedndave

#19
you'll spend more time making a good random number generator - lol

for simple tasks, you can use some low-order bits from QueryPerformanceCounter
as for the arrays, you don't neccessarily need to have them
just write a rountine that spits out random ASCII chars in eax or al

RChar   PROC

        sub     esp,8

RChar0: INVOKE  Sleep,1
        INVOKE  QueryPerformanceCounter,esp
        mov     eax,[esp]
        and     eax,7Fh
        or      al,20h
        cmp     al,'0'
        jb      RChar0

        cmp     al,'9'
        jbe     RChar1

        cmp     al,'a'
        jb      RChar0

        cmp     al,'z'
        ja      RChar0

RChar1: add     esp,8
        ret

RChar   ENDP

something like that should work

EDIT - i mentioned this program to Hutch - he seems ok with it

EDIT - there are better ways to do it - you could force all values from the performance counter to be valid
        with a little manipulation - would be a much better routine - and you could then take out the sleeper

nrdev

I have made this program before but in basic, it didn't used any letters. If this program looks suspicious to someone it is not some illegal program. The pourpose of this program is to serve as a support utillity for creation serial numbers for protection from piracy. It should generate random combination of the letters and numbers so it can be used to protect any software. You know the thing when you need to type-in the registration code for continuing of installation, or to register some product from shareware to full version, and such.
Maybe it isn't some protection software but it's mine.

Mark Jones

There are many reversing/cracking/security forums out there, by the way. Just google and you will find many. Ask questions there if this forum is too restrictive for you. Most of those people will know assembler well anyways...
"To deny our impulses... foolish; to revel in them, chaos." MCJ 2003.08

PBrennick

dedndave,

I think

        INVOKE  QueryPerformanceCounter,esp

should be

        INVOKE  QueryPerformanceCounter,esi

Paul
The GeneSys Project is available from:
The Repository or My crappy website

dedndave

lol - thanks Paul
actually we were both half-right
i have the output going to the stack (scratch-pad)

the bad guy was: mov eax,[esi]  sh be: mov eax,[esp]

PBrennick

I know, I had to take a guess which was wrong.

Paul
The GeneSys Project is available from:
The Repository or My crappy website

nrdev

Jimg have posted the right thing, but that code can't generate truly random numbers. I'am a bit confused I find randlib, that maybe can help me on this. But I doesn't understand what should be a DWORD type. Is it a number or char or what, how can I use that evry function in masm is different and all of the have this?

dedndave


db 'A',0FFh            ;bytes
dw 0FFFFh              ;word = 2 bytes
dd 0FFFFFFFFh          ;dword (double word) = 2 words
dq 0FFFFFFFFFFFFFFFFh  ;qword (quad word) = 4 words

nrdev

that is way I have asked this question


InitRand PROTO :DWORD,:DWORD


All functions in masm have this format, so how can I use this function

dedndave

that proto tells you that the function has (2) dword parameters
i don't know where the function InitRand is located, and i see no documentation for it

nrdev