Hi, I've been experimenting with injectso. And, my test module works to a degree. I am having a few difficulties, though. I've modified the example module from injectso.
Code: Select all
#include <stdio.h>
#include <unistd.h>
#define LOG_FILE "/dtv/module.log"
int Highjack(int *r0, int *r1, int *r2)
{
FILE* fp = fopen(LOG_FILE, "a+");
fprintf(fp, "<Highjack>: hit.\n" );
fprintf(fp, "<Highjack>: r0 = 0x%x, r1 = 0x%x, r2 = 0x%x.\n", r0, r1, r2 );
fprintf(fp, "<Highjack>: *r0 = 0x%x 0x%x.\n", r0[0], r0[1] );
fprintf(fp, "<Highjack>: *r1 = 0x%x 0x%x.\n", r1[0], r1[1] );
fclose(fp);
return 0;
}
int Inject_Main( const char * arg1 )
{
int reg_pc,reg_fp,reg_sp;
asm ("mov %[result],pc" : [result] "=r" (reg_pc));
asm ("mov %[result],fp" : [result] "=r" (reg_fp));
asm ("mov %[result],sp" : [result] "=r" (reg_sp));
FILE* fp = fopen(LOG_FILE, "a+");
fprintf(fp, "<Inject_Main>: module loaded.\n");
fprintf(fp, "<Inject_Main>: arg1 = '%s'.\n", arg1);
fprintf(fp, "<Inject_Main>: &Highjack = 0x%x.\n", &Highjack);
int (*hp)(int *r0, int *r1, int *r2) = &Highjack;
fprintf(fp, "<Inject_Main>: &Highjack = 0x%x.\n", hp);
fprintf(fp, "<Inject_Main>: &Inject_Main = 0x%x, pc = 0x%x.\n", &Inject_Main, reg_pc);
fprintf(fp, "<Inject_Main>: fp = 0x%x, sp = 0x%x.\n", reg_fp, reg_sp);
fclose(fp);
char data[] = "abcdefghABCDEFGH";
hp((int*)&data[0], (int*)&data[8], (int*)5);
#if 0
// convert to unconditional branch
*((int*)0x4c09ec) = 0xeaffffdc; // b 0x4c0964
#endif
return 0;
}
The code above works as I've pasted it in. But, I'm trying to patch calls to my Highjack function into exeDSP. The first problem I ran into is that when I patch exeDSP, like with the line towards the end of Inject_Main (unrelated to Highjack). Modifying this instruction causes exeDSP to exit with a fault. It faults immediately during the write, but I am able to modify the instruction with gdb. Is there a way around the write protection so I can modify exeDSP within the module? Or do I have to do it with an external program? There's really no problem with doing it externally, I just didn't try it that way yet.
My next problem, is that the injected file seems to be unloaded when Inject_Main exits. After injecting the module, I try to peek into exeDSP with gdb. And, when I look at addresses where Highjack and Inject_Main should be, there're not there. The only explanation I can think of is that when Inject_Main exits, the whole module is unloaded. Or, somehow the pointers are wrong, but I don't see how.