News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

Uncle Remus Tales

Started by Mikl__, May 26, 2017, 08:43:47 PM

Previous topic - Next topic

TWell

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\.wmv]
@="WMP11.AssocFile.WMV"
"Content Type"="video/x-ms-wmv"
"PerceivedType"="video"

[HKEY_CLASSES_ROOT\.wmv\OpenWithProgids]
"WMP11.AssocFile.WMV"=hex(0):

Mikl__

hi, TWell and caballero!
you haveHKEY_CLASSES_ROOT\WMP11.AssocFile.WMV\shell\Play\command\"%ProgramFiles(x86)%\Windows Media Player\wmplayer.exe" /prefetch:7 /Play "%L"but tut_14-04.exe not runs?

TWell

crash at 0040037A, Exception: Access violation
   invoke ReadFile,eax,edi,100h

Mikl__

TWell
WndProc proc hWnd:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM
local progStartInfo:STARTUPINFO
local hKey:qword
local lpcbData:dword
local hFile:qword
local szBuff[MAX_PATH*4]:byte
local old_rdi:qword
local old_rsi:qword

mov old_rdi,rdi
mov old_rsi,rsi
        . . . .
wmCREATE: . . .
lea edx,szBuff
invoke ReadFile,eax,,100h
        . . . .
wmBYE:  mov rdi,old_rdi
mov rsi,old_rsi
leave
retn

Mikl__

asm-file; GUI #
include win64a.inc
include advapi32.inc
includelib advapi32.lib

MI_PROCESS_CREATE equ 0
MI_PROCESS_TERMINATE equ 1
MI_EXIT equ 2
IDR_MAINMENU equ 30
WM_FINISH equ WM_USER+100h
MAX_KEY_LENGTH equ 255
MAX_VALUE_NAME equ 16383
.code
WinMain proc
local msg:MSG

      xor ebx,ebx
mov edi,offset ClassName
mov esi,IMAGE_BASE
mov ecx,offset FileName
invoke LoadCursorFromFile
push rax ;hIconSm
push rdi ;lpszClassName
push IDR_MAINMENU;lpszMenuName
push COLOR_WINDOW;hbrBackground
push 10003h ;hCursor
push rax ;hIcon
push rsi ;hInstance
push rbx ;cbClsExtra & cbWndExtra
pushaddr WndProc;lpfnWndProc
push sizeof WNDCLASSEX;cbSize & style
invoke RegisterClassEx,esp ;addr WNDCLASSEX
push rbx
push rsi ;rsi=400000h
shl esi,9 ;rsi=CW_USEDEFAULT
push rbx
push rbx
push 200
push 300
push rsi
push rsi
sub esp,20h
    invoke CreateWindowEx,WS_EX_CLIENTEDGE,edi,edi,WS_OVERLAPPEDWINDOW or WS_VISIBLE
invoke GetMenu,eax
mov hMenu,rax
    lea edi,msg
@@:    invoke GetMessage,edi,0,0,0
invoke DispatchMessage,edi
      jmp @b
WinMain endp

WndProc proc hWnd:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM
local progStartInfo:STARTUPINFO
local hKey:qword
local lpcbData:dword
local lpType:dword
local hFile:qword
local szBuff[MAX_PATH*4]:byte
local old_rdi:qword
local old_rsi:qword

mov hWnd,rcx
mov wParam,r8
mov lParam,r9
mov old_rdi,rdi
        mov old_rsi,rsi

cmp  edx,WM_DESTROY
je   wmDESTROY
cmp  edx,WM_CREATE
je   wmCREATE
cmp  edx,WM_COMMAND
je   wmCOMMAND
cmp  edx,WM_INITMENUPOPUP
je   wmINITMENUPOPUP
cmp  edx,WM_FINISH
je   TERMINATE
cmp  edx,WM_TIMER
je   wmTIMER
leave
jmp DefWindowProc

wmDESTROY:invoke GetExitCodeProcess,processInfo.hProcess,esi;proExitCode
cmp dword ptr proExitCode,STILL_ACTIVE
jne @f
invoke TerminateProcess,processInfo.hProcess,0
@@: invoke CloseHandle,processInfo.hProcess
mov processInfo.hProcess,rbx
invoke ExitProcess,NULL
wmCREATE:
;get the length of playing a wmv-file
mov [rsp+30h],rbx ;hTemplateFile
mov qword ptr [rsp+28h],FILE_ATTRIBUTE_ARCHIVE ;dwFlagsAndAttributes
mov qword ptr [rsp+20h],OPEN_EXISTING ;dwCreationDisposition
mov ecx,offset FileName1+1    ;lpFileName
invoke CreateFile,,GENERIC_READ,\    ;dwDesiredAccess
FILE_SHARE_READ or FILE_SHARE_WRITE,\;dwShareMode
0 ;lpSecurityAttributes
mov hFile,rax;handle to file
mov [rsp+20h],rbx
lea r9d,lpcbData
lea edi,szBuff
invoke ReadFile,eax,edi,100h
invoke CloseHandle,hFile
mov rax,qword ptr szBuff[66h];duration in 100 nSec
;Duration in 100nSec-units is divided by 10000 and get in duration in 1mSec-units
mov edx,3518437209;"magic number"
mul edx
shr edx,13
mov duration,rdx;in mSec
;----------------------------------------------------
;Open the section HKEY_CLASSES_ROOT\.wmv\OpenWithProgids
mov edx,offset aWmv1
invoke RegOpenKeyEx,HKEY_CLASSES_ROOT,,0,KEY_READ,&hKey
        or eax,eax
