* Minor work on egg and rasc

This commit is contained in:
pancake 2011-07-27 10:30:23 +02:00
parent deced01103
commit dc93b16f7b
5 changed files with 38 additions and 13 deletions

View File

@ -74,13 +74,27 @@ static int show_help() {
int encode (const char *encoder, ut8 *dst, int dstlen, ut8 *src, int srclen) {
if (!strcmp (encoder, "xor")) {
// Find valid
//const ut8 *call_pop = "\xe8\xfb\xff\xff";
//const ut8 *pop_ebx = "\x5b";
//const ut8 *xor_ecx_ecx = "\x31\xc9";
// decode:
// pop ebx
ut8 key = 33;
// Find valid xor key
// length is key here
const ut8 *xordec =
// TODO: setup ecx here
"\xe8\xff\xff\xff\xff" // call $$+4
"\xc1" // ffc1 = inc ecx
"\x5e" // pop esi
"\x30\x4c\x0e\x07" // xor [esi+ecx+7], cl
"\xe2\xfa"; // loop xoresi
int xordeclen = strlen (xordec);
if (srclen+xordeclen>=dstlen) {
eprintf ("encode: too long");
return 0;
}
memcpy (dst, xordec, xordeclen);
for (i=0;i<srclen; i++) {
dst[xordeclen+i] = src[i] ^ i; // XXX
}
memcpy (dst+xordeclen, src, srclen);
return srclen + xordeclen;
} else {
eprintf ("Encoders: xor\n");
exit (0);
@ -89,7 +103,7 @@ int encode (const char *encoder, ut8 *dst, int dstlen, ut8 *src, int srclen) {
}
char *filetostr(char *file) {
FILE *fd = fopen(file,"r");
FILE *fd = fopen (file,"r");
char *buf;
int i, size = BLOCK;
@ -98,10 +112,10 @@ char *filetostr(char *file) {
buf = (char *)malloc (size);
buf[0]='\0';
for (i=0;!feof(fd);i++) {
for (i=0; !feof (fd); i++) {
if (i==size) {
size = size + BLOCK;
buf = realloc(buf, size);
buf = realloc (buf, size);
}
fread (buf+i, 1, 1, fd);
}
@ -130,7 +144,7 @@ int otf_patch() {
ptr = getenv ("HOST");
if (ptr) {
int x,y,z,w;
sscanf(ptr,"%d.%d.%d.%d", &x,&y,&z,&w);
sscanf (ptr,"%d.%d.%d.%d", &x,&y,&z,&w);
shellcode[shellcodes[scidx].host+3]=x;
shellcode[shellcodes[scidx].host+2]=y;
shellcode[shellcodes[scidx].host+1]=z;

View File

@ -1,6 +1,7 @@
#include <stdio.h>
#include <stdlib.h>
// XXX: only for x86
int swallow_redpill () {
unsigned char m[2+4], rpill[] = "\x0f\x01\x0d\x00\x00\x00\x00\xc3";
*((unsigned*)&rpill[3]) = (unsigned long int) m;

View File

@ -99,6 +99,11 @@ R_API void r_egg_label(REgg *egg, const char *name) {
r_egg_printf (egg, "%s:\n", name);
}
R_API void r_egg_math (REgg *egg) {//, char eq, const char *vs, char type, const char *sr
// TODO
//e->mathop (egg, op, type, eq, p);
}
R_API void r_egg_raw(REgg *egg, const ut8 *b, int len) {
}
@ -176,3 +181,7 @@ R_API char *r_egg_get_source(REgg *egg) {
R_API char *r_egg_get_assembly(REgg *egg) {
return r_buf_to_string (egg->buf);
}
R_API void r_egg_append(REgg *egg, const char *src) {
r_buf_append_bytes (egg->src, (const ut8*)src, strlen (src));
}

View File

@ -555,13 +555,13 @@ static void rcc_next(REgg *egg) {
int vs = 'l';
char type, *eq, *ptr = elem;
elem[elem_n] = '\0';
while (isspace (ptr[0])) ptr=ptr+1; /* skip spaces */
while (isspace (ptr[0])) ptr++; /* skip spaces */
if (*ptr) {
eq = strchr (ptr, '=');
if (eq) {
char str2[64], *p, ch = *(eq-1);
*eq = '\0';
for (eq=eq+1; *eq==' '; eq++);
for (eq++; *eq==' '; eq++);
p = r_egg_mkvar (egg, str2, ptr, 0);
vs = varsize;
if (IS_VAR (eq)) {

View File

@ -67,6 +67,7 @@ R_API RBuffer *r_egg_get_bin(REgg *egg);
R_API char *r_egg_get_source(REgg *egg);
R_API RBuffer *r_egg_get_bin(REgg *egg);
R_API char *r_egg_get_assembly(REgg *egg);
R_API void r_egg_append(REgg *egg, const char *src);
/* lang.c */
R_API char *r_egg_mkvar(REgg *egg, char *out, const char *_str, int delta);