start implement detections of export functions name. not finish does not working yet. Only fix pe loader so it works

svn path=/trunk/; revision=25658
This commit is contained in:
Magnus Olsen 2007-01-28 19:52:02 +00:00
parent 61bb2998be
commit 70ab8ffa3c
4 changed files with 67 additions and 71 deletions

View file

@ -156,6 +156,19 @@ CPU_INT ConvertToIA32Process( FILE *outfp,
/* dst are register */
tmp = stack - (pMystart->dst*regbits);
if ((pMystart->type & 2)== 2)
{
fprintf(outfp,"mov ");
standardreg( RegTableCount,
pMystart->dst,
setup_ebp, outfp);
fprintf(outfp," , ");
standardreg( RegTableCount,
pMystart->src,
setup_ebp, outfp);
fprintf(outfp,"\n");
}
if ((pMystart->type & 16)== 16)
{
/* source are imm */

View file

@ -98,8 +98,11 @@ int main(int argc, char * argv[])
// mode 1 convert to intel
// mode 2 convert to ppc
//return LoadPFileImage(infile,outfile,BaseAddress,cpuid,type, mode);
LoadPFileImage("e:\\testppc.exe","e:\\cputoppc.asm",0,0,0,1);
LoadPFileImage("e:\\testppc.exe","e:\\cputointel.asm",0,0,0,2);
//LoadPFileImage("e:\\testppc.exe","e:\\cputointel.asm",0,0,0,1);
LoadPFileImage("e:\\testppc.exe","e:\\cputointel.asm",0,0,0,1);
//pMyBrainAnalys = NULL;
//pStartMyBrainAnalys = NULL;
//LoadPFileImage("e:\\testppc.exe","e:\\cputoppc.asm",0,0,0,2);
// return LoadPFileImage("e:\\testms.exe","e:\\cputointel.asm",0,0,0,1); // convert
return 0;

View file

@ -10,24 +10,16 @@
*/
/* FIXME RA should be 0 in stwu */
CPU_BYTE cpuPPCInit_Blr[32] = {0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,1,0,0,1,1,1,0};
CPU_BYTE cpuPPCInit_Li[32] = {2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,0,0,0,0,0,0,0,1,1,1,0,2,2};
CPU_BYTE cpuPPCInit_stw[32] = {2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2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1,1,1,2,2};
00: 2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,1,0,0,1,0,1,2,2 stwu r1,-32(r1)
04: 2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,1,0,0,1,0,0,2,2 stw r31,28(r1)
08: 0,1,1,1,1,0,0,0,0,0,0,0,1,0,1,1,2,2,2,2,2,2,2,2,0,1,1,1,1,1,2,2 mr r31,r1
0c: 2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,1,0,0,1,0,0,2,2 stw r3,8(r31)
10: 2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,1,0,0,0,0,0,2,2 lwz r9,8(r31)
*/
/* mask */
/*
* no mask we implement function getting the reg right

View file

@ -253,15 +253,20 @@ CPU_INT LoadPFileImage( char *infileName, char *outputfileName,
return 0;
}
#define MAXSECTIONNUMBER 16
CPU_INT PEFileStart( CPU_BYTE *memory, CPU_UNINT pos,
CPU_UNINT base, CPU_UNINT size,
FILE *outfp, CPU_INT mode)
{
PIMAGE_DOS_HEADER DosHeader;
PIMAGE_NT_HEADERS NtHeader;
PIMAGE_SECTION_HEADER SectionHeader;
IMAGE_SECTION_HEADER SectionHeader[MAXSECTIONNUMBER] = {NULL};
PIMAGE_SECTION_HEADER pSectionHeader;
PIMAGE_EXPORT_DIRECTORY ExportEntry;
INT NumberOfSections;
INT NumberOfSectionsCount=0;
INT i;
DosHeader = (PIMAGE_DOS_HEADER)memory;
if ( (DosHeader->e_magic != IMAGE_DOS_SIGNATURE) ||
@ -339,61 +344,47 @@ CPU_INT PEFileStart( CPU_BYTE *memory, CPU_UNINT pos,
break;
}
/*
SectionHeader->Name == ".tls$"
SectionHeader->Name == ".tls"
SectionHeader->Name == ".text" // Executable code
SectionHeader->Name == ".sxdata"
SectionHeader->Name == ".sdata"
SectionHeader->Name == ".sbss"
SectionHeader->Name == ".rsrc" // rc data
SectionHeader->Name == ".reloc"
SectionHeader->Name == ".rdata" // read only initialized data
SectionHeader->Name == ".pdata"
SectionHeader->Name == ".idlsym"
SectionHeader->Name == ".idata" // Import tables
SectionHeader->Name == ".edata" // Export tables
SectionHeader->Name == ".drective"
SectionHeader->Name == ".debug$T"
SectionHeader->Name == ".debug$S"
SectionHeader->Name == ".debug$P"
SectionHeader->Name == ".debug$F"
SectionHeader->Name == ".data" //data segment
SectionHeader->Name == ".cormeta"
SectionHeader->Name == ".bss" // bss segment
undoc
SectionHeader->Name == ".textbss" // bss segment
*/
printf("Number of object : %d\n",NtHeader->FileHeader.NumberOfSections);
printf("Base Address : %8x\n\n",NtHeader->OptionalHeader.ImageBase);
//*base = NtHeader->OptionalHeader.AddressOfEntryPoint;
pSectionHeader = IMAGE_FIRST_SECTION(NtHeader);
SectionHeader = IMAGE_FIRST_SECTION(NtHeader);
NumberOfSections = NtHeader->FileHeader.NumberOfSections;
for (NumberOfSectionsCount = 0; NumberOfSectionsCount < NumberOfSections; NumberOfSectionsCount++, SectionHeader++)
for (i = 0; i < NumberOfSections; i++)
{
if (strnicmp((PCHAR) SectionHeader->Name,".rsrc",5)==0)
{
/* FIXME add a rc bin to text scanner */
}
SectionHeader[i] = *pSectionHeader++;
printf("Found Sector : %s \n ",SectionHeader[i].Name);
printf("RVA: %08lX ",SectionHeader[i].VirtualAddress);
printf("Offset: %08lX ",SectionHeader[i].PointerToRawData);
printf("Size: %08lX ",SectionHeader[i].SizeOfRawData);
printf("Flags: %08lX \n\n",SectionHeader[i].Characteristics);
}
else if (strnicmp((PCHAR) SectionHeader->Name,".textbss",8)==0)
{
/* FIXME add a bss to text scanner */
}
/* Get export data */
if (NtHeader->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_EXPORT].Size != 0)
{
for (i = 0; i < NumberOfSections; i++)
{
if ( SectionHeader[i].VirtualAddress <= (ULONG) NtHeader->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_EXPORT].VirtualAddress &&
SectionHeader[i].VirtualAddress + SectionHeader[i].SizeOfRawData > (ULONG)NtHeader->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_EXPORT].VirtualAddress)
{
ExportEntry = (PIMAGE_NT_HEADERS) (((ULONG)memory) +
(ULONG)(NtHeader->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_EXPORT].VirtualAddress -
SectionHeader[i].VirtualAddress +
SectionHeader[i].PointerToRawData));
}
}
}
else if (strnicmp((PCHAR) SectionHeader->Name,".text\0",6)==0)
{
/*
FIXME we should output gas syntax
BITS 32
GLOBAL _lrotate;
EXTERN _printf;
COMMON _commvar 4;
*/
/* start decoding */
for (i=0;i < NumberOfSections; i++)
{
if (strnicmp((PCHAR) SectionHeader[i].Name,".text\0",6)==0)
{
switch (NtHeader->FileHeader.Machine)
{
case IMAGE_FILE_MACHINE_ALPHA:
@ -485,7 +476,7 @@ CPU_INT PEFileStart( CPU_BYTE *memory, CPU_UNINT pos,
fprintf(outfp,"; CPU found POWERPC\n");
//PPCBrain(memory, pos, cpu_size, base, 0, outfp);
machine_type = IMAGE_FILE_MACHINE_POWERPC;
PPCBrain(memory+SectionHeader->PointerToRawData, 0, SectionHeader->SizeOfRawData, 0, 0, outfp);
PPCBrain(memory+SectionHeader[i].PointerToRawData, 0, SectionHeader[i].SizeOfRawData, NtHeader->OptionalHeader.ImageBase, 0, outfp);
break;
@ -564,12 +555,9 @@ CPU_INT PEFileStart( CPU_BYTE *memory, CPU_UNINT pos,
default:
printf("Unknown Machine : %d",NtHeader->FileHeader.Machine);
return 4;
/* End case swich */
}
/* End if .text statment */
}
/* End for loop */
}
} /* end case switch*/
} /* end if text sector */
} /* end for */
return 0;
}