Archive: mac address with system plugin


mac address with system plugin
  Hello ¡¡¡ And congratulations for NSIS¡¡¡

I want to know the Mac address with the system plugin but i don´t know how to do that. I read the tutorials of brainsucker , Lobo Lunal and a lot of examples but i don´t know how to do :(
In msdn i found this information:

DWORD GetAdaptersInfo(
PIP_ADAPTER_INFO pAdapterInfo,
PULONG pOutBufLen);


typedef struct _IP_ADAPTER_INFO {
struct _IP_ADAPTER_INFO* Next;
DWORD ComboIndex;
char AdapterName[MAX_ADAPTER_NAME_LENGTH + 4];
char Description MAX_ADAPTER_DESCRIPTION_LENGTH + 4];
UINT AddressLength;
BYTE Address[MAX_ADAPTER_ADDRESS_LENGTH];
DWORD Index;
UINT Type;
UINT DhcpEnabled;
PIP_ADDR_STRING CurrentIpAddress;
IP_ADDR_STRING IpAddressList;
IP_ADDR_STRING GatewayList;
IP_ADDR_STRING DhcpServer;
BOOL HaveWins;
IP_ADDR_STRING PrimaryWinsServer;
IP_ADDR_STRING SecondaryWinsServer;
time_t LeaseObtained;
time_t LeaseExpires;
} IP_ADAPTER_INFO, *PIP_ADAPTER_INFO;

I looking for samples and i don´t know why my code dont´work. What´s wrong with my code?


Section "GetMac" GetMac
System::Alloc 400
pop $2

System::Call 'iphlpapi::GetAdaptersInfo(*i .r3 ,i )v .r1'

System::Call '$3(i,i,i,i,i,i .r4,i,i,i,i,i,i,i,i,i,i,i,i)'
MessageBox MB_OK "Mac is $4"

System::Free $2
SectionEnd


Thanks in advance


Hello¡¡¡¡

I study this problem more . And I think this code must run .But I´m wrong in something.:(

Section "GetMac" GetMac
System::Alloc 640
pop $2
System::Call 'iphlpapi::GetAdaptersInfo( i .r3,*l r2)i.r1'
MessageBox MB_OK "GetAdaptersInfo return is $1"
System::Call '*$3(v,v,&t.r5,v,v,v,v,v,v,v,v,v,v,v,v,v,v,v)'
MessageBox MB_OK "Adapter name is is $5"
System::Free $2
SectionEnd

The var $1 is always 111 (ERROR_BUFFER_OVERFLOW). And var $5 is allways null.
Sorry but i don´t know what´s the problem . I think that i need more bytes to allocates but i increase more than 640 and the results is always the same.
What´s wrong?

Thanks a lot and sorry for my poor english.


Remove the asterisk, you don't want a pointer to $2.


Hello guys ;)
Script enumerates thru all installed adapters.
Math used only for formating, so if you don't need pretty mac addr, remove math::script lines.
GL.


Name "MacAddr Plugin Example"

>OutFile "macaddr.exe"
>SetPluginUnload alwaysoff

Section "ThisNameIsIgnoredSoWhyBother?"
SetOutPath $TEMP

>!define maxsize 4096

System
::Alloc ${maxsize}
pop $3
System::Call 'iphlpapi::GetAdaptersInfo(i r3r4, *l ${maxsize} r2)i.r1'
MessageBox MB_OK "GetAdaptersInfo return is $1"
strcmp $1 0 0 finish ;in case of errors

cont:
strcmp $4 0 finish ; no more adapters
System::Call '*$4(i.r4,i,&t260.r5, &t132.r6, i.r7, l.r8)'

Math::Script "hex={'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};"
Math::Script "s=''; a=r8; b=r7; #{b-->0,s=s+hex***91;a/16%16***93;+hex***91;a%16***93;+#***91;b>0,'-',''***93;; a=a/256;}; r9=s;"

