From 90df1b9764ef4f5e15316a1aed7a98220ba15422 Mon Sep 17 00:00:00 2001 From: RamiLego4Game Date: Thu, 10 May 2018 12:02:08 +0300 Subject: [PATCH] Reached the PE optional header --- icon-changer.lua | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/icon-changer.lua b/icon-changer.lua index d2ce057..602fc4f 100644 --- a/icon-changer.lua +++ b/icon-changer.lua @@ -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