Author: greatlrd
Date: Sun Jan 28 22:52:02 2007
New Revision: 25658
URL:
http://svn.reactos.org/svn/reactos?rev=25658&view=rev
Log:
start implement detections of export functions name. not finish does not working yet. Only
fix pe loader so it works
Modified:
trunk/rosapps/devutils/cputointel/ConvertToIA32Process.c
trunk/rosapps/devutils/cputointel/CpuToIntel.c
trunk/rosapps/devutils/cputointel/From/PPC/PPCBrain.h
trunk/rosapps/devutils/cputointel/ImageLoader.c
Modified: trunk/rosapps/devutils/cputointel/ConvertToIA32Process.c
URL:
http://svn.reactos.org/svn/reactos/trunk/rosapps/devutils/cputointel/Conver…
==============================================================================
--- trunk/rosapps/devutils/cputointel/ConvertToIA32Process.c (original)
+++ trunk/rosapps/devutils/cputointel/ConvertToIA32Process.c Sun Jan 28 22:52:02 2007
@@ -156,6 +156,19 @@
/* 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 */
Modified: trunk/rosapps/devutils/cputointel/CpuToIntel.c
URL:
http://svn.reactos.org/svn/reactos/trunk/rosapps/devutils/cputointel/CpuToI…
==============================================================================
--- trunk/rosapps/devutils/cputointel/CpuToIntel.c (original)
+++ trunk/rosapps/devutils/cputointel/CpuToIntel.c Sun Jan 28 22:52:02 2007
@@ -98,8 +98,11 @@
// 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;
Modified: trunk/rosapps/devutils/cputointel/From/PPC/PPCBrain.h
URL:
http://svn.reactos.org/svn/reactos/trunk/rosapps/devutils/cputointel/From/P…
==============================================================================
--- trunk/rosapps/devutils/cputointel/From/PPC/PPCBrain.h (original)
+++ trunk/rosapps/devutils/cputointel/From/PPC/PPCBrain.h Sun Jan 28 22:52:02 2007
@@ -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,2,2,2,2,2,2,1,0,0,1,0,0,2,2};
-CPU_BYTE cpuPPCInit_stwu[32] =
{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};
-CPU_BYTE cpuPPCInit_mr[32] =
{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};
+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};
+/* addi */
+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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,1,0,0,0,0,0,2,2 lwz r9,8(r31)
-*/
/* mask */
/*
* no mask we implement function getting the reg right
Modified: trunk/rosapps/devutils/cputointel/ImageLoader.c
URL:
http://svn.reactos.org/svn/reactos/trunk/rosapps/devutils/cputointel/ImageL…
==============================================================================
--- trunk/rosapps/devutils/cputointel/ImageLoader.c (original)
+++ trunk/rosapps/devutils/cputointel/ImageLoader.c Sun Jan 28 22:52:02 2007
@@ -253,15 +253,20 @@
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 @@
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
- */
-
- //*base = NtHeader->OptionalHeader.AddressOfEntryPoint;
-
- SectionHeader = IMAGE_FIRST_SECTION(NtHeader);
+
+ printf("Number of object :
%d\n",NtHeader->FileHeader.NumberOfSections);
+ printf("Base Address : %8x\n\n",NtHeader->OptionalHeader.ImageBase);
+
+ pSectionHeader = IMAGE_FIRST_SECTION(NtHeader);
+
NumberOfSections = NtHeader->FileHeader.NumberOfSections;
- for (NumberOfSectionsCount = 0; NumberOfSectionsCount < NumberOfSections;
NumberOfSectionsCount++, SectionHeader++)
- {
- if (strnicmp((PCHAR) SectionHeader->Name,".rsrc",5)==0)
+ for (i = 0; i < NumberOfSections; i++)
+ {
+ 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);
+ }
+
+ /* 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));
+ }
+ }
+ }
+
+
+/* start decoding */
+
+for (i=0;i < NumberOfSections; i++)
+{
+ if (strnicmp((PCHAR) SectionHeader[i].Name,".text\0",6)==0)
{
- /* FIXME add a rc bin to text scanner */
- }
-
- else if (strnicmp((PCHAR) SectionHeader->Name,".textbss",8)==0)
- {
- /* FIXME add a bss to text scanner */
- }
-
-
- 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;
- */
-
switch (NtHeader->FileHeader.Machine)
{
case IMAGE_FILE_MACHINE_ALPHA:
@@ -485,7 +476,7 @@
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 @@
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;
}