[ros-diffs] [greatlrd] 25453: the public frist version that can convert arty testms.exe that are commited to powerpc branch in the alink folder. the program doing main() ( return 0 ) fixing minior bugs as well

greatlrd at svn.reactos.org greatlrd at svn.reactos.org
Sun Jan 14 19:01:56 CET 2007


Author: greatlrd
Date: Sun Jan 14 21:01:56 2007
New Revision: 25453

URL: http://svn.reactos.org/svn/reactos?rev=25453&view=rev
Log:
the public frist version that can convert arty testms.exe that are commited to powerpc branch in the alink folder. 
the program doing main() ( return 0 )
fixing minior bugs as well

Added:
    trunk/rosapps/devutils/cputointel/ImageLoader.c
Modified:
    trunk/rosapps/devutils/cputointel/ConvertToIntelProcess.c
    trunk/rosapps/devutils/cputointel/CpuToIntel.c
    trunk/rosapps/devutils/cputointel/From/PPC/PPCopcode.c
    trunk/rosapps/devutils/cputointel/any_op.h
    trunk/rosapps/devutils/cputointel/misc.c
    trunk/rosapps/devutils/cputointel/misc.h

Modified: trunk/rosapps/devutils/cputointel/ConvertToIntelProcess.c
URL: http://svn.reactos.org/svn/reactos/trunk/rosapps/devutils/cputointel/ConvertToIntelProcess.c?rev=25453&r1=25452&r2=25453&view=diff
==============================================================================
--- trunk/rosapps/devutils/cputointel/ConvertToIntelProcess.c (original)
+++ trunk/rosapps/devutils/cputointel/ConvertToIntelProcess.c Sun Jan 14 21:01:56 2007
@@ -8,11 +8,83 @@
 #include "misc.h"
 #include "any_op.h"
 
-CPU_INT ConvertToIntelProcess(FILE *outfp,  char *cpuid)
+CPU_INT ConvertToIntelProcess(FILE *outfp,  CPU_INT cpuid)
 {
-    /* cpuid we need it to known the register 
-       we should solv it another way 
-     */
+    CPU_INT eax = 0;
+    CPU_INT stack = 0;
+    CPU_INT regbits = 0;
+    CPU_UNINT tmp;
 
+    pMyBrainAnalys = pStartMyBrainAnalys;
+
+    if (cpuid == IMAGE_FILE_MACHINE_POWERPC)
+    {
+        regbits = 64 / 8;
+        eax = 3;  /* eax = r3 */
+        stack = 31 * regbits;  /* r0-r31 are 64bits reg  ? */
+        /* exemple  :
+         *          : [ebp - 256]  = r0 
+         *          : [ebp - 248]  = r1 
+         */
+    }
+    else
+    {
+        printf("not supported yet\n");
+        return -1;
+    }
+    
+
+    fprintf(outfp,"BITS 32\n");
+    fprintf(outfp,"GLOBAL _main\n");
+    fprintf(outfp,"SECTION .text\n\n");
+    fprintf(outfp,"; compile with nasm filename.asm -f win32, gcc filename.obj -o filename.exe\n\n");
+    fprintf(outfp,"_main:\n");
+
+    /* setup a frame pointer */
+    fprintf(outfp,"\n; Setup frame pointer \n");
+    fprintf(outfp,"push ebp\n");
+    fprintf(outfp,"mov  ebp,esp\n");
+    fprintf(outfp,"sub  esp, %d ; Alloc %d bytes for reg\n\n",stack,stack);
+
+    fprintf(outfp,"; Start the program \n");
+    while (pMyBrainAnalys!=NULL)
+    {
+        /* fixme the line lookup from anaylysing process */
+
+        /* mov not full implement */
+        if (pMyBrainAnalys->op == OP_ANY_mov)
+        {
+            printf("waring OP_ANY_mov are not full implement\n");
+
+            if ((pMyBrainAnalys->type & 8)== 8)
+            {
+                /* dst are register */
+                tmp = stack - (pMyBrainAnalys->dst*regbits);
+
+                if ((pMyBrainAnalys->type & 16)== 16)
+                {
+                    /* source are imm */
+                    fprintf(outfp,"mov dword [ebp - %d], %llu\n", tmp, pMyBrainAnalys->src);
+                    if (pMyBrainAnalys->dst == eax)
+                    {
+                        fprintf(outfp,"mov eax,[ebp - %d]\n", tmp);
+                    }
+                }
+            } /* end pMyBrainAnalys->type & 8 */
+        }
+
+        /* return */
+        if (pMyBrainAnalys->op == OP_ANY_ret)
+        {
+            if (pMyBrainAnalys->ptr_next == NULL)
+            {
+               fprintf(outfp,"\n; clean up after the frame \n");
+               fprintf(outfp,"mov esp, ebp\n");
+               fprintf(outfp,"pop ebp\n");
+            }
+            fprintf(outfp,"ret\n");
+        }
+        pMyBrainAnalys = (PMYBrainAnalys) pMyBrainAnalys->ptr_next;
+    }
     return 0;
 }

