/*static void initPTS() { int fdm, fds, rc; char * name; char input[150]; fdm = posix_openpt(O_RDWR); if (fdm < 0) { eprintf ("Error on posix_openpt()\n"); } rc = grantpt(fdm); if (rc != 0) { eprintf("Error on grantpt()\n"); } rc = unlockpt(fdm); if (rc != 0) { eprintf("Error on unlockpt()\n"); } ptsname_r(fdm,input,150);//int fd, char *buf, size_t buflen);ptsname(fdm); ptsHandle=fdm;//open(input, O_RDWR); if (ptsHandle) eprintf("Opened %s for ESIL input/output\n",input ); } void printCommand() { if (ptsHandle) { eprintf("printCommand: Enviando..\n"); write(ptsHandle,"\01",1); } } void readCommand() { if (ptsHandle) write(ptsHandle,"\02",1); } void printOutput(char * s) { printCommand(); if (ptsHandle) { write (ptsHandle, s, strlen (s)+1); } } */ static int esil_trap(RAnalEsil *esil) { ut64 valor; ut64 valor1; ut32 v; int f,i; //FILE *f; char *dst = r_anal_esil_pop (esil); char buff[255]; /*if (!ptsHandle) { eprintf("Iniciando pts\n"); initPTS(); }*/ /*f=open("/dev/pts/10", O_RDWR); if (!f) eprintf("eeror en pts\n");*/ r_anal_esil_get_parm (esil, dst, &valor); reg_read(esil,"r_00",&valor1); eprintf("esil->trap = %08x esil->trap_code = %08x pila = 0x%"PFMT64x " valor1 = 0x%"PFMT64x"\n",esil->trap,esil->trap_code,valor,valor1); v=(ut32)valor1; if (valor==0){ sprintf(buff,"%c%c",(ut8)v,0); eprintf("emulando api:%s\n",buff); //printOutput(&buff); //printOutput(buff); //write (ptsHandle, buff, 2); } return 1; }
// Unmarshall the string in stack to the struct. RAnalReilArg *reil_pop_arg(RAnalEsil *esil) { RAnalReilArg *op; int i, j = 0, flag = 0, len; char tmp_buf[REGBUFSZ]; char *buf = r_anal_esil_pop(esil); if (!buf) return NULL; len = strlen(buf); op = R_NEW0(RAnalReilArg); for (i = 0; i < len; i++) { if (buf[i] == ':') { tmp_buf[j] = '\0'; strncpy(op->name, tmp_buf, sizeof(op->name) - 1); memset(tmp_buf, 0, sizeof(tmp_buf)); j = 0; flag = 1; continue; } // Strip all spaces if (buf[i] == ' ') continue; tmp_buf[j] = buf[i]; j++; } tmp_buf[j] = '\0'; // If we have not encountered a ':' we don't know the size yet. if (!flag) { strncpy(op->name, tmp_buf, sizeof(op->name) - 1); op->type = reil_get_arg_type(esil, op->name); if (op->type == ARG_REG) { op->size = esil_internal_sizeof_reg(esil, op->name); } else if (op->type == ARG_CONST) { op->size = esil->anal->bits; } free(buf); return op; } op->size = strtoll(tmp_buf, NULL, 10); op->type = reil_get_arg_type(esil, op->name); free(buf); return op; }