mirror of
https://github.com/radareorg/radare2.git
synced 2025-02-21 23:01:03 +00:00
* Initial import of asm.x86.as plugin
- Uses OSX/GNU/BSD 'as' assembler
This commit is contained in:
parent
860e608d23
commit
aad2e91d96
@ -11,6 +11,7 @@
|
|||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
#if __UNIX__
|
#if __UNIX__
|
||||||
|
#include <sys/mman.h>
|
||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
#include <netinet/in.h>
|
#include <netinet/in.h>
|
||||||
#endif
|
#endif
|
||||||
@ -73,19 +74,19 @@ static int show_help() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int encode (const char *encoder, ut8 *dst, int dstlen, ut8 *src, int srclen) {
|
int encode (const char *encoder, ut8 *dst, int dstlen, ut8 *src, int srclen) {
|
||||||
int i;
|
int xordeclen, i;
|
||||||
if (!strcmp (encoder, "xor")) {
|
if (!strcmp (encoder, "xor")) {
|
||||||
ut8 key = 33;
|
//ut8 key = 33;
|
||||||
// Find valid xor key
|
// Find valid xor key
|
||||||
// length is key here
|
// length is key here
|
||||||
const ut8 *xordec =
|
const ut8 *xordec = (const ut8*)
|
||||||
// TODO: setup ecx here
|
// TODO: setup ecx here
|
||||||
"\xe8\xff\xff\xff\xff" // call $$+4
|
"\xe8\xff\xff\xff\xff" // call $$+4
|
||||||
"\xc1" // ffc1 = inc ecx
|
"\xc1" // ffc1 = inc ecx
|
||||||
"\x5e" // pop esi
|
"\x5e" // pop esi
|
||||||
"\x30\x4c\x0e\x07" // xor [esi+ecx+7], cl
|
"\x30\x4c\x0e\x07" // xor [esi+ecx+7], cl
|
||||||
"\xe2\xfa"; // loop xoresi
|
"\xe2\xfa"; // loop xoresi
|
||||||
int xordeclen = strlen (xordec);
|
xordeclen = strlen ((const char *)xordec);
|
||||||
if (srclen+xordeclen>=dstlen) {
|
if (srclen+xordeclen>=dstlen) {
|
||||||
eprintf ("encode: too long");
|
eprintf ("encode: too long");
|
||||||
return 0;
|
return 0;
|
||||||
@ -249,8 +250,16 @@ int print_shellcode() {
|
|||||||
printf("No shellcode defined\n");
|
printf("No shellcode defined\n");
|
||||||
return 1;
|
return 1;
|
||||||
} else {
|
} else {
|
||||||
|
ut8 *ptr = malloc (4096);
|
||||||
void (*cb)() = (void *)&shellcode;
|
void (*cb)() = (void *)&shellcode;
|
||||||
|
memcpy (ptr, shellcode, strlen ((const char *)shellcode));
|
||||||
|
#if __UNIX__
|
||||||
|
mprotect (ptr, 4096, PROT_READ|PROT_EXEC); // rx must be ok
|
||||||
|
mprotect (ptr, 4096, PROT_READ|PROT_WRITE|PROT_EXEC); // try rwx
|
||||||
|
#endif
|
||||||
|
cb = (void*)ptr;
|
||||||
cb();
|
cb();
|
||||||
|
free (ptr);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 4:
|
case 4:
|
||||||
|
@ -10,7 +10,7 @@ foo: all
|
|||||||
|
|
||||||
ALL_TARGETS=
|
ALL_TARGETS=
|
||||||
# TODO: rename to enabled plugins
|
# TODO: rename to enabled plugins
|
||||||
ARCHS=mips.mk sparc.mk java.mk bf.mk arm.mk dalvik.mk
|
ARCHS=mips.mk sparc.mk java.mk bf.mk arm.mk dalvik.mk x86_as.mk
|
||||||
ARCHS+=ppc.mk x86_olly.mk x86.mk csr.mk x86_nasm.mk psosvm.mk avr.mk
|
ARCHS+=ppc.mk x86_olly.mk x86.mk csr.mk x86_nasm.mk psosvm.mk avr.mk
|
||||||
ARCHS+=msil.mk sh.mk
|
ARCHS+=msil.mk sh.mk
|
||||||
include $(ARCHS)
|
include $(ARCHS)
|
||||||
|
76
libr/asm/p/asm_x86_as.c
Normal file
76
libr/asm/p/asm_x86_as.c
Normal file
@ -0,0 +1,76 @@
|
|||||||
|
/* radare - LGPL - Copyright 2011 pancake<nopcode.org> */
|
||||||
|
|
||||||
|
#include <r_types.h>
|
||||||
|
#include <r_util.h>
|
||||||
|
#include <r_lib.h>
|
||||||
|
#include <r_asm.h>
|
||||||
|
|
||||||
|
static int assemble(RAsm *a, RAsmOp *op, const char *buf) {
|
||||||
|
char *ipath, *opath;
|
||||||
|
int ifd, ofd;
|
||||||
|
const char *syntaxstr = "";
|
||||||
|
char asm_buf[R_ASM_BUFSIZE];
|
||||||
|
int len = 0;
|
||||||
|
|
||||||
|
ifd = r_file_mkstemp ("r_as", &ipath);
|
||||||
|
ofd = r_file_mkstemp ("r_as", &opath);
|
||||||
|
|
||||||
|
syntaxstr = ".intel_syntax noprefix\n"; // if intel syntax
|
||||||
|
len = snprintf (asm_buf, sizeof (asm_buf),
|
||||||
|
"%s.code%i\n" //.org 0x%"PFMT64x"\n"
|
||||||
|
".ascii \"BEGINMARK\"\n"
|
||||||
|
"%s\n"
|
||||||
|
".ascii \"ENDMARK\"\n",
|
||||||
|
syntaxstr, a->bits, buf); // a->pc ??
|
||||||
|
write (ifd, asm_buf, len);
|
||||||
|
close (ifd);
|
||||||
|
|
||||||
|
if (!r_sys_cmdf ("as %s -o %s", ipath, opath)) {
|
||||||
|
const ut8 *begin, *end;
|
||||||
|
close (ofd);
|
||||||
|
ofd = open (opath, O_RDONLY);
|
||||||
|
len = read (ofd, op->buf, R_ASM_BUFSIZE);
|
||||||
|
begin = r_mem_mem (op->buf, len, (const ut8*)"BEGINMARK", 9);
|
||||||
|
end = r_mem_mem (op->buf, len, (const ut8*)"ENDMARK", 7);
|
||||||
|
if (!begin || !end) {
|
||||||
|
eprintf ("Cannot find water marks\n");
|
||||||
|
len = 0;
|
||||||
|
} else {
|
||||||
|
len = (int)(size_t)(end-begin-9);
|
||||||
|
if (len>0) memcpy (op->buf, begin+9, len);
|
||||||
|
else len = 0;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
eprintf ("Error running 'as'\n");
|
||||||
|
len = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
close (ofd);
|
||||||
|
|
||||||
|
unlink (ipath);
|
||||||
|
unlink (opath);
|
||||||
|
free (ipath);
|
||||||
|
free (opath);
|
||||||
|
|
||||||
|
op->inst_len = len;
|
||||||
|
return len;
|
||||||
|
}
|
||||||
|
|
||||||
|
RAsmPlugin r_asm_plugin_x86_as = {
|
||||||
|
.name = "x86.as",
|
||||||
|
.desc = "X86 assembler plugin using 'as' program",
|
||||||
|
.arch = "x86",
|
||||||
|
// NOTE: 64bits is not supported on OSX's nasm :(
|
||||||
|
.bits = (int[]){ 16, 32, 64, 0 },
|
||||||
|
.init = NULL,
|
||||||
|
.fini = NULL,
|
||||||
|
.disassemble = NULL,
|
||||||
|
.assemble = &assemble,
|
||||||
|
};
|
||||||
|
|
||||||
|
#ifndef CORELIB
|
||||||
|
struct r_lib_struct_t radare_plugin = {
|
||||||
|
.type = R_LIB_TYPE_ASM,
|
||||||
|
.data = &r_asm_plugin_x86_as
|
||||||
|
};
|
||||||
|
#endif
|
@ -46,6 +46,7 @@ RAsmPlugin r_asm_plugin_x86_nasm = {
|
|||||||
.name = "x86.nasm",
|
.name = "x86.nasm",
|
||||||
.desc = "X86 nasm assembler plugin",
|
.desc = "X86 nasm assembler plugin",
|
||||||
.arch = "x86",
|
.arch = "x86",
|
||||||
|
// NOTE: 64bits is not supported on OSX's nasm :(
|
||||||
.bits = (int[]){ 16, 32, 64, 0 },
|
.bits = (int[]){ 16, 32, 64, 0 },
|
||||||
.init = NULL,
|
.init = NULL,
|
||||||
.fini = NULL,
|
.fini = NULL,
|
||||||
|
9
libr/asm/p/x86_as.mk
Normal file
9
libr/asm/p/x86_as.mk
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
OBJ_X86_AS=asm_x86_as.o
|
||||||
|
|
||||||
|
STATIC_OBJ+=${OBJ_X86_AS}
|
||||||
|
TARGET_X86_AS=asm_x86_as.${EXT_SO}
|
||||||
|
|
||||||
|
ALL_TARGETS+=${TARGET_X86_AS}
|
||||||
|
|
||||||
|
${TARGET_X86_AS}: ${OBJ_X86_AS}
|
||||||
|
${CC} $(call libname,asm_x86_nasm) ${LDFLAGS} ${CFLAGS} -o ${TARGET_X86_AS} ${OBJ_X86_AS}
|
@ -130,6 +130,7 @@ extern RAsmPlugin r_asm_plugin_bf;
|
|||||||
extern RAsmPlugin r_asm_plugin_java;
|
extern RAsmPlugin r_asm_plugin_java;
|
||||||
extern RAsmPlugin r_asm_plugin_mips;
|
extern RAsmPlugin r_asm_plugin_mips;
|
||||||
extern RAsmPlugin r_asm_plugin_x86;
|
extern RAsmPlugin r_asm_plugin_x86;
|
||||||
|
extern RAsmPlugin r_asm_plugin_x86_as;
|
||||||
extern RAsmPlugin r_asm_plugin_x86_olly;
|
extern RAsmPlugin r_asm_plugin_x86_olly;
|
||||||
extern RAsmPlugin r_asm_plugin_x86_nasm;
|
extern RAsmPlugin r_asm_plugin_x86_nasm;
|
||||||
extern RAsmPlugin r_asm_plugin_arm;
|
extern RAsmPlugin r_asm_plugin_arm;
|
||||||
|
@ -15,6 +15,7 @@ asm.ppc
|
|||||||
asm.x86
|
asm.x86
|
||||||
asm.x86_olly
|
asm.x86_olly
|
||||||
asm.x86_nasm
|
asm.x86_nasm
|
||||||
|
asm.x86_as
|
||||||
asm.msil
|
asm.msil
|
||||||
anal.sh
|
anal.sh
|
||||||
anal.x86
|
anal.x86
|
||||||
|
Loading…
x
Reference in New Issue
Block a user