Skip to content

Commit b060607

Browse files
committed
Implemented GetTime
1 parent b9fa8fa commit b060607

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

qiling/os/uefi/UefiSpec.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,13 @@
1010
from .UefiBaseType import *
1111
from .UefiMultiPhase import *
1212

13+
# definitions for EFI_TIME.Daylight
14+
EFI_TIME_ADJUST_DAYLIGHT = (1 << 1)
15+
EFI_TIME_IN_DAYLIGHT = (1 << 2)
16+
17+
# definition for EFI_TIME.TimeZone
18+
EFI_UNSPECIFIED_TIMEZONE = 0x07ff
19+
1320
class EFI_ALLOCATE_TYPE(ENUM):
1421
_members_ = [
1522
'AllocateAnyPages',
@@ -244,6 +251,9 @@ class EFI_SYSTEM_TABLE(STRUCT):
244251
]
245252

246253
__all__ = [
254+
'EFI_TIME_ADJUST_DAYLIGHT',
255+
'EFI_TIME_IN_DAYLIGHT',
256+
'EFI_UNSPECIFIED_TIMEZONE',
247257
'EFI_RUNTIME_SERVICES',
248258
'EFI_BOOT_SERVICES',
249259
'EFI_CONFIGURATION_TABLE',

qiling/os/uefi/rt.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,45 @@
33
# Cross Platform and Multi Architecture Advanced Binary Emulation Framework
44
#
55

6+
import time
7+
68
from qiling import Qiling
79
from qiling.os.const import *
810
from .const import *
911
from .utils import *
1012
from .fncc import *
1113
from .ProcessorBind import *
14+
from .UefiBaseType import EFI_TIME
1215
from .UefiSpec import *
1316

1417
@dxeapi(params={
1518
"Time" : POINTER, # OUT PTR(EFI_TIME)
1619
"Capabilities" : POINTER # OUT PTR(EFI_TIME_CAPABILITIES)
1720
})
1821
def hook_GetTime(ql: Qiling, address: int, params):
22+
Time = params['Time']
23+
24+
if not Time:
25+
return EFI_INVALID_PARAMETER
26+
27+
localtime = time.localtime()
28+
29+
efitime = EFI_TIME()
30+
efitime.Year = localtime.tm_year
31+
efitime.Month = localtime.tm_mon
32+
efitime.Day = localtime.tm_mday
33+
efitime.Hour = localtime.tm_hour
34+
efitime.Minute = localtime.tm_min
35+
efitime.Second = localtime.tm_sec
36+
efitime.Nanosecond = 0
37+
38+
# tz and dst settings are stored in the "RtcTimeSettings" nvram variable.
39+
# we just use the default settings instead
40+
efitime.TimeZone = EFI_UNSPECIFIED_TIMEZONE
41+
efitime.Daylight = 0
42+
43+
efitime.saveTo(ql, Time)
44+
1945
return EFI_SUCCESS
2046

2147
@dxeapi(params={

0 commit comments

Comments
 (0)