diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/siscomponentrecord.cpp | 11 | ||||
-rw-r--r-- | lib/sisfile.cpp | 12 | ||||
-rw-r--r-- | lib/sisfile.h | 13 | ||||
-rw-r--r-- | lib/sisfileheader.cpp | 75 | ||||
-rw-r--r-- | lib/sisfileheader.h | 15 | ||||
-rw-r--r-- | lib/sisfilerecord.cpp | 31 | ||||
-rw-r--r-- | lib/sislangrecord.cpp | 7 | ||||
-rw-r--r-- | lib/sisreqrecord.cpp | 23 | ||||
-rw-r--r-- | lib/sistypes.cpp | 14 | ||||
-rw-r--r-- | lib/sistypes.h | 6 |
10 files changed, 145 insertions, 62 deletions
diff --git a/lib/siscomponentrecord.cpp b/lib/siscomponentrecord.cpp index b4b313a..ff3153f 100644 --- a/lib/siscomponentrecord.cpp +++ b/lib/siscomponentrecord.cpp @@ -13,7 +13,8 @@ SISComponentNameRecord::~SISComponentNameRecord() void SISComponentNameRecord::fillFrom(uchar* buf, int base, SISFile* sisFile) { - int ix = base; + uchar* p = buf + base; + int size = 0; int n = sisFile->m_header.m_nlangs; m_nameLengths = new uint32[n]; @@ -24,14 +25,16 @@ SISComponentNameRecord::fillFrom(uchar* buf, int base, SISFile* sisFile) // for (int i = 0; i < n; ++i) { - m_nameLengths[i] = read32(buf, &ix); + m_nameLengths[i] = read32(p + size); + size += 4; } // Then read ptrs. // for (int i = 0; i < n; ++i) { - m_namePtrs[i] = read32(buf, &ix); + m_namePtrs[i] = read32(p + size); + size += 4; if (logLevel >= 2) printf("Name %d (for %s) is %.*s\n", i, @@ -44,7 +47,7 @@ SISComponentNameRecord::fillFrom(uchar* buf, int base, SISFile* sisFile) m_names[i][len] = 0; } if (logLevel >= 1) - printf("%d .. %d (%d bytes): Name records\n", base, ix, ix - base); + printf("%d .. %d (%d bytes): Name records\n", base, base + size, size); } uchar* diff --git a/lib/sisfile.cpp b/lib/sisfile.cpp index 53b9c24..9435f52 100644 --- a/lib/sisfile.cpp +++ b/lib/sisfile.cpp @@ -65,6 +65,18 @@ SISFile::getName() } void +SISFile::setDrive(char drive) +{ + m_header.setDrive(drive); +} + +void +SISFile::setFiles(int nFiles) +{ + m_header.setFiles(nFiles); +} + +void SISFile::setLanguage(int lang) { m_header.m_installationLanguage = lang; diff --git a/lib/sisfile.h b/lib/sisfile.h index 5f0bcd5..aa5683d 100644 --- a/lib/sisfile.h +++ b/lib/sisfile.h @@ -36,6 +36,19 @@ public: */ uchar* getName(); + /** + * Set the installed drive. + */ + void setDrive(char drive); + + /** + * Set the number of installed files. + */ + void setFiles(int nFiles); + + /** + * Set the selected installation language. + */ void setLanguage(int lang); SISFileHeader m_header; diff --git a/lib/sisfileheader.cpp b/lib/sisfileheader.cpp index b9800b2..ddd8a11 100644 --- a/lib/sisfileheader.cpp +++ b/lib/sisfileheader.cpp @@ -4,14 +4,18 @@ #include <stdio.h> #include <stdlib.h> +const int OFF_NUMBER_OF_FILES = 26; +const int OFF_INSTALLATION_DRIVE = 28; + void SISFileHeader::fillFrom(uchar* buf, int* base) { - int ix = *base; - m_uid1 = read32(buf, &ix); + uchar* start = buf + *base; + m_buf = buf; + m_uid1 = read32(start); if (logLevel >= 1) printf("Got uid1 = %08x\n", m_uid1); - m_uid2 = read32(buf, &ix); + m_uid2 = read32(start + 4); if (m_uid2 != 0x1000006d) { printf("Got bad uid2.\n"); @@ -19,7 +23,7 @@ SISFileHeader::fillFrom(uchar* buf, int* base) } if (logLevel >= 2) printf("Got uid2 = %08x\n", m_uid2); - m_uid3 = read32(buf, &ix); + m_uid3 = read32(start + 8); if (m_uid3 != 0x10000419) { printf("Got bad uid3.\n"); @@ -27,7 +31,7 @@ SISFileHeader::fillFrom(uchar* buf, int* base) } if (logLevel >= 2) printf("Got uid3 = %08x\n", m_uid3); - m_uid4 = read32(buf, &ix); + m_uid4 = read32(start + 12); // printf("Got uid4 = %08x\n", m_uid4); uint16 crc1 = 0; for (int i = 0; i < 12; i += 2) @@ -43,50 +47,73 @@ SISFileHeader::fillFrom(uchar* buf, int* base) printf("Got bad crc.\n"); exit(1); } - m_crc = read16(buf, &ix); - m_nlangs = read16(buf, &ix); + m_crc = read16(start + 16); + m_nlangs = read16(start + 18); if (logLevel >= 2) printf("Got %d languages\n", m_nlangs); - m_nfiles = read16(buf, &ix); + m_nfiles = read16(start + 20); if (logLevel >= 2) printf("Got %d files\n", m_nfiles); - m_nreqs = read16(buf, &ix); + m_nreqs = read16(start + 22); if (logLevel >= 2) printf("Got %d reqs\n", m_nreqs); - m_installationLanguage = read16(buf, &ix); - m_installationFiles = read16(buf, &ix); - m_installationDrive = read32(buf, &ix); - m_installerVersion = read32(buf, &ix); + m_installationLanguage = read16(start + 24); + if (logLevel >= 2) + printf("Selected language is %d\n", m_installationLanguage); + m_installationFiles = read16(start + OFF_NUMBER_OF_FILES); + if (logLevel >= 2) + printf("Installed files: %d / %d\n", m_installationFiles, m_nfiles); + m_installationDrive = read32(start + OFF_INSTALLATION_DRIVE); + if (logLevel >= 2) + printf("Installed on drive %c\n", m_installationDrive); + m_installerVersion = read32(start + 32); if (logLevel >= 2) printf("Got installer version: %08x\n", m_installerVersion); - m_options = read16(buf, &ix); + m_options = read16(start + 36); if (logLevel >= 2) printf("Got options: %04x\n", m_options); - m_type = read16(buf, &ix); + m_type = read16(start + 38); if (logLevel >= 2) printf("Got type: %0x\n", m_type); - m_major = read16(buf, &ix); + m_major = read16(start + 40); if (logLevel >= 2) printf("Got major: %d\n", m_major); - m_minor = read16(buf, &ix); + m_minor = read16(start + 42); if (logLevel >= 2) printf("Got minor: %d\n", m_minor); - m_minor = read32(buf, &ix); + m_variant = read32(start + 44); if (logLevel >= 2) printf("Got variant: %d\n", m_variant); - m_languagePtr = read32(buf, &ix); + m_languagePtr = read32(start + 48); if (logLevel >= 2) printf("Languages begin at %d\n", m_languagePtr); - m_filesPtr = read32(buf, &ix); + m_filesPtr = read32(start + 52); if (logLevel >= 2) printf("Files begin at %d\n", m_filesPtr); - m_reqPtr = read32(buf, &ix); + m_reqPtr = read32(start + 56); if (logLevel >= 2) printf("Requisites begin at %d\n", m_reqPtr); - m_unknown = read32(buf, &ix); - m_componentPtr = read32(buf, &ix); + m_unknown = read32(start + 60); + m_componentPtr = read32(start + 64); if (logLevel >= 2) printf("Components begin at %d\n", m_componentPtr); - *base = ix; + *base += 68; +} + +void +SISFileHeader::setDrive(char drive) +{ + m_installationDrive = drive; + m_buf[OFF_INSTALLATION_DRIVE] = drive; + m_buf[OFF_INSTALLATION_DRIVE + 1] = + m_buf[OFF_INSTALLATION_DRIVE + 2] = + m_buf[OFF_INSTALLATION_DRIVE + 3] = 0; +} + +void +SISFileHeader::setFiles(int nFiles) +{ + m_installationFiles = nFiles; + write16(m_buf + OFF_NUMBER_OF_FILES, nFiles); } diff --git a/lib/sisfileheader.h b/lib/sisfileheader.h index 1583365..98ca179 100644 --- a/lib/sisfileheader.h +++ b/lib/sisfileheader.h @@ -15,6 +15,16 @@ public: */ void fillFrom(uchar* buf, int* base); + /** + * Update the drive letter, and patch the parsed buffer. + */ + void setDrive(char drive); + + /** + * Update the number of installed files, and patch the parsed buffer. + */ + void setFiles(int nFiles); + enum FileOptions { op_isUnicode = 1, op_isDistributable = 2, @@ -57,6 +67,11 @@ public: uint32 m_reqPtr; uint32 m_unknown; uint32 m_componentPtr; + +private: + + uchar* m_buf; + }; #endif diff --git a/lib/sisfilerecord.cpp b/lib/sisfilerecord.cpp index 74b78c5..3102f1e 100644 --- a/lib/sisfilerecord.cpp +++ b/lib/sisfilerecord.cpp @@ -7,36 +7,39 @@ void SISFileRecord::fillFrom(uchar* buf, int* base, SISFile* sisFile) { - int ix = *base; - m_flags = read32(buf, &ix); + uchar* p = buf + *base; + int size = 0; + m_flags = read32(p); if (logLevel >= 2) printf("Got flags %d\n", m_flags); - m_fileType = read32(buf, &ix); + m_fileType = read32(p + 4); if (logLevel >= 2) printf("Got file type %d\n", m_fileType); - m_fileDetails = read32(buf, &ix); + m_fileDetails = read32(p + 8); if (logLevel >= 2) printf("Got file details %d\n", m_fileDetails); - m_sourceLength = read32(buf, &ix); - m_sourcePtr = read32(buf, &ix); + m_sourceLength = read32(p + 12); + m_sourcePtr = read32(p + 16); // printf("Got source length = %d, source name ptr = %d\n", // m_sourceLength, m_sourcePtr); if (logLevel >= 2) if (m_sourceLength > 0) printf("Got source name %.*s\n", m_sourceLength, buf + m_sourcePtr); - m_destLength = read32(buf, &ix); - m_destPtr = read32(buf, &ix); + m_destLength = read32(p + 20); + m_destPtr = read32(p + 24); // printf("Got dest length = %d, dest name ptr = %d\n", // m_destLength, m_destPtr); if (logLevel >= 2) printf("Got destination name %.*s\n", m_destLength, buf + m_destPtr); + size = 28; switch (m_flags) { case 0: // Only one file. m_fileLengths = new uint32[1]; m_filePtrs = new uint32[1]; - m_fileLengths[0] = read32(buf, &ix); - m_filePtrs[0] = read32(buf, &ix); + m_fileLengths[0] = read32(p + size); + m_filePtrs[0] = read32(p + size + 4); + size += 8; if (logLevel >= 2) printf("File is %d bytes long (at %d) (to %d)\n", m_fileLengths[0], m_filePtrs[0], @@ -57,11 +60,13 @@ SISFileRecord::fillFrom(uchar* buf, int* base, SISFile* sisFile) m_filePtrs = new uint32[n]; for (int i = 0; i < n; ++i) { - m_fileLengths[i] = read32(buf, &ix); + m_fileLengths[i] = read32(p + size); + size += 4; } for (int i = 0; i < n; ++i) { - m_filePtrs[i] = read32(buf, &ix); + m_filePtrs[i] = read32(p + size); + size += 4; int len = m_fileLengths[i]; if (logLevel >= 2) printf("File %d (for %s) is %d bytes long (at %d)\n", @@ -84,6 +89,6 @@ SISFileRecord::fillFrom(uchar* buf, int* base, SISFile* sisFile) if (logLevel >= 2) printf("Unknown file flags %d\n", m_flags); } - *base = ix; + *base += size; } diff --git a/lib/sislangrecord.cpp b/lib/sislangrecord.cpp index c79c45b..ede1d33 100644 --- a/lib/sislangrecord.cpp +++ b/lib/sislangrecord.cpp @@ -6,13 +6,12 @@ void SISLangRecord::fillFrom(uchar* buf, int* base) { - int ix = *base; - m_lang = read16(buf, &ix); + m_lang = read16(buf + *base); if (logLevel >= 2) printf("Got language %d (%s)\n", m_lang, langTable[m_lang].m_name); if (logLevel >= 1) printf("%d .. %d (%d bytes): Language record for %s\n", - *base, ix, ix - *base, langTable[m_lang].m_name); - *base = ix; + *base, *base + 2, 2, langTable[m_lang].m_name); + *base += 2; } diff --git a/lib/sisreqrecord.cpp b/lib/sisreqrecord.cpp index 978ce48..d0c2d12 100644 --- a/lib/sisreqrecord.cpp +++ b/lib/sisreqrecord.cpp @@ -7,28 +7,32 @@ void SISReqRecord::fillFrom(uchar* buf, int* base, SISFile* sisFile) { - int ix = *base; + uchar* p = buf + *base; + int size = 0; - m_uid = read32(buf, &ix); - m_major = read16(buf, &ix); - m_minor = read16(buf, &ix); - m_variant = read32(buf, &ix); + m_uid = read32(p); + m_major = read16(p + 4); + m_minor = read16(p + 6); + m_variant = read32(p + 8); int n = sisFile->m_header.m_nreqs; m_nameLengths = new uint32[n]; m_namePtrs = new uint32[n]; // First read lengths. // + size = 12; for (int i = 0; i < n; ++i) { - m_nameLengths[i] = read32(buf, &ix); + m_nameLengths[i] = read32(p + size); + size += 4; } // Then read ptrs. // for (int i = 0; i < n; ++i) { - m_namePtrs[i] = read32(buf, &ix); + m_namePtrs[i] = read32(p + size); + size += 4; if (logLevel >= 2) printf("Name %d (for %s) is %.*s\n", i, @@ -37,7 +41,8 @@ SISReqRecord::fillFrom(uchar* buf, int* base, SISFile* sisFile) buf + m_namePtrs[i]); } if (logLevel >= 1) - printf("%d .. %d (%d bytes): Req record\n", *base, ix, ix - *base); - *base = ix; + printf("%d .. %d (%d bytes): Req record\n", + *base, *base + size, size); + *base += size; } diff --git a/lib/sistypes.cpp b/lib/sistypes.cpp index 74ae5ea..eb23e5e 100644 --- a/lib/sistypes.cpp +++ b/lib/sistypes.cpp @@ -35,20 +35,22 @@ uint16 calcCRC(uchar* data, int len) return crc; } -uint16 read16(uchar* buf, int* ix) +uint16 read16(uchar* p) { - uchar* p = buf + *ix; - *ix += 2; return p[0] | (p[1] << 8); } -uint32 read32(uchar* buf, int* ix) +uint32 read32(uchar* p) { - uchar* p = buf + *ix; - *ix += 4; return p[0] | (p[1] << 8) | (p[2] << 16) | (p[3] << 24); } +void write16(uchar* p, int val) +{ + p[0] = val & 255; + p[1] = (val >> 8) & 255; +} + LangTableEntry langTable[] = { { 0, "", "Test" }, diff --git a/lib/sistypes.h b/lib/sistypes.h index 834cf43..fbee0d0 100644 --- a/lib/sistypes.h +++ b/lib/sistypes.h @@ -5,9 +5,11 @@ typedef unsigned short uint16; typedef unsigned int uint32; typedef unsigned char uchar; -extern uint16 read16(uchar* buf, int* ix); +extern uint16 read16(uchar* p); -extern uint32 read32(uchar* buf, int* ix); +extern uint32 read32(uchar* p); + +extern void write16(uchar* p, int val); extern void createCRCTable(); |