64 bit assembler > Mikl__'s ml64 examples

Interprocess communication

(1/13) > >>

Mikl__:
Interprocess communication (IPC)
The Windows operating system provides mechanisms for facilitating communications and data sharing between applications. Collectively, the activities enabled by these mechanisms are called interprocess communications (IPC). Some forms of IPC facilitate the division of labor among several specialized processes. Other forms of IPC facilitate the division of labor among computers on a network.

Typically, applications can use IPC categorized as clients or servers. A client is an application or a process that requests a service from some other application or process. A server is an application or a process that responds to a client request. Many applications act as both a client and a server, depending on the situation.

The following IPC mechanisms are supported by Windows:
* Data Copy
* Clipboard
* Shared memory
* Memory Mapped File
* Paging File
* Mail Slots
* Named Pipes
* Dynamic Data Exchange (DDE)
* Interprocess Synchronization
* Event Pipes
* Mutexes
* Semaphores
* Windows Sockets
* OLE/ActiveX
* COM
* Distributed Component Object Model (DCOM)
* Remote Method Invocation (RMI)
* Common Object Request Broker Architecture (CORBA)
* Remote Procedure Call (RPC)
* Local Procedure Call (LPC)
* Microsoft Message Queue (MSMQ)There are show several ways to transfer data between two applications in this thread. Text string, 128x128 pictures and media data are sent.
The pictures and the wav file are in an attachment in the Images folder.
Place the sender-application with the index "s" and the reciever-application with the index "r" side by side.
* Write or edit the text in the sender-application and press the "Send Text" button.
* Press the "Send ICO" button several times.
* Press the "Send WAV" button.There are total IPC mechanisms: 19/are written: 12 now.01. WM_COPYDATA
The following example demonstrates how to send information between two applications using the WM_COPYDATA message.
The sending application displays a dialog box to the user which requests certain information. The application packages the information into a private data structure, includes a pointer to the structure in the COPYDATASTRUCT structure, and sends the information to the receiving application using the WM_COPYDATA message.
01s.asm (Server)
--- Code: ---; GUI #
include win64a.inc

ID_TXT equ 100
ID_SEND_TXT equ 101
ID_SEND_ICO equ 102
ID_SEND_WAV equ 103
IDC_DIALOG equ 200
IDC_ICON1 equ 500
IDC_IMG1 equ 104

.code
WinMain proc ;dummy:qword
enter 30h,0
mov r9d,256
mov [rbp-10h],r9
and     qword ptr [rbp-8],LR_DEFAULTCOLOR
invoke LoadImageA,IMAGE_BASE,IDC_ICON1,IMAGE_ICON;,0,0,LR_DEFAULTCOLOR
mov r9d,offset DialogProc
mov [rbp-10h],rax
invoke DialogBoxParamA,IMAGE_BASE,IDC_DIALOG,HWND_DESKTOP
invoke RtlExitUserProcess,NULL
WinMain endp

DialogProc proc hWnddlg:QWORD,uMsg:QWORD,wParam:QWORD,lParam:QWORD
local buffer:qword
local cdata:COPYDATASTRUCT
local FSize:dword
local hFile:dword
local p:qword
local szReadWrite:qword ;number of bytes actually read or write
local hResource:qword
local pResource:qword

mov hWnddlg,rcx
mov lParam,r9

cmp edx,WM_CLOSE
je wmCLOSE
cmp edx,WM_COMMAND
je wmCOMMAND
cmp edx,WM_INITDIALOG
        jne wmBYE
wmINITDIALOG:invoke GetDlgItem,,IDC_IMG1
invoke SendMessageA,eax,STM_SETIMAGE,IMAGE_ICON,lParam
jmp wmBYE
wmSEND_TXT:invoke GlobalAlloc,GPTR,256
mov buffer,rax
        mov cdata.lpData,rax
invoke  GetDlgItemTextA,hWnddlg,ID_TXT,eax,256
        or      eax,eax
        jz      wmBYE
        ; fill structure COPYDATASTRUCT
        mov     cdata.dwData,CF_TEXT
        inc     eax
        mov     cdata.cbData,eax
jmp @f
wmSEND_ICO:mov     cdata.dwData,CF_BITMAP
mov edx,p1
invoke FindResource,0,,RT_ICON; find the resource
mov hResource,rax
invoke  SizeofResource,0,eax ; get its size
mov     cdata.cbData,eax
mov FSize,eax
invoke LoadResource,0,hResource ; load the resource
invoke LockResource,eax;pResource
mov cdata.lpData,rax
mov p,rax
;-------------------------------------------------
        mov ecx,256
and qword ptr[rsp+30h],LR_DEFAULTCOLOR;LR_DEFAULTCOLOR=0
mov [rsp+20h],rcx
mov [rsp+28h],rcx
mov edx,FSize
invoke  CreateIconFromResourceEx,p,,TRUE,30000h;270376,TRUE,30000h
mov [rsp+20h],rax
invoke  SendDlgItemMessageA,hWnddlg,IDC_IMG1,STM_SETIMAGE,IMAGE_ICON
xor p1,11b
;--------------------------------------------------
jmp @f
wmSEND_WAV:mov ecx,offset wav_file
invoke CreateFile,,GENERIC_READ,FILE_SHARE_READ,0,OPEN_EXISTING,\
        FILE_ATTRIBUTE_ARCHIVE,0
        mov hFile,eax
        invoke GetFileSize,eax,0
mov FSize,eax
        mov     cdata.dwData,CF_WAVE
        mov     cdata.cbData,eax
invoke GlobalAlloc,GPTR,eax
        mov cdata.lpData,rax
lea r9d,szReadWrite
and qword ptr[rsp+20h],0
        invoke ReadFile,hFile,eax,FSize
        invoke CloseHandle,hFile
@@:mov edx,offset szWin
        invoke  FindWindowA,NULL
        or      eax,eax
        jz      wmBYE
lea r9d,cdata
mov qword ptr[rsp+20h],SMTO_ABORTIFHUNG
mov qword ptr[rsp+28h],500
and qword ptr[rsp+30h],0
invoke  SendMessageTimeoutA,eax,WM_COPYDATA,hWnddlg
jmp wmBYE
wmCOMMAND:cmp r8d,BN_CLICKED shl 16 + ID_SEND_TXT
        je      wmSEND_TXT
        cmp r8d,BN_CLICKED shl 16 + ID_SEND_ICO
        je      wmSEND_ICO
cmp r8d,BN_CLICKED shl 16 + ID_SEND_WAV
        je      wmSEND_WAV
cmp     r8d,BN_CLICKED shl 16 + IDCANCEL
        jne     wmBYE
wmCLOSE:invoke EndDialog,,0
wmBYE: xor eax,eax
leave
retn
DialogProc endp
;---------------------------------------
.data
szWin db 'WM_COPYDATA Reciever',0
wav_file db '..\Images\03.wav',0
p1 dd 1
end
--- End code ---
01s.rc
--- Code: ---#include "resource.h"
#define ID_TXT 100
#define ID_SEND_TXT 101
#define ID_SEND_ICO 102
#define ID_SEND_WAV 103
#define IDC_IMG1 104

#define IDC_DIALOG 200
#define IDC_ICON1 500

IDC_ICON1 ICON "..\\Images\\icon1.ico"
IDC_ICON2 ICON "..\\Images\\icon2.ico"

IDC_DIALOG DIALOGEX 0, 0, 212, 154
STYLE DS_MODALFRAME | DS_CENTER | WS_CAPTION | WS_MINIMIZEBOX |
WS_SYSMENU | WS_VISIBLE | WS_OVERLAPPED | DS_MODALFRAME | DS_3DLOOK
CAPTION "WM_COPYDATA Sender"
{
CONTROL "",-1,BUTTON,BS_GROUPBOX | WS_CHILD | WS_VISIBLE,2,-1,207,24
CONTROL "",IDC_IMG1,STATIC,SS_ICON | WS_CHILD | WS_VISIBLE,3,40,128,128
CONTROL "Write something and click 'Send Text'",ID_TXT,EDIT,ES_LEFT |
ES_AUTOHSCROLL|WS_CHILD|WS_VISIBLE|WS_BORDER|WS_TABSTOP,5,7,199,13
CONTROL "Send Text", ID_SEND_TXT, BUTTON, BS_DEFPUSHBUTTON | WS_CHILD |
WS_VISIBLE | WS_TABSTOP, 149, 27, 60, 15
CONTROL "Send ICO", ID_SEND_ICO, BUTTON, BS_PUSHBUTTON | WS_CHILD |
WS_VISIBLE | WS_TABSTOP, 149, 45, 60, 15
CONTROL "Send WAV", ID_SEND_WAV, BUTTON, BS_PUSHBUTTON | WS_CHILD |
WS_VISIBLE | WS_TABSTOP, 149, 65, 60, 15
CONTROL "Exit",IDCANCEL,BUTTON,BS_PUSHBUTTON | WS_CHILD | WS_VISIBLE |
WS_TABSTOP, 149, 85, 60, 15
}
--- End code ---
01r.asm (Client)
--- Code: ---; GUI #
include win64a.inc