Modified: trunk/rosapps/devutils/cputointel/CpuToIntel.c
URL: http://svn.reactos.org/svn/reactos/trunk/rosapps/devutils/cputointel/CpuToIntel.c?rev=25453&r1=25452&r2=25453&view=diff
==============================================================================
--- trunk/rosapps/devutils/cputointel/CpuToIntel.c (original)
+++ trunk/rosapps/devutils/cputointel/CpuToIntel.c Sun Jan 14 21:01:56 2007
@@ -7,94 +7,96 @@
 #include "any_op.h"
 
 PMYBrainAnalys pMyBrainAnalys = NULL;
+PMYBrainAnalys pStartMyBrainAnalys = NULL;
 
 
 int main(int argc, char * argv[])
 {
-    CPU_UNINT BaseAddress=0;
-    int t=0;
-    char *infile=NULL;
-    char *outfile=NULL;
-    char *cpuid=NULL;
-    CPU_INT type=0;
-    CPU_INT mode = 1;
+    //CPU_UNINT BaseAddress=0;
+    //int t=0;
+    //char *infile=NULL;
+    //char *outfile=NULL;
+    //char *cpuid=NULL;
+    //CPU_INT type=0;
+    //CPU_INT mode = 1;
 
 
-    printf("Usage :\n");
-    printf(" need for -inbin and autodetect  if it does not found a PE header \n");
-    printf("       -cpu m68000      : convert motorala 68000/68008 to intel asm \n");
-    printf("       -cpu m68010      : convert motorala 68010 to intel asm \n");
-    printf("       -cpu m68020      : convert motorala 68020 to intel asm \n");
-    printf("       -cpu m68030      : convert motorala 68030 to intel asm \n");
-    printf("       -cpu m68040      : convert motorala 68040 to intel asm \n");
-    printf("       -cpu ppc         : convert PowerPC to intel asm \n");
-    printf("       -cpu ARM4        : convert ARM4 to intel asm \n");
-    printf("------------------------------------------------------------------\n");
-    printf(" for -inbin and autodetect  if it does not found a PE header or do\n");
-    printf(" not set at all, this options are free to use     \n");
-    printf(".......-BaseAddress adr : the start base address only accpect \n");
-    printf(".......                   dec value");
-    printf("------------------------------------------------------------------\n");
-    printf("       -in filename     : try autodetect file type for you");
-    printf("                          whant convert\n");
-    printf("       -inBin filename  : the bin file you whant convert\n");
-    printf("       -inExe filename  : the PE file you whant convert\n");
-    printf("       -OutAsm filename : the Asm file you whant create\n");
-    printf("       -OutDis filename : Do disambler of the source file\n");
-    printf("------------------------------------------------------------------\n");
-    printf("More cpu will be added with the time or options, this is      \n");
-    printf("version 0.0.1 of the cpu to intel converter writen by         \n");
-    printf("Magnus Olsen (magnus at greatlord.com), it does not do anything  \n");
-    printf("yet, more that basic desgin how it should be writen.          \n");
-    printf("Copyright 2006 by Magnus Olsen, licen under GPL 2.0 for now.  \n");
+    //printf("Usage :\n");
+    //printf(" need for -inbin and autodetect  if it does not found a PE header \n");
+    //printf("       -cpu m68000      : convert motorala 68000/68008 to intel asm \n");
+    //printf("       -cpu m68010      : convert motorala 68010 to intel asm \n");
+    //printf("       -cpu m68020      : convert motorala 68020 to intel asm \n");
+    //printf("       -cpu m68030      : convert motorala 68030 to intel asm \n");
+    //printf("       -cpu m68040      : convert motorala 68040 to intel asm \n");
+    //printf("       -cpu ppc         : convert PowerPC to intel asm \n");
+    //printf("       -cpu ARM4        : convert ARM4 to intel asm \n");
+    //printf("------------------------------------------------------------------\n");
+    //printf(" for -inbin and autodetect  if it does not found a PE header or do\n");
+    //printf(" not set at all, this options are free to use     \n");
+    //printf(".......-BaseAddress adr : the start base address only accpect \n");
+    //printf(".......                   dec value");
+    //printf("------------------------------------------------------------------\n");
+    //printf("       -in filename     : try autodetect file type for you");
+    //printf("                          whant convert\n");
+    //printf("       -inBin filename  : the bin file you whant convert\n");
+    //printf("       -inExe filename  : the PE file you whant convert\n");
+    //printf("       -OutAsm filename : the Asm file you whant create\n");
+    //printf("       -OutDis filename : Do disambler of the source file\n");
+    //printf("------------------------------------------------------------------\n");
+    //printf("More cpu will be added with the time or options, this is      \n");
+    //printf("version 0.0.1 of the cpu to intel converter writen by         \n");
+    //printf("Magnus Olsen (magnus at greatlord.com), it does not do anything  \n");
+    //printf("yet, more that basic desgin how it should be writen.          \n");
+    //printf("Copyright 2006 by Magnus Olsen, licen under GPL 2.0 for now.  \n");
 
 
-    if (argc <4)
-        return 110;
+    //if (argc <4)
+    //    return 110;
 
-    /* fixme better error checking for the input param */
-    for (t=1; t<argc;t+=2)
-    {
-        if (stricmp(argv[t],"-in"))
-        {
-            infile = argv[t+1];
-            type=0;
-        }
+    ///* fixme better error checking for the input param */
+    //for (t=1; t<argc;t+=2)
+    //{
+    //    if (stricmp(argv[t],"-in"))
+    //    {
+    //        infile = argv[t+1];
+    //        type=0;
+    //    }
 
-        if (stricmp(argv[t],"-inBin"))
-        {
-            infile = argv[t+1];
-            type=1;
-        }
+    //    if (stricmp(argv[t],"-inBin"))
+    //    {
+    //        infile = argv[t+1];
+    //        type=1;
+    //    }
 
-        if (stricmp(argv[t],"-inExe"))
-        {
-            infile = argv[t+1];
-            type=1;
-        }
+    //    if (stricmp(argv[t],"-inExe"))
+    //    {
+    //        infile = argv[t+1];
+    //        type=1;
+    //    }
 
-        if (stricmp(argv[t],"-OutAsm"))
-        {
-            outfile = argv[t+1];
-        }
-        if (stricmp(argv[t],"-OutDis"))
-        {
-            outfile = argv[t+1];
-            mode = 0;
-        }
-        if (stricmp(argv[t],"-BaseAddress"))
-        {
-            BaseAddress = atol(argv[t+1]);
-        }
-        if (stricmp(argv[t],"-cpu"))
-        {
-            cpuid = argv[t+1];
-        }
+    //    if (stricmp(argv[t],"-OutAsm"))
+    //    {
+    //        outfile = argv[t+1];
+    //    }
+    //    if (stricmp(argv[t],"-OutDis"))
+    //    {
+    //        outfile = argv[t+1];
+    //        mode = 0;
+    //    }
+    //    if (stricmp(argv[t],"-BaseAddress"))
+    //    {
+    //        BaseAddress = atol(argv[t+1]);
+    //    }
+    //    if (stricmp(argv[t],"-cpu"))
+    //    {
+    //        cpuid = argv[t+1];
+    //    }
 
-    }
+    //}
 
-    return LoadPFileImage(infile,outfile,BaseAddress,cpuid,type, mode);
-    //return LoadPFileImage("e:\\testms.exe","e:\\cputointel.asm",0,0,0,0);
+    //return LoadPFileImage(infile,outfile,BaseAddress,cpuid,type, mode);
+    //return LoadPFileImage("e:\\testms.exe","e:\\cputointel.asm",0,0,0,0); // disambler
+    return LoadPFileImage("e:\\testms.exe","e:\\cputointel.asm",0,0,0,1); // convert
 
 }
 