jnz bad0
xor esi,esi
; inc esi
@@:     mov lpcbData,MAX_VALUE_NAME
invoke RegEnumValue,hKey,esi,edi,&lpcbData,NULL,&lpType,NULL,NULL
;HKEY hKey, // A handle to an open registry key
;DWORD dwIndex,=esi // The index of the value to be retrieved
;LPTSTR lpValueName,edi=&szBuff // A pointer to a buffer that receives the name of the value as a null-terminated string
;LPDWORD lpcbValueName,=&lpcbData // A pointer to a variable that specifies the size of the buffer pointed to by the lpValueName parameter, in characters
;LPDWORD lpReserved,=0 // This parameter is reserved and must be NULL.
;LPDWORD lpType,=&lpType // A pointer to a variable that receives a code indicating the type of data stored in the specified value
;LPBYTE lpData,=0 // A pointer to a buffer that receives the data for the value entry
;LPDWORD lpcbData,=&lpcbData // A pointer to a variable that specifies the size of the buffer pointed to by the lpData parameter, in bytes
or eax,eax
jnz bad1;Until we get all the keys HKEY_CLASSES_ROOT\.wmv\OpenWithProgids
;Looking for a key with an end on .wmv
        cmp lpcbData,5;The string is longer than ".wmv" ?
jb a1; To the next line
mov eax,edi
add eax,lpcbData;Go to the end of the line
mov eax,[rax-4]
or eax,20202000h;We give an extension to the lower case
cmp eax,dword ptr aWmv;это ".wmv" ?
jz @f
a1: inc esi
jmp @b
bad0:   invoke MessageBox,0,&error0,&ClassName,MB_OK
jmp wmDESTROY
bad1:;Closed the section HKEY_CLASSES_ROOT\.wmv\OpenWithProgids
invoke RegCloseKey,hKey
invoke MessageBox,0,&error1,&ClassName,MB_OK
jmp wmDESTROY
@@:;Closed the section HKEY_CLASSES_ROOT\.wmv\OpenWithProgids
invoke RegCloseKey,hKey
;Get the name mplayerc.wmv or WMP11.AssocFile.WMV
;Make of it HKEY_CLASSES_ROOT\mplayerc.wmv\shell
;or HKEY_CLASSES_ROOT\WMP11.AssocFile.WMV\shell
add edi,lpcbData
cmp lpType,REG_SZ
jne @f
dec edi
@@: mov dword ptr [rdi],'ehs\'
mov dword ptr [rdi+4],'ll'
lea edx,szBuff
invoke RegOpenKeyEx,HKEY_CLASSES_ROOT,,0,KEY_READ,&hKey
;Read the meaning HKEY_CLASSES_ROOT\mplayerc.wmv\shell = open
;or        HKEY_CLASSES_ROOT\WMP11.AssocFile.WMV\shell = Play
        lea eax,lpcbData
