I thought I had it figured out on how to read the subfolders in the System Registry, but apparently I don't.
Does anyone have any sample code in MASM32 I could examine that shows how to read them? In particular I'm trying to read the folder names in "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\Interfaces\"
Many thanks,
Shooter
http://www.masm32.com/board/index.php?topic=11963.msg90835#msg90835
version 2.03 has a decent routine
you would make a string like:
SubKeyName db "SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\Interfaces",0
another null terminated string for the value name,
and use HKEY_LOCAL_MACHINE as the key, which is an equate in windows.inc
don't forget to:
INCLUDE \masm32\include\advapi32.inc
INCLUDELIB \masm32\lib\advapi32.lib
Dave,
Thanks. I ran into that while searching the forum and I've VERY interested in how that all works for converting the ProductIDs, but for now I have to concentrate on this program. I've written some code that reads values of subkeys with success, but in this particular case I need to find a subfolder first before I can read the values in it's subkeys. Windows is kinda strange as to where it stores some of it's info.
In your proggy, does it actually read sub-folders, or just the values listed in "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion" ?
-Shooter
well - there are Keys, SubKeys, and Values
Values may have a number of different Types
in your case, "HKEY_LOCAL_MACHINE" is the Key name
"SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\Interfaces" is a SubKey name
under that SubKey, are more SubKeys
you may need to use RegEnumKey or RegEnumKeyEx to enumerate the SubKeys
under those SubKeys, you will find Values like "Domain", which has the Type REG_SZ (zero-terminated string)
another example is "EnableDHCP", which has the Type REG_DWORD
the Keys (HKEY_LOCAL_MACHINE) and Types (REG_DWORD) are all defined as EQUates in windows.inc (they really belong in advapi32.inc)
here is a link to the registry functions...
http://msdn.microsoft.com/en-us/library/ms724875%28v=VS.85%29.aspx
in my code, i already knew the subkey names in advance, which simplifies the code a bit :P
Shooter, it is actually very easy... you basically open a handle to the "root" key ("parent folder") you want to enumerate then you pass that handle to RegEnumKeyEx in a loop until RegEnumKeyEx returns ERROR_NO_MORE_ITEMS you can use RegEnumValue
to get all the values in the currently enumerated key... You must open the "root" key with KEY_ENUMERATE_SUB_KEYS rights...
Quote from: Gunner on February 15, 2011, 11:24:36 PM
Shooter, it is actually very easy... you basically open a handle to the "root" key ("parent folder") you want to enumerate then you pass that handle to RegEnumKeyEx in a loop until RegEnumKeyEx returns ERROR_NO_MORE_ITEMS you can use RegEnumValue
to get all the values in the currently enumerated key... You must open the "root" key with KEY_ENUMERATE_SUB_KEYS rights...
Rob, Question about that... I took a look at a discussion (http://www.masm32.com/board/index.php?topic=13291.0) on the forum you and Dave (and others) were having the other day using RegEnumKeyEx and wrote a quick code causing it to loop (pretty close to exactly what you wrote as an example)... I noticed that it didn't stop at the end of the current 'folder' set, but continued on to the next one. I take it does that all the way until the end of the registry? I don't want to read the entire registry, just the one 'folder' set... anyway of knowing when I reach that end? (I'm still trying to understand all of the API calls, but it's a slow process, especially when I can't sit down and concentrate on it like I want to.)
In particular, I've used GetHostByName to find the active IP address, but when the computer is using a manual connection, I want to identify the other addresses (Subnet Mask, Default Gateway, Preferred DNS, etc). So far the only means that I know of to determine if DHCP is being used (from the registry) is to look at [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\DHCP] to see if the "Start" value is not equal to 4. If it's 4 (DHCP not used), then I need to extract those other addresses.
I suppose I could compare the value of "DhcpIPAddress" within the TCPIP set of 'folders' to the one I retrieve from GetHostByName to see if I've found the correct NIC, and then get the other addresses from that folder (such a pain in the @$$).
I tried to see if GetHostByName could be used to extract the non-DHCP addresses, but I haven't really been able to find an example to study off of yet, and my current machine USES DHCP, so it's not like I can use my computer as an example.
-Shooter
it will enumerate all subkeys under the one you start with
if you want to enumerate only one, create a string with that subkey and open a handle to it, then enumerate
as Rob said, it will return ERROR_NO_MORE_ITEMS when done
Quote from: Shooter on February 16, 2011, 12:04:26 PM
Rob, Question about that... I took a look at a discussion (http://www.masm32.com/board/index.php?topic=13291.0) on the forum you and Dave (and others) were having the other day using RegEnumKeyEx and wrote a quick code causing it to loop (pretty close to exactly what you wrote as an example)... I noticed that it didn't stop at the end of the current 'folder' set, but continued on to the next one. I take it does that all the way until the end of the registry? I don't want to read the entire registry, just the one 'folder' set... anyway of knowing when I reach that end? (I'm still trying to understand all of the API calls, but it's a slow process, especially when I can't sit down and concentrate on it like I want to.)
In particular, I've used GetHostByName to find the active IP address, but when the computer is using a manual connection, I want to identify the other addresses (Subnet Mask, Default Gateway, Preferred DNS, etc). So far the only means that I know of to determine if DHCP is being used (from the registry) is to look at [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\DHCP] to see if the "Start" value is not equal to 4. If it's 4 (DHCP not used), then I need to extract those other addresses.
I suppose I could compare the value of "DhcpIPAddress" within the TCPIP set of 'folders' to the one I retrieve from GetHostByName to see if I've found the correct NIC, and then get the other addresses from that folder (such a pain in the @$$).
I tried to see if GetHostByName could be used to extract the non-DHCP addresses, but I haven't really been able to find an example to study off of yet, and my current machine USES DHCP, so it's not like I can use my computer as an example.
-Shooter
Yes it will enumerate all "Top level" folders until there is no more. So if you pass HCU as the root folder to RegEnumKeyEx, it will enumerate ALL the "Top Level" folders of HKEY_CURRENT_USER. RegEnum does not however enumerate child folders of the TL Folders or children of the children.
But if all you want is to see if some value is set a certain way, then (In your example above) Off the top of my head so if I get an api name wrong, don't shoot me! You would do a RegOpenKeyEx with:
HKEY_LOCAL_MACHINE == hKey
"SYSTEM\CurrentControlSet\Services\DHCP" == SubKey
KEY_QUERY_VALUE == access rights
The handle is returned in the pointer you passed as phkResult...
Next RegQueryValueEx:
phkResult == hKey
Start == ValueName
REG_DWORD == lpType (I don't think you need to set this since you are expecting a dword anyway so you know the type of data you are expecting)
lpData is a pointer to a dword var to hold the setting
Once you got the info, pass phkResult to RegCloseKey
Now, if you still want to Enumerate all keys of a "Folder" I will help with that too...
Welp, I'm thinking the best way I can do what I want above is to read in the GUIDs (#4) from the subkey (#5), compare the value in DhcpIPAddress (#1) to the IP address I got from GetHostByName. If I get a match, then read in the other two values I'm looking for (#2 & #3), if not, move on.
It's the loading of the names of the GUIDs that I'm having a problem with. Recursive input seems to be the only viable means to achieve this as each machine I work on has a different set of numbers depending on the model of the NIC.
Got a good way to do that, OR possibly a completely different approach to this?
Thanks a million,
-Shooter
(http://img109.imageshack.us/img109/8543/findmeregeditscrshot01.png) (http://img109.imageshack.us/i/findmeregeditscrshot01.png/)
Sure you could enumerate the subkeys under interfaces, but there should be API functions to get the info you need.. Check out:
GetIpAddrTable
The GetIpAddrTable function retrieves the interface–to–IP address mapping table.
And the structure IP_ADAPTER_INFO might be of use to you:
IP_ADAPTER_INFO
The IP_ADAPTER_INFO structure contains information about a particular network adapter on the local computer
Hell, the more I look in the PSDK the more I find... Look up Internet Protocal Helper on MSDN or your PSDK and you will find what you need...
GetIpAddrTable
The GetIpAddrTable function retrieves the interface–to–IP address mapping table.
I take it I have to build my own Structs for this to work with Masm32? I've included "Iphlpapi.lib", but something is still wrong.
I get the following error:
QuoteReadRegKey.asm(289) : error A2114: INVOKE argument type mismatch : argument : 1
ReadRegKey.asm(126) : warning A4014: instructions and initialized data not supported in BSS segments
My declaration is:
.data
_MIB_IPADDRTABLE struct
dwAddr DW 0
dwIndex DW 0
dwMask DW 0
dwBCastAddr DW 0
dwReasmSize DW 0
unused1 DB 0
wType DW 0
_MIB_IPADDRTABLE ends
Line 126:
pIpAddrTable _MIB_IPADDRTABLE <?>
.
.
.
bOrder DW ?
pdwSize DW ?
And I'm calling it with (line 289):
INVOKE GetIpAddrTable,pIpAddrTable,pdwSize,bOrder
I'm not undertstanding what I'm doing wrong. Any ideas?
-Shooter
(bump)
do you have:
INCLUDE \masm32\include\iphlpapi.inc
INCLUDELIB \masm32\lib\iphlpapi.lib
Quote from: dedndave on February 19, 2011, 03:34:08 PM
do you have:
INCLUDE \masm32\include\iphlpapi.inc
INCLUDELIB \masm32\lib\iphlpapi.lib
Dave,
Yup... just not sure how to implement this one. All the examples I'm finding across the web (very few, by the way) are in a different language, and I don't know how to translate them.
-Shooter
well - this tells you something is wrong
ReadRegKey.asm(289) : error A2114: INVOKE argument type mismatch : argument : 1
that can be caused by the lack of a PROTOtype
or else, the first parm probably should be a dword type and you have it defined otherwise
perhaps it needs a pointer...
INVOKE GetIpAddrTable,ADDR pIpAddrTable,pdwSize,bOrder
;or
INVOKE GetIpAddrTable,OFFSET pIpAddrTable,pdwSize,bOrder
but that mistake usually assembles ok - then generates c0000005 :P
Might be needs addr like:
INVOKE GetIpAddrTable, Addr pIpAddrTable,Addr pdwSize, bOrder
Quote from: fearless on February 19, 2011, 04:05:41 PM
Might be needs addr like:
INVOKE GetIpAddrTable, Addr pIpAddrTable,Addr pdwSize, bOrder
Addr on the first param assembles fine, but yields an exception when ran. I haven't tried it on the second one yet.
your structure defintion is out of the ballpark, i think
http://msdn.microsoft.com/en-us/library/aa366847%28v=vs.85%29.aspx
it is a nested structure - you will also need to look at MIB_IPADDRROW
http://msdn.microsoft.com/en-us/library/aa366845%28v=vs.85%29.aspx
fearless is right also - the first 2 parms are pointers
Quote from: dedndave on February 19, 2011, 04:11:27 PM
your structure defintion is out of the ballpark, i think
http://msdn.microsoft.com/en-us/library/aa366847%28v=vs.85%29.aspx
it is a nested structure - you will also need to look at MIB_IPADDRROW
http://msdn.microsoft.com/en-us/library/aa366845%28v=vs.85%29.aspx
fearless is right also - the first 2 parms are pointers
Wouldn't these be part of the included files?
i don't find them in the includes
here is an example by Farabi...
http://www.masm32.com/board/index.php?topic=15028.msg121757#msg121757
usually, if something is missing in the inc files, you can use the forum search tool to find info :P
Quote from: dedndave on February 19, 2011, 04:21:55 PM
i don't find them in the includes
here is an example by Farabi...
http://www.masm32.com/board/index.php?topic=15028.msg121757#msg121757
usually, if something is missing in the inc files, you can use the forum search tool to find info :P
OK, I see how Farabi created not one, but three structs that appear to be what I need, but either I'm blind or they aren't there... he didn't seem to use them in his post.
_MIB_IPADDRTABLE struct
dwAddr DW 0
dwIndex DW 0
dwMask DW 0
dwBCastAddr DW 0
dwReasmSize DW 0
unused1 DB 0
wType DW 0
_MIB_IPADDRTABLE ends
a problem here is that you have defined the structure as initialized
then, in the uninitialized data section...
pIpAddrTable _MIB_IPADDRTABLE <?>
it spits out an error
replace the 0's with ?'s
_MIB_IPADDRTABLE struct
dwAddr DW ?
dwIndex DW ?
dwMask DW ?
dwBCastAddr DW ?
dwReasmSize DW ?
unused1 DB ?
wType DW ?
_MIB_IPADDRTABLE ends
usually, structures are defined as initialized only when they are your own invention - not msdn stuff
Quote from: dedndave on February 19, 2011, 04:45:20 PM
a problem here is that you have defined the structure as initialized
then, in the uninitialized data section...
Alright... tried that, but still crashes, and no matter what, I'm still getting that 'warning' about the BSS segment. How, or rather, where should I be putting this code? I noticed in Farabi's code he didn't have .data, .data?, or .code.
I usually put my structures under the .const section and before any .data stuff. Then i put the data structure variables in .data and any other uninitialized data vars in .data?
I would probably arrange it all like this:
.CONST
_MIB_IPADDRTABLE STRUCT
dwAddr DW 0
dwIndex DW 0
dwMask DW 0
dwBCastAddr DW 0
dwReasmSize DW 0
unused1 DB 0
wType DW 0
_MIB_IPADDRTABLE ENDS
.DATA
pIpAddrTable _MIB_IPADDRTABLE <>
.DATA?
pdwSize DW ?
bOrder DW ?
.CODE
INVOKE GetIpAddrTable, Addr pIpAddrTable, Addr pdwSize, TRUE ; instead of using bOrder var just set it
Edit: after looking at pdwSize - needs to be set before call to function to specifies the size in bytes of the buffer pointed to by the pIpAddrTable parameter. which is a MIB_IPADDRTABLE Structure (http://msdn.microsoft.com/en-us/library/aa366847%28v=vs.85%29.aspx). The one defined and your using is also required, but is called MIB_IPADDRROW Structure (http://msdn.microsoft.com/en-us/library/aa366845%28v=vs.85%29.aspx)
typedef struct _MIB_IPADDRTABLE {
DWORD dwNumEntries;
MIB_IPADDRROW table[ANY_SIZE];
} MIB_IPADDRTABLE, *PMIB_IPADDRTABLE;
typedef struct _MIB_IPADDRROW {
DWORD dwAddr;
DWORD dwIndex;
DWORD dwMask;
DWORD dwBCastAddr;
DWORD dwReasmSize;
unsigned short unused1;
unsigned short wType;
} MIB_IPADDRROW, *PMIB_IPADDRROW;
tbh it looks a bit messy. The community comment on the page has this which is just lol:
QuoteI came across this poor excuse for a structure and immediately had to call over a fellow developer to point how absurd it looked. To seriously consider, in production code, making a two member struct where one member simply gives the number of elements of the other and then use the worst macro name I have ever come across, "ANY_SIZE, is lunacy. Only a vast amount of bumbling chicanery could have made such a simple concept so confusing to the first glance.
Quotebumbling chicanery
:lol
.CONST
_MIB_IPADDRTABLE STRUCT
dwAddr DW 0
dwIndex DW 0
dwMask DW 0
dwBCastAddr DW 0
dwReasmSize DW 0
unused1 DB 0
wType DW 0
_MIB_IPADDRTABLE ENDS
.DATA
pIpAddrTable _MIB_IPADDRTABLE <>
when you define a structure type, it does not need to be in a section
placing it a section generates data - in the code fearless posted - twice :bg
you are merely describing the data type
So, back to what Fearless was saying about pdwSize, how is it known how big to make it?
from what i can see.....
you set the dwSize dword to 0
call the function - it should fail with ERROR_INSUFFICIENT_BUFFER
but - it will fill the dwSize value with the number of bytes required in the buffer
then - allocate space (HeapAlloc or something) for that buffer
set the pointer
set the size it's set for you
make the call again
it's similar to reading a registry value for which you do not know the size
i dunno how to test it without DHCP :P
i mean - i can dump the results and all
i just can't see how it would look if i were on a DNS domain
i cheated - lol
without using any structures....
INCLUDE \masm32\include\masm32rt.inc
INCLUDE \masm32\include\ws2_32.inc
INCLUDE \masm32\include\iphlpapi.inc
INCLUDELIB \masm32\lib\ws2_32.lib
INCLUDELIB \masm32\lib\iphlpapi.lib
_MIB_IPADDRROW STRUCT
dwAddr dd ?
dwIndex dd ?
dwMask dd ?
dwBCastAddr dd ?
dwReasmSize dd ?
unused1 dd ?
wType dd ?
_MIB_IPADDRROW ENDS
_MIB_IPADDRTABLE STRUCT
dwNumEntries dd ?
table dd ?
_MIB_IPADDRTABLE ENDS
.DATA
IPdwSize dd 0
.DATA?
BigAssBuffer db 8192 dup(?)
.CODE
_main PROC
;call it once to get the required buffer size
INVOKE GetIpAddrTable,offset BigAssBuffer,offset IPdwSize,0
;call it again to fill the buffer
INVOKE GetIpAddrTable,offset BigAssBuffer,offset IPdwSize,0
mov edx,offset BigAssBuffer
mov ecx,128
loop00: push ecx
push edx
mov eax,[edx]
print uhex$(eax),32
pop edx
pop ecx
add edx,4
loop loop00
print chr$(13,10)
inkey
exit
_main ENDP
END _main
Dave,
Do you know of any reason why adding this line:
include masm32rt.inc
blocks windows.inc from loading? I received the error:
QuoteE:\Program Files\RadASM\masm32\Include\masm32rt.inc(38) : fatal error A1000: cannot open file : \masm32\include\windows.inc
But, if I comment out the 'masm32rt.inc', it assembles just fine.
-Shooter
well - there are a few issues there
first - you have much of that stuff declared elsewhere
second - you're on the drive E:
is that the drive where you have MASM32 installed ?
third - i noticed you have no paths in your INCLUDE's
i guess you have the LIB and INCLUDE environment variables set ?
finally - have a look in the file \masm32\include\masm32rt.inc
you can see what it does :U
Quote from: dedndave on February 19, 2011, 08:46:58 PM
well - there are a few issues there
first - you have much of that stuff declared elsewhere
second - you're on the drive E:
is that the drive where you have MASM32 installed ?
third - i noticed you have no paths in your INCLUDE's
i guess you have the LIB and INCLUDE environment variables set ?
finally - have a look in the file \masm32\include\masm32rt.inc
you can see what it does :U
Yup, everything is on my thumb-drive, E:. Yup, my environment is already established to those paths. Huh? Declared elsewhere? How does that keep a file from being read in? I should've received a different error, right?
as i said - have a look inside that file
you have most of the stuff it includes elsewhere in your source (your ReadRegKey.inc file)
at any rate - you should assemble from the same drive as masm32 is installed
and - the masm32 folder must be in the root
then - specify paths like i did in the example code
the entire library is set up to work that way
not how i would have done it - but that is how it is :P
here is the EXE for you to play with Scott
later on, when i have some time, i will make a proper version using structures...
Quote from: dedndave on February 19, 2011, 09:13:59 PM
here is the EXE for you to play with Scott
later on, when i have some time, i will make a proper version using structures...
Thank you very much, especially for your efforts. There's a lot more data than I thought there'd be, or is that just a result of ECX=128?
i just didn't know how much to display
after all, it is an 8 Kb buffer - it can hold 2048 dwords
on my machine, of the 128 dwords shown, most are 0's at the end
it looks like only a couple structures worth of stuff
but - you can see what the values are by looking at the corresponding names in the structure
When you see C statements like:
MIB_IPADDRROW table[ANY_SIZE];
It generally means that you need to allocate memory dynamically because you don't know at assembly time what the required buffer size will be. Accessing the buffer in assembly is a little more difficult than it is in C, but still not a problem.
The attachment contains the Microsoft example from here (http://msdn.microsoft.com/en-us/library/aa365949(VS.85).aspx), in C and in assembly (MSDN was inaccessible at the time I posted this, but the link was working earlier).
Dave,
I modified to your code example for the purpose of my program:
mov edx,offset BigAssBuffer
mov ecx,16
loop00: push ecx
push edx
mov eax,[edx]
; print uhex$(eax),32
pop edx
pop ecx
add edx,4
loop loop00
lea eax, BigAssBuffer
invoke inet_ntoa,eax
mov DWORD PTR [lpbSubnetMask], eax
mov eax, DWORD PTR [BigAssBuffer]+16
invoke inet_ntoa,eax
mov DWORD PTR [lpbDNSAddress], eax
and I get two addresses that are not showing up on my LAN Status dialog: 78.88.64.0 and 1.0.0.0. I'll need to do some research to identify where in that BigAssBuffer the Subnet Mask (should be 255.255.0.0) and Default Gateway (should be 172.17.1.1) are supposed to be.
Michael,
I tried that link, but I get
QuoteThe specified CGI application encountered an error and the server terminated the process.
Not sure what's going on there.
-Shooter
Scott
does the program Michael posted work for you ?
it works ok here - i really can't improve on it - lol
it is a port of the msdn example - which is what i planned on doing
well - a little mysterious that one structure is 24 bytes, one is 28 bytes, the function requires 300, and i only have 2 devices - lol
but - we have to get your installation working correctly
if you cannot assemble the example programs posted, you are working with one hand tied behind your back
the print macro requires:
INCLUDE \masm32\include\masm32.inc
INCLUDE \masm32\macros\macros.asm
INCLUDELIB \masm32\lib\masm32.lib
notice the path of macros.asm - in my earlier PM, i think i had it wrong
I was thinking that perhaps the explanation for the 300 byte buffer size was that there were other entries that were not included in the dwNumEntries count, but when I alter the code to display the next entry I get:
Interface Index[2]: 0
IP Address[2]: 0.0.0.0
Subnet Mask[2]: 0.0.0.0
BroadCast[2]: 0.0.0.0 (0)
Reassembly size[2]: 0
Type and State[2]:
i think the 300 bytes is some sort of "minimum size" or something for this function
it may be usable by other API's that rely on this function as a prerequisite - like what was it - AddIPAddress, etc
Scott,
let's get this working...
you should be able to assemble and run this program
INCLUDE \masm32\include\masm32rt.inc
.CODE
_main PROC
print chr$('Hello World'),13,10
inkey
exit
_main ENDP
END _main
Sorry guys. I went to a college bar last night and, well... I'm gonna need a few hours to get my head back on level. The ole' grey matter ain't what it used to be. :red
Dave,
I've manually edited the "masm32rt.inc" file to remove any path reference, which works just fine for all the .lib .inc references, but the environmental settings do not include a path for .asm files (macros.asm is in this file)... not really sure how to get RadASM to play nice with that.
Michael,
Is it safe to assume that "Interface Index
- " will always be the NIC that's actively connected to a network? I don't see a reason to go beyond reading any more info if that's the case. All of the computers I'll be dealing with will only have one NIC and unless there's a problem connecting to the domain, that's the only set of addresses I need.
Truth be told, I'm not sure what the other indexes are referring to.
Also, I noticed that your example did not come up with the Default Gateway address. Is that a shortcoming of doing it this way, or did I miss something?
Thanks,
-Shooter
well - that's not a very good fix - lol
you might try assembling with the /X switch (ML)
(after restoring the paths in masm32rt.inc)
Quote from: dedndave on February 21, 2011, 04:41:07 PM
well - that's not a very good fix - lol
you might try assembling with the /X switch (ML)
(after restoring the paths in masm32rt.inc)
I'm not all that up to speed on that... what does the /X switch do?
well - i am thinking you have INCLUDE and LIB environment variables set up for some compiler
the /X switch forces MASM to ignore the environment variable for includes
the problem with modifying the masm32rt.inc file is that it makes your installation different from everyone elses
Quote from: dedndave on February 21, 2011, 05:00:23 PM
the problem with modifying the masm32rt.inc file is that it makes your installation different from everyone elses
This is true, but I'm not the one that designed the environmental features of RadASM. This goes back to what I was trying to ask about in the RadASM bug find posts... are they relative to the root, or are they relative to the project file? (On that particular case I had an .RC file with a relative path set, but I never got the real answer if it was in relation to the root folder or to the .RC folder.)
By the way, has anyone ever messed around with the DNS API set of functions? I was debugging ipconfig.exe and saw it used several times. So far, however, I'm only finding it as part of the MS Visual Studio set of SDKs, which I don't have with me on the road.
-Shooter
well - another way to go....
in the assembly batch file, SET LIB= and SET INCLUDE=
these are applied on a per-session basis, so do not permanently modify the variables
maybe use the SETLOCAL batch command - i.e., they are only applied during the batch run
OK, I 'm confused on what this is for:
push [edi].MIB_IPADDRTABLE.table.MIB_IPADDRROW.dwAddr
pop IPAddr.S_un.S_addr
it's a memory to memory move
they are taking the IP address from one structure and placing it into another
might be an unnecessary step, too - lol
they could probably convert it where is sits
Quote from: dedndave on February 21, 2011, 07:43:49 PM
it's a memory to memory move
they are taking the IP address from one structure and placing it into another
might be an unnecessary step, too - lol
they could probably convert it where is sits
That's what I was wondering. Is it not possible to do this:
invoke inet_ntoa,[edi].MIB_IPADDRTABLE.table.MIB_IPADDRROW.dwMask
(I haven't tried it yet... just wondering though.)
Quote from: Shooter on February 21, 2011, 06:53:06 PM
OK, I 'm confused on what this is for:
push [edi].MIB_IPADDRTABLE.table.MIB_IPADDRROW.dwAddr
pop IPAddr.S_un.S_addr
The push instruction effectively uses the structures as a template, with the:
.MIB_IPADDRTABLE.table.MIB_IPADDRROW.dwAddr
Resolved to the value 4 at assembly time, so the source operand is effectively [edi+4].
Quote
Is it not possible to do this:
Code:
invoke inet_ntoa,[edi].MIB_IPADDRTABLE.table.MIB_IPADDRROW.dwMask
That will work, without any need for the DWORD PTR, but I was translating a C source, where to do it that way you would probably have to resort to some messy code to satisfy the compiler.
Michael,
That makes sense now.
I'm still trying to find a means of extracting the Default Gateway. I've read through some of the stuff on MSDN about GetHostByName and GetIpAddrTable, but no joy so far, unless like their tables it's buried somewhere.
-Shooter
there are a few functions...
GetNetworkParams
GetAdaptersAddresses
GetAdaptersInfo
GetPerAdapterInfo
searching around a bit, i have found a number of solutions that involve shelling an "ipconfig /all>temp.txt" command and parsing the output text
after looking at the functions, that sounds a lot easier :P
i found this code that may be of interest...
http://www.koders.com/c/fidE8769D7EC08E6C2F7D9D0A2E16E43E8F5A199529.aspx
some methods use WMI
that's a real bag of worms
Quote from: dedndave on February 21, 2011, 09:19:44 PM
searching around a bit, i have found a number of solutions that involve shelling an "ipconfig /all>temp.txt" command and parsing the output text
after looking at the functions, that sounds a lot easier :P
I think I'm in agreement with you on that. Shoot, looking at the registry shows just how messed up the network stuff is.
Quote from: dedndave on February 21, 2011, 09:53:15 PM
i found this code that may be of interest...
http://www.koders.com/c/fidE8769D7EC08E6C2F7D9D0A2E16E43E8F5A199529.aspx
I dunno... it's sort of looking like that's how I originally wanted to go, examine the system registry, but in this case it appears as though the coder is looking for one specific type of 'control', or NIC... I'm dealing with a variety of them.
The attachment contains the Microsoft example from here (http://msdn.microsoft.com/en-us/library/aa365917%28VS.85%29.aspx), in C and in assembly. The example source contains some components that Visual C++ Toolkit 2003 could not handle (mostly the LeaseObtained and LeaseExpired code with the _s ("secure") functions), so I took the lazy route and simply removed these components.
The GetAdaptersAddresses (http://msdn.microsoft.com/en-us/library/aa365917%28VS.85%29.aspx) function for XP and later returns more information, but since I can't test it I didn't try to translate the example.
Quote from: MichaelW on February 22, 2011, 07:50:58 AM
The attachment contains the Microsoft example from here (http://msdn.microsoft.com/en-us/library/aa365917%28VS.85%29.aspx), in C and in assembly. The example source contains some components that Visual C++ Toolkit 2003 could not handle (mostly the LeaseObtained and LeaseExpired code with the _s ("secure") functions), so I took the lazy route and simply removed these components.
Michael,
That's exactly what I'm looking for! Thank you so very much. I'll have to delve into the code later on and see how you did it, but you nailed it on this one (test.exe). Thank you so very much!
-Shooter
Hey guys,
I'm getting this error:
QuoteReadRegKey.asm(324) : error A2070: invalid instruction operands
For this line:
mov IPIndexNum,[edi].MIB_IPADDRTABLE.table.MIB_IPADDRROW.dwIndex
I'm trying to implement Michael's example from his sample, GetIpAddrTable, from his original line:
Quote printf "\n\tInterface Index[%d]:\t%d\n", \
esi,[edi].MIB_IPADDRTABLE.table.MIB_IPADDRROW.dwIndex
I've tried to define IPIndexNum as both "DD ?" and "DW ?". The goal is to create a GUI application from his example, so I'd like to store the values into a variable to be called on by SendDlgItemMessage later on.
Can anyone give me a clue how to do this in MASM32?
Thanks,
-Shooter
I would move it to a register first, then move that to your variable (assuming IPIndexNum is defined as a dword value), so:
mov eax, [edi].MIB_IPADDRTABLE.table.MIB_IPADDRROW.dwIndex
mov IPIndexNum, eax
or...
push [edi].MIB_IPADDRTABLE.table.MIB_IPADDRROW.dwIndex
pop IPIndexNum
might be a byte or 2 smaller :P
That is true as well :U
when using register-index addressing - there may be no advantage to push/pop
i dunno - i'd have to disassemble some code to see
You guys are my heroes! I did that push/pop thing and it works great. Now.... moving on to translating the rest of it into something I want it to do via my GUI. He-he-hehhh. :bdg
FYI there is a masm32 macro
m2m which will make your code a little neater in this context:
m2m IPIndexNum, [edi].MIB_IPADDRTABLE.table.MIB_IPADDRROW.dwAddr
Alternatively there is an equivilent eax register version mrm
In my GetIpAddrTable code, after I posted I noticed that my indirect memory operands are "over-specified". So for example in the code below, while the MIB_IPADDRTABLE reference is necessary to indicate what [edi] is pointing to, the MIB_IPADDRROW reference is not because the table member is declared in the MIB_IPADDRTABLE structure as a MIB_IPADDRROW structure.
push [edi].MIB_IPADDRTABLE.table.MIB_IPADDRROW.dwAddr
pop IPAddr.S_un.S_addr
And the code can be shortened to:
push [edi].MIB_IPADDRTABLE.table.dwAddr
pop IPAddr.S_un.S_addr
Quote from: MichaelW on February 26, 2011, 09:28:41 PM
In my GetIpAddrTable code, after I posted I noticed that my indirect memory operands are "over-specified".
Sometimes for a person like me, being "over-specified" can have it's advantages... that told me how it 'really' worked. :bg