IDC_DIALOG equ 200
ID_TXT equ 100
ID_ICON equ 102
IDC_ICON1 equ 500

.code
WinMain proc dummy:qword

        invoke  DialogBoxParam,IMAGE_BASE,IDC_DIALOG,HWND_DESKTOP,qword ptr(offset DialogProc),0
        invoke  RtlExitUserProcess,NULL
WinMain endp
DialogProc proc hWnddlg:qword,msg:qword,wParam:qword,lParam:qword
local p:qword
local FSize:dword
local lpwiocb:WAVEHDR
local hWaveOut:qword

mov hWnddlg,rcx
mov lParam,r9

cmp edx,WM_CLOSE
je wmCLOSE
cmp edx,WM_COPYDATA ; Пришло сообщение WM_COPYDATA?
je wmCOPYDATA
cmp edx,WM_COMMAND
je wmCOMMAND
        cmp edx,WM_INITDIALOG
jne wmBYE

wmINITDIALOG:;mov rcx,hWnd
; Найти окно получателя
        invoke  FindWindow,NULL,&szWin
        or      eax,eax
        jnz wmBYE
invoke MessageBox,hWnddlg,&Error1,&szAppName,MB_ICONEXCLAMATION or MB_YESNO
cmp eax,IDNO
jz      wmBYE     
invoke WinExec,&szService,SW_SHOW
jmp wmBYE
wmCOPYDATA:; Получить строку от первого приложения
; В lParam приходит указатель на структуру COPYDATASTRUCT
        mov eax,[r9+COPYDATASTRUCT.cbData]
or eax,eax; Размер данных нулевой?
        je      wmBYE; Да, пропускаем
mov FSize,eax
        mov rax,[r9+COPYDATASTRUCT.lpData]
mov p,rax
mov rax,[r9+COPYDATASTRUCT.dwData]
        cmp     eax,CF_TEXT; Это нужный тип данных?
        je COPYDATA_TEXT; Нет, пропускаем
cmp     eax,CF_WAVE; Это нужный тип данных?
        je COPYDATA_MUSIC; Нет, пропускаем
cmp     eax,CF_BITMAP; Это нужный тип данных?
        jne wmBYE
COPYDATA_ICON:; Создать HICON напрямую из памяти
invoke  CreateIconFromResourceEx,p,FSize,TRUE,30000h,256,256,LR_DEFAULTCOLOR
invoke  SendDlgItemMessage,hWnddlg,ID_ICON,STM_SETIMAGE,IMAGE_ICON,eax
jmp wmBYE
COPYDATA_MUSIC:mov r8,p
;"RIFF"+(File size)+(File Type Header)+(Format chunk marker)+(Length of format data) = 14h
        add r8d,14h
        invoke waveOutOpen,&hWaveOut,WAVE_MAPPER,,0,0,WAVE_ALLOWSYNC
; Подготавливаем заголовок для вывода
lea edi,lpwiocb
mov edx,edi
xor eax,eax
mov ecx,(sizeof WAVEHDR)/8
rep stosq

mov rax,p
;"RIFF"+(File size)+(File Type Header)+(Format chunk marker)+(Length of format data)+\
;(Type of format)+(Number of Channels)+(Sample Rate)+(Sample Rate*BitsPerSample*Channels/8)+\
;(BitsPerSample*Channels/8)+(Bits per sample)+(“data” chunk header)+(Size of the data section)=2Ch
add rax,2Ch
mov [rdx].WAVEHDR.lpData,rax ;адрес блока данных
mov eax,FSize
sub eax,2Ch
mov [rdx].WAVEHDR.dwBufferLength,eax ;размер блока данных
invoke waveOutPrepareHeader,hWaveOut,,sizeof WAVEHDR
; Запускаем проигрывание блока
invoke waveOutWrite,hWaveOut,&lpwiocb,sizeof WAVEHDR
@@: test lpwiocb.dwFlags,WHDR_DONE
jz @b
invoke waveOutUnprepareHeader,hWaveOut,&lpwiocb,sizeof WAVEHDR
invoke waveOutClose,hWaveOut
jmp wmBYE
COPYDATA_TEXT:invoke SetDlgItemText,,ID_TXT,p
jmp wmBYE
wmCOMMAND:cmp r8d,BN_CLICKED shl 16 + IDCANCEL
jne wmBYE
wmCLOSE:invoke EndDialog,,0
wmBYE: xor eax,eax
leave
retn
DialogProc endp
.data
szWin   db "Clipboard Sender",0
Error1   db "The server is not running.",10,"Run?",0
szAppName db "Clipboard Reciever",0
szService db "01s",0
end
--- End code ---
01r.rc
--- Code: ---#include "resource.h"
#define IDC_DIALOG 200
#define ID_TXT 100
#define ID_ICON 102
#define ID_PROGRESS 106
#define ID_TXT1 107

IDC_DIALOG DIALOGEX 0,0,212,154
STYLE DS_MODALFRAME | DS_CENTER | WS_CAPTION | WS_MINIMIZEBOX |
WS_SYSMENU | WS_VISIBLE | WS_OVERLAPPED | DS_MODALFRAME | DS_3DLOOK
CAPTION "WM_COPYDATA Reciever"

{
CONTROL "",-1,BUTTON,BS_GROUPBOX | WS_CHILD | WS_VISIBLE, 2,-3,207,24
CONTROL "", ID_TXT, STATIC, SS_LEFT | SS_NOPREFIX | WS_CHILD |
WS_VISIBLE | WS_BORDER | WS_TABSTOP, 5, 5, 199, 13
CONTROL "Exit", IDCANCEL, BUTTON, BS_DEFPUSHBUTTON | WS_CHILD |
WS_VISIBLE | WS_TABSTOP, 149, 25, 60, 15
CONTROL "",ID_ICON, STATIC, SS_ICON | WS_CHILD | WS_VISIBLE,3,40,128,128
}
--- End code ---

Mikl__:
02. ClipBoard
The clipboard is a set of functions and messages that enable applications to transfer data. Because all applications have access to the clipboard, data can be easily transferred between applications or within an application.02r.asm (Client)
--- Code: ---; GUI #
include win64a.inc
IDC_DIALOG equ 200
ID_TXT equ 100
ID_ICON equ 102
IDC_ICON1 equ 500

.code
WinMain proc  dummy:qword

        invoke  DialogBoxParamA,IMAGE_BASE,IDC_DIALOG,HWND_DESKTOP,qword ptr(offset DialogProc),0
        invoke  RtlExitUserProcess,NULL
WinMain endp
DialogProc proc hWnddlg:qword,msg:qword,wParam:qword,lParam:qword
local hGin:qword
local p:qword
local FSize:dword
local lpwiocb:WAVEHDR
local hWaveOut:qword

mov hWnddlg,rcx
mov lParam,r9

cmp edx,WM_CLOSE
je wmCLOSE
cmp edx,WM_CLIPBOARDUPDATE
je wmCLIPBOARDUPDATE
cmp edx,WM_COMMAND
je wmCOMMAND
        cmp edx,WM_INITDIALOG
jne wmBYE
wmINITDIALOG:invoke  FindWindowA,NULL,&szWin
        or      eax,eax
        jnz wmBYE
invoke MessageBoxA,hWnddlg,&Error1,&szAppName,MB_ICONEXCLAMATION or MB_YESNO
cmp eax,IDNO
jz      wmBYE     
invoke WinExec,&szService,SW_SHOW
jmp wmBYE
wmCLIPBOARDUPDATE:; В lParam приходит длина и тип данных
invoke OpenClipboard ;открываем буфер обмена
mov ecx,dword ptr lParam
invoke GetClipboardData;извлекаем текст из буфера обмена
mov hGin,rax
invoke GlobalLock,eax  ;блокируем память
mov p,rax
mov rax,lParam
shr rax,32
mov FSize,eax
cmp     dword ptr lParam,CF_WAVE; Это нужный тип данных?
        jz WAVE
cmp     dword ptr lParam,CF_DIB; Это нужный тип данных?
        jz DIB
cmp dword ptr lParam,CF_TEXT
jnz wmBYE
;---------------------------------------------------
; Получить строку от первого приложения
TXT: invoke  SetDlgItemTextA,hWnddlg,ID_TXT,p
jmp @0
DIB: mov edx,FSize
invoke  CreateIconFromResourceEx,p,,TRUE,30000h,256,256,LR_DEFAULTCOLOR
invoke  SendDlgItemMessageA,hWnddlg,ID_ICON,STM_SETIMAGE,IMAGE_ICON,eax
jmp @0
WAVE: mov r8,p
;"RIFF"+(File size)+(File Type Header)+(Format chunk marker)+(Length of format data) = 14h
        add r8d,14h
        invoke waveOutOpen,&hWaveOut,WAVE_MAPPER,,0,0,WAVE_ALLOWSYNC
