Author: greatlrd Date: Wed Jan 17 18:02:43 2007 New Revision: 25495
URL: http://svn.reactos.org/svn/reactos?rev=25495&view=rev Log: This break the ppc disambler support and convert to ia32, temporary I change the desgin lite to preopare the ia32 to ppc
Added: trunk/rosapps/devutils/cputointel/ConvertToIA32Process.c - copied, changed from r25473, trunk/rosapps/devutils/cputointel/ConvertToIntelProcess.c trunk/rosapps/devutils/cputointel/ReadMe.txt Removed: trunk/rosapps/devutils/cputointel/ConvertToIntelProcess.c Modified: trunk/rosapps/devutils/cputointel/CpuToIntel.c trunk/rosapps/devutils/cputointel/ImageLoader.c trunk/rosapps/devutils/cputointel/any_op.h trunk/rosapps/devutils/cputointel/cputointel.rbuild trunk/rosapps/devutils/cputointel/misc.h
Copied: trunk/rosapps/devutils/cputointel/ConvertToIA32Process.c (from r25473, trunk/rosapps/devutils/cputointel/ConvertToIntelProcess.c) URL: http://svn.reactos.org/svn/reactos/trunk/rosapps/devutils/cputointel/Convert... ============================================================================== --- trunk/rosapps/devutils/cputointel/ConvertToIntelProcess.c (original) +++ trunk/rosapps/devutils/cputointel/ConvertToIA32Process.c Wed Jan 17 18:02:43 2007 @@ -8,83 +8,107 @@ #include "misc.h" #include "any_op.h"
-CPU_INT ConvertToIntelProcess(FILE *outfp, CPU_INT cpuid) +CPU_INT ConvertToIntelProcess( FILE *outfp, CPU_INT eax, CPU_INT ebp, + CPU_INT edx, CPU_INT esp, + PMYBrainAnalys pMystart, + PMYBrainAnalys pMyend, CPU_INT regbits, + CPU_INT HowManyRegInUse) { - CPU_INT eax = 0; + CPU_INT stack = 0; - CPU_INT regbits = 0; CPU_UNINT tmp; + CPU_INT setup_ebp = 0 ; /* 0 = no, 1 = yes */
- pMyBrainAnalys = pStartMyBrainAnalys; + if (HowManyRegInUse > 8) + { + setup_ebp =1; /* we will use ebx as ebp */ + }
- 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,"; compile with nasm filename.asm -f win32, ld 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,"\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) + while (pMystart!=pMyend) { /* fixme the line lookup from anaylysing process */
/* mov not full implement */ - if (pMyBrainAnalys->op == OP_ANY_mov) + if (pMystart->op == OP_ANY_mov) { printf("waring OP_ANY_mov are not full implement\n");
- if ((pMyBrainAnalys->type & 8)== 8) + if ((pMystart->type & 8)== 8) { /* dst are register */ - tmp = stack - (pMyBrainAnalys->dst*regbits); + tmp = stack - (pMystart->dst*regbits);
- if ((pMyBrainAnalys->type & 16)== 16) + if ((pMystart->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); + if (pMystart->src == 0) + fprintf(outfp,"xor eax,eax\n"); + else + fprintf(outfp,"mov eax,%llu\n",pMystart->src); + } + else if (pMystart->dst == ebp) + { + if (pMystart->src == 0) + fprintf(outfp,"xor ebp,ebp\n"); + else + fprintf(outfp,"mov ebp,%llu\n",pMystart->src); + } + else if (pMystart->dst == edx) + { + if (pMystart->src == 0) + fprintf(outfp,"xor edx,edx\n"); + else + fprintf(outfp,"mov edx,%llu\n",pMystart->src); + } + else if (pMystart->dst == esp) + { + if (pMystart->src == 0) + fprintf(outfp,"xor esp,esp\n"); + else + fprintf(outfp,"mov esp,%llu\n",pMystart->src); + } + else + { + //fprintf(outfp,"mov dword [ebp - %d], %llu\n", tmp, pMystart->src); + printf("not support move from register\n"); } } } /* end pMyBrainAnalys->type & 8 */ }
/* return */ - if (pMyBrainAnalys->op == OP_ANY_ret) + if (pMystart->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"); - } + //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; + pMystart = (PMYBrainAnalys) pMystart->ptr_next; } return 0; }
Removed: trunk/rosapps/devutils/cputointel/ConvertToIntelProcess.c URL: http://svn.reactos.org/svn/reactos/trunk/rosapps/devutils/cputointel/Convert... ============================================================================== --- trunk/rosapps/devutils/cputointel/ConvertToIntelProcess.c (original) +++ trunk/rosapps/devutils/cputointel/ConvertToIntelProcess.c (removed) @@ -1,90 +1,0 @@ - -#include <windows.h> -#include <winnt.h> - -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include "misc.h" -#include "any_op.h" - -CPU_INT ConvertToIntelProcess(FILE *outfp, CPU_INT cpuid) -{ - 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/CpuToIn... ============================================================================== --- trunk/rosapps/devutils/cputointel/CpuToIntel.c (original) +++ trunk/rosapps/devutils/cputointel/CpuToIntel.c Wed Jan 17 18:02:43 2007 @@ -95,7 +95,7 @@ //}
//return LoadPFileImage(infile,outfile,BaseAddress,cpuid,type, mode); - //return LoadPFileImage("e:\testms.exe","e:\cputointel.asm",0,0,0,0); // disambler + // return LoadPFileImage("e:\testppc.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/ImageLoader.c URL: http://svn.reactos.org/svn/reactos/trunk/rosapps/devutils/cputointel/ImageLo... ============================================================================== --- trunk/rosapps/devutils/cputointel/ImageLoader.c (original) +++ trunk/rosapps/devutils/cputointel/ImageLoader.c Wed Jan 17 18:02:43 2007 @@ -10,6 +10,7 @@ #include "From/PPC/PPC.h"
static CPU_INT machine_type = 0; +static CPU_INT ToMachine_type = IMAGE_FILE_MACHINE_I386;
/* * infileName file name to convert or disambler @@ -121,7 +122,7 @@ if (mode > 0) { AnyalsingProcess(); - ConvertToIntelProcess(outfp,machine_type); + ConvertProcess(outfp, machine_type, ToMachine_type); FreeAny(); } fclose(outfp); @@ -137,7 +138,7 @@ if (mode > 1) { AnyalsingProcess(); - ConvertToIntelProcess(outfp,machine_type); + ConvertProcess(outfp, machine_type, ToMachine_type); FreeAny(); } fclose(outfp); @@ -148,7 +149,7 @@ if (mode > 1) { AnyalsingProcess(); - ConvertToIntelProcess(outfp,machine_type); + ConvertProcess(outfp, machine_type, ToMachine_type); FreeAny(); } fclose(outfp); @@ -160,7 +161,7 @@ if (mode > 1) { AnyalsingProcess(); - ConvertToIntelProcess(outfp,machine_type); + ConvertProcess(outfp, machine_type, ToMachine_type); FreeAny(); } fclose(outfp); @@ -172,7 +173,7 @@ if (mode > 1) { AnyalsingProcess(); - ConvertToIntelProcess(outfp,machine_type); + ConvertProcess(outfp, machine_type, ToMachine_type); FreeAny(); } fclose(outfp); @@ -184,7 +185,7 @@ if (mode > 1) { AnyalsingProcess(); - ConvertToIntelProcess(outfp,machine_type); + ConvertProcess(outfp, machine_type, ToMachine_type); FreeAny(); } fclose(outfp); @@ -196,7 +197,7 @@ if (mode > 1) { AnyalsingProcess(); - ConvertToIntelProcess(outfp,machine_type); + ConvertProcess(outfp, machine_type, ToMachine_type); FreeAny(); } fclose(outfp); @@ -208,7 +209,7 @@ if (mode > 1) { AnyalsingProcess(); - ConvertToIntelProcess(outfp,machine_type); + ConvertProcess(outfp, machine_type, ToMachine_type); FreeAny(); } fclose(outfp); @@ -223,7 +224,7 @@ if (mode > 1) { AnyalsingProcess(); - ConvertToIntelProcess(outfp,machine_type); + ConvertProcess(outfp, machine_type, ToMachine_type); FreeAny(); } fclose(outfp);
Added: trunk/rosapps/devutils/cputointel/ReadMe.txt URL: http://svn.reactos.org/svn/reactos/trunk/rosapps/devutils/cputointel/ReadMe.... ============================================================================== --- trunk/rosapps/devutils/cputointel/ReadMe.txt (added) +++ trunk/rosapps/devutils/cputointel/ReadMe.txt Wed Jan 17 18:02:43 2007 @@ -1,0 +1,73 @@ +CpuToIntel is a experment tools and is strict under havy devloping + + +The Idea +The idea is to convert a binary file or win pe file +from one cpu to another cpu, But it does not exists +plan to port over diffent hardware architect like +how diffent hw comucate, example x86 DMA controller +to PPC like. It is only to convert the the binary or +pe file to another cpu. it mean a user mode apps +will always be ported, but if it self modify code +it will not work. But it exists a idea to deal with +self modify code. + + +The idea to handling self modify code +The idea is to add a small emulator that +runing the apps or adding a anylasuing process +to dectect self modify code and extract it +this is hard thing todo. almost imposible + + +Why the name are CpuToIntel +When I start write on it it was only ment to convert +from ARM, PPC, m68k to X86 but then I come think of +ReactOS PPC port that is going on. for or later we +will need something that doing convert from x86 to +PPC apps. It exists two way todo it. One is to use +dymatic translation a jit, like UAE or QEMU doing +converting. But it will lose of allot of speed if +it is a game or a havy apps to much. So the idea +is to convert the whole file in one sweep. will give + one other problem it will be a slow process todo it, +and hard dectect self modify program. so not all program +can be really convert with this process. + + +Who will it work +we take it step for step and I will describe the +binary translations how it works. The PE file +work simluare way. + +step 1 : it will disambler the program frist + +step 2 : translate everthing to a middle asm dialect, + it is own asm dialect it is not suite for a real + +step 3 : (not implement) send it to ananalysing processs + to get any name or mark out which row is a new functions + +step 3.5 (not implement) split the code into functions here + +step 4 : Now it start the convert process. + +step 4.5 (not implement) maybe a optimzer. + +step 5 : now it is finish. + + +The arch that are plan +PPC to IA32, PPC (work in progress) +m68k to IA32, PPC (stubed) +ARM to IA32, PPC (stubed) +IA32 to IA32, PPC (work in progress) + + +The Winodws NT PPC and x85 diffrent +R1 The stack pointer equal with x86 esp +R3 The return reg equal with x86 eax +R4 The return reg equal with x86 edx +R31 The base pointer equal with x86 ebp + +
Modified: trunk/rosapps/devutils/cputointel/any_op.h URL: http://svn.reactos.org/svn/reactos/trunk/rosapps/devutils/cputointel/any_op.... ============================================================================== --- trunk/rosapps/devutils/cputointel/any_op.h (original) +++ trunk/rosapps/devutils/cputointel/any_op.h Wed Jan 17 18:02:43 2007 @@ -1,4 +1,6 @@
+#ifndef __ANY_OP_H__ +#define __ANY_OP_H__
#define OP_ANY_mov 0x00000000 #define OP_ANY_ret 0x00000001 @@ -18,6 +20,11 @@
CPU_UNINT memAdr; /* where are we in the current memory pos + baseaddress */
+ CPU_INT row; /* 0 = no row, + * 1 = row is bcc (conditions), + * 2 = row is jsr (Call) + */ + /* try translate the Adress to a name */ CPU_BYTE* ptr_next; /* hook next one */ CPU_BYTE* ptr_prev; /* hook previus one */ @@ -25,3 +32,11 @@
extern PMYBrainAnalys pMyBrainAnalys; /* current working address */ extern PMYBrainAnalys pStartMyBrainAnalys; /* start address */ + +CPU_INT ConvertToIntelProcess( FILE *outfp, CPU_INT eax, CPU_INT ebp, + CPU_INT edx, CPU_INT esp, + PMYBrainAnalys pMystart, + PMYBrainAnalys pMyend, CPU_INT regbits, + CPU_INT HowManyRegInUse); + +#endif
Modified: trunk/rosapps/devutils/cputointel/cputointel.rbuild URL: http://svn.reactos.org/svn/reactos/trunk/rosapps/devutils/cputointel/cputoin... ============================================================================== --- trunk/rosapps/devutils/cputointel/cputointel.rbuild (original) +++ trunk/rosapps/devutils/cputointel/cputointel.rbuild Wed Jan 17 18:02:43 2007 @@ -6,14 +6,14 @@ <library>kernel32</library> <library>user32</library>
- <file>AnyalsingProcess.c</file> - <file>ConvertToIntelProcess.c</file> <file>CpuToIntel.c</file> - <file>ImageLoader.c</file> <file>misc.c</file>
<file>From/ARM/ARMBrain.c</file> <file>From/ARM/ARMopcode.c</file> + + <file>From/IA32/IA32Brain.c</file> + <file>From/IA32/IA32opcode.c</file>
<file>From/m68k/M68kBrain.c</file> <file>From/m68k/M68kopcode.c</file> @@ -24,4 +24,9 @@ <file>From/dummycpu/DummyBrain.c</file> <file>From/dummycpu/Dummyopcode.c</file>
+ <file>ImageLoader.c</file> + <file>AnyalsingProcess.c</file> + <file>ConvertingProcess.c</file> + <file>ConvertToIA32Process.c</file> + </module>
Modified: trunk/rosapps/devutils/cputointel/misc.h URL: http://svn.reactos.org/svn/reactos/trunk/rosapps/devutils/cputointel/misc.h?... ============================================================================== --- trunk/rosapps/devutils/cputointel/misc.h (original) +++ trunk/rosapps/devutils/cputointel/misc.h Wed Jan 17 18:02:43 2007 @@ -26,5 +26,7 @@ CPU_INT AllocAny(); CPU_INT FreeAny(); CPU_INT AnyalsingProcess(); -CPU_INT ConvertToIntelProcess(FILE *outfp, CPU_INT cpuid);
+CPU_INT ConvertProcess(FILE *outfp, CPU_INT FromCpuid, CPU_INT ToCpuid); + +