mirror of
https://github.com/reactos/reactos.git
synced 2024-09-30 22:47:28 +00:00
This break the ppc disambler support and convert to ia32, temporary
I change the desgin lite to preopare the ia32 to ppc svn path=/trunk/; revision=25495
This commit is contained in:
parent
60fc740a7d
commit
69999a5ad4
114
rosapps/devutils/cputointel/ConvertToIA32Process.c
Normal file
114
rosapps/devutils/cputointel/ConvertToIA32Process.c
Normal file
|
@ -0,0 +1,114 @@
|
|||
|
||||
#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 eax, CPU_INT ebp,
|
||||
CPU_INT edx, CPU_INT esp,
|
||||
PMYBrainAnalys pMystart,
|
||||
PMYBrainAnalys pMyend, CPU_INT regbits,
|
||||
CPU_INT HowManyRegInUse)
|
||||
{
|
||||
|
||||
CPU_INT stack = 0;
|
||||
CPU_UNINT tmp;
|
||||
CPU_INT setup_ebp = 0 ; /* 0 = no, 1 = yes */
|
||||
|
||||
if (HowManyRegInUse > 8)
|
||||
{
|
||||
setup_ebp =1; /* we will use ebx as ebp */
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
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, 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,"; Start the program \n");
|
||||
while (pMystart!=pMyend)
|
||||
{
|
||||
/* fixme the line lookup from anaylysing process */
|
||||
|
||||
/* mov not full implement */
|
||||
if (pMystart->op == OP_ANY_mov)
|
||||
{
|
||||
printf("waring OP_ANY_mov are not full implement\n");
|
||||
|
||||
if ((pMystart->type & 8)== 8)
|
||||
{
|
||||
/* dst are register */
|
||||
tmp = stack - (pMystart->dst*regbits);
|
||||
|
||||
if ((pMystart->type & 16)== 16)
|
||||
{
|
||||
/* source are imm */
|
||||
|
||||
if (pMyBrainAnalys->dst == eax)
|
||||
{
|
||||
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 (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");
|
||||
//}
|
||||
fprintf(outfp,"ret\n");
|
||||
}
|
||||
pMystart = (PMYBrainAnalys) pMystart->ptr_next;
|
||||
}
|
||||
return 0;
|
||||
}
|
|
@ -1,90 +0,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;
|
||||
}
|
|
@ -95,7 +95,7 @@ int main(int argc, char * argv[])
|
|||
//}
|
||||
|
||||
//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
|
||||
|
||||
}
|
||||
|
|
|
@ -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 @@ CPU_INT LoadPFileImage( char *infileName, char *outputfileName,
|
|||
if (mode > 0)
|
||||
{
|
||||
AnyalsingProcess();
|
||||
ConvertToIntelProcess(outfp,machine_type);
|
||||
ConvertProcess(outfp, machine_type, ToMachine_type);
|
||||
FreeAny();
|
||||
}
|
||||
fclose(outfp);
|
||||
|
@ -137,7 +138,7 @@ CPU_INT LoadPFileImage( char *infileName, char *outputfileName,
|
|||
if (mode > 1)
|
||||
{
|
||||
AnyalsingProcess();
|
||||
ConvertToIntelProcess(outfp,machine_type);
|
||||
ConvertProcess(outfp, machine_type, ToMachine_type);
|
||||
FreeAny();
|
||||
}
|
||||
fclose(outfp);
|
||||
|
@ -148,7 +149,7 @@ CPU_INT LoadPFileImage( char *infileName, char *outputfileName,
|
|||
if (mode > 1)
|
||||
{
|
||||
AnyalsingProcess();
|
||||
ConvertToIntelProcess(outfp,machine_type);
|
||||
ConvertProcess(outfp, machine_type, ToMachine_type);
|
||||
FreeAny();
|
||||
}
|
||||
fclose(outfp);
|
||||
|
@ -160,7 +161,7 @@ CPU_INT LoadPFileImage( char *infileName, char *outputfileName,
|
|||
if (mode > 1)
|
||||
{
|
||||
AnyalsingProcess();
|
||||
ConvertToIntelProcess(outfp,machine_type);
|
||||
ConvertProcess(outfp, machine_type, ToMachine_type);
|
||||
FreeAny();
|
||||
}
|
||||
fclose(outfp);
|
||||
|
@ -172,7 +173,7 @@ CPU_INT LoadPFileImage( char *infileName, char *outputfileName,
|
|||
if (mode > 1)
|
||||
{
|
||||
AnyalsingProcess();
|
||||
ConvertToIntelProcess(outfp,machine_type);
|
||||
ConvertProcess(outfp, machine_type, ToMachine_type);
|
||||
FreeAny();
|
||||
}
|
||||
fclose(outfp);
|
||||
|
@ -184,7 +185,7 @@ CPU_INT LoadPFileImage( char *infileName, char *outputfileName,
|
|||
if (mode > 1)
|
||||
{
|
||||
AnyalsingProcess();
|
||||
ConvertToIntelProcess(outfp,machine_type);
|
||||
ConvertProcess(outfp, machine_type, ToMachine_type);
|
||||
FreeAny();
|
||||
}
|
||||
fclose(outfp);
|
||||
|
@ -196,7 +197,7 @@ CPU_INT LoadPFileImage( char *infileName, char *outputfileName,
|
|||
if (mode > 1)
|
||||
{
|
||||
AnyalsingProcess();
|
||||
ConvertToIntelProcess(outfp,machine_type);
|
||||
ConvertProcess(outfp, machine_type, ToMachine_type);
|
||||
FreeAny();
|
||||
}
|
||||
fclose(outfp);
|
||||
|
@ -208,7 +209,7 @@ CPU_INT LoadPFileImage( char *infileName, char *outputfileName,
|
|||
if (mode > 1)
|
||||
{
|
||||
AnyalsingProcess();
|
||||
ConvertToIntelProcess(outfp,machine_type);
|
||||
ConvertProcess(outfp, machine_type, ToMachine_type);
|
||||
FreeAny();
|
||||
}
|
||||
fclose(outfp);
|
||||
|
@ -223,7 +224,7 @@ CPU_INT LoadPFileImage( char *infileName, char *outputfileName,
|
|||
if (mode > 1)
|
||||
{
|
||||
AnyalsingProcess();
|
||||
ConvertToIntelProcess(outfp,machine_type);
|
||||
ConvertProcess(outfp, machine_type, ToMachine_type);
|
||||
FreeAny();
|
||||
}
|
||||
fclose(outfp);
|
||||
|
|
73
rosapps/devutils/cputointel/ReadMe.txt
Normal file
73
rosapps/devutils/cputointel/ReadMe.txt
Normal file
|
@ -0,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
|
||||
|
||||
|
|
@ -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 @@ typedef struct _BrainAnalys
|
|||
|
||||
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 @@ typedef struct _BrainAnalys
|
|||
|
||||
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
|
||||
|
|
|
@ -6,15 +6,15 @@
|
|||
<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>
|
|
@ -26,5 +26,7 @@ CPU_UNINT GetData32Be(CPU_BYTE *cpu_buffer);
|
|||
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);
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue