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
|
/* $Id$ */
/*
* (C) Copyright 2009 Jakub Zawadzki <darkjames@darkjames.ath.cx>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License Version
* 2.1 as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307,
* USA.
*/
#ifndef LIBGADU_INTERNAL_H
#define LIBGADU_INTERNAL_H
#include "libgadu.h"
#define GG_DEFAULT_CLIENT_VERSION_100 "10.1.0.11070"
#define GG_DEFAULT_CLIENT_VERSION_110 "11.3.45.10771"
#ifdef _WIN32
# ifdef __COVERITY__
# define GG_SIZE_FMT "lu"
# define _GG_INT64_MODIFIER "ll"
# undef PRIu64
# undef PRIx64
# undef PRId64
# else
# define GG_SIZE_FMT "Iu"
# define _GG_INT64_MODIFIER "I64"
# endif
#elif defined(_LP64)
# define GG_SIZE_FMT "zu"
# define _GG_INT64_MODIFIER "l"
#else
# define GG_SIZE_FMT "zu"
# define _GG_INT64_MODIFIER "ll"
#endif
#ifndef PRIu64
# define PRIu64 _GG_INT64_MODIFIER "u"
#endif
#ifndef PRIx64
# define PRIx64 _GG_INT64_MODIFIER "x"
#endif
#ifndef PRId64
# define PRId64 _GG_INT64_MODIFIER "d"
#endif
#define GG_LOGIN_PARAMS_HAS_FIELD(glp, member) \
(offsetof(struct gg_login_params, member) < (glp)->struct_size || \
offsetof(struct gg_login_params, member) <= offsetof(struct gg_login_params, struct_size))
#ifdef __GNUC__
# define GG_UNUSED __attribute__ ((unused))
# define GG_NORETURN __attribute__ ((noreturn))
# define GG_CDECL __attribute__ ((__cdecl__))
#else
# define GG_UNUSED
# define GG_NORETURN
# define GG_CDECL
#endif
#define GG_STATIC_ASSERT(condition, message) \
{ typedef char static_assertion_failed_ ## message \
[(condition) ? 1 : -1]; static_assertion_failed_ ## message dummy; \
(void)dummy; }
#define GG_IMGOUT_WAITING_MAX 4
struct gg_dcc7_relay {
uint32_t addr;
uint16_t port;
uint8_t family;
};
typedef struct _gg_chat_list gg_chat_list_t;
struct _gg_chat_list {
uint64_t id;
uint32_t version;
uint32_t participants_count;
uin_t *participants;
gg_chat_list_t *next;
};
typedef struct _gg_msg_list gg_msg_list_t;
struct _gg_msg_list {
int seq;
uin_t *recipients;
size_t recipients_count;
gg_msg_list_t *next;
};
typedef struct _gg_eventqueue gg_eventqueue_t;
struct _gg_eventqueue {
struct gg_event *event;
gg_eventqueue_t *next;
};
typedef struct _gg_imgout_queue_t gg_imgout_queue_t;
struct _gg_imgout_queue_t {
struct gg_send_msg msg_hdr;
char buf[1910];
size_t buf_len;
gg_imgout_queue_t *next;
};
struct gg_session_private {
gg_compat_t compatibility;
gg_chat_list_t *chat_list;
gg_msg_list_t *sent_messages;
gg_eventqueue_t *event_queue;
int check_after_queue;
int fd_after_queue;
gg_imgout_queue_t *imgout_queue;
int imgout_waiting_ack;
gg_socket_manager_type_t socket_manager_type;
gg_socket_manager_t socket_manager;
void *socket_handle;
int socket_next_state;
int socket_is_external;
enum gg_failure_t socket_failure;
int time_diff;
int dummyfds_created;
int dummyfds[2];
char **host_white_list;
};
typedef enum
{
GG_COMPAT_FEATURE_ACK_EVENT,
GG_COMPAT_FEATURE_LEGACY_CONFER
} gg_compat_feature_t;
typedef struct gg_dcc7_relay gg_dcc7_relay_t;
void * gg_new0(size_t size);
int gg_required_proto(struct gg_session *gs, int protocol_version);
int gg_get_dummy_fd(struct gg_session *sess);
int gg_compat_feature_is_enabled(struct gg_session *sess, gg_compat_feature_t feature);
int gg_pubdir50_handle_reply_sess(struct gg_session *sess, struct gg_event *e, const char *packet, int length);
int gg_resolve(int *fd, int *pid, const char *hostname);
int gg_resolve_pthread(int *fd, void **resolver, const char *hostname);
void gg_resolve_pthread_cleanup(void *resolver, int kill);
int gg_login_hash_sha1_2(const char *password, uint32_t seed, uint8_t *result);
int gg_chat_update(struct gg_session *sess, uint64_t id, uint32_t version,
const uin_t *participants, unsigned int participants_count);
gg_chat_list_t *gg_chat_find(struct gg_session *sess, uint64_t id);
uin_t gg_str_to_uin(const char *str, int len);
uint64_t gg_fix64(uint64_t x);
void gg_connection_failure(struct gg_session *gs, struct gg_event *ge,
enum gg_failure_t failure);
time_t gg_server_time(struct gg_session *gs);
int gg_session_init_ssl(struct gg_session *gs);
void gg_close(struct gg_session *gs);
struct gg_event *gg_eventqueue_add(struct gg_session *sess);
void gg_compat_message_ack(struct gg_session *sess, int seq);
void gg_image_sendout(struct gg_session *sess);
void gg_strarr_free(char **strarr);
char ** gg_strarr_dup(char **strarr);
#ifdef _WIN32
#include <windows.h>
typedef struct {
void (*fnc)();
#ifdef _WIN64
uint8_t trap[12];
uint8_t original[12];
#else
uint8_t trap[7];
uint8_t original[7];
#endif
} gg_win32_hook_data_t;
#define gg_win32_hook(orig_func, hook_func, data) \
gg_win32_hook_f((void (*)())(orig_func), (void (*)())(hook_func), (data))
static inline void
gg_win32_hook_f(void (*orig_func)(), void (*hook_func)(), gg_win32_hook_data_t *data)
{
DWORD dPermission;
uint8_t trap[] = {
#ifdef _WIN64
0x48, 0xb8, 0, 0, 0, 0, 0, 0, 0, 0, /* mov rax, uint64_t */
0xff, 0xe0 /* jmp rax */
#else
0xB8, 0, 0, 0, 0, /* mov eax, uint32_t */
0xff, 0xe0 /* jmp eax */
#endif
};
#ifdef _WIN64
uint64_t addr = (uint64_t)hook_func;
memcpy(&trap[2], &addr, sizeof(addr));
#else
uint32_t addr = (uint32_t)hook_func;
memcpy(&trap[1], &addr, sizeof(addr));
#endif
VirtualProtect(orig_func, sizeof(trap),
PAGE_EXECUTE_READWRITE, &dPermission);
if (data != NULL) {
data->fnc = orig_func;
memcpy(data->trap, trap, sizeof(trap));
memcpy(data->original, orig_func, sizeof(trap));
}
memcpy(orig_func, trap, sizeof(trap));
VirtualProtect(orig_func, sizeof(trap),
dPermission, &dPermission);
}
static inline void
gg_win32_hook_set_enabled(gg_win32_hook_data_t *data, int enabled)
{
DWORD dPermission;
uint8_t *src;
if (enabled)
src = data->trap;
else
src = data->original;
VirtualProtect(data->fnc, sizeof(data->trap),
PAGE_EXECUTE_READWRITE, &dPermission);
memcpy(data->fnc, src, sizeof(data->trap));
VirtualProtect(data->fnc, sizeof(data->trap),
dPermission, &dPermission);
}
#endif /* _WIN32 */
#endif /* LIBGADU_INTERNAL_H */
|