plptools
Loading...
Searching...
No Matches
sisreqrecord.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 "sisreqrecord.h"
22#include "sisfile.h"
23#include "plpintl.h"
24
25#include <stdio.h>
26
27SisRC SISReqRecord::fillFrom(uint8_t* buf, int* base, off_t len, SISFile* sisFile) {
28 int n = sisFile->m_header.m_nlangs;
29 if (*base + 12 + n * 4 * 2 > len) {
30 return SIS_TRUNCATED;
31 }
32
33 uint8_t* p = buf + *base;
34 int size = 0;
35
36 m_uid = read32(p);
37 m_major = read16(p + 4);
38 m_minor = read16(p + 6);
39 m_variant = read32(p + 8);
40 m_nameLengths = new uint32_t[n];
41 m_namePtrs = new uint32_t[n];
42 if (logLevel >= 2) {
43 printf(_("Requisite: uid=%08x, version=%d.%d-%d.\n"), m_uid, m_major, m_minor, m_variant);
44 }
45
46 // First read lengths.
47 //
48 size = 12;
49 for (int i = 0; i < n; ++i) {
50 m_nameLengths[i] = read32(p + size);
51 if (logLevel >= 2) {
52 printf(_("Got namelength %d\n"), m_nameLengths[i]);
53 }
54 size += 4;
55 }
56
57 // Then read ptrs.
58 //
59 for (int i = 0; i < n; ++i) {
60 m_namePtrs[i] = read32(p + size);
61 if (logLevel >= 2) {
62 printf(_("Got namepos %d\n"), m_namePtrs[i]);
63 }
64 if (m_namePtrs[i] + m_nameLengths[i] > len) {
65 printf(_("Position/length too large for req record %d.\n"), i);
66 return SIS_CORRUPTED;
67 }
68 size += 4;
69 if (logLevel >= 2) {
70 printf(_("Name of requisite for %s is %.*s\n"),
71 sisFile->getLanguage(i)->m_name,
73 buf + m_namePtrs[i]);
74 }
75 }
76 if (logLevel >= 1) {
77 printf(_("%d .. %d (%d bytes): Req record for uid %08x\n"), *base, *base + size, size, m_uid);
78 }
79 *base += size;
80 return SIS_OK;
81}
uint16_t m_nlangs
Definition: sisfileheader.h:85
The top level container of a SIS file.
Definition: sisfile.h:34
SISFileHeader m_header
Definition: sisfile.h:106
int getLanguage()
Return the currently selected installation language.
Definition: sisfile.cpp:137
uint32_t m_uid
Definition: sisreqrecord.h:43
uint16_t m_major
Definition: sisreqrecord.h:44
uint32_t m_variant
Definition: sisreqrecord.h:46
uint32_t * m_namePtrs
Definition: sisreqrecord.h:48
SisRC fillFrom(uint8_t *buf, int *base, off_t len, SISFile *sisFile)
Populate the fields.
uint16_t m_minor
Definition: sisreqrecord.h:45
uint32_t * m_nameLengths
Definition: sisreqrecord.h:47
#define _(String)
Definition: plpintl.h:34
uint32_t read32(uint8_t *p)
Definition: sistypes.cpp:56
int logLevel
Definition: sistypes.cpp:25
uint16_t read16(uint8_t *p)
Definition: sistypes.cpp:52
SisRC
Return Codes.
Definition: sistypes.h:27
@ SIS_OK
Definition: sistypes.h:28
@ SIS_TRUNCATED
Definition: sistypes.h:29
@ SIS_CORRUPTED
Definition: sistypes.h:31