News:

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

looping through an array?

Started by marla, February 16, 2006, 06:15:50 PM

Previous topic - Next topic

marla

i am trying to loop through my array and print each array element to the screen.
what is wrong with my code?


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

.data

TCP_Ports DB
1,
2,
3,
5,
8,
1222,
666,
44,
33
;-----------------

.data?

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

.code

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

Start:
; CX to array size
mov CX, [TCP_Ports]

; loop through the array and print each elements value
ports_display:
print chr$([TCP_Ports + CX])
loop ports_display
End Start

Tedd

calls to functions will usually destroy the values in many of your registers (in particular: eax,ecx,edx)
So..

    ; CX to array size
    mov CX, [TCP_Ports]
    ; loop through the array and print each elements value
  ports_display:
    PUSH ECX
    print chr$([TCP_Ports + CX])
    POP ECX
    loop ports_display

No snowflake in an avalanche feels responsible.

Ian_B

Or store important values in EDI/ESI/EBX instead which are ALWAYS preserved through system API calls, but make sure you PUSH these registers at the start of your code then POP them in reverse order at the end, so that the calling code external to your program also gets back what it expected in them...

IanB

Mark Jones

#3
.... post removed until the O.P. gives a good explanation to what they are trying to accomplish. Professors don't give n00b students "port scanning" excercises...
"To deny our impulses... foolish; to revel in them, chaos." MCJ 2003.08

marla

since i am a n00b i am using tedds example. when i have the file opened though in qeditor, i am using "console assemble and link" and i get the following errors:

Microsoft (R) Macro Assembler Version 6.14.8444
Copyright (C) Microsoft Corp 1981-1997.  All rights reserved.

Assembling: C:\masm32\ports.asm
C:\masm32\ports.asm(33) : error A2008: syntax error : in directive
C:\masm32\ports.asm(34) : error A2042: statement too complex
C:\masm32\ports.asm(34) : error A2039: line too long
C:\masm32\ports.asm(84) : error A2039: line too long
C:\masm32\ports.asm(142) : error A2008: syntax error : chr$
C:\masm32\ports.asm(137) : error A2006: undefined symbol : TCP_Ports
_
Assembly Error
Press any key to continue . . .

here is my exact .asm file:



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

; ports.asm
; marla@hush.com

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

.486
.model flat, stdcall
option casemap:none

include \MASM32\INCLUDE\windows.inc
include \MASM32\INCLUDE\masm32.inc
include \MASM32\INCLUDE\kernel32.inc
include \masm32\include\gdi32.inc
include \masm32\include\user32.inc

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

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

.data?

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

.data
; TCP ports to scan
TCP_Ports DB
21, ; FTP
23, ; Telnet
80, ; HTTP
109, ; POP
110, ; ------
135, ; RPC-COM
137, ; Net-BIOS
138, ; ------
139, ; ------
143, ; IMAP
445, ; SMB File Sharing
1433, ; MS SQL
1521, ; Oracle
199, ; ------
1520, ; ------
1522, ; ------
1523, ; ------
1524, ; ------
1525, ; ------
1526, ; ------
1527, ; ------
1528, ; ------
1529, ; ------
1530, ; ------
1748, ; ------
1754, ; ------
1809, ; ------
1830, ; ------
1831, ; ------
2030, ; ------
2100, ; ------
2481, ; ------
2482, ; ------
3025, ; ------
3026, ; ------
4696, ; ------
6003, ; ------
6004, ; ------
6200, ; ------
6201, ; ------
1810, ; ------
2481, ; ------
7778, ; ------
1863, ; MSN Messenger
3306, ; MySQL
37337, ; back orifice
12345, ; NetBus
12346, ; ------
20034, ; ------
31790, ; Hack'a'Tack
31789,  ; ------
1214,  ; kazaa
31789,  ; ------
6257, ; WinMX/Napster
6699, ; ------
6346, ; Gnutella
6881, ; BitTorrent
6882, ; ------
6883, ; ------
6884, ; ------
6885, ; ------
6886, ; ------
6887, ; ------
6888, ; ------
6889, ; ------
4661, ; eDonkey & Clones
4662, ; ------
4663, ; ------
4664, ; ------
4665, ; ------
4666, ; ------
4667, ; ------
4668, ; ------
4669, ; ------
4670, ; ------
4671, ; ------
4672, ; ------
2234, ; SoulSeek
5534, ; ------
3050, ; Borland Interbase database
3689, ; iTune Music Sharing
5050, ; yahoo messenger
5190, ; AIM/AOL
5191, ; ------
5192, ; ------
5193, ; ------
5222, ; Jabber
5269, ; ------
6665, ; IRC
6666, ; ------
6667, ; ------
6668, ; ------
6669, ; ------
515, ; LDD Printer
631, ; IPP Printer
9100 ; PDL-Datastream

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

