mirror of
https://github.com/TangentFoxy/love-pe.git
synced 2025-07-28 02:02:16 +00:00
Reached the PE optional header
This commit is contained in:
@@ -12,7 +12,7 @@ local bor,band,lshift,rshift = bit.bor,bit.band,bit.lshift,bit.rshift
|
||||
|
||||
--==Internal Functions==--
|
||||
|
||||
local function readNumber(str,bigEndian)
|
||||
local function decodeNumber(str,bigEndian)
|
||||
local num = 0
|
||||
|
||||
if bigEndian then str = str:reverse() end
|
||||
@@ -36,6 +36,26 @@ function icapi.extractIcon(exeFile)
|
||||
--DOS Header
|
||||
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
|
||||
|
||||
|
Reference in New Issue
Block a user