LibreOffice Module hwpfilter (master) 1
htags.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 */
19
20#include "precompile.h"
21
23#include <unotools/tempfile.hxx>
24
25#include <string.h>
26
27#include "hwplib.h"
28#include "hwpfile.h"
29#include "htags.h"
30
32{
33 size_t nRead = hwpf.ReadBlock(filename, 256);
34 nRead += hwpf.Read2b(bookmark, 16);
35 nRead += hwpf.ReadBlock(macro, 325);
36 if (hwpf.Read1b(type))
37 ++nRead;
38 else
39 type = 0;
40 nRead += hwpf.ReadBlock(reserve, 3);
41 if( type == 2 )
42 {
43 for( int i = 1; i < 256; i++)
44 {
45 filename[i-1] = filename[i];
46 if( filename[i] == 0 )
47 break;
48 }
49 }
50 return nRead == 617;
51}
52
54 : size(tsize >= 32 ? tsize - 32 : 0)
55 , data(size, 0)
56{
57}
58
60{
61};
62
64{
65 if (size == 0)
66 return false;
67 hwpf.ReadBlock(name, 16);
68 hwpf.ReadBlock(type, 16);
69 name[0] = 'H';
70 name[1] = 'W';
71 name[2] = 'P';
72 return hwpf.ReadBlock(data.data(), size) != 0;
73}
74
75
77 : signature(0)
78#ifdef _WIN32
79 , pis(nullptr)
80#endif
81{
82 size = tsize - 4;
83 if (size <= 0)
84 return;
85};
86
87#ifdef _WIN32
88OlePicture::~OlePicture()
89{
90 if( pis )
91 pis->Release();
92};
93#endif
94
95#define FILESTG_SIGNATURE_NORMAL 0xF8995568
96
98{
99 if (size <= 0)
100 return;
101
102// We process only FILESTG_SIGNATURE_NORMAL.
103 hwpf.Read4b(signature);
105 return;
106#ifdef _WIN32
107 char *data = new char[size];
108 if (hwpf.ReadBlock(data,size) == 0)
109 {
110 delete [] data;
111 return;
112 }
113
114 utl::TempFileNamed aTempFile;
115 aTempFile.EnableKillingFile();
116
117 SvFileStream aOutputStream(aTempFile.GetURL(), StreamMode::WRITE);
118 aOutputStream.WriteBytes(data, size);
119 delete [] data;
120 aOutputStream.Close();
121 if( StgOpenStorage(o3tl::toW(aTempFile.GetFileName().getStr()), nullptr,
122 STGM_READWRITE|STGM_SHARE_EXCLUSIVE|STGM_TRANSACTED,
123 nullptr, 0, &pis) != S_OK ) {
124 pis = nullptr;
125 return;
126 }
127#else
128 hwpf.SkipBlock(size);
129#endif
130}
131
132/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
The HWPFile class is the main class of hwp for reading file information from stream.
Definition: hwpfile.h:98
size_t SkipBlock(size_t size)
Skips some bytes from HIODev.
Definition: hwpfile.cxx:176
bool Read1b(unsigned char &out)
Reads one byte from HIODev.
Definition: hwpfile.cxx:123
bool Read2b(unsigned short &out)
Reads two byte from HIODev.
Definition: hwpfile.cxx:137
size_t ReadBlock(void *ptr, size_t size)
Reads some bytes from HIODev not regarding endian's way.
Definition: hwpfile.cxx:171
bool Read4b(unsigned int &out)
Reads four byte from HIODev.
Definition: hwpfile.cxx:152
std::size_t WriteBytes(const void *pData, std::size_t nSize)
void EnableKillingFile(bool bEnable=true)
OUString const & GetURL() const
OUString GetFileName() const
#define FILESTG_SIGNATURE_NORMAL
Definition: htags.cxx:95
size
int i
char name[16]
Definition: htags.h:36
size_t size
Definition: htags.h:35
char type[16]
Definition: htags.h:37
bool Read(HWPFile &hwpf)
Definition: htags.cxx:63
EmPicture(size_t size)
Definition: htags.cxx:53
~EmPicture(void)
Definition: htags.cxx:59
std::vector< uchar > data
Definition: htags.h:38
char reserve[3]
Definition: htags.h:54
kchar filename[256]
Definition: htags.h:50
bool Read(HWPFile &hwpf)
Definition: htags.cxx:31
uchar type
Definition: htags.h:53
hchar bookmark[16]
Definition: htags.h:51
char macro[325]
Definition: htags.h:52
int size
Definition: htags.h:62
OlePicture(int tsize)
Definition: htags.cxx:76
uint signature
Definition: htags.h:63
void Read(HWPFile &hwpf)
Definition: htags.cxx:97