.code

start:
; CX to array size
mov CX, [TCP_Ports]

; loop through the array and print each elements value
ports_display:
push ECX
    print chr$([TCP_Ports + CX])
    pop ECX
    loop ports_display
end start

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

Tedd

QuoteC:\masm32\ports.asm(33) : error A2008: syntax error : in directive
C:\masm32\ports.asm(34) : error A2042: statement too complex
C:\masm32\ports.asm(34) : error A2039: line too long
C:\masm32\ports.asm(84) : error A2039: line too long
DB needs some data on the same line. Also, split the list into many db statements, instead of a single loooonnnnnnnngggggg one.

QuoteC:\masm32\ports.asm(142) : error A2008: syntax error : chr$
C:\masm32\ports.asm(137) : error A2006: undefined symbol : TCP_Ports
Whare and what is TCP_Ports? It isn't defined anywhere.



We're quite paranoid here and will not help hackers/crackers/losers to create malicous code. Yours is looking very much that way. And it's obvious you have quite a lot to learn, but this program of yours is possibly not simply a beginners exercise.
Why do you really want to do this?
(Hint: "because the prof said so" is not a good answer.)
No snowflake in an avalanche feels responsible.

u

 :eek

foul 1

TCP_Ports DB

after "db" you have to put at least one data-value, otherwise you should do

TCP_Ports:          ; this is a label



foul 2
starting lines with numbers... At this moment the assembler chokes by the surprise you cooked. The assembler won't know what to do with these numbers!
Now, a statement like the following makes perfect sense to it:

db 21

Here it knows to write 1 byte with the value "21" decimal, into the current section (.data or .code/.text). The assembler doesn't care whether this byte belongs to the TCP_Ports array. It just wrote a byte...

foul 3


mov CX, [TCP_Ports]

This one does NOT get the size of the array! Instead, it loads the first two bytes of it...
So your loop will crash and burn.

To get the size of an array, in bytes, you do it like this:


TCP_Ports:
db 1
db 2
db 20
db 81
endof_TCP_Ports:

...

mov CX, endof_TCP_Ports - TCP_Ports



foul 4 was mentioned, about preserving CX ... though if this is actually VKDebug, and if chr$ is well-done, here we needn't preserve the register. Yet, register-preservation is important, so bear it in mind.


foul 5
missing "ret" or "invoke ExitProcess,0" at end. The latter is a must-have in win32 apps.
Otherwise after your app executes correctly, it's bound to crash - via executing the appended garbage.



So, after these 5 fouls, where did you guys see any threat in his post ?  :toothy
His reason to make such labels (TCP_Ports, ports) is probably since he couldn't come up with a reallife example of array enumeration.
Now, how hard is it to just copy/paste the code of an existing port-scanner, compared to learning assembly from scratch (and keeping good style in it, too) ?
Please use a smaller graphic in your signature.

marla

i fixed the five 'fouls', however i am still getting errors. mainly one error for each of my array elements.




;-----------------
; ports.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

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

.data?

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

.data

