Giter Club home page Giter Club logo

resource_dasm's Introduction

resource_dasm

This project contains multiple tools for reverse-engineering classic Mac OS applications and games.

The tools in this project are:

  • General tools
    • resource_dasm: a utility for working with classic Mac OS resources. It can read resources from classic Mac OS resource forks, AppleSingle/AppleDouble files, MacBinary files, Mohawk archives, or HIRF/RMF/IREZ/HSB archives, and convert the resources to modern formats and/or export them verbatim. It can also create and modify resource forks.
    • libresource_file: a library implementing most of resource_dasm's functionality.
    • m68kdasm: a 68K, PowerPC, x86, and SH-4 binary disassembler. m68kdasm can also disassemble some common executable formats.
    • m68kexec: a 68K, PowerPC, and x86 CPU emulator and debugger.
    • render_bits: a raw data renderer, useful for figuring out embedded images or 2-D arrays in unknown file formats.
    • replace_clut: remaps an existing image from one indexed color space to another.
    • assemble_images: combines multiple images into one.
    • dupe_finder: a tool for finding duplicate resources across multiple resource files.
  • Decompressors/dearchivers for specific formats
    • hypercard_dasm: disassembles HyperCard stacks and draws card images.
    • decode_data: decodes some custom compression formats (see below).
    • render_sprite: renders sprites from a variety of custom formats (see below).
    • icon_unarchiver: exports icons from an Icon Archiver archive to .icns (see below).
  • Game map generators
    • blobbo_render: generates maps from Blobbo levels.
    • bugs_bannis_render: generates maps from Bugs Bannis levels.
    • ferazel_render: generates maps from Ferazel's Wand world files.
    • gamma_zee_render: generates maps of Gamma Zee mazes.
    • harry_render: generates maps from Harry the Handsome Executive world files.
    • infotron_render: generates maps from Infotron levels files.
    • lemmings_render: generates maps from Lemmings and Oh No! More Lemmings levels and graphics files.
    • mshines_render: generates maps from Monkey Shines world files.
    • realmz_dasm: generates maps from Realmz scenarios and disassembles the scenario scripts into readable assembly-like syntax.

