News:

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

nested loops?

Started by marla, February 16, 2006, 04:14:09 PM

Previous topic - Next topic

hutch--

Perhaps these trailing discussions should be posted in another subforum rather than the campus as they are of little value to the majority of people learning a complex language like assembler.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

Ian_B

Can't you just split them off as a separate thread like on most other forums?

IanB

hutch--

I actually don't need advice on how to use the forum software. I was more interested in keeping the campus for what it was intended for instead of extended waffle that is of little use to learners.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

Ian_B

That's OK, I've removed the "waffle". I guess as a forum owner myself I was expecting a little more proactive moderation/management rather than being told off like a child.  ::)

Please remove my account.

marla

when i try and assemble this, i get the error:

Assembling: ips.asm
ips.asm(69) : error A2071: initializer magnitude too large for specified size
chr$(3): Macro Called From
  print(0): Macro Called From
   ips.asm(69): Main Line Code

... any idea why this happens guys?


Ratch

marla,
     Googling for error A2071 gives the following link. http://support.microsoft.com/default.aspx?scid=kb%3Ben-us%3B73752
It says that the error is at line 69 of ips.asm.  It tells you that MACRO functions chr$(3) and print(0) were called.  Can't tell much more without the assembly listing, preferably with the MACRO's expanded (.LISTMACROALL).  Ratch

marla

what does that mean, the macros expanded? and how do i do that .. sorry noob. :/  :tdown

zooba

Reading upwards:

At line 69 of ips.asm, 'print' was called
At line 0 of print, 'chr$' was called
At line 3 of chr$, the initializer was too large for the specified size

Looking at line 3 of chr$ (txtname db any_text,0) I would guess you're passing an integer directly (ie, chr$(1234) ) where the integer is too large to fit within a byte. However, without seeing the original code (specifically, line 69 of ips.asm) there isn't much we can do to help.

Cheers,

Zooba :U

marla

ok, here is the code, but isnt an ip address a 32 bit number? then shouldnt format and char both be DWORD 's veruss BYTE 's ?

here is my code:




;-----------------
; ips.asm
;-----------------

.486
.model flat, stdcall
option casemap :none

include C:\MASM32\INCLUDE\windows.inc
      include C:\masm32\macros\macros.asm
include C:\MASM32\INCLUDE\masm32.inc
      include C:\MASM32\INCLUDE\user32.inc
include C:\MASM32\INCLUDE\kernel32.inc
include C:\MASM32\INCLUDE\gdi32.inc

includelib C:\MASM32\LIB\masm32.lib
includelib C:\MASM32\LIB\user32.lib
includelib C:\MASM32\LIB\kernel32.lib
includelib C:\MASM32\LIB\gdi32.lib

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

TCP_portsCount equ 0ffffh

SCANINT STRUCT
   a_      DWORD ?
   b_      DWORD ?
   c_      DWORD ?
   d_      DWORD ?
   e_      DWORD ?
SCANINT ENDS

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

.data
format1 BYTE '%d.%d.%d.%d',0

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

.data?
scint   SCANINT <?>
char    BYTE 32 DUP (?)

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

.code

scanner:
xor eax,eax
mov [scint.a_], 1
mov [scint.b_], eax
mov [scint.c_], eax
mov [scint.d_], eax
mov [scint.e_], eax

    @loop_a:
      @loop_b:
          @loop_c:
              @loop_d:
                  INVOKE wsprintf,OFFSET char,OFFSET format1,[scint.a_],[scint.b_],[scint.c_],[scint.d_]
                  @loop_port:
                  print chr$(char)
                  INC [scint.e_]
                    cmp [scint.e_],TCP_portsCount
                    jle @loop_port
                INC [scint.d_]
                cmp [scint.d_], 255
                jle @loop_d
            INC [scint.c_]
            cmp [scint.c_], 255
            jle @loop_c
        INC [scint.b_]
        cmp [scint.b_], 255
        jle @loop_d
    INC [scint.a_]
    cmp [scint.a_], 254
    jle @loop_a

    invoke ExitProcess, NULL

end
;-----------------
;
;
;
;

zooba

'format' and 'char' are strings - ASCII strings are simply consecutive bytes. 'char' is actually an uninitialised string of length 32 (hence 32 DUP (?)).

The problem is that what you are actually passing to chr$ is the address of char:

      chr$ MACRO any_text:VARARG
        LOCAL txtname
        .data
          txtname db any_text,0
        .code
        EXITM <OFFSET txtname>
      ENDM


We now substitute 'char' for 'any_text', in accordance with your line of code:

LOCAL txtname
        .data
          txtname db char,0
        .code


In this context, the assembler attempts to use the address of char, since it has no way of knowing it's contents. A 32-bit address won't fit into a single byte, hence the error.

Not being familiar with the MASM32 macros, I'm not aware of the best way to do this. I would expect something like this would suffice:

print OFFSET char


Also, have a look in the M32LIB help file (masmlib.hlp) at the IPtoString function. It is possible to use this function and only a single loop (yep, no nested loops required :wink ) to do what you are attempting - but I'll leave it as an exercise :U

marla

i fixed the errors, but i am getting now:

POLINK: error: Unresolved external symbol '__mainCRTStartup'.

i google and see that it might have something to do with my assembler? hmm .. what the hell is the issue this is very confusing to a newjack, especiallywhen its a reference to somethng now even in my code ...




;-----------------
; ips.asm
;-----------------

.486
.model flat, stdcall
option casemap :none

include C:\MASM32\INCLUDE\windows.inc
      include C:\masm32\macros\macros.asm
include C:\MASM32\INCLUDE\masm32.inc
      include C:\MASM32\INCLUDE\user32.inc
include C:\MASM32\INCLUDE\kernel32.inc
include C:\MASM32\INCLUDE\gdi32.inc

includelib C:\MASM32\LIB\masm32.lib
includelib C:\MASM32\LIB\user32.lib
includelib C:\MASM32\LIB\kernel32.lib
includelib C:\MASM32\LIB\gdi32.lib

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

TCP_portsCount equ 0ffffh

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

SCANINT STRUCT
   a_      DWORD ?
   b_      DWORD ?
   c_      DWORD ?
   d_      DWORD ?
   e_      DWORD ?
SCANINT ENDS

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

.data
format1 BYTE '%d.%d.%d.%d',0

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

.data?
scint   SCANINT <?>
char    BYTE 32 DUP (?)

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

.code

scanner:
xor eax,eax
mov [scint.a_], 1
mov [scint.b_], eax
mov [scint.c_], eax
mov [scint.d_], eax
mov [scint.e_], eax

    @loop_a:
      @loop_b:
          @loop_c:
              @loop_d:
                  INVOKE wsprintf,OFFSET char,OFFSET format1,[scint.a_],[scint.b_],[scint.c_],[scint.d_]
                  @loop_port:
                  print OFFSET char
                  INC [scint.e_]
                    cmp [scint.e_],TCP_portsCount
                    jle @loop_port
                INC [scint.d_]
                cmp [scint.d_], 255
                jle @loop_d
            INC [scint.c_]
            cmp [scint.c_], 255
            jle @loop_c
        INC [scint.b_]
        cmp [scint.b_], 255
        jle @loop_d
    INC [scint.a_]
    cmp [scint.a_], 254
    jle @loop_a

    invoke ExitProcess, NULL

end
;-----------------
;
;
;
;



zooba

The problem is you haven't told the linker where the start of your program is. Change the last line to this:

END scanner

hutch--

Posted in the winasm forum under the name Marla.

Quote
how can i translate win32 masm code into opcodes/ ie: shell code?

Thread closed.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php