;---------
; TCP ports to scan
TCP_Ports:
;---------
DB  21 ; FTP
DB  23 ; Telnet
DB  80 ; HTTP
DB  109 ; POP
DB  110 ; ------
DB  135 ; RPC-COM
DB  137 ; Net-BIOS
DB  138 ; ------
DB  139 ; ------
DB  143 ; IMAP
DB  445 ; SMB File Sharing
DB  1433 ; MS SQL
DB  1521 ; Oracle
DB  199 ; ------
DB  1520 ; ------
DB  1522 ; ------
DB  1523 ; ------
DB  1524 ; ------
DB  1525 ; ------
DB  1526 ; ------
DB  1527 ; ------
DB  1528 ; ------
DB  1529 ; ------
DB  1530 ; ------
DB  1748 ; ------
DB  1754 ; ------
DB  1809 ; ------
DB  1830 ; ------
DB  1831 ; ------
DB  2030 ; ------
DB  2100 ; ------
DB  2481 ; ------
DB  2482 ; ------
DB  3025 ; ------
DB  3026 ; ------
DB  4696 ; ------
DB  6003 ; ------
DB  6004 ; ------
DB  6200 ; ------
DB  6201 ; ------
DB  1810 ; ------
DB  2481 ; ------
DB  7778 ; ------
DB  1863 ; MSN Messenger
DB  3306 ; MySQL
DB  37337 ; back orifice
DB  12345 ; NetBus
DB  12346 ; ------
DB  20034 ; ------
DB  31790 ; Hack'a'Tack
DB  31789  ; ------
DB  1214  ; kazaa
DB  31789 ; ------
DB  6257 ; WinMX/Napster
DB  6699 ; ------
DB  6346 ; Gnutella
DB  6881 ; BitTorrent
DB  6882 ; ------
DB  6883 ; ------
DB  6884 ; ------
DB  6885 ; ------
DB  6886 ; ------
DB  6887 ; ------
DB  6888 ; ------
DB  6889 ; ------
DB  4661 ; eDonkey & Clones
DB  4662 ; ------
DB  4663 ; ------
DB  4664 ; ------
DB  4665 ; ------
DB  4666 ; ------
DB  4667 ; ------
DB  4668 ; ------
DB  4669 ; ------
DB  4670 ; ------
DB  4671 ; ------
DB  4672 ; ------
DB  2234 ; SoulSeek
DB  5534 ; ------
DB  3050 ; Borland Interbase database
DB  3689 ; iTune Music Sharing
DB  5050 ; yahoo messenger
DB  5190 ; AIM/AOL
DB  5191 ; ------
DB  5192 ; ------
DB  5193 ; ------
DB  5222 ; Jabber
DB  5269 ; ------
DB  6665 ; IRC
DB  6666 ; ------
DB  6667 ; ------
DB  6668 ; ------
DB  6669 ; ------
DB  515 ; LDD Printer
DB  631 ; IPP Printer
DB  9100 ; PDL-Datastream
;---------------
End_Of_TCP_Ports:

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

.code

start:
; size of array
mov CX, [End_Of_TCP_Ports - TCP_Ports]

; loop through the array and print each elements value
ports_display:
push ECX
    print chr$([TCP_Ports + CX])
    pop ECX
    loop ports_display
invoke ExitProcess,0
end start

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


here are my errors:
Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.

Z:\asm>make_ports.bat

Z:\asm>c:\masm32\bin\ml /c /coff ports.asm
Microsoft (R) Macro Assembler Version 6.14.8444
Copyright (C) Microsoft Corp 1981-1997.  All rights reserved.

