Compare commits

...

3 Commits

5 changed files with 167 additions and 5 deletions

136
src/format/mach-o.c Normal file
View File

@ -0,0 +1,136 @@
/* $Id$ */
/* Copyright (c) 2025 Pierre Pronchery <khorben@defora.org> */
/* This file is part of DeforaOS Devel Asm */
/* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, version 3 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. */
#include <System.h>
#include <string.h>
#include "Asm.h"
/* Mach-O */
/* private */
/* types */
struct _AsmFormatPlugin
{
AsmFormatPluginHelper * helper;
};
/* prototypes */
/* plug-in */
static AsmFormatPlugin * _macho_init(AsmFormatPluginHelper * helper,
char const * arch);
static int _macho_destroy(AsmFormatPlugin * format);
static char const * _macho_guess(AsmFormatPlugin * format, char const * hint);
static int _macho_section(AsmFormatPlugin * format, char const * section);
static int _macho_decode(AsmFormatPlugin * format, int raw);
static int _macho_decode_section(AsmFormatPlugin * format, AsmSection * section,
AsmArchInstructionCall ** calls, size_t * calls_cnt);
/* public */
/* variables */
/* plug-in */
AsmFormatPluginDefinition format_plugin =
{
"mach-o",
"Mach-O file",
LICENSE_GNU_LGPL3_FLAGS,
NULL,
0,
_macho_init,
_macho_destroy,
_macho_guess,
NULL,
NULL,
_macho_section,
NULL,
_macho_decode,
_macho_decode_section
};
/* private */
/* functions */
/* plug-in */
/* macho_init */
static AsmFormatPlugin * _macho_init(AsmFormatPluginHelper * helper,
char const * arch)
{
AsmFormatPlugin * macho;
(void) arch;
if((macho = object_new(sizeof(*macho))) == NULL)
return NULL;
macho->helper = helper;
return macho;
}
/* macho_destroy */
static int _macho_destroy(AsmFormatPlugin * format)
{
object_delete(format);
return 0;
}
/* macho_guess */
static char const * _macho_guess(AsmFormatPlugin * format, char const * hint)
{
(void) format;
return hint;
}
/* macho_section */
static int _macho_section(AsmFormatPlugin * format, char const * section)
{
(void) format;
(void) section;
/* ignore sections */
return 0;
}
/* macho_decode */
static int _macho_decode(AsmFormatPlugin * format, int raw)
{
AsmFormatPluginHelper * helper = format->helper;
off_t offset;
(void) raw;
if((offset = helper->seek(helper->format, 0, SEEK_END)) >= 0
&& helper->set_section(helper->format, 0, 0, ".text", 0,
offset, 0) != NULL)
return 0;
return -1;
}
/* macho_decode_section */
static int _macho_decode_section(AsmFormatPlugin * format, AsmSection * section,
AsmArchInstructionCall ** calls, size_t * calls_cnt)
{
AsmFormatPluginHelper * helper = format->helper;
if(section->id != 0)
return -1;
return helper->decode(helper->format, section->offset, section->size,
section->base, calls, calls_cnt);
}

View File

@ -1,4 +1,4 @@
targets=dex,elf,flat,java,mbr,pe,template
targets=dex,elf,flat,java,mach-o,mbr,pe,template
cppflags_force=-I../../include
cflags_force=`pkg-config --cflags libSystem` -fPIC
cflags=-W -Wall -g -O2 -D_FORTIFY_SOURCE=2 -fstack-protector
@ -33,6 +33,10 @@ type=plugin
sources=java.c
install=$(LIBDIR)/Asm/format
[mach-o]
type=plugin
sources=mach-o.c
[mbr]
type=plugin
sources=mbr.c

View File

@ -1,5 +1,5 @@
/* $Id$ */
/* Copyright (c) 2012-2015 Pierre Pronchery <khorben@defora.org> */
/* Copyright (c) 2012-2025 Pierre Pronchery <khorben@defora.org> */
/* This file is part of DeforaOS Devel Asm */
/* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
@ -25,6 +25,7 @@ extern AsmFormatPluginDefinition format_plugin_dex;
extern AsmFormatPluginDefinition format_plugin_elf;
extern AsmFormatPluginDefinition format_plugin_flat;
extern AsmFormatPluginDefinition format_plugin_java;
extern AsmFormatPluginDefinition format_plugin_macho;
extern AsmFormatPluginDefinition format_plugin_mbr;
extern AsmFormatPluginDefinition format_plugin_pe;
@ -38,6 +39,7 @@ static struct
{ "elf", NULL },
{ "flat", NULL },
{ "java", NULL },
{ "mach-o", NULL },
{ "mbr", NULL },
{ "pe", NULL }
};
@ -137,7 +139,8 @@ static void _format_init(void)
_formats[1].definition = &format_plugin_elf;
_formats[2].definition = &format_plugin_flat;
_formats[3].definition = &format_plugin_java;
_formats[4].definition = &format_plugin_mbr;
_formats[5].definition = &format_plugin_pe;
_formats[4].definition = &format_plugin_macho;
_formats[5].definition = &format_plugin_mbr;
_formats[6].definition = &format_plugin_pe;
}
}

19
tools/format/mach-o.c Normal file
View File

@ -0,0 +1,19 @@
/* $Id$ */
/* Copyright (c) 2025 Pierre Pronchery <khorben@defora.org> */
/* This file is part of DeforaOS Devel Asm */
/* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, version 3 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. */
#define format_plugin format_plugin_macho
#include "../src/format/mach-o.c"

View File

@ -16,7 +16,7 @@ cflags=-W -Wall -O2 -D_FORTIFY_SOURCE=2 -fstack-protector
#targets
[libAsm]
type=library
sources=arch.c,arch/amd64.c,arch/arm.c,arch/armeb.c,arch/armel.c,arch/dalvik.c,arch/eth.c,arch/i386.c,arch/i386_real.c,arch/i486.c,arch/i586.c,arch/i686.c,arch/java.c,arch/mips.c,arch/mipseb.c,arch/mipsel.c,arch/sparc.c,arch/sparc64.c,arch/template.c,arch/yasep.c,arch/yasep16.c,arch/yasep32.c,format.c,format/dex.c,format/elf.c,format/elf/elf32.c,format/elf/elf64.c,format/flat.c,format/java.c,format/mbr.c,format/pe.c,asm.c,code.c,parser.c,token.c
sources=arch.c,arch/amd64.c,arch/arm.c,arch/armeb.c,arch/armel.c,arch/dalvik.c,arch/eth.c,arch/i386.c,arch/i386_real.c,arch/i486.c,arch/i586.c,arch/i686.c,arch/java.c,arch/mips.c,arch/mipseb.c,arch/mipsel.c,arch/sparc.c,arch/sparc64.c,arch/template.c,arch/yasep.c,arch/yasep16.c,arch/yasep32.c,format.c,format/dex.c,format/elf.c,format/elf/elf32.c,format/elf/elf64.c,format/flat.c,format/java.c,format/mach-o.c,format/mbr.c,format/pe.c,asm.c,code.c,parser.c,token.c
cflags=-fPIC
[asm-static]