forked from Cookies_Github_mirror/AquaDX
Initial Commit
This commit is contained in:
@@ -0,0 +1,20 @@
|
||||
package icu.samnyan.aqua.sega.aimedb.util;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author samnyan (privateamusement@protonmail.com)
|
||||
*/
|
||||
public class AimeDbUtil {
|
||||
|
||||
public static Map<String, Object> getBaseInfo(ByteBuf in) {
|
||||
Map<String, Object> resultMap = new HashMap<>();
|
||||
resultMap.put("gameId", in.toString(0x000a, 0x000e - 0x000a, StandardCharsets.US_ASCII));
|
||||
resultMap.put("keychipId", in.toString(0x0014, 0x001f - 0x0014, StandardCharsets.US_ASCII));
|
||||
return resultMap;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
package icu.samnyan.aqua.sega.aimedb.util;
|
||||
|
||||
import icu.samnyan.aqua.sega.util.ByteBufUtil;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.buffer.Unpooled;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import javax.crypto.BadPaddingException;
|
||||
import javax.crypto.Cipher;
|
||||
import javax.crypto.IllegalBlockSizeException;
|
||||
import javax.crypto.NoSuchPaddingException;
|
||||
import javax.crypto.spec.SecretKeySpec;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.security.InvalidKeyException;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
|
||||
/**
|
||||
* @author samnyan (privateamusement@protonmail.com)
|
||||
*/
|
||||
public class Encryption {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(Encryption.class);
|
||||
|
||||
private static SecretKeySpec KEY = new SecretKeySpec("Copyright(C)SEGA".getBytes(StandardCharsets.UTF_8), "AES");
|
||||
|
||||
public static ByteBuf decrypt(ByteBuf src) throws NoSuchPaddingException, NoSuchAlgorithmException, InvalidKeyException, BadPaddingException, IllegalBlockSizeException {
|
||||
Cipher cipher = Cipher.getInstance("AES/ECB/NoPadding");
|
||||
cipher.init(Cipher.DECRYPT_MODE, KEY);
|
||||
|
||||
return Unpooled.copiedBuffer(cipher.doFinal(ByteBufUtil.toBytes(src)));
|
||||
}
|
||||
|
||||
public static ByteBuf encrypt(ByteBuf src) throws NoSuchPaddingException, NoSuchAlgorithmException, InvalidKeyException, BadPaddingException, IllegalBlockSizeException {
|
||||
Cipher cipher = Cipher.getInstance("AES/ECB/NoPadding");
|
||||
cipher.init(Cipher.ENCRYPT_MODE, KEY);
|
||||
byte[] bytes = cipher.doFinal(ByteBufUtil.toAllBytes(src));
|
||||
return Unpooled.copiedBuffer(bytes);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package icu.samnyan.aqua.sega.aimedb.util;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.module.SimpleModule;
|
||||
import icu.samnyan.aqua.sega.util.jackson.ByteBufSerializer;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* @author samnyan (privateamusement@protonmail.com)
|
||||
*/
|
||||
@Component
|
||||
public class LogMapper {
|
||||
|
||||
private final ObjectMapper mapper;
|
||||
private final SimpleModule module;
|
||||
|
||||
public LogMapper() {
|
||||
mapper = new ObjectMapper();
|
||||
module = new SimpleModule();
|
||||
module.addSerializer(ByteBuf.class, new ByteBufSerializer());
|
||||
mapper.registerModule(module);
|
||||
}
|
||||
|
||||
public String write(Object o) throws JsonProcessingException {
|
||||
return mapper.writeValueAsString(o);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user