Assembling: ports.asm
ports.asm(33) : error A2108: use of register assumed to ERROR
ports.asm(132) : error A2108: use of register assumed to ERROR
ports.asm(45) : error A2071: initializer magnitude too large for specified size
ports.asm(46) : error A2071: initializer magnitude too large for specified size
ports.asm(47) : error A2071: initializer magnitude too large for specified size
ports.asm(49) : error A2071: initializer magnitude too large for specified size
ports.asm(50) : error A2071: initializer magnitude too large for specified size
ports.asm(51) : error A2071: initializer magnitude too large for specified size
ports.asm(52) : error A2071: initializer magnitude too large for specified size
ports.asm(53) : error A2071: initializer magnitude too large for specified size
ports.asm(54) : error A2071: initializer magnitude too large for specified size
ports.asm(55) : error A2071: initializer magnitude too large for specified size
ports.asm(56) : error A2071: initializer magnitude too large for specified size
ports.asm(57) : error A2071: initializer magnitude too large for specified size
ports.asm(58) : error A2071: initializer magnitude too large for specified size
ports.asm(59) : error A2071: initializer magnitude too large for specified size
ports.asm(60) : error A2071: initializer magnitude too large for specified size
ports.asm(61) : error A2071: initializer magnitude too large for specified size
ports.asm(62) : error A2071: initializer magnitude too large for specified size
ports.asm(63) : error A2071: initializer magnitude too large for specified size
ports.asm(64) : error A2071: initializer magnitude too large for specified size
ports.asm(65) : error A2071: initializer magnitude too large for specified size
ports.asm(66) : error A2071: initializer magnitude too large for specified size
ports.asm(67) : error A2071: initializer magnitude too large for specified size
ports.asm(68) : error A2071: initializer magnitude too large for specified size
ports.asm(69) : error A2071: initializer magnitude too large for specified size
ports.asm(70) : error A2071: initializer magnitude too large for specified size
ports.asm(71) : error A2071: initializer magnitude too large for specified size
ports.asm(72) : error A2071: initializer magnitude too large for specified size
ports.asm(73) : error A2071: initializer magnitude too large for specified size
ports.asm(74) : error A2071: initializer magnitude too large for specified size
ports.asm(75) : error A2071: initializer magnitude too large for specified size
ports.asm(76) : error A2071: initializer magnitude too large for specified size
ports.asm(77) : error A2071: initializer magnitude too large for specified size
ports.asm(78) : error A2071: initializer magnitude too large for specified size
ports.asm(79) : error A2071: initializer magnitude too large for specified size
ports.asm(80) : error A2071: initializer magnitude too large for specified size
ports.asm(81) : error A2071: initializer magnitude too large for specified size
ports.asm(82) : error A2071: initializer magnitude too large for specified size
ports.asm(83) : error A2071: initializer magnitude too large for specified size
ports.asm(84) : error A2071: initializer magnitude too large for specified size
ports.asm(85) : error A2071: initializer magnitude too large for specified size
ports.asm(86) : error A2071: initializer magnitude too large for specified size
ports.asm(87) : error A2071: initializer magnitude too large for specified size
ports.asm(88) : error A2071: initializer magnitude too large for specified size
ports.asm(89) : error A2071: initializer magnitude too large for specified size
ports.asm(90) : error A2071: initializer magnitude too large for specified size
ports.asm(91) : error A2071: initializer magnitude too large for specified size
ports.asm(92) : error A2071: initializer magnitude too large for specified size
ports.asm(93) : error A2071: initializer magnitude too large for specified size
ports.asm(94) : error A2071: initializer magnitude too large for specified size
ports.asm(95) : error A2071: initializer magnitude too large for specified size
ports.asm(96) : error A2071: initializer magnitude too large for specified size
ports.asm(97) : error A2071: initializer magnitude too large for specified size
ports.asm(98) : error A2071: initializer magnitude too large for specified size
ports.asm(99) : error A2071: initializer magnitude too large for specified size
ports.asm(100) : error A2071: initializer magnitude too large for specified size

ports.asm(101) : error A2071: initializer magnitude too large for specified size

ports.asm(102) : error A2071: initializer magnitude too large for specified size

ports.asm(103) : error A2071: initializer magnitude too large for specified size

ports.asm(104) : error A2071: initializer magnitude too large for specified size

ports.asm(105) : error A2071: initializer magnitude too large for specified size

ports.asm(106) : error A2071: initializer magnitude too large for specified size

ports.asm(107) : error A2071: initializer magnitude too large for specified size

ports.asm(108) : error A2071: initializer magnitude too large for specified size

ports.asm(109) : error A2071: initializer magnitude too large for specified size