; Подготавливаем заголовок для вывода
lea edi,lpwiocb
mov edx,edi
xor eax,eax
mov ecx,(sizeof WAVEHDR)/8
rep stosq
mov rax,p
;"RIFF"+(File size)+(File Type Header)+(Format chunk marker)+(Length of format data)+\
;(Type of format)+(Number of Channels)+(Sample Rate)+(Sample Rate*BitsPerSample*Channels/8)+\
;(BitsPerSample*Channels/8)+(Bits per sample)+(“data” chunk header)+(Size of the data section)=2Ch
add rax,2Ch
mov [rdx].WAVEHDR.lpData,rax ;адрес блока данных
mov eax,FSize
sub eax,2Ch
mov [rdx].WAVEHDR.dwBufferLength,eax ;размер блока данных
invoke waveOutPrepareHeader,hWaveOut,,sizeof WAVEHDR
; Запускаем проигрывание блока
invoke waveOutWrite,hWaveOut,&lpwiocb,sizeof WAVEHDR
@@: test lpwiocb.dwFlags,WHDR_DONE
jz @b
invoke waveOutUnprepareHeader,hWaveOut,&lpwiocb,sizeof WAVEHDR
invoke waveOutClose,hWaveOut
@0: invoke GlobalLock,hGin
invoke CloseClipboard
jmp wmBYE
wmCOMMAND:cmp r8d,BN_CLICKED shl 16 + IDCANCEL
jne wmBYE
wmCLOSE:invoke EndDialog,,0
wmBYE: xor eax,eax
leave
retn
DialogProc endp
.data
szWin db "Clipboard Sender",0
Error1 db "The server is not running.",10,"Run?",0
szAppName db "Clipboard Reciever",0
szService db "02s",0
end
--- End code ---
02r.rc
--- Code: ---#include "resource.h"
#define IDC_DIALOG 200
#define ID_TXT 100
#define ID_ICON 102
#define ID_PROGRESS 106
#define ID_TXT1 107

IDC_DIALOG DIALOGEX 0,0,212,154
STYLE DS_MODALFRAME | DS_CENTER | WS_CAPTION | WS_MINIMIZEBOX |
WS_SYSMENU | WS_VISIBLE | WS_OVERLAPPED | DS_MODALFRAME | DS_3DLOOK
CAPTION "Clipboard Reciever"

{
CONTROL "",-1,BUTTON,BS_GROUPBOX | WS_CHILD | WS_VISIBLE, 2,-3,207,24
CONTROL "", ID_TXT, STATIC, SS_LEFT | SS_NOPREFIX | WS_CHILD |
WS_VISIBLE | WS_BORDER | WS_TABSTOP, 5, 5, 199, 13
CONTROL "Exit", IDCANCEL, BUTTON, BS_DEFPUSHBUTTON | WS_CHILD |
WS_VISIBLE | WS_TABSTOP, 149, 25, 60, 15
CONTROL "",ID_ICON, STATIC, SS_ICON | WS_CHILD | WS_VISIBLE,3,40,128,128
}
--- End code ---
02s.asm (Server)
--- Code: ---; GUI #
include win64a.inc
ID_TXT equ 100
ID_SEND_TXT equ 101
ID_SEND_ICO equ 102
ID_SEND_WAV equ 103
IDC_DIALOG equ 200
IDC_ICON1 equ 500
IDC_IMG1 equ 104
WM_CLIPBOARDUPDATE  equ 31Dh

.code
WinMain proc dummy:qword

invoke LoadImageA,IMAGE_BASE,IDC_ICON1,IMAGE_ICON,256,256,LR_DEFAULTCOLOR
mov r9d,offset DialogProc
invoke DialogBoxParamA,IMAGE_BASE,IDC_DIALOG,HWND_DESKTOP,,eax
invoke RtlExitUserProcess,NULL
WinMain endp

DialogProc proc hWnddlg:QWORD,uMsg:QWORD,wParam:QWORD,lParam:QWORD
size_of_buffer equ 96
local hGout:qword
local p:qword
local FSize:dword
local hFile:dword
local szReadWrite:qword ;number of bytes actually read or write
local hResource:qword
local pResource:qword
local type0:qword

mov hWnddlg,rcx
mov lParam,r9

cmp edx,WM_CLOSE
je wmCLOSE
cmp edx,WM_COMMAND
je wmCOMMAND
cmp edx,WM_INITDIALOG
        jne wmBYE
wmINITDIALOG:invoke GetDlgItem,,IDC_IMG1
invoke SendMessageA,eax,STM_SETIMAGE,IMAGE_ICON,lParam
jmp wmBYE
wmSEND_TXT:invoke GlobalAlloc,GPTR,size_of_buffer;GHND or GMEM_DDESHARE
mov hGout,rax
invoke GlobalLock,eax
mov p,rax
invoke  GetDlgItemTextA,hWnddlg,ID_TXT,eax,size_of_buffer;255
        or      eax,eax
        jz      wmBYE
mov FSize,eax
add rax,p
and byte ptr[rax],0
mov rdx,CF_TEXT
jmp @f
;--------------------------------------------------
wmSEND_ICO:; Отправить изображение второму приложению
mov edx,p1
invoke FindResource,0,,RT_ICON; find the resource
mov hResource,rax
invoke  SizeofResource,0,eax ; get its size
mov FSize,eax
invoke GlobalAlloc,GPTR,eax; or GMEM_DDESHARE,eax
mov hGout,rax
invoke GlobalLock,eax
mov p,rax
mov edi,eax
invoke LoadResource,0,hResource ; load the resource
invoke LockResource,eax;pResource
mov esi,eax
mov ecx,FSize
rep movsb
;------------------------------------------------
mov edx,FSize
invoke  CreateIconFromResourceEx,p,,TRUE,30000h,256,256,LR_DEFAULTCOLOR
invoke  SendDlgItemMessageA,hWnddlg,IDC_IMG1,STM_SETIMAGE,IMAGE_ICON,eax
xor p1,11b
mov rdx,CF_DIB
jmp @f
;--------------------------------------------------
wmSEND_WAV:invoke CreateFile,&wav_file,GENERIC_READ,0,0,OPEN_EXISTING,FILE_ATTRIBUTE_ARCHIVE,0
        mov hFile,eax
        invoke GetFileSize,eax,0
mov FSize,eax
invoke GlobalAlloc,GPTR,eax
mov hGout,rax
invoke GlobalLock,eax
mov p,rax
        invoke ReadFile,hFile,eax,FSize,&szReadWrite,0
        invoke CloseHandle,hFile
mov rdx,CF_WAVE
;--------------------------------------------------------
@@: mov eax,FSize
shl rax,32
or rax,rdx
mov type0,rax
invoke GlobalUnlock,hGout
invoke OpenClipboard,hWnddlg
or eax,eax
jz wmBYE
invoke EmptyClipboard
invoke SetClipboardData,type0,hGout
invoke CloseClipboard
; Найти окно получателя
        invoke  FindWindowA,NULL,&szWin
        or      eax,eax
        jz      wmBYE
; Отправить данные получателю
invoke  PostMessageA,eax,WM_CLIPBOARDUPDATE,hWnddlg,type0
jmp wmBYE
wmCOMMAND:cmp r8d,BN_CLICKED shl 16 + ID_SEND_TXT
        je      wmSEND_TXT
        cmp r8d,BN_CLICKED shl 16 + ID_SEND_ICO
        je      wmSEND_ICO
cmp r8d,BN_CLICKED shl 16 + ID_SEND_WAV
        je      wmSEND_WAV
cmp     r8d,BN_CLICKED shl 16 + IDCANCEL
        jne     wmBYE
wmCLOSE:invoke EndDialog,,0
wmBYE: xor eax,eax
leave
retn
DialogProc endp
;---------------------------------------
.data
szWin db 'Clipboard Reciever',0
wav_file db '..\Images\03.wav',0
p1 dd 1
end
--- End code ---
02s.rc
--- Code: ---#include "resource.h"
#define ID_TXT 100
#define ID_SEND_TXT 101
#define ID_SEND_ICO 102
#define ID_SEND_WAV 103
#define IDC_IMG1 104

#define IDC_DIALOG 200
#define IDC_ICON1 500

IDC_ICON1 ICON "..\\Images\\icon1.ico"
IDC_ICON2 ICON "..\\Images\\icon2.ico"

