Commit e5449329 authored by Max Lv's avatar Max Lv

refine

parent 01fbabb4
No preview for this file type
...@@ -11,7 +11,7 @@ static int random_compare(const void *_x, const void *_y) { ...@@ -11,7 +11,7 @@ static int random_compare(const void *_x, const void *_y) {
return (a % (x + i) - a % (y + i)); return (a % (x + i) - a % (y + i));
} }
static void md5(const unsigned char *text, unsigned char *digest) { static void md5(const uint8_t *text, uint8_t *digest) {
md5_state_t state; md5_state_t state;
md5_init(&state); md5_init(&state);
md5_append(&state, text, strlen((char*)text)); md5_append(&state, text, strlen((char*)text));
...@@ -119,7 +119,7 @@ static void merge_sort(uint8_t array[], int length) { ...@@ -119,7 +119,7 @@ static void merge_sort(uint8_t array[], int length) {
void encrypt(char *buf, int len, struct rc4_state *ctx) { void encrypt(char *buf, int len, struct rc4_state *ctx) {
if (ctx != NULL) { if (ctx != NULL) {
rc4_crypt(ctx, (unsigned char*) buf, (unsigned char*) buf, len); rc4_crypt(ctx, (uint8_t*) buf, (uint8_t*) buf, len);
} else { } else {
char *end = buf + len; char *end = buf + len;
while (buf < end) { while (buf < end) {
...@@ -131,7 +131,7 @@ void encrypt(char *buf, int len, struct rc4_state *ctx) { ...@@ -131,7 +131,7 @@ void encrypt(char *buf, int len, struct rc4_state *ctx) {
void decrypt(char *buf, int len, struct rc4_state *ctx) { void decrypt(char *buf, int len, struct rc4_state *ctx) {
if (ctx != NULL) { if (ctx != NULL) {
rc4_crypt(ctx, (unsigned char*) buf, (unsigned char*) buf, len); rc4_crypt(ctx, (uint8_t*) buf, (uint8_t*) buf, len);
} else { } else {
char *end = buf + len; char *end = buf + len;
while (buf < end) { while (buf < end) {
...@@ -150,7 +150,7 @@ void enc_ctx_init(struct rc4_state *ctx, int enc) { ...@@ -150,7 +150,7 @@ void enc_ctx_init(struct rc4_state *ctx, int enc) {
void enc_key_init(const char *pass) { void enc_key_init(const char *pass) {
enc_ctx.rc4.key_len = 16; enc_ctx.rc4.key_len = 16;
enc_ctx.rc4.key = malloc(16); enc_ctx.rc4.key = malloc(16);
md5((const unsigned char*)pass, enc_ctx.rc4.key); md5((const uint8_t*)pass, enc_ctx.rc4.key);
} }
void get_table(const char *pass) { void get_table(const char *pass) {
...@@ -159,7 +159,7 @@ void get_table(const char *pass) { ...@@ -159,7 +159,7 @@ void get_table(const char *pass) {
uint8_t digest[16]; uint8_t digest[16];
uint32_t i; uint32_t i;
md5((const unsigned char*)pass, digest); md5((const uint8_t*)pass, digest);
for (i = 0; i < 8; i++) { for (i = 0; i < 8; i++) {
_a += OFFSET_ROL(digest, i); _a += OFFSET_ROL(digest, i);
......
...@@ -21,7 +21,7 @@ union { ...@@ -21,7 +21,7 @@ union {
} table; } table;
struct { struct {
unsigned char *key; uint8_t *key;
int key_len; int key_len;
} rc4; } rc4;
} enc_ctx; } enc_ctx;
......
...@@ -30,14 +30,14 @@ static char *_remote_port; ...@@ -30,14 +30,14 @@ static char *_remote_port;
static int _timeout; static int _timeout;
static char *_key; static char *_key;
int setnonblocking(int fd) { static int setnonblocking(int fd) {
int flags; int flags;
if (-1 ==(flags = fcntl(fd, F_GETFL, 0))) if (-1 ==(flags = fcntl(fd, F_GETFL, 0)))
flags = 0; flags = 0;
return fcntl(fd, F_SETFL, flags | O_NONBLOCK); return fcntl(fd, F_SETFL, flags | O_NONBLOCK);
} }
int create_and_bind(const char *port) { static int create_and_bind(const char *port) {
struct addrinfo hints; struct addrinfo hints;
struct addrinfo *result, *rp; struct addrinfo *result, *rp;
int s, listen_sock; int s, listen_sock;
...@@ -178,7 +178,7 @@ static void server_recv_cb (EV_P_ ev_io *w, int revents) { ...@@ -178,7 +178,7 @@ static void server_recv_cb (EV_P_ ev_io *w, int revents) {
} }
char addr_to_send[256]; char addr_to_send[256];
unsigned char addr_len = 0; uint8_t addr_len = 0;
addr_to_send[addr_len++] = request->atyp; addr_to_send[addr_len++] = request->atyp;
// get remote addr and port // get remote addr and port
...@@ -191,14 +191,14 @@ static void server_recv_cb (EV_P_ ev_io *w, int revents) { ...@@ -191,14 +191,14 @@ static void server_recv_cb (EV_P_ ev_io *w, int revents) {
} else if (request->atyp == 3) { } else if (request->atyp == 3) {
// Domain name // Domain name
unsigned char name_len = *(unsigned char *)(server->buf + 4); uint8_t name_len = *(uint8_t *)(server->buf + 4);
addr_to_send[addr_len++] = name_len; addr_to_send[addr_len++] = name_len;
memcpy(addr_to_send + addr_len, server->buf + 4 + 1, name_len); memcpy(addr_to_send + addr_len, server->buf + 4 + 1, name_len);
addr_len += name_len; addr_len += name_len;
// get port // get port
addr_to_send[addr_len++] = *(unsigned char *)(server->buf + 4 + 1 + name_len); addr_to_send[addr_len++] = *(uint8_t *)(server->buf + 4 + 1 + name_len);
addr_to_send[addr_len++] = *(unsigned char *)(server->buf + 4 + 1 + name_len + 1); addr_to_send[addr_len++] = *(uint8_t *)(server->buf + 4 + 1 + name_len + 1);
} else { } else {
LOGE("unsupported addrtype: %d\n", request->atyp); LOGE("unsupported addrtype: %d\n", request->atyp);
close_and_free_remote(EV_A_ remote); close_and_free_remote(EV_A_ remote);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment