How can i get mac address? through asm code offcourse..

And this long time problem which i still dont know how to solve in masm32 having references or data ahead in the program will give you an error..
In tasm its solved with the assembler passes over code more then once..
Whats the workaround with masm32?
Posted on 2005-02-02 01:08:02 by pwn
I can only answer the second one. You have to have all data declared before it is used. I guess MASM only uses a one pass assembler. This is just like C so you shouldn't have much problem with it. You can use the PROTO directive for functions if you think you have to (I use this mostly for the WinMain function). As for data, you have to declare it before you use it.

Spara
Posted on 2005-02-02 02:33:03 by Sparafusile
so I can answer question one :)

have a look at the "GetIfTable" API function, it delivers description structures from all network adapters, including physical address.
Posted on 2005-02-02 07:42:31 by beaster
hope this can help you some.
regards.

mac_1.bat


;@echo off
;goto make
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
; the code for < Win32MASM Programming > written by LYB
; it can get net Adapters Infomation.
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
.386
.model flat, stdcall
option casemap :none
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
include \masm32\include\windows.inc
include \masm32\include\user32.inc
include \masm32\include\kernel32.inc
includelib \masm32\lib\user32.lib
includelib \masm32\lib\kernel32.lib
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
MAX_ADAPTER_DESCRIPTION_LENGTH equ 128
MAX_ADAPTER_NAME_LENGTH equ 256
MAX_ADAPTER_ADDRESS_LENGTH equ 8
;-----------------------------------------
IP_ADDR_STRING struct

Next dword ?
IpAddress byte 16 dup (?)
IpMask byte 16 dup (?)
Context dword ?

IP_ADDR_STRING ends
;------------------------------------------
IP_ADAPTER_INFO struct

Next dword ?
ComboIndex dword ?
AdapterName byte MAX_ADAPTER_NAME_LENGTH + 4 dup (?)
Description byte MAX_ADAPTER_DESCRIPTION_LENGTH + 4 dup (?)
AddressLength dword ?
Address byte MAX_ADAPTER_ADDRESS_LENGTH dup (?)
Index dword ?
_Type dword ?
DhcpEnabled dword ?
CurrentIpAddress dword ?
IpAddressList IP_ADDR_STRING <>
GatewayList IP_ADDR_STRING <>
DhcpServer IP_ADDR_STRING <>
HaveWins dword ?
PrimaryWinsServer IP_ADDR_STRING <>
SecondaryWinsServer IP_ADDR_STRING <>
LeaseObtained dword ?
LeaseExpires dword ?

IP_ADAPTER_INFO ends
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
ICO_MAIN equ 1000
DLG_MAIN equ 1000
IDC_ADPT equ 1001
IDC_TYPE equ 1002
IDC_MAC equ 1003
IDC_IP equ 1004
IDC_GATEWAY equ 1005
IDC_WINS equ 1006
IDC_DHCP equ 1007
IDC_REFRESH equ 1008
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
.data?
hInstance dd ?
hWinMain dd ?
hDll dd ?
lpGetInfo dd ?
dwStructSize dd ?
lpInfo dd ?
lpMemory dd ?
szBuffer db 1024 dup (?)
szBuffer1 db 1024 dup (?)
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
.const
szDll db 'Iphlpapi.dll',0
szGetInfo db 'GetAdaptersInfo',0
szErrNoAdapter db 'not installed net Adapters',0
szNA db 'N/A',0
szMac db '%02X:%02X:%02X:%02X:%02X:%02X',0
szSpar db '/',0
szCrLf db 0dh,0ah,0
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
.code
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
_GetIPString proc _lpIP,_lpOut,_dwSize,_dwIfMask

pushad
invoke RtlZeroMemory,_lpOut,_dwSize
mov esi,_lpIP
assume esi:ptr IP_ADDR_STRING
@@:
.if byte ptr [esi].IpAddress
invoke lstrcat,_lpOut,addr [esi].IpAddress
.if (byte ptr [esi].IpMask) && _dwIfMask
invoke lstrcat,_lpOut,addr szSpar
invoke lstrcat,_lpOut,addr [esi].IpMask
.endif
.endif
mov esi,[esi].Next
.if esi
invoke lstrcat,_lpOut,addr szCrLf
jmp @B
.endif
assume esi:nothing
popad
ret

_GetIPString endp
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
_ShowInfo proc