IDC_DIALOG DIALOGEX 0, 0, 212, 154
STYLE DS_MODALFRAME | DS_CENTER | WS_CAPTION | WS_MINIMIZEBOX |
WS_SYSMENU | WS_VISIBLE | WS_OVERLAPPED | DS_MODALFRAME | DS_3DLOOK
CAPTION "Clipboard Sender"
{
CONTROL "",-1,BUTTON,BS_GROUPBOX | WS_CHILD | WS_VISIBLE,2,-1,207,24
CONTROL "",IDC_IMG1,STATIC,SS_ICON | WS_CHILD | WS_VISIBLE,3,40,128,128
CONTROL "Write something and click 'Send Text'",ID_TXT,EDIT,ES_LEFT |
ES_AUTOHSCROLL|WS_CHILD|WS_VISIBLE|WS_BORDER|WS_TABSTOP,5,7,199,13
CONTROL "Send Text", ID_SEND_TXT, BUTTON, BS_DEFPUSHBUTTON | WS_CHILD |
WS_VISIBLE | WS_TABSTOP, 149, 27, 60, 15
CONTROL "Send ICO", ID_SEND_ICO, BUTTON, BS_PUSHBUTTON | WS_CHILD |
WS_VISIBLE | WS_TABSTOP, 149, 45, 60, 15
CONTROL "Send WAV", ID_SEND_WAV, BUTTON, BS_PUSHBUTTON | WS_CHILD |
WS_VISIBLE | WS_TABSTOP, 149, 65, 60, 15
CONTROL "Exit",IDCANCEL,BUTTON,BS_PUSHBUTTON | WS_CHILD | WS_VISIBLE |
WS_TABSTOP, 149, 85, 60, 15
}
--- End code ---

Mikl__:
03. Memory Mapped File
Memory-mapped files can be shared across multiple processes. Processes can map to the same memory-mapped file by using a common name that is assigned by the process that created the file.
To work with a memory-mapped file, you must create a view of the entire memory-mapped file or a part of it. You can also create multiple views to the same part of the memory-mapped file, thereby creating concurrent memory. For two views to remain concurrent, they have to be created from the same memory-mapped file.03r.asm (Client)
--- Code: ---; GUI #
include win64a.inc
IDC_DIALOG equ 200
ID_TXT equ 100
ID_ICON equ 102
IDC_ICON1 equ 500

.code
WinMain proc dummy:qword

        invoke  DialogBoxParamA,IMAGE_BASE,IDC_DIALOG,HWND_DESKTOP,qword ptr(offset DialogProc),0
        invoke  RtlExitUserProcess,NULL
WinMain endp
DialogProc proc hWnddlg:qword,msg:qword,wParam:qword,lParam:qword
local pMapping:qword
local hMapping:qword
local FSize:dword
local lpwiocb:WAVEHDR
local hWaveOut:qword

mov hWnddlg,rcx
mov lParam,r9

cmp edx,WM_CLOSE
je wmCLOSE
cmp edx,WM_USER+1
je wmUSER_1
cmp edx,WM_COMMAND
je wmCOMMAND
cmp edx,WM_INITDIALOG
        jne wmBYE
wmINITDIALOG:; Найти окно получателя
        invoke  FindWindowA,NULL,&szWin
        or      eax,eax
        jnz wmBYE
invoke MessageBoxA,hWnddlg,&Error1,&szAppName,MB_ICONEXCLAMATION or MB_YESNO
cmp eax,IDNO
jz      wmBYE     
invoke WinExec,&szService,SW_SHOW
jmp wmBYE
wmUSER_1:; Получить строку от первого приложения
invoke OpenFileMapping,FILE_MAP_READ,FALSE,&lpszName
mov hMapping,rax
invoke MapViewOfFile,eax,FILE_MAP_READ,0,0,0
mov pMapping,rax
;-------------------------------------------
mov rax,lParam
shr rax,8
mov FSize,eax
cmp byte ptr lParam,CF_DIB
je DIB
cmp byte ptr lParam,CF_WAVE
je WAVE
cmp byte ptr lParam,CF_TEXT
jne wmBYE
TEXT: invoke  SetDlgItemTextA,hWnddlg,ID_TXT,pMapping
        jmp @0
DIB: mov edx,FSize
invoke  CreateIconFromResourceEx,pMapping,,TRUE,30000h,256,256,LR_DEFAULTCOLOR
invoke  SendDlgItemMessageA,hWnddlg,ID_ICON,STM_SETIMAGE,IMAGE_ICON,eax
        jmp @0
WAVE: mov r8,pMapping
;"RIFF"+(File size)+(File Type Header)+(Format chunk marker)+(Length of format data) = 14h
        add r8d,14h
        invoke waveOutOpen,&hWaveOut,WAVE_MAPPER,,0,0,WAVE_ALLOWSYNC
; Подготавливаем заголовок для вывода
lea edx,lpwiocb
mov edi,edx
xor eax,eax
        mov ecx,(sizeof WAVEHDR)/8
rep stosq
mov rax,pMapping
;"RIFF"+(File size)+(File Type Header)+(Format chunk marker)+(Length of format data)+\
;(Type of format)+(Number of Channels)+(Sample Rate)+(Sample Rate*BitsPerSample*Channels/8)+\
;(BitsPerSample*Channels/8)+(Bits per sample)+(“data” chunk header)+(Size of the data section)=2Ch
add rax,2Ch
mov [rdx].WAVEHDR.lpData,rax ;адрес блока данных
mov eax,FSize
sub eax,2Ch
mov [rdx].WAVEHDR.dwBufferLength,eax ;размер блока данных
invoke waveOutPrepareHeader,hWaveOut,,sizeof WAVEHDR
; Запускаем проигрывание блока
invoke waveOutWrite,hWaveOut,&lpwiocb,sizeof WAVEHDR
@@: cmp lpwiocb.dwFlags,WHDR_DONE or WHDR_PREPARED
jnz @b
invoke waveOutUnprepareHeader,hWaveOut,&lpwiocb,sizeof WAVEHDR
invoke waveOutClose,hWaveOut
@0: invoke UnmapViewOfFile,pMapping
        invoke CloseHandle,hMapping
jmp wmBYE
wmCOMMAND:cmp r8d,BN_CLICKED shl 16 + IDCANCEL
jne wmBYE
wmCLOSE:invoke EndDialog,,0
wmBYE: xor eax,eax
leave
retn
DialogProc endp
;--------------------------------------------------------
.data
szWin   db "Memory-Mapped File Sender",0
Error1   db "The server is not running.",10,"Run?",0
szAppName db "Memory-Mapped File Reciever",0
szService db "03s",0
align 10h
lpszName db "Song_of_the_South",0
end
--- End code ---
03r.rc
--- Code: ---#include "resource.h"
#define IDC_DIALOG 200
#define ID_TXT 100
#define ID_ICON 102
#define ID_PROGRESS 106
#define ID_TXT1 107

IDC_DIALOG DIALOGEX 0,0,212,154
STYLE DS_MODALFRAME | DS_CENTER | WS_CAPTION | WS_MINIMIZEBOX |
WS_SYSMENU | WS_VISIBLE | WS_OVERLAPPED | DS_MODALFRAME | DS_3DLOOK
CAPTION "Memory-Mapped File Reciever"

{
CONTROL "",-1,BUTTON,BS_GROUPBOX | WS_CHILD | WS_VISIBLE, 2,-3,207,24
CONTROL "", ID_TXT, STATIC, SS_LEFT | SS_NOPREFIX | WS_CHILD |
WS_VISIBLE | WS_BORDER | WS_TABSTOP, 5, 5, 199, 13
CONTROL "Exit", IDCANCEL, BUTTON, BS_DEFPUSHBUTTON | WS_CHILD |
WS_VISIBLE | WS_TABSTOP, 149, 25, 60, 15
CONTROL "",ID_ICON, STATIC, SS_ICON | WS_CHILD | WS_VISIBLE,3,40,128,128
}
--- End code ---
03s.asm (Server)
--- Code: ---; GUI #
include win64a.inc
ID_TXT equ 100
ID_SEND_TXT equ 101
ID_SEND_ICO equ 102
ID_SEND_WAV equ 103
IDC_DIALOG equ 200
IDC_ICON1 equ 500
IDC_IMG1 equ 104

.code
WinMain proc dummy:qword

invoke LoadImageA,IMAGE_BASE,IDC_ICON1,IMAGE_ICON,256,256,LR_DEFAULTCOLOR
invoke DialogBoxParamA,IMAGE_BASE,IDC_DIALOG,HWND_DESKTOP,qword ptr(offset DialogProc),eax
invoke RtlExitUserProcess,NULL
WinMain endp

DialogProc proc hWnddlg:QWORD,uMsg:QWORD,wParam:QWORD,lParam:QWORD
size_of_buffer equ 96
local FSize:dword
local hResource:qword
local pResource:qword
local szReadWrite:qword
local type0:qword
local p:qword

mov hWnddlg,rcx
mov lParam,r9

cmp edx,WM_CLOSE
je wmCLOSE
cmp edx,WM_COMMAND
je wmCOMMAND
cmp edx,WM_INITDIALOG
        jne wmBYE
wmINITDIALOG:invoke GetDlgItem,,IDC_IMG1
invoke SendMessageA,eax,STM_SETIMAGE,IMAGE_ICON,lParam
jmp wmBYE
wmSEND_TXT:invoke GlobalAlloc,GPTR,size_of_buffer
        invoke GlobalLock,eax
mov p,rax
invoke  GetDlgItemTextA,hWnddlg,ID_TXT,eax,size_of_buffer;255
        or      eax,eax
        jz      wmBYE
        inc     eax
