you mean you want to search for a hex pattern in an arbitrary file using your own code either in python or c ?
have you considered using regex or grep to satisfy your needs ?
there are certain things you should be aware of
1) file offsets will not be equal to virtual offsets
2) even if you manage to map the file you may have to deal with aslr
2) you need to brush up your understanding of RVA ,VA , File Offset,File Alignment Versus Section Alignment etc
here is a sample grep demo (notice the similarity in the last 5 bytes )
:\>grep -obaP "\x48\x8b\x45\xa8\x48\x8d\x1c\x02\x48\x8b\x45\xc8" nmap
2821223:H<E"H?∟☻H<EE
:\>printf "%x\n" 2821223
2b0c67
or python demo
source
D:\>cat nmap.py
import re
fin = open("d:/nmap" , "rb")
dat = fin.read()
fin.close()
pat = re.search("\x48\x8b\x45\xa8\x48\x8d\x1c\x02\x48\x8b\x45\xc8",dat)
offset = hex(pat.start())
print (offset)
result
D:\>python nmap.py
0x2b0c67
now that you know how to find offset you can use any hex editor to print the bytes
here is an xxd demo
D:\>xxd -l 32 -g 1 -s 0x2b0c67 nmap
02b0c67: 48 8b 45 a8 48 8d 1c 02 48 8b 45 c8 48 89 c7 e8 H.E.H...H.E.H...
02b0c77: a3 d7 ff ff 48 89 c2 48 8b 45 c0 48 01 d0 48 39 ....H..H.E.H..H9
you can simply use binascii to print the bytes at an offset in python as below
D:\>type nmap.py
import re
import binascii
fin = open("d:/nmap" , "rb")
dat = fin.read()
pat = re.search("\x48\x8b\x45\xa8\x48\x8d\x1c\x02\x48\x8b\x45\xc8",dat)
offset = hex(pat.start())
print (offset)
print ( binascii.hexlify(dat[pat.start():pat.start()+16]))
fin.close()
D:\>
D:\>python nmap.py
0x2b0c67
488b45a8488d1c02488b45c84889c7e8