;; B0 EXECUTABLE
;; PE FORMAT


;Register renaming

r0 equ rax
r0d equ eax
r0w equ ax
r0b equ al
r1 equ rbx
r1d equ ebx
r1w equ bx
r1b equ bl
r2 equ rcx
r2d equ ecx
r2w equ cx
r2b equ cl
r3 equ rdx
r3d equ edx
r3w equ dx
r3b equ dl
r4 equ rdi
r4d equ edi
r4w equ di
r4b equ dil
r5 equ rsi
r5d equ esi
r5w equ si
r5b equ sil
r6 equ rbp
r6d equ ebp
r6w equ bp
r6b equ bpl
r7 equ rsp
r7d equ esp
r7w equ sp
r7b equ spl

fp0 equ ST0
fp1 equ ST1
fp2 equ ST2
fp3 equ ST3
fp4 equ ST4
fp5 equ ST5
fp6 equ ST6
fp7 equ ST7

;Default Macros
macro UTF16_STRING name, [string]
{
common
	name:
local label,label2
	label:
	dw ((label2-label)/2)-3
	dw ((label2-label)/2)-3
	dw string
	label2:
	dw 0
}

macro UTF8_STRING name, [string]
{
common
	name:
local label,label2
	label:
	db ((label2-label)/2)-3
	db ((label2-label)/2)-3
	db string
	label2:
	db 0
}

format PE64 CONSOLE 4.0
use64

entry start


section '.data' data readable writeable


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; __Init_Win64 Function Variables ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; End __Init_Win64 Function Variables ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; strlen Function Variables ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

_B0_strlen_string equ 0

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; End strlen Function Variables ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; sys_write Function Variables ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

_B0_sys_write__handle equ 0
_B0_sys_write__ptr equ 8
_B0_sys_write__size equ 16
_B0_sys_write_buffer equ 24

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; End sys_write Function Variables ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; echo_string Function Variables ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

_B0_echo_string_handle equ 0
_B0_echo_string_string equ 8

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; End echo_string Function Variables ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; echo_hex Function Variables ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

_B0_echo_hex_handle equ 0
_B0_echo_hex_integer equ 8
_B0_echo_hex_hex_string equ 16

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; End echo_hex Function Variables ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; itoah Function Variables ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

_B0_itoah_string equ 0
_B0_itoah_value equ 8

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; End itoah Function Variables ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; itoa Function Variables ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

_B0_itoa_dest_ptr equ 0
_B0_itoa_value equ 8

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; End itoa Function Variables ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; itoa_puti2 Function Variables ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

_B0_itoa_puti2_value equ 0

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; End itoa_puti2 Function Variables ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; echo_integer Function Variables ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

_B0_echo_integer_handle equ 0
_B0_echo_integer_integer equ 8
_B0_echo_integer_int_string equ 16

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; End echo_integer Function Variables ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; echo_character Function Variables ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

_B0_echo_character_handle equ 0
_B0_echo_character_character equ 8
_B0_echo_character_char_string equ 16

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; End echo_character Function Variables ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

_B0_pArgc dq 0
_B0_pArgv dq 0

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; SetArgCV Function Variables ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; End SetArgCV Function Variables ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; _fopen Function Variables ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

_B0__fopen_file2open equ 0
_B0__fopen_acl equ 8

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; End _fopen Function Variables ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; _fclose Function Variables ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

_B0__fclose_handle equ 0

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; End _fclose Function Variables ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; _fgetc Function Variables ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

_B0__fgetc_handle equ 0
_B0__fgetc_buffer equ 8
_B0__fgetc_buffer2 equ 16

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; End _fgetc Function Variables ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; _ftell Function Variables ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

_B0__ftell_handle equ 0

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; End _ftell Function Variables ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; main Function Variables ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

