Skip to content

Commit

Permalink
dji_imah_fwsig: Type field is 4 chars.
Browse files Browse the repository at this point in the history
The field was previously unused, so we didn't knew for sure
what its format was. But in WM240 it is used - stores short
text name of the module.

The change will cause old .ini files to set type to one-char string
of '0' while signing; but no matter - it was unused anyway.
And this can be easily corrected by just generating new .ini
(unsigning the firmware file before re-signing).
  • Loading branch information
mefistotelis committed Aug 2, 2019
1 parent 1e59602 commit 61df79f
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions dji_imah_fwsig.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ class ImgPkgHeader(LittleEndianStructure):
('enc_key', c_char * 4), #44
('scram_key', c_ubyte * 16), #48
('name', c_char * 32), #64
('type', c_uint), #96
('type', c_char * 4), #96
('version', c_uint), #100
('date', c_uint), #104
('reserved2', c_ubyte * 20), #108
Expand Down Expand Up @@ -218,6 +218,8 @@ def dict_export(self):
d[varkey] = d[varkey].decode("utf-8")
varkey = 'enc_key'
d[varkey] = d[varkey].decode("utf-8")
varkey = 'type'
d[varkey] = d[varkey].decode("utf-8")
return d

def ini_export(self, fp):
Expand Down Expand Up @@ -247,7 +249,7 @@ def ini_export(self, fp):
varkey = 'compression'
fp.write("{:s}={:d}\n".format(varkey,d[varkey]))
varkey = 'type'
fp.write("{:s}={:d}\n".format(varkey,d[varkey]))
fp.write("{:s}={:s}\n".format(varkey,d[varkey]))
varkey = 'userdata'
fp.write("{:s}={:s}\n".format(varkey,d[varkey].decode("utf-8"))) # not sure if string or binary
varkey = 'entry'
Expand Down Expand Up @@ -414,7 +416,7 @@ def imah_read_fwsig_head(po):
pkghead.os = int(parser.get("asection", "os"))
pkghead.arch = int(parser.get("asection", "arch"))
pkghead.compression = int(parser.get("asection", "compression"))
pkghead.type = int(parser.get("asection", "type"))
pkghead.type = bytes(parser.get("asection", "type"), "utf-8")
entry_bt = bytes.fromhex(parser.get("asection", "entry"))
pkghead.entry = (c_ubyte * len(entry_bt)).from_buffer_copy(entry_bt)

Expand Down

0 comments on commit 61df79f

Please sign in to comment.