flat assembler
Message board for the users of flat assembler.

Index > Windows > How to get System time,etc in FASM

Author
Thread Post new topic Reply to topic
logic



Joined: 21 Oct 2003
Posts: 5
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
Post 28 Oct 2003, 15:26
View user's profile Send private message Reply with quote
silkodyssey



Joined: 02 Oct 2003
Posts: 198
Location: St.Vincent & the Grenadines
silkodyssey 28 Oct 2003, 17:31
You try the GetSystenTime function.

Code:
 
The GetSystemTime function retrieves the current system date and time. The system time is expressed in Coordinated Universal Time (UTC). 

VOID GetSystemTime(

    LPSYSTEMTIME lpSystemTime    // address of system time structure  
   );      
 

Parameters

lpSystemTime

Points to a SYSTEMTIME structure to receive the current system date and time. 

 

Return Values

This function does not return a value. 

See Also

GetLocalTime, GetSystemTimeAdjustment, SetSystemTime, SYSTEMTIME 
    

_________________
silkodyssey
Post 28 Oct 2003, 17:31
View user's profile Send private message MSN Messenger Reply with quote
CeeBee



Joined: 26 Sep 2003
Posts: 1
Location: Melbourne, Australia
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
Post 29 Oct 2003, 02:45
View user's profile Send private message Reply with quote
eet_1024



Joined: 22 Jul 2003
Posts: 59
eet_1024 30 Oct 2003, 00:58
Hey, I recognize that code.Razz

Glad that you're getting some use out of it
Post 30 Oct 2003, 00:58
View user's profile Send private message Reply with quote
semiono



Joined: 31 Aug 2007
Posts: 198
Location: section '.code' executable
semiono 11 Apr 2009, 07:02
Sad please, post an example for me?
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    
Post 11 Apr 2009, 07:02
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20537
Location: In your JS exploiting you and your system
revolution 11 Apr 2009, 07:08
From the Win32 FM
Quote:
typedef struct _SYSTEMTIME { // st
WORD wYear;
WORD wMonth;
WORD wDayOfWeek;
WORD wDay;
WORD wHour;
WORD wMinute;
WORD wSecond;
WORD wMilliseconds;
} SYSTEMTIME;
semiono wrote:
set to like 0101200100000000
So like this maybe?
Code:
lpSystemTime SYSTEMTIME 2001,1,1,1,0,0,0,0    
Post 11 Apr 2009, 07:08
View user's profile Send private message Visit poster's website Reply with quote
semiono



Joined: 31 Aug 2007
Posts: 198
Location: section '.code' executable
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? Smile
Why need?


Last edited by semiono on 11 Apr 2009, 07:24; edited 1 time in total
Post 11 Apr 2009, 07:19
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20537
Location: In your JS exploiting you and your system
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.
Post 11 Apr 2009, 07:23
View user's profile Send private message Visit poster's website Reply with quote
semiono



Joined: 31 Aug 2007
Posts: 198
Location: section '.code' executable
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
Post 11 Apr 2009, 07:26
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20537
Location: In your JS exploiting you and your system
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    
Post 11 Apr 2009, 07:30
View user's profile Send private message Visit poster's website Reply with quote
semiono



Joined: 31 Aug 2007
Posts: 198
Location: section '.code' executable
semiono 11 Apr 2009, 07:32
Oh! Thanks!
I save this great example for me! OK! Cool!
Post 11 Apr 2009, 07:32
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.