原版本下载地址 :
http://linux.insigma.com.cn/download/software/unifiedkernel-2.6.13.tar.gz
原版本官方网站:
http://linux.insigma.com.cn/
修改版官方网站:
http://www.unifiedkernel.org/
修改版所做的改进,
this version don't need to compile the linux kernel 2.6.13.
just make to test it.
add sysmap.c sysmap.h config.h
modify w32entry.S w32syscall.c w32init.c
test platform fedora core 6.
Include windows.inc
Include kernel32.inc
Include user32.inc
include masm32.inc
IncludeLib kernel32.lib
IncludeLib user32.lib
STEXT MACRO Text
local szText
LOCAL lbl
LOCAL lbllbl
call lbllbl
lbllbl:
pop edx
add edx,6
jmp lbl
szText db Text,0
lbl:
exitm <edx>
ENDM
PATCH_CODE STRUCT
oldptr DWORD ?
destptr DWORD ?
parameter DWORD ?
pcode db 16 ?
code_length DWORD ?
PATCH_CODE ENDS
.data
patch db 32
.CODE
START:
lea edi,patch
mov (PATCH_CODE PTR[edi]).parameter,4
mov (PATCH_CODE PTR[edi]).destptr,MessageBox
mov (PATCH_CODE PTR[edi]).pcode,0c3h
push 0
push STEXT("test")
push STEXT("Hello world!")
push 0
push ExitProcess;return to
push 0
jmp next1
ret
next:;//call before
push eax
push ebx
push ecx
push edx
push edi
push esi
push ebp
mov eax,[esp+28]
shl eax,5
lea edi,patch
add edi,eax
push edi;save this point
mov ecx,(PATCH_CODE PTR[edi]).parameter
and ecx,0ffh
mov edx,ecx
lea esi,[esp+40];copy parameter
shl edx,2
mov edi,esp
sub edi,edx
sub edi,4
rep movsd
mov edi,[esp]
push ebp
mov ebp,esp
sub esp,edx
mov eax,(PATCH_CODE PTR[edi]).destptr
call eax
mov esp,ebp
pop ebp
pop edi
lea eax,(PATCH_CODE PTR[edi]).pcode
mov [esp-4],eax
pop ebp
pop esi
pop edi
pop edx
pop ecx
pop ebx
pop eax
add esp,4
jmp DWORD ptr[esp-36]
ret
next1:
push eax
push ebx
push ecx
push edx
push edi
push esi
push ebp
mov ecx,(PATCH_CODE PTR[edi]).parameter
and ecx,0ffh
mov edx,ecx
lea esi,[esp+36];copy parameter
shl edx,2
mov ebx,edi
mov edi,esp
sub edi,edx
sub edi,8
rep movsd
call retaddr;get eip
retaddr:
pop eax
add eax,34h
mov ecx,esp
sub ecx,edx
sub ecx,12
mov DWORD ptr[ecx],eax;save ret addr.
lea eax,(PATCH_CODE PTR[ebx]).pcode
mov DWORD ptr[ecx-4],eax
mov eax,esp
sub eax,edx
sub eax,12
mov DWORD ptr[esp-8],eax
mov DWORD ptr[esp-4],ebx
pop ebp
pop esi
pop edi
pop edx
pop ecx
pop ebx
pop eax
push ebp
mov ebp,esp
mov esp,[esp-32]
;lea eax,(PATCH_CODE PTR[edi]).pcode
jmp DWORD ptr[esp-4]
mov esp,ebp
pop ebp
add esp,4
push eax
push ebx
push ecx
push edx
push edi
push esi
push ebp
mov ebx,[esp-8]
call ecx;eax,and edx may be usefully
mov esp,ebp
pop ebp
pop ebp
pop esi
pop edi
pop edx
pop ecx
mov eax,[esp-1ch]
mov ebx,[esp+8]
mov DWORD ptr[esp+eax+8],ebx
pop ebx
pop eax
add esp,[esp-24h]
add esp,4
jmp DWORD ptr[esp-4]
ret
jCreateFile proc
push 0
jmp next
jCreateFile endp
END START
typedef struct _PATCH_CODE
{
unsigned long oldptr;
unsigned long destptr;
int parameter;
char pcode[16];
int code_length;
}PATCH_CODE,*PPATCH_CODE;
int get_disasm_len(unsigned char * src)
{
int len = 0;
if((*src >= 0x50)&&(*src <=0x61)) //push EAX -> popad
return 1;
if((*src == 0x83)&&(src[1]==0xec))//sub esp,xx
return 3;
if((*src == 0x81)&&(src[1]==0xec))//sub esp,xxxxxxxx
return 6;
if(*src == 0x6a)//push xx
return 2;
if(*src == 0x68)//push xxxxxxxx
return 5;
if((*src == 0x89)|| (*src == 0x8b))
{
if((src[1]>=0xc0) && (src[1]<=0xff))//mov reg,reg
return 2;
}
return 0;
}
//this is don't support relocate
int add_patch_code(unsigned long prev,unsigned long dest,PPATCH_CODE ppc)
{
int cplen = 0;
int i;
while(cplen<5)
{
i = get_disasm_len((unsigned char *)prev+cplen);
if(i == 0)
return -1;
cplen +=i;
}
memcpy(ppc->pcode,(void *)prev,cplen);
ppc->code_length = cplen;
ppc->pcode[cplen] = 0xe9;//jmp xxxxxxxx
*(DWORD *)(ppc->pcode+cplen+1) = prev - ((DWORD)ppc->pcode+cplen) - 5;
return 0;
}
int unpatch_kernel_code()
{
return 0;
}
int patch_kernel_code()
{
PATCH_CODE pc;
memset(&pc,0,sizeof(PATCH_CODE));
add_patch_code((unsigned long)CreateFile,0,&pc);
return 0;
}