void dump_mach_header(FILE *obj_file, int offset, int is_64, int is_swap) { uint32_t ncmds; int load_commands_offset = offset; if (is_64) { int header_size = sizeof(struct mach_header_64); struct mach_header_64 *header = load_bytes(obj_file, offset, header_size); if (is_swap) { swap_mach_header_64(header, 0); } ncmds = header->ncmds; load_commands_offset += header_size; printf("%s\n", cpu_type_name(header->cputype)); free(header); } else { int header_size = sizeof(struct mach_header); struct mach_header *header = load_bytes(obj_file, offset, header_size); if (is_swap) { swap_mach_header(header, 0); } ncmds = header->ncmds; load_commands_offset += header_size; printf("%s\n", cpu_type_name(header->cputype)); free(header); } dump_segment_commands(obj_file, load_commands_offset, is_swap, ncmds); }
void dump_segment_commands(FILE *obj_file, int offset, int is_swap, uint32_t ncmds) { int actual_offset = offset; for (int i = 0; i < ncmds; i++) { struct load_command *cmd = load_bytes(obj_file, actual_offset, sizeof(struct load_command)); if (is_swap) { swap_load_command(cmd, 0); } if (cmd->cmd == LC_SEGMENT_64) { struct segment_command_64 *segment = load_bytes(obj_file, actual_offset, sizeof(struct segment_command_64)); if (is_swap) { swap_segment_command_64(segment, 0); } printf("segname: %s\n", segment->segname); free(segment); } else if (cmd->cmd == LC_SEGMENT) { struct segment_command *segment = load_bytes(obj_file, actual_offset, sizeof(struct segment_command)); if (is_swap) { swap_segment_command(segment, 0); } printf("segname: %s\n", segment->segname); free(segment); } actual_offset += cmd->cmdsize; free(cmd); } }
void dump_fat_header(FILE *obj_file, int is_swap) { int header_size = sizeof(struct fat_header); int arch_size = sizeof(struct fat_arch); struct fat_header *header = load_bytes(obj_file, 0, header_size); if (is_swap) { swap_fat_header(header, 0); } int arch_offset = header_size; for (int i = 0; i < header->nfat_arch; i++) { struct fat_arch *arch = load_bytes(obj_file, arch_offset, arch_size); if (is_swap) { swap_fat_arch(arch, 1, 0); } int mach_header_offset = arch->offset; free(arch); arch_offset += arch_size; uint32_t magic = read_magic(obj_file, mach_header_offset); int is_64 = is_magic_64(magic); int is_swap_mach = should_swap_bytes(magic); dump_mach_header(obj_file, mach_header_offset, is_64, is_swap_mach); } free(header); }
/* Load a marshalled credential from the cache file into buf, without * unmarshalling it. */ static krb5_error_code load_cred(krb5_context context, krb5_ccache id, size_t maxsize, struct k5buf *buf) { krb5_error_code ret; uint32_t count, i; /* client and server */ ret = load_principal(context, id, maxsize, buf); if (ret) return ret; ret = load_principal(context, id, maxsize, buf); if (ret) return ret; /* keyblock (enctype, enctype again for version 3, length, value) */ ret = load_bytes(context, id, (version(id) == 3) ? 4 : 2, buf); if (ret) return ret; ret = load_data(context, id, maxsize, buf); if (ret) return ret; /* times (4*4 bytes), is_skey (1 byte), ticket flags (4 bytes) */ ret = load_bytes(context, id, 4 * 4 + 1 + 4, buf); if (ret) return ret; /* addresses and authdata, both lists of {type, length, data} */ for (i = 0; i < 2; i++) { ret = read32(context, id, buf, &count); if (ret) return ret; while (count-- > 0) { ret = load_bytes(context, id, 2, buf); if (ret) return ret; ret = load_data(context, id, maxsize, buf); if (ret) return ret; } } /* ticket and second_ticket */ ret = load_data(context, id, maxsize, buf); if (ret) return ret; return load_data(context, id, maxsize, buf); }
/* Load a marshalled principal from the cache file into buf, without * unmarshalling it. */ static krb5_error_code load_principal(krb5_context context, krb5_ccache id, size_t maxsize, struct k5buf *buf) { krb5_error_code ret; uint32_t count; if (version(id) > 1) { ret = load_bytes(context, id, 4, buf); if (ret) return ret; } ret = read32(context, id, buf, &count); if (ret) return ret; /* Add one for the realm (except in version 1 which already counts it). */ if (version(id) != 1) count++; while (count-- > 0) { ret = load_data(context, id, maxsize, buf); if (ret) return ret; } return 0; }
static int load(RBinFile *arch) { const ut8 *bytes = arch ? r_buf_buffer (arch->buf) : NULL; ut64 sz = arch ? r_buf_size (arch->buf): 0; if (!arch || !arch->o) return R_FALSE; arch->o->bin_obj = load_bytes (bytes, sz, arch->o->loadaddr, arch->sdb); return check_bytes (bytes, sz); }
inline byte FileInputStream::read_bit_as_byte( ) { if ( !eof && buffered_count == next_unread && buffered_bits_count == 0 ) { load_bytes( ); } if ( end_of_stream( ) ) { return false; } if ( buffered_bits_count == 0 ) { buffered_bits = buffered_bytes[next_unread++]; buffered_bits_count = 8; } byte result = buffered_bits >> 7; buffered_bits <<= 1; --buffered_bits_count; ++position; return result; }
static int load(RBinFile *arch) { const ut8 *bytes = arch ? r_buf_buffer (arch->buf) : NULL; ut64 sz = arch ? r_buf_size (arch->buf): 0; if (!arch || !arch->o) return false; arch->o->bin_obj = load_bytes (arch, bytes, sz, arch->o->loadaddr, arch->sdb); return arch->o->bin_obj ? true: false; }
static bool load(RBinFile *arch) { if (arch && arch->buf) { const ut8 *bytes = r_buf_buffer (arch->buf); ut64 sz = r_buf_size (arch->buf); return load_bytes (arch, bytes, sz, arch->o->loadaddr, arch->sdb) != NULL; } return false; }
static bool load(RBinFile *bf) { if (!bf || !bf->o) { return false; } ut64 sz; const ut8 *bytes = r_buf_buffer (bf->buf, &sz); load_bytes (bf, &bf->o->bin_obj, bytes, sz, bf->o->loadaddr, bf->sdb); return check_bytes (bytes, sz); }
static bool load(RBinFile *bf) { const ut8 *bytes = bf? r_buf_buffer (bf->buf): NULL; ut64 sz = bf? r_buf_size (bf->buf): 0; if (!bf || !bf->o) { return false; } bf->o->bin_obj = load_bytes (bf, bytes, sz, bf->o->loadaddr, bf->sdb); return check_bytes (bytes, sz); }
static bool load(RBinFile *bf) { if (!bf || !bf->buf || !bf->o) { return false; } const ut64 sz = r_buf_size (bf->buf); const ut64 la = bf->o->loadaddr; const ut8 *bytes = r_buf_buffer (bf->buf); bf->o->bin_obj = load_bytes (bf, bytes, sz, la, bf->sdb); return bf->o->bin_obj != NULL; }
static bool load(RBinFile *bf) { if (!bf || !bf->o) { return false; } const ut8 *bytes = r_buf_buffer (bf->buf); ut64 sz = r_buf_size (bf->buf); const void *res = load_bytes (bf, bytes, sz, bf->o->loadaddr, bf->sdb); bf->o->bin_obj = (void *)res; return res != NULL; }
static int load(RBinFile *arch) { const ut8 *byte = arch ? r_buf_buffer(arch->buf) : NULL; ut64 size = arch ? r_buf_size(arch->buf) : 0; if (!arch || !arch->o) { return false; } if (!(arch->o->bin_obj = load_bytes(arch, byte, \ size, arch->o->loadaddr, arch->sdb))) return false; return true; }
/* Load a 32-bit length and data from the cache file into buf, but not more * than maxsize bytes. */ static krb5_error_code load_data(krb5_context context, krb5_ccache id, size_t maxsize, struct k5buf *buf) { krb5_error_code ret; uint32_t count; ret = read32(context, id, buf, &count); if (ret) return ret; if (count > maxsize) return KRB5_CC_FORMAT; return load_bytes(context, id, count, buf); }
static int load(RBinFile *arch) { const void *res; const ut8 *bytes; ut64 sz; if (!arch || !arch->o) return false; bytes = r_buf_buffer (arch->buf); sz = r_buf_size (arch->buf); res = load_bytes (arch, bytes, sz, arch->o->loadaddr, arch->sdb); arch->o->bin_obj = (void *)res; return res != NULL; }
static bool load(RBinFile *bf) { int result = false; const ut8 *bytes = bf? r_buf_buffer (bf->buf): NULL; ut64 sz = bf? r_buf_size (bf->buf): 0; struct r_bin_java_obj_t *bin_obj = NULL; if (!bf || !bf->o) { return false; } bin_obj = load_bytes (bf, bytes, sz, bf->o->loadaddr, bf->sdb); if (bin_obj) { if (!bf->o->kv) { bf->o->kv = bin_obj->kv; } bf->o->bin_obj = bin_obj; bin_obj->AllJavaBinObjs = DB; // XXX - /\ this is a hack, but (one way but) necessary to get access to // the object addrs from anal. If only global variables are used, // they get "lost" somehow after they are initialized and go out of // scope. // // There are several points of indirection, but here is the gist: // 1) RAnal->(through RBinBind) RBin->RBinJavaObj->DB // // The purpose is to ensure that information about a give class file // can be grabbed at any time from RAnal. This was tried with global // variables, but failed when attempting to access the DB // in the class.c scope. Once DB was moved here, it is initialized // once here and assigned to each of the other RBinJavaObjs. // // Now, the RAnal component of radare can get to each of the // RBinJavaObjs for analysing functions and dependencies using an Sdb. add_bin_obj_to_sdb (bin_obj); if (bf->file) { bin_obj->file = strdup (bf->file); } result = true; } return result; }
static void * load_buffer(RBinFile *arch, RBuffer *buf, ut64 loadaddr, Sdb *sdb){ ut8 data[64]; int data_len = r_buf_read_at (buf, 0, data, sizeof (data)); void *bo = NULL; return (void*)(bool)(load_bytes (arch, &bo, data, data_len, loadaddr, sdb)); }
unsigned short load_short(){ unsigned short x; load_bytes(&x,2); return x; }
unsigned char load_char(){ unsigned char x; load_bytes(&x,1); return x; }
unsigned int load_unsigned_int(){ int x; load_bytes(&x,4); return x; }
void load_str(char * arg_0, unsigned int arg_4){ arg_4 = min(arg_4, strlen(ptr)+1); arg_4 = min(arg_4, end-ptr+1); load_bytes(arg_0, arg_4); arg_0[arg_4] = 0x00; }
static bool load(RBinFile *bf) { const ut8 *bytes = bf ? r_buf_buffer (bf->buf) : NULL; ut64 sz = bf ? r_buf_size (bf->buf): 0; ut64 la = (bf && bf->o) ? bf->o->loadaddr: 0; return load_bytes (bf, bytes, sz, la, bf? bf->sdb: NULL) != NULL; }
int load_int(){ int x; load_bytes(&x,4); return x; }
static bool load(RBinFile *arch) { const ut8 *bytes = arch ? r_buf_buffer (arch->buf) : NULL; ut64 sz = arch ? r_buf_size (arch->buf): 0; ut64 la = (arch && arch->o) ? arch->o->loadaddr: 0; return load_bytes (arch, bytes, sz, la, arch? arch->sdb: NULL) != NULL; }