{"id":3620,"date":"2023-08-11T12:19:04","date_gmt":"2023-08-11T04:19:04","guid":{"rendered":"https:\/\/www.zhidianwl.net\/zhidianwl\/?p=3620"},"modified":"2023-08-11T12:19:04","modified_gmt":"2023-08-11T04:19:04","slug":"go%e5%81%9aexe%e5%8f%af%e4%bb%a5%e5%98%9b","status":"publish","type":"post","link":"https:\/\/www.zhidianwl.net\/zhidianwl\/2023\/08\/11\/go%e5%81%9aexe%e5%8f%af%e4%bb%a5%e5%98%9b\/","title":{"rendered":"go\u505aexe\u53ef\u4ee5\u561b?"},"content":{"rendered":"

\u5728\u672c\u6559\u7a0b\u4e2d\uff0c\u6211\u4eec\u5c06\u8ba8\u8bba\u5982\u4f55\u4f7f\u7528Go\u8bed\u8a00\u521b\u5efa\u53ef\u6267\u884c\u6587\u4ef6\uff08.exe\u6587\u4ef6\uff09\u3002\u5728\u5f00\u59cb\u4e4b\u524d\uff0c\u6211\u4eec\u5148\u4e86\u89e3\u4e00\u4e0bGo\u8bed\u8a00\u4ee5\u53caWindows\u7cfb\u7edf\u4e0a\u7684\u53ef\u6267\u884c\u6587\u4ef6\u7684\u57fa\u672c\u539f<\/p>\n

<\/figure>\n<\/p>\n

\u7406\u3002<\/p>\n

Go\u8bed\u8a00\uff08Golang\uff09\u662f\u4e00\u79cd\u9759\u6001\u7c7b\u578b\u3001\u7f16\u8bd1\u578b\u7684\u7f16\u7a0b\u8bed\u8a00\uff0c\u7531\u8c37\u6b4c\u516c\u53f8\u5f00\u53d1\u3002Go\u8bed\u8a00\u7684\u7279\u70b9\u5305\u62ec\u7b80\u5355\u6613\u5b66\u3001\u9ad8\u6027\u80fd\u3001\u9ad8\u5e76\u53d1\u7b49\u3002Go\u8bed\u8a00\u7684\u8de8\u5e73\u53f0\u7279\u6027\u4f7f\u5b83\u80fd\u591f\u5f88\u5bb9\u6613\u5730\u5728Windows\u3001Linux\u548cMac\u7cfb\u7edf\u4e0a\u8fdb\u884c\u5f00\u53d1\u3002<\/p>\n

\u5728Windows\u64cd\u4f5c\u7cfb\u7edf\u4e0a\uff0c\u53ef\u6267\u884c\u6587\u4ef6\uff08\u5982.exe\u6587\u4ef6\uff09\u662f\u7528\u4e8e\u57fa\u4e8e\u7528\u6237\u64cd\u4f5c\u6267\u884c\u4ee3\u7801\u7684\u6587\u4ef6\u7c7b\u578b\u3002\u5f53\u4f60\u53cc\u51fb\u4e00\u4e2a.exe\u6587\u4ef6\u65f6\uff0c\u7cfb\u7edf\u5c06\u8fd0\u884c\u5176\u4e2d\u7684\u4ee3\u7801\uff0c\u5e76\u6267\u884c\u76f8\u5e94\u7684\u4efb\u52a1\u3002<\/p>\n

\u63a5\u4e0b\u6765\uff0c\u6211\u4eec\u6765\u770b\u4e00\u4e0b\u5982\u4f55\u4f7f\u7528Go\u8bed\u8a00\u521b\u5efa\u4e00\u4e2a\u7b80\u5355\u7684\u53ef\u6267\u884c\u6587\u4ef6\u3002<\/p>\n

1. \u5b89\u88c5Go\u7f16\u8bd1\u5668<\/p>\n

\u9996\u5148\u9700\u8981\u4e0b\u8f7d\u5e76\u5b89\u88c5Go\u7f16\u8bd1\u5668\u3002\u8bbf\u95ee\u5b98\u65b9\u7f51\u7ad9\uff08https:\/\/golang.org\/\uff09\uff0c\u6309\u7167\u8bf4\u660e\u5b89\u88c5\u9002\u5408\u60a8\u64cd\u4f5c\u7cfb\u7edf\u7684Go\u7f16\u8bd1\u5668\u3002<\/p>\n

2. \u521b\u5efa\u4e00\u4e2a\u7b80\u5355\u7684Go\u7a0b\u5e8f<\/p>\n

\u6211\u4eec\u521b\u5efa\u4e00\u4e2a\u6587\u4ef6\uff0c\u547d\u540d\u4e3a`main.go`\uff0c\u5185\u5bb9\u5982\u4e0b\uff1a<\/p>\n

“`go<\/p>\n

package main<\/p>\n

import “fmt”<\/p>\n

func main() {<\/p>\n

\tfmt.Println(“Hello, World!”)<\/p>\n

}<\/p>\n

“`<\/p>\n

\u6b64\u7a0b\u5e8f\u975e\u5e38\u7b80\u5355\uff0c\u5b83\u4ec5\u8f93\u51fa\u201cHello, World!\u201d\u3002<\/p>\n

3. \u7f16\u8bd1\u7a0b\u5e8f\u4ee5\u751f\u6210\u53ef\u6267\u884c\u6587\u4ef6<\/p>\n

\u5728\u547d\u4ee4\u63d0\u793a\u7b26\uff08Windows\uff09\u6216\u7ec8\u7aef\uff08Linux\u548cMac\uff09\u4e2d\uff0c\u5bfc\u822a\u81f3\u5305\u542b`main.go`\u6587\u4ef6\u7684\u76ee\u5f55\uff0c\u7136\u540e\u8fd0\u884c\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n

“`sh<\/p>\n

go build<\/p>\n

“`<\/p>\n

\u5b8c\u6210\u540e\uff0c\u5728\u5f53\u524d\u76ee\u5f55\u4e0b\u5c06\u751f\u6210\u4e00\u4e2a\u540d\u4e3amain\uff08Windows\u7cfb\u7edf\u4e0a\u4e3a`main.exe`\uff09\u7684\u53ef\u6267\u884c\u6587\u4ef6\u3002<\/p>\n

4. \u73af\u5883\u53d8\u91cf\u548cGOOS\u3001GOARCH\u53c2\u6570<\/p>\n

\u4f60\u53ef\u4ee5\u5229\u7528Go\u8bed\u8a00\u652f\u6301\u7684GOOS\u548cGOARCH\u73af\u5883\u53d8\u91cf\u6765\u4e3a\u5176\u4ed6\u5e73\u53f0\u751f\u6210\u53ef\u6267\u884c\u6587\u4ef6\u3002\u53ea\u9700\u5728\u7f16\u8bd1\u65f6\u8bbe\u7f6e\u8fd9\u4e24\u4e2a\u53d8\u91cf\uff0c\u4f8b\u5982\uff1a<\/p>\n

“`sh<\/p>\n

set GOOS=windows<\/p>\n

set GOARCH=amd64<\/p>\n

go build<\/p>\n

“`<\/p>\n

\u4e0a\u9762\u7684\u793a\u4f8b\u5c06\u4e3a64\u4f4dWindows\u7cfb\u7edf\u751f\u6210\u53ef\u6267\u884c\u6587\u4ef6\u3002<\/p>\n

5. \u538b\u7f29\u53ef\u6267\u884c\u6587\u4ef6<\/p>\n

\u9ed8\u8ba4\u60c5\u51b5\u4e0b\uff0c\u751f\u6210\u7684\u53ef\u6267\u884c\u6587\u4ef6\u53ef\u80fd\u4f1a\u5f88\u5927\uff0c\u56e0\u4e3a\u5176\u4e2d\u5305\u542b\u4e86Go\u8fd0\u884c\u65f6\u3002\u4f60\u53ef\u4ee5\u4f7f\u7528`upmac\u597d\u7528\u7684\u5f00\u53d1\u8f6f\u4ef6<\/a>x`\u8fdb\u884c\u538b\u7f29\uff1a<\/p>\n

“`sh<\/p>\n

upx –brute main.exe<\/p>\n

“`<\/p>\n

\u8fd9\u5c06\u751f\u6210\u4e00\u4e2a\u4f53\u79ef\u66f4\u5c0f\u7684.exe\u6587\u4ef6\u3002<\/p>\n

6. \u8fd0\u884c\u751f\u6210\u7684\u53ef\u6267\u884c\u6587\u4ef6<\/p>\n

\u5728Windows\u7cfb\u5f00\u53d1\u81ea\u5efa\u5e94\u7528<\/a>\u7edf\u4e0a\uff0c\u53cc\u51fb`main.exe`\u6587\u4ef6\u5373\u53ef\u6267\u884c\uff0c\u6216\u8005\u5728\u547d\u4ee4\u63d0\u793a\u7b26\u4e2d\u8f93\u5165\uff1a<\/p>\n

“`sh<\/p>\n

main.exe<\/p>\n

“`<\/p>\n

\u603b\u7ed3\uff1a<\/p>\n

\u901a\u8fc7\u4ee5\u4e0a\u6b65\u9aa4\uff0c\u6211\u4eec\u5b66\u4e60\u4e86\u4f7f\u7528Go\u8bed\u8a00\u7f16\u5199\u548c\u7f16\u8bd1\u7a0b\u5e8f\u4ee5\u521b\u5efa\u53ef\u5728Windows\u7cfb\u7edf\u4e0a\u8fd0\u884c\u7684\u53ef\u6267\u884c\u6587\u4ef6\u3002Go\u7684\u7b80\u6d01\u6027\u548c\u8de8\u5e73\u53f0\u7279\u6027\u4f7f\u5176\u5728\u5b9e\u9645\u5f00\u53d1\u4e2d\u5177\u6709\u5f88\u9ad8\u7684\u7075\u6d3b\u6027\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"

\u5728\u672c\u6559\u7a0b\u4e2d\uff0c\u6211\u4eec\u5c06\u8ba8\u8bba\u5982\u4f55\u4f7f\u7528Go\u8bed\u8a00\u521b\u5efa\u53ef\u6267\u884c\u6587\u4ef6\uff08.exe\u6587\u4ef6\uff09\u3002\u5728\u5f00\u59cb\u4e4b\u524d\uff0c\u6211\u4eec\u5148\u4e86\u89e3\u4e00\u4e0bGo\u8bed\u8a00\u4ee5\u53caWindows\u7cfb\u7edf\u4e0a\u7684\u53ef\u6267\u884c\u6587\u4ef6\u7684\u57fa\u672c\u539f\u7406\u3002Go\u8bed\u8a00\uff08Golang\uff09\u662f\u4e00\u79cd\u9759\u6001\u7c7b\u578b\u3001\u7f16\u8bd1\u578b<\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[7200,24,7199,12,614],"topic":[],"class_list":["post-3620","post","type-post","status-publish","format-standard","hentry","category-zhuomianruanjian","tag-matlab-guiexe","tag-24","tag-dllexe","tag-12","tag-614"],"_links":{"self":[{"href":"https:\/\/www.zhidianwl.net\/zhidianwl\/wp-json\/wp\/v2\/posts\/3620","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.zhidianwl.net\/zhidianwl\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.zhidianwl.net\/zhidianwl\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.zhidianwl.net\/zhidianwl\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/www.zhidianwl.net\/zhidianwl\/wp-json\/wp\/v2\/comments?post=3620"}],"version-history":[{"count":0,"href":"https:\/\/www.zhidianwl.net\/zhidianwl\/wp-json\/wp\/v2\/posts\/3620\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.zhidianwl.net\/zhidianwl\/wp-json\/wp\/v2\/media?parent=3620"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.zhidianwl.net\/zhidianwl\/wp-json\/wp\/v2\/categories?post=3620"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.zhidianwl.net\/zhidianwl\/wp-json\/wp\/v2\/tags?post=3620"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.zhidianwl.net\/zhidianwl\/wp-json\/wp\/v2\/topic?post=3620"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}