├── .vscode └── launch.json ├── Dockerfile ├── Gopkg.lock ├── Gopkg.toml ├── README.md ├── cmd └── socksd │ ├── README.md │ ├── config.go │ ├── http_transport.go │ ├── log.go │ ├── main.go │ ├── pac_generator.go │ ├── pac_generator_new.md │ ├── pac_updater.go │ ├── server_http.go │ ├── server_socks4.go │ ├── server_socks5.go │ └── socksd.json ├── direct.go ├── example_test.go ├── http_handler.go ├── shadowsocks_client.go ├── socks4.go ├── socks4_test.go ├── socks5_client.go ├── socks5_client_test.go ├── socks5_protocol.go ├── socks5_server.go ├── upstream ├── cipher.go ├── dns_cache.go ├── docorator_cipher.go ├── settings.go ├── transport_conn.go ├── transport_dialer.go ├── transport_listener.go ├── upstream.go └── upstream_http.go └── vendor └── github.com └── ssoor ├── fundadore ├── api │ └── api.go ├── common │ ├── common.go │ ├── hardware_windows.go │ └── socket.go └── log │ └── log.go └── winapi ├── AUTHORS ├── LICENSE ├── README.mdown ├── advapi32.go ├── combobox.go ├── comctl32.go ├── comdlg32.go ├── datetimepicker.go ├── edit.go ├── gdi32.go ├── gdiplus.go ├── header.go ├── kernel32.go ├── listbox.go ├── listview.go ├── menu.go ├── ole32.go ├── oleaut32.go ├── oleaut32_386.go ├── oleaut32_amd64.go ├── opengl32.go ├── pdh.go ├── shdocvw.go ├── shell32.go ├── shobj.go ├── shobj_386.go ├── shobj_amd64.go ├── statusbar.go ├── tab.go ├── toolbar.go ├── tooltip.go ├── treeview.go ├── updown.go ├── user32.go ├── uxtheme.go ├── win.go ├── wininet.go └── winspool.go /.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // 使用 IntelliSense 了解相关属性。 3 | // 悬停以查看现有属性的描述。 4 | // 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387 5 | "version": "0.2.0", 6 | "configurations": [ 7 | { 8 | "name": "Launch", 9 | "type": "go", 10 | "request": "launch", 11 | "mode": "debug", 12 | "remotePath": "", 13 | "port": 2345, 14 | "host": "127.0.0.1", 15 | "program": "${fileDirname}", 16 | "env": {}, 17 | "args": [], 18 | "showLog": true 19 | } 20 | ] 21 | } -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM golang AS builder 2 | 3 | COPY . ${GOPATH}/src/github.com/ssoor/socks 4 | 5 | RUN CGO_ENABLED=0 go build -o /socksd github.com/ssoor/socks/cmd/socksd && chmod +x /socksd 6 | 7 | # Runtime 8 | 9 | FROM scratch 10 | 11 | COPY cmd/socksd/socksd.json /etc/socks/ 12 | # 将编译结果拷贝到容器中 13 | COPY --from=builder /socksd /socks/socksd 14 | 15 | ENTRYPOINT ["/socks/socksd"] 16 | 17 | CMD [ "--config=/etc/socks/socksd.json" ] -------------------------------------------------------------------------------- /Gopkg.lock: -------------------------------------------------------------------------------- 1 | # This file is autogenerated, do not edit; changes may be undone by the next 'dep ensure'. 2 | 3 | 4 | [[projects]] 5 | branch = "master" 6 | digest = "1:c15e8f52523c3f958266940315ebd95e75d6360b65126b66959fe80dcfaae807" 7 | name = "github.com/ssoor/fundadore" 8 | packages = [ 9 | "api", 10 | "common", 11 | "log", 12 | ] 13 | pruneopts = "UT" 14 | revision = "6e6dfc5de14952e2077e20ed36ac16388027f739" 15 | 16 | [[projects]] 17 | branch = "master" 18 | digest = "1:1a8042f3908e4b4fa5b27428c001a7134c641c791578d103be8f801bf2289d0c" 19 | name = "github.com/ssoor/winapi" 20 | packages = ["."] 21 | pruneopts = "UT" 22 | revision = "489b1d8d85f99de87b218d6c772e262bc73cf264" 23 | 24 | [solve-meta] 25 | analyzer-name = "dep" 26 | analyzer-version = 1 27 | input-imports = [ 28 | "github.com/ssoor/fundadore/api", 29 | "github.com/ssoor/fundadore/log", 30 | ] 31 | solver-name = "gps-cdcl" 32 | solver-version = 1 33 | -------------------------------------------------------------------------------- /Gopkg.toml: -------------------------------------------------------------------------------- 1 | # Gopkg.toml example 2 | # 3 | # Refer to https://golang.github.io/dep/docs/Gopkg.toml.html 4 | # for detailed Gopkg.toml documentation. 5 | # 6 | # required = ["github.com/user/thing/cmd/thing"] 7 | # ignored = ["github.com/user/project/pkgX", "bitbucket.org/user/project/pkgA/pkgY"] 8 | # 9 | # [[constraint]] 10 | # name = "github.com/user/project" 11 | # version = "1.0.0" 12 | # 13 | # [[constraint]] 14 | # name = "github.com/user/project2" 15 | # branch = "dev" 16 | # source = "github.com/myfork/project2" 17 | # 18 | # [[override]] 19 | # name = "github.com/x/y" 20 | # version = "2.4.0" 21 | # 22 | # [prune] 23 | # non-go = false 24 | # go-tests = true 25 | # unused-packages = true 26 | 27 | 28 | [[constraint]] 29 | branch = "master" 30 | name = "github.com/ssoor/fundadore" 31 | 32 | [prune] 33 | go-tests = true 34 | unused-packages = true 35 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # SOCKS 2 | [![Build Status](https://travis-ci.org/eahydra/socks.svg?branch=master)](https://travis-ci.org/eahydra/socks) [![GoDoc](https://godoc.org/github.com/eahydra/socks?status.svg)](https://godoc.org/github.com/eahydra/socks) 3 | 4 | SOCKS 实现了 SOCKS4/5 代理协议以及 HTTP 代理隧道, 你可以通过使用这些来简化你编写代理的难度. 5 | [cmd/socksd](https://github.com/eahydra/socks/blob/master/cmd/socksd) 这个项目是一个使用 socks 包构建的转换代理, 用于将 shadowsocks 或者 socsk5 转换成 SOCKS4/5 或者 HTTP 代理. 6 | 7 | 目前 socks 支持的加密方式有 rc4, des, aes-128-cfb, aes-192-cfb , aes-256-cfb, 后端协议支持 shadowsocks 或者 socsk5. 8 | 9 | # Install 10 | 如果你需要从源码安装, 可以尝试执行如下指令. 11 | ``` 12 | go get github.com/ssoor/socks 13 | ``` 14 | 15 | 如果你想获得可运行文件, 请编译 [cmd/socksd](https://github.com/ssoor/socks/blob/master/cmd/socksd), 编译时可以参考此文档 [README.md](https://github.com/ssoor/socks/blob/master/cmd/socksd/README.md) -------------------------------------------------------------------------------- /cmd/socksd/README.md: -------------------------------------------------------------------------------- 1 | # SOCKS 2 | [![Build Status](https://travis-ci.org/eahydra/socks.svg?branch=master)](https://travis-ci.org/eahydra/socks) 3 | 4 | cmd/socksd 编译时需要 SOCKS 项目支持 , 目前这个项目支持的加密方式有: rc4, des, aes-128-cfb, aes-192-cfb and aes-256-cfb, 上游服务器可以使用: shadowsocks, socsk5. 5 | 6 | # 安装 7 | 如果你有一个 go 语言开发环境, 你可以通过执行以下命令通过源代码来安装. 8 | ``` 9 | go get github.com/eahydra/socks/cmd/socksd 10 | ``` 11 | 12 | # 使用 13 | 配置文件使用 Json 格式. 这个文件必须命名为 **socks.config** 并且和生成的执行文件放在一起. 14 | 配置文件内容: 15 | ```json 16 | { 17 | "pac": { 18 | "address": "127.0.0.1:2016", 19 | "upstream": { 20 | "type": "shadowsocks", 21 | "crypto": "aes-128-cfb", 22 | "password": "111222333", 23 | "address": "127.0.0.1:1080" 24 | }, 25 | "rules": [ 26 | { 27 | "name": "remote_proxy", 28 | "proxy": "8.8.8.8:2333", 29 | "local_rule_file": "Appreciation.txt" 30 | }, 31 | { 32 | "name": "local_proxy", 33 | "proxy": "127.0.0.1:2333", 34 | "socks4": "127.0.0.1:2334", 35 | "socks5": "127.0.0.1:2335", 36 | "local_rule_file": "Hijacker.txt", 37 | "remote_rule_file": "https://raw.githubusercontent.com/Leask/BRICKS/master/gfw.bricks" 38 | } 39 | ] 40 | }, 41 | "proxies": [ 42 | { 43 | "http": ":2333", 44 | "socks4": ":2334", 45 | "socks5": ":2335", 46 | "upstreams": [ 47 | { 48 | "type": "shadowsocks", 49 | "crypto": "aes-128-cfb", 50 | "password": "111222333", 51 | "address": "127.0.0.1:1080" 52 | } 53 | ] 54 | } 55 | ] 56 | } 57 | 58 | ``` 59 | 60 | * **pac** - PAC 配置信息 61 | * **address** - PAC服务器监听信息 (127.0.0.1:50000) 62 | * **upstream** - (OPTIONAL) 读取 **remote_rule_file** 使用的代理信息 63 | * **rules** - **rules** 数组, PAC服务器运行使用的规则信息 64 | 65 | * **rules** - PAC解析规则信息 66 | * **name** - (OPTIONAL) PAC 名称 67 | * **proxy** - (OPTIONAL) PAC HTTP 代理服务器信息 68 | * **socks4** - (OPTIONAL) PAC SOCKET4 代理服务器信息 69 | * **socks5** - (OPTIONAL) PAC SOCKS5 代理服务器信息 70 | * **local_rule_file** - (OPTIONAL) 本地PAC规则文件 (一行填写一个域名) 71 | * **remote_rule_file** - (OPTIONAL) 远程PAC规则文件 [bricks](https://raw.githubusercontent.com/Leask/BRICKS/master/gfw.bricks) 72 | 73 | * **proxies** - 代理配置项 74 | * **http** - (OPTIONAL) 启用HTTP代理 (127.0.0.1:8080 / :8080) 75 | * **socks4** - (OPTIONAL) 启用 SOCKS4 代理 (127.0.0.1:9090 / :9090) 76 | * **socks5** - (OPTIONAL) 启用 SOCKS5 代理 (127.0.0.1:9999 / :9999) 77 | * **crypto** - (OPTIONAL) SOCKS5的加密方法, 现在支持 rc4, des, aes-128-cfb, aes-192-cfb and aes-256-cfb 78 | * **password** - 如果你设置了 **crypto**, 在这里就填写加密密码 79 | * **dnsCacheTimeout** - (OPTIONAL) 启用 dns 缓存 (单位为秒) 80 | * **upstreams** - **upstream** 数组 81 | 82 | * **upstream** 83 | * **type** - 指定上游代理服务器的类型。现在支持shadowsocks和SOCKS5 84 | * **crypto** - 指定上游代理服务器的加密方法。该加密方法同 **proxies.crypto** 85 | * **password** - 指定上游代理服务器的加密密码 86 | * **address** - 指定上游代理服务器的地址 (8.8.8.8:1111) 87 | -------------------------------------------------------------------------------- /cmd/socksd/config.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "github.com/ssoor/socks/upstream" 5 | "encoding/json" 6 | "io/ioutil" 7 | ) 8 | 9 | type Upstream struct { 10 | Type string `json:"type"` 11 | Crypto string `json:"crypto"` 12 | Password string `json:"password"` 13 | Address string `json:"address"` 14 | } 15 | 16 | type PACRule struct { 17 | Name string `json:"name"` 18 | Proxy string `json:"proxy"` 19 | SOCKS4 string `json:"socks4"` 20 | SOCKS5 string `json:"socks5"` 21 | LocalRules string `json:"local_rule_file"` 22 | RemoteRules string `json:"remote_rule_file"` 23 | } 24 | 25 | type PAC struct { 26 | Rules []PACRule `json:"rules"` 27 | Address string `json:"address"` 28 | Upstream Upstream `json:"upstream"` 29 | } 30 | 31 | type Proxy struct { 32 | HTTP string `json:"http"` 33 | SOCKS4 string `json:"socks4"` 34 | SOCKS5 string `json:"socks5"` 35 | Crypto string `json:"crypto"` 36 | Password string `json:"password"` 37 | DNSCacheTimeout int `json:"dnsCacheTimeout"` 38 | Upstreams []upstream.Upstream `json:"upstreams"` 39 | } 40 | 41 | type Config struct { 42 | PAC PAC `json:"pac"` 43 | Proxies []Proxy `json:"proxies"` 44 | } 45 | 46 | func LoadConfig(s string) (*Config, error) { 47 | data, err := ioutil.ReadFile(s) 48 | if err != nil { 49 | return nil, err 50 | } 51 | cfgGroup := &Config{} 52 | if err = json.Unmarshal(data, cfgGroup); err != nil { 53 | return nil, err 54 | } 55 | return cfgGroup, nil 56 | } 57 | -------------------------------------------------------------------------------- /cmd/socksd/http_transport.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "github.com/ssoor/socks" 5 | "crypto/tls" 6 | "net" 7 | "io/ioutil" 8 | "net/http" 9 | "strings" 10 | 11 | ) 12 | 13 | type HTTPTransport struct { 14 | tranpoort *http.Transport 15 | } 16 | 17 | func (this *HTTPTransport) create502Response(req *http.Request, err error) (resp *http.Response) { 18 | 19 | resp = &http.Response{ 20 | StatusCode: http.StatusBadGateway, 21 | ProtoMajor: 1, 22 | ProtoMinor: 1, 23 | Request: req, 24 | Header: http.Header{ 25 | "X-Request-Error": []string{err.Error()}, 26 | }, 27 | ContentLength: 0, 28 | TransferEncoding: nil, 29 | Body: ioutil.NopCloser(strings.NewReader("")), 30 | Close: true, 31 | } 32 | 33 | return 34 | } 35 | 36 | func NewHTTPTransport(forward socks.Dialer) *HTTPTransport { 37 | transport := &HTTPTransport{ 38 | tranpoort: &http.Transport{ 39 | Dial: func(network, addr string) (net.Conn, error) { 40 | return forward.Dial(network, addr) 41 | }, 42 | TLSClientConfig: &tls.Config{InsecureSkipVerify: true}, 43 | }, 44 | } 45 | 46 | return transport 47 | } 48 | 49 | func (h *HTTPTransport) RoundTrip(req *http.Request) (resp *http.Response, err error) { 50 | req.Header.Del("X-Forwarded-For") 51 | 52 | if resp, err = h.tranpoort.RoundTrip(req); err != nil { 53 | if resp, err = h.tranpoort.RoundTrip(req); err != nil { 54 | return h.create502Response(req, err), nil 55 | } 56 | } 57 | 58 | return 59 | } 60 | -------------------------------------------------------------------------------- /cmd/socksd/log.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "log" 5 | "os" 6 | ) 7 | 8 | var ( 9 | InfoLog = log.New(os.Stdout, "INFO ", log.LstdFlags) 10 | ErrLog = log.New(os.Stderr, "ERROR ", log.LstdFlags) 11 | WarnLog = log.New(os.Stdout, "WARN ", log.LstdFlags) 12 | ) 13 | -------------------------------------------------------------------------------- /cmd/socksd/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "time" 5 | "bytes" 6 | "flag" 7 | "net/http" 8 | 9 | "github.com/ssoor/socks" 10 | "github.com/ssoor/fundadore/log" 11 | "github.com/ssoor/socks/upstream" 12 | ) 13 | 14 | func runHTTPProxy(conf Proxy, dialer socks.Dialer) { 15 | if conf.HTTP == "" { 16 | return 17 | } 18 | 19 | waitTime := float32(1) 20 | 21 | for { 22 | transport := NewHTTPTransport(dialer) 23 | 24 | if err := HTTPServe(conf.HTTP, dialer, transport); nil != err { 25 | ErrLog.Println("Start http proxy error: ", err) 26 | } 27 | 28 | waitTime += waitTime * 0.618 29 | log.Warning("http service will restart in", int(waitTime), "seconds ...") 30 | time.Sleep(time.Duration(waitTime) * time.Second) 31 | } 32 | } 33 | 34 | func runSOCKS4Server(conf Proxy, dialer socks.Dialer) { 35 | if conf.SOCKS4 == "" { 36 | return 37 | } 38 | 39 | waitTime := float32(1) 40 | 41 | for { 42 | decorator := upstream.NewCipherDecorator(conf.Crypto, conf.Password) 43 | 44 | if err := Socks4Serve(conf.SOCKS4, dialer, decorator); nil != err { 45 | ErrLog.Println("Start socks4 proxy error: ", err) 46 | } 47 | 48 | waitTime += waitTime * 0.618 49 | log.Warning("http service will restart in", int(waitTime), "seconds ...") 50 | time.Sleep(time.Duration(waitTime) * time.Second) 51 | } 52 | } 53 | 54 | func runSOCKS5Server(conf Proxy, dialer socks.Dialer) { 55 | if conf.SOCKS5 == "" { 56 | return 57 | } 58 | 59 | waitTime := float32(1) 60 | 61 | for { 62 | decorator := upstream.NewCipherDecorator(conf.Crypto, conf.Password) 63 | 64 | if err := Socks5Serve(conf.SOCKS5, dialer, decorator); nil != err { 65 | ErrLog.Println("Start socks5 proxy error: ", err) 66 | } 67 | 68 | waitTime += waitTime * 0.618 69 | log.Warning("http service will restart in", int(waitTime), "seconds ...") 70 | time.Sleep(time.Duration(waitTime) * time.Second) 71 | } 72 | } 73 | 74 | func runPACServer(pac PAC) { 75 | pu, err := NewPACUpdater(pac) 76 | if err != nil { 77 | ErrLog.Println("failed to NewPACUpdater, err:", err) 78 | return 79 | } 80 | 81 | http.HandleFunc("/proxy.pac", func(w http.ResponseWriter, r *http.Request) { 82 | w.Header().Add("Content-Type", "application/x-ns-proxy-autoconfig") 83 | data, time := pu.get() 84 | reader := bytes.NewReader(data) 85 | http.ServeContent(w, r, "proxy.pac", time, reader) 86 | }) 87 | 88 | err = http.ListenAndServe(pac.Address, nil) 89 | 90 | if err != nil { 91 | ErrLog.Println("listen failed, err:", err) 92 | return 93 | } 94 | } 95 | 96 | func main() { 97 | var configFile string 98 | 99 | flag.StringVar(&configFile, "config", "socksd.json", "socksd start config info file path") 100 | 101 | flag.Parse() 102 | 103 | conf, err := LoadConfig(configFile) 104 | if err != nil { 105 | InfoLog.Printf("Load config: %s failed, err: %s\n", configFile, err) 106 | return 107 | } 108 | InfoLog.Printf("Load config: %s succeeded\n", configFile) 109 | 110 | for _, c := range conf.Proxies { 111 | upstreamSettings := upstream.Settings{ 112 | DialTimeout: c.DNSCacheTimeout, 113 | DNSCacheTime: c.DNSCacheTimeout, 114 | Upstreams: c.Upstreams, 115 | } 116 | 117 | dialer := upstream.NewUpstreamDialer(upstreamSettings) 118 | 119 | go runHTTPProxy(c, dialer) 120 | go runSOCKS4Server(c, dialer) 121 | go runSOCKS5Server(c, dialer) 122 | } 123 | 124 | runPACServer(conf.PAC) 125 | } 126 | -------------------------------------------------------------------------------- /cmd/socksd/pac_generator.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "bytes" 5 | "fmt" 6 | "text/template" 7 | ) 8 | 9 | var pacTemplate = ` 10 | var hasOwnProperty = Object.hasOwnProperty; 11 | {{range .Rules}} 12 | var proxy_{{.Name}} = "{{if .Proxy}}PROXY {{.Proxy}};{{end}}{{if .SOCKS5}}SOCKS5 {{.SOCKS5}};{{end}}{{if .SOCKS4}}SOCKS4 {{.SOCKS4}};{{end}}DIRECT;"; 13 | 14 | var domains_{{.Name}} = { 15 | {{.LocalRules}} 16 | }; 17 | {{end}} 18 | 19 | function FindProxyForURL(url, host) { 20 | if (isPlainHostName(host) || host === '127.0.0.1' || host === 'localhost') { 21 | return 'DIRECT'; 22 | } 23 | 24 | var suffix; 25 | var pos = host.lastIndexOf('.'); 26 | while(1) { 27 | suffix = host.substring(pos + 1); 28 | {{range .Rules}} 29 | if (hasOwnProperty.call(domains_{{.Name}}, suffix)) { 30 | return proxy_{{.Name}}; 31 | } 32 | {{end}} 33 | if (pos <= 0) { 34 | break; 35 | } 36 | 37 | pos = host.lastIndexOf('.', pos - 1); 38 | } 39 | return 'DIRECT'; 40 | } 41 | ` 42 | 43 | type PACGenerator struct { 44 | filter map[string]int 45 | Rules []PACRule 46 | } 47 | 48 | func NewPACGenerator(pacRules []PACRule) *PACGenerator { 49 | rules := make([]PACRule, len(pacRules)) 50 | 51 | copy(rules, pacRules) 52 | 53 | return &PACGenerator{ 54 | Rules: rules, 55 | filter: make(map[string]int), 56 | } 57 | } 58 | 59 | func (p *PACGenerator) Generate(index int, rules []string) ([]byte, error) { 60 | 61 | for _, v := range rules { 62 | if _, ok := p.filter[v]; !ok { 63 | p.filter[v] = index 64 | } 65 | } 66 | 67 | data := struct { 68 | Rules []PACRule 69 | }{ 70 | Rules: p.Rules, 71 | } 72 | 73 | for i := 0; i < len(data.Rules); i++ { 74 | data.Rules[i].LocalRules = "" 75 | } 76 | 77 | for host, index := range p.filter { 78 | data.Rules[index].LocalRules += fmt.Sprintf(",'%s' : 1", host) 79 | } 80 | 81 | for i := 0; i < len(data.Rules); i++ { 82 | strlen := len(data.Rules[i].LocalRules) 83 | if strlen > 0 { 84 | data.Rules[i].LocalRules = data.Rules[i].LocalRules[1:strlen] 85 | } 86 | } 87 | 88 | t, err := template.New("proxy.pac").Parse(pacTemplate) 89 | 90 | if err != nil { 91 | ErrLog.Println("failed to parse pacTempalte, err:", err) 92 | } 93 | buff := bytes.NewBuffer(nil) 94 | err = t.Execute(buff, &data) 95 | if err != nil { 96 | InfoLog.Println(err) 97 | return nil, err 98 | } 99 | return buff.Bytes(), nil 100 | } 101 | -------------------------------------------------------------------------------- /cmd/socksd/pac_generator_new.md: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "bytes" 5 | "encoding/json" 6 | "text/template" 7 | ) 8 | 9 | var pacTemplate = ` 10 | {{range .Rules}} 11 | var proxy_{{.Name}} = "{{if .Proxy}}PROXY {{.Proxy}};{{end}}{{if .SOCKS5}}SOCKS5 {{.SOCKS5}};{{end}}{{if .SOCKS4}}SOCKS4 {{.SOCKS4}};{{end}}DIRECT;"; 12 | 13 | var domains_{{.Name}} = {{.LocalRules}}; 14 | {{end}} 15 | 16 | var regExpMatch = function(url, pattern) { 17 | try { 18 | return new RegExp(pattern).test(url); 19 | } catch(ex) { 20 | return false; 21 | } 22 | }; 23 | 24 | var _internal_ScreeningURL4List_pos = 0; 25 | var _internal_ScreeningURL4List_suffix = ""; 26 | 27 | var ScreeningURL4List = function(host, lists) { 28 | if (null == lists) 29 | return false; 30 | 31 | _internal_ScreeningURL4List_pos = host.lastIndexOf('.'); 32 | 33 | while(1) { 34 | _internal_ScreeningURL4List_suffix = host.substring(_internal_ScreeningURL4List_pos + 1); 35 | 36 | if (-1 != lists.indexOf(_internal_ScreeningURL4List_suffix)) { 37 | return true; 38 | } 39 | 40 | if (_internal_ScreeningURL4List_pos <= 0) { 41 | break; 42 | } 43 | 44 | _internal_ScreeningURL4List_pos = host.lastIndexOf('.', _internal_ScreeningURL4List_pos - 1); 45 | } 46 | 47 | return false; 48 | } 49 | 50 | var _internal_ScreeningURL4Shell_lastRule = ''; 51 | 52 | var ScreeningURL4Shell = function(url, shells) { 53 | if (null == shells) 54 | return false; 55 | 56 | for (var i = 0; i < shells.length; i++) { 57 | _internal_ScreeningURL4Shell_lastRule = shells[i]; 58 | 59 | if(true == shExpMatch(url, _internal_ScreeningURL4Shell_lastRule)) { 60 | return true; 61 | } 62 | } 63 | 64 | return false; 65 | } 66 | 67 | var _internal_ScreeningURL4Regular_lastRule = ''; 68 | 69 | var ScreeningURL4Regular = function(url, regulars) { 70 | if (null == regulars) 71 | return false; 72 | 73 | for (var i = 0; i < regulars.length; i++) { 74 | _internal_ScreeningURL4Regular_lastRule = regulars[i]; 75 | 76 | if(true == regExpMatch(url, _internal_ScreeningURL4Regular_lastRule)) { 77 | return true; 78 | } 79 | } 80 | 81 | return false; 82 | } 83 | 84 | var ScreeningURL = function(url, host, filters) { 85 | 86 | if(true == ScreeningURL4List(host,filters["List"])){ 87 | return true; 88 | } 89 | 90 | if(true == ScreeningURL4Shell(host,filters["Shell"])){ 91 | return true; 92 | } 93 | 94 | if(true == ScreeningURL4Regular(host,filters["Regular"])){ 95 | return true; 96 | } 97 | 98 | return false; 99 | }; 100 | 101 | function FindProxyForURL(url, host) { 102 | if (isPlainHostName(host) || host === '127.0.0.1' || host === 'localhost') { 103 | return 'DIRECT'; 104 | } 105 | 106 | {{range .Rules}} 107 | if (ScreeningURL(url, host, domains_{{.Name}})) { 108 | return proxy_{{.Name}}; 109 | } 110 | {{end}} 111 | 112 | return 'DIRECT'; 113 | } 114 | ` 115 | 116 | type Expressions struct { 117 | List []string 118 | Shell []string 119 | Regular []string 120 | } 121 | 122 | type PACGenerator struct { 123 | Rules []PACRule 124 | filters []Expressions 125 | } 126 | 127 | func NewPACGenerator(pacRules []PACRule) *PACGenerator { 128 | rules := make([]PACRule, len(pacRules)) 129 | 130 | copy(rules, pacRules) 131 | 132 | return &PACGenerator{ 133 | Rules: rules, 134 | filters: make([]Expressions, len(rules)), 135 | } 136 | } 137 | 138 | func (this *PACGenerator) registrationList(index int, rules []string) error { 139 | this.filters[index].List = append(this.filters[index].List, rules...) 140 | 141 | return nil 142 | } 143 | 144 | func (this *PACGenerator) registrationShell(index int, rules []string) error { 145 | this.filters[index].Shell = append(this.filters[index].Shell, rules...) 146 | 147 | return nil 148 | } 149 | 150 | func (this *PACGenerator) registrationRegular(index int, rules []string) error { 151 | this.filters[index].Regular = append(this.filters[index].Shell, rules...) 152 | 153 | return nil 154 | } 155 | 156 | func (p *PACGenerator) Generate() ([]byte, error) { 157 | 158 | data := struct { 159 | Rules []PACRule 160 | }{ 161 | Rules: p.Rules, 162 | } 163 | 164 | for i := 0; i < len(data.Rules); i++ { 165 | jsonstr, err := json.Marshal(p.filters[i]) 166 | 167 | data.Rules[i].LocalRules = string(jsonstr) 168 | 169 | if err != nil { 170 | ErrLog.Println("failed to parse json, err:", err) 171 | return nil, err 172 | } 173 | } 174 | 175 | t, err := template.New("proxy.pac").Parse(pacTemplate) 176 | 177 | if err != nil { 178 | ErrLog.Println("failed to parse pacTempalte, err:", err) 179 | return nil, err 180 | } 181 | 182 | buff := bytes.NewBuffer(nil) 183 | err = t.Execute(buff, &data) 184 | if err != nil { 185 | InfoLog.Println(err) 186 | return nil, err 187 | } 188 | return buff.Bytes(), nil 189 | } 190 | -------------------------------------------------------------------------------- /cmd/socksd/pac_updater.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "bufio" 5 | "io" 6 | "net/http" 7 | "os" 8 | "sync" 9 | "time" 10 | 11 | //"github.com/ssoor/socks" 12 | ) 13 | 14 | type PACUpdater struct { 15 | pac PAC 16 | lock sync.RWMutex 17 | data []byte 18 | modtime time.Time 19 | timer *time.Timer 20 | } 21 | 22 | func NewPACUpdater(pac PAC) (*PACUpdater, error) { 23 | p := &PACUpdater{ 24 | pac: pac, 25 | } 26 | go p.backgroundUpdate() 27 | return p, nil 28 | } 29 | 30 | func parseRule(reader io.Reader) ([]string, error) { 31 | var err error 32 | var line []byte 33 | var rules []string 34 | r := bufio.NewReader(reader) 35 | for line, _, err = r.ReadLine(); err == nil; line, _, err = r.ReadLine() { 36 | s := string(line) 37 | if s != "" { 38 | rules = append(rules, s) 39 | } 40 | } 41 | if err == io.EOF { 42 | err = nil 43 | } 44 | return rules, err 45 | } 46 | 47 | func loadLocalRule(filepath string) ([]string, error) { 48 | f, err := os.OpenFile(filepath, os.O_RDONLY, os.ModePerm) 49 | if err != nil { 50 | return nil, err 51 | } 52 | defer f.Close() 53 | return parseRule(f) 54 | } 55 | 56 | func loadRemoteRule(ruleURL string, upstream Upstream) ([]string, error) { 57 | //forward, err := BuildUpstream(upstream, socks.Direct) 58 | //if err != nil { 59 | // return nil, err 60 | //} 61 | client := &http.Client{ 62 | Transport: &http.Transport{ 63 | //Dial: forward.Dial, 64 | }, 65 | } 66 | resp, err := client.Get(ruleURL) 67 | if err != nil { 68 | return nil, err 69 | } 70 | defer resp.Body.Close() 71 | return parseRule(resp.Body) 72 | } 73 | 74 | func (p *PACUpdater) get() ([]byte, time.Time) { 75 | p.lock.RLock() 76 | defer p.lock.RUnlock() 77 | d := make([]byte, len(p.data)) 78 | copy(d, p.data) 79 | return d, p.modtime 80 | } 81 | 82 | func (p *PACUpdater) set(data []byte) { 83 | p.lock.Lock() 84 | defer p.lock.Unlock() 85 | p.data = make([]byte, len(data)) 86 | copy(p.data, data) 87 | p.modtime = time.Now() 88 | } 89 | 90 | func (p *PACUpdater) backgroundUpdate() { 91 | pg := NewPACGenerator(p.pac.Rules) 92 | for { 93 | duration := 1 * time.Minute 94 | 95 | for pacindex, pac := range p.pac.Rules { 96 | 97 | if rules, err := loadLocalRule(pac.LocalRules); err == nil { 98 | if data, err := pg.Generate(pacindex, rules); err == nil { 99 | p.set(data) 100 | InfoLog.Println("update rules from", pac.LocalRules, "succeeded") 101 | } 102 | } 103 | 104 | if rules, err := loadRemoteRule(pac.RemoteRules, p.pac.Upstream); err == nil { 105 | if data, err := pg.Generate(pacindex, rules); err == nil { 106 | p.set(data) 107 | duration = 24 * time.Hour 108 | InfoLog.Println("update rules from", pac.RemoteRules, "succeeded") 109 | } 110 | } 111 | } 112 | 113 | time.Sleep(duration) 114 | } 115 | } 116 | -------------------------------------------------------------------------------- /cmd/socksd/server_http.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "net/http" 5 | 6 | "github.com/ssoor/socks" 7 | ) 8 | 9 | func HTTPServe(addr string, router socks.Dialer, tran *HTTPTransport) (error) { 10 | handler := socks.NewHTTPProxyHandler("http", router, tran) 11 | 12 | return http.ListenAndServe(addr, handler) 13 | } -------------------------------------------------------------------------------- /cmd/socksd/server_socks4.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "github.com/ssoor/socks/upstream" 5 | "net" 6 | 7 | "github.com/ssoor/socks" 8 | ) 9 | 10 | func Socks4Serve(addr string, dialer socks.Dialer, decorators ...upstream.TransportDecorator) (error) { 11 | listener, err := net.Listen("tcp", addr) 12 | if err != nil { 13 | return err 14 | } 15 | listener = upstream.NewDecorateListener(listener, decorators...) 16 | defer listener.Close() 17 | 18 | socks4Svr, err := socks.NewSocks4Server(dialer) 19 | 20 | if err != nil { 21 | return err 22 | } 23 | 24 | return socks4Svr.Serve(listener) 25 | } -------------------------------------------------------------------------------- /cmd/socksd/server_socks5.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "github.com/ssoor/socks/upstream" 5 | "net" 6 | 7 | "github.com/ssoor/socks" 8 | ) 9 | 10 | func Socks5Serve(addr string, dialer socks.Dialer, decorators ...upstream.TransportDecorator) (error) { 11 | listener, err := net.Listen("tcp", addr) 12 | if err != nil { 13 | return err 14 | } 15 | listener = upstream.NewDecorateListener(listener, decorators...) 16 | defer listener.Close() 17 | 18 | socks4Svr, err := socks.NewSocks5Server(dialer) 19 | 20 | if err != nil { 21 | return err 22 | } 23 | 24 | return socks4Svr.Serve(listener) 25 | } -------------------------------------------------------------------------------- /cmd/socksd/socksd.json: -------------------------------------------------------------------------------- 1 | { 2 | "pac": { 3 | "address": "127.0.0.1:2016", 4 | "upstream": { 5 | "type": "shadowsocks", 6 | "crypto": "aes-128-cfb", 7 | "password": "111222333", 8 | "address": "127.0.0.1:1080" 9 | }, 10 | "rules": [ 11 | { 12 | "name": "remote_proxy", 13 | "proxy": "8.8.8.8:2333", 14 | "local_rule_file": "Appreciation.txt" 15 | }, 16 | { 17 | "name": "local_proxy", 18 | "proxy": "127.0.0.1:2333", 19 | "socks4": "127.0.0.1:2334", 20 | "socks5": "127.0.0.1:2335", 21 | "local_rule_file": "Hijacker.txt", 22 | "remote_rule_file": "https://raw.githubusercontent.com/Leask/BRICKS/master/gfw.bricks" 23 | } 24 | ] 25 | }, 26 | "proxies": [ 27 | { 28 | "http": ":2333", 29 | "socks4": ":2334", 30 | "socks5": ":2335", 31 | "upstreams": [ 32 | { 33 | "type": "shadowsocks", 34 | "crypto": "aes-128-cfb", 35 | "password": "111222333", 36 | "address": "127.0.0.1:1080" 37 | } 38 | ] 39 | } 40 | ] 41 | } -------------------------------------------------------------------------------- /direct.go: -------------------------------------------------------------------------------- 1 | package socks 2 | 3 | import ( 4 | "net" 5 | "time" 6 | ) 7 | 8 | // A Dialer is a means to establish a connection. 9 | type Dialer interface { 10 | // Dial connects to the given address via the proxy. 11 | Dial(network, address string) (net.Conn, error) 12 | } 13 | 14 | type direct struct{} 15 | 16 | // Direct is a direct proxy which implements Dialer interface: one that makes connections directly. 17 | var Direct = direct{} 18 | 19 | func (direct) Dial(network, address string) (net.Conn, error) { 20 | return net.Dial(network, address) 21 | } 22 | 23 | func (direct) DialTimeout(network, address string, timeout time.Duration) (net.Conn, error) { 24 | return net.DialTimeout(network, address, timeout) 25 | } 26 | -------------------------------------------------------------------------------- /example_test.go: -------------------------------------------------------------------------------- 1 | package socks 2 | 3 | import ( 4 | "net" 5 | "net/http" 6 | "net/http/httputil" 7 | ) 8 | 9 | func ExampleSocks5Client() { 10 | user := "" 11 | password := "" 12 | client, err := NewSocks5Client("tcp", "127.0.0.1:1080", user, password, Direct) 13 | if err != nil { 14 | return 15 | } 16 | conn, err := client.Dial("tcp", "www.google.com:80") 17 | if err != nil { 18 | return 19 | } 20 | httpClient := httputil.NewClientConn(conn, nil) 21 | defer httpClient.Close() 22 | 23 | request, err := http.NewRequest("GET", "/", nil) 24 | if err != nil { 25 | return 26 | } 27 | resp, err := httpClient.Do(request) 28 | if err != nil { 29 | return 30 | } 31 | dump, err := httputil.DumpResponse(resp, true) 32 | if err != nil { 33 | return 34 | } 35 | println(string(dump)) 36 | return 37 | } 38 | 39 | func ExampleSocks5Server() { 40 | listener, err := net.Listen("tcp", ":1080") 41 | if err != nil { 42 | return 43 | } 44 | defer listener.Close() 45 | 46 | if server, err := NewSocks5Server(Direct); err == nil { 47 | server.Serve(listener) 48 | } 49 | } 50 | 51 | func ExampleSocks4Client() { 52 | user := "" 53 | client, err := NewSocks4Client("tcp", "127.0.0.1:1080", user, Direct) 54 | if err != nil { 55 | return 56 | } 57 | addrs, err := net.LookupHost("www.google.com") 58 | if err != nil { 59 | return 60 | } 61 | if len(addrs) == 0 { 62 | return 63 | } 64 | conn, err := client.Dial("tcp", addrs[0]+":80") 65 | if err != nil { 66 | return 67 | } 68 | httpClient := httputil.NewClientConn(conn, nil) 69 | defer httpClient.Close() 70 | 71 | request, err := http.NewRequest("GET", "/", nil) 72 | if err != nil { 73 | return 74 | } 75 | resp, err := httpClient.Do(request) 76 | if err != nil { 77 | return 78 | } 79 | dump, err := httputil.DumpResponse(resp, true) 80 | if err != nil { 81 | return 82 | } 83 | println(string(dump)) 84 | return 85 | } 86 | 87 | func ExampleSocks4Server() { 88 | listener, err := net.Listen("tcp", ":1080") 89 | if err != nil { 90 | return 91 | } 92 | defer listener.Close() 93 | 94 | if server, err := NewSocks4Server(Direct); err == nil { 95 | server.Serve(listener) 96 | } 97 | } 98 | -------------------------------------------------------------------------------- /http_handler.go: -------------------------------------------------------------------------------- 1 | package socks 2 | 3 | import ( 4 | "bytes" 5 | "strings" 6 | "fmt" 7 | "io" 8 | "net" 9 | "net/http" 10 | "net/http/httputil" 11 | "net/url" 12 | ) 13 | 14 | // HTTPProxy is an HTTP Handler that serve CONNECT method and 15 | // route request to proxy server by Router. 16 | type HTTPProxyHandler struct { 17 | scheme string 18 | forward Dialer 19 | *httputil.ReverseProxy 20 | } 21 | 22 | // NewHTTPProxy constructs one HTTPProxy 23 | func NewHTTPProxyHandler(scheme string, forward Dialer, transport http.RoundTripper) *HTTPProxyHandler { 24 | return &HTTPProxyHandler{ 25 | scheme: scheme, 26 | forward: forward, 27 | ReverseProxy: &httputil.ReverseProxy{ 28 | Director: director, 29 | Transport: transport, 30 | }, 31 | } 32 | } 33 | 34 | func director(request *http.Request) { 35 | u, err := url.Parse(request.RequestURI) 36 | if err != nil { 37 | return 38 | } 39 | 40 | request.RequestURI = u.RequestURI() 41 | valueConnection := request.Header.Get("Proxy-Connection") 42 | if valueConnection != "" { 43 | request.Header.Del("Connection") 44 | request.Header.Del("Proxy-Connection") 45 | request.Header.Add("Connection", valueConnection) 46 | } 47 | } 48 | 49 | // ServeHTTPTunnel serve incoming request with CONNECT method, then route data to proxy server 50 | func (h *HTTPProxyHandler) ServeHTTPTunnel(response http.ResponseWriter, request *http.Request) { 51 | var conn net.Conn 52 | if hj, ok := response.(http.Hijacker); ok { 53 | var err error 54 | if conn, _, err = hj.Hijack(); err != nil { 55 | http.Error(response, err.Error(), http.StatusInternalServerError) 56 | return 57 | } 58 | } else { 59 | http.Error(response, "Hijacker failed", http.StatusInternalServerError) 60 | return 61 | } 62 | defer conn.Close() 63 | 64 | dest, err := h.forward.Dial("tcp", request.Host) 65 | if err != nil { 66 | fmt.Fprintf(conn, "HTTP/1.0 500 NewRemoteSocks failed, err:%s\r\n\r\n", err) 67 | return 68 | } 69 | defer dest.Close() 70 | 71 | if request.Body != nil { 72 | if _, err = io.Copy(dest, request.Body); err != nil { 73 | fmt.Fprintf(conn, "%d %s", http.StatusBadGateway, err.Error()) 74 | return 75 | } 76 | } 77 | 78 | fmt.Fprintf(conn, "HTTP/1.0 200 Connection established\r\n\r\n") 79 | 80 | go func() { 81 | defer conn.Close() 82 | defer dest.Close() 83 | io.Copy(dest, conn) 84 | }() 85 | io.Copy(conn, dest) 86 | } 87 | 88 | 89 | // ServeHTTPTunnel serve incoming request with CONNECT method, then route data to proxy server 90 | func (h *HTTPProxyHandler) xInternalConnect(req *http.Request, response http.ResponseWriter) { 91 | var conn net.Conn 92 | if hj, ok := response.(http.Hijacker); ok { 93 | var err error 94 | if conn, _, err = hj.Hijack(); err != nil { 95 | http.Error(response, err.Error(), http.StatusInternalServerError) 96 | return 97 | } 98 | } else { 99 | http.Error(response, "Hijacker failed", http.StatusInternalServerError) 100 | return 101 | } 102 | defer conn.Close() 103 | 104 | host := req.Host+":80" 105 | if strings.EqualFold(req.URL.Scheme,"https") { 106 | host = req.Host+":443" 107 | } 108 | 109 | dest, err := h.forward.Dial("tcp", host) 110 | if err != nil { 111 | fmt.Fprintf(conn, "HTTP/1.0 500 NewRemoteSocks failed, err:%s\r\n\r\n", err) 112 | return 113 | } 114 | defer dest.Close() 115 | 116 | sendRequest, err := httputil.DumpRequestOut(req, true) 117 | if err != nil { 118 | fmt.Fprintf(conn, "HTTP/1.0 500 Dump Request failed, err:%s\r\n\r\n", err) 119 | return 120 | } 121 | println(string(sendRequest)) 122 | if _, err = io.Copy(dest, bytes.NewReader(sendRequest)); err != nil { 123 | fmt.Fprintf(conn, "%d %s", http.StatusBadGateway, err.Error()) 124 | return 125 | } 126 | 127 | go func() { 128 | defer conn.Close() 129 | defer dest.Close() 130 | io.Copy(dest, conn) 131 | }() 132 | io.Copy(conn, dest) 133 | } 134 | 135 | // ServeHTTP implements HTTP Handler 136 | func (h *HTTPProxyHandler) ServeHTTP(response http.ResponseWriter, request *http.Request) { 137 | request.URL.Scheme = h.scheme 138 | request.URL.Host = request.Host 139 | 140 | if request.Method == "GET" && strings.EqualFold(request.Header.Get("Connection"), "Upgrade") && strings.EqualFold(request.Header.Get("Upgrade"), "websocket") { 141 | h.xInternalConnect(request, response) 142 | } 143 | 144 | if request.Method == "CONNECT" { 145 | h.ServeHTTPTunnel(response, request) 146 | } else { 147 | h.ReverseProxy.ServeHTTP(response, request) 148 | } 149 | } 150 | -------------------------------------------------------------------------------- /shadowsocks_client.go: -------------------------------------------------------------------------------- 1 | package socks 2 | 3 | import ( 4 | "errors" 5 | //ss "github.com/shadowsocks/shadowsocks-go/shadowsocks" 6 | "net" 7 | "strconv" 8 | ) 9 | 10 | // ShadowSocksClient implements ShadowSocks Proxy Protocol 11 | type ShadowSocksClient struct { 12 | network string 13 | address string 14 | forward Dialer 15 | } 16 | 17 | // NewShadowSocksClient return a new ShadowSocksClient that implements Dialer interface. 18 | func NewShadowSocksClient(network, address string, forward Dialer) (*ShadowSocksClient, error) { 19 | return &ShadowSocksClient{ 20 | network: network, 21 | address: address, 22 | forward: forward, 23 | }, nil 24 | } 25 | 26 | func RawAddr(host string, port int) (buf []byte, err error) { 27 | 28 | buff := make([]byte, 0, 1+(1+255)+2) // addrType + (lenByte + address) + port (host) | addrType + (address) + port (ip4 & ip6) 29 | 30 | if ip := net.ParseIP(host); ip != nil { 31 | if ip4 := ip.To4(); ip4 != nil { 32 | buff = append(buff, 1) 33 | ip = ip4 34 | } else { 35 | buff = append(buff, 4) 36 | } 37 | buff = append(buff, ip...) 38 | } else { 39 | if len(host) > 255 { 40 | return nil, errors.New("socks: destination hostname too long: " + host) 41 | } 42 | buff = append(buff, 3) 43 | buff = append(buff, uint8(len(host))) 44 | buff = append(buff, host...) 45 | } 46 | buff = append(buff, uint8(port>>8), uint8(port)) 47 | 48 | return buff, nil 49 | } 50 | 51 | // Dial return a new net.Conn that through proxy server establish with address 52 | func (s *ShadowSocksClient) Dial(network, address string) (net.Conn, error) { 53 | switch network { 54 | case "tcp", "tcp4", "tcp6": 55 | default: 56 | return nil, errors.New("socks: no support ShadowSocks proxy connections of type: " + network) 57 | } 58 | 59 | host, portStr, err := net.SplitHostPort(address) 60 | if err != nil { 61 | return nil, err 62 | } 63 | 64 | port, err := strconv.Atoi(portStr) 65 | if err != nil { 66 | return nil, errors.New("socks: failed to parse port number:" + portStr) 67 | } 68 | 69 | if port < 1 || port > 0xffff { 70 | return nil, errors.New("socks5: port number out of range:" + portStr) 71 | } 72 | 73 | conn, err := s.forward.Dial(s.network, s.address) 74 | if err != nil { 75 | return nil, err 76 | } 77 | 78 | closeConn := &conn 79 | 80 | defer func() { 81 | if closeConn != nil { 82 | (*closeConn).Close() 83 | } 84 | }() 85 | 86 | rawaddr, err := RawAddr(host, port) 87 | if err != nil { 88 | return nil, err 89 | } 90 | 91 | //remote, err = ss.DialWithRawAddr(rawaddr, address, se.cipher.Copy()) 92 | 93 | _, err = conn.Write(rawaddr) 94 | if err != nil { 95 | return nil, err 96 | } 97 | 98 | closeConn = nil 99 | return conn, nil 100 | } 101 | -------------------------------------------------------------------------------- /socks4.go: -------------------------------------------------------------------------------- 1 | package socks 2 | 3 | import ( 4 | "bufio" 5 | "errors" 6 | "fmt" 7 | "io" 8 | "net" 9 | "strconv" 10 | ) 11 | 12 | const ( 13 | socks4Version = 4 14 | socks4Connect = 1 15 | socks4Granted = 90 16 | socks4Rejected = 91 17 | socks4ConnectFailed = 92 18 | socks4UserIDInvalid = 93 19 | ) 20 | 21 | var socks4Errors = []string{ 22 | "", 23 | "request rejected or failed", 24 | "request rejected because SOCKS server cannot connect to identd on the client", 25 | "request rejected because the client program and identd report different user-ids", 26 | } 27 | 28 | // Socks4Server implements Socks4 Proxy Protocol(http://www.openssh.com/txt/socks4.protocol). 29 | // Just support CONNECT command. 30 | type Socks4Server struct { 31 | forward Dialer 32 | } 33 | 34 | // NewSocks4Server returns a new Socks4Server that can serve from new clients. 35 | func NewSocks4Server(forward Dialer) (*Socks4Server, error) { 36 | return &Socks4Server{ 37 | forward: forward, 38 | }, nil 39 | } 40 | 41 | // Serve with net.Listener for clients. 42 | func (s *Socks4Server) Serve(listener net.Listener) error { 43 | for { 44 | conn, err := listener.Accept() 45 | if err != nil { 46 | if netErr, ok := err.(net.Error); ok && netErr.Temporary() { 47 | continue 48 | } else { 49 | return err 50 | } 51 | } 52 | 53 | go serveSOCKS4Client(conn, s.forward) 54 | } 55 | } 56 | 57 | // Socks4Client implements Socks4 Proxy Protocol(http://www.openssh.com/txt/socks4.protocol). 58 | type Socks4Client struct { 59 | network string 60 | address string 61 | userID string 62 | forward Dialer 63 | } 64 | 65 | // NewSocks4Client return a new Socks4Client that implements Dialer interface. 66 | // network must be supported by forward, address is proxy server's address, userID can empty. 67 | func NewSocks4Client(network, address, userID string, forward Dialer) (*Socks4Client, error) { 68 | return &Socks4Client{ 69 | network: network, 70 | address: address, 71 | userID: userID, 72 | forward: forward, 73 | }, nil 74 | } 75 | 76 | // Dial return a new net.Conn if succeeded. network must be tcp, tcp4 or tcp6, address only is IPV4. 77 | func (s *Socks4Client) Dial(network, address string) (net.Conn, error) { 78 | switch network { 79 | case "tcp", "tcp4", "tcp6": 80 | default: 81 | return nil, errors.New("socks: no support for SOCKS4 proxy connections of type:" + network) 82 | } 83 | 84 | host, portStr, err := net.SplitHostPort(address) 85 | if err != nil { 86 | return nil, err 87 | } 88 | port, err := strconv.Atoi(portStr) 89 | if err != nil { 90 | return nil, errors.New("socks: failed to parse port:" + portStr) 91 | } 92 | if port < 1 || port > 0xffff { 93 | return nil, errors.New("socks: port number out of range:" + portStr) 94 | } 95 | ip := net.ParseIP(host) 96 | if ip == nil { 97 | return nil, errors.New("socks: destination host invalid:" + host) 98 | } 99 | ip4 := ip.To4() 100 | if ip4 == nil { 101 | return nil, errors.New("socks:destination ip must be ipv4:" + host) 102 | } 103 | 104 | conn, err := s.forward.Dial(s.network, s.address) 105 | if err != nil { 106 | return nil, err 107 | } 108 | closeConn := &conn 109 | defer func() { 110 | if closeConn != nil { 111 | (*closeConn).Close() 112 | } 113 | }() 114 | 115 | buff := make([]byte, 0, 8+len(s.userID)+1) 116 | buff = append(buff, socks4Version, socks4Connect) 117 | buff = append(buff, byte(port>>8), byte(port)) 118 | buff = append(buff, ip4...) 119 | if len(s.userID) != 0 { 120 | buff = append(buff, []byte(s.userID)...) 121 | } 122 | buff = append(buff, 0) 123 | 124 | if _, err := conn.Write(buff); err != nil { 125 | return nil, errors.New("socks: failed to write connect request to SOCKS4 server at: " + s.address + ": " + err.Error()) 126 | } 127 | buff = buff[:8] 128 | if _, err := io.ReadFull(conn, buff); err != nil { 129 | return nil, errors.New("socks: failed to read connect reply from SOCKS4 server at: " + s.address + ": " + err.Error()) 130 | } 131 | if buff[1] != socks4Granted { 132 | cd := int(buff[1]) - socks4Granted 133 | failure := "unknown error" 134 | if cd < len(socks4Errors) { 135 | failure = socks4Errors[cd] 136 | } 137 | return nil, errors.New("socks: SOCKS4 server at " + s.address + " failed to connect: " + failure) 138 | } 139 | 140 | closeConn = nil 141 | return conn, nil 142 | } 143 | 144 | func serveSOCKS4Client(conn net.Conn, forward Dialer) { 145 | defer conn.Close() 146 | 147 | reader := bufio.NewReader(conn) 148 | buff, err := reader.Peek(9) 149 | if err != nil { 150 | return 151 | } 152 | if buff[8] != 0 { 153 | if _, err = reader.ReadSlice(0); err != nil { 154 | return 155 | } 156 | } 157 | 158 | reply := make([]byte, 8) 159 | if buff[0] != socks4Version { 160 | reply[1] = socks4Rejected 161 | conn.Write(reply) 162 | return 163 | } 164 | if buff[1] != socks4Connect { 165 | reply[1] = socks4Rejected 166 | conn.Write(reply) 167 | return 168 | } 169 | 170 | port := uint16(buff[2])<<8 | uint16(buff[3]) 171 | ip := buff[4:8] 172 | 173 | host := fmt.Sprintf("%d.%d.%d.%d:%d", ip[0], ip[1], ip[2], ip[3], port) 174 | dest, err := forward.Dial("tcp4", host) 175 | if err != nil { 176 | reply[1] = socks4ConnectFailed 177 | conn.Write(reply) 178 | return 179 | } 180 | defer dest.Close() 181 | 182 | reply[1] = socks4Granted 183 | if _, err = conn.Write(reply); err != nil { 184 | return 185 | } 186 | 187 | go func() { 188 | defer conn.Close() 189 | defer dest.Close() 190 | io.Copy(dest, conn) 191 | }() 192 | io.Copy(conn, dest) 193 | } 194 | -------------------------------------------------------------------------------- /socks4_test.go: -------------------------------------------------------------------------------- 1 | package socks 2 | 3 | import ( 4 | "net" 5 | "net/http" 6 | "net/http/httputil" 7 | "testing" 8 | ) 9 | 10 | const ( 11 | TestSocks4ServerAddr = "127.0.0.1:8000" 12 | TestSocks4TargetDomain = "www.baidu.com" 13 | ) 14 | 15 | func TestSocks4Client(t *testing.T) { 16 | listener, err := net.Listen("tcp", TestSocks4ServerAddr) 17 | if err != nil { 18 | t.Fatal(err) 19 | } 20 | defer listener.Close() 21 | go func() { 22 | server, err := NewSocks4Server(Direct) 23 | if err != nil { 24 | t.Fatal(err) 25 | } 26 | server.Serve(listener) 27 | }() 28 | 29 | client, err := NewSocks4Client("tcp", TestSocks4ServerAddr, "", Direct) 30 | if err != nil { 31 | t.Fatal(err) 32 | } 33 | 34 | addrs, err := net.LookupHost(TestSocks4TargetDomain) 35 | if err != nil { 36 | t.Fatal(err) 37 | } 38 | if len(addrs) == 0 { 39 | t.Fatal("net.LookupHost with " + TestSocks4TargetDomain + " result invalid") 40 | } 41 | 42 | conn, err := client.Dial("tcp", addrs[0]+":80") 43 | if err != nil { 44 | t.Fatal("socks4 client.Dial failed, err: " + err.Error()) 45 | } 46 | t.Log("client.Dial succeeded") 47 | httpClient := httputil.NewClientConn(conn, nil) 48 | if err != nil { 49 | conn.Close() 50 | t.Fatal(err) 51 | } 52 | defer httpClient.Close() 53 | 54 | request, err := http.NewRequest("GET", "/", nil) 55 | if err != nil { 56 | t.Fatal(err) 57 | } 58 | resp, err := httpClient.Do(request) 59 | if err != nil { 60 | t.Fatal(err) 61 | } 62 | data, err := httputil.DumpResponse(resp, true) 63 | if err != nil { 64 | t.Fatal(err) 65 | } 66 | t.Log("socks4 HTTP Get:", string(data)) 67 | } 68 | -------------------------------------------------------------------------------- /socks5_client.go: -------------------------------------------------------------------------------- 1 | package socks 2 | 3 | import ( 4 | "errors" 5 | "net" 6 | "strconv" 7 | ) 8 | 9 | // Socks5Client implements Socks5 Proxy Protocol(RFC 1928) Client Protocol. 10 | // Just support CONNECT command, and support USERNAME/PASSWORD authentication methods(RFC 1929) 11 | type Socks5Client struct { 12 | network string 13 | address string 14 | user string 15 | password string 16 | forward Dialer 17 | } 18 | 19 | // NewSocks5Client return a new Socks5Client that implements Dialer interface. 20 | func NewSocks5Client(network, address, user, password string, forward Dialer) (*Socks5Client, error) { 21 | return &Socks5Client{ 22 | network: network, 23 | address: address, 24 | user: user, 25 | password: password, 26 | forward: forward, 27 | }, nil 28 | } 29 | 30 | // Dial return a new net.Conn that through the CONNECT command to establish connections with proxy server. 31 | // address as RFC's requirements that can be IPV4, IPV6 and domain host, such as 8.8.8.8:999 or google.com:80 32 | func (s *Socks5Client) Dial(network, address string) (net.Conn, error) { 33 | switch network { 34 | case "tcp", "tcp4", "tcp6": 35 | default: 36 | return nil, errors.New("socks: no support for SOCKS5 proxy connections of type:" + network) 37 | } 38 | 39 | conn, err := s.forward.Dial(s.network, s.address) 40 | if err != nil { 41 | return nil, err 42 | } 43 | closeConn := &conn 44 | defer func() { 45 | if closeConn != nil { 46 | (*closeConn).Close() 47 | } 48 | }() 49 | 50 | host, portStr, err := net.SplitHostPort(address) 51 | if err != nil { 52 | return nil, err 53 | } 54 | 55 | // check port 56 | port, err := strconv.Atoi(portStr) 57 | 58 | if err != nil { 59 | return nil, errors.New("socks: failed to parse port number: " + portStr) 60 | } 61 | 62 | if port < 1 || port > 0xffff { 63 | return nil, errors.New("socks: port number out of range: " + portStr) 64 | } 65 | 66 | if err := buildHandShakeRequest(conn, s.user, s.password); err != nil { 67 | return nil, err 68 | } 69 | 70 | if err := buildConnectionRequest(conn, host, port); err != nil { 71 | return nil, err 72 | } 73 | 74 | closeConn = nil 75 | return conn, nil 76 | } 77 | -------------------------------------------------------------------------------- /socks5_client_test.go: -------------------------------------------------------------------------------- 1 | package socks 2 | 3 | import ( 4 | "net" 5 | "net/http" 6 | "net/http/httputil" 7 | "testing" 8 | ) 9 | 10 | const ( 11 | TestSocks5ServerAddress = "127.0.0.1:8001" 12 | TestSocks5TargetDomain = "www.baidu.com" 13 | ) 14 | 15 | func TestSocks5Client(t *testing.T) { 16 | listener, err := net.Listen("tcp", TestSocks5ServerAddress) 17 | if err != nil { 18 | t.Fatal(err) 19 | } 20 | defer listener.Close() 21 | 22 | go func() { 23 | server, err := NewSocks5Server(Direct) 24 | if err != nil { 25 | t.Fatal(err) 26 | } 27 | server.Serve(listener) 28 | }() 29 | 30 | client, err := NewSocks5Client("tcp", TestSocks5ServerAddress, "", "", Direct) 31 | if err != nil { 32 | t.Fatal(err) 33 | } 34 | conn, err := client.Dial("tcp", TestSocks5TargetDomain+":80") 35 | if err != nil { 36 | t.Fatal(err) 37 | } 38 | 39 | t.Log("client.Dial succeeded") 40 | httpClient := httputil.NewClientConn(conn, nil) 41 | if err != nil { 42 | conn.Close() 43 | t.Fatal(err) 44 | } 45 | defer httpClient.Close() 46 | 47 | request, err := http.NewRequest("GET", "/", nil) 48 | if err != nil { 49 | t.Fatal(err) 50 | } 51 | resp, err := httpClient.Do(request) 52 | if err != nil { 53 | t.Fatal(err) 54 | } 55 | data, err := httputil.DumpResponse(resp, true) 56 | if err != nil { 57 | t.Fatal(err) 58 | } 59 | t.Log("socks5 HTTP Get:", string(data)) 60 | 61 | } 62 | -------------------------------------------------------------------------------- /socks5_protocol.go: -------------------------------------------------------------------------------- 1 | package socks 2 | 3 | import ( 4 | "errors" 5 | "io" 6 | "net" 7 | "strconv" 8 | ) 9 | 10 | const ( 11 | socks5Version = 5 12 | 13 | socks5AuthNone = 0 14 | socks5AuthPassword = 2 15 | socks5AuthNoAccept = 0xff 16 | 17 | socks5AuthPasswordVer = 1 18 | 19 | socks5Connect = 1 20 | 21 | socks5IP4 = 1 22 | socks5Domain = 3 23 | socks5IP6 = 4 24 | ) 25 | 26 | const ( 27 | socks5Success = 0 28 | socks5GeneralFailure = 1 29 | socks5ConnectNotAllowed = 2 30 | socks5NetworkUnreachable = 3 31 | socks5HostUnreachable = 4 32 | socks5ConnectionRefused = 5 33 | socks5TTLExpired = 6 34 | socks5CommandNotSupported = 7 35 | socks5AddressTypeNotSupported = 8 36 | ) 37 | 38 | var socks5Errors = []string{ 39 | "", 40 | "general SOCKS server failure", 41 | "connection not allowed by ruleset", 42 | "network unreachable", 43 | "Host unreachable", 44 | "Connection refused", 45 | "TTL expired", 46 | "Command not supported", 47 | "Address type not supported", 48 | } 49 | 50 | func buildHandShakeRequest(conn net.Conn, user, password string) error { 51 | 52 | buff := make([]byte, 0, 3) 53 | 54 | buff = append(buff, socks5Version) 55 | 56 | // set authentication methods 57 | if len(user) > 0 && len(user) < 256 && len(password) < 256 { 58 | buff = append(buff, 2, socks5AuthNone, socks5AuthPassword) 59 | } else { 60 | buff = append(buff, 1, socks5AuthNone) 61 | } 62 | 63 | // send authentication methods 64 | if _, err := conn.Write(buff); err != nil { 65 | return errors.New("protocol: failed to write handshake request at: " + err.Error()) 66 | } 67 | if _, err := io.ReadFull(conn, buff[:2]); err != nil { 68 | return errors.New("protocol: failed to read handshake reply at: " + err.Error()) 69 | } 70 | 71 | // handle authentication methods reply 72 | if buff[0] != socks5Version { 73 | return errors.New("protocol: SOCKS5 server at: " + strconv.Itoa(int(buff[0])) + " invalid version") 74 | } 75 | if buff[1] == socks5AuthNoAccept { 76 | return errors.New("protocol: SOCKS5 server at: no acceptable methods") 77 | } 78 | 79 | if buff[1] == socks5AuthPassword { 80 | // build username/password authentication request 81 | buff = buff[:0] 82 | buff = append(buff, socks5AuthPasswordVer) 83 | buff = append(buff, uint8(len(user))) 84 | buff = append(buff, []byte(user)...) 85 | buff = append(buff, uint8(len(password))) 86 | buff = append(buff, []byte(password)...) 87 | 88 | if _, err := conn.Write(buff); err != nil { 89 | return errors.New("protocol: failed to write password authentication request to SOCKS5 server at: " + err.Error()) 90 | } 91 | if _, err := io.ReadFull(conn, buff[:2]); err != nil { 92 | return errors.New("protocol: failed to read password authentication reply from SOCKS5 server at: " + err.Error()) 93 | } 94 | // 0 indicates success 95 | if buff[1] != 0 { 96 | return errors.New("protocol: SOCKS5 server at: reject username/password") 97 | } 98 | } 99 | 100 | return nil 101 | } 102 | 103 | func buildConnectionRequest(conn net.Conn, host string, port int) error { 104 | 105 | buff := make([]byte, 0, 6+len(host)) 106 | 107 | // build connect request 108 | buff = buff[:0] 109 | buff = append(buff, socks5Version, socks5Connect, 0) 110 | 111 | if ip := net.ParseIP(host); ip != nil { 112 | if ip4 := ip.To4(); ip4 != nil { 113 | buff = append(buff, socks5IP4) 114 | ip = ip4 115 | } else { 116 | buff = append(buff, socks5IP6) 117 | } 118 | buff = append(buff, ip...) 119 | } else { 120 | if len(host) > 255 { 121 | return errors.New("protocol: destination hostname too long: " + host) 122 | } 123 | buff = append(buff, socks5Domain) 124 | buff = append(buff, uint8(len(host))) 125 | buff = append(buff, host...) 126 | } 127 | buff = append(buff, byte(port>>8), byte(port)) 128 | 129 | if _, err := conn.Write(buff); err != nil { 130 | return errors.New("protocol: failed to write connect request to SOCKS5 server at: " + err.Error()) 131 | } 132 | if _, err := io.ReadFull(conn, buff[:4]); err != nil { 133 | return errors.New("protocol: failed to read connect reply from SOCKS5 server at: " + err.Error()) 134 | } 135 | 136 | failure := "Undefined REP field" 137 | if int(buff[1]) < len(socks5Errors) { 138 | failure = socks5Errors[buff[1]] 139 | } 140 | if len(failure) > 0 { 141 | return errors.New("protocol: SOCKS5 server failed to connect: " + failure) 142 | } 143 | 144 | // read remain data include BIND.ADDRESS and BIND.PORT 145 | discardBytes := 0 146 | switch buff[3] { 147 | case socks5IP4: 148 | discardBytes = net.IPv4len 149 | case socks5IP6: 150 | discardBytes = net.IPv6len 151 | case socks5Domain: 152 | if _, err := io.ReadFull(conn, buff[:1]); err != nil { 153 | return errors.New("protocol: failed to read domain length from SOCKS5 server at: " + err.Error()) 154 | } 155 | discardBytes = int(buff[0]) 156 | default: 157 | return errors.New("protocol: got unknown address type " + strconv.Itoa(int(buff[3])) + " from SOCKS5 server") 158 | } 159 | discardBytes += 2 160 | if cap(buff) < discardBytes { 161 | buff = make([]byte, discardBytes) 162 | } else { 163 | buff = buff[:discardBytes] 164 | } 165 | if _, err := io.ReadFull(conn, buff); err != nil { 166 | return errors.New("protocol: failed to read address and port from SOCKS5 server at: " + err.Error()) 167 | } 168 | 169 | return nil 170 | } 171 | -------------------------------------------------------------------------------- /socks5_server.go: -------------------------------------------------------------------------------- 1 | package socks 2 | 3 | import ( 4 | "io" 5 | "net" 6 | "strconv" 7 | ) 8 | 9 | // Socks5Server implements Socks5 Proxy Protocol(RFC 1928), just support CONNECT command. 10 | type Socks5Server struct { 11 | forward Dialer 12 | } 13 | 14 | // NewSocks5Server return a new Socks5Server 15 | func NewSocks5Server(forward Dialer) (*Socks5Server, error) { 16 | return &Socks5Server{ 17 | forward: forward, 18 | }, nil 19 | } 20 | 21 | func serveSocks5Client(conn net.Conn, forward Dialer) { 22 | defer conn.Close() 23 | 24 | buff := make([]byte, 262) 25 | reply := []byte{0x05, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x22, 0x22} 26 | 27 | if _, err := io.ReadFull(conn, buff[:2]); err != nil { 28 | return 29 | } 30 | if buff[0] != socks5Version { 31 | reply[1] = socks5AuthNoAccept 32 | conn.Write(reply[:2]) 33 | return 34 | } 35 | numMethod := buff[1] 36 | if _, err := io.ReadFull(conn, buff[:numMethod]); err != nil { 37 | return 38 | } 39 | reply[1] = socks5AuthNone 40 | if _, err := conn.Write(reply[:2]); err != nil { 41 | return 42 | } 43 | 44 | if _, err := io.ReadFull(conn, buff[:4]); err != nil { 45 | return 46 | } 47 | if buff[1] != socks5Connect { 48 | reply[1] = socks5CommandNotSupported 49 | conn.Write(reply) 50 | return 51 | } 52 | 53 | addressType := buff[3] 54 | addressLen := 0 55 | switch addressType { 56 | case socks5IP4: 57 | addressLen = net.IPv4len 58 | case socks5IP6: 59 | addressLen = net.IPv6len 60 | case socks5Domain: 61 | if _, err := io.ReadFull(conn, buff[:1]); err != nil { 62 | return 63 | } 64 | addressLen = int(buff[0]) 65 | default: 66 | reply[1] = socks5AddressTypeNotSupported 67 | conn.Write(reply) 68 | return 69 | } 70 | host := make([]byte, addressLen) 71 | if _, err := io.ReadFull(conn, host); err != nil { 72 | return 73 | } 74 | if _, err := io.ReadFull(conn, buff[:2]); err != nil { 75 | return 76 | } 77 | hostStr := "" 78 | switch addressType { 79 | case socks5IP4, socks5IP6: 80 | ip := net.IP(host) 81 | hostStr = ip.String() 82 | case socks5Domain: 83 | hostStr = string(host) 84 | } 85 | port := uint16(buff[0])<<8 | uint16(buff[1]) 86 | if port < 1 || port > 0xffff { 87 | reply[1] = socks5HostUnreachable 88 | conn.Write(reply) 89 | return 90 | } 91 | portStr := strconv.Itoa(int(port)) 92 | 93 | hostStr = net.JoinHostPort(hostStr, portStr) 94 | dest, err := forward.Dial("tcp", hostStr) 95 | if err != nil { 96 | reply[1] = socks5ConnectionRefused 97 | conn.Write(reply) 98 | return 99 | } 100 | defer dest.Close() 101 | reply[1] = socks5Success 102 | if _, err := conn.Write(reply); err != nil { 103 | return 104 | } 105 | 106 | go func() { 107 | defer conn.Close() 108 | defer dest.Close() 109 | io.Copy(conn, dest) 110 | }() 111 | 112 | io.Copy(dest, conn) 113 | } 114 | 115 | // Serve with net.Listener for new incoming clients. 116 | func (s *Socks5Server) Serve(listener net.Listener) error { 117 | for { 118 | conn, err := listener.Accept() 119 | if err != nil { 120 | if netErr, ok := err.(net.Error); ok && netErr.Temporary() { 121 | continue 122 | } else { 123 | return err 124 | } 125 | } 126 | 127 | go serveSocks5Client(conn, s.forward) 128 | } 129 | } 130 | -------------------------------------------------------------------------------- /upstream/cipher.go: -------------------------------------------------------------------------------- 1 | package upstream 2 | 3 | import ( 4 | "crypto/md5" 5 | "crypto/aes" 6 | "crypto/cipher" 7 | "crypto/des" 8 | "crypto/rand" 9 | "crypto/rc4" 10 | "io" 11 | ) 12 | 13 | type RC4Cipher struct { 14 | *cipher.StreamReader 15 | *cipher.StreamWriter 16 | } 17 | 18 | func NewRC4Cipher(rwc io.ReadWriteCloser, password []byte) (*RC4Cipher, error) { 19 | decryptCipher, err := rc4.NewCipher(password) 20 | if err != nil { 21 | return nil, err 22 | } 23 | encryptCipher, err := rc4.NewCipher(password) 24 | if err != nil { 25 | return nil, err 26 | } 27 | return &RC4Cipher{ 28 | StreamReader: &cipher.StreamReader{ 29 | S: decryptCipher, 30 | R: rwc, 31 | }, 32 | StreamWriter: &cipher.StreamWriter{ 33 | S: encryptCipher, 34 | W: rwc, 35 | }, 36 | }, nil 37 | } 38 | 39 | type DESCFBCipher struct { 40 | block cipher.Block 41 | rwc io.ReadWriteCloser 42 | *cipher.StreamReader 43 | *cipher.StreamWriter 44 | } 45 | 46 | func NewDESCFBCipher(rwc io.ReadWriteCloser, password []byte) (*DESCFBCipher, error) { 47 | block, err := des.NewCipher(password) 48 | if err != nil { 49 | return nil, err 50 | } 51 | 52 | return &DESCFBCipher{ 53 | block: block, 54 | rwc: rwc, 55 | }, nil 56 | } 57 | 58 | func (d *DESCFBCipher) Read(p []byte) (n int, err error) { 59 | if d.StreamReader == nil { 60 | iv := make([]byte, d.block.BlockSize()) 61 | n, err = io.ReadFull(d.rwc, iv) 62 | if err != nil { 63 | return n, err 64 | } 65 | stream := cipher.NewCFBDecrypter(d.block, iv) 66 | d.StreamReader = &cipher.StreamReader{ 67 | S: stream, 68 | R: d.rwc, 69 | } 70 | } 71 | return d.StreamReader.Read(p) 72 | } 73 | 74 | func (d *DESCFBCipher) Write(p []byte) (n int, err error) { 75 | if d.StreamWriter == nil { 76 | iv := make([]byte, d.block.BlockSize()) 77 | _, err = rand.Read(iv) 78 | if err != nil { 79 | return 0, err 80 | } 81 | stream := cipher.NewCFBEncrypter(d.block, iv) 82 | d.StreamWriter = &cipher.StreamWriter{ 83 | S: stream, 84 | W: d.rwc, 85 | } 86 | n, err := d.rwc.Write(iv) 87 | if err != nil { 88 | return n, err 89 | } 90 | } 91 | return d.StreamWriter.Write(p) 92 | } 93 | 94 | func (d *DESCFBCipher) Close() error { 95 | if d.StreamWriter != nil { 96 | d.StreamWriter.Close() 97 | } 98 | if d.rwc != nil { 99 | d.rwc.Close() 100 | } 101 | return nil 102 | } 103 | 104 | type AESCFBCipher struct { 105 | rwc io.ReadWriteCloser 106 | iv []byte 107 | block cipher.Block 108 | *cipher.StreamReader 109 | *cipher.StreamWriter 110 | } 111 | 112 | 113 | func md5sum(d []byte) []byte { 114 | h := md5.New() 115 | h.Write(d) 116 | return h.Sum(nil) 117 | } 118 | 119 | func evpBytesToKey(password string, keyLen int) (key []byte) { 120 | const md5Len = 16 121 | 122 | cnt := (keyLen-1)/md5Len + 1 123 | m := make([]byte, cnt*md5Len) 124 | copy(m, md5sum([]byte(password))) 125 | 126 | // Repeatedly call md5 until bytes generated is enough. 127 | // Each call to md5 uses data: prev md5 sum + password. 128 | d := make([]byte, md5Len+len(password)) 129 | start := 0 130 | for i := 1; i < cnt; i++ { 131 | start += md5Len 132 | copy(d, m[start-md5Len:start]) 133 | copy(d[md5Len:], password) 134 | copy(m[start:], md5sum(d)) 135 | } 136 | return m[:keyLen] 137 | } 138 | 139 | 140 | func NewAESCFGCipher(rwc io.ReadWriteCloser, password string, bit int) (*AESCFBCipher, error) { 141 | block, err := aes.NewCipher(evpBytesToKey(password, bit)) 142 | if err != nil { 143 | return nil, err 144 | } 145 | return &AESCFBCipher{ 146 | block: block, 147 | rwc: rwc, 148 | }, nil 149 | } 150 | 151 | func (a *AESCFBCipher) Read(p []byte) (n int, err error) { 152 | if a.StreamReader == nil { 153 | iv := make([]byte, a.block.BlockSize()) 154 | n, err = io.ReadFull(a.rwc, iv) 155 | if err != nil { 156 | return n, err 157 | } 158 | stream := cipher.NewCFBDecrypter(a.block, iv) 159 | a.StreamReader = &cipher.StreamReader{ 160 | S: stream, 161 | R: a.rwc, 162 | } 163 | } 164 | return a.StreamReader.Read(p) 165 | } 166 | 167 | func (a *AESCFBCipher) Write(p []byte) (n int, err error) { 168 | if a.StreamWriter == nil { 169 | iv := make([]byte, a.block.BlockSize()) 170 | _, err = rand.Read(iv) 171 | if err != nil { 172 | return 0, err 173 | } 174 | stream := cipher.NewCFBEncrypter(a.block, iv) 175 | a.StreamWriter = &cipher.StreamWriter{ 176 | S: stream, 177 | W: a.rwc, 178 | } 179 | n, err := a.rwc.Write(iv) 180 | if err != nil { 181 | return n, err 182 | } 183 | } 184 | return a.StreamWriter.Write(p) 185 | } 186 | 187 | func (a *AESCFBCipher) Close() error { 188 | if a.StreamWriter != nil { 189 | a.StreamWriter.Close() 190 | } 191 | if a.rwc != nil { 192 | a.rwc.Close() 193 | } 194 | return nil 195 | } 196 | -------------------------------------------------------------------------------- /upstream/dns_cache.go: -------------------------------------------------------------------------------- 1 | package upstream 2 | 3 | import ( 4 | "net" 5 | "sync" 6 | "time" 7 | ) 8 | 9 | type DNSCache struct { 10 | lock sync.RWMutex 11 | cacheTimeout time.Duration 12 | dns map[string]DNSElement 13 | } 14 | 15 | type DNSElement struct { 16 | ip net.IP 17 | startTime time.Time 18 | } 19 | 20 | func NewDNSCache(cacheTimeout int) *DNSCache { 21 | if cacheTimeout <= 0 { 22 | cacheTimeout = 30 23 | } 24 | return &DNSCache{ 25 | cacheTimeout: time.Duration(cacheTimeout) * time.Minute, 26 | dns: make(map[string]DNSElement), 27 | } 28 | } 29 | 30 | func (c *DNSCache) Get(domain string) (net.IP, bool) { 31 | c.lock.RLock() 32 | e, ok := c.dns[domain] 33 | c.lock.RUnlock() 34 | if ok && time.Since(e.startTime) > c.cacheTimeout { 35 | c.lock.Lock() 36 | delete(c.dns, domain) 37 | c.lock.Unlock() 38 | return nil, false 39 | } 40 | return e.ip, ok 41 | } 42 | 43 | func (c *DNSCache) Set(domain string, ip net.IP) { 44 | c.lock.Lock() 45 | c.dns[domain] = DNSElement{ip: ip, startTime: time.Now()} 46 | c.lock.Unlock() 47 | } 48 | -------------------------------------------------------------------------------- /upstream/docorator_cipher.go: -------------------------------------------------------------------------------- 1 | package upstream 2 | 3 | import ( 4 | "io" 5 | "net" 6 | "strings" 7 | ) 8 | 9 | type CipherConn struct { 10 | net.Conn 11 | rwc io.ReadWriteCloser 12 | } 13 | 14 | func (this *CipherConn) Read(data []byte) (int, error) { 15 | return this.rwc.Read(data) 16 | } 17 | 18 | func (this *CipherConn) Write(data []byte) (int, error) { 19 | return this.rwc.Write(data) 20 | } 21 | 22 | func (this *CipherConn) Close() error { 23 | err := this.Conn.Close() 24 | this.rwc.Close() 25 | return err 26 | } 27 | 28 | func NewCipherConn(conn net.Conn, cryptMethod string, password string) (*CipherConn, error) { 29 | var rwc io.ReadWriteCloser 30 | var err error 31 | switch strings.ToLower(cryptMethod) { 32 | default: 33 | rwc = conn 34 | case "rc4": 35 | rwc, err = NewRC4Cipher(conn, []byte(password)) 36 | case "des": 37 | rwc, err = NewDESCFBCipher(conn, []byte(password)) 38 | case "aes-128-cfb": 39 | rwc, err = NewAESCFGCipher(conn, password, 16) 40 | case "aes-192-cfb": 41 | rwc, err = NewAESCFGCipher(conn, password, 24) 42 | case "aes-256-cfb": 43 | rwc, err = NewAESCFGCipher(conn, password, 32) 44 | } 45 | if err != nil { 46 | return nil, err 47 | } 48 | 49 | return &CipherConn{ 50 | Conn: conn, 51 | rwc: rwc, 52 | }, nil 53 | } 54 | 55 | func NewCipherDecorator(cryptoMethod, password string) TransportDecorator { 56 | return func(conn net.Conn) (net.Conn, error) { 57 | return NewCipherConn(conn, cryptoMethod, password) 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /upstream/settings.go: -------------------------------------------------------------------------------- 1 | package upstream 2 | 3 | type Upstream struct { 4 | Type string `json:"type"` 5 | Crypto string `json:"crypto"` 6 | Password string `json:"password"` 7 | Address string `json:"address"` 8 | } 9 | 10 | type Settings struct { 11 | DialTimeout int `json:"dial_timeout"` 12 | DNSCacheTime int `json:"dnscache_time"` 13 | Upstreams []Upstream `json:"services"` 14 | } 15 | -------------------------------------------------------------------------------- /upstream/transport_conn.go: -------------------------------------------------------------------------------- 1 | package upstream 2 | 3 | import ( 4 | "net" 5 | 6 | "errors" 7 | 8 | "github.com/ssoor/socks" 9 | ) 10 | 11 | var ErrorUpStaeamDail error = errors.New("forward connect service failed.") 12 | 13 | type TransportDecorator func(net.Conn) (net.Conn, error) 14 | 15 | type TransportConn struct { 16 | forward socks.Dialer 17 | decorators []TransportDecorator 18 | } 19 | 20 | func decorateTransportConn(conn net.Conn, ds ...TransportDecorator) (net.Conn, error) { 21 | decorated := conn 22 | var err error 23 | for _, decorate := range ds { 24 | decorated, err = decorate(decorated) 25 | if err != nil { 26 | return nil, err 27 | } 28 | } 29 | return decorated, nil 30 | } 31 | 32 | func NewTransportConn(forward socks.Dialer, ds ...TransportDecorator) *TransportConn { 33 | d := &TransportConn{ 34 | forward: forward, 35 | } 36 | d.decorators = append(d.decorators, ds...) 37 | return d 38 | } 39 | 40 | func (d *TransportConn) Dial(network, address string) (net.Conn, error) { 41 | conn, err := d.forward.Dial(network, address) 42 | if err != nil { 43 | return nil, err 44 | } 45 | dconn, err := decorateTransportConn(conn, d.decorators...) 46 | if err != nil { 47 | conn.Close() 48 | return nil, err 49 | } 50 | return dconn, nil 51 | } 52 | -------------------------------------------------------------------------------- /upstream/transport_dialer.go: -------------------------------------------------------------------------------- 1 | package upstream 2 | 3 | import ( 4 | "net" 5 | "time" 6 | 7 | "github.com/ssoor/socks" 8 | ) 9 | 10 | type TransportDialer struct { 11 | dnsCache *DNSCache 12 | timeoutDial time.Duration 13 | } 14 | 15 | func NewTransportDialer(timeoutDNSCache int, timeoutDial time.Duration) *TransportDialer { 16 | var dnsCache *DNSCache 17 | if timeoutDNSCache != 0 { 18 | dnsCache = NewDNSCache(timeoutDNSCache) 19 | } 20 | return &TransportDialer{ 21 | dnsCache: dnsCache, 22 | timeoutDial: time.Duration(timeoutDial) * time.Second, 23 | } 24 | } 25 | 26 | func parseAddress(address string) (interface{}, string, error) { 27 | host, port, err := net.SplitHostPort(address) 28 | if err != nil { 29 | return nil, "", err 30 | } 31 | ip := net.ParseIP(address) 32 | if ip != nil { 33 | return ip, port, nil 34 | } else { 35 | return host, port, nil 36 | } 37 | } 38 | 39 | func (d *TransportDialer) Dial(network, address string) (conn net.Conn, err error) { 40 | host, port, err := parseAddress(address) 41 | if err != nil { 42 | return nil, err 43 | } 44 | var dest string 45 | var ipCached bool 46 | switch h := host.(type) { 47 | case net.IP: 48 | { 49 | dest = h.String() 50 | ipCached = true 51 | } 52 | case string: 53 | { 54 | dest = h 55 | if d.dnsCache != nil { 56 | if p, ok := d.dnsCache.Get(h); ok { 57 | dest = p.String() 58 | ipCached = true 59 | } 60 | } 61 | } 62 | } 63 | address = net.JoinHostPort(dest, port) 64 | if 0 == d.timeoutDial { 65 | conn, err = socks.Direct.Dial(network, address) 66 | } else { 67 | conn, err = socks.Direct.DialTimeout(network, address, d.timeoutDial) 68 | } 69 | if err != nil { 70 | return nil, err 71 | } 72 | 73 | if d.dnsCache != nil && !ipCached { 74 | d.dnsCache.Set(host.(string), conn.RemoteAddr().(*net.TCPAddr).IP) 75 | } 76 | return conn, nil 77 | } -------------------------------------------------------------------------------- /upstream/transport_listener.go: -------------------------------------------------------------------------------- 1 | package upstream 2 | 3 | import "net" 4 | 5 | type TransportListener struct { 6 | listener net.Listener 7 | decorators []TransportDecorator 8 | } 9 | 10 | func NewDecorateListener(listener net.Listener, ds ...TransportDecorator) *TransportListener { 11 | l := &TransportListener{ 12 | listener: listener, 13 | } 14 | l.decorators = append(l.decorators, ds...) 15 | return l 16 | } 17 | 18 | func (s *TransportListener) Accept() (net.Conn, error) { 19 | conn, err := s.listener.Accept() 20 | if err != nil { 21 | return nil, err 22 | } 23 | dconn, err := decorateTransportConn(conn, s.decorators...) 24 | if err != nil { 25 | conn.Close() 26 | return nil, err 27 | } 28 | return dconn, nil 29 | } 30 | 31 | func (s *TransportListener) Close() error { 32 | return s.listener.Close() 33 | } 34 | 35 | func (s *TransportListener) Addr() net.Addr { 36 | return s.listener.Addr() 37 | } 38 | -------------------------------------------------------------------------------- /upstream/upstream.go: -------------------------------------------------------------------------------- 1 | package upstream 2 | 3 | import ( 4 | "errors" 5 | "net" 6 | "strings" 7 | "sync" 8 | "time" 9 | 10 | "github.com/ssoor/socks" 11 | "github.com/ssoor/fundadore/log" 12 | ) 13 | 14 | type UpstreamDialer struct { 15 | index int 16 | lock sync.Mutex 17 | dialers []socks.Dialer 18 | } 19 | 20 | func BuildUpstreamDialer(upstream Upstream, forward socks.Dialer) (socks.Dialer, error) { 21 | cipherDecorator := NewCipherDecorator(upstream.Crypto, upstream.Password) 22 | forward = NewTransportConn(forward, cipherDecorator) 23 | 24 | switch strings.ToLower(upstream.Type) { 25 | case "socks5": 26 | { 27 | return socks.NewSocks5Client("tcp", upstream.Address, "", "", forward) 28 | } 29 | case "shadowsocks": 30 | { 31 | return socks.NewShadowSocksClient("tcp", upstream.Address, forward) 32 | } 33 | } 34 | 35 | return nil, errors.New("unknown upstream type" + upstream.Type) 36 | } 37 | 38 | func buildSetting(setting Settings) []socks.Dialer { 39 | var err error 40 | var forward socks.Dialer 41 | var allForward []socks.Dialer 42 | 43 | for _, upstream := range setting.Upstreams { 44 | forward = NewTransportDialer(setting.DNSCacheTime, time.Duration(setting.DialTimeout)) 45 | 46 | if forward, err = BuildUpstreamDialer(upstream, forward); nil != err { 47 | log.Warning("failed to BuildUpstream, err:", err) 48 | } else { 49 | allForward = append(allForward, forward) 50 | } 51 | } 52 | 53 | if len(allForward) == 0 { 54 | router := NewTransportDialer(setting.DNSCacheTime, time.Duration(setting.DialTimeout)) 55 | allForward = append(allForward, router) 56 | } 57 | 58 | return allForward 59 | } 60 | 61 | func NewUpstreamDialer(setting Settings) *UpstreamDialer { 62 | dialer := &UpstreamDialer{ 63 | index: 0, 64 | dialers: buildSetting(setting), // 原始连接,不经过任何处理 65 | } 66 | 67 | return dialer 68 | } 69 | 70 | func (u *UpstreamDialer) CallNextDialer(network, address string) (conn net.Conn, err error) { 71 | u.lock.Lock() 72 | defer u.lock.Unlock() 73 | for { 74 | if 0 == len(u.dialers) { 75 | return socks.Direct.Dial(network, address) 76 | } 77 | 78 | if u.index++; u.index >= len(u.dialers) { 79 | u.index = 0 80 | } 81 | 82 | if conn, err = u.dialers[u.index].Dial(network, address); nil == err { 83 | break 84 | } 85 | 86 | switch err.(type) { 87 | case *net.OpError: 88 | if strings.EqualFold("dial", err.(*net.OpError).Op) { 89 | copy(u.dialers[u.index:], u.dialers[u.index+1:]) 90 | u.dialers = u.dialers[:len(u.dialers)-1] 91 | 92 | log.Warning("Socks dial", network, address, "failed, delete current dialer:", err.(*net.OpError).Addr, ", err:", err) 93 | continue 94 | } 95 | } 96 | 97 | return nil, err 98 | } 99 | 100 | return conn, err 101 | } 102 | 103 | func (u *UpstreamDialer) Dial(network, address string) (conn net.Conn, err error) { 104 | if conn, err = u.CallNextDialer(network, address); nil != err { 105 | log.Warning("Upstream dial ", network, address, " failed, err:", err) 106 | return nil, err 107 | } 108 | 109 | return conn, nil 110 | } 111 | -------------------------------------------------------------------------------- /upstream/upstream_http.go: -------------------------------------------------------------------------------- 1 | package upstream 2 | 3 | import ( 4 | "encoding/json" 5 | "errors" 6 | "fmt" 7 | "net" 8 | "sync" 9 | "time" 10 | 11 | "github.com/ssoor/fundadore/api" 12 | "github.com/ssoor/fundadore/log" 13 | ) 14 | 15 | type URLUpstreamDialer struct { 16 | url string 17 | lock sync.Mutex 18 | interval time.Duration 19 | 20 | dialer *UpstreamDialer 21 | } 22 | 23 | func NewUpstreamDialerByURL(url string, updateInterval time.Duration) *URLUpstreamDialer { 24 | settings := Settings{ 25 | 26 | } 27 | 28 | dialer := &URLUpstreamDialer{ 29 | url: url, 30 | interval: updateInterval * time.Second, 31 | dialer: NewUpstreamDialer(settings), 32 | } 33 | 34 | go dialer.backgroundUpdateServices() 35 | 36 | return dialer 37 | } 38 | 39 | func getSocksdSetting(url string) (setting Settings, err error) { 40 | var jsonData string 41 | 42 | if jsonData, err = api.GetURL(url); err != nil { 43 | return setting, errors.New(fmt.Sprint("Query setting interface failed, err: ", err)) 44 | } 45 | 46 | if err = json.Unmarshal([]byte(jsonData), &setting); err != nil { 47 | return setting, errors.New("Unmarshal setting interface failed.") 48 | } 49 | 50 | return setting, nil 51 | } 52 | 53 | func (u *URLUpstreamDialer) backgroundUpdateServices() { 54 | var err error 55 | var setting Settings 56 | 57 | for { 58 | log.Info("Setting messenger server information:") 59 | 60 | log.Info("\tNext flush time :", u.interval) 61 | 62 | if setting, err = getSocksdSetting(u.url); nil == err { 63 | log.Info("\tDial timeout time :", setting.DialTimeout) 64 | log.Info("\tDNS cache timeout time :", setting.DNSCacheTime) 65 | 66 | for _, upstream := range setting.Upstreams { 67 | log.Info("\tUpstream :", upstream.Address) 68 | } 69 | 70 | u.lock.Lock() 71 | u.dialer = NewUpstreamDialer(setting) 72 | u.lock.Unlock() 73 | } 74 | 75 | time.Sleep(u.interval) 76 | } 77 | } 78 | 79 | func (u *URLUpstreamDialer) Dial(network, address string) (conn net.Conn, err error) { 80 | u.lock.Lock() 81 | defer u.lock.Unlock() 82 | 83 | return u.dialer.Dial(network, address) 84 | } 85 | -------------------------------------------------------------------------------- /vendor/github.com/ssoor/fundadore/api/api.go: -------------------------------------------------------------------------------- 1 | package api 2 | 3 | import ( 4 | "fmt" 5 | "compress/zlib" 6 | "crypto/aes" 7 | "crypto/cipher" 8 | "io" 9 | 10 | "github.com/ssoor/fundadore/common" 11 | 12 | "bytes" 13 | "net/http" 14 | ) 15 | 16 | const APIEnkey = "890161F37139989CFA9433BAF32BDAFB" 17 | 18 | func Decrypt(key string, base64Code []byte) (decode []byte, err error) { 19 | for i := 0; i < len(base64Code); i++ { 20 | base64Code[i] = base64Code[i] - 0x90 21 | } 22 | 23 | iv := base64Code[:16] 24 | encode := base64Code[16:] 25 | 26 | var block cipher.Block 27 | if block, err = aes.NewCipher([]byte(key)); err != nil { 28 | return nil, err 29 | } 30 | 31 | mode := cipher.NewCBCDecrypter(block, iv) 32 | mode.CryptBlocks(encode, encode) 33 | 34 | var zipReader io.ReadCloser 35 | if zipReader, err = zlib.NewReader(bytes.NewBuffer(encode)); nil != err { 36 | return nil, err 37 | } 38 | defer zipReader.Close() 39 | 40 | decodeBuf := bytes.NewBuffer(nil) 41 | if _, err := io.Copy(decodeBuf, zipReader); nil != err { 42 | return nil, err 43 | } 44 | 45 | return decodeBuf.Bytes(), nil 46 | } 47 | 48 | func GetURL(url string) (decodeData string, err error) { 49 | var data []byte 50 | 51 | fmt.Println(url) 52 | 53 | var resp *http.Response 54 | for i := 0; i < 3; i++ { 55 | if resp, err = http.Get(url); nil != err { 56 | continue 57 | } 58 | 59 | break 60 | } 61 | if err != nil { 62 | return "", err 63 | } 64 | 65 | defer resp.Body.Close() 66 | 67 | var bodyBuf bytes.Buffer 68 | 69 | bodyBuf.ReadFrom(resp.Body) 70 | 71 | data, err = Decrypt(APIEnkey, bodyBuf.Bytes()) 72 | if err != nil { 73 | return "", err 74 | } 75 | 76 | //log.Info("<", url, ">", common.GetValidString(data)) 77 | 78 | return common.GetValidString(data), nil 79 | } 80 | -------------------------------------------------------------------------------- /vendor/github.com/ssoor/fundadore/common/common.go: -------------------------------------------------------------------------------- 1 | package common 2 | 3 | import ( 4 | "fmt" 5 | "os" 6 | "path/filepath" 7 | "strings" 8 | ) 9 | 10 | var ChanSignalExit chan os.Signal = make(chan os.Signal, 1) 11 | 12 | func Substr(s string, pos, length int) string { 13 | runes := []rune(s) 14 | l := pos + length 15 | if l > len(runes) { 16 | l = len(runes) 17 | } 18 | return string(runes[pos:l]) 19 | } 20 | 21 | func GetValidString(src []byte) string { 22 | var str_buf []byte 23 | 24 | for _, v := range src { 25 | if v != 0 { 26 | str_buf = append(str_buf, v) 27 | } 28 | } 29 | 30 | return string(str_buf) 31 | } 32 | 33 | func GetParentDirectory(dirctory string) string { 34 | return Substr(dirctory, 0, strings.LastIndex(dirctory, "/")) 35 | } 36 | 37 | func GetCurrentDirectory() (string, error) { 38 | dir, err := filepath.Abs(filepath.Dir(os.Args[0])) 39 | if err != nil { 40 | return "", err 41 | } 42 | return strings.Replace(dir, "\\", "/", -1), nil 43 | } 44 | 45 | func GetCurrentExePath() (string, error) { 46 | prog := os.Args[0] 47 | p, err := filepath.Abs(prog) 48 | if err != nil { 49 | return "", err 50 | } 51 | fi, err := os.Stat(p) 52 | if err == nil { 53 | if !fi.Mode().IsDir() { 54 | return p, nil 55 | } 56 | err = fmt.Errorf("%s is directory", p) 57 | } 58 | if filepath.Ext(p) == "" { 59 | p += ".exe" 60 | fi, err := os.Stat(p) 61 | if err == nil { 62 | if !fi.Mode().IsDir() { 63 | return p, nil 64 | } 65 | err = fmt.Errorf("%s is directory", p) 66 | } 67 | } 68 | return "", err 69 | } 70 | -------------------------------------------------------------------------------- /vendor/github.com/ssoor/fundadore/common/hardware_windows.go: -------------------------------------------------------------------------------- 1 | package common 2 | 3 | import ( 4 | "fmt" 5 | "runtime" 6 | "syscall" 7 | 8 | "github.com/ssoor/winapi" 9 | ) 10 | 11 | func GetCPUString() (string, error) { 12 | var regHKey winapi.HKEY 13 | if errorCode := winapi.RegOpenKeyEx(winapi.HKEY_LOCAL_MACHINE, "HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\0", 0, winapi.KEY_READ, ®HKey); winapi.ERROR_SUCCESS != errorCode { 14 | return "", nil 15 | } 16 | 17 | var bufSize uint32 = 256 18 | bufCPUName := make([]uint16, bufSize) 19 | 20 | if errorCode := winapi.RegQueryValueEx(regHKey, "ProcessorNameString", 0, nil, &bufCPUName, &bufSize); winapi.ERROR_SUCCESS != errorCode { 21 | return "", nil 22 | } 23 | 24 | winapi.RegCloseKey(regHKey) 25 | 26 | return fmt.Sprintf("%s (%d)", syscall.UTF16ToString(bufCPUName), runtime.NumCPU()), nil 27 | } 28 | -------------------------------------------------------------------------------- /vendor/github.com/ssoor/fundadore/common/socket.go: -------------------------------------------------------------------------------- 1 | package common 2 | 3 | import ( 4 | "errors" 5 | "net" 6 | "strconv" 7 | "strings" 8 | ) 9 | 10 | var ( 11 | ErrorSocketUnavailable error = errors.New("socket port not find") 12 | ErrorNotValidAddress = errors.New("Not a valid link address") 13 | ) 14 | 15 | func GetConnectIP(connType string, connHost string) (ip string, err error) { //Get ip 16 | conn, err := net.Dial(connType, connHost) 17 | if err != nil { 18 | return ip, err 19 | } 20 | 21 | defer conn.Close() 22 | 23 | strSplit := strings.Split(conn.LocalAddr().String(), ":") 24 | 25 | if len(strSplit) < 2 { 26 | return ip, ErrorNotValidAddress 27 | } 28 | 29 | return strSplit[0], nil 30 | } 31 | 32 | func GetConnectMAC(connType string, connHost string) (string, error) { 33 | ip, err := GetConnectIP(connType, connHost) 34 | if nil != err { 35 | return "", err 36 | } 37 | 38 | interfaces, err := net.Interfaces() // 获取本机的MAC地址 39 | if err != nil { 40 | return "", err 41 | } 42 | 43 | if len(interfaces) == 0 { 44 | return "", errors.New("not find network hardware interface") 45 | } 46 | 47 | for _, inter := range interfaces { 48 | interAddrs, err := inter.Addrs() 49 | if nil != err { 50 | continue 51 | } 52 | 53 | for _, addr := range interAddrs { 54 | 55 | strSplit := strings.Split(addr.String(), "/") 56 | 57 | if len(strSplit) < 2 { 58 | continue 59 | } 60 | 61 | if strings.EqualFold(ip, strSplit[0]) { 62 | return inter.HardwareAddr.String(), nil 63 | } 64 | } 65 | } 66 | 67 | return "", errors.New("unknown error") 68 | } 69 | 70 | func GetIPs() (ips []string, err error) { 71 | addrs, err := net.InterfaceAddrs() 72 | if err != nil { 73 | return ips, err 74 | } 75 | 76 | for _, a := range addrs { 77 | if ipnet, ok := a.(*net.IPNet); ok && !ipnet.IP.IsLoopback() { 78 | if ipnet.IP.To4() != nil { 79 | ips = append(ips, ipnet.IP.String()) 80 | } 81 | } 82 | } 83 | 84 | return ips, nil 85 | } 86 | 87 | func GetMACs() (MACs []string, err error) { 88 | interfaces, err := net.Interfaces() // 获取本机的MAC地址 89 | if err != nil { 90 | return nil, err 91 | } 92 | 93 | for _, inter := range interfaces { 94 | MACs = append(MACs, inter.HardwareAddr.String()) // 获取本机MAC地址 95 | } 96 | 97 | return MACs, nil 98 | } 99 | 100 | // 得到地址对应的端口. 101 | func SocketGetPortFormAddr(addr string) (host string, port uint16, err error) { 102 | var intPort int 103 | var portString string 104 | 105 | if host, portString, err = net.SplitHostPort(addr); err != nil { 106 | return "", 0, err 107 | } 108 | 109 | if intPort, err = strconv.Atoi(portString); err != nil { 110 | return "", 0, err 111 | } 112 | 113 | port = uint16(intPort) 114 | return host, port, nil 115 | } 116 | 117 | // 得到一个可用的端口. 118 | func SocketSelectPort(port_type string) (port uint16, err error) { 119 | listener, err := net.Listen(port_type, "127.0.0.1:0") 120 | if err != nil { 121 | return 0, err 122 | } 123 | defer listener.Close() 124 | 125 | _, port, err = SocketGetPortFormAddr(listener.Addr().String()) 126 | 127 | return port, err 128 | } 129 | 130 | // 得到一个可用的端口. 131 | func SocketSelectAddr(port_type string, ip string) (addr string, err error) { 132 | listener, err := net.Listen(port_type, ip+":0") 133 | if err != nil { 134 | return "", err 135 | } 136 | defer listener.Close() 137 | 138 | return listener.Addr().String(), nil 139 | } 140 | -------------------------------------------------------------------------------- /vendor/github.com/ssoor/fundadore/log/log.go: -------------------------------------------------------------------------------- 1 | package log 2 | 3 | import ( 4 | "io" 5 | "os" 6 | "time" 7 | 8 | . "log" 9 | ) 10 | 11 | var ( 12 | Out *Logger 13 | Err *Logger 14 | Warn *Logger 15 | _fileOut *os.File 16 | ) 17 | 18 | func init() { 19 | Out = New(os.Stdout, "INFO ", LstdFlags) 20 | Err = New(os.Stdout, "ERROR ", LstdFlags) 21 | Warn = New(os.Stdout, "WARN ", LstdFlags) 22 | } 23 | 24 | func GetFileName() string { 25 | return _fileOut.Name() 26 | } 27 | 28 | func SetOutputFile(file *os.File) { 29 | _fileOut = file 30 | 31 | writers := []io.Writer{ 32 | _fileOut, 33 | os.Stdout, 34 | } 35 | logWriters := io.MultiWriter(writers...) 36 | 37 | Out = New(logWriters, "INFO\t", LstdFlags) 38 | Err = New(logWriters, "ERROR\t", LstdFlags) 39 | Warn = New(logWriters, "WARN\t", LstdFlags) 40 | 41 | } 42 | 43 | func Info(v ...interface{}) { 44 | Out.Println(v...) 45 | } 46 | 47 | func Infof(format string, v ...interface{}) { 48 | Out.Printf(format, v...) 49 | } 50 | 51 | func Warning(v ...interface{}) { 52 | Warn.Println(v...) 53 | } 54 | 55 | func Warningf(format string, v ...interface{}) { 56 | Warn.Printf(format, v...) 57 | } 58 | 59 | func Error(v ...interface{}) { 60 | Err.Println(v...) 61 | } 62 | 63 | func Errorf(format string, v ...interface{}) { 64 | Err.Printf(format, v...) 65 | } 66 | 67 | // 写超时警告日志 通用方法 68 | 69 | func TimeoutWarning(detailed string, start time.Time, timeLimit float64) { 70 | dis := time.Now().Sub(start).Seconds() 71 | if dis > timeLimit { 72 | Warning(detailed, "using", dis, "seconds") 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /vendor/github.com/ssoor/winapi/AUTHORS: -------------------------------------------------------------------------------- 1 | # This is the official list of 'win' authors for copyright purposes. 2 | 3 | # Names should be added to this file as 4 | # Name or Organization 5 | # The email address is not required for organizations. 6 | 7 | # Please keep the list sorted. 8 | 9 | # Contributors 10 | # ============ 11 | 12 | Alexander Neumann 13 | Anton Lahti 14 | Benny Siegert 15 | Bruno Bigras 16 | Carlos Cobo 17 | Cary Cherng 18 | Hill 19 | Joseph Watson 20 | Kevin Pors 21 | ktye 22 | mycaosf 23 | wsf01 24 | -------------------------------------------------------------------------------- /vendor/github.com/ssoor/winapi/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2010 The win Authors. All rights reserved. 2 | 3 | Redistribution and use in source and binary forms, with or without 4 | modification, are permitted provided that the following conditions 5 | are met: 6 | 1. Redistributions of source code must retain the above copyright 7 | notice, this list of conditions and the following disclaimer. 8 | 2. Redistributions in binary form must reproduce the above copyright 9 | notice, this list of conditions and the following disclaimer in the 10 | documentation and/or other materials provided with the distribution. 11 | 3. The names of the authors may not be used to endorse or promote products 12 | derived from this software without specific prior written permission. 13 | 14 | THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR 15 | IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 16 | OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 17 | IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT, 18 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 19 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 20 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 21 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 23 | THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | -------------------------------------------------------------------------------- /vendor/github.com/ssoor/winapi/README.mdown: -------------------------------------------------------------------------------- 1 | About win 2 | ========= 3 | 4 | win is a Windows API wrapper package for Go. 5 | 6 | Originally part of [walk](https://github.com/lxn/walk), it is now a separate 7 | project. 8 | 9 | Setup 10 | ===== 11 | 12 | Make sure you have a working Go installation. 13 | See [Getting Started](http://golang.org/doc/install.html) 14 | 15 | Now run `go get github.com/lxn/win` 16 | -------------------------------------------------------------------------------- /vendor/github.com/ssoor/winapi/advapi32.go: -------------------------------------------------------------------------------- 1 | // Copyright 2010 The win Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // +build windows 6 | 7 | package winapi 8 | 9 | import ( 10 | "syscall" 11 | "unsafe" 12 | ) 13 | 14 | const KEY_READ REGSAM = 0x20019 15 | const KEY_WRITE REGSAM = 0x20006 16 | 17 | const ( 18 | HKEY_CLASSES_ROOT HKEY = 0x80000000 19 | HKEY_CURRENT_USER HKEY = 0x80000001 20 | HKEY_LOCAL_MACHINE HKEY = 0x80000002 21 | HKEY_USERS HKEY = 0x80000003 22 | HKEY_PERFORMANCE_DATA HKEY = 0x80000004 23 | HKEY_CURRENT_CONFIG HKEY = 0x80000005 24 | HKEY_DYN_DATA HKEY = 0x80000006 25 | ) 26 | 27 | const ( 28 | ERROR_NO_MORE_ITEMS = 259 29 | ) 30 | 31 | type ( 32 | ACCESS_MASK uint32 33 | HKEY HANDLE 34 | REGSAM ACCESS_MASK 35 | ) 36 | 37 | const ( 38 | REG_NONE uint64 = 0 // No value type 39 | REG_SZ = 1 // Unicode nul terminated string 40 | REG_EXPAND_SZ = 2 // Unicode nul terminated string 41 | // (with environment variable references) 42 | REG_BINARY = 3 // Free form binary 43 | REG_DWORD = 4 // 32-bit number 44 | REG_DWORD_LITTLE_ENDIAN = 4 // 32-bit number (same as REG_DWORD) 45 | REG_DWORD_BIG_ENDIAN = 5 // 32-bit number 46 | REG_LINK = 6 // Symbolic Link (unicode) 47 | REG_MULTI_SZ = 7 // Multiple Unicode strings 48 | REG_RESOURCE_LIST = 8 // Resource list in the resource map 49 | REG_FULL_RESOURCE_DESCRIPTOR = 9 // Resource list in the hardware description 50 | REG_RESOURCE_REQUIREMENTS_LIST = 10 51 | REG_QWORD = 11 // 64-bit number 52 | REG_QWORD_LITTLE_ENDIAN = 11 // 64-bit number (same as REG_QWORD) 53 | 54 | ) 55 | 56 | const ( 57 | REG_OPTION_NON_VOLATILE = 0 58 | 59 | REG_CREATED_NEW_KEY = 1 60 | REG_OPENED_EXISTING_KEY = 2 61 | ) 62 | 63 | var ( 64 | // Library 65 | libadvapi32 uintptr 66 | 67 | // Functions 68 | regCloseKey uintptr 69 | regOpenKeyEx uintptr 70 | regDeleteKey uintptr 71 | regCreateKeyEx uintptr 72 | regQueryValueEx uintptr 73 | regEnumValue uintptr 74 | regSetValueEx uintptr 75 | ) 76 | 77 | func init() { 78 | // Library 79 | libadvapi32 = MustLoadLibrary("advapi32.dll") 80 | 81 | // Functions 82 | regCloseKey = MustGetProcAddress(libadvapi32, "RegCloseKey") 83 | regOpenKeyEx = MustGetProcAddress(libadvapi32, "RegOpenKeyExW") 84 | regDeleteKey = MustGetProcAddress(libadvapi32, "RegDeleteKeyW") 85 | regCreateKeyEx = MustGetProcAddress(libadvapi32, "RegCreateKeyExW") 86 | regQueryValueEx = MustGetProcAddress(libadvapi32, "RegQueryValueExW") 87 | regEnumValue = MustGetProcAddress(libadvapi32, "RegEnumValueW") 88 | regSetValueEx = MustGetProcAddress(libadvapi32, "RegSetValueExW") 89 | } 90 | 91 | func RegDeleteKey(hKey HKEY, subkey string) (regerrno error) { 92 | ret, _, _ := syscall.Syscall(regDeleteKey, 2, 93 | uintptr(hKey), 94 | uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(subkey))), 95 | 0) 96 | 97 | if ret != 0 { 98 | regerrno = syscall.Errno(ret) 99 | } 100 | return 101 | } 102 | 103 | func RegCreateKeyEx(hKey HKEY, subkey string, reserved uint32, class *uint16, options uint32, desired uint32, sa *syscall.SecurityAttributes, result *HKEY, disposition *uint32) (regerrno error) { 104 | ret, _, _ := syscall.Syscall9(regCreateKeyEx, 9, 105 | uintptr(hKey), 106 | uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(subkey))), 107 | uintptr(reserved), 108 | uintptr(unsafe.Pointer(class)), 109 | uintptr(options), 110 | uintptr(desired), 111 | uintptr(unsafe.Pointer(sa)), 112 | uintptr(unsafe.Pointer(result)), 113 | uintptr(unsafe.Pointer(disposition))) 114 | 115 | if ret != 0 { 116 | regerrno = syscall.Errno(ret) 117 | } 118 | return 119 | } 120 | 121 | func RegCloseKey(hKey HKEY) int32 { 122 | ret, _, _ := syscall.Syscall(regCloseKey, 1, 123 | uintptr(hKey), 124 | 0, 125 | 0) 126 | 127 | return int32(ret) 128 | } 129 | 130 | func RegOpenKeyEx(hKey HKEY, lpSubKey string, ulOptions uint32, samDesired REGSAM, phkResult *HKEY) int32 { 131 | ret, _, _ := syscall.Syscall6(regOpenKeyEx, 5, 132 | uintptr(hKey), 133 | uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(lpSubKey))), 134 | uintptr(ulOptions), 135 | uintptr(samDesired), 136 | uintptr(unsafe.Pointer(phkResult)), 137 | 0) 138 | 139 | return int32(ret) 140 | } 141 | 142 | func RegQueryValueEx(hKey HKEY, lpValueName string, lpReserved uint32, lpType *uint32, lpData *[]uint16, lpcbData *uint32) int32 { 143 | ret, _, _ := syscall.Syscall6(regQueryValueEx, 6, 144 | uintptr(hKey), 145 | uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(lpValueName))), 146 | uintptr(lpReserved), 147 | uintptr(unsafe.Pointer(lpType)), 148 | uintptr(unsafe.Pointer(&(*lpData)[0])), 149 | uintptr(unsafe.Pointer(lpcbData))) 150 | 151 | return int32(ret) 152 | } 153 | 154 | func RegEnumValue(hKey HKEY, index uint32, lpValueName string, lpcchValueName *uint32, lpReserved uint32, lpType *uint32, lpData *byte, lpcbData *uint32) int32 { 155 | ret, _, _ := syscall.Syscall9(regEnumValue, 8, 156 | uintptr(hKey), 157 | uintptr(index), 158 | uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(lpValueName))), 159 | uintptr(unsafe.Pointer(lpcchValueName)), 160 | uintptr(lpReserved), 161 | uintptr(unsafe.Pointer(lpType)), 162 | uintptr(unsafe.Pointer(lpData)), 163 | uintptr(unsafe.Pointer(lpcbData)), 164 | 0) 165 | return int32(ret) 166 | } 167 | 168 | func RegSetValueEx(hKey HKEY, lpValueName string, lpReserved uint32, lpDataType uint32, lpData *byte, cbData uint32) int32 { 169 | ret, _, _ := syscall.Syscall6(regSetValueEx, 6, 170 | uintptr(hKey), 171 | uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(lpValueName))), 172 | uintptr(lpReserved), 173 | uintptr(lpDataType), 174 | uintptr(unsafe.Pointer(lpData)), 175 | uintptr(cbData)) 176 | return int32(ret) 177 | } 178 | -------------------------------------------------------------------------------- /vendor/github.com/ssoor/winapi/combobox.go: -------------------------------------------------------------------------------- 1 | // Copyright 2010 The win Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // +build windows 6 | 7 | package winapi 8 | 9 | // ComboBox return values 10 | const ( 11 | CB_OKAY = 0 12 | CB_ERR = ^uintptr(0) // -1 13 | CB_ERRSPACE = ^uintptr(1) // -2 14 | ) 15 | 16 | // ComboBox notifications 17 | const ( 18 | CBN_ERRSPACE = -1 19 | CBN_SELCHANGE = 1 20 | CBN_DBLCLK = 2 21 | CBN_SETFOCUS = 3 22 | CBN_KILLFOCUS = 4 23 | CBN_EDITCHANGE = 5 24 | CBN_EDITUPDATE = 6 25 | CBN_DROPDOWN = 7 26 | CBN_CLOSEUP = 8 27 | CBN_SELENDOK = 9 28 | CBN_SELENDCANCEL = 10 29 | ) 30 | 31 | // ComboBox styles 32 | const ( 33 | CBS_SIMPLE = 0x0001 34 | CBS_DROPDOWN = 0x0002 35 | CBS_DROPDOWNLIST = 0x0003 36 | CBS_OWNERDRAWFIXED = 0x0010 37 | CBS_OWNERDRAWVARIABLE = 0x0020 38 | CBS_AUTOHSCROLL = 0x0040 39 | CBS_OEMCONVERT = 0x0080 40 | CBS_SORT = 0x0100 41 | CBS_HASSTRINGS = 0x0200 42 | CBS_NOINTEGRALHEIGHT = 0x0400 43 | CBS_DISABLENOSCROLL = 0x0800 44 | CBS_UPPERCASE = 0x2000 45 | CBS_LOWERCASE = 0x4000 46 | ) 47 | 48 | // ComboBox messages 49 | const ( 50 | CB_GETEDITSEL = 0x0140 51 | CB_LIMITTEXT = 0x0141 52 | CB_SETEDITSEL = 0x0142 53 | CB_ADDSTRING = 0x0143 54 | CB_DELETESTRING = 0x0144 55 | CB_DIR = 0x0145 56 | CB_GETCOUNT = 0x0146 57 | CB_GETCURSEL = 0x0147 58 | CB_GETLBTEXT = 0x0148 59 | CB_GETLBTEXTLEN = 0x0149 60 | CB_INSERTSTRING = 0x014A 61 | CB_RESETCONTENT = 0x014B 62 | CB_FINDSTRING = 0x014C 63 | CB_SELECTSTRING = 0x014D 64 | CB_SETCURSEL = 0x014E 65 | CB_SHOWDROPDOWN = 0x014F 66 | CB_GETITEMDATA = 0x0150 67 | CB_SETITEMDATA = 0x0151 68 | CB_GETDROPPEDCONTROLRECT = 0x0152 69 | CB_SETITEMHEIGHT = 0x0153 70 | CB_GETITEMHEIGHT = 0x0154 71 | CB_SETEXTENDEDUI = 0x0155 72 | CB_GETEXTENDEDUI = 0x0156 73 | CB_GETDROPPEDSTATE = 0x0157 74 | CB_FINDSTRINGEXACT = 0x0158 75 | CB_SETLOCALE = 0x0159 76 | CB_GETLOCALE = 0x015A 77 | CB_GETTOPINDEX = 0x015b 78 | CB_SETTOPINDEX = 0x015c 79 | CB_GETHORIZONTALEXTENT = 0x015d 80 | CB_SETHORIZONTALEXTENT = 0x015e 81 | CB_GETDROPPEDWIDTH = 0x015f 82 | CB_SETDROPPEDWIDTH = 0x0160 83 | CB_INITSTORAGE = 0x0161 84 | CB_MULTIPLEADDSTRING = 0x0163 85 | CB_GETCOMBOBOXINFO = 0x0164 86 | ) 87 | -------------------------------------------------------------------------------- /vendor/github.com/ssoor/winapi/comctl32.go: -------------------------------------------------------------------------------- 1 | // Copyright 2010 The win Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // +build windows 6 | 7 | package winapi 8 | 9 | import ( 10 | "syscall" 11 | "unsafe" 12 | ) 13 | 14 | // Button control messages 15 | const ( 16 | BCM_FIRST = 0x1600 17 | BCM_GETIDEALSIZE = BCM_FIRST + 0x0001 18 | BCM_SETIMAGELIST = BCM_FIRST + 0x0002 19 | BCM_GETIMAGELIST = BCM_FIRST + 0x0003 20 | BCM_SETTEXTMARGIN = BCM_FIRST + 0x0004 21 | BCM_GETTEXTMARGIN = BCM_FIRST + 0x0005 22 | BCM_SETDROPDOWNSTATE = BCM_FIRST + 0x0006 23 | BCM_SETSPLITINFO = BCM_FIRST + 0x0007 24 | BCM_GETSPLITINFO = BCM_FIRST + 0x0008 25 | BCM_SETNOTE = BCM_FIRST + 0x0009 26 | BCM_GETNOTE = BCM_FIRST + 0x000A 27 | BCM_GETNOTELENGTH = BCM_FIRST + 0x000B 28 | ) 29 | 30 | const ( 31 | CCM_FIRST = 0x2000 32 | CCM_LAST = CCM_FIRST + 0x200 33 | CCM_SETBKCOLOR = 8193 34 | CCM_SETCOLORSCHEME = 8194 35 | CCM_GETCOLORSCHEME = 8195 36 | CCM_GETDROPTARGET = 8196 37 | CCM_SETUNICODEFORMAT = 8197 38 | CCM_GETUNICODEFORMAT = 8198 39 | CCM_SETVERSION = 0x2007 40 | CCM_GETVERSION = 0x2008 41 | CCM_SETNOTIFYWINDOW = 0x2009 42 | CCM_SETWINDOWTHEME = 0x200b 43 | CCM_DPISCALE = 0x200c 44 | ) 45 | 46 | // Common controls styles 47 | const ( 48 | CCS_TOP = 1 49 | CCS_NOMOVEY = 2 50 | CCS_BOTTOM = 3 51 | CCS_NORESIZE = 4 52 | CCS_NOPARENTALIGN = 8 53 | CCS_ADJUSTABLE = 32 54 | CCS_NODIVIDER = 64 55 | CCS_VERT = 128 56 | CCS_LEFT = 129 57 | CCS_NOMOVEX = 130 58 | CCS_RIGHT = 131 59 | ) 60 | 61 | // InitCommonControlsEx flags 62 | const ( 63 | ICC_LISTVIEW_CLASSES = 1 64 | ICC_TREEVIEW_CLASSES = 2 65 | ICC_BAR_CLASSES = 4 66 | ICC_TAB_CLASSES = 8 67 | ICC_UPDOWN_CLASS = 16 68 | ICC_PROGRESS_CLASS = 32 69 | ICC_HOTKEY_CLASS = 64 70 | ICC_ANIMATE_CLASS = 128 71 | ICC_WIN95_CLASSES = 255 72 | ICC_DATE_CLASSES = 256 73 | ICC_USEREX_CLASSES = 512 74 | ICC_COOL_CLASSES = 1024 75 | ICC_INTERNET_CLASSES = 2048 76 | ICC_PAGESCROLLER_CLASS = 4096 77 | ICC_NATIVEFNTCTL_CLASS = 8192 78 | INFOTIPSIZE = 1024 79 | ICC_STANDARD_CLASSES = 0x00004000 80 | ICC_LINK_CLASS = 0x00008000 81 | ) 82 | 83 | // WM_NOTITY messages 84 | const ( 85 | NM_FIRST = 0 86 | NM_OUTOFMEMORY = ^uint32(0) // NM_FIRST - 1 87 | NM_CLICK = ^uint32(1) // NM_FIRST - 2 88 | NM_DBLCLK = ^uint32(2) // NM_FIRST - 3 89 | NM_RETURN = ^uint32(3) // NM_FIRST - 4 90 | NM_RCLICK = ^uint32(4) // NM_FIRST - 5 91 | NM_RDBLCLK = ^uint32(5) // NM_FIRST - 6 92 | NM_SETFOCUS = ^uint32(6) // NM_FIRST - 7 93 | NM_KILLFOCUS = ^uint32(7) // NM_FIRST - 8 94 | NM_CUSTOMDRAW = ^uint32(11) // NM_FIRST - 12 95 | NM_HOVER = ^uint32(12) // NM_FIRST - 13 96 | NM_NCHITTEST = ^uint32(13) // NM_FIRST - 14 97 | NM_KEYDOWN = ^uint32(14) // NM_FIRST - 15 98 | NM_RELEASEDCAPTURE = ^uint32(15) // NM_FIRST - 16 99 | NM_SETCURSOR = ^uint32(16) // NM_FIRST - 17 100 | NM_CHAR = ^uint32(17) // NM_FIRST - 18 101 | NM_TOOLTIPSCREATED = ^uint32(18) // NM_FIRST - 19 102 | NM_LAST = ^uint32(98) // NM_FIRST - 99 103 | ) 104 | 105 | // ProgressBar messages 106 | const ( 107 | PBM_SETPOS = WM_USER + 2 108 | PBM_DELTAPOS = WM_USER + 3 109 | PBM_SETSTEP = WM_USER + 4 110 | PBM_STEPIT = WM_USER + 5 111 | PBM_SETMARQUEE = WM_USER + 10 112 | PBM_SETRANGE32 = 1030 113 | PBM_GETRANGE = 1031 114 | PBM_GETPOS = 1032 115 | PBM_SETBARCOLOR = 1033 116 | PBM_SETBKCOLOR = CCM_SETBKCOLOR 117 | ) 118 | 119 | // ProgressBar styles 120 | const ( 121 | PBS_SMOOTH = 0x01 122 | PBS_VERTICAL = 0x04 123 | PBS_MARQUEE = 0x08 124 | ) 125 | 126 | // ImageList creation flags 127 | const ( 128 | ILC_MASK = 0x00000001 129 | ILC_COLOR = 0x00000000 130 | ILC_COLORDDB = 0x000000FE 131 | ILC_COLOR4 = 0x00000004 132 | ILC_COLOR8 = 0x00000008 133 | ILC_COLOR16 = 0x00000010 134 | ILC_COLOR24 = 0x00000018 135 | ILC_COLOR32 = 0x00000020 136 | ILC_PALETTE = 0x00000800 137 | ILC_MIRROR = 0x00002000 138 | ILC_PERITEMMIRROR = 0x00008000 139 | ) 140 | 141 | const ( 142 | CDDS_PREPAINT = 0x00000001 143 | CDDS_POSTPAINT = 0x00000002 144 | CDDS_PREERASE = 0x00000003 145 | CDDS_POSTERASE = 0x00000004 146 | CDDS_ITEM = 0x00010000 147 | CDDS_ITEMPREPAINT = CDDS_ITEM | CDDS_PREPAINT 148 | CDDS_ITEMPOSTPAINT = CDDS_ITEM | CDDS_POSTPAINT 149 | CDDS_ITEMPREERASE = CDDS_ITEM | CDDS_PREERASE 150 | CDDS_ITEMPOSTERASE = CDDS_ITEM | CDDS_POSTERASE 151 | CDDS_SUBITEM = 0x00020000 152 | ) 153 | 154 | const ( 155 | CDIS_SELECTED = 0x0001 156 | CDIS_GRAYED = 0x0002 157 | CDIS_DISABLED = 0x0004 158 | CDIS_CHECKED = 0x0008 159 | CDIS_FOCUS = 0x0010 160 | CDIS_DEFAULT = 0x0020 161 | CDIS_HOT = 0x0040 162 | CDIS_MARKED = 0x0080 163 | CDIS_INDETERMINATE = 0x0100 164 | CDIS_SHOWKEYBOARDCUES = 0x0200 165 | CDIS_NEARHOT = 0x0400 166 | CDIS_OTHERSIDEHOT = 0x0800 167 | CDIS_DROPHILITED = 0x1000 168 | ) 169 | 170 | const ( 171 | CDRF_DODEFAULT = 0x00000000 172 | CDRF_NEWFONT = 0x00000002 173 | CDRF_SKIPDEFAULT = 0x00000004 174 | CDRF_DOERASE = 0x00000008 175 | CDRF_NOTIFYPOSTPAINT = 0x00000010 176 | CDRF_NOTIFYITEMDRAW = 0x00000020 177 | CDRF_NOTIFYSUBITEMDRAW = 0x00000020 178 | CDRF_NOTIFYPOSTERASE = 0x00000040 179 | CDRF_SKIPPOSTPAINT = 0x00000100 180 | ) 181 | 182 | const ( 183 | LPSTR_TEXTCALLBACK = ^uintptr(0) 184 | I_CHILDRENCALLBACK = -1 185 | ) 186 | 187 | type HIMAGELIST HANDLE 188 | 189 | type INITCOMMONCONTROLSEX struct { 190 | DwSize, DwICC uint32 191 | } 192 | 193 | type NMCUSTOMDRAW struct { 194 | Hdr NMHDR 195 | DwDrawStage uint32 196 | Hdc HDC 197 | Rc RECT 198 | DwItemSpec uintptr 199 | UItemState uint32 200 | LItemlParam uintptr 201 | } 202 | 203 | var ( 204 | // Library 205 | libcomctl32 uintptr 206 | 207 | // Functions 208 | imageList_Add uintptr 209 | imageList_AddMasked uintptr 210 | imageList_Create uintptr 211 | imageList_Destroy uintptr 212 | imageList_ReplaceIcon uintptr 213 | initCommonControlsEx uintptr 214 | ) 215 | 216 | func init() { 217 | // Library 218 | libcomctl32 = MustLoadLibrary("comctl32.dll") 219 | 220 | // Functions 221 | imageList_Add = MustGetProcAddress(libcomctl32, "ImageList_Add") 222 | imageList_AddMasked = MustGetProcAddress(libcomctl32, "ImageList_AddMasked") 223 | imageList_Create = MustGetProcAddress(libcomctl32, "ImageList_Create") 224 | imageList_Destroy = MustGetProcAddress(libcomctl32, "ImageList_Destroy") 225 | imageList_ReplaceIcon = MustGetProcAddress(libcomctl32, "ImageList_ReplaceIcon") 226 | initCommonControlsEx = MustGetProcAddress(libcomctl32, "InitCommonControlsEx") 227 | 228 | // Initialize the common controls we support 229 | var initCtrls INITCOMMONCONTROLSEX 230 | initCtrls.DwSize = uint32(unsafe.Sizeof(initCtrls)) 231 | initCtrls.DwICC = ICC_LISTVIEW_CLASSES | ICC_PROGRESS_CLASS | ICC_TAB_CLASSES | ICC_TREEVIEW_CLASSES 232 | 233 | InitCommonControlsEx(&initCtrls) 234 | } 235 | 236 | func ImageList_Add(himl HIMAGELIST, hbmImage, hbmMask HBITMAP) int32 { 237 | ret, _, _ := syscall.Syscall(imageList_Add, 3, 238 | uintptr(himl), 239 | uintptr(hbmImage), 240 | uintptr(hbmMask)) 241 | 242 | return int32(ret) 243 | } 244 | 245 | func ImageList_AddMasked(himl HIMAGELIST, hbmImage HBITMAP, crMask COLORREF) int32 { 246 | ret, _, _ := syscall.Syscall(imageList_AddMasked, 3, 247 | uintptr(himl), 248 | uintptr(hbmImage), 249 | uintptr(crMask)) 250 | 251 | return int32(ret) 252 | } 253 | 254 | func ImageList_Create(cx, cy int32, flags uint32, cInitial, cGrow int32) HIMAGELIST { 255 | ret, _, _ := syscall.Syscall6(imageList_Create, 5, 256 | uintptr(cx), 257 | uintptr(cy), 258 | uintptr(flags), 259 | uintptr(cInitial), 260 | uintptr(cGrow), 261 | 0) 262 | 263 | return HIMAGELIST(ret) 264 | } 265 | 266 | func ImageList_Destroy(hIml HIMAGELIST) bool { 267 | ret, _, _ := syscall.Syscall(imageList_Destroy, 1, 268 | uintptr(hIml), 269 | 0, 270 | 0) 271 | 272 | return ret != 0 273 | } 274 | 275 | func ImageList_ReplaceIcon(himl HIMAGELIST, i int32, hicon HICON) int32 { 276 | ret, _, _ := syscall.Syscall(imageList_ReplaceIcon, 3, 277 | uintptr(himl), 278 | uintptr(i), 279 | uintptr(hicon)) 280 | 281 | return int32(ret) 282 | } 283 | 284 | func InitCommonControlsEx(lpInitCtrls *INITCOMMONCONTROLSEX) bool { 285 | ret, _, _ := syscall.Syscall(initCommonControlsEx, 1, 286 | uintptr(unsafe.Pointer(lpInitCtrls)), 287 | 0, 288 | 0) 289 | 290 | return ret != 0 291 | } 292 | -------------------------------------------------------------------------------- /vendor/github.com/ssoor/winapi/comdlg32.go: -------------------------------------------------------------------------------- 1 | // Copyright 2010 The win Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // +build windows 6 | 7 | package winapi 8 | 9 | import ( 10 | "syscall" 11 | "unsafe" 12 | ) 13 | 14 | // Common error codes 15 | const ( 16 | CDERR_DIALOGFAILURE = 0xFFFF 17 | CDERR_FINDRESFAILURE = 0x0006 18 | CDERR_INITIALIZATION = 0x0002 19 | CDERR_LOADRESFAILURE = 0x0007 20 | CDERR_LOADSTRFAILURE = 0x0005 21 | CDERR_LOCKRESFAILURE = 0x0008 22 | CDERR_MEMALLOCFAILURE = 0x0009 23 | CDERR_MEMLOCKFAILURE = 0x000A 24 | CDERR_NOHINSTANCE = 0x0004 25 | CDERR_NOHOOK = 0x000B 26 | CDERR_NOTEMPLATE = 0x0003 27 | CDERR_REGISTERMSGFAIL = 0x000C 28 | CDERR_STRUCTSIZE = 0x0001 29 | ) 30 | 31 | // CHOOSECOLOR flags 32 | const ( 33 | CC_ANYCOLOR = 0x00000100 34 | CC_ENABLEHOOK = 0x00000010 35 | CC_ENABLETEMPLATE = 0x00000020 36 | CC_ENABLETEMPLATEHANDLE = 0x00000040 37 | CC_FULLOPEN = 0x00000002 38 | CC_PREVENTFULLOPEN = 0x00000004 39 | CC_RGBINIT = 0x00000001 40 | CC_SHOWHELP = 0x00000008 41 | CC_SOLIDCOLOR = 0x00000080 42 | ) 43 | 44 | type CHOOSECOLOR struct { 45 | LStructSize uint32 46 | HwndOwner HWND 47 | HInstance HWND 48 | RgbResult COLORREF 49 | LpCustColors *COLORREF 50 | Flags uint32 51 | LCustData uintptr 52 | LpfnHook uintptr 53 | LpTemplateName *uint16 54 | } 55 | 56 | // PrintDlg specific error codes 57 | const ( 58 | PDERR_CREATEICFAILURE = 0x100A 59 | PDERR_DEFAULTDIFFERENT = 0x100C 60 | PDERR_DNDMMISMATCH = 0x1009 61 | PDERR_GETDEVMODEFAIL = 0x1005 62 | PDERR_INITFAILURE = 0x1006 63 | PDERR_LOADDRVFAILURE = 0x1004 64 | PDERR_NODEFAULTPRN = 0x1008 65 | PDERR_NODEVICES = 0x1007 66 | PDERR_PARSEFAILURE = 0x1002 67 | PDERR_PRINTERNOTFOUND = 0x100B 68 | PDERR_RETDEFFAILURE = 0x1003 69 | PDERR_SETUPFAILURE = 0x1001 70 | ) 71 | 72 | // ChooseFont specific error codes 73 | const ( 74 | CFERR_MAXLESSTHANMIN = 0x2002 75 | CFERR_NOFONTS = 0x2001 76 | ) 77 | 78 | // GetOpenFileName and GetSaveFileName specific error codes 79 | const ( 80 | FNERR_BUFFERTOOSMALL = 0x3003 81 | FNERR_INVALIDFILENAME = 0x3002 82 | FNERR_SUBCLASSFAILURE = 0x3001 83 | ) 84 | 85 | // FindText and ReplaceText specific error codes 86 | const ( 87 | FRERR_BUFFERLENGTHZERO = 0x4001 88 | ) 89 | 90 | // GetOpenFileName and GetSaveFileName flags 91 | const ( 92 | OFN_ALLOWMULTISELECT = 0x00000200 93 | OFN_CREATEPROMPT = 0x00002000 94 | OFN_DONTADDTORECENT = 0x02000000 95 | OFN_ENABLEHOOK = 0x00000020 96 | OFN_ENABLEINCLUDENOTIFY = 0x00400000 97 | OFN_ENABLESIZING = 0x00800000 98 | OFN_ENABLETEMPLATE = 0x00000040 99 | OFN_ENABLETEMPLATEHANDLE = 0x00000080 100 | OFN_EXPLORER = 0x00080000 101 | OFN_EXTENSIONDIFFERENT = 0x00000400 102 | OFN_FILEMUSTEXIST = 0x00001000 103 | OFN_FORCESHOWHIDDEN = 0x10000000 104 | OFN_HIDEREADONLY = 0x00000004 105 | OFN_LONGNAMES = 0x00200000 106 | OFN_NOCHANGEDIR = 0x00000008 107 | OFN_NODEREFERENCELINKS = 0x00100000 108 | OFN_NOLONGNAMES = 0x00040000 109 | OFN_NONETWORKBUTTON = 0x00020000 110 | OFN_NOREADONLYRETURN = 0x00008000 111 | OFN_NOTESTFILECREATE = 0x00010000 112 | OFN_NOVALIDATE = 0x00000100 113 | OFN_OVERWRITEPROMPT = 0x00000002 114 | OFN_PATHMUSTEXIST = 0x00000800 115 | OFN_READONLY = 0x00000001 116 | OFN_SHAREAWARE = 0x00004000 117 | OFN_SHOWHELP = 0x00000010 118 | ) 119 | 120 | // GetOpenFileName and GetSaveFileName extended flags 121 | const ( 122 | OFN_EX_NOPLACESBAR = 0x00000001 123 | ) 124 | 125 | // PrintDlg[Ex] result actions 126 | const ( 127 | PD_RESULT_APPLY = 2 128 | PD_RESULT_CANCEL = 0 129 | PD_RESULT_PRINT = 1 130 | ) 131 | 132 | // PrintDlg[Ex] flags 133 | const ( 134 | PD_ALLPAGES = 0x00000000 135 | PD_COLLATE = 0x00000010 136 | PD_CURRENTPAGE = 0x00400000 137 | PD_DISABLEPRINTTOFILE = 0x00080000 138 | PD_ENABLEPRINTTEMPLATE = 0x00004000 139 | PD_ENABLEPRINTTEMPLATEHANDLE = 0x00010000 140 | PD_EXCLUSIONFLAGS = 0x01000000 141 | PD_HIDEPRINTTOFILE = 0x00100000 142 | PD_NOCURRENTPAGE = 0x00800000 143 | PD_NOPAGENUMS = 0x00000008 144 | PD_NOSELECTION = 0x00000004 145 | PD_NOWARNING = 0x00000080 146 | PD_PAGENUMS = 0x00000002 147 | PD_PRINTTOFILE = 0x00000020 148 | PD_RETURNDC = 0x00000100 149 | PD_RETURNDEFAULT = 0x00000400 150 | PD_RETURNIC = 0x00000200 151 | PD_SELECTION = 0x00000001 152 | PD_USEDEVMODECOPIES = 0x00040000 153 | PD_USEDEVMODECOPIESANDCOLLATE = 0x00040000 154 | PD_USELARGETEMPLATE = 0x10000000 155 | ) 156 | 157 | // PrintDlgEx exclusion flags 158 | const ( 159 | PD_EXCL_COPIESANDCOLLATE = DM_COPIES | DM_COLLATE 160 | ) 161 | 162 | const START_PAGE_GENERAL = 0xffffffff 163 | 164 | type ( 165 | LPOFNHOOKPROC uintptr 166 | HPROPSHEETPAGE HANDLE 167 | LPUNKNOWN uintptr 168 | ) 169 | 170 | type OPENFILENAME struct { 171 | LStructSize uint32 172 | HwndOwner HWND 173 | HInstance HINSTANCE 174 | LpstrFilter *uint16 175 | LpstrCustomFilter *uint16 176 | NMaxCustFilter uint32 177 | NFilterIndex uint32 178 | LpstrFile *uint16 179 | NMaxFile uint32 180 | LpstrFileTitle *uint16 181 | NMaxFileTitle uint32 182 | LpstrInitialDir *uint16 183 | LpstrTitle *uint16 184 | Flags uint32 185 | NFileOffset uint16 186 | NFileExtension uint16 187 | LpstrDefExt *uint16 188 | LCustData uintptr 189 | LpfnHook LPOFNHOOKPROC 190 | LpTemplateName *uint16 191 | PvReserved unsafe.Pointer 192 | DwReserved uint32 193 | FlagsEx uint32 194 | } 195 | 196 | type PRINTPAGERANGE struct { 197 | NFromPage uint32 198 | NToPage uint32 199 | } 200 | 201 | type DEVNAMES struct { 202 | WDriverOffset uint16 203 | WDeviceOffset uint16 204 | WOutputOffset uint16 205 | WDefault uint16 206 | } 207 | 208 | type PRINTDLGEX struct { 209 | LStructSize uint32 210 | HwndOwner HWND 211 | HDevMode HGLOBAL 212 | HDevNames HGLOBAL 213 | HDC HDC 214 | Flags uint32 215 | Flags2 uint32 216 | ExclusionFlags uint32 217 | NPageRanges uint32 218 | NMaxPageRanges uint32 219 | LpPageRanges *PRINTPAGERANGE 220 | NMinPage uint32 221 | NMaxPage uint32 222 | NCopies uint32 223 | HInstance HINSTANCE 224 | LpPrintTemplateName *uint16 225 | LpCallback LPUNKNOWN 226 | NPropertyPages uint32 227 | LphPropertyPages *HPROPSHEETPAGE 228 | NStartPage uint32 229 | DwResultAction uint32 230 | } 231 | 232 | var ( 233 | // Library 234 | libcomdlg32 uintptr 235 | 236 | // Functions 237 | chooseColor uintptr 238 | commDlgExtendedError uintptr 239 | getOpenFileName uintptr 240 | getSaveFileName uintptr 241 | printDlgEx uintptr 242 | ) 243 | 244 | func init() { 245 | // Library 246 | libcomdlg32 = MustLoadLibrary("comdlg32.dll") 247 | 248 | // Functions 249 | chooseColor = MustGetProcAddress(libcomdlg32, "ChooseColorW") 250 | commDlgExtendedError = MustGetProcAddress(libcomdlg32, "CommDlgExtendedError") 251 | getOpenFileName = MustGetProcAddress(libcomdlg32, "GetOpenFileNameW") 252 | getSaveFileName = MustGetProcAddress(libcomdlg32, "GetSaveFileNameW") 253 | printDlgEx = MustGetProcAddress(libcomdlg32, "PrintDlgExW") 254 | } 255 | 256 | func ChooseColor(lpcc *CHOOSECOLOR) bool { 257 | ret, _, _ := syscall.Syscall(chooseColor, 1, 258 | uintptr(unsafe.Pointer(lpcc)), 259 | 0, 260 | 0) 261 | 262 | return ret != 0 263 | } 264 | 265 | func CommDlgExtendedError() uint32 { 266 | ret, _, _ := syscall.Syscall(commDlgExtendedError, 0, 267 | 0, 268 | 0, 269 | 0) 270 | 271 | return uint32(ret) 272 | } 273 | 274 | func GetOpenFileName(lpofn *OPENFILENAME) bool { 275 | ret, _, _ := syscall.Syscall(getOpenFileName, 1, 276 | uintptr(unsafe.Pointer(lpofn)), 277 | 0, 278 | 0) 279 | 280 | return ret != 0 281 | } 282 | 283 | func GetSaveFileName(lpofn *OPENFILENAME) bool { 284 | ret, _, _ := syscall.Syscall(getSaveFileName, 1, 285 | uintptr(unsafe.Pointer(lpofn)), 286 | 0, 287 | 0) 288 | 289 | return ret != 0 290 | } 291 | 292 | func PrintDlgEx(lppd *PRINTDLGEX) HRESULT { 293 | ret, _, _ := syscall.Syscall(printDlgEx, 1, 294 | uintptr(unsafe.Pointer(lppd)), 295 | 0, 296 | 0) 297 | 298 | return HRESULT(ret) 299 | } 300 | -------------------------------------------------------------------------------- /vendor/github.com/ssoor/winapi/datetimepicker.go: -------------------------------------------------------------------------------- 1 | // Copyright 2011 The win Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // +build windows 6 | 7 | package winapi 8 | 9 | const DTM_FIRST = 0x1000 10 | const DTN_FIRST = ^uint32(739) // -740 11 | const DTN_FIRST2 = ^uint32(752) // -753 12 | 13 | const ( 14 | GDTR_MIN = 0x0001 15 | GDTR_MAX = 0x0002 16 | ) 17 | 18 | const ( 19 | GDT_ERROR = -1 20 | GDT_VALID = 0 21 | GDT_NONE = 1 22 | ) 23 | 24 | // Messages 25 | const ( 26 | DTM_GETSYSTEMTIME = DTM_FIRST + 1 27 | DTM_SETSYSTEMTIME = DTM_FIRST + 2 28 | DTM_GETRANGE = DTM_FIRST + 3 29 | DTM_SETRANGE = DTM_FIRST + 4 30 | DTM_SETFORMAT = DTM_FIRST + 50 31 | DTM_SETMCCOLOR = DTM_FIRST + 6 32 | DTM_GETMCCOLOR = DTM_FIRST + 7 33 | DTM_GETMONTHCAL = DTM_FIRST + 8 34 | DTM_SETMCFONT = DTM_FIRST + 9 35 | DTM_GETMCFONT = DTM_FIRST + 10 36 | ) 37 | 38 | // Styles 39 | const ( 40 | DTS_UPDOWN = 0x0001 41 | DTS_SHOWNONE = 0x0002 42 | DTS_SHORTDATEFORMAT = 0x0000 43 | DTS_LONGDATEFORMAT = 0x0004 44 | DTS_SHORTDATECENTURYFORMAT = 0x000C 45 | DTS_TIMEFORMAT = 0x0009 46 | DTS_APPCANPARSE = 0x0010 47 | DTS_RIGHTALIGN = 0x0020 48 | ) 49 | 50 | // Notifications 51 | const ( 52 | DTN_DATETIMECHANGE = DTN_FIRST2 - 6 53 | DTN_USERSTRING = DTN_FIRST - 5 54 | DTN_WMKEYDOWN = DTN_FIRST - 4 55 | DTN_FORMAT = DTN_FIRST - 3 56 | DTN_FORMATQUERY = DTN_FIRST - 2 57 | DTN_DROPDOWN = DTN_FIRST2 - 1 58 | DTN_CLOSEUP = DTN_FIRST2 59 | ) 60 | 61 | // Structs 62 | type ( 63 | NMDATETIMECHANGE struct { 64 | Nmhdr NMHDR 65 | DwFlags uint32 66 | St SYSTEMTIME 67 | } 68 | 69 | NMDATETIMESTRING struct { 70 | Nmhdr NMHDR 71 | PszUserString *uint16 72 | St SYSTEMTIME 73 | DwFlags uint32 74 | } 75 | 76 | NMDATETIMEWMKEYDOWN struct { 77 | Nmhdr NMHDR 78 | NVirtKey int 79 | PszFormat *uint16 80 | St SYSTEMTIME 81 | } 82 | 83 | NMDATETIMEFORMAT struct { 84 | Nmhdr NMHDR 85 | PszFormat *uint16 86 | St SYSTEMTIME 87 | PszDisplay *uint16 88 | SzDisplay [64]uint16 89 | } 90 | 91 | NMDATETIMEFORMATQUERY struct { 92 | Nmhdr NMHDR 93 | PszFormat *uint16 94 | SzMax SIZE 95 | } 96 | ) 97 | -------------------------------------------------------------------------------- /vendor/github.com/ssoor/winapi/edit.go: -------------------------------------------------------------------------------- 1 | // Copyright 2010 The win Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // +build windows 6 | 7 | package winapi 8 | 9 | // Edit styles 10 | const ( 11 | ES_LEFT = 0x0000 12 | ES_CENTER = 0x0001 13 | ES_RIGHT = 0x0002 14 | ES_MULTILINE = 0x0004 15 | ES_UPPERCASE = 0x0008 16 | ES_LOWERCASE = 0x0010 17 | ES_PASSWORD = 0x0020 18 | ES_AUTOVSCROLL = 0x0040 19 | ES_AUTOHSCROLL = 0x0080 20 | ES_NOHIDESEL = 0x0100 21 | ES_OEMCONVERT = 0x0400 22 | ES_READONLY = 0x0800 23 | ES_WANTRETURN = 0x1000 24 | ES_NUMBER = 0x2000 25 | ) 26 | 27 | // Edit notifications 28 | const ( 29 | EN_SETFOCUS = 0x0100 30 | EN_KILLFOCUS = 0x0200 31 | EN_CHANGE = 0x0300 32 | EN_UPDATE = 0x0400 33 | EN_ERRSPACE = 0x0500 34 | EN_MAXTEXT = 0x0501 35 | EN_HSCROLL = 0x0601 36 | EN_VSCROLL = 0x0602 37 | EN_ALIGN_LTR_EC = 0x0700 38 | EN_ALIGN_RTL_EC = 0x0701 39 | ) 40 | 41 | // Edit messages 42 | const ( 43 | EM_GETSEL = 0x00B0 44 | EM_SETSEL = 0x00B1 45 | EM_GETRECT = 0x00B2 46 | EM_SETRECT = 0x00B3 47 | EM_SETRECTNP = 0x00B4 48 | EM_SCROLL = 0x00B5 49 | EM_LINESCROLL = 0x00B6 50 | EM_SCROLLCARET = 0x00B7 51 | EM_GETMODIFY = 0x00B8 52 | EM_SETMODIFY = 0x00B9 53 | EM_GETLINECOUNT = 0x00BA 54 | EM_LINEINDEX = 0x00BB 55 | EM_SETHANDLE = 0x00BC 56 | EM_GETHANDLE = 0x00BD 57 | EM_GETTHUMB = 0x00BE 58 | EM_LINELENGTH = 0x00C1 59 | EM_REPLACESEL = 0x00C2 60 | EM_GETLINE = 0x00C4 61 | EM_LIMITTEXT = 0x00C5 62 | EM_CANUNDO = 0x00C6 63 | EM_UNDO = 0x00C7 64 | EM_FMTLINES = 0x00C8 65 | EM_LINEFROMCHAR = 0x00C9 66 | EM_SETTABSTOPS = 0x00CB 67 | EM_SETPASSWORDCHAR = 0x00CC 68 | EM_EMPTYUNDOBUFFER = 0x00CD 69 | EM_GETFIRSTVISIBLELINE = 0x00CE 70 | EM_SETREADONLY = 0x00CF 71 | EM_SETWORDBREAKPROC = 0x00D0 72 | EM_GETWORDBREAKPROC = 0x00D1 73 | EM_GETPASSWORDCHAR = 0x00D2 74 | EM_SETMARGINS = 0x00D3 75 | EM_GETMARGINS = 0x00D4 76 | EM_SETLIMITTEXT = EM_LIMITTEXT 77 | EM_GETLIMITTEXT = 0x00D5 78 | EM_POSFROMCHAR = 0x00D6 79 | EM_CHARFROMPOS = 0x00D7 80 | EM_SETIMESTATUS = 0x00D8 81 | EM_GETIMESTATUS = 0x00D9 82 | EM_SETCUEBANNER = 0x1501 83 | EM_GETCUEBANNER = 0x1502 84 | ) 85 | -------------------------------------------------------------------------------- /vendor/github.com/ssoor/winapi/gdiplus.go: -------------------------------------------------------------------------------- 1 | // Copyright 2010 The win Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // +build windows 6 | 7 | package winapi 8 | 9 | import ( 10 | "syscall" 11 | "unsafe" 12 | ) 13 | 14 | type GpStatus int32 15 | 16 | const ( 17 | Ok GpStatus = 0 18 | GenericError GpStatus = 1 19 | InvalidParameter GpStatus = 2 20 | OutOfMemory GpStatus = 3 21 | ObjectBusy GpStatus = 4 22 | InsufficientBuffer GpStatus = 5 23 | NotImplemented GpStatus = 6 24 | Win32Error GpStatus = 7 25 | WrongState GpStatus = 8 26 | Aborted GpStatus = 9 27 | FileNotFound GpStatus = 10 28 | ValueOverflow GpStatus = 11 29 | AccessDenied GpStatus = 12 30 | UnknownImageFormat GpStatus = 13 31 | FontFamilyNotFound GpStatus = 14 32 | FontStyleNotFound GpStatus = 15 33 | NotTrueTypeFont GpStatus = 16 34 | UnsupportedGdiplusVersion GpStatus = 17 35 | GdiplusNotInitialized GpStatus = 18 36 | PropertyNotFound GpStatus = 19 37 | PropertyNotSupported GpStatus = 20 38 | ProfileNotFound GpStatus = 21 39 | ) 40 | 41 | func (s GpStatus) String() string { 42 | switch s { 43 | case Ok: 44 | return "Ok" 45 | 46 | case GenericError: 47 | return "GenericError" 48 | 49 | case InvalidParameter: 50 | return "InvalidParameter" 51 | 52 | case OutOfMemory: 53 | return "OutOfMemory" 54 | 55 | case ObjectBusy: 56 | return "ObjectBusy" 57 | 58 | case InsufficientBuffer: 59 | return "InsufficientBuffer" 60 | 61 | case NotImplemented: 62 | return "NotImplemented" 63 | 64 | case Win32Error: 65 | return "Win32Error" 66 | 67 | case WrongState: 68 | return "WrongState" 69 | 70 | case Aborted: 71 | return "Aborted" 72 | 73 | case FileNotFound: 74 | return "FileNotFound" 75 | 76 | case ValueOverflow: 77 | return "ValueOverflow" 78 | 79 | case AccessDenied: 80 | return "AccessDenied" 81 | 82 | case UnknownImageFormat: 83 | return "UnknownImageFormat" 84 | 85 | case FontFamilyNotFound: 86 | return "FontFamilyNotFound" 87 | 88 | case FontStyleNotFound: 89 | return "FontStyleNotFound" 90 | 91 | case NotTrueTypeFont: 92 | return "NotTrueTypeFont" 93 | 94 | case UnsupportedGdiplusVersion: 95 | return "UnsupportedGdiplusVersion" 96 | 97 | case GdiplusNotInitialized: 98 | return "GdiplusNotInitialized" 99 | 100 | case PropertyNotFound: 101 | return "PropertyNotFound" 102 | 103 | case PropertyNotSupported: 104 | return "PropertyNotSupported" 105 | 106 | case ProfileNotFound: 107 | return "ProfileNotFound" 108 | } 109 | 110 | return "Unknown Status Value" 111 | } 112 | 113 | type GdiplusStartupInput struct { 114 | GdiplusVersion uint32 115 | DebugEventCallback uintptr 116 | SuppressBackgroundThread BOOL 117 | SuppressExternalCodecs BOOL 118 | } 119 | 120 | type GdiplusStartupOutput struct { 121 | NotificationHook uintptr 122 | NotificationUnhook uintptr 123 | } 124 | 125 | type GpImage struct{} 126 | 127 | type GpBitmap GpImage 128 | 129 | type ARGB uint32 130 | 131 | var ( 132 | // Library 133 | libgdiplus uintptr 134 | 135 | // Functions 136 | gdipCreateBitmapFromFile uintptr 137 | gdipCreateBitmapFromHBITMAP uintptr 138 | gdipCreateHBITMAPFromBitmap uintptr 139 | gdipDisposeImage uintptr 140 | gdiplusShutdown uintptr 141 | gdiplusStartup uintptr 142 | ) 143 | 144 | var ( 145 | token uintptr 146 | ) 147 | 148 | func init() { 149 | // Library 150 | libgdiplus = MustLoadLibrary("gdiplus.dll") 151 | 152 | // Functions 153 | gdipCreateBitmapFromFile = MustGetProcAddress(libgdiplus, "GdipCreateBitmapFromFile") 154 | gdipCreateBitmapFromHBITMAP = MustGetProcAddress(libgdiplus, "GdipCreateBitmapFromHBITMAP") 155 | gdipCreateHBITMAPFromBitmap = MustGetProcAddress(libgdiplus, "GdipCreateHBITMAPFromBitmap") 156 | gdipDisposeImage = MustGetProcAddress(libgdiplus, "GdipDisposeImage") 157 | gdiplusShutdown = MustGetProcAddress(libgdiplus, "GdiplusShutdown") 158 | gdiplusStartup = MustGetProcAddress(libgdiplus, "GdiplusStartup") 159 | } 160 | 161 | func GdipCreateBitmapFromFile(filename *uint16, bitmap **GpBitmap) GpStatus { 162 | ret, _, _ := syscall.Syscall(gdipCreateBitmapFromFile, 2, 163 | uintptr(unsafe.Pointer(filename)), 164 | uintptr(unsafe.Pointer(bitmap)), 165 | 0) 166 | 167 | return GpStatus(ret) 168 | } 169 | 170 | func GdipCreateBitmapFromHBITMAP(hbm HBITMAP, hpal HPALETTE, bitmap **GpBitmap) GpStatus { 171 | ret, _, _ := syscall.Syscall(gdipCreateBitmapFromHBITMAP, 3, 172 | uintptr(hbm), 173 | uintptr(hpal), 174 | uintptr(unsafe.Pointer(bitmap))) 175 | 176 | return GpStatus(ret) 177 | } 178 | 179 | func GdipCreateHBITMAPFromBitmap(bitmap *GpBitmap, hbmReturn *HBITMAP, background ARGB) GpStatus { 180 | ret, _, _ := syscall.Syscall(gdipCreateHBITMAPFromBitmap, 3, 181 | uintptr(unsafe.Pointer(bitmap)), 182 | uintptr(unsafe.Pointer(hbmReturn)), 183 | uintptr(background)) 184 | 185 | return GpStatus(ret) 186 | } 187 | 188 | func GdipDisposeImage(image *GpImage) GpStatus { 189 | ret, _, _ := syscall.Syscall(gdipDisposeImage, 1, 190 | uintptr(unsafe.Pointer(image)), 191 | 0, 192 | 0) 193 | 194 | return GpStatus(ret) 195 | } 196 | 197 | func GdiplusShutdown() { 198 | syscall.Syscall(gdiplusShutdown, 1, 199 | token, 200 | 0, 201 | 0) 202 | } 203 | 204 | func GdiplusStartup(input *GdiplusStartupInput, output *GdiplusStartupOutput) GpStatus { 205 | ret, _, _ := syscall.Syscall(gdiplusStartup, 3, 206 | uintptr(unsafe.Pointer(&token)), 207 | uintptr(unsafe.Pointer(input)), 208 | uintptr(unsafe.Pointer(output))) 209 | 210 | return GpStatus(ret) 211 | } 212 | 213 | /*GdipSaveImageToFile(image *GpImage, filename *uint16, clsidEncoder *CLSID, encoderParams *EncoderParameters) GpStatus { 214 | ret, _, _ := syscall.Syscall6(gdipSaveImageToFile, 4, 215 | uintptr(unsafe.Pointer(image)), 216 | uintptr(unsafe.Pointer(filename)), 217 | uintptr(unsafe.Pointer(clsidEncoder)), 218 | uintptr(unsafe.Pointer(encoderParams)), 219 | 0, 220 | 0) 221 | 222 | return GpStatus(ret) 223 | }*/ 224 | -------------------------------------------------------------------------------- /vendor/github.com/ssoor/winapi/header.go: -------------------------------------------------------------------------------- 1 | // Copyright 2012 The win Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // +build windows 6 | 7 | package winapi 8 | 9 | const ( 10 | HDF_SORTDOWN = 0x200 11 | HDF_SORTUP = 0x400 12 | ) 13 | 14 | const ( 15 | HDI_FORMAT = 4 16 | ) 17 | 18 | const ( 19 | HDM_FIRST = 0x1200 20 | HDM_GETITEM = HDM_FIRST + 11 21 | HDM_SETITEM = HDM_FIRST + 12 22 | ) 23 | 24 | const ( 25 | HDS_NOSIZING = 0x0800 26 | ) 27 | 28 | type HDITEM struct { 29 | Mask uint32 30 | Cxy int32 31 | PszText *uint16 32 | Hbm HBITMAP 33 | CchTextMax int32 34 | Fmt int32 35 | LParam uintptr 36 | IImage int32 37 | IOrder int32 38 | Type uint32 39 | PvFilter uintptr 40 | } 41 | -------------------------------------------------------------------------------- /vendor/github.com/ssoor/winapi/kernel32.go: -------------------------------------------------------------------------------- 1 | // Copyright 2010 The win Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // +build windows 6 | 7 | package winapi 8 | 9 | import ( 10 | "syscall" 11 | "unsafe" 12 | ) 13 | 14 | const MAX_PATH = 260 15 | 16 | // Error codes 17 | const ( 18 | ERROR_SUCCESS = 0 19 | ERROR_INVALID_FUNCTION = 1 20 | ERROR_FILE_NOT_FOUND = 2 21 | ERROR_INVALID_PARAMETER = 87 22 | ERROR_INSUFFICIENT_BUFFER = 122 23 | ERROR_MORE_DATA = 234 24 | ) 25 | 26 | // GlobalAlloc flags 27 | const ( 28 | GHND = 0x0042 29 | GMEM_FIXED = 0x0000 30 | GMEM_MOVEABLE = 0x0002 31 | GMEM_ZEROINIT = 0x0040 32 | GPTR = 0x004 33 | ) 34 | 35 | // Predefined locale ids 36 | const ( 37 | LOCALE_CUSTOM_DEFAULT LCID = 0x0c00 38 | LOCALE_CUSTOM_UI_DEFAULT LCID = 0x1400 39 | LOCALE_CUSTOM_UNSPECIFIED LCID = 0x1000 40 | LOCALE_INVARIANT LCID = 0x007f 41 | LOCALE_USER_DEFAULT LCID = 0x0400 42 | LOCALE_SYSTEM_DEFAULT LCID = 0x0800 43 | ) 44 | 45 | // LCTYPE constants 46 | const ( 47 | LOCALE_SDECIMAL LCTYPE = 14 48 | LOCALE_STHOUSAND LCTYPE = 15 49 | LOCALE_SISO3166CTRYNAME LCTYPE = 0x5a 50 | LOCALE_SISO3166CTRYNAME2 LCTYPE = 0x68 51 | LOCALE_SISO639LANGNAME LCTYPE = 0x59 52 | LOCALE_SISO639LANGNAME2 LCTYPE = 0x67 53 | ) 54 | 55 | var ( 56 | // Library 57 | libkernel32 uintptr 58 | 59 | // Functions 60 | closeHandle uintptr 61 | fileTimeToSystemTime uintptr 62 | getConsoleTitle uintptr 63 | getConsoleWindow uintptr 64 | getLastError uintptr 65 | getLocaleInfo uintptr 66 | getLogicalDriveStrings uintptr 67 | getModuleHandle uintptr 68 | getNumberFormat uintptr 69 | getThreadLocale uintptr 70 | getThreadUILanguage uintptr 71 | getVersion uintptr 72 | globalAlloc uintptr 73 | globalFree uintptr 74 | globalLock uintptr 75 | globalUnlock uintptr 76 | moveMemory uintptr 77 | mulDiv uintptr 78 | setLastError uintptr 79 | systemTimeToFileTime uintptr 80 | getProfileString uintptr 81 | globalMemoryStatusEx uintptr 82 | setStdHandle uintptr 83 | ) 84 | 85 | type ( 86 | ATOM uint16 87 | HANDLE uintptr 88 | HGLOBAL HANDLE 89 | HINSTANCE HANDLE 90 | LCID uint32 91 | LCTYPE uint32 92 | LANGID uint16 93 | ) 94 | 95 | type FILETIME struct { 96 | DwLowDateTime uint32 97 | DwHighDateTime uint32 98 | } 99 | 100 | type NUMBERFMT struct { 101 | NumDigits uint32 102 | LeadingZero uint32 103 | Grouping uint32 104 | LpDecimalSep *uint16 105 | LpThousandSep *uint16 106 | NegativeOrder uint32 107 | } 108 | 109 | type SYSTEMTIME struct { 110 | WYear uint16 111 | WMonth uint16 112 | WDayOfWeek uint16 113 | WDay uint16 114 | WHour uint16 115 | WMinute uint16 116 | WSecond uint16 117 | WMilliseconds uint16 118 | } 119 | type MEMORYSTATUSEX struct { 120 | Length uint32 121 | MemoryLoad uint32 122 | TotalPhys uint64 123 | AvailPhys uint64 124 | TotalPageFile uint64 125 | AvailPageFile uint64 126 | TotalVirtual uint64 127 | AvailVirtual uint64 128 | AvailExtendedVirtual uint64 129 | } 130 | 131 | func init() { 132 | // Library 133 | libkernel32 = MustLoadLibrary("kernel32.dll") 134 | 135 | // Functions 136 | closeHandle = MustGetProcAddress(libkernel32, "CloseHandle") 137 | fileTimeToSystemTime = MustGetProcAddress(libkernel32, "FileTimeToSystemTime") 138 | getConsoleTitle = MustGetProcAddress(libkernel32, "GetConsoleTitleW") 139 | getConsoleWindow = MustGetProcAddress(libkernel32, "GetConsoleWindow") 140 | getLastError = MustGetProcAddress(libkernel32, "GetLastError") 141 | getLocaleInfo = MustGetProcAddress(libkernel32, "GetLocaleInfoW") 142 | getLogicalDriveStrings = MustGetProcAddress(libkernel32, "GetLogicalDriveStringsW") 143 | getModuleHandle = MustGetProcAddress(libkernel32, "GetModuleHandleW") 144 | getNumberFormat = MustGetProcAddress(libkernel32, "GetNumberFormatW") 145 | getProfileString = MustGetProcAddress(libkernel32, "GetProfileStringW") 146 | getThreadLocale = MustGetProcAddress(libkernel32, "GetThreadLocale") 147 | getThreadUILanguage, _ = syscall.GetProcAddress(syscall.Handle(libkernel32), "GetThreadUILanguage") 148 | getVersion = MustGetProcAddress(libkernel32, "GetVersion") 149 | globalAlloc = MustGetProcAddress(libkernel32, "GlobalAlloc") 150 | globalFree = MustGetProcAddress(libkernel32, "GlobalFree") 151 | globalLock = MustGetProcAddress(libkernel32, "GlobalLock") 152 | globalUnlock = MustGetProcAddress(libkernel32, "GlobalUnlock") 153 | moveMemory = MustGetProcAddress(libkernel32, "RtlMoveMemory") 154 | mulDiv = MustGetProcAddress(libkernel32, "MulDiv") 155 | setLastError = MustGetProcAddress(libkernel32, "SetLastError") 156 | systemTimeToFileTime = MustGetProcAddress(libkernel32, "SystemTimeToFileTime") 157 | globalMemoryStatusEx = MustGetProcAddress(libkernel32, "GlobalMemoryStatusEx") 158 | setStdHandle = MustGetProcAddress(libkernel32, "SetStdHandle") 159 | 160 | } 161 | 162 | func CloseHandle(hObject HANDLE) bool { 163 | ret, _, _ := syscall.Syscall(closeHandle, 1, 164 | uintptr(hObject), 165 | 0, 166 | 0) 167 | 168 | return ret != 0 169 | } 170 | 171 | func FileTimeToSystemTime(lpFileTime *FILETIME, lpSystemTime *SYSTEMTIME) bool { 172 | ret, _, _ := syscall.Syscall(fileTimeToSystemTime, 2, 173 | uintptr(unsafe.Pointer(lpFileTime)), 174 | uintptr(unsafe.Pointer(lpSystemTime)), 175 | 0) 176 | 177 | return ret != 0 178 | } 179 | 180 | func GetConsoleTitle(lpConsoleTitle *uint16, nSize uint32) uint32 { 181 | ret, _, _ := syscall.Syscall(getConsoleTitle, 2, 182 | uintptr(unsafe.Pointer(lpConsoleTitle)), 183 | uintptr(nSize), 184 | 0) 185 | 186 | return uint32(ret) 187 | } 188 | 189 | func GetConsoleWindow() HWND { 190 | ret, _, _ := syscall.Syscall(getConsoleWindow, 0, 191 | 0, 192 | 0, 193 | 0) 194 | 195 | return HWND(ret) 196 | } 197 | 198 | func GetLastError() uint32 { 199 | ret, _, _ := syscall.Syscall(getLastError, 0, 200 | 0, 201 | 0, 202 | 0) 203 | 204 | return uint32(ret) 205 | } 206 | 207 | func GetLocaleInfo(Locale LCID, LCType LCTYPE, lpLCData *uint16, cchData int32) int32 { 208 | ret, _, _ := syscall.Syscall6(getLocaleInfo, 4, 209 | uintptr(Locale), 210 | uintptr(LCType), 211 | uintptr(unsafe.Pointer(lpLCData)), 212 | uintptr(cchData), 213 | 0, 214 | 0) 215 | 216 | return int32(ret) 217 | } 218 | 219 | func GetLogicalDriveStrings(nBufferLength uint32, lpBuffer *uint16) uint32 { 220 | ret, _, _ := syscall.Syscall(getLogicalDriveStrings, 2, 221 | uintptr(nBufferLength), 222 | uintptr(unsafe.Pointer(lpBuffer)), 223 | 0) 224 | 225 | return uint32(ret) 226 | } 227 | 228 | func GetModuleHandle(lpModuleName *uint16) HINSTANCE { 229 | ret, _, _ := syscall.Syscall(getModuleHandle, 1, 230 | uintptr(unsafe.Pointer(lpModuleName)), 231 | 0, 232 | 0) 233 | 234 | return HINSTANCE(ret) 235 | } 236 | 237 | func GetNumberFormat(Locale LCID, dwFlags uint32, lpValue *uint16, lpFormat *NUMBERFMT, lpNumberStr *uint16, cchNumber int32) int32 { 238 | ret, _, _ := syscall.Syscall6(getNumberFormat, 6, 239 | uintptr(Locale), 240 | uintptr(dwFlags), 241 | uintptr(unsafe.Pointer(lpValue)), 242 | uintptr(unsafe.Pointer(lpFormat)), 243 | uintptr(unsafe.Pointer(lpNumberStr)), 244 | uintptr(cchNumber)) 245 | 246 | return int32(ret) 247 | } 248 | 249 | func GetProfileString(lpAppName, lpKeyName, lpDefault *uint16, lpReturnedString uintptr, nSize uint32) bool { 250 | ret, _, _ := syscall.Syscall6(getProfileString, 5, 251 | uintptr(unsafe.Pointer(lpAppName)), 252 | uintptr(unsafe.Pointer(lpKeyName)), 253 | uintptr(unsafe.Pointer(lpDefault)), 254 | lpReturnedString, 255 | uintptr(nSize), 256 | 0) 257 | return ret != 0 258 | } 259 | 260 | func GetThreadLocale() LCID { 261 | ret, _, _ := syscall.Syscall(getThreadLocale, 0, 262 | 0, 263 | 0, 264 | 0) 265 | 266 | return LCID(ret) 267 | } 268 | 269 | func GetThreadUILanguage() LANGID { 270 | if getThreadUILanguage == 0 { 271 | return 0 272 | } 273 | 274 | ret, _, _ := syscall.Syscall(getThreadUILanguage, 0, 275 | 0, 276 | 0, 277 | 0) 278 | 279 | return LANGID(ret) 280 | } 281 | 282 | func GetVersion() int64 { 283 | ret, _, _ := syscall.Syscall(getVersion, 0, 284 | 0, 285 | 0, 286 | 0) 287 | return int64(ret) 288 | } 289 | 290 | func GlobalAlloc(uFlags uint32, dwBytes uintptr) HGLOBAL { 291 | ret, _, _ := syscall.Syscall(globalAlloc, 2, 292 | uintptr(uFlags), 293 | dwBytes, 294 | 0) 295 | 296 | return HGLOBAL(ret) 297 | } 298 | 299 | func GlobalFree(hMem HGLOBAL) HGLOBAL { 300 | ret, _, _ := syscall.Syscall(globalFree, 1, 301 | uintptr(hMem), 302 | 0, 303 | 0) 304 | 305 | return HGLOBAL(ret) 306 | } 307 | 308 | func GlobalLock(hMem HGLOBAL) unsafe.Pointer { 309 | ret, _, _ := syscall.Syscall(globalLock, 1, 310 | uintptr(hMem), 311 | 0, 312 | 0) 313 | 314 | return unsafe.Pointer(ret) 315 | } 316 | 317 | func GlobalUnlock(hMem HGLOBAL) bool { 318 | ret, _, _ := syscall.Syscall(globalUnlock, 1, 319 | uintptr(hMem), 320 | 0, 321 | 0) 322 | 323 | return ret != 0 324 | } 325 | 326 | func MoveMemory(destination, source unsafe.Pointer, length uintptr) { 327 | syscall.Syscall(moveMemory, 3, 328 | uintptr(unsafe.Pointer(destination)), 329 | uintptr(source), 330 | uintptr(length)) 331 | } 332 | 333 | func MulDiv(nNumber, nNumerator, nDenominator int32) int32 { 334 | ret, _, _ := syscall.Syscall(mulDiv, 3, 335 | uintptr(nNumber), 336 | uintptr(nNumerator), 337 | uintptr(nDenominator)) 338 | 339 | return int32(ret) 340 | } 341 | 342 | func SetLastError(dwErrorCode uint32) { 343 | syscall.Syscall(setLastError, 1, 344 | uintptr(dwErrorCode), 345 | 0, 346 | 0) 347 | } 348 | 349 | func SystemTimeToFileTime(lpSystemTime *SYSTEMTIME, lpFileTime *FILETIME) bool { 350 | ret, _, _ := syscall.Syscall(systemTimeToFileTime, 2, 351 | uintptr(unsafe.Pointer(lpSystemTime)), 352 | uintptr(unsafe.Pointer(lpFileTime)), 353 | 0) 354 | 355 | return ret != 0 356 | } 357 | 358 | func GlobalMemoryStatusEx(lpBuffer *MEMORYSTATUSEX) bool { 359 | ret, _, _ := syscall.Syscall(globalMemoryStatusEx, 1, 360 | uintptr(unsafe.Pointer(lpBuffer)), 361 | 0, 0) 362 | 363 | return ret != 0 364 | } 365 | 366 | func SetStdHandle(stdhandle int32, handle HANDLE) bool { 367 | ret, _, _ := syscall.Syscall(setStdHandle, 2, 368 | uintptr(stdhandle), uintptr(handle), 369 | 0) 370 | 371 | return ret != 0 372 | } 373 | -------------------------------------------------------------------------------- /vendor/github.com/ssoor/winapi/listbox.go: -------------------------------------------------------------------------------- 1 | // Copyright 2012 The win Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // +build windows 6 | 7 | package winapi 8 | 9 | // ListBox style 10 | const ( 11 | LBS_NOTIFY = 0x0001 12 | LBS_SORT = 0x0002 13 | LBS_NOREDRAW = 0x0004 14 | LBS_MULTIPLESEL = 0x0008 15 | LBS_OWNERDRAWFIXED = 0x0010 16 | LBS_OWNERDRAWVARIABLE = 0x0020 17 | LBS_HASSTRINGS = 0x0040 18 | LBS_USETABSTOPS = 0x0080 19 | LBS_NOINTEGRALHEIGHT = 0x0100 20 | LBS_MULTICOLUMN = 0x0200 21 | LBS_WANTKEYBOARDINPUT = 0x0400 22 | LBS_EXTENDEDSEL = 0x0800 23 | LBS_DISABLENOSCROLL = 0x1000 24 | LBS_NODATA = 0x2000 25 | LBS_NOSEL = 0x4000 26 | LBS_COMBOBOX = 0x8000 27 | LBS_STANDARD = LBS_NOTIFY | LBS_SORT | WS_BORDER | WS_VSCROLL 28 | ) 29 | 30 | // ListBox messages 31 | const ( 32 | LB_ADDSTRING = 0x0180 33 | LB_INSERTSTRING = 0x0181 34 | LB_DELETESTRING = 0x0182 35 | LB_SELITEMRANGEEX = 0x0183 36 | LB_RESETCONTENT = 0x0184 37 | LB_SETSEL = 0x0185 38 | LB_SETCURSEL = 0x0186 39 | LB_GETSEL = 0x0187 40 | LB_GETCURSEL = 0x0188 41 | LB_GETTEXT = 0x0189 42 | LB_GETTEXTLEN = 0x018A 43 | LB_GETCOUNT = 0x018B 44 | LB_SELECTSTRING = 0x018C 45 | LB_DIR = 0x018D 46 | LB_GETTOPINDEX = 0x018E 47 | LB_FINDSTRING = 0x018F 48 | LB_GETSELCOUNT = 0x0190 49 | LB_GETSELITEMS = 0x0191 50 | LB_SETTABSTOPS = 0x0192 51 | LB_GETHORIZONTALEXTENT = 0x0193 52 | LB_SETHORIZONTALEXTENT = 0x0194 53 | LB_SETCOLUMNWIDTH = 0x0195 54 | LB_ADDFILE = 0x0196 55 | LB_SETTOPINDEX = 0x0197 56 | LB_GETITEMRECT = 0x0198 57 | LB_GETITEMDATA = 0x0199 58 | LB_SETITEMDATA = 0x019A 59 | LB_SELITEMRANGE = 0x019B 60 | LB_SETANCHORINDEX = 0x019C 61 | LB_GETANCHORINDEX = 0x019D 62 | LB_SETCARETINDEX = 0x019E 63 | LB_GETCARETINDEX = 0x019F 64 | LB_SETITEMHEIGHT = 0x01A0 65 | LB_GETITEMHEIGHT = 0x01A1 66 | LB_FINDSTRINGEXACT = 0x01A2 67 | LB_SETLOCALE = 0x01A5 68 | LB_GETLOCALE = 0x01A6 69 | LB_SETCOUNT = 0x01A7 70 | LB_INITSTORAGE = 0x01A8 71 | LB_ITEMFROMPOINT = 0x01A9 72 | LB_MULTIPLEADDSTRING = 0x01B1 73 | ) 74 | 75 | //Listbox Notification Codes 76 | const ( 77 | LBN_ERRSPACE = -2 78 | LBN_SELCHANGE = 1 79 | LBN_DBLCLK = 2 80 | LBN_SELCANCEL = 3 81 | LBN_SETFOCUS = 4 82 | LBN_KILLFOCUS = 5 83 | ) 84 | const ( 85 | LB_ERR = -1 86 | LB_ERRSPACE = -2 87 | ) 88 | -------------------------------------------------------------------------------- /vendor/github.com/ssoor/winapi/menu.go: -------------------------------------------------------------------------------- 1 | // Copyright 2010 The win Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // +build windows 6 | 7 | package winapi 8 | 9 | // Constants for MENUITEMINFO.fMask 10 | const ( 11 | MIIM_STATE = 1 12 | MIIM_ID = 2 13 | MIIM_SUBMENU = 4 14 | MIIM_CHECKMARKS = 8 15 | MIIM_TYPE = 16 16 | MIIM_DATA = 32 17 | MIIM_STRING = 64 18 | MIIM_BITMAP = 128 19 | MIIM_FTYPE = 256 20 | ) 21 | 22 | // Constants for MENUITEMINFO.fType 23 | const ( 24 | MFT_BITMAP = 4 25 | MFT_MENUBARBREAK = 32 26 | MFT_MENUBREAK = 64 27 | MFT_OWNERDRAW = 256 28 | MFT_RADIOCHECK = 512 29 | MFT_RIGHTJUSTIFY = 0x4000 30 | MFT_SEPARATOR = 0x800 31 | MFT_RIGHTORDER = 0x2000 32 | MFT_STRING = 0 33 | ) 34 | 35 | // Constants for MENUITEMINFO.fState 36 | const ( 37 | MFS_CHECKED = 8 38 | MFS_DEFAULT = 4096 39 | MFS_DISABLED = 3 40 | MFS_ENABLED = 0 41 | MFS_GRAYED = 3 42 | MFS_HILITE = 128 43 | MFS_UNCHECKED = 0 44 | MFS_UNHILITE = 0 45 | ) 46 | 47 | // Constants for MENUITEMINFO.hbmp* 48 | const ( 49 | HBMMENU_CALLBACK = -1 50 | HBMMENU_SYSTEM = 1 51 | HBMMENU_MBAR_RESTORE = 2 52 | HBMMENU_MBAR_MINIMIZE = 3 53 | HBMMENU_MBAR_CLOSE = 5 54 | HBMMENU_MBAR_CLOSE_D = 6 55 | HBMMENU_MBAR_MINIMIZE_D = 7 56 | HBMMENU_POPUP_CLOSE = 8 57 | HBMMENU_POPUP_RESTORE = 9 58 | HBMMENU_POPUP_MAXIMIZE = 10 59 | HBMMENU_POPUP_MINIMIZE = 11 60 | ) 61 | 62 | // MENUINFO mask constants 63 | const ( 64 | MIM_APPLYTOSUBMENUS = 0x80000000 65 | MIM_BACKGROUND = 0x00000002 66 | MIM_HELPID = 0x00000004 67 | MIM_MAXHEIGHT = 0x00000001 68 | MIM_MENUDATA = 0x00000008 69 | MIM_STYLE = 0x00000010 70 | ) 71 | 72 | // MENUINFO style constants 73 | const ( 74 | MNS_AUTODISMISS = 0x10000000 75 | MNS_CHECKORBMP = 0x04000000 76 | MNS_DRAGDROP = 0x20000000 77 | MNS_MODELESS = 0x40000000 78 | MNS_NOCHECK = 0x80000000 79 | MNS_NOTIFYBYPOS = 0x08000000 80 | ) 81 | 82 | const ( 83 | MF_BYCOMMAND = 0x00000000 84 | MF_BYPOSITION = 0x00000400 85 | ) 86 | 87 | type MENUITEMINFO struct { 88 | CbSize uint32 89 | FMask uint32 90 | FType uint32 91 | FState uint32 92 | WID uint32 93 | HSubMenu HMENU 94 | HbmpChecked HBITMAP 95 | HbmpUnchecked HBITMAP 96 | DwItemData uintptr 97 | DwTypeData *uint16 98 | Cch uint32 99 | HbmpItem HBITMAP 100 | } 101 | 102 | type MENUINFO struct { 103 | CbSize uint32 104 | FMask uint32 105 | DwStyle uint32 106 | CyMax uint32 107 | HbrBack HBRUSH 108 | DwContextHelpID uint32 109 | DwMenuData uintptr 110 | } 111 | -------------------------------------------------------------------------------- /vendor/github.com/ssoor/winapi/oleaut32.go: -------------------------------------------------------------------------------- 1 | // Copyright 2010 The win Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // +build windows 6 | 7 | package winapi 8 | 9 | import ( 10 | "syscall" 11 | "unsafe" 12 | ) 13 | 14 | type DISPID int32 15 | 16 | const ( 17 | DISPID_BEFORENAVIGATE DISPID = 100 18 | DISPID_NAVIGATECOMPLETE DISPID = 101 19 | DISPID_STATUSTEXTCHANGE DISPID = 102 20 | DISPID_QUIT DISPID = 103 21 | DISPID_DOWNLOADCOMPLETE DISPID = 104 22 | DISPID_COMMANDSTATECHANGE DISPID = 105 23 | DISPID_DOWNLOADBEGIN DISPID = 106 24 | DISPID_NEWWINDOW DISPID = 107 25 | DISPID_PROGRESSCHANGE DISPID = 108 26 | DISPID_WINDOWMOVE DISPID = 109 27 | DISPID_WINDOWRESIZE DISPID = 110 28 | DISPID_WINDOWACTIVATE DISPID = 111 29 | DISPID_PROPERTYCHANGE DISPID = 112 30 | DISPID_TITLECHANGE DISPID = 113 31 | DISPID_TITLEICONCHANGE DISPID = 114 32 | DISPID_FRAMEBEFORENAVIGATE DISPID = 200 33 | DISPID_FRAMENAVIGATECOMPLETE DISPID = 201 34 | DISPID_FRAMENEWWINDOW DISPID = 204 35 | DISPID_BEFORENAVIGATE2 DISPID = 250 36 | DISPID_NEWWINDOW2 DISPID = 251 37 | DISPID_NAVIGATECOMPLETE2 DISPID = 252 38 | DISPID_ONQUIT DISPID = 253 39 | DISPID_ONVISIBLE DISPID = 254 40 | DISPID_ONTOOLBAR DISPID = 255 41 | DISPID_ONMENUBAR DISPID = 256 42 | DISPID_ONSTATUSBAR DISPID = 257 43 | DISPID_ONFULLSCREEN DISPID = 258 44 | DISPID_DOCUMENTCOMPLETE DISPID = 259 45 | DISPID_ONTHEATERMODE DISPID = 260 46 | DISPID_ONADDRESSBAR DISPID = 261 47 | DISPID_WINDOWSETRESIZABLE DISPID = 262 48 | DISPID_WINDOWCLOSING DISPID = 263 49 | DISPID_WINDOWSETLEFT DISPID = 264 50 | DISPID_WINDOWSETTOP DISPID = 265 51 | DISPID_WINDOWSETWIDTH DISPID = 266 52 | DISPID_WINDOWSETHEIGHT DISPID = 267 53 | DISPID_CLIENTTOHOSTWINDOW DISPID = 268 54 | DISPID_SETSECURELOCKICON DISPID = 269 55 | DISPID_FILEDOWNLOAD DISPID = 270 56 | DISPID_NAVIGATEERROR DISPID = 271 57 | DISPID_PRIVACYIMPACTEDSTATECHANGE DISPID = 272 58 | ) 59 | 60 | var ( 61 | IID_IDispatch = IID{0x00020400, 0x0000, 0x0000, [8]byte{0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46}} 62 | ) 63 | 64 | const ( 65 | DISP_E_MEMBERNOTFOUND = 0x80020003 66 | ) 67 | 68 | type VARTYPE uint16 69 | 70 | const ( 71 | VT_EMPTY VARTYPE = 0 72 | VT_NULL VARTYPE = 1 73 | VT_I2 VARTYPE = 2 74 | VT_I4 VARTYPE = 3 75 | VT_R4 VARTYPE = 4 76 | VT_R8 VARTYPE = 5 77 | VT_CY VARTYPE = 6 78 | VT_DATE VARTYPE = 7 79 | VT_BSTR VARTYPE = 8 80 | VT_DISPATCH VARTYPE = 9 81 | VT_ERROR VARTYPE = 10 82 | VT_BOOL VARTYPE = 11 83 | VT_VARIANT VARTYPE = 12 84 | VT_UNKNOWN VARTYPE = 13 85 | VT_DECIMAL VARTYPE = 14 86 | VT_I1 VARTYPE = 16 87 | VT_UI1 VARTYPE = 17 88 | VT_UI2 VARTYPE = 18 89 | VT_UI4 VARTYPE = 19 90 | VT_I8 VARTYPE = 20 91 | VT_UI8 VARTYPE = 21 92 | VT_INT VARTYPE = 22 93 | VT_UINT VARTYPE = 23 94 | VT_VOID VARTYPE = 24 95 | VT_HRESULT VARTYPE = 25 96 | VT_PTR VARTYPE = 26 97 | VT_SAFEARRAY VARTYPE = 27 98 | VT_CARRAY VARTYPE = 28 99 | VT_USERDEFINED VARTYPE = 29 100 | VT_LPSTR VARTYPE = 30 101 | VT_LPWSTR VARTYPE = 31 102 | VT_RECORD VARTYPE = 36 103 | VT_INT_PTR VARTYPE = 37 104 | VT_UINT_PTR VARTYPE = 38 105 | VT_FILETIME VARTYPE = 64 106 | VT_BLOB VARTYPE = 65 107 | VT_STREAM VARTYPE = 66 108 | VT_STORAGE VARTYPE = 67 109 | VT_STREAMED_OBJECT VARTYPE = 68 110 | VT_STORED_OBJECT VARTYPE = 69 111 | VT_BLOB_OBJECT VARTYPE = 70 112 | VT_CF VARTYPE = 71 113 | VT_CLSID VARTYPE = 72 114 | VT_VERSIONED_STREAM VARTYPE = 73 115 | VT_BSTR_BLOB VARTYPE = 0xfff 116 | VT_VECTOR VARTYPE = 0x1000 117 | VT_ARRAY VARTYPE = 0x2000 118 | VT_BYREF VARTYPE = 0x4000 119 | VT_RESERVED VARTYPE = 0x8000 120 | VT_ILLEGAL VARTYPE = 0xffff 121 | VT_ILLEGALMASKED VARTYPE = 0xfff 122 | VT_TYPEMASK VARTYPE = 0xfff 123 | ) 124 | 125 | type VARIANT struct { 126 | Vt VARTYPE 127 | reserved [14]byte 128 | } 129 | 130 | type VARIANTARG VARIANT 131 | 132 | type VARIANT_BOOL int16 133 | 134 | //type BSTR *uint16 135 | 136 | func StringToBSTR(value string) *uint16 /*BSTR*/ { 137 | // IMPORTANT: Don't forget to free the BSTR value when no longer needed! 138 | return SysAllocString(value) 139 | } 140 | 141 | func BSTRToString(value *uint16 /*BSTR*/) string { 142 | // ISSUE: Is this really ok? 143 | bstrArrPtr := (*[200000000]uint16)(unsafe.Pointer(value)) 144 | 145 | bstrSlice := make([]uint16, SysStringLen(value)) 146 | copy(bstrSlice, bstrArrPtr[:]) 147 | 148 | return syscall.UTF16ToString(bstrSlice) 149 | } 150 | 151 | type VAR_I4 struct { 152 | vt VARTYPE 153 | reserved1 [6]byte 154 | lVal int32 155 | reserved2 [4]byte 156 | } 157 | 158 | func IntToVariantI4(value int32) *VAR_I4 { 159 | return &VAR_I4{vt: VT_I4, lVal: value} 160 | } 161 | 162 | func VariantI4ToInt(value *VAR_I4) int32 { 163 | return value.lVal 164 | } 165 | 166 | type VAR_BOOL struct { 167 | vt VARTYPE 168 | reserved1 [6]byte 169 | boolVal VARIANT_BOOL 170 | reserved2 [6]byte 171 | } 172 | 173 | func BoolToVariantBool(value bool) *VAR_BOOL { 174 | return &VAR_BOOL{vt: VT_BOOL, boolVal: VARIANT_BOOL(BoolToBOOL(value))} 175 | } 176 | 177 | func VariantBoolToBool(value *VAR_BOOL) bool { 178 | return value.boolVal != 0 179 | } 180 | 181 | func StringToVariantBSTR(value string) *VAR_BSTR { 182 | // IMPORTANT: Don't forget to free the BSTR value when no longer needed! 183 | return &VAR_BSTR{vt: VT_BSTR, bstrVal: StringToBSTR(value)} 184 | } 185 | 186 | func VariantBSTRToString(value *VAR_BSTR) string { 187 | return BSTRToString(value.bstrVal) 188 | } 189 | 190 | type DISPPARAMS struct { 191 | Rgvarg *VARIANTARG 192 | RgdispidNamedArgs *DISPID 193 | CArgs int32 194 | CNamedArgs int32 195 | } 196 | 197 | var ( 198 | // Library 199 | liboleaut32 uintptr 200 | 201 | // Functions 202 | sysAllocString uintptr 203 | sysFreeString uintptr 204 | sysStringLen uintptr 205 | ) 206 | 207 | func init() { 208 | // Library 209 | liboleaut32 = MustLoadLibrary("oleaut32.dll") 210 | 211 | // Functions 212 | sysAllocString = MustGetProcAddress(liboleaut32, "SysAllocString") 213 | sysFreeString = MustGetProcAddress(liboleaut32, "SysFreeString") 214 | sysStringLen = MustGetProcAddress(liboleaut32, "SysStringLen") 215 | } 216 | 217 | func SysAllocString(s string) *uint16 /*BSTR*/ { 218 | ret, _, _ := syscall.Syscall(sysAllocString, 1, 219 | uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(s))), 220 | 0, 221 | 0) 222 | 223 | return (*uint16) /*BSTR*/ (unsafe.Pointer(ret)) 224 | } 225 | 226 | func SysFreeString(bstr *uint16 /*BSTR*/) { 227 | syscall.Syscall(sysFreeString, 1, 228 | uintptr(unsafe.Pointer(bstr)), 229 | 0, 230 | 0) 231 | } 232 | 233 | func SysStringLen(bstr *uint16 /*BSTR*/) uint32 { 234 | ret, _, _ := syscall.Syscall(sysStringLen, 1, 235 | uintptr(unsafe.Pointer(bstr)), 236 | 0, 237 | 0) 238 | 239 | return uint32(ret) 240 | } 241 | -------------------------------------------------------------------------------- /vendor/github.com/ssoor/winapi/oleaut32_386.go: -------------------------------------------------------------------------------- 1 | // Copyright 2012 The win Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package winapi 6 | 7 | type VAR_BSTR struct { 8 | vt VARTYPE 9 | reserved1 [6]byte 10 | bstrVal *uint16 /*BSTR*/ 11 | reserved2 [4]byte 12 | } 13 | -------------------------------------------------------------------------------- /vendor/github.com/ssoor/winapi/oleaut32_amd64.go: -------------------------------------------------------------------------------- 1 | // Copyright 2012 The win Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // +build windows 6 | 7 | package winapi 8 | 9 | type VAR_BSTR struct { 10 | vt VARTYPE 11 | reserved1 [6]byte 12 | bstrVal *uint16 /*BSTR*/ 13 | } 14 | -------------------------------------------------------------------------------- /vendor/github.com/ssoor/winapi/opengl32.go: -------------------------------------------------------------------------------- 1 | // Copyright 2011 The win Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // +build windows 6 | 7 | package winapi 8 | 9 | import ( 10 | "syscall" 11 | "unsafe" 12 | ) 13 | 14 | // for second parameter of WglSwapLayerBuffers 15 | const ( 16 | WGL_SWAP_MAIN_PLANE = (1 << 0) 17 | WGL_SWAP_OVERLAY1 = (1 << 1) 18 | WGL_SWAP_OVERLAY2 = (1 << 2) 19 | WGL_SWAP_OVERLAY3 = (1 << 3) 20 | WGL_SWAP_OVERLAY4 = (1 << 4) 21 | WGL_SWAP_OVERLAY5 = (1 << 5) 22 | WGL_SWAP_OVERLAY6 = (1 << 6) 23 | WGL_SWAP_OVERLAY7 = (1 << 7) 24 | WGL_SWAP_OVERLAY8 = (1 << 8) 25 | WGL_SWAP_OVERLAY9 = (1 << 9) 26 | WGL_SWAP_OVERLAY10 = (1 << 10) 27 | WGL_SWAP_OVERLAY11 = (1 << 11) 28 | WGL_SWAP_OVERLAY12 = (1 << 12) 29 | WGL_SWAP_OVERLAY13 = (1 << 13) 30 | WGL_SWAP_OVERLAY14 = (1 << 14) 31 | WGL_SWAP_OVERLAY15 = (1 << 15) 32 | WGL_SWAP_UNDERLAY1 = (1 << 16) 33 | WGL_SWAP_UNDERLAY2 = (1 << 17) 34 | WGL_SWAP_UNDERLAY3 = (1 << 18) 35 | WGL_SWAP_UNDERLAY4 = (1 << 19) 36 | WGL_SWAP_UNDERLAY5 = (1 << 20) 37 | WGL_SWAP_UNDERLAY6 = (1 << 21) 38 | WGL_SWAP_UNDERLAY7 = (1 << 22) 39 | WGL_SWAP_UNDERLAY8 = (1 << 23) 40 | WGL_SWAP_UNDERLAY9 = (1 << 24) 41 | WGL_SWAP_UNDERLAY10 = (1 << 25) 42 | WGL_SWAP_UNDERLAY11 = (1 << 26) 43 | WGL_SWAP_UNDERLAY12 = (1 << 27) 44 | WGL_SWAP_UNDERLAY13 = (1 << 28) 45 | WGL_SWAP_UNDERLAY14 = (1 << 29) 46 | WGL_SWAP_UNDERLAY15 = (1 << 30) 47 | ) 48 | 49 | type ( 50 | HGLRC HANDLE 51 | ) 52 | 53 | type LAYERPLANEDESCRIPTOR struct { 54 | NSize uint16 55 | NVersion uint16 56 | DwFlags uint32 57 | IPixelType uint8 58 | CColorBits uint8 59 | CRedBits uint8 60 | CRedShift uint8 61 | CGreenBits uint8 62 | CGreenShift uint8 63 | CBlueBits uint8 64 | CBlueShift uint8 65 | CAlphaBits uint8 66 | CAlphaShift uint8 67 | CAccumBits uint8 68 | CAccumRedBits uint8 69 | CAccumGreenBits uint8 70 | CAccumBlueBits uint8 71 | CAccumAlphaBits uint8 72 | CDepthBits uint8 73 | CStencilBits uint8 74 | CAuxBuffers uint8 75 | ILayerType uint8 76 | BReserved uint8 77 | CrTransparent COLORREF 78 | } 79 | 80 | type POINTFLOAT struct { 81 | X, Y float32 82 | } 83 | 84 | type GLYPHMETRICSFLOAT struct { 85 | GmfBlackBoxX float32 86 | GmfBlackBoxY float32 87 | GmfptGlyphOrigin POINTFLOAT 88 | GmfCellIncX float32 89 | GmfCellIncY float32 90 | } 91 | 92 | var ( 93 | // Library 94 | lib uintptr 95 | 96 | // Functions 97 | wglCopyContext uintptr 98 | wglCreateContext uintptr 99 | wglCreateLayerContext uintptr 100 | wglDeleteContext uintptr 101 | wglDescribeLayerPlane uintptr 102 | wglGetCurrentContext uintptr 103 | wglGetCurrentDC uintptr 104 | wglGetLayerPaletteEntries uintptr 105 | wglGetProcAddress uintptr 106 | wglMakeCurrent uintptr 107 | wglRealizeLayerPalette uintptr 108 | wglSetLayerPaletteEntries uintptr 109 | wglShareLists uintptr 110 | wglSwapLayerBuffers uintptr 111 | wglUseFontBitmaps uintptr 112 | wglUseFontOutlines uintptr 113 | ) 114 | 115 | func init() { 116 | // Library 117 | lib = MustLoadLibrary("opengl32.dll") 118 | 119 | // Functions 120 | wglCopyContext = MustGetProcAddress(lib, "wglCopyContext") 121 | wglCreateContext = MustGetProcAddress(lib, "wglCreateContext") 122 | wglCreateLayerContext = MustGetProcAddress(lib, "wglCreateLayerContext") 123 | wglDeleteContext = MustGetProcAddress(lib, "wglDeleteContext") 124 | wglDescribeLayerPlane = MustGetProcAddress(lib, "wglDescribeLayerPlane") 125 | wglGetCurrentContext = MustGetProcAddress(lib, "wglGetCurrentContext") 126 | wglGetCurrentDC = MustGetProcAddress(lib, "wglGetCurrentDC") 127 | wglGetLayerPaletteEntries = MustGetProcAddress(lib, "wglGetLayerPaletteEntries") 128 | wglGetProcAddress = MustGetProcAddress(lib, "wglGetProcAddress") 129 | wglMakeCurrent = MustGetProcAddress(lib, "wglMakeCurrent") 130 | wglRealizeLayerPalette = MustGetProcAddress(lib, "wglRealizeLayerPalette") 131 | wglSetLayerPaletteEntries = MustGetProcAddress(lib, "wglSetLayerPaletteEntries") 132 | wglShareLists = MustGetProcAddress(lib, "wglShareLists") 133 | wglSwapLayerBuffers = MustGetProcAddress(lib, "wglSwapLayerBuffers") 134 | wglUseFontBitmaps = MustGetProcAddress(lib, "wglUseFontBitmapsW") 135 | wglUseFontOutlines = MustGetProcAddress(lib, "wglUseFontOutlinesW") 136 | } 137 | 138 | func WglCopyContext(hglrcSrc, hglrcDst HGLRC, mask uint) bool { 139 | ret, _, _ := syscall.Syscall(wglCopyContext, 3, 140 | uintptr(hglrcSrc), 141 | uintptr(hglrcDst), 142 | uintptr(mask)) 143 | 144 | return ret != 0 145 | } 146 | 147 | func WglCreateContext(hdc HDC) HGLRC { 148 | ret, _, _ := syscall.Syscall(wglCreateContext, 1, 149 | uintptr(hdc), 150 | 0, 151 | 0) 152 | 153 | return HGLRC(ret) 154 | } 155 | 156 | func WglCreateLayerContext(hdc HDC, iLayerPlane int) HGLRC { 157 | ret, _, _ := syscall.Syscall(wglCreateLayerContext, 2, 158 | uintptr(hdc), 159 | uintptr(iLayerPlane), 160 | 0) 161 | 162 | return HGLRC(ret) 163 | } 164 | 165 | func WglDeleteContext(hglrc HGLRC) bool { 166 | ret, _, _ := syscall.Syscall(wglDeleteContext, 1, 167 | uintptr(hglrc), 168 | 0, 169 | 0) 170 | 171 | return ret != 0 172 | } 173 | 174 | func WglDescribeLayerPlane(hdc HDC, iPixelFormat, iLayerPlane int, nBytes uint8, plpd *LAYERPLANEDESCRIPTOR) bool { 175 | ret, _, _ := syscall.Syscall6(wglDescribeLayerPlane, 5, 176 | uintptr(hdc), 177 | uintptr(iPixelFormat), 178 | uintptr(iLayerPlane), 179 | uintptr(nBytes), 180 | uintptr(unsafe.Pointer(plpd)), 181 | 0) 182 | 183 | return ret != 0 184 | } 185 | 186 | func WglGetCurrentContext() HGLRC { 187 | ret, _, _ := syscall.Syscall(wglGetCurrentContext, 0, 188 | 0, 189 | 0, 190 | 0) 191 | 192 | return HGLRC(ret) 193 | } 194 | 195 | func WglGetCurrentDC() HDC { 196 | ret, _, _ := syscall.Syscall(wglGetCurrentDC, 0, 197 | 0, 198 | 0, 199 | 0) 200 | 201 | return HDC(ret) 202 | } 203 | 204 | func WglGetLayerPaletteEntries(hdc HDC, iLayerPlane, iStart, cEntries int, pcr *COLORREF) int { 205 | ret, _, _ := syscall.Syscall6(wglGetLayerPaletteEntries, 5, 206 | uintptr(hdc), 207 | uintptr(iLayerPlane), 208 | uintptr(iStart), 209 | uintptr(cEntries), 210 | uintptr(unsafe.Pointer(pcr)), 211 | 0) 212 | 213 | return int(ret) 214 | } 215 | 216 | func WglGetProcAddress(lpszProc *byte) uintptr { 217 | ret, _, _ := syscall.Syscall(wglGetProcAddress, 1, 218 | uintptr(unsafe.Pointer(lpszProc)), 219 | 0, 220 | 0) 221 | 222 | return uintptr(ret) 223 | } 224 | 225 | func WglMakeCurrent(hdc HDC, hglrc HGLRC) bool { 226 | ret, _, _ := syscall.Syscall(wglMakeCurrent, 2, 227 | uintptr(hdc), 228 | uintptr(hglrc), 229 | 0) 230 | 231 | return ret != 0 232 | } 233 | 234 | func WglRealizeLayerPalette(hdc HDC, iLayerPlane int, bRealize bool) bool { 235 | ret, _, _ := syscall.Syscall(wglRealizeLayerPalette, 3, 236 | uintptr(hdc), 237 | uintptr(iLayerPlane), 238 | uintptr(BoolToBOOL(bRealize))) 239 | 240 | return ret != 0 241 | } 242 | 243 | func WglSetLayerPaletteEntries(hdc HDC, iLayerPlane, iStart, cEntries int, pcr *COLORREF) int { 244 | ret, _, _ := syscall.Syscall6(wglSetLayerPaletteEntries, 5, 245 | uintptr(hdc), 246 | uintptr(iLayerPlane), 247 | uintptr(iStart), 248 | uintptr(cEntries), 249 | uintptr(unsafe.Pointer(pcr)), 250 | 0) 251 | 252 | return int(ret) 253 | } 254 | 255 | func WglShareLists(hglrc1, hglrc2 HGLRC) bool { 256 | ret, _, _ := syscall.Syscall(wglShareLists, 2, 257 | uintptr(hglrc1), 258 | uintptr(hglrc2), 259 | 0) 260 | 261 | return ret != 0 262 | } 263 | 264 | func WglSwapLayerBuffers(hdc HDC, fuPlanes uint) bool { 265 | ret, _, _ := syscall.Syscall(wglSwapLayerBuffers, 2, 266 | uintptr(hdc), 267 | uintptr(fuPlanes), 268 | 0) 269 | 270 | return ret != 0 271 | } 272 | 273 | func WglUseFontBitmaps(hdc HDC, first, count, listbase uint32) bool { 274 | ret, _, _ := syscall.Syscall6(wglUseFontBitmaps, 4, 275 | uintptr(hdc), 276 | uintptr(first), 277 | uintptr(count), 278 | uintptr(listbase), 279 | 0, 280 | 0) 281 | 282 | return ret != 0 283 | } 284 | 285 | func WglUseFontOutlines(hdc HDC, first, count, listbase uint32, deviation, extrusion float32, format int, pgmf *GLYPHMETRICSFLOAT) bool { 286 | ret, _, _ := syscall.Syscall12(wglUseFontBitmaps, 8, 287 | uintptr(hdc), 288 | uintptr(first), 289 | uintptr(count), 290 | uintptr(listbase), 291 | uintptr(deviation), 292 | uintptr(extrusion), 293 | uintptr(format), 294 | uintptr(unsafe.Pointer(pgmf)), 295 | 0, 296 | 0, 297 | 0, 298 | 0) 299 | 300 | return ret != 0 301 | } 302 | -------------------------------------------------------------------------------- /vendor/github.com/ssoor/winapi/shdocvw.go: -------------------------------------------------------------------------------- 1 | // Copyright 2010 The win Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // +build windows 6 | 7 | package winapi 8 | 9 | import ( 10 | "syscall" 11 | "unsafe" 12 | ) 13 | 14 | const ( 15 | DOCHOSTUIDBLCLK_DEFAULT = 0 16 | DOCHOSTUIDBLCLK_SHOWPROPERTIES = 1 17 | DOCHOSTUIDBLCLK_SHOWCODE = 2 18 | ) 19 | 20 | const ( 21 | DOCHOSTUIFLAG_DIALOG = 0x1 22 | DOCHOSTUIFLAG_DISABLE_HELP_MENU = 0x2 23 | DOCHOSTUIFLAG_NO3DBORDER = 0x4 24 | DOCHOSTUIFLAG_SCROLL_NO = 0x8 25 | DOCHOSTUIFLAG_DISABLE_SCRIPT_INACTIVE = 0x10 26 | DOCHOSTUIFLAG_OPENNEWWIN = 0x20 27 | DOCHOSTUIFLAG_DISABLE_OFFSCREEN = 0x40 28 | DOCHOSTUIFLAG_FLAT_SCROLLBAR = 0x80 29 | DOCHOSTUIFLAG_DIV_BLOCKDEFAULT = 0x100 30 | DOCHOSTUIFLAG_ACTIVATE_CLIENTHIT_ONLY = 0x200 31 | DOCHOSTUIFLAG_OVERRIDEBEHAVIORFACTORY = 0x400 32 | DOCHOSTUIFLAG_CODEPAGELINKEDFONTS = 0x800 33 | DOCHOSTUIFLAG_URL_ENCODING_DISABLE_UTF8 = 0x1000 34 | DOCHOSTUIFLAG_URL_ENCODING_ENABLE_UTF8 = 0x2000 35 | DOCHOSTUIFLAG_ENABLE_FORMS_AUTOCOMPLETE = 0x4000 36 | DOCHOSTUIFLAG_ENABLE_INPLACE_NAVIGATION = 0x10000 37 | DOCHOSTUIFLAG_IME_ENABLE_RECONVERSION = 0x20000 38 | DOCHOSTUIFLAG_THEME = 0x40000 39 | DOCHOSTUIFLAG_NOTHEME = 0x80000 40 | DOCHOSTUIFLAG_NOPICS = 0x100000 41 | DOCHOSTUIFLAG_NO3DOUTERBORDER = 0x200000 42 | DOCHOSTUIFLAG_DISABLE_EDIT_NS_FIXUP = 0x400000 43 | DOCHOSTUIFLAG_LOCAL_MACHINE_ACCESS_CHECK = 0x800000 44 | DOCHOSTUIFLAG_DISABLE_UNTRUSTEDPROTOCOL = 0x1000000 45 | ) 46 | 47 | // BrowserNavConstants 48 | const ( 49 | NavOpenInNewWindow = 0x1 50 | NavNoHistory = 0x2 51 | NavNoReadFromCache = 0x4 52 | NavNoWriteToCache = 0x8 53 | NavAllowAutosearch = 0x10 54 | NavBrowserBar = 0x20 55 | NavHyperlink = 0x40 56 | NavEnforceRestricted = 0x80 57 | NavNewWindowsManaged = 0x0100 58 | NavUntrustedForDownload = 0x0200 59 | NavTrustedForActiveX = 0x0400 60 | NavOpenInNewTab = 0x0800 61 | NavOpenInBackgroundTab = 0x1000 62 | NavKeepWordWheelText = 0x2000 63 | NavVirtualTab = 0x4000 64 | NavBlockRedirectsXDomain = 0x8000 65 | NavOpenNewForegroundTab = 0x10000 66 | ) 67 | 68 | var ( 69 | CLSID_WebBrowser = CLSID{0x8856F961, 0x340A, 0x11D0, [8]byte{0xA9, 0x6B, 0x00, 0xC0, 0x4F, 0xD7, 0x05, 0xA2}} 70 | DIID_DWebBrowserEvents2 = IID{0x34A715A0, 0x6587, 0x11D0, [8]byte{0x92, 0x4A, 0x00, 0x20, 0xAF, 0xC7, 0xAC, 0x4D}} 71 | IID_IWebBrowser2 = IID{0xD30C1661, 0xCDAF, 0x11D0, [8]byte{0x8A, 0x3E, 0x00, 0xC0, 0x4F, 0xC9, 0xE2, 0x6E}} 72 | IID_IDocHostUIHandler = IID{0xBD3F23C0, 0xD43E, 0x11CF, [8]byte{0x89, 0x3B, 0x00, 0xAA, 0x00, 0xBD, 0xCE, 0x1A}} 73 | ) 74 | 75 | type DWebBrowserEvents2Vtbl struct { 76 | QueryInterface uintptr 77 | AddRef uintptr 78 | Release uintptr 79 | GetTypeInfoCount uintptr 80 | GetTypeInfo uintptr 81 | GetIDsOfNames uintptr 82 | Invoke uintptr 83 | } 84 | 85 | type DWebBrowserEvents2 struct { 86 | LpVtbl *DWebBrowserEvents2Vtbl 87 | } 88 | 89 | type IWebBrowser2Vtbl struct { 90 | QueryInterface uintptr 91 | AddRef uintptr 92 | Release uintptr 93 | GetTypeInfoCount uintptr 94 | GetTypeInfo uintptr 95 | GetIDsOfNames uintptr 96 | Invoke uintptr 97 | GoBack uintptr 98 | GoForward uintptr 99 | GoHome uintptr 100 | GoSearch uintptr 101 | Navigate uintptr 102 | Refresh uintptr 103 | Refresh2 uintptr 104 | Stop uintptr 105 | Get_Application uintptr 106 | Get_Parent uintptr 107 | Get_Container uintptr 108 | Get_Document uintptr 109 | Get_TopLevelContainer uintptr 110 | Get_Type uintptr 111 | Get_Left uintptr 112 | Put_Left uintptr 113 | Get_Top uintptr 114 | Put_Top uintptr 115 | Get_Width uintptr 116 | Put_Width uintptr 117 | Get_Height uintptr 118 | Put_Height uintptr 119 | Get_LocationName uintptr 120 | Get_LocationURL uintptr 121 | Get_Busy uintptr 122 | Quit uintptr 123 | ClientToWindow uintptr 124 | PutProperty uintptr 125 | GetProperty uintptr 126 | Get_Name uintptr 127 | Get_HWND uintptr 128 | Get_FullName uintptr 129 | Get_Path uintptr 130 | Get_Visible uintptr 131 | Put_Visible uintptr 132 | Get_StatusBar uintptr 133 | Put_StatusBar uintptr 134 | Get_StatusText uintptr 135 | Put_StatusText uintptr 136 | Get_ToolBar uintptr 137 | Put_ToolBar uintptr 138 | Get_MenuBar uintptr 139 | Put_MenuBar uintptr 140 | Get_FullScreen uintptr 141 | Put_FullScreen uintptr 142 | Navigate2 uintptr 143 | QueryStatusWB uintptr 144 | ExecWB uintptr 145 | ShowBrowserBar uintptr 146 | Get_ReadyState uintptr 147 | Get_Offline uintptr 148 | Put_Offline uintptr 149 | Get_Silent uintptr 150 | Put_Silent uintptr 151 | Get_RegisterAsBrowser uintptr 152 | Put_RegisterAsBrowser uintptr 153 | Get_RegisterAsDropTarget uintptr 154 | Put_RegisterAsDropTarget uintptr 155 | Get_TheaterMode uintptr 156 | Put_TheaterMode uintptr 157 | Get_AddressBar uintptr 158 | Put_AddressBar uintptr 159 | Get_Resizable uintptr 160 | Put_Resizable uintptr 161 | } 162 | 163 | type IWebBrowser2 struct { 164 | LpVtbl *IWebBrowser2Vtbl 165 | } 166 | 167 | func (wb2 *IWebBrowser2) Release() HRESULT { 168 | ret, _, _ := syscall.Syscall(wb2.LpVtbl.Release, 1, 169 | uintptr(unsafe.Pointer(wb2)), 170 | 0, 171 | 0) 172 | 173 | return HRESULT(ret) 174 | } 175 | 176 | func (wb2 *IWebBrowser2) Refresh() HRESULT { 177 | ret, _, _ := syscall.Syscall(wb2.LpVtbl.Refresh, 1, 178 | uintptr(unsafe.Pointer(wb2)), 179 | 0, 180 | 0) 181 | 182 | return HRESULT(ret) 183 | } 184 | 185 | func (wb2 *IWebBrowser2) Put_Left(Left int32) HRESULT { 186 | ret, _, _ := syscall.Syscall(wb2.LpVtbl.Put_Left, 2, 187 | uintptr(unsafe.Pointer(wb2)), 188 | uintptr(Left), 189 | 0) 190 | 191 | return HRESULT(ret) 192 | } 193 | 194 | func (wb2 *IWebBrowser2) Put_Top(Top int32) HRESULT { 195 | ret, _, _ := syscall.Syscall(wb2.LpVtbl.Put_Top, 2, 196 | uintptr(unsafe.Pointer(wb2)), 197 | uintptr(Top), 198 | 0) 199 | 200 | return HRESULT(ret) 201 | } 202 | 203 | func (wb2 *IWebBrowser2) Put_Width(Width int32) HRESULT { 204 | ret, _, _ := syscall.Syscall(wb2.LpVtbl.Put_Width, 2, 205 | uintptr(unsafe.Pointer(wb2)), 206 | uintptr(Width), 207 | 0) 208 | 209 | return HRESULT(ret) 210 | } 211 | 212 | func (wb2 *IWebBrowser2) Put_Height(Height int32) HRESULT { 213 | ret, _, _ := syscall.Syscall(wb2.LpVtbl.Put_Height, 2, 214 | uintptr(unsafe.Pointer(wb2)), 215 | uintptr(Height), 216 | 0) 217 | 218 | return HRESULT(ret) 219 | } 220 | 221 | func (wb2 *IWebBrowser2) Get_LocationURL(pbstrLocationURL **uint16 /*BSTR*/) HRESULT { 222 | ret, _, _ := syscall.Syscall(wb2.LpVtbl.Get_LocationURL, 2, 223 | uintptr(unsafe.Pointer(wb2)), 224 | uintptr(unsafe.Pointer(pbstrLocationURL)), 225 | 0) 226 | 227 | return HRESULT(ret) 228 | } 229 | 230 | func (wb2 *IWebBrowser2) Navigate2(URL *VAR_BSTR, Flags *VAR_I4, TargetFrameName *VAR_BSTR, PostData unsafe.Pointer, Headers *VAR_BSTR) HRESULT { 231 | ret, _, _ := syscall.Syscall6(wb2.LpVtbl.Navigate2, 6, 232 | uintptr(unsafe.Pointer(wb2)), 233 | uintptr(unsafe.Pointer(URL)), 234 | uintptr(unsafe.Pointer(Flags)), 235 | uintptr(unsafe.Pointer(TargetFrameName)), 236 | uintptr(PostData), 237 | uintptr(unsafe.Pointer(Headers))) 238 | 239 | return HRESULT(ret) 240 | } 241 | 242 | type IDocHostUIHandlerVtbl struct { 243 | QueryInterface uintptr 244 | AddRef uintptr 245 | Release uintptr 246 | ShowContextMenu uintptr 247 | GetHostInfo uintptr 248 | ShowUI uintptr 249 | HideUI uintptr 250 | UpdateUI uintptr 251 | EnableModeless uintptr 252 | OnDocWindowActivate uintptr 253 | OnFrameWindowActivate uintptr 254 | ResizeBorder uintptr 255 | TranslateAccelerator uintptr 256 | GetOptionKeyPath uintptr 257 | GetDropTarget uintptr 258 | GetExternal uintptr 259 | TranslateUrl uintptr 260 | FilterDataObject uintptr 261 | } 262 | 263 | type IDocHostUIHandler struct { 264 | LpVtbl *IDocHostUIHandlerVtbl 265 | } 266 | 267 | type DOCHOSTUIINFO struct { 268 | CbSize uint32 269 | DwFlags uint32 270 | DwDoubleClick uint32 271 | PchHostCss *uint16 272 | PchHostNS *uint16 273 | } 274 | -------------------------------------------------------------------------------- /vendor/github.com/ssoor/winapi/shell32.go: -------------------------------------------------------------------------------- 1 | // Copyright 2010 The win Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // +build windows 6 | 7 | package winapi 8 | 9 | import ( 10 | "syscall" 11 | "unsafe" 12 | ) 13 | 14 | type CSIDL uint32 15 | type HDROP HANDLE 16 | 17 | const ( 18 | CSIDL_DESKTOP = 0x00 19 | CSIDL_INTERNET = 0x01 20 | CSIDL_PROGRAMS = 0x02 21 | CSIDL_CONTROLS = 0x03 22 | CSIDL_PRINTERS = 0x04 23 | CSIDL_PERSONAL = 0x05 24 | CSIDL_FAVORITES = 0x06 25 | CSIDL_STARTUP = 0x07 26 | CSIDL_RECENT = 0x08 27 | CSIDL_SENDTO = 0x09 28 | CSIDL_BITBUCKET = 0x0A 29 | CSIDL_STARTMENU = 0x0B 30 | CSIDL_MYDOCUMENTS = 0x0C 31 | CSIDL_MYMUSIC = 0x0D 32 | CSIDL_MYVIDEO = 0x0E 33 | CSIDL_DESKTOPDIRECTORY = 0x10 34 | CSIDL_DRIVES = 0x11 35 | CSIDL_NETWORK = 0x12 36 | CSIDL_NETHOOD = 0x13 37 | CSIDL_FONTS = 0x14 38 | CSIDL_TEMPLATES = 0x15 39 | CSIDL_COMMON_STARTMENU = 0x16 40 | CSIDL_COMMON_PROGRAMS = 0x17 41 | CSIDL_COMMON_STARTUP = 0x18 42 | CSIDL_COMMON_DESKTOPDIRECTORY = 0x19 43 | CSIDL_APPDATA = 0x1A 44 | CSIDL_PRINTHOOD = 0x1B 45 | CSIDL_LOCAL_APPDATA = 0x1C 46 | CSIDL_ALTSTARTUP = 0x1D 47 | CSIDL_COMMON_ALTSTARTUP = 0x1E 48 | CSIDL_COMMON_FAVORITES = 0x1F 49 | CSIDL_INTERNET_CACHE = 0x20 50 | CSIDL_COOKIES = 0x21 51 | CSIDL_HISTORY = 0x22 52 | CSIDL_COMMON_APPDATA = 0x23 53 | CSIDL_WINDOWS = 0x24 54 | CSIDL_SYSTEM = 0x25 55 | CSIDL_PROGRAM_FILES = 0x26 56 | CSIDL_MYPICTURES = 0x27 57 | CSIDL_PROFILE = 0x28 58 | CSIDL_SYSTEMX86 = 0x29 59 | CSIDL_PROGRAM_FILESX86 = 0x2A 60 | CSIDL_PROGRAM_FILES_COMMON = 0x2B 61 | CSIDL_PROGRAM_FILES_COMMONX86 = 0x2C 62 | CSIDL_COMMON_TEMPLATES = 0x2D 63 | CSIDL_COMMON_DOCUMENTS = 0x2E 64 | CSIDL_COMMON_ADMINTOOLS = 0x2F 65 | CSIDL_ADMINTOOLS = 0x30 66 | CSIDL_CONNECTIONS = 0x31 67 | CSIDL_COMMON_MUSIC = 0x35 68 | CSIDL_COMMON_PICTURES = 0x36 69 | CSIDL_COMMON_VIDEO = 0x37 70 | CSIDL_RESOURCES = 0x38 71 | CSIDL_RESOURCES_LOCALIZED = 0x39 72 | CSIDL_COMMON_OEM_LINKS = 0x3A 73 | CSIDL_CDBURN_AREA = 0x3B 74 | CSIDL_COMPUTERSNEARME = 0x3D 75 | CSIDL_FLAG_CREATE = 0x8000 76 | CSIDL_FLAG_DONT_VERIFY = 0x4000 77 | CSIDL_FLAG_NO_ALIAS = 0x1000 78 | CSIDL_FLAG_PER_USER_INIT = 0x8000 79 | CSIDL_FLAG_MASK = 0xFF00 80 | ) 81 | 82 | // NotifyIcon flags 83 | const ( 84 | NIF_MESSAGE = 0x00000001 85 | NIF_ICON = 0x00000002 86 | NIF_TIP = 0x00000004 87 | NIF_STATE = 0x00000008 88 | NIF_INFO = 0x00000010 89 | ) 90 | 91 | // NotifyIcon messages 92 | const ( 93 | NIM_ADD = 0x00000000 94 | NIM_MODIFY = 0x00000001 95 | NIM_DELETE = 0x00000002 96 | NIM_SETFOCUS = 0x00000003 97 | NIM_SETVERSION = 0x00000004 98 | ) 99 | 100 | // NotifyIcon states 101 | const ( 102 | NIS_HIDDEN = 0x00000001 103 | NIS_SHAREDICON = 0x00000002 104 | ) 105 | 106 | // NotifyIcon info flags 107 | const ( 108 | NIIF_NONE = 0x00000000 109 | NIIF_INFO = 0x00000001 110 | NIIF_WARNING = 0x00000002 111 | NIIF_ERROR = 0x00000003 112 | NIIF_USER = 0x00000004 113 | NIIF_NOSOUND = 0x00000010 114 | ) 115 | 116 | const NOTIFYICON_VERSION = 3 117 | 118 | // SHGetFileInfo flags 119 | const ( 120 | SHGFI_LARGEICON = 0x000000000 121 | SHGFI_SMALLICON = 0x000000001 122 | SHGFI_OPENICON = 0x000000002 123 | SHGFI_SHELLICONSIZE = 0x000000004 124 | SHGFI_PIDL = 0x000000008 125 | SHGFI_USEFILEATTRIBUTES = 0x000000010 126 | SHGFI_ADDOVERLAYS = 0x000000020 127 | SHGFI_OVERLAYINDEX = 0x000000040 128 | SHGFI_ICON = 0x000000100 129 | SHGFI_DISPLAYNAME = 0x000000200 130 | SHGFI_TYPENAME = 0x000000400 131 | SHGFI_ATTRIBUTES = 0x000000800 132 | SHGFI_ICONLOCATION = 0x000001000 133 | SHGFI_EXETYPE = 0x000002000 134 | SHGFI_SYSICONINDEX = 0x000004000 135 | SHGFI_LINKOVERLAY = 0x000008000 136 | SHGFI_SELECTED = 0x000010000 137 | SHGFI_ATTR_SPECIFIED = 0x000020000 138 | ) 139 | 140 | type NOTIFYICONDATA struct { 141 | CbSize uint32 142 | HWnd HWND 143 | UID uint32 144 | UFlags uint32 145 | UCallbackMessage uint32 146 | HIcon HICON 147 | SzTip [128]uint16 148 | DwState uint32 149 | DwStateMask uint32 150 | SzInfo [256]uint16 151 | UVersion uint32 152 | SzInfoTitle [64]uint16 153 | DwInfoFlags uint32 154 | GuidItem syscall.GUID 155 | } 156 | 157 | type SHFILEINFO struct { 158 | HIcon HICON 159 | IIcon int32 160 | DwAttributes uint32 161 | SzDisplayName [MAX_PATH]uint16 162 | SzTypeName [80]uint16 163 | } 164 | 165 | type BROWSEINFO struct { 166 | HwndOwner HWND 167 | PidlRoot uintptr 168 | PszDisplayName *uint16 169 | LpszTitle *uint16 170 | UlFlags uint32 171 | Lpfn uintptr 172 | LParam uintptr 173 | IImage int32 174 | } 175 | 176 | var ( 177 | // Library 178 | libshell32 uintptr 179 | 180 | // Functions 181 | dragAcceptFiles uintptr 182 | dragFinish uintptr 183 | dragQueryFile uintptr 184 | shBrowseForFolder uintptr 185 | shGetFileInfo uintptr 186 | shGetPathFromIDList uintptr 187 | shGetSpecialFolderPath uintptr 188 | shell_NotifyIcon uintptr 189 | ) 190 | 191 | func init() { 192 | // Library 193 | libshell32 = MustLoadLibrary("shell32.dll") 194 | 195 | // Functions 196 | dragAcceptFiles = MustGetProcAddress(libshell32, "DragAcceptFiles") 197 | dragFinish = MustGetProcAddress(libshell32, "DragFinish") 198 | dragQueryFile = MustGetProcAddress(libshell32, "DragQueryFileW") 199 | shBrowseForFolder = MustGetProcAddress(libshell32, "SHBrowseForFolderW") 200 | shGetFileInfo = MustGetProcAddress(libshell32, "SHGetFileInfoW") 201 | shGetPathFromIDList = MustGetProcAddress(libshell32, "SHGetPathFromIDListW") 202 | shGetSpecialFolderPath = MustGetProcAddress(libshell32, "SHGetSpecialFolderPathW") 203 | shell_NotifyIcon = MustGetProcAddress(libshell32, "Shell_NotifyIconW") 204 | } 205 | 206 | func DragAcceptFiles(hWnd HWND, fAccept bool) bool { 207 | ret, _, _ := syscall.Syscall(dragAcceptFiles, 2, 208 | uintptr(hWnd), 209 | uintptr(BoolToBOOL(fAccept)), 210 | 0) 211 | 212 | return ret != 0 213 | } 214 | 215 | func DragQueryFile(hDrop HDROP, iFile uint, lpszFile *uint16, cch uint) uint { 216 | ret, _, _ := syscall.Syscall6(dragQueryFile, 4, 217 | uintptr(hDrop), 218 | uintptr(iFile), 219 | uintptr(unsafe.Pointer(lpszFile)), 220 | uintptr(cch), 221 | 0, 222 | 0) 223 | 224 | return uint(ret) 225 | } 226 | 227 | func DragFinish(hDrop HDROP) { 228 | syscall.Syscall(dragAcceptFiles, 1, 229 | uintptr(hDrop), 230 | 0, 231 | 0) 232 | } 233 | 234 | func SHBrowseForFolder(lpbi *BROWSEINFO) uintptr { 235 | ret, _, _ := syscall.Syscall(shBrowseForFolder, 1, 236 | uintptr(unsafe.Pointer(lpbi)), 237 | 0, 238 | 0) 239 | 240 | return ret 241 | } 242 | 243 | func SHGetFileInfo(pszPath *uint16, dwFileAttributes uint32, psfi *SHFILEINFO, cbFileInfo, uFlags uint32) uintptr { 244 | ret, _, _ := syscall.Syscall6(shGetFileInfo, 5, 245 | uintptr(unsafe.Pointer(pszPath)), 246 | uintptr(dwFileAttributes), 247 | uintptr(unsafe.Pointer(psfi)), 248 | uintptr(cbFileInfo), 249 | uintptr(uFlags), 250 | 0) 251 | 252 | return ret 253 | } 254 | 255 | func SHGetPathFromIDList(pidl uintptr, pszPath *uint16) bool { 256 | ret, _, _ := syscall.Syscall(shGetPathFromIDList, 2, 257 | pidl, 258 | uintptr(unsafe.Pointer(pszPath)), 259 | 0) 260 | 261 | return ret != 0 262 | } 263 | 264 | func SHGetSpecialFolderPath(hwndOwner HWND, lpszPath *uint16, csidl CSIDL, fCreate bool) bool { 265 | ret, _, _ := syscall.Syscall6(shGetSpecialFolderPath, 4, 266 | uintptr(hwndOwner), 267 | uintptr(unsafe.Pointer(lpszPath)), 268 | uintptr(csidl), 269 | uintptr(BoolToBOOL(fCreate)), 270 | 0, 271 | 0) 272 | 273 | return ret != 0 274 | } 275 | 276 | func Shell_NotifyIcon(dwMessage uint32, lpdata *NOTIFYICONDATA) bool { 277 | ret, _, _ := syscall.Syscall(shell_NotifyIcon, 2, 278 | uintptr(dwMessage), 279 | uintptr(unsafe.Pointer(lpdata)), 280 | 0) 281 | 282 | return ret != 0 283 | } 284 | -------------------------------------------------------------------------------- /vendor/github.com/ssoor/winapi/shobj.go: -------------------------------------------------------------------------------- 1 | // Copyright 2012 The win Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // +build windows 6 | 7 | package winapi 8 | 9 | import ( 10 | "syscall" 11 | "unsafe" 12 | ) 13 | 14 | var ( 15 | CLSID_TaskbarList = CLSID{0x56FDF344, 0xFD6D, 0x11d0, [8]byte{0x95, 0x8A, 0x00, 0x60, 0x97, 0xC9, 0xA0, 0x90}} 16 | IID_ITaskbarList3 = IID{0xea1afb91, 0x9e28, 0x4b86, [8]byte{0x90, 0xe9, 0x9e, 0x9f, 0x8a, 0x5e, 0xef, 0xaf}} 17 | ) 18 | 19 | //TBPFLAG 20 | const ( 21 | TBPF_NOPROGRESS = 0 22 | TBPF_INDETERMINATE = 0x1 23 | TBPF_NORMAL = 0x2 24 | TBPF_ERROR = 0x4 25 | TBPF_PAUSED = 0x8 26 | ) 27 | 28 | type ITaskbarList3Vtbl struct { 29 | QueryInterface uintptr 30 | AddRef uintptr 31 | Release uintptr 32 | HrInit uintptr 33 | AddTab uintptr 34 | DeleteTab uintptr 35 | ActivateTab uintptr 36 | SetActiveAlt uintptr 37 | MarkFullscreenWindow uintptr 38 | SetProgressValue uintptr 39 | SetProgressState uintptr 40 | RegisterTab uintptr 41 | UnregisterTab uintptr 42 | SetTabOrder uintptr 43 | SetTabActive uintptr 44 | ThumbBarAddButtons uintptr 45 | ThumbBarUpdateButtons uintptr 46 | ThumbBarSetImageList uintptr 47 | SetOverlayIcon uintptr 48 | SetThumbnailTooltip uintptr 49 | SetThumbnailClip uintptr 50 | } 51 | 52 | type ITaskbarList3 struct { 53 | LpVtbl *ITaskbarList3Vtbl 54 | } 55 | 56 | func (obj *ITaskbarList3) SetProgressState(hwnd HWND, state int) HRESULT { 57 | ret, _, _ := syscall.Syscall(obj.LpVtbl.SetProgressState, 3, 58 | uintptr(unsafe.Pointer(obj)), 59 | uintptr(hwnd), 60 | uintptr(state)) 61 | return HRESULT(ret) 62 | } 63 | -------------------------------------------------------------------------------- /vendor/github.com/ssoor/winapi/shobj_386.go: -------------------------------------------------------------------------------- 1 | // Copyright 2012 The win Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package winapi 6 | 7 | import ( 8 | "syscall" 9 | "unsafe" 10 | ) 11 | 12 | func (obj *ITaskbarList3) SetProgressValue(hwnd HWND, current uint32, length uint32) HRESULT { 13 | ret, _, _ := syscall.Syscall6(obj.LpVtbl.SetProgressValue, 6, 14 | uintptr(unsafe.Pointer(obj)), 15 | uintptr(hwnd), 16 | uintptr(current), 17 | 0, 18 | uintptr(length), 19 | 0) 20 | 21 | return HRESULT(ret) 22 | } 23 | -------------------------------------------------------------------------------- /vendor/github.com/ssoor/winapi/shobj_amd64.go: -------------------------------------------------------------------------------- 1 | // Copyright 2012 The win Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // +build windows 6 | 7 | package winapi 8 | 9 | import ( 10 | "syscall" 11 | "unsafe" 12 | ) 13 | 14 | func (obj *ITaskbarList3) SetProgressValue(hwnd HWND, current uint32, length uint32) HRESULT { 15 | ret, _, _ := syscall.Syscall6(obj.LpVtbl.SetProgressValue, 4, 16 | uintptr(unsafe.Pointer(obj)), 17 | uintptr(hwnd), 18 | uintptr(current), 19 | uintptr(length), 20 | 0, 21 | 0) 22 | 23 | return HRESULT(ret) 24 | } 25 | -------------------------------------------------------------------------------- /vendor/github.com/ssoor/winapi/statusbar.go: -------------------------------------------------------------------------------- 1 | // Copyright 2013 The win Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // +build windows 6 | 7 | package winapi 8 | 9 | // Styles 10 | const ( 11 | SBARS_SIZEGRIP = 0x100 12 | SBARS_TOOLTIPS = 0x800 13 | ) 14 | 15 | // Messages 16 | const ( 17 | SB_SETPARTS = WM_USER + 4 18 | SB_GETPARTS = WM_USER + 6 19 | SB_GETBORDERS = WM_USER + 7 20 | SB_SETMINHEIGHT = WM_USER + 8 21 | SB_SIMPLE = WM_USER + 9 22 | SB_GETRECT = WM_USER + 10 23 | SB_SETTEXT = WM_USER + 11 24 | SB_GETTEXTLENGTH = WM_USER + 12 25 | SB_GETTEXT = WM_USER + 13 26 | SB_ISSIMPLE = WM_USER + 14 27 | SB_SETICON = WM_USER + 15 28 | SB_SETTIPTEXT = WM_USER + 17 29 | SB_GETTIPTEXT = WM_USER + 19 30 | SB_GETICON = WM_USER + 20 31 | SB_SETUNICODEFORMAT = CCM_SETUNICODEFORMAT 32 | SB_GETUNICODEFORMAT = CCM_GETUNICODEFORMAT 33 | SB_SETBKCOLOR = CCM_SETBKCOLOR 34 | ) 35 | 36 | // SB_SETTEXT options 37 | const ( 38 | SBT_NOBORDERS = 0x100 39 | SBT_POPOUT = 0x200 40 | SBT_RTLREADING = 0x400 41 | SBT_NOTABPARSING = 0x800 42 | SBT_OWNERDRAW = 0x1000 43 | ) 44 | 45 | const ( 46 | SBN_FIRST = -880 47 | SBN_SIMPLEMODECHANGE = SBN_FIRST - 0 48 | ) 49 | 50 | const SB_SIMPLEID = 0xff 51 | -------------------------------------------------------------------------------- /vendor/github.com/ssoor/winapi/tab.go: -------------------------------------------------------------------------------- 1 | // Copyright 2011 The win Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // +build windows 6 | 7 | package winapi 8 | 9 | const TCM_FIRST = 0x1300 10 | const TCN_FIRST = -550 11 | 12 | const ( 13 | TCS_SCROLLOPPOSITE = 0x0001 14 | TCS_BOTTOM = 0x0002 15 | TCS_RIGHT = 0x0002 16 | TCS_MULTISELECT = 0x0004 17 | TCS_FLATBUTTONS = 0x0008 18 | TCS_FORCEICONLEFT = 0x0010 19 | TCS_FORCELABELLEFT = 0x0020 20 | TCS_HOTTRACK = 0x0040 21 | TCS_VERTICAL = 0x0080 22 | TCS_TABS = 0x0000 23 | TCS_BUTTONS = 0x0100 24 | TCS_SINGLELINE = 0x0000 25 | TCS_MULTILINE = 0x0200 26 | TCS_RIGHTJUSTIFY = 0x0000 27 | TCS_FIXEDWIDTH = 0x0400 28 | TCS_RAGGEDRIGHT = 0x0800 29 | TCS_FOCUSONBUTTONDOWN = 0x1000 30 | TCS_OWNERDRAWFIXED = 0x2000 31 | TCS_TOOLTIPS = 0x4000 32 | TCS_FOCUSNEVER = 0x8000 33 | ) 34 | 35 | const ( 36 | TCS_EX_FLATSEPARATORS = 0x00000001 37 | TCS_EX_REGISTERDROP = 0x00000002 38 | ) 39 | 40 | const ( 41 | TCM_GETIMAGELIST = TCM_FIRST + 2 42 | TCM_SETIMAGELIST = TCM_FIRST + 3 43 | TCM_GETITEMCOUNT = TCM_FIRST + 4 44 | TCM_GETITEM = TCM_FIRST + 60 45 | TCM_SETITEM = TCM_FIRST + 61 46 | TCM_INSERTITEM = TCM_FIRST + 62 47 | TCM_DELETEITEM = TCM_FIRST + 8 48 | TCM_DELETEALLITEMS = TCM_FIRST + 9 49 | TCM_GETITEMRECT = TCM_FIRST + 10 50 | TCM_GETCURSEL = TCM_FIRST + 11 51 | TCM_SETCURSEL = TCM_FIRST + 12 52 | TCM_HITTEST = TCM_FIRST + 13 53 | TCM_SETITEMEXTRA = TCM_FIRST + 14 54 | TCM_ADJUSTRECT = TCM_FIRST + 40 55 | TCM_SETITEMSIZE = TCM_FIRST + 41 56 | TCM_REMOVEIMAGE = TCM_FIRST + 42 57 | TCM_SETPADDING = TCM_FIRST + 43 58 | TCM_GETROWCOUNT = TCM_FIRST + 44 59 | TCM_GETTOOLTIPS = TCM_FIRST + 45 60 | TCM_SETTOOLTIPS = TCM_FIRST + 46 61 | TCM_GETCURFOCUS = TCM_FIRST + 47 62 | TCM_SETCURFOCUS = TCM_FIRST + 48 63 | TCM_SETMINTABWIDTH = TCM_FIRST + 49 64 | TCM_DESELECTALL = TCM_FIRST + 50 65 | TCM_HIGHLIGHTITEM = TCM_FIRST + 51 66 | TCM_SETEXTENDEDSTYLE = TCM_FIRST + 52 67 | TCM_GETEXTENDEDSTYLE = TCM_FIRST + 53 68 | TCM_SETUNICODEFORMAT = CCM_SETUNICODEFORMAT 69 | TCM_GETUNICODEFORMAT = CCM_GETUNICODEFORMAT 70 | ) 71 | 72 | const ( 73 | TCIF_TEXT = 0x0001 74 | TCIF_IMAGE = 0x0002 75 | TCIF_RTLREADING = 0x0004 76 | TCIF_PARAM = 0x0008 77 | TCIF_STATE = 0x0010 78 | ) 79 | 80 | const ( 81 | TCIS_BUTTONPRESSED = 0x0001 82 | TCIS_HIGHLIGHTED = 0x0002 83 | ) 84 | 85 | const ( 86 | TCHT_NOWHERE = 0x0001 87 | TCHT_ONITEMICON = 0x0002 88 | TCHT_ONITEMLABEL = 0x0004 89 | TCHT_ONITEM = TCHT_ONITEMICON | TCHT_ONITEMLABEL 90 | ) 91 | 92 | const ( 93 | TCN_KEYDOWN = TCN_FIRST - 0 94 | TCN_SELCHANGE = TCN_FIRST - 1 95 | TCN_SELCHANGING = TCN_FIRST - 2 96 | TCN_GETOBJECT = TCN_FIRST - 3 97 | TCN_FOCUSCHANGE = TCN_FIRST - 4 98 | ) 99 | 100 | type TCITEMHEADER struct { 101 | Mask uint32 102 | LpReserved1 uint32 103 | LpReserved2 uint32 104 | PszText *uint16 105 | CchTextMax int32 106 | IImage int32 107 | } 108 | 109 | type TCITEM struct { 110 | Mask uint32 111 | DwState uint32 112 | DwStateMask uint32 113 | PszText *uint16 114 | CchTextMax int32 115 | IImage int32 116 | LParam uintptr 117 | } 118 | 119 | type TCHITTESTINFO struct { 120 | Pt POINT 121 | flags uint32 122 | } 123 | 124 | type NMTCKEYDOWN struct { 125 | Hdr NMHDR 126 | WVKey uint16 127 | Flags uint32 128 | } 129 | -------------------------------------------------------------------------------- /vendor/github.com/ssoor/winapi/toolbar.go: -------------------------------------------------------------------------------- 1 | // Copyright 2010 The win Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // +build windows 6 | 7 | package winapi 8 | 9 | // ToolBar messages 10 | const ( 11 | TB_ENABLEBUTTON = WM_USER + 1 12 | TB_CHECKBUTTON = WM_USER + 2 13 | TB_PRESSBUTTON = WM_USER + 3 14 | TB_HIDEBUTTON = WM_USER + 4 15 | TB_INDETERMINATE = WM_USER + 5 16 | TB_MARKBUTTON = WM_USER + 6 17 | TB_ISBUTTONENABLED = WM_USER + 9 18 | TB_ISBUTTONCHECKED = WM_USER + 10 19 | TB_ISBUTTONPRESSED = WM_USER + 11 20 | TB_ISBUTTONHIDDEN = WM_USER + 12 21 | TB_ISBUTTONINDETERMINATE = WM_USER + 13 22 | TB_ISBUTTONHIGHLIGHTED = WM_USER + 14 23 | TB_SETSTATE = WM_USER + 17 24 | TB_GETSTATE = WM_USER + 18 25 | TB_ADDBITMAP = WM_USER + 19 26 | TB_DELETEBUTTON = WM_USER + 22 27 | TB_GETBUTTON = WM_USER + 23 28 | TB_BUTTONCOUNT = WM_USER + 24 29 | TB_COMMANDTOINDEX = WM_USER + 25 30 | TB_SAVERESTORE = WM_USER + 76 31 | TB_CUSTOMIZE = WM_USER + 27 32 | TB_ADDSTRING = WM_USER + 77 33 | TB_GETITEMRECT = WM_USER + 29 34 | TB_BUTTONSTRUCTSIZE = WM_USER + 30 35 | TB_SETBUTTONSIZE = WM_USER + 31 36 | TB_SETBITMAPSIZE = WM_USER + 32 37 | TB_AUTOSIZE = WM_USER + 33 38 | TB_GETTOOLTIPS = WM_USER + 35 39 | TB_SETTOOLTIPS = WM_USER + 36 40 | TB_SETPARENT = WM_USER + 37 41 | TB_SETROWS = WM_USER + 39 42 | TB_GETROWS = WM_USER + 40 43 | TB_GETBITMAPFLAGS = WM_USER + 41 44 | TB_SETCMDID = WM_USER + 42 45 | TB_CHANGEBITMAP = WM_USER + 43 46 | TB_GETBITMAP = WM_USER + 44 47 | TB_GETBUTTONTEXT = WM_USER + 75 48 | TB_REPLACEBITMAP = WM_USER + 46 49 | TB_GETBUTTONSIZE = WM_USER + 58 50 | TB_SETBUTTONWIDTH = WM_USER + 59 51 | TB_SETINDENT = WM_USER + 47 52 | TB_SETIMAGELIST = WM_USER + 48 53 | TB_GETIMAGELIST = WM_USER + 49 54 | TB_LOADIMAGES = WM_USER + 50 55 | TB_GETRECT = WM_USER + 51 56 | TB_SETHOTIMAGELIST = WM_USER + 52 57 | TB_GETHOTIMAGELIST = WM_USER + 53 58 | TB_SETDISABLEDIMAGELIST = WM_USER + 54 59 | TB_GETDISABLEDIMAGELIST = WM_USER + 55 60 | TB_SETSTYLE = WM_USER + 56 61 | TB_GETSTYLE = WM_USER + 57 62 | TB_SETMAXTEXTROWS = WM_USER + 60 63 | TB_GETTEXTROWS = WM_USER + 61 64 | TB_GETOBJECT = WM_USER + 62 65 | TB_GETBUTTONINFO = WM_USER + 63 66 | TB_SETBUTTONINFO = WM_USER + 64 67 | TB_INSERTBUTTON = WM_USER + 67 68 | TB_ADDBUTTONS = WM_USER + 68 69 | TB_HITTEST = WM_USER + 69 70 | TB_SETDRAWTEXTFLAGS = WM_USER + 70 71 | TB_GETHOTITEM = WM_USER + 71 72 | TB_SETHOTITEM = WM_USER + 72 73 | TB_SETANCHORHIGHLIGHT = WM_USER + 73 74 | TB_GETANCHORHIGHLIGHT = WM_USER + 74 75 | TB_GETINSERTMARK = WM_USER + 79 76 | TB_SETINSERTMARK = WM_USER + 80 77 | TB_INSERTMARKHITTEST = WM_USER + 81 78 | TB_MOVEBUTTON = WM_USER + 82 79 | TB_GETMAXSIZE = WM_USER + 83 80 | TB_SETEXTENDEDSTYLE = WM_USER + 84 81 | TB_GETEXTENDEDSTYLE = WM_USER + 85 82 | TB_GETPADDING = WM_USER + 86 83 | TB_SETPADDING = WM_USER + 87 84 | TB_SETINSERTMARKCOLOR = WM_USER + 88 85 | TB_GETINSERTMARKCOLOR = WM_USER + 89 86 | TB_MAPACCELERATOR = WM_USER + 90 87 | TB_GETSTRING = WM_USER + 91 88 | TB_SETCOLORSCHEME = CCM_SETCOLORSCHEME 89 | TB_GETCOLORSCHEME = CCM_GETCOLORSCHEME 90 | TB_SETUNICODEFORMAT = CCM_SETUNICODEFORMAT 91 | TB_GETUNICODEFORMAT = CCM_GETUNICODEFORMAT 92 | ) 93 | 94 | // ToolBar notifications 95 | const ( 96 | TBN_FIRST = -700 97 | TBN_DROPDOWN = TBN_FIRST - 10 98 | ) 99 | 100 | // TBN_DROPDOWN return codes 101 | const ( 102 | TBDDRET_DEFAULT = 0 103 | TBDDRET_NODEFAULT = 1 104 | TBDDRET_TREATPRESSED = 2 105 | ) 106 | 107 | // ToolBar state constants 108 | const ( 109 | TBSTATE_CHECKED = 1 110 | TBSTATE_PRESSED = 2 111 | TBSTATE_ENABLED = 4 112 | TBSTATE_HIDDEN = 8 113 | TBSTATE_INDETERMINATE = 16 114 | TBSTATE_WRAP = 32 115 | TBSTATE_ELLIPSES = 0x40 116 | TBSTATE_MARKED = 0x0080 117 | ) 118 | 119 | // ToolBar style constants 120 | const ( 121 | TBSTYLE_BUTTON = 0 122 | TBSTYLE_SEP = 1 123 | TBSTYLE_CHECK = 2 124 | TBSTYLE_GROUP = 4 125 | TBSTYLE_CHECKGROUP = TBSTYLE_GROUP | TBSTYLE_CHECK 126 | TBSTYLE_DROPDOWN = 8 127 | TBSTYLE_AUTOSIZE = 16 128 | TBSTYLE_NOPREFIX = 32 129 | TBSTYLE_TOOLTIPS = 256 130 | TBSTYLE_WRAPABLE = 512 131 | TBSTYLE_ALTDRAG = 1024 132 | TBSTYLE_FLAT = 2048 133 | TBSTYLE_LIST = 4096 134 | TBSTYLE_CUSTOMERASE = 8192 135 | TBSTYLE_REGISTERDROP = 0x4000 136 | TBSTYLE_TRANSPARENT = 0x8000 137 | ) 138 | 139 | // ToolBar extended style constants 140 | const ( 141 | TBSTYLE_EX_DRAWDDARROWS = 0x00000001 142 | TBSTYLE_EX_MIXEDBUTTONS = 8 143 | TBSTYLE_EX_HIDECLIPPEDBUTTONS = 16 144 | TBSTYLE_EX_DOUBLEBUFFER = 0x80 145 | ) 146 | 147 | // ToolBar button style constants 148 | const ( 149 | BTNS_BUTTON = TBSTYLE_BUTTON 150 | BTNS_SEP = TBSTYLE_SEP 151 | BTNS_CHECK = TBSTYLE_CHECK 152 | BTNS_GROUP = TBSTYLE_GROUP 153 | BTNS_CHECKGROUP = TBSTYLE_CHECKGROUP 154 | BTNS_DROPDOWN = TBSTYLE_DROPDOWN 155 | BTNS_AUTOSIZE = TBSTYLE_AUTOSIZE 156 | BTNS_NOPREFIX = TBSTYLE_NOPREFIX 157 | BTNS_WHOLEDROPDOWN = 0x0080 158 | BTNS_SHOWTEXT = 0x0040 159 | ) 160 | 161 | // TBBUTTONINFO mask flags 162 | const ( 163 | TBIF_IMAGE = 0x00000001 164 | TBIF_TEXT = 0x00000002 165 | TBIF_STATE = 0x00000004 166 | TBIF_STYLE = 0x00000008 167 | TBIF_LPARAM = 0x00000010 168 | TBIF_COMMAND = 0x00000020 169 | TBIF_SIZE = 0x00000040 170 | TBIF_BYINDEX = 0x80000000 171 | ) 172 | 173 | type NMMOUSE struct { 174 | Hdr NMHDR 175 | DwItemSpec uintptr 176 | DwItemData uintptr 177 | Pt POINT 178 | DwHitInfo uintptr 179 | } 180 | 181 | type NMTOOLBAR struct { 182 | Hdr NMHDR 183 | IItem int32 184 | TbButton TBBUTTON 185 | CchText int32 186 | PszText *uint16 187 | RcButton RECT 188 | } 189 | 190 | type TBBUTTON struct { 191 | IBitmap int32 192 | IdCommand int32 193 | FsState byte 194 | FsStyle byte 195 | //#ifdef _WIN64 196 | // BYTE bReserved[6] // padding for alignment 197 | //#elif defined(_WIN32) 198 | BReserved [2]byte // padding for alignment 199 | //#endif 200 | DwData uintptr 201 | IString uintptr 202 | } 203 | 204 | type TBBUTTONINFO struct { 205 | CbSize uint32 206 | DwMask uint32 207 | IdCommand int32 208 | IImage int32 209 | FsState byte 210 | FsStyle byte 211 | Cx uint16 212 | LParam uintptr 213 | PszText uintptr 214 | CchText int32 215 | } 216 | -------------------------------------------------------------------------------- /vendor/github.com/ssoor/winapi/tooltip.go: -------------------------------------------------------------------------------- 1 | // Copyright 2010 The win Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // +build windows 6 | 7 | package winapi 8 | 9 | import ( 10 | "unsafe" 11 | ) 12 | 13 | // ToolTip styles 14 | const ( 15 | TTS_ALWAYSTIP = 0x01 16 | TTS_NOPREFIX = 0x02 17 | TTS_NOANIMATE = 0x10 18 | TTS_NOFADE = 0x20 19 | TTS_BALLOON = 0x40 20 | TTS_CLOSE = 0x80 21 | ) 22 | 23 | // ToolTip messages 24 | const ( 25 | TTM_ACTIVATE = WM_USER + 1 26 | TTM_SETDELAYTIME = WM_USER + 3 27 | TTM_ADDTOOL = WM_USER + 50 28 | TTM_DELTOOL = WM_USER + 51 29 | TTM_NEWTOOLRECT = WM_USER + 52 30 | TTM_RELAYEVENT = WM_USER + 7 31 | TTM_GETTOOLINFO = WM_USER + 53 32 | TTM_SETTOOLINFO = WM_USER + 54 33 | TTM_HITTEST = WM_USER + 55 34 | TTM_GETTEXT = WM_USER + 56 35 | TTM_UPDATETIPTEXT = WM_USER + 57 36 | TTM_GETTOOLCOUNT = WM_USER + 13 37 | TTM_ENUMTOOLS = WM_USER + 58 38 | TTM_GETCURRENTTOOL = WM_USER + 59 39 | TTM_WINDOWFROMPOINT = WM_USER + 16 40 | TTM_TRACKACTIVATE = WM_USER + 17 41 | TTM_TRACKPOSITION = WM_USER + 18 42 | TTM_SETTIPBKCOLOR = WM_USER + 19 43 | TTM_SETTIPTEXTCOLOR = WM_USER + 20 44 | TTM_GETDELAYTIME = WM_USER + 21 45 | TTM_GETTIPBKCOLOR = WM_USER + 22 46 | TTM_GETTIPTEXTCOLOR = WM_USER + 23 47 | TTM_SETMAXTIPWIDTH = WM_USER + 24 48 | TTM_GETMAXTIPWIDTH = WM_USER + 25 49 | TTM_SETMARGIN = WM_USER + 26 50 | TTM_GETMARGIN = WM_USER + 27 51 | TTM_POP = WM_USER + 28 52 | TTM_UPDATE = WM_USER + 29 53 | TTM_GETBUBBLESIZE = WM_USER + 30 54 | TTM_ADJUSTRECT = WM_USER + 31 55 | TTM_SETTITLE = WM_USER + 33 56 | TTM_POPUP = WM_USER + 34 57 | TTM_GETTITLE = WM_USER + 35 58 | ) 59 | 60 | // ToolTip flags 61 | const ( 62 | TTF_IDISHWND = 0x0001 63 | TTF_CENTERTIP = 0x0002 64 | TTF_RTLREADING = 0x0004 65 | TTF_SUBCLASS = 0x0010 66 | TTF_TRACK = 0x0020 67 | TTF_ABSOLUTE = 0x0080 68 | TTF_TRANSPARENT = 0x0100 69 | TTF_DI_SETITEM = 0x8000 70 | ) 71 | 72 | // ToolTip icons 73 | const ( 74 | TTI_NONE = 0 75 | TTI_INFO = 1 76 | TTI_WARNING = 2 77 | TTI_ERROR = 3 78 | ) 79 | 80 | type TOOLINFO struct { 81 | CbSize uint32 82 | UFlags uint32 83 | Hwnd HWND 84 | UId uintptr 85 | Rect RECT 86 | Hinst HINSTANCE 87 | LpszText *uint16 88 | LParam uintptr 89 | LpReserved unsafe.Pointer 90 | } 91 | 92 | type TTGETTITLE struct { 93 | DwSize uint32 94 | UTitleBitmap uint32 95 | Cch uint32 96 | PszTitle *uint16 97 | } 98 | -------------------------------------------------------------------------------- /vendor/github.com/ssoor/winapi/treeview.go: -------------------------------------------------------------------------------- 1 | // Copyright 2010 The win Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // +build windows 6 | 7 | package winapi 8 | 9 | // TreeView styles 10 | const ( 11 | TVS_HASBUTTONS = 0x0001 12 | TVS_HASLINES = 0x0002 13 | TVS_LINESATROOT = 0x0004 14 | TVS_EDITLABELS = 0x0008 15 | TVS_DISABLEDRAGDROP = 0x0010 16 | TVS_SHOWSELALWAYS = 0x0020 17 | TVS_RTLREADING = 0x0040 18 | TVS_NOTOOLTIPS = 0x0080 19 | TVS_CHECKBOXES = 0x0100 20 | TVS_TRACKSELECT = 0x0200 21 | TVS_SINGLEEXPAND = 0x0400 22 | TVS_INFOTIP = 0x0800 23 | TVS_FULLROWSELECT = 0x1000 24 | TVS_NOSCROLL = 0x2000 25 | TVS_NONEVENHEIGHT = 0x4000 26 | TVS_NOHSCROLL = 0x8000 27 | ) 28 | 29 | const ( 30 | TVS_EX_NOSINGLECOLLAPSE = 0x0001 31 | TVS_EX_MULTISELECT = 0x0002 32 | TVS_EX_DOUBLEBUFFER = 0x0004 33 | TVS_EX_NOINDENTSTATE = 0x0008 34 | TVS_EX_RICHTOOLTIP = 0x0010 35 | TVS_EX_AUTOHSCROLL = 0x0020 36 | TVS_EX_FADEINOUTEXPANDOS = 0x0040 37 | TVS_EX_PARTIALCHECKBOXES = 0x0080 38 | TVS_EX_EXCLUSIONCHECKBOXES = 0x0100 39 | TVS_EX_DIMMEDCHECKBOXES = 0x0200 40 | TVS_EX_DRAWIMAGEASYNC = 0x0400 41 | ) 42 | 43 | const ( 44 | TVIF_TEXT = 0x0001 45 | TVIF_IMAGE = 0x0002 46 | TVIF_PARAM = 0x0004 47 | TVIF_STATE = 0x0008 48 | TVIF_HANDLE = 0x0010 49 | TVIF_SELECTEDIMAGE = 0x0020 50 | TVIF_CHILDREN = 0x0040 51 | TVIF_INTEGRAL = 0x0080 52 | TVIF_STATEEX = 0x0100 53 | TVIF_EXPANDEDIMAGE = 0x0200 54 | ) 55 | 56 | const ( 57 | TVIS_SELECTED = 0x0002 58 | TVIS_CUT = 0x0004 59 | TVIS_DROPHILITED = 0x0008 60 | TVIS_BOLD = 0x0010 61 | TVIS_EXPANDED = 0x0020 62 | TVIS_EXPANDEDONCE = 0x0040 63 | TVIS_EXPANDPARTIAL = 0x0080 64 | TVIS_OVERLAYMASK = 0x0F00 65 | TVIS_STATEIMAGEMASK = 0xF000 66 | TVIS_USERMASK = 0xF000 67 | ) 68 | 69 | const ( 70 | TVIS_EX_FLAT = 0x0001 71 | TVIS_EX_DISABLED = 0x0002 72 | TVIS_EX_ALL = 0x0002 73 | ) 74 | 75 | const ( 76 | TVI_ROOT = ^HTREEITEM(0xffff) 77 | TVI_FIRST = ^HTREEITEM(0xfffe) 78 | TVI_LAST = ^HTREEITEM(0xfffd) 79 | TVI_SORT = ^HTREEITEM(0xfffc) 80 | ) 81 | 82 | // TVM_EXPAND action flags 83 | const ( 84 | TVE_COLLAPSE = 0x0001 85 | TVE_EXPAND = 0x0002 86 | TVE_TOGGLE = 0x0003 87 | TVE_EXPANDPARTIAL = 0x4000 88 | TVE_COLLAPSERESET = 0x8000 89 | ) 90 | 91 | const ( 92 | TVGN_CARET = 9 93 | ) 94 | 95 | // TreeView messages 96 | const ( 97 | TV_FIRST = 0x1100 98 | 99 | TVM_INSERTITEM = TV_FIRST + 50 100 | TVM_DELETEITEM = TV_FIRST + 1 101 | TVM_EXPAND = TV_FIRST + 2 102 | TVM_GETITEMRECT = TV_FIRST + 4 103 | TVM_GETCOUNT = TV_FIRST + 5 104 | TVM_GETINDENT = TV_FIRST + 6 105 | TVM_SETINDENT = TV_FIRST + 7 106 | TVM_GETIMAGELIST = TV_FIRST + 8 107 | TVM_SETIMAGELIST = TV_FIRST + 9 108 | TVM_GETNEXTITEM = TV_FIRST + 10 109 | TVM_SELECTITEM = TV_FIRST + 11 110 | TVM_GETITEM = TV_FIRST + 62 111 | TVM_SETITEM = TV_FIRST + 63 112 | TVM_EDITLABEL = TV_FIRST + 65 113 | TVM_GETEDITCONTROL = TV_FIRST + 15 114 | TVM_GETVISIBLECOUNT = TV_FIRST + 16 115 | TVM_HITTEST = TV_FIRST + 17 116 | TVM_CREATEDRAGIMAGE = TV_FIRST + 18 117 | TVM_SORTCHILDREN = TV_FIRST + 19 118 | TVM_ENSUREVISIBLE = TV_FIRST + 20 119 | TVM_SORTCHILDRENCB = TV_FIRST + 21 120 | TVM_ENDEDITLABELNOW = TV_FIRST + 22 121 | TVM_GETISEARCHSTRING = TV_FIRST + 64 122 | TVM_SETTOOLTIPS = TV_FIRST + 24 123 | TVM_GETTOOLTIPS = TV_FIRST + 25 124 | TVM_SETINSERTMARK = TV_FIRST + 26 125 | TVM_SETUNICODEFORMAT = CCM_SETUNICODEFORMAT 126 | TVM_GETUNICODEFORMAT = CCM_GETUNICODEFORMAT 127 | TVM_SETITEMHEIGHT = TV_FIRST + 27 128 | TVM_GETITEMHEIGHT = TV_FIRST + 28 129 | TVM_SETBKCOLOR = TV_FIRST + 29 130 | TVM_SETTEXTCOLOR = TV_FIRST + 30 131 | TVM_GETBKCOLOR = TV_FIRST + 31 132 | TVM_GETTEXTCOLOR = TV_FIRST + 32 133 | TVM_SETSCROLLTIME = TV_FIRST + 33 134 | TVM_GETSCROLLTIME = TV_FIRST + 34 135 | TVM_SETINSERTMARKCOLOR = TV_FIRST + 37 136 | TVM_GETINSERTMARKCOLOR = TV_FIRST + 38 137 | TVM_GETITEMSTATE = TV_FIRST + 39 138 | TVM_SETLINECOLOR = TV_FIRST + 40 139 | TVM_GETLINECOLOR = TV_FIRST + 41 140 | TVM_MAPACCIDTOHTREEITEM = TV_FIRST + 42 141 | TVM_MAPHTREEITEMTOACCID = TV_FIRST + 43 142 | TVM_SETEXTENDEDSTYLE = TV_FIRST + 44 143 | TVM_GETEXTENDEDSTYLE = TV_FIRST + 45 144 | TVM_SETAUTOSCROLLINFO = TV_FIRST + 59 145 | ) 146 | 147 | // TreeView notifications 148 | const ( 149 | TVN_FIRST = ^uint32(399) 150 | 151 | TVN_SELCHANGING = TVN_FIRST - 50 152 | TVN_SELCHANGED = TVN_FIRST - 51 153 | TVN_GETDISPINFO = TVN_FIRST - 52 154 | TVN_ITEMEXPANDING = TVN_FIRST - 54 155 | TVN_ITEMEXPANDED = TVN_FIRST - 55 156 | TVN_BEGINDRAG = TVN_FIRST - 56 157 | TVN_BEGINRDRAG = TVN_FIRST - 57 158 | TVN_DELETEITEM = TVN_FIRST - 58 159 | TVN_BEGINLABELEDIT = TVN_FIRST - 59 160 | TVN_ENDLABELEDIT = TVN_FIRST - 60 161 | TVN_KEYDOWN = TVN_FIRST - 12 162 | TVN_GETINFOTIP = TVN_FIRST - 14 163 | TVN_SINGLEEXPAND = TVN_FIRST - 15 164 | TVN_ITEMCHANGING = TVN_FIRST - 17 165 | TVN_ITEMCHANGED = TVN_FIRST - 19 166 | TVN_ASYNCDRAW = TVN_FIRST - 20 167 | ) 168 | 169 | // TreeView hit test constants 170 | const ( 171 | TVHT_NOWHERE = 1 172 | TVHT_ONITEMICON = 2 173 | TVHT_ONITEMLABEL = 4 174 | TVHT_ONITEM = TVHT_ONITEMICON | TVHT_ONITEMLABEL | TVHT_ONITEMSTATEICON 175 | TVHT_ONITEMINDENT = 8 176 | TVHT_ONITEMBUTTON = 16 177 | TVHT_ONITEMRIGHT = 32 178 | TVHT_ONITEMSTATEICON = 64 179 | TVHT_ABOVE = 256 180 | TVHT_BELOW = 512 181 | TVHT_TORIGHT = 1024 182 | TVHT_TOLEFT = 2048 183 | ) 184 | 185 | type HTREEITEM HANDLE 186 | 187 | type TVITEM struct { 188 | Mask uint32 189 | HItem HTREEITEM 190 | State uint32 191 | StateMask uint32 192 | PszText uintptr 193 | CchTextMax int32 194 | IImage int32 195 | ISelectedImage int32 196 | CChildren int32 197 | LParam uintptr 198 | } 199 | 200 | /*type TVITEMEX struct { 201 | mask UINT 202 | hItem HTREEITEM 203 | state UINT 204 | stateMask UINT 205 | pszText LPWSTR 206 | cchTextMax int 207 | iImage int 208 | iSelectedImage int 209 | cChildren int 210 | lParam LPARAM 211 | iIntegral int 212 | uStateEx UINT 213 | hwnd HWND 214 | iExpandedImage int 215 | }*/ 216 | 217 | type TVINSERTSTRUCT struct { 218 | HParent HTREEITEM 219 | HInsertAfter HTREEITEM 220 | Item TVITEM 221 | // itemex TVITEMEX 222 | } 223 | 224 | type NMTREEVIEW struct { 225 | Hdr NMHDR 226 | Action uint32 227 | ItemOld TVITEM 228 | ItemNew TVITEM 229 | PtDrag POINT 230 | } 231 | 232 | type NMTVDISPINFO struct { 233 | Hdr NMHDR 234 | Item TVITEM 235 | } 236 | 237 | type NMTVKEYDOWN struct { 238 | Hdr NMHDR 239 | WVKey uint16 240 | Flags uint32 241 | } 242 | 243 | type TVHITTESTINFO struct { 244 | Pt POINT 245 | Flags uint32 246 | HItem HTREEITEM 247 | } 248 | -------------------------------------------------------------------------------- /vendor/github.com/ssoor/winapi/updown.go: -------------------------------------------------------------------------------- 1 | // Copyright 2011 The win Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // +build windows 6 | 7 | package winapi 8 | 9 | const UDN_FIRST = ^uint32(720) 10 | 11 | const ( 12 | UD_MAXVAL = 0x7fff 13 | UD_MINVAL = ^uintptr(UD_MAXVAL - 1) 14 | ) 15 | 16 | const ( 17 | UDS_WRAP = 0x0001 18 | UDS_SETBUDDYINT = 0x0002 19 | UDS_ALIGNRIGHT = 0x0004 20 | UDS_ALIGNLEFT = 0x0008 21 | UDS_AUTOBUDDY = 0x0010 22 | UDS_ARROWKEYS = 0x0020 23 | UDS_HORZ = 0x0040 24 | UDS_NOTHOUSANDS = 0x0080 25 | UDS_HOTTRACK = 0x0100 26 | ) 27 | 28 | const ( 29 | UDM_SETRANGE = WM_USER + 101 30 | UDM_GETRANGE = WM_USER + 102 31 | UDM_SETPOS = WM_USER + 103 32 | UDM_GETPOS = WM_USER + 104 33 | UDM_SETBUDDY = WM_USER + 105 34 | UDM_GETBUDDY = WM_USER + 106 35 | UDM_SETACCEL = WM_USER + 107 36 | UDM_GETACCEL = WM_USER + 108 37 | UDM_SETBASE = WM_USER + 109 38 | UDM_GETBASE = WM_USER + 110 39 | UDM_SETRANGE32 = WM_USER + 111 40 | UDM_GETRANGE32 = WM_USER + 112 41 | UDM_SETUNICODEFORMAT = CCM_SETUNICODEFORMAT 42 | UDM_GETUNICODEFORMAT = CCM_GETUNICODEFORMAT 43 | UDM_SETPOS32 = WM_USER + 113 44 | UDM_GETPOS32 = WM_USER + 114 45 | ) 46 | 47 | const UDN_DELTAPOS = UDN_FIRST - 1 48 | 49 | type UDACCEL struct { 50 | NSec uint32 51 | NInc uint32 52 | } 53 | 54 | type NMUPDOWN struct { 55 | Hdr NMHDR 56 | IPos int32 57 | IDelta int32 58 | } 59 | -------------------------------------------------------------------------------- /vendor/github.com/ssoor/winapi/uxtheme.go: -------------------------------------------------------------------------------- 1 | // Copyright 2010 The win Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // +build windows 6 | 7 | package winapi 8 | 9 | import ( 10 | "syscall" 11 | "unsafe" 12 | ) 13 | 14 | // LISTVIEW parts 15 | const ( 16 | LVP_LISTITEM = 1 17 | LVP_LISTGROUP = 2 18 | LVP_LISTDETAIL = 3 19 | LVP_LISTSORTEDDETAIL = 4 20 | LVP_EMPTYTEXT = 5 21 | LVP_GROUPHEADER = 6 22 | LVP_GROUPHEADERLINE = 7 23 | LVP_EXPANDBUTTON = 8 24 | LVP_COLLAPSEBUTTON = 9 25 | LVP_COLUMNDETAIL = 10 26 | ) 27 | 28 | // LVP_LISTITEM states 29 | const ( 30 | LISS_NORMAL = 1 31 | LISS_HOT = 2 32 | LISS_SELECTED = 3 33 | LISS_DISABLED = 4 34 | LISS_SELECTEDNOTFOCUS = 5 35 | LISS_HOTSELECTED = 6 36 | ) 37 | 38 | // TREEVIEW parts 39 | const ( 40 | TVP_TREEITEM = 1 41 | TVP_GLYPH = 2 42 | TVP_BRANCH = 3 43 | TVP_HOTGLYPH = 4 44 | ) 45 | 46 | // TVP_TREEITEM states 47 | const ( 48 | TREIS_NORMAL = 1 49 | TREIS_HOT = 2 50 | TREIS_SELECTED = 3 51 | TREIS_DISABLED = 4 52 | TREIS_SELECTEDNOTFOCUS = 5 53 | TREIS_HOTSELECTED = 6 54 | ) 55 | 56 | type HTHEME HANDLE 57 | 58 | var ( 59 | // Library 60 | libuxtheme uintptr 61 | 62 | // Functions 63 | closeThemeData uintptr 64 | drawThemeBackground uintptr 65 | drawThemeText uintptr 66 | getThemeTextExtent uintptr 67 | openThemeData uintptr 68 | setWindowTheme uintptr 69 | ) 70 | 71 | func init() { 72 | // Library 73 | libuxtheme = MustLoadLibrary("uxtheme.dll") 74 | 75 | // Functions 76 | closeThemeData = MustGetProcAddress(libuxtheme, "CloseThemeData") 77 | drawThemeBackground = MustGetProcAddress(libuxtheme, "DrawThemeBackground") 78 | drawThemeText = MustGetProcAddress(libuxtheme, "DrawThemeText") 79 | getThemeTextExtent = MustGetProcAddress(libuxtheme, "GetThemeTextExtent") 80 | openThemeData = MustGetProcAddress(libuxtheme, "OpenThemeData") 81 | setWindowTheme = MustGetProcAddress(libuxtheme, "SetWindowTheme") 82 | } 83 | 84 | func CloseThemeData(hTheme HTHEME) HRESULT { 85 | ret, _, _ := syscall.Syscall(closeThemeData, 1, 86 | uintptr(hTheme), 87 | 0, 88 | 0) 89 | 90 | return HRESULT(ret) 91 | } 92 | 93 | func DrawThemeBackground(hTheme HTHEME, hdc HDC, iPartId, iStateId int32, pRect, pClipRect *RECT) HRESULT { 94 | ret, _, _ := syscall.Syscall6(drawThemeBackground, 6, 95 | uintptr(hTheme), 96 | uintptr(hdc), 97 | uintptr(iPartId), 98 | uintptr(iStateId), 99 | uintptr(unsafe.Pointer(pRect)), 100 | uintptr(unsafe.Pointer(pClipRect))) 101 | 102 | return HRESULT(ret) 103 | } 104 | 105 | func DrawThemeText(hTheme HTHEME, hdc HDC, iPartId, iStateId int32, pszText *uint16, iCharCount int32, dwTextFlags, dwTextFlags2 uint32, pRect *RECT) HRESULT { 106 | ret, _, _ := syscall.Syscall9(drawThemeText, 9, 107 | uintptr(hTheme), 108 | uintptr(hdc), 109 | uintptr(iPartId), 110 | uintptr(iStateId), 111 | uintptr(unsafe.Pointer(pszText)), 112 | uintptr(iCharCount), 113 | uintptr(dwTextFlags), 114 | uintptr(dwTextFlags2), 115 | uintptr(unsafe.Pointer(pRect))) 116 | 117 | return HRESULT(ret) 118 | } 119 | 120 | func GetThemeTextExtent(hTheme HTHEME, hdc HDC, iPartId, iStateId int32, pszText *uint16, iCharCount int32, dwTextFlags uint32, pBoundingRect, pExtentRect *RECT) HRESULT { 121 | ret, _, _ := syscall.Syscall9(getThemeTextExtent, 9, 122 | uintptr(hTheme), 123 | uintptr(hdc), 124 | uintptr(iPartId), 125 | uintptr(iStateId), 126 | uintptr(unsafe.Pointer(pszText)), 127 | uintptr(iCharCount), 128 | uintptr(dwTextFlags), 129 | uintptr(unsafe.Pointer(pBoundingRect)), 130 | uintptr(unsafe.Pointer(pExtentRect))) 131 | 132 | return HRESULT(ret) 133 | } 134 | 135 | func OpenThemeData(hwnd HWND, pszClassList *uint16) HTHEME { 136 | ret, _, _ := syscall.Syscall(openThemeData, 2, 137 | uintptr(hwnd), 138 | uintptr(unsafe.Pointer(pszClassList)), 139 | 0) 140 | 141 | return HTHEME(ret) 142 | } 143 | 144 | func SetWindowTheme(hwnd HWND, pszSubAppName, pszSubIdList *uint16) HRESULT { 145 | ret, _, _ := syscall.Syscall(setWindowTheme, 3, 146 | uintptr(hwnd), 147 | uintptr(unsafe.Pointer(pszSubAppName)), 148 | uintptr(unsafe.Pointer(pszSubIdList))) 149 | 150 | return HRESULT(ret) 151 | } 152 | -------------------------------------------------------------------------------- /vendor/github.com/ssoor/winapi/win.go: -------------------------------------------------------------------------------- 1 | // Copyright 2010 The win Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // +build windows 6 | 7 | package winapi 8 | 9 | import ( 10 | "runtime" 11 | "syscall" 12 | "unsafe" 13 | ) 14 | 15 | func init() { 16 | runtime.LockOSThread() 17 | } 18 | 19 | const ( 20 | S_OK = 0x00000000 21 | S_FALSE = 0x00000001 22 | E_UNEXPECTED = 0x8000FFFF 23 | E_NOTIMPL = 0x80004001 24 | E_OUTOFMEMORY = 0x8007000E 25 | E_INVALIDARG = 0x80070057 26 | E_NOINTERFACE = 0x80004002 27 | E_POINTER = 0x80004003 28 | E_HANDLE = 0x80070006 29 | E_ABORT = 0x80004004 30 | E_FAIL = 0x80004005 31 | E_ACCESSDENIED = 0x80070005 32 | E_PENDING = 0x8000000A 33 | ) 34 | 35 | const ( 36 | FALSE = 0 37 | TRUE = 1 38 | ) 39 | 40 | type ( 41 | BOOL int32 42 | HRESULT int32 43 | ) 44 | 45 | func MustLoadLibrary(name string) uintptr { 46 | lib, err := syscall.LoadLibrary(name) 47 | if err != nil { 48 | panic(err) 49 | } 50 | 51 | return uintptr(lib) 52 | } 53 | 54 | func MustGetProcAddress(lib uintptr, name string) uintptr { 55 | addr, err := syscall.GetProcAddress(syscall.Handle(lib), name) 56 | if err != nil { 57 | panic(err) 58 | } 59 | 60 | return uintptr(addr) 61 | } 62 | 63 | func SUCCEEDED(hr HRESULT) bool { 64 | return hr >= 0 65 | } 66 | 67 | func FAILED(hr HRESULT) bool { 68 | return hr < 0 69 | } 70 | 71 | func MAKEWORD(lo, hi byte) uint16 { 72 | return uint16(uint16(lo) | ((uint16(hi)) << 8)) 73 | } 74 | 75 | func LOBYTE(w uint16) byte { 76 | return byte(w) 77 | } 78 | 79 | func HIBYTE(w uint16) byte { 80 | return byte(w >> 8 & 0xff) 81 | } 82 | 83 | func MAKELONG(lo, hi uint16) uint32 { 84 | return uint32(uint32(lo) | ((uint32(hi)) << 16)) 85 | } 86 | 87 | func LOWORD(dw uint32) uint16 { 88 | return uint16(dw) 89 | } 90 | 91 | func HIWORD(dw uint32) uint16 { 92 | return uint16(dw >> 16 & 0xffff) 93 | } 94 | 95 | func UTF16PtrToString(s *uint16) string { 96 | if s == nil { 97 | return "" 98 | } 99 | return syscall.UTF16ToString((*[1 << 29]uint16)(unsafe.Pointer(s))[0:]) 100 | } 101 | 102 | func MAKEINTRESOURCE(id uintptr) *uint16 { 103 | return (*uint16)(unsafe.Pointer(id)) 104 | } 105 | 106 | func BoolToBOOL(value bool) BOOL { 107 | if value { 108 | return 1 109 | } 110 | 111 | return 0 112 | } 113 | -------------------------------------------------------------------------------- /vendor/github.com/ssoor/winapi/wininet.go: -------------------------------------------------------------------------------- 1 | // Copyright 2011 The win Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // +build windows 6 | 7 | package winapi 8 | 9 | import ( 10 | "syscall" 11 | "unsafe" 12 | ) 13 | 14 | // 15 | // access types for InternetOpen() 16 | // 17 | const ( 18 | INTERNET_OPEN_TYPE_PRECONFIG uint32 = 0 // use registry configuration 19 | INTERNET_OPEN_TYPE_DIRECT = 1 // direct to net 20 | INTERNET_OPEN_TYPE_PROXY = 3 // via named proxy 21 | INTERNET_OPEN_TYPE_PRECONFIG_WITH_NO_AUTOPROXY = 4 // prevent using java/script/INS 22 | ) 23 | 24 | // 25 | // Options used in INTERNET_PER_CONN_OPTON struct 26 | // 27 | const ( 28 | INTERNET_PER_CONN_FLAGS uint32 = 1 29 | INTERNET_PER_CONN_PROXY_SERVER = 2 30 | INTERNET_PER_CONN_PROXY_BYPASS = 3 31 | INTERNET_PER_CONN_AUTOCONFIG_URL = 4 32 | INTERNET_PER_CONN_AUTODISCOVERY_FLAGS = 5 33 | INTERNET_PER_CONN_AUTOCONFIG_SECONDARY_URL = 6 34 | INTERNET_PER_CONN_AUTOCONFIG_RELOAD_DELAY_MINS = 7 35 | INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_TIME = 8 36 | INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_URL = 9 37 | INTERNET_PER_CONN_FLAGS_UI = 10 38 | ) 39 | 40 | // 41 | // PER_CONN_FLAGS 42 | // 43 | const ( 44 | PROXY_TYPE_DIRECT uint64 = 0x00000001 // direct to net 45 | PROXY_TYPE_PROXY = 0x00000002 // via named proxy 46 | PROXY_TYPE_AUTO_PROXY_URL = 0x00000004 // autoproxy URL 47 | PROXY_TYPE_AUTO_DETECT = 0x00000008 // use autoproxy detection 48 | ) 49 | 50 | const ( 51 | INTERNET_OPTION_REFRESH uint32 = 37 52 | INTERNET_OPTION_PER_CONNECTION_OPTION uint32 = 75 53 | ) 54 | 55 | type ( 56 | HINTERNET *byte 57 | ) 58 | 59 | // 60 | // INTERNET_PROXY_INFO - structure supplied with INTERNET_OPTION_PROXY to get/ 61 | // set proxy information on a InternetOpen() handle 62 | // 63 | type INTERNET_PROXY_INFO struct { 64 | dwAccessType uint32 65 | lpszProxy *uint16 66 | lpszProxyBypass *uint16 67 | } 68 | 69 | /* 70 | type FILETIME struct { 71 | dwLowDateTime uint32 72 | dwHighDateTime uint32 73 | } 74 | */ 75 | type INTERNET_PER_CONN_OPTION struct { 76 | Option uint32 // option to be queried or set // union 77 | Value uint64 // union 78 | } 79 | 80 | type INTERNET_PER_CONN_OPTION_LIST struct { 81 | Size uint32 // size of the INTERNET_PER_CONN_OPTION_LIST struct 82 | Connection *uint16 // connection name to set/query options 83 | OptionCount uint32 // number of options to set/query 84 | OptionError uint32 // on error, which option failed 85 | Options *INTERNET_PER_CONN_OPTION 86 | // array of options to set/query 87 | } 88 | 89 | var ( 90 | // Library 91 | libwininet uintptr 92 | 93 | // Functions 94 | internetSetOption uintptr 95 | ) 96 | 97 | func init() { 98 | // Library 99 | libwininet = MustLoadLibrary("wininet.dll") 100 | 101 | // Functions 102 | internetSetOption = MustGetProcAddress(libwininet, "InternetSetOptionW") 103 | } 104 | 105 | type InternetPtr interface{} 106 | 107 | func InternetSetOption(hInternet HINTERNET, dwOption uint32, interfaceBuffer InternetPtr, dwBufferLength uint32) bool { 108 | var lpBuffer unsafe.Pointer 109 | 110 | switch dwOption { 111 | case INTERNET_OPTION_PER_CONNECTION_OPTION: 112 | lpBuffer = unsafe.Pointer(interfaceBuffer.(*INTERNET_PER_CONN_OPTION_LIST)) 113 | } 114 | 115 | ret, _, _ := syscall.Syscall6(internetSetOption, 4, 116 | uintptr(unsafe.Pointer(hInternet)), 117 | uintptr(dwOption), 118 | uintptr(lpBuffer), 119 | uintptr(dwBufferLength), 120 | 0, 121 | 0) 122 | 123 | return (0 != ret) 124 | } 125 | -------------------------------------------------------------------------------- /vendor/github.com/ssoor/winapi/winspool.go: -------------------------------------------------------------------------------- 1 | // Copyright 2010 The win Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // +build windows 6 | 7 | package winapi 8 | 9 | import ( 10 | "syscall" 11 | "unsafe" 12 | ) 13 | 14 | // EnumPrinters flags 15 | const ( 16 | PRINTER_ENUM_DEFAULT = 0x00000001 17 | PRINTER_ENUM_LOCAL = 0x00000002 18 | PRINTER_ENUM_CONNECTIONS = 0x00000004 19 | PRINTER_ENUM_FAVORITE = 0x00000004 20 | PRINTER_ENUM_NAME = 0x00000008 21 | PRINTER_ENUM_REMOTE = 0x00000010 22 | PRINTER_ENUM_SHARED = 0x00000020 23 | PRINTER_ENUM_NETWORK = 0x00000040 24 | ) 25 | 26 | type PRINTER_INFO_4 struct { 27 | PPrinterName *uint16 28 | PServerName *uint16 29 | Attributes uint32 30 | } 31 | 32 | var ( 33 | // Library 34 | libwinspool uintptr 35 | 36 | // Functions 37 | deviceCapabilities uintptr 38 | documentProperties uintptr 39 | enumPrinters uintptr 40 | getDefaultPrinter uintptr 41 | ) 42 | 43 | func init() { 44 | // Library 45 | libwinspool = MustLoadLibrary("winspool.drv") 46 | 47 | // Functions 48 | deviceCapabilities = MustGetProcAddress(libwinspool, "DeviceCapabilitiesW") 49 | documentProperties = MustGetProcAddress(libwinspool, "DocumentPropertiesW") 50 | enumPrinters = MustGetProcAddress(libwinspool, "EnumPrintersW") 51 | getDefaultPrinter = MustGetProcAddress(libwinspool, "GetDefaultPrinterW") 52 | } 53 | 54 | func DeviceCapabilities(pDevice, pPort *uint16, fwCapability uint16, pOutput *uint16, pDevMode *DEVMODE) uint32 { 55 | ret, _, _ := syscall.Syscall6(deviceCapabilities, 5, 56 | uintptr(unsafe.Pointer(pDevice)), 57 | uintptr(unsafe.Pointer(pPort)), 58 | uintptr(fwCapability), 59 | uintptr(unsafe.Pointer(pOutput)), 60 | uintptr(unsafe.Pointer(pDevMode)), 61 | 0) 62 | 63 | return uint32(ret) 64 | } 65 | 66 | func DocumentProperties(hWnd HWND, hPrinter HANDLE, pDeviceName *uint16, pDevModeOutput, pDevModeInput *DEVMODE, fMode uint32) int32 { 67 | ret, _, _ := syscall.Syscall6(documentProperties, 6, 68 | uintptr(hWnd), 69 | uintptr(hPrinter), 70 | uintptr(unsafe.Pointer(pDeviceName)), 71 | uintptr(unsafe.Pointer(pDevModeOutput)), 72 | uintptr(unsafe.Pointer(pDevModeInput)), 73 | uintptr(fMode)) 74 | 75 | return int32(ret) 76 | } 77 | 78 | func EnumPrinters(Flags uint32, Name *uint16, Level uint32, pPrinterEnum *byte, cbBuf uint32, pcbNeeded, pcReturned *uint32) bool { 79 | ret, _, _ := syscall.Syscall9(enumPrinters, 7, 80 | uintptr(Flags), 81 | uintptr(unsafe.Pointer(Name)), 82 | uintptr(Level), 83 | uintptr(unsafe.Pointer(pPrinterEnum)), 84 | uintptr(cbBuf), 85 | uintptr(unsafe.Pointer(pcbNeeded)), 86 | uintptr(unsafe.Pointer(pcReturned)), 87 | 0, 88 | 0) 89 | 90 | return ret != 0 91 | } 92 | 93 | func GetDefaultPrinter(pszBuffer *uint16, pcchBuffer *uint32) bool { 94 | ret, _, _ := syscall.Syscall(getDefaultPrinter, 2, 95 | uintptr(unsafe.Pointer(pszBuffer)), 96 | uintptr(unsafe.Pointer(pcchBuffer)), 97 | 0) 98 | 99 | return ret != 0 100 | } 101 | --------------------------------------------------------------------------------