Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add specification for TP-Link's minifs #682

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
112 changes: 112 additions & 0 deletions filesystem/tplink_minifs.ksy
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
meta:
id: tplink_minifs
title: TP-Link MINIFS
license: CC0-1.0
endian: be
encoding: ASCII
doc: |
MINIFS is a file system found in certain TP-Link firmware files, such as
RE450(V4)_210531.zip, for TP-Link's own TPOS RTOS.

It consists of a header, followed by a list of file names, followed by
meta information for each file, meta information about the LZMA compressed
blobs including length, offset and uncompressed length, and then a number
of LZMA compressed blobs.

The LZMA blobs can contain the concatenated contents of multiple files.
The meta information of a file contains an offset to the directory name,
a file name, the LZMA blob (numbering starts at 0), the offset of the file
in the uncompressed data and the size of the uncompressed file.
seq:
- id: header
size: 32
type: header
- id: filenames
size: header.len_filenames
type: filenames
- id: inodes
type: 'inode(_index != 0 ? inodes[_index - 1].cur_max_lzma_blob : 0)'
repeat: expr
repeat-expr: header.num_files
- id: lzma_metas
type: 'lzma_meta(_index != 0 ? lzma_metas[_index - 1].ofs_end : 0)'
repeat: expr
repeat-expr: inodes.last.cur_max_lzma_blob + 1
doc: Count starts at 0, so there is one more blob than the highest blob number
- id: lzma_blobs_area
size: lzma_metas.last.ofs_end
type: dummy
instances:
lzma_blobs:
io: _root.lzma_blobs_area._io
type: lzma_blob(_index)
repeat: expr
repeat-expr: _root.inodes.last.cur_max_lzma_blob + 1
types:
dummy: {}
lzma_blob:
params:
- id: index
type: u4
instances:
data:
pos: _root.lzma_metas[index].ofs_blob
size: _root.lzma_metas[index].len_blob
header:
seq:
- id: magic
contents: "MINIFS\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
- id: unknown_1
type: u4
- id: num_files
type: u4
- id: unknown_2
type: u4
- id: len_filenames
type: u4
filenames:
seq:
- id: filename
type: strz
repeat: eos
inode:
params:
- id: prev_max_lzma_blob
type: u4
seq:
- id: ofs_directory
type: u4
- id: ofs_name
type: u4
- id: lzma_blob
type: u4
- id: ofs_file
type: u4
- id: size
type: u4
instances:
cur_max_lzma_blob:
value: 'lzma_blob > prev_max_lzma_blob ? lzma_blob : prev_max_lzma_blob'
filename:
io: _root.filenames._io
pos: ofs_name
type: strz
directory_name:
io: _root.filenames._io
pos: ofs_directory
type: strz
lzma_meta:
params:
- id: prev_ofs_end
type: u4
seq:
- id: ofs_blob
type: u4
valid: prev_ofs_end
- id: len_blob
type: u4
- id: len_blob_uncompressed
type: u4
instances:
ofs_end:
value: ofs_blob + len_blob