Code: Select all
ParseELFImage:
; Check for ELF Magic signature
mov ebx, dword [KERNELADDR]
mov eax, dword [ELFSignature]
cmp eax, ebx
jne FailureMagic
; Check for null data encoding
mov ebx, dword [KERNELADDR + 5]
cmp ebx, 0
je FailureData
; Check file size
; -- Needs work!!!!
xor eax, eax
xor ebx, ebx
mov bx, word [KERNELADDR + 40]
mov word [ImageSizeTest], bx
mov bx, word [KERNELADDR + 42]
mov ax, word [KERNELADDR + 44]
movzx eax, ax
movzx ebx, bx
mul ebx
add dword [ImageSizeTest], eax
xor eax, eax
xor ebx, ebx
mov bx, word [KERNELADDR + 46]
mov ax, word [KERNELADDR + 48]
movzx eax, ax
movzx ebx, bx
mul ebx
add dword [ImageSizeTest], eax
mov ebx, dword [ImageSizeTest]
mov eax, dword [ImageSize]
cmp ebx, eax
jge FailureSizes
It's the third test I do that fails. Using the ELF specification: http://www.skyfree.org/linux/references/ELF_Format.pdf (Search for 1-3), I add up the ELF Header size + (Program Header Size * Number of Program Headers) + (Section Header Size * Number of Section Headers). Now I am aware that this isn't the full size of the file. But if all this combined is greater than ImageSize, then there is a major problem. Which is why I do jge, ebx being the combined size of all the headers. FailureSizes is just to print an error, so I know what failed.
The size of ImageSize is correct for sure. I make sure to increment ecx during the loading of the executable. Then I move ecx into ImageSize after the file has been loaded. KERNELADDR is:
Code: Select all
%define KERNELADDR 0x100000