Modified: trunk/rosapps/devutils/cputointel/From/PPC/PPCopcode.c
URL: http://svn.reactos.org/svn/reactos/trunk/rosapps/devutils/cputointel/From/PPC/PPCopcode.c?rev=25453&r1=25452&r2=25453&view=diff
==============================================================================
--- trunk/rosapps/devutils/cputointel/From/PPC/PPCopcode.c (original)
+++ trunk/rosapps/devutils/cputointel/From/PPC/PPCopcode.c Sun Jan 14 21:01:56 2007
@@ -103,7 +103,7 @@
             return -1;
         }
         pMyBrainAnalys->op = OP_ANY_mov;
-        pMyBrainAnalys->type= 1 + 8; /* 1 dst reg, 8 imm */
+        pMyBrainAnalys->type= 8 + 16; /* 8 dst reg, 16 imm */
         pMyBrainAnalys->src_size = 16;
         pMyBrainAnalys->src = formDS;
         pMyBrainAnalys->dst = formA;

Added: trunk/rosapps/devutils/cputointel/ImageLoader.c
URL: http://svn.reactos.org/svn/reactos/trunk/rosapps/devutils/cputointel/ImageLoader.c?rev=25453&view=auto
==============================================================================
--- trunk/rosapps/devutils/cputointel/ImageLoader.c (added)
+++ trunk/rosapps/devutils/cputointel/ImageLoader.c Sun Jan 14 21:01:56 2007
@@ -1,0 +1,554 @@
+#include <windows.h>
+#include <winnt.h>
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include "misc.h"
+#include "From/ARM/ARM.h"
+#include "From/m68k/m68k.h"
+#include "From/PPC/PPC.h"
+
+static  CPU_INT machine_type = 0;
+
+/*
+ * infileName       file name to convert or disambler 
+ * outputfileName   file name to save to
+ * BaseAddress      the address we should emulate
+ * cpuid            the cpu we choice not vaild for pe loader
+ * type             the loading mode Auto, PE, bin
+ * mode             disambler mode : 0 the arch cpu.
+ *                  translate mode : 1 intel
+ * 
+ */
+
+CPU_INT LoadPFileImage( char *infileName, char *outputfileName, 
+                     CPU_UNINT BaseAddress, char *cpuid,
+                     CPU_UNINT type, CPU_INT mode)
+{
+    FILE *infp;
+    FILE *outfp;
+    CPU_BYTE *cpu_buffer;   
+    CPU_UNINT cpu_pos = 0;
+    CPU_UNINT cpu_size=0;
+    CPU_INT ret;
+     //fopen("testms.exe","RB");
+    
+
+    /* Open file for read */
+
+    if (!(infp = fopen(infileName, "rb")))
+    {
+        printf("Can not open file %s\n",infileName);
+        return 3;
+    }
+
+    /* Open file for write */
+    if (!(outfp = fopen(outputfileName,"wb")))
+    {
+        printf("Can not open file %s\n",outputfileName);
+        return 4;
+    }
+
+    /* Load the binary file to a memory buffer */
+    fseek(infp,0,SEEK_END);
+    if (ferror(infp))
+    {
+        printf("error can not seek in the read file");
+        fclose(infp);
+        fclose(outfp);
+        return 5;
+    }
+    
+    /* get the memory size buffer */
+    cpu_size = ftell(infp);
+    if (ferror(infp))
+    {
+        printf("error can not get file size of the read file");
+        fclose(infp);
+        fclose(outfp);
+        return 6;
+    }
+
+    /* Load the binary file to a memory buffer */
+    fseek(infp,0,SEEK_SET);
+    if (ferror(infp))
+    {
+        printf("error can not seek in the read file");
+        fclose(infp);
+        fclose(outfp);
+        return 5;
+    }
+
+    if (cpu_size==0)
+    {
+        printf("error file size is Zero lenght of the read file");
+        fclose(infp);
+        fclose(outfp);
+        return 7;
+    }
+
+    /* alloc memory now */
+   ;
+    if (!(cpu_buffer = (unsigned char *) malloc(cpu_size+1)))
+    {
+        printf("error can not alloc %uld size for memory buffer",cpu_size);
+        fclose(infp);
+        fclose(outfp);
+        return 8;
+    }
+    ZeroMemory(cpu_buffer,cpu_size);
+
+    /* read from the file now in one sweep */
+    fread((void *)cpu_buffer,1,cpu_size,infp);
+    if (ferror(infp))
+    {
+        printf("error can not read file ");
+        fclose(infp);
+        fclose(outfp);
+        return 9;
+    }
+    fclose(infp);
+
+    if (type==0) 
+    {
+       if ( PEFileStart(cpu_buffer, 0, BaseAddress, cpu_size, outfp, mode) !=0)
+       {
+            type=1;
+       }
+       else
+       {
+            if (mode > 0)
+            {
+                AnyalsingProcess();
+                ConvertToIntelProcess(outfp,machine_type);
+                FreeAny();
+            }
+            fclose(outfp);
+            return 0;
+       }
+    }
+
+    if (type== 1)
+    {
+        if (stricmp(cpuid,"m68000"))
+        {
+            ret = M68KBrain(cpu_buffer,cpu_pos,cpu_size,BaseAddress,68000,outfp,mode);
+            if (mode > 1)
+            {
+                AnyalsingProcess();
+                ConvertToIntelProcess(outfp,machine_type);
+                FreeAny();
+            }
+            fclose(outfp);
+        }
+        else if (stricmp(cpuid,"m68010"))
+        {
+            ret = M68KBrain(cpu_buffer,cpu_pos,cpu_size,BaseAddress,68010,outfp,mode);
+            if (mode > 1)
+            {
+                AnyalsingProcess();
+                ConvertToIntelProcess(outfp,machine_type);
+                FreeAny();
+            }
+            fclose(outfp);
+            return ret;
+        }
+        else if (stricmp(cpuid,"m68020"))
+        {
+            ret = M68KBrain(cpu_buffer,cpu_pos,cpu_size,BaseAddress,68020,outfp,mode);
+            if (mode > 1)
+            {
+                AnyalsingProcess();
+                ConvertToIntelProcess(outfp,machine_type);
+                FreeAny();
+            }
+            fclose(outfp);
+            return ret;
+        }
+        else if (stricmp(cpuid,"m68030"))
+        {
+            ret = M68KBrain(cpu_buffer,cpu_pos,cpu_size,BaseAddress,68030,outfp,mode);
+            if (mode > 1)
+            {
+                AnyalsingProcess();
+                ConvertToIntelProcess(outfp,machine_type);
+                FreeAny();
+            }
+            fclose(outfp);
+            return ret;
+        }
+        else if (stricmp(cpuid,"m68040"))
+        {
+            ret = M68KBrain(cpu_buffer,cpu_pos,cpu_size,BaseAddress,68040,outfp,mode);
+            if (mode > 1)
+            {
+                AnyalsingProcess();
+                ConvertToIntelProcess(outfp,machine_type);
+                FreeAny();
+            }
+            fclose(outfp);
+            return ret;
+        }
+        else if (stricmp(cpuid,"ppc"))
+        {
+            ret = PPCBrain(cpu_buffer,cpu_pos,cpu_size,BaseAddress,0,outfp,mode);
+            if (mode > 1)
+            {
+                AnyalsingProcess();
+                ConvertToIntelProcess(outfp,machine_type);
+                FreeAny();
+            }
+            fclose(outfp);
+            return ret;
+        }
+        else if (stricmp(cpuid,"arm4"))
+        {
+            ret = ARMBrain(cpu_buffer,cpu_pos,cpu_size,BaseAddress,4,outfp,mode);
+            if (mode > 1)
+            {
+                AnyalsingProcess();
+                ConvertToIntelProcess(outfp,machine_type);
+                FreeAny();
+            }
+            fclose(outfp);
+            return ret;
+        }
+    }
+
+    if (type==2) 
+    {
+
+       ret = PEFileStart(cpu_buffer, 0, BaseAddress, cpu_size, outfp, mode);
+       if (mode > 1)
+       {
+            AnyalsingProcess();
+            ConvertToIntelProcess(outfp,machine_type);
+            FreeAny();
+       }
+       fclose(outfp);
+       return ret;
+    }
+
+    return 0;
+}
+
+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;
+    INT NumberOfSections;
+    INT NumberOfSectionsCount=0;
+
+    DosHeader = (PIMAGE_DOS_HEADER)memory;
+    if ( (DosHeader->e_magic != IMAGE_DOS_SIGNATURE) ||
+         (size < 0x3c+2) )
+    {
+        printf("No MZ file \n");
+        return -1;
+    }
+
+    NtHeader = (PIMAGE_NT_HEADERS) (((ULONG)memory) + ((ULONG)DosHeader->e_lfanew));
+    if (NtHeader->Signature != IMAGE_NT_SIGNATURE)
+    {
+        printf("No PE header found \n");
+    }
+
+    if (!(NtHeader->FileHeader.Characteristics & IMAGE_FILE_EXECUTABLE_IMAGE))
+    {
+        printf("No execute image found \n");
+        return -1;
+    }
+
+    switch(NtHeader->OptionalHeader.Subsystem)
+    {
+        case IMAGE_SUBSYSTEM_EFI_APPLICATION:
+             fprintf(outfp,"; OS type : IMAGE_SUBSYSTEM_EFI_APPLICATION\n");
+             printf("This exe file is desgin run in EFI bios as applactions\n");
+             break;
+        case IMAGE_SUBSYSTEM_EFI_BOOT_SERVICE_DRIVER:
+             fprintf(outfp,"; OS type : IMAGE_SUBSYSTEM_EFI_BOOT_SERVICE_DRIVER\n");
+             printf("This exe file is desgin run in EFI bios as service driver\n");
+             break;
+        case IMAGE_SUBSYSTEM_EFI_ROM:
+             fprintf(outfp,"; OS type : IMAGE_SUBSYSTEM_EFI_ROM\n");
+             printf("This exe file is EFI ROM\n");
+             break;
+        case IMAGE_SUBSYSTEM_EFI_RUNTIME_DRIVER:
+             fprintf(outfp,"; OS type : IMAGE_SUBSYSTEM_EFI_RUNTIME_DRIVER\n");
+             printf("This exe file is desgin run in EFI bios as driver\n");
+             break;
+        case IMAGE_SUBSYSTEM_NATIVE:
+             fprintf(outfp,"; OS type : IMAGE_SUBSYSTEM_NATIVE\n");
+             printf("This exe file does not need any subsystem\n");
+             break;
+        case IMAGE_SUBSYSTEM_NATIVE_WINDOWS:
+             fprintf(outfp,"; OS type : IMAGE_SUBSYSTEM_NATIVE_WINDOWS\n");
+             printf("This exe file is desgin run on Windows 9x as driver \n");
+             break;
+        case IMAGE_SUBSYSTEM_OS2_CUI:
+             fprintf(outfp,"; OS type : IMAGE_SUBSYSTEM_OS2_CUI\n");
+             printf("This exe file is desgin run on OS2 as CUI\n");
+             break;
+        case IMAGE_SUBSYSTEM_POSIX_CUI:
+             fprintf(outfp,"; OS type : IMAGE_SUBSYSTEM_POSIX_CUI\n");
+             printf("This exe file is desgin run on POSIX as CUI\n");
+             break;
+        case IMAGE_SUBSYSTEM_WINDOWS_CE_GUI:
+             fprintf(outfp,"; OS type : IMAGE_SUBSYSTEM_WINDOWS_CE_GUI\n");
+             printf("This exe file is desgin run on Windows CE as GUI\n");
+             break;
+        case IMAGE_SUBSYSTEM_WINDOWS_CUI:
+             fprintf(outfp,"; OS type : IMAGE_SUBSYSTEM_WINDOWS_CUI\n");
+             printf("This exe file is desgin run on Windows as CUI\n");
+             break;
+        case IMAGE_SUBSYSTEM_WINDOWS_GUI:
+             fprintf(outfp,"; OS type : IMAGE_SUBSYSTEM_WINDOWS_GUI\n");
+             printf("This exe file is desgin run on Windows as GUI\n");
+             break;
+        case IMAGE_SUBSYSTEM_XBOX:
+             fprintf(outfp,"; OS type : IMAGE_SUBSYSTEM_XBOX\n");
+             printf("This exe file is desgin run on X-Box\n");
+             break;
+        default:
+            fprintf(outfp,"; OS type : Unknown\n");
+            printf("Unknown OS : SubID : %d\n",NtHeader->OptionalHeader.Subsystem);
+            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);
+    NumberOfSections = NtHeader->FileHeader.NumberOfSections;
+
+    for (NumberOfSectionsCount = 0; NumberOfSectionsCount < NumberOfSections; NumberOfSectionsCount++, SectionHeader++)
+    {
+       if (strnicmp((PCHAR) SectionHeader->Name,".rsrc",5)==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:
+                     printf("CPU ALPHA Detected no CPUBrain implement for it\n");
+                     fprintf(outfp,"; CPU found Alpha\n");
+                     machine_type = IMAGE_FILE_MACHINE_ALPHA;
+                     return 3;
+
+                case IMAGE_FILE_MACHINE_ALPHA64:
+                     printf("CPU ALPHA64/AXP64 Detected no CPUBrain implement for it\n");
+                     fprintf(outfp,"; CPU found Alpha64/AXP64\n");
+                     machine_type = IMAGE_FILE_MACHINE_ALPHA64;
+                     return 3;
+
+                case IMAGE_FILE_MACHINE_AM33:
+                     printf("CPU AM33 Detected no CPUBrain implement for it\n");
+                     fprintf(outfp,"; CPU found AM33\n");
+                     machine_type = IMAGE_FILE_MACHINE_AM33;
+                     return 3;
+
+                case IMAGE_FILE_MACHINE_AMD64:
+                     printf("CPU AMD64 Detected no CPUBrain implement for it\n");
+                     fprintf(outfp,"; CPU found AMD64\n");
+                     machine_type = IMAGE_FILE_MACHINE_AMD64;
+                     return 3;
+
+                case IMAGE_FILE_MACHINE_ARM:
+                     printf("CPU ARM Detected no CPUBrain implement for it\n");
+                     fprintf(outfp,"; CPU found ARM\n");
+                     machine_type = IMAGE_FILE_MACHINE_ARM;
+                     return 3;
+
+                case IMAGE_FILE_MACHINE_CEE:
+                     printf("CPU CEE Detected no CPUBrain implement for it\n");
+                     fprintf(outfp,"; CPU found CEE\n");
+                     machine_type = IMAGE_FILE_MACHINE_CEE;
+                     return 3;
+
+                case IMAGE_FILE_MACHINE_CEF:
+                     printf("CPU CEF Detected no CPUBrain implement for it\n");
+                     fprintf(outfp,"; CPU found CEF\n");
+                     machine_type = IMAGE_FILE_MACHINE_CEF;
+                     return 3;
+
+                case IMAGE_FILE_MACHINE_EBC:
+                     printf("CPU EBC Detected no CPUBrain implement for it\n");
+                     fprintf(outfp,"; CPU found EBC\n");
+                     machine_type = IMAGE_FILE_MACHINE_EBC;
+                     return 3;
+
+                case IMAGE_FILE_MACHINE_I386:
+                     printf("CPU I386 Detected no CPUBrain implement for it\n");
+                     fprintf(outfp,"; CPU found I386\n");
+                     machine_type = IMAGE_FILE_MACHINE_I386;
+                     return 3;
+
+                case IMAGE_FILE_MACHINE_IA64:
+                     printf("CPU IA64 Detected no CPUBrain implement for it\n");
+                     fprintf(outfp,"; CPU found IA64\n");
+                     machine_type = IMAGE_FILE_MACHINE_IA64;
+                     return 3;
+
+                case IMAGE_FILE_MACHINE_M32R:
+                     printf("CPU M32R Detected no CPUBrain implement for it\n");
+                     fprintf(outfp,"; CPU found M32R\n");
+                     machine_type = IMAGE_FILE_MACHINE_M32R;
+                     return 3;
+
+                case IMAGE_FILE_MACHINE_MIPS16:
+                     printf("CPU MIPS16 Detected no CPUBrain implement for it\n");
+                     fprintf(outfp,"; CPU found MIPS16\n");
+                     machine_type = IMAGE_FILE_MACHINE_MIPS16;
+                     return 3;
+
+                case IMAGE_FILE_MACHINE_MIPSFPU:
+                     printf("CPU MIPSFPU Detected no CPUBrain implement for it\n");
+                     fprintf(outfp,"; CPU found MIPSFPU\n");
+                     machine_type = IMAGE_FILE_MACHINE_MIPSFPU;
+                     return 3;
+
+                case IMAGE_FILE_MACHINE_MIPSFPU16:
+                     printf("CPU MIPSFPU16 Detected no CPUBrain implement for it\n");
+                     fprintf(outfp,"; CPU found MIPSFPU16\n");
+                     machine_type = IMAGE_FILE_MACHINE_MIPSFPU16;
+                     return 3;
+
+               case IMAGE_FILE_MACHINE_POWERPC:
+                    printf("CPU POWERPC Detected partily CPUBrain implement for it\n");
+                    fprintf(outfp,"; CPU found POWERPC\n");
+                         //PPCBrain(memory, pos, cpu_size, base, 0, outfp);
+                    machine_type = IMAGE_FILE_MACHINE_POWERPC;
+                    return PPCBrain(memory+SectionHeader->PointerToRawData,  0, SectionHeader->SizeOfRawData, 0, 0, outfp,mode);
+
+
+               case IMAGE_FILE_MACHINE_POWERPCFP:
+                    printf("CPU POWERPCFP Detected no CPUBrain implement for it\n");
+                    fprintf(outfp,"; CPU found POWERPCFP\n");
+                    machine_type = IMAGE_FILE_MACHINE_POWERPCFP;
+                    return 3;
+
+               case IMAGE_FILE_MACHINE_R10000:
+                    printf("CPU R10000 Detected no CPUBrain implement for it\n");
+                    fprintf(outfp,"; CPU found R10000\n");
+                    machine_type = IMAGE_FILE_MACHINE_R10000;
+                    return 3;
+
+               case IMAGE_FILE_MACHINE_R3000:
+                    printf("CPU R3000 Detected no CPUBrain implement for it\n");
+                    fprintf(outfp,"; CPU found R3000\n");
+                    machine_type = IMAGE_FILE_MACHINE_R3000;
+                    return 3;
+
+               case IMAGE_FILE_MACHINE_R4000:
+                    printf("CPU R4000 Detected no CPUBrain implement for it\n");
+                    fprintf(outfp,"; CPU found R4000\n");
+                    machine_type = IMAGE_FILE_MACHINE_R4000;
+                    return 3;
+
+               case IMAGE_FILE_MACHINE_SH3:
+                    printf("CPU SH3 Detected no CPUBrain implement for it\n");
+                    fprintf(outfp,"; CPU found SH3\n");
+                    machine_type = IMAGE_FILE_MACHINE_SH3;
+                    return 3;
+
+               case IMAGE_FILE_MACHINE_SH3DSP:
+                    printf("CPU SH3DSP Detected no CPUBrain implement for it\n");
+                    fprintf(outfp,"; CPU found SH3DSP\n");
+                    machine_type = IMAGE_FILE_MACHINE_SH3DSP;
+                    return 3;
+
+               case IMAGE_FILE_MACHINE_SH3E:
+                    printf("CPU SH3E Detected no CPUBrain implement for it\n");
+                    fprintf(outfp,"; CPU found SH3E\n");
+                    machine_type = IMAGE_FILE_MACHINE_SH3E;
+                    return 3;
+
+               case IMAGE_FILE_MACHINE_SH4:
+                    printf("CPU SH4 Detected no CPUBrain implement for it\n");
+                    fprintf(outfp,"; CPU found SH4\n");
+                    machine_type = IMAGE_FILE_MACHINE_SH4;
+                    return 3;
+
+               case IMAGE_FILE_MACHINE_SH5:
+                    printf("CPU SH5 Detected no CPUBrain implement for it\n");
+                    fprintf(outfp,"; CPU found SH5\n");
+                    machine_type = IMAGE_FILE_MACHINE_SH5;
+                    return 3;
+
+               case IMAGE_FILE_MACHINE_THUMB:
+                    printf("CPU THUMB Detected no CPUBrain implement for it\n");
+                    fprintf(outfp,"; CPU found THUMB\n");
+                    machine_type = IMAGE_FILE_MACHINE_THUMB;
+                    return 3;
+
+               case IMAGE_FILE_MACHINE_TRICORE:
+                    printf("CPU TRICORE Detected no CPUBrain implement for it\n");
+                    fprintf(outfp,"; CPU found TRICORE\n");
+                    machine_type = IMAGE_FILE_MACHINE_TRICORE;
+                    return 3;
+
+               case IMAGE_FILE_MACHINE_WCEMIPSV2:
+                    printf("CPU WCEMIPSV2 Detected no CPUBrain implement for it\n");
+                    fprintf(outfp,"; CPU found WCEMIPSV2\n");
+                    machine_type = IMAGE_FILE_MACHINE_WCEMIPSV2;
+                    return 3;
+
+               default:
+                    printf("Unknown Machine : %d",NtHeader->FileHeader.Machine);
+                    return 4;
+            /* End case swich */
+            }
+       /* End if .text statment */
+      }
+    /* End for loop */
+   } 
+
+   return 0;
+}