mov [rsp+28h],rax
add edi,7;Length of string "\shell\"
mov [rsp+20h],rdi
mov lpcbData,MAX_PATH
invoke RegQueryValueEx,hKey,0,0,,edi,&lpcbData
;Closed the section HKEY_CLASSES_ROOT\mplayerc.wmv\shell
;   or  HKEY_CLASSES_ROOT\WMP11.AssocFile.WMV\shell
invoke RegCloseKey,hKey
;Open the section HKEY_CLASSES_ROOT\mplayerc.wmv\shell\open\command
;or       HKEY_CLASSES_ROOT\WMP11.AssocFile.WMV\shell\play\command
or word ptr [rdi-1],605Ch;"\"+ lower case
mov rax,'dnammoc\'
mov [rdi+4],rax
mov [rdi+12],rbx
invoke RegOpenKeyEx,HKEY_CLASSES_ROOT,&szBuff,0,KEY_READ,&hKey
;Read the meaning HKEY_CLASSES_ROOT\mplayerc.wmv\shell\open\command
;"C:\Program Files (x86)\Combined Community Codec Pack\MPC\mpc-hc.exe" "%1"
;     or HKEY_CLASSES_ROOT\WMP11.AssocFile.WMV\shell\play\command
;"%ProgramFiles(x86)%\Windows Media Player\wmplayer.exe" /prefetch:7 /Play "%L"
mov lpcbData,MAX_PATH
lea r9d,lpType
invoke RegQueryValueEx,hKey,0,0,,&szBuff,&lpcbData
;Closed the section HKEY_CLASSES_ROOT\mplayerc.wmv\shell\open\command
;    or HKEY_CLASSES_ROOT\WMP11.AssocFile.WMV\shell\play\command
invoke RegCloseKey,hKey
lea edi,szBuff
add edi,lpcbData
sub edi,4
invoke GetCurrentDirectory,MAX_PATH,edi
lea edi,[rdi+rax]
mov aWmv[4],'"'
mov esi,offset FileName1
mov ecx,sizeof FileName1+6
rep movsb
lea ecx,szBuff
mov edx,offset szBuff1
invoke ExpandEnvironmentStrings,,,MAX_PATH
jmp wmBYE
wmINITMENUPOPUP:mov edx,offset proExitCode
invoke GetExitCodeProcess,processInfo.hProcess
or eax,eax
jz @f;GetExitCodeProcess_TRUE
cmp dword ptr proExitCode,STILL_ACTIVE ;cmp proExitCode,STILL_ACTIVE
jne @f ;     GetExitCodeProcess_STILL_ACTIVE
invoke EnableMenuItem,hMenu,MI_PROCESS_CREATE,MF_GRAYED
xor r8,r8; mov r8d,MF_ENABLED=0
jmp @0
@@: invoke EnableMenuItem,hMenu,MI_PROCESS_CREATE,MF_ENABLED
mov r8d,MF_GRAYED
@0:    invoke EnableMenuItem,hMenu,MI_PROCESS_TERMINATE
jmp wmBYE
wmCOMMAND:movzx eax,word ptr wParam
or r9,r9 ;cmp lParam,0
jnz wmBYE
cmp rax,MI_EXIT
ja wmBYE
jmp  [menu_handlers+rax*8]
PROCESS_CREATE:cmp processInfo.hProcess,rbx
je pi_hProcess_IS_0
invoke CloseHandle,processInfo.hProcess
mov processInfo.hProcess,rbx
pi_hProcess_IS_0:lea esi,progStartInfo
invoke GetStartupInfo,esi
invoke CreateProcess,0,&szBuff1,\
0,\;process security attributes
0,\;primary thread security attributes
0,\;handles are inherited
NORMAL_PRIORITY_CLASS,\;creation flags
0,\;use parent's environment
0,\;use parent's current directory
rsi,\;STARTUPINFO pointer
&processInfo ;receives PROCESS_INFORMATION
invoke CloseHandle,processInfo.hThread
invoke SetTimer,hWnd,1,duration,0
jmp wmBYE
TERMINATE:mov edx,offset proExitCode
invoke GetExitCodeProcess,processInfo.hProcess
cmp dword ptr proExitCode,STILL_ACTIVE
jne proExitCode_NOT_STILL_ACTIVE;a4;
invoke TerminateProcess,processInfo.hProcess,0
proExitCode_NOT_STILL_ACTIVE:
invoke CloseHandle,processInfo.hProcess
mov processInfo.hProcess,rbx;0
invoke PostMessage,hWnd,WM_INITMENUPOPUP,NULL,NULL
invoke KillTimer,hWnd,1
jmp wmBYE
wmTIMER:invoke PostMessage,,WM_FINISH,0,0
jmp wmBYE
EXIT: invoke DestroyWindow
wmBYE:  mov rdi,old_rdi
        mov rsi,old_rsi
leave
retn
menu_handlers dq PROCESS_CREATE, TERMINATE, EXIT
WndProc endp
;---------------------------------------
.data
ClassName       db 'Uncle Remus tales:#14 Process',0
hMenu dq ?
proExitCode dq ?;process exit code
FileName db "..\Images\br_Rabbit3.cur",0
FileName1 db '\movie3'
aWmv db '.wmv',0,0
aWmv1           db '.wmv\OpenWithProgids',0
processInfo PROCESS_INFORMATION <>
szBuff1 db MAX_PATH dup(?)
duration dq ?
error0 db "No section HKEY_CLASSES_ROOT\.wmv\OpenWithProgids",0
error1 db "Did not find the application that plays the wmv-files",0
end
rc-file#define MI_PROCESS_CREATE 0
#define MI_PROCESS_TERMINATE 1
#define MI_EXIT 2

#define IDR_MAINMENU 30

