plptools
Loading...
Searching...
No Matches
sisfileheader.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 "sisfileheader.h"
22#include "plpintl.h"
23
24#include <stdio.h>
25#include <stdlib.h>
26
27const int OFF_NUMBER_OF_FILES = 26;
29
32{
33 if (m_uid1 != other->m_uid1)
34 return SIS_DIFFERENT_APP;
35 if ((m_major < other->m_major) ||
36 ((m_major == other->m_major) &&
37 (m_minor < other->m_minor)))
38 return SIS_VER_EARLIER;
39 if ((m_major == other->m_major) &&
40 (m_minor == other->m_minor) &&
41 (m_variant != other->m_variant))
42 return SIS_OTHER_VARIANT;
43 return SIS_SAME_OR_LATER;
44}
45
47SISFileHeader::fillFrom(uint8_t* buf, int* base, off_t len)
48{
49 if (*base + 68 > len)
50 return SIS_TRUNCATED;
51 uint8_t* start = buf + *base;
52 m_buf = buf;
53 m_uid1 = read32(start);
54 if (logLevel >= 1)
55 printf(_("Got uid1 = %08x\n"), m_uid1);
56 m_uid2 = read32(start + 4);
57 if (m_uid2 != 0x1000006d)
58 {
59 printf("%s", _("Got bad uid2.\n"));
60 return SIS_CORRUPTED;
61 }
62 if (logLevel >= 2)
63 printf(_("Got uid2 = %08x\n"), m_uid2);
64 m_uid3 = read32(start + 8);
65 if (m_uid3 != 0x10000419)
66 {
67 printf("%s", _("Got bad uid3.\n"));
68 return SIS_CORRUPTED;
69 }
70 if (logLevel >= 2)
71 printf(_("Got uid3 = %08x\n"), m_uid3);
72 m_uid4 = read32(start + 12);
73 if (logLevel >= 2)
74 printf(_("Got uid4 = %08x\n"), m_uid4);
75 uint16_t crc1 = 0;
76 for (int i = 0; i < 12; i += 2)
77 crc1 = updateCrc(crc1, buf[*base + i]);
78 uint16_t crc2 = 0;
79 for (int i = 0; i < 12; i += 2)
80 crc2 = updateCrc(crc2, buf[*base + i + 1]);
81 if (logLevel >= 2)
82 printf(_("Got first crc = %08x, wanted %08x\n"),
83 crc2 << 16 | crc1, m_uid4);
84 if ((crc2 << 16 | crc1) != m_uid4)
85 {
86 printf("%s", _("Got bad crc.\n"));
87 return SIS_CORRUPTED;
88 }
89 m_crc = read16(start + 16);
90 m_nlangs = read16(start + 18);
91 if (logLevel >= 2)
92 printf(_("Got %d languages\n"), m_nlangs);
93 m_nfiles = read16(start + 20);
94 if (logLevel >= 2)
95 printf(_("Got %d files\n"), m_nfiles);
96 m_nreqs = read16(start + 22);
97 if (logLevel >= 2)
98 printf(_("Got %d reqs\n"), m_nreqs);
99 m_installationLanguage = read16(start + 24);
100 if (logLevel >= 2)
101 printf(_("Selected language is %d\n"), m_installationLanguage);
103 if (logLevel >= 2)
104 printf(_("Installed files: %d / %d\n"), m_installationFiles, m_nfiles);
106 if (logLevel >= 2)
107 printf(_("Installed on drive %c\n"), m_installationDrive);
108 m_installerVersion = read32(start + 32);
109 if (logLevel >= 2)
110 printf(_("Got installer version: %08x\n"), m_installerVersion);
111 m_options = read16(start + 36);
112 if (logLevel >= 2)
113 printf(_("Got options: %04x\n"), m_options);
114 m_type = read16(start + 38);
115 if (logLevel >= 2)
116 printf(_("Got type: %04x\n"), m_type);
117 m_major = read16(start + 40);
118 if (logLevel >= 2)
119 printf(_("Got major: %d\n"), m_major);
120 m_minor = read16(start + 42);
121 if (logLevel >= 2)
122 printf(_("Got minor: %d\n"), m_minor);
123 m_variant = read32(start + 44);
124 if (logLevel >= 2)
125 printf(_("Got variant: %d\n"), m_variant);
126 m_languagePtr = read32(start + 48);
127 if (logLevel >= 2)
128 printf(_("Languages begin at %d\n"), m_languagePtr);
129// if (m_languagePtr >= len)
130// return SIS_TRUNCATED;
131 m_filesPtr = read32(start + 52);
132 if (logLevel >= 2)
133 printf(_("Files begin at %d\n"), m_filesPtr);
134// if (m_filesPtr >= len)
135// return SIS_TRUNCATED;
136 m_reqPtr = read32(start + 56);
137 if (logLevel >= 2)
138 printf(_("Requisites begin at %d\n"), m_reqPtr);
139// if (m_reqPtr >= len)
140// return SIS_TRUNCATED;
141 m_unknown = read32(start + 60);
142 m_componentPtr = read32(start + 64);
143 if (logLevel >= 2)
144 printf(_("Components begin at %d\n"), m_componentPtr);
145// if (m_componentPtr >= len)
146// return SIS_TRUNCATED;
147 *base += 68;
148 return SIS_OK;
149}
150
151void
153{
154 m_installationDrive = drive;
159}
160
161void
163{
164 m_installationFiles = nFiles;
166}
The first part of a SISFile.
Definition: sisfileheader.h:32
uint32_t m_reqPtr
uint8_t * m_buf
uint32_t m_uid3
Definition: sisfileheader.h:84
void setFiles(int nFiles)
Update the number of installed files, and patch the parsed buffer.
uint32_t m_uid1
Definition: sisfileheader.h:82
SisRC compareApp(SISFileHeader *other)
Compare uid and version number of this file, with another.
void setDrive(char drive)
Update the drive letter, and patch the parsed buffer.
uint32_t m_uid4
Definition: sisfileheader.h:85
uint32_t m_componentPtr
uint32_t m_languagePtr
Definition: sisfileheader.h:99
uint32_t m_filesPtr
SisRC fillFrom(uint8_t *buf, int *base, off_t len)
Populate the fields.
uint32_t m_uid2
Definition: sisfileheader.h:83
uint16_t m_nlangs
Definition: sisfileheader.h:87
uint16_t m_major
Definition: sisfileheader.h:96
uint32_t m_variant
Definition: sisfileheader.h:98
uint32_t m_unknown
uint32_t m_installerVersion
Definition: sisfileheader.h:93
uint16_t m_nreqs
Definition: sisfileheader.h:89
uint16_t m_type
Definition: sisfileheader.h:95
uint16_t m_crc
Definition: sisfileheader.h:86
uint16_t m_minor
Definition: sisfileheader.h:97
uint16_t m_installationLanguage
Definition: sisfileheader.h:90
uint16_t m_installationFiles
Definition: sisfileheader.h:91
uint16_t m_nfiles
Definition: sisfileheader.h:88
uint16_t m_options
Definition: sisfileheader.h:94
uint32_t m_installationDrive
Definition: sisfileheader.h:92
#define _(String)
Definition: plpintl.h:35
const int OFF_NUMBER_OF_FILES
const int OFF_INSTALLATION_DRIVE
uint16_t updateCrc(uint16_t crc, uint8_t value)
Definition: sistypes.cpp:41
uint32_t read32(uint8_t *p)
Definition: sistypes.cpp:62
void write16(uint8_t *p, int val)
Definition: sistypes.cpp:67
int logLevel
Definition: sistypes.cpp:25
uint16_t read16(uint8_t *p)
Definition: sistypes.cpp:57
SisRC
Return Codes.
Definition: sistypes.h:29
@ SIS_OK
Definition: sistypes.h:30
@ SIS_VER_EARLIER
Definition: sistypes.h:37
@ SIS_DIFFERENT_APP
Definition: sistypes.h:36
@ SIS_TRUNCATED
Definition: sistypes.h:31
@ SIS_CORRUPTED
Definition: sistypes.h:33
@ SIS_SAME_OR_LATER
Definition: sistypes.h:38
@ SIS_OTHER_VARIANT
Definition: sistypes.h:39