inno 0.4.2

Library for reading Inno Setup executables
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
/*!
Inno is a read-only parser for [Inno Setup](https://jrsoftware.org/isinfo.php) installers (.exe).
It reads the installer structures so you can inspect an installer without actually running it.

This crate focuses on correctness across a wide range of Inno Setup versions and provides
strongly-typed access to sections like Languages, Files, Tasks, Components, Registry entries, and
more. It does not execute any installer logic.

# Getting started

Add this to your `Cargo.toml`:

```toml
[dependencies]
inno = "0.4"
```

Then, open an installer and inspect its contents:

```no_run
use std::fs::File;
use inno::Inno;

fn main() -> Result<(), inno::error::InnoError> {
    let file = File::open("path/to/setup.exe")?;
    let inno = Inno::new(file)?;

    println!("Inno Setup version: {}", inno.version());

    if let Some(name) = inno.header.app_name() {
        println!("App name: {name}");
    }

    println!("Languages ({}):", inno.languages().len());
    for lang in inno.languages() {
        println!("- {}", lang.name());
    }

    Ok(())
}
```

## Optional Features

The following are a list of [Cargo features][cargo-features] that can be enabled or disabled:

- **chrono**: Enables converting a file's created at time to a [`DateTime<UTC>`].
- **jiff**: Enables converting a file's created at time to a [`Timestamp`].

# What this crate provides

- A high-level [`Inno`] struct representing a parsed installer, including:
  - [`Inno::version`]: the detected installer version and variant (Unicode/ANSI, ISX, etc.).
  - [`Inno::header`]: top-level metadata and configuration (app name, publisher, compression, wizard
    settings, etc.).
  - Collections for languages, messages, permissions, types, components, tasks, directories, files,
    icons, INI entries, registry entries, and run entries.
  - [`Inno::file_locations`]: low-level data/file location entries for consumers that want to
    implement extraction.
- Safe decoding of text according to the installer’s Unicode/ANSI mode and language codepage.
- Version-aware parsing that accounts for structural changes between Inno Setup releases.

This crate does not extract files by itself, but it exposes enough information
(e.g., file locations, checksums, compression type) for downstream tools to do so.
See the `innex` CLI in this repository for a reference consumer.

# Supported versions

Parsing is supported up to Inno Setup 6.7.x. Newer installers may work but can introduce format
changes. In that case, you will get [`InnoError::UnsupportedVersion`].

# Features

- LZMA/BZip2/Deflate detection through header metadata.
- Optional static LZMA linking via the `lzma-static` feature for consumers that
  need it:

  ```toml
  [dependencies]
  inno = { version = "0.2", features = ["lzma-static"] }
  ```

# Error handling

All fallible operations return [`InnoError`]. Typical errors include:

- Not an Inno installer file.
- Unsupported (too-new) installer version.
- I/O errors while reading.
- Unexpected data at the end of a header stream (corruption or truncated file).

# Notes on text decoding

In Unicode installers, text is always read as UTF-16LE. In ANSI installers,
this crate picks a codepage based on the language table, preferring
Windows-1252 when no explicit match is found, to maximize compatibility with
older installers.

# Minimum Supported Rust Version (MSRV)

This crate is tested with Rust 1.88 or newer. Newer Rust versions are generally recommended.

# Acknowledgements

- innoextract: <https://github.com/dscharrer/innoextract>
- Inno Setup: <https://jrsoftware.org/isinfo.php>

[cargo-features]: https://doc.rust-lang.org/stable/cargo/reference/manifest.html#the-features-section
[`DateTime<Utc>`]: https://docs.rs/chrono/latest/chrono/struct.DateTime.html
[`Timestamp`]: https://docs.rs/jiff/latest/jiff/struct.Timestamp.html
*/

#![doc(html_root_url = "https://docs.rs/inno")]
#![allow(dead_code)]

mod compression;
mod encryption;
pub mod entry;
pub mod error;
pub mod header;
mod loader;
mod lzma_stream_header;
mod pe;
mod read;
pub mod string;
pub mod version;
mod wizard;

use std::{
    io,
    io::{Read, Seek, SeekFrom},
};

