plptools
Loading...
Searching...
No Matches
siscomponentrecord.cpp
Go to the documentation of this file.
1/*
2 * This file is part of plptools.
3 *
4 * Copyright (C) 2002 Daniel Brahneborg <basic.chello@se>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * along with this program; if not, see <https://www.gnu.org/licenses/>.
18 */
19#include "config.h"
20
21#include "siscomponentrecord.h"
22#include "sisfile.h"
23#include "plpintl.h"
24
25#include <stdio.h>
26#include <string.h>
27
29{
30 m_names = NULL;
31}
32
34{
35 if (m_names)
36 {
37 for (int i = 0; i < m_nameCount; ++i)
38 delete[] m_names[i];
39 delete[] m_names;
40 }
41}
42
44SISComponentNameRecord::fillFrom(uint8_t* buf, int* basePos, off_t len,
45 SISFile* sisFile)
46{
47 int n = sisFile->m_header.m_nlangs;
48 int base = *basePos;
49 int entrySize = 8 + n * 4 * 2;
50 if (base + entrySize > len)
51 return SIS_TRUNCATED;
52 *basePos += entrySize;
53
54 uint8_t* p = buf + base;
55 int size = 0;
56
57 m_nameLengths = new uint32_t[n];
58 m_namePtrs = new uint32_t[n];
59
60 // First read lengths.
61 //
62 for (int i = 0; i < n; ++i)
63 {
64 m_nameLengths[i] = read32(p + size);
65 if (m_nameLengths[i] > len)
66 {
67 printf(_("Length too large for name record %d.\n"), i);
68 return SIS_TRUNCATED;
69 }
70 size += 4;
71 }
72
73 // Then read ptrs.
74 //
75 m_names = new uint8_t*[n];
76 m_nameCount = n;
77 for (int i = 0; i < n; ++i)
78 {
79 m_namePtrs[i] = read32(p + size);
80 if (m_namePtrs[i] + m_nameLengths[i] > len)
81 {
82 printf(_("Position/length too large for name record %d.\n"), i);
83 return SIS_TRUNCATED;
84 }
85 size += 4;
86 if (logLevel >= 2)
87 printf(_("Name %d (for %s) is %.*s\n"),
88 i,
89 sisFile->getLanguage(i)->m_name,
91 buf + m_namePtrs[i]);
92 int nlen = m_nameLengths[i];
93 m_names[i] = new uint8_t[nlen + 1];
94 memcpy(m_names[i], buf + m_namePtrs[i], nlen);
95 m_names[i][nlen] = 0;
96 }
97 if (logLevel >= 1)
98 printf(_("%d .. %d (%d bytes): Name records\n"), base, base + size, size);
99 return SIS_OK;
100}
101
102uint32_t
104{
105 uint32_t last = 0;
106 for (int i = 0; i < m_nameCount; ++i)
107 {
108 uint32_t pos = m_namePtrs[i] + m_nameLengths[i];
109 if (last < pos)
110 last = pos;
111 }
112 return last;
113}
114
115uint8_t*
117{
118 return m_names[no];
119}
SisRC fillFrom(uint8_t *buf, int *base, off_t len, SISFile *sisFile)
Populate the fields.
int m_nameCount
The number of names, so we know how much to delete.
uint32_t getLastEnd()
Find out the end position for the last name in the file.
uint8_t ** m_names
The extracted names, as zero terminated strings.
uint8_t * getName(int no)
Return the name for the given language.
uint16_t m_nlangs
Definition: sisfileheader.h:87
The top level container of a SIS file.
Definition: sisfile.h:36
SISFileHeader m_header
Definition: sisfile.h:108
int getLanguage()
Return the currently selected installation language.
Definition: sisfile.cpp:137
#define _(String)
Definition: plpintl.h:35
uint32_t read32(uint8_t *p)
Definition: sistypes.cpp:62
int logLevel
Definition: sistypes.cpp:25
SisRC
Return Codes.
Definition: sistypes.h:29
@ SIS_OK
Definition: sistypes.h:30
@ SIS_TRUNCATED
Definition: sistypes.h:31