forked from KolibriOS/kolibrios
'kerpack' removed (it already exists on SVN in /programs/other folder). 'MyKey' updated till ver. 0.2
git-svn-id: svn://kolibrios.org@1816 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
parent
7920032ceb
commit
3d31c6abab
@ -17,7 +17,7 @@ macro start_draw_window x,y,xsize,ysize,areacolor,caption,capsize
|
||||
; WINDOW LABEL
|
||||
mov eax, 4 ; function 4 : write text to window
|
||||
mov ebx, 8*65536+8 ; [x start] *65536 + [y start]
|
||||
mov ecx, 0x00ffffff ; color of text RRGGBB
|
||||
mov ecx, 0x0;0ffffff ; color of text RRGGBB
|
||||
mov edx, caption ; pointer to text beginning
|
||||
mov esi, capsize ; text length
|
||||
int 0x40
|
||||
@ -89,6 +89,10 @@ proc outtextxy stdcall, x:dword, y:dword, prompt:dword, prompt_len:dword, color:
|
||||
mov ecx, dword [color]
|
||||
mov edx, dword [prompt]
|
||||
mov esi, dword [prompt_len]
|
||||
test esi, esi
|
||||
jnz @f
|
||||
or ecx, 0x80000000
|
||||
@@:
|
||||
int 0x40
|
||||
popa
|
||||
ret
|
||||
@ -138,6 +142,16 @@ macro rectangle x,y,xsize,ysize,color
|
||||
line x2,y,x2,y2,color
|
||||
}
|
||||
|
||||
macro rectangle2 x,y,xsize,ysize,color1,color2
|
||||
{
|
||||
x2=x+xsize
|
||||
y2=y+ysize
|
||||
line x,y,x2,y,color1
|
||||
line x,y,x,y2,color1
|
||||
line x,y2,x2,y2,color2
|
||||
line x2,y,x2,y2,color2
|
||||
}
|
||||
|
||||
macro putpixel x,y,color
|
||||
{
|
||||
mov eax, 1
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -12,11 +12,10 @@
|
||||
â íèæíåå - ïåðåäàâàåìûå åé ïàðàìåòðû.
|
||||
|
||||
Íåîáõîäèìî ñäåëàòü:
|
||||
a. Çàãðóçêà è ñîõðàíåíèå êîíôèãóðàöèîííîãî ôàéëà.
|
||||
b. Óäàëåíèå ãîðÿ÷èõ êëàâèø.
|
||||
c. Èçìåíåíèå óæå óñòàíîâëåííûõ ãîðÿ÷èõ êëàâèø.
|
||||
a. Óäŕëĺíčĺ ăîđ˙÷čő ęëŕâčř.
|
||||
b. Čçěĺíĺíčĺ óćĺ óńňŕíîâëĺííűő ăîđ˙÷čő ęëŕâčř.
|
||||
|
||||
Íîìåð âåðñèè: 0.1
|
||||
Íîěĺđ âĺđńčč: 0.2
|
||||
|
||||
==Àâòîð==
|
||||
Asper
|
||||
@ -38,11 +37,10 @@ on the keyboard.
|
||||
in the lower text field - parametrs have to be passed to program.
|
||||
|
||||
ToDo:
|
||||
a. Load and save of configuration file will be implemented in the next version.
|
||||
b. Delete hotkeys.
|
||||
c. Change hotkeys that are already set.
|
||||
a. Delete hotkeys.
|
||||
b. Change hotkeys that are already set.
|
||||
|
||||
Version number: 0.1
|
||||
Version number: 0.2
|
||||
|
||||
==Author==
|
||||
Asper
|
||||
|
@ -139,10 +139,12 @@ debug_outhex:
|
||||
ret
|
||||
|
||||
SysMsgBoardChar:
|
||||
push eax ebx ecx
|
||||
mov cl, al
|
||||
mov eax, 63
|
||||
mov ebx, 1
|
||||
int 0x40
|
||||
pop ecx ebx eax
|
||||
ret
|
||||
|
||||
SysMsgBoardStr:
|
||||
|
157
programs/system/MyKey/trunk/dll.inc
Normal file
157
programs/system/MyKey/trunk/dll.inc
Normal file
@ -0,0 +1,157 @@
|
||||
;-----------------------------------------------------------------------------
|
||||
proc mem.Alloc size ;/////////////////////////////////////////////////////////
|
||||
;-----------------------------------------------------------------------------
|
||||
push ebx ecx
|
||||
mov eax,[size]
|
||||
lea ecx,[eax+4+4095]
|
||||
and ecx,not 4095
|
||||
mcall 68,12
|
||||
add ecx,-4
|
||||
mov [eax],ecx
|
||||
add eax,4
|
||||
pop ecx ebx
|
||||
ret
|
||||
endp
|
||||
|
||||
;-----------------------------------------------------------------------------
|
||||
proc mem.ReAlloc mptr,size;///////////////////////////////////////////////////
|
||||
;-----------------------------------------------------------------------------
|
||||
push ebx ecx esi edi eax
|
||||
mov eax,[mptr]
|
||||
mov ebx,[size]
|
||||
or eax,eax
|
||||
jz @f
|
||||
lea ecx,[ebx+4+4095]
|
||||
and ecx,not 4095
|
||||
add ecx,-4
|
||||
cmp ecx,[eax-4]
|
||||
je .exit
|
||||
@@: mov eax,ebx
|
||||
call mem.Alloc
|
||||
xchg eax,[esp]
|
||||
or eax,eax
|
||||
jz .exit
|
||||
mov esi,eax
|
||||
xchg eax,[esp]
|
||||
mov edi,eax
|
||||
mov ecx,[esi-4]
|
||||
cmp ecx,[edi-4]
|
||||
jbe @f
|
||||
mov ecx,[edi-4]
|
||||
@@: add ecx,3
|
||||
shr ecx,2
|
||||
cld
|
||||
rep movsd
|
||||
xchg eax,[esp]
|
||||
call mem.Free
|
||||
.exit:
|
||||
pop eax edi esi ecx ebx
|
||||
ret
|
||||
endp
|
||||
|
||||
;-----------------------------------------------------------------------------
|
||||
proc mem.Free mptr ;//////////////////////////////////////////////////////////
|
||||
;-----------------------------------------------------------------------------
|
||||
mov eax,[mptr]
|
||||
or eax,eax
|
||||
jz @f
|
||||
push ebx ecx
|
||||
lea ecx,[eax-4]
|
||||
mcall 68,13
|
||||
pop ecx ebx
|
||||
@@: ret
|
||||
endp
|
||||
|
||||
|
||||
proc dll.Load, import_table:dword
|
||||
mov esi,[import_table]
|
||||
.next_lib: mov edx,[esi]
|
||||
or edx,edx
|
||||
jz .exit
|
||||
push esi
|
||||
mov esi,[esi+4]
|
||||
mov edi,s_libdir.fname
|
||||
@@: lodsb
|
||||
stosb
|
||||
or al,al
|
||||
jnz @b
|
||||
mcall 68,19,s_libdir
|
||||
or eax,eax
|
||||
jz .fail
|
||||
stdcall dll.Link,eax,edx
|
||||
stdcall dll.Init,[eax+4]
|
||||
pop esi
|
||||
add esi,8
|
||||
jmp .next_lib
|
||||
.exit: xor eax,eax
|
||||
ret
|
||||
.fail: add esp,4
|
||||
xor eax,eax
|
||||
inc eax
|
||||
ret
|
||||
endp
|
||||
|
||||
proc dll.Link, exp:dword,imp:dword
|
||||
push eax
|
||||
mov esi,[imp]
|
||||
test esi,esi
|
||||
jz .done
|
||||
.next: lodsd
|
||||
test eax,eax
|
||||
jz .done
|
||||
stdcall dll.GetProcAddress,[exp],eax
|
||||
or eax,eax
|
||||
jz @f
|
||||
mov [esi-4],eax
|
||||
jmp .next
|
||||
@@: mov dword[esp],0
|
||||
.done: pop eax
|
||||
ret
|
||||
endp
|
||||
|
||||
proc dll.Init, dllentry:dword
|
||||
pushad
|
||||
mov eax,mem.Alloc
|
||||
mov ebx,mem.Free
|
||||
mov ecx,mem.ReAlloc
|
||||
mov edx,dll.Load
|
||||
stdcall [dllentry]
|
||||
popad
|
||||
ret
|
||||
endp
|
||||
|
||||
proc dll.GetProcAddress, exp:dword,sz_name:dword
|
||||
mov edx,[exp]
|
||||
xor eax,eax
|
||||
.next: or edx,edx
|
||||
jz .end
|
||||
cmp dword[edx],0
|
||||
jz .end
|
||||
stdcall strcmp,[edx],[sz_name]
|
||||
test eax,eax
|
||||
jz .ok
|
||||
add edx,8
|
||||
jmp .next
|
||||
.ok: mov eax,[edx+4]
|
||||
.end: ret
|
||||
endp
|
||||
|
||||
proc strcmp, str1:dword,str2:dword
|
||||
push esi edi
|
||||
mov esi,[str1]
|
||||
mov edi,[str2]
|
||||
xor eax,eax
|
||||
@@: lodsb
|
||||
scasb
|
||||
jne .fail
|
||||
or al,al
|
||||
jnz @b
|
||||
jmp .ok
|
||||
.fail: or eax,-1
|
||||
.ok: pop edi esi
|
||||
ret
|
||||
endp
|
||||
|
||||
s_libdir:
|
||||
db '/sys/lib/'
|
||||
.fname rb 32
|
46
programs/system/MyKey/trunk/mykey.ini
Normal file
46
programs/system/MyKey/trunk/mykey.ini
Normal file
@ -0,0 +1,46 @@
|
||||
[main]
|
||||
keynum=7
|
||||
|
||||
[hotkey0]
|
||||
name =FCE Ultra
|
||||
keycode =1074
|
||||
keycode_name =LCtrl + m
|
||||
path =/hd0/2/fce
|
||||
param =/hd0/2/gd/city.nes
|
||||
|
||||
[hotkey1]
|
||||
name =Kolibri Packer
|
||||
keycode=4143
|
||||
keycode_name=LAlt + v
|
||||
path =/sys/kpack
|
||||
param =mykey.bin mykey
|
||||
[hotkey2]
|
||||
name=kfar
|
||||
keycode=4137
|
||||
keycode_name=LAlt + `
|
||||
path=file managers/kfar
|
||||
param=
|
||||
[hotkey3]
|
||||
name=Minesweeper
|
||||
keycode=1058
|
||||
keycode_name=LCtrl + g
|
||||
path=games/mine
|
||||
param=
|
||||
[hotkey4]
|
||||
name=Games directory
|
||||
keycode=8226
|
||||
keycode_name=RAlt + g
|
||||
path=file managers/eolite
|
||||
param=/sys/games
|
||||
[hotkey5]
|
||||
name=KFM
|
||||
keycode=1589
|
||||
keycode_name=RShift + LCtrl + ?
|
||||
path=file managers/kfm
|
||||
param=
|
||||
[hotkey6]
|
||||
name=System Message Board
|
||||
keycode=4127
|
||||
keycode_name=LAlt + s
|
||||
path=develop/board
|
||||
param=
|
94
programs/system/MyKey/trunk/string.inc
Normal file
94
programs/system/MyKey/trunk/string.inc
Normal file
@ -0,0 +1,94 @@
|
||||
;****************************************
|
||||
;* input: esi = pointer to string *
|
||||
;* output: ecx = length of the string *
|
||||
;****************************************
|
||||
strlen:
|
||||
push eax esi
|
||||
xor ecx, ecx
|
||||
@@:
|
||||
lodsb
|
||||
or al, al
|
||||
jz @f
|
||||
inc ecx
|
||||
jmp @b
|
||||
@@:
|
||||
pop esi eax
|
||||
ret
|
||||
|
||||
;*************************************************
|
||||
;* input: esi = pointer to the src string *
|
||||
;* edi = pointer to the dest string *
|
||||
;* ecx = number of bytes to copy *
|
||||
;*************************************************
|
||||
strncpy:
|
||||
push eax ecx esi edi
|
||||
@@:
|
||||
lodsb
|
||||
stosb
|
||||
or al, al
|
||||
jz @f
|
||||
dec ecx
|
||||
jz @f
|
||||
jmp @b
|
||||
@@:
|
||||
pop edi esi ecx eax
|
||||
ret
|
||||
|
||||
;*************************************************
|
||||
;* input: esi = pointer to the src string *
|
||||
;* edi = pointer to the dest string *
|
||||
;*************************************************
|
||||
strcpy:
|
||||
push esi edi
|
||||
rep movsb
|
||||
pop edi esi
|
||||
ret
|
||||
|
||||
;*************************************************
|
||||
;* input: esi = pointer to the src string *
|
||||
;* edi = pointer to the dest string *
|
||||
;*************************************************
|
||||
strcat:
|
||||
push esi
|
||||
call strlen
|
||||
add esi, ecx
|
||||
call strcpy
|
||||
pop esi
|
||||
ret
|
||||
|
||||
;*************************************************
|
||||
;* input: esi = pointer to the src string *
|
||||
;* edi = pointer to the dest string *
|
||||
;* ecx = number of bytes to copy *
|
||||
;*************************************************
|
||||
strncat:
|
||||
push edi
|
||||
push ecx esi
|
||||
mov esi, edi
|
||||
call strlen
|
||||
add edi, ecx
|
||||
pop esi ecx
|
||||
call strncpy
|
||||
pop edi
|
||||
ret
|
||||
|
||||
;*************************************************
|
||||
;* input: edi = pointer to the dest string *
|
||||
;* al = byte to set the string to *
|
||||
;*************************************************
|
||||
;strset:
|
||||
; push edi
|
||||
; rep stosb
|
||||
; pop edi
|
||||
; ret
|
||||
|
||||
;*************************************************
|
||||
;* input: edi = pointer to the dest string *
|
||||
;* al = byte to set the string to *
|
||||
;* ecx = number of bytes to set *
|
||||
;*************************************************
|
||||
strnset:
|
||||
push edi ecx
|
||||
rep stosb
|
||||
pop ecx edi
|
||||
ret
|
@ -1,32 +0,0 @@
|
||||
pop esi
|
||||
push esi
|
||||
loader_patch4:
|
||||
mov ecx, 0 ; will be patched: number of calltrick entries
|
||||
ctrloop:
|
||||
lodsb
|
||||
@@:
|
||||
cmp al, 0xF
|
||||
jnz .f
|
||||
lodsb
|
||||
cmp al, 80h
|
||||
jb @b
|
||||
cmp al, 90h
|
||||
jb @f
|
||||
.f:
|
||||
sub al, 0E8h
|
||||
cmp al, 1
|
||||
ja ctrloop
|
||||
@@:
|
||||
cmp byte [esi], 0 ; will be patched: code in calltrick entries
|
||||
loader_patch5:
|
||||
jnz ctrloop
|
||||
lodsd
|
||||
; "bswap eax" is not supported on i386
|
||||
; mov al,0/bswap eax = 4 bytes, following instructions = 9 bytes
|
||||
shr ax, 8
|
||||
ror eax, 16
|
||||
xchg al, ah
|
||||
sub eax, esi
|
||||
add eax, [esp]
|
||||
mov [esi-4], eax
|
||||
loop ctrloop
|
@ -1,68 +0,0 @@
|
||||
filename equ 'kerpack.exe'
|
||||
|
||||
virtual at 0
|
||||
file filename:3Ch,4
|
||||
load pehea dword from 0
|
||||
file filename:pehea,0F8h+28h*3
|
||||
load NumberOfSections word from 4+6
|
||||
load SizeOfOptionalHeader word from 4+14h
|
||||
if NumberOfSections<>3
|
||||
error Expected three sections, .text, .bss and .reloc
|
||||
end if
|
||||
if SizeOfOptionalHeader<>0E0h
|
||||
error Nonstandard PE header
|
||||
end if
|
||||
load RelocsRVA dword from 4+0A0h
|
||||
load RelocsSize dword from 4+0A4h
|
||||
load ImageBase dword from 4+34h
|
||||
load TextRVA dword from 4+0F8h+0Ch
|
||||
load TextSize dword from 4+0F8h+8
|
||||
load TextOffs dword from 4+0F8h+14h
|
||||
load BSSSize dword from 4+0F8h+28h+10h
|
||||
load RelocRVA dword from 4+0F8h+28h*2+0Ch
|
||||
load RelocOffs dword from 4+0F8h+28h*2+14h
|
||||
if BSSSize
|
||||
error Second section expected to be .bss
|
||||
end if
|
||||
if RelocRVA<>RelocsRVA
|
||||
error Third section expected to be .reloc
|
||||
end if
|
||||
;file 'test.exe':pehea+0F8h,28h
|
||||
;load physofs dword from 4+14h
|
||||
;load mem dword from 4+8
|
||||
;file 'test.exe':physofs+16,4
|
||||
;load sz dword from $-4
|
||||
end virtual
|
||||
|
||||
file filename:TextOffs,TextSize
|
||||
|
||||
while RelocsSize>8
|
||||
virtual at 0
|
||||
file filename:RelocOffs,8
|
||||
load CurRelocPage dword from 0
|
||||
load CurRelocChunkSize dword from 4
|
||||
end virtual
|
||||
RelocsSize=RelocsSize-CurRelocChunkSize
|
||||
CurRelocChunkSize = CurRelocChunkSize-8
|
||||
RelocOffs=RelocOffs+8
|
||||
while CurRelocChunkSize
|
||||
virtual at 0
|
||||
file filename:RelocOffs,2
|
||||
RelocOffs=RelocOffs+2
|
||||
CurRelocChunkSize=CurRelocChunkSize-2
|
||||
load s word from 0
|
||||
end virtual
|
||||
CurRelocType = s shr 12
|
||||
RelocItem = CurRelocPage + (s and 0xFFF)
|
||||
if CurRelocType=0
|
||||
else if CurRelocType=3
|
||||
load z dword from RelocItem-TextRVA
|
||||
store dword z-(TextRVA+ImageBase) at RelocItem-TextRVA
|
||||
else
|
||||
error Unexpected relocation type
|
||||
end if
|
||||
end while
|
||||
end while
|
||||
|
||||
store dword TextSize at 10h
|
||||
store dword RelocRVA-TextRVA at 14h
|
@ -1,232 +0,0 @@
|
||||
; Kolibri kernel packer
|
||||
; (C) copyright diamond 2006, 2007
|
||||
;
|
||||
; This program is free software; you can redistribute it and/or modify
|
||||
; it under the terms of the GNU General Public License as published by
|
||||
; the Free Software Foundation; either version 2 of the License, or
|
||||
; (at your option) any later version.
|
||||
;
|
||||
; This program is distributed in the hope that it will be useful,
|
||||
; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
; GNU General Public License for more details.
|
||||
|
||||
; Uses LZMA compression library by Igor Pavlov
|
||||
; (for more information on LZMA and 7-Zip visit http://www.7-zip.org)
|
||||
; (plain-C packer is ported by diamond)
|
||||
|
||||
format MS COFF
|
||||
|
||||
extrn '_lzma_compress@16' as lzma_compress
|
||||
extrn '_lzma_set_dict_size@4' as lzma_set_dict_size
|
||||
|
||||
section '.text' code executable readable
|
||||
|
||||
die_with_err:
|
||||
pop esi
|
||||
@@:
|
||||
lodsb
|
||||
test al, al
|
||||
jz @f
|
||||
mov cl, al
|
||||
push 63
|
||||
pop eax
|
||||
push 1
|
||||
pop ebx
|
||||
int 40h
|
||||
jmp @b
|
||||
@@:
|
||||
mov al, 63
|
||||
mov cl, 13
|
||||
int 40h
|
||||
mov cl, 10
|
||||
int 40h
|
||||
or eax, -1
|
||||
int 40h
|
||||
|
||||
public _start
|
||||
_start:
|
||||
push 70
|
||||
pop eax
|
||||
mov ebx, fn70_read
|
||||
int 40h
|
||||
cmp eax, 6
|
||||
jz read_ok
|
||||
read_err:
|
||||
call die_with_err
|
||||
db 'KerPack: cannot load kernel.mnt',0
|
||||
read_ok:
|
||||
push 18
|
||||
call lzma_set_dict_size
|
||||
; find jump to 32-bit code
|
||||
mov edi, infile - 1
|
||||
@@:
|
||||
inc edi
|
||||
cmp dword [edi], 0E88EE08Eh ; mov fs,ax/mov gs,ax
|
||||
jnz @b
|
||||
cmp dword [edi+4], 00BCD08Eh ; mov ss,ax/mov esp,00xxxxxx
|
||||
jnz @b
|
||||
add edi, 11
|
||||
mov [inptr], edi
|
||||
sub edi, infile
|
||||
mov [indelta], edi
|
||||
lea eax, [ebx+0x10000]
|
||||
mov [..loader_patch3+2], eax
|
||||
sub ebx, edi
|
||||
mov [insize], ebx
|
||||
call preprocess_calltrick2
|
||||
mov al, [cti]
|
||||
mov [loader_patch5-1], al
|
||||
mov eax, [ctn]
|
||||
mov [loader_patch4+1], eax
|
||||
mov eax, [inptr]
|
||||
add eax, outfile - infile + loader_size - 5
|
||||
push workmem
|
||||
push [insize]
|
||||
push eax
|
||||
push [inptr]
|
||||
call lzma_compress
|
||||
add eax, loader_size-5
|
||||
mov [loader_patch1+6], eax
|
||||
add eax, [indelta]
|
||||
mov [outsize], eax
|
||||
mov eax, [indelta]
|
||||
mov ecx, dword [eax + outfile + loader_size - 4]
|
||||
bswap ecx
|
||||
mov [loader_patch2+4], ecx
|
||||
add eax, 0x10000
|
||||
mov [loader_patch1+1], eax
|
||||
mov esi, infile
|
||||
mov edi, outfile
|
||||
mov ecx, [indelta]
|
||||
rep movsb
|
||||
mov esi, loader_start
|
||||
mov ecx, loader_size
|
||||
rep movsb
|
||||
push 70
|
||||
pop eax
|
||||
mov ebx, fn70_write
|
||||
int 40h
|
||||
test eax, eax
|
||||
jz @f
|
||||
call die_with_err
|
||||
db 'KerPack: cannot save kernel.mnt',0
|
||||
@@:
|
||||
call die_with_err
|
||||
db 'KerPack: all is OK',0
|
||||
|
||||
preprocess_calltrick2:
|
||||
; input preprocessing
|
||||
mov edi, ct1
|
||||
xor eax, eax
|
||||
push edi
|
||||
mov ecx, 256/4
|
||||
rep stosd
|
||||
pop edi
|
||||
mov ecx, ebx
|
||||
mov esi, [inptr]
|
||||
mov ebx, inbuftmp
|
||||
xchg eax, edx
|
||||
input_pre2:
|
||||
lodsb
|
||||
@@:
|
||||
cmp al, 0Fh
|
||||
jnz ip1
|
||||
dec ecx
|
||||
jz input_pre_done2
|
||||
lodsb
|
||||
cmp al, 80h
|
||||
jb @b
|
||||
cmp al, 90h
|
||||
jb @f
|
||||
ip1:
|
||||
sub al, 0E8h
|
||||
cmp al, 1
|
||||
ja input_pre_cont2
|
||||
@@:
|
||||
cmp ecx, 5
|
||||
jb input_pre_done2
|
||||
lodsd
|
||||
add eax, esi
|
||||
sub eax, [inptr]
|
||||
cmp eax, [insize]
|
||||
jae xxx2
|
||||
cmp eax, 1000000h
|
||||
jae xxx2
|
||||
sub ecx, 4
|
||||
xchg al, ah
|
||||
rol eax, 16
|
||||
xchg al, ah
|
||||
mov [esi-4], eax
|
||||
inc edx
|
||||
mov [ebx], esi
|
||||
add ebx, 4
|
||||
jmp input_pre_cont2
|
||||
xxx2: sub esi, 4
|
||||
movzx eax, byte [esi]
|
||||
mov byte [eax+edi], 1
|
||||
input_pre_cont2:
|
||||
loop input_pre2
|
||||
input_pre_done2:
|
||||
mov [ctn], edx
|
||||
xor eax, eax
|
||||
mov ecx, 256
|
||||
repnz scasb
|
||||
jnz pack_calltrick_done
|
||||
not cl
|
||||
mov [cti], cl
|
||||
@@:
|
||||
cmp ebx, inbuftmp
|
||||
jz pack_calltrick_done
|
||||
sub ebx, 4
|
||||
mov eax, [ebx]
|
||||
mov [eax-4], cl
|
||||
jmp @b
|
||||
pack_calltrick_done:
|
||||
ret
|
||||
|
||||
include 'loader_lzma.asm'
|
||||
|
||||
section '.data' data readable writeable
|
||||
db 'MENUET01'
|
||||
dd 1
|
||||
dd _start
|
||||
dd bss_start ; i_end
|
||||
dd bss_end ; memory
|
||||
dd mtstack_end ; esp
|
||||
dd 0 ; params
|
||||
dd 0 ; icon
|
||||
fn70_read:
|
||||
dd 0
|
||||
dd 0
|
||||
dd 0
|
||||
dd 200*1024
|
||||
dd infile
|
||||
filename db '/rd/1/kernel.mnt',0
|
||||
fn70_write:
|
||||
dd 2
|
||||
dd 0
|
||||
dd 0
|
||||
outsize dd ?
|
||||
dd outfile
|
||||
db 0
|
||||
dd filename
|
||||
section '.bss' readable writeable
|
||||
bss_start:
|
||||
align 4
|
||||
inptr dd ?
|
||||
indelta dd ?
|
||||
insize dd ?
|
||||
ct1 rb 256
|
||||
ctn dd ?
|
||||
cti db ?
|
||||
|
||||
align 4
|
||||
mtstack rb 1000h
|
||||
mtstack_end:
|
||||
|
||||
infile rb 200*1024
|
||||
inbuftmp rb 200*1024
|
||||
outfile rb 200*1024
|
||||
workmem rb 6A8000h
|
||||
bss_end:
|
@ -1,7 +0,0 @@
|
||||
del kerpack
|
||||
del kerpack.obj
|
||||
del kerpack.exe
|
||||
fasm memset.asm
|
||||
fasm kerpack.asm
|
||||
"C:\Program Files\Microsoft Visual Studio 9.0\VC\bin\link.exe" /section:.bss,E /fixed:no /subsystem:native /merge:.data=.text /merge:.rdata=.text /nologo /entry:start /out:kerpack.exe /ltcg kerpack.obj /nodefaultlib lzmapack.lib memset.obj
|
||||
fasm doexe2.asm kerpack
|
@ -1,404 +0,0 @@
|
||||
loader_start:
|
||||
; start address; this code will be injected after the init code
|
||||
; (some commands below "B32" in the kernel)
|
||||
mov edi, 0x280000
|
||||
lea ebx, [edi+loader_size1+16]
|
||||
lea edx, [ebx+4]
|
||||
loader_patch1:
|
||||
mov esi, 0 ; will be patched: start address to copy
|
||||
mov ecx, 0 ; will be patched: size of data to copy
|
||||
push esi
|
||||
rep movsb
|
||||
jmp edx
|
||||
loader_size1 = $ - loader_start
|
||||
|
||||
loader_patch2:
|
||||
dd 0x280000 + loader_size
|
||||
dd 0 ; will be patched: start value for code
|
||||
; (LZMA-specific)
|
||||
dd -1
|
||||
dd _RangeDecoderBitDecode_edx - loader_start + 0x280000
|
||||
dd _RangeDecoderBitDecode - loader_start + 0x280000
|
||||
RangeDecoderBitDecode equ dword [ebx]
|
||||
RangeDecoderBitDecode_edx equ dword [ebx-4]
|
||||
code_ equ ebx-12
|
||||
range equ ebx-8
|
||||
|
||||
rep1 equ ebx-28
|
||||
rep2 equ ebx-24
|
||||
rep3 equ ebx-20
|
||||
inptr_ldr equ ebx-16
|
||||
|
||||
pb equ 0 ; pos state bits
|
||||
lp equ 0 ; literal pos state bits
|
||||
lc equ 3 ; literal context bits
|
||||
posStateMask equ ((1 shl pb)-1)
|
||||
literalPosMask equ ((1 shl lp)-1)
|
||||
|
||||
kNumPosBitsMax = 4
|
||||
kNumPosStatesMax = (1 shl kNumPosBitsMax)
|
||||
|
||||
kLenNumLowBits = 3
|
||||
kLenNumLowSymbols = (1 shl kLenNumLowBits)
|
||||
kLenNumMidBits = 3
|
||||
kLenNumMidSymbols = (1 shl kLenNumMidBits)
|
||||
kLenNumHighBits = 8
|
||||
kLenNumHighSymbols = (1 shl kLenNumHighBits)
|
||||
|
||||
LenChoice = 0
|
||||
LenChoice2 = 1
|
||||
LenLow = 2
|
||||
LenMid = (LenLow + (kNumPosStatesMax shl kLenNumLowBits))
|
||||
LenHigh = (LenMid + (kNumPosStatesMax shl kLenNumMidBits))
|
||||
kNumLenProbs = (LenHigh + kLenNumHighSymbols)
|
||||
|
||||
kNumStates = 12
|
||||
kNumLitStates = 7
|
||||
kStartPosModelIndex = 4
|
||||
kEndPosModelIndex = 14
|
||||
kNumFullDistances = (1 shl (kEndPosModelIndex/2))
|
||||
kNumPosSlotBits = 6
|
||||
kNumLenToPosStates = 4
|
||||
kNumAlignBits = 4
|
||||
kAlignTableSize = (1 shl kNumAlignBits)
|
||||
kMatchMinLen = 2
|
||||
|
||||
IsMatch = 0
|
||||
IsRep = 0xC0 ; (IsMatch + (kNumStates shl kNumPosBitsMax))
|
||||
IsRepG0 = 0xCC ; (IsRep + kNumStates)
|
||||
IsRepG1 = 0xD8 ; (IsRepG0 + kNumStates)
|
||||
IsRepG2 = 0xE4 ; (IsRepG1 + kNumStates)
|
||||
IsRep0Long = 0xF0 ; (IsRepG2 + kNumStates)
|
||||
PosSlot = 0x1B0 ; (IsRep0Long + (kNumStates shl kNumPosBitsMax))
|
||||
SpecPos = 0x2B0 ; (PosSlot + (kNumLenToPosStates shl kNumPosSlotBits))
|
||||
Align_ = 0x322 ; (SpecPos + kNumFullDistances - kEndPosModelIndex)
|
||||
Lencoder = 0x332 ; (Align_ + kAlignTableSize)
|
||||
RepLencoder = 0x534 ; (Lencoder + kNumLenProbs)
|
||||
Literal = 0x736 ; (RepLencoder + kNumLenProbs)
|
||||
|
||||
LZMA_BASE_SIZE = 1846 ; must be ==Literal
|
||||
LZMA_LIT_SIZE = 768
|
||||
|
||||
kNumTopBits = 24
|
||||
kTopValue = (1 shl kNumTopBits)
|
||||
|
||||
kNumBitModelTotalBits = 11
|
||||
kBitModelTotal = (1 shl kNumBitModelTotalBits)
|
||||
kNumMoveBits = 5
|
||||
|
||||
uninit_base = 2C0000h
|
||||
|
||||
p = uninit_base
|
||||
|
||||
unpacker:
|
||||
xor ebp, ebp
|
||||
xor eax, eax
|
||||
dec eax
|
||||
lea edi, [rep1]
|
||||
stosd
|
||||
stosd
|
||||
stosd
|
||||
xchg eax, esi
|
||||
; mov ecx, Literal + (LZMA_LIT_SIZE shl (lc+lp))
|
||||
mov ch, (Literal + (LZMA_LIT_SIZE shl (lc+lp)) + 0xFF) shr 8
|
||||
mov eax, kBitModelTotal/2
|
||||
mov edi, p
|
||||
rep stosd
|
||||
pop edi
|
||||
push edi
|
||||
.main_loop:
|
||||
..loader_patch3:
|
||||
cmp edi, dword 0 ; will be patched: end of data to unpack
|
||||
jae .main_loop_done
|
||||
if posStateMask
|
||||
mov edx, edi
|
||||
and edx, posStateMask
|
||||
else
|
||||
xor edx, edx
|
||||
end if
|
||||
push eax ; al = previous byte
|
||||
lea eax, [ebp + ((p+IsMatch*4) shr (kNumPosBitsMax+2))]
|
||||
shl eax, kNumPosBitsMax+2
|
||||
if posStateMask
|
||||
call RangeDecoderBitDecode_edx
|
||||
else
|
||||
call RangeDecoderBitDecode
|
||||
end if
|
||||
pop eax
|
||||
jc .1
|
||||
movzx eax, al
|
||||
if literalPosMask
|
||||
mov ah, dl
|
||||
and ah, literalPosMask
|
||||
end if
|
||||
if ((LZMA_LIT_SIZE*4) and ((1 shl (8-lc)) - 1)) <> 0
|
||||
shr eax, 8-lc
|
||||
imul eax, LZMA_LIT_SIZE*4
|
||||
else
|
||||
and al, not ((1 shl (8-lc)) - 1)
|
||||
imul eax, (LZMA_LIT_SIZE*4) shr (8-lc)
|
||||
end if
|
||||
add eax, p+Literal*4
|
||||
mov dl, 1
|
||||
cmp ebp, kNumLitStates
|
||||
jb .literal
|
||||
mov cl, [edi + esi]
|
||||
.lx0:
|
||||
add cl, cl
|
||||
adc dh, 1
|
||||
call RangeDecoderBitDecode_edx
|
||||
adc dl, dl
|
||||
jc .lx1
|
||||
xor dh, dl
|
||||
test dh, 1
|
||||
mov dh, 0
|
||||
jnz .lx0
|
||||
.literal:
|
||||
@@:
|
||||
call RangeDecoderBitDecode_edx
|
||||
adc dl, dl
|
||||
jnc @b
|
||||
.lx1:
|
||||
mov eax, ebp
|
||||
cmp al, 4
|
||||
jb @f
|
||||
cmp al, 10
|
||||
mov al, 3
|
||||
jb @f
|
||||
mov al, 6
|
||||
@@: sub ebp, eax
|
||||
xchg eax, edx
|
||||
.stosb_main_loop:
|
||||
stosb
|
||||
jmp .main_loop
|
||||
.1:
|
||||
lea eax, [p + IsRep*4 + ebp*4]
|
||||
call RangeDecoderBitDecode
|
||||
jnc .10
|
||||
add eax, (IsRepG0 - IsRep)*4 ;lea eax, [p + IsRepG0*4 + ebp*4]
|
||||
call RangeDecoderBitDecode
|
||||
jc .111
|
||||
mov eax, ebp
|
||||
shl eax, kNumPosBitsMax+2
|
||||
add eax, p + IsRep0Long*4
|
||||
call RangeDecoderBitDecode_edx
|
||||
jc .1101
|
||||
cmp ebp, 7
|
||||
sbb ebp, ebp
|
||||
lea ebp, [ebp+ebp+11]
|
||||
mov al, [edi + esi]
|
||||
jmp .stosb_main_loop
|
||||
.111:
|
||||
add eax, (IsRepG1 - IsRepG0) * 4 ;lea eax, [p + IsRepG1*4 + ebp*4]
|
||||
call RangeDecoderBitDecode
|
||||
xchg esi, [rep1]
|
||||
jnc @f
|
||||
add eax, (IsRepG2 - IsRepG1) * 4 ;lea eax, [p + IsRepG2*4 + ebp*4]
|
||||
call RangeDecoderBitDecode
|
||||
xchg esi, [rep2]
|
||||
jnc @f
|
||||
xchg esi, [rep3]
|
||||
@@:
|
||||
.1101:
|
||||
mov eax, p + RepLencoder*4
|
||||
call LzmaLenDecode
|
||||
push 8
|
||||
jmp .rmu
|
||||
.10:
|
||||
xchg esi, [rep1]
|
||||
xchg esi, [rep2]
|
||||
mov [rep3], esi
|
||||
mov eax, p + Lencoder*4
|
||||
call LzmaLenDecode
|
||||
push kNumLenToPosStates-1
|
||||
pop edx
|
||||
cmp edx, ecx
|
||||
jb @f
|
||||
mov edx, ecx
|
||||
@@:
|
||||
push ecx
|
||||
push kNumPosSlotBits
|
||||
pop ecx
|
||||
mov eax, p+PosSlot*4
|
||||
shl edx, cl
|
||||
call RangeDecoderBitTreeDecode
|
||||
mov esi, ecx
|
||||
cmp ecx, kStartPosModelIndex
|
||||
jb .l6
|
||||
mov edx, ecx
|
||||
xor eax, eax
|
||||
shr ecx, 1
|
||||
adc al, 2
|
||||
dec ecx
|
||||
shl eax, cl
|
||||
mov esi, eax
|
||||
sub eax, edx
|
||||
lea eax, [p + (SpecPos - 1)*4 + eax*4]
|
||||
cmp edx, kEndPosModelIndex
|
||||
jb .l59
|
||||
; call RangeDecoderDecodeDirectBits
|
||||
;RangeDecoderDecodeDirectBits:
|
||||
xor eax, eax
|
||||
.l:
|
||||
shr dword [range], 1
|
||||
add eax, eax
|
||||
mov edx, [code_]
|
||||
sub edx, [range]
|
||||
jb @f
|
||||
mov [code_], edx
|
||||
add al, 1 shl kNumAlignBits
|
||||
@@:
|
||||
call update_decoder
|
||||
dec ecx
|
||||
cmp ecx, kNumAlignBits
|
||||
jnz .l
|
||||
; ret
|
||||
add esi, eax
|
||||
mov eax, p+Align_*4
|
||||
.l59:
|
||||
; call RangeDecoderReverseBitTreeDecode_addesi
|
||||
;_RangeDecoderReverseBitTreeDecode_addesi:
|
||||
; in: eax->probs,ecx=numLevels
|
||||
; out: esi+=length; destroys edx
|
||||
push edi
|
||||
xor edx, edx
|
||||
inc edx
|
||||
mov edi, edx
|
||||
@@:
|
||||
call RangeDecoderBitDecode_edx
|
||||
jnc .591
|
||||
add esi, edi
|
||||
stc
|
||||
.591:
|
||||
adc edx, edx
|
||||
add edi, edi
|
||||
loop @b
|
||||
pop edi
|
||||
; ret
|
||||
.l6:
|
||||
pop ecx
|
||||
not esi
|
||||
push 7
|
||||
.rmu:
|
||||
cmp ebp, 7
|
||||
pop ebp
|
||||
jb @f
|
||||
add ebp, 3
|
||||
@@:
|
||||
.repmovsb:
|
||||
inc ecx
|
||||
push esi
|
||||
add esi, edi
|
||||
rep movsb
|
||||
lodsb
|
||||
pop esi
|
||||
jmp .stosb_main_loop
|
||||
.main_loop_done:
|
||||
include 'calltrick2.asm'
|
||||
ret
|
||||
|
||||
_RangeDecoderBitDecode:
|
||||
; in: eax->prob
|
||||
; out: CF=bit
|
||||
push edx
|
||||
mov edx, [range]
|
||||
shr edx, kNumBitModelTotalBits
|
||||
imul edx, [eax]
|
||||
cmp [code_], edx
|
||||
jae .ae
|
||||
mov [range], edx
|
||||
mov edx, kBitModelTotal
|
||||
sub edx, [eax]
|
||||
shr edx, kNumMoveBits
|
||||
add [eax], edx
|
||||
.n:
|
||||
pushfd
|
||||
call update_decoder
|
||||
popfd
|
||||
pop edx
|
||||
ret
|
||||
.ae:
|
||||
sub [range], edx
|
||||
sub [code_], edx
|
||||
mov edx, [eax]
|
||||
shr edx, kNumMoveBits
|
||||
sub [eax], edx
|
||||
stc
|
||||
jmp .n
|
||||
|
||||
update_decoder:
|
||||
cmp byte [range+3], 0 ;cmp dword [range], kTopValue
|
||||
jnz @f ;jae @f
|
||||
shl dword [range], 8
|
||||
shl dword [code_], 8
|
||||
push eax
|
||||
mov eax, [inptr_ldr]
|
||||
mov al, [eax]
|
||||
inc dword [inptr_ldr]
|
||||
mov byte [code_], al
|
||||
pop eax
|
||||
@@: ret
|
||||
|
||||
_RangeDecoderBitDecode_edx:
|
||||
push eax
|
||||
lea eax, [eax+edx*4]
|
||||
call RangeDecoderBitDecode
|
||||
pop eax
|
||||
ret
|
||||
|
||||
LzmaLenDecode:
|
||||
; in: eax->prob, edx=posState
|
||||
; out: ecx=len
|
||||
|
||||
; LenChoice==0
|
||||
; add eax, LenChoice*4
|
||||
if kLenNumMidBits <> kLenNumLowBits
|
||||
error in optimization
|
||||
end if
|
||||
mov cl, kLenNumMidBits
|
||||
call RangeDecoderBitDecode
|
||||
jnc .0
|
||||
add eax, (LenChoice2-LenChoice)*4
|
||||
call RangeDecoderBitDecode
|
||||
jc @f
|
||||
if (kLenNumMidBits <> 3) | (LenMid-LenChoice2 > 0x7F + kLenNumMidBits)
|
||||
shl edx, cl
|
||||
add edx, LenMid-LenChoice2
|
||||
else
|
||||
lea edx, [ecx + edx*8 - kLenNumMidBits + LenMid-LenChoice2]
|
||||
end if
|
||||
push kLenNumLowSymbols
|
||||
jmp RangeDecoderBitTreeDecode.1
|
||||
@@:
|
||||
mov edx, LenHigh-LenChoice2
|
||||
mov cl, kLenNumHighBits
|
||||
push kLenNumLowSymbols + kLenNumMidSymbols
|
||||
jmp RangeDecoderBitTreeDecode.1
|
||||
.0:
|
||||
shl edx, cl
|
||||
if LenLow = 2
|
||||
inc edx
|
||||
inc edx
|
||||
else
|
||||
add edx, LenLow
|
||||
end if
|
||||
RangeDecoderBitTreeDecode:
|
||||
; in: eax+edx*4->probs,ecx=numLevels
|
||||
; out: ecx=length; destroys edx
|
||||
push 0
|
||||
.1:
|
||||
lea eax, [eax+edx*4]
|
||||
xor edx, edx
|
||||
inc edx
|
||||
push ecx
|
||||
@@:
|
||||
call RangeDecoderBitDecode_edx
|
||||
adc edx, edx
|
||||
loop @b
|
||||
pop ecx
|
||||
btc edx, ecx
|
||||
pop ecx
|
||||
add ecx, edx
|
||||
ret
|
||||
|
||||
loader_size = $ - loader_start
|
Binary file not shown.
@ -1,11 +0,0 @@
|
||||
format MS COFF
|
||||
section '.text' code readable executable
|
||||
public _memset
|
||||
_memset:
|
||||
push edi
|
||||
mov edi, [esp+8]
|
||||
mov al, [esp+12]
|
||||
mov ecx, [esp+16]
|
||||
rep stosb
|
||||
pop edi
|
||||
ret
|
Loading…
Reference in New Issue
Block a user