#include "misc.h"
#include "any_op.h"
-CPU_INT ConvertToIA32Process( FILE *outfp, CPU_INT eax, CPU_INT ebp,
- CPU_INT edx, CPU_INT esp,
+/*
+ * eax = register 3
+ * edx = register 4
+ * esp = register 1
+ * ebp = register 31
+
+ * ecx = 8
+ * ebx = 9
+ * esi = 10
+ * edi = 11
+ * mmx/sse/fpu 0 = 12
+ * mmx/sse/fpu 1 = 14
+ * mmx/sse/fpu 2 = 16
+ * mmx/sse/fpu 3 = 18
+ * mmx/sse/fpu 4 = 20
+ * mmx/sse/fpu 5 = 22
+ * mmx/sse/fpu 6 = 24
+ * mmx/sse/fpu 7 = 28
+ */
+
+CPU_INT ConvertToIA32Process( FILE *outfp,
PMYBrainAnalys pMystart,
PMYBrainAnalys pMyend, CPU_INT regbits,
- CPU_INT HowManyRegInUse)
+ CPU_INT HowManyRegInUse,
+ CPU_INT *RegTableCount)
{
CPU_INT stack = 0;
CPU_UNINT tmp;
CPU_INT setup_ebp = 0 ; /* 0 = no, 1 = yes */
+ CPU_INT t=0;
+
+ /* Fixme optimze the RegTableCount table */
- /* Fixme at moment we can not optimze code */
//if (HowManyRegInUse > 9)
- if (HowManyRegInUse > 4)
+ if (HowManyRegInUse > 8)
{
setup_ebp =1; /* we will use ebx as ebp */
stack = HowManyRegInUse * regbits;
}
+ if (RegTableCount[1]!=0)
+ t++;
+ if (RegTableCount[3]!=0)
+ t++;
+ if (RegTableCount[4]!=0)
+ t++;
+ if (RegTableCount[8]!=0)
+ t++;
+ if (RegTableCount[9]!=0)
+ t++;
+ if (RegTableCount[10]!=0)
+ t++;
+ if (RegTableCount[11]!=0)
+ t++;
+ if (RegTableCount[31]!=0)
+ t++;
+
+ if (HowManyRegInUse != t)
+ {
+ /* fixme optimze the table or active the frame pointer */
+ setup_ebp =1; /* we will use ebx as ebp */
+ stack = HowManyRegInUse * regbits;
+ }
+
fprintf(outfp,"BITS 32\n");
fprintf(outfp,"GLOBAL _main\n");
fprintf(outfp,"SECTION .text\n\n");
fprintf(outfp,"mov ebx,esp\n");
fprintf(outfp,"sub esp, %d ; Alloc %d bytes for reg\n\n",stack,stack);
}
- else
- {
- /*
- 0 EAX
- 1 ECX
- 2 EDX
- 5 EBX
- 6 ESP
- 7 EBP
- 8 ESI
- 9 EDI
- */
- }
+
fprintf(outfp,"; Start the program \n");
while (pMystart!=NULL)
{
/* source are imm */
- if (pMystart->dst == eax)
+ /*
+ * esi = 10
+ * edi = 11 */
+
+ /* eax */
+ if (pMystart->dst == RegTableCount[3])
{
if (pMystart->src == 0)
fprintf(outfp,"xor eax,eax\n");
else
fprintf(outfp,"mov eax,%llu\n",pMystart->src);
}
- else if (pMystart->dst == ebp)
+ /* ebp */
+ else if (pMystart->dst == RegTableCount[31])
{
if (pMystart->src == 0)
fprintf(outfp,"xor ebp,ebp\n");
else
fprintf(outfp,"mov ebp,%llu\n",pMystart->src);
}
- else if (pMystart->dst == edx)
+ /* edx */
+ else if (pMystart->dst == RegTableCount[4])
{
if (pMystart->src == 0)
fprintf(outfp,"xor edx,edx\n");
else
fprintf(outfp,"mov edx,%llu\n",pMystart->src);
}
- else if (pMystart->dst == esp)
+ /* esp */
+ else if (pMystart->dst == RegTableCount[1])
{
if (pMystart->src == 0)
fprintf(outfp,"xor esp,esp\n");
else
fprintf(outfp,"mov esp,%llu\n",pMystart->src);
}
+ /* ecx */
+ else if (pMystart->dst == RegTableCount[8])
+ {
+ if (pMystart->src == 0)
+ fprintf(outfp,"xor ecx,ecx\n");
+ else
+ fprintf(outfp,"mov ecx,%llu\n",pMystart->src);
+ }
+ /* ebx */
+ else if (pMystart->dst == RegTableCount[9])
+ {
+ if (pMystart->src == 0)
+ fprintf(outfp,"xor ebx,ebx\n");
+ else
+ fprintf(outfp,"mov ebx,%llu\n",pMystart->src);
+ }
+ /* esi */
+ else if (pMystart->dst == RegTableCount[10])
+ {
+ if (pMystart->src == 0)
+ fprintf(outfp,"xor esi,esi\n");
+ else
+ fprintf(outfp,"mov esi,%llu\n",pMystart->src);
+ }
+ /* edi */
+ else if (pMystart->dst == RegTableCount[10])
+ {
+ if (pMystart->src == 0)
+ fprintf(outfp,"xor edi,edi\n");
+ else
+ fprintf(outfp,"mov edi,%llu\n",pMystart->src);
+ }
else
{
if (setup_ebp == 1)
CPU_INT ConvertProcess(FILE *outfp, CPU_INT FromCpuid, CPU_INT ToCpuid)
{
CPU_INT ret=0;
- CPU_INT eax =-1;
- CPU_INT ebp =-1;
- CPU_INT edx =-1;
- CPU_INT esp =-1;
CPU_INT regbits=-1;
CPU_INT HowManyRegInUse = 0;
CPU_INT RegTableCount[32] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
(FromCpuid == IMAGE_FILE_MACHINE_I386))
{
regbits = 32 / 8;
- esp = 1;
- eax = 3;
- edx = 4;
- ebp = 31;
}
/* FIXME calc where todo first split */
if (RegTableCount[t]!=0)
{
HowManyRegInUse++;
+ RegTableCount[t]=t;
}
-
}
+
/* switch to the acual converting now */
switch (ToCpuid)
{
case IMAGE_FILE_MACHINE_I386:
- ret = ConvertToIA32Process( outfp, eax, ebp,
- edx, esp,
- pMystart,
- pMyend, regbits,
- HowManyRegInUse);
+ ret = ConvertToIA32Process( outfp, pMystart,
+ pMyend, regbits,
+ HowManyRegInUse,
+ RegTableCount);
if (ret !=0)
{
printf("should not happen contact a devloper, x86 fail\n");
break;
case IMAGE_FILE_MACHINE_POWERPC:
- ret = ConvertToPPCProcess( outfp, eax, ebp,
- edx, esp,
- pMystart,
- pMyend, regbits,
- HowManyRegInUse);
+ ret = ConvertToPPCProcess( outfp, pMystart,
+ pMyend, regbits,
+ HowManyRegInUse,
+ RegTableCount);
if (ret !=0)
{
printf("should not happen contact a devloper, x86 fail\n");
* esp = register 1
* ebp = register 31
- * ecx = 5
- * ebx = 6
- * esi = 7
- * edi = 8
- * mmx/sse/fpu 0 = 10
- * mmx/sse/fpu 1 = 12
- * mmx/sse/fpu 2 = 14
- * mmx/sse/fpu 3 = 16
- * mmx/sse/fpu 4 = 18
- * mmx/sse/fpu 5 = 20
- * mmx/sse/fpu 6 = 22
- * mmx/sse/fpu 7 = 24
+ * ecx = 8
+ * ebx = 9
+ * esi = 10
+ * edi = 11
+ * mmx/sse/fpu 0 = 12
+ * mmx/sse/fpu 1 = 14
+ * mmx/sse/fpu 2 = 16
+ * mmx/sse/fpu 3 = 18
+ * mmx/sse/fpu 4 = 20
+ * mmx/sse/fpu 5 = 22
+ * mmx/sse/fpu 6 = 24
+ * mmx/sse/fpu 7 = 28
*/
typedef struct _BrainAnalys
extern PMYBrainAnalys pMyBrainAnalys; /* current working address */
extern PMYBrainAnalys pStartMyBrainAnalys; /* start address */
-CPU_INT ConvertToIA32Process( FILE *outfp, CPU_INT eax, CPU_INT ebp,
- CPU_INT edx, CPU_INT esp,
+CPU_INT ConvertToIA32Process( FILE *outfp,
PMYBrainAnalys pMystart,
PMYBrainAnalys pMyend, CPU_INT regbits,
- CPU_INT HowManyRegInUse);
+ CPU_INT HowManyRegInUse,
+ CPU_INT *RegTableCount);
-CPU_INT ConvertToPPCProcess( FILE *outfp, CPU_INT r3, CPU_INT r31,
- CPU_INT r4, CPU_INT r1,
+CPU_INT ConvertToPPCProcess( FILE *outfp,
PMYBrainAnalys pMystart,
PMYBrainAnalys pMyend, CPU_INT regbits,
- CPU_INT HowManyRegInUse);
+ CPU_INT HowManyRegInUse,
+ CPU_INT *RegTableCount);
#endif