use encoding_rs::{UTF_16LE, WINDOWS_1252};
use encryption::EncryptionHeader;
use entry::{
    Component, DeleteEntry, Directory, File, FileLocation, ISSigKey, Icon, Ini, Language, Message,
    MessageEntry, Permission, RegistryEntry, RunEntry, Task, Type,
};
use error::{HeaderStream, InnoError};
pub use header::Header;
use itertools::Itertools;
use loader::SetupLoader;
use read::{ReadBytesExt, stream::InnoStreamReader};
use version::{InnoVersion, windows_version::WindowsVersionRange};
pub use wizard::Wizard;
pub use zerocopy;

#[derive(Debug)]
pub struct Inno {
    pub setup_loader: SetupLoader,
    version: InnoVersion,
    encryption_header: Option<EncryptionHeader>,
    pub header: Header,
    languages: Vec<Language>,
    messages: Vec<MessageEntry>,
    permissions: Vec<Permission>,
    type_entries: Vec<Type>,
    components: Vec<Component>,
    tasks: Vec<Task>,
    directories: Vec<Directory>,
    is_sig_keys: Vec<ISSigKey>,
    files: Vec<File>,
    icons: Vec<Icon>,
    ini_entries: Vec<Ini>,
    registry_entries: Vec<RegistryEntry>,
    delete_entries: Vec<DeleteEntry>,
    uninstall_delete_entries: Vec<DeleteEntry>,
    run_entries: Vec<RunEntry>,
    uninstall_run_entries: Vec<RunEntry>,
    wizard: Wizard,
    file_locations: Vec<FileLocation>,
}

impl Inno {
    /// The maximum supported Inno Version by this library.
    ///
    /// Inno Setup versions newer than this version are likely to have breaking changes where the
    /// changes have not yet been implemented into this library.
    pub const MAX_SUPPORTED_VERSION: InnoVersion = InnoVersion::new(6, 7, u8::MAX, u8::MAX);

    pub fn new<R>(mut reader: R) -> Result<Self, InnoError>
    where
        R: Read + Seek,
    {
        let setup_loader =
            SetupLoader::read_from(&mut reader).map_err(|_| InnoError::NotInnoFile)?;

        // Seek to Inno header
        reader.seek(SeekFrom::Start(setup_loader.header_offset().unsigned_abs()))?;

        let mut inno_version = InnoVersion::read(&mut reader)?;

        if inno_version > Self::MAX_SUPPORTED_VERSION {
            return Err(InnoError::UnsupportedVersion(inno_version));
        }

        // Inno Setup sometimes didn't increment the version number between versions with breaking
        // changes. If the version is ambiguous, try reading using successive candidate versions
        // until one succeeds.
        if let Some(mut versions_to_try) = inno_version.ambiguous_candidates().map(Vec::into_iter) {
            let position = reader.stream_position()?;

            loop {
                match Self::read_stream(&mut reader, setup_loader, inno_version) {
                    Ok(inno) => break Ok(inno),
                    Err(err) => {
                        if let Some(next) = versions_to_try.next() {
                            inno_version = next;
                            reader.seek(SeekFrom::Start(position))?;
                        } else {
                            break Err(err);
                        }
                    }
                }
            }
        } else {
            Self::read_stream(&mut reader, setup_loader, inno_version)
        }
    }

