fixed decryption

This commit is contained in:
LagradOst 2023-08-19 17:03:27 +02:00
parent e20e3dcfd3
commit b3abf1e45f
2 changed files with 12 additions and 14 deletions

View file

@ -88,21 +88,17 @@ object M3u8Helper2 {
} }
} }
private val defaultIvGen = sequence { private fun defaultIv(index: Int) : ByteArray {
var initial = 1 return toBytes16Big(index+1)
while (true) {
yield(toBytes16Big(initial))
++initial
} }
}.iterator()
fun getDecrypter( fun getDecrypted(
secretKey: ByteArray, secretKey: ByteArray,
data: ByteArray, data: ByteArray,
iv: ByteArray = "".toByteArray() iv: ByteArray = byteArrayOf(),
index : Int,
): ByteArray { ): ByteArray {
val ivKey = if (iv.isEmpty()) defaultIvGen.next() else iv val ivKey = if (iv.isEmpty()) defaultIv(index) else iv
val c = Cipher.getInstance("AES/CBC/PKCS5Padding") val c = Cipher.getInstance("AES/CBC/PKCS5Padding")
val skSpec = SecretKeySpec(secretKey, "AES") val skSpec = SecretKeySpec(secretKey, "AES")
val ivSpec = IvParameterSpec(ivKey) val ivSpec = IvParameterSpec(ivKey)
@ -234,7 +230,7 @@ object M3u8Helper2 {
if (tsData.isEmpty()) throw ErrorLoadingException("no data") if (tsData.isEmpty()) throw ErrorLoadingException("no data")
return if (isEncrypted) { return if (isEncrypted) {
getDecrypter(encryptionData, tsData, encryptionIv) getDecrypted(encryptionData, tsData, encryptionIv, index)
} else { } else {
tsData tsData
} }
@ -272,13 +268,13 @@ object M3u8Helper2 {
val match = val match =
ENCRYPTION_URL_IV_REGEX.find(m3u8Response)!!.groupValues ENCRYPTION_URL_IV_REGEX.find(m3u8Response)!!.groupValues
var encryptionUri = match[1] var encryptionUri = match[2]
if (isNotCompleteUrl(encryptionUri)) { if (isNotCompleteUrl(encryptionUri)) {
encryptionUri = "${getParentLink(secondSelection.streamUrl)}/$encryptionUri" encryptionUri = "${getParentLink(secondSelection.streamUrl)}/$encryptionUri"
} }
encryptionIv = match[2].toByteArray() encryptionIv = match[3].toByteArray()
val encryptionKeyResponse = app.get(encryptionUri, headers = headers, verify = false) val encryptionKeyResponse = app.get(encryptionUri, headers = headers, verify = false)
encryptionData = encryptionKeyResponse.body.bytes() encryptionData = encryptionKeyResponse.body.bytes()
} }

View file

@ -803,6 +803,8 @@ object VideoDownloadManager {
bytesDownloaded = 0 bytesDownloaded = 0
hlsWrittenProgress = 0 hlsWrittenProgress = 0
hlsProgress = 0 hlsProgress = 0
if (id != null)
downloadDeleteEvent(id)
//internalType = DownloadType.IsStopped //internalType = DownloadType.IsStopped
notify() notify()