-
Notifications
You must be signed in to change notification settings - Fork 1
/
global_svc.py
42 lines (36 loc) · 1.61 KB
/
global_svc.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# Copyright (C) 2018 Iru Cai <[email protected]>
# SPDX-License-Identifier: GPL-3.0-or-later
from efiobj import EfiObj, regMap, efiAddrMap
from uefi_tables import rt_svc_name, boot_svc_name
from smmbase import smmbaseobj
def doLocateProtocol(r2):
if regMap.get("rcx") is not None and regMap.get("r8") is not None:
f = r2.cmdj("fdj {}".format(regMap["rcx"]["value"]))
if f.get("name") is not None:
guidname = f["name"]
staddr = regMap["r8"]["value"]
if len(guidname) > 16 and guidname[0:4] == "gEfi" and guidname[-12:] == "ProtocolGuid":
guidname = guidname[4:-12]
r2.cmd("f {} @ {}".format(guidname, staddr))
if guidname == "SmmBase":
efiAddrMap[staddr] = smmbaseobj
def doInstallProtocolInterface(r2):
if regMap.get("r9") is not None:
r2.cmd("\"CC protocol interface\" @ {}".format(regMap.get("r9")["insn"]["offset"]))
def gBSact(r2, insn):
fname = boot_svc_name(insn["ptr"])
if fname is not None:
r2.cmd("CC \"gBS->{}\" @ {}".format(fname, insn["offset"]))
if fname == "LocateProtocol":
doLocateProtocol(r2)
elif fname == "InstallProtocolInterface":
doInstallProtocolInterface(r2)
elif fname == "CreateEvent" or fname == "CreateEventEx":
if regMap.get("r8").get("value") is not None:
r2.cmd("af {}".format(regMap["r8"]["value"]))
def gRTact(r2, insn):
fname = rt_svc_name(insn["ptr"])
if (fname is not None):
r2.cmd("CC \"gRT->{}\" @ {}".format(fname, insn["offset"]))
gbsobj = EfiObj(gBSact)
grtobj = EfiObj(gRTact)