From 0b2548da922602c4ea27b60d7ac76b8d7046f255 Mon Sep 17 00:00:00 2001 From: Dmitry Isaenko Date: Tue, 17 Jan 2023 00:58:56 +0300 Subject: [PATCH] Add some sugar to KIP1 and Converter --- src/main/java/libKonogonka/Converter.java | 16 ++++++++++++---- .../Tools/other/System2/ini1/KIP1Provider.java | 10 +++++++++- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/src/main/java/libKonogonka/Converter.java b/src/main/java/libKonogonka/Converter.java index b57066f..a52ed93 100644 --- a/src/main/java/libKonogonka/Converter.java +++ b/src/main/java/libKonogonka/Converter.java @@ -47,12 +47,20 @@ public class Converter { return ByteBuffer.wrap(holder).order(ByteOrder.LITTLE_ENDIAN).getLong(); } - public static String byteArrToHexStringAsLE(byte[] bArr){ - if (bArr == null) + public static String byteArrToHexStringAsLE(byte[] array){ + return byteArrToHexStringAsLE(array, false); + } + public static String byteArrToHexStringAsLE(byte[] array, boolean upperCase){ + if (upperCase) + return byteArrToHexStringAsLE(array, "%02X"); + return byteArrToHexStringAsLE(array, "%02x"); + } + private static String byteArrToHexStringAsLE(byte[] array, String format){ + if (array == null) return ""; StringBuilder sb = new StringBuilder(); - for (byte b: bArr) - sb.append(String.format("%02x", b)); + for (byte b: array) + sb.append(String.format(format, b)); return sb.toString(); } diff --git a/src/main/java/libKonogonka/Tools/other/System2/ini1/KIP1Provider.java b/src/main/java/libKonogonka/Tools/other/System2/ini1/KIP1Provider.java index 169b494..15dc1bb 100644 --- a/src/main/java/libKonogonka/Tools/other/System2/ini1/KIP1Provider.java +++ b/src/main/java/libKonogonka/Tools/other/System2/ini1/KIP1Provider.java @@ -31,6 +31,7 @@ public class KIP1Provider extends ExportAble { private long startOffset; private long endOffset; + private long size; public KIP1Provider(String fileLocation) throws Exception{ this.producer = new InFileStreamClassicProducer(Paths.get(fileLocation)); @@ -58,17 +59,24 @@ public class KIP1Provider extends ExportAble { this.endOffset = HEADER_SIZE + kip1StartOffset + header.getTextSegmentHeader().getSize() + header.getRoDataSegmentHeader().getSize() + header.getRwDataSegmentHeader().getSize() + header.getBssSegmentHeader().getSize(); + size = endOffset - startOffset; } public KIP1Header getHeader() { return header; } public long getStartOffset() { return startOffset; } public long getEndOffset() { return endOffset; } + public long getSize(){ return size; } public boolean export(String saveTo) throws Exception{ stream = producer.produce(); - return export(saveTo, header.getName()+".kip1", startOffset, endOffset - startOffset); + return export(saveTo, header.getName()+".kip1", startOffset, size); } + + public InFileStreamClassicProducer getStreamProducer() throws Exception{ + return producer.getSuccessor(startOffset, true); + } + public boolean exportAsDecompressed(String saveToLocation) throws Exception{ return Kip1Unpacker.unpack(header, producer.getSuccessor(startOffset, true), saveToLocation); }