Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 37 additions & 20 deletions main/POIFS/FileSystem/Ole10Native.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,15 @@ namespace NPOI.POIFS.FileSystem
*
* @author Rainer Schwarze
*/

public class Ole10Native
{
public static String OLE10_NATIVE = "\x0001Ole10Native";
protected static String ISO1 = "ISO-8859-1";

// (the fields as they appear in the raw record:)
private int totalSize; // 4 bytes, total size of record not including this field

private short flags1 = 2; // 2 bytes, unknown, mostly [02 00]
private String label; // ASCIIZ, stored in this field without the terminating zero
private String fileName; // ASCIIZ, stored in this field without the terminating zero
Expand All @@ -46,8 +48,10 @@ public class Ole10Native

/**
* the field encoding mode - merely a try-and-error guess ...
**/
private enum EncodingMode {
**/

private enum EncodingMode
{
/**
* the data is stored in parsed format - including label, command, etc.
*/
Expand All @@ -61,8 +65,9 @@ private enum EncodingMode {
*/
compact
}

private EncodingMode mode;

/// <summary>
/// Creates an instance of this class from an embedded OLE Object. The OLE Object is expected
/// to include a stream &quot;{01}Ole10Native&quot; which Contains the actual
Expand Down Expand Up @@ -91,15 +96,17 @@ public static Ole10Native CreateFromEmbeddedOleObject(DirectoryNode directory)

return new Ole10Native(data, 0);
}

/**
* Creates an instance and fills the fields based on ... the fields
*/

public Ole10Native(String label, String filename, String command, byte[] data)
{
Label=(label);
FileName=(filename);
Command=(command);
DataBuffer=(data);
Label = (label);
FileName = (filename);
Command = (command);
DataBuffer = (data);
mode = EncodingMode.parsed;
}

Expand All @@ -110,6 +117,7 @@ public Ole10Native(String label, String filename, String command, byte[] data)
* @param offset The start offset of the record in the buffer
* @throws Ole10NativeException on invalid or unexcepted data format
*/

public Ole10Native(byte[] data, int offset)
{
int ofs = offset; // current offset, Initialized to start
Expand Down Expand Up @@ -172,25 +180,31 @@ public Ole10Native(byte[] data, int offset)
}

break;

case EncodingMode.compact:
flags1 = LittleEndian.GetShort(data, ofs);
ofs += LittleEndianConsts.SHORT_SIZE;
dataSize = totalSize - LittleEndianConsts.SHORT_SIZE;
break;

case EncodingMode.unparsed:
dataSize = totalSize;
break;
}

if ((long)dataSize + (long)ofs > (long)data.Length)
{ //cast to avoid overflow
throw new Ole10NativeException("Invalid Ole10Native: declared data length > available data");
}
dataBuffer = new byte[dataSize];
Array.Copy(data, ofs, dataBuffer, 0, dataSize);
ofs += dataSize;

}

/*
* Helper - determine length of zero terminated string (ASCIIZ).
*/

private static int GetStringLength(byte[] data, int ofs)
{
int len = 0;
Expand All @@ -208,6 +222,7 @@ private static int GetStringLength(byte[] data, int ofs)
*
* @return the totalSize
*/

public int TotalSize
{
get
Expand All @@ -221,6 +236,7 @@ public int TotalSize
*
* @return the flags1
*/

public short Flags1
{
get
Expand All @@ -236,6 +252,7 @@ public short Flags1
*
* @return the label
*/

public String Label
{
get
Expand All @@ -254,6 +271,7 @@ public String Label
*
* @return the fileName
*/

public String FileName
{
get
Expand All @@ -271,6 +289,7 @@ public String FileName
*
* @return the flags2
*/

public short Flags2
{
get
Expand All @@ -288,6 +307,7 @@ public short Flags2
*
* @return the unknown1
*/

public short Unknown1
{
get
Expand All @@ -306,6 +326,7 @@ public short Unknown1
*
* @return the command
*/

public String Command
{
get
Expand All @@ -322,10 +343,10 @@ public String Command
*
* @return the dataSize
*/

public int DataSize
{
get{return dataBuffer.Length;}

get { return dataBuffer.Length; }
}

/**
Expand All @@ -336,17 +357,19 @@ public int DataSize
*
* @return the dataBuffer
*/

public byte[] DataBuffer
{
get { return dataBuffer; }
set { dataBuffer =(byte[])value.Clone(); }
set { dataBuffer = (byte[])value.Clone(); }
}

/**
* Returns the flags3 - currently unknown.
*
* @return the flags3
*/

public short Flags3
{
get
Expand All @@ -365,12 +388,13 @@ public short Flags3
* around, but non atom classes will just request the bytes from their
* children, then chuck on their header and return)
*/

public void WriteOut(Stream out1)
{
byte[] intbuf = new byte[LittleEndianConsts.INT_SIZE];
byte[] shortbuf = new byte[LittleEndianConsts.SHORT_SIZE];
byte[] zerobuf = { 0, 0, 0, 0 };

LittleEndianOutputStream leosOut = new LittleEndianOutputStream(out1);

switch (mode)
Expand Down Expand Up @@ -405,20 +429,13 @@ public void WriteOut(Stream out1)
leosOut.WriteShort(Flags1);
out1.Write(DataBuffer, 0, DataBuffer.Length);
break;

default:
case EncodingMode.unparsed:
leosOut.WriteInt(DataSize);
out1.Write(DataBuffer, 0, DataBuffer.Length);
break;
}

}

}

}





Loading