CLEO Help Get/Change My Local IP Address

CLEO related
Status
Not open for further replies.

ajom

Well-known member
Joined
Apr 14, 2020
Messages
389
Solutions
2
Reaction score
268
Location
Pluto
I can Get the Server IP Address and Port number using this:
Code:
0B39: samp get_current_server_address 1@ port 2@
I know how to change the Server IP and Port in memory.

But I was wondering how can I get what my Local IP address is? which applies on this scenarios:
  • My current Local IP Address is 192.68.1.34, then I will get a string of "192.168.1.34"
  • If I am running a vpn and my VPN IP is 10.1.1.54, then I will get a string of "10.1.1.54"

My primary goal is to recreate SAMP IP Changer in a flexible manner. But I can't even find my ip address using cheat engine. I tried the following:
  1. localhost ip address 127.0.0.1
  2. My Local IP Address 192.168.1.34
  3. My Public IP for example 155.29.32.2

I appreciate if you all can share some Snippets,Demo,Memory Pointer about how samp get my ip.
 

ajom

Well-known member
Joined
Apr 14, 2020
Messages
389
Solutions
2
Reaction score
268
Location
Pluto

That seems to be what I'm looking for getting the IP address. Suppose that now I can get the IP address by reading the IPv4 of a certain adapter, but how can I redirect all GTA SAMP raknet towards my target IP gateway(eg I got 3 running VPN on my PC and I pick a certain VPN local gateway)? I imagine the idea of real-time intercepting all data-net and charging it's route, but might prove inefficient.

Thank you again @monday
 

Parazitas

God
Joined
Jan 2, 2017
Messages
3,116
Solutions
5
Reaction score
882
Location
Lithuania
I made this following tutorial and i don't know what to do next , stuck
PHP:
:Adapter
// 0AB0: @Adapter 0
0AA2: 31@ = load_library "Iphlpapi.dll" // IF and SET
if 0AA4: 30@ = get_proc_address "GetAdaptersInfo" library 31@
then
    0AA7: call_function 30@ num_params 0 pop 0 29@ 28@
    0AD1: "%d" 1337 29@
end
0AA3: free_library 31@
0AB2: ret 0
 
Last edited:

ajom

Well-known member
Joined
Apr 14, 2020
Messages
389
Solutions
2
Reaction score
268
Location
Pluto
I made this following tutorial and i don't know what to do next , stuck

You forgot to pass the buffer length pointer, the input param needs to be 2:
PHP:
0AA7: call_function 30@ num_params 0 pop 0 29@ 28@


With this Script I can Obtain all information about a certain adapter index:
Code:
{$CLEO}
0000:

wait 10000

0AB1: @GetAdaptersInfo 1 _adapterindex 3 // 4th index is my wlan, try getting your own index

0A93: end_custom_thread

const
        // https://stuff.mit.edu/afs/athena/astaff/project/opssrc/nmap-2.54BETA34/mswin32/IPTypes.h
    MAX_ADAPTER_DESCRIPTION_LENGTH  = 128
    MAX_ADAPTER_NAME_LENGTH         = 256
    MAX_ADAPTER_ADDRESS_LENGTH      = 8 
        //

    ADAPTERLIBRARY                = 31@
    ADAPTERPROC                    = 30@
    ALLADAPTERSINFO                = 29@
    NEXTIPADAPTERINFO            = 28@
    ADAPTERCOMBOINDEX            = 27@
    ADAPTERSERIALKEY            = 26@
    ADAPTERDESCRIPTION            = 25@
    ADAPTERADDRESSLENGTH        = 24@
    ADAPTERADDRESS                 = 23@
    ADAPTERINDEX                 = 22@
    ADAPTERTYPE                 = 21@
    ADAPTERDHCPENABLED             = 20@
    ADAPTERCURRENTIPADDRESS     = 19@
    ADAPTERCURRENTSUBNETMASK    = 18@
    ADAPTERGATEWAY                 = 17@
    ADAPTERDHCPSERVER             = 16@
    ADAPTERHAVEWINS             = 15@ // I cannot find this inside the memory
    ADAPTERPRIMARYDNSSERVER     = 14@
    ADAPTERSECONDARYDNSSERVER     = 13@
    ADAPTERLEASEOBTAINED         = 12@
    ADAPTERLEASEEXPIRES         = 10@

    ADAPTERBLOCKSIZEPERINDEX = 9@
end

// https://docs.microsoft.com/en-us/windows/win32/api/iphlpapi/nf-iphlpapi-getadaptersinfo
// https://docs.microsoft.com/en-us/windows/win32/api/iptypes/ns-iptypes-ip_adapter_info
// 0AB1: @GetAdaptersInfo 1 _adapterindex 0@
// index must be within "0 upto ADAPTERMAXINDEX-1" where ADAPTERMAXINDEX is the number of adapters on your computer
:GetAdaptersInfo
if 0AA2: ADAPTERLIBRARY = load_library "Iphlpapi.dll" // IF and SET
then
    if 0AA4: ADAPTERPROC = get_proc_address "GetAdaptersInfo" library ADAPTERLIBRARY // IF and SET
    then
        28@ = 4096
        alloc ALLADAPTERSINFO 28@
        0AA5: call ADAPTERPROC num_params 2 pop 0 28@v ALLADAPTERSINFO // inparams 28@v=buffer size pointer << ALLADAPTERSINFO=buffer pointer

        0085: 11@ = ALLADAPTERSINFO
        0A8D: NEXTIPADAPTERINFO = read_memory 11@ size 4 virtual_protect 0 // get the pointer of the next ip adapter
      
        0085: ADAPTERBLOCKSIZEPERINDEX = NEXTIPADAPTERINFO
        0062: ADAPTERBLOCKSIZEPERINDEX -= 11@

        006A: 0@ *= ADAPTERBLOCKSIZEPERINDEX
        005A: 11@ += 0@  // jump to the specified index then afterwards read that adapter block

        11@ += 4
        0A8D: ADAPTERCOMBOINDEX = read_memory 11@ size 4 virtual_protect 0
      
        11@ += 4
        0085: ADAPTERSERIALKEY = 11@

        11@ += MAX_ADAPTER_NAME_LENGTH
        11@ += 4
        0085: ADAPTERDESCRIPTION = 11@

        11@ += MAX_ADAPTER_DESCRIPTION_LENGTH
        11@ += 4
        0A8D: ADAPTERADDRESSLENGTH = read_memory 11@ size 4 virtual_protect 0

        11@+=4
        0085: ADAPTERADDRESS = 11@ // byte array with "ADAPTERADDRESSLENGTH" index

        11@ += MAX_ADAPTER_ADDRESS_LENGTH
        0A8D: ADAPTERINDEX = read_memory 11@ size 4 virtual_protect 0

        11@ += 4
        0A8D: ADAPTERTYPE = read_memory 11@ size 4 virtual_protect 0

        11@ += 4
        0A8D: ADAPTERDHCPENABLED = read_memory 11@ size 4 virtual_protect 0

        11@ += 4
        // 0A8D: $UNKNOWN = read_memory 11@ size 8 virtual_protect 0

        11@ += 8
        0085: ADAPTERCURRENTIPADDRESS = 11@

        11@ += 16
        0085: ADAPTERCURRENTSUBNETMASK = 11@

        11@ += 16
        // 0A8D: $UNKNOWN = read_memory 11@ size 8 virtual_protect 0 // I think this is 4 byte leaseobtained and another 4 byte leaseexipires

        11@ += 8
        0085: ADAPTERGATEWAY = 11@

        11@ += 16
        0085: ADAPTERDHCPSERVER = 11@

        11@ += 16
        // 0A8D: $UNKNOWN = read_memory 11@ size 8 virtual_protect 0 // I think this is 4 byte leaseobtained and another 4 byte leaseexipires

        11@ += 8
        0085: ADAPTERPRIMARYDNSSERVER = 11@

        11@ += 16
        0085: ADAPTERSECONDARYDNSSERVER = 11@

        11@ += 16
        0A8D: ADAPTERLEASEOBTAINED = read_memory 11@ size 4 virtual_protect 0

        11@ += 4
        0A8D: ADAPTERLEASEEXPIRES = read_memory 11@ size 4 virtual_protect 0

        chatmsg "Memory Size per Adapter Block: %d" -1 ADAPTERBLOCKSIZEPERINDEX
        chatmsg "Pointer to Next IP Adapter Info: %d" -1 NEXTIPADAPTERINFO
        chatmsg "ComboIndex: %d" -1 ADAPTERCOMBOINDEX
        chatmsg "AdapterName: %s" -1 ADAPTERSERIALKEY
        chatmsg "Description: %s" -1 ADAPTERDESCRIPTION
        chatmsg "AddressLength: %d" -1 ADAPTERADDRESSLENGTH
        chatmsg "Address[%d] Pointer: %d" -1 ADAPTERADDRESSLENGTH ADAPTERDESCRIPTION
        chatmsg "Index: %d" -1 ADAPTERINDEX
        chatmsg "Type: %d" -1 ADAPTERTYPE
        chatmsg "DhcpEnabled: %d" -1 ADAPTERDHCPENABLED
        chatmsg "CurrentIpAddress: %s" -1 ADAPTERCURRENTIPADDRESS
        chatmsg "IpAddressList: %s" -1 ADAPTERCURRENTSUBNETMASK
        chatmsg "GatewayList: %s" -1 ADAPTERGATEWAY
        chatmsg "DhcpServer: %s" -1 ADAPTERDHCPSERVER
        chatmsg "HaveWins(UNKNOWN I cant Find at Memory): %d" -1 ADAPTERHAVEWINS
        chatmsg "PrimaryWinsServer: %s" -1 ADAPTERPRIMARYDNSSERVER
        chatmsg "SecondaryWinsServer: %s" -1 ADAPTERSECONDARYDNSSERVER
        chatmsg "LeaseObtained: %d" -1 ADAPTERLEASEOBTAINED
        chatmsg "LeaseExpires: %d" -1 ADAPTERLEASEEXPIRES

        free ALLADAPTERSINFO
    end
    0AA3: free_library ADAPTERLIBRARY