mov FSize,eax
;созддание файла
invoke CreateFile,&szMapName0,GENERIC_READ or GENERIC_WRITE,0,0,OPEN_ALWAYS,0,0
mov hFile,rax
invoke WriteFile,eax,p,FSize,&szReadWrite,0
invoke Func,hFile,0
mov edx,CF_TEXT
jmp @0
wmSEND_ICO:mov edx,p1
invoke FindResource,0,,RT_ICON; find the resource
mov hResource,rax
invoke  SizeofResource,0,eax ; get its size
mov     FSize,eax
; shl eax,8
; mov edx,CF_DIB
;        mov type0,rax
invoke LoadResource,0,hResource ; load the resource
invoke LockResource,eax
mov esi,eax
;созддание в памяти объекта "проекция файла" и
;отображение проекции файла на адресное пространство процесса
invoke Func,INVALID_HANDLE_VALUE,FSize
;-----------------------------------------------------------------
mov ecx,FSize
mov edi,eax;rdi,pMapping
rep movsb
;--------------------------------------------------
mov edx,FSize
invoke  CreateIconFromResourceEx,pMapping,,TRUE,30000h,256,256,LR_DEFAULTCOLOR
invoke  SendDlgItemMessageA,hWnddlg,IDC_IMG1,STM_SETIMAGE,IMAGE_ICON,eax
xor p1,11b
mov edx,CF_DIB
jmp @0
;-------------------------------------------------------
wmSEND_WAV:invoke CreateFile,&wav_file,GENERIC_READ or GENERIC_WRITE,FILE_SHARE_READ \
or FILE_SHARE_WRITE,0,OPEN_EXISTING,FILE_ATTRIBUTE_ARCHIVE,0
        mov hFile,rax
        invoke GetFileSize,eax,0
mov FSize,eax
invoke Func,hFile,0
mov edx,CF_WAVE
;-------------------------------------------------------
@0: mov eax,FSize
shl eax,8
or eax,edx
mov type0,rax
; Найти окно получателя
mov edx,offset szWin
        invoke  FindWindowA,NULL
        or      eax,eax
        jz      wmBYE
; Отправить данные получателю
        invoke  SendMessageTimeoutA,eax,WM_USER+1,hWnddlg,type0,SMTO_ABORTIFHUNG,5000,0
invoke UnmapViewOfFile,pMapping
invoke CloseHandle,hMapping
invoke CloseHandle,hFile
cmp byte ptr type0,CF_TEXT
jnz     wmBYE
mov ecx,offset szMapName0
invoke DeleteFile
jmp wmBYE
wmCOMMAND:cmp r8d,BN_CLICKED shl 16 + ID_SEND_TXT
        je      wmSEND_TXT
        cmp r8d,BN_CLICKED shl 16 + ID_SEND_ICO
        je      wmSEND_ICO
cmp r8d,BN_CLICKED shl 16 + ID_SEND_WAV
        je      wmSEND_WAV
cmp     r8d,BN_CLICKED shl 16 + IDCANCEL
        jne     wmBYE
wmCLOSE:invoke EndDialog,,0
wmBYE: xor eax,eax
leave
retn
DialogProc endp
;----------------------------------------
Func proc hFile:qword,FSize:qword
mov FSize,rdx
;созддание в памяти объекта "проекция файла"
movr qword ptr[rsp+28h],szMapName
mov [rsp+20h],rdx
        invoke CreateFileMapping,,0,PAGE_READWRITE,0
mov hMapping,rax
;отображение проекции файла на адресное пространство процесса
mov rax,FSize
mov [rsp+20h],rax
invoke MapViewOfFile,hMapping,FILE_MAP_ALL_ACCESS,0,0
mov pMapping,rax
leave
ret
Func endp
;---------------------------------------
szWin      db 'Memory-Mapped File Reciever',0
wav_file   db '..\Images\03.wav',0
szMapName  db "Song_of_the_South",0
szMapName0 db "15.txt",0
p1 dd 1
hMapping dq ?
pMapping dq ?
hFile dq ?
end
--- End code ---
03s.rc
--- Code: ---#include "resource.h"
#define ID_TXT 100
#define ID_SEND_TXT 101
#define ID_SEND_ICO 102
#define ID_SEND_WAV 103
#define IDC_IMG1 104

#define IDC_DIALOG 200
#define IDC_ICON1 500

IDC_ICON1 ICON "..\\Images\\icon1.ico"
IDC_ICON2 ICON "..\\Images\\icon2.ico"

IDC_DIALOG DIALOGEX 0, 0, 212, 154
STYLE DS_MODALFRAME | DS_CENTER | WS_CAPTION | WS_MINIMIZEBOX |
WS_SYSMENU | WS_VISIBLE | WS_OVERLAPPED | DS_MODALFRAME | DS_3DLOOK
CAPTION "Memory-Mapped File Sender"
{
CONTROL "",-1,BUTTON,BS_GROUPBOX | WS_CHILD | WS_VISIBLE,2,-1,207,24
CONTROL "",IDC_IMG1,STATIC,SS_ICON | WS_CHILD | WS_VISIBLE,3,40,128,128
CONTROL "Write something and click 'Send Text'",ID_TXT,EDIT,ES_LEFT |
ES_AUTOHSCROLL|WS_CHILD|WS_VISIBLE|WS_BORDER|WS_TABSTOP,5,7,199,13
CONTROL "Send Text", ID_SEND_TXT, BUTTON, BS_DEFPUSHBUTTON | WS_CHILD |
WS_VISIBLE | WS_TABSTOP, 149, 27, 60, 15
CONTROL "Send ICO", ID_SEND_ICO, BUTTON, BS_PUSHBUTTON | WS_CHILD |
WS_VISIBLE | WS_TABSTOP, 149, 45, 60, 15
CONTROL "Send WAV", ID_SEND_WAV, BUTTON, BS_PUSHBUTTON | WS_CHILD |
WS_VISIBLE | WS_TABSTOP, 149, 65, 60, 15
CONTROL "Exit",IDCANCEL,BUTTON,BS_PUSHBUTTON | WS_CHILD | WS_VISIBLE |
WS_TABSTOP, 149, 85, 60, 15
}
--- End code ---

Mikl__:
04. Paging File

Memory Mapped File and Paging File: fast communication mechanisms between processes, provide an efficient way to use the contents of a file in virtual memory or by accessing shared memory. In these IPCs, the file data is treated as part of the process's address space, so that the process can easily access the address of the content. Any other process that has access to shared memory must implement synchronization to reduce the risk of data corruption. File mapping is performed on the same system/machine and is not available to network processes.04r.asm (Client)
--- Code: ---; GUI #
include win64a.inc
IDC_DIALOG equ 200
IMAGE_BASE equ 400000h
ID_TXT equ 100
ID_ICON equ 102
IDC_ICON1 equ 500

.code
WinMain proc dummy:qword

invoke  DialogBoxParamA,IMAGE_BASE,IDC_DIALOG,HWND_DESKTOP,qword ptr(offset DialogProc),0
        invoke  RtlExitUserProcess,NULL
WinMain endp
DialogProc proc hWnddlg:qword,msg:qword,wParam:qword,lParam:qword
local pMapping:qword
local hMapping:qword
local FSize:dword
local lpwiocb:WAVEHDR
local hWaveOut:qword
local type0:byte

mov hWnddlg,rcx
mov lParam,r9

cmp edx,WM_CLOSE
je wmCLOSE
cmp edx,WM_USER+1
je wmUSER_1
cmp edx,WM_COMMAND
je wmCOMMAND
        cmp edx,WM_INITDIALOG
        jne wmBYE
wmINITDIALOG:; Найти окно отправителя
        invoke  FindWindowA,NULL,&szWin
        or      eax,eax
        jnz wmBYE
invoke MessageBoxA,hWnddlg,&Error1,&szAppName,MB_ICONEXCLAMATION or MB_YESNO
cmp eax,IDNO
jz      wmBYE     
invoke WinExec,&szService,SW_SHOW
jmp wmBYE
wmUSER_1:mov rcx,lParam
mov type0,cl
shr ecx,8
mov FSize,ecx
@@: mov r8d,offset lpszName
invoke OpenFileMapping,FILE_MAP_ALL_ACCESS,FALSE
mov hMapping,rax
mov ecx,eax
mov eax,FSize;lParam
mov [rsp+20h],rax
invoke MapViewOfFile,,FILE_MAP_ALL_ACCESS,0,0
mov pMapping,rax
cmp type0,CF_TEXT
je TXT
cmp type0,CF_DIB
je DIB
WAVE: mov r8,pMapping
        add r8d,14h
        invoke waveOutOpen,&hWaveOut,WAVE_MAPPER,,0,0,WAVE_ALLOWSYNC
; Подготавливаем заголовок для вывода
lea edx,lpwiocb
mov edi,edx
xor eax,eax
mov ecx,(sizeof WAVEHDR)/8
rep stosq

