Skip to content

Commit

Permalink
ysp
Browse files Browse the repository at this point in the history
  • Loading branch information
lizongying committed Jun 8, 2024
1 parent eac355a commit fccd64c
Show file tree
Hide file tree
Showing 5 changed files with 145 additions and 3 deletions.
Binary file modified app/src/main/cpp/arm64-v8a/libnative.so
Binary file not shown.
Binary file modified app/src/main/cpp/armeabi-v7a/libnative.so
Binary file not shown.
139 changes: 139 additions & 0 deletions app/src/main/java/com/lizongying/mytv/Utils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.lizongying.mytv

import android.content.res.Resources
import android.os.Build
import android.util.Log
import android.util.TypedValue
import com.google.gson.Gson
import com.lizongying.mytv.api.TimeResponse
Expand All @@ -18,6 +19,10 @@ import java.util.Locale
object Utils {
private var between: Long = 0

private var a: String = ""
var b: String = ""
private var c: String = ""

private var listener: Request.RequestListener? = null

fun getDateFormat(format: String): String {
Expand Down Expand Up @@ -45,6 +50,31 @@ object Utils {
println("Failed to retrieve timestamp from server: ${e.message}")
}

var x = ""
try {
x = getNothing()
} catch (e: Exception) {
x = ""
println("a ${e.message}")
}

if (x != "") {
try {
x = getNothing2(x)
} catch (e: Exception) {
x = ""
println("b ${e.message}")
}
}

if (x != "") {
try {
getNothing3(x)
} catch (e: Exception) {
println("b ${e.message}")
}
}

withContext(Dispatchers.Main) {
listener?.onRequestFinished(null)
}
Expand Down Expand Up @@ -88,6 +118,115 @@ object Utils {
}
}

private val regex = Regex("""chunk-vendors\.([^.]+)\.js""")

private suspend fun getNothing(): String {
return withContext(Dispatchers.IO) {
val client = okhttp3.OkHttpClient.Builder()
.addInterceptor(RetryInterceptor(3))
.build()
val request = okhttp3.Request.Builder()
.url("https://www.yangshipin.cn")
.build()
try {
client.newCall(request).execute().use { response ->
if (!response.isSuccessful) throw IOException("Unexpected code $response")
val string = response.body()?.string()

val matchResult = string?.let { regex.find(it) }
var x = ""
if (matchResult != null) {
x = matchResult.groupValues[1]
}
x
}
} catch (e: IOException) {
throw IOException("Error during network request", e)
}
}
}

private val regex2 = Regex(""""ysp_tx"[^:]+:"([^"]+)[^:]+:"([^"]+)""")

private val regex3 = Regex(""""(https[^"]+wasm([^"]+))""")

private suspend fun getNothing2(x: String): String {
return withContext(Dispatchers.IO) {
val client = okhttp3.OkHttpClient.Builder()
.addInterceptor(RetryInterceptor(3))
.build()

val request = okhttp3.Request.Builder()
.url("https://www.yangshipin.cn/js/chunk-vendors.$x.js")
.build()
try {
client.newCall(request).execute().use { response ->
if (!response.isSuccessful) throw IOException("Unexpected code $response")
val string = response.body()?.string()

val matches = string?.let { regex2.findAll(it) }

var matchResult = matches?.lastOrNull()

if (matchResult != null) {
val (aa, bb) = matchResult.destructured
a = aa
b = bb
}

matchResult = string?.let { regex3.find(it) }

if (matchResult != null) {
val (cc) = matchResult.destructured
c = cc
Log.i("", "ccccc $c")
}
c
}
} catch (e: IOException) {
throw IOException("Error during network request", e)
}
}
}

private suspend fun getNothing3(x: String): String {
return withContext(Dispatchers.IO) {
val client = okhttp3.OkHttpClient.Builder()
.addInterceptor(RetryInterceptor(3))
.build()

val request = okhttp3.Request.Builder()
.url("https://www.yangshipin.cn/js/chunk-vendors.$x.js")
.build()
try {
client.newCall(request).execute().use { response ->
if (!response.isSuccessful) throw IOException("Unexpected code $response")
val string = response.body()?.string()

val matches = string?.let { regex2.findAll(it) }

var matchResult = matches?.lastOrNull()

if (matchResult != null) {
val (aa, bb) = matchResult.destructured
a = aa
b = bb
}

matchResult = string?.let { regex3.find(it) }

if (matchResult != null) {
val (cc) = matchResult.destructured
c = cc
}
c
}
} catch (e: IOException) {
throw IOException("Error during network request", e)
}
}
}

fun dpToPx(dp: Float): Int {
return TypedValue.applyDimension(
TypedValue.COMPLEX_UNIT_DIP, dp, Resources.getSystem().displayMetrics
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/java/com/lizongying/mytv/api/Encryptor.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ class Encryptor {

external fun hash2(data: ByteArray): ByteArray?

external fun hash3(data: ByteArray): ByteArray?

companion object {
init {
System.loadLibrary("native")
Expand Down
7 changes: 4 additions & 3 deletions app/src/main/java/com/lizongying/mytv/api/YSP.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.lizongying.mytv.api
import android.content.Context
import android.util.Log
import com.lizongying.mytv.SP
import com.lizongying.mytv.Utils
import com.lizongying.mytv.Utils.getDateTimestamp
import com.lizongying.mytv.models.TVViewModel
import java.security.MessageDigest
Expand Down Expand Up @@ -182,13 +183,13 @@ object YSP {

private fun getAuthSignature(): String {
val e =
"appid=${appid}&guid=${guid}&pid=${livepid}&rand_str=${randStr}".toByteArray()
val hashedData = encryptor.hash2(e) ?: return ""
"appid=${appid}&guid=${guid}&pid=${livepid}&rand_str=${randStr}${Utils.b}".toByteArray()
val hashedData = encryptor.hash3(e) ?: return ""
return hashedData.let { it -> it.joinToString("") { "%02x".format(it) } }
}

fun getAuthSignature(e: String): String {
val hashedData = encryptor.hash2(e.toByteArray()) ?: return ""
val hashedData = encryptor.hash3("$e${Utils.b}".toByteArray()) ?: return ""
return hashedData.let { it -> it.joinToString("") { "%02x".format(it) } }
}
}

0 comments on commit fccd64c

Please sign in to comment.