MessageBox MB_OK "Adapter name is $5$\ndesc $6$\naddr len $7$\naddr $8$\nMacAddr: $9"

>goto cont

finish:
System::Free $3

; last plugin call must not have /NOUNLOAD so NSIS will be able to delete the temporary DLL
SetPluginUnload manual
; do nothing
System::Free 0
Math::Script ""

>SectionEnd
>

Hello

Thanks to Kichik and of course to brainsucker¡¡¡¡¡

The solution is incredible ¡¡¡¡ :D

I think that i need two weeks o more to understand the solution ¡¡¡
Where´s the system plugin school? :p

Can i do some questions ?

System::Call 'iphlpapi::GetAdaptersInfo(i r3r4, *l ${maxsize} r2)i.r1'

a) why "i r3r4"? If r3 is the space of memory , what´s r4?

b) "*l ${maxsize} r2" . What´s r2?

Thatks a lot brainsucker i´m impressed :D


The school is here: nsis.sourceforge.net/system.html.
r4 gets the value of r3.
r2 gets the resulting length.
the system parameter consists of two parts: the input and the output one. r3, ${maxsize} - input, r4, r2 - output.


thank you very much for you help¡¡¡¡


thank you very much for you help¡¡¡¡


FYI... the link is broken. I think it might have something to do with the migration to a wiki for the NSIS homepage.


It was just a temporary file which is now available at:

http://nsis.sourceforge.net/Docs/System/System.html


Hi,brainsucker .
I use the following script in my installation script,but
when i run the setup.exe,i got the following error msg,and the setup.exe aborted.I just use your script as a standalone
function,am i do something wrong?Many thanks.
------------------------------------------------------------
AppName: zimssetup.exe AppVer: 0.0.0.0 ModName: math.dll
ModVer: 0.0.0.0 Offset: 00001d04

-----------------------------------------------------------
error report
-----------------------------------------------------------
Exception Information
Code:0x0000005 Flags:0x00000000
Record 0x0000000000000000 address:0x0000000000d31d04
but when i run your script alone,it works well.
...and more
----------------------------------------------------------

Originally posted by brainsucker
Hello guys ;)
Script enumerates thru all installed adapters.
Math used only for formating, so if you don't need pretty mac addr, remove math::script lines.
GL.


Name "MacAddr Plugin Example"

>OutFile "macaddr.exe"
>SetPluginUnload alwaysoff

Section "ThisNameIsIgnoredSoWhyBother?"
SetOutPath $TEMP

>!define maxsize 4096

System
::Alloc ${maxsize}
pop $3
System
::Call 'iphlpapi::GetAdaptersInfo(i r3r4, *l ${maxsize} r2)i.r1'
MessageBox MB_OK "GetAdaptersInfo return is $1"
strcmp $1 0 0 finish ;in case of errors

cont:
strcmp $4 0 finish ; no more adapters
System::Call '*$4(i.r4,i,&t260.r5, &t132.r6, i.r7, l.r8)'

Math::Script "hex={'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};"
Math::Script "s=''; a=r8; b=r7; #{b-->0,s=s+hex***91;a/16%16***93;+hex***91;a%16***93;+#***91;b>0,'-',''***93;; a=a/256;}; r9=s;"

MessageBox MB_OK "Adapter name is $5$\ndesc $6$\naddr len $7$\naddr $8$\nMacAddr: $9"

>goto cont

finish:
System::Free $3

; last plugin call must not have /NOUNLOAD so NSIS will be able to delete the temporary DLL
SetPluginUnload manual
; do nothing
System::Free 0
Math::Script ""

>SectionEnd
>

The script should work fine so long as Math isn't unloaded between the two calls. You can add /NOUNLOAD on the first call to make sure of that and then you won't need SetPluginUnload.

When I add /NOUNLOAD, the script runs fine for me. Let me know if that's not the case for you.