    fn read_stream<R: Read + Seek>(
        mut reader: R,
        setup_loader: SetupLoader,
        inno_version: InnoVersion,
    ) -> Result<Self, InnoError> {
        let encryption_header = if inno_version >= 6.5 {
            Some(EncryptionHeader::read(&mut reader, inno_version)?)
        } else {
            None
        };

        let mut reader = InnoStreamReader::new(&mut reader, inno_version)?;

        let mut header = Header::read(&mut reader, inno_version)?;

        let languages = (0..header.language_count())
            .map(|_| Language::read(&mut reader, inno_version))
            .collect::<io::Result<Vec<_>>>()?;

        let codepage = if inno_version.is_unicode() {
            UTF_16LE
        } else {
            languages
                .iter()
                .map(Language::codepage)
                .find_or_first(|&codepage| codepage == WINDOWS_1252)
                .unwrap_or(WINDOWS_1252)
        };

        header.decode(codepage);

        let mut wizard = if inno_version < 4 {
            Wizard::read(&mut reader, &header, inno_version)?
        } else {
            Wizard::default()
        };

        let messages = (0..header.custom_message_count())
            .map(|_| MessageEntry::read(&mut reader, &languages, codepage))
            .collect::<io::Result<Vec<_>>>()?;

        let permissions = (0..header.permission_count())
            .map(|_| Permission::read(&mut reader))
            .collect::<io::Result<Vec<_>>>()?;

        let type_entries = (0..header.type_count())
            .map(|_| Type::read(&mut reader, codepage, inno_version))
            .collect::<io::Result<Vec<_>>>()?;

        let components = (0..header.component_count())
            .map(|_| Component::read(&mut reader, codepage, inno_version))
            .collect::<io::Result<Vec<_>>>()?;

        let tasks = (0..header.task_count())
            .map(|_| Task::read(&mut reader, codepage, inno_version))
            .collect::<io::Result<Vec<_>>>()?;

        let directories = (0..header.directory_count())
            .map(|_| Directory::read(&mut reader, codepage, inno_version))
            .collect::<io::Result<Vec<_>>>()?;

        let is_sig_keys = (0..header.is_sig_keys_count())
            .map(|_| ISSigKey::read(&mut reader, codepage))
            .collect::<io::Result<Vec<_>>>()?;

        let files = (0..header.file_count())
            .map(|_| File::read(&mut reader, codepage, inno_version))
            .collect::<io::Result<Vec<_>>>()?;

        let icons = (0..header.icon_count())
            .map(|_| Icon::read(&mut reader, codepage, inno_version))
            .collect::<io::Result<Vec<_>>>()?;

        let ini_entries = (0..header.ini_entry_count())
            .map(|_| Ini::read(&mut reader, codepage, inno_version))
            .collect::<io::Result<Vec<_>>>()?;

        let registry_entries = (0..header.registry_entry_count())
            .map(|_| RegistryEntry::read(&mut reader, codepage, inno_version))
            .collect::<io::Result<Vec<_>>>()?;

        let delete_entries = (0..header.install_delete_entry_count())
            .map(|_| DeleteEntry::read(&mut reader, codepage, inno_version))
            .collect::<io::Result<Vec<_>>>()?;

        let uninstall_delete_entries = (0..header.uninstall_delete_entry_count())
            .map(|_| DeleteEntry::read(&mut reader, codepage, inno_version))
            .collect::<io::Result<Vec<_>>>()?;

        let run_entries = (0..header.run_entry_count())
            .map(|_| RunEntry::read(&mut reader, codepage, inno_version))
            .collect::<io::Result<Vec<_>>>()?;

        let uninstall_run_entries = (0..header.uninstall_run_entry_count())
            .map(|_| RunEntry::read(&mut reader, codepage, inno_version))
            .collect::<io::Result<Vec<_>>>()?;

        if inno_version >= 4 {
            wizard = Wizard::read(&mut reader, &header, inno_version)?;
        }

        // Check that the reader is at the end of the primary header stream
        if !reader.is_end_of_stream() {
            return Err(InnoError::UnexpectedExtraData(HeaderStream::Primary));
        }

        // Reset the block reader for the secondary header stream
        reader = reader.reset()?;

        let file_locations = (0..header.file_location_entry_count())
            .map(|_| FileLocation::read(&mut reader, &header, inno_version))
            .collect::<io::Result<Vec<_>>>()?;

        if !reader.is_end_of_stream() {
            return Err(InnoError::UnexpectedExtraData(HeaderStream::Secondary));
        }

        Ok(Self {
            setup_loader,
            version: inno_version,
            encryption_header,
            header,
            languages,
            messages,
            permissions,
            type_entries,
            components,
            tasks,
            directories,
            is_sig_keys,
            files,
            icons,
            ini_entries,
            registry_entries,
            delete_entries,
            uninstall_delete_entries,
            run_entries,
            uninstall_run_entries,
            wizard,
            file_locations,
        })
    }

