SHARE
TWEET

Untitled

a guest Feb 24th, 2020 86 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. module TraceConverter =
  2.     type TraceBlock () =
  3.         member val Position = "" with get, set
  4.         member val Command = "" with get, set
  5.         member val Argument = "" with get, set
  6.         member val Registers = new Dictionary<string, string> () with get, set
  7.         member val Flags = new Dictionary<string, string> () with get, set
  8.         member val Stack = "" with get, set
  9.         member this.TryGetRegister (data : string) =
  10.             match this.Registers.TryGetValue data with
  11.                 | true, v ->
  12.                     try Int32.Parse(v, Globalization.NumberStyles.AllowHexSpecifier)
  13.                     with | exn -> 0
  14.                 | false, _ ->
  15.                     try Int32.Parse(data, Globalization.NumberStyles.AllowHexSpecifier)
  16.                     with | exn -> 0
  17.         member this.TryGetAddress : string =
  18.             let parsed = Regex.Match(this.Argument, @"\[.+\]")
  19.             if not parsed.Success then
  20.                 ""
  21.             else
  22.                 let mutable sum = 0
  23.                 let mutable ans = ""
  24.                 let clean = parsed.Value.Replace("[", "").Replace("]", "")
  25.                 let unsignedMember = Regex.Match(clean, @"^\w+")
  26.                 let captures = Regex.Matches(clean, @"[+,-]\w+")
  27.                 if unsignedMember.Success then
  28.                     let pnum = this.TryGetRegister unsignedMember.Value
  29.                     sum <- sum + pnum
  30.                 for cap in captures do
  31.                     let mutable IsNegative = 1
  32.                     if cap.Value.StartsWith('-') then
  33.                         IsNegative <- -IsNegative
  34.                     let pnum = this.TryGetRegister(cap.Value.TrimStart([|'+'; '-'|]))
  35.                     sum <- sum + pnum*IsNegative
  36.                 ans <- String.Format("{0:X}", sum)
  37.                 while ans.Length < 4 do ans <- "0"+ans
  38.                 ans
  39.            
  40.     type TraceBlockS () =
  41.         member val Id = -1 with get, set
  42.         member val Position = "" with get, set
  43.         member val MachineCode = "" with get, set
  44.         member val Command = "" with get, set
  45.         member val Argument = "" with get, set  
  46.  
  47. module ConverterHelper =
  48.     let ConvertToTrace (raw : List<string>) : byte array =
  49.         let transformed = raw.Skip(3).TakeWhile(fun line -> not (line.Contains "*** End of TRACE buffer ***"))
  50.         let traceBlocks = new List<IEnumerable<string>>()
  51.         for i in [0..((transformed.Count()/4)-1)] do
  52.             traceBlocks.Add(transformed.Skip(4*i).Take(4))
  53.         use ep = new ExcelPackage() in (
  54.             let ws = ep.Workbook.Worksheets.Add("TraceTable")
  55.             let mutable tCounter = 2
  56.             TableHelper.WriteTraceHeaders ws;
  57.             for b in traceBlocks do
  58.                 tCounter <- tCounter + 1
  59.                 let tb = TableHelper.ReadTraceBlock(b)
  60.                 TableHelper.WriteTraceLine(ws, tb, tCounter)
  61.             let prevVal =
  62.                 try Int32.Parse(ws.Cells.["A"+ (string) tCounter].Value.ToString(), Globalization.NumberStyles.AllowHexSpecifier) with
  63.                 | _ -> 0
  64.             let mutable lastPos = String.Format("{0:X}", prevVal+1)
  65.             while lastPos.Length < 4 do lastPos <- "0" + lastPos
  66.             ws.Cells.["G" + (string) tCounter].Value <- lastPos
  67.             ep.GetAsByteArray()
  68.         )
  69.     let ConvertToCode (raw : List<string>) : byte array =
  70.         let transofrmed = raw.Skip(3).TakeWhile(fun line -> not (line.Contains "*** End of TRACE buffer ***"))
  71.         use ep = new ExcelPackage() in (
  72.             let ws = ep.Workbook.Worksheets.Add("CodeTable")
  73.             let ul = new SortedList<int, TraceConverter.TraceBlockS>()
  74.             TableHelper.WriteCodeHeaders ws
  75.             for line in transofrmed do
  76.                 let tbs = TableHelper.ReadCodeLine(line)
  77.                 ul.[tbs.Id] <- tbs
  78.             let mutable tc = 1
  79.             for kvp in ul do
  80.                 tc <- tc + 1
  81.                 TableHelper.WriteCodeLine ws kvp.Value tc
  82.             ep.GetAsByteArray()
  83.         )
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top