4,9 → 4,9 |
; All rights reserved. |
|
formatter: |
mov [current_offset],edi |
cmp [output_file],0 |
jne output_path_ok |
push edi |
mov esi,[input_file] |
mov edi,[free_additional_memory] |
copy_output_path: |
118,8 → 118,30 |
inc edi |
mov [structures_buffer],edi |
mov [output_file],edi |
pop edi |
output_path_ok: |
cmp [symbols_file],0 |
je labels_table_ok |
mov ecx,[memory_end] |
sub ecx,[labels_list] |
mov edi,[display_buffer] |
sub edi,8 |
mov [edi],ecx |
or dword [edi+4],-1 |
sub edi,ecx |
cmp edi,[esp] |
jbe out_of_memory |
mov [display_buffer],edi |
mov esi,[memory_end] |
copy_labels: |
sub esi,32 |
cmp esi,[labels_list] |
jb labels_table_ok |
mov ecx,32 shr 2 |
rep movs dword [edi],[esi] |
sub esi,32 |
jmp copy_labels |
labels_table_ok: |
mov edi,[current_offset] |
cmp [output_format],4 |
je coff_formatter |
cmp [output_format],5 |
134,6 → 156,7 |
jne calculate_code_size |
mov edi,[undefined_data_start] |
calculate_code_size: |
mov [current_offset],edi |
sub edi,[code_start] |
mov [code_size],edi |
mov [written_size],0 |
155,6 → 178,8 |
call write_code |
output_written: |
call close |
cmp [symbols_file],0 |
jne dump_symbols |
ret |
write_code: |
mov eax,[written_size] |
162,6 → 187,7 |
mov edx,[code_start] |
mov ecx,[code_size] |
add [written_size],ecx |
lea eax,[edx+ecx] |
call write |
jc write_failed |
ret |
837,6 → 863,10 |
jc setting_already_specified |
and ax,3Fh |
mov [subsystem],ax |
cmp ax,10 |
jb subsystem_type_ok |
or [format_flags],8 |
subsystem_type_ok: |
cmp byte [esi],'(' |
jne pe_settings |
inc esi |
890,11 → 920,11 |
push edx edi |
add edi,[stub_size] |
test [format_flags],8 |
jnz get_pe64_base |
jnz get_peplus_base |
call get_dword_value |
mov [image_base],eax |
jmp pe_base_ok |
get_pe64_base: |
get_peplus_base: |
call get_qword_value |
mov [image_base],eax |
mov [image_base_high],edx |
957,7 → 987,7 |
pe_alignment_ok: |
mov word [edx+1Ah],VERSION_MAJOR + VERSION_MINOR shl 8 |
test [format_flags],8 |
jnz init_pe64_specific |
jnz init_peplus_specific |
mov dword [edx+14h],0E0h ; size of optional header |
mov dword [edx+16h],10B010Eh; flags and magic value |
mov eax,[image_base] |
968,7 → 998,7 |
mov dword [edx+6Ch],0 ; heap commit |
mov dword [edx+74h],16 ; number of directories |
jmp pe_header_ok |
init_pe64_specific: |
init_peplus_specific: |
mov dword [edx+14h],0F0h ; size of optional header |
mov dword [edx+16h],20B002Eh; flags and magic value |
mov eax,[image_base] |
1031,13 → 1061,13 |
add eax,edi |
adc ecx,0 |
test [format_flags],8 |
jnz pe64_org |
jnz peplus_org |
sub eax,[edx+34h] |
sbb ecx,0 |
mov bl,2 |
mov [code_type],32 |
jmp pe_org_ok |
pe64_org: |
peplus_org: |
sub eax,[edx+30h] |
sbb ecx,[edx+34h] |
mov bl,4 |
1103,7 → 1133,7 |
sub eax,[ebx+0Ch] |
sbb ecx,0 |
test [format_flags],8 |
jnz pe64_section_org |
jnz peplus_section_org |
sub eax,[edx+34h] |
sbb ecx,0 |
mov [labels_type],2 |
1112,7 → 1142,7 |
jc pe_section_org_ok |
mov [labels_type],0 |
jmp pe_section_org_ok |
pe64_section_org: |
peplus_section_org: |
sub eax,[edx+30h] |
sbb ecx,[edx+34h] |
mov [labels_type],4 |
1138,11 → 1168,11 |
inc esi |
mov ecx,ebx |
test [format_flags],8 |
jnz pe64_directory |
jnz peplus_directory |
xchg ecx,[edx+78h+eax*8] |
mov dword [edx+78h+eax*8+4],-1 |
jmp pe_directory_set |
pe64_directory: |
peplus_directory: |
xchg ecx,[edx+88h+eax*8] |
mov dword [edx+88h+eax*8+4],-1 |
pe_directory_set: |
1199,6 → 1229,27 |
mov eax,[code_start] |
sub eax,[stub_size] |
sub [ebx+14h],eax |
|
mov ecx,[ebx+10h] |
test byte [ebx+24h],20h |
jz pe_code_sum_ok |
add [edx+1Ch],ecx |
cmp dword [edx+2Ch],0 |
jne pe_code_sum_ok |
mov eax,[ebx+0Ch] |
mov [edx+2Ch],eax |
pe_code_sum_ok: |
test byte [ebx+24h],40h |
jz pe_data_sum_ok |
add [edx+20h],ecx |
test [format_flags],8 |
jnz pe_data_sum_ok |
cmp dword [edx+30h],0 |
jne pe_data_sum_ok |
mov eax,[ebx+0Ch] |
mov [edx+30h],eax |
pe_data_sum_ok: |
|
mov eax,[ebx+8] |
or eax,eax |
jz udata_ok |
1205,7 → 1256,9 |
cmp dword [ebx+10h],0 |
jne udata_ok |
or byte [ebx+24h],80h |
add [edx+24h],ecx |
udata_ok: |
|
mov ecx,[edx+38h] |
dec ecx |
add eax,ecx |
1239,10 → 1292,10 |
add ecx,[ebx+0Ch] |
mov edx,[code_start] |
test [format_flags],8 |
jnz pe64_data |
jnz peplus_data |
xchg ecx,[edx+78h+eax*8] |
jmp init_pe_data |
pe64_data: |
peplus_data: |
xchg ecx,[edx+88h+eax*8] |
init_pe_data: |
or ecx,ecx |
1266,11 → 1319,11 |
add ecx,[edx+0Ch] |
mov edx,[code_start] |
test [format_flags],8 |
jnz end_pe64_data |
jnz end_peplus_data |
sub ecx,[edx+78h+eax*8] |
mov [edx+78h+eax*8+4],ecx |
jmp remove_structure_data |
end_pe64_data: |
end_peplus_data: |
sub ecx,[edx+88h+eax*8] |
mov [edx+88h+eax*8+4],ecx |
jmp remove_structure_data |
1281,7 → 1334,7 |
cmp byte [esi],'.' |
je invalid_value |
test [format_flags],8 |
jnz pe64_entry |
jnz peplus_entry |
call get_dword_value |
mov bl,2 |
bt [resolver_flags],0 |
1300,29 → 1353,29 |
sub eax,[edx+34h] |
mov [edx+28h],eax |
jmp instruction_assembled |
pe64_entry: |
peplus_entry: |
call get_qword_value |
mov bl,4 |
bt [resolver_flags],0 |
jc check_pe64_entry_label_type |
jc check_peplus_entry_label_type |
xor bl,bl |
check_pe64_entry_label_type: |
check_peplus_entry_label_type: |
cmp [value_type],bl |
je pe64_entry_type_ok |
je peplus_entry_type_ok |
cmp [error_line],0 |
jne pe64_entry_type_ok |
jne peplus_entry_type_ok |
mov edx,[current_line] |
mov [error_line],edx |
mov [error],invalid_address |
pe64_entry_type_ok: |
peplus_entry_type_ok: |
mov ecx,[code_start] |
sub eax,[ecx+30h] |
sbb edx,[ecx+34h] |
jz pe64_entry_range_ok |
jz peplus_entry_range_ok |
mov edx,[current_line] |
mov [error_line],edx |
mov [error],value_out_of_range |
pe64_entry_range_ok: |
peplus_entry_range_ok: |
mov [ecx+28h],eax |
jmp instruction_assembled |
pe_stack: |
1332,7 → 1385,7 |
cmp byte [esi],'.' |
je invalid_value |
test [format_flags],8 |
jnz pe64_stack |
jnz peplus_stack |
call get_dword_value |
cmp [value_type],0 |
jne invalid_use_of_symbol |
1361,7 → 1414,7 |
ja instruction_assembled |
mov dword [edx+64h],eax |
jmp instruction_assembled |
pe64_stack: |
peplus_stack: |
call get_qword_value |
cmp [value_type],0 |
jne invalid_use_of_symbol |
1369,7 → 1422,7 |
mov [ecx+60h],eax |
mov [ecx+64h],edx |
cmp byte [esi],',' |
jne default_pe64_stack_commit |
jne default_peplus_stack_commit |
lods byte [esi] |
lods byte [esi] |
cmp al,'(' |
1388,7 → 1441,7 |
cmp eax,[ecx+60h] |
ja value_out_of_range |
jmp instruction_assembled |
default_pe64_stack_commit: |
default_peplus_stack_commit: |
mov dword [ecx+68h],1000h |
cmp dword [ecx+64h],0 |
jne instruction_assembled |
1404,7 → 1457,7 |
cmp byte [esi],'.' |
je invalid_value |
test [format_flags],8 |
jnz pe64_heap |
jnz peplus_heap |
call get_dword_value |
cmp [value_type],0 |
jne invalid_use_of_symbol |
1426,7 → 1479,7 |
cmp eax,[edx+68h] |
ja value_out_of_range |
jmp instruction_assembled |
pe64_heap: |
peplus_heap: |
call get_qword_value |
cmp [value_type],0 |
jne invalid_use_of_symbol |
1963,7 → 2016,7 |
jge check_next_language_id |
mov edx,eax |
mov eax,[esp] |
mov [current_offset],eax |
mov dword [value],eax |
check_next_language_id: |
pop esi |
mov eax,[esi+16] |
1981,7 → 2034,7 |
jae out_of_memory |
mov eax,ebx |
stos dword [edi] |
mov eax,[current_offset] |
mov eax,dword [value] |
stos dword [edi] |
jmp make_language_id_directory |
language_id_directory_done: |
2331,6 → 2384,9 |
test [format_flags],8 |
jnz coff_64bit_relocation |
mov al,6 |
cmp [value_type],5 |
jne coff_relocation |
inc al |
jmp coff_relocation |
coff_64bit_relocation: |
mov al,1 |
2337,6 → 2393,9 |
cmp [value_type],4 |
je coff_relocation |
mov al,2 |
cmp [value_type],5 |
jne coff_relocation |
inc al |
jmp coff_relocation |
coff_relocation_relative: |
push ebx |
3514,6 → 3573,7 |
mov [edx+1+4],eax |
mov dword [edx+1+8],'.str' |
mov [edx+1+8+4],eax |
mov [resource_data],edx |
mov [written_size],0 |
mov edx,[output_file] |
call create |
3909,3 → 3969,281 |
or [next_pass_needed],-1 |
elf64_exe_ok: |
ret |
|
dump_symbols: |
mov ebx,[code_start] |
mov dword [ebx],'fas'+27 shl 24 |
mov dword [ebx+4],VERSION_MAJOR + VERSION_MINOR shl 8 + 38h shl 16 |
add ebx,38h |
mov edi,ebx |
mov dword [ebx-38h+10h],38h |
mov dword [ebx-38h+8],0 |
mov esi,[input_file] |
call copy_asciiz |
cmp edi,[display_buffer] |
jae out_of_memory |
mov eax,edi |
sub eax,ebx |
mov [ebx-38h+0Ch],eax |
mov esi,[output_file] |
call copy_asciiz |
cmp edi,[display_buffer] |
jae out_of_memory |
mov edx,[symbols_stream] |
mov ebp,[free_additional_memory] |
mov [number_of_sections],0 |
cmp [output_format],4 |
je prepare_strings_table |
cmp [output_format],5 |
jne strings_table_ready |
bt [format_flags],0 |
jc strings_table_ready |
prepare_strings_table: |
cmp edx,ebp |
je strings_table_ready |
mov al,[edx] |
test al,al |
jz prepare_string |
cmp al,80h |
je prepare_string |
add edx,0Ch |
cmp al,0C0h |
jne prepare_strings_table |
add edx,4 |
jmp prepare_strings_table |
prepare_string: |
mov esi,edi |
sub esi,ebx |
xchg esi,[edx+4] |
test al,al |
jz prepare_section_string |
or dword [edx+4],1 shl 31 |
add edx,0Ch |
prepare_external_string: |
mov ecx,[esi] |
add esi,4 |
rep movs byte [edi],[esi] |
mov byte [edi],0 |
inc edi |
cmp edi,[display_buffer] |
jae out_of_memory |
jmp prepare_strings_table |
prepare_section_string: |
mov ecx,[number_of_sections] |
mov eax,ecx |
inc eax |
mov [number_of_sections],eax |
xchg eax,[edx+4] |
shl ecx,2 |
add ecx,[free_additional_memory] |
mov [ecx],eax |
add edx,20h |
test esi,esi |
jz prepare_default_section_string |
cmp [output_format],5 |
jne prepare_external_string |
bt [format_flags],0 |
jc prepare_external_string |
mov esi,[esi] |
add esi,[resource_data] |
copy_elf_section_name: |
lods byte [esi] |
cmp edi,[display_buffer] |
jae out_of_memory |
stos byte [edi] |
test al,al |
jnz copy_elf_section_name |
jmp prepare_strings_table |
prepare_default_section_string: |
mov eax,'.fla' |
stos dword [edi] |
mov ax,'t' |
stos word [edi] |
cmp edi,[display_buffer] |
jae out_of_memory |
jmp prepare_strings_table |
strings_table_ready: |
mov edx,[display_buffer] |
mov ebp,[memory_end] |
sub ebp,[labels_list] |
add ebp,edx |
prepare_labels_dump: |
cmp edx,ebp |
je labels_dump_ok |
mov eax,[edx+24] |
test eax,eax |
jz label_dump_name_ok |
cmp eax,[memory_start] |
jb label_name_outside_source |
cmp eax,[source_start] |
ja label_name_outside_source |
sub eax,[memory_start] |
dec eax |
mov [edx+24],eax |
jmp label_dump_name_ok |
label_name_outside_source: |
mov esi,eax |
mov eax,edi |
sub eax,ebx |
or eax,1 shl 31 |
mov [edx+24],eax |
movzx ecx,byte [esi-1] |
lea eax,[edi+ecx+1] |
cmp edi,[display_buffer] |
jae out_of_memory |
rep movsb |
xor al,al |
stosb |
label_dump_name_ok: |
mov eax,[edx+28] |
test eax,eax |
jz label_dump_line_ok |
sub eax,[memory_start] |
mov [edx+28],eax |
label_dump_line_ok: |
mov eax,[edx+20] |
test eax,eax |
jz base_symbol_for_label_ok |
cmp eax,[symbols_stream] |
mov eax,[eax+4] |
jae base_symbol_for_label_ok |
xor eax,eax |
base_symbol_for_label_ok: |
mov [edx+20],eax |
add edx,32 |
jmp prepare_labels_dump |
labels_dump_ok: |
mov eax,edi |
sub eax,ebx |
mov [ebx-38h+14h],eax |
add eax,38h |
mov [ebx-38h+18h],eax |
mov ecx,[memory_end] |
sub ecx,[labels_list] |
mov [ebx-38h+1Ch],ecx |
add eax,ecx |
mov [ebx-38h+20h],eax |
mov ecx,[source_start] |
sub ecx,[memory_start] |
mov [ebx-38h+24h],ecx |
add eax,ecx |
mov [ebx-38h+28h],eax |
mov eax,[number_of_sections] |
shl eax,3 |
mov [ebx-38h+34h],eax |
mov esi,[memory_start] |
prepare_preprocessed_source: |
cmp esi,[source_start] |
jae preprocessed_source_ok |
mov eax,[memory_start] |
mov edx,[input_file] |
cmp [esi],edx |
jne line_not_from_main_input |
mov [esi],eax |
line_not_from_main_input: |
sub [esi],eax |
test byte [esi+7],1 shl 7 |
jz prepare_next_preprocessed_line |
sub [esi+8],eax |
sub [esi+12],eax |
prepare_next_preprocessed_line: |
add esi,16 |
call skip_foreign_line |
jmp prepare_preprocessed_source |
preprocessed_source_ok: |
mov esi,[labels_list] |
mov ebp,edi |
make_lines_dump: |
cmp esi,[display_buffer] |
je lines_dump_ok |
mov eax,[esi-4] |
mov ecx,[esi-8] |
sub esi,8 |
sub esi,ecx |
cmp eax,1 |
jne make_lines_dump |
mov eax,[esi+4] |
sub eax,[code_start] |
add eax,[headers_size] |
cmp byte [esi+1Ah],0 |
je store_offset |
xor eax,eax |
store_offset: |
stos dword [edi] |
mov eax,[esi] |
sub eax,[memory_start] |
stos dword [edi] |
mov eax,[esi+4] |
xor edx,edx |
sub eax,[esi+8] |
sbb edx,[esi+8+4] |
stos dword [edi] |
mov eax,edx |
stos dword [edi] |
mov eax,[esi+10h] |
stos dword [edi] |
mov eax,[esi+14h] |
test eax,eax |
jz base_symbol_for_line_ok |
cmp eax,[symbols_stream] |
mov eax,[eax+4] |
jae base_symbol_for_line_ok |
xor eax,eax |
base_symbol_for_line_ok: |
stos dword [edi] |
mov eax,[esi+18h] |
and eax,001FFFFh |
stos dword [edi] |
jmp make_lines_dump |
lines_dump_ok: |
mov edx,edi |
mov eax,[current_offset] |
sub eax,[code_start] |
add eax,[headers_size] |
stos dword [edi] |
mov ecx,edi |
sub ecx,ebx |
sub ecx,[ebx-38h+14h] |
mov [ebx-38h+2Ch],ecx |
add ecx,[ebx-38h+28h] |
mov [ebx-38h+30h],ecx |
find_inexisting_offsets: |
sub edx,1Ch |
cmp edx,ebp |
jb write_symbols |
test byte [edx+1Ah],1 |
jnz find_inexisting_offsets |
cmp eax,[edx] |
jb correct_inexisting_offset |
mov eax,[edx] |
jmp find_inexisting_offsets |
correct_inexisting_offset: |
mov dword [edx],0 |
or byte [edx+1Ah],2 |
jmp find_inexisting_offsets |
write_symbols: |
mov edx,[symbols_file] |
call create |
jc write_failed |
mov edx,[code_start] |
mov ecx,[edx+14h] |
add ecx,38h |
call write |
mov edx,[display_buffer] |
mov ecx,[memory_end] |
sub ecx,[labels_list] |
call write |
mov edx,[memory_start] |
mov ecx,[source_start] |
sub ecx,edx |
call write |
mov edx,ebp |
mov ecx,edi |
sub ecx,edx |
call write |
mov edx,[free_additional_memory] |
mov ecx,[number_of_sections] |
shl ecx,2 |
call write |
call close |
ret |