From 59145d4eb02c5759a0637a601aa5fe7cfb5c3921 Mon Sep 17 00:00:00 2001 From: Huan Du Date: Thu, 18 Aug 2016 23:34:06 +0800 Subject: [PATCH] add doc for hack tool --- hack/README.md | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 hack/README.md diff --git a/hack/README.md b/hack/README.md new file mode 100644 index 0000000..4045a06 --- /dev/null +++ b/hack/README.md @@ -0,0 +1,24 @@ +# Hack Go Runtime # + +This is a hack tool to copy const and type declarations from go source and inject hacked code. +With this hack, it's possible to expose any interesting type to wild world. + +## Play with it ## + +Download a go src tar file from https://golang.org/dl/, extract all files to a folder and +run following command. + + ./hack.sh path-to-go-src + +## How it works ## + +The basic idea is quite simple: If we can get internal type declarations and make it public, +then we can use it easily. So what I do is to parse all interesting go source files and copy +types to a folder and inject some hacked code to make some types public. + +The `generator.go` is the key file to make it happen. It loads all hacks and walk through +all AST tree nodes in a file to find out all constants and types. It works quite well with +internal package and ignored files, as these features are required for go1.6 and greater. + +There is only 1 hack implemented in `runtime_hacker.go`. If we want to add more hacks, just +implement more hacker files.