Home
About
Blog
Products
Forum
Support
Contact
Sunbelt Computer Software
PL/B Language Development and Support
Home
About
Blog
Products
Forum
Support
Contact
TelegramCommunicationJS/hello.cpp at master · BaseMax/TelegramCommunicationJS · GitHub
Skip to content
Navigation Menu
Sign in
Appearance settings
Platform
AI CODE CREATION
GitHub Copilot
Write better code with AI
GitHub Copilot app
Direct agents from issue to merge
MCP Registry
Integrate external tools
DEVELOPER WORKFLOWS
Actions
Automate any workflow
Codespaces
Instant dev environments
Issues
Plan and track work
Code Review
Manage code changes
Code Quality
Enforce quality at merge
APPLICATION SECURITY
GitHub Advanced Security
Find and fix vulnerabilities
Code security
Secure your code as you build
Secret protection
Stop leaks before they start
EXPLORE
Why GitHub
Documentation
Blog
Changelog
Marketplace
View all features
Solutions
BY COMPANY SIZE
Enterprises
Small and medium teams
Startups
Nonprofits
BY USE CASE
App Modernization
DevSecOps
DevOps
CI/CD
View all use cases
BY INDUSTRY
Healthcare
Financial services
Manufacturing
Government
View all industries
View all solutions
Resources
EXPLORE BY TOPIC
AI
Software Development
DevOps
Security
View all topics
EXPLORE BY TYPE
Customer stories
Events & webinars
Ebooks & reports
Business insights
GitHub Skills
SUPPORT & SERVICES
Documentation
Customer support
Community forum
Trust center
Partners
View all resources
Open Source
COMMUNITY
GitHub Sponsors
Fund open source developers
PROGRAMS
Security Lab
Maintainer Community
GitHub Stars
Archive Program
REPOSITORIES
Topics
Trending
Collections
Enterprise
ENTERPRISE SOLUTIONS
Enterprise platform
AI-powered developer platform
AVAILABLE ADD-ONS
GitHub Advanced Security
Enterprise-grade security features
Copilot for Business
Enterprise-grade AI features
Premium Support
Enterprise-grade 24/7 support
Pricing
Search
/
Sign in
Sign up
Appearance settings
You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.
You switched accounts on another tab or window.
Reload
to refresh your session.
Dismiss alert
{{ message }}
BaseMax
/
TelegramCommunicationJS
Public
Notifications
You must be signed in to change notification settings
Fork
7
Star
29
Code
Issues
0
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Files
Expand file tree
master
Breadcrumbs
TelegramCommunicationJS
/
hello.cpp
Copy path
Blame
More file actions
Blame
More file actions
Latest commit
History
History
History
203 lines (154 loc) · 4.42 KB
master
Breadcrumbs
TelegramCommunicationJS
/
hello.cpp
Copy path
Top
File metadata and controls
Code
Blame
203 lines (154 loc) · 4.42 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
#
include
<
stdio.h
>
#
include
<
stdlib.h
>
#
include
<
cstring
>
#
include
<
emscripten.h
>
#
include
<
emscripten/websocket.h
>
#
include
<
emscripten/bind.h
>
#
include
<
time.h
>
#
include
"
myfunc.h
"
using
namespace
emscripten
;
unsigned
char
mode =
0
;
EMSCRIPTEN_WEBSOCKET_T
socket =
NULL
;
uint8_t
key[
32
];
uint8_t
iv[
16
];
uint8_t
revkey[
32
];
uint8_t
reviv[
16
];
void
_rnd
(
uint8_t
* array,
uint8_t
* revarray,
int
len){
for
(
int
i=
0
;i<len;i++){
uint8_t
t = (
uint8_t
)(
emscripten_random
()*
256
);
revarray[len-i-
1
] = t;
array[i] = t;
}
}
void
ar_ar
(
uint8_t
* dest,
uint8_t
* src,
int
len){
for
(
int
i=
0
;i<len;i++){
dest[i] = src[len-i];
}
}
void
ll_ar
(
uint8_t
* dest,
int64_t
src){
for
(
int
i=
0
;i<
8
;i++){
dest[i] = (src &
0x00000000000000ff
);
src >>=
8
;
}
}
void
l_ar
(
uint8_t
* dest,
int32_t
src){
for
(
int
i=
0
;i<
4
;i++){
dest[i] = (src &
0x000000ff
);
src >>=
8
;
}
}
void
reqpq
()
{
emscripten_pause_main_loop
();
uint8_t
in[
105
] ;
uint8_t
out[
64
];
uint8_t
enc_buf[
64
];
uint8_t
revin[
64
] ;
_rnd
(in,revin,
64
);
memcpy
(&out, &in[
0
],
64
);
memcpy
(&key, &in[
8
],
32
);
memcpy
(&iv, &in[
40
],
16
);
memcpy
(&revkey, &revin[
8
],
32
);
memcpy
(&reviv, &revin[
40
],
16
);
in[
56
]=
0xef
;
in[
57
]=
0xef
;
in[
58
]=
0xef
;
in[
59
]=
0xef
;
uint8_t
req_pq[
41
];
char
* ptrMsgID =
getNewMsgId
();
memcpy
(&req_pq[
1
], ptrMsgID ,
40
);
req_pq[
0
]=
0x0a
;
memcpy
(&in[
64
], &req_pq[
0
],
41
);
char
* ptrEncrypt =
mycrypt
(key, iv, in,
sizeof
(in));
memcpy
(&enc_buf, ptrEncrypt ,
sizeof
(enc_buf));
memcpy
(&req_pq, ptrEncrypt+
64
,
sizeof
(req_pq));
out[
56
]=enc_buf[
56
];
out[
57
]=enc_buf[
57
];
out[
58
]=enc_buf[
58
];
out[
59
]=enc_buf[
59
];
//
char* ptrDecrypt = mycrypt(key, iv, out, sizeof(out));
//
memcpy(&enc_buf, ptrDecrypt , sizeof(enc_buf));
//
rintf("enc \n"); for(int i= 0; i< 64;i++){printf(" %02x", enc_buf[i]);if(!((i+1) % 16))printf("\n");} printf("\n");
emscripten_websocket_send_binary
(socket, out,
sizeof
(out));
emscripten_websocket_send_binary
(socket, req_pq ,
sizeof
(req_pq));
emscripten_resume_main_loop
();
}
void
main_proc
() {
switch
(mode) {
case
0
: {
unsigned
short
readyState;
emscripten_websocket_get_ready_state
(socket, &readyState);
if
( readyState ==
1
) mode =
1
;
break
;
}
case
1
: {
reqpq
();
mode =
2
;
break
;
}
case
2
:{
mode =
3
;
}
}
printf
(
"
step %2x
\n
"
,mode);
}
EM_BOOL
WebSocketOpen
(
int
eventType,
const
EmscriptenWebSocketOpenEvent *e,
void
*userData)
{
return
0
;
}
EM_BOOL
WebSocketClose
(
int
eventType,
const
EmscriptenWebSocketCloseEvent *e,
void
*userData)
{
printf
(
"
close(eventType=%2x, wasClean=%2x, code=%2x, reason=%s, userData=%2x)
\n
"
, eventType, e->
wasClean
, e->
code
, e->
reason
, (
int
)userData);
return
0
;
}
EM_BOOL
WebSocketError
(
int
eventType,
const
EmscriptenWebSocketErrorEvent *e,
void
*userData)
{
printf
(
"
error(eventType=%2x, userData=%2x)
\n
"
, eventType, (
int
)userData);
return
0
;
}
EM_BOOL
WebSocketMessage
(
int
eventType,
const
EmscriptenWebSocketMessageEvent *e,
void
*userData)
{
printf
(
"
message(eventType=%2x, userData=%2x, data=%p, numBytes=%2x, isText=%2x)
\n
"
, eventType, (
int
)userData, e->
data
, e->
numBytes
, e->
isText
);
if
(e->
isText
)
printf
(
"
text data:
\"
%s
\"\n
"
, e->
data
);
else
{
printf
(
"
binary data:
"
);
for
(
int
i =
0
; i < e->
numBytes
; ++i)
printf
(
"
%02X
"
, e->
data
[i]);
printf
(
"
\n
"
);
//
emscripten_websocket_delete(e->socket);
char
* ptrDecrypt =
mycrypt
(revkey, reviv, e->
data
, e->
numBytes
);
printf
(
"
binary data:
"
);
for
(
int
i =
0
; i < e->
numBytes
; ++i)
printf
(
"
%02X
"
, (
uint8_t
)*ptrDecrypt++);
printf
(
"
\n
"
);
emscripten_run_script
(
"
alert('look console.log')
"
);
}
return
0
;
}
void
EMSCRIPTEN_KEEPALIVE
connect
(std::string url)
{
if
(!
emscripten_websocket_is_supported
())
{
printf
(
"
WebSockets are not supported, cannot continue!
\n
"
);
exit
(
1
);
}
EmscriptenWebSocketCreateAttributes attr;
emscripten_websocket_init_create_attributes
(&attr);
attr.
url
= url.
c_str
();
socket =
emscripten_websocket_new
(&attr);
if
(socket <=
0
)
{
printf
(
"
WebSocket creation failed, error code %2x!
\n
"
, (
EMSCRIPTEN_RESULT
)socket);
exit
(
1
);
}
emscripten_websocket_set_onopen_callback
(socket, (
void
*)
42
, WebSocketOpen);
emscripten_websocket_set_onclose_callback
(socket, (
void
*)
43
, WebSocketClose);
emscripten_websocket_set_onerror_callback
(socket, (
void
*)
44
, WebSocketError);
emscripten_websocket_set_onmessage_callback
(socket, (
void
*)
45
, WebSocketMessage);
emscripten_set_main_loop
(main_proc,
60
,
0
);
}
EMSCRIPTEN_BINDINGS
(my_module) {
function
(
"
connect
"
, &connect);
}
You can’t perform that action at this time.