best way to know executable version without running it

141 views
Skip to first unread message

thatipelli santhosh

unread,
Aug 13, 2020, 4:30:56 AM8/13/20
to golang-nuts
Hi All,

What is best way to know a executable version without executing it through golang?

I tried with reading the executable file through a scanner and matching every line with regex (like ngnix regx) but this is not working for all executables.

Do you have any idea?

seank...@gmail.com

unread,
Aug 13, 2020, 5:42:36 AM8/13/20
to golang-nuts
go version -m <executable>

Sathish VJ

unread,
Aug 13, 2020, 9:05:27 AM8/13/20
to golang-nuts
Maybe you are asking how to get build version information into the executable.  If yes, then use -ldflags.  https://pmcgrath.net/include-version-information-in-golang-app

thatipelli santhosh

unread,
Aug 19, 2020, 4:36:54 AM8/19/20
to Sathish VJ, golang-nuts
Hi Guys

Thank you for your response.

Consul is go executable. I can get version using /bin/consul version command but I need to find the version using string search in executable file data.


I noticed some pattern in executables 

1.8.312345156252160h3100043191500ms781258760h94105:***@ => 1.8.3

1.8.212345156252160h3100043191500ms781258760h94105:***@ => 1.8.2

1.8.112345156252160h3100043191500ms781258760h94105:***@ => 1.8.1

1.8.012345156252160h3100043191500ms781258760h94105:***@

1.7.712345156252160h3100043191500ms781258760h94105:***@

1.7.612345156252160h3100043191500ms781258760h94105:***@

1.7.412345156252160h3100043191500ms781258760h94105:***@

1.7.312345156252160h3100043191500ms781258760h94105:***@

1.7.212345156252160h3100043191500ms781258760h94105:***@

1.6.812345156252160h3100043191500ms781258760h94105:***@


the first 3 digits are version number in above strings which we found them executable but I don't find this string in all versions of consul


So does go use any specific delimiter before or after adding version numbers in executable file (compiled file)?

do you have any idea to get version number from go executable without executing it which is common for all?

Note: Attached screenshot method is not working for all versions



--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/eac6fad2-edcf-47c2-8b0e-e1f2d2dd6d56n%40googlegroups.com.
Screenshot from 2020-08-19 13-49-53.png

Axel Wagner

unread,
Aug 19, 2020, 9:16:14 AM8/19/20
to thatipelli santhosh, Sathish VJ, golang-nuts
AIUI, the version number output by `consul version` is not specified by Go, but by the consul source itself. As far as Go is concerned, it's just be a string constant (or maybe even a dynamically assembled string from integer constants or.... Anything really). As such, there is no really reliable way to do what you want.

Go provides version information via the `go version -m` command pointed out by others - as long as the binary is built using modules, which is the only case *Go* knows anything about versions at all. If that doesn't work for you, I don't think there is anything as far as Go is concerned.

Reply all
Reply to author
Forward
0 new messages