mov rax,pMapping
add rax,2Ch

mov [rdx].WAVEHDR.lpData,rax ;адрес блока данных
mov eax,FSize;[rcx+4]
sub eax,2Ch
mov [rdx].WAVEHDR.dwBufferLength,eax ;размер блока данных
invoke waveOutPrepareHeader,hWaveOut,,sizeof WAVEHDR
; Запускаем проигрывание блока
invoke waveOutWrite,hWaveOut,&lpwiocb,sizeof WAVEHDR
@@: cmp lpwiocb.dwFlags,WHDR_DONE or WHDR_PREPARED
jnz @b
invoke waveOutUnprepareHeader,hWaveOut,&lpwiocb,sizeof WAVEHDR
invoke waveOutClose,hWaveOut
jmp @f
TXT: invoke  SetDlgItemTextA,hWnddlg,ID_TXT,pMapping
jmp @f
DIB: and qword ptr[rsp+30h],LR_DEFAULTCOLOR;LR_DEFAULTCOLOR=0
mov qword ptr[rsp+20h],256
mov qword ptr[rsp+28h],256
mov edx,FSize
invoke  CreateIconFromResourceEx,pMapping,,TRUE,30000h
invoke  SendDlgItemMessageA,hWnddlg,ID_ICON,STM_SETIMAGE,IMAGE_ICON,eax
@@: invoke UnmapViewOfFile,pMapping
        invoke CloseHandle,hMapping
jmp wmBYE
wmCOMMAND:cmp r8d,BN_CLICKED shl 16 + IDCANCEL
jne wmBYE
wmCLOSE:invoke EndDialog,,0
wmBYE: xor eax,eax
leave
retn
DialogProc endp
.data
lpszName  db "Song_of_the_South",0
Error1   db "The server is not running.",10,"Run?",0
szService db "04s",0
szWin   db "Paging File Sender",0
szAppName db "Paging File Reciever",0
end
--- End code ---
04r.rc
--- Code: ---#include "resource.h"
#define IDC_DIALOG 200
#define ID_TXT 100
#define ID_ICON 102
#define ID_PROGRESS 106
#define ID_TXT1 107

IDC_DIALOG DIALOGEX 0,0,212,154
STYLE DS_MODALFRAME | DS_CENTER | WS_CAPTION | WS_MINIMIZEBOX |
WS_SYSMENU | WS_VISIBLE | WS_OVERLAPPED | DS_MODALFRAME | DS_3DLOOK
CAPTION "Paging File Reciever"

{
CONTROL "",-1,BUTTON,BS_GROUPBOX | WS_CHILD | WS_VISIBLE, 2,-3,207,24
CONTROL "", ID_TXT, STATIC, SS_LEFT | SS_NOPREFIX | WS_CHILD |
WS_VISIBLE | WS_BORDER | WS_TABSTOP, 5, 5, 199, 13
CONTROL "Exit", IDCANCEL, BUTTON, BS_DEFPUSHBUTTON | WS_CHILD |
WS_VISIBLE | WS_TABSTOP, 149, 25, 60, 15
CONTROL "",ID_ICON, STATIC, SS_ICON | WS_CHILD | WS_VISIBLE,3,40,128,128
}
--- End code ---
04s.asm (Server)
--- Code: ---; GUI #
include win64a.inc
ID_TXT equ 100
ID_SEND_TXT equ 101
ID_SEND_ICO equ 102
ID_SEND_WAV equ 103
IDC_DIALOG equ 200
IDC_ICON1 equ 500
IDC_IMG1 equ 104

.code
WinMain proc dummy:qword

invoke LoadImageA,IMAGE_BASE,IDC_ICON1,IMAGE_ICON,256,256,LR_DEFAULTCOLOR

mov r9d,offset DialogProc
invoke DialogBoxParamA,IMAGE_BASE,IDC_DIALOG,HWND_DESKTOP,,eax
invoke RtlExitUserProcess,NULL
WinMain endp

DialogProc proc hWnddlg:QWORD,uMsg:QWORD,wParam:QWORD,lParam:QWORD
size_of_buffer equ 96
local buffer[size_of_buffer]:BYTE
local hFile:dword
local FSize:dword
local hMapping:qword
local pMapping:qword
local hResource:qword
local pResource:qword
local szReadWrite:qword
local type0:qword

        mov hWnddlg,rcx
mov lParam,r9

cmp edx,WM_CLOSE
je wmCLOSE
cmp edx,WM_COMMAND
je wmCOMMAND
        cmp edx,WM_INITDIALOG
        jne wmBYE
wmINITDIALOG:invoke GetDlgItem,,IDC_IMG1
invoke SendMessageA,eax,STM_SETIMAGE,IMAGE_ICON,lParam
jmp wmBYE
wmSEND_TXT:lea r8d,buffer
invoke  GetDlgItemTextA,,ID_TXT,,size_of_buffer;255
        or      eax,eax
        jz      wmBYE
        inc     eax
mov FSize,eax
;созддание в памяти объекта "проекция файла"
; sub esp,30h
movr qword ptr[rsp+28h],szMapName
mov eax,FSize
mov [rsp+20h],rax
or rcx,INVALID_HANDLE_VALUE
        invoke CreateFileMapping,,0,PAGE_READWRITE,0
mov hMapping,rax
;отображение проекции файла на адресное пространство процесса
mov ecx,eax
mov eax,FSize
mov [rsp+20h],rax
invoke MapViewOfFile,,FILE_MAP_ALL_ACCESS,0,0
mov pMapping,rax
mov ecx,FSize
mov edi,eax
lea esi,buffer
rep movsb
mov eax,FSize
shl rax,8
or rax,CF_TEXT
mov type0,rax
;--------------------------------------------------
jmp @f
wmSEND_ICO:;sub esp,30h
mov edx,p1
invoke FindResource,0,,RT_ICON; find the resource
mov hResource,rax
invoke  SizeofResource,0,eax ; get its size
mov     FSize,eax
invoke LoadResource,0,hResource ; load the resource
invoke LockResource,eax
mov esi,eax
;созддание в памяти объекта "проекция файла"
movr qword ptr[rsp+28h],szMapName
mov eax,FSize
mov [rsp+20h],rax
or rcx,INVALID_HANDLE_VALUE
        invoke CreateFileMapping,,0,PAGE_READWRITE,0
mov hMapping,rax
;отображение проекции файла на адресное пространство процесса
mov ecx,eax
mov eax,FSize
mov [rsp+20h],rax
invoke MapViewOfFile,,FILE_MAP_ALL_ACCESS,0,0
mov pMapping,rax
mov ecx,FSize
mov edi,eax;rdi,pMapping
rep movsb
;--------------------------------------------------
        mov ecx,256
and qword ptr[rsp+30h],LR_DEFAULTCOLOR;LR_DEFAULTCOLOR=0
mov [rsp+20h],rcx
mov [rsp+28h],rcx
mov edx,FSize
invoke  CreateIconFromResourceEx,pMapping,,TRUE,30000h;270376,TRUE,30000h
mov [rsp+20h],rax
invoke  SendDlgItemMessageA,hWnddlg,IDC_IMG1,STM_SETIMAGE,IMAGE_ICON
xor p1,11b
        mov eax,FSize
shl rax,8
or rax,CF_DIB
mov type0,rax
;-------------------------------------------------------
jmp @f
wmSEND_WAV:;sub esp,40h
mov ecx,offset wav_file
xor r9d,r9d
mov qword ptr[rsp+30h],r9
mov qword ptr[rsp+28h],FILE_ATTRIBUTE_ARCHIVE
mov qword ptr[rsp+20h],OPEN_EXISTING
invoke CreateFile,,GENERIC_READ or GENERIC_WRITE,\
FILE_SHARE_READ or FILE_SHARE_WRITE
        mov hFile,eax
        invoke GetFileSize,eax,0
mov FSize,eax
;созддание в памяти объекта "проекция файла"
movr qword ptr[rsp+28h],szMapName
mov eax,FSize
mov [rsp+20h],rax
or rcx,INVALID_HANDLE_VALUE
        invoke CreateFileMapping,,0,PAGE_READWRITE,0
mov hMapping,rax
;отображение проекции файла на адресное пространство процесса
invoke MapViewOfFile,eax,FILE_MAP_ALL_ACCESS,0,0,FSize
mov pMapping,rax
;-------------------------------------------------
and qword ptr[rsp+20h],0
lea r9,szReadWrite
invoke ReadFile,hFile,pMapping,FSize
mov eax,FSize
shl rax,8
or rax,CF_WAVE
mov type0,rax
@@:; Найти окно получателя
        invoke  FindWindowA,NULL,&szWin
        or      eax,eax
        jz      wmBYE
; Отправить данные получателю
mov qword ptr[rsp+20h],SMTO_ABORTIFHUNG
mov qword ptr[rsp+28h],5000
and qword ptr[rsp+30h],0
        invoke  SendMessageTimeoutA,eax,WM_USER+1,hWnddlg,type0
invoke UnmapViewOfFile,pMapping
invoke CloseHandle,hMapping
jmp wmBYE
wmCOMMAND:cmp r8d,BN_CLICKED shl 16 + ID_SEND_TXT
        je      wmSEND_TXT
        cmp r8d,BN_CLICKED shl 16 + ID_SEND_ICO
        je      wmSEND_ICO
cmp r8d,BN_CLICKED shl 16 + ID_SEND_WAV
        je      wmSEND_WAV
cmp     r8d,BN_CLICKED shl 16 + IDCANCEL
        jne     wmBYE
wmCLOSE:invoke EndDialog,,0
wmBYE: xor eax,eax
leave
retn
DialogProc endp
;---------------------------------------
.data
szWin     db 'Paging File Reciever',0
wav_file  db '..\Images\03.wav',0
szMapName db "Song_of_the_South",0
p1   dd 1
end
--- End code ---
04s.rc
--- Code: ---#include "resource.h"
#define ID_TXT 100
#define ID_SEND_TXT 101
#define ID_SEND_ICO 102
#define ID_SEND_WAV 103
#define IDC_IMG1 104

#define IDC_DIALOG 200
#define IDC_ICON1 500

IDC_ICON1 ICON "..\\Images\\icon1.ico"
IDC_ICON2 ICON "..\\Images\\icon2.ico"

IDC_DIALOG DIALOGEX 0, 0, 212, 154
STYLE DS_MODALFRAME | DS_CENTER | WS_CAPTION | WS_MINIMIZEBOX |
WS_SYSMENU | WS_VISIBLE | WS_OVERLAPPED | DS_MODALFRAME | DS_3DLOOK
CAPTION "Paging File Sender"
{
CONTROL "",-1,BUTTON,BS_GROUPBOX | WS_CHILD | WS_VISIBLE,2,-1,207,24
CONTROL "",IDC_IMG1,STATIC,SS_ICON | WS_CHILD | WS_VISIBLE,3,40,128,128
CONTROL "Write something and click 'Send Text'",ID_TXT,EDIT,ES_LEFT |
ES_AUTOHSCROLL|WS_CHILD|WS_VISIBLE|WS_BORDER|WS_TABSTOP,5,7,199,13
CONTROL "Send Text", ID_SEND_TXT, BUTTON, BS_DEFPUSHBUTTON | WS_CHILD |
WS_VISIBLE | WS_TABSTOP, 149, 27, 60, 15
CONTROL "Send ICO", ID_SEND_ICO, BUTTON, BS_PUSHBUTTON | WS_CHILD |
WS_VISIBLE | WS_TABSTOP, 149, 45, 60, 15
CONTROL "Send WAV", ID_SEND_WAV, BUTTON, BS_PUSHBUTTON | WS_CHILD |
WS_VISIBLE | WS_TABSTOP, 149, 65, 60, 15
CONTROL "Exit",IDCANCEL,BUTTON,BS_PUSHBUTTON | WS_CHILD | WS_VISIBLE |
WS_TABSTOP, 149, 85, 60, 15
}
--- End code ---

Mikl__:
05. Mail Slots
A mailslot is a mechanism for one-way interprocess communications (IPC). Applications can store messages in a mailslot. The owner of the mailslot can retrieve messages that are stored there. These messages are typically sent over a network to either a specified computer or to all computers in a specified domain. 05r.asm (Client)
--- Code: ---; GUI #
include win64a.inc
WM_CLIPBOARDUPDATE equ 31Dh
IDC_DIALOG equ 200
ID_TXT equ 100
ID_ICON equ 102
IDC_ICON1 equ 500
TXT equ 10
ICO equ 11
WAV equ 12
.code
WinMain proc dummy:qword

mov r9d,offset DialogProc
        invoke  DialogBoxParamA,IMAGE_BASE,IDC_DIALOG,HWND_DESKTOP,,0
        invoke  RtlExitUserProcess,NULL
WinMain endp
DialogProc proc hWnddlg:qword,msg:qword,wParam:qword,lParam:qword
local cbRead:DWORD;Количество байт данных, принятых через канал
local cbMessages:DWORD;Размер сообщения в байтах
local cbMsgNumber:DWORD;Количество сообщений в канале Mailslot
local p:QWORD
local lpwiocb:WAVEHDR
local hWaveOut:qword
local FSize:qword

mov hWnddlg,rcx
mov lParam,r9

cmp edx,WM_CLOSE
je wmCLOSE
cmp edx,WM_USER+1
je wmUSER_1
cmp edx,WM_COMMAND
je wmCOMMAND
        cmp edx,WM_INITDIALOG
jne wmBYE
wmINITDIALOG:; Найти окно отправителя
        invoke  FindWindowA,NULL,&szWin
        or      eax,eax
        jnz @f
invoke MessageBoxA,hWnddlg,&Error1,&szAppName,MB_ICONEXCLAMATION or MB_YESNO
cmp eax,IDNO
jz      @f     
invoke WinExec,&szService,SW_SHOW
; Создаем канал Mailslot, имеющий имя lpszMailslotName
@@: mov ecx,offset lpszMailslotName
invoke CreateMailslot,,0,MAILSLOT_WAIT_FOREVER, NULL
mov hMailslot,rax
jmp wmBYE
wmUSER_1:mov rax,lParam
mov type0,al
shr rax,8
mov FSize,rax
; Определяем состояние канала Mailslot
lea r8d,cbMessages
lea r9d,cbMsgNumber
xor edx,edx
mov [rsp+20h],rdx
invoke GetMailslotInfo,hMailslot
; Выполняем задержку на  500 миллисекунд
invoke Sleep,500
; Если в канале есть Mailslot сообщения, читаем первое из них и выводим на экран
cmp cbMsgNumber,0
jz wmBYE
invoke GlobalAlloc,GMEM_FIXED,FSize
mov p,rax
invoke ReadFile,hMailslot,p,FSize,&cbRead,0
cmp type0,CF_TEXT
je TEXT
        cmp type0,CF_DIB
je DIB
WAVE: mov r8,p
;"RIFF"+(File size)+(File Type Header)+(Format chunk marker)+(Length of format data) = 14h
        add r8d,14h
        invoke waveOutOpen,&hWaveOut,WAVE_MAPPER,,0,0,WAVE_ALLOWSYNC
; Подготавливаем заголовок для вывода
lea edx,lpwiocb
mov edi,edx
xor eax,eax
mov ecx,(sizeof WAVEHDR)/8
rep stosq

mov rax,p
;"RIFF"+(File size)+(File Type Header)+(Format chunk marker)+(Length of format data)+\
;(Type of format)+(Number of Channels)+(Sample Rate)+(Sample Rate*BitsPerSample*Channels/8)+\
;(BitsPerSample*Channels/8)+(Bits per sample)+(“data” chunk header)+(Size of the data section)=2Ch
add rax,2Ch
mov [rdx].WAVEHDR.lpData,rax ;адрес блока данных
mov rax,FSize
sub eax,2Ch
mov [rdx].WAVEHDR.dwBufferLength,eax ;размер блока данных

invoke waveOutPrepareHeader,hWaveOut,,sizeof WAVEHDR
; Запускаем проигрывание блока
invoke waveOutWrite,hWaveOut,&lpwiocb,sizeof WAVEHDR
@@: test lpwiocb.dwFlags,WHDR_DONE
jz @b
invoke waveOutUnprepareHeader,hWaveOut,&lpwiocb,sizeof WAVEHDR
invoke waveOutClose,hWaveOut
jmp @0
TEXT: invoke  SetDlgItemTextA,hWnddlg,ID_TXT,p
jmp @0
DIB:    and qword ptr[rsp+30h],LR_DEFAULTCOLOR;LR_DEFAULTCOLOR=0
mov qword ptr[rsp+20h],256
mov qword ptr[rsp+28h],256
invoke  CreateIconFromResourceEx,p,FSize,TRUE,30000h
invoke  SendDlgItemMessageA,hWnddlg,ID_ICON,STM_SETIMAGE,IMAGE_ICON,eax
@0: invoke GlobalFree,p
jmp wmBYE
wmCOMMAND:cmp r8d,BN_CLICKED shl 16 + IDCANCEL
jne wmBYE
wmCLOSE:;Перед завершением приложения закрываем идентификатор канала Mailslot
invoke CloseHandle,hMailslot
invoke EndDialog,hWnddlg,0
wmBYE: xor eax,eax
leave
retn
DialogProc endp
.data
lpszMailslotName db "\\.\mailslot\brer_Rabbit",0;Имя создаваемого канала Mailslot
hMailslot dq ?;Идентификатор канала Mailslot
type0 db ?
szWin db "Mailslot Sender",0
Error1 db "The server is not running.",10,"Run?",0
szAppName db "Mailslot Reciever",0
szService db "05s",0
end
--- End code ---
05r.rc
--- Code: ---#include "resource.h"
#define IDC_DIALOG 200
#define ID_TXT 100
#define ID_ICON 102
#define ID_PROGRESS 106
#define ID_TXT1 107

