Line 1... |
Line 1... |
//convert.c by Steve Rhoads 4/26/01
|
//convert.c by Steve Rhoads 4/26/01
|
//This program takes a little-endian MIPS executable and
|
//This program strips off the first 0x1000 bytes
|
//converts it to a big-endian executable and changes
|
|
//absolute jumps to branches.
|
|
#include <stdio.h>
|
#include <stdio.h>
|
#include <stdlib.h>
|
#include <stdlib.h>
|
|
|
#define BUF_SIZE (1024*1024)
|
#define BUF_SIZE (1024*1024)
|
#define CODE_OFFSET 0x200
|
#define CODE_OFFSET 0x1000
|
|
|
int main(int argc,char *argv[])
|
int main(int argc,char *argv[])
|
{
|
{
|
FILE *infile,*outfile;
|
FILE *infile,*outfile,*txtfile;
|
unsigned char *buf;
|
unsigned char *buf;
|
long size,i,j;
|
long size,i,j;
|
unsigned long d;
|
unsigned long d;
|
infile=fopen("test.exe","rb");
|
infile=fopen("test.exe","rb");
|
if(infile==NULL) {
|
if(infile==NULL) {
|
Line 20... |
Line 18... |
return 0;
|
return 0;
|
}
|
}
|
buf=(unsigned char*)malloc(BUF_SIZE);
|
buf=(unsigned char*)malloc(BUF_SIZE);
|
size=fread(buf,1,BUF_SIZE,infile);
|
size=fread(buf,1,BUF_SIZE,infile);
|
fclose(infile);
|
fclose(infile);
|
outfile=fopen("code.txt","w");
|
outfile=fopen("test2.exe","wb");
|
infile=fopen("test2.exe","wb");
|
txtfile=fopen("code.txt","w");
|
for(i=CODE_OFFSET;i<size;i+=4) {
|
for(i=CODE_OFFSET;i<size;i+=4) {
|
d=(buf[i+3]<<24)|(buf[i+2]<<16)|(buf[i+1]<<8)|buf[i];
|
d=(buf[i]<<24)|(buf[i+1]<<16)|(buf[i+2]<<8)|buf[i+3];
|
if((d>>24)==0x0c) { //JAL
|
// if((d>>24)==0x0c) { //JAL
|
j=(d&0xfffff)-0x400-((i-CODE_OFFSET)>>2)-1; //BGEZAL
|
// j=(d&0xfffff)-0x400-((i-CODE_OFFSET)>>2)-1; //BGEZAL
|
d=0x04110000+(j&0xffff);
|
// d=0x04110000+(j&0xffff);
|
}
|
// }
|
if(i==CODE_OFFSET) {
|
fprintf(txtfile,"%8.8x\n",d);
|
d=0x341d8000; //ori $29,0,0x8000
|
fwrite(buf+i,4,1,outfile);
|
}
|
|
fprintf(outfile,"%8.8x\n",d);
|
|
fwrite(&d,4,1,infile);
|
|
}
|
}
|
fclose(outfile);
|
fclose(outfile);
|
fclose(infile);
|
fclose(txtfile);
|
free(buf);
|
free(buf);
|
return 0;
|
return 0;
|
}
|
}
|
|
|
|
|
No newline at end of file
|
No newline at end of file
|