pushad
mov esi,lpInfo
assume esi:ptr IP_ADAPTER_INFO
.if [esi].Next
invoke GetDlgItem,hWinMain,IDOK
invoke EnableWindow,eax,TRUE
.else
invoke GetDlgItem,hWinMain,IDOK
invoke EnableWindow,eax,FALSE
.endif
invoke SetDlgItemText,hWinMain,IDC_ADPT,addr [esi].Description
invoke SetDlgItemInt,hWinMain,IDC_TYPE,[esi]._Type,FALSE

lea edi,[esi].Address
mov ebx,6
.while ebx
movzx eax,byte ptr [edi+ebx-1]
push eax
dec ebx
.endw
invoke wsprintf,addr szBuffer,addr szMac
add esp,6 * 4
invoke SetDlgItemText,hWinMain,IDC_MAC,addr szBuffer

invoke _GetIPString,addr [esi].IpAddressList,addr szBuffer,sizeof szBuffer,TRUE
invoke SetDlgItemText,hWinMain,IDC_IP,addr szBuffer
invoke _GetIPString,addr [esi].GatewayList,addr szBuffer,sizeof szBuffer,FALSE
.if szBuffer
invoke SetDlgItemText,hWinMain,IDC_GATEWAY,addr szBuffer
.endif
.if [esi].DhcpEnabled
invoke _GetIPString,addr [esi].DhcpServer,addr szBuffer,sizeof szBuffer,FALSE
invoke SetDlgItemText,hWinMain,IDC_DHCP,addr szBuffer
.endif
.if [esi].HaveWins
invoke _GetIPString,addr [esi].PrimaryWinsServer,addr szBuffer,sizeof szBuffer,FALSE
invoke _GetIPString,addr [esi].SecondaryWinsServer,addr szBuffer1,sizeof szBuffer,FALSE
.if szBuffer1
invoke lstrcat,addr szBuffer,addr szCrLf
invoke lstrcat,addr szBuffer,addr szBuffer1
.endif
invoke SetDlgItemText,hWinMain,IDC_WINS,addr szBuffer
.endif
assume esi:nothing
popad
ret

_ShowInfo endp
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
_GetInfo proc

.if lpMemory
invoke GlobalFree,lpMemory
mov lpMemory,0
.endif
mov ebx,IDC_ADPT
.while ebx <= IDC_DHCP
invoke SetDlgItemText,hWinMain,ebx,addr szNA
inc ebx
.endw
invoke GetDlgItem,hWinMain,IDOK
invoke EnableWindow,eax,FALSE
invoke GlobalAlloc,GPTR,sizeof IP_ADAPTER_INFO
.if eax
mov lpMemory,eax
mov dwStructSize,sizeof IP_ADAPTER_INFO
@@:
push offset dwStructSize
push lpMemory
call lpGetInfo

.if eax == ERROR_BUFFER_OVERFLOW
invoke GlobalReAlloc,lpMemory,dwStructSize,GMEM_MOVEABLE
.if ! eax
jmp @F
.endif
mov lpMemory,eax
jmp @B
.elseif eax == ERROR_SUCCESS
push lpMemory
pop lpInfo
invoke _ShowInfo
.elseif eax == ERROR_NO_DATA
invoke MessageBox,NULL,addr szErrNoAdapter,NULL,MB_OK or MB_ICONWARNING
.endif
.endif
@@:
ret

_GetInfo endp
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
_ProcDlgMain proc uses ebx edi esi hWnd,wMsg,wParam,lParam

mov eax,wMsg
.if eax == WM_COMMAND
mov eax,wParam
.if ax == IDOK
mov eax,lpInfo
mov eax,[eax]
mov lpInfo,eax
invoke _ShowInfo
.elseif ax == IDC_REFRESH
invoke _GetInfo
.endif
.elseif eax == WM_CLOSE
invoke EndDialog,hWnd,NULL
.elseif eax == WM_INITDIALOG
push hWnd
pop hWinMain
invoke LoadIcon,hInstance,ICO_MAIN
invoke SendMessage,hWnd,WM_SETICON,ICON_BIG,eax
invoke _GetInfo
.else
mov eax,FALSE
ret
.endif
mov eax,TRUE
ret

