Last active
November 3, 2021 07:31
-
-
Save akkuman/6915a250eab8063e861a0b0b275f41f4 to your computer and use it in GitHub Desktop.
[golang实现的pe的rva2foa] #pe #golang
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"debug/pe" | |
"fmt" | |
"math/big" | |
"os" | |
) | |
func RVA2FOA(pefile *pe.File, rva uint32) (foa uint32, err error) { | |
for i := 0; i < int(pefile.NumberOfSections); i++ { | |
if rva >= pefile.Sections[i].VirtualAddress && rva <= pefile.Sections[i].VirtualAddress+pefile.Sections[i].Size { | |
foa = rva - pefile.Sections[i].VirtualAddress + pefile.Sections[i].Offset | |
return | |
} | |
} | |
err = fmt.Errorf("Could not find the foa for rva") | |
return | |
} | |
func main() { | |
pefile, err := pe.Open(os.Args[1]) | |
if err != nil { | |
fmt.Println(err) | |
return | |
} | |
rva := new(big.Int) | |
rva.SetString(os.Args[2], 16) | |
foa, err := RVA2FOA(pefile, uint32(rva.Uint64())) | |
fmt.Printf("FOA: 0x%x", foa) | |
} | |
/* | |
usage: main.exe target.exe RVAAddress | |
example: | |
> main.exe 360zip.exe 113a98 | |
FOA: 0x10da98 | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment