Get samp version

This can be used to create scripts that work with various samp versions.

In order to use it, I suggest to create "includes" folder inside the "gta_sa/cleo" folder. Then create "get_samp_version.txt" file inside it and paste the code below into it.
The code below contains 2 functions:
- get_samp_version_id (returning arbitrary number so you can easily compare it in your scripts)
- get_samp_version_name
Code:
/* 
    get_samp_version_id function is reading the "IMAGE_FILE_HEADER" of samp.dll (TimeDateStamp to be specific)
    That TimeDateStamp is based on compilation time. See this for more info:
    https://docs.microsoft.com/en-us/windows/win32/debug/pe-format#file-headers
    
    "TimeDateStamp = The low 32 bits of the number of seconds since 00:00 January 1, 1970 (a C run-time time_t value), that indicates when the file was created. " 
    
    In most versions that time stamp is located at offset 0x128 from samp.dll. In "0.3.7 R3 1" it is located at 0x120 offset though. 
*/

// Usage: 0AB1: call_scm_func @get_samp_version_id 0 _returned_id 0@   
:get_samp_version_id
30@ = 0
if 0AA2: 31@ = load_library "samp.dll" // IF and SET
then
    31@ += 0x128
    0A8D: 29@ = read_memory 31@ size 4 virtual_protect 1
    if 29@ == 0x5542F47A
    then
    // 0.3.7 R1
    30@ = 1
    end
    
    if 29@ == 0x59C30C94
    then
    // 0.3.7 R2
    30@ = 2
    end
    
    if 29@ == 0x5A6A3130
    then
    // 0.3.DL R1
    30@ = 3
    end
    
    31@ -= 8 // reading samp.dll + 0x120
    0A8D: 29@ = read_memory 31@ size 4 virtual_protect 1
    if 29@ == 0x5C0B4243
    then
    // 0.3.7 R3 1
    30@ = 4
    end   
end
0AB2: ret 1 30@

// Usage: 0AB1: call_scm_func @get_samp_version_name 0 _returned_name 0@
//
// There's no need to allocate memory, it is allocated inside function. If the function is called
// repetitively then you can free memory before making another call (using: 0AC9: free_allocated_memory 0@)
:get_samp_version_name
0AB1: call_scm_func @get_samp_version_id 0 _returned_id 30@
0AC8: 31@ = allocate_memory_size 30
if 30@ == 0
then
0AD3: 31@ = format "Not recognized"
end

if 30@ == 1
then
0AD3: 31@ = format "0.3.7 R1"
end

if 30@ == 2
then
0AD3: 31@ = format "0.3.7 R2"
end

if 30@ == 3
then
0AD3: 31@ = format "0.3.DL R1"
end

if 30@ == 4
then
0AD3: 31@ = format "0.3.7 R3 1"
end
0AB2: ret 1 31@

Then, the whole content of this txt file can be included in your scripts by using "$INCLUDE" directive of sanny builder like:
{$INCLUDE includes/get_samp_version.txt}

It should be included at the end of the script.

You could use it like this:
Code:
{$CLEO}
0000:

// this testing code requires sampfuncs (but the get_samp_version.txt file doesn't)
// so you could include it in some code without sampfuncs and both functions (id, name) should still work

repeat
wait 0
until 0AFA:  is_samp_available

call @get_samp_version_id 0 id 0@
call @get_samp_version_name 0 name 1@
chatmsg "%d, %s" -1 0@ 1@

0A93: end_custom_thread

{$INCLUDE includes/get_samp_version.txt}
 

dovidas147

Active member
Joined
Nov 1, 2018
Messages
32
Reaction score
2
Is this what im thinking it is? @Parazitas @monday ? Can you guys help me? Im trying to understand basic logic of memory offsets, pointers etc.

29@ == 0x5542F47A in decimal is unix time: 1430451322?
29@ is variable which is reading memory — samp.dll pointer + offset of unix time
in which we get hex value of unix time of compiled build which we can compare with other samp builds because all the builds contains different hex unix time?
 

monday

Expert
Joined
Jun 23, 2014
Messages
1,125
Reaction score
149
Depends on what you think it is:p
When you compile a binary (e.g. dll or exe file), it automatically includes information about the current time inside it, so this snippet reads that information. It resides at 0x128 (or 0x120) offset of samp.dll file and represents the number of seconds since January 1, 1970.
To find the offsets and values of other samp version you can use a program called PEview (or Ghidra). You can read about it here:
http://venom630.free.fr/pdf/Practical_Malware_Analysis.pdf
(pages 22-26)

I think it's an elegant way of checking samp version because every version was compiled at different time (the only issue is the inconsistent offset, some have it at 0x128, some have it at 0x120, maybe others have it another offset).

In that snippet, 31@ is an address, 29@ is value obtained from that address, 30@ is an aritrary number used as an identifier.
 

dovidas147

Active member
Joined
Nov 1, 2018
Messages
32
Reaction score
2
Yea i think that's a best way for checking SAMP version. There are other ways to detect it for example, you can find a pointer which contains string of that "SAMP 0.3.7 R1-2-3" message which i'm pretty sure this exists because i recently found pointers of F1 dialog caption, dialog text, screenshot message string, etc. But your method is way more preferable because you could just overwrite that memory string value of samp version. Plus i don't think that this message's pointer is consistent through samp versions.