    /// Returns the Inno Setup version.
    #[must_use]
    #[inline]
    pub const fn version(&self) -> InnoVersion {
        self.version
    }

    /// Returns the encryption header, if any.
    #[must_use]
    pub fn encryption_header(&self) -> Option<&EncryptionHeader> {
        self.encryption_header
            .as_ref()
            .or_else(|| self.header.encryption_header())
    }

    /// Returns the primary language of the installer, if available.
    #[must_use]
    #[inline]
    pub const fn primary_language(&self) -> Option<&Language> {
        self.languages().first()
    }

    /// Returns the languages as a slice.
    #[must_use]
    #[inline]
    pub const fn languages(&self) -> &[Language] {
        self.languages.as_slice()
    }

    /// Returns the message entries as a slice.
    #[must_use]
    #[inline]
    pub const fn message_entries(&self) -> &[MessageEntry] {
        self.messages.as_slice()
    }

    pub fn messages(&self) -> impl Iterator<Item = Message<'_, '_>> {
        self.messages
            .iter()
            .map(|message| Message::new(message, self.languages()))
    }

    /// Returns the permission entries as a slice.
    #[must_use]
    #[inline]
    pub const fn permissions(&self) -> &[Permission] {
        self.permissions.as_slice()
    }

    /// Returns the type entries as a slice.
    #[must_use]
    #[inline]
    pub const fn type_entries(&self) -> &[Type] {
        self.type_entries.as_slice()
    }

    /// Returns the component entries as a slice.
    #[must_use]
    #[inline]
    pub const fn components(&self) -> &[Component] {
        self.components.as_slice()
    }

    /// Returns the task entries as a slice.
    #[must_use]
    #[inline]
    pub const fn tasks(&self) -> &[Task] {
        self.tasks.as_slice()
    }

    /// Returns the directory entries as a slice.
    #[must_use]
    #[inline]
    pub const fn directories(&self) -> &[Directory] {
        self.directories.as_slice()
    }

    /// Returns the IS Sig Key entries as a slice.
    #[must_use]
    #[inline]
    pub const fn is_sig_keys(&self) -> &[ISSigKey] {
        self.is_sig_keys.as_slice()
    }

    /// Returns the file entries as a slice.
    #[must_use]
    #[inline]
    pub const fn files(&self) -> &[File] {
        self.files.as_slice()
    }

    /// Returns the icon entries as a slice.
    #[must_use]
    #[inline]
    pub const fn icons(&self) -> &[Icon] {
        self.icons.as_slice()
    }

    /// Returns the ini entries as a slice.
    #[must_use]
    #[inline]
    pub const fn ini_entries(&self) -> &[Ini] {
        self.ini_entries.as_slice()
    }

    /// Returns the registry entries a slice.
    #[must_use]
    #[inline]
    pub const fn registry_entries(&self) -> &[RegistryEntry] {
        self.registry_entries.as_slice()
    }

    /// Returns the delete entries as a slice.
    #[must_use]
    #[inline]
    pub const fn delete_entries(&self) -> &[DeleteEntry] {
        self.delete_entries.as_slice()
    }

    /// Returns the uninstall delete entries as a slice.
    #[must_use]
    #[inline]
    pub const fn uninstall_delete_entries(&self) -> &[DeleteEntry] {
        self.uninstall_delete_entries.as_slice()
    }

    /// Returns the run entries as a slice.
    #[must_use]
    #[inline]
    pub const fn run_entries(&self) -> &[RunEntry] {
        self.run_entries.as_slice()
    }

    /// Returns the uninstall run entries as a slice.
    #[must_use]
    #[inline]
    pub const fn uninstall_run_entries(&self) -> &[RunEntry] {
        self.uninstall_run_entries.as_slice()
    }

    /// Returns a reference to the [`Wizard`].
    #[must_use]
    #[inline]
    pub const fn wizard(&self) -> &Wizard {
        &self.wizard
    }

    /// Returns the file locations entries as a slice.
    #[must_use]
    #[inline]
    pub const fn file_locations(&self) -> &[FileLocation] {
        self.file_locations.as_slice()
    }
}