Search in sources :

Example 1 with SerializedFileHeader

use of info.ata4.junity.serialize.SerializedFileHeader in project disunity by ata4.

the class SerializedFileReader method readMetadata.

private void readMetadata(DataReader in) throws IOException {
    SerializedFileMetadata metadata = serialized.metadata();
    SerializedFileHeader header = serialized.header();
    DataBlock metadataBlock = serialized.metadataBlock();
    metadataBlock.markBegin(in);
    metadata.version(header.version());
    in.readStruct(metadata);
    metadataBlock.markEnd(in);
    L.log(Level.FINER, "metadataBlock: {0}", metadataBlock);
}
Also used : DataBlock(info.ata4.util.io.DataBlock)

Example 2 with SerializedFileHeader

use of info.ata4.junity.serialize.SerializedFileHeader in project disunity by ata4.

the class SerializedFileReader method readObjects.

private void readObjects(DataReader in) throws IOException {
    long ofsMin = Long.MAX_VALUE;
    long ofsMax = Long.MIN_VALUE;
    SerializedFileHeader header = serialized.header();
    SerializedFileMetadata metadata = serialized.metadata();
    Map<Long, ObjectInfo> objectInfoMap = metadata.objectInfoTable().infoMap();
    Map<Integer, TypeRoot<Type>> typeTreeMap = metadata.typeTree().typeMap();
    List<SerializedObjectData> objectData = serialized.objectData();
    for (Map.Entry<Long, ObjectInfo> infoEntry : objectInfoMap.entrySet()) {
        ObjectInfo info = infoEntry.getValue();
        long id = infoEntry.getKey();
        long ofs = header.dataOffset() + info.offset();
        ofsMin = Math.min(ofsMin, ofs);
        ofsMax = Math.max(ofsMax, ofs + info.length());
        SerializedObjectData object = new SerializedObjectData(id);
        object.info(info);
        // create and read object data buffer
        ByteBuffer buf = ByteBufferUtils.allocate((int) info.length());
        in.position(ofs);
        in.readBuffer(buf);
        object.buffer(buf);
        // get type tree if possible
        TypeRoot typeRoot = typeTreeMap.get(info.typeID());
        if (typeRoot != null) {
            object.typeTree(typeRoot.nodes());
        }
        objectData.add(object);
    }
    DataBlock objectDataBlock = serialized.objectDataBlock();
    objectDataBlock.offset(ofsMin);
    objectDataBlock.endOffset(ofsMax);
    L.log(Level.FINER, "objectDataBlock: {0}", objectDataBlock);
}
Also used : ByteBuffer(java.nio.ByteBuffer) ObjectInfo(info.ata4.junity.serialize.objectinfo.ObjectInfo) DataBlock(info.ata4.util.io.DataBlock) TypeRoot(info.ata4.junity.serialize.typetree.TypeRoot) Map(java.util.Map)

Example 3 with SerializedFileHeader

use of info.ata4.junity.serialize.SerializedFileHeader in project disunity by ata4.

the class SerializedFileWriter method writeMetadata.

private void writeMetadata(DataWriter out) throws IOException {
    SerializedFileMetadata metadata = serialized.metadata();
    SerializedFileHeader header = serialized.header();
    DataBlock metadataBlock = serialized.metadataBlock();
    metadataBlock.markBegin(out);
    metadata.version(header.version());
    out.writeStruct(metadata);
    metadataBlock.markEnd(out);
    L.log(Level.FINER, "metadataBlock: {0}", metadataBlock);
}
Also used : DataBlock(info.ata4.util.io.DataBlock)

Example 4 with SerializedFileHeader

use of info.ata4.junity.serialize.SerializedFileHeader in project disunity by ata4.

the class SerializedFileTest method offsetsAndSizesValid.