Modified: trunk/rosapps/devutils/cputointel/any_op.h
URL: http://svn.reactos.org/svn/reactos/trunk/rosapps/devutils/cputointel/any_op.h?rev=25453&r1=25452&r2=25453&view=diff
==============================================================================
--- trunk/rosapps/devutils/cputointel/any_op.h (original)
+++ trunk/rosapps/devutils/cputointel/any_op.h Sun Jan 14 21:01:56 2007
@@ -6,9 +6,9 @@
 typedef struct _BrainAnalys
 {
     CPU_UNINT op;  /*  one tranlator for any cpu type set our own opcode */
-    CPU_INT  type; /*  0 = source are memmory, 1 source are register */
-                   /*  2 = dest are memmory,   4 dest are register */
-                   /*  8 = source are imm                          */
+    CPU_INT  type; /*  1 = source are memmory, 2 source are register */
+                   /*  4 = dest are memmory,   8 dest are register */
+                   /*  16 = source are imm                          */
 
     CPU_INT src_size; /* who many bits are src not vaild for reg*/
     CPU_INT dst_size; /* who many bits are dst not vaild for reg*/
@@ -23,5 +23,5 @@
     CPU_BYTE* ptr_prev; /* hook previus one */
 } MYBrainAnalys, *PMYBrainAnalys;
 