_B0_main_str_buffer equ 0
UTF8_STRING B0_DynStr0 , 074h,065h,073h,074h,020h,061h,072h,067h,063h,02ch,020h,061h,072h,067h,076h,020h,061h,070h,070h,06ch,069h,063h,061h,074h,069h,06fh,06eh,0ah,0
UTF8_STRING B0_DynStr1 , 041h,072h,067h,063h,020h,03dh,020h,0
UTF8_STRING B0_DynStr2 , 0ah,041h,072h,067h,076h,020h,03dh,020h,0
UTF8_STRING B0_DynStr3 , 0ah,0
UTF8_STRING B0_DynStr4 , 041h,072h,067h,076h,05bh,0
UTF8_STRING B0_DynStr5 , 05dh,020h,03dh,020h,0
UTF8_STRING B0_DynStr6 , 0ah,0
UTF8_STRING B0_DynStr7 , 043h,06fh,06dh,06dh,061h,06eh,064h,04ch,069h,06eh,065h,054h,06fh,041h,072h,067h,076h,057h,020h,066h,061h,069h,06ch,065h,064h,0ah,0
UTF8_STRING B0_DynStr8 , 0ah,04fh,070h,065h,06eh,020h,046h,069h,06ch,065h,020h,074h,065h,073h,074h,0ah,0
UTF8_STRING B0_DynStr9 , 052h,045h,041h,044h,04dh,045h,0
UTF8_STRING B0_DynStr10 , 072h,0
UTF8_STRING B0_DynStr11 , 046h,069h,06ch,065h,020h,048h,061h,06eh,064h,06ch,065h,020h,03dh,020h,0
UTF8_STRING B0_DynStr12 , 0ah,052h,065h,061h,064h,069h,06eh,067h,020h,046h,069h,06ch,065h,020h,043h,06fh,06eh,074h,065h,06eh,074h,073h,03ah,0ah,0
UTF8_STRING B0_DynStr13 , 0ah,043h,06ch,06fh,073h,069h,06eh,067h,020h,046h,069h,06ch,065h,0ah,0

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; End main Function Variables ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


db "EXB0 0.0.19",0

_B0_env_buffer rb 256
_B0__stdin rq 1
_B0__stdout rq 1
_B0__stderr rq 1

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; __Init_Win64 Function BSS Variables ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; End __Init_Win64 Function BSS Variables ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; strlen Function BSS Variables ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; End strlen Function BSS Variables ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; sys_write Function BSS Variables ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; End sys_write Function BSS Variables ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; echo_string Function BSS Variables ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; End echo_string Function BSS Variables ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; echo_hex Function BSS Variables ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; End echo_hex Function BSS Variables ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; itoah Function BSS Variables ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; End itoah Function BSS Variables ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; itoa Function BSS Variables ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; End itoa Function BSS Variables ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; itoa_puti2 Function BSS Variables ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; End itoa_puti2 Function BSS Variables ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; echo_integer Function BSS Variables ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; End echo_integer Function BSS Variables ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; echo_character Function BSS Variables ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; End echo_character Function BSS Variables ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

_B0_szArglist rq 1
_B0_nArgs rq 1
_B0___argv rq 256
_B0___argv_strings rb 65536

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; SetArgCV Function BSS Variables ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; End SetArgCV Function BSS Variables ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; _fopen Function BSS Variables ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; End _fopen Function BSS Variables ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; _fclose Function BSS Variables ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; End _fclose Function BSS Variables ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; _fgetc Function BSS Variables ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; End _fgetc Function BSS Variables ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; _ftell Function BSS Variables ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; End _ftell Function BSS Variables ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; main Function BSS Variables ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; End main Function BSS Variables ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

align 16
DATA_END:
	rb 200000h

section '.code' code readable executable


start:
	finit
	lea r6,[DATA_END]
	call _B0_main

B0_sys_exit:
	mov ecx,eax
	call [ExitProcess]

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; __Init_Win64 Function Code ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