IDR_MAINMENU MENU
{
POPUP "&Process"
        {
         MENUITEM "&Create Process",MI_PROCESS_CREATE
         MENUITEM "&Terminate Process",MI_PROCESS_TERMINATE,GRAYED
         MENUITEM SEPARATOR
         MENUITEM "E&xit",MI_EXIT
        }
}
movie3.wmv

jj2007

lea eax,lpcbData

You rely on zero-extension, right?

Mikl__

Buona sera, signore jj2007!
The program doesn't play the wmv-file again?

jj2007

Добрый вечер, Майкл!

It plays, sure. I just wonder if your uses of 32-bit registers for pointers are safe. Is the stack guaranteed to be in 32-bit land?
        lea eax,lpcbData
mov [rsp+28h],rax
add edi,7;Length of string "\shell\"
mov [rsp+20h],rdi

Mikl__

The use of 32-bit registers with their zero extension in 64-bit and 32-bit addresses with /LARGEADDRESSAWARE:NO is just a way to make the tiny size program I create my exe-/dll-/sys-files using bat-file cls
set masm64_path=c:\masm64\
set filename=%~n1

call :read_settings %filename%
@echo %kind_of_file%
goto %kind_of_file%
:GUI
if exist %filename%.exe del %filename%.exe
if exist %filename%.obj del %filename%.obj
if exist errors.txt del errors.txt
%masm64_path%bin\ml64 /Cp /c /I"%masm64_path%Include" %filename%.asm >> errors.txt
if errorlevel 1 exit
if exist %1.rc (
%masm64_path%\bin\RC /r /i"%masm64_path%\Include" %filename%.rc >> errors.txt
%masm64_path%bin\link /SUBSYSTEM:WINDOWS /LIBPATH:"%masm64_path%Lib" ^
/LARGEADDRESSAWARE:NO /BASE:0x400000 /STUB:%masm64_path%bin\stubby.exe ^
/SECTION:.text,W /ALIGN:16 /entry:WinMain /MERGE:.rdata=.text ^
/fixed /nocoffgrpinfo %filename%.obj %filename%.res >> errors.txt
) else (
%masm64_path%bin\link /SUBSYSTEM:WINDOWS /LIBPATH:"%masm64_path%Lib" ^
/LARGEADDRESSAWARE:NO /BASE:0x400000 /STUB:%masm64_path%bin\stubby.exe ^
/SECTION:.text,W /ALIGN:16 /entry:WinMain /MERGE:.rdata=.text ^
/fixed /nocoffgrpinfo %filename%.obj >> errors.txt
)
if errorlevel 1 exit
if exist %1.res del %1.res
del %filename%.obj
del errors.txt
exit
:DLL
if exist %filename%.dll del %filename%.dll
%masm64_path%bin\ml64 /c /Cp /I %masm64_path%include %filename%.asm >> errors.txt
if errorlevel 1 exit
if exist %1.rc (
%masm64_path%bin\RC /r  %filename%.rc >> errors.txt
if errorlevel 1 exit
%masm64_path%bin\link /SUBSYSTEM:WINDOWS /LIBPATH:%masm64_path%lib ^
/ENTRY:DllMain /DLL /DLL /section:.bss,S /stub:%masm64_path%bin\stubby.exe  ^
%filename%.obj %filename%.res /DEF:%filename%.def >> errors.txt
) else (
%masm64_path%bin\link /SUBSYSTEM:WINDOWS /LIBPATH:%masm64_path%lib ^
/ENTRY:DllMain /DLL /DLL /section:.bss,S /stub:%masm64_path%bin\stubby.exe  ^
%filename%.obj /DEF:%filename%.def >> errors.txt
)
if errorlevel 1 exit
if exist %1.res del %1.res
del %filename%.obj
del %filename%.exp
del errors.txt
exit
:read_settings
for /f "eol=# tokens=2-3" %%A in (%filename%.asm) do (
set kind_of_file=%%A
if %%B == # exit /b )
exit /b
jj2007,
Do You live in Italy and try not to use Italian?

jj2007

OK, so you need the linker option. The result will be a bit like x32 ABI :biggrin:

Quote from: Mikl__ on July 13, 2017, 11:03:16 PMDo You live in Italy and try not to use Italian?

Yes, I live here, and use 4 languages every day, including Italian, of course 8)

Mikl__

In my programs there is no need to use 48- or 64-bit addressing.
I taught myself Italian. Then there were no Google-translators. I just do not have enough practice.

jj2007

C'è un solo modo valido per imparare l'italiano: praticarlo con una bella italiana :biggrin:

Mikl__

#57
imparare qualsiasi lingua è utile con una bella interprete sul cuscino

Mikl__

#58
Quote14.zip (7.1 kB - downloaded 64 times.)
one is jj2007 he has workig program, I'm interested - 63 men have workig program or they have unworking program?

Mikl__

It looks like some robot trains in downloading a file. Yesterday there were 64 downloads, today 128 and no comments about the program