Building

  • Install Netpbm (http://netpbm.sourceforge.net/). This is only needed for converting PICT resources that resource_dasm can't decode by itself - if you don't care about PICTs, you can skip this step. Also, this is a runtime dependency only; you can install it later if you find that you need it, and you won't have to rebuild resource_dasm.
  • Install zlib, if you somehow don't have it already. (macOS and most Linuxes come with it preinstalled, but some Linuxes like Raspbian may not. If your Linux doesn't have it, you can apt-get install zlibg1-dev.)
  • Install CMake.
  • Build and install phosg (https://github.com/fuzziqersoftware/phosg).
  • Run cmake ., then make.

This project should build properly on sufficiently recent versions of macOS and Linux.

Using resource_dasm

resource_dasm is a disassembler for classic Mac OS resource forks. It extracts resources from the resource fork of any file and converts many classic Mac OS resource formats (images, sounds, text, etc.) into modern formats.

Examples:

  • Export all resources from a specific file and convert them to modern formats (output is written to the <filename>.out directory by default): ./resource_dasm files/Tesserae

  • Export all resources from all files in a folder, writing the output files into a parallel folder structure in the current directory: ./resource_dasm "files/Apeiron ƒ/" ./apeiron.out

  • Export a specific resource from a specific file, in both modern and original formats: ./resource_dasm "files/MacSki 1.7/MacSki Sounds" ./macski.out --target-type=snd --target-id=1023 --save-raw=yes

  • Export a PowerPC application's resources and disassemble its code: ./resource_dasm "files/Adventures of Billy" ./billy.out ./m68kdasm --pef "files/Adventures of Billy" ./billy.out/dasm.txt

  • Export all resources from a Mohawk archive: ./resource_dasm files/Riven/Data/a_Data.MHK ./riven_data_a.out --index-format=mohawk

  • Due to copying files across different types of filesystems, you might have a file's resource fork in the data fork of a separate file instead. To export resources from such a file: ./resource_dasm "windows/Realmz/Data Files/Portraits.rsf" ./portraits.out --data-fork

  • Create a new resource file, with a few TEXT and clut resources: ./resource_dasm --create --add-resource=TEXT:[email protected] --add-resource=TEXT:[email protected] --add-resource=clut:[email protected] output.rsrc

  • Add a resource to an existing resource file: ./resource_dasm file.rsrc --add-resource=TEXT:[email protected] output.rsrc

  • Delete a resource from an existing resource file: ./resource_dasm file.rsrc --delete-resource=TEXT:128 output.rsrc

This isn't all resource_dasm can do. Run it without any arguments (or look at print_usage() in src/resource_dasm.cc) for a full description of all the options.

Capabilities

resource_dasm can convert these resource types:

Type   | Output format                                           | Notes
------------------------------------------------------------------------
Text resources
  bstr | .txt (one file per string)                              | *3
  card | .txt                                                    |
  finf | .txt (description of contents)                          |
  FCMT | .txt                                                    | *3
  FONT | .txt (description) and image (one image per glyph)      | *E
  lstr | .txt                                                    | *3
  MACS | .txt                                                    | *3
  minf | .txt                                                    | *3
  mstr | .txt                                                    | *3
  mst# | .txt (one file per string)                              | *3
  NFNT | .txt (description) and image (one image per glyph)      | *E
  PSAP | .txt                                                    |
  sfnt | .ttf (TrueType font)                                    |
  STR  | .txt                                                    | *3
  STR# | .txt (one file per string)                              | *3
  styl | .rtf                                                    | *4
  TEXT | .txt                                                    | *3
  TwCS | .txt (one file per string)                              |
  wstr | .txt                                                    |
------------------------------------------------------------------------
Image and color resources
  actb | image (24-bit)                                          | *E *8
  acur | .txt (list of cursor frame IDs)                         |
  cctb | image (24-bit)                                          | *E *8
  cicn | image (32-bit and monochrome)                           | *E
  clut | image (24-bit)                                          | *E *8
  crsr | image (32-bit and monochrome)                           | *E *1
  CTBL | image (24-bit)                                          | *E
  CURS | image (32-bit)                                          | *E *1
  dctb | image (24-bit)                                          | *E *8
  fctb | image (24-bit)                                          | *E *8
  icl4 | image (24 or 32-bit) and .icns                          | *E *0
  icl8 | image (24 or 32-bit) and .icns                          | *E *0
  icm# | image (32-bit)                                          | *E
  icm4 | image (24 or 32-bit)                                    | *E *0
  icm8 | image (24 or 32-bit)                                    | *E *0
  ICN# | image (32-bit) and .icns                                | *E
  icns | image, .png, .jp2, .txt, .plist, .bin, etc.             | *E *9
  ICON | image (24-bit)                                          | *E
  ics# | image (32-bit) and .icns                                | *E
  ics4 | image (24 or 32-bit) and .icns                          | *E *0
  ics8 | image (24 or 32-bit) and .icns                          | *E *0
  kcs# | image (32-bit)                                          | *E
  kcs4 | image (24 or 32-bit)                                    | *E *0
  kcs8 | image (24 or 32-bit)                                    | *E *0
  PAT  | image (24-bit; pattern and 8x8 tiling)                  | *E
  PAT# | image (24-bit; pattern and 8x8 tiling for each pattern) | *E
  PICT | image (24-bit) or other format                          | *E *2
  pltt | image (24-bit)                                          | *E *8
  ppat | image (24-bit; color, color 8x8, mono, mono 8x8)        | *E
  ppt# | image (24-bit; 4 images as above for each pattern)      | *E
  SICN | image (24-bit, one per icon)                            | *E
  wctb | image (24-bit)                                          | *E *8
------------------------------------------------------------------------
Sound and sequence resources
  .mod | .mod (ProTracker module)                                |
  ALIS | .txt (description of contents)                          |
  cmid | .midi                                                   |
  csnd | .wav or .mp3                                            | *5
  ecmi | .midi                                                   |
  emid | .midi                                                   |
  esnd | .wav or .mp3                                            | *5
  ESnd | .wav or .mp3                                            | *5
  INST | .json                                                   | *6
  MADH | .madh (PlayerPRO module)                                |
  MADI | .madi (PlayerPRO module)                                |
  MIDI | .midi                                                   |
  Midi | .midi                                                   |
  midi | .midi                                                   |
  SMSD | .wav                                                    | *A
  snd  | .wav or .mp3                                            | *5
  SONG | .json (smssynth)                                        | *6
  SOUN | .wav                                                    | *A
  Tune | .midi                                                   | *7
  Ysnd | .wav                                                    |
------------------------------------------------------------------------
Code resources
  ADBS | .txt (68K assembly)                                     | *C
  adio | .txt (68K assembly)                                     | *C
  AINI | .txt (68K assembly)                                     | *C
  atlk | .txt (68K assembly)                                     | *C
  boot | .txt (68K assembly)                                     | *C
  CDEF | .txt (68K assembly)                                     | *C
  cdek | .txt (PPC32 assembly and header description)            |
  cdev | .txt (68K assembly)                                     | *C
  CDRV | .txt (68K assembly)                                     | *C
  cfrg | .txt (description of code fragments)                    | *D
  citt | .txt (68K assembly)                                     | *C
  clok | .txt (68K assembly)                                     | *C
  cmtb | .txt (68K assembly)                                     | *C
  cmu! | .txt (68K assembly)                                     | *C
  CODE | .txt (68K assembly or import table description)         | *B *C
  code | .txt (68K assembly)                                     | *C
  dcmp | .txt (68K assembly)                                     | *C
  dcod | .txt (PPC32 assembly and header description)            |
  dem  | .txt (68K assembly)                                     | *C
  dimg | .txt (68K assembly)                                     | *C
  drvr | .txt (68K assembly)                                     | *C
  DRVR | .txt (68K assembly)                                     | *C
  enet | .txt (68K assembly)                                     | *C
  epch | .txt (PPC32 assembly)                                   |
  expt | .txt (PPC32 assembly)                                   |
  FKEY | .txt (68K assembly)                                     | *C
  fovr | .txt (PPC32 assembly and header description)            |
  gcko | .txt (68K assembly)                                     | *C
  gdef | .txt (68K assembly)                                     | *C
  GDEF | .txt (68K assembly)                                     | *C
  gnld | .txt (68K assembly)                                     | *C
  INIT | .txt (68K assembly)                                     | *C
  krnl | .txt (PPC32 assembly)                                   |
  LDEF | .txt (68K assembly)                                     | *C
  lmgr | .txt (68K assembly)                                     | *C
  lodr | .txt (68K assembly)                                     | *C
  ltlk | .txt (68K assembly)                                     | *C
  MBDF | .txt (68K assembly)                                     | *C
  MDEF | .txt (68K assembly)                                     | *C
  mntr | .txt (68K assembly)                                     | *C
  ncmp | .txt (PPC32 assembly and header description)            |
  ndlc | .txt (PPC32 assembly and header description)            |
  ndmc | .txt (PPC32 assembly and header description)            |
  ndrv | .txt (PPC32 assembly and header description)            |
  nift | .txt (PPC32 assembly and header description)            |
  nitt | .txt (PPC32 assembly and header description)            |
  nlib | .txt (PPC32 assembly and header description)            |
  nsnd | .txt (PPC32 assembly and header description)            |
  nsrd | .txt (PPC32 assembly)                                   |
  ntrb | .txt (PPC32 assembly and header description)            |
  osl  | .txt (68K assembly)                                     | *C
  otdr | .txt (68K assembly)                                     | *C
  otlm | .txt (68K assembly)                                     | *C
  PACK | .txt (68K assembly)                                     | *C
  pnll | .txt (68K assembly)                                     | *C
  ppct | .txt (PPC32 assembly and header description)            |
  proc | .txt (68K assembly)                                     | *C
  PTCH | .txt (68K assembly)                                     | *C
  ptch | .txt (68K assembly)                                     | *C
  pthg | .txt (68K or PPC32 assembly and header description)     | *C
  qtcm | .txt (PPC32 assembly and header description)            |
  ROvr | .txt (68K assembly)                                     | *C
  RSSC | .txt (68K assembly)                                     | *C
  scal | .txt (PPC32 assembly and header description)            |
  scod | .txt (68K assembly)                                     | *C
  SERD | .txt (68K assembly)                                     | *C
  sfvr | .txt (PPC32 assembly and header description)            |
  shal | .txt (68K assembly)                                     | *C
  sift | .txt (68K assembly)                                     | *C
  SMOD | .txt (68K assembly)                                     | *C
  snth | .txt (68K assembly)                                     | *C
  tdig | .txt (68K assembly)                                     | *C
  tokn | .txt (68K assembly)                                     | *C
  vdig | .txt (68K or PPC32 assembly and header description)     | *C
  wart | .txt (68K assembly)                                     | *C
  WDEF | .txt (68K assembly)                                     | *C
  XCMD | .txt (68K assembly)                                     | *C
  XFCN | .txt (68K assembly)                                     | *C
------------------------------------------------------------------------
MacApp resources
  68k! | .txt (description of memory config for 680x0)           |
  CMNU | .txt (description of menu)                              |
  cmnu | .txt (description of menu)                              |
  errs | .txt (description of error ranges)                      |
  mem! | .txt (description of memory config)                     |
  ppc! | .txt (description of memory config for PPC)             |
  res! | .txt (string list of always resident segments)          |
  seg! | .txt (string list of segments)                          |
  TxSt | .txt (description of text style)                        |
------------------------------------------------------------------------
Miscellaneous resources
  ALRT | .txt (alert parameters)                                 |
  APPL | .txt (description of contents)                          |
  audt | .txt (description of contents)                          |
  BNDL | .txt (description of contents)                          |
  CMDK | .txt (list of keys)                                     |
  CNTL | .txt (description of control)                           |
  CTY# | .txt (description of cities)                            |
  dbex | .txt (description of contents)                          |
  DITL | .txt (dialog parameters)                                |
  DLOG | .txt (dialog parameters)                                |
  FBTN | .txt (description of buttons)                           |
  FDIR | .txt (description of contents)                          |
  fld# | .txt (description of folders)                           |
  flst | .txt (description of font family list)                  |
  fmap | .txt (description of finder icon mappings)              |
  FREF | .txt (description of file references)                   |
  FRSV | .txt (list of font IDs)                                 |
  FWID | .txt (font parameters)                                  |
  gbly | .txt (description of Gibbly aka. System Enabler)        |
  GNRL | .txt (description of contents)                          |
  hwin | .txt (description of help window)                       |
  icmt | .txt (icon reference and comment)                       |
  inbb | .txt (description of contents)                          |
  indm | .txt (description of contents)                          |
  infs | .txt (description of contents)                          |
  inpk | .txt (description of contents)                          |
  inra | .txt (description of contents)                          |
  insc | .txt (description of contents)                          |
  itl0 | .txt (international formatting information)             |
  ITL1 | .txt (short dates flag value)                           |
  itlb | .txt (internationalization parameters)                  |
  itlc | .txt (internationalization parameters)                  |
  itlk | .txt (keyboard mappings)                                |
  KBDN | .txt (keyboard name)                                    |
  LAYO | .txt (description of layout)                            |
  mach | .txt (description of contents)                          |
  MBAR | .txt (list of menu IDs)                                 |
  mcky | .txt (threshold values)                                 |
  MENU | .txt (description of menu)                              |
  mitq | .txt (description of queue sizes)                       |
  nrct | .txt (rectangle boundaries)                             |
  PAPA | .txt (printer parameters)                               |
  PICK | .txt (picker parameters)                                |
  ppcc | .txt (description of contents)                          |
  ppci | .txt (description of contents)                          |
  PRC0 | .txt (description of contents)                          |
  PRC3 | .txt (description of contents)                          |
  pslt | .txt (description of Nubus pseudo-slot lists)           |
  ptbl | .txt (description of patch table)                       |
  qrsc | .txt (description of queries)                           |
  RECT | .txt (description of the rectangle)                     |
  resf | .txt (list of fonts)                                    |
  RMAP | .txt (type mapping and list of ID exceptions)           |
  ROv# | .txt (list of overridden resource IDs)                  |
  rtt# | .txt (list of database result handlers)                 |
  RVEW | .txt (description of contents)                          |
  scrn | .txt (screen device parameters)                         |
  sect | .txt (description of contents)                          |
  SIGN | .txt (description of contents)                          |
  SIZE | .txt (description of parameters)                        |
  slut | .txt (description of mapping)                           |
  thn# | .txt (description of 'thng' mapping)                    |
  TMPL | .txt (description of format)                            |
  TOOL | .txt (description of contents)                          |
  vers | .txt (version flags and strings)                        |
  WIND | .txt (window parameters)                                |

Notes:
*0: Produces a 32-bit image if a corresponding monochrome resource exists
    (ICN# for icl4/8, icm# for icm4/8, ics# for ics4/8, kcs# for kcs4/8). If
    no monochrome resource exists, produces a 24-bit image instead. All
    color information in the original resource is reproduced in the output,
    even for fully-transparent pixels. If the icon was originally intended
    to be used with a nonstandard compositing mode, the colors of fully-
    transparent pixels may have been relevant, but most modern image viewers
    and editors don't have a way to display this information.
*1: The hotspot coordinates are appended to the output filename. As in *0,
    resource_dasm faithfully reproduces the color values of transparent
    pixels in the output file, but most modern image editors won't show
    these "transparent" pixels.
*2: resource_dasm implements multiple PICT decoders. It will first attempt
    to decode the PICT using its internal decoder, which usually produces
    correct results but fails on PICTs that contain complex drawing opcodes.
    This decoder can handle basic QuickTime images as well (e.g. embedded
    JPEGs and PNGs), but can't do any drawing under or over them, or
    matte/mask effects. PICTs that contain embedded JPEGs or PNGs will
    result in a JPEG or PNG file rather than the format specified by
    --image-format (which is BMP by default). If the internal decoder fails,
    resource_dasm will fall back to a decoder that uses picttoppm, which is
    part of NetPBM. There is a rare failure mode in which picttoppm hangs
    forever; resource_dasm gives it 10 seconds to do its job before killing
    it and giving up. If picttoppm is not installed, fails to decode the
    PICT, or is killed due to a timeout, resource_dasm will prepend the
    necessary header and save the data as a PICT file instead.
*3: Text is assumed to use the Mac OS Roman encoding. It is converted to
    UTF-8, and line endings (\r) are converted to Unix style (\n).
*4: Some rare style options may not be translated correctly. styl resources
    provide styling information for the TEXT resource with the same ID, so
    such a resource must be present to properly decode a styl.
*5: RMF archives can contain snd resources that are actually in MP3 format;
    in this case, the exported sound will be a .mp3 file. Otherwise, the
    exported sound is an uncompressed WAV file, even if the resource's data
    is compressed. resource_dasm can decompress IMA 4:1, MACE 3:1, MACE 6:1,
    A-law, and mu-law (ulaw) compression.
*6: JSON files from SoundMusicSys SONG resources can be played with smssynth
    (http://www.github.com/fuzziqersoftware/gctools). The JSON file refers
    to the instrument sounds and MIDI sequence by filename and does not
    include directory names, so if you want to play these, you'll have to
    manually put the sounds and MIDI files in the same directory as the JSON
    file if you're using --filename-format.
*7: Tune decoding is experimental and will likely produce unplayable MIDIs.
*8: For color table resources, the raw data is always saved even if it is
    decoded properly, since the original data contains 16-bit values for
    each channel and the output image file has less-precise 8-bit channels.
*9: icns resources are decoded into many different file types depending on
    the contents of the resource. For subfields that have split alpha
    channels (that is, the transparency data is in a different subfield),
    resource_dasm produces an original image and one with transparency
    applied. Some icns resources also contain metadata, which is exported as
    .bin, .txt, and .plist files, except for the Icon Composer version used
    to create the file, which is ignored. If you want the result in Icon
    Composer format, use --save-raw=yes and resource_dasm will save it as a
    .icns file.
*A: These resources appear to have a fixed format, with a constant sample
    rate, sample width and channel count. You may have to adjust these
    parameters in the output if it turns out that these are configurable.
*B: The disassembler attempts to find exported functions by parsing the jump
    table in the CODE 0 resource, but if this resource is missing or not in
    the expected format, it skips this step and does not fail. Generally, if
    any "export_X:" labels appear in the disassembly, then export resolution
    succeeded and all of the labels should be correct (otherwise they will
    all be missing).
*C: Some coprocessor and floating-point opcodes (F-class) are not
    implemented and will disassemble with the comment "// unimplemented".
*D: Most PowerPC applications have their executable code in the data fork.
    To disassemble it, use m68kdasm (example above).
*E: The output image format can be specified using --image-format. The
    default output format is bmp (Windows bitmap); other supported formats
    are png and ppm.

If resource_dasm fails to convert a resource, or doesn't know how to, it will attempt to decode the resource using the corresponding TMPL (template) resource if it exists. If there's no appropriate TMPL, the TMPL is corrupt, or the TMPL can't decode the resource, resource_dasm will produce the resource's raw data instead.

Most of the decoder implementations in resource_dasm are based on reverse-engineering existing software and pawing through the dregs of old documentation, so some rarer types of resources probably won't work yet. However, I want this project to be as complete as possible, so if you have a resource that you think should be decodable but resource_dasm can't decode it, send it to me (perhaps by attaching to a GitHub issue) and I'll try my best to make resource_dasm understand it.

Compressed resources

resource_dasm transparently decompresses resources that are marked by the resource manager as compressed.

The resource manager compression scheme was never officially documented by Apple or made public, so the implementation of these decompressors is based on reverse-engineering ResEdit and other classic Mac OS code. In summary, resources are decompressed by executing 68K or PowerPC code from a dcmp or ncmp resource, which is looked up at runtime in the chain of open resource files like most other resources are. (In practice, the relevant dcmp/ncmp is usually contained in either the same file as the compressed resource or in the System file.) There are two different formats of compressed resources and two corresponding formats of 68K decompressors; resource_dasm implements support for both formats.

resource_dasm contains native implementations of all four decompressors built into the Mac OS System file. Specifically:

  • dcmp 0 (DonnDecompress) works
  • dcmp 1 (a variant of DonnDecompress) is not tested
  • dcmp 2 (GreggyDecompress) is not tested
  • dcmp 3 (an LZSS-like scheme) works

resource_dasm has built-in 68K and PowerPC emulators to run non-default decompressors. These emulators can also run the default decompressors, which are included with resource_dasm. Current status of emulated decompressors:

  • System dcmp 0 works
  • System dcmp 1 is not tested
  • System dcmp 2 is not tested
  • System dcmp 3 works
  • Ben Mickaelian's self-modifying dcmp 128 from After Dark works
  • FutureBASIC (probably) dcmp 200 works

There may be other decompressors out there that I haven't seen, which may not work. If you see "warning: failed to decompress resource" when using resource_dasm, please create a GitHub issue and upload the exported compressed resource (.bin file) that caused the failure, and all the dcmp and ncmp resources from the same source file.

Using resource_dasm as a library

Run sudo make install to copy the header files and library to the relevant paths after building. After installation, you can #include <resource_file/IndexFormats/ResourceFork.hh> (for example) and link with -lresource_file. There is no documentation for this library beyond what's written in the header files.

The library contains the following useful functions and classes:

  • AudioCodecs.hh: MACE3/6, IMA4, mu-law and A-law audio decoders
  • DataCodecs/Codecs.hh: Decompressors and compressors for some common and custom data formats
  • Emulators/M68KEmulator.hh: 68000 CPU emulator and disassembler
  • Emulators/PPC32Emulator.hh: PowerPC CPU emulator, assembler, and disassembler
  • Emulators/X86Emulator.hh: x86 CPU emulator and disassembler
  • ExecutableFormats/...: Parsers for various executable formats
  • IndexFormats/Formats.hh: Parsers and serializers for various resource archive formats
  • Lookups.hh: Indexes of some constant values used in multiple resource types
  • LowMemoryGlobals.hh: Structure definition and field lookup for Classic Mac OS low-memory global variables
  • ResourceDecompressors/System.hh: Decompressors for standard resource compression formats
  • ResourceFile.hh: Loaded representation of a resource archive, with decoding functions for many types
  • ResourceTypes.hh: Constants representing many common resource types
  • TextCodecs.hh: Mac OS Roman decoder
  • TrapInfo.hh: Index of Classic Mac OS 68K system calls

Using m68kdasm

Using m68kdasm is fairly straightforward. Run m68kdasm --help for a full list of options.

Currently m68kdasm can disassemble these types of data:

  • Raw 68K, PowerPC, x86, or SH-4 code
  • PEF (Classic Mac OS PowerPC executable) files
  • DOL (Nintendo Gamecube executable) files
  • REL (Nintendo Gamecube library) files
  • PE (Windows EXE/DLL/etc.) files
  • XBE (Microsoft Xbox executable) files
  • ELF files

m68kdasm can also assemble PowerPC, x86, and SH-4 assembly into binary.

Some of these formats support CPU architectures that m68kdasm does not support; if it encounters one of these, it prints the code segments as data segments instead.

Using m68kexec

m68kexec is a CPU emulator and debugger for the Motorola 68000, 32-bit PowerPC, and x86 architectures. I often use it to help understand what some archaic code is trying to do, or to compare the behavior of code that I've transcribed to a modern language with the original code's behavior. For use cases like this, you generally will want to set up one or more input regions containing the data you're testing with, and one or more output regions for the emulated code to write to.

Perhaps this is best explained by example. This command is used to execute the encryption context generation function from Phantasy Star Online Blue Burst, to compare it with the same function as implemented in newserv:

./m68kexec --x86 --trace \
    --mem=A0000000/2AC43585C46A6366188889BCE3DB88B15C2B3C751DB6757147E7E9390598275CC79547B2E5C00DD145002816B59C067C \
    --mem=A1000000:1048 \
    --load-pe=files/windows/pso/psobb.exe \
    --pc=00763FD0 \
    --reg=ecx:A1000000 \
    --push=00000030 \
    --push=A0000000 \
    --push=FFFFFFFF \
    --breakpoint=FFFFFFFF

The --mem options set up the input regions; the A0000000 region contains the encryption seed (0x30 bytes) and the A1000000 region will contain the generated encryption context when the function returns. The --load-pe option loads the code to be executed and --pc tells the emulator where to start. (By default, it will start at the entrypoint defined in the executable, if any is given; here, we want to call a specific function instead.) The --reg option sets the this pointer in the function to the space we allocated for it. The --push options set the function's arguments and return address. It will return to FFFFFFFF, which has no allocated memory, but we've also set a --breakpoint at that address which will stop emulation just before an exception is thrown.

Since we used --trace, the emulator prints the registers' state after every opcode, so we can trace through its behavior and compare it with our external implementation of the same function. When the function returns and triggers the breakpoint, we can use r A1000000 1048 in the shell to see the data that it generated, and also compare that to our external function's result.

Using the other tools

render_bits

render_bits is useful to answer the question "might this random-looking binary data actually be an image or 2-D array?" Give it a color format and some binary data, and it will produce a full-color BMP file that you can look at with your favorite image viewer or editor. You can also give a color table (.bin file produced by resource_dasm from a clut resource) if you think the input is indexed color data. If the output looks like garbage, play around with the width and color format until you figure out the right parameters.

Run render_bits without any options for usage information.

replace_clut

Sometimes in the course of reverse-engineering you'll end up with an image that has the right content and structure, but the colors are completely wrong. Chances are it was rendered with the wrong color table; to fix this, you can use replace_clut to map all of the image's pixels from one colorspace to another.

Run replace_clut without any options for usage information.

assemble_images

Some games store large images split up into a set of smaller textures; assemble_images can programmatically combine them into a a single large image again. Run assemble_images without any options to see how to use it.

dupe_finder

dupe_finder finds duplicate resources of the same type in one or several resource files.

Run dupe_finder without any options for usage information.

Decompressors/dearchivers for specific formats

  • For HyperCard stacks: hypercard_dasm stack_file [output_dir], or just hypercard_dasm to see all options
  • For Alessandro Levi Montalcini's Icon Archiver: icon_dearchiver archive_file [output_dir] unpacks the icons to .icns files.
  • For VRFS files: vrfs_dump VRFS_file [output_dir]

decode_data

decode_data can decode and decompress a few custom encoding formats used by various games. Specifically:

Game/App/Library       | Encoding | CLI option        | Notes
-------------------------------------------------------------
DinoPark Tycoon        | LZSS     | --dinopark        | %0
DinoPark Tycoon        | RLE      | --dinopark        |
Flashback              | LZSS     | --presage         | %0
MacSki                 | COOK     | --macski          |
MacSki                 | CO2K     | --macski          |
MacSki                 | RUN4     | --macski          |
PackBits (compress)    | PackBits | --pack-bits       |
PackBits (decompress)  | PackBits | --unpack-bits     |
Pathways Into Darkness | Pathways | --unpack-pathways |
SoundMusicSys          | LZSS     | --sms             | %0

Notes:
%0: Although these are all variants of LZSS (and are indeed very similar to
    each other), they are mutually incompatible formats.

decode_data can be used on its own to decompress data, or can be used as an external preprocessor via resource_dasm to transparently decompress some formats. For example, to use decode_data for MacSki resources, you can run a command like resource_dasm --external-preprocessor="./decode_data --macski" input_filename ...

render_sprite

render_sprite can render several custom game sprite formats. For some formats listed below, you'll have to provide a color table resource in addition to the sprite resource. A .bin file produced by resource_dasm from a clut, pltt, or CTBL resource will suffice; usually these can be found in the same file as the sprite resources or in the game application. Run render_sprite with no arguments for usage information.

Supported formats:

Game                         | Type | CLI option | Need color table | Notes
---------------------------------------------------------------------------
Beyond Dark Castle           | PBLK | --PBLK     | No               |
Beyond Dark Castle           | PPCT | --PPCT     | No               |
Beyond Dark Castle           | PSCR | --PSCR-v2  | No               |
Blobbo                       | BTMP | --BTMP     | No               |
Blobbo                       | PMP8 | --PMP8     | Yes              | $9
BodyScope                    | Imag | --Imag     | Yes              | $2 $3
Bonkheads                    | Sprt | --Sprt     | Yes              |
Bubble Trouble               | btSP | --btSP     | Yes              |
Dark Castle (color)          | DC2  | --DC2      | No               | $4
Dark Castle (monochrome)     | PPCT | --PPCT     | No               |
Dark Castle (monochrome)     | PSCR | --PSCR-v1  | No               |
DinoPark Tycoon              | BMap | --BMap     | No               |
DinoPark Tycoon              | XBig | --XBig     | No               | $2
DinoPark Tycoon              | XMap | --XMap     | Yes              | $2 $7
Dr. Quandary                 | Imag | --Imag     | Sometimes        | $1 $2 $3
Factory                      | 1img | --1img     | No               |
Factory                      | 4img | --4img     | Yes              |
Factory                      | 8img | --8img     | Yes              |
Flashback                    | PPSS | --PPSS     | Yes              | $2 $8
Fraction Munchers            | Imag | --Imag-fm  | Sometimes        | $1 $2 $3
Greebles                     | GSIF | --GSIF     | Yes              |
Harry the Handsome Executive | HrSp | --HrSp     | Yes              | $9
Lemmings                     | SHPD | --SHPD-v1  | Sometimes        | $0 $1 $2 $5
Marathon                     | .256 | --.256-m   | No               | $2
Mario Teaches Typing         | Pak  | --Pak      | Sometimes        | $1 $2
Mars Rising                  | btSP | --btSP     | Yes              |
Number Munchers              | Imag | --Imag-fm  | Sometimes        | $1 $2 $3
Odell Down Under             | Imag | --Imag     | Sometimes        | $1 $2 $3
Oh No! More Lemmings         | SHPD | --SHPD-v2  | Sometimes        | $0 $1 $2 $5
Pathways Into Darkness       | .256 | --.256-pd  | No               | $2
Prince of Persia             | SHPD | --SHPD-p   | Sometimes        | $0 $1 $2 $5
Prince of Persia 2           | SHAP | --SHAP     | Yes              |
SimCity 2000                 | SPRT | --SPRT     | Yes              | $2
SimTower                     |      |            | No               | $A
Slithereens                  | SprD | --SprD     | Yes              | $2
SnapDragon                   | Imag | --Imag     | Sometimes        | $1 $2 $3
Spectre                      | shap | --shap     | No               | $6
Step On It!                  | sssf | --sssf     | Yes              | $2
Super Munchers               | Imag | --Imag-fm  | Sometimes        | $1 $2 $3
Swamp Gas                    | PPic | --PPic     | Sometimes        | $0 $2 $3
The Amazon Trail             | Imag | --Imag     | Sometimes        | $2 $3
The Oregon Trail             | Imag | --Imag     | Sometimes        | $1 $2 $3
TheZone                      | Spri | --Spri     | Yes              |
Word Munchers                | Imag | --Imag-fm  | Sometimes        | $1 $2 $3

Notes:
$0: render_sprite can't tell from the contents of the resource whether it is
    color or monochrome, so it assumes the resource is color if you give a
    color table on the command line. If decoding fails with a color table,
    try decoding without one (or vice versa).
$1: These games contain some color and some monochrome graphics. It should
    be obvious which are which (usually color graphics are in a separate
    file), but if not, you can give a clut anyway in these cases and
    render_sprite will ignore it if the image is monochrome.
$2: These sprite formats contain multiple images, so render_sprite will
    produce multiple image files.
$3: Resources of this type can contain embedded color tables; if you're
    rendering a color image that doesn't have a color table, you'll have to
    provide one via a command-line option. If the resource (or individual
    images therein) contain their own color tables or are monochrome, no
    color table is required on the command line, and any provided color
    table via the command line will be ignored.
$4: You can get DC2 sprites from the DC Data file with
    `resource_dasm --index-format=dc-data "DC Data"`.
$5: The graphics files contain resources that refer to segments of the data
    fork in the same file. So, this option expects the original Graphics or
    BW Graphics or Persia file (with both data and resource forks present),
    not an already-extracted resource.
$6: shap resources contain 3D models and 2D top-down projections of them.
    When given a shap resource, render_sprite produces an STL file and an
    OBJ file for the 3D model, and an SVG file for the 2D top-down view.
$7: Some XMap resources are stored inside CBag archives. You can extract
    them with `resource_dasm --index-format=cbag <CBAG_file.bin>`.
$8: This game has only one clut and it's huge - far longer than the usual
    256 entries. It seems PPSS image sets are meant to be rendered with a
    subset of this clut, but I haven't been able to figure out (yet) how the
    game chooses what subset of it to use.
$9: The game doesn't contain any color tables. You can use a 256-color clut
    resource from the Mac OS System file, or use the --default-clut option.
$A: The game stores its sprites in normal PICT resources with an incorrect
    type. Use `resource_dasm --copy-handler=PICT:%89%E6%91%9C` to decode
    them instead of using render_sprite.

icon_dearchiver

icon_dearchiver unpacks the icons in an Icon Archiver (by Alessandro Levi Montalcini) archive to .icns. Run it with no options for usage information.

Game map generators

  • For Blobbo maps: use resource_dasm to get the PMP8 and Blev resources from Blobbo, then use render_sprite to convert PMP8 128 into a .bmp file, then run blobbo_render <Blev-file.bin> <PMP8-128.bmp>
  • For Ferazel's Wand maps: ferazel_render in the directory with the data files, or ferazel_render --help to see all the options (there are many!)
  • For Gamma Zee maps: gamma_zee_render gamma_zee_application levels_filename
  • For Harry the Handsome Executive maps: harry_render --clut-file=clut.bin, or just harry_render to see all the options (there are many!)
  • For Infotron maps: infotron_render in the Info Datafiles directory
  • For Lemmings (Mac version) maps: lemmings_render --clut-file=clut.bin, or lemmings_render --help to see all the options
  • For Monkey Shines maps: mshines_render world_file [output_directory]
  • For Oh No! More Lemmings (Mac version) maps: Use lemmings_render as for original Lemmings, but also use the --v2 option
  • For Realmz maps and scripts: realmz_dasm global_data_dir [scenario_dir] out_dir (if scenario_dir is not given, disassembles the shared data instead)

resource_dasm's People

Contributors

fuzziqersoftware avatar kristine1975 avatar ownezx avatar sembiance avatar syto203 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

resource_dasm's Issues

Suggestion: Conditional compilation for some features

My July 2022 build of resource_dasm was 13 MB, and the one I did just now is 12.5 MB (Intel)

I thought maybe separating the disassembly stuff would make the build smaller, but it didn't seem to help?

It's a low priority issue. But I plan to bundle resource_dasm, picttoppm, and a 3rd program I am developing (a converter) which will convert 90's (Al Staffieri) GameMaker games to a new modern runtime (a 4th program that's long been written). All the program sizes add up I guess, and my first computer was an LC II with 4 MB of RAM and an 80 MB hard drive and I never quite shed that mentality ;)

I remember ~2 years ago hacking a build of resource_dasm that was much smaller after cutting out everything except for the PICT and 'snd ' converters.

I could probably take a stab at it, basically would just be a bunch of #ifdef statements?

Build error ih hypercard_dasm.cc

Got the following build error with g++ (Gentoo 10.2.0-r5 p6) 10.2.0 for file hypercard_dasm.cc:

hypercard_dasm.cc: In function ‘std::string autoformat_hypertalk(const string&)’:
hypercard_dasm.cc:66:94: error: no matching function for call to ‘transform(std::__cxx11::basic_string<char>::iterator, std::__cxx11::basic_string<char>::iterator, std::__cxx11::basic_string<char>::iterator, <unresolved overloaded function type>)’
   66 |       transform(lowercase_line.begin(), lowercase_line.end(), lowercase_line.begin(), tolower);
      |                                                                                              ^
In file included from /usr/lib/gcc/x86_64-pc-linux-gnu/10.2.0/include/g++-v10/functional:65,
                 from /usr/include/phosg/Filesystem.hh:15,
                 from hypercard_dasm.cc:9:
/usr/lib/gcc/x86_64-pc-linux-gnu/10.2.0/include/g++-v10/bits/stl_algo.h:4302:5: note: candidate: ‘template<class _IIter, class _OIter, class _UnaryOperation> _OIter std::transform(_IIter, _IIter, _OIter, _UnaryOperation)’
 4302 |     transform(_InputIterator __first, _InputIterator __last,
      |     ^~~~~~~~~

Replacing Line #66 in hypercard_dasm.cc from:

transform(lowercase_line.begin(), lowercase_line.end(), lowercase_line.begin(), tolower);

to
transform(lowercase_line.begin(), lowercase_line.end(), lowercase_line.begin(), ::tolower);

Fixed it.

warning: PICT rendering failed (mask region rect Rect(x1=-27892, y1=26790, x2=0, y2=256) is not same as source rect

Always make a new build before submitting issues 🤣

I got a new one for you 😊

Most of the PICT resources in Dude 2000 v2.71 fail to decode. (Disclaimer: I wrote this game when I was like, 11)

... dudenew/Dude 2000 v2.71_PICT_1118.pict
warning: PICT rendering failed (mask region rect Rect(x1=-27892, y1=26790, x2=0, y2=256) is not same as source rect Rect(x1=152, y1=163, x2=398, y2=388)); attempting rendering using picttoppm
picttoppm: Invalid PICT: compressed line of 63232 bytes for Row 0 is too big to represent a 256-byte padded row, even with worse case compression.
warning: failed to decode resource: picttoppm failed (256)

PICT 1118 totally fails both resource_dasm and picttoppm. I will raise this issue separately with the NetPBM guy. The picttoppm error here doesn't make sense to me, since the entire PICT is only 6826 bytes.

... dudenew/Dude 2000 v2.71_PICT_1119.pict
warning: PICT rendering failed (mask region rect Rect(x1=-27892, y1=26790, x2=0, y2=256) is not same as source rect Rect(x1=152, y1=163, x2=398, y2=388)); attempting rendering using picttoppm

PICT 1119 fails in resource_dasm, and picttoppm does not have an error but I still don't get the BMP output for some reason?

Actually, now I'm confused, because for 1120 I did get a BMP file, but the program output looks identical to 1118, which failed totally and gave me the raw PICT output?

... dudenew/Dude 2000 v2.71_PICT_1120.bmp
warning: PICT rendering failed (mask region rect Rect(x1=-27892, y1=26790, x2=0, y2=256) is not same as source rect Rect(x1=27, y1=163, x2=523, y2=388)); attempting rendering using picttoppm
picttoppm: Invalid PICT: compressed line of 1153 bytes for Row 0 is too big to represent a 496-byte padded row, even with worse case compression.
warning: failed to decode resource: picttoppm failed (256)

I ran resource_dasm again with skip-decode and the 3 PICTs (1118, 1119, 1120) are in the attached ZIP. The entire game is available here, use The Unarchiver to decompress: https://mikerichardson.name/graveyard/dude2000_271.sit

3 picts.zip

Even weirder: 1118 and 1119 render fine in Catalina (Preview, QuickLook, etc). 1120 does not (just shows white). The BMP output I got from (whatever managed to decode it) is correct (just shows blue).

image

My build of resource_dasm is from master on July 11, 2022. If any PICT stuff changed since then let me know and I'll try with the latest sources. (It's not super easy to build for me, for some reason.)

size_t compile error with GCC 11.1

Attempting to compile with GCC 11.1 produces the error:

In file included from AudioCodecs.cc:1:
AudioCodecs.hh:5:55: error: ‘size_t’ has not been declared
    5 | std::vector<int16_t> decode_mace(const uint8_t* data, size_t size, bool stereo,
      |                                                       ^~~~~~
AudioCodecs.hh:7:55: error: ‘size_t’ has not been declared
    7 | std::vector<int16_t> decode_ima4(const uint8_t* data, size_t size, bool stereo);
      |                                                       ^~~~~~
AudioCodecs.hh:8:55: error: ‘size_t’ has not been declared
    8 | std::vector<int16_t> decode_alaw(const uint8_t* data, size_t size);
      |                                                       ^~~~~~
AudioCodecs.hh:9:55: error: ‘size_t’ has not been declared
    9 | std::vector<int16_t> decode_ulaw(const uint8_t* data, size_t size);
      |                                                       ^~~~~~
make: *** [<builtin>: AudioCodecs.o] Error 1

Adding this to the top of AudioCodecs.hh fixes it:
#include <stddef.h>

Format of Spectre Supreme "shap" resources

* Spectre Supreme: shap (these might be 3D models)

These are indeed 3D models. In Spectre VR, the "... Matrix" files contain a TMPL resource that describe the format. In Spectre Supreme, this TMPL is missing, but the shap format is almost identical; just the last field has been removed (some of the shap exist in both VR and Supreme, making it easy to compare).

Here's a HQX-encoded resource file with the Supreme TMPL: shap_SpectreSupreme.rsrc.hqx (txt extension because Github).

compile error with g++ 11.2.1_p20220115

I got the following compile error with latest git code from Mar 28 using g++ 11.2.1_p20220115:

[2/57] /usr/bin/x86_64-pc-linux-gnu-g++ -Dresource_file_EXPORTS -I/usr/local/include  -DNDEBUG -O2 -march=native -pipe -fPIC -Wall -Wextra -Werror -Wno-strict-aliasing -std=gnu++20 -MD -MT CMakeFiles/resource_file.dir/src/Decompressors/System2.cc.o -MF CMakeFiles/resource_file.dir/src/Decompressors/System2.cc.o.d -o CMakeFiles/resource_file.dir/src/Decompressors/System2.cc.o -c /var/tmp/portage/app-arch/resource-dasm-0_p20220329/work/resource_dasm-master/src/Decompressors/System2.cc
FAILED: CMakeFiles/resource_file.dir/src/Decompressors/System2.cc.o 
/usr/bin/x86_64-pc-linux-gnu-g++ -Dresource_file_EXPORTS -I/usr/local/include  -DNDEBUG -O2 -march=native -pipe -fPIC -Wall -Wextra -Werror -Wno-strict-aliasing -std=gnu++20 -MD -MT CMakeFiles/resource_file.dir/src/Decompressors/System2.cc.o -MF CMakeFiles/resource_file.dir/src/Decompressors/System2.cc.o.d -o CMakeFiles/resource_file.dir/src/Decompressors/System2.cc.o -c /var/tmp/portage/app-arch/resource-dasm-0_p20220329/work/resource_dasm-master/src/Decompressors/System2.cc
/var/tmp/portage/app-arch/resource-dasm-0_p20220329/work/resource_dasm-master/src/Decompressors/System2.cc: In function ‘std::string decompress_system2(const CompressedResourceHeader&, const void*, size_t)’:
/var/tmp/portage/app-arch/resource-dasm-0_p20220329/work/resource_dasm-master/src/Decompressors/System2.cc:106:20: error: ‘source_types’ may be used uninitialized in this function [-Werror=maybe-uninitialized]
  106 |       source_types <<= 1;
      |       ~~~~~~~~~~~~~^~~~~
cc1plus: all warnings being treated as errors

Modifying the initial value of source_types with uint8_t source_types=0; fixes it.

Minor Issue: BCD Version numbers in 'vers' resources

"Inside Macintosh: Toolbox Essentials" says that, in vers resources the first two binary bytes are encoded in binary coded decimal or BCD. (Page 7-69)

For instance, resource_dasm output suggests that Dark Castle 1.1 is version 1.16 because the first two bytes of the vers resource are 0x01 0x10. 1.16 would be correct if taking the bytes were sufficient. However, each digit is encoded in a nibble rather than a byte. So there are 4 digits and the version number is 01.10 in hex aka 1.1 in decimal

decoded.major_version = r.get_u8();

issue with Mail.app .emlx files

I have a bunch of old Mail.app message files (.emlx) that contain resource forks.
I tried using resource_dasm on one of them, and it produced a .emlx_cmpf_1.bin file.
Is this a compressed resource of some kind?
Any suggestions on what to do with it?

Improvement : extracting as png instead of bmp

Hi, I was recently extracting the files from slithereen and managed to use your library to extract all I wanted to extract.

I did realize as I was starting to compress my images into png that the lossless compression of the file format makes a massive difference for the color lookup table generated images. The file size goes from 1.9MB to 47kB.

Perhaps that format should be used for any image extracted to make the extract files lighter while not loosing any data.

compile errors with g++ 11.2.1_p20211127

I got the following compile error with g++ 11.2.1_p20211127

/var/tmp/portage/app-arch/resource-dasm-0_p20220101/work/resource_dasm-master/src/hypercard_dasm.cc: In function ‘int main(int, char**)’:
/var/tmp/portage/app-arch/resource-dasm-0_p20220101/work/resource_dasm-master/src/hypercard_dasm.cc:1220:74: error: cannot bind packed field ‘header.BlockHeader::id’ to ‘int&’
 1220 |         backgrounds.emplace(piecewise_construct, forward_as_tuple(header.id),
      |                                                                   ~~~~~~~^~
/var/tmp/portage/app-arch/resource-dasm-0_p20220101/work/resource_dasm-master/src/hypercard_dasm.cc:1224:68: error: cannot bind packed field ‘header.BlockHeader::id’ to ‘int&’
 1224 |         cards.emplace(piecewise_construct, forward_as_tuple(header.id),
      |                                                             ~~~~~~~^~
/var/tmp/portage/app-arch/resource-dasm-0_p20220101/work/resource_dasm-master/src/hypercard_dasm.cc:1228:70: error: cannot bind packed field ‘header.BlockHeader::id’ to ‘int&’
 1228 |         bitmaps.emplace(piecewise_construct, forward_as_tuple(header.id),
      |                                                               ~~~~~~~^~

Which led me to this report: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=36566

Also got this error:

/var/tmp/portage/app-arch/resource-dasm-0_p20220101/work/resource_dasm-master/src/RealmzLib.cc: In member function ‘void ComplexEncounter::byteswap()’:
/var/tmp/portage/app-arch/resource-dasm-0_p20220101/work/resource_dasm-master/src/RealmzLib.cc:810:53: error: iteration 5 invokes undefined behavior [-Werror=aggressive-loop-optimizations]
  810 |     this->item_codes[x] = bswap16(this->item_codes[x]);
      |                                   ~~~~~~~~~~~~~~~~~~^
/var/tmp/portage/app-arch/resource-dasm-0_p20220101/work/resource_dasm-master/src/RealmzLib.cc:809:21: note: within this loop
  809 |   for (int x = 0; x < 10; x++) {
      |                   ~~^~~~

That and some other errors led me to this patch to fix the issues:

diff -Naur a/CMakeLists.txt b/CMakeLists.txt
--- a/CMakeLists.txt	2022-01-01 19:29:02.196919666 -0500
+++ b/CMakeLists.txt	2022-01-01 19:29:31.827894405 -0500
@@ -12,7 +12,7 @@
 if (MSVC)
     add_compile_options(/W4 /WX)
 else()
-    add_compile_options(-Wall -Wextra -Werror)
+    add_compile_options(-Wall -Wextra -Werror -Wno-strict-aliasing -Wno-unused-result -Wno-overflow -Wno-maybe-uninitialized -Wno-format -Wno-aggressive-loop-optimizations)
 endif()
 
 include_directories("/usr/local/include")
diff -Naur a/src/hypercard_dasm.cc b/src/hypercard_dasm.cc
--- a/src/hypercard_dasm.cc	2022-01-01 19:29:15.748908114 -0500
+++ b/src/hypercard_dasm.cc	2022-01-01 19:24:45.749129132 -0500
@@ -1201,6 +1201,7 @@
     size_t block_offset = r.where();
     BlockHeader header = r.get_sw<BlockHeader>(false);
     size_t block_end = block_offset + header.size;
+    const int& header_id(header.id);
 
     if (dump_raw_blocks) {
       string type_str = string_for_resource_type(header.type);
@@ -1217,15 +1218,15 @@
         stack_format = stack->format;
         break;
       case 0x424B4744: // BKGD
-        backgrounds.emplace(piecewise_construct, forward_as_tuple(header.id),
+        backgrounds.emplace(piecewise_construct, forward_as_tuple(header_id),
             forward_as_tuple(r, stack_format));
         break;
       case 0x43415244: // CARD
-        cards.emplace(piecewise_construct, forward_as_tuple(header.id),
+        cards.emplace(piecewise_construct, forward_as_tuple(header_id),
             forward_as_tuple(r, stack_format));
         break;
       case 0x424D4150: // BMAP
-        bitmaps.emplace(piecewise_construct, forward_as_tuple(header.id),
+        bitmaps.emplace(piecewise_construct, forward_as_tuple(header_id),
             forward_as_tuple(r, stack_format));
         break;

Incorrect canvas size for some PICTs

Thanks for these great tools, I'm glad I found them! I used resource_dasm to extract the resources from the DOCMaker readme for Marathon Infinity and convert its PICTs, but the tool got tripped up converting a couple of the resources, attached. As you'll see, the resulting bitmaps seem to contain only the top-left quadrant of the original image. I've called this an "incorrect canvas size" in the issue title; not sure if that's an accurate description of the problem.

P.S.: Almost all of the other PICT resources in the app fail conversion with the error "(subheader has incorrect version (00000000 or 0000)); attempting rendering using picttoppm", however picttoppm converts them correctly. Do you want me to open another issue with samples of those problem PICTs, or is it considered acceptable behavior to punt those to picttoppm since it handles the resources successfully?

badpicts.zip

Suggestion: Rework the codebase into a .hsb/.rmf extractor

I suggest that someone (maybe fuzziqer) reworks this into something that can rip .rmf/.hsb files.
It also uses snd/esnd/csnd, midi/emid/cmid/ecmi, SONG and INST.
Documentation on hsb/rmf can be found in the miniBAE source code. ALIS is for duplicate patches.

Decoding QuickTime files?

I've got an old texture CD my buddy gave me and I stumbled across this program while searching for ways to decode it. In the extracted files, there are files labeled stuff like 1.MOV, 2.MOV, 3.MOV... etc. with correspondingly-named files in the .rsrc folder. I do have to use the --data-fork tag for this to decode anything at all though, so maybe that means something.

Playing some of these files in something like VLC or MPV works, but most of them don't. I imagine that's because some of them are split up, but I attempted to run this program on them and it only gives me a few bmps, some bin files, or disassemblies of the viewer program meant to run on the actual machine. I had a look through the command line arguments and tried a few more, but to no avail.

I'm wondering if maybe you've come across this before. I haven't included the files here due to the actual CD being quite large, I'm unsure of the proper way I could split them to send examples of the files I'm decoding, but if you happen to know a little bit about this and know what files I'd need to potentially send for examples, I can provide.

make error on Debian 10

Hi, I'm not a C++ expert, this is my output on my Debian 10

make
g++ -I/opt/local/include -g -Wall -std=c++14 -c -o render_bits.o render_bits.cc
In file included from resource_fork.hh:14,
from render_bits.cc:10:
quickdraw_formats.hh:48:8: warning: ignoring packed attribute because of unpacked non-POD field ‘rect bit_map_header::bounds’
rect bounds;
^~~~~~
quickdraw_formats.hh:55:8: warning: ignoring packed attribute because of unpacked non-POD field ‘rect pixel_map_header::bounds’
rect bounds;
^~~~~~
render_bits.cc: In function ‘int main(int, char**)’:
render_bits.cc:136:24: warning: comparison of integer expressions of different signedness: ‘size_t’ {aka ‘long unsigned int’} and ‘int’ [-Wsign-compare]
for (size_t x = 1; x < argc; x++) {
~~^~~~~~
render_bits.cc:176:16: error: ‘sqrt’ was not declared in this scope
double z = sqrt(pixel_count);
^~~~
render_bits.cc:176:16: note: suggested alternative: ‘stat’
double z = sqrt(pixel_count);
^~~~
stat
render_bits.cc:177:14: error: ‘floor’ was not declared in this scope
if (z != floor(z)) {
^~~~~
render_bits.cc:177:14: note: suggested alternative: ‘flock’
if (z != floor(z)) {
^~~~~
flock
make: *** [: render_bits.o] Error 1

[Question] CLUT file

Question regarding extracting CLUTs for use with resource_dasm.

I can see the system CLUT resource using resedit, how can this be extracted into a useable file for resource_dasm?

image

Prebuilt binary for Linux with phosg prelinked

I'm trying to pull the pictures and sounds out of old HyperCard stacks in an environment where I don't have root/sudo so I can't install phosg as a library.

I've been playing with the make files to try to merge the two codebases. There's probably a trick to make it easy, since the macOS release.zip has all the binaries and they seem to run. Can we have a Debian release?

Easier way to convert TEXT/styl to .rtf?

The data format of SilverCreator is a proprietary non-resource fork format, but in v1.5.1 and earlier it stored styled text in that file using "styl" data. However it seems the only way to convert a TEXT/styl pair with resource_dasm is to put it into a resource fork first, but that's super awkward. A SilverCreator file may have 100s of old TEXT/styl parings in it.

Maybe if --decode-single-resource could be specified twice, something like this (where the output name would also have to be specified, due to the ambiguity of two input files)

resource_dasm --decode-single-resource TEXT text.data --decode-single-resource styl styl.data OutputFile.rtf

Or this syntax would be a bit cleaner. If no output file is specified then stdout is assumed.

resource_dasm --decode-text-styl-pair text.data styl.data

Black borders when decoding PICT

I used resource_dasm revision b435972 to convert a PICT file: resource_dasm --decode-pict-file Test.pict. The result was a bmp of the correct size and contents except that close to the edges the image was black. See attached files
Test.pict.zip and Test.pict_PICT_1.bmp.zip (zipped, because Github likes neither PICT nor BMP).

I created the PICT file with Superpaint 3.5, it should contain only a pixmap, no drawing commands. Preview.app displays it correctly.

Support PICTs that contain a PNG or JPEG

Attached are two PICTs. One contains a standard PNG, and the other contains a standard JPEG. These PICTs are obtained from "resource_dasm --save-raw=yes" using the latest source available.

Besides the compressed image, each PICT also contains a few other opcodes, the purpose of which are to draw a warning message that says, "QuickTime™ and a XXXX decompressor are needed to see this picture." where XXXX may be either "PNG" or "Photo - JPEG" (but perhaps other formats as well, which I have yet to personally encounter).

I am dealing with some game files right now that seem to use this "Compressed Image within a PICT" format. Currently, the compressed image is ignored and the PICT is passed off (I assume to) picttoppm which renders the "QuickTime... needed" text and ignores the compressed image.
PICTs with Compressed Images.zip

Unable to build on Fedora 40

I keep receiving this error while trying to build the library in Fedora 40


[ 71%] Building CXX object CMakeFiles/dupe_finder.dir/src/dupe_finder.cc.o
/home/maria/scratchpad/resource_dasm/src/dupe_finder.cc: In function ‘int main(int, const char**)’:
/home/maria/scratchpad/resource_dasm/src/dupe_finder.cc:117:13: error: ‘find_if’ was not declared in this scope; did you mean ‘std::ranges::find_if’?
  117 |         if (find_if(input_filenames.begin(), input_filenames.end(), [&](auto s) { return !strcmp(s, argv[x]); }) == input_filenames.end())
      |             ^~~~~~~
      |             std::ranges::find_if
In file included from /usr/include/c++/14/tuple:44,
                 from /usr/include/c++/14/bits/uses_allocator_args.h:39,
                 from /usr/include/c++/14/bits/memory_resource.h:41,
                 from /usr/include/c++/14/string:67,
                 from /usr/include/c++/14/bitset:52,
                 from /home/maria/scratchpad/resource_dasm/src/ResourceIDs.hh:3,
                 from /home/maria/scratchpad/resource_dasm/src/Cli.hh:3,
                 from /home/maria/scratchpad/resource_dasm/src/dupe_finder.cc:3:
/usr/include/c++/14/bits/ranges_util.h:543:33: note: ‘std::ranges::find_if’ declared here
  543 |   inline constexpr __find_if_fn find_if{};
      |                                 ^~~~~~~
make[2]: *** [CMakeFiles/dupe_finder.dir/build.make:76: CMakeFiles/dupe_finder.dir/src/dupe_finder.cc.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:307: CMakeFiles/dupe_finder.dir/all] Error 2
make: *** [Makefile:136: all] Error 2


compile errors with g++ 13.2.1 20230826

Running g++ 13.2.1 20230826 and cmake 3.27.4 and the latest resource_dasm 2023-08-31 and phosg 2023-09-21 I get this error:

[20/100] /usr/bin/x86_64-pc-linux-gnu-g++ -Dresource_file_EXPORTS -I/usr/local/include  -O2 -march=native -pipe -std=gnu++20 -fPIC -Wall -Wextra -Werror -Wno-strict-aliasing -O2 -MD -MT CMakeFiles/resource_file.dir/src/ExecutableFormats/PEFile.cc.o -MF CMakeFiles/resource_file.dir/src/ExecutableFormats/PEFile.cc.o.d -o CMakeFiles/resource_file.dir/src/ExecutableFormats/PEFile.cc.o -c /var/tmp/portage/app-arch/resource-dasm-0_p20230831/work/resource_dasm-master/src/ExecutableFormats/PEFile.cc
FAILED: CMakeFiles/resource_file.dir/src/ExecutableFormats/PEFile.cc.o 
/usr/bin/x86_64-pc-linux-gnu-g++ -Dresource_file_EXPORTS -I/usr/local/include  -O2 -march=native -pipe -std=gnu++20 -fPIC -Wall -Wextra -Werror -Wno-strict-aliasing -O2 -MD -MT CMakeFiles/resource_file.dir/src/ExecutableFormats/PEFile.cc.o -MF CMakeFiles/resource_file.dir/src/ExecutableFormats/PEFile.cc.o.d -o CMakeFiles/resource_file.dir/src/ExecutableFormats/PEFile.cc.o -c /var/tmp/portage/app-arch/resource-dasm-0_p20230831/work/resource_dasm-master/src/ExecutableFormats/PEFile.cc
/var/tmp/portage/app-arch/resource-dasm-0_p20230831/work/resource_dasm-master/src/ExecutableFormats/PEFile.cc: In member function ‘void PEFile::parse(const void*, size_t)’:
/var/tmp/portage/app-arch/resource-dasm-0_p20230831/work/resource_dasm-master/src/ExecutableFormats/PEFile.cc:195:17: error: possibly dangling reference to a temporary [-Werror=dangling-reference]
  195 |     const auto& header = this->read_from_rva(
      |                 ^~~~~~
/var/tmp/portage/app-arch/resource-dasm-0_p20230831/work/resource_dasm-master/src/ExecutableFormats/PEFile.cc:197:55: note: the temporary was destroyed at the end of the full expression ‘PEFile::read_from_rva(uint32_t, uint32_t) const(((PEFile*)this)->PEFile::header.PEHeader::export_table_rva.little_endian<unsigned int>::<anonymous>.same_endian<unsigned int, unsigned int>::<anonymous>.converted_endian<unsigned int, unsigned int, ident_st<unsigned int, unsigned int>, ident_st<unsigned int, unsigned int> >::operator unsigned int(), ((PEFile*)this)->PEFile::header.PEHeader::export_table_size.little_endian<unsigned int>::<anonymous>.same_endian<unsigned int, unsigned int>::<anonymous>.converted_endian<unsigned int, unsigned int, ident_st<unsigned int, unsigned int>, ident_st<unsigned int, unsigned int> >::operator unsigned int()).StringReader::get<PEExportTableHeader>(1, sizeof (PEExportTableHeader))’
  195 |     const auto& header = this->read_from_rva(
      |                          ~~~~~~~~~~~~~~~~~~~~          
  196 |                                  this->header.export_table_rva, this->header.export_table_size)
      |                                  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  197 |                              .get<PEExportTableHeader>();
      |                              ~~~~~~~~~~~~~~~~~~~~~~~~~^~
cc1plus: all warnings being treated as errors

and

[54/100] /usr/bin/x86_64-pc-linux-gnu-g++  -I/usr/local/include  -O2 -march=native -pipe -std=gnu++20 -Wall -Wextra -Werror -Wno-strict-aliasing -Wno-dangling-reference -O2 -MD -MT CMakeFiles/resource_dasm.dir/src/resource_dasm.cc.o -MF CMakeFiles/resource_dasm.dir/src/resource_dasm.cc.o.d -o CMakeFiles/resource_dasm.dir/src/resource_dasm.cc.o -c /var/tmp/portage/app-arch/resource-dasm-0_p20230831/work/resource_dasm-master/src/resource_dasm.cc
FAILED: CMakeFiles/resource_dasm.dir/src/resource_dasm.cc.o 
/usr/bin/x86_64-pc-linux-gnu-g++  -I/usr/local/include  -O2 -march=native -pipe -std=gnu++20 -Wall -Wextra -Werror -Wno-strict-aliasing -Wno-dangling-reference -O2 -MD -MT CMakeFiles/resource_dasm.dir/src/resource_dasm.cc.o -MF CMakeFiles/resource_dasm.dir/src/resource_dasm.cc.o.d -o CMakeFiles/resource_dasm.dir/src/resource_dasm.cc.o -c /var/tmp/portage/app-arch/resource-dasm-0_p20230831/work/resource_dasm-master/src/resource_dasm.cc
/var/tmp/portage/app-arch/resource-dasm-0_p20230831/work/resource_dasm-master/src/resource_dasm.cc:533:120: error: ‘std::uint32_t’ has not been declared
  533 |   shared_ptr<const ResourceFile::Resource> load_family_icon(const std::shared_ptr<const ResourceFile::Resource>& icon, std::uint32_t type) {
      |                                                                                                                        ^~~
/var/tmp/portage/app-arch/resource-dasm-0_p20230831/work/resource_dasm-master/src/resource_dasm.cc: In member function ‘std::shared_ptr<const ResourceFile::Resource> ResourceExporter::load_family_icon(const std::shared_ptr<const ResourceFile::Resource>&, int)’:
/var/tmp/portage/app-arch/resource-dasm-0_p20230831/work/resource_dasm-master/src/resource_dasm.cc:534:20: error: comparison of integer expressions of different signedness: ‘const uint32_t’ {aka ‘const unsigned int’} and ‘int’ [-Werror=sign-compare]
  534 |     if (icon->type == type) {
      |         ~~~~~~~~~~~^~~~~~~
cc1plus: all warnings being treated as errors

Disabling the errors with -Wno-dangling-reference and -Wno-sign-compare allows it to continue but then I get:

[48/100] /usr/bin/x86_64-pc-linux-gnu-g++ -Dresource_file_EXPORTS -I/usr/local/include  -O2 -march=native -pipe -std=gnu++20 -fPIC -Wall -Wextra -Werror -Wno-strict-aliasing -Wno-dangling-reference -O2 -MD -MT CMakeFiles/resource_file.dir/src/TextCodecs.cc.o -MF CMakeFiles/resource_file.dir/src/TextCodecs.cc.o.d -o CMakeFiles/resource_file.dir/src/TextCodecs.cc.o -c /var/tmp/portage/app-arch/resource-dasm-0_p20230831/work/resource_dasm-master/src/TextCodecs.cc
FAILED: CMakeFiles/resource_file.dir/src/TextCodecs.cc.o 
/usr/bin/x86_64-pc-linux-gnu-g++ -Dresource_file_EXPORTS -I/usr/local/include  -O2 -march=native -pipe -std=gnu++20 -fPIC -Wall -Wextra -Werror -Wno-strict-aliasing -Wno-dangling-reference -O2 -MD -MT CMakeFiles/resource_file.dir/src/TextCodecs.cc.o -MF CMakeFiles/resource_file.dir/src/TextCodecs.cc.o.d -o CMakeFiles/resource_file.dir/src/TextCodecs.cc.o -c /var/tmp/portage/app-arch/resource-dasm-0_p20230831/work/resource_dasm-master/src/TextCodecs.cc
In file included from /var/tmp/portage/app-arch/resource-dasm-0_p20230831/work/resource_dasm-master/src/TextCodecs.cc:1:
/var/tmp/portage/app-arch/resource-dasm-0_p20230831/work/resource_dasm-master/src/TextCodecs.hh:11:38: error: ‘uint32_t’ was not declared in this scope
   11 | std::string string_for_resource_type(uint32_t type, bool for_filename = false);
      |                                      ^~~~~~~~
/var/tmp/portage/app-arch/resource-dasm-0_p20230831/work/resource_dasm-master/src/TextCodecs.hh:4:1: note: ‘uint32_t’ is defined in header ‘<cstdint>’; did you forget to ‘#include <cstdint>’?
    3 | #include <string>
  +++ |+#include <cstdint>
    4 | 
/var/tmp/portage/app-arch/resource-dasm-0_p20230831/work/resource_dasm-master/src/TextCodecs.hh:11:53: error: expected primary-expression before ‘bool’
   11 | std::string string_for_resource_type(uint32_t type, bool for_filename = false);
      |                                                     ^~~~
/var/tmp/portage/app-arch/resource-dasm-0_p20230831/work/resource_dasm-master/src/TextCodecs.hh:12:42: error: ‘uint32_t’ was not declared in this scope
   12 | std::string raw_string_for_resource_type(uint32_t type);
      |                                          ^~~~~~~~
/var/tmp/portage/app-arch/resource-dasm-0_p20230831/work/resource_dasm-master/src/TextCodecs.hh:12:42: note: ‘uint32_t’ is defined in header ‘<cstdint>’; did you forget to ‘#include <cstdint>’?
/var/tmp/portage/app-arch/resource-dasm-0_p20230831/work/resource_dasm-master/src/TextCodecs.cc:98:65: error: ‘std::string string_for_resource_type(uint32_t, bool)’ redeclared as different kind of entity
   98 | string string_for_resource_type(uint32_t type, bool for_filename) {
      |                                                                 ^
/var/tmp/portage/app-arch/resource-dasm-0_p20230831/work/resource_dasm-master/src/TextCodecs.hh:11:13: note: previous declaration ‘std::string string_for_resource_type’
   11 | std::string string_for_resource_type(uint32_t type, bool for_filename = false);
      |             ^~~~~~~~~~~~~~~~~~~~~~~~
/var/tmp/portage/app-arch/resource-dasm-0_p20230831/work/resource_dasm-master/src/TextCodecs.cc:113:50: error: ‘std::string raw_string_for_resource_type(uint32_t)’ redeclared as different kind of entity
  113 | string raw_string_for_resource_type(uint32_t type) {
      |                                                  ^
/var/tmp/portage/app-arch/resource-dasm-0_p20230831/work/resource_dasm-master/src/TextCodecs.hh:12:13: note: previous declaration ‘std::string raw_string_for_resource_type’
   12 | std::string raw_string_for_resource_type(uint32_t type);
      |             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~

Which I can fix by adding #include <cstdint> to src/TextCodecs.hh

But then I get:

[21/22] /usr/bin/x86_64-pc-linux-gnu-g++  -I/usr/local/include  -O2 -march=native -pipe -std=gnu++20 -Wall -Wextra -Werror -Wno-strict-aliasing -Wno-dangling-reference -Wno-sign-compare -O2 -MD -MT CMakeFiles/hypercard_dasm.dir/src/hypercard_dasm.cc.o -MF CMakeFiles/hypercard_dasm.dir/src/hypercard_dasm.cc.o.d -o CMakeFiles/hypercard_dasm.dir/src/hypercard_dasm.cc.o -c /var/tmp/portage/app-arch/resource-dasm-0_p20230831/work/resource_dasm-master/src/hypercard_dasm.cc
FAILED: CMakeFiles/hypercard_dasm.dir/src/hypercard_dasm.cc.o 
/usr/bin/x86_64-pc-linux-gnu-g++  -I/usr/local/include  -O2 -march=native -pipe -std=gnu++20 -Wall -Wextra -Werror -Wno-strict-aliasing -Wno-dangling-reference -Wno-sign-compare -O2 -MD -MT CMakeFiles/hypercard_dasm.dir/src/hypercard_dasm.cc.o -MF CMakeFiles/hypercard_dasm.dir/src/hypercard_dasm.cc.o.d -o CMakeFiles/hypercard_dasm.dir/src/hypercard_dasm.cc.o -c /var/tmp/portage/app-arch/resource-dasm-0_p20230831/work/resource_dasm-master/src/hypercard_dasm.cc
/var/tmp/portage/app-arch/resource-dasm-0_p20230831/work/resource_dasm-master/src/hypercard_dasm.cc: In function ‘int main(int, char**)’:
/var/tmp/portage/app-arch/resource-dasm-0_p20230831/work/resource_dasm-master/src/hypercard_dasm.cc:1163:29: error: redundant move in initialization [-Werror=redundant-move]
 1163 |       string dir = std::move(*it);
      |                    ~~~~~~~~~^~~~~
/var/tmp/portage/app-arch/resource-dasm-0_p20230831/work/resource_dasm-master/src/hypercard_dasm.cc:1163:29: note: remove ‘std::move’ call
cc1plus: all warnings being treated as errors

If I disable that error with -Wno-redundant-move then everything finishes compiling ok.

Doesn't Work On Amazon Trail?

Pretty sure there are snd and csnd resources in this file, but the tool doesn't work on it? I'm probably doing something wrong, but I had to run the installer in Basilisk II and then extract the installed files from the hard disk using HFVExplorer. Maybe doing this copy screwed something up? Any tips on how to extract sounds from this game?

Blobbo - resource fork missing or empty

Hi,
I've been trying to dump the Blobbo lite 1.0.1 resource files for a personal project of mine (a "demake" of the original game for the Playdate). The issue is, attempting to invoke resource_dasm on the Blobbo.rsrc file produced by unar yields

./resource_dasm ./Blobbo.rsrc
>>> ./Blobbo.rsrc (resource fork missing or empty)

Platform used : Ubuntu 22.04 on WSL2
resource_dasm build : whatever was on master last night

I reckon I'm probably doing it wrong because I know little about classic Mac files. Do you have any insights into this ?

Bad CPU type in executable

I'm on OS 10.15.7 Intel Mac Mini (late 2012) and when I run I get this:
-bash: ./resource_dasm: Bad CPU type in executable
What systems is this utility expected to work on?

Encoding.hh: shifting a negative signed value is undefined

(Not sure if I should file this here or in phosg)

I'm using master (f0950b7) and phosg master (9336a3a) with AppleClang 11.0.0.11000033. Compiling results in the following error:

Encoding.hh:14:66: error: shifting a negative signed value is undefined
      [-Werror,-Wshift-negative-value]
    return static_cast<ResultT>(src) | (static_cast<ResultT>(-1) << (sizeof(SrcT) << 3));

Fix that uses unsigned for the shift and then converts to the result type:

template <typename ResultT, typename SrcT>
ResultT sign_extend(SrcT src) {
  using UResultT = std::make_unsigned_t<ResultT>;
  if (src & (1 << ((sizeof(SrcT) << 3) - 1))) {
    return static_cast<ResultT>(src) | (static_cast<ResultT>(static_cast<UResultT>(-1) << (sizeof(SrcT) << 3)));
  } else {
    return static_cast<ResultT>(src);
  }
}

Format string errors

I'm using master (f0950b7) with AppleClang 11.0.0.11000033. Compiling results in the following error:

resource_dasm.cc:287:77: error: format specifies type 'unsigned short' but the argument has type 'uint8_t' (aka 'unsigned char')

Fix: replace %hu with %hhu:

add_line(prefix + string_printf("(align to %hhu-byte boundary)", entry->end_alignment));

Then:

RealmzScenarioData.cc:587:14: error: format specifies type 'short' but the argument has type 'int8_t' (aka 'signed char')
RealmzScenarioData.cc:645:14: error: format specifies type 'short' but the argument has type 'int8_t' (aka 'signed char')

Fix: replace %hd with %hhd (twice):

string ret = string_printf("===== SIMPLE ENCOUNTER id=%zu can_backout=%hhd max_times=%hhd prompt=%s [SEC%zu]\n",
                                                                       ^^^            ^^^

And finally:

RealmzScenarioData.cc:2046:23: error: format specifies type 'short' but the argument has type 'uint8_t' (aka 'unsigned char')

Fix: replace %hd with %hhu:

map.draw_text(text_xp, text_yp, 0xFFFFFFFF, 0x00000080, "%d-%hhu%%",

compile error in Ubuntu on Pi4 ARM

[ 12%] Building CXX object CMakeFiles/resource_file.dir/src/Emulators/MemoryContext.cc.o
/home/pi/programs/resource_dasm/src/Emulators/MemoryContext.cc: In member function ‘std::__cxx11::string MemoryContext::Arena::str() const’:
/home/pi/programs/resource_dasm/src/Emulators/MemoryContext.cc:193:30: error: format ‘%lX’ expects argument of type ‘long unsigned int’, but argument 3 has type ‘unsigned int’ [-Werror=format=]
   string ret = string_printf("[Arena %08" PRIX32 "-%08lX at %p alloc=%zX free=%zX alloc_blocks=[",
                              ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/pi/programs/resource_dasm/src/Emulators/MemoryContext.cc:195:7:
       this->addr + this->size,
       ~~~~~~~~~~~~~~~~~~~~~~~
cc1plus: all warnings being treated as errors
make[2]: *** [CMakeFiles/resource_file.dir/build.make:206: CMakeFiles/resource_file.dir/src/Emulators/MemoryContext.cc.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:224: CMakeFiles/resource_file.dir/all] Error 2
make: *** [Makefile:130: all] Error 2

changing the source line to the following seems to allow it to compile OK (take out the L from %08lX):
string ret = string_printf("[Arena %08" PRIX32 "-%08X at %p alloc=%zX free=%zX alloc_blocks=[",

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.