align 8
_B0___Init_Win64:
	push r1
	push r2
	push r3
	push r4
	push r5
	push r8
	push r9
	push r10
	push r11
	push r12
	push r13
	push r14
	push r15
	mov r2, -10
	sub r7, 20h
	call [GetStdHandle]
	add r7, 20h
	mov qword [_B0__stdin], r0 
	mov r2, -11
	sub r7, 20h
	call [GetStdHandle]
	add r7, 20h
	mov qword [_B0__stdout], r0 
	mov r2, -12
	sub r7, 20h
	call [GetStdHandle]
	add r7, 20h
	mov qword [_B0__stderr], r0 
	pop r15
	pop r14
	pop r13
	pop r12
	pop r11
	pop r10
	pop r9
	pop r8
	pop r5
	pop r4
	pop r3
	pop r2
	pop r1
	mov r0, 0
	ret

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; End __Init_Win64 Function Code;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; strlen Function Code ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

align 8
_B0_strlen:
	push r1
	push r2
	mov r1, qword [r6+_B0_strlen_string]
	add r1, 2
	xor r0, r0
	mov r2, r0
	mov r2b, [r1+r0]
	test r2, r2
	je .B0_END_BLOCK_00005
	.B0_END_BLOCK_00004:
	add r0, 1
	mov r2b, [r1+r0]
	test r2, r2
	jne .B0_END_BLOCK_00004
	.B0_END_BLOCK_00005:
	pop r2
	pop r1
	ret
	mov r0, 0
	ret

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; End strlen Function Code;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; sys_write Function Code ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

align 8
_B0_sys_write:
	mov r2, qword [r6+_B0_sys_write__handle]
	mov r0, 0
	cmp r2, r0
	jne .B0_END_BLOCK_00007
	mov r2, qword [_B0__stdin]
	jmp .B0_END_BLOCK_00008
	.B0_END_BLOCK_00007:
	mov r0, 1
	cmp r2, r0
	jne .B0_END_BLOCK_00009
	mov r2, qword [_B0__stdout]
	jmp .B0_END_BLOCK_000010
	.B0_END_BLOCK_00009:
	mov r0, 2
	cmp r2, r0
	jne .B0_END_BLOCK_000011
	mov r2, qword [_B0__stderr]
	.B0_END_BLOCK_000011:
	.B0_END_BLOCK_000010:
	.B0_END_BLOCK_00008:
	mov r3, qword [r6+_B0_sys_write__ptr]
	add r3, 2
	mov r8, qword [r6+_B0_sys_write__size]
	lea r9, [r6+_B0_sys_write_buffer]
	mov r0, 0
	push r0
	push r6
	mov r6, r7
	and r7, -16
	sub r7, 20h
	call [WriteFile]
	add r7, 20h
	mov r7, r6
	pop r6
	pop r2
	ret
	mov r0, 0
	ret

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; End sys_write Function Code;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; echo_string Function Code ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

align 8
_B0_echo_string:
	push r1
	push r2
	push r3
	push r4
	push r5
	push r8
	push r9
	push r10
	push r11
	push r12
	push r13
	push r14
	push r15
	mov r1, qword [r6+_B0_echo_string_string]
	push r0
	push r6
	add r6, 010h
	mov [r6+00h], r1
	call _B0_strlen
	pop r6
	mov r3, r0
	pop r0
	mov r2, qword [r6+_B0_echo_string_handle]
	push r6
	add r6, 010h
	mov [r6+00h], r2
	mov [r6+08h], r1
	mov [r6+010h], r3
	call _B0_sys_write
	pop r6
	pop r15
	pop r14
	pop r13
	pop r12
	pop r11
	pop r10
	pop r9
	pop r8
	pop r5
	pop r4
	pop r3
	pop r2
	pop r1
	ret
	mov r0, 0
	ret

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; End echo_string Function Code;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; echo_hex Function Code ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

