UTF-8 file path input, unicode names for apps and libs

git-svn-id: svn://kolibrios.org@6502 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
pathoswithin 2016-08-25 19:30:08 +00:00
parent 5f44c836b1
commit 31fad3ee4a
9 changed files with 331 additions and 390 deletions

View File

@ -1,7 +1,7 @@
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; ;; ;; ;;
;; Copyright (C) KolibriOS team 2004-2015. All rights reserved. ;; ;; Copyright (C) KolibriOS team 2004-2016. All rights reserved. ;;
;; Distributed under terms of the GNU General Public License ;; ;; Distributed under terms of the GNU General Public License. ;;
;; ;; ;; ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
@ -900,27 +900,25 @@ coff_get_align:
align 4 align 4
proc load_library stdcall, file_name:dword proc load_library stdcall, file_name:dword
locals locals
fullname rb 260 fullname dd ?
fileinfo rb 40 fileinfo rb 40
coff dd ? coff dd ?
img_base dd ? img_base dd ?
endl endl
; resolve file name ; resolve file name
stdcall kernel_alloc, maxPathLength
mov [fullname], eax
mov ebx, [file_name] mov ebx, [file_name]
lea edi, [fullname+1] stdcall get_full_file_name, eax, maxPathLength
mov byte [edi-1], '/' test eax, eax
stdcall get_full_file_name, edi, 259
test al, al
jz .fail jz .fail
; scan for required DLL in list of already loaded for this process, ; scan for required DLL in list of already loaded for this process,
; ignore timestamp ; ignore timestamp
cli cli
mov esi, [current_process] mov esi, [current_process]
lea edi, [fullname] mov edi, [fullname]
mov ebx, [esi+PROC.dlls_list_ptr] mov ebx, [esi+PROC.dlls_list_ptr]
test ebx, ebx test ebx, ebx
jz .not_in_process jz .not_in_process
@ -942,12 +940,16 @@ proc load_library stdcall, file_name:dword
sub eax, [ecx+DLLDESCR.defaultbase] sub eax, [ecx+DLLDESCR.defaultbase]
add eax, [esi+HDLL.base] add eax, [esi+HDLL.base]
sti sti
push eax
stdcall kernel_free, [fullname]
pop eax
ret ret
.next_in_process: .next_in_process:
mov esi, [esi+HDLL.fd] mov esi, [esi+HDLL.fd]
jmp .scan_in_process jmp .scan_in_process
.not_in_process:
.not_in_process:
; scan in full list, compare timestamp ; scan in full list, compare timestamp
sti sti
lea eax, [fileinfo] lea eax, [fileinfo]
@ -1182,11 +1184,11 @@ proc load_library stdcall, file_name:dword
mov [esi+DLLDESCR.bk], eax mov [esi+DLLDESCR.bk], eax
mov [eax+DLLDESCR.fd], esi mov [eax+DLLDESCR.fd], esi
.dll_already_loaded: .dll_already_loaded:
stdcall kernel_free, [fullname]
inc [esi+DLLDESCR.refcount] inc [esi+DLLDESCR.refcount]
push esi push esi
call init_heap call init_heap
pop esi pop esi
mov edi, [esi+DLLDESCR.size] mov edi, [esi+DLLDESCR.size]
stdcall user_alloc_at, [esi+DLLDESCR.defaultbase], edi stdcall user_alloc_at, [esi+DLLDESCR.defaultbase], edi
test eax, eax test eax, eax
@ -1255,6 +1257,7 @@ proc load_library stdcall, file_name:dword
add eax, [img_base] add eax, [img_base]
sti sti
ret ret
.fail_and_free_data: .fail_and_free_data:
stdcall kernel_free, [esi+DLLDESCR.data] stdcall kernel_free, [esi+DLLDESCR.data]
.fail_and_free_dll: .fail_and_free_dll:
@ -1263,8 +1266,10 @@ proc load_library stdcall, file_name:dword
.fail_and_free_coff: .fail_and_free_coff:
stdcall kernel_free, [coff] stdcall kernel_free, [coff]
.fail: .fail:
stdcall kernel_free, [fullname]
xor eax, eax xor eax, eax
ret ret
.fail_and_free_user: .fail_and_free_user:
stdcall user_free, [img_base] stdcall user_free, [img_base]
.fail_and_dereference: .fail_and_dereference:

View File

