-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit db8d0bf
Showing
13 changed files
with
299 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# Auto detect text files and perform LF normalization | ||
* text=auto |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
main: main.go | ||
go build ./main.go |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
function FindProxyForURL(url, host) | ||
{ | ||
proxy = "PROXY discord.cnnblike.com:9092"; | ||
if (shExpMatch(url, "\/index\.php\/(\d{4}?)\/Index\/index") && ((shExpMatch(host,"gf-(adrgw|ios)-cn-zs-game-0001\.ppgame\.com") || shExpMatch(host, "s\d{1,2}\.(gw|ios)\.gf\.game\.com")))) | ||
return proxy; | ||
return "DIRECT"; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
function FindProxyForURL(url, host) | ||
{ | ||
proxy = "PROXY discord.cnnblike.com:9091"; | ||
if (shExpMatch(host, "version.jr.moefantasy.com")) | ||
return proxy; | ||
return "DIRECT"; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
function FindProxyForURL(url, host) | ||
{ | ||
proxy = "PROXY discord.cnnblike.com:9090"; | ||
if (shExpMatch(host, "version.jr.moefantasy.com")) | ||
return proxy; | ||
if (shExpMatch(host,"version.channel.jr.moefantasy.com")) | ||
return proxy; | ||
return "DIRECT"; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
{ | ||
"comment": "for mobile game GirlsFroneline, enable you to access iOS server on Android", | ||
"port": 9094, | ||
"modifiers": [{ | ||
"filter": { | ||
"host": "^adr\\.transit\\.gf\\.ppgame\\.com$", | ||
"url": "index.php$"}, | ||
"rules": [{ | ||
"hook": "onRequest", | ||
"target": "url", | ||
"pattern": "adr", | ||
"replacement": "ios" | ||
}, { | ||
"hook": "onRequest", | ||
"target": "body", | ||
"pattern": "channel=cn_mica", | ||
"replacement": "channel=cn_appstore" | ||
}, { | ||
"hook": "onRequest", | ||
"target": "platformChannelId=GWGW", | ||
"replacement": "platformChannelId=ios" | ||
}] | ||
}] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"comment": "decensorship for mobile game GirlsFrontline", | ||
"port": 9092, | ||
"modifiers": [{ | ||
"filter": { | ||
"host": ".*\\.ppgame\\.com$", | ||
"url": "index.php/1000/Index/index$"}, | ||
"rules": [{ | ||
"hook": "onResponse", | ||
"target": "body", | ||
"pattern": "\"naive_build_gun_formula\":\"(\\d+:\\d+:\\d+:\\d+)?\"", | ||
"replacement": "\"naive_build_gun_formula\":\"33:33:33:33\"" | ||
}] | ||
}] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
{ | ||
"comment": "for mobile game GirlsFroneline, enable you to access Android server on iPhone", | ||
"port": 9093, | ||
"modifiers": [{ | ||
"filter": { | ||
"host": "^ios\\.transit\\.gf\\.ppgame\\.com$", | ||
"url": "index.php$"}, | ||
"rules": [{ | ||
"hook": "onRequest", | ||
"target": "url", | ||
"pattern": "ios", | ||
"replacement": "adr" | ||
}, { | ||
"hook": "onRequest", | ||
"target": "body", | ||
"pattern": "channel=cn_appstore", | ||
"replacement": "channel=cn_mica" | ||
}, { | ||
"hook": "onRequest", | ||
"target": "platformChannelId=ios", | ||
"replacement": "platformChannelId=GWGW" | ||
}] | ||
}] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"comment": "decensorship for mobile game WarShipGirls", | ||
"port": 9090, | ||
"modifiers": [{ | ||
"filter": { | ||
"host": "^version(\\.channel)?\\.jr\\.moefantasy\\.com$", | ||
"url": "index/checkVer"}, | ||
"rules": [{ | ||
"hook": "onResponse", | ||
"target": "body", | ||
"pattern": "\"cheatsCheck\":0", | ||
"replacement": "\"cheatsCheck\":1" | ||
}] | ||
}] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
{ | ||
"comment": "for mobile game WarShipGirls, enable you to access Android server on iPhone", | ||
"port": 9091, | ||
"modifiers": [{ | ||
"filter": { | ||
"host": "^version\\.jr\\.moefantasy\\.com$", | ||
"url": "index/checkVer"}, | ||
"rules": [{ | ||
"hook": "onRequest", | ||
"target": "url", | ||
"pattern": "100020", | ||
"replacement": "100021" | ||
}, { | ||
"hook": "onResponse", | ||
"target": "body", | ||
"pattern": "\"cheatsCheck\":0", | ||
"replacement": "\"cheatsCheck\":1" | ||
}] | ||
}] | ||
} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,170 @@ | ||
package main | ||
|
||
import ( | ||
"bytes" | ||
"encoding/json" | ||
"io/ioutil" | ||
"log" | ||
"net" | ||
"net/http" | ||
"os" | ||
"path/filepath" | ||
"regexp" | ||
"strconv" | ||
"strings" | ||
|
||
"github.com/elazarl/goproxy" | ||
) | ||
|
||
func GetLocalIP() string { | ||
conn, err := net.Dial("udp", "1.2.4.8:53") | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
defer conn.Close() | ||
localAddr := conn.LocalAddr().(*net.UDPAddr) | ||
return localAddr.IP.String() | ||
} | ||
|
||
type rule struct { | ||
Hook string `json: "hook"` | ||
Target string `json: "target"` | ||
Pattern string `json: "pattern"` | ||
Replacement string `json: "replacement"` | ||
} | ||
type filter struct { | ||
Host string `json: "host"` | ||
Url string `json: "url"` | ||
} | ||
type compiledFilter struct { | ||
Host *regexp.Regexp | ||
Url *regexp.Regexp | ||
} | ||
type modifier struct { | ||
Filter filter `json: "filter"` | ||
Rules []rule `json: "rules"` | ||
} | ||
|
||
type config struct { | ||
Comment string `json: "comment"` | ||
Port int `json: "port"` | ||
Modifiers []modifier `json: "modifiers"` | ||
} | ||
|
||
func readConfigs() []config { | ||
configPath := "." + string(filepath.Separator) + "config" | ||
files, _ := ioutil.ReadDir(configPath) | ||
result := make([]config, 0) | ||
for _, file := range files { | ||
if (!file.IsDir()) && (strings.HasSuffix(file.Name(), ".json")) { | ||
raw, err := ioutil.ReadFile(configPath + string(filepath.Separator) + file.Name()) | ||
if err != nil { | ||
panic(err) | ||
} | ||
tmp := new(config) | ||
json.Unmarshal(raw, &tmp) | ||
result = append(result, *tmp) | ||
} | ||
} | ||
return result | ||
} | ||
|
||
func ReqMatches(filters ...*compiledFilter) goproxy.ReqConditionFunc { | ||
return func(req *http.Request, ctx *goproxy.ProxyCtx) bool { | ||
for _, compiled := range filters { | ||
if compiled.Host.MatchString(req.Host) && compiled.Url.MatchString(req.URL.Path) { | ||
return true | ||
} | ||
} | ||
return false | ||
} | ||
} | ||
|
||
func filterCompiler(f filter) *compiledFilter { | ||
result := new(compiledFilter) | ||
result.Host = regexp.MustCompile(f.Host) | ||
result.Url = regexp.MustCompile(f.Url) | ||
return result | ||
} | ||
|
||
func main() { | ||
configs := readConfigs() | ||
proxies := make([]*goproxy.ProxyHttpServer, len(configs)) | ||
for i, config := range configs { | ||
proxies[i] = goproxy.NewProxyHttpServer() | ||
compiledFilters := make([]*compiledFilter, 0) | ||
for _, modify := range config.Modifiers { | ||
tmpCompiled := filterCompiler(modify.Filter) | ||
compiledFilters = append(compiledFilters, tmpCompiled) | ||
// onRequest here | ||
rs := make([]rule, 0) | ||
for _, r := range modify.Rules { | ||
if r.Hook == "onRequest" { | ||
rs = append(rs, r) | ||
} | ||
} | ||
proxies[i].OnRequest(ReqMatches(tmpCompiled)).DoFunc( | ||
func(req *http.Request, ctx *goproxy.ProxyCtx) (*http.Request, *http.Response) { | ||
// modify to get new request here. | ||
for _, r := range rs { | ||
if r.Target == "url" { | ||
req.URL.Host = string(regexp.MustCompile(r.Pattern).ReplaceAll([]byte(req.URL.Host), []byte(r.Replacement))) | ||
req.URL.Path = string(regexp.MustCompile(r.Pattern).ReplaceAll([]byte(req.URL.Path), []byte(r.Replacement))) | ||
} else if r.Target == "body" { | ||
body, err := ioutil.ReadAll(req.Body) | ||
if err == nil { | ||
modifiedBody := regexp.MustCompile(r.Pattern).ReplaceAll(body, []byte(r.Replacement)) | ||
req.Body = ioutil.NopCloser(bytes.NewBuffer(modifiedBody)) | ||
} | ||
} | ||
} | ||
return req, nil | ||
}) | ||
} | ||
if len(os.Args) > 1 && os.Args[1] == "server" { | ||
proxies[i].Verbose = false | ||
proxies[i].OnRequest(goproxy.Not(ReqMatches(compiledFilters...))).DoFunc( // allow the request we need only | ||
func(r *http.Request, ctx *goproxy.ProxyCtx) (*http.Request, *http.Response) { | ||
return r, goproxy.NewResponse(r, goproxy.ContentTypeText, http.StatusForbidden, "abuse of this vps is not allowed!") | ||
}) | ||
proxies[i].OnRequest(goproxy.Not(goproxy.ReqHostMatches(regexp.MustCompile(":80$")))).HandleConnect(goproxy.AlwaysReject) // forbid every non-80 port | ||
} else { | ||
proxies[i].Verbose = true | ||
} | ||
} | ||
|
||
if len(os.Args) > 1 && os.Args[1] == "server" { | ||
log.Println("sfc9982-GFResProxy, working in server mode") | ||
} else { | ||
log.Println("sfc9982-GFResProxy, working in PC mode") | ||
} | ||
|
||
for i, config := range configs { | ||
for _, modify := range config.Modifiers { | ||
tmpCompiled := filterCompiler(modify.Filter) | ||
rs := make([]rule, 0) | ||
for _, r := range modify.Rules { | ||
if r.Hook == "onResponse" { | ||
rs = append(rs, r) | ||
} | ||
} | ||
proxies[i].OnResponse(ReqMatches(tmpCompiled)).DoFunc( | ||
func(resp *http.Response, ctx *goproxy.ProxyCtx) *http.Response { | ||
for _, r := range rs { | ||
if r.Target == "body" { | ||
body, err := ioutil.ReadAll(resp.Body) | ||
if err == nil { | ||
modifiedBody := regexp.MustCompile(r.Pattern).ReplaceAll(body, []byte(r.Replacement)) | ||
resp.Body = ioutil.NopCloser(bytes.NewBuffer(modifiedBody)) | ||
} | ||
} | ||
} | ||
return resp | ||
}) | ||
} | ||
log.Printf("Proxy #%d, address: %s:%d, %s", i, GetLocalIP(), config.Port, config.Comment) | ||
go http.ListenAndServe(":"+strconv.Itoa(config.Port), proxies[i]) | ||
} | ||
http.Handle("/", http.FileServer(http.Dir("."+string(filepath.Separator)+"PACFile"))) | ||
http.ListenAndServe(":3000", nil) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
@ECHO OFF | ||
TITLE ¸ńŔďˇŇҤ×Ó By:sfc9982 | ||
.\main.exe | ||
PAUSE |