ports.asm(110) : error A2071: initializer magnitude too large for specified size

ports.asm(111) : error A2071: initializer magnitude too large for specified size

ports.asm(112) : error A2071: initializer magnitude too large for specified size

ports.asm(113) : error A2071: initializer magnitude too large for specified size

ports.asm(114) : error A2071: initializer magnitude too large for specified size

ports.asm(115) : error A2071: initializer magnitude too large for specified size

ports.asm(116) : error A2071: initializer magnitude too large for specified size

ports.asm(117) : error A2071: initializer magnitude too large for specified size

ports.asm(118) : error A2071: initializer magnitude too large for specified size

ports.asm(119) : error A2071: initializer magnitude too large for specified size

ports.asm(120) : error A2071: initializer magnitude too large for specified size

ports.asm(121) : error A2071: initializer magnitude too large for specified size

ports.asm(122) : error A2071: initializer magnitude too large for specified size

ports.asm(123) : error A2071: initializer magnitude too large for specified size

ports.asm(124) : error A2071: initializer magnitude too large for specified size

ports.asm(125) : error A2071: initializer magnitude too large for specified size

ports.asm(126) : error A2071: initializer magnitude too large for specified size

ports.asm(127) : error A2071: initializer magnitude too large for specified size

ports.asm(128) : error A2071: initializer magnitude too large for specified size

ports.asm(129) : error A2071: initializer magnitude too large for specified size

ports.asm(130) : error A2071: initializer magnitude too large for specified size

ports.asm(145) : error A2032: invalid use of register
chr$(3): Macro Called From
  print(0): Macro Called From
   ports.asm(145): Main Line Code

Z:\asm>c:\masm32\bin\polink /SUBSYSTEM:CONSOLE ports.obj
POLINK: fatal error: File not found: 'ports.obj'.

Z:\asm>


also, is this the best way to use an array or integers? with a label ...
btw: wouldnt it be easier just to download nmap versus me learning assembler? :P

zooba

The reason you're getting an error for most of your initialisers is because you're initialising BYTEs (DB = declare byte). I'm sure you know you can't fit any value larger than 255 into a byte, so you'll need to use either WORDs or DWORDs.

