Shellcode


/* shellcode.c                                                 *
 * my way of inlining assembler code in C programs             *
 * and making it accesible from C                              *
 * specially crated to feed your brain by gera [at] corest,com */

/* on some compilers you may need to add underscores           *
 * on code and codelen inside the asm() directive and          *
 * compile without optimizations                               */

#include <string.h>

int main() {
	extern unsigned char codeend,code;
	char unsigned codecopy[200];
	unsigned int codelen = &codeend-&code;
	void(*test_the_code)() = (void(*)())codecopy;

	if (0) asm("
		code:
			xor	%eax, %eax
			mov	%eax, %ebx
			inc	%eax
			mov	$42,%bl
			int	$0x80
		codeend:
			");

	memcpy(&codecopy,(void*)&code,codelen);

	printf("%02x %02x %02x %02x - %02x %02x %02x %02x\n",
		(&code)[0],(&code)[1],(&code)[2],(&code)[3],
		(&code)[4],(&code)[5],(&code)[6],(&code)[7]);

	test_the_code();
	exit(0);
}
{Previous} {index} {Next}