Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
T
tg
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
tg
Commits
77f56cfd
Commit
77f56cfd
authored
Jan 10, 2014
by
vysheng
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' of
https://github.com/antma/tg
Conflicts: tools.c
parents
3c3f1e79
286ffe8c
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
56 additions
and
49 deletions
+56
-49
main.c
main.c
+11
-4
mtproto-client.c
mtproto-client.c
+3
-17
mtproto-common.c
mtproto-common.c
+1
-1
mtproto-common.h
mtproto-common.h
+1
-1
net.c
net.c
+6
-3
net.h
net.h
+4
-4
queries.c
queries.c
+4
-19
tools.c
tools.c
+25
-0
tools.h
tools.h
+1
-0
No files found.
main.c
View file @
77f56cfd
...
...
@@ -180,12 +180,19 @@ char *make_full_path (char *s) {
return
s
;
}
void
running_for_first_time
(
void
)
{
if
(
sizeof
(
void
)
!=
1
)
{
logprintf
(
"sizeof (void) isn't equal 1
\n
"
);
logprintf
(
"GNU C compiler extension isn't available?
\n
"
);
void
check_type_sizes
(
void
)
{
if
(
sizeof
(
int
)
!=
4u
)
{
logprintf
(
"sizeof (int) isn't equal 4.
\n
"
);
exit
(
1
);
}
if
(
sizeof
(
char
)
!=
1u
)
{
logprintf
(
"sizeof (char) isn't equal 1.
\n
"
);
exit
(
1
);
}
}
void
running_for_first_time
(
void
)
{
check_type_sizes
();
if
(
config_filename
)
{
return
;
// Do not create custom config file
}
...
...
mtproto-client.c
View file @
77f56cfd
...
...
@@ -40,7 +40,6 @@
#include <netinet/in.h>
#include <netinet/tcp.h>
#include <poll.h>
#include <zlib.h>
#include "net.h"
#include "include.h"
...
...
@@ -1493,26 +1492,13 @@ void work_packed (struct connection *c, long long msg_id) {
int
l
=
prefetch_strlen
();
char
*
s
=
fetch_str
(
l
);
size_t
dl
=
MAX_PACKED_SIZE
;
z_stream
strm
;
memset
(
&
strm
,
0
,
sizeof
(
strm
));
assert
(
inflateInit2
(
&
strm
,
16
+
MAX_WBITS
)
==
Z_OK
);
strm
.
avail_in
=
l
;
strm
.
next_in
=
(
void
*
)
s
;
strm
.
avail_out
=
MAX_PACKED_SIZE
;
strm
.
next_out
=
(
void
*
)
buf
;
int
err
=
inflate
(
&
strm
,
Z_FINISH
);
if
(
verbosity
)
{
logprintf
(
"inflate error = %d
\n
"
,
err
);
logprintf
(
"inflated %d bytes
\n
"
,
(
int
)
strm
.
total_out
);
}
int
total_out
=
tinflate
(
s
,
l
,
buf
,
MAX_PACKED_SIZE
);
int
*
end
=
in_ptr
;
int
*
eend
=
in_end
;
assert
(
dl
%
4
==
0
);
//assert (total_out
% 4 == 0);
in_ptr
=
buf
;
in_end
=
in_ptr
+
strm
.
total_out
/
4
;
in_end
=
in_ptr
+
total_out
/
4
;
if
(
verbosity
>=
4
)
{
logprintf
(
"Unzipped data: "
);
hexdump_in
();
...
...
mtproto-common.c
View file @
77f56cfd
...
...
@@ -52,7 +52,7 @@ long long rsa_encrypted_chunks, rsa_decrypted_chunks;
BN_CTX
*
BN_ctx
;
int
verbosity
;
int
get_random_bytes
(
void
*
buf
,
int
n
)
{
int
get_random_bytes
(
unsigned
char
*
buf
,
int
n
)
{
int
r
=
0
,
h
=
open
(
"/dev/random"
,
O_RDONLY
|
O_NONBLOCK
);
if
(
h
>=
0
)
{
r
=
read
(
h
,
buf
,
n
);
...
...
mtproto-common.h
View file @
77f56cfd
...
...
@@ -427,7 +427,7 @@ static inline void fetch_ints (void *data, int count) {
in_ptr
+=
count
;
}
int
get_random_bytes
(
void
*
buf
,
int
n
);
int
get_random_bytes
(
unsigned
char
*
buf
,
int
n
);
int
pad_rsa_encrypt
(
char
*
from
,
int
from_len
,
char
*
to
,
int
size
,
BIGNUM
*
N
,
BIGNUM
*
E
);
int
pad_rsa_decrypt
(
char
*
from
,
int
from_len
,
char
*
to
,
int
size
,
BIGNUM
*
N
,
BIGNUM
*
D
);
...
...
net.c
View file @
77f56cfd
...
...
@@ -115,7 +115,8 @@ void delete_connection_buffer (struct connection_buffer *b) {
tfree
(
b
,
sizeof
(
*
b
));
}
int
write_out
(
struct
connection
*
c
,
const
void
*
data
,
int
len
)
{
int
write_out
(
struct
connection
*
c
,
const
void
*
_data
,
int
len
)
{
const
unsigned
char
*
data
=
_data
;
if
(
!
len
)
{
return
0
;
}
assert
(
len
>
0
);
int
x
=
0
;
...
...
@@ -146,7 +147,8 @@ int write_out (struct connection *c, const void *data, int len) {
return
x
;
}
int
read_in
(
struct
connection
*
c
,
void
*
data
,
int
len
)
{
int
read_in
(
struct
connection
*
c
,
void
*
_data
,
int
len
)
{
unsigned
char
*
data
=
_data
;
if
(
!
len
)
{
return
0
;
}
assert
(
len
>
0
);
if
(
len
>
c
->
in_bytes
)
{
...
...
@@ -177,7 +179,8 @@ int read_in (struct connection *c, void *data, int len) {
return
x
;
}
int
read_in_lookup
(
struct
connection
*
c
,
void
*
data
,
int
len
)
{
int
read_in_lookup
(
struct
connection
*
c
,
void
*
_data
,
int
len
)
{
unsigned
char
*
data
=
_data
;
if
(
!
len
||
!
c
->
in_bytes
)
{
return
0
;
}
assert
(
len
>
0
);
if
(
len
>
c
->
in_bytes
)
{
...
...
net.h
View file @
77f56cfd
...
...
@@ -93,10 +93,10 @@ struct dc_serialized {
};
struct
connection_buffer
{
void
*
start
;
void
*
end
;
void
*
rptr
;
void
*
wptr
;
unsigned
char
*
start
;
unsigned
char
*
end
;
unsigned
char
*
rptr
;
unsigned
char
*
wptr
;
struct
connection_buffer
*
next
;
};
...
...
queries.c
View file @
77f56cfd
...
...
@@ -20,7 +20,6 @@
#include <string.h>
#include <memory.h>
#include <stdlib.h>
#include <zlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
...
...
@@ -215,26 +214,12 @@ void query_result (long long id UU) {
fetch_int
();
int
l
=
prefetch_strlen
();
char
*
s
=
fetch_str
(
l
);
size_t
dl
=
MAX_PACKED_SIZE
;
z_stream
strm
;
memset
(
&
strm
,
0
,
sizeof
(
strm
));
assert
(
inflateInit2
(
&
strm
,
16
+
MAX_WBITS
)
==
Z_OK
);
strm
.
avail_in
=
l
;
strm
.
next_in
=
(
void
*
)
s
;
strm
.
avail_out
=
MAX_PACKED_SIZE
;
strm
.
next_out
=
(
void
*
)
packed_buffer
;
int
err
=
inflate
(
&
strm
,
Z_FINISH
);
if
(
verbosity
)
{
logprintf
(
"inflate error = %d
\n
"
,
err
);
logprintf
(
"inflated %d bytes
\n
"
,
(
int
)
strm
.
total_out
);
}
int
total_out
=
tinflate
(
s
,
l
,
packed_buffer
,
MAX_PACKED_SIZE
);
end
=
in_ptr
;
eend
=
in_end
;
assert
(
dl
%
4
==
0
);
//assert (total_out
% 4 == 0);
in_ptr
=
packed_buffer
;
in_end
=
in_ptr
+
strm
.
total_out
/
4
;
in_end
=
in_ptr
+
total_out
/
4
;
if
(
verbosity
>=
4
)
{
logprintf
(
"Unzipped data: "
);
hexdump_in
();
...
...
@@ -2329,7 +2314,7 @@ void do_create_keys_end (struct secret_chat *U) {
ensure_ptr
(
a
);
ensure
(
BN_mod_exp
(
r
,
g_b
,
a
,
p
,
ctx
));
void
*
t
=
talloc
(
256
);
unsigned
char
*
t
=
talloc
(
256
);
memcpy
(
t
,
U
->
key
,
256
);
memset
(
U
->
key
,
0
,
sizeof
(
U
->
key
));
...
...
tools.c
View file @
77f56cfd
...
...
@@ -24,10 +24,12 @@
#include <stdlib.h>
#include <string.h>
#include <openssl/err.h>
#include <zlib.h>
#include "interface.h"
#include "tools.h"
extern
int
verbosity
;
static
void
out_of_memory
(
void
)
{
logprintf
(
"Out of memory
\n
"
);
...
...
@@ -137,3 +139,26 @@ void ensure_ptr (void *p) {
out_of_memory
();
}
}
int
tinflate
(
void
*
input
,
int
ilen
,
void
*
output
,
int
olen
)
{
z_stream
strm
;
memset
(
&
strm
,
0
,
sizeof
(
strm
));
assert
(
inflateInit2
(
&
strm
,
16
+
MAX_WBITS
)
==
Z_OK
);
strm
.
avail_in
=
ilen
;
strm
.
next_in
=
input
;
strm
.
avail_out
=
olen
;
strm
.
next_out
=
output
;
int
err
=
inflate
(
&
strm
,
Z_FINISH
),
total_out
=
0
;
if
(
err
==
Z_OK
||
err
==
Z_STREAM_END
)
{
total_out
=
(
int
)
strm
.
total_out
;
if
(
err
==
Z_STREAM_END
&&
verbosity
>=
2
)
{
logprintf
(
"inflated %d bytes
\n
"
,
(
int
)
strm
.
total_out
);
}
}
if
(
verbosity
&&
err
!=
Z_STREAM_END
)
{
logprintf
(
"inflate error = %d
\n
"
,
err
);
logprintf
(
"inflated %d bytes
\n
"
,
(
int
)
strm
.
total_out
);
}
inflateEnd
(
&
strm
);
return
total_out
;
}
tools.h
View file @
77f56cfd
...
...
@@ -24,6 +24,7 @@ void *talloc (size_t size);
void
*
trealloc
(
void
*
ptr
,
size_t
old_size
,
size_t
size
);
void
*
talloc0
(
size_t
size
);
char
*
tstrdup
(
const
char
*
s
);
int
tinflate
(
void
*
input
,
int
ilen
,
void
*
output
,
int
olen
);
void
ensure
(
int
r
);
void
ensure_ptr
(
void
*
p
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment