News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

GetCl help

Started by Magnum, November 18, 2011, 05:01:13 PM

Previous topic - Next topic

Magnum

I would like to modify this to enable it to take a Command line argument for the time before it hangs up.

I looked at some examples that use GetCl but I don't know where to begin.

What are the criteria that determine whether some code can be compiled as Console Build All ?



.DATA

.data?

l_RASCONN RASCONN 0FFh dup ({})
l_Buffer_Size dd   ?
l_Conn_Count  dd   ?

.CODE

Start:

mov l_RASCONN.dwSize, sizeof RASCONN + 1
mov l_Buffer_Size, sizeof l_RASCONN

; list all active RAS connections
invoke RasEnumConnections, addr l_RASCONN, addr l_Buffer_Size, addr l_Conn_Count

; terminate the Remote Access Connection

invoke RasHangUp, l_RASCONN.hrasconn

invoke Sleep,2000 ; give the system enuf time to end the connection
                  ; don't want to leave the port in an inconsistent state.

invoke ExitProcess, 0

END Start
Have a great day,
                         Andy

ragdog

hi

Can you send the compiling this source you *.bat or commandline settings for ml and link?
or look into and change it

LINK.EXE /SUBSYSTEM:CONSOLE

Greets

Magnum

Ragdog,

I have no problem in compiling the program.

I need help in making it accept a command line argument of time.

Ex.

Hangup.exe 30

The program would wait and then run after 30 minutes.
Have a great day,
                         Andy

ragdog

Search in Masm32/Examples/ it have 55 examples with GetCl
And now must you coding a Timer

example can you found here
http://win32assembly.online.fr/source.html

Time ShutDown 1.0

As example:


.elseif uMsg == WM_TIMER

                invoke GetCurrentTime

                    mov ax, MinSetting
                    .if ax == CurrentMin  ;CurrentMin if the 30 from the getcl
                       ;RasHangUp

It is a example you must it figure out

qWord

Quote from: Magnum on November 18, 2011, 05:21:03 PMHangup.exe 30
mov esi,cmd$(1)
mov esi,a2ud(esi)
imul esi,DWORD ptr [esi],1000
invoke Sleep,esi ; sleep N seconds
FPU in a trice: SmplMath
It's that simple!

Magnum

I am trying to make a simple timer to do something when the time is up.

I was using .while but it wasn't working.

Instead, this is an infinite loop.  :bg


invoke GetTickCount
          mov var2, eax
          add var2, 30000  ; milliseconds delay 30 seconds

      again:   

         .if eax < var2
           invoke GetTickCount
           jmp again
         .else
         
          exit
         
         .endif

Have a great day,
                         Andy

Magnum

Quote from: ragdog on November 18, 2011, 05:35:45 PM
Search in Masm32/Examples/ it have 55 examples with GetCl
And now must you coding a Timer

example can you found here
http://win32assembly.online.fr/source.html

Time ShutDown 1.0


Ragdog,

The Time Shutdown program there won't compile.

The executable doesn't work either on my XP Sp3 system.

It starts O.K. when I set it to shutdown in 2 minutes, but it never shuts down. ??

Many errors with windows.inc.
I guess the current windows.inc is not compatible with it.

I would like to get it working. :-)


Have a great day,
                         Andy

Magnum

Making a lot of progress.

When I use the first 4 lines of code by itself, it runs fine.
Got errors when combined with other code to terminate the phone connection.

C:\masm32\SOURCE\Hangup1.asm(36) : error A2006:undefined symbol : GetCL
cmd$(8): Macro Called From
  C:\masm32\SOURCE\Hangup1.asm(36): Main Line Code
C:\masm32\SOURCE\Hangup1.asm(37) : error A2006:undefined symbol : crt_sscanf
a2ud(9): Macro Called From
  C:\masm32\SOURCE\Hangup1.asm(37): Main Line Code


Start:

; from Qword
; hangup.exe 20 would delay for 20 seconds

