News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

Read PE file

Started by Miniloserchamp, May 07, 2021, 08:58:38 PM

Previous topic - Next topic

Miniloserchamp

Hello, I've been stuck trying to get the value of e_Ifanew within an PE file so that I can get to the optional header. The problem is that when I try do mov ebx,[eax + 03Ch]ebx becomes 0x0? I've started to think the way I am going about this is completely wrong, any help would be appreciated! And also sorry if I explained this poorly. Thanks.


include \masm32\include\masm32rt.inc

.data
FileName db "C:\Users\64211\Desktop\test\worker.exe"

.code
start:
    mov eax, [offset FileName]
    mov ebx, [eax+03ch] ;e_Ifanew
   
    exit
end start

hutch--

Hi champ, you normally use the structures to access parts of a PE header.

jj2007

#2
Welcome to the Forum :thup:

include \masm32\MasmBasic\MasmBasic.inc
  Init
  Let esi=FileRead$("MyFavouriteGame.exe")
  Inkey Str$("The value is %i", [esi.IMAGE_DOS_HEADER.e_lfanew])
EndOfCode


Output: The value is 128

Miniloserchamp

Alright thanks, I'll give it another crack when my laptop charges