Add workaround for bulkBarrierPreWrite: unaligned arguments panic

This commit is contained in:
armv9 2024-12-12 21:09:44 +09:00
parent ad61b2ee66
commit fd825c5532
7 changed files with 44 additions and 11 deletions

View File

@ -23,6 +23,7 @@ import io.nekohasekai.sagernet.ktx.*
import libcore.Libcore
import moe.matsuri.nb4a.Protocols
import moe.matsuri.nb4a.proxy.config.ConfigBean
import moe.matsuri.nb4a.utils.Util
import org.ini4j.Ini
import org.json.JSONArray
import org.json.JSONObject
@ -66,10 +67,11 @@ object RawUpdater : GroupUpdater() {
setURL(subscription.link)
setUserAgent(subscription.customUserAgent.takeIf { it.isNotBlank() } ?: USER_AGENT)
}.execute()
proxies = parseRaw(response.contentString)
proxies = parseRaw(Util.getStringBox(response.contentString))
?: error(app.getString(R.string.no_proxies_found))
subscription.subscriptionUserinfo = response.getHeader("Subscription-Userinfo")
subscription.subscriptionUserinfo =
Util.getStringBox(response.getHeader("Subscription-Userinfo"))
}
val proxiesMap = LinkedHashMap<String, AbstractBean>()

View File

@ -18,6 +18,7 @@ import io.nekohasekai.sagernet.databinding.LayoutAssetsBinding
import io.nekohasekai.sagernet.ktx.*
import io.nekohasekai.sagernet.widget.UndoSnackbarManager
import libcore.Libcore
import moe.matsuri.nb4a.utils.Util
import org.json.JSONObject
import java.io.File
import java.io.FileWriter
@ -283,7 +284,7 @@ class AssetsActivity : ThemedActivity() {
setURL("https://api.github.com/repos/$repo/releases/latest")
}.execute()
val release = JSONObject(response.contentString)
val release = JSONObject(Util.getStringBox(response.contentString))
val tagName = release.optString("tag_name")
if (tagName == localVersion) {

View File

@ -9,6 +9,7 @@ import io.nekohasekai.sagernet.utils.cf.RegisterRequest
import io.nekohasekai.sagernet.utils.cf.UpdateDeviceRequest
import libcore.Libcore
import moe.matsuri.nb4a.utils.JavaUtil.gson
import moe.matsuri.nb4a.utils.Util
// kang from wgcf
object Cloudflare {
@ -37,8 +38,9 @@ object Cloudflare {
setUserAgent("okhttp/3.12.1")
}.execute()
Logs.d(response.contentString)
val device = gson.fromJson(response.contentString, DeviceResponse::class.java)
Logs.d(Util.getStringBox(response.contentString))
val device =
gson.fromJson(Util.getStringBox(response.contentString), DeviceResponse::class.java)
val accessToken = device.token
client.newRequest().apply {

View File

@ -3,6 +3,7 @@ package moe.matsuri.nb4a.utils
import android.annotation.SuppressLint
import android.content.Context
import android.util.Base64
import libcore.StringBox
import java.io.ByteArrayOutputStream
import java.text.SimpleDateFormat
import java.util.*
@ -181,4 +182,10 @@ object Util {
}
}
fun getStringBox(b: StringBox?): String {
if (b != null && b.value != null) {
return b.value
}
return ""
}
}

View File

@ -1,5 +1,6 @@
#!/bin/bash
source ../../env_go.sh || true
source ../buildScript/init/env_ndk.sh
BUILD=".build"

12
libcore/fix.go Normal file
View File

@ -0,0 +1,12 @@
package libcore
// https://github.com/golang/go/issues/46893
// TODO: remove after `bulkBarrierPreWrite: unaligned arguments` fixed
type StringBox struct {
Value string
}
func wrapString(value string) *StringBox {
return &StringBox{Value: value}
}

View File

@ -45,9 +45,9 @@ type HTTPRequest interface {
}
type HTTPResponse interface {
GetHeader(string) string
GetHeader(string) *StringBox
GetContent() ([]byte, error)
GetContentString() (string, error)
GetContentString() (*StringBox, error)
WriteTo(path string) error
}
@ -204,7 +204,7 @@ type httpResponse struct {
}
func (h *httpResponse) errorString() string {
content, err := h.GetContentString()
content, err := h.getContentString()
if err != nil {
return fmt.Sprint("HTTP ", h.Status)
}
@ -214,8 +214,8 @@ func (h *httpResponse) errorString() string {
return fmt.Sprint("HTTP ", h.Status, ": ", content)
}
func (h *httpResponse) GetHeader(key string) string {
return h.Header.Get(key)
func (h *httpResponse) GetHeader(key string) *StringBox {
return wrapString(h.Header.Get(key))
}
func (h *httpResponse) GetContent() ([]byte, error) {
@ -226,7 +226,15 @@ func (h *httpResponse) GetContent() ([]byte, error) {
return h.content, h.contentError
}
func (h *httpResponse) GetContentString() (string, error) {
func (h *httpResponse) GetContentString() (*StringBox, error) {
content, err := h.getContentString()
if err != nil {
return nil, err
}
return wrapString(content), nil
}
func (h *httpResponse) getContentString() (string, error) {
content, err := h.GetContent()
if err != nil {
return "", err