-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathArray_LoadItemsFromFile.asm
108 lines (94 loc) · 2.38 KB
/
Array_LoadItemsFromFile.asm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
;==============================================================================
;
; UASM64 Library
;
; https://github.com/mrfearless/UASM64-Library
;
;==============================================================================
.686
.MMX
.XMM
.x64
option casemap : none
IF @Platform EQ 1
option win64 : 11
ENDIF
option frame : auto
;GlobalAlloc PROTO uFlags:DWORD, qwBytes:QWORD
;GlobalFree PROTO pMem:QWORD
;
;IFNDEF GMEM_FIXED
;GMEM_FIXED EQU 0000h
;ENDIF
;
;includelib kernel32.lib
include UASM64.inc
.CODE
UASM64_ALIGN
;------------------------------------------------------------------------------
; Array_LoadItemsFromFile
;
; Create an array by loading a text file. Each line of the text file is set as
; a new item in the array.
;
; Parameters:
;
; * lpszFilename - filename to load and create an array from.
;
; Returns:
;
; A pointer to the newly created array, which is used with the other array
; functions, or 0 if an error occurred.
;
; Notes:
;
; This function as based on the MASM32 Library function: arrfile
;
; See Also:
;
; Array_LoadItemsFromMem, Array_SaveItemsToFile, Array_SaveItemsToMem
;
;------------------------------------------------------------------------------
Array_LoadItemsFromFile PROC FRAME USES RBX RCX lpszFilename:QWORD
LOCAL arr:QWORD
LOCAL hMem:QWORD
LOCAL flen:QWORD
LOCAL lcnt:QWORD
LOCAL pbuf:QWORD
LOCAL spos:QWORD
LOCAL void:QWORD
;push ebx
Invoke File_ReadFileToMemoryA, lpszFilename, Addr hMem, Addr flen
;Invoke InputFile, lpszFilename
;mov hMem, rax ; InputFile(file_name)
;mov flen, rcx
Invoke Text_LineCountExA, hMem, flen
;Invoke get_line_count, hMem, flen
mov lcnt, rax ; rv(get_line_count,hMem,flen)
Invoke Array_Create, lcnt
mov arr, rax ; arralloc$(lcnt)
Invoke Memory_Alloc, rax
;Invoke GlobalAlloc, GMEM_FIXED, rax
mov pbuf, rax ; alloc(flen)
mov spos, 0
mov rbx, 1
@@:
Invoke Text_ReadLineA, hMem, pbuf, spos
;Invoke readline, hMem, pbuf, spos
mov spos, rax ; rv(readline,hMem,pbuf,spos)
Invoke Array_ItemSetText, arr, rbx, pbuf
mov void, rax ; arrset$(arr,rbx,pbuf)
add rbx, 1
cmp rbx, lcnt
jle @B
Invoke Memory_Free, pbuf
Invoke Memory_Free, hMem
;Invoke GlobalFree, pbuf
;Invoke GlobalFree, hMem
;free pbuf
;free hMem
mov rax, arr
;pop ebx
ret
Array_LoadItemsFromFile ENDP
END