summaryrefslogtreecommitdiff
path: root/filter
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@collabora.co.uk>2018-03-23 14:53:44 +0100
committerMiklos Vajna <vmiklos@collabora.co.uk>2018-03-23 15:46:25 +0100
commit679a3b9314d56cad05b5ff2a2c2fa3d320f719bb (patch)
tree97a949dd4f9ba96b461bb34c4ab1aee16a3871d2 /filter
parent1ed1753be26325edf3660c9b9cbd76dc0e9d36ce (diff)
msfilter: extract copy&pasted RTF code from sw and writerfilter
Both the hexdump and the OLE1 reader can be shared. Change-Id: I97d72a8deeb9c79fc8e8c4a73c613213badfa744 Reviewed-on: https://gerrit.libreoffice.org/51783 Reviewed-by: Miklos Vajna <vmiklos@collabora.co.uk> Tested-by: Jenkins <ci@libreoffice.org>
Diffstat (limited to 'filter')
-rw-r--r--filter/source/msfilter/rtfutil.cxx72
1 files changed, 72 insertions, 0 deletions
diff --git a/filter/source/msfilter/rtfutil.cxx b/filter/source/msfilter/rtfutil.cxx
index 31bcffeb4a09..8ac044032163 100644
--- a/filter/source/msfilter/rtfutil.cxx
+++ b/filter/source/msfilter/rtfutil.cxx
@@ -11,6 +11,9 @@
#include <rtl/strbuf.hxx>
#include <osl/diagnose.h>
#include <svtools/rtfkeywd.hxx>
+#include <rtl/character.hxx>
+#include <tools/stream.hxx>
+#include <unotools/streamwrap.hxx>
namespace msfilter
{
@@ -182,6 +185,75 @@ OString OutStringUpr(const sal_Char* pToken, const OUString& rStr, rtl_TextEncod
aRet.append("}}}");
return aRet.makeStringAndClear();
}
+
+int AsHex(char ch)
+{
+ int ret = 0;
+ if (rtl::isAsciiDigit(static_cast<unsigned char>(ch)))
+ ret = ch - '0';
+ else
+ {
+ if (ch >= 'a' && ch <= 'f')
+ ret = ch - 'a';
+ else if (ch >= 'A' && ch <= 'F')
+ ret = ch - 'A';
+ else
+ return -1;
+ ret += 10;
+ }
+ return ret;
+}
+
+bool ExtractOLE2FromObjdata(const OString& rObjdata, SvStream& rOle2)
+{
+ SvMemoryStream aStream;
+ int b = 0, count = 2;
+
+ // Feed the destination text to a stream.
+ for (int i = 0; i < rObjdata.getLength(); ++i)
+ {
+ char ch = rObjdata[i];
+ if (ch != 0x0d && ch != 0x0a)
+ {
+ b = b << 4;
+ sal_Int8 parsed = msfilter::rtfutil::AsHex(ch);
+ if (parsed == -1)
+ return false;
+ b += parsed;
+ count--;
+ if (!count)
+ {
+ aStream.WriteChar(b);
+ count = 2;
+ b = 0;
+ }
+ }
+ }
+
+ // Skip ObjectHeader, see [MS-OLEDS] 2.2.4.
+ if (aStream.Tell())
+ {
+ aStream.Seek(0);
+ sal_uInt32 nData;
+ aStream.ReadUInt32(nData); // OLEVersion
+ aStream.ReadUInt32(nData); // FormatID
+ aStream.ReadUInt32(nData); // ClassName
+ aStream.SeekRel(nData);
+ aStream.ReadUInt32(nData); // TopicName
+ aStream.SeekRel(nData);
+ aStream.ReadUInt32(nData); // ItemName
+ aStream.SeekRel(nData);
+ aStream.ReadUInt32(nData); // NativeDataSize
+
+ if (nData)
+ {
+ rOle2.WriteStream(aStream);
+ rOle2.Seek(0);
+ }
+ }
+
+ return true;
+}
}
}