align 8
_B0_echo_hex:
	push r1
	push r2
	push r3
	push r4
	push r5
	push r8
	push r9
	push r10
	push r11
	push r12
	push r13
	push r14
	push r15
	lea r0, [r6+_B0_echo_hex_hex_string]
	mov r1, qword [r6+_B0_echo_hex_integer]
	push r6
	add r6, 0118h
	mov [r6+00h], r0
	mov [r6+08h], r1
	call _B0_itoah
	pop r6
	lea r0, [r6+_B0_echo_hex_hex_string]
	mov r1, qword [r6+_B0_echo_hex_handle]
	push r6
	add r6, 0118h
	mov [r6+00h], r1
	mov [r6+08h], r0
	call _B0_echo_string
	pop r6
	pop r15
	pop r14
	pop r13
	pop r12
	pop r11
	pop r10
	pop r9
	pop r8
	pop r5
	pop r4
	pop r3
	pop r2
	pop r1
	ret
	mov r0, 0
	ret

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; End echo_hex Function Code;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; itoah Function Code ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

align 8
_B0_itoah:
	push r1
	push r2
	push r3
	push r4
	push r5
	push r15
	mov r5, qword [r6+_B0_itoah_string]
	mov r0, qword [r6+_B0_itoah_value]
	xor r3, r3
	mov r2, 64
	mov r4, 57h
	mov r1, 48
	mov [r5+2], r1b
	add r5, 3
	test r2, r2
	je .B0_END_BLOCK_000016
	.B0_END_BLOCK_000015:
	sub r2, 4
	mov r1, r0
	shr r1, r2b
	and r1, 0fh
	mov r15, 48

			cmp r1, 09h
			cmova r15, r4	
			add r1, r15
	mov [r5], r1b
	add r5, 1
	add r3, 1
	test r2, r2
	jne .B0_END_BLOCK_000015
	.B0_END_BLOCK_000016:
	mov r1, 104
	mov [r5], r1b
	mov r5, qword [r6+_B0_itoah_string]
	add r3, 2
	mov [r5+1], r3b
	pop r15
	pop r5
	pop r4
	pop r3
	pop r2
	pop r1
	ret
	mov r0, 0
	ret

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; End itoah Function Code;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; itoa Function Code ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

align 8
_B0_itoa:
	push r1
	push r2
	push r3
	push r4
	push r5
	mov r5, qword [r6+_B0_itoa_dest_ptr]
	mov r0, qword [r6+_B0_itoa_value]
	mov r1, 10
	xor r2, r2
	xor r4, r4
	mov [r5], r2w
	add r5, 2
	cmp r0, r2
	jge .B0_END_BLOCK_000019
	neg r0
	mov r1, 45
	mov [r5], r1b
	add r5, 1
	mov r1, 10
	add r4, 1
	.B0_END_BLOCK_000019:
	push r6
	add r6, 010h
	mov [r6+00h], r0
	call _B0_itoa_puti2
	pop r6
	mov r5, qword [r6+_B0_itoa_dest_ptr]
	mov [r5+1], r4b
	mov r0, 0
	mov [r5+r4+2], r0
	pop r5
	pop r4
	pop r3
	pop r2
	pop r1
	mov r0, 0
	ret

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; End itoa Function Code;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; itoa_puti2 Function Code ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

align 8
_B0_itoa_puti2:
	xor r3, r3
	div r1
	add r3, 30h
	test r0, r0
	je .B0_END_BLOCK_000021
	push r3
	push r6
	add r6, 08h
	mov [r6+00h], r0
	call _B0_itoa_puti2
	pop r6
	pop r3
	.B0_END_BLOCK_000021:
	mov [r5], r3b
	add r5, 1
	add r4, 1
	mov r0, 0
	ret

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; End itoa_puti2 Function Code;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; echo_integer Function Code ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

align 8
_B0_echo_integer:
	push r1
	push r2
	push r3
	push r4
	push r5
	push r8
	push r9
	push r10
	push r11
	push r12
	push r13
	push r14
	push r15
	lea r0, [r6+_B0_echo_integer_int_string]
	mov r1, qword [r6+_B0_echo_integer_integer]
	push r6
	add r6, 0118h
	mov [r6+00h], r0
	mov [r6+08h], r1
	call _B0_itoa
	pop r6
	lea r0, [r6+_B0_echo_integer_int_string]
	mov r1, qword [r6+_B0_echo_integer_handle]
	push r6
	add r6, 0118h
	mov [r6+00h], r1
	mov [r6+08h], r0
	call _B0_echo_string
	pop r6
	pop r15
	pop r14
	pop r13
	pop r12
	pop r11
	pop r10
	pop r9
	pop r8
	pop r5
	pop r4
	pop r3
	pop r2
	pop r1
	ret
	mov r0, 0
	ret

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; End echo_integer Function Code;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; echo_character Function Code ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

