dump.ml 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. open PeDataDebug;;
  2. open PeData;;
  3. open PeReader;;
  4. open Printf;;
  5. open IlData;;
  6. open IlMetaTools;;
  7. open IlMetaDebug;;
  8. let main () =
  9. if Array.length Sys.argv <> 2 then
  10. print_endline "Usage: dump <exe-path>"
  11. else begin
  12. let r = create_r (open_in Sys.argv.(1)) PMap.empty in
  13. let ctx = read r in
  14. let pe = ctx.pe_header in
  15. print_endline (coff_header_s pe.pe_coff_header);
  16. print_endline (pe_header_s pe);
  17. let idata = read_idata ctx in
  18. List.iter (fun t -> print_endline (idata_table_s t)) idata;
  19. let clr_header = read_clr_header ctx in
  20. print_endline (clr_header_s (clr_header));
  21. let cache = IlMetaReader.create_cache () in
  22. let meta = IlMetaReader.read_meta_tables ctx clr_header cache in
  23. Hashtbl.iter (fun path _ ->
  24. print_endline ("\n\nclass " ^ path_s path ^ ": ");
  25. let cls = convert_class meta path in
  26. List.iter (fun t -> printf "%d: <%s> " t.tnumber (if t.tname = None then "_" else Option.get t.tname)) cls.ctypes;
  27. printf "\n\tis nested: %s - %s\n" (string_of_bool (cls.cenclosing <> None)) (if cls.cenclosing = None then "None" else path_s (Option.get cls.cenclosing));
  28. print_endline "\tfields:";
  29. List.iter (fun f -> printf "\t\t%s : %s\n" f.fname (ilsig_s f.fsig.ssig)) cls.cfields;
  30. print_endline "\tmethods:";
  31. List.iter (fun m -> printf "\t\t%s : %s\n" m.mname (ilsig_s m.msig.ssig)) cls.cmethods;
  32. print_endline "\tprops:";
  33. List.iter (fun p -> printf "\t\t%s : %s\n" p.pname (ilsig_s p.psig.ssig)) cls.cprops;
  34. ) meta.il_typedefs
  35. end;;
  36. main()