mov esi,cmd$(1)
mov esi,a2ud(esi)
imul esi,DWORD ptr [esi],1000 ; I think it multiplies ms by 1000 to get seconds
invoke Sleep,esi ; sleep N seconds

mov l_RASCONN.dwSize, sizeof RASCONN + 1
mov l_Buffer_Size, sizeof l_RASCONN
Have a great day,
                         Andy

dedndave

hi Andy
includelib \masm32\lib\USER32.LIB
includelib \masm32\lib\KERNEL32.LIB
includelib \masm32\lib\GDI32.LIB
includelib \masm32\lib\ADVAPI32.LIB
includelib \masm32\lib\SHELL32.LIB

include    \masm32\include\USER32.INC
include    \masm32\include\KERNEL32.INC
include    \masm32\include\GDI32.INC
include    \masm32\include\ADVAPI32.INC
include    \masm32\include\SHELL32.INC

include    \masm32\include\WINDOWS.INC


it's usually best if windows.inc is the first one included
also - it may not make much difference, but the libs are generally added after the includes
include    \masm32\include\WINDOWS.INC
include    \masm32\include\USER32.INC
include    \masm32\include\KERNEL32.INC
include    \masm32\include\GDI32.INC
include    \masm32\include\ADVAPI32.INC
include    \masm32\include\SHELL32.INC

includelib \masm32\lib\USER32.LIB
includelib \masm32\lib\KERNEL32.LIB
includelib \masm32\lib\GDI32.LIB
includelib \masm32\lib\ADVAPI32.LIB
includelib \masm32\lib\SHELL32.LIB


even then, some things seem to be missing
i replaced the processor, model, and includes with the following and got it to assemble
; *************************************************************************
;                          - Time ShutDown v1.0 -
;
;                   Coded by [G-MaX]/Mamtasoft (C) 2002
;                     
;         Program to shutdown your computer at a specified time.
;           Program works on Win9x and WinNT/2k type Platforms.

        INCLUDE    \masm32\include\masm32rt.inc
        INCLUDE    \masm32\include\advapi32.inc
        INCLUDELIB \masm32\lib\advapi32.lib

;=================


dedndave

here is the code i use to strip the executable file name out of the command line string
        INVOKE  GetCommandLine
        mov     dx,2022h                                     ;space and double quote
        xor     ecx,ecx
        cmp     dl,[eax]
        mov     lpCmndLineFull,eax
        jz      Start2

Start0: mov     dl,dh

Start1: mov     cl,[eax]
        or      ecx,ecx
        jz      Start4

Start2: inc     eax
        cmp     cl,dl
        jnz     Start1

        cmp     dl,dh
        jnz     Start2

Start3: mov     cl,[eax]
        or      ecx,ecx
        jz      Start4

        inc     eax
        cmp     cl,dl
        jz      Start3

        dec     eax

Start4: mov     lpCmndLine,eax


when done, lpCmndLineFull points to the full command line (including the exe file name)
in some cases, the executable is surrounded by double-quotes - in some cases, it is not

lpCmndLine points to the first non-space character of the command line tail
if there is no tail, lpCmndLine will point to a null string

Magnum

Dave,

The reason the code would not compile was because
OPTION CASEMAP: NONE was missing.

I got it to compile, but on my XP Home System, the program just doesn't work.

I noticed that it uses the obselete GetCurrentTime.

Can you and anyone else who wants to test it, see if it works on your system and let me know what O.S. you are running
too ?

Have a great day,
                         Andy

Magnum

When this is run as Time.exe 20, it waits the 20 secs and then exits.

When I add it before the code that hangs up the fone, then it fails for some reason.  :dazzled:

start:

; from Qword
; time 20 would delay for 20 seconds
mov esi,cmd$(1)
mov esi,a2ud(esi)
imul esi,DWORD ptr [esi],1000 ; I think it multiplies ms by 1000 to get seconds
invoke Sleep,esi ; sleep N seconds

invoke ExitProcess,0


end start
Have a great day,
                         Andy

dedndave

QuoteOPTION CASEMAP: NONE was missing

good job Andy   :U

however, there is something else missing - that is the resource file to go with this program
IDI_ICON        equ     500
IDC_HOURS       equ     1000
IDC_MINUTES     equ     1001
IDC_SPINH       equ     1002
IDC_SPINM       equ     1003
IDC_PRGNAME     equ     1004
IDC_AUTORUN     equ     1005
IDM_TRAYMENU    equ     1200
IDM_CONFIG      equ     1201
IDM_EXIT        equ     1202
IDC_CANCEL      equ     3003
IDC_APPLY       equ     3004
IDC_STATIC      equ     -1


i don't feel good about running this code because it accesses the registry with adjusted access privileges
to perform the desired function, there should be no need of accessing the registry, at all

considering the absence of a resource file, you may be better off to start from scratch

Magnum

Here is the rsrc.rc for it.

The code is safe, it puts in a reg key to store the time for when it shuts down the computer and also puts in a RunKey if it is selected by the user.

I just would like to know why the program doesn't work, even if I can't get it to work.


// Resource file for Time ShutDown v1.0


#include <\masm32\include\resource.h>

#define IDI_ICON                        500
#define IDC_LOGO                        501
#define IDC_HOURS                       1000
#define IDC_MINUTES                     1001
#define IDC_SPINH                       1002
#define IDC_SPINM                       1003
#define IDC_PRGNAME                     1004
#define IDC_AUTORUN                     1005
#define IDM_TRAYMENU                    1200
#define IDM_CONFIG                      1201
#define IDM_EXIT                        1202
#define IDC_CANCEL                      3003
#define IDC_APPLY                       3004
#define IDC_STATIC                      -1


IDI_ICON ICON MOVEABLE PURE LOADONCALL DISCARDABLE "Icon.ico"

IDB_LOGO BITMAP  MOVEABLE PURE   "Logo.bmp"

MAINDIALOG Dialog 95, 49, 160, 74
STYLE DS_MODALFRAME | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU
CAPTION "Time ShutDown Program"
FONT 8, "MS Sans Serif"
BEGIN
End

CONFIGDIALOG DIALOGEX 44, 38, 211, 110
STYLE DS_MODALFRAME | WS_POPUP | WS_VISIBLE | WS_CAPTION
CAPTION "Time ShutDown v1.0 © 2002 eVC/[G-MaX]"
FONT 8, "MS Sans Serif"
BEGIN
    CTEXT           "- Time ShutDown v1.0 -",IDC_PRGNAME,45,6,159,9
    GROUPBOX        "Set Time:",IDC_STATIC,45,39,159,30
    RTEXT           "Hours:",IDC_STATIC,54,52,30,9
    RTEXT           "Minutes:",IDC_STATIC,123,52,30,9
    EDITTEXT        IDC_HOURS,85,49,18,11,ES_RIGHT | ES_NUMBER
    CONTROL         "Spin1",IDC_SPINH,"msctls_updown32",UDS_WRAP |
                    UDS_SETBUDDYINT | UDS_AUTOBUDDY | UDS_ARROWKEYS |
                    UDS_NOTHOUSANDS | UDS_HOTTRACK,105,49,11,12,
                    WS_EX_STATICEDGE
    EDITTEXT        IDC_MINUTES,156,49,18,11,ES_RIGHT | ES_NUMBER
    CONTROL         "Spin1",IDC_SPINM,"msctls_updown32",UDS_WRAP |
                    UDS_SETBUDDYINT | UDS_AUTOBUDDY | UDS_ARROWKEYS |
                    UDS_NOTHOUSANDS | UDS_HOTTRACK,176,49,11,12,
                    WS_EX_STATICEDGE
    CTEXT           "Created by [G-MaX]/Mamtasoft © 2002",IDC_STATIC,45,17,
                    159,9
    CTEXT           "Member of eBOLA vIRUS cREW",IDC_STATIC,45,26,159,9
    CONTROL         "  Run Time ShutDown at Windows Start",IDC_AUTORUN,
                    "Button",BS_AUTOCHECKBOX | WS_TABSTOP,56,74,148,9
    PUSHBUTTON      "&Cancel",IDC_CANCEL,68,90,40,16,0,WS_EX_STATICEDGE
    PUSHBUTTON      "&Apply",IDC_APPLY,140,90,40,16,0,WS_EX_STATICEDGE
    CONTROL         "IDB_LOGO",IDC_STATIC,"Static",SS_BITMAP |
                    SS_REALSIZEIMAGE,4,3,21,19,WS_EX_DLGMODALFRAME |
                    WS_EX_CLIENTEDGE | WS_EX_STATICEDGE
