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
27
const
int
OFF_NUMBER_OF_FILES
= 26;
28
const
int
OFF_INSTALLATION_DRIVE
= 28;
29
30
SisRC
31
SISFileHeader::compareApp
(
SISFileHeader
* other)
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
46
SisRC
47
SISFileHeader::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
);
102
m_installationFiles
=
read16
(start +
OFF_NUMBER_OF_FILES
);
103
if
(
logLevel
>= 2)
104
printf(
_
(
"Installed files: %d / %d\n"
),
m_installationFiles
,
m_nfiles
);
105
m_installationDrive
=
read32
(start +
OFF_INSTALLATION_DRIVE
);
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
151
void
152
SISFileHeader::setDrive
(
char
drive)
153
{
154
m_installationDrive
= drive;
155
m_buf
[
OFF_INSTALLATION_DRIVE
] = drive;
156
m_buf
[
OFF_INSTALLATION_DRIVE
+ 1] =
157
m_buf
[
OFF_INSTALLATION_DRIVE
+ 2] =
158
m_buf
[
OFF_INSTALLATION_DRIVE
+ 3] = 0;
159
}
160
161
void
162
SISFileHeader::setFiles
(
int
nFiles)
163
{
164
m_installationFiles
= nFiles;
165
write16
(
m_buf
+
OFF_NUMBER_OF_FILES
, nFiles);
166
}
SISFileHeader
The first part of a SISFile.
Definition
sisfileheader.h:30
SISFileHeader::m_reqPtr
uint32_t m_reqPtr
Definition
sisfileheader.h:99
SISFileHeader::m_buf
uint8_t * m_buf
Definition
sisfileheader.h:105
SISFileHeader::m_uid3
uint32_t m_uid3
Definition
sisfileheader.h:82
SISFileHeader::setFiles
void setFiles(int nFiles)
Update the number of installed files, and patch the parsed buffer.
Definition
sisfileheader.cpp:162
SISFileHeader::m_uid1
uint32_t m_uid1
Definition
sisfileheader.h:80
SISFileHeader::compareApp
SisRC compareApp(SISFileHeader *other)
Compare uid and version number of this file, with another.
Definition
sisfileheader.cpp:31
SISFileHeader::setDrive
void setDrive(char drive)
Update the drive letter, and patch the parsed buffer.
Definition
sisfileheader.cpp:152
SISFileHeader::m_uid4
uint32_t m_uid4
Definition
sisfileheader.h:83
SISFileHeader::m_componentPtr
uint32_t m_componentPtr
Definition
sisfileheader.h:101
SISFileHeader::m_languagePtr
uint32_t m_languagePtr
Definition
sisfileheader.h:97
SISFileHeader::m_filesPtr
uint32_t m_filesPtr
Definition
sisfileheader.h:98
SISFileHeader::fillFrom
SisRC fillFrom(uint8_t *buf, int *base, off_t len)
Populate the fields.
Definition
sisfileheader.cpp:47
SISFileHeader::m_uid2
uint32_t m_uid2
Definition
sisfileheader.h:81
SISFileHeader::m_nlangs
uint16_t m_nlangs
Definition
sisfileheader.h:85
SISFileHeader::m_major
uint16_t m_major
Definition
sisfileheader.h:94
SISFileHeader::m_variant
uint32_t m_variant
Definition
sisfileheader.h:96
SISFileHeader::m_unknown
uint32_t m_unknown
Definition
sisfileheader.h:100
SISFileHeader::m_installerVersion
uint32_t m_installerVersion
Definition
sisfileheader.h:91
SISFileHeader::m_nreqs
uint16_t m_nreqs
Definition
sisfileheader.h:87
SISFileHeader::m_type
uint16_t m_type
Definition
sisfileheader.h:93
SISFileHeader::m_crc
uint16_t m_crc
Definition
sisfileheader.h:84
SISFileHeader::m_minor
uint16_t m_minor
Definition
sisfileheader.h:95
SISFileHeader::m_installationLanguage
uint16_t m_installationLanguage
Definition
sisfileheader.h:88
SISFileHeader::m_installationFiles
uint16_t m_installationFiles
Definition
sisfileheader.h:89
SISFileHeader::m_nfiles
uint16_t m_nfiles
Definition
sisfileheader.h:86
SISFileHeader::m_options
uint16_t m_options
Definition
sisfileheader.h:92
SISFileHeader::m_installationDrive
uint32_t m_installationDrive
Definition
sisfileheader.h:90
plpintl.h
_
#define _(String)
Definition
plpintl.h:34
OFF_NUMBER_OF_FILES
const int OFF_NUMBER_OF_FILES
Definition
sisfileheader.cpp:27
OFF_INSTALLATION_DRIVE
const int OFF_INSTALLATION_DRIVE
Definition
sisfileheader.cpp:28
sisfileheader.h
updateCrc
uint16_t updateCrc(uint16_t crc, uint8_t value)
Definition
sistypes.cpp:39
read32
uint32_t read32(uint8_t *p)
Definition
sistypes.cpp:56
write16
void write16(uint8_t *p, int val)
Definition
sistypes.cpp:60
logLevel
int logLevel
Definition
sistypes.cpp:25
read16
uint16_t read16(uint8_t *p)
Definition
sistypes.cpp:52
SisRC
SisRC
Return Codes.
Definition
sistypes.h:27
SIS_OK
@ SIS_OK
Definition
sistypes.h:28
SIS_VER_EARLIER
@ SIS_VER_EARLIER
Definition
sistypes.h:35
SIS_DIFFERENT_APP
@ SIS_DIFFERENT_APP
Definition
sistypes.h:34
SIS_TRUNCATED
@ SIS_TRUNCATED
Definition
sistypes.h:29
SIS_CORRUPTED
@ SIS_CORRUPTED
Definition
sistypes.h:31
SIS_SAME_OR_LATER
@ SIS_SAME_OR_LATER
Definition
sistypes.h:36
SIS_OTHER_VARIANT
@ SIS_OTHER_VARIANT
Definition
sistypes.h:37
lib
sisfileheader.cpp
Generated by
1.12.0