From: qydysky Date: Sat, 10 Apr 2021 16:35:10 +0000 (+0800) Subject: 小心心加密可选择nodejs服务 X-Git-Tag: v0.5.9~1^2~31 X-Git-Url: http://127.0.0.1:8081/?a=commitdiff_plain;h=1d2dd1391c8f1be2f13638416339ef082974a9dd;p=bili_danmu%2F.git 小心心加密可选择nodejs服务 --- diff --git a/.gitignore b/.gitignore index 9eb9905..774147d 100644 --- a/.gitignore +++ b/.gitignore @@ -18,3 +18,4 @@ demo/ui/*.glade~ demo/tts.mp3 demo/cpu.pprof demo/qr.png +demo/live diff --git a/F/api.go b/F/api.go index 3d63743..93dc031 100644 --- a/F/api.go +++ b/F/api.go @@ -1763,6 +1763,7 @@ func F_x25Kn() { Benchmark:res.Data.Secret_key, Time:res.Data.Heartbeat_interval, Ts:int(p.Sys().GetMTime()), + Ua:`Mozilla/5.0 (X11; Linux x86_64; rv:84.0) Gecko/20100101 Firefox/84.0`, }, T:res.Data.Secret_rule, } @@ -1775,7 +1776,7 @@ func F_x25Kn() { PostStr += `&ts=`+strconv.Itoa(rt_obj.R.Ts) PostStr += `&is_patch=0&` PostStr += `heart_beat=[]&` - PostStr += `ua=Mozilla/5.0 (X11; Linux x86_64; rv:84.0) Gecko/20100101 Firefox/84.0&` + PostStr += `ua=`+rt_obj.R.Ua+`&` PostStr += `csrf_token=`+csrf+`&csrf=`+csrf+`&` PostStr += `visit_id=` diff --git a/F/xinxin.go b/F/xinxin.go index 9962879..e3ea50e 100644 --- a/F/xinxin.go +++ b/F/xinxin.go @@ -2,12 +2,14 @@ package F import ( "net/http" + "strconv" "encoding/json" "time" "github.com/skratchdot/open-golang/open" websocket "github.com/qydysky/part/websocket" msgq "github.com/qydysky/part/msgq" web "github.com/qydysky/part/web" + p "github.com/qydysky/part" c "github.com/qydysky/bili_danmu/CV" ) @@ -23,6 +25,7 @@ type R struct { Benchmark string `json:"benchmark"` Time int `json:"time"` Ts int `json:"ts"` + Ua string `json:"ua"` } //发送的原始对象 @@ -44,6 +47,7 @@ var ( rec_chan = make(chan S,5)//收通道 webpath string//web地址,由于实时获取空闲端口,故将在稍后web启动后赋值 ws = websocket.New_server()//新建websocket实例 + nodeJsUrl string ) func init() { @@ -59,7 +63,17 @@ func init() { } //初始化web服务器,初始化websocket - server() + NodeJsUrl,ok := c.K_v.LoadV("小心心nodjs加密服务地址").(string) + if ok && NodeJsUrl != "" { + nodeJsUrl = NodeJsUrl + if test(0) { + wslog.L(`I: `,`使用NodeJs`,NodeJsUrl,`进行加密`) + } else { + wslog.L(`E: `,`发生错误!`) + } + } else { + server() + } wslog.L(`T: `,`启动`) }() } @@ -120,37 +134,80 @@ func server() { func Wasm(maxloop int, uid uintptr,s RT) (o string) {//maxloop 超时重试 if maxloop <= 0 {return} - for try:=5;try > 0 && ws.Len() == 0;try-=1 {//没有从池中取出 - open.Run(webpath) - wslog.L(`I: `,`浏览器打开`,webpath) - time.Sleep(time.Second*time.Duration(3)) - } + {//nodejs + if nodeJsUrl != "" { + req := p.Req() + if err := req.Reqf(p.Rval{ + Header:map[string]string{ + `Content-Type`: `application/json`, + }, + Url:nodeJsUrl, + PostStr:toNodeJsString(s), + Timeout:3, + });err != nil { + wslog.L(`E: `,err) + //重试时刷新时间 + s.R.Ts = int(p.Sys().GetMTime()) + o = Wasm(maxloop-1, uid, s) + return + } + + var res struct{ + Code int `json:"code"` + S string `json:"s"` + Message string `json:"message"` + } - b, e := json.Marshal(s) - if e != nil { - wslog.L(`E: `,e) + if e := json.Unmarshal(req.Respon, &res);e != nil { + wslog.L(`E: `,e) + } else if res.Code != 0 { + wslog.L(`E: `,res.Message) + } else { + o = res.S + } + return + } } - //获取websocket操作对象 发送 - ws.Interface().Push_tag(`send`,websocket.Uinterface{ - Id:uid, - Data:b, - }) + {//web + b, e := json.Marshal(s) + if e != nil { + wslog.L(`E: `,e) + } - for { - select { - case r :=<- rec_chan: - if r.Id != s.R.Id {break}//或许接收到之前的请求,校验Id字段 - return r.S - case <- time.After(time.Second*time.Duration(3)): - wslog.L(`E: `,`超时!响应>1s,确认保持`,webpath,`开启`) - o = Wasm(maxloop-1, uid, s) - return + for try:=5;try > 0 && ws.Len() == 0;try-=1 {//没有从池中取出 + open.Run(webpath) + wslog.L(`I: `,`浏览器打开`,webpath) + time.Sleep(time.Second*time.Duration(3)) + } + + //获取websocket操作对象 发送 + ws.Interface().Push_tag(`send`,websocket.Uinterface{ + Id:uid, + Data:b, + }) + + for { + select { + case r :=<- rec_chan: + if r.Id != s.R.Id {break}//或许接收到之前的请求,校验Id字段 + return r.S + case <- time.After(time.Second*time.Duration(3)): + wslog.L(`E: `,`超时!响应>1s,确认保持`,webpath,`开启`) + //重试时刷新时间 + s.R.Ts = int(p.Sys().GetMTime()) + o = Wasm(maxloop-1, uid, s) + return + } } } } func Close(uid uintptr){ + //nodejs不需要关闭 + if nodeJsUrl != "" { + return + } //获取websocket操作对象 关闭 ws.Interface().Push_tag(`close`,websocket.Uinterface{ Id:uid, @@ -168,6 +225,7 @@ func test(uid uintptr) bool { Benchmark: "seacasdgyijfhofiuxoannn", Time: 60, Ts: 1611836642190, + Ua:`Mozilla/5.0 (X11; Linux x86_64; rv:84.0) Gecko/20100101 Firefox/84.0`, }, T: []int{2, 5, 1, 4}, });s != `e4249b7657c2d4a44955548eb814797d41ddd99bfdfa5974462b8c387d701b8c83898f6d7dde1772c67fad6a113d20c20e454be1d1627e7ea99617a8a1f99bd0` { @@ -175,4 +233,21 @@ func test(uid uintptr) bool { return false } return true +} + +func toNodeJsString(r RT) (o string) { + o += `{"t":{"id":` + o += r.R.Id+`,` + o += `"device":`+r.R.Device+`,` + o += `"ets":`+strconv.Itoa(r.R.Ets)+`,` + o += `"benchmark":"`+r.R.Benchmark+`",` + o += `"time":`+strconv.Itoa(r.R.Time)+`,` + o += `"ts":`+strconv.Itoa(r.R.Ts)+`,` + o += `"ua":"`+r.R.Ua+`"},"r":[` + o += strconv.Itoa(r.T[0])+`,` + o += strconv.Itoa(r.T[1])+`,` + o += strconv.Itoa(r.T[2])+`,` + o += strconv.Itoa(r.T[3]) + o += `]}` + return } \ No newline at end of file diff --git a/README.md b/README.md index 15a5161..d00b6b8 100644 --- a/README.md +++ b/README.md @@ -162,12 +162,28 @@ openssl genrsa -out private.pem 2048 openssl rsa -in private.pem -pubout -out public.pem ``` #### 小心心 -在登录后,可以自动获取小心心 +在登录后,可以自动获取小心心,获取小心心需要加密 -需要支持webassembly的浏览器(通常可以在bili直播间获得小心心的浏览器均可) +加密方式: +- 浏览器(默认) +当`小心心nodjs加密服务地址`为空时启用,需要支持webassembly的浏览器(通常可以在bili直播间获得小心心的浏览器均可) golang通过websocket与浏览器js进行通讯,在浏览器js调用bilibili的webassembly组件,对信息进行加密。最后返回加密字符串,并由golang进行获取请求。因此需要保持浏览器的相关标签页不被关闭。 +- NodeJs + +支持使用nodeJs服务来进行加密,在`config/config_K_v.json`配置。当`小心心nodjs加密服务地址`不为空(如Nodejs服务在本地`5200`端口启动:`http://127.0.0.1:5200/enc`)时,将使用此服务来进行加密。注意:加密失败将导致小心心获取退出。 +nodejs小心心加密项目地址[lkeme/bilibili-pcheartbeat](https://github.com/lkeme/bilibili-pcheartbeat)。请自行配置启动。 + +- golang?暂无 + +至于为什么没有直接的golang实现,是因为查找资料一番后发现golang执行wasm是使用虚拟机。出于效率及平台普遍性的考量,故没使用,等相关项目更加完善在添加。 + +相关项目 + +- [mathetake/gasm](https://github.com/mathetake/gasm) +- [wasmerio/wasmer-go](https://github.com/wasmerio/wasmer-go) + #### 私信 在登录后,可以使用私信 diff --git a/demo/config/config_K_v.json b/demo/config/config_K_v.json index 9b01944..4a20681 100644 --- a/demo/config/config_K_v.json +++ b/demo/config/config_K_v.json @@ -19,6 +19,8 @@ "save_to_json": "", "get_xiao_xinxin-help": "获取小心心", "get_xiao_xinxin": true, + "小心心nodjs加密服务地址-help": "请查看项目README", + "小心心nodjs加密服务地址": "", "进房弹幕-help": "进入房间发送弹幕,似乎屏蔽了一些字符", "进房弹幕_内容": [ "(`・ω・´)",