mirror of
https://github.com/MewoLab/AquaDX.git
synced 2026-02-10 06:27:26 +08:00
[-] ByteBufUtil
This commit is contained in:
@@ -1,12 +1,30 @@
|
|||||||
package icu.samnyan.aqua.sega.aimedb
|
package icu.samnyan.aqua.sega.aimedb
|
||||||
|
|
||||||
import icu.samnyan.aqua.sega.util.ByteBufUtil
|
|
||||||
import io.netty.buffer.ByteBuf
|
import io.netty.buffer.ByteBuf
|
||||||
import io.netty.buffer.Unpooled.copiedBuffer
|
import io.netty.buffer.Unpooled.copiedBuffer
|
||||||
import java.nio.charset.StandardCharsets
|
import java.nio.charset.StandardCharsets
|
||||||
import javax.crypto.Cipher
|
import javax.crypto.Cipher
|
||||||
import javax.crypto.spec.SecretKeySpec
|
import javax.crypto.spec.SecretKeySpec
|
||||||
|
|
||||||
|
fun ByteBuf.toBytes(): ByteArray {
|
||||||
|
val readerPos = readerIndex()
|
||||||
|
resetReaderIndex()
|
||||||
|
val result = ByteArray(readableBytes())
|
||||||
|
readBytes(result)
|
||||||
|
readerIndex(readerPos)
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
|
fun ByteBuf.toAllBytes(): ByteArray {
|
||||||
|
val readerPos = readerIndex()
|
||||||
|
resetReaderIndex()
|
||||||
|
writerIndex(capacity())
|
||||||
|
val result = ByteArray(capacity())
|
||||||
|
readBytes(result)
|
||||||
|
readerIndex(readerPos)
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author samnyan (privateamusement@protonmail.com)
|
* @author samnyan (privateamusement@protonmail.com)
|
||||||
*/
|
*/
|
||||||
@@ -15,7 +33,6 @@ object AimeDbEncryption {
|
|||||||
val enc = Cipher.getInstance("AES/ECB/NoPadding").apply { init(Cipher.ENCRYPT_MODE, KEY) }
|
val enc = Cipher.getInstance("AES/ECB/NoPadding").apply { init(Cipher.ENCRYPT_MODE, KEY) }
|
||||||
val dec = Cipher.getInstance("AES/ECB/NoPadding").apply { init(Cipher.DECRYPT_MODE, KEY) }
|
val dec = Cipher.getInstance("AES/ECB/NoPadding").apply { init(Cipher.DECRYPT_MODE, KEY) }
|
||||||
|
|
||||||
fun decrypt(src: ByteBuf) = copiedBuffer(dec.doFinal(ByteBufUtil.toBytes(src)))
|
fun decrypt(src: ByteBuf) = copiedBuffer(dec.doFinal(src.toBytes()))
|
||||||
|
fun encrypt(src: ByteBuf) = copiedBuffer(enc.doFinal(src.toAllBytes()))
|
||||||
fun encrypt(src: ByteBuf) = copiedBuffer(enc.doFinal(ByteBufUtil.toAllBytes(src)))
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ package icu.samnyan.aqua.sega.allnet
|
|||||||
import ext.*
|
import ext.*
|
||||||
import icu.samnyan.aqua.net.db.AquaNetUserRepo
|
import icu.samnyan.aqua.net.db.AquaNetUserRepo
|
||||||
import icu.samnyan.aqua.sega.allnet.AllNetBillingDecoder.decodeAllNet
|
import icu.samnyan.aqua.sega.allnet.AllNetBillingDecoder.decodeAllNet
|
||||||
import icu.samnyan.aqua.sega.util.AquaConst
|
|
||||||
import jakarta.servlet.http.HttpServletRequest
|
import jakarta.servlet.http.HttpServletRequest
|
||||||
import jakarta.servlet.http.HttpServletResponse
|
import jakarta.servlet.http.HttpServletResponse
|
||||||
import org.springframework.boot.context.properties.ConfigurationProperties
|
import org.springframework.boot.context.properties.ConfigurationProperties
|
||||||
@@ -14,7 +13,6 @@ import java.io.InputStream
|
|||||||
import java.nio.charset.StandardCharsets
|
import java.nio.charset.StandardCharsets
|
||||||
import java.time.Instant
|
import java.time.Instant
|
||||||
import java.time.LocalDateTime
|
import java.time.LocalDateTime
|
||||||
import java.util.*
|
|
||||||
|
|
||||||
@Configuration
|
@Configuration
|
||||||
@ConfigurationProperties(prefix = "allnet.server")
|
@ConfigurationProperties(prefix = "allnet.server")
|
||||||
@@ -84,7 +82,7 @@ class AllNet(
|
|||||||
|
|
||||||
logger.info("AllNet /DownloadOrder : $reqMap")
|
logger.info("AllNet /DownloadOrder : $reqMap")
|
||||||
|
|
||||||
val serial = reqMap["serial"] ?: AquaConst.DEFAULT_KEYCHIP_ID
|
val serial = reqMap["serial"] ?: "A69E01A8888"
|
||||||
val resp = mapOf(
|
val resp = mapOf(
|
||||||
"stat" to "1",
|
"stat" to "1",
|
||||||
"serial" to serial
|
"serial" to serial
|
||||||
|
|||||||
@@ -1,59 +0,0 @@
|
|||||||
package icu.samnyan.aqua.sega.util;
|
|
||||||
|
|
||||||
import io.netty.buffer.ByteBuf;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author samnyan (privateamusement@protonmail.com)
|
|
||||||
*/
|
|
||||||
public class ByteBufUtil {
|
|
||||||
|
|
||||||
private static final char[] HEX_ARRAY = "0123456789ABCDEF".toCharArray();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Read bytes from start to current writer index
|
|
||||||
* Not modifying the reader index
|
|
||||||
*
|
|
||||||
* @param byteBuf The input buffer
|
|
||||||
* @return bytes
|
|
||||||
*/
|
|
||||||
public static byte[] toBytes(ByteBuf byteBuf) {
|
|
||||||
|
|
||||||
int readerPos = byteBuf.readerIndex();
|
|
||||||
byteBuf.resetReaderIndex();
|
|
||||||
byte[] result = new byte[byteBuf.readableBytes()];
|
|
||||||
byteBuf.readBytes(result);
|
|
||||||
|
|
||||||
byteBuf.readerIndex(readerPos);
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Move writer index to the capacity and read all the byte to the end
|
|
||||||
* Not modifying the reader index
|
|
||||||
*
|
|
||||||
* @param byteBuf The input buffer
|
|
||||||
* @return bytes
|
|
||||||
*/
|
|
||||||
public static byte[] toAllBytes(ByteBuf byteBuf) {
|
|
||||||
|
|
||||||
int readerPos = byteBuf.readerIndex();
|
|
||||||
byteBuf.resetReaderIndex();
|
|
||||||
byteBuf.writerIndex(byteBuf.capacity());
|
|
||||||
byte[] result = new byte[byteBuf.capacity()];
|
|
||||||
byteBuf.readBytes(result);
|
|
||||||
|
|
||||||
byteBuf.readerIndex(readerPos);
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String bytesToHex(byte[] bytes) {
|
|
||||||
char[] hexChars = new char[bytes.length * 2];
|
|
||||||
for (int j = 0; j < bytes.length; j++) {
|
|
||||||
int v = bytes[j] & 0xFF;
|
|
||||||
hexChars[j * 2] = HEX_ARRAY[v >>> 4];
|
|
||||||
hexChars[j * 2 + 1] = HEX_ARRAY[v & 0x0F];
|
|
||||||
}
|
|
||||||
return new String(hexChars);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user