TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Reverse-Engineering Apple Dictionary (2020)

278 pointsby goranmoominover 3 years ago

18 comments

btnover 3 years ago
Another approach for this is to explore the format through Apple&#x27;s tools for building dictionaries – as they provide a &quot;Dictionary Development Kit&quot; in Xcode&#x27;s downloadable &quot;Additional Tools&quot; package (which has documentation for the XML format and a bunch of scripts&#x2F;binaries for building the bundle).<p>I wound up doing this a while ago for a similar toy project. After some poking around, it turned out that dictionary bundles are entirely supported by system APIs in CoreServices! The APIs are private, but Apple accidentally shipped a header file with documentation for them in the 10.7 SDK [1]. You can load a dictionary with `IDXCreateIndexObject()`, read through its indices with the search methods (and the convenient `kIDXSearchAllMatch`), and get pointers to its entry data with `IDXGetFieldDataPtrs()`.<p>It takes a bit of fiddling to figure out the structure (there are multiple indices for headwords, search keywords, cross-references, etc., and the API is a general-purpose trie library) and request the right fields, but those property lists in the bundle are there to help! (As the author of this article discovered, the entries are compressed and are proceeded with a 4-byte length marker.)<p>[1] <a href="https:&#x2F;&#x2F;github.com&#x2F;phracker&#x2F;MacOSX-SDKs&#x2F;blob&#x2F;master&#x2F;MacOSX10.7.sdk&#x2F;usr&#x2F;include&#x2F;IndexedSearch.h" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;phracker&#x2F;MacOSX-SDKs&#x2F;blob&#x2F;master&#x2F;MacOSX10...</a>
评论 #28508006 未加载
enragedcactiover 3 years ago
For anyone else needing to tackle something like this, its definitely worth checking out Binwalk [1]. It is meant for extracting firmware but it works decently well on most files-in-files type data formats.<p>[1] <a href="https:&#x2F;&#x2F;github.com&#x2F;ReFirmLabs&#x2F;binwalk" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;ReFirmLabs&#x2F;binwalk</a>
评论 #28509468 未加载
gilgoomeshover 3 years ago
It seems highly likely (given that this is a dictionary and requires fast lookups) that you&#x27;re reverse engineering something like CEVFS (i.e. a virtual file system for compressing a database). Which is why the dictionary is broken into chunks... these are the compressed pages of the database.
tim--over 3 years ago
Another way to extract all of those compressed zip files would have been to use binwalk.<p><pre><code> binwalk --dd=&#x27;.*&#x27; *.asset </code></pre> Edit: should have read the comments before I posted this, because enragedcacti already mentioned this tool an hour ago.
评论 #28571933 未加载
peterburkimsherover 3 years ago
Thank you for posting this code on Github! There has been some reverse-engineering done on the language dictionaries bundled with Mac OS, and it&#x27;s nice to know that the same model is being used on the Apple Watch! I look forward to seeing your dictionary app.<p><a href="https:&#x2F;&#x2F;josephg.com&#x2F;blog&#x2F;reverse-engineering-apple-dictionaries&#x2F;" rel="nofollow">https:&#x2F;&#x2F;josephg.com&#x2F;blog&#x2F;reverse-engineering-apple-dictionar...</a><p>There&#x27;s also a command-line tool that can query the dictionary:<p><a href="https:&#x2F;&#x2F;github.com&#x2F;takumakei&#x2F;osx-dictionary" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;takumakei&#x2F;osx-dictionary</a><p>Something I haven&#x27;t yet reverse-engineered is Apple&#x27;s word segmentation. I can get the word breaks in Chinese by pressing option + right arrow + space, repeatedly. But I have no idea how the backend for that works.
评论 #28506371 未加载
octrefover 3 years ago
I have thought about building a vocabulary learning tool for learning Japanese on top of Apple Dictionary. My idea is simple: user collects dicitionary items and the tool offers lookup &#x2F; spaced-repetition.<p>However, I&#x27;m concerned that the dictionary is copyrighted. Is there any precedent that says whether such a tool would be legal&#x2F;illegal?
评论 #28506247 未加载
ranvelover 3 years ago
This was an amazingly delightful read. I was hoping it would shed some light on a long-time project I had which was reversing the Oxford language dictionaries that were included on CDROM with the big printed texts. (I already did it, but with a debugger instead of by reversing the binary format). Alas, it did not, but it was super encouraging to see the enthusiasm and interest in language dictionaries.
cogburnd02over 3 years ago
would be really really cool if someone could make a small script to convert these into a format understandable by dict:&#x2F;&#x2F;<p><a href="https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;DICT" rel="nofollow">https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;DICT</a>
评论 #28571940 未加载
dunhamover 3 years ago
The &quot;seemingly random bytes&quot; look like a small 32-bit little endian number to me, probably the length of the subsequent payload.
atorodiusover 3 years ago
Author here, funny to see this popping up on HN :) Was definitly a fun ride making this.
评论 #28571959 未加载
评论 #28509090 未加载
ChrisMarshallNYover 3 years ago
That&#x27;s awesome!<p>But be aware (i.e. &quot;beware&quot;) that Apple can pull the rug out of unpublished APIs, without warning.<p>I have been caught out, by this, myself.
etaioinshrdluover 3 years ago
This is fun. I have another idea: I&#x27;d be interested on calling Siri from the command line. Even if using private APIs. (But without hacky fake drivers, or accessibility tools)
评论 #28506013 未加载
gfaureover 3 years ago
I assume one reason Apple has made it more challenging to extract the dictionary resources is in order to satisfy licensing constraints with the dictionary authors. I wonder if they&#x27;d block an app like this through the App Store submission process, if submitted.
评论 #28506079 未加载
评论 #28505908 未加载
评论 #28505750 未加载
hyperstarover 3 years ago
At the moment, I&#x27;m using a slight modification of the gist plus `sed &#x27;s&#x2F;&lt;[^&gt;]*&gt;&#x2F;&#x2F;g&#x27;` to look up words from the shell on Linux. It would be nice to have some XML parsing into plain text, but it kind of works.
hellothereworldover 3 years ago
I also found this Dictionary API which imports the dictionaries into NodeJs by utilizing a utility called „dedict“.<p><a href="https:&#x2F;&#x2F;github.com&#x2F;nikvdp&#x2F;dictionary-api&#x2F;blob&#x2F;master&#x2F;convertDicts.js" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;nikvdp&#x2F;dictionary-api&#x2F;blob&#x2F;master&#x2F;convert...</a>
diimdeepover 3 years ago
Unfortunately it is not possible to implement add-on(add source) to Dictionary.app that is dynamic, like built-in Wikipedia; for example to query urbandictionary.com; only static offline is possible. I tried to investigate this years ago, don&#x27;t think something changed since then.
bhlover 3 years ago
Has anyone reversed-engineered the Apple emoji dictionary that maps some keywords to emojis? Last time I checked, they only shipped binaries on the newest MacOS. Would love to use that mapping to elevate search on my custom emoji picker.
评论 #28508659 未加载
评论 #28507025 未加载
评论 #28508563 未加载
cratermoonover 3 years ago
Is this a plist?