Skip to content

Commit

Permalink
same hardware in chatrequire and conversation
Browse files Browse the repository at this point in the history
  • Loading branch information
xqdoo00o committed May 1, 2024
1 parent 2ed1941 commit a288523
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 20 deletions.
2 changes: 1 addition & 1 deletion handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ func nightmare(c *gin.Context) {
}
var proofToken string
if chat_require.Proof.Required {
proofToken = chatgpt.CalcProofToken(chat_require.Proof.Seed, chat_require.Proof.Difficulty, proxy_url)
proofToken = chatgpt.CalcProofToken(chat_require, proxy_url)
}
// Convert the chat request to a ChatGPT request
translated_request := chatgpt_request_converter.ConvertAPIRequest(original_request, account, &secret, deviceId, chat_require.Arkose.Required, chat_require.Arkose.DX, proxy_url)
Expand Down
40 changes: 21 additions & 19 deletions internal/chatgpt/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ var (
FILES_REVERSE_PROXY = os.Getenv("FILES_REVERSE_PROXY")
connPool = map[string][]*connInfo{}
userAgent = "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36"
answers = map[string]string{}
cores = []int{8, 12, 16, 24}
screens = []int{3000, 4000, 6000}
timeLocation, _ = time.LoadLocation("Asia/Shanghai")
Expand Down Expand Up @@ -272,28 +271,29 @@ func getDpl(proxy string) bool {
})
return len(cachedScripts) != 0
}
func getConfig() []interface{} {
rand.New(rand.NewSource(time.Now().UnixNano()))
core := cores[rand.Intn(4)]
rand.New(rand.NewSource(time.Now().UnixNano()))
screen := screens[rand.Intn(3)]
func getConfig(hardware int) []interface{} {
if hardware == 0 {
rand.New(rand.NewSource(time.Now().UnixNano()))
core := cores[rand.Intn(4)]
rand.New(rand.NewSource(time.Now().UnixNano()))
screen := screens[rand.Intn(3)]
hardware = core + screen
}
rand.New(rand.NewSource(time.Now().UnixNano()))
script := cachedScripts[rand.Intn(len(cachedScripts))]
return []interface{}{core + screen, getParseTime(), int64(4294705152), 0, userAgent, script, cachedDpl, "zh-CN", "zh-CN,en,en-GB,en-US"}
return []interface{}{hardware, getParseTime(), int64(4294705152), 0, userAgent, script, cachedDpl, "zh-CN", "zh-CN,en,en-GB,en-US"}

}
func CalcProofToken(seed string, diff string, proxy string) string {
if answers[seed] != "" {
return "gAAAAAB" + answers[seed]
}
return "gAAAAAB" + generateAnswer(seed, diff, proxy)
func CalcProofToken(require *ChatRequire, proxy string) string {
proof, _ := generateAnswer(require.Proof.Seed, require.Proof.Difficulty, require.Hardware, proxy)
return "gAAAAAB" + proof
}

func generateAnswer(seed string, diff string, proxy string) string {
func generateAnswer(seed string, diff string, hardware int, proxy string) (string, int) {
if !getDpl(proxy) {
return "wQ8Lk5FbGpA2NcR9dShT6gYjU7VxZ4D" + base64.StdEncoding.EncodeToString([]byte(`"`+seed+`"`))
return "wQ8Lk5FbGpA2NcR9dShT6gYjU7VxZ4D" + base64.StdEncoding.EncodeToString([]byte(`"`+seed+`"`)), 0
}
config := getConfig()
config := getConfig(hardware)
diffLen := len(diff) / 2
hasher := sha3.New512()
for i := 0; i < 1000000; i++ {
Expand All @@ -304,11 +304,10 @@ func generateAnswer(seed string, diff string, proxy string) string {
hash := hasher.Sum(nil)
hasher.Reset()
if hex.EncodeToString(hash[:diffLen]) <= diff {
answers[seed] = base
return answers[seed]
return base, config[0].(int)
}
}
return "wQ8Lk5FbGpA2NcR9dShT6gYjU7VxZ4D" + base64.StdEncoding.EncodeToString([]byte(`"`+seed+`"`))
return "wQ8Lk5FbGpA2NcR9dShT6gYjU7VxZ4D" + base64.StdEncoding.EncodeToString([]byte(`"`+seed+`"`)), config[0].(int)
}

type ChatRequire struct {
Expand All @@ -318,13 +317,15 @@ type ChatRequire struct {
Required bool `json:"required"`
DX string `json:"dx,omitempty"`
} `json:"arkose"`
Hardware int
}

func CheckRequire(secret *tokens.Secret, deviceId string, proxy string) *ChatRequire {
if proxy != "" {
client.SetProxy(proxy)
}
body := bytes.NewBuffer([]byte(`{"p":"` + "gAAAAAC" + generateAnswer(strconv.FormatFloat(rand.Float64(), 'f', -1, 64), "0", proxy) + `"}`))
proof, hardware := generateAnswer(strconv.FormatFloat(rand.Float64(), 'f', -1, 64), "0", 0, proxy)
body := bytes.NewBuffer([]byte(`{"p":"` + "gAAAAAC" + proof + `"}`))
var apiUrl string
if secret.Token == "" {
apiUrl = "https://chat.openai.com/backend-anon/sentinel/chat-requirements"
Expand All @@ -346,6 +347,7 @@ func CheckRequire(secret *tokens.Secret, deviceId string, proxy string) *ChatReq
if err != nil {
return nil
}
require.Hardware = hardware
return &require
}

Expand Down

0 comments on commit a288523

Please sign in to comment.