@ -5,17 +5,22 @@
;; ;; ;; ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;============================================================================ ; External kernel dependencies (libraries) loading.
; ; The code currently does not work, requires correcting dll.inc.
; External kernel dependencies (libraries) loading
;
;============================================================================
$Revision$ $Revision$
if 0 if 0
; The code currently does not work. Kill "if 0/end if" only after correcting iglobal
; to current kernel (dll.inc). tmp_file_name_size dd 1
endg
uglobal
tmp_file_name_table dd ?
s_libname rb 64
def_val_1 db ?
endg
macro library [name,fname] macro library [name,fname]
{ {
forward forward
@ -327,7 +332,145 @@ proc mem.Free mptr ;//////////////////////////////////////////////////////////
ret ret
endp endp
uglobal proc load_file_parse_table
s_libname db 64 dup (0) stdcall kernel_alloc, 0x1000
endg mov [tmp_file_name_table], eax
mov edi, eax
mov esi, sysdir_name
mov ecx, 128/4
rep movsd
invoke ini.enum_keys, conf_fname, conf_path_sect, get_every_key
mov eax, [tmp_file_name_table]
mov [full_file_name_table], eax
mov eax, [tmp_file_name_size]
mov [full_file_name_table.size], eax
ret
endp
proc get_every_key stdcall, f_name, sec_name, key_name
mov esi, [key_name]
mov ecx, esi
cmp byte [esi], '/'
jnz @f
inc esi
@@:
mov edi, [tmp_file_name_size]
shl edi, 7
cmp edi, 0x1000
jae .stop_parse
add edi, [tmp_file_name_table]
lea ebx, [edi+64]
@@:
cmp edi, ebx
jae .skip_this_key
lodsb
test al, al
jz @f
or al, 20h
stosb
jmp @b
.stop_parse:
xor eax, eax
ret
@@:
stosb
invoke ini.get_str, [f_name], [sec_name], ecx, ebx, 64, def_val_1
cmp byte [ebx], '/'
jnz @f
lea esi, [ebx+1]
mov edi, ebx
mov ecx, 63
rep movsb
@@:
push ebp
mov ebp, [tmp_file_name_table]
mov ecx, [tmp_file_name_size]
jecxz .noreplace
mov eax, ecx
dec eax
shl eax, 7
add ebp, eax
.replace_loop:
mov edi, ebx
mov esi, ebp
@@:
lodsb
test al, al
jz .doreplace
mov dl, [edi]
inc edi
test dl, dl
jz .replace_loop_cont
or dl, 20h
cmp al, dl
jz @b
jmp .replace_loop_cont
.doreplace:
cmp byte [edi], 0
jz @f
cmp byte [edi], '/'
jnz .replace_loop_cont
@@:
lea esi, [ebp+64]
call .replace
jc .skip_this_key2
.replace_loop_cont:
sub ebp, 128
loop .replace_loop
.noreplace:
pop ebp
inc [tmp_file_name_size]
.skip_this_key:
xor eax, eax
inc eax
ret
.skip_this_key2:
pop ebp
jmp .skip_this_key
endp
proc get_every_key.replace
; in: ebx->destination, esi->first part of name, edi->second part of name
; maximum length is 64 bytes
; out: CF=1 <=> overflow
sub esp, 64 ; allocate temporary buffer in stack
push esi
lea esi, [esp+4] ; esi->tmp buffer
xchg esi, edi ; edi->tmp buffer, esi->source
@@: ; save second part of name to temporary buffer
lodsb
stosb
test al, al
jnz @b
pop esi
mov edi, ebx
@@: ; copy first part of name to destination
lodsb
test al, al
jz @f
stosb
jmp @b
@@: ; restore second part of name from temporary buffer to destination
lea edx, [ebx+64] ; limit of destination
mov esi, esp
@@:
cmp edi, edx
jae .overflow
lodsb
stosb
test al, al
jnz @b
add esp, 64 ; CF is cleared
ret
.overflow: ; name is too long
add esp, 64
stc
ret
endp
end if end if

View File

@ -1,7 +1,7 @@
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; ;; ;; ;;
;; Copyright (C) KolibriOS team 2004-2015. All rights reserved. ;; ;; Copyright (C) KolibriOS team 2004-2016. All rights reserved. ;;
;; Distributed under terms of the GNU General Public License ;; ;; Distributed under terms of the GNU General Public License. ;;
;; ;; ;; ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
@ -41,6 +41,7 @@ struct APP_HDR
img_size rd 1 img_size rd 1
filename_size rd 1 filename_size rd 1
cmdline_size rd 1 cmdline_size rd 1
path_string rd 1
ends ends
macro _clear_ op macro _clear_ op
@ -66,50 +67,45 @@ fs_execute_from_sysdir:
xor ebx, ebx xor ebx, ebx
fs_execute_from_sysdir_param: fs_execute_from_sysdir_param:
xor edx, edx xor edx, edx
align 4
proc fs_execute proc fs_execute
; ebx - cmdline ; ebx - cmdline
; edx - flags ; edx - flags
; ebp - full filename ; ebp - full filename
locals
cmdline rd 1
flags rd 1
slot rd 1
slot_base rd 1
; app header data
hdr_cmdline rd 1
hdr_path rd 1
hdr_eip rd 1
hdr_esp rd 1
hdr_edata rd 1
hdr_emem rd 1
file_base rd 1
file_size rd 1
filename_size rd 1
cmdline_size rd 1
path_string rd 1
endl
locals
filename rd 1
cmdline rd 1
flags rd 1
slot rd 1
slot_base rd 1
;app header data
hdr_cmdline rd 1 ;0x00
hdr_path rd 1 ;0x04
hdr_eip rd 1 ;0x08
hdr_esp rd 1 ;0x0C
hdr_edata rd 1 ;0x10
hdr_emem rd 1 ;0x14
file_base rd 1 ;0x18
file_size rd 1 ;0x1c
filename_size rd 1 ;0x20
cmdline_size rd 1 ;0x24
endl
mov eax, [ebp]
mov [flags], edx mov [flags], edx
mov [cmdline], ebx mov [cmdline], ebx
mov [filename], eax stdcall kernel_alloc, maxPathLength
mov [path_string], eax
mov ebx, [ebp]
stdcall get_full_file_name, eax, maxPathLength
test eax, eax
jz .err_file
mov eax, [filename] stdcall load_file, [path_string]
stdcall load_file, eax
mov esi, -ERROR_FILE_NOT_FOUND mov esi, -ERROR_FILE_NOT_FOUND
test eax, eax test eax, eax
jz .err_file jz .err_file
mov [file_base], eax mov [file_base], eax
mov [file_size], ebx mov [file_size], ebx
lea ebx, [hdr_cmdline] lea ebx, [hdr_cmdline]
call test_app_header call test_app_header
mov esi, -0x1F mov esi, -0x1F
@ -117,9 +113,8 @@ proc fs_execute
jz .err_hdr jz .err_hdr
call lock_application_table call lock_application_table
call alloc_thread_slot call alloc_thread_slot
mov esi, -0x20 ; too many processes mov esi, -0x20 ; too many processes
test eax, eax test eax, eax
jz .err_0 jz .err_0
@ -127,103 +122,80 @@ proc fs_execute
shl eax, 8 shl eax, 8
lea edi, [SLOT_BASE+eax] lea edi, [SLOT_BASE+eax]
mov [slot_base], edi mov [slot_base], edi
; clean extended information about process
;clean extended information about process
mov ecx, 256/4 mov ecx, 256/4
xor eax, eax xor eax, eax
cld cld
rep stosd rep stosd
; write application name ; write application name
stdcall strrchr, [filename], '/' ; now eax points to name without path stdcall strrchr, [path_string], '/'
lea esi, [eax+1] ; -> name without path
lea esi, [eax+1] mov ecx, 11
test eax, eax
jnz @F
mov esi, [filename]
@@:
mov ecx, 11 ; 11 chars for name! 8 - is old value!
mov edi, [slot_base] mov edi, [slot_base]
.copy_process_name_loop: @@:
lodsb call utf8to16
call uni2ansi_char
cmp al, '.' cmp al, '.'
jz .copy_process_name_done jz @f
test al, al test al, al
jz .copy_process_name_done jz @f
stosb stosb
loop .copy_process_name_loop loop @b
.copy_process_name_done:
@@:
mov edi, [cmdline] mov edi, [cmdline]
xor eax, eax xor eax, eax
test edi, edi test edi, edi
jz @F jz @f
mov ecx, 65535 mov ecx, 65535
call _strnlen call _strnlen
cmp eax, 256 cmp eax, 256
jb @F jb @f
lea ebx, [eax+1] lea ebx, [eax+1]
add [hdr_emem], ebx add [hdr_emem], ebx
@@: @@:
mov [cmdline_size], eax mov [cmdline_size], eax
stdcall create_process, [hdr_emem] stdcall create_process, [hdr_emem]
mov esi, -30 ; no memory
mov esi, -30; no memory
test eax, eax test eax, eax
jz .err_hdr jz .err_hdr
mov ebx, [sys_proc+LHEAD.prev] mov ebx, [sys_proc+LHEAD.prev]
__list_add eax, ebx, sys_proc __list_add eax, ebx, sys_proc
mov ebx, [hdr_emem] mov ebx, [hdr_emem]
mov [eax+PROC.mem_used], ebx mov [eax+PROC.mem_used], ebx
mov ebx, [slot_base] mov ebx, [slot_base]
mov [ebx+APPDATA.process], eax mov [ebx+APPDATA.process], eax
lea edx, [ebx+APPDATA.list] lea edx, [ebx+APPDATA.list]
lea ecx, [eax+PROC.thr_list] lea ecx, [eax+PROC.thr_list]
list_add_tail edx, ecx list_add_tail edx, ecx
mov edi, [path_string]
mov esi, sizeof.APP_HDR mov ecx, maxPathLength
add esi, [cmdline_size]
mov edi, [filename]
mov ecx, 1023
call _strnlen call _strnlen
add esi, eax
mov [filename_size], eax mov [filename_size], eax
mov eax, [cmdline_size]
stdcall kernel_alloc, esi add eax, sizeof.APP_HDR
stdcall kernel_alloc, eax
mov [ebx+APPDATA.exec_params], eax mov [ebx+APPDATA.exec_params], eax
mov edi, eax mov edi, eax
lea esi, [hdr_cmdline] lea esi, [hdr_cmdline]
mov ecx, sizeof.APP_HDR/4 mov ecx, sizeof.APP_HDR/4
rep movsd rep movsd
mov esi, [filename]
mov ecx, [filename_size]
rep movsb
mov ecx, [cmdline_size] mov ecx, [cmdline_size]
mov esi, [cmdline] mov esi, [cmdline]
rep movsb rep movsb
lea eax, [hdr_cmdline] lea eax, [hdr_cmdline]
stdcall set_app_params , [slot], eax, [flags] stdcall set_app_params , [slot], eax, [flags]
mov eax, [process_number] ;set result
mov eax, [process_number] ;set result
call unlock_application_table call unlock_application_table
ret ret
.err_0: .err_0:
call unlock_application_table call unlock_application_table
.err_hdr: .err_hdr:
stdcall kernel_free, [file_base] stdcall kernel_free, [file_base]
.err_file: .err_file:
stdcall kernel_free, [path_string]
mov eax, esi mov eax, esi
ret ret
endp endp
@ -848,96 +820,48 @@ endp
align 4 align 4
common_app_entry: common_app_entry:
mov ebp, [current_slot] mov ebp, [current_slot]
mov ebp, [ebp+APPDATA.exec_params] mov ebp, [ebp+APPDATA.exec_params]
test ebp, ebp test ebp, ebp
jz .exit jz .exit
stdcall map_process_image, [ebp+APP_HDR._emem],\ stdcall map_process_image, [ebp+APP_HDR._emem],\
[ebp+APP_HDR.img_base], [ebp+APP_HDR.img_size] [ebp+APP_HDR.img_base], [ebp+APP_HDR.img_size]
mov esi, [ebp+APP_HDR.path_string]
xor eax, eax
mov edi, [ebp+APP_HDR.path] mov edi, [ebp+APP_HDR.path]
lea esi, [ebp+sizeof.APP_HDR] push esi
mov ecx, [ebp+APP_HDR.filename_size]
test edi, edi test edi, edi
jnz .copy_filename jz @f
mov ecx, [ebp+APP_HDR.filename_size]
add esi, ecx rep movsb
jmp .check_cmdline mov byte [edi], 0
.copy_full_path:
mov esi, [current_slot]
mov esi, [esi+APPDATA.cur_dir]
mov ebx, 1023
mov al, '/'
stosb
.copy_path:
dec ebx
jz .finish_path
lodsb
stosb
test al, al
jnz .copy_path
mov byte [edi-1], '/'
cmp ecx, ebx
jbe @F
mov ecx, ebx
@@: @@:
lea esi, [ebp+sizeof.APP_HDR] call kernel_free
xor eax, eax
rep movsb
stosb
jmp .check_cmdline
.finish_path:
xor eax, eax
stosb
jmp .check_cmdline
.copy_filename:
cmp byte [esi], '/'
jne .copy_full_path
rep movsb
stosb
.check_cmdline:
mov edi, [ebp+APP_HDR.cmdline] mov edi, [ebp+APP_HDR.cmdline]
mov ecx, [ebp+APP_HDR.cmdline_size]
test edi, edi test edi, edi
jz .check_tls_header jz .check_tls_header
lea esi, [ebp+sizeof.APP_HDR]
mov ecx, [ebp+APP_HDR.cmdline_size]
cmp ecx, 256 cmp ecx, 256
jb .copy_cmdline jb .copy_cmdline
mov edi, [ebp+APP_HDR._emem] mov edi, [ebp+APP_HDR._emem]
add edi, 4095 add edi, 4095
and edi, -4096 and edi, -4096
sub edi, ecx sub edi, ecx
dec edi dec edi
cmp word [6], '00' cmp word [6], '00'
jne @F jne @f
mov [APP_HEADER_00_.i_param], edi mov [APP_HEADER_00_.i_param], edi
jmp .copy_cmdline jmp .copy_cmdline
@@: @@:
mov [APP_HEADER_01_.i_param], edi mov [APP_HEADER_01_.i_param], edi
.copy_cmdline: .copy_cmdline:
rep movsb rep movsb
stosb mov byte [edi], 0
.check_tls_header: .check_tls_header:
cmp word [6], '02' cmp word [6], '02'
jne .cleanup jne .cleanup
call init_heap call init_heap
stdcall user_alloc, 4096 stdcall user_alloc, 4096
mov edx, [current_slot] mov edx, [current_slot]
mov [edx+APPDATA.tls_base], eax mov [edx+APPDATA.tls_base], eax
mov [tls_data_l+2], ax mov [tls_data_l+2], ax
@ -946,11 +870,9 @@ common_app_entry:
mov [tls_data_l+7], ah mov [tls_data_l+7], ah
mov dx, app_tls mov dx, app_tls
mov fs, dx mov fs, dx
.cleanup: .cleanup:
stdcall free_kernel_space, [ebp+APP_HDR.img_base] stdcall free_kernel_space, [ebp+APP_HDR.img_base]
stdcall kernel_free, ebp stdcall kernel_free, ebp
mov ebx, [current_slot] mov ebx, [current_slot]
cmp [ebx+APPDATA.debugger_slot], 0 cmp [ebx+APPDATA.debugger_slot], 0
je .exit je .exit
@ -1018,11 +940,11 @@ proc set_app_params stdcall,slot:dword, params:dword, flags:dword
mov [SLOT_BASE+APPDATA.saved_esp0+ebx], eax mov [SLOT_BASE+APPDATA.saved_esp0+ebx], eax
push ebx push ebx
stdcall kernel_alloc, 0x1000 stdcall kernel_alloc, maxPathLength
pop ebx pop ebx
mov esi, [current_slot] mov esi, [current_slot]
mov esi, [esi+APPDATA.cur_dir] mov esi, [esi+APPDATA.cur_dir]
mov ecx, 0x1000/4 mov ecx, maxPathLength/4
mov edi, eax mov edi, eax
mov [ebx+SLOT_BASE+APPDATA.cur_dir], eax mov [ebx+SLOT_BASE+APPDATA.cur_dir], eax
rep movsd rep movsd

View File

@ -3385,7 +3385,8 @@ Architecture Software Developer's Manual, Volume 3, Appendix B);
Параметры: Параметры:
* eax = 68 - номер функции * eax = 68 - номер функции
* ebx = 19 - номер подфункции * ebx = 19 - номер подфункции
* ecx = указатель на ASCIIZ-строку с полным путём к DLL * ecx = указатель на строку с путём к DLL,
правила формирования строки указаны в описании функции 70.
Возвращаемое значение: Возвращаемое значение:
* eax = 0 - неудача * eax = 0 - неудача
* иначе eax = указатель на таблицу экспорта DLL * иначе eax = указатель на таблицу экспорта DLL
@ -3894,12 +3895,15 @@ Architecture Software Developer's Manual, Volume 3, Appendix B);
* +12 = +0xC: dword: размер * +12 = +0xC: dword: размер
* +16 = +0x10: dword: указатель на данные * +16 = +0x10: dword: указатель на данные
* +20 = +0x14: ?: текстовая строка - путь к файлу, заканчивается нулём * +20 = +0x14: ?: текстовая строка - путь к файлу, заканчивается нулём
или или
* +20 = +0x14: byte: 0 * +20 = +0x14: byte: 0
* +21 = +0x15: dword: указатель на строку * +21 = +0x15: dword: указатель на строку
Для ввода текста в кодировке UTF-16LE нужно расположить в начале строки
байт со значением 2, иначе будет использоваться кодировка cp866.
Чувствительность к регистру букв зависит от файловой системы. Чувствительность к регистру букв зависит от файловой системы.
Можно указать кодировку, поместив в начале строки байт со значениями:
* 1 = cp866
* 2 = UTF-16LE
* 3 = UTF-8
иначе будет использоваться кодировка cp866.
Формат строки: Формат строки:
/base/number/dir1/dir2/.../dirn/file, /base/number/dir1/dir2/.../dirn/file,
где base/number идентифицирует устройство, на котором ищется файл: где base/number идентифицирует устройство, на котором ищется файл:

View File

@ -3348,7 +3348,8 @@ Remarks:
Parameters: Parameters:
* eax = 68 - function number * eax = 68 - function number
* ebx = 19 - subfunction number * ebx = 19 - subfunction number
* ecx = pointer to ASCIIZ-string with the full path to DLL * ecx = pointer to the string with path to DLL,
rules of path forming can be found in function 70 description.
Returned value: Returned value:
* eax = 0 - failed * eax = 0 - failed
* otherwise eax = pointer to DLL export table * otherwise eax = pointer to DLL export table
@ -3849,11 +3850,15 @@ General format of the information structure:
* +12 = +0xC: dword: size * +12 = +0xC: dword: size
* +16 = +0x10: dword: pointer to data * +16 = +0x10: dword: pointer to data
* +20 = +0x14: ?: path - zero terminated string * +20 = +0x14: ?: path - zero terminated string
or or
* +20 = +0x14: byte: 0 * +20 = +0x14: byte: 0
* +21 = +0x15: dword: pointer to string * +21 = +0x15: dword: pointer to string
You may set encoding to UTF-16LE by starting the string with a byte with value 2, Case sensitivity depends on filesystem.
otherwise will be used cp866. Case sensitivity depends on filesystem. To set the encoding, put at the start of the string a byte with next values:
* 1 = cp866
* 2 = UTF-16LE
* 3 = UTF-8
otherwise will be used cp866.
Format of filename: Format of filename:
/base/number/dir1/dir2/.../dirn/file, /base/number/dir1/dir2/.../dirn/file,
where base/number identifies device, on which file is located: where base/number identifies device, on which file is located:

View File

@ -55,35 +55,39 @@ file_system_lfn:
cmp byte [ebp], 0 cmp byte [ebp], 0
jnz @f jnz @f
mov ebp, [ebx+21] mov ebp, [ebx+21]
@@:
cmp word [ebp], '/'
jz .rootdir
cmp byte [ebp], 4
jnc @f
cmp byte [ebp], 0
jz @f
cmp word [ebp+1], '/'
jnz @f
cmp byte [ebp], 2
jnz .rootdir
cmp word [ebp+3], 0
jz .rootdir
@@: @@:
cmp dword[ebx], 7 ; start application cmp dword[ebx], 7 ; start application
jne @f jnz @f
mov edx, [ebx+4] mov edx, [ebx+4]
mov ebx, [ebx+8] mov ebx, [ebx+8]
call fs_execute ; ebp, ebx, edx call fs_execute ; ebp, ebx, edx
mov [image_of_eax], eax mov [image_of_eax], eax
ret ret
@@:
cmp word [ebp], '/'
jz .rootdir
cmp byte [ebp], 2
jnz @f
cmp dword[ebp+1], '/'
jz .rootdir
@@: @@:
stdcall kernel_alloc, maxPathLength stdcall kernel_alloc, maxPathLength
push ebx push ebx
mov ebx, ebp mov ebx, ebp
mov ebp, eax mov ebp, eax
push maxPathLength stdcall get_full_file_name, eax, maxPathLength
push eax
call get_full_file_name
pop ebx pop ebx
test eax, eax test eax, eax
jz .notfound jz .notfound
mov esi, ebp lea esi, [ebp+2]
mov ax, [ebp] mov ax, [esi]
or ax, 2020h or ax, 2020h
cmp ax, 'cd' cmp ax, 'cd'
jz .CD jz .CD
@ -496,11 +500,13 @@ sys_current_directory: ; sysfunction 30
mov ebx, ecx mov ebx, ecx
get_full_file_name: get_full_file_name:
; in: ebx -> file name, [esp+4] -> destination, [esp+8] = max length ; in: ebx -> file name, [esp+4] -> destination, [esp+8] = max length
; out: eax=0 -> out of length ; out: UTF-8 string, eax=0 -> out of length
push ebp ebx push ebp ebx
cmp byte [ebx], 0
jz .set_relative
mov esi, ebx mov esi, ebx
cmp byte [ebx], 2 cmp byte [ebx], 4
jnz @f jnc @f
inc esi inc esi
@@: @@:
cmp byte [esi], '/' cmp byte [esi], '/'
@ -513,6 +519,10 @@ get_full_file_name:
call process_replace_file_name call process_replace_file_name
mov edi, [esp+12] mov edi, [esp+12]
mov ecx, [esp+16] mov ecx, [esp+16]
mov al, 3
mov ah, '/'
stosw
sub ecx, 2
test ebp, ebp test ebp, ebp
jz .absolute jz .absolute
@@: @@:
@ -525,12 +535,23 @@ get_full_file_name:
dec edi dec edi
.absolute: .absolute:
cmp byte [ebx], 2 cmp byte [ebx], 2
jz @f jz .utf16
cmp byte [ebx], 3
jz .utf8
call cp866toUTF8_string call cp866toUTF8_string
jns .ret jns .ret
jmp .fail jmp .fail
@@: .utf8:
dec ecx
js .fail
lodsb
stosb
test al, al
jz .ret
jmp .utf8
.utf16:
call UTF16to8_string call UTF16to8_string
jns .ret jns .ret
.fail: .fail:
@ -550,7 +571,12 @@ get_full_file_name:
dec esi dec esi
mov edi, [esp+12] mov edi, [esp+12]
jecxz .fail jecxz .fail
cmp byte [ebx], 2 cmp byte [ebx], 0
jz .set_ok
cmp byte [ebx], 4
jnc .relative
inc ebx
cmp byte [ebx-1], 2
jz .relative16 jz .relative16
.relative: .relative:
cmp byte [ebx], 0 cmp byte [ebx], 0

View File

@ -7,54 +7,43 @@
$Revision$ $Revision$
iglobal iglobal
; pointer to memory for path replace table, full_file_name_table dd sysdir_name
; size of one record is 128 bytes: 64 bytes for search pattern + 64 bytes for replace string .size dd 1
; start with one entry: sys -> <sysdir>
full_file_name_table dd sysdir_name
.size dd 1
tmp_file_name_size dd 1
endg endg
uglobal uglobal
; Parser_params will initialize: sysdir_name = "sys", sysdir_path = <sysdir> sysdir_name rb 64 ; 'sys',0
sysdir_name rb 64 sysdir_path rb 64
sysdir_path rb 64 sysdir_name1 rb 64
sysdir_name1 rb 64 sysdir_path1 rb 64
sysdir_path1 rb 64
; for example:
;dir_name1 db 'KolibriOS',0
; rb 64-8
;dir_path1 db 'HD0/1',0
; rb 64-6
endg endg
; Example:
; align 64
; sysdir_name1 db 'KolibriOS',0
; align 64
; sysdir_path1 db 'HD0/1',0
uglobal
tmp_file_name_table dd ?
endg
; use bx_from_load and init system directory /sys
proc Parser_params proc Parser_params
locals locals
buff db 4 dup(?) ; for test cd buff rb 4 ; for test cd
endl endl
mov eax, [OS_BASE+0x10000+bx_from_load] mov eax, [OS_BASE+0x10000+bx_from_load]
mov ecx, sysdir_path mov ecx, sysdir_path
mov [ecx-64], dword 'sys' mov [ecx-64], dword 'sys'
cmp al, 'r'; if ram disk mov [ecx-2], byte 3
mov [ecx-1], byte '/'
cmp al, 'r' ; ram disk
jnz @f jnz @f
mov [ecx], dword 'RD/?' mov [ecx], dword 'RD/?'
mov [ecx+3], byte ah mov [ecx+3], byte ah
mov [ecx+4], byte 0 mov [ecx+4], byte 0
ret ret
@@: @@:
cmp al, 'm'; if ram disk cmp al, 'm'
jnz @f jnz .hard_disk
mov [ecx], dword 'CD?/'; if cd disk {m} mov [ecx], dword 'CD?/'
mov [ecx+4], byte '1' mov [ecx+4], byte '1'
mov [ecx+5], dword '/KOL' mov [ecx+5], dword '/KOL'
mov [ecx+9], dword 'IBRI' mov [ecx+9], dword 'IBRI'
@ -63,177 +52,24 @@ endl
mov [ecx+2], byte ah mov [ecx+2], byte ah
inc ah inc ah
cmp ah, '5' cmp ah, '5'
je .not_found_cd je @f
lea edx, [buff] lea edx, [buff]
pushad pushad
stdcall read_file, read_firstapp, edx, 0, 4 stdcall read_file, read_firstapp, edx, 0, 4
popad popad
cmp [edx], dword 'MENU' cmp [edx], dword 'MENU'
jne .next_cd jne .next_cd
jmp .ok
@@: @@:
sub al, 49 ret
mov [ecx], dword 'HD?/'; if hard disk
.hard_disk:
sub al, '1'
mov [ecx], dword 'HD?/'
mov [ecx+2], byte al mov [ecx+2], byte al
mov [ecx+4], byte ah mov [ecx+4], byte ah
mov [ecx+5], dword '/KOL' mov [ecx+5], dword '/KOL'
mov [ecx+9], dword 'IBRI' mov [ecx+9], dword 'IBRI'
mov [ecx+13], byte 0 mov [ecx+13], byte 0
.ok:
.not_found_cd:
ret
endp
proc load_file_parse_table
stdcall kernel_alloc, 0x1000
mov [tmp_file_name_table], eax
mov edi, eax
mov esi, sysdir_name
mov ecx, 128/4
rep movsd
invoke ini.enum_keys, conf_fname, conf_path_sect, get_every_key
mov eax, [tmp_file_name_table]
mov [full_file_name_table], eax
mov eax, [tmp_file_name_size]
mov [full_file_name_table.size], eax
ret
endp
uglobal
def_val_1 db 0
endg
proc get_every_key stdcall, f_name, sec_name, key_name
mov esi, [key_name]
mov ecx, esi
cmp byte [esi], '/'
jnz @f
inc esi
@@:
mov edi, [tmp_file_name_size]
shl edi, 7
cmp edi, 0x1000
jae .stop_parse
add edi, [tmp_file_name_table]
lea ebx, [edi+64]
@@:
cmp edi, ebx
jae .skip_this_key
lodsb
test al, al
jz @f
or al, 20h
stosb
jmp @b
@@:
stosb
invoke ini.get_str, [f_name], [sec_name], ecx, ebx, 64, def_val_1
cmp byte [ebx], '/'
jnz @f
lea esi, [ebx+1]
mov edi, ebx
mov ecx, 63
rep movsb
@@:
push ebp
mov ebp, [tmp_file_name_table]
mov ecx, [tmp_file_name_size]
jecxz .noreplace
mov eax, ecx
dec eax
shl eax, 7
add ebp, eax
.replace_loop:
mov edi, ebx
mov esi, ebp
@@:
lodsb
test al, al
jz .doreplace
mov dl, [edi]
inc edi
test dl, dl
jz .replace_loop_cont
or dl, 20h
cmp al, dl
jz @b
jmp .replace_loop_cont
.doreplace:
cmp byte [edi], 0
jz @f
cmp byte [edi], '/'
jnz .replace_loop_cont
@@:
lea esi, [ebp+64]
call .replace
jc .skip_this_key2
.replace_loop_cont:
sub ebp, 128
loop .replace_loop
.noreplace:
pop ebp
inc [tmp_file_name_size]
.skip_this_key:
xor eax, eax
inc eax
ret
.skip_this_key2:
pop ebp
jmp .skip_this_key
.stop_parse:
xor eax, eax
ret
endp
proc get_every_key.replace
; in: ebx->destination, esi->first part of name, edi->second part of name
; maximum length is 64 bytes
; out: CF=1 <=> overflow
; 1) allocate temporary buffer in stack
sub esp, 64
; 2) save second part of name to temporary buffer
push esi
lea esi, [esp+4] ; esi->tmp buffer
xchg esi, edi ; edi->tmp buffer, esi->source
@@:
lodsb
stosb
test al, al
jnz @b
; 3) copy first part of name to destination
pop esi
mov edi, ebx
@@:
lodsb
test al, al
jz @f
stosb
jmp @b
@@:
; 4) restore second part of name from temporary buffer to destination
; (may cause overflow)
lea edx, [ebx+64] ; limit of destination
mov esi, esp
@@:
cmp edi, edx
jae .overflow
lodsb
stosb
test al, al
jnz @b
; all is OK
add esp, 64 ; CF is cleared
ret
.overflow:
; name is too long
add esp, 64
stc
ret ret
endp endp