Anyways, good job. Gonna use this for sure
Depends on what you think it is
When you compile a binary (e.g. dll or exe file), it automatically includes information about the current time inside it, so this snippet reads that information. It resides at 0x128 (or 0x120) offset of samp.dll file and represents the number of seconds since January 1, 1970.
To find the offsets and values of other samp version you can use a program called PEview (or Ghidra). You can read about it here:
http://venom630.free.fr/pdf/Practical_Malware_Analysis.pdf
(pages 22-26)

I think it's an elegant way of checking samp version because every version was compiled at different time (the only issue is the inconsistent offset, some have it at 0x128, some have it at 0x120, maybe others have it another offset).

In that snippet, 31@ is an address, 29@ is value obtained from that address, 30@ is an aritrary number used as an identifier.
 

Attachments

  • gta_sa_nfTk3IDf2a.png
    gta_sa_nfTk3IDf2a.png
    2 KB · Views: 22
Last edited:

Parazitas

God
Joined
Jan 2, 2017
Messages
3,113
Solutions
5
Reaction score
878
Location
Lithuania
Added R4
PHP:
:get_samp_version_id
// 0AB1: @get_samp_version_id 0 _returned_id 0@  
30@ = 0
if 0AA2: 31@ = load_library "samp.dll" // IF and SET
then
    31@ += 0x128
    0A8D: 29@ = read_memory 31@ size 4 virtual_protect 1
    if 29@ == 0x5542F47A
    then // 0.3.7 R1
        30@ = 1
    end
    
    if 29@ == 0x59C30C94
    then // 0.3.7 R2
        30@ = 2
    end
    
    if 29@ == 0x5A6A3130
    then // 0.3.DL
        30@ = 3
    end
    
    31@ -= 8 // reading samp.dll + 0x120
    0A8D: 29@ = read_memory 31@ size 4 virtual_protect 1
    
    if 29@ == 0x5C0B4243
    then // 0.3.7 R3 
        30@ = 4
    end  
    
    if 29@ == 0x5DD606CD
    then // 0.3.7 R4
        30@ = 5
    end 
end
0AB2: ret 1 30@
 

Parazitas

God
Joined
Jan 2, 2017
Messages
3,113
Solutions
5
Reaction score
878
Location
Lithuania
Since samp 0.3.7 R4 got updated i leaving updated snippet Here:
PHP:
:get_samp_version_id
// 0AB1: @get_samp_version_id 0 _returned: ID 0@  
30@ = 0
IF 0AA2: 31@ = "samp.dll" // IF and SET
THEN
    31@ += 0x128
    0A8D: 29@ = read_memory 31@ size 4 virtual_protect 1
    IF 29@ == 0x5542F47A
    THEN // 0.3.7 R1
        30@ = 1
    END
    
    IF 29@ == 0x59C30C94
    THEN // 0.3.7 R2
        30@ = 2
    END
    
    IF 29@ == 0x5A6A3130
    THEN // 0.3.DL
        30@ = 3
    END
    
    31@ -= 8 // reading samp.dll + 0x120
    0A8D: 29@ = read_memory 31@ size 4 virtual_protect 1
    
    IF 29@ == 0x5C0B4243
    THEN // 0.3.7 R3 
        30@ = 4
    END  
    
    IF 29@ == 0x5DD606CD
    THEN // 0.3.7 R4
        30@ = 5
    END
    IF 29@ == 0x6094ACAB
    THEN // 0.3.7 R4 - v2
        30@ = 6
    END 
END
0AB2: ret 1 30@
 

Parazitas

God
Joined
Jan 2, 2017
Messages
3,113
Solutions
5
Reaction score
878
Location
Lithuania
Added samp 0.3.7 R5
PHP:
:get_samp_version_id
// 0AB1: @get_samp_version_id 0 _returned: ID 0@  
30@ = 0
IF 0AA2: 31@ = "samp.dll" // IF and SET
THEN
    31@ += 0x128
    0A8D: 29@ = read_memory 31@ size 4 virtual_protect 1
    IF 29@ == 0x5542F47A
    THEN // 0.3.7 R1
        30@ = 1
    END
    
    IF 29@ == 0x59C30C94
    THEN // 0.3.7 R2
        30@ = 2
    END
    
    IF 29@ == 0x5A6A3130
    THEN // 0.3.DL
        30@ = 3
    END
    31@ -= 8 // reading samp.dll + 0x120
    0A8D: 29@ = read_memory 31@ size 4 virtual_protect 1
    IF 29@ == 0x5C0B4243
    THEN // 0.3.7 R3 
        30@ = 4
    END  
    
    IF 29@ == 0x5DD606CD
    THEN // 0.3.7 R4
        30@ = 5
    END
    IF 29@ == 0x6094ACAB
    THEN // 0.3.7 R4 - v2
        30@ = 6
    END 
    IF 29@ == 0x6372C39E
    THEN // 0.3.7 R5
        30@ = 7
    END 
END
0AB2: ret 1 30@
 
Top