Guest User

VBA sessionstore.js URL extractor

a guest
Jun 3rd, 2014
456
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Option Explicit
  2. Sub FindURLs()
  3. ' v0.2 2014-06-03 Jefferson Scher (Word 2010) NO WARRANTIES!
  4. ' Try to extract URLs from sessionstore file opened as a document
  5. Dim strTemp As String, arrWindows() As String, lngWindows As Long
  6. ' Get session history for open windows, discard closed windows
  7. strTemp = Split(ActiveDocument.Content.Text, ",""_closedWindows"":[")(0)
  8. ' Create an array of windows
  9. arrWindows = Split(strTemp, "{""tabs"":[")
  10. ' Create an output document
  11. Dim docNew As Word.Document
  12. Set docNew = Application.Documents.Add
  13. docNew.PageSetup.Orientation = wdOrientLandscape
  14. docNew.Content.InsertAfter "URLs from sessionstore"
  15. ' Iterate over windows
  16. Dim arrEntries() As String, lngEntries As Long, arrURLs() As String, lngURLs As Long, strURL As String
  17. For lngWindows = 1 To UBound(arrWindows)
  18.     docNew.Content.InsertAfter vbCrLf & "Window " & lngWindows & ":"
  19.     ' Discard closed tabs and identify history entries
  20.    strTemp = Split(arrWindows(lngWindows), ",""_closedTabs"":[")(0)
  21.     arrEntries = Split(strTemp, "{""entries"":[")
  22.     ' Iterate over tabs
  23.    For lngEntries = 1 To UBound(arrEntries)
  24.         docNew.Content.InsertAfter vbCrLf & vbTab & "Tab " & lngEntries & " History (oldest to newest):"
  25.         ' Discard children URLs (are these iframes??) and create array of URLs (tab history)
  26.        strTemp = Split(arrEntries(lngEntries), ",""children"":[")(0)
  27.         arrURLs = Split(strTemp, "{""url"":""")
  28.         For lngURLs = 1 To UBound(arrURLs)
  29.             strURL = Left(arrURLs(lngURLs), InStr(1, arrURLs(lngURLs), """") - 1)
  30.             docNew.Content.InsertAfter vbCrLf & vbTab & vbTab & strURL
  31.         Next
  32.     Next
  33. Next
  34. End Sub
RAW Paste Data