end
ret 0

My Only problem from the beginning is how can I change the local IP used by my client to connect towards the server

Edit: Forgot to add 0AA3: free_library ADAPTERLIBRARY
 

Attachments

  • my WLAN Adapter Info cut1.png
    my WLAN Adapter Info cut1.png
    1.1 MB · Views: 40
  • my WLAN Adapter Info cut2.png
    my WLAN Adapter Info cut2.png
    1.1 MB · Views: 37
  • my WLAN Adapter Info cut3.png
    my WLAN Adapter Info cut3.png
    1.1 MB · Views: 33
Last edited:

ajom

Well-known member
Joined
Apr 14, 2020
Messages
389
Solutions
2
Reaction score
268
Location
Pluto
@Parazitas Try this snippet to get the Local IPv4 Address of a certain adapter:
Code:
{$CLEO}
0000:

wait 10000

alloc 0@ 16

for 1@ = 0 to 5 // in my pc I got 6 adapters with me
    0AB1: @GetMyLocalIP 2 _adapterindex 1@ _storetobuffer 0@ // 4th index is my wlan, try getting your own index
    chatmsg "Adapter %d IP: %s" -1 1@ 0@
end

free 0@

0A93: end_custom_thread

const
    ADAPTERLIBRARY                = 31@
    ADAPTERPROC                    = 30@
    ALLADAPTERSINFO                = 29@
    NEXTIPADAPTERINFO            = 28@
    ADAPTERBLOCKSIZEPERINDEX    = 27@

    ADAPTERCAPACITY = 4096 // ADAPTERCAPACITY >= 640 * ADAPTERSCOUNT
   
    // uncomment the one that you need
    IPOFFSET = 0x1B0 // Current IP Address
    // IPOFFSET = 0x1C0 // Subnet Mask
    // IPOFFSET = 0x1D8 // Default Gateway
    // IPOFFSET = 0x1E8 // DHCP Server
    // IPOFFSET = 0x200 // Primary WINS Server
    // IPOFFSET = 0x210 // Secondary WINS Server
end

// 0AB1: @GetMyLocalIP 2 _adapterindex 0@ _storetobuffer 1@
// index must be within "0 upto ADAPTERMAXINDEX-1" where ADAPTERMAXINDEX is the number of adapters on your computer
// buffer size must be >= 16
:GetMyLocalIP
if 0AA2: ADAPTERLIBRARY = load_library "Iphlpapi.dll" // IF and SET
then
    if 0AA4: ADAPTERPROC = get_proc_address "GetAdaptersInfo" library ADAPTERLIBRARY // IF and SET
    then
        28@ = 4096
        alloc ALLADAPTERSINFO 28@
        0AA5: call ADAPTERPROC num_params 2 pop 0 28@v ALLADAPTERSINFO // inparams 28@v=buffer size pointer << ALLADAPTERSINFO=buffer pointer

        0085: 11@ = ALLADAPTERSINFO
        0A8D: NEXTIPADAPTERINFO = read_memory 11@ size 4 virtual_protect 0 // get the pointer of the next ip adapter
       
        0085: ADAPTERBLOCKSIZEPERINDEX = NEXTIPADAPTERINFO
        0062: ADAPTERBLOCKSIZEPERINDEX -= 11@

        006A: 0@ *= ADAPTERBLOCKSIZEPERINDEX
        005A: 11@ += 0@  // jump to the specified index then afterwards read that adapter block

        11@ += IPOFFSET

            // memcpy _source 11@ _destination 0@ _size 16
        1@+=15
        0A8C: write_memory 1@ size 1 value 0 virtual_protect 0 // null terminator
        1@-=15
        for 9@ = 1 to 15
            0A8D: 10@ = read_memory 11@ size 1 virtual_protect 0
            0A8C: write_memory 1@ size 1 value 10@ virtual_protect 0
            if 10@ == 0x0 // null terminator
            then break
            else
                1@++
                11@++
            end
        end
            //

        free ALLADAPTERSINFO
    end
    0AA3: free_library ADAPTERLIBRARY
end
ret 0

It needs a certain index, you can try doing a loop to get all ip of a certain range of index, it is safe from crash even if the index is out of bounds.
 

Attachments

  • IPOFFSET0x1B0.png
    IPOFFSET0x1B0.png
    1.1 MB · Views: 16

ajom

Well-known member
Joined
Apr 14, 2020
Messages
389
Solutions
2
Reaction score
268
Location
Pluto
Status
Not open for further replies.
Top