9 return (segment << 4) +
offset;
13 return la + (
bin->dos_header->header_paragraphs << 4);
21 if (!
bin || !
bin->dos_header) {
28 if (la >=
bin->load_module_size) {
29 RZ_LOG_ERROR(
"The entry point is outside the load module size\n");
34 entrypoint->
vaddr = la;
67 int i, num_relocs, section_number;
70 if (!
bin || !
bin->dos_header) {
89 num_relocs =
bin->dos_header->num_relocs;
90 for (
i = 0;
i < num_relocs;
i++) {
92 ut64 laddr, paddr, section_laddr;
96 if ((laddr + 2) >=
bin->load_module_size) {
110 if (section_laddr >
bin->load_module_size) {
114 c.vaddr = section_laddr;
127 ss =
bin->dos_header->ss;
140 if (section_number) {
165 const int num_relocs =
bin->dos_header->num_relocs;
170 RZ_LOG_ERROR(
"Cannot allocate struct rz_bin_mz_reloc_t\n");
173 for (
i = 0, j = 0;
i < num_relocs;
i++) {
179 if (
relocs[j].vaddr < bin->load_module_size) {
193 free((
void *)
bin->dos_extended_header);
194 free((
void *)
bin->relocation_entries);
202 int relocations_size, dos_file_size;
208 bin->dos_header = mz;
227 bin->dos_file_size = dos_file_size;
228 if (dos_file_size >
bin->size) {
243 sdb_set(
bin->kv,
"mz.dos_header.format",
"[2]zwwwwwwwwwwwww"
244 " signature bytes_in_last_block blocks_in_file num_relocs "
245 " header_paragraphs min_extra_paragraphs max_extra_paragraphs "
246 " ss sp checksum ip cs reloc_table_offset overlay_number ",
252 if (
bin->dos_extended_header_size > 0) {
253 if (!(
bin->dos_extended_header =
254 malloc(
bin->dos_extended_header_size))) {
259 (
ut8 *)
bin->dos_extended_header,
260 bin->dos_extended_header_size) == -1) {
266 if (relocations_size > 0) {
267 if (!(
bin->relocation_entries =
malloc(relocations_size))) {
272 (
ut8 *)
bin->relocation_entries, relocations_size) == -1) {
283 bin->dos_extended_header =
NULL;
284 bin->relocation_entries =
NULL;
347 if (
b[0] == 0xb4 &&
b[1] == 0x30) {
353 for (
n = 0;
n <
sizeof(
b) - 18;
n++) {
354 if (
b[
n] == 0xff &&
b[
n + 4] == 0xff &&
b[
n + 8] == 0xff &&
b[
n + 12] == 0x9a &&
b[
n + 17] == 0x50) {
RZ_API void rz_bin_section_free(RzBinSection *bs)
RzList * relocs(RzBinFile *bf)
RZ_API void Ht_() free(HtName_(Ht) *ht)
RZ_API RZ_BORROW RzListIter * rz_list_find(RZ_NONNULL const RzList *list, const void *p, RZ_NONNULL RzListComparator cmp)
Returns RzListIter element which matches via the RzListComparator.
RZ_API RZ_OWN RzList * rz_list_newf(RzListFree f)
Returns a new initialized RzList pointer and sets the free method.
RZ_API RZ_BORROW void * rz_list_get_top(RZ_NONNULL const RzList *list)
Returns the last element of the list.
RZ_API RZ_BORROW RzListIter * rz_list_add_sorted(RZ_NONNULL RzList *list, void *data, RZ_NONNULL RzListComparator cmp)
Adds an element to a sorted list via the RzListComparator.
RZ_API void rz_list_free(RZ_NONNULL RzList *list)
Empties the list and frees the list pointer.
void * malloc(size_t size)
void * calloc(size_t number, size_t size)
RzList * rz_bin_mz_get_segments(const struct rz_bin_mz_obj_t *bin)
static ut64 rz_bin_mz_la_to_pa(const struct rz_bin_mz_obj_t *bin, ut64 la)
struct rz_bin_mz_obj_t * rz_bin_mz_new(const char *file)
static bool rz_bin_mz_init(struct rz_bin_mz_obj_t *bin)
static int rz_bin_mz_init_hdr(struct rz_bin_mz_obj_t *bin)
RzBinAddr * rz_bin_mz_get_entrypoint(const struct rz_bin_mz_obj_t *bin)
static RzBinSection * rz_bin_mz_init_section(const struct rz_bin_mz_obj_t *bin, ut64 laddr)
struct rz_bin_mz_obj_t * rz_bin_mz_new_buf(RzBuffer *buf)
void * rz_bin_mz_free(struct rz_bin_mz_obj_t *bin)
static int cmp_sections(const void *a, const void *b)
RzBinAddr * rz_bin_mz_get_main_vaddr(struct rz_bin_mz_obj_t *bin)
static ut64 rz_bin_mz_va_to_la(const ut16 segment, const ut16 offset)
struct rz_bin_mz_reloc_t * rz_bin_mz_get_relocs(const struct rz_bin_mz_obj_t *bin)
RZ_API int sdb_num_set(Sdb *s, const char *key, ut64 v, ut32 cas)
#define rz_buf_read_le16_at(b, addr, result)
RZ_API RZ_OWN RzBuffer * rz_buf_new_with_buf(RzBuffer *b)
Creates a new buffer from a source buffer.
RZ_API st64 rz_buf_read_at(RZ_NONNULL RzBuffer *b, ut64 addr, RZ_NONNULL RZ_OUT ut8 *buf, ut64 len)
Read len bytes of the buffer at the specified address.
RZ_API void rz_buf_free(RzBuffer *b)
Free all internal data hold by the buffer and the buffer.
RZ_API bool rz_buf_set_bytes(RZ_NONNULL RzBuffer *b, RZ_NONNULL const ut8 *buf, ut64 len)
Replace the content of the buffer with the bytes array.
RZ_API RZ_OWN RzBuffer * rz_buf_new_with_bytes(RZ_NULLABLE RZ_BORROW const ut8 *bytes, ut64 len)
Creates a new buffer with a bytes array.
RZ_API ut64 rz_buf_size(RZ_NONNULL RzBuffer *b)
Return the size of the buffer.
static ut16 rz_read_ble16(const void *src, bool big_endian)
RZ_API RZ_OWN char * rz_file_slurp(const char *str, RZ_NULLABLE size_t *usz)
void(* RzListFree)(void *ptr)
#define RZ_LOG_WARN(fmtstr,...)
#define RZ_LOG_ERROR(fmtstr,...)
RZ_API char * rz_str_newf(const char *fmt,...) RZ_PRINTF_CHECK(1
RZ_API int rz_str_rwx(const char *str)
RZ_API int sdb_set(Sdb *s, const char *key, const char *val, ut32 cas)
RZ_API Sdb * sdb_new0(void)
ut64(WINAPI *w32_GetEnabledXStateFeatures)()