align 8
_B0_echo_character:
	push r1
	push r2
	push r3
	push r4
	push r5
	push r8
	push r9
	push r10
	push r11
	push r12
	push r13
	push r14
	push r15
	mov r0, 0
	lea r1, [r6+_B0_echo_character_char_string]
	mov r2, qword [r6+_B0_echo_character_character]
	mov [r1], r2
	sub r1, 2
	mov r2, qword [r6+_B0_echo_character_handle]
	mov r3, 1
	push r6
	add r6, 020h
	mov [r6+00h], r2
	mov [r6+08h], r1
	mov [r6+010h], r3
	call _B0_sys_write
	pop r6
	pop r15
	pop r14
	pop r13
	pop r12
	pop r11
	pop r10
	pop r9
	pop r8
	pop r5
	pop r4
	pop r3
	pop r2
	pop r1
	ret
	mov r0, 0
	ret

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; End echo_character Function Code;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; SetArgCV Function Code ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

align 8
_B0_SetArgCV:
	push r1
	push r2
	push r3
	push r4
	push r5
	push r8
	push r9
	push r10
	push r11
	push r12
	push r13
	push r14
	push r15
	sub r7, 20h
	call [GetCommandLineW]
	add r7, 20h
	sub r7, 20h
	mov r2, r0
	lea r3, [_B0_nArgs]
	call [CommandLineToArgvW]
	add r7, 20h
	mov qword [_B0_szArglist], r0 
	lea r15, [_B0___argv_strings]
	mov r14, qword [_B0_szArglist]
	mov r13, qword [_B0_nArgs]
	mov r1, 0
	mov qword [_B0___argv+8*r1], r15 
	cmp r1, r13
	jae .B0_END_BLOCK_000026
	.B0_END_BLOCK_000025:
	mov r12, [r14+r1*8]
	mov r11, 0
	mov r11w, [r12]
	test r11, r11
	je .B0_END_BLOCK_000028
	.B0_END_BLOCK_000027:
	mov [r15], r11b
	add r15, 1
	mov [r15], dword 0
	add r12, 2
	mov r11, 0
	mov r11w, [r12]
	test r11, r11
	jne .B0_END_BLOCK_000027
	.B0_END_BLOCK_000028:
	add r1, 1
	add r15, 1
	mov qword [_B0___argv+8*r1], r15 
	cmp r1, r13
	jb .B0_END_BLOCK_000025
	.B0_END_BLOCK_000026:
	sub r7, 20h
	mov r2, qword [_B0_szArglist]
	call [LocalFree]
	add r7, 20h
	pop r15
	pop r14
	pop r13
	pop r12
	pop r11
	pop r10
	pop r9
	pop r8
	pop r5
	pop r4
	pop r3
	pop r2
	pop r1
	mov r4, qword [_B0_nArgs]
	lea r5, [_B0___argv]
	mov r0, 0
	ret

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; End SetArgCV Function Code;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; _fopen Function Code ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

