-
Notifications
You must be signed in to change notification settings - Fork 0
/
functions64.inc
804 lines (725 loc) · 20.3 KB
/
functions64.inc
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
;
;Include file for the functions library
;
%macro PUSHREGS 0
push rax
push rbx
push rcx
push rdx
push rsi
push rdi
push r8
push r9
push r10
push r11
push r12
push r13
push r14
push r15
%endmacro
%macro POPREGS 0
pop r15
pop r14
pop r13
pop r12
pop r11
pop r10
pop r9
pop r8
pop rdi
pop rsi
pop rdx
pop rcx
pop rbx
pop rax
%endmacro
;Swap one String with another
;Stack contents:
; Address of destination string
; Address of source string
;Example Usage:
; push string1Address
; push string2Address
; push length
; call StringSwap
;
extern StringSwap
;Compare one String with another
; If source is less than destination, rax = -1
; If source is greater than destination, rax = 1
; If source is equal to destination, rax = 0
;Stack contents:
; Address of destination string
; Address of source string
;Example Usage:
; push string1Address
; push string2Address
; call StringCompare
;
extern StringCompare
;Copy one String to another
;Stack contents:
; Address of destination string
; Address of source string
;Example Usage:
; push string1Address
; push string2Address
; call StringCopy
;
extern StringCopy
;Print the data for a current function/procedure's stack frame
;Notes:
; This function assumes you have created a valid stack frame
; Call this function after the stack frame is created an all
; local function variables have been allocated and before you use
; the stack for any other purposes
;Stack contents:
; None
;Example Usage:
; call PrintStackFrame
;
extern PrintStackFrame
;Print a tab character to stdout
;Stack contents:
; None
;Example Usage:
; call PrintTab
;
extern PrintTab
;Print all Quad Word values found in an array
;Stack Contents:
; Address of the Array (Stack)
; Number of items in the array
;Example Usage:
; push ArrayToPrint
; push NumerOfEntriesInArray
; call PrintQWordArray
extern PrintQWordArray
;Print all Quad Word values found in an array in Decimal Format
;Stack Contents:
; Address of the Array (Stack)
; Number of items in the array
;Example Usage:
; push ArrayToPrint
; push NumerOfEntriesInArray
; call PrintQWordArrayDec
extern PrintQWordArrayDec
;Print all Quad Word signed values found in an array in Decimal Format
;Stack Contents:
; Address of the Array
; Number of items in the array
;Example Usage:
; push ArrayToPrint
; push NumerOfEntriesInArray
; call PrintSQWordArrayDec
extern PrintSQWordArrayDec
;Print all byte values found in an array in Hex format
;Stack Contents:
; Address of the Array
; Number of items in the array
;Example Usage:
; push ArrayToPrint
; push NumerOfEntriesInArray
; call PrintByteArray
extern PrintByteArray
;Print all byte values found in an array in Decimal format
;Stack Contents:
; Address of the Array
; Number of items in the array
;Example Usage:
; push ArrayToPrint
; push NumerOfEntriesInArray
; call PrintByteArrayDec
extern PrintByteArrayDec
;Print all signed byte values found in an array in Decimal format
;Stack Contents:
; Address of the Array
; Number of items in the array
;Example Usage:
; push ArrayToPrint
; push NumerOfEntriesInArray
; call PrintSByteArrayDec
extern PrintSByteArrayDec
;Print all word values found in an array in Hex format
;Stack Contents:
; Address of the Array
; Number of items in the array
;Example Usage:
; push ArrayToPrint
; push NumerOfEntriesInArray
; call PrintWordArray
extern PrintWordArray
;Print all word values found in an array in Decimal format
;Stack Contents:
; Address of the Array
; Number of items in the array
;Example Usage:
; push ArrayToPrint
; push NumerOfEntriesInArray
; call PrintWordArrayDec
extern PrintWordArrayDec
;Print all signed word values found in an array in Decimal format
;Stack Contents:
; Address of the Array
; Number of items in the array
;Example Usage:
; push ArrayToPrint
; push NumerOfEntriesInArray
; call PrintSWordArrayDec
extern PrintSWordArrayDec
;Print all Double Word values found in an array in Hex format
;Stack Contents:
; Address of the Array
; Number of items in the array
;Example Usage:
; push ArrayToPrint
; push NumerOfEntriesInArray
; call PrintDWordArray
extern PrintDWordArray
;Print all Double Word values found in an array in Decimal format
;Stack Contents:
; Address of the Array
; Number of items in the array
;Example Usage:
; push ArrayToPrint
; push NumerOfEntriesInArray
; call PrintDWordArrayDec
extern PrintDWordArrayDec
;Print all signed Double Word values found in an array in Decimal format
;Stack Contents:
; Address of the Array (Stack)
; Number of items in the array
;Example Usage:
; push ArrayToPrint
; push NumerOfEntriesInArray
; call PrintSDWordArrayDec
extern PrintSDWordArrayDec
;Print a string with an ending 00h delimiter to the console
;Stack Contents:
; Address of the String (Stack)
;Example Usage:
; push stringVariable
; call PrintString
extern PrintString
;Get the length of a null-terminated string. Can be used for functions
;which need a string length and don't search for null-terminated characters
;Stack Contents:
; Address of the String (Stack)
;Return Value:
; RAX will equal the length of the string
;Example Usage:
; push stringVariable
; call StringLength
extern StringLength
;Print a space to the console
;Stack Contents:
; None
;Example Usage:
; call PrintSpace
extern PrintSpace
;Print 'x' number of spaces
;Stack Contents:
; the total spaces to print
;Example Usage:
; push DWORD 5
; call PrintSpaces
extern PrintSpaces
;Print a comma to the console
;Stack Contents:
; None
;Example Usage:
; call PrintComma
extern PrintComma
;Print a new line to the console
;Stack Contents:
; None
;Example Usage:
; call Printendl
extern Printendl
;Print a string which is not null terminated
;Stack contents:
; The Address of the string to print
; The length of the string to print
;Example Usage:
; push stringVariable
; push stringVariable.len
; call PrintText
extern PrintText
;Convert and then print a 64bit hex number
;Stack contents:
; Value to Convert to an Ascii String
;Example Usage:
; push QWORD [quadWordVariable]
; call Print64bitNumHex
extern Print64bitNumHex
;Convert and then print a 64bit octal number
;Stack contents:
; Value to Convert to an Ascii String
;Example Usage:
; push QWORD [quadWordVariable]
; call Print64bitNumOctal
extern Print64bitNumOctal
;Convert and then print a 64bit decimal number
;Stack contents:
; Value to Convert to an Ascii String
;Example Usage:
; push QWORD [quadwordvariable]
; call Print64bitNumDecimal
extern Print64bitNumDecimal
;Convert and then print a signed 64bit decimal number
;Stack contents:
; Value to Convert to an Ascii String
;Example Usage:
; push QWORD [quadwordvariable]
; call Print64bitNumDecimal
extern Print64bitSNumDecimal
;Convert and then print a 64bit binary number
;Stack contents:
; Value to Convert to an Ascii String
;Example Usage:
; push QWORD [quadwordvariable]
; call Print64bitNumBinary
extern Print64bitNumBinary
;Print a full 64bit binary number including leading zeros
;Stack contents:
; Value to Convert to an Ascii String
;Example Usage:
; push QWORD [quadwordvariable]
; call Print64bitFullBinary
extern Print64bitFullBinary
;This routine prints a string to the screen left justified
;Stack contents:
; Address of the string [ebp + 16]
; Number of characters it will be justified within [ebp + 24]
;Example Usage:
; push stringVariable
; push QWORD 80
; call PrintLeft
extern PrintLeft
;This routine prints a string to the screen right justified
;Stack contents:
; Address of the string [ebp + 16]
; Number of characters it will be justified within [ebp + 24]
;Example Usage:
; push stringVariable
; push QWORD 80
; call PrintRight
extern PrintRight
;This routine prints a string to the screen center justified
;Stack contents:
; Address of the string [ebp + 16]
; Number of characters it will be justified within [ebp + 24]
;Example Usage:
; push stringVariable
; push QWORD 80
; call PrintCenter
extern PrintCenter
;Print all 64bit Registers to the screen
;Stack contents:
; None
;Example Usage:
; call PrintRegisters
extern PrintRegisters
;Call the necessary interrupt with the necessary register values to read data from the keyboard
;Stack Contents:
; Address of keyboard buffer
; Size of the keyboard buffer
;Return:
; Rax will contain the number of characters the user input
;Example Usage:
; push readbuffer
; push readbuffer.len
; call ReadText
extern ReadText
;Input UnSigned Int
;This function will let the user input an integer returned into the RAX register
;Arguments: None
;Return: rax will contain the usigned ingeter
; Carry flag will be set if invalid integer was input
;Example Usage:
; call InputInt
; Note: eax will contain the value of the unsigned integer entered
; jnc validIntegerInput
; Otherwise, an invalid integer was input
extern InputUInt
;Input Signed Int
;This function will let the user input a signed integer and put the value
;into the RAX register.
;Arguments: None
;Return: eax will contain the usigned ingeter
; Carry flag will be set if invalid integer was input
;Example Usage:
; call InputSInt
; Note: eax will contain the value of the signed integer entered
; jnc validIntegerInput
; Otherwise, an invalid integer was input
extern InputSInt
;Call the necessary interrupt with the necessary register values to read data from the keyboard
;Stack Contents:
; Address of the string to print
; Address of keyboard buffer
; Size of the keyboard buffer
;Return:
; Rax will contain the number of characters input
;Example Usage:
; push inputPromptVariable
; push keyboardBufferVariable
; push keyboardBufferVariable.len ;This is the maximum size of the buffer
; call ReadTextWPrompt
extern ReadTextWPrompt
;Print a Quad-word floating point number
;Stack Contents:
; The number of fractional digits to print
; The floating point number to print
;Return:
; None
;Example Usage:
; push numberToPrint
; push [fractionalDigits]
; call PrintQWFloat
extern PrintQWFloat
;Print a Double-word floating point number with scientific notation
;This version uses the integer extraction power of the FPU instead of moving bits
; around to extract the exponent and left/right mantissa's making this a
; much easier and shorter algorithm
;Stack Contents:
; The number of fractional digits to print
; The floating point number to print
;Return:
; None
;Example Usage:
; push [numberToPrint]
; push [fractionalDigits]
; call PrintQWFloatSN
extern PrintQWFloatSN
;Input a Floating Point Number
;This function will let the user input a string, then it will check it to make sure it
;is a valid floating point number. It will then convert the ASCII string into a QWORD
;and return that value in the RAX register.
;Stack Contents:
; None
;Return: RAX and ST(0) will contain the number
; Carry flag will be set if invalid binary number was input
;Example Usage:
; call InputFloat
; jnc ValidFloatLabel
; otherwise, a problem occured - print an error message
extern InputFloat
;Input Binary Number
;This function will let the user input a string, then it will check it to make sure it
;is a binary string. It will then convert the ASCII string into a DWORD and return
;that value in the RAX register.
;Stack Contents:
; None
;Return: rax will contain the numeric binary value
; Carry flag will be set if invalid binary number was input
;Example Usage:
; call InputBin
; jnc ValidBinLabel
; otherwise, a problem occured - print an error message
extern InputBin
;This function will let the user input a string, then it will check it to make sure it
;is a hexidecimal string. It will then convert the ASCII string into a DWORD and return
;that value in the EAX register.
;Stack Contents:
; None
;Return: rax will contain the numeric hexidecimal value
; Carry flag will be set if invalid hex number was input
;Example Usage:
; call InputHex
; jnc ValidHexLabel
; otherwise, a problem occured - print an error message
extern InputHex
;Allocate some memory (x bytes) and return the high address to RAX
;Stack Contents:
; Number of BYTES to add to memory
;Return: RAX will contain the new high memory address
;Example Usage:
; push QWORD 1024 ;increase memory by 1024 bytes
; call AllocateBytes
extern AllocateBytes
;Free some memory (x bytes) and return the high address to RAX
;Stack Contents:
; Number of BYTES to remove from memory
;Return: RAX will contain the new high memory address
;Example Usage:
; push QWORD 1024 ;reduce memory by 1024 bytes
; call FreeBytes
extern FreeBytes
;Print all of the floating point registers ST0 - ST7
;Stack Contents:
; None
;Return: None
;Example Usage:
; call PrintFloatingRegisters
extern PrintFloatingRegisters
;Print a 64-bit floating point number
;Stack Contents:
; The floating point number
;Return: None
;Example Usage:
; call Print64bitFloatBinary
extern Print64bitFloatBinary
;Set the carry flag if the floating poing number pushed onto the Stack
;is a +NAN, -NAN, +Infinity or -Infinity
;Stack Contents:
; QWORD Floating Point number (Stack)
;Return: Carry Flag Set if NAN, Clear if OK
;Example Usage
; push QWORD [floatingVariable]
; call IsNAN
extern IsNAN
;Simple xor encryption/decryption of a string using a user entered key
;Stack Contents:
; String address to encrypt/decrypt (Stack rbp + 48)
; Length of the string to encrypt (Stack rbp + 40)
; string address to be used as a key (Stack rbp + 32)
; integer value indicating the length of the key (Stack rbp + 24)
; string address where the encrypted/decrypted data should go (Stack rbp + 16)
;Return: Total bytes encrypted in eax
;Example Usage
; push stringaddress
; push lengthofstring
; push keystringaddress
; push lengthofkey
; push resultaddress
; call EncryptString
extern EncryptString
;Clears the keyboard buffer until \n or null are encountered
;Stack contents:
; None
;Example Usage:
; call ClearKBuffer
extern ClearKBuffer
;An Internal function used to get the system time in hours
;Stack Contents:
; None
;Return: RAX will have the current Hour
;Example Usage
; call GetCurrentHour
extern GetCurrentHour
;An Internal function used to get the system time in minutes
;Stack Contents:
; None
;Return: RAX will have the current minute
;Example Usage
; call GetCurrentMinute
extern GetCurrentMinute
;An Internal function used to get the system time in seconds
;Stack Contents:
; None
;Return: RAX will have the current seconds
;Example Usage
; call GetCurrentSecond
extern GetCurrentSecond
;An Internal function used to get the system year
;Stack Contents:
; None
;Return: RAX will have the current year
;Example Usage
; call GetCurrentYear
extern GetCurrentYear
;An Internal function used to get the system month
;Stack Contents:
; None
;Return: RAX will have the current month
;Example Usage
; call GetCurrentMonth
extern GetCurrentMonth
;An Internal function used to get the system day
;Stack Contents:
; None
;Return: RAX will have the current day
;Example Usage
; call GetCurrentDay
extern GetCurrentDay
;An Internal function used to get the system time hours, minutes, seconds
;Stack Contents:
; None
;Return: None
;Example Usage
; call GetSystemTime
extern GetSystemTime
;Print the time in the format hh:mm:ss
;Stack Contents:
; None
;Return: None
;Example Usage
; call PrintSystemTime
extern PrintSystemTime
;Print the date in the format mm/dd/yyyy
;Stack Contents:
; None
;Return: None
;Example Usage
; call PrintSystemDateEng
extern PrintSystemDateEng
;Print the date in the format yyyy/mm/dd
;Stack Contents:
; None
;Return: None
;Example Usage
; call PrintSystemDateEuro
extern PrintSystemDateEuro
;Convert and then return in a byte array a64-but number in decimal format
;Stack contents:
; Value to Convert to an Ascii String
; Address of byte array to contain the result
;Return Value:
; rax = Number of characters returned
;Example Usage:
; push QWORD [quadwordvariable]
; push stringbuffer
; call ToString64bitNumDecimal
extern ToString64bitNumDecimal
;Convert and then return in a byte array a 64bit signed number in decimal format
;Stack contents:
; Value to Convert to an Ascii String
; Address of byte array to contain the result
;Return Value:
; rax = Number of characters returned
;Example Usage:
; push QWORD [quadwordvariable]
; push stringbuffer
; call ToString64bitSNumDecimal
extern ToString64bitSNumDecimal
;Get the system date in English format and return to the calling function in th array
; provided
;Stack contents:
; Address of byte array to contain the result
;Return Value:
; rax = Number of characters returned
;Example Usage:
; push stringbuffer
; call GetEngDateString
extern GetEngDateString
;Get the system date in European format and return to the calling function in th array
; provided
;Stack contents:
; Address of byte array to contain the result
;Return Value:
; rax = Number of characters returned
;Example Usage:
; push stringbuffer
; call GetEuroDateString
extern GetEuroDateString
;Get the system time and return to the calling function in th array
; provided
;Stack contents:
; Address of byte array to contain the result
;Return Value:
; rax = Number of characters returned
;Example Usage:
; push stringbuffer
; call GetTimeString
extern GetTimeString
;Get a random number from the CPU
;Stack contents:
; The maximum value of the random number
; Signed = 1, Unsigned = 0
;Return Value:
; rax = Random number value
;Example Usage:
; push QWORD 200 ;Will create a random number no greater than 200
; push QWORD 1 ;1 = signed, 0 = uinsigned
; call GetRandomInt
extern GetRandomInt
;Calculate the Variance from an array of numbers returning an integer result
;Stack contents:
; Address of sample array of Quad words
; The number of samples to process
;Return Value:
; rax = Calculated Variance
;Example Usage:
; push sampleArray ;Address of the array of numeric samples
; push 10 ;process 10 of the numbers in the array
; call CalcVariance
extern CalcVariance
;Calculate the Variance from an array of numbers returning a floating point number
;Stack contents:
; Address of sample array of Quad words
; The number of samples to process
;Return Value:
; rax = Calculated Variance
;Example Usage:
; push sampleArray ;Address of the array of numeric samples
; push 10 ;process 10 of the numbers in the array
; call CalcVariance
extern CalcVarianceFloat
;Calculate the Standard Deviation from an array of numbers
;Stack contents:
; Address of sample array of Quad words
; The number of samples to process
;Return Value:
; rax = Calculated Standard Deviation
;Example Usage:
; push sampleArray ;Address of the array of numeric samples
; push 10 ;process 10 of the numbers in the array
; call CalcStdDev
extern CalcStdDev
;Calculate the Mean from an array of numbers
;Stack contents:
; Address of sample array of Quad words
; The number of samples to process
;Return Value:
; rax = Calculated Mean
;Example Usage:
; push sampleArray ;Address of the array of numeric samples
; push 10 ;process 10 of the numbers in the array
; call CalcMean
extern CalcMean
;Fills an array with random quad values
;Stack contents:
; Address of array of Quad words
; The number of samples to process
; Maximum value of the random number(s)
; Signed = 1, Unsigned = 0
;Return Value:
; Nothing
;Example Usage:
; push sampleArray ;Address of the array of numeric samples
; push 10 ;process 10 of the numbers in the array
; push 500 ;The maximum random value should be 500
; push 0 ;Unsigned only
; call RandomArray
extern RandomArray
;Calculate the sum from an array of numbers
;Stack contents:
; Address of sample array of Quad words
; The number of samples to process
;Return Value:
; rax = Calculated Sum
;Example Usage:
; push sampleArray ;Address of the array of numeric samples
; push 10 ;process 10 of the numbers in the array
; call CalcSumArray
extern CalcSumArray
;Calculate the GCD of two numbers passed to this function
;Stack contents:
; Integer #1
; Integer #2
;Return Value:
; rax = Calculated Greatest Common Denominator
;Example Usage:
; push 15 ;Our first number
; push 5 ;Our second number
; call CalcGCD
extern CalcGCD
;Calculate the factorial of a number passed to this function
;Stack contents:
; Integer number to factor
;Return Value:
; rax = Calculated Factorial of the argument passed in
;Example Usage:
; push 15 ;The number fo factor - 15 in this case
; call CalcFactorial
extern CalcFactorial
;Calculate the factorial of a number passed to this function
;Stack contents:
; Integer number to factor
;Return Value:
; rax = Calculated Factorial of the argument passed in floating point format
;Example Usage:
; push 15 ;The number fo factor - 15 in this case
; call CalcFactorialFloat
extern CalcFactorialFloat