Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
M
Mirai
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
MyCard
Mirai
Commits
905823b9
Commit
905823b9
authored
Jan 29, 2020
by
Him188
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Slider captcha solver
parent
817f3b02
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
71 additions
and
76 deletions
+71
-76
mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/QQAndroidBotNetworkHandler.kt
...moe/mirai/qqandroid/network/QQAndroidBotNetworkHandler.kt
+8
-6
mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/protocol/packet/OutgoingPacketAndroid.kt
...qandroid/network/protocol/packet/OutgoingPacketAndroid.kt
+0
-46
mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/protocol/packet/Tlv.kt
.../net/mamoe/mirai/qqandroid/network/protocol/packet/Tlv.kt
+9
-0
mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/protocol/packet/login/LoginPacket.kt
...ai/qqandroid/network/protocol/packet/login/LoginPacket.kt
+38
-11
mirai-core/src/androidMain/kotlin/net/mamoe/mirai/utils/defaultLoginSolver.kt
...idMain/kotlin/net/mamoe/mirai/utils/defaultLoginSolver.kt
+1
-1
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/utils/BotConfiguration.kt
...mmonMain/kotlin/net.mamoe.mirai/utils/BotConfiguration.kt
+1
-1
mirai-core/src/jvmMain/kotlin/net/mamoe/mirai/utils/DefaultCaptchaSolverJvm.kt
...n/kotlin/net/mamoe/mirai/utils/DefaultCaptchaSolverJvm.kt
+13
-10
mirai-demos/mirai-demo-android/src/main/kotlin/net/mamoe/mirai/demo/MiraiService.kt
...roid/src/main/kotlin/net/mamoe/mirai/demo/MiraiService.kt
+1
-1
No files found.
mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/QQAndroidBotNetworkHandler.kt
View file @
905823b9
...
@@ -53,19 +53,21 @@ internal class QQAndroidBotNetworkHandler(bot: QQAndroidBot) : BotNetworkHandler
...
@@ -53,19 +53,21 @@ internal class QQAndroidBotNetworkHandler(bot: QQAndroidBot) : BotNetworkHandler
is
Captcha
->
when
(
response
)
{
is
Captcha
->
when
(
response
)
{
is
Captcha
.
Picture
->
{
is
Captcha
.
Picture
->
{
bot
.
logger
.
info
(
"需要图片验证码"
)
var
result
=
bot
.
configuration
.
loginSolver
.
onSolvePicCaptcha
(
bot
,
response
.
data
)
var
result
=
bot
.
configuration
.
loginSolver
.
onSolvePicCaptcha
(
bot
,
response
.
data
)
if
(
result
==
=
null
||
result
.
length
!=
4
)
{
if
(
result
==
null
||
result
.
length
!=
4
)
{
//refresh captcha
//refresh captcha
result
=
"ABCD"
result
=
"ABCD"
}
}
bot
.
logger
.
info
(
"提交验证码"
)
response
=
LoginPacket
.
SubCommand2
.
SubmitPictureCaptcha
(
bot
.
client
,
response
.
sign
,
result
).
sendAndExpect
()
response
=
LoginPacket
.
SubCommand2
(
bot
.
client
,
response
.
sign
,
result
).
sendAndExpect
()
continue
@
mainloop
continue
@
mainloop
}
}
is
Captcha
.
Slider
->
{
is
Captcha
.
Slider
->
{
bot
.
logger
.
info
(
"需要滑动验证码"
)
var
ticket
=
bot
.
configuration
.
loginSolver
.
onSolveSliderCaptcha
(
bot
,
response
.
url
)
TODO
(
"滑动验证码"
)
if
(
ticket
==
null
)
{
ticket
=
""
}
response
=
LoginPacket
.
SubCommand2
.
SubmitSliderCaptcha
(
bot
.
client
,
ticket
).
sendAndExpect
()
continue
@
mainloop
}
}
}
}
...
...
mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/protocol/packet/OutgoingPacketAndroid.kt
View file @
905823b9
...
@@ -264,52 +264,6 @@ internal inline fun BytePacketBuilder.writeSsoPacket(
...
@@ -264,52 +264,6 @@ internal inline fun BytePacketBuilder.writeSsoPacket(
writeIntLVPacket
(
lengthOffset
=
{
it
+
4
},
builder
=
body
)
writeIntLVPacket
(
lengthOffset
=
{
it
+
4
},
builder
=
body
)
}
}
internal
inline
fun
BytePacketBuilder
.
writeSmsSsoPacket
(
client
:
QQAndroidClient
,
subAppId
:
Long
,
commandName
:
String
,
extraData
:
ByteReadPacket
=
BRP_STUB
,
sequenceId
:
Int
,
body
:
BytePacketBuilder
.()
->
Unit
)
{
writeIntLVPacket
(
lengthOffset
=
{
it
+
4
})
{
writeInt
(
sequenceId
)
writeInt
(
subAppId
.
toInt
())
writeInt
(
subAppId
.
toInt
())
writeHex
(
"00 00 00 00 00 00 00 00 00 00 01 00"
)
if
(
extraData
===
BRP_STUB
)
{
writeInt
(
0
x04
)
}
else
{
writeInt
((
extraData
.
remaining
+
4
).
toInt
())
writePacket
(
extraData
)
}
commandName
.
let
{
writeInt
(
it
.
length
+
4
)
writeStringUtf8
(
it
)
}
writeInt
(
4
+
4
)
writeInt
(
45112203
)
// 02 B0 5B 8B
client
.
device
.
imei
.
let
{
writeInt
(
it
.
length
+
4
)
writeStringUtf8
(
it
)
}
writeInt
(
4
)
client
.
ksid
.
let
{
writeShort
((
it
.
size
+
2
).
toShort
())
writeFully
(
it
)
}
writeInt
(
4
)
}
// body
writeIntLVPacket
(
lengthOffset
=
{
it
+
4
},
builder
=
body
)
}
/**
/**
* Writes a request packet
* Writes a request packet
...
...
mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/protocol/packet/Tlv.kt
View file @
905823b9
...
@@ -566,6 +566,15 @@ fun BytePacketBuilder.t188(
...
@@ -566,6 +566,15 @@ fun BytePacketBuilder.t188(
}
shouldEqualsTo
16
}
shouldEqualsTo
16
}
}
fun
BytePacketBuilder
.
t193
(
ticket
:
String
)
{
writeShort
(
0
x193
)
writeShortLVPacket
{
writeFully
(
ticket
.
toByteArray
())
}
}
fun
BytePacketBuilder
.
t194
(
fun
BytePacketBuilder
.
t194
(
imsiMd5
:
ByteArray
imsiMd5
:
ByteArray
)
{
)
{
...
...
mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/protocol/packet/login/LoginPacket.kt
View file @
905823b9
...
@@ -23,12 +23,30 @@ import net.mamoe.mirai.utils.io.discardExact
...
@@ -23,12 +23,30 @@ import net.mamoe.mirai.utils.io.discardExact
@UseExperimental
(
ExperimentalUnsignedTypes
::
class
)
@UseExperimental
(
ExperimentalUnsignedTypes
::
class
)
internal
object
LoginPacket
:
PacketFactory
<
LoginPacket
.
LoginPacketResponse
>(
"wtlogin.login"
)
{
internal
object
LoginPacket
:
PacketFactory
<
LoginPacket
.
LoginPacketResponse
>(
"wtlogin.login"
)
{
/**
* 提交验证码
*/
object
SubCommand2
{
object
SubCommand2
{
private
const
val
appId
=
16L
private
const
val
appId
=
16L
private
const
val
subAppId
=
537062845L
private
const
val
subAppId
=
537062845L
@UseExperimental
(
MiraiInternalAPI
::
class
)
fun
SubmitSliderCaptcha
(
operator
fun
invoke
(
client
:
QQAndroidClient
,
ticket
:
String
):
OutgoingPacket
=
buildLoginOutgoingPacket
(
client
,
bodyType
=
2
)
{
sequenceId
->
writeSsoPacket
(
client
,
subAppId
,
commandName
,
sequenceId
=
sequenceId
)
{
writeOicqRequestPacket
(
client
,
EncryptMethodECDH7
(
client
.
ecdh
),
0
x0810
)
{
writeShort
(
2
)
// subCommand
writeShort
(
4
)
// count of TLVs
t193
(
ticket
)
t8
(
2052
)
t104
(
client
.
t104
)
t116
(
150470524
,
66560
)
}
}
}
fun
SubmitPictureCaptcha
(
client
:
QQAndroidClient
,
client
:
QQAndroidClient
,
captchaSign
:
ByteArray
,
captchaSign
:
ByteArray
,
captchaAnswer
:
String
captchaAnswer
:
String
...
@@ -36,7 +54,7 @@ internal object LoginPacket : PacketFactory<LoginPacket.LoginPacketResponse>("wt
...
@@ -36,7 +54,7 @@ internal object LoginPacket : PacketFactory<LoginPacket.LoginPacketResponse>("wt
writeSsoPacket
(
client
,
subAppId
,
commandName
,
sequenceId
=
sequenceId
)
{
writeSsoPacket
(
client
,
subAppId
,
commandName
,
sequenceId
=
sequenceId
)
{
writeOicqRequestPacket
(
client
,
EncryptMethodECDH7
(
client
.
ecdh
),
0
x0810
)
{
writeOicqRequestPacket
(
client
,
EncryptMethodECDH7
(
client
.
ecdh
),
0
x0810
)
{
writeShort
(
2
)
// subCommand
writeShort
(
2
)
// subCommand
writeShort
(
4
)
// count of TLVs
, probably ignored by server?
writeShort
(
4
)
// count of TLVs
t2
(
captchaAnswer
,
captchaSign
,
0
)
t2
(
captchaAnswer
,
captchaSign
,
0
)
t8
(
2052
)
t8
(
2052
)
t104
(
client
.
t104
)
t104
(
client
.
t104
)
...
@@ -69,6 +87,9 @@ internal object LoginPacket : PacketFactory<LoginPacket.LoginPacketResponse>("wt
...
@@ -69,6 +87,9 @@ internal object LoginPacket : PacketFactory<LoginPacket.LoginPacketResponse>("wt
}
}
}
}
/**
* 提交 SMS
*/
object
SubCommand7
{
object
SubCommand7
{
private
const
val
appId
=
16L
private
const
val
appId
=
16L
private
const
val
subAppId
=
537062845L
private
const
val
subAppId
=
537062845L
...
@@ -79,7 +100,7 @@ internal object LoginPacket : PacketFactory<LoginPacket.LoginPacketResponse>("wt
...
@@ -79,7 +100,7 @@ internal object LoginPacket : PacketFactory<LoginPacket.LoginPacketResponse>("wt
t402
:
ByteArray
,
t402
:
ByteArray
,
phoneNumber
:
String
phoneNumber
:
String
):
OutgoingPacket
=
buildLoginOutgoingPacket
(
client
,
bodyType
=
2
)
{
sequenceId
->
):
OutgoingPacket
=
buildLoginOutgoingPacket
(
client
,
bodyType
=
2
)
{
sequenceId
->
writeS
msSsoPacket
(
client
,
subAppId
,
commandName
,
sequenceId
=
sequenceId
)
{
writeS
soPacket
(
client
,
subAppId
,
commandName
,
sequenceId
=
sequenceId
,
unknownHex
=
"01 00 00 00 00 00 00 00 00 00 01 00"
)
{
writeOicqRequestPacket
(
client
,
EncryptMethodECDH7
(
client
.
ecdh
),
0
x0810
)
{
writeOicqRequestPacket
(
client
,
EncryptMethodECDH7
(
client
.
ecdh
),
0
x0810
)
{
writeShort
(
8
)
// subCommand
writeShort
(
8
)
// subCommand
writeShort
(
6
)
// count of TLVs, probably ignored by server?TODO
writeShort
(
6
)
// count of TLVs, probably ignored by server?TODO
...
@@ -96,6 +117,9 @@ internal object LoginPacket : PacketFactory<LoginPacket.LoginPacketResponse>("wt
...
@@ -96,6 +117,9 @@ internal object LoginPacket : PacketFactory<LoginPacket.LoginPacketResponse>("wt
}
}
}
}
/**
* 密码登录
*/
object
SubCommand9
{
object
SubCommand9
{
private
const
val
appId
=
16L
private
const
val
appId
=
16L
private
const
val
subAppId
=
537062845L
private
const
val
subAppId
=
537062845L
...
@@ -257,8 +281,7 @@ internal object LoginPacket : PacketFactory<LoginPacket.LoginPacketResponse>("wt
...
@@ -257,8 +281,7 @@ internal object LoginPacket : PacketFactory<LoginPacket.LoginPacketResponse>("wt
sealed
class
Captcha
:
LoginPacketResponse
()
{
sealed
class
Captcha
:
LoginPacketResponse
()
{
class
Slider
(
class
Slider
(
val
data
:
IoBuffer
,
val
url
:
String
val
sign
:
ByteArray
)
:
Captcha
()
{
)
:
Captcha
()
{
override
fun
toString
():
String
{
override
fun
toString
():
String
{
return
"LoginPacketResponse.Captcha.Slider"
return
"LoginPacketResponse.Captcha.Slider"
...
@@ -340,10 +363,12 @@ internal object LoginPacket : PacketFactory<LoginPacket.LoginPacketResponse>("wt
...
@@ -340,10 +363,12 @@ internal object LoginPacket : PacketFactory<LoginPacket.LoginPacketResponse>("wt
@UseExperimental
(
MiraiDebugAPI
::
class
)
@UseExperimental
(
MiraiDebugAPI
::
class
)
private
fun
onSolveLoginCaptcha
(
tlvMap
:
TlvMap
,
bot
:
QQAndroidBot
):
LoginPacketResponse
.
Captcha
{
private
fun
onSolveLoginCaptcha
(
tlvMap
:
TlvMap
,
bot
:
QQAndroidBot
):
LoginPacketResponse
.
Captcha
{
// val ret = tlvMap[0x104]?.let { println(it.toUHexString()) }
// val ret = tlvMap[0x104]?.let { println(it.toUHexString()) }
println
()
tlvMap
[
0
x192
]
?.
let
{
val
question
=
tlvMap
[
0
x165
]
?:
error
(
"CAPTCHA QUESTION UNKNOWN"
)
bot
.
client
.
t104
=
tlvMap
.
getOrFail
(
0
x104
)
when
(
question
[
18
].
toInt
())
{
return
LoginPacketResponse
.
Captcha
.
Slider
(
it
.
encodeToString
())
0
x36
->
{
}
tlvMap
[
0
x165
]
?.
let
{
question
->
if
(
question
[
18
].
toInt
()
==
0
x36
)
{
//图片验证
//图片验证
DebugLogger
.
debug
(
"是一个图片验证码"
)
DebugLogger
.
debug
(
"是一个图片验证码"
)
bot
.
client
.
t104
=
tlvMap
.
getOrFail
(
0
x104
)
bot
.
client
.
t104
=
tlvMap
.
getOrFail
(
0
x104
)
...
@@ -356,8 +381,10 @@ internal object LoginPacket : PacketFactory<LoginPacket.LoginPacketResponse>("wt
...
@@ -356,8 +381,10 @@ internal object LoginPacket : PacketFactory<LoginPacket.LoginPacketResponse>("wt
sign
=
sign
sign
=
sign
)
)
}
}
else
->
error
(
"UNKNOWN CAPTCHA QUESTION: $question"
)
else
error
(
"UNKNOWN CAPTCHA QUESTION: $question"
)
}
}
error
(
"UNKNOWN CAPTCHA"
)
}
}
@UseExperimental
(
MiraiDebugAPI
::
class
)
@UseExperimental
(
MiraiDebugAPI
::
class
)
...
...
mirai-core/src/androidMain/kotlin/net/mamoe/mirai/utils/defaultLoginSolver.kt
View file @
905823b9
...
@@ -11,7 +11,7 @@ actual var defaultLoginSolver: LoginSolver = object : LoginSolver() {
...
@@ -11,7 +11,7 @@ actual var defaultLoginSolver: LoginSolver = object : LoginSolver() {
error
(
"should be implemented manually by you"
)
error
(
"should be implemented manually by you"
)
}
}
override
suspend
fun
onSolveSliderCaptcha
(
bot
:
Bot
,
data
:
IoBuffer
):
String
?
{
override
suspend
fun
onSolveSliderCaptcha
(
bot
:
Bot
,
url
:
String
):
String
?
{
error
(
"should be implemented manually by you"
)
error
(
"should be implemented manually by you"
)
}
}
...
...
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/utils/BotConfiguration.kt
View file @
905823b9
...
@@ -11,7 +11,7 @@ import kotlin.jvm.JvmStatic
...
@@ -11,7 +11,7 @@ import kotlin.jvm.JvmStatic
abstract
class
LoginSolver
{
abstract
class
LoginSolver
{
abstract
suspend
fun
onSolvePicCaptcha
(
bot
:
Bot
,
data
:
IoBuffer
):
String
?
abstract
suspend
fun
onSolvePicCaptcha
(
bot
:
Bot
,
data
:
IoBuffer
):
String
?
abstract
suspend
fun
onSolveSliderCaptcha
(
bot
:
Bot
,
data
:
IoBuffer
):
String
?
abstract
suspend
fun
onSolveSliderCaptcha
(
bot
:
Bot
,
url
:
String
):
String
?
abstract
suspend
fun
onGetPhoneNumber
():
String
abstract
suspend
fun
onGetPhoneNumber
():
String
...
...
mirai-core/src/jvmMain/kotlin/net/mamoe/mirai/utils/DefaultCaptchaSolverJvm.kt
View file @
905823b9
...
@@ -34,38 +34,41 @@ class DefaultLoginSolver : LoginSolver() {
...
@@ -34,38 +34,41 @@ class DefaultLoginSolver : LoginSolver() {
val
tempFile
:
File
=
createTempFile
(
suffix
=
".png"
).
apply
{
deleteOnExit
()
}
val
tempFile
:
File
=
createTempFile
(
suffix
=
".png"
).
apply
{
deleteOnExit
()
}
withContext
(
Dispatchers
.
IO
)
{
withContext
(
Dispatchers
.
IO
)
{
tempFile
.
createNewFile
()
tempFile
.
createNewFile
()
MiraiLogger
.
info
(
"需要
验证码登录, 验证码为 4 字母"
)
bot
.
logger
.
info
(
"需要图片
验证码登录, 验证码为 4 字母"
)
try
{
try
{
tempFile
.
writeChannel
().
use
{
writeFully
(
data
)
}
tempFile
.
writeChannel
().
use
{
writeFully
(
data
)
}
MiraiL
ogger
.
info
(
"将会显示字符图片. 若看不清字符图片, 请查看文件 ${tempFile.absolutePath}"
)
bot
.
l
ogger
.
info
(
"将会显示字符图片. 若看不清字符图片, 请查看文件 ${tempFile.absolutePath}"
)
}
catch
(
e
:
Exception
)
{
}
catch
(
e
:
Exception
)
{
MiraiL
ogger
.
info
(
"无法写出验证码文件(${e.message}), 请尝试查看以上字符图片"
)
bot
.
l
ogger
.
info
(
"无法写出验证码文件(${e.message}), 请尝试查看以上字符图片"
)
}
}
tempFile
.
inputStream
().
use
{
tempFile
.
inputStream
().
use
{
val
img
=
ImageIO
.
read
(
it
)
val
img
=
ImageIO
.
read
(
it
)
if
(
img
==
null
)
{
if
(
img
==
null
)
{
MiraiL
ogger
.
info
(
"无法创建字符图片. 请查看文件"
)
bot
.
l
ogger
.
info
(
"无法创建字符图片. 请查看文件"
)
}
else
{
}
else
{
MiraiL
ogger
.
info
(
img
.
createCharImg
())
bot
.
l
ogger
.
info
(
img
.
createCharImg
())
}
}
}
}
}
}
MiraiL
ogger
.
info
(
"请输入 4 位字母验证码. 若要更换验证码, 请直接回车"
)
bot
.
l
ogger
.
info
(
"请输入 4 位字母验证码. 若要更换验证码, 请直接回车"
)
return
readLine
()
?.
takeUnless
{
it
.
isEmpty
()
||
it
.
length
!=
4
}
return
readLine
()
?.
takeUnless
{
it
.
isEmpty
()
||
it
.
length
!=
4
}
}
}
}
}
override
suspend
fun
onSolveSliderCaptcha
(
bot
:
Bot
,
data
:
IoBuffer
):
String
?
{
override
suspend
fun
onSolveSliderCaptcha
(
bot
:
Bot
,
url
:
String
):
String
?
{
TODO
(
"not implemented"
)
//To change body of created functions use File | Settings | File Templates.
bot
.
logger
.
info
(
"需要滑动验证码"
)
bot
.
logger
.
info
(
"请在任意浏览器中打开以下链接并完成验证码. "
)
bot
.
logger
.
info
(
url
)
return
readLine
()
}
}
override
suspend
fun
onGetPhoneNumber
():
String
{
override
suspend
fun
onGetPhoneNumber
():
String
{
loginSolverLock
.
withLock
{
loginSolverLock
.
withLock
{
while
(
true
){
while
(
true
)
{
MiraiLogger
.
info
(
"请输入你的手机号码"
)
MiraiLogger
.
info
(
"请输入你的手机号码"
)
val
var0
=
readLine
()
val
var0
=
readLine
()
if
(
var0
!==
null
&&
var0
.
length
>
10
)
{
if
(
var0
!==
null
&&
var0
.
length
>
10
)
{
return
var0
;
return
var0
;
}
}
}
}
...
...
mirai-demos/mirai-demo-android/src/main/kotlin/net/mamoe/mirai/demo/MiraiService.kt
View file @
905823b9
...
@@ -53,7 +53,7 @@ class MiraiService : Service() {
...
@@ -53,7 +53,7 @@ class MiraiService : Service() {
return
mCaptchaDeferred
.
await
()
return
mCaptchaDeferred
.
await
()
}
}
override
suspend
fun
onSolveSliderCaptcha
(
bot
:
Bot
,
data
:
IoBuffer
):
String
?
{
override
suspend
fun
onSolveSliderCaptcha
(
bot
:
Bot
,
url
:
String
):
String
?
{
TODO
(
"not implemented"
)
TODO
(
"not implemented"
)
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment