Skip to content

Binary Internals

botrx555 edited this page Jul 14, 2026 · 1 revision

Binary Internals

The static-disassembly reference for the original m8raw2dng.exe, and the record of how its behaviour was established. Where The Original Tool says what the original does, this page says how it is known: the constants, functions and tag tables read out of the binary, and the empirical comparison that confirmed them on real frames.

No original source is reproduced here - only functional facts: constants, tag numbers, function roles and file-format details. Tools used: radare2, pefile and capstone for the disassembly; exiftool, tifffile, PIL and numpy for the frame measurements.

Binary identity

Field Value
SHA-256 c757f0d2...96436a9
Size / format 141,824 bytes; PE32 i386 console; 5 sections
Build 2014-02-21 11:41:32 UTC; MSVC 2010 (MSVCR100 / MSVCP100), C++ iostreams
Copyright (C) 2013 Arvid Kuehl
Homepage m8raw2dng.de
PDB path E:\DB_YB\Data\m8raw2dng\Release\m8raw2dng.pdb
Third-party CSimpleIni (INI parser)

The copyright string, the Leica forums and the Mac droplet's own output all agree on Arvid Kuehl; this is the finalized attribution.

Constant pool (.rdata doubles)

Thirteen IEEE-754 doubles decoded from .rdata. These are the numeric backbone of the tool.

Address Value Meaning
0x41dce0 0.5 rounding bias (round-half-up before truncation)
0x41dce8 255.0 8-bit clamp / preview
0x41dcf0 4.0 -
0x41dcf8 240.0 preview height (320 x 240)
0x41dd00 320.0 preview width (320 x 240)
0x41dd08 3.0 ExposureBias denominator (thirds)
0x41dd10 32767.0 16-bit signed clamp (NOT the DNG WhiteLevel)
0x41dd28 1.33 Leica M8 crop factor -> FocalLengthIn35mmFilm
0x41dd30 2.0 log2 base (used as ln(x)/ln(2))
0x41dd38 2000.0 APEX MaxApertureValue numerator scale (2 x 1000)
0x41dd40 1.52587890625e-05 1/65536, undoes the fixed-point aperture
0x41dd48 1000.0 APEX rational denominator
0x41dd50 65536.0 fixed-point aperture / FNumber scale

Two often-misread values: 32767.0 is a 16-bit signed working clamp, not the DNG WhiteLevel (which is the byte-verified 16383); and 65536.0 is the FNumber and fixed-point-aperture scale, shared by both tools.

Function map

Twenty functions labelled by role.

Address Role
fcn.004109a0 usage / help printer
fcn.00413ac0 top-level driver; arg parse; mode dispatch; loads lensdb; .BIA load
fcn.004193e0 loads lensdb.ini
fcn.00418590 lens-DB lookup (Maker/Model/SerialNo/FocalLength); aperture list as x65536 fixed-point
fcn.00410640 JPG read + EXIF orchestration + lens detection
fcn.00411ec0 JPEG container parser (FFD8..FFD9, marker scan, APP1 to EXIF)
fcn.00411f70 EXIF / IFD parser; per-tag dispatch; parses Leica MakerNote (0x927c)
fcn.00404e10 DNG IFD0 metadata builder (path A)
fcn.00403xxx DNG IFD builder (path B; second model / preview variant)
fcn.004040f0 tag setter (SHORT / LONG and simple types)
fcn.00404730 tag setter (RATIONAL)
fcn.00406920 DNG writer ("Writing DNG header...", "Writing image data...")
fcn.00406680 DNG header entry emitter
fcn.00406d40 black-level calc (ISO scaling base x {1,2,4,8,16})
fcn.0040b7f0 defect-pixel correction (horizontal neighbours over a defect list)
fcn.0040f490 sensor level / darkfield correction (LevelCorrection)
fcn.00417890 -sd compute: per-column sums binned by (index mod columns), divided by row count
fcn.00416d00 sensdb.ini writer via CSimpleIni
fcn.0041a480 / fcn.0041a710 .BIA writer / reader (serialized std::vector)
sub 0x41b51c _CIlog thunk (called only from MaxApertureValue, 4 sites)