@Test
public void offsetsAndSizesValid() throws IOException {
    SerializedFileHeader header = asset.header();
    long fileSize = Files.size(readFile);
    assertEquals("Header file size and actual file size must be equal", header.fileSize(), fileSize);
    assertTrue("Data offset must be within file", header.dataOffset() < header.fileSize());
    // allowing a difference of 3 bytes because of padding
    assertEquals("Metadata sizes in data block and header must match", header.metadataSize(), asset.metadataBlock().length(), 3);
    // check blocks
    List<DataBlock> blocks = asset.dataBlocks();
    blocks.forEach(block1 -> blocks.forEach(block2 -> {
        if (block1 != block2) {
            assertFalse("Blocks are overlapping: " + block1 + " / " + block2, block1.isIntersecting(block2));
        }
    }));
}
Also used : SerializedFileWriter(info.ata4.junity.serialize.SerializedFileWriter) RunWith(org.junit.runner.RunWith) Type(info.ata4.junity.serialize.typetree.Type) ArrayList(java.util.ArrayList) Path(java.nio.file.Path) WRITE(java.nio.file.StandardOpenOption.WRITE) Parameterized(org.junit.runners.Parameterized) Before(org.junit.Before) DataWriters(info.ata4.io.DataWriters) ParameterizedUtils(info.ata4.test.ParameterizedUtils) Files(java.nio.file.Files) Node(info.ata4.util.collection.Node) Assert.assertNotNull(org.junit.Assert.assertNotNull) Assert.assertTrue(org.junit.Assert.assertTrue) IOException(java.io.IOException) FileUtils(org.apache.commons.io.FileUtils) Test(org.junit.Test) DataBlock(info.ata4.util.io.DataBlock) SerializedFile(info.ata4.junity.serialize.SerializedFile) List(java.util.List) SerializedFileHeader(info.ata4.junity.serialize.SerializedFileHeader) Paths(java.nio.file.Paths) Assert.assertFalse(org.junit.Assert.assertFalse) SerializedFileReader(info.ata4.junity.serialize.SerializedFileReader) Assert.assertEquals(org.junit.Assert.assertEquals) SerializedFileHeader(info.ata4.junity.serialize.SerializedFileHeader) DataBlock(info.ata4.util.io.DataBlock) Test(org.junit.Test)

Example 5 with SerializedFileHeader

use of info.ata4.junity.serialize.SerializedFileHeader in project disunity by ata4.

the class AssetHeader method tableModel.

@Override
protected TableModel tableModel(SerializedFile serialized) {
    SerializedFileHeader header = serialized.header();
    TableBuilder table = new TableBuilder();
    table.row("Field", "Value");
    table.row("metadataSize", header.metadataSize());
    table.row("fileSize", header.fileSize());
    table.row("version", header.version());
    table.row("dataOffset", header.dataOffset());
    if (header.version() >= 9) {
        table.row("endianness", header.endianness());
    }
    return new TableModel("Header", table.get());
}
Also used : TableBuilder(info.ata4.disunity.cli.util.TableBuilder) SerializedFileHeader(info.ata4.junity.serialize.SerializedFileHeader) TableModel(info.ata4.disunity.cli.util.TableModel)

Aggregations

DataBlock (info.ata4.util.io.DataBlock)4 SerializedFileHeader (info.ata4.junity.serialize.SerializedFileHeader)2 TableBuilder (info.ata4.disunity.cli.util.TableBuilder)1 TableModel (info.ata4.disunity.cli.util.TableModel)1 DataWriters (info.ata4.io.DataWriters)1 SerializedFile (info.ata4.junity.serialize.SerializedFile)1 SerializedFileReader (info.ata4.junity.serialize.SerializedFileReader)1 SerializedFileWriter (info.ata4.junity.serialize.SerializedFileWriter)1 ObjectInfo (info.ata4.junity.serialize.objectinfo.ObjectInfo)1 Type (info.ata4.junity.serialize.typetree.Type)1 TypeRoot (info.ata4.junity.serialize.typetree.TypeRoot)1 ParameterizedUtils (info.ata4.test.ParameterizedUtils)1 Node (info.ata4.util.collection.Node)1 IOException (java.io.IOException)1 ByteBuffer (java.nio.ByteBuffer)1 Files (java.nio.file.Files)1 Path (java.nio.file.Path)1 Paths (java.nio.file.Paths)1 WRITE (java.nio.file.StandardOpenOption.WRITE)1 ArrayList (java.util.ArrayList)1