Hello Charles
you have a macro peeks for string as shown below
macro peeks string(r,v,i,n)
===========================
'r returned string
'v variable being peeked
'i offest from variable's base address
'n number of bytes
r=nuls n
#if typecodeof(v)<=0 'not a variable
' ' '
#elseif typecodeof(v)<0x80 'primitive number
copy strptr(r),@v+i,n '
#elseif typecodeof(v)<0x100 'string
copy strptr(r),strptr(v)+i,n '
#else 'UDTs, Objects etc
copy strptr(r),@v+i,n '
#endif
end macro
how about a macro for peeking integer ?
i couldn't figure out how to do it , please help, thanxx in advance
Hi Chris,
Are you trying to peek integers from a string?
No, peeking a DWORD array called ipArray(0)
the code is as below for getting a MAC address inside the FUNCTION GetMACaddress
note that the results from this program are wrong MAC addresses and do not use this program
'GitMacAdd2.o2bas
$ filename "GitMacAdd2.exe"
uses rtl64
uses corewin
#lookahead
'declares
%NO_ERROR = 0
'
! SendARP LIB "iphlpapi.dll" ALIAS "SendARP" _
(BYVAL DestIP AS DWORD, BYVAL SrcIP AS DWORD, pMacAddr AS DWORD, _
PhyAddrLen AS DWORD) AS DWORD
! inet_addr LIB "wsock32.dll" ALIAS "inet_addr" (cp AS ASCIIZ) AS DWORD
def codeptr @ %1
def varptr @ %1
def Trim ltrim(rtrim(%1))
'================================
FUNCTION GetMACaddress(szIP AS ASCIIZ) AS STRING
'
' Input: IP address from which you want the MAC address
' Output: The MAC address as "00-00-00-00-00-00" on success
' null string on failure. Bad IP addresses returns a
' null string.
'
LOCAL Result AS LONG
LOCAL MACbytes AS LONG
indexbase 0
DIM ipArray(0) AS DWORD
DIM p AS sys
Local RetSt as string
Local dwRemoteIP As Dword
int v[5]
'
FUNCTION = ""
IF LEN(TRIM(szIP)) = 0 THEN
return ""
EXIT FUNCTION
end if
'
'The first six bytes of the array receive the physical address that corresponds to the IP
'address specified by szIP. See "SendARP" in MSDN for more info.
MACbytes = 6
'
'Convert Asciiz IP to a DWord IP.
dwRemoteIP = inet_addr(szIP)
Result = SendARP( dwRemoteIP , 0, ipArray(0), MACbytes)
IF Result = %NO_ERROR THEN
'Success
' we cannot use a STRPTR here - the prog will just exit
p = VARPTR(ipArray(0))
copy @v,p+1 ,6
' original code was like this which comes with peek
' RetSt= HEX( peek(ipArray(0)) ) + "-" + HEX(peek(ipArray(0))+1) + "-" + HEX(peek(ipArray(0))+2) +
' "-" + HEX(peek(ipArray(0))+3) + _
' "-" + HEX(peek(ipArray(0))+4) + "-" + HEX(peek(ipArray(0)) +5)
RetSt= HEX(@v[0]) + "-" + HEX(@v[1]) + "-" + HEX(@v[2]) +
"-" + HEX(@v[3]) + _
"-" + HEX(@v[4]) + "-" + HEX(@v[5])
RetSt = Trim(RetSt)
Return RetSt
END IF
END FUNCTION
'============================
FUNCTION GMAIN()
'
'just test the GetMACaddress function. If you want a standalone utility
'add a little code to PARSE COMMAND$, pass an IP address and voila'.
'
LOCAL sMAC AS STRING
sMAC = GetMACaddress("127.0.0.1")
print " Gmain Mac Address : " SMac
'
END FUNCTION
GMAIN()
' if done outside then this gives a different string value?
string sMAC
sMAC = GetMACaddress("127.0.0.1")
print " Mac Address : " SMac
GMAIN()
Hi Chris,
To read the bytes in any numeric array, you can use a byte overlay
byte bt at @ipArray 'or byte bt at varptr(ipArray)
Then display the bytes you want: hex(bt(0)) "-" Hex(bt(1) etc.