|
|
本帖最后由 Bluebells 于 2026-10-18 19:55 编辑
看到此版区某"原创" 重置系统安装日期为当前时间 的帖子, 发现有不少人感兴趣, 故尝试用 PECMD 调用 winapi 编写了一个
- _SUB GetWindowsInstallDate
- TEAM ENVI-ret %~1=Unknow| ENVI &samDesired=0x20019| ENVI-ptr &phKey=0
- FIND $%&bX64%=1,CALC #&samDesired = %&samDesired% | 0x0100
- CALL $--qd --ret:&ret Advapi32.dll,RegOpenKeyExW,#0x80000002,$SOFTWARE\Microsoft\Windows NT\CurrentVersion,#0,#%&samDesired%,*&phKey
- IFEX $%&ret%=0,
- {
- ENVI?ptr &phKey=&hKey
- TEAM ENVI-int &pType=0| ENVI-int &pSize=0
- CALL $--qd --ret:&ret Advapi32.dll,RegQueryValueExW,#%&hKey%,$InstallDate,#0,*&pType,#0,*&pSize
- IFEX $%&ret%=0,
- {
- ENVI?int &pType=&Type
- IFEX $%&Type%=4,
- {
- ENVI-int &pData=0
- CALL $--qd --ret:&ret Advapi32.dll,RegQueryValueExW,#%&hKey%,$InstallDate,#0,*&pType,*&pData,*&pSize
- IFEX $%&ret%=0,
- {
- ENVI?int &pData=&Data
- ENVI$# &pSystemTime=*8 0
- CALL $--qd --ret:&ret ntdll.dll,RtlSecondsSince1970ToTime,#%&Data%,*&pSystemTime
- IFEX $%&ret%<>0,
- {
- ENVI$# &pLocalTime=*8 0
- CALL $--qd --ret:&ret ntdll.dll,RtlSystemTimeToLocalTime,*&pSystemTime,*&pLocalTime
- IFEX $%&ret%=0,
- {
- ENVI$# &pTimeFields=*16 0
- CALL $--qd ntdll.dll,RtlTimeToTimeFields,*&pLocalTime,*&pTimeFields
- TEAM ENVI?short &pTimeFields=&Year:0| ENVI?short &pTimeFields=&Month:2| ENVI?short &pTimeFields=&Day:4
- TEAM CALC -base=10 #&Year = %&&Year%| CALC -base=10 #&Month = %&&Month%| CALC -base=10 #&Day = %&&Day%
- TEAM ENVI?short &pTimeFields=&Hour:6| ENVI?short &pTimeFields=&Minute:8| ENVI?short &pTimeFields=&Second:10
- TEAM CALC -base=10 #&Hour = %&&Hour%| CALC -base=10 #&Minute = %&&Minute%| CALC -base=10 #&Second = %&&Second%
- ENVI-ret %~1=%&Year%/%&Month%/%&Day%, %&Hour%:%&Minute%:%&Second%
- }
- }
- }
- }
- }
- CALL $--qd --ret:&ret Advapi32.dll,RegCloseKey,#%&hKey%
- }
- _END
- _SUB SetWindowsInstallDate
- TEAM ENVI-ret %~1=0| ENVI$# &pSystemTime=*8 0
- CALL $--qd --ret:&ret ntdll.dll,NtQuerySystemTime,*&pSystemTime
- IFEX $%&ret%=0,
- {
- ENVI-int &pElapsedSeconds=0
- CALL $--qd --ret:&ret ntdll.dll,RtlTimeToSecondsSince1970,*&pSystemTime,*&pElapsedSeconds
- IFEX $%&ret%<>0,
- {
- TEAM ENVI &samDesired=0x20006| ENVI-ptr &phKey=0
- FIND $%&bX64%=1,CALC #&samDesired = %&samDesired% | 0x0100
- CALL $--qd --ret:&ret Advapi32.dll,RegCreateKeyExW,#0x80000002,$SOFTWARE\Microsoft\Windows NT\CurrentVersion,#0,#0,#0,#%&samDesired%,#0,*&phKey,#0
- IFEX $%&ret%=0,
- {
- ENVI?ptr &phKey=&hKey
- CALL $--qd --ret:&ret Advapi32.dll,RegSetValueExW,#%&hKey%,$InstallDate,#0,#0x4,*&pElapsedSeconds,#4
- IFEX $%&ret%=0,ENVI-ret %~1=1
- CALL $--qd --ret:&ret Advapi32.dll,RegCloseKey,#%&hKey%
- }
- }
- }
- _END
- ;示例
- GetWindowsInstallDate &RetVal
- MESS 系统初始安装日期: %&RetVal%
- SetWindowsInstallDate &RetVal
- FIND $%&RetVal%=1,MESS 成功设置系统安装日期为当前时间!! MESS 设置系统安装日期为当前时间失败!
复制代码 备注:
1. 使用 PECMD 自带的注册表读写命令 REGI 可以节省很多代码, 但我不清楚 PECMD 自带命令有没有执行返回值, 因此没有采用 REGI 命令
2. 上述 PECMD 代码好像很复杂, 如果将它转译成其它编程语言代码会发现其实代码异常简单
3. 在测试"设置Windows安装日期(SetWindowsInstallDate)"前, 建议先备份注册表项 [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion] 的值 InstallDate 的数据
|
评分
-
查看全部评分
|