和C/C++编译的程序一样,都是机器码,如果你能反编译C的就能反编译Go的.
可以反编译成汇编
举例:我的机器:
GOPATH= c:\go;c:\go\src;F:\workspace\goSample01;
GOBIN=c:\go\bin;F:\workspace\goSample01\bin;
其中,c:\go是go的安装路径;
F:\workspace\goSample01是我写的go语言项目的工程目录;
F:\workspace\goSample01\bin是go语言项目的工程目录下的可执行文件路径;
注意:这个基本环境不包含开发工具,也不能直接编译带C代码的go程序.
/downloads/list.如果下的是压缩包,请把它解压到C盘.例如,C:\gowin-env.里面有个Console.bat是以后使用go
get的环境.举例:有个文件a.go,里面import(
"fmt"
"github.com/astaxie/beedb"
_ "github.com/ziutek/mymysql/godrv"
为了编译该a.go文件,需要启动Console.bat,然后在该命令行窗口,进入c:\go\src目录下,执行go getgithub.com/astaxie/beedb
Go get github.com/ziutek/mymysql/godrv .
配置goclipse(可选)
(如果不喜欢eclipse开发工具,请跳过这个配置.)
packagemainimport"fmt"func main(){ fmt.Printf("hello, world")}
配置gocode(可选)
如果不需要go语法辅助和eclipse里面的(按ALT+/)弹出go语言自动辅助功能,请跳过这个配置.
从开发工具这块看,go语言还不够成熟,开发工具都还不完善,有待改进.
Google有个在线运行go语言的教程(),很不错.支持在web上直接运行大部分的go程序,想了解这个教程的源代码的朋友可以通过以下方式获取.如果没兴趣,可以跳过这个步骤.
hg clone
编译带调用C代码的go文件(可选)
set GOOS=windows
set GOROOT=c:\go
set GOBIN=%GOROOT%\bin
set GOPATH=%GOROOT%;F:\workspace\goSample01;
例如:
go build -compiler gccgo test_c.go
运行调用C代码的go文件(可选)
①.、testc.go.
创建rand目录,然后在rand里面创建testc.go. 代码如下:
package rand
/*
//
#include stdio.h
*/
import "C"
func PrintHello() {
C.puts(C.CString("Hello, world\n"))
}
在rand下创建a.go.代码如下:
import "fmt"
func SayHello(name string){
fmt.Println(name)
在rand的上一级创建test_import.go.代码如下:
package main
import "./rand"
func main(){
rand.SayHello("tom")
rand.PrintHello()
go run test_import.go
在测试其它几个C代码的时候,发现windows版本的cgo还有些编译问题,同样的代码转移到苹果的XCODE下就没有问题.后来终于发现原因了,原来有些例子是unix平台下的,而在windows平台下,方法名和参数需要做调整.
例如:下面代码在windows下编译报一堆错误.
#include stdlib.h
func Random() int {
return int(C.random())
func Seed(i int) {
C.srandom(C.uint(i))
这里需要把return int(C.random()) 修改为"return int(C.rand())"
C.srandom(C.uint(i))修改为"C.srand(C.uint(i))"编译就OK了.
你在编译器里面Build一下,然后去\bin\Debug目录下找.exeexe就是可执行文件了.运行的时候可能需要用到Debug目录下的其他文件(如配置文件、DLL等),所以需要把Debug下的所有文件都放到一起.
①.、解压压缩包到go工作目录,如解压到E:\opensource\go\go,解压后的目录结构如下:
E:\opensource\go\go
├─api
├─bin
│ ├─go.exe
│ ├─godoc.exe
│ └─gofmt.exe
├─doc
├─include
├─lib
├─misc
├─pkg
├─src
└─test
修改goenv.bat文件中的GOROOT值为上面的go工作目录后直接双击该bat文件,go编译环境变量即设置完成.
E:\opensource\go\gogo
Go is a tool for managing Go source code.
Usage:
go command [arguments]
The commands are:
build compile packages and dependencies
clean remove object files
doc run godoc on package sources
env print Go environment information
fix run go tool fix on packages
fmt run gofmt on package sources
get download and install packages and dependencies
install compile and install packages and dependencies
list list packages
run compile and run Go program
test test packages
tool run specified go tool
version print Go version
vet run go tool vet on packages
Use "go help [command]" for more information about a command.
Additional help topics:
gopath GOPATH environment variable
packages description of package lists
remote remote import path syntax
testflag description of testing flags
testfunc description of testing functions
Use "go help [topic]" for more information about that topic.
直接调用"go build helloworld.go"就生成了"helloworld.exe"可执行程序,运行一下这个程序看到了我们期望的hello,wolrd.
E:\opensource\go\go\testgo build helloworld.go
E:\opensource\go\go\testhelloworld.exe
hello, world
E:\opensource\go\go\test
附一 helloworld.go
// cmpout
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// Test that we can do page 1 of the C book.
func main() {
print("hello, world\n")
以上就是土嘎嘎小编为大家整理的反编译go语言可执行文件相关主题介绍,如果您觉得小编更新的文章只要能对粉丝们有用,就是我们最大的鼓励和动力,不要忘记讲本站分享给您身边的朋友哦!!