diff options
| author | ruki <[email protected]> | 2018-05-23 22:45:06 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2018-05-23 10:30:41 +0800 |
| commit | abd2f0cc0aa5c9d48ce6fbb11ed57c441c0a3623 (patch) | |
| tree | 3f873fd5ae323fe3a77ed9122f7fc9a5cab7f580 | |
| parent | 6f36d0d4e5ce896424c51df8e544506f54660a44 (diff) | |
impl wdk.sign.test rule
| -rw-r--r-- | tests/projects/wdk/kmdf/ioctl/xmake.lua | 2 | ||||
| -rw-r--r-- | tests/projects/wdk/kmdf/serial/xmake.lua | 2 | ||||
| -rw-r--r-- | tests/projects/wdk/umdf/echo/xmake.lua | 2 | ||||
| -rw-r--r-- | tests/projects/wdk/umdf/skeleton/xmake.lua | 2 | ||||
| -rw-r--r-- | tests/projects/wdk/wdm/perfcounters/xmake.lua | 2 | ||||
| -rw-r--r-- | xmake/rules/wdk/inf/xmake.lua | 5 | ||||
| -rw-r--r-- | xmake/rules/wdk/sign/test/xmake.lua | 39 |
7 files changed, 46 insertions, 8 deletions
diff --git a/tests/projects/wdk/kmdf/ioctl/xmake.lua b/tests/projects/wdk/kmdf/ioctl/xmake.lua index 6c7c6f7a7..0fe5dda38 100644 --- a/tests/projects/wdk/kmdf/ioctl/xmake.lua +++ b/tests/projects/wdk/kmdf/ioctl/xmake.lua @@ -9,7 +9,7 @@ add_includedirs(".") target("nonpnp") -- add rules - add_rules("wdk.kmdf.driver") + add_rules("wdk.kmdf.driver", "wdk.sign.test") -- add flags for rule: wdk.tracewpp add_values("wdk.tracewpp.flags", "-func:TraceEvents(LEVEL,FLAGS,MSG,...)", "-func:Hexdump((LEVEL,FLAGS,MSG,...))") diff --git a/tests/projects/wdk/kmdf/serial/xmake.lua b/tests/projects/wdk/kmdf/serial/xmake.lua index e2f91d20f..2114fdcca 100644 --- a/tests/projects/wdk/kmdf/serial/xmake.lua +++ b/tests/projects/wdk/kmdf/serial/xmake.lua @@ -6,7 +6,7 @@ add_rules("mode.debug", "mode.release") target("serial") -- add rules - add_rules("wdk.kmdf.driver") + add_rules("wdk.kmdf.driver", "wdk.sign.test") -- add flags for rule: wdk.tracewpp add_values("wdk.tracewpp.flags", "-func:SerialDbgPrintEx(LEVEL,FLAGS,MSG,...)") diff --git a/tests/projects/wdk/umdf/echo/xmake.lua b/tests/projects/wdk/umdf/echo/xmake.lua index 45ec8ec9d..64a25a118 100644 --- a/tests/projects/wdk/umdf/echo/xmake.lua +++ b/tests/projects/wdk/umdf/echo/xmake.lua @@ -9,7 +9,7 @@ add_defines("_UNICODE", "UNICODE") target("echo") -- add rules - add_rules("wdk.umdf.driver") + add_rules("wdk.umdf.driver", "wdk.sign.test") -- add files add_files("driver/*.c") diff --git a/tests/projects/wdk/umdf/skeleton/xmake.lua b/tests/projects/wdk/umdf/skeleton/xmake.lua index 6fbd074a2..e06c2ac57 100644 --- a/tests/projects/wdk/umdf/skeleton/xmake.lua +++ b/tests/projects/wdk/umdf/skeleton/xmake.lua @@ -9,7 +9,7 @@ add_defines("_UNICODE", "UNICODE") target("skeleton") -- add rules - add_rules("wdk.umdf.driver") + add_rules("wdk.umdf.driver", "wdk.sign.test") -- add flags fro tracewpp add_values("wdk.tracewpp.flags", "-scan:internal.h") diff --git a/tests/projects/wdk/wdm/perfcounters/xmake.lua b/tests/projects/wdk/wdm/perfcounters/xmake.lua index fb0bc3d54..de86d9b53 100644 --- a/tests/projects/wdk/wdm/perfcounters/xmake.lua +++ b/tests/projects/wdk/wdm/perfcounters/xmake.lua @@ -6,7 +6,7 @@ add_rules("mode.debug", "mode.release") target("kcs") -- add rules - add_rules("wdk.wdm.driver") + add_rules("wdk.wdm.driver", "wdk.sign.test") -- add flags for rule: wdk.man add_values("wdk.man.prefix", "Kcs") diff --git a/xmake/rules/wdk/inf/xmake.lua b/xmake/rules/wdk/inf/xmake.lua index 7c3e37790..a9ab72212 100644 --- a/xmake/rules/wdk/inf/xmake.lua +++ b/xmake/rules/wdk/inf/xmake.lua @@ -64,8 +64,11 @@ rule("wdk.inf") -- add clean files target:data_add("wdk.cleanfiles", targetfile) + -- save this target file for signing (wdk.sign.* rules) + target:data_set("wdk.sign.inf", targetfile) + -- init args - local args = {"-d", "*", "-a", is_arch("x64") and "arm64" or "x86", "-v", "*"} + local args = {"-d", "*", "-a", is_arch("x64") and "amd64" or "x86", "-v", "*"} local flags = target:values("wdk.inf.flags", sourcefile) if flags then table.join2(args, flags) diff --git a/xmake/rules/wdk/sign/test/xmake.lua b/xmake/rules/wdk/sign/test/xmake.lua index dc8a7b12b..362731358 100644 --- a/xmake/rules/wdk/sign/test/xmake.lua +++ b/xmake/rules/wdk/sign/test/xmake.lua @@ -34,6 +34,7 @@ rule("wdk.sign.test") -- imports import("core.base.option") import("core.project.config") + import("lib.detect.find_file") -- trace progress info cprintf("${green}[%02d%%]:${clear} ", opt.progress) @@ -56,6 +57,16 @@ rule("wdk.sign.test") end assert(os.isexec(signtool), "signtool not found!") + -- get inf2cat + local inf2cat = path.join(wdk.bindir, arch, "inf2cat.exe") + if not os.isexec(inf2cat) then + inf2cat = path.join(wdk.bindir, wdk.sdkver, arch, "inf2cat.exe") + end + if not os.isexec(inf2cat) then + inf2cat = path.join(wdk.bindir, wdk.sdkver, "x86", "inf2cat.exe") + end + assert(os.isexec(inf2cat), "inf2cat not found!") + -- try to get certificate info local certinfo = try { @@ -71,8 +82,32 @@ rule("wdk.sign.test") end -- get thumbprint from certificate info - local thumbprint = certinfo:match("sha1.-: (%w+)") - print(thumbprint) + local thumbprint = (certinfo:match("sha1.-: (%w+)") or ""):trim() + assert(#thumbprint > 0, "cannot get thumbprint of certificate!") + + -- sign the target file + os.vrunv(signtool, {"sign", "/ph", "/sha1", thumbprint, target:targetfile()}) + + -- get inf file + local infile = target:data("wdk.sign.inf") + if not infile or not os.isfile(infile) then + vprint("Inf2Cat task was skipped as there were no inf files to process") + return + end + + -- do inf2cat + local inf2cat_dir = path.directory(target:targetfile()) + local inf2cat_argv = {"/driver:" .. inf2cat_dir} + local inf2cat_os = target:values("wdk.inf2cat.os") or {"10_" .. config.arch()} -- TODO 7_, 8_ .. ? + table.insert(inf2cat_argv, "/os:" .. table.concat(table.wrap(inf2cat_os), ',')) + os.vrunv(inf2cat, inf2cat_argv) + + -- get *.cat file path from the output directory + local catfile = find_file("*.cat", inf2cat_dir) + assert(catfile, "*.cat not found!") + + -- sign *.cat file + os.vrunv(signtool, {"sign", "/ph", "/sha1", thumbprint, catfile}) end) |