IDC_DIALOG DIALOGEX 0,0,212,154
STYLE DS_MODALFRAME | DS_CENTER | WS_CAPTION | WS_MINIMIZEBOX |
WS_SYSMENU | WS_VISIBLE | WS_OVERLAPPED | DS_MODALFRAME | DS_3DLOOK
CAPTION "Mailslot Reciever"

{
CONTROL "",-1,BUTTON,BS_GROUPBOX | WS_CHILD | WS_VISIBLE, 2,-3,207,24
CONTROL "", ID_TXT, STATIC, SS_LEFT | SS_NOPREFIX | WS_CHILD |
WS_VISIBLE | WS_BORDER | WS_TABSTOP, 5, 5, 199, 13
CONTROL "Exit", IDCANCEL, BUTTON, BS_DEFPUSHBUTTON | WS_CHILD |
WS_VISIBLE | WS_TABSTOP, 149, 25, 60, 15
CONTROL "",ID_ICON, STATIC, SS_ICON | WS_CHILD | WS_VISIBLE,3,40,128,128
}
--- End code ---
05s.asm (Server)
--- Code: ---; GUI #
include win64a.inc
WM_CLIPBOARDUPDATE equ 31Dh
ID_TXT equ 100
ID_SEND_TXT equ 101
ID_SEND_ICO equ 102
ID_SEND_WAV equ 103
IDC_DIALOG equ 200
IDC_ICON1 equ 500
IDC_IMG1 equ 104
.code
WinMain proc dummy:qword

mov r9d,256
mov [rsp+20h],r9
mov qword ptr [rsp+28],LR_DEFAULTCOLOR
invoke LoadImageA,IMAGE_BASE,IDC_ICON1,IMAGE_ICON;,256,256,LR_DEFAULTCOLOR

mov r9d,offset DialogProc
mov qword ptr[rsp+20h],rax
invoke DialogBoxParamA,IMAGE_BASE,IDC_DIALOG,HWND_DESKTOP
invoke RtlExitUserProcess,NULL
WinMain endp

DialogProc proc hWnddlg:QWORD,uMsg:QWORD,wParam:QWORD,lParam:QWORD
local cbWritten:dword;Количество байт, переданных через канал
local FSize:dword;
local p:qword
local hMailslot:qword; Идентификатор канала Mailslot
local hResource:qword
local hFile:dword
local szReadWrite:qword ;number of bytes actually read or write
local lpwiocb:WAVEHDR
local hWaveOut:qword
local type0:qword

mov hWnddlg,rcx
mov lParam,r9

cmp edx,WM_CLOSE
je wmCLOSE
cmp edx,WM_COMMAND
je wmCOMMAND
cmp edx,WM_INITDIALOG
        jne wmBYE
wmINITDIALOG:invoke GetDlgItem,,IDC_IMG1
invoke SendMessageA,eax,STM_SETIMAGE,IMAGE_ICON,lParam
jmp wmBYE
wmSEND_TXT:invoke GlobalAlloc,GPTR,256
        mov p,rax;Буфер для передачи данных через канал
invoke  GetDlgItemTextA,hWnddlg,ID_TXT,eax,256
        or      eax,eax
        jz      wmBYE
        inc     eax
mov FSize,eax
shl rax,8
or rax,CF_TEXT
mov type0,rax
jmp @f
wmSEND_ICO:mov edx,p1
invoke FindResource,0,,RT_ICON; find the resource
mov hResource,rax
invoke  SizeofResource,0,eax ; get its size
mov FSize,eax
shl rax,8
or rax,CF_DIB
mov type0,rax
invoke LoadResource,0,hResource ; load the resource
invoke LockResource,eax;pResource
  mov p,rax
;-------------------------------------------------
and qword ptr[rsp+30h],LR_DEFAULTCOLOR;LR_DEFAULTCOLOR=0
mov qword ptr[rsp+20h],256
mov qword ptr[rsp+28h],256
mov edx,FSize
invoke  CreateIconFromResourceEx,p,,TRUE,30000h;270376,TRUE,30000h
invoke  SendDlgItemMessageA,hWnddlg,IDC_IMG1,STM_SETIMAGE,IMAGE_ICON,eax
xor p1,11b
jmp @f
wmSEND_WAV:;sub esp,40h
mov ecx,offset wav_file
xor r9d,r9d
mov qword ptr[rsp+30h],r9
mov qword ptr[rsp+28h],FILE_ATTRIBUTE_ARCHIVE
mov qword ptr[rsp+20h],OPEN_EXISTING
invoke CreateFile,,GENERIC_READ or GENERIC_WRITE,\
FILE_SHARE_READ or FILE_SHARE_WRITE
        mov hFile,eax
        invoke GetFileSize,eax,0
mov FSize,eax
invoke GlobalAlloc,GPTR,eax
        mov p,rax
mov eax,FSize
shl rax,8
or rax,CF_WAVE
mov type0,rax
lea r9d,cbWritten
and qword ptr[rsp+20h],0
        invoke ReadFile,hFile,p,FSize
        invoke CloseHandle,hFile
@@:; Создаем канал с процессом MSLOTS
mov ecx,offset szMailslotName
xor r9d,r9d
mov qword ptr[rsp+20h],OPEN_EXISTING
mov [rsp+28h],r9
mov [rsp+30h],r9
invoke CreateFile,,GENERIC_WRITE,FILE_SHARE_READ
mov hMailslot,rax

lea r9d,cbWritten
and qword ptr[rsp+20h],0
        invoke WriteFile,hMailslot,p,FSize
; Найти окно получателя
mov edx,offset szWin
        invoke  FindWindowA,NULL
        or      eax,eax
        jz      wmBYE
; Отправить данные получателю
invoke PostMessageA,eax,WM_USER+1,hWnddlg,type0
;Закрываем идентификатор канала
invoke CloseHandle,hMailslot
jmp wmBYE
wmCOMMAND:cmp r8d,BN_CLICKED shl 16 + ID_SEND_TXT
        je      wmSEND_TXT
        cmp r8d,BN_CLICKED shl 16 + ID_SEND_ICO
        je      wmSEND_ICO
cmp r8d,BN_CLICKED shl 16 + ID_SEND_WAV
        je      wmSEND_WAV
cmp     r8d,BN_CLICKED shl 16 + IDCANCEL
        jne     wmBYE
wmCLOSE:invoke EndDialog,,0
wmBYE: xor eax,eax
leave
retn
DialogProc endp
;---------------------------------------
szWin db 'Mailslot Reciever',0
szMailslotName db "\\.\mailslot\brer_Rabbit",0; Имя создаваемого канала
wav_file db '..\Images\03.wav',0
p1 dd 1
end
--- End code ---
05s.rc
--- Code: ---#include "resource.h"
#define ID_TXT 100
#define ID_SEND_TXT 101
#define ID_SEND_ICO 102
#define ID_SEND_WAV 103
#define IDC_IMG1 104

#define IDC_DIALOG 200
#define IDC_ICON1 500

IDC_ICON1 ICON "..\\Images\\icon1.ico"
IDC_ICON2 ICON "..\\Images\\icon2.ico"

IDC_DIALOG DIALOGEX 0, 0, 212, 154
STYLE DS_MODALFRAME | DS_CENTER | WS_CAPTION | WS_MINIMIZEBOX |
WS_SYSMENU | WS_VISIBLE | WS_OVERLAPPED | DS_MODALFRAME | DS_3DLOOK
CAPTION "Mailslot Sender"
{
CONTROL "",-1,BUTTON,BS_GROUPBOX | WS_CHILD | WS_VISIBLE,2,-1,207,24
CONTROL "",IDC_IMG1,STATIC,SS_ICON | WS_CHILD | WS_VISIBLE,3,40,128,128
CONTROL "Write something and click 'Send Text'",ID_TXT,EDIT,ES_LEFT |
ES_AUTOHSCROLL|WS_CHILD|WS_VISIBLE|WS_BORDER|WS_TABSTOP,5,7,199,13
CONTROL "Send Text", ID_SEND_TXT, BUTTON, BS_DEFPUSHBUTTON | WS_CHILD |
WS_VISIBLE | WS_TABSTOP, 149, 27, 60, 15
CONTROL "Send ICO", ID_SEND_ICO, BUTTON, BS_PUSHBUTTON | WS_CHILD |
WS_VISIBLE | WS_TABSTOP, 149, 45, 60, 15
CONTROL "Send WAV", ID_SEND_WAV, BUTTON, BS_PUSHBUTTON | WS_CHILD |
WS_VISIBLE | WS_TABSTOP, 149, 65, 60, 15
CONTROL "Exit",IDCANCEL,BUTTON,BS_PUSHBUTTON | WS_CHILD | WS_VISIBLE |
WS_TABSTOP, 149, 85, 60, 15
}
--- End code ---

Navigation

[0] Message Index

[#] Next page

Go to full version