However, keep in mind that if you make your array elements larger (and they all need to become larger, not just some of them) then your indexing code (currently print chr$([TCP_Ports + CX]) which BTW probably isn't going to do what you want - try str$ :thumbu)

marla


fixed... but:

Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.

Z:\asm>make_ports.bat

Z:\asm>c:\masm32\bin\ml /c /coff ports.asm
Microsoft (R) Macro Assembler Version 6.14.8444
Copyright (C) Microsoft Corp 1981-1997.  All rights reserved.

Assembling: ports.asm
ports.asm(33) : error A2108: use of register assumed to ERROR
ports.asm(132) : error A2108: use of register assumed to ERROR

Z:\asm>c:\masm32\bin\polink /SUBSYSTEM:CONSOLE ports.obj
POLINK: fatal error: File not found: 'ports.obj'.

Z:\asm>




;-----------------
; ports.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

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

.data?

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

.data

;---------
; TCP ports to scan
TCP_Ports:
;---------
DD  21 ; FTP
DD  23 ; Telnet
DD  80 ; HTTP
DD  109 ; POP
DD  110 ; ------
DD  135 ; RPC-COM
DD  137 ; Net-BIOS
DD  138 ; ------
DD  139 ; ------
DD  143 ; IMAP
DD  445 ; SMB File Sharing
DD  1433 ; MS SQL
DD  1521 ; Oracle
DD  199 ; ------
DD  1520 ; ------
DD  1522 ; ------
DD  1523 ; ------
DD  1524 ; ------
DD  1525 ; ------
DD  1526 ; ------
DD  1527 ; ------
DD  1528 ; ------
DD  1529 ; ------
DD  1530 ; ------
DD  1748 ; ------
DD  1754 ; ------
DD  1809 ; ------
DD  1830 ; ------
DD  1831 ; ------
DD  2030 ; ------
DD  2100 ; ------
DD  2481 ; ------
DD  2482 ; ------
DD  3025 ; ------
DD  3026 ; ------
DD  4696 ; ------
DD  6003 ; ------
DD  6004 ; ------
DD  6200 ; ------
DD  6201 ; ------
DD  1810 ; ------
DD  2481 ; ------
DD  7778 ; ------
DD  1863 ; MSN Messenger
DD  3306 ; MySQL
DD  37337 ; back orifice
DD  12345 ; NetBus
DD  12346 ; ------
DD  20034 ; ------
DD  31790 ; Hack'a'Tack
DD  31789  ; ------
DD  1214  ; kazaa
DD  31789 ; ------
DD  6257 ; WinMX/Napster
DD  6699 ; ------
DD  6346 ; Gnutella
DD  6881 ; BitTorrent
DD  6882 ; ------
DD  6883 ; ------
DD  6884 ; ------
DD  6885 ; ------
DD  6886 ; ------
DD  6887 ; ------
DD  6888 ; ------
DD  6889 ; ------
DD  4661 ; eDonkey & Clones
DD  4662 ; ------
DD  4663 ; ------
DD  4664 ; ------
DD  4665 ; ------
DD  4666 ; ------
DD  4667 ; ------
DD  4668 ; ------
DD  4669 ; ------
DD  4670 ; ------
DD  4671 ; ------
DD  4672 ; ------
DD  2234 ; SoulSeek
DD  5534 ; ------
DD  3050 ; Borland Interbase database
DD  3689 ; iTune Music Sharing
DD  5050 ; yahoo messenger
DD  5190 ; AIM/AOL
DD  5191 ; ------
DD  5192 ; ------
DD  5193 ; ------
DD  5222 ; Jabber
DD  5269 ; ------
DD  6665 ; IRC
DD  6666 ; ------
DD  6667 ; ------
DD  6668 ; ------
DD  6669 ; ------
DD  515 ; LDD Printer
DD  631 ; IPP Printer
DD  9100 ; PDL-Datastream
;---------------
End_Of_TCP_Ports:

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

.code

start:
; size of array
mov CX, [End_Of_TCP_Ports - TCP_Ports]

; loop through the array and print each elements value
ports_display:
push ECX
    print str$([TCP_Ports + CX])
    pop ECX
    loop ports_display
invoke ExitProcess,0
end start

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

hutch--

Marla,


mov CX, [End_Of_TCP_Ports - TCP_Ports]


This is a mistake as you are trying to write an address calculated at assembly time into a 16 bit register. Change the CX to ECX.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

marla

hutch, i changed all to ECX, still getting errors. i was looking at some code, and thought that i could learn more and it was more standard to not use labels ... so here is what i am trying now ... i wanted to play with LEA and learn more about memory...




;-----------------
; ports2.asm
;-----------------

.486
.model flat, stdcall
option casemap :none

include C:\MASM32\INCLUDE\windows.inc
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

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

print macro lpszText:VARARG
local txt
.data
  txt db lpszText,13,10,0
.code
invoke StdOut,addr txt
ENDM

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

.data?

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

.data

;---------
; TCP ports to scan
TCP_Ports DD  21 ; FTP
DD  23 ; Telnet
DD  80 ; HTTP
DD  109 ; POP
DD  110 ; ------
DD  135 ; RPC-COM
DD  137 ; Net-BIOS
DD  138 ; ------
DD  139 ; ------
DD  143 ; IMAP
DD  445 ; SMB File Sharing
DD  1433 ; MS SQL
DD  1521 ; Oracle
DD  199 ; ------
DD  1520 ; ------
DD  1522 ; ------
DD  1523 ; ------
DD  1524 ; ------
DD  1525 ; ------
DD  1526 ; ------
DD  1527 ; ------
DD  1528 ; ------
DD  1529 ; ------
DD  1530 ; ------
DD  1748 ; ------
DD  1754 ; ------
DD  1809 ; ------
DD  1830 ; ------
DD  1831 ; ------
DD  2030 ; ------
DD  2100 ; ------
DD  2481 ; ------
DD  2482 ; ------
DD  3025 ; ------
DD  3026 ; ------
DD  4696 ; ------
DD  6003 ; ------
DD  6004 ; ------
DD  6200 ; ------
DD  6201 ; ------
DD  1810 ; ------
DD  2481 ; ------
DD  7778 ; ------
DD  1863 ; MSN Messenger
DD  3306 ; MySQL
DD  37337 ; back orifice
DD  12345 ; NetBus
DD  12346 ; ------
DD  20034 ; ------
DD  31790 ; Hack'a'Tack
DD  31789  ; ------
DD  1214  ; kazaa
DD  31789 ; ------
DD  6257 ; WinMX/Napster
DD  6699 ; ------
DD  6346 ; Gnutella
DD  6881 ; BitTorrent
DD  6882 ; ------
DD  6883 ; ------
DD  6884 ; ------
DD  6885 ; ------
DD  6886 ; ------
DD  6887 ; ------
DD  6888 ; ------
DD  6889 ; ------
DD  4661 ; eDonkey & Clones
DD  4662 ; ------
DD  4663 ; ------
DD  4664 ; ------
DD  4665 ; ------
DD  4666 ; ------
DD  4667 ; ------
DD  4668 ; ------
DD  4669 ; ------
DD  4670 ; ------
DD  4671 ; ------
DD  4672 ; ------
DD  2234 ; SoulSeek
DD  5534 ; ------
DD  3050 ; Borland Interbase database
DD  3689 ; iTune Music Sharing
DD  5050 ; yahoo messenger
DD  5190 ; AIM/AOL
DD  5191 ; ------
DD  5192 ; ------
DD  5193 ; ------
DD  5222 ; Jabber
DD  5269 ; ------
DD  6665 ; IRC
DD  6666 ; ------
DD  6667 ; ------
DD  6668 ; ------
DD  6669 ; ------
DD  515 ; LDD   Printer
DD  631 ; IPP Printer
DD  9100 ; PDL-Datastream

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

.code

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

scanner:
call main
invoke ExitProcess,0

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

main proc:
lea EDI, TCP_Ports

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

scan_loop:
mov eax, [edi]
cmp eax, 0
je scan_finished
inc edi
mov TCP_Ports, eax
mov eax, [eax+12]
mov eax, [eax]
mov eax, [eax]

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

scan_finished:
print "-- finished --"
ret

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

main endp

end scanner

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


but i get the error:

Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.

Z:\asm>make_ports2.bat

Z:\asm>c:\masm32\bin\ml /c /coff ports2.asm
Microsoft (R) Macro Assembler Version 6.14.8444
Copyright (C) Microsoft Corp 1981-1997.  All rights reserved.

Assembling: ports2.asm
ports2.asm(151) : error A2008: syntax error : :
ports2.asm(174) : fatal error A1010: unmatched block nesting : main

Z:\asm>c:\masm32\bin\polink /SUBSYSTEM:CONSOLE ports2.obj
POLINK: fatal error: File not found: 'ports2.obj'.

Z:\asm>

however, what i do not understand, is that main is properly closed ... once i get this fixed no more posts in the forum until i learn alot more asm, its just that there are no good or event almost decent win32 books for asm out there .. thanks in advance...

u


main proc:

here's the prob. Remove the ":"
Please use a smaller graphic in your signature.

MichaelW

Marla,

ports2.asm(151) : error A2008: syntax error : :

Line 151:

main proc:

The error message is trying to tell you that the colon is a syntax error. A label should have a colon:

main:

But a procedure should not have a colon:

main proc

In addition to errors that are preventing it from assembling and linking, your code contains multiple errors that will appear when it is executed, and these errors will be difficult for a beginner to isolate. I think you would have far fewer problems if you would start with some simple code that will assemble and link and execute correctly, like some of the simpler MASM32 examples. After you have verified that everything is working correctly, then you can begin experimenting with the code, assembling, linking, and testing after each change or small number of changes. If the code fails assembling, linking, or testing, then you know where to look for the problem.

eschew obfuscation

marla

i am working on the tutorials as i speak now, however most are geared to people using actual windows non console, and do not really deal with anything that i am working on. but; i am doing them. in the mean time, i would like to fix this: i fixed some code and it compiles with no errors, but i does not display the output. it just goes to "---scan finished---". i do understand the code though, but not why there is no output...




;-----------------
; ports2.asm
;-----------------

.486
.model flat, stdcall
option casemap :none

include C:\MASM32\INCLUDE\windows.inc
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

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

print macro lpszText:VARARG
local txt
.data
  txt db lpszText,13,10,0
.code
invoke StdOut,addr txt
ENDM

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

.data?

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

.data

;---------
; TCP ports to scan
TCP_Ports DD  21 ; FTP
DD  23 ; Telnet
DD  80 ; HTTP
DD  109 ; POP
DD  110 ; ------
DD  135 ; RPC-COM
DD  137 ; Net-BIOS
DD  138 ; ------
DD  139 ; ------
DD  143 ; IMAP
DD  445 ; SMB File Sharing
DD  1433 ; MS SQL
DD  1521 ; Oracle
DD  199 ; ------
DD  1520 ; ------
DD  1522 ; ------
DD  1523 ; ------
DD  1524 ; ------
DD  1525 ; ------
DD  1526 ; ------
DD  1527 ; ------
DD  1528 ; ------
DD  1529 ; ------
DD  1530 ; ------
DD  1748 ; ------
DD  1754 ; ------
DD  1809 ; ------
DD  1830 ; ------
DD  1831 ; ------
DD  2030 ; ------
DD  2100 ; ------
DD  2481 ; ------
DD  2482 ; ------
DD  3025 ; ------
DD  3026 ; ------
DD  4696 ; ------
DD  6003 ; ------
DD  6004 ; ------
DD  6200 ; ------
DD  6201 ; ------
DD  1810 ; ------
DD  2481 ; ------
DD  7778 ; ------
DD  1863 ; MSN Messenger
DD  3306 ; MySQL
DD  37337 ; back orifice
DD  12345 ; NetBus
DD  12346 ; ------
DD  20034 ; ------
DD  31790 ; Hack'a'Tack
DD  31789  ; ------
DD  1214  ; kazaa
DD  31789 ; ------
DD  6257 ; WinMX/Napster
DD  6699 ; ------
DD  6346 ; Gnutella
DD  6881 ; BitTorrent
DD  6882 ; ------
DD  6883 ; ------
DD  6884 ; ------
DD  6885 ; ------
DD  6886 ; ------
DD  6887 ; ------
DD  6888 ; ------
DD  6889 ; ------
DD  4661 ; eDonkey & Clones
DD  4662 ; ------
DD  4663 ; ------
DD  4664 ; ------
DD  4665 ; ------
DD  4666 ; ------
DD  4667 ; ------
DD  4668 ; ------
DD  4669 ; ------
DD  4670 ; ------
DD  4671 ; ------
DD  4672 ; ------
DD  2234 ; SoulSeek
DD  5534 ; ------
DD  3050 ; Borland Interbase database
DD  3689 ; iTune Music Sharing
DD  5050 ; yahoo messenger
DD  5190 ; AIM/AOL
DD  5191 ; ------
DD  5192 ; ------
DD  5193 ; ------
DD  5222 ; Jabber
DD  5269 ; ------
DD  6665 ; IRC
DD  6666 ; ------
DD  6667 ; ------
DD  6668 ; ------
DD  6669 ; ------
DD  515 ; LDD   Printer
DD  631 ; IPP Printer
DD  9100 ; PDL-Datastream

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

.code

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

scanner:
call main
invoke ExitProcess,0

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

main proc
lea EDI, TCP_Ports

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

scan_loop:
mov eax, [edi]
cmp eax, 0
je scan_finished
inc edi
jmp scan_loop

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

scan_finished:
print "-- finished --"
ret

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

main endp

end scanner

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