Add some sugar to KIP1 and Converter
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Dmitry Isaenko 2023-01-17 00:58:56 +03:00
parent 373d254b6a
commit 0b2548da92
2 changed files with 21 additions and 5 deletions

View file

@ -47,12 +47,20 @@ public class Converter {
return ByteBuffer.wrap(holder).order(ByteOrder.LITTLE_ENDIAN).getLong(); return ByteBuffer.wrap(holder).order(ByteOrder.LITTLE_ENDIAN).getLong();
} }
public static String byteArrToHexStringAsLE(byte[] bArr){ public static String byteArrToHexStringAsLE(byte[] array){
if (bArr == null) 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 ""; return "";
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
for (byte b: bArr) for (byte b: array)
sb.append(String.format("%02x", b)); sb.append(String.format(format, b));
return sb.toString(); return sb.toString();
} }

View file

@ -31,6 +31,7 @@ public class KIP1Provider extends ExportAble {
private long startOffset; private long startOffset;
private long endOffset; private long endOffset;
private long size;
public KIP1Provider(String fileLocation) throws Exception{ public KIP1Provider(String fileLocation) throws Exception{
this.producer = new InFileStreamClassicProducer(Paths.get(fileLocation)); this.producer = new InFileStreamClassicProducer(Paths.get(fileLocation));
@ -58,17 +59,24 @@ public class KIP1Provider extends ExportAble {
this.endOffset = HEADER_SIZE + kip1StartOffset + this.endOffset = HEADER_SIZE + kip1StartOffset +
header.getTextSegmentHeader().getSize() + header.getRoDataSegmentHeader().getSize() + header.getTextSegmentHeader().getSize() + header.getRoDataSegmentHeader().getSize() +
header.getRwDataSegmentHeader().getSize() + header.getBssSegmentHeader().getSize(); header.getRwDataSegmentHeader().getSize() + header.getBssSegmentHeader().getSize();
size = endOffset - startOffset;
} }
public KIP1Header getHeader() { return header; } public KIP1Header getHeader() { return header; }
public long getStartOffset() { return startOffset; } public long getStartOffset() { return startOffset; }
public long getEndOffset() { return endOffset; } public long getEndOffset() { return endOffset; }
public long getSize(){ return size; }
public boolean export(String saveTo) throws Exception{ public boolean export(String saveTo) throws Exception{
stream = producer.produce(); 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{ public boolean exportAsDecompressed(String saveToLocation) throws Exception{
return Kip1Unpacker.unpack(header, producer.getSuccessor(startOffset, true), saveToLocation); return Kip1Unpacker.unpack(header, producer.getSuccessor(startOffset, true), saveToLocation);
} }