fork download
  1. open System
  2.  
  3. let ImageBase = 0x400000
  4. let SectionAlignment = 4096
  5. let FileAlignment = 512
  6.  
  7. let Align v a = ((v + a - 1) / a) * a
  8.  
  9. type Section = { Name:string; Size:int }
  10.  
  11. let Sections = [ { Name = "Header"; Size = 500}
  12. { Name = ".text" ; Size = 5000}
  13. { Name = ".data" ; Size = 10000}
  14. { Name = ".idata"; Size = 2000} ]
  15.  
  16. let mutable rva = 0
  17. let mutable off = 0
  18. for section in Sections do
  19. printfn "%-8s Size=%08x, Addr=%08x, RVA=%08x, File Offset=%08x"
  20. section.Name section.Size (ImageBase + rva) rva off
  21. rva <- Align section.Size SectionAlignment
  22. off <- Align section.Size FileAlignment
  23.  
  24. ignore <| Console.ReadLine()
Success #stdin #stdout 0.13s 12144KB
stdin
Standard input is empty
stdout
Header   Size=000001f4, Addr=00400000, RVA=00000000, File Offset=00000000
.text    Size=00001388, Addr=00401000, RVA=00001000, File Offset=00000200
.data    Size=00002710, Addr=00402000, RVA=00002000, File Offset=00001400
.idata   Size=000007d0, Addr=00403000, RVA=00003000, File Offset=00002800