plptools
Loading...
Searching...
No Matches
sisfilerecord.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 "sisfilerecord.h"
22#include "sisfile.h"
23#include "plpintl.h"
24
25#include <stdio.h>
26
28SISFileRecord::fillFrom(uint8_t* buf, int* base, off_t len, SISFile* sisFile)
29{
30 if (*base + 28 + 4 * 2 > len)
31 return SIS_TRUNCATED;
32
33 SisRC rc = SIS_OK;
34 m_buf = buf;
35 m_len = len;
36 uint8_t* p = buf + *base;
37 int size = 0;
38 m_flags = read32(p);
39 if (logLevel >= 2)
40 printf(_("Got flags %d\n"), m_flags);
41 m_fileType = read32(p + 4);
42 if (logLevel >= 2)
43 printf(_("Got file type %d\n"), m_fileType);
44 m_fileDetails = read32(p + 8);
45 if (logLevel >= 2)
46 printf(_("Got file details %d\n"), m_fileDetails);
47 m_sourceLength = read32(p + 12);
48 m_sourcePtr = read32(p + 16);
49// printf(_("Got source length = %d, source name ptr = %d\n"),
50// m_sourceLength, m_sourcePtr);
51 if (logLevel >= 2)
52 if (m_sourceLength > 0)
53 printf(_("Got source name %.*s\n"), m_sourceLength, buf + m_sourcePtr);
54 m_destLength = read32(p + 20);
55 m_destPtr = read32(p + 24);
56// printf(_("Got dest length = %d, dest name ptr = %d\n"),
57// m_destLength, m_destPtr);
58 if (logLevel >= 2)
59 printf(_("Got destination name %.*s\n"), m_destLength, buf + m_destPtr);
60 size = 28;
61 switch (m_flags)
62 {
63 case 0: // Only one file.
64 m_fileLengths = new uint32_t[1];
65 m_filePtrs = new uint32_t[1];
66 m_fileLengths[0] = read32(p + size);
67 m_filePtrs[0] = read32(p + size + 4);
68 size += 8;
69 if (logLevel >= 2)
70 printf(_("File is %d bytes long (at %d) (to %d)\n"),
73 if (logLevel >= 1)
74 printf(_("%d .. %d (%d bytes): Single file record type %d, %.*s\n"),
75 m_filePtrs[0],
79 m_destLength, buf + m_destPtr);
80 break;
81
82 case 1: // One file per language.
83 {
84 int n = sisFile->m_header.m_nlangs;
85 m_fileLengths = new uint32_t[n];
86 m_filePtrs = new uint32_t[n];
87 if (*base + size + n * 8 > len)
88 return SIS_TRUNCATED;
89 for (int i = 0; i < n; ++i)
90 {
91 m_fileLengths[i] = read32(p + size);
92// if (m_fileLengths[i] > len)
93// rc = SIS_TRUNCATEDDATA;
94 size += 4;
95 }
96 for (int i = 0; i < n; ++i)
97 {
98 m_filePtrs[i] = read32(p + size);
99 int fileLen = m_fileLengths[i];
100// if (m_filePtrs[i] + fileLen > len)
101// rc = SIS_TRUNCATEDDATA;
102 size += 4;
103 if (logLevel >= 2)
104 printf(_("File %d (for %s) is %d bytes long (at %d)\n"),
105 i,
106 sisFile->getLanguage(i)->m_name,
107 fileLen,
108 m_filePtrs[i]);
109 if (logLevel >= 1)
110 printf(_("%d .. %d (%d bytes): File record (%s) for %.*s\n"),
111 m_filePtrs[i],
112 m_filePtrs[i] + fileLen,
113 fileLen,
114 sisFile->getLanguage(i)->m_name,
115 m_destLength, buf + m_destPtr);
116 }
117 break;
118 }
119
120 default:
121 if (logLevel >= 2)
122 printf(_("Unknown file flags %d\n"), m_flags);
123 }
124 *base += size;
125 return rc;
126}
127
128uint8_t*
130{
131 if (fileNo < 0)
132 return 0;
133 if (m_filePtrs[fileNo] >= m_len)
134 return 0;
135 return &m_buf[m_filePtrs[fileNo]];
136}
137
138void
140{
141 if (m_buf[m_destPtr] == '!')
142 m_buf[m_destPtr] = drive;
143}
uint16_t m_nlangs
Definition: sisfileheader.h:87
uint8_t * getFilePtr(int fileNo)
Return a pointer to the file data for the file for the specified language.
uint32_t m_flags
1 if multiple language versions, otherwise 0.
Definition: sisfilerecord.h:64
uint32_t m_sourceLength
Definition: sisfilerecord.h:93
uint32_t m_fileDetails
If file type is 1:
Definition: sisfilerecord.h:91
uint32_t m_destLength
Definition: sisfilerecord.h:95
uint32_t m_destPtr
SisRC fillFrom(uint8_t *buf, int *base, off_t len, SISFile *sisFile)
Populate the fields.
uint8_t * m_buf
The buffer we belong to.
uint32_t m_fileType
Type of file.
Definition: sisfilerecord.h:76
void setMainDrive(char drive)
uint32_t m_sourcePtr
Definition: sisfilerecord.h:94
uint32_t * m_filePtrs
uint32_t * m_fileLengths
Definition: sisfilerecord.h:96
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