END


IDM_TRAYMENU Menu
  BEGIN
    Popup "&Tray"
      BEGIN
        MENUITEM "&Configure Program", IDM_CONFIG
        MENUITEM SEPARATOR
        MENUITEM "&Exit Time ShutDown", IDM_EXIT
      End
  End

Have a great day,
                         Andy

Magnum

This works but it needs some improvements.

Since it is a console app, it takes up my whole screen when I run it from a batch file.

Will see if there is a way of either:

Making a smaller window

OR

Finding a way to make it a GUI app.


; Cl_Hangup.asm Console APP !!
;           Syntax: Cl_Hangup <number of seconds>
;           
;         ** Requires a command line argument, otherwise program continues.

.686                                     
.model flat, stdcall                     
option casemap :none                       

include \masm32\include\windows.inc   
include \masm32\include\masm32.inc     

include \masm32\include\gdi32.inc
include \masm32\include\user32.inc
include \masm32\include\kernel32.inc
include \masm32\include\Comctl32.inc
include \masm32\include\comdlg32.inc
include \masm32\include\shell32.inc
include \masm32\include\oleaut32.inc
include \masm32\include\ole32.inc
include \masm32\include\msvcrt.inc
include \masm32\include\winmm.inc
include \masm32\include\advapi32.inc

include \masm32\include\shlwapi.inc
include \masm32\include\rasapi32.inc

include \masm32\include\dialogs.inc   
include \masm32\macros\macros.asm     
includelib \masm32\lib\masm32.lib     

includelib \masm32\lib\gdi32.lib
includelib \masm32\lib\user32.lib
includelib \masm32\lib\kernel32.lib
includelib \masm32\lib\Comctl32.lib
includelib \masm32\lib\comdlg32.lib
includelib \masm32\lib\shell32.lib
includelib \masm32\lib\oleaut32.lib
includelib \masm32\lib\ole32.lib
includelib \masm32\lib\msvcrt.lib
includelib \masm32\lib\winmm.lib
includelib \masm32\lib\advapi32.lib
includelib  \masm32\lib\rasapi32.lib
includelib  \masm32\lib\shlwapi.lib

.CONST

.DATA

.DATA?

l_RASCONN RASCONN 0FFh dup ({})
l_Buffer_Size dd   ?
l_Conn_Count  dd   ?


.CODE

WaterMark   db "SiegeWorks 2011"
%Date       db " &@Date " ; Compile date

start:

; from Qword
; Cl_Hangup 20 would delay for 20 seconds
mov esi,cmd$(1)
mov esi,a2ud(esi)     ; 4 hours = 1000 x 3600 x 4 = 14,400,000
imul esi,DWORD ptr [esi],1000 ; I think it multiplies ms by 1000 to get seconds
invoke Sleep,esi ; sleep N seconds

;-----------------------------------

mov l_RASCONN.dwSize, sizeof RASCONN + 1
mov l_Buffer_Size, sizeof l_RASCONN

; list all active RAS connections
invoke RasEnumConnections, addr l_RASCONN, addr l_Buffer_Size, addr l_Conn_Count

; terminate the Remote Access Connection

invoke RasHangUp, l_RASCONN.hrasconn

invoke Sleep,2000 ; give the system enuf time to end the connection
                  ; don't want to leave the port in an inconsistent state.


invoke ExitProcess,0


end start


Have a great day,
                         Andy