10 #define RZ_BIN_MACH064 1
11 #include "../format/mach0/mach0.h"
12 #include "../format/mach0/mach0_defines.h"
59 struct MACH0_(mach_header) * hdr;
64 ut64 text_offset_in_whole;
65 ut64 data_offset_in_whole;
92 #define BTW(val, min, max) ((val) > min && (val) < max)
107 if (msr_vbar_el1 != 0xd518c002) {
116 if (
adr != 0x10003fe2) {
126 if (
tmp != 0x14000000) {
134 if (
tmp != 0x14000000) {
143 if (
tmp != 0x326e6f69) {
153 if (hdr_offset >= sz) {
186 if (!
bin->cur->xtr_obj) {
210 for (
i = 1; data &&
i < narch;
i++) {
285 if (
idx >=
ctx->hdr->n_apps + 3) {
295 ut64 nominal_offset = 0;
301 total_size =
ctx->hdr->kernel_base_paddr;
302 }
else if (
idx == 1) {
309 nominal_offset =
ctx->hdr->kernel_base_paddr;
310 total_size =
info->total_size;
311 }
else if (
idx == 2) {
318 nominal_offset =
ctx->hdr->init_base_paddr;
319 total_size =
info->total_size;
321 int app_idx =
idx - 3;
327 info->data_offset_in_whole =
ctx->apps[app_idx].phys_data;
329 nominal_offset =
ctx->apps[app_idx].phys_text;
330 total_size =
info->total_size;
333 if (!
name || !slice_buf) {
359 slice->
buf = slice_buf;
380 struct MACH0_(mach_header) *hdr =
NULL;
382 ut64 total_size = 0, text_size = 0, data_offset = 0, data_size = 0;
384 ut32 hdr_size =
sizeof(
struct MACH0_(mach_header));
392 if (hdr->magic !=
MH_MAGIC_64 || !
BTW(hdr->sizeofcmds, 0, max_size)) {
406 for (
i = 0;
i < hdr->ncmds;
i++) {
409 const struct MACH0_(segment_command) *seg = (
struct MACH0_(segment_command) *)cursor;
410 ut64 end = seg->fileoff + seg->filesize;
411 if (total_size <
end) {
414 if (!strcmp(seg->segname,
"__TEXT")) {
415 text_size = seg->filesize;
416 }
else if (!strcmp(seg->segname,
"__DATA")) {
417 data_offset = seg->fileoff;
418 data_size = seg->filesize;
421 cursor = cursor +
cmd->cmdsize;
424 if (total_size == 0 || text_size == 0 || data_offset == 0 || data_size == 0) {
434 result->total_size = total_size;
435 result->text_size = text_size;
436 result->data_offset = data_offset;
437 result->data_size = data_size;
438 result->text_offset_in_whole = at;
471 ut64 data_offset =
info->data_offset_in_whole ?
info->data_offset_in_whole :
info->text_offset_in_whole +
info->data_offset;
491 char *proper_name =
calloc(13, 1);
497 for (
i = 12;
i != -1;
i--) {
498 if (app_name[
i] ==
' ') {
501 proper_name[
i] = app_name[
i];
522 .desc =
"64-bit SEP bin extractor plugin",
533 #ifndef RZ_PLUGIN_INCORE
static RzILOpEffect * adr(cs_insn *insn, bool is_thumb)
RZ_API void rz_bin_xtrdata_free(void *data_)
RZ_API RzBinXtrData * rz_bin_xtrdata_new(RzBuffer *buf, ut64 offset, ut64 size, ut32 file_count, RzBinXtrMetadata *metadata)
RzBinInfo * info(RzBinFile *bf)
static RSepMachoInfo * mach0_info_new(RzBuffer *buf, ut64 at, ut64 max_size)
struct _RSepMachoInfo RSepMachoInfo
struct _RSepApp64 RSepApp64
static RzList * oneshotall_buffer(RzBin *bin, RzBuffer *b)
static void destroy(RzBin *bin)
static int size(RzBin *bin)
RZ_API RzLibStruct rizin_plugin
struct _RSepSlice64 RSepSlice64
static bool check_buffer(RzBuffer *b)
static bool load(RzBin *bin)
struct _RSepHdr64 RSepHdr64
static void fill_metadata_info_from_hdr(RzBinXtrMetadata *meta, struct MACH0_(mach_header) *hdr)
static RSepSlice64 * sep64_xtr_ctx_get_slice(RSepXtr64Ctx *ctx, RzBuffer *whole, int idx)
static char * get_proper_name(const char *app_name)
static bool read_arm64_ins(RzBuffer *b, int idx, ut64 *result)
struct _RSepXtr64Ctx RSepXtr64Ctx
static RzBuffer * extract_slice(RzBuffer *whole, RSepMachoInfo *info)
RzBinXtrPlugin rz_bin_xtr_plugin_xtr_sep64
static RSepXtr64Ctx * sep64_xtr_ctx_new(RzBuffer *buf)
#define BTW(val, min, max)
static void mach0_info_free(RSepMachoInfo *info)
static void sep64_xtr_ctx_free(void *p)
static RzBinXtrData * oneshot_buffer(RzBin *bin, RzBuffer *b, int idx)
static static sync static getppid static getegid const char static filename char static len const char char static bufsiz static mask static vfork const void static prot static getpgrp const char static swapflags cmd
static const char * commands[]
RZ_API void Ht_() free(HtName_(Ht) *ht)
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 RzListIter * rz_list_append(RZ_NONNULL RzList *list, void *data)
Appends at the end of the list a new element.
void * malloc(size_t size)
void * calloc(size_t number, size_t size)
return strdup("=SP r13\n" "=LR r14\n" "=PC r15\n" "=A0 r0\n" "=A1 r1\n" "=A2 r2\n" "=A3 r3\n" "=ZF zf\n" "=SF nf\n" "=OF vf\n" "=CF cf\n" "=SN or0\n" "gpr lr .32 56 0\n" "gpr pc .32 60 0\n" "gpr cpsr .32 64 0 ____tfiae_________________qvczn\n" "gpr or0 .32 68 0\n" "gpr tf .1 64.5 0 thumb\n" "gpr ef .1 64.9 0 endian\n" "gpr jf .1 64.24 0 java\n" "gpr qf .1 64.27 0 sticky_overflow\n" "gpr vf .1 64.28 0 overflow\n" "gpr cf .1 64.29 0 carry\n" "gpr zf .1 64.30 0 zero\n" "gpr nf .1 64.31 0 negative\n" "gpr itc .4 64.10 0 if_then_count\n" "gpr gef .4 64.16 0 great_or_equal\n" "gpr r0 .32 0 0\n" "gpr r1 .32 4 0\n" "gpr r2 .32 8 0\n" "gpr r3 .32 12 0\n" "gpr r4 .32 16 0\n" "gpr r5 .32 20 0\n" "gpr r6 .32 24 0\n" "gpr r7 .32 28 0\n" "gpr r8 .32 32 0\n" "gpr r9 .32 36 0\n" "gpr r10 .32 40 0\n" "gpr r11 .32 44 0\n" "gpr r12 .32 48 0\n" "gpr r13 .32 52 0\n" "gpr r14 .32 56 0\n" "gpr r15 .32 60 0\n" "gpr r16 .32 64 0\n" "gpr r17 .32 68 0\n")
char *MACH0_() get_filetype_from_hdr(struct MACH0_(mach_header) *hdr)
int MACH0_() get_bits_from_hdr(struct MACH0_(mach_header) *hdr)
const char *MACH0_() get_cputype_from_hdr(struct MACH0_(mach_header) *hdr)
char *MACH0_() get_cpusubtype_from_hdr(struct MACH0_(mach_header) *hdr)
#define rz_return_val_if_fail(expr, val)
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 RZ_OWN RzBuffer * rz_buf_new_with_pointers(const ut8 *bytes, ut64 len, bool steal)
Creates a new buffer with a bytes array.
RZ_API st64 rz_buf_fread_at(RZ_NONNULL RzBuffer *b, ut64 addr, RZ_NONNULL ut8 *buf, RZ_NONNULL const char *fmt, int n)
...
#define rz_buf_read_le32_at(b, addr, result)
RZ_API void rz_buf_free(RzBuffer *b)
Free all internal data hold by the buffer and the buffer.
RZ_API RZ_OWN RzBuffer * rz_buf_new_slice(RzBuffer *b, ut64 offset, ut64 size)
Creates a new buffer from a slice of another buffer.
RZ_API ut64 rz_buf_size(RZ_NONNULL RzBuffer *b)
Return the size of the buffer.
#define rz_buf_read_le64_at(b, addr, result)
ut64 app_images_max_paddr
ut64 app_images_base_paddr
ut64(WINAPI *w32_GetEnabledXStateFeatures)()