term_t bif_rc4_init1(term_t Key, process_t *ctx) { apr_byte_t *s; apr_byte_t i, j; apr_byte_t key_len; apr_byte_t *key_data; if (!is_binary(Key)) return A_BADARG; s = xalloc(proc_gc_pool(ctx), 256+2); //2 for i and j key_len = (apr_byte_t)int_value(bin_size(Key)); key_data = bin_data(Key); i = 0; do { s[i] = i++; } while (i != 0); i = j = 0; do { apr_byte_t temp; j += key_data[i%key_len]+s[i]; temp = s[i]; s[i] = s[j]; s[j] = temp; i++; } while (i != 0); s[256] = 0; s[257] = 0; result(make_binary(intnum(256+2), s, proc_gc_pool(ctx))); return AI_OK; }
char *autocomplete(int *index, char *str, t_cmd *cmd) { int star; t_bin *bin; int size; if (isatty(0) == 0) return (str); star = contain_star(&str[*index]); if (!(bin = xmalloc(sizeof(*bin)))) return (str); bin->next = NULL; if (is_first_word(str, *index) == 1 && str[0] != '.') { if (auto_binaries(cmd, str, bin) == -1) return (str); } else if (auto_file(str, index, bin, star) == -1) return (str); size = bin_size(bin); print_possibilities_or_not(bin, size); while (str[*index] != '\0' && str[*index] != ' ' && str[*index] != '\t') *index = *index + 1; if ((size > 0 && star == 0) || size == 1) str = autocomplete_replace(str, bin, index, cmd); replace_index(str, cmd, bin, index); return (str); }
ExprBinaryOp::ExprBinaryOp(const ExprNode& left, const ExprNode& right, const Dim& dim) : ExprNode( max_height(left,right)+1, bin_size(left,right), dim ), left(left), right(right) { ((ExprNode&) left).fathers.add(*this); ((ExprNode&) right).fathers.add(*this); }
term_t bif_md5_1(term_t Data, process_t *ctx) { apr_byte_t *digest = xalloc(proc_gc_pool(ctx), MD5_DIGESTSIZE); if (!is_binary(Data)) return A_BADARG; md5(digest, bin_data(Data), (apr_size_t)int_value(bin_size(Data))); result(make_binary(intnum(MD5_DIGESTSIZE), digest, proc_gc_pool(ctx))); return AI_OK; }
term_t bif_md5_update2(term_t Data, term_t Context, process_t *ctx) { apr_size_t size; md5_ctx_t *tmp; if (!is_binary(Data) || !is_binary(Context)) return A_BADARG; if (int_value2(bin_size(Context)) != sizeof(md5_ctx_t)) return A_BADARG; size = (apr_size_t)int_value(bin_size(Data)); tmp = xalloc(proc_gc_pool(ctx), sizeof(*tmp)); memcpy(tmp, bin_data(Context), sizeof(*tmp)); md5_update(tmp, bin_data(Data), size); result(make_binary(intnum(sizeof(*tmp)), (apr_byte_t *)tmp, proc_gc_pool(ctx))); return AI_OK; }
ExprBinaryOp::ExprBinaryOp(const ExprNode& left, const ExprNode& right, const Dim& dim) : ExprNode( max_height(left,right)+1, bin_size(left,right), dim ), left(left), right(right) { ((ExprNode*&) left.father)=this; ((ExprNode*&) right.father)=this; }
term_t bif_rc4_update2(term_t Text, term_t Opaque, process_t *ctx) { apr_byte_t *text_data; apr_uint32_t text_size, k; apr_byte_t *s; apr_byte_t i, j; term_t Text1, Opaque1; if (!is_binary(Text) || !is_binary(Opaque) || bin_size(Opaque) != intnum(256+2)) return A_BADARG; text_size = int_value2(bin_size(Text)); text_data = xalloc(proc_gc_pool(ctx), text_size); memcpy(text_data, bin_data(Text), text_size); s = xalloc(proc_gc_pool(ctx), 256+2); memcpy(s, bin_data(Opaque), 256+2); i = s[256]; j = s[257]; for (k = 0; k < text_size; k++) { apr_byte_t temp; i++; j += s[i]; temp = s[i]; s[i] = s[j]; s[j] = temp; text_data[k] ^= s[(s[i]+s[j]) & 255]; } s[256] = i; s[257] = j; Text1 = make_binary(intnum(text_size), text_data, proc_gc_pool(ctx)); Opaque1 = make_binary(intnum(256+2), s, proc_gc_pool(ctx)); result(make_tuple2(Text1, Opaque1, proc_gc_pool(ctx))); return AI_OK; }
term_t bif_md5_final1(term_t Context, process_t *ctx) { apr_byte_t *data; if (!is_binary(Context) || int_value2(bin_size(Context)) != sizeof(md5_ctx_t)) return A_BADARG; data = xalloc(proc_gc_pool(ctx), 16); md5_final(data, (md5_ctx_t *)bin_data(Context)); result(make_binary(intnum(MD5_DIGESTSIZE), data, proc_gc_pool(ctx))); return AI_OK; }
term_t bif_write0_2(term_t Port, term_t Bin, process_t *ctx) { apr_status_t rs; apr_size_t size; port_t *p; if (!is_port(Port) || !is_binary(Bin)) return A_BADARG; p = port_lookup(prp_serial(Port)); if (p == 0) return A_BADARG; size = (apr_size_t)int_value(bin_size(Bin)); rs = p->write(p, bin_data(Bin), &size); if (rs != 0) return decipher_status(rs); //TODO: something may still be written result(intnum(size)); return AI_OK; }
term_t bif_sendto4(term_t Sock, term_t RemIP, term_t RemPort, term_t Bin, process_t *ctx) { apr_status_t rs; port_t *port; apr_socket_t *sock; const char *host; int udp_port; apr_sockaddr_t *sa; apr_pool_t *p; if (!is_port(Sock)) return A_BADARG; if (!is_binary(RemIP) || !is_int(RemPort)) return A_BADARG; if (!is_binary(Bin)) return A_BADARG; port = port_lookup(prp_serial(Sock)); if (port == 0) return A_CLOSED; if (!port->is_socket(port)) return A_BADARG; sock = port->get_socket(port); host = (const char *)bin_data(RemIP); udp_port = (apr_port_t)int_value(RemPort); apr_pool_create(&p, 0); rs = apr_sockaddr_info_get(&sa, host, APR_INET, udp_port, 0, p); if (rs == 0) { apr_size_t len = (apr_size_t)int_value(bin_size(Bin)); rs = apr_socket_sendto(sock, sa, 0, (const char *)bin_data(Bin), &len); } if (rs != 0) { apr_pool_destroy(p); return decipher_status(rs); } result(A_OK); return AI_OK; }
static apr_status_t port_buffer_send(buffer_t *buf, term_t io) { int avail; if (is_nil(io)) return 0; avail = buffer_available(buf); if (is_int(io)) { if (avail == 0) return APR_EINCOMPLETE; else buffer_put_byte(buf, int_value(io)); } else if (is_binary(io)) { int size = int_value2(bin_size(io)); if (size > avail) { buffer_put_data(buf, bin_data(io), avail); return APR_EINCOMPLETE; } else buffer_put_data(buf, bin_data(io), size); } if (is_list(io)) { while (is_cons(io)) { apr_status_t rs; rs = port_buffer_send(buf, lst_value(io)); if (rs != 0) return rs; io = lst_next(io); } } return APR_SUCCESS; }
int SourceFile::tot_size() const { return sizeof( int ) + bin_size() + sizeof( int ) + str_size() + 1; }
int SourceFile::str_size() const { return *reinterpret_cast<const int *>( ptr + sizeof( int ) + bin_size() ); }
const char *SourceFile::filename() const{ return reinterpret_cast<const char *>( ptr + sizeof( int ) + bin_size() + sizeof( int ) ); }
gboolean hcheck_cell_pass(Hive *in_hive, RRACheckData *in_data) { if (in_hive == NULL) { return FALSE; } gboolean ret_val = TRUE; Bin *b; for (b = hive_get_first_bin(in_hive); b != NULL; b = bin_get_next_bin(b)) { offset end_of_bin = offset_make_relative(bin_get_offset(b), bin_size(b) - 1); if (offset_to_begin (end_of_bin) == 0) { rra_check_warning( in_data, _("Bad end offset for end of bin from: %d and %d"), bin_get_offset(b), bin_size(b)); bin_debug_print(b, TRUE); } Cell *last_c = NULL; Cell *c; for (c = bin_first_cell(b); c != NULL; last_c = c, c = cell_get_next(c)) { rra_check_checking(in_data, _("valid size")); if (cell_size(c) < sizeof(guint32) * 2) { rra_check_error(in_data, _("invalid cell size: %d"), cell_size(c)); ret_val = FALSE; } rra_check_checking(in_data, _("last cell correct")); if (cell_get_prev(c) != last_c) { rra_check_error(in_data, _("last cell incorrect")); ret_val = FALSE; } rra_check_checking(in_data, _("cell stays within bin")); offset end_of_cell = offset_make_relative(cell_get_offset(c), cell_size(c) - 1); int cmp_val = offset_compare(end_of_bin, end_of_cell); if (cmp_val < 0) { rra_check_error( in_data, _("cell extends past end of bin: " "Bin(%d) vs Cell(%d) => %d"), offset_to_begin(end_of_bin), offset_to_begin(end_of_cell), cmp_val); ret_val = FALSE; } } } return TRUE; }