mirror of
https://github.com/Waujito/youtubeUnblock.git
synced 2024-12-22 06:15:31 +00:00
Fix getrandom on older versions
This commit is contained in:
parent
e9b033ccca
commit
05cc0054d8
4
args.h
4
args.h
@ -1,6 +1,3 @@
|
||||
#include "utils.h"
|
||||
#include "tls.h"
|
||||
|
||||
#ifndef ARGS_H
|
||||
#define ARGS_H
|
||||
|
||||
@ -11,5 +8,4 @@ int parse_args(int argc, char *argv[]);
|
||||
/* Prints starting messages */
|
||||
void print_welcome();
|
||||
|
||||
|
||||
#endif /* ARGS_H */
|
||||
|
22
tls.c
22
tls.c
@ -5,8 +5,8 @@
|
||||
#include "utils.h"
|
||||
|
||||
#ifndef KERNEL_SPACE
|
||||
#include <stdlib.h>
|
||||
#include <sys/random.h>
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
#define TLS_CONTENT_TYPE_HANDSHAKE 0x16
|
||||
@ -274,6 +274,8 @@ int gen_fake_sni(struct fake_type type,
|
||||
const struct tcphdr *tcph, uint32_t tcph_len,
|
||||
uint8_t *buf, uint32_t *buflen) {
|
||||
uint32_t data_len = type.fake_len;
|
||||
int ret;
|
||||
|
||||
if (type.type == FAKE_PAYLOAD_RANDOM && data_len == 0) {
|
||||
data_len = (uint32_t)randint() % 1200;
|
||||
}
|
||||
@ -317,9 +319,21 @@ int gen_fake_sni(struct fake_type type,
|
||||
default: // FAKE_PAYLOAD_RANDOM
|
||||
#ifdef KERNEL_SPACE
|
||||
get_random_bytes(bfdptr, data_len);
|
||||
#else
|
||||
#else /* KERNEL_SPACE */
|
||||
#if _NO_GETRANDOM
|
||||
ret = open("/dev/urandom", O_RDONLY);
|
||||
if (ret < 0) {
|
||||
lgerror("Unable to open /dev/urandom", ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
read(ret, bfdptr, data_len);
|
||||
close(ret);
|
||||
|
||||
#else /* _NO_GETRANDOM */
|
||||
getrandom(bfdptr, data_len, 0);
|
||||
#endif
|
||||
#endif /* _NO_GETRANDOM */
|
||||
#endif /* KERNEL_SPACE */
|
||||
}
|
||||
|
||||
if (ipxv == IP4VERSION) {
|
||||
|
6
types.h
6
types.h
@ -14,7 +14,13 @@
|
||||
#include <stdint.h> // IWYU pragma: export
|
||||
#include <string.h> // IWYU pragma: export
|
||||
#include <stdlib.h> // IWYU pragma: export
|
||||
|
||||
|
||||
#define _NO_GETRANDOM ((__GLIBC__ <= 2 && __GLIBC_MINOR__ < 25))
|
||||
|
||||
#if !_NO_GETRANDOM
|
||||
#include <sys/random.h> // IWYU pragma: export
|
||||
#endif
|
||||
|
||||
#endif /* SPACES */
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user