Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,7 @@ Based on the [hirochachacha/go-smb2 fork](https://github.com/oiweiwei/go-smb2.fo
| Spec | Description | Package |
|------|-------------|---------|
| [MIMICOM](https://gist.github.com/gentilkiwi/e3d9c92b93ed4bb48f7956492c1d335a) | Mimikatz Command Interface | [msrpc/mimicom](./msrpc/mimicom) |
| [MS-LCID](https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-lcid) | Windows Language Code Identifier (LCID) Reference | [msrpc/lcid](./msrpc/lcid) |

### Documentation

Expand Down
3 changes: 2 additions & 1 deletion examples/even6.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import (

_ "github.com/oiweiwei/go-msrpc/msrpc/erref/hresult"
"github.com/oiweiwei/go-msrpc/msrpc/erref/win32"
"github.com/oiweiwei/go-msrpc/msrpc/lcid"
)

func init() {
Expand Down Expand Up @@ -184,7 +185,7 @@ func Metadata(ctx context.Context, cli ieventservice.EventServiceClient) {

meta, err := cli.GetPublisherMetadata(ctx, &ieventservice.GetPublisherMetadataRequest{
PublisherID: pbl,
Locale: 1033,
Locale: (uint32)(lcid.LangEN_US),
})

if err != nil {
Expand Down
3 changes: 2 additions & 1 deletion examples/samples_with_config/even6.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (

_ "github.com/oiweiwei/go-msrpc/msrpc/erref/hresult"
"github.com/oiweiwei/go-msrpc/msrpc/erref/win32"
"github.com/oiweiwei/go-msrpc/msrpc/lcid"
)

var (
Expand Down Expand Up @@ -180,7 +181,7 @@ func Metadata(ctx context.Context, cli ieventservice.EventServiceClient) {

meta, err := cli.GetPublisherMetadata(ctx, &ieventservice.GetPublisherMetadataRequest{
PublisherID: pbl,
Locale: 1033,
Locale: (uint32)(lcid.LangEN_US),
})

if err != nil {
Expand Down
152 changes: 152 additions & 0 deletions msrpc/lcid/gen/gen.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
package main

import (
"bytes"
"flag"
"fmt"
"go/format"
"net/http"
"os"
"strconv"
"strings"

"github.com/PuerkitoBio/goquery"
)

const defaultURL = "https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-lcid/63d3d639-7fd2-4afb-abbe-0d5b5551eef8"

var out, pkg, url string

func init() {
flag.StringVar(&out, "o", "-", "output file")
flag.StringVar(&pkg, "pkg", "lcid", "output package")
flag.StringVar(&url, "url", defaultURL, "target url")
flag.Parse()
}

type LCID struct {
ID string
Tag string
Code string
}

type P struct {
bytes.Buffer
}

func (p *P) P(args ...interface{}) {
fmt.Fprintln(&p.Buffer, args...)
}

func main() {
lcids, err := collect(url)
if err != nil {
fmt.Printf("collect: %v\n", err)
return
}

pp := &P{}
p := pp.P
p("// Code generated by github.com/oiweiwei/go-msrpc/msrpc/lcid/gen/gen.go; DO NOT EDIT.")
p("package", pkg)
p()
p("const", "(")

for _, lcid := range lcids {
ui, err := strconv.ParseUint(lcid.ID, 0, 32)
if err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
p("Lang"+lcid.Code, "LCID", "=", ui, "//", lcid.Tag, "("+lcid.ID+")")
}
p(")")

p()
p("var langToTag = map[LCID]string{")
for _, lcid := range lcids {
p("Lang"+lcid.Code+":", strconv.Quote(strings.ToLower(lcid.Tag))+",")
}
p("}")

b, err := format.Source(pp.Bytes())
if err != nil {
fmt.Fprintln(os.Stderr, err)
fmt.Fprintln(os.Stderr, pp.String())
os.Exit(1)
}

f := os.Stdout

switch out {
case "-", "stdout":
default:
f, err = os.OpenFile(out, os.O_RDWR|os.O_TRUNC|os.O_CREATE, 0644)
if err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
}

fmt.Fprintln(f, string(b))

}

func collect(url string) ([]*LCID, error) {

req, err := http.NewRequest(http.MethodGet, url, nil)
if err != nil {
return nil, fmt.Errorf("create request: %w", err)
}

req.Header = make(http.Header)

resp, err := http.DefaultClient.Do(req)
if err != nil {
return nil, fmt.Errorf("do request: %w", err)
}

defer resp.Body.Close()

if resp.StatusCode != 200 {
return nil, fmt.Errorf("http: %s: %s", url, resp.Status)
}

doc, err := goquery.NewDocumentFromReader(resp.Body)
if err != nil {
return nil, fmt.Errorf("parse html: %w", err)
}

lcid := make([]*LCID, 0)

doc.Find(`table tr`).Each(func(i int, s *goquery.Selection) {
var id, tag string
s.Find("td").Each(func(j int, td *goquery.Selection) {
if j == 0 {
id = strings.TrimSpace(td.Text())
if len(id) >= 10 {
id = id[:10]
} else if len(id) >= 6 {
id = id[:6]
}
} else if j == 1 {
tag, _, _ = strings.Cut(strings.TrimSpace(td.Text()), " ")
tag = strings.TrimRight(tag, ",")

if strings.HasPrefix(id, "0x") && !ignore[strings.ToLower(tag)] {
lcid = append(lcid, &LCID{ID: id, Tag: tag, Code: strings.ToUpper(strings.ReplaceAll(tag, "-", "_"))})
}
}

})
})

return lcid, nil
}

var ignore = map[string]bool{
"unassigned": true,
"reserved": true,
"neither": true,
"locale": true,
}
Loading