Created
June 15, 2011 15:25
-
-
Save 7shi/1027330 to your computer and use it in GitHub Desktop.
セクションサイズからアドレスとファイルオフセットを求める
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
Module Module1 | |
Const ImageBase = &H400000 | |
Const SectionAlignment = 4096, FileAlignment = 512 | |
Sub Main() | |
Dim Sections = {New With {.Name = "Header", .Size = 500}, | |
New With {.Name = ".text", .Size = 5000}, | |
New With {.Name = ".data", .Size = 10000}, | |
New With {.Name = ".idata", .Size = 2000}} | |
Dim rva = 0, off = 0 | |
For Each sect In Sections | |
Console.WriteLine("{0,-8} Size={1:x8}, Addr={2:x8}, RVA={3:x8}, File Offset={4:x8}", | |
sect.Name, sect.Size, ImageBase + rva, rva, off) | |
rva += Align(sect.Size, SectionAlignment) | |
off += Align(sect.Size, FileAlignment) | |
Next | |
Console.ReadLine() | |
End Sub | |
Function Align%(v%, a%) | |
Return Int((v + a - 1) / a) * a | |
End Function | |
End Module |
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
Header Size=000001f4, Addr=00400000, RVA=00000000, File Offset=00000000 | |
.text Size=00001388, Addr=00401000, RVA=00001000, File Offset=00000200 | |
.data Size=00002710, Addr=00403000, RVA=00003000, File Offset=00001600 | |
.idata Size=000007d0, Addr=00406000, RVA=00006000, File Offset=00003e00 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment