public static Library GetLibraryFromDisk(string filepath) { Library l = new Library(); // PEParser p = new PEParser(filepath); return l; }
private void load_library_tracefile() { LibraryViewModel global_library_list = (LibraryViewModel)this.FindResource("library_view_model"); // Clear the model global_library_list.Model.Clear(); try { using (FileStream fs = new FileStream(logfile_name, FileMode.Open)) { using (StreamReader sr = new StreamReader(fs)) { while (!sr.EndOfStream) { // Create a new library object for this line Library l = new Library(); string line = sr.ReadLine().Trim(); // make sure this is a library line if(line.Contains("[LIB]") == false) continue; string[] kvpairs = line.Split('|'); uint start_address = 0; uint end_address = 0; foreach (string kv in kvpairs) { if (kv == "") continue; // Split on the first colon string[] members = kv.Split(new char[] { ':' }, 2, StringSplitOptions.RemoveEmptyEntries); if(members.Length == 1 && kv.Contains("[LIB]")) { // drop the header continue; } else if (members.Length != 2) { Debug.WriteLine("Key-Value pair causing problems: " + kv); continue; } string key = members[0].Trim(); string value = members[1].Trim(); uint entry_address = 0; switch (key) { case "Name": // Library name l.Library_name = value; break; case "Strt": // Address loaded to, may be different than on disk, due to ASLR uint start_address_parsed; if (UInt32.TryParse(value, NumberStyles.HexNumber, CultureInfo.InvariantCulture, out start_address_parsed)) { l.Address_execution = start_address_parsed; start_address = start_address_parsed; } else Debug.WriteLine("Couldn't parse start address " + value); break; case "High": // Address loaded to, may be different than on disk, due to ASLR uint end_address_parsed; if (UInt32.TryParse(value, NumberStyles.HexNumber, CultureInfo.InvariantCulture, out end_address_parsed)) end_address = end_address_parsed; else Debug.WriteLine("Couldn't parse end address " + value); break; case "Enty": // Address loaded to, may be different than on disk, due to ASLR uint entry_address_parsed; if (UInt32.TryParse(value, NumberStyles.HexNumber, CultureInfo.InvariantCulture, out entry_address_parsed)) entry_address = entry_address_parsed; else Debug.WriteLine("Couldn't parse entry address " + value); break; case "Low": break; case "Mapd": break; case "Type": break; case "Msg": // defaut informational, non-relevant data portion continue; default: Debug.WriteLine("Key " + key + " not handled."); break; } } if (end_address == 0 || start_address == 0) { // Debug.WriteLine("Start or end address is empty."); continue; } else l.Size_execution = end_address - start_address; // Add the library to the model. Make sure its not already in there though (in case it was loaded, unloaded, and reloaded) bool already_exists = false; foreach(Library library_iterator in global_library_list.Model) { if(library_iterator.Library_name == l.Library_name) { already_exists = true; Debug.WriteLine("Library already inside list. Stopping"); } } if(!already_exists) global_library_list.Model.Add(l); } } } } catch(FileNotFoundException ex) { Debug.WriteLine("Could not load libray file: " + logfile_name); throw new FileNotFoundException("Could not load libray file: " + logfile_name); } }