flat assembler
Message board for the users of flat assembler.
  
|  Index
      > Windows > How to get System time,etc in FASM | 
| Author | 
 | 
| logic 28 Oct 2003, 15:26 I want get the Current system dat,time in FASM.
 Also how cani get the process ID of particular process Sandy | |||
| 
 | 
| CeeBee 29 Oct 2003, 02:45 Hi Logic, this code works for me: ;***------------model----------------------------------------------*** format PE console entry Main include '%include%\WIN32A.INC' ;***------------end model------------------------------------------*** _TITLE equ "Local Time" _NAME equ "LocTime" _VERSION equ "1.0" _VERSIONTEXT equ _VERSION Cr = 0x0D Lf = 0x0A ;***------------code-----------------------------------------------*** section '.code' code readable executable Main: stdcall [GetStdHandle], STD_OUTPUT_HANDLE mov [StdOut], eax cmp eax, INVALID_HANDLE_VALUE jz Exit Get_Time: stdcall [GetLocalTime], Time call Format_Time Write: stdcall [WriteFile], [StdOut], Msg, Msg._size, Msg.Len, 0 Exit: stdcall [ExitProcess], 0 ;***-------------------------[Subroutine]--------------------------*** Format_Time: mov ax, [Time.wDay] mov edi, Msg.Date_S + 1 call .ascii mov ax, [Time.wMonth] mov edi, Msg.Date_S + 4 call .ascii mov ax, [Time.wYear] mov edi, Msg.Date_S + 9 call .ascii .wHour: mov ax, [Time.wHour] mov edi, Msg.Time_S + 1 call .ascii mov ax, [Time.wMinute] mov edi, Msg.Time_S + 4 call .ascii mov ax, [Time.wSecond] mov edi, Msg.Time_S + 7 call .ascii ret .ascii: std cmp ax, 10 jl .onex10 and ah, ah jz .twox16 mov bh, 10 div bh or ah, 0x30 mov [edi], ah dec edi .twox16: aam or al, 0x30 stosb mov al, ah cmp ah, 9 jg .twox16 .onex10: or al, 0x30 stosb cld ret ;***------------end code-------------------------------------------*** ;***------------data-----------------------------------------------*** section '.data' data readable writeable StdIn dd 0 StdOut dd 0 Msg: .Date_S db '00.00.0000' db '-' .Time_S db '00:00:00' Msg._size = $ - Msg Msg.Len dd 0 Time SYSTEMTIME ;***----------------------[Import Table / IAT]---------------------*** section '.idata' import data readable writeable library kernel, 'KERNEL32.DLL' import kernel,\ GetModuleHandle, 'GetModuleHandleA',\ GetLocalTime, 'GetLocalTime',\ GetStdHandle, 'GetStdHandle',\ WriteFile, 'WriteFile',\ CloseHandle, 'CloseHandle',\ ExitProcess, 'ExitProcess' ;***------------end data-------------------------------------------*** Cheers, Carsten | |||
| 
 | 
| eet_1024 30 Oct 2003, 00:58 Hey, I recognize that code. Glad that you're getting some use out of it | |||
| 
 | 
| semiono 11 Apr 2009, 07:02 how could i SetSystemTime!? set to like 0101200100000000 Code: ; why not work!? include '%fasm%\win32ax.inc' section '.code' code readable executable start: invoke SetSystemTime,lpSystemTime invoke ExitProcess,0 section '.data' data readable writeable lpSystemTime SYSTEMTIME 1,1,1,1,1,1,1,1 data import library kernel32,'KERNEL32.DLL' import kernel32,ExitProcess,'ExitProcess',\ SetSystemTime,'SetSystemTime' end data | |||
| 
 | 
| revolution 11 Apr 2009, 07:08 From the Win32 FM     Quote: typedef struct _SYSTEMTIME { // st semiono wrote: set to like 0101200100000000 Code: lpSystemTime SYSTEMTIME 2001,1,1,1,0,0,0,0 | |||
| 
 | 
| semiono 11 Apr 2009, 07:19 really work it now!
 das ist fantastisch! - it's only this 1,1,1,1,1,1,1,1 synops problem!? thanks!!! cool! I think about this before "Remarks: The SetLocalTime function enables the SE_SYSTEMTIME_NAME privilege before changing the local time" It's sure? Why need? Last edited by semiono on 11 Apr 2009, 07:24; edited 1 time in total | |||
| 
 | 
| revolution 11 Apr 2009, 07:23 Remember that in later versions of Windows, setting the time requires SeSystemtimePrivilege. You may have to enable this privilege before you code can successfully set the time. | |||
| 
 | 
| semiono 11 Apr 2009, 07:26 hm... how api get it?
 invoke SetSystemTime,lpSystemTime there is not fields to put an privilegies a signature Privileges very big part of msdn for newbie as i'm Last edited by semiono on 11 Apr 2009, 07:30; edited 1 time in total | |||
| 
 | 
| revolution 11 Apr 2009, 07:30 Call this first.     Code: struc LUID_AND_ATTRIBUTES { .Luid dq ? .Attributes dd ? } TOKEN_ADJUST_PRIVILEGES =0x0020 SE_PRIVILEGE_ENABLED =2 .data hToken dd ? tokens dd ? luid LUID_AND_ATTRIBUTES .code get_time_privileges: invoke GetCurrentProcess invoke OpenProcessToken,eax,TOKEN_ADJUST_PRIVILEGES,addr hToken test eax,eax jz .proces_token_failure invoke LookupPrivilegeValue,0,'SeSystemtimePrivilege',addr luid.Luid test eax,eax jz .lookup_privilege_failure mov [tokens],1 mov [luid.Attributes],SE_PRIVILEGE_ENABLED invoke AdjustTokenPrivileges,[hToken],0,addr tokens,0,0,0 test eax,eax jz .adjust_privileges_failure xor eax,eax ret .proces_token_failure: mov eax,-1 ret .lookup_privilege_failure: mov eax,-2 ret .adjust_privileges_failure: mov eax,-3 ret | |||
| 
 | 
| semiono 11 Apr 2009, 07:32 Oh! Thanks!
 I save this great example for me! OK! Cool! | |||
| 
 | 
| < Last Thread | Next Thread > | 
| Forum Rules: 
 | 
Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.