align 8
_B0__fopen:
	push r1
	push r2
	push r3
	push r4
	push r5
	push r8
	push r9
	push r10
	push r11
	push r12
	push r13
	push r14
	push r15
	mov r2, qword [r6+_B0__fopen_acl]
	mov r3, 0
	mov r3b, [r2+2]
	mov r2, 119
	cmp r3, r2
	jne .B0_END_BLOCK_000030
	mov r3, -1073741824
	mov r10, 2
	jmp .B0_END_BLOCK_000031
	.B0_END_BLOCK_000030:
	mov r3, -2147483648
	mov r10, 3
	.B0_END_BLOCK_000031:
	mov r2, qword [r6+_B0__fopen_file2open]
	add r2, 2
	mov r8, 1
	mov r9, 0
	push r6
	mov r6, r7
	and r7, -16
	sub r7, 40h
	mov [r7+20h], r10
	mov r10, 128
	mov [r7+28h], r10
	mov r10, 0
	mov [r7+30h], r10
	call [CreateFileA]
	mov r1, -1
	cmp r0, r1
	jne .B0_END_BLOCK_000032
	mov r0, 0
	.B0_END_BLOCK_000032:
	mov r7, r6
	pop r6
	pop r15
	pop r14
	pop r13
	pop r12
	pop r11
	pop r10
	pop r9
	pop r8
	pop r5
	pop r4
	pop r3
	pop r2
	pop r1
	ret
	mov r0, 0
	ret

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; End _fopen Function Code;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; _fclose Function Code ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

align 8
_B0__fclose:
	push r1
	push r2
	push r3
	push r4
	push r5
	push r8
	push r9
	push r10
	push r11
	push r12
	push r13
	push r14
	push r15
	mov r2, qword [r6+_B0__fclose_handle]
	push r6
	mov r6, r7
	and r7, -16
	sub r7, 20h
	call [CloseHandle]
	mov r7, r6
	pop r6
	pop r15
	pop r14
	pop r13
	pop r12
	pop r11
	pop r10
	pop r9
	pop r8
	pop r5
	pop r4
	pop r3
	pop r2
	pop r1
	ret
	mov r0, 0
	ret

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; End _fclose Function Code;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; _fgetc Function Code ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

align 8
_B0__fgetc:
	push r1
	push r2
	push r3
	push r4
	push r5
	push r8
	push r9
	push r10
	push r11
	push r12
	push r13
	push r14
	push r15
	mov r2, qword [r6+_B0__fgetc_handle]
	lea r3, [r6+_B0__fgetc_buffer]
	mov r8, 1
	lea r9, [r6+_B0__fgetc_buffer2]
	mov r0, 0
	push r6
	mov r6, r7
	and r7, -16
	sub r7, 30h
	call [ReadFile]
	mov r7, r6
	pop r6
	test r0, r0
	je .B0_END_BLOCK_000035
	lea r2, [r6+_B0__fgetc_buffer2]
	mov r0, 0
	mov r0d, [r2]
	mov r1, 0
	cmp r1, r0
	jne .B0_END_BLOCK_000036
	mov r0, -1
	jmp .B0_END_BLOCK_000037
	.B0_END_BLOCK_000036:
	lea r2, [r6+_B0__fgetc_buffer]
	mov r0, 0
	mov r0b, [r2]
	.B0_END_BLOCK_000037:
	jmp .B0_END_BLOCK_000038
	.B0_END_BLOCK_000035:
	mov r0, -1
	.B0_END_BLOCK_000038:
	pop r15
	pop r14
	pop r13
	pop r12
	pop r11
	pop r10
	pop r9
	pop r8
	pop r5
	pop r4
	pop r3
	pop r2
	pop r1
	ret
	mov r0, 0
	ret

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; End _fgetc Function Code;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; _ftell Function Code ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

align 8
_B0__ftell:
	push r1
	push r2
	push r3
	push r4
	push r5
	push r8
	push r9
	push r10
	push r11
	push r12
	push r13
	push r14
	push r15
	mov r2, qword [r6+_B0__ftell_handle]
	mov r3, 0
	mov r8, 0
	mov r9, 1
	push r6
	mov r6, r7
	and r7, -16
	sub r7, 20h
	call [SetFilePointer]
	mov r7, r6
	pop r6
	pop r15
	pop r14
	pop r13
	pop r12
	pop r11
	pop r10
	pop r9
	pop r8
	pop r5
	pop r4
	pop r3
	pop r2
	pop r1
	ret
	mov r0, 0
	ret

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; End _ftell Function Code;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; main Function Code ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

