Skip to content

Repository files navigation

chmdec — a plain-C CHM reader

This is a CHM / ITSS archive reader, ported and cleaned from CHMLib.

  • plain C, no dependencies
  • wasm build to be used in web apps
  • simpler / cleaned API
  • easy to integrate: copy dist/chm.h and dist/chm.c to your project (amalgamated build like sqlite)
  • in-memory only (no incremental I/O)
  • fuzzed for robustness
  • battle tested in SumatraPDF

API

See src/chm.h. Basic usage:

chm_ctx *ctx = chm_open(NULL, data, len);   /* data must outlive ctx */
struct chm_entry **entries = NULL;
int n = chm_get_entries(ctx, &entries);
for (int i = 0; i < n; i++) {
    if (strcmp(entries[i]->path, "/foo/bar.html") == 0) {
        uint8_t *buf = malloc(entries[i]->length);
        if (buf) {
            chm_read_entry(ctx, entries[i], buf);
            free(buf);
        }
        break;
    }
}
chm_close(ctx);

Dev build & test

For dev, we require bun and use msvc and clang as C compilers.

bun cmd/build.ts          # builds out/clang/chm_test
bun cmd/get-deps.ts       # download public .chm samples → testfiles/chm
bun cmd/tests.ts          # smoke tests over testfiles/chm (auto get-deps)
bun cmd/build-dist.ts     # updates dist/chm.{h,c} (+ wasm when run as main)
bun cmd/build-wasm.ts     # dist/wasm/chm.js + chm.wasm + demo.html (bootstraps emsdk if needed)
bun cmd/verify-wasm.ts f.chm  # open/list through the wasm glue (CI)
bun cmd/run-wasm-demo.ts  # serve the browser demo
bun cmd/fuzz.ts           # libFuzzer (seeded from testfiles/chm)
bun cmd/fuzz.ts -check-crashes  # replay fuzz/crashes/* under ASan (CI)

CI (GitHub Actions): .github/workflows/ci.yml — Windows/Linux/macOS smoke + CHMLib oracle tests + amalgamation, fuzz crash regression, WASM open/list.

CLI:

chm_test -list file.chm

How it was made

Port of CHMLib (from SumatraPDF's ext/CHMLib) cleaned up coding conventions, with ctx/alloc, amalgamated build, fuzzing, wasm build.

License

See LICENSE.md (LGPL-ish origin from CHMLib, adapted).

About

plain-C CHM / ITSS archive reader library

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages