Search in sources :

Example 1 with HSLFEscherRecordFactory

use of org.apache.poi.hslf.record.HSLFEscherRecordFactory in project poi by apache.

the class SlideShowDumper method walkEscherDDF.

/**
   * Use the DDF code to walk the Escher records
   */
public void walkEscherDDF(int indent, int pos, int len) {
    if (len < 8) {
        return;
    }
    final String ind = (indent == 0) ? "%1$s" : "%1$" + indent + "s";
    byte[] contents = new byte[len];
    System.arraycopy(docstream, pos, contents, 0, len);
    DefaultEscherRecordFactory erf = new HSLFEscherRecordFactory();
    EscherRecord record = erf.createRecord(contents, 0);
    // For now, try filling in the fields
    record.fillFields(contents, 0, erf);
    long atomType = LittleEndian.getUShort(contents, 2);
    // This lacks the 8 byte header size
    long atomLen = LittleEndian.getUShort(contents, 4);
    // This (should) include the 8 byte header size
    int recordLen = record.getRecordSize();
    String fmt = ind + "At position %2$d (%2$04x): type is %3$d (%3$04x), len is %4$d (%4$04x) (%5$d) - record claims %6$d";
    out.println(String.format(Locale.ROOT, fmt, "", pos, atomType, atomLen, atomLen + 8, recordLen));
    // Check for corrupt / lying ones
    if (recordLen != 8 && (recordLen != (atomLen + 8))) {
        out.println(String.format(Locale.ROOT, ind + "** Atom length of $2d ($3d) doesn't match record length of %4d", "", atomLen, atomLen + 8, recordLen));
    }
    // Print the record's details
    String recordStr = record.toString().replace("\n", String.format(Locale.ROOT, "\n" + ind, ""));
    out.println(String.format(Locale.ROOT, ind + "%2$s", "", recordStr));
    if (record instanceof EscherContainerRecord) {
        walkEscherDDF((indent + 3), pos + 8, (int) atomLen);
    }
    // Handle records that seem to lie
    if (atomType == 61451L) {
        // Normally claims a size of 8
        recordLen = (int) atomLen + 8;
    }
    if (atomType == 61453L) {
        // Returns EscherContainerRecord, but really msofbtClientTextbox
        recordLen = (int) atomLen + 8;
        record.fillFields(contents, 0, erf);
        if (!(record instanceof EscherTextboxRecord)) {
            out.println(String.format(Locale.ROOT, ind + "%2$s", "", "** Really a msofbtClientTextbox !"));
        }
    }
    // Decide on what to do, based on how the lengths match up
    if (recordLen == 8 && atomLen > 8) {
        // Assume it has children, rather than being corrupted
        walkEscherDDF((indent + 3), pos + 8, (int) atomLen);
        // Wind on our length + our header
        pos += atomLen;
        pos += 8;
        len -= atomLen;
        len -= 8;
    } else {
        // No children, wind on our real length
        pos += atomLen;
        pos += 8;
        len -= atomLen;
        len -= 8;
    }
    // Move on to the next one, if we're not at the end yet
    if (len >= 8) {
        walkEscherDDF(indent, pos, len);
    }
}
Also used : EscherTextboxRecord(org.apache.poi.ddf.EscherTextboxRecord) HSLFEscherRecordFactory(org.apache.poi.hslf.record.HSLFEscherRecordFactory) EscherContainerRecord(org.apache.poi.ddf.EscherContainerRecord) EscherRecord(org.apache.poi.ddf.EscherRecord) DefaultEscherRecordFactory(org.apache.poi.ddf.DefaultEscherRecordFactory)

Example 2 with HSLFEscherRecordFactory

use of org.apache.poi.hslf.record.HSLFEscherRecordFactory in project poi by apache.

the class SlideShowRecordDumper method walkTree.

public void walkTree(int depth, int pos, Record[] records, int indent) throws IOException {
    String ind = tabs.substring(0, indent);
    for (int i = 0; i < records.length; i++) {
        Record r = records[i];
        if (r == null) {
            ps.println(ind + "At position " + pos + " (" + makeHex(pos, 6) + "):");
            ps.println(ind + "Warning! Null record found.");
            continue;
        }
        // Figure out how big it is
        int len = getDiskLen(r);
        // Grab the type as hex
        String hexType = makeHex((int) r.getRecordType(), 4);
        String rHexType = reverseHex(hexType);
        // Grab the hslf.record type
        Class<? extends Record> c = r.getClass();
        String cname = c.toString();
        if (cname.startsWith("class ")) {
            cname = cname.substring(6);
        }
        if (cname.startsWith("org.apache.poi.hslf.record.")) {
            cname = cname.substring(27);
        }
        // Display the record
        ps.println(ind + "At position " + pos + " (" + makeHex(pos, 6) + "):");
        ps.println(ind + " Record is of type " + cname);
        ps.println(ind + " Type is " + r.getRecordType() + " (" + hexType + " -> " + rHexType + " )");
        ps.println(ind + " Len is " + (len - 8) + " (" + makeHex((len - 8), 8) + "), on disk len is " + len);
        // print additional information for drawings and atoms
        if (optEscher && cname.equals("PPDrawing")) {
            DefaultEscherRecordFactory factory = new HSLFEscherRecordFactory();
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            r.writeOut(baos);
            byte[] b = baos.toByteArray();
            EscherRecord er = factory.createRecord(b, 0);
            er.fillFields(b, 0, factory);
            printEscherRecord(er, indent + 1);
        } else if (optVerbose && r.getChildRecords() == null) {
            String recData = getPrintableRecordContents(r);
            ps.println(ind + recData);
        }
        ps.println();
        // If it has children, show them
        if (r.getChildRecords() != null) {
            walkTree((depth + 3), pos + 8, r.getChildRecords(), indent + 1);
        }
        // Wind on the position marker
        pos += len;
    }
}
Also used : Record(org.apache.poi.hslf.record.Record) EscherContainerRecord(org.apache.poi.ddf.EscherContainerRecord) EscherTextboxRecord(org.apache.poi.ddf.EscherTextboxRecord) EscherRecord(org.apache.poi.ddf.EscherRecord) HSLFEscherRecordFactory(org.apache.poi.hslf.record.HSLFEscherRecordFactory) ByteArrayOutputStream(java.io.ByteArrayOutputStream) EscherRecord(org.apache.poi.ddf.EscherRecord) DefaultEscherRecordFactory(org.apache.poi.ddf.DefaultEscherRecordFactory)

Aggregations

DefaultEscherRecordFactory (org.apache.poi.ddf.DefaultEscherRecordFactory)2 EscherContainerRecord (org.apache.poi.ddf.EscherContainerRecord)2 EscherRecord (org.apache.poi.ddf.EscherRecord)2 EscherTextboxRecord (org.apache.poi.ddf.EscherTextboxRecord)2 HSLFEscherRecordFactory (org.apache.poi.hslf.record.HSLFEscherRecordFactory)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 Record (org.apache.poi.hslf.record.Record)1