align 8
_B0_main:
	push r6
	add r6, 018h
	call _B0___Init_Win64
	pop r6
	push r6
	add r6, 018h
	mov qword [r6+00h], 1
	push r0
	mov r0, B0_DynStr0
	mov qword [r6+08h], r0
	pop r0
	call _B0_echo_string
	pop r6
	push r6
	add r6, 018h
	call _B0_SetArgCV
	pop r6
	mov qword [_B0_pArgc], r4 
	mov qword [_B0_pArgv], r5 
	test r4, r4
	je .B0_END_BLOCK_000041
	push r6
	add r6, 018h
	mov qword [r6+00h], 1
	push r0
	mov r0, B0_DynStr1
	mov qword [r6+08h], r0
	pop r0
	call _B0_echo_string
	pop r6
	push r6
	add r6, 018h
	mov qword [r6+00h], 1
	mov [r6+08h], r4
	call _B0_echo_integer
	pop r6
	push r6
	add r6, 018h
	mov qword [r6+00h], 1
	push r0
	mov r0, B0_DynStr2
	mov qword [r6+08h], r0
	pop r0
	call _B0_echo_string
	pop r6
	push r6
	add r6, 018h
	mov qword [r6+00h], 1
	mov [r6+08h], r5
	call _B0_echo_integer
	pop r6
	push r6
	add r6, 018h
	mov qword [r6+00h], 1
	push r0
	mov r0, B0_DynStr3
	mov qword [r6+08h], r0
	pop r0
	call _B0_echo_string
	pop r6
	mov r1, 0
	cmp r4, r1
	jbe .B0_END_BLOCK_000043
	.B0_END_BLOCK_000042:
	push r6
	add r6, 018h
	mov qword [r6+00h], 1
	push r0
	mov r0, B0_DynStr4
	mov qword [r6+08h], r0
	pop r0
	call _B0_echo_string
	pop r6
	push r6
	add r6, 018h
	mov qword [r6+00h], 1
	mov [r6+08h], r1
	call _B0_echo_integer
	pop r6
	push r6
	add r6, 018h
	mov qword [r6+00h], 1
	push r0
	mov r0, B0_DynStr5
	mov qword [r6+08h], r0
	pop r0
	call _B0_echo_string
	pop r6
	mov r2, [r5+r1*8]
	sub r2, 2
	push r6
	add r6, 018h
	mov qword [r6+00h], 1
	mov [r6+08h], r2
	call _B0_echo_string
	pop r6
	push r6
	add r6, 018h
	mov qword [r6+00h], 1
	push r0
	mov r0, B0_DynStr6
	mov qword [r6+08h], r0
	pop r0
	call _B0_echo_string
	pop r6
	add r1, 1
	cmp r4, r1
	ja .B0_END_BLOCK_000042
	.B0_END_BLOCK_000043:
	jmp .B0_END_BLOCK_000044
	.B0_END_BLOCK_000041:
	push r6
	add r6, 018h
	mov qword [r6+00h], 1
	push r0
	mov r0, B0_DynStr7
	mov qword [r6+08h], r0
	pop r0
	call _B0_echo_string
	pop r6
	.B0_END_BLOCK_000044:
	push r6
	add r6, 018h
	mov qword [r6+00h], 1
	push r0
	mov r0, B0_DynStr8
	mov qword [r6+08h], r0
	pop r0
	call _B0_echo_string
	pop r6
	push r0
	push r6
	add r6, 018h
	push r0
	mov r0, B0_DynStr9
	mov qword [r6+00h], r0
	pop r0
	push r0
	mov r0, B0_DynStr10
	mov qword [r6+08h], r0
	pop r0
	call _B0__fopen
	pop r6
	mov r1, r0
	pop r0
	push r6
	add r6, 018h
	mov qword [r6+00h], 1
	push r0
	mov r0, B0_DynStr11
	mov qword [r6+08h], r0
	pop r0
	call _B0_echo_string
	pop r6
	push r6
	add r6, 018h
	mov qword [r6+00h], 1
	mov [r6+08h], r1
	call _B0_echo_integer
	pop r6
	push r6
	add r6, 018h
	mov qword [r6+00h], 1
	push r0
	mov r0, B0_DynStr12
	mov qword [r6+08h], r0
	pop r0
	call _B0_echo_string
	pop r6
	mov r2, -1
	test r1, r1
	je .B0_END_BLOCK_000045
	push r0
	push r6
	add r6, 018h
	mov [r6+00h], r1
	call _B0__fgetc
	pop r6
	mov r3, r0
	pop r0
	cmp r3, r2
	je .B0_END_BLOCK_000047
	.B0_END_BLOCK_000046:
	push r6
	add r6, 018h
	mov qword [r6+00h], 1
	mov [r6+08h], r3
	call _B0_echo_character
	pop r6
	push r0
	push r6
	add r6, 018h
	mov [r6+00h], r1
	call _B0__fgetc
	pop r6
	mov r3, r0
	pop r0
	cmp r3, r2
	jne .B0_END_BLOCK_000046
	.B0_END_BLOCK_000047:
	push r6
	add r6, 018h
	mov qword [r6+00h], 1
	push r0
	mov r0, B0_DynStr13
	mov qword [r6+08h], r0
	pop r0
	call _B0_echo_string
	pop r6
	push r6
	add r6, 018h
	mov [r6+00h], r1
	call _B0__fclose
	pop r6
	.B0_END_BLOCK_000045:
	mov r0, 0
	jmp B0_sys_exit
	mov r0, 0
	ret

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; End main Function Code;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