_ProcDlgMain endp
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
start:
invoke LoadLibrary,addr szDll
.if eax
mov hDll,eax
invoke GetProcAddress,eax,offset szGetInfo
.if eax
mov lpGetInfo,eax
.endif
.endif
invoke GetModuleHandle,NULL
mov hInstance,eax
invoke DialogBoxParam,hInstance,DLG_MAIN,NULL,offset _ProcDlgMain,NULL
invoke ExitProcess,NULL
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

end start

;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
:make
set name=MAC_1

\masm32\bin\ml /c /coff %name%.bat
\masm32\bin\rc %name%.rc
\masm32\bin\Link /subsystem:windows %name%.obj %name%.res

if exist *.bak del *.bak
if exist *.res del *.res
if exist *.obj del *.obj
echo.


Mac_1.rc

//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
#include <\masm32\include\resource.h>
//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
#define ICO_MAIN 1000
#define DLG_MAIN 1000
#define IDC_ADPT 1001
#define IDC_TYPE 1002
#define IDC_MAC 1003
#define IDC_IP 1004
#define IDC_GATEWAY 1005
#define IDC_WINS 1006
#define IDC_DHCP 1007
#define IDC_REFRESH 1008
//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
ICO_MAIN ICON "MAC_1.ico"
//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
DLG_MAIN DIALOG 111, 104, 217, 136
STYLE DS_MODALFRAME | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU
CAPTION "Net Adapters Information "
FONT 9, "MS Sans Serif"
{
LTEXT "Adapter Name", -1, 7, 8, 60, 8
EDITTEXT IDC_ADPT, 71, 5, 139, 12, ES_AUTOHSCROLL | WS_BORDER | WS_TABSTOP
LTEXT "Adapter Type", -1, 7, 24, 60, 8
EDITTEXT IDC_TYPE, 71, 21, 139, 12, ES_AUTOHSCROLL | WS_BORDER | WS_TABSTOP
LTEXT "Adapter MAC Address", -1, 7, 40, 60, 8
EDITTEXT IDC_MAC, 71, 37, 139, 12, ES_AUTOHSCROLL | WS_BORDER | WS_TABSTOP
LTEXT "IP Address", -1, 7, 56, 60, 8
EDITTEXT IDC_IP, 71, 53, 139, 12, ES_MULTILINE | ES_AUTOHSCROLL | WS_BORDER | WS_VSCROLL | WS_TABSTOP
LTEXT "Gateway", -1, 7, 72, 60, 8
EDITTEXT IDC_GATEWAY, 71, 69, 139, 12, ES_MULTILINE | ES_AUTOHSCROLL | WS_BORDER | WS_VSCROLL | WS_TABSTOP
LTEXT "WINS Server", -1, 7, 88, 60, 8
EDITTEXT IDC_WINS, 71, 85, 139, 12, ES_MULTILINE | ES_AUTOHSCROLL | WS_BORDER | WS_VSCROLL | WS_TABSTOP
LTEXT "DHCP Server", -1, 7, 104, 60, 8
EDITTEXT IDC_DHCP, 71, 101, 139, 12, ES_MULTILINE | ES_AUTOHSCROLL | WS_BORDER | WS_VSCROLL | WS_TABSTOP
PUSHBUTTON "Refurbish(&R)", IDC_REFRESH, 35, 117, 70, 14
PUSHBUTTON "Next(&N)", IDOK, 109, 117, 70, 14
}
//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

Posted on 2005-02-02 09:51:32 by dcskm4200
thx it was pretty obvious that i could just declare my data at start of program. thats why i was asking whats the workaround.

And i checked out that api from iphlpapi dll...
Do you have more specific info or perhaps a sample code..

Although microsoft documented it pretty well here:
http://msdn.microsoft.com/library/en-us/iphlp/iphlp/ip_helper_function_reference.asp

Edit: just saw your msg dcskm4200, thx.
Posted on 2005-02-02 09:52:26 by pwn
awsome dude. worked like a charm. just had to a get some icon mac_1.ico and it was runing. thx again.
Posted on 2005-02-02 09:59:37 by pwn
I guess MASM only uses a one pass assembler...


If this were true, you wouldn't be able to do forward jumps! Right? What's the differance between a forward jump and a call to a procedure declared later in the source code? If there is no differance, then why doesn't MASM allow the later?

Spara
Posted on 2005-02-03 01:51:33 by Sparafusile
You can reference data later in the file using OFFSET. Using addr will only work for previously declared data.
Posted on 2005-02-03 13:33:24 by QuantumMatrix1024