View File

@ -1198,7 +1198,7 @@ proc setup_os_slot
mov dword [edx+APPDATA.fd_obj], eax mov dword [edx+APPDATA.fd_obj], eax
mov dword [edx+APPDATA.bk_obj], eax mov dword [edx+APPDATA.bk_obj], eax
mov dword [edx+APPDATA.cur_dir], sysdir_path mov dword [edx+APPDATA.cur_dir], sysdir_path-2
mov [edx + APPDATA.process], sys_proc mov [edx + APPDATA.process], sys_proc

View File

@ -26,8 +26,6 @@ include "core/irq.inc" ; interrupt handling functions
include "core/apic.inc" include "core/apic.inc"
include "core/timers.inc" include "core/timers.inc"
include "core/clipboard.inc" include "core/clipboard.inc"
include "core/conf_lib.inc"
include "core/ext_lib.inc" ; load external library
include "boot/shutdown.inc" ; kernel shutdown include "boot/shutdown.inc" ; kernel shutdown
@ -67,4 +65,6 @@ include "fs/fs_lfn.inc" ; sysfunction 70
include "network/stack.inc" include "network/stack.inc"
include "imports.inc" ; list of external functions ; include "imports.inc"
; include "core/ext_lib.inc"
; include "core/conf_lib.inc"