section '.idata' import data readable writeable

dd 0,0,0, RVA KERNEL32_name, RVA KERNEL32_table
dd 0,0,0, RVA USER32_name, RVA USER32_table
dd 0,0,0, RVA SHELL32_name, RVA SHELL32_table
dd 0,0,0,0,0

KERNEL32_table:
	GetCommandLineA dq RVA _GetCommandLineA
	GetCommandLineW dq RVA _GetCommandLineW
	GetEnvironmentVariable dq RVA _GetEnvironmentVariable
	GetStdHandle dq RVA _GetStdHandle
	GlobalAlloc dq RVA _GlobalAlloc
	CreateFileA dq RVA _CreateFileA
	WriteFile dq RVA _WriteFile
	SetFilePointer dq RVA _SetFilePointer
	GetTickCount dq RVA _GetTickCount
	LocalFree dq RVA _LocalFree
	CloseHandle dq RVA _CloseHandle
	DeleteFile dq RVA _DeleteFile
	ExitProcess dq RVA _ExitProcess
	ReadFile dq RVA _ReadFile
	dq 0

USER32_table:
	MessageBox dq RVA _MessageBox
	dq 0

SHELL32_table:
	CommandLineToArgvW dq RVA _CommandLineToArgvW
	dq 0

KERNEL32_name db 'KERNEL32.DLL',0
USER32_name db 'USER32.DLL',0
SHELL32_name db 'SHELL32.DLL',0

_GetCommandLineA dw 0
	db 'GetCommandLineA',0
_GetCommandLineW dw 0
	db 'GetCommandLineW',0
_GetEnvironmentVariable dw 0
	db 'GetEnvironmentVariableA',0
_GetStdHandle dw 0
	db 'GetStdHandle',0
_GlobalAlloc dw 0
	db 'GlobalAlloc',0
_CreateFileA dw 0
	db 'CreateFileA',0
_CommandLineToArgvW dw 0
	db 'CommandLineToArgvW',0
_WriteFile dw 0
	db 'WriteFile',0
_SetFilePointer dw 0
	db 'SetFilePointer',0
_MessageBox dw 0
	db 'MessageBoxA',0
_GetTickCount dw 0
	db 'GetTickCount',0
_LocalFree dw 0
	db 'LocalFree',0
_CloseHandle dw 0
	db 'CloseHandle',0
_DeleteFile dw 0
	db 'DeleteFileA',0
_ExitProcess dw 0
	db 'ExitProcess',0
_ReadFile dw 0
	db 'ReadFile',0




;EOF
