Search in sources :

Example 1 with Type

use of info.ata4.junity.serialize.typetree.Type 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 2 with Type

use of info.ata4.junity.serialize.typetree.Type in project disunity by ata4.

the class TypeTreeV1 method writeNode.

private void writeNode(DataWriter out, Node<T> node) throws IOException {
    T type = node.data();
    out.writeStruct(type);
    int numChildren = node.size();
    out.writeInt(numChildren);
    for (Node child : node) {
        writeNode(out, child);
    }
}
Also used : Node(info.ata4.util.collection.Node)

Example 3 with Type

use of info.ata4.junity.serialize.typetree.Type in project disunity by ata4.

the class AssetObjects method tableModel.

@Override
protected TableModel tableModel(SerializedFile serialized) {
    SerializedFileMetadata metadata = serialized.metadata();
    TableBuilder table = new TableBuilder();
    table.row("Path ID", "Offset", "Length", "Type ID", "Class ID");
    Class<ObjectInfo> factory = metadata.objectInfoTable().elementFactory();
    boolean typeTreePresent = metadata.typeTree().embedded();
    boolean v2 = ObjectInfoV2.class.isAssignableFrom(factory);
    boolean v3 = ObjectInfoV3.class.isAssignableFrom(factory);
    if (typeTreePresent) {
        table.append("Class Name");
    }
    if (v2) {
        table.append("Script Type ID");
    }
    if (v3) {
        table.append("Stripped");
    }
    metadata.objectInfoTable().infoMap().entrySet().stream().forEach(e -> {
        ObjectInfo info = e.getValue();
        table.row(e.getKey(), info.offset(), info.length(), info.typeID(), info.classID());
        if (typeTreePresent) {
            TypeRoot<Type> baseClass = metadata.typeTree().typeMap().get(info.typeID());
            String className = baseClass.nodes().data().typeName();
            table.append(className);
        }
        if (v2) {
            table.append(((ObjectInfoV2) info).scriptTypeIndex());
        }
        if (v3) {
            table.append(((ObjectInfoV3) info).isStripped());
        }
    });
    TableModel model = new TableModel("Objects", table.get());
    TextTableFormat format = model.format();
    format.columnFormatter(1, Formatters::hex);
    return model;
}
Also used : SerializedFileMetadata(info.ata4.junity.serialize.SerializedFileMetadata) Type(info.ata4.junity.serialize.typetree.Type) Formatters(info.ata4.disunity.cli.util.Formatters) TextTableFormat(info.ata4.disunity.cli.util.TextTableFormat) TableBuilder(info.ata4.disunity.cli.util.TableBuilder) ObjectInfo(info.ata4.junity.serialize.objectinfo.ObjectInfo) TableModel(info.ata4.disunity.cli.util.TableModel)

Example 4 with Type

use of info.ata4.junity.serialize.typetree.Type in project disunity by ata4.

the class AssetTypes method printTypeNodeText.

private void printTypeNodeText(Node<? extends Type> node, int level) {
    String indent = StringUtils.repeat("  ", level);
    Type type = node.data();
    output().printf("% 4d: %s%s %s (metaFlag: %x)%n", type.index(), indent, type.typeName(), type.fieldName(), type.metaFlag());
    node.forEach(t -> printTypeNodeText(t, level + 1));
}
Also used : Type(info.ata4.junity.serialize.typetree.Type)

Example 5 with Type

use of info.ata4.junity.serialize.typetree.Type in project disunity by ata4.

the class TypeTreeV3 method writeNode.

private void writeNode(DataWriter out, Node<T> node) throws IOException {
    List<T> types = new ArrayList<>();
    serializeNode(node, types, 0);
    // build string table
    AtomicInteger index = new AtomicInteger();
    Map<String, Integer> localMap = new LinkedHashMap<>();
    Map<String, Integer> commonMap = StringTable.commonStrings(revision.major()).inverse();
    Function<String, Integer> addStringOffset = typeName -> {
        if (commonMap.containsKey(typeName)) {
            return commonMap.get(typeName);
        } else if (localMap.containsKey(typeName)) {
            return localMap.get(typeName);
        } else {
            int stringIndex = index.getAndAdd(typeName.length() + 1);
            localMap.put(typeName, stringIndex);
            return stringIndex;
        }
    };
    // apply string offsets
    types.forEach(type -> {
        type.typeOffset(addStringOffset.apply(type.typeName()));
        type.nameOffset(addStringOffset.apply(type.fieldName()));
    });
    out.writeInt(types.size());
    out.writeInt(index.get());
    for (T type : types) {
        out.writeStruct(type);
    }
    for (String string : localMap.keySet()) {
        out.writeStringNull(string);
    }
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) BiMap(com.google.common.collect.BiMap) DataWriter(info.ata4.io.DataWriter) Node(info.ata4.util.collection.Node) IOException(java.io.IOException) SerializedFileException(info.ata4.junity.serialize.SerializedFileException) Function(java.util.function.Function) ArrayList(java.util.ArrayList) UnityHash128(info.ata4.junity.UnityHash128) LinkedHashMap(java.util.LinkedHashMap) List(java.util.List) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Map(java.util.Map) DataReader(info.ata4.io.DataReader) UnityVersion(info.ata4.junity.UnityVersion) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap)

Aggregations

TableBuilder (info.ata4.disunity.cli.util.TableBuilder)3 TableModel (info.ata4.disunity.cli.util.TableModel)3 Map (java.util.Map)3 Formatters (info.ata4.disunity.cli.util.Formatters)2 TextTableFormat (info.ata4.disunity.cli.util.TextTableFormat)2 ObjectInfo (info.ata4.junity.serialize.objectinfo.ObjectInfo)2 Type (info.ata4.junity.serialize.typetree.Type)2 Node (info.ata4.util.collection.Node)2 DataBlock (info.ata4.util.io.DataBlock)2 LinkedHashMap (java.util.LinkedHashMap)2 Parameters (com.beust.jcommander.Parameters)1 BiMap (com.google.common.collect.BiMap)1 DataReader (info.ata4.io.DataReader)1 DataWriter (info.ata4.io.DataWriter)1 UnityHash128 (info.ata4.junity.UnityHash128)1 UnityVersion (info.ata4.junity.UnityVersion)1 SerializedFile (info.ata4.junity.serialize.SerializedFile)1 SerializedFileException (info.ata4.junity.serialize.SerializedFileException)1 SerializedFileMetadata (info.ata4.junity.serialize.SerializedFileMetadata)1 FileIdentifier (info.ata4.junity.serialize.fileidentifier.FileIdentifier)1