-sd format strings live at 0x41dc74 (%ld), 0x41dc78 (%f), 0x41dc7c (CRLF), 0x41dc80 (section header [).

DNG tag maps

The original writes 47 IFD0 tags and 21 EXIF sub-IFD tags. A bare -v conversion is byte-identical to it on every value except the estimated FNumber, so the two tools' tag values match. Selected mappings (full behaviour in File Formats):

IFD0 highlights:

Tag Name Value
256 / 257 ImageWidth / Length 3968 / 2646
258 BitsPerSample 16
259 Compression 1 (none)
262 PhotometricInterpretation 32803 (CFA)
271 / 272 Make / Model "Leica Camera AG" / "M8 Digital Camera"
282 / 283 X / YResolution 300 / 1
33421 / 33422 CFARepeatPatternDim / CFAPattern (2,2) / RGGB
50706 DNGVersion 01 04 00 00
50708 UniqueCameraModel "M8 Digital Camera"
50717 WhiteLevel 16383
50719 / 50720 DefaultCropOrigin / Size (2,2) / (3964,2642)
50721 / 50722 ColorMatrix1 / 2 M8 sets (M9 with -c)
50723 / 50724 CameraCalibration1 / 2 identity
50728 AsShotNeutral per-shot, from MakerNote WB
50733 BayerGreenSplit 500
50778 / 50779 CalibrationIlluminant1 / 2 17 (Std A) / 21 (D65)
50713 / 50714 BlackLevelRepeatDim / BlackLevel none on a bare -v; both tools write it under -b (original base_black x gain; m8raw2dng2 flat under plain -b, gain-scaled under -s)

EXIF highlights:

Tag Name Value
33434 ExposureTime from JPG
33437 FNumber n / 65536 (estimate; see The Math)
34855 ISOSpeedRatings from JPG
37380 ExposureBiasValue (n, 3) thirds
37381 MaxApertureValue round(2000 * log2(aperture)) / 1000
41989 FocalLengthIn35mmFilm round(focal * 1.33)

Leica MakerNote tags

Read from the JPG's MakerNote (0x927c); the RAW carries no EXIF.

Tag Meaning Original reads it
0x0303 CameraSerialNumber yes
0x0310 LensCode (6-bit) yes (0x412c53)
0x0311 ExternalSensorBrightnessValue (ext_bv) yes (0x412831)
0x0312 MeasuredLV (meas_lv) likely
0x0313 ApproximateFNumber read, but not the FNumber source; not emitted
0x0322 / 0x0323 / 0x0324 white balance -> AsShotNeutral yes

The two meter tags 0x0311 and 0x0312 are the ones the aperture recovery works from; 0x0313 (the camera's own rough FNumber) is read but written by neither tool.

How this was established

Two phases: a static disassembly, then an empirical comparison of both tools on real M8 frames (both run -v, no -A, no -l; identical, untouched lens database). The empirical measurement is authoritative wherever it overrode a disassembly inference.

Corpus Count
binaries analysed 1
constant doubles decoded 13
functions mapped 20
IFD0 / EXIF tags mapped 47 / 21
ColorMatrix variants decoded (M8/M9 x 1/2) 4
frames measured 10
original DNGs examined 9
m8raw2dng2 DNGs examined 8
.BIA files examined 6
sensdb.ini compared (3968 rows each) 2
full-frame pixel comparisons 20
pixels compared, total ~210 million
original executed under wine (v1.20) 12 flag / .BIA conditions
tool conversions run 4
Verdict Count
static-disassembly checks 13
empirical checks (both tools on real frames) 23
dynamic checks (original run under wine + readme cross-check) 7+
total discrete checks 43+
open questions remaining 0

Several early inferences were corrected as the grounding improved - first by measuring both tools on real frames, then by running the original itself under wine (v1.20; a bare -v reproduced a reference DNG to a single byte) and cross-checking the official readme. The traps this format sets, and how they resolved: FNumber is not a lens-database lookup and not a passthrough of the camera's ApproxFN, but a compressed meter estimate; the original writes no BlackLevel on a bare -v but writes base_black x gain under -b (tag-only, pixels never touched); an early reading that m8raw2dng2 "corrects by default" was wrong - that divergence traced to an adjacent .BIA being auto-subtracted; the RAW-mode width is 3968, while 3920 is the separate standard-M8-DNG input mode's width (both are real, both live in the binary); and the original's darkfield target is deterministic in the binary but not decoded, empirically unpredicted by the frame statistics tested (see The Math).

The sixteen confirmations that held: Arvid Kuehl authorship; all four ColorMatrix variants exact; crop factor 1.33; the APEX MaxApertureValue formula; illuminants 17 / 21; 300 DPI; identity CameraCalibration; WhiteLevel 16383 (9 of 9 DNGs); FNumber denominator 65536 (both tools); the ISO black factor {1,2,4,8,16}; the -sd six-decimal CRLF format; no logarithm in the FNumber path; the .BIA as a raw-container dark frame; the original's pixel passthrough (5 of 5 ISOs); -b tag-only (both test values); and bare -v producing pixels identical to the original.

Clone this wiki locally