-extern PMYBrainAnalys pMyBrainAnalys;
-
+extern PMYBrainAnalys pMyBrainAnalys;     /* current working address */
+extern PMYBrainAnalys pStartMyBrainAnalys; /* start address */

Modified: trunk/rosapps/devutils/cputointel/misc.c
URL: http://svn.reactos.org/svn/reactos/trunk/rosapps/devutils/cputointel/misc.c?rev=25453&r1=25452&r2=25453&view=diff
==============================================================================
--- trunk/rosapps/devutils/cputointel/misc.c (original)
+++ trunk/rosapps/devutils/cputointel/misc.c Sun Jan 14 21:01:56 2007
@@ -140,6 +140,7 @@
             return -1;
         }
         ZeroMemory(pMyBrainAnalys,sizeof(MYBrainAnalys));
+        pStartMyBrainAnalys = pMyBrainAnalys;
     }
     else
     {
@@ -149,7 +150,7 @@
         {
             return -1;
         }
-        ZeroMemory(pMyBrainAnalys,sizeof(MYBrainAnalys));
+        ZeroMemory(tmp,sizeof(MYBrainAnalys));
 
         pMyBrainAnalys->ptr_next = (CPU_BYTE*)tmp;
         tmp->ptr_prev= (CPU_BYTE*)pMyBrainAnalys;

Modified: trunk/rosapps/devutils/cputointel/misc.h
URL: http://svn.reactos.org/svn/reactos/trunk/rosapps/devutils/cputointel/misc.h?rev=25453&r1=25452&r2=25453&view=diff
==============================================================================
--- trunk/rosapps/devutils/cputointel/misc.h (original)
+++ trunk/rosapps/devutils/cputointel/misc.h Sun Jan 14 21:01:56 2007
@@ -26,5 +26,5 @@
 CPU_INT AllocAny();
 CPU_INT FreeAny();
 CPU_INT AnyalsingProcess();
-CPU_INT ConvertToIntelProcess(FILE *outfp,  char *cpuid);
+CPU_INT ConvertToIntelProcess(FILE *outfp, CPU_INT cpuid);
 




More information about the Ros-diffs mailing list