Reached the PE optional header

This commit is contained in:
RamiLego4Game
2018-05-10 12:02:08 +03:00
parent 8a1618c034
commit 90df1b9764

View File

@@ -12,7 +12,7 @@ local bor,band,lshift,rshift = bit.bor,bit.band,bit.lshift,bit.rshift
--==Internal Functions==-- --==Internal Functions==--
local function readNumber(str,bigEndian) local function decodeNumber(str,bigEndian)
local num = 0 local num = 0
if bigEndian then str = str:reverse() end if bigEndian then str = str:reverse() end
@@ -36,6 +36,26 @@ function icapi.extractIcon(exeFile)
--DOS Header --DOS Header
if exeFile:read(2) ~= "MZ" then return error("This is not an executable file !") end if exeFile:read(2) ~= "MZ" then return error("This is not an executable file !") end
exeFile:read(58) --Skip 58 bytes
local PEHeaderOffset = decodeNumber(exeFile:read(4),true) --Offset to the 'PE\0\0' signature relative to the beginning of the file
exeFile:seek(PEHeaderOffset) --Seek into the PE Header
--PE Header
if exeFile:read(4) ~= "PE\0\0" then return error("Corrupted executable file !") end
--COFF Header
exeFile:read(2) --Skip Machine.
local NumberOfSections = decodeNumber(exeFile:read(2))
exeFile:read(12) --Skip 3 long values (12 bytes).
local SizeOfOptionalHeader = decodeNumber(exeFile:read(2))
exeFile:read(2) --Skip a short value (2 bytes) (Characteristics).
end end