api - 使用win内核基础编程的GetLocalTime函数
问题描述
我正在使用基于内核的编程在 MASM32 中执行“创建一个将在早上 7:00 提醒“早上好”的程序”的活动,这意味着我需要使用 peb 结构。我已经获得了将在调用 API 时使用的 kernel32.dll 的基地址。我还得到了我要使用的 API 的地址,即 GetLocalTime。
我的问题是在最后一部分,我将调用 GetLocalTime 函数来获取时间。现在我迷失了这部分,我无法调用在 GetlocalTime 函数中很重要的 SYSTEMTIME。有什么建议吗?谢谢你!
.386
.model flat, stdcall
OPTION CASEMAP:NONE
.data
stime dd ?
wHour dw ?
.code
Main:
;getting the kernel32 base address
xor ecx, ecx
ASSUME FS:NOTHING
mov eax, fs:[ecx + 30H] ; EAX = PEB
ASSUME FS:ERROR
mov eax, [eax + 0CH] ; EAX = PEB->Ldrs
mov esi, [eax + 14H] ; ESI = PEB->Ldr.InMemOrder
lodsd ; EAX = Second module
xchg eax, esi ; EAX = ESI, ESI = EAX
lodsd ; EAX = Third(kernel32)
mov ebx, [eax + 10H] ; EBX = Base address
;finding the export table of kernel32
mov edx, [ebx + 3CH] ; EDX = DOS->e_lfanew
add edx, ebx ; EDX = PE Header
mov edx, [edx + 78H] ; EDX = Offset export table
add edx, ebx ; EDX = Export table
mov esi, [edx + 20H] ; ESI = Offset namestable
add esi, ebx ; ESI = Names table
xor ecx, ecx ; EXC = 0
;start of getlocaltime function;
;Find GetLocalTime function name
Get_Time:
inc ecx ; Increment the ordinal
lodsd ; Get name offset
add eax, ebx ; Get function name
cmp dword ptr[eax], 4C746547H ; GetL
jnz Get_Time
cmp dword ptr[eax + 4H], 6C61636FH ; ocal
jnz Get_Time
cmp dword ptr[eax + 8H], 656D6954H ; Time
jnz Get_Time
;Find the address of GetLocalTime function
mov esi, [edx + 24H] ; ESI = Offset ordinals
add esi, ebx ; ESI = Ordinals table
mov cx, [esi + ecx * 2] ; Number of function
dec ecx
mov esi, [edx + 1CH] ; Offset address table
add esi, ebx ; ESI = Address table
mov edx, [esi + ecx * 4] ; EDX = Pointer(offset)
add edx, ebx ; EDX = GetLocalTime
;Call GetLocalTime
add esp, 14H ; Cleanup stack
push offset stime ; offset of the address of hello is pushed in the stack memory
call edx ; getlocaltime nasa eax babagsak
;comparing
push wHour
cmp 00402001H.wHour, 37H
end Main
解决方案
SYSTEMTIME 只是一个 8 个字(16 位整数)的块;可以分配8个字,字段顺序参考Win32。
推荐阅读
- java - 特定的 RepaintManager 可以用于特定的 JPanel 吗?
- c# - 从 VS 创建的 .exe 文件上的文件或目录已损坏且无法读取
- node.js - 如果我们删除 www 前缀,Node/Express 中的 CORS 问题
- javascript - 推送通知错误“缺少注册”firebase 功能
- angular - 使用 Angular Universal 的选择性 SSR(服务器端渲染)
- pytorch - Pytorch - 分布式数据并行混淆
- asp.net - 使用脚本和 css 引用调用文件
- react-native - 导航到下一个屏幕时,所有以前的屏幕都会重新安装 react-navigation 5x
- python - 修复错误“numpy.ndarray”对象没有属性“convert”
- c# - hasura\firebase 的替代方案,但适用于 .net c# stack