-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathremote_client.pb
More file actions
2655 lines (2268 loc) · 107 KB
/
Copy pathremote_client.pb
File metadata and controls
2655 lines (2268 loc) · 107 KB
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
EnableExplicit
IncludeFile "Curve64Unicode.pb"
Structure settingsStructure
host.s
port.i
name.s
pass.s
isPaired.i
Role.i
isAuthorized.i
Connect.i
dis.i
isWaitPart.i
isBroadcast.i
isReadyRecieve.i
canvasH.i
canvasW.i
frameW.i
frameH.i
imgquality.i
isChangeQuality.i
quit.i
thrCN.i
thrMS.i
thrAP.i
thrCNquit.i
thrMSquit.i
thrAPquit.i
delayTime.i
clipboardtext.s
Newclipboardtext.s
clipboardfilename.s
Newclipboardfilename.s
lastpingTimer.i
isAskPair.i
AskPairName.s
AskPairTime.i
AskWinState.i
PrivateKey.s
CPublicKey.s
Secret.s
*SecretBuf32
RanD.s
currentJob.i
IamFileTranciever.i
IamsendallFiles.i
IamFileTrancieverName.s
IamFileReciever.i
TransferFileUploaded.i
TransferFilesize.i
TransferName.s
WpartX.i
WpartY.i
partX.i
partY.i
EndStructure
Structure jobtructure
*pointer
WpartX.i
WpartY.i
partX.i
partY.i
EndStructure
Structure ClientsListStructure
isOnline.i
EndStructure
Enumeration
#File
#File2
EndEnumeration
Enumeration
#CanvasGaget
#EditorGaget
#StringGadgetClid
#ButtonGadgetClCon
#ButtonGadgetClCloseCon
#ComboGadgetClid
#SpinGagetImgQuality
#set_clipboard_id
#ButtonGadgetRequestYes
#ButtonGadgetRequestNo
#txtRequestGadget
#AutoPairCheckBox
#ButtonGadgetPassOk
#StringGadgetPass
#ButtonGadgetClADD
#ButtonGadgetTransferToRemote
#ButtonGadgetTransferFromRemote
#ButtonGadgetServer
#IPGadget
#ButtonIPSave
EndEnumeration
#askpair_id = 1
#login_id = 2
#answerpair_id = 3
#text_id = 4
#imagetransfer_id = 5
#sendpart_id = 6
#ping_id = 7
#autopair_id = 8
#askfileclip_id = 9
#filepart_id = 10
#continue_id = 11
#minDelay = 40
#maxDelay = 500
#maxtcp = 65536
#MB = 1024*1024
#GB = 1024*1024*1024
#align_size = 256
#CAPTUREBLT = $40000000
Define *CurveP, *CurveGX, *CurveGY, *Curveqn
*CurveP = Curve::m_getCurveValues()
*CurveGX = *CurveP+32
*CurveGY = *CurveP+64
*Curveqn = *CurveP+96
Define NewMap ClientsList.ClientsListStructure()
Define NewMap settings.settingsStructure()
Define Dim Roles.s(2)
Roles(0)="Master":Roles(1)="Slave"
Define MutexConsole, sendMutex, ImgMutex
Define canvasMouseX, canvasMouseY, DroppedFrames, isInCnvasArea= #False, thrMS, thrAP
ImgMutex = CreateMutex()
MutexConsole = CreateMutex()
sendMutex = CreateMutex()
Define totalsended.f, Kbsecond.d, fps.d
Define NewMap req.jobtructure()
Define jobMutex = CreateMutex()
Define NewMap keybardmap()
Define SettingsFileName$="Clients.dat"
Procedure SPrint(text$)
Protected count
Shared MutexConsole
LockMutex(MutexConsole)
count = CountGadgetItems(#EditorGaget)
AddGadgetItem(#EditorGaget, 0, FormatDate("%hh:%ii:%ss ", Date())+" "+text$)
If count>10
RemoveGadgetItem(#EditorGaget, count-1)
EndIf
UnlockMutex(MutexConsole)
EndProcedure
Procedure.i SendQuestion(con_id,string$)
Protected err
Shared settings(), sendMutex, totalsended
If con_id
LockMutex(sendMutex)
settings("1")\lastpingTimer = ElapsedMilliseconds()
SendNetworkString(con_id,string$+#LF$,#PB_Unicode)
totalsended + StringByteLength(string$+#LF$, #PB_Unicode)/1024
Debug "send to socket :"+Str(con_id)+">"+string$
UnlockMutex(sendMutex)
EndIf
ProcedureReturn err
EndProcedure
Procedure.s cutHex(a$)
a$=Trim(UCase(a$))
If Left(a$,2)="0X"
a$=Mid(a$,3,Len(a$)-2)
EndIf
If Len(a$)=1
a$="0"+a$
EndIf
ProcedureReturn a$
EndProcedure
Procedure.s getElem(js.i,pname.s="",pelem.l=0,aelem.l=0)
Protected result$,jsFloat_g
result$=""
If IsJSON(js) And GetJSONMember(JSONValue(js), pname)
Select JSONType(GetJSONMember(JSONValue(js), pname))
Case #PB_JSON_String
result$= GetJSONString(GetJSONMember(JSONValue(js), pname))
Case #PB_JSON_Array
If JSONArraySize(GetJSONMember(JSONValue(js), pname))>pelem
Select JSONType(GetJSONElement(GetJSONMember(JSONValue(js), pname), pelem))
Case #PB_JSON_String
result$= GetJSONString(GetJSONElement(GetJSONMember(JSONValue(js), pname), pelem))
Case #PB_JSON_Number
result$= Str(GetJSONInteger(GetJSONElement(GetJSONMember(JSONValue(js), pname), pelem)))
jsFloat_g=GetJSONDouble(GetJSONElement(GetJSONMember(JSONValue(js), pname), pelem))
Case #PB_JSON_Array
If JSONArraySize(GetJSONElement(GetJSONMember(JSONValue(js), pname), pelem))>aelem
result$+ GetJSONString(GetJSONElement(GetJSONElement(GetJSONMember(JSONValue(js), pname), pelem),aelem))
EndIf
Case #PB_JSON_Boolean
result$=Str(GetJSONBoolean(GetJSONElement(GetJSONMember(JSONValue(js), pname), pelem)))
EndSelect
EndIf
Case #PB_JSON_Boolean
result$=Str(GetJSONBoolean(GetJSONMember(JSONValue(js), pname)))
Case #PB_JSON_Number
result$= Str(GetJSONInteger(GetJSONMember(JSONValue(js), pname)))
EndSelect
EndIf
ProcedureReturn result$
EndProcedure
Procedure.s commpressed2uncomressedPub(ha$)
Protected y_parity, ruc$, x$, a$, *a, *res
Shared *CurveP
*a = AllocateMemory(64)
*res=*a + 32
y_parity = Val(Left(ha$,2))-2
x$ = Right(ha$,Len(ha$)-2)
a$=RSet(x$, 64,"0")
Curve::m_sethex32(*a, a$)
Curve::m_YfromX64(*res,*a, *CurveP)
If PeekB(*res)&1<>y_parity
Curve::m_subModX64(*res,*CurveP,*res,*CurveP)
EndIf
ruc$ = Curve::m_gethex32(*res)
FreeMemory(*a)
ProcedureReturn x$+ruc$
EndProcedure
Procedure.s uncomressed2commpressedPub(ha$)
Protected x$,y$,ru$,rc$
ha$=LCase(ha$)
If Left(ha$,2)="04" And Len(ha$)=130
ha$=Right(ha$,Len(ha$)-2)
EndIf
x$=RSet(Left(ha$,64),64,"0")
y$=RSet(Right(ha$,64),64,"0")
ru$="04"+x$+y$
If FindString("13579bdf",Right(y$,1))>0
rc$="03"+x$
Else
rc$="02"+x$
EndIf
ProcedureReturn rc$
EndProcedure
Procedure.s GetPrivateKey()
Protected a$
a$ =Trim(ComputerName() + CPUName())
ProcedureReturn LCase(SHA1Fingerprint(@a$, StringByteLength(a$)))
EndProcedure
Procedure.s GetPublicKey(priv.s)
Protected a$, *a=AllocateMemory(32), *cx=AllocateMemory(32), *cy=AllocateMemory(32)
Shared *CurveGY, *CurveGX, *CurveP
Curve::m_sethex32(*a, priv)
Curve::m_PTMULX64(*cx, *cy, *CurveGx, *CurveGY, *a,*CurveP)
a$ = uncomressed2commpressedPub(Curve::m_gethex32(*cx) + Curve::m_gethex32(*cy))
FreeMemory(*a)
FreeMemory(*cx)
FreeMemory(*cy)
ProcedureReturn LCase(a$)
EndProcedure
Procedure.s GetSecretKey(priv.s, compressedPub.s)
Protected a$, *prv=AllocateMemory(32), *secr=AllocateMemory(32), *ax=AllocateMemory(32), *ay=AllocateMemory(32), *cx=AllocateMemory(32), *cy=AllocateMemory(32), uncompressedPub.s, x$, y$
Shared *CurveGY, *CurveGX, *CurveP
uncompressedPub = commpressed2uncomressedPub(compressedPub)
x$=RSet(Left(uncompressedPub,64),64,"0")
y$=RSet(Right(uncompressedPub,64),64,"0")
Curve::m_sethex32(*ax, x$)
Curve::m_sethex32(*ay, y$)
Curve::m_sethex32(*prv, priv)
Curve::m_PTMULX64(*cx, *cy, *ax, *ay, *prv,*CurveP)
a$ = Curve::m_gethex32(*cx)
FreeMemory(*prv)
FreeMemory(*ax)
FreeMemory(*ay)
FreeMemory(*cx)
FreeMemory(*cy)
ProcedureReturn LCase(a$)
EndProcedure
; some random generated data uisng CryptRandom()
; size of Key = 32 (AES-256Bits)
; size of InitVect = 16 (CBC)
; PaddingB64 is a random 64-char string needed for padding short strings used with Base64Encoding and AES
DataSection
ENC_InitVect:
Data.b $8C,$0D,$4E,$ED,$67,$96,$FB,$F0,$D3,$72,$87,$35,$3E,$BE,$42,$A2
ENC_PaddingB64:
Data.s "c1e39477b19d95223577a457960959be693060b0c683ec7aaf127d87807c6e02"
EndDataSection
Procedure.i _EncBuffer(*Input, *Output)
Shared settings()
If (MemorySize(*Input) >= 16) And (MemorySize(*Input) = MemorySize(*Output))
If AESEncoder(*Input, *Output, MemorySize(*Input), settings("1")\SecretBuf32, 256, ?ENC_InitVect, #PB_Cipher_CBC)
ProcedureReturn #True
EndIf
EndIf
ProcedureReturn #False ; AES cant encrypt a memory block with size < 16
EndProcedure
Procedure.i _DecBuffer(*Input, *Output)
Shared settings()
If (MemorySize(*Input) >= 16) And (MemorySize(*Input) = MemorySize(*Output))
If AESDecoder(*Input, *Output, MemorySize(*Input), settings("1")\SecretBuf32, 256, ?ENC_InitVect, #PB_Cipher_CBC)
ProcedureReturn #True
EndIf
EndIf
ProcedureReturn #False ; AES cant encrypt a memory block with size < 16
EndProcedure
Procedure.s EncString(in.s)
Protected paddStr.s, wrd.s, out.s, *p, *mb0, *mb1, *mb2, n0, n1, n2
If in = "" : ProcedureReturn "" : EndIf
Restore ENC_PaddingB64
Read.s paddStr
; we always padd as input could be too short
n0 = StringByteLength(paddStr) + StringByteLength(in) + SizeOf(Character)
*mb0 = AllocateMemory(n0) : *p = *mb0
CopyMemoryString(@paddStr, @*p)
CopyMemoryString(@in)
; encrypting using AES
n1 = n0
*mb1 = AllocateMemory(n1)
_EncBuffer(*mb0, *mb1)
; encoding encrypted buffer using Base64 to mask \0 if any (needed for PeekS())
n2 = n1 * 1.4
*mb2 = AllocateMemory(n2)
Base64Encoder(*mb1, n1, *mb2, n2)
; encrypted buffer is now ready for PeekS()
out = PeekS(*mb2)
FreeMemory(*mb0)
FreeMemory(*mb1)
FreeMemory(*mb2)
ProcedureReturn out
EndProcedure
Procedure.s DecString(in.s)
; decrypts a string encrypted with EncString()
Protected paddStr.s, wrd.s, out.s, *mb1, *mb2, n0, n1, n2
If in = "" : ProcedureReturn "" : EndIf
; decode encrypted string using Base64 --> encrypted-buffer
n0 = StringByteLength(in)
*mb1 = AllocateMemory(n0)
n1 = Base64Decoder(@in, n0, *mb1, n0)
*mb1 = ReAllocateMemory(*mb1, n1) ; adjust size fo encrypted-buffer!
n2 = n1
*mb2 = AllocateMemory(n2)
_DecBuffer(*mb1, *mb2)
wrd = PeekS(*mb2)
Restore ENC_PaddingB64
Read.s paddStr
If Mid(wrd, 1, Len(paddStr)) = paddStr
out = Mid(wrd, Len(paddStr)+1)
EndIf
FreeMemory(*mb1)
FreeMemory(*mb2)
ProcedureReturn out
EndProcedure
Procedure.s RanD()
Protected *Buffer=AllocateMemory(32), a$
Shared settings()
RandomData(*Buffer, 32)
a$ = SHA1Fingerprint(*Buffer, 32)
settings("1")\RanD = a$
FreeMemory(*Buffer)
ProcedureReturn a$
EndProcedure
Procedure AcceptSkipPair(isAccept)
Protected tempjson, get_work, Values, get_string.s
Shared settings()
tempjson = CreateJSON(#PB_Any)
If tempjson
get_work = SetJSONObject(JSONValue(tempjson))
SetJSONInteger(AddJSONMember(get_work, "id"), #answerpair_id)
SetJSONString(AddJSONMember(get_work, "method"), "answerpair")
Values =SetJSONArray(AddJSONMember(get_work, "params"))
SetJSONString(AddJSONElement(Values), settings("1")\AskPairName)
If isAccept
SetJSONString(AddJSONElement(Values), RanD())
Else
SetJSONString(AddJSONMember(get_work, "error"), "Connection skiped")
EndIf
SetJSONBoolean(AddJSONMember(get_work, "result"), isAccept)
get_string=ComposeJSON(tempjson)
FreeJSON(tempjson)
SendQuestion(settings("1")\Connect,get_string)
EndIf
EndProcedure
Procedure IamReadytoContinue()
Protected tempjson, get_work, Values, get_string.s
Shared settings()
tempjson = CreateJSON(#PB_Any)
If tempjson
get_work = SetJSONObject(JSONValue(tempjson))
SetJSONInteger(AddJSONMember(get_work, "id"), #continue_id)
SetJSONString(AddJSONMember(get_work, "method"), "continue")
get_string=ComposeJSON(tempjson)
FreeJSON(tempjson)
SendQuestion(settings("1")\Connect,get_string)
EndIf
EndProcedure
Procedure AskPair(pairname$)
Protected tempjson, get_work, send_string.s, Values
Shared settings()
If settings("1")\isAuthorized And settings("1")\Connect
tempjson = CreateJSON(#PB_Any)
If tempjson
get_work = SetJSONObject(JSONValue(tempjson))
SetJSONInteger(AddJSONMember(get_work, "id"), #askpair_id)
SetJSONString(AddJSONMember(get_work, "method"), "askpair")
Values =SetJSONArray(AddJSONMember(get_work, "params"))
SetJSONString(AddJSONElement(Values), pairname$)
send_string=ComposeJSON(tempjson)
FreeJSON(tempjson)
EndIf
SendQuestion(settings("1")\Connect,send_string)
EndIf
EndProcedure
Procedure AskFileClipBoard()
Protected tempjson, get_work, send_string.s, Values
Shared settings()
If settings("1")\isAuthorized And settings("1")\Connect
tempjson = CreateJSON(#PB_Any)
If tempjson
get_work = SetJSONObject(JSONValue(tempjson))
SetJSONInteger(AddJSONMember(get_work, "id"), #askfileclip_id)
SetJSONString(AddJSONMember(get_work, "method"), "askfileclip")
send_string=ComposeJSON(tempjson)
FreeJSON(tempjson)
EndIf
SendQuestion(settings("1")\Connect,send_string)
EndIf
EndProcedure
Procedure AskSendingData(frameid, full_size, computeCRC32file, WpartX, WpartY, partX, partY)
Protected tempjson, get_work, send_string.s, Values, clip$
Shared settings()
If settings("1")\isAuthorized And settings("1")\Connect And settings("1")\isBroadcast
tempjson = CreateJSON(#PB_Any)
If tempjson
get_work = SetJSONObject(JSONValue(tempjson))
SetJSONInteger(AddJSONMember(get_work, "id"), #sendpart_id)
SetJSONString(AddJSONMember(get_work, "method"), "datapart")
Values =SetJSONArray(AddJSONMember(get_work, "params"))
SetJSONInteger(AddJSONElement(Values), full_size)
SetJSONString(AddJSONElement(Values), Hex(computeCRC32file))
SetJSONInteger(AddJSONElement(Values), WpartX)
SetJSONInteger(AddJSONElement(Values), WpartY)
SetJSONInteger(AddJSONElement(Values), partX)
SetJSONInteger(AddJSONElement(Values), partY)
SetJSONInteger(AddJSONElement(Values), frameid)
clip$ = GetClipboardText()
If settings("1")\clipboardtext <> clip$ And clip$<>""
If settings("1")\Newclipboardtext= clip$
settings("1")\clipboardtext = clip$
Else
settings("1")\clipboardtext = clip$
settings("1")\Newclipboardtext = clip$
SetJSONString(AddJSONElement(Values), "t"+EncString(settings("1")\clipboardtext))
EndIf
ElseIf settings("1")\Newclipboardfilename <> settings("1")\clipboardfilename And settings("1")\Newclipboardfilename<>""
settings("1")\clipboardfilename = settings("1")\Newclipboardfilename
SetJSONString(AddJSONElement(Values), "f"+EncString(settings("1")\clipboardfilename))
EndIf
send_string=ComposeJSON(tempjson)
FreeJSON(tempjson)
EndIf
SendQuestion(settings("1")\Connect,send_string)
EndIf
EndProcedure
Procedure AskSendingFile(full_size, computeCRC32file, Name.s, isLastFile)
Protected tempjson, get_work, send_string.s, Values
Shared settings()
If settings("1")\isAuthorized And settings("1")\Connect And settings("1")\IamFileTranciever
tempjson = CreateJSON(#PB_Any)
If tempjson
get_work = SetJSONObject(JSONValue(tempjson))
SetJSONInteger(AddJSONMember(get_work, "id"), #filepart_id)
SetJSONString(AddJSONMember(get_work, "method"), "filepart")
Values =SetJSONArray(AddJSONMember(get_work, "params"))
SetJSONInteger(AddJSONElement(Values), full_size)
SetJSONString(AddJSONElement(Values), Hex(computeCRC32file))
SetJSONString(AddJSONElement(Values), Name)
SetJSONBoolean(AddJSONMember(get_work, "lastfile"), isLastFile)
send_string=ComposeJSON(tempjson)
FreeJSON(tempjson)
EndIf
SendQuestion(settings("1")\Connect,send_string)
EndIf
EndProcedure
Procedure sendPing()
Protected tempjson, get_work, send_string.s
Shared settings()
tempjson = CreateJSON(#PB_Any)
If settings("1")\isAuthorized And settings("1")\Connect
If tempjson
get_work = SetJSONObject(JSONValue(tempjson))
SetJSONInteger(AddJSONMember(get_work, "id"), #ping_id)
SetJSONString(AddJSONMember(get_work, "method"), "ping")
send_string=ComposeJSON(tempjson)
FreeJSON(tempjson)
SendQuestion(settings("1")\Connect,send_string)
EndIf
EndIf
EndProcedure
Procedure sendBackFrameId(frameid)
Protected tempjson, get_work, send_string.s, Values
Shared settings()
If settings("1")\isAuthorized And settings("1")\Connect
tempjson = CreateJSON(#PB_Any)
If tempjson
get_work = SetJSONObject(JSONValue(tempjson))
SetJSONInteger(AddJSONMember(get_work, "id"), #sendpart_id)
SetJSONInteger(AddJSONMember(get_work, "result"), frameid)
send_string=ComposeJSON(tempjson)
FreeJSON(tempjson)
SendQuestion(settings("1")\Connect,send_string)
EndIf
EndIf
EndProcedure
Procedure SendTextFrame(text.s)
Protected tempjson, get_work, send_string.s, Values
Shared settings()
If settings("1")\isAuthorized And settings("1")\Connect
tempjson = CreateJSON(#PB_Any)
If tempjson
get_work = SetJSONObject(JSONValue(tempjson))
SetJSONInteger(AddJSONMember(get_work, "id"), #text_id)
SetJSONString(AddJSONMember(get_work, "method"), "text")
Values =SetJSONArray(AddJSONMember(get_work, "params"))
SetJSONString(AddJSONElement(Values), text)
send_string=ComposeJSON(tempjson)
FreeJSON(tempjson)
SendQuestion(settings("1")\Connect,send_string)
EndIf
EndIf
EndProcedure
Procedure SendKeyFrame(symbol.i, isPresed)
Protected tempjson, get_work, send_string.s, Values
Static lastsymbol, lastisPresed
Shared settings()
If symbol<>lastsymbol Or lastisPresed<>isPresed
lastsymbol = symbol : lastisPresed = isPresed
If settings("1")\isAuthorized And settings("1")\Connect
tempjson = CreateJSON(#PB_Any)
If tempjson
get_work = SetJSONObject(JSONValue(tempjson))
SetJSONInteger(AddJSONMember(get_work, "id"), #text_id)
SetJSONString(AddJSONMember(get_work, "method"), "keyboard")
Values =SetJSONArray(AddJSONMember(get_work, "params"))
SetJSONString(AddJSONElement(Values), EncString("key:"+Str(symbol)+":"+Str(isPresed)))
send_string=ComposeJSON(tempjson)
FreeJSON(tempjson)
SendQuestion(settings("1")\Connect,send_string)
EndIf
EndIf
EndIf
EndProcedure
Procedure SendMouseFrame(posX, posY, isLBpressed, isMBpressed, isRBpressed, isWheel)
Protected tempjson, get_work, send_string.s, Values, scaleH.d, scaleW.d
Shared settings()
If settings("1")\isAuthorized And settings("1")\Connect And settings("1")\isReadyRecieve
scaleH = settings("1")\frameH / settings("1")\canvasH
scaleW = settings("1")\frameW / settings("1")\canvasW
tempjson = CreateJSON(#PB_Any)
If tempjson
get_work = SetJSONObject(JSONValue(tempjson))
SetJSONInteger(AddJSONMember(get_work, "id"), #text_id)
SetJSONString(AddJSONMember(get_work, "method"), "mouse")
Values =SetJSONArray(AddJSONMember(get_work, "params"))
SetJSONInteger(AddJSONElement(Values), scaleH * posX)
SetJSONInteger(AddJSONElement(Values), scaleW * posY)
SetJSONInteger(AddJSONElement(Values), isLBpressed)
SetJSONInteger(AddJSONElement(Values), isMBpressed)
SetJSONInteger(AddJSONElement(Values), isRBpressed)
SetJSONInteger(AddJSONElement(Values), isWheel)
send_string=ComposeJSON(tempjson)
FreeJSON(tempjson)
SendQuestion(settings("1")\Connect,send_string)
EndIf
EndIf
EndProcedure
Procedure SetQualityFrame(imgQuality)
Protected tempjson, get_work, send_string.s, Values
Shared settings()
If settings("1")\isAuthorized And settings("1")\Connect And settings("1")\isReadyRecieve
If imgQuality<0
imgQuality =0
ElseIf imgQuality>9
imgQuality = 9
EndIf
tempjson = CreateJSON(#PB_Any)
If tempjson
get_work = SetJSONObject(JSONValue(tempjson))
SetJSONInteger(AddJSONMember(get_work, "id"), #text_id)
SetJSONString(AddJSONMember(get_work, "method"), "setquality")
Values =SetJSONArray(AddJSONMember(get_work, "params"))
SetJSONInteger(AddJSONElement(Values), imgQuality)
send_string=ComposeJSON(tempjson)
FreeJSON(tempjson)
SendQuestion(settings("1")\Connect,send_string)
EndIf
EndIf
EndProcedure
Procedure SendClipboardTxt()
Protected tempjson, get_work, send_string.s, Values
Shared settings()
If settings("1")\isAuthorized And settings("1")\Connect And settings("1")\isReadyRecieve
tempjson = CreateJSON(#PB_Any)
If tempjson
get_work = SetJSONObject(JSONValue(tempjson))
SetJSONInteger(AddJSONMember(get_work, "id"), #set_clipboard_id)
SetJSONString(AddJSONMember(get_work, "method"), "setclipboardtxt")
Values =SetJSONArray(AddJSONMember(get_work, "params"))
SetJSONString(AddJSONElement(Values), EncString(settings("1")\clipboardtext))
send_string=ComposeJSON(tempjson)
FreeJSON(tempjson)
SendQuestion(settings("1")\Connect,send_string)
EndIf
EndIf
EndProcedure
Procedure Mouse_Wheel (Delta)
Protected In.INPUT
In\type = #INPUT_MOUSE;
In\mi\dwFlags = #MOUSEEVENTF_WHEEL
In\mi\mouseData = Delta*120
SendInput_(1,@In,SizeOf(INPUT))
EndProcedure
Procedure MouseSetPos(x.i, y.i)
SetCursorPos_(x, y)
EndProcedure
Procedure MouseLBdown()
mouse_event_(#MOUSEEVENTF_LEFTDOWN,0,0,0,0)
EndProcedure
Procedure MouseMBdown()
mouse_event_(#MOUSEEVENTF_MIDDLEDOWN,0,0,0,0)
EndProcedure
Procedure MouseRBdown()
mouse_event_(#MOUSEEVENTF_RIGHTDOWN,0,0,0,0)
EndProcedure
Procedure MouseLBup()
mouse_event_(#MOUSEEVENTF_LEFTUP,0,0,0,0)
EndProcedure
Procedure MouseRBup()
mouse_event_(#MOUSEEVENTF_RIGHTUP,0,0,0,0)
EndProcedure
Procedure MouseMBup()
mouse_event_(#MOUSEEVENTF_MIDDLEUP,0,0,0,0)
EndProcedure
Procedure CopyRectangle(*s,*t, w, h, linelenghtS, linelenghtT, depth)
Protected *localS, *localT, localH
*localS = *s
*localT = *t
localH = h
While localH
CopyMemory(*localS, *localT, w * depth)
*localS + linelenghtS
*localT + linelenghtT
localH -1
Wend
EndProcedure
Procedure.i m_check_equil(*s,*t, w, h, linelenght, depth)
Protected *localS, *localT, localH, result = 1
*localS = *s
*localT = *t
localH = h
While localH
If Not CompareMemory(*localS, *localT, w * depth)
result=0
Break
EndIf
*localS + linelenght
*localT + linelenght
localH -1
Wend
ProcedureReturn result
EndProcedure
Procedure getpart(h.i, part.i )
While h%part
part+1
Wend
ProcedureReturn part
EndProcedure
Procedure resizeCanvas(canvid.i, w.i, h.i)
Protected curwinW, curwinH, scalex.d, offsetTopY = 90, offsetBottomY = 20, offsetX = 10, newW, newH
Shared settings()
curwinW = WindowWidth(0)
curwinH = WindowHeight(0)
scalex = h / w
If curwinW>=w And curwinH>=h + offsetTopY + 5
newW = w
newH = h
offsetBottomY = 5
Else
newW = curwinW-20
newH = (curwinW-20) * scalex
EndIf
If newH + offsetTopY + offsetBottomY>curwinH
scalex = w / h
newH = curwinH - offsetTopY - offsetBottomY
newW = newH * scalex
EndIf
offsetX = (curwinW -newW)/2
offsetTopY = (curwinH-offsetTopY-newH)/2+offsetTopY
settings("1")\canvasH = newH
settings("1")\canvasW = newW
ResizeGadget(#CanvasGaget, offsetX, offsetTopY, settings("1")\canvasW, settings("1")\canvasH)
If IsImage(1) And IsImage(5)
If settings("1")\canvasH = h And settings("1")\canvasW = w
SetGadgetAttribute(#CanvasGaget, #PB_Canvas_Image , ImageID(1))
Else
scalex = h/w
CopyImage(1, 5)
curwinW = settings("1")\canvasW
If Not ResizeImage(5, curwinW , curwinW*scalex)
Debug "gg"
EndIf
SetGadgetAttribute(#CanvasGaget, #PB_Canvas_Image , ImageID(5))
EndIf
EndIf
EndProcedure
Procedure addPart(i)
Protected msginit$="[ADDPART]", *Buffer, *BufferAES, WpartX, WpartY, partX, partY, jobkey$, j, currentJob, precurrentJob, isInform=#False
Protected w, h, *ImageAddress, depth, size, *buftemp, *buftemp_unalign, buflinewidth, buflinewidthOld, scalex.d, buflinewidth2img, insecondsend, speed.f
Protected imagsize, possize, *posArray, copiedElements, *pointerPosAyyay, *bufPointer, ix, jx, addpointerx, addpointer, curwinW, curwinH, newheight, copiedElementsTemp
Protected filename$, TransferFilesize, computeCRC32file, totalloadbytes, maxloadbytes, loadedBytes, *pp, resultUploadedBytes, boxw.f, lastboxupdatetimer, totaltransferfiles, starttime
Shared settings(), req(), jobMutex, totalsended, DroppedFrames
settings("1")\thrAP = 1
Repeat
If isInform = #True And settings("1")\isReadyRecieve=#False
Sprint(msginit$+" Thread stoped")
isInform = #False
EndIf
If settings("1")\thrAPquit = #False
If isInform = #False And settings("1")\isReadyRecieve=#True
Sprint(msginit$+" Thread started")
isInform = #True
If IsImage(1)
FreeImage(1)
HideGadget(#CanvasGaget, 1)
HideGadget(#SpinGagetImgQuality, 1)
HideGadget(#ButtonGadgetServer, 0)
EndIf
EndIf
If settings("1")\isReadyRecieve=#True
If settings("1")\IamFileTranciever = #False
If settings("1")\IamFileReciever = #False
If MapSize(req())>0
If settings("1")\thrAPquit = #False And settings("1")\isReadyRecieve=#True
currentJob + 1
jobkey$ = Str(currentJob)
LockMutex(jobMutex)
If Not FindMapElement(req(), jobkey$)
Sprint(msginit$+" Can`t find map["+jobkey$+"]")
EndIf
*Buffer = req(jobkey$)\pointer
WpartX = req(jobkey$)\WpartX
WpartY = req(jobkey$)\WpartY
settings()\WpartX = WpartX
settings()\WpartY = WpartY
partX = req(jobkey$)\partX
partY = req(jobkey$)\partY
settings()\partX=partX
settings()\partY=partY
size = MemorySize(req(jobkey$)\pointer)
UnlockMutex(jobMutex)
copiedElements = PeekU(*Buffer)
possize = 2 + copiedElements * 4
imagsize = size - possize
*BufferAES = AllocateMemory(imagsize)
AESDecoder(*Buffer + possize, *BufferAES, MemorySize(*BufferAES), settings("1")\SecretBuf32, 256, ?ENC_InitVect, #PB_Cipher_CBC)
If Not CatchImage(2, *BufferAES, imagsize)
Sprint(msginit$+" Can`t catch image")
settings("1")\dis = #True
EndIf
FreeMemory(*BufferAES)
If settings("1")\dis = #False
Debug ">>>>copiedElements:" + Str(copiedElements)
*posArray = AllocateMemory(possize - 2)
CopyMemory(*Buffer + 2, *posArray, possize - 2)
LockMutex(jobMutex)
FreeMemory(req(jobkey$)\pointer)
DeleteMapElement(req(), jobkey$)
UnlockMutex(jobMutex)
w = WpartX * partX
h = WpartY * partY
settings("1")\frameW = w
settings("1")\frameH = h
StartDrawing(ImageOutput(2))
*ImageAddress = DrawingBuffer()
depth = ImageDepth(2)/8
buflinewidth = DrawingBufferPitch()
imagsize = buflinewidth * OutputHeight()
Debug ">>>>buflinewidth:"+Str(buflinewidth)
size = w * h * depth
If *buftemp_unalign
If MemorySize(*buftemp_unalign)<>size+#align_size
Debug "NEWW"
FreeMemory(*buftemp_unalign)
*buftemp_unalign = AllocateMemory(size+#align_size, #PB_Memory_NoClear)
*buftemp= *buftemp_unalign + #align_size-(*buftemp_unalign % #align_size)
EndIf
Else
*buftemp_unalign = AllocateMemory(size+#align_size, #PB_Memory_NoClear)
*buftemp= *buftemp_unalign + #align_size-(*buftemp_unalign % #align_size)
EndIf
CopyMemory(*ImageAddress, *buftemp, imagsize)
StopDrawing()
FreeImage(2)
buflinewidthOld = buflinewidth
If IsImage(1)
If ImageWidth(1)<>w Or ImageHeight(1)<>h
FreeImage(1)
CreateImage(1, w, h, depth * 8)
resizeCanvas(#CanvasGaget, w, h)
StartDrawing(CanvasOutput(#CanvasGaget))
FillMemory(DrawingBuffer(), DrawingBufferPitch() * OutputHeight(), $FF)
StopDrawing()
EndIf
Else
HideGadget(#CanvasGaget, 0)
HideGadget(#SpinGagetImgQuality, 0)
resizeCanvas(#CanvasGaget, w, h)
CreateImage(1, w, h, depth * 8)
HideGadget(#ButtonGadgetServer, 1)
EndIf
StartDrawing(ImageOutput(1))
*ImageAddress = DrawingBuffer()
buflinewidth= DrawingBufferPitch()
*bufPointer = *buftemp
*pointerPosAyyay = *posArray
jx = 0
ix = 0
copiedElementsTemp = copiedElements
While copiedElementsTemp
j = PeekU(*pointerPosAyyay)
i = PeekU(*pointerPosAyyay + 2)
*pointerPosAyyay + 4
addpointer = i * WpartY * buflinewidth + j * WpartX * depth
addpointerx = ix * WpartY * buflinewidthOld + jx * WpartX * depth
CopyRectangle( *bufPointer + addpointerx, *ImageAddress + addpointer, WpartX, WpartY, buflinewidthOld, buflinewidth, depth)
jx+1
If jx>=partX
ix+1
jx=0
EndIf
copiedElementsTemp - 1
Wend
StopDrawing()
CopyImage(1, 5)
;StartDrawing(ImageOutput(5))
;DrawingMode(#PB_2DDrawing_Outlined )
;copiedElementsTemp = copiedElements
;*pointerPosAyyay = *posArray
;While copiedElementsTemp
;j = PeekU(*pointerPosAyyay)
;i = PeekU(*pointerPosAyyay + 2)
;*pointerPosAyyay + 4
;Box(j * WpartX, h-(i+1) * WpartY, WpartX, WpartY, #Red)
;copiedElementsTemp-1
;Wend
;DrawingMode(#PB_2DDrawing_Default )
;StopDrawing()
If settings("1")\canvasH = h And settings("1")\canvasW = w
Debug "No resize"
SetGadgetAttribute(#CanvasGaget, #PB_Canvas_Image , ImageID(5))
Else
scalex = h/w