Example #1
0
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);
}
Example #2
0
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);
  }
}
Example #3
0
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); 
}
Example #4
0
/* 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);
}
Example #5
0
/* 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;
}
Example #6
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);
}
Example #7
0
		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;
		}
Example #8
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 false;
	arch->o->bin_obj = load_bytes (arch, bytes, sz, arch->o->loadaddr, arch->sdb);
	return arch->o->bin_obj ? true: false;
}
Example #9
0
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;
}
Example #10
0
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);
}
Example #11
0
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);
}
Example #12
0
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;
}
Example #13
0
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;
}
Example #14
0
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;
}
Example #15
0
/* 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);
}
Example #16
0
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;
}
Example #17
0
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;
}
Example #18
0
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));
}
Example #19
0
 unsigned short load_short(){
     unsigned short x;
     load_bytes(&x,2);
     return x;
 }
Example #20
0
 unsigned char load_char(){
     unsigned char x;
     load_bytes(&x,1);
     return x;
 }
Example #21
0
	unsigned int load_unsigned_int(){
        int x;
        load_bytes(&x,4);
        return x;
    }
Example #22
0
    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;
    }
Example #23
0
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;
}
Example #24
0
	int load_int(){
        int x;
        load_bytes(&x,4);
        return x;
    }
Example #25
0
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;
}