From 03904879a78363164262ed0311f950e07207d6e0 Mon Sep 17 00:00:00 2001 From: Woshiluo Luo Date: Sun, 1 May 2022 01:07:37 +0800 Subject: [PATCH 1/8] fix: can not find csrf --- client/login.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/login.go b/client/login.go index bb7f9d8d..d6453703 100644 --- a/client/login.go +++ b/client/login.go @@ -43,7 +43,7 @@ func findHandle(body []byte) (string, error) { } func findCsrf(body []byte) (string, error) { - reg := regexp.MustCompile(`csrf='(.+?)'`) + reg := regexp.MustCompile(`csrf="(.+?)"`) tmp := reg.FindSubmatch(body) if len(tmp) < 2 { return "", errors.New("Cannot find csrf") From 4a7203e916203d24bf8b424532efc96529a79588 Mon Sep 17 00:00:00 2001 From: Woshiluo Luo Date: Sun, 1 May 2022 12:11:41 +0800 Subject: [PATCH 2/8] fix: auto add RCPC --- util/util.go | 44 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) diff --git a/util/util.go b/util/util.go index e8e0210f..ceee9c3e 100644 --- a/util/util.go +++ b/util/util.go @@ -2,6 +2,7 @@ package util import ( "bufio" + "encoding/hex" "encoding/json" "fmt" "io/ioutil" @@ -11,7 +12,10 @@ import ( "net/url" "os" "strconv" + "regexp" "strings" + "crypto/aes" + "crypto/cipher" "github.com/fatih/color" ) @@ -72,6 +76,38 @@ func YesOrNo(note string) bool { } } +// GetBody read body +func SetRCPC(client *http.Client, body []byte, URL string) ([]byte, error) { + reg := regexp.MustCompile(`toNumbers\("(.+?)"\)`) + res := reg.FindAllStringSubmatch(string(body), -1) + text, _ := hex.DecodeString( res[2][1] ) + key, _ := hex.DecodeString( res[0][1] ) + iv, _ := hex.DecodeString( res[1][1] ) + + block, _ := aes.NewCipher(key) + mode := cipher.NewCBCDecrypter(block, iv) + + mode.CryptBlocks([]byte(text), []byte(text)) + + fmt.Println(hex.EncodeToString(text)); + + var cookies []*http.Cookie + cookie := &http.Cookie{ + Name: "RCPC", + Value: hex.EncodeToString(text), + Path: "/", + Domain: ".codeforces.com", + } + cookies = append(cookies, cookie) + u, _ := url.Parse("https://codeforces.com/") + client.Jar.SetCookies(u, cookies) + + reg = regexp.MustCompile(`href="(.+?)"`) + tmp := reg.FindSubmatch(body) + fmt.Println(string(tmp[1])); + return GetBody(client, string(tmp[1]) ) +} + // GetBody read body func GetBody(client *http.Client, URL string) ([]byte, error) { resp, err := client.Get(URL) @@ -79,7 +115,13 @@ func GetBody(client *http.Client, URL string) ([]byte, error) { return nil, err } defer resp.Body.Close() - return ioutil.ReadAll(resp.Body) + body, err := ioutil.ReadAll(resp.Body); + reg := regexp.MustCompile(`Redirecting...`) + is_redirected := ( len( reg.FindSubmatch(body) ) > 0 ); + if is_redirected { + return SetRCPC(client, body, URL) + } + return body, err } // PostBody read post body From 3feb18a5d76cd2a34cf3818fc0486e0043dcec02 Mon Sep 17 00:00:00 2001 From: Woshiluo Luo Date: Sun, 1 May 2022 12:15:57 +0800 Subject: [PATCH 3/8] fix: remove debug log --- util/util.go | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/util/util.go b/util/util.go index ceee9c3e..3c066c9b 100644 --- a/util/util.go +++ b/util/util.go @@ -89,8 +89,6 @@ func SetRCPC(client *http.Client, body []byte, URL string) ([]byte, error) { mode.CryptBlocks([]byte(text), []byte(text)) - fmt.Println(hex.EncodeToString(text)); - var cookies []*http.Cookie cookie := &http.Cookie{ Name: "RCPC", @@ -103,9 +101,8 @@ func SetRCPC(client *http.Client, body []byte, URL string) ([]byte, error) { client.Jar.SetCookies(u, cookies) reg = regexp.MustCompile(`href="(.+?)"`) - tmp := reg.FindSubmatch(body) - fmt.Println(string(tmp[1])); - return GetBody(client, string(tmp[1]) ) + link := reg.FindSubmatch(body)[1] + return GetBody( client, string(link) ) } // GetBody read body From 992c95070816ed6539f02dacf95e5a340ba334ee Mon Sep 17 00:00:00 2001 From: Woshiluo Luo Date: Sun, 1 May 2022 12:19:40 +0800 Subject: [PATCH 4/8] fix: auto add RCPC while using POST --- util/util.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/util/util.go b/util/util.go index 3c066c9b..7efa1e53 100644 --- a/util/util.go +++ b/util/util.go @@ -123,6 +123,9 @@ func GetBody(client *http.Client, URL string) ([]byte, error) { // PostBody read post body func PostBody(client *http.Client, URL string, data url.Values) ([]byte, error) { + // TODO: Rewrite to avoid visit this page + GetBody( client, "https://codeforces.com" ); + resp, err := client.PostForm(URL, data) if err != nil { return nil, err @@ -133,6 +136,8 @@ func PostBody(client *http.Client, URL string, data url.Values) ([]byte, error) // GetJSONBody read json body func GetJSONBody(client *http.Client, url string) (map[string]interface{}, error) { + GetBody( client, "https://codeforces.com" ); + resp, err := client.Get(url) if err != nil { return nil, err From af7a8d69f1904fa101d0697d9e456b3e05ca66be Mon Sep 17 00:00:00 2001 From: Woshiluo Luo Date: Sun, 1 May 2022 12:24:21 +0800 Subject: [PATCH 5/8] fix: revert 03904879a78363164262ed0311f950e07207d6e0 --- client/login.go | 2 +- util/util.go | 4 +--- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/client/login.go b/client/login.go index d6453703..bb7f9d8d 100644 --- a/client/login.go +++ b/client/login.go @@ -43,7 +43,7 @@ func findHandle(body []byte) (string, error) { } func findCsrf(body []byte) (string, error) { - reg := regexp.MustCompile(`csrf="(.+?)"`) + reg := regexp.MustCompile(`csrf='(.+?)'`) tmp := reg.FindSubmatch(body) if len(tmp) < 2 { return "", errors.New("Cannot find csrf") diff --git a/util/util.go b/util/util.go index 7efa1e53..40325992 100644 --- a/util/util.go +++ b/util/util.go @@ -115,6 +115,7 @@ func GetBody(client *http.Client, URL string) ([]byte, error) { body, err := ioutil.ReadAll(resp.Body); reg := regexp.MustCompile(`Redirecting...`) is_redirected := ( len( reg.FindSubmatch(body) ) > 0 ); + if is_redirected { return SetRCPC(client, body, URL) } @@ -123,8 +124,6 @@ func GetBody(client *http.Client, URL string) ([]byte, error) { // PostBody read post body func PostBody(client *http.Client, URL string, data url.Values) ([]byte, error) { - // TODO: Rewrite to avoid visit this page - GetBody( client, "https://codeforces.com" ); resp, err := client.PostForm(URL, data) if err != nil { @@ -136,7 +135,6 @@ func PostBody(client *http.Client, URL string, data url.Values) ([]byte, error) // GetJSONBody read json body func GetJSONBody(client *http.Client, url string) (map[string]interface{}, error) { - GetBody( client, "https://codeforces.com" ); resp, err := client.Get(url) if err != nil { From f117fcead800d87591d55eafae97ab74127cd7e5 Mon Sep 17 00:00:00 2001 From: Woshiluo Luo Date: Mon, 2 May 2022 09:47:15 +0800 Subject: [PATCH 6/8] feat: add cpp20 --- client/langs.go | 2 ++ util/util.go | 2 -- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/client/langs.go b/client/langs.go index b09c69fd..6253e696 100644 --- a/client/langs.go +++ b/client/langs.go @@ -9,6 +9,7 @@ var Langs = map[string]string{ "42": "GNU G++11 5.1.0", "50": "GNU G++14 6.4.0", "54": "GNU G++17 7.3.0", + "73": "GNU G++20 11.2.0 (64 bit, winlibs)", "2": "Microsoft Visual C++ 2010", "59": "Microsoft Visual C++ 2017", "9": "C# Mono 5.18", @@ -60,6 +61,7 @@ var LangsExt = map[string]string{ "GNU C++11": "cpp", "GNU C++14": "cpp", "GNU C++17": "cpp", + "GNU G++20": "cpp", "MS C++": "cpp", "MS C++ 2017": "cpp", "Mono C#": "cs", diff --git a/util/util.go b/util/util.go index 40325992..6ec7ef56 100644 --- a/util/util.go +++ b/util/util.go @@ -124,7 +124,6 @@ func GetBody(client *http.Client, URL string) ([]byte, error) { // PostBody read post body func PostBody(client *http.Client, URL string, data url.Values) ([]byte, error) { - resp, err := client.PostForm(URL, data) if err != nil { return nil, err @@ -135,7 +134,6 @@ func PostBody(client *http.Client, URL string, data url.Values) ([]byte, error) // GetJSONBody read json body func GetJSONBody(client *http.Client, url string) (map[string]interface{}, error) { - resp, err := client.Get(url) if err != nil { return nil, err From 5b3c94682a1cdf2976dc9f23311f210f79830541 Mon Sep 17 00:00:00 2001 From: Woshiluo Luo Date: Mon, 2 May 2022 11:01:11 +0800 Subject: [PATCH 7/8] bump: v1.0.1 --- cf.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cf.go b/cf.go index 44290328..5c319838 100644 --- a/cf.go +++ b/cf.go @@ -15,7 +15,7 @@ import ( docopt "github.com/docopt/docopt-go" ) -const version = "v1.0.0" +const version = "v1.0.1" const configPath = "~/.cf/config" const sessionPath = "~/.cf/session" @@ -63,7 +63,7 @@ Examples: cf submit cf will detect what you want to submit automatically. cf submit -f a.cpp cf submit https://codeforces.com/contest/100/A - cf submit -f a.cpp 100A + cf submit -f a.cpp 100A cf submit -f a.cpp 100 a cf submit contest 100 a cf submit gym 100001 a From 762f8a5d3ef327b780e40bba29853a4dd712b139 Mon Sep 17 00:00:00 2001 From: Woshiluo Luo Date: Tue, 16 Aug 2022 08:47:31 +0800 Subject: [PATCH 8/8] fix: wrong sample input when the origin has color block --- client/parse.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/client/parse.go b/client/parse.go index 382b7345..0792d045 100644 --- a/client/parse.go +++ b/client/parse.go @@ -26,9 +26,11 @@ func findSample(body []byte) (input [][]byte, output [][]byte, err error) { if a == nil || b == nil || len(a) != len(b) { return nil, nil, fmt.Errorf("Cannot parse sample with input %v and output %v", len(a), len(b)) } - newline := regexp.MustCompile(`<[\s/br]+?>`) + startline := regexp.MustCompile(`<[\s\S.]+?>`) + endline := regexp.MustCompile(``) filter := func(src []byte) []byte { - src = newline.ReplaceAll(src, []byte("\n")) + src = endline.ReplaceAll(src, []byte("\n")) + src = startline.ReplaceAll(src, []byte("")) s := html.UnescapeString(string(src)) return []byte(strings.TrimSpace(s) + "\n") }