/// <summary> Attempt to set a swf as a filter /// for the file list that we create /// </summary> public virtual bool setSwfFilter(String swfName) { // look for a match in our list bool worked = false; if (swfName == null) { m_swfFilter = null; worked = true; } else { SwfInfo[] swfs = Swfs; for (int i = 0; i < swfs.Length; i++) { SwfInfo e = swfs[i]; if (e != null && nameOfSwf(e).ToUpper().Equals(swfName.ToUpper())) { worked = true; m_swfFilter = e; break; } } } // reload if it worked if (worked) { reloadCache(); } return(worked); }
// locate the name of the swf public static String nameOfSwf(SwfInfo e) { int at = -1; String name = e.Url; if ((at = e.Url.LastIndexOf('/')) > -1) { name = e.Url.Substring(at + 1); } if ((at = e.Url.LastIndexOf('\\')) > -1) { name = e.Url.Substring(at + 1); } else if ((at = e.Path.LastIndexOf('\\')) > -1) { name = e.Path.Substring(at + 1); } else if ((at = e.Path.LastIndexOf('/')) > -1) { name = e.Path.Substring(at + 1); } // now rip off any trailing ? options at = name.LastIndexOf('?'); name = (at > -1)?name.Substring(0, (at) - (0)):name; return(name); }
public void SwfInfo_parse_no_tags() { SwfInfo swf; using (var stream = TestSwf_NoTags()) { swf = new SwfInfo(stream); } Assert.AreEqual(0, swf.Tags.Length); }
public static ActionLocation outputAssembly(DebugCLI cli, SwfInfo info, ActionLocation lStart, ActionLocation lEnd) { // now make sure our actions lists are the same (i.e we haven't spanned past one tag) if (lStart.actions != lEnd.actions) { lEnd.at = lStart.actions.size() - 1; } Disassembler.disassemble(lStart.actions, lStart.pool, lStart.at, lEnd.at, new StreamWriter(cli.Out.BaseStream, System.Text.Encoding.Default)); return(lEnd); }
public void SwfInfo_parse_empty_tag() { SwfInfo swf; using (var stream = TestSwf_EmptyTag()) { swf = new SwfInfo(stream); } Assert.AreEqual(1, swf.Tags.Length); Assert.AreEqual(4, swf.Tags[0].Code); Assert.AreEqual(0, swf.Tags[0].Length); }
public void SwfInfo_parse_non_empty_tag() { SwfInfo swf; using (var stream = TestSwf_NonEmptyTag()) { swf = new SwfInfo(stream); } Assert.AreEqual(1, swf.Tags.Length); Assert.AreEqual(4, swf.Tags[0].Code); Assert.AreEqual(8, swf.Tags[0].Length); Assert.AreEqual(8, ((GenericTag)swf.Tags[0]).Data.Length); }
/// <summary> Given a SourceFile locate the swf which it came from</summary> public virtual SwfInfo swfForFile(SourceFile f) { // We use the id to determine which swf this source files resides in int id = f.Id; SwfInfo info = null; SwfInfo[] swfs = Swfs; for (int i = 0; (i < swfs.Length && (info == null)); i++) { if (swfs[i] != null && swfs[i].containsSource(f)) { info = swfs[i]; } } return(info); }
// locate the name of the swf public static String shortNameOfSwf(SwfInfo e) { String name = nameOfSwf(e); // now strip off any leading path int at = -1; if ((at = name.LastIndexOf('/')) > -1) { name = name.Substring(at + 1); } else if ((at = name.LastIndexOf('\\')) > -1) { name = name.Substring(at + 1); } return(name); }
public void SwfInfo_parse_header() { SwfInfo swf; using (var stream = TestSwf_HeaderOnly()) { swf = new SwfInfo(stream); } Assert.AreEqual(SwfHeaderSignature.FWS, swf.Header.Signature); Assert.AreEqual(9, swf.Header.Version); Assert.AreEqual(19, swf.Header.FileLength); Assert.AreEqual(0, swf.Header.FrameSize.XMin); Assert.AreEqual(1024, swf.Header.FrameSize.XMax); Assert.AreEqual(0, swf.Header.FrameSize.YMin); Assert.AreEqual(768, swf.Header.FrameSize.YMax); Assert.AreEqual(3, swf.Header.FrameRate); Assert.AreEqual(1, swf.Header.FrameCount); }
/// <summary> Given the URL of a specfic swf determine /// if there is a file within it that appears /// to be the same as the given source file /// </summary> /// <param name="f"> /// </param> /// <returns> /// </returns> public virtual SourceFile similarFileInSwf(SwfInfo info, SourceFile f) { SourceFile hit = null; SourceFile[] files = info.getSourceList(m_session); if (!info.ProcessingComplete) { throw new InProgressException(); } for (int i = 0; i < files.Length; i++) { if (filesMatch(f, files[i])) { hit = files[i]; } } return(hit); }
// Extended low level break information public static void appendBreakInfo(DebugCLI cli, System.Text.StringBuilder sb, bool includeFault) { Session session = cli.Session; FileInfoCache fileInfo = cli.FileCache; int reason = session.suspendReason(); int offset = ((PlayerSession)session).SuspendOffset; int index = ((PlayerSession)session).SuspendActionIndex; SwfInfo info = null; try { info = fileInfo.Swfs[index]; } catch (IndexOutOfRangeException) { } if (info != null) { System.Collections.IDictionary args = new System.Collections.Hashtable(); args["swfName"] = FileInfoCache.nameOfSwf(info); //$NON-NLS-1$ sb.Append(LocalizationManager.getLocalizedTextString("key35", args)); //$NON-NLS-1$ sb.Append(' '); } System.Collections.IDictionary args2 = new System.Collections.Hashtable(); System.Text.StringBuilder sb2 = new System.Text.StringBuilder(); args2["address"] = "0x" + FieldFormat.formatLongToHex(sb2, offset, 8) + " (" + offset + ")"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ sb.Append(LocalizationManager.getLocalizedTextString("atAddress", args2)); //$NON-NLS-1$ if (includeFault) { args2 = new System.Collections.Hashtable(); System.Text.StringBuilder reasonBuffer = new System.Text.StringBuilder(); cli.appendReason(reasonBuffer, reason); args2["fault"] = reasonBuffer.ToString(); //$NON-NLS-1$ sb.Append(' '); sb.Append(LocalizationManager.getLocalizedTextString("haltedDueToFault", args2)); //$NON-NLS-1$ } }
internal virtual bool loadSwfFiles(System.Collections.ArrayList ar, SwfInfo swf) { bool worked = true; try { // @todo should we include unloaded swfs? SourceFile[] files = swf.getSourceList(m_session); SupportClass.IListSupport.EnsureCapacity(ar, ar.Count + files.Length); // add each file to our global source file IntMap and our list for (int i = 0; i < files.Length; i++) { putFile(files[i]); ar.Add(files[i]); } } catch (InProgressException) { // can't load this one, its not ready yet worked = false; } return(worked); }
/// <summary> Given the URL of a specfic swf determine /// if there is a file within it that appears /// to be the same as the given source file /// </summary> /// <param name="f"> /// </param> /// <returns> /// </returns> public virtual SourceFile similarFileInSwf(SwfInfo info, SourceFile f) { SourceFile hit = null; SourceFile[] files = info.getSourceList(m_session); if (!info.ProcessingComplete) throw new InProgressException(); for (int i = 0; i < files.Length; i++) { if (filesMatch(f, files[i])) hit = files[i]; } return hit; }
// locate the name of the swf public static String nameOfSwf(SwfInfo e) { int at = - 1; String name = e.Url; if ((at = e.Url.LastIndexOf('/')) > - 1) name = e.Url.Substring(at + 1); if ((at = e.Url.LastIndexOf('\\')) > - 1) name = e.Url.Substring(at + 1); else if ((at = e.Path.LastIndexOf('\\')) > - 1) name = e.Path.Substring(at + 1); else if ((at = e.Path.LastIndexOf('/')) > - 1) name = e.Path.Substring(at + 1); // now rip off any trailing ? options at = name.LastIndexOf('?'); name = (at > - 1)?name.Substring(0, (at) - (0)):name; return name; }
public static void doDisassemble(DebugCLI cli) { /* currentXXX may NOT be invalid! */ int currentModule = cli.propertyGet(DebugCLI.LIST_MODULE); int currentLine = cli.propertyGet(DebugCLI.LIST_LINE); String arg1 = null; int module1 = currentModule; int line1 = currentLine; String arg2 = null; int line2 = currentLine; bool functionNamed = false; int numLines = 0; try { FileInfoCache fileInfo = cli.FileCache; Session session = cli.Session; if (cli.hasMoreTokens()) { arg1 = cli.nextToken(); if (arg1.Equals("-")) //$NON-NLS-1$ { // move back one line line1 = line2 = line1 - 1; } else { int[] result = cli.parseLocationArg(currentModule, currentLine, arg1); module1 = result[0]; line2 = line1 = result[1]; functionNamed = (result[2] == 0)?false:true; if (cli.hasMoreTokens()) { arg2 = cli.nextToken(); line2 = cli.parseLineArg(module1, arg2); } } } else { // since no parms test for valid location if none use players concept of where we stopped if (fileInfo.getFile(currentModule) == null) { //here we simply use the players concept of suspsend DSuspendInfo info = ((PlayerSession)session).SuspendInfo; int at = info.Offset; int which = info.ActionIndex; int until = info.NextOffset; if (info.Reason == SuspendReason.Unknown) { throw new SuspendedException(); } SwfInfo swf = fileInfo.Swfs[which]; outputAssembly(cli, (DSwfInfo)swf, at, until); throw new AmbiguousException(LocalizationManager.getLocalizedTextString("key27")); //$NON-NLS-1$ } } /* * Check for a few error conditions, otherwise we'll write a listing! */ if (cli.hasMoreTokens()) { cli.err(LocalizationManager.getLocalizedTextString("key28")); //$NON-NLS-1$ } else { SourceFile file = fileInfo.getFile(module1); numLines = file.LineCount; // pressing return is ok, otherwise throw the exception if (line1 > numLines && arg1 != null) { throw new IndexOutOfRangeException(); } /* if no arg2 then user list a single line */ if (arg2 == null) { line2 = line1; } /* adjust our range of lines to ensure we conform */ if (line1 < 1) { /* shrink line 1, grow line2 */ line2 += -(line1 - 1); line1 = 1; } if (line2 > numLines) { line2 = numLines; } // System.out.println("1="+module1+":"+line1+",2="+module2+":"+line2+",num="+numLines+",half="+half); /* nothing to display */ if (line1 > line2) { throw new IndexOutOfRangeException(); } /* now dump the mixed source / assembly */ // now lets find which swf this in DSwfInfo swf = (DSwfInfo)fileInfo.swfForFile(file); ActionLocation lStart = null; ActionLocation lEnd = null; if (swf == null) { System.Collections.IDictionary args = new System.Collections.Hashtable(); args["arg3"] = file.Name; //$NON-NLS-1$ cli.err(LocalizationManager.getLocalizedTextString("key29", args)); //$NON-NLS-1$ } else if (functionNamed) { // if we name a function just dump the whole thing without source. int offset = file.getOffsetForLine(line1); lStart = swf.locate(offset); if (lStart.function == null) { cli.err(LocalizationManager.getLocalizedTextString("key30")); } //$NON-NLS-1$ else { // create a psudeo action list from which to disasemble the function ActionList al = new ActionList(true); al.setActionOffset(0, lStart.function); lStart.actions = al; lStart.at = 0; lEnd = new ActionLocation(); lEnd.actions = al; lEnd.at = 0; outputAssembly(cli, swf, lStart, lEnd); } } else { ActionLocation lastEnd = null; for (int i = line1; i <= line2; i++) { int offset = file.getOffsetForLine(i); // locate the action list associated with this of the swf if (offset != 0) { // get the starting point and try to locate a nice ending lStart = swf.locate(offset); lEnd = swf.locateSourceLineEnd(lStart); // now see if we skipped some assembly between source lines if (lastEnd != null) { lastEnd.at++; // point our pseudo start to the next action // new actions list so attempt to find the end of source in the old actions list if (lastEnd.actions != lStart.actions && lastEnd.actions.size() != lastEnd.at) { String atString = lastEnd.actions.getOffset(lastEnd.at).ToString("X"); System.Collections.IDictionary args = new System.Collections.Hashtable(); args["arg4"] = atString; //$NON-NLS-1$ cli.output(LocalizationManager.getLocalizedTextString("key31", args)); //$NON-NLS-1$ // we are missing some of the dissassembly, so back up a bit and dump it out ActionLocation gapEnd = swf.locateSourceLineEnd(lastEnd); outputAssembly(cli, swf, lastEnd, gapEnd); } else if (lastEnd.at < lStart.at) { // same action list but we skipped some instructions ActionLocation gapEnd = new ActionLocation(lStart); gapEnd.at--; outputAssembly(cli, swf, lastEnd, gapEnd); } } lastEnd = lEnd; } // dump source cli.outputSource(module1, i, file.getLine(i)); // obtain the offset, locate it in the swf if (offset != 0) { outputAssembly(cli, swf, lStart, lEnd); } } /* save away valid context */ cli.propertyPut(DebugCLI.LIST_MODULE, module1); cli.propertyPut(DebugCLI.LIST_LINE, line2 + 1); // add one cli.m_repeatLine = "disassemble"; /* allow repeated listing by typing CR */ //$NON-NLS-1$ } } } catch (IndexOutOfRangeException) { String name = "#" + module1; //$NON-NLS-1$ System.Collections.IDictionary args = new System.Collections.Hashtable(); args["arg5"] = Convert.ToString(line1); //$NON-NLS-1$ args["arg6"] = name; //$NON-NLS-1$ args["arg7"] = Convert.ToString(numLines); //$NON-NLS-1$ cli.err(LocalizationManager.getLocalizedTextString("key32", args)); //$NON-NLS-1$ } catch (AmbiguousException ae) { cli.err(ae.Message); } catch (NullReferenceException) { cli.err(LocalizationManager.getLocalizedTextString("key33")); //$NON-NLS-1$ } catch (FormatException pe) { cli.err(pe.Message); } catch (NoMatchException nme) { cli.err(nme.Message); } catch (SuspendedException) { cli.err(LocalizationManager.getLocalizedTextString("key34")); //$NON-NLS-1$ } }
internal virtual bool loadSwfFiles(System.Collections.ArrayList ar, SwfInfo swf) { bool worked = true; try { // @todo should we include unloaded swfs? SourceFile[] files = swf.getSourceList(m_session); SupportClass.IListSupport.EnsureCapacity(ar, ar.Count + files.Length); // add each file to our global source file IntMap and our list for (int i = 0; i < files.Length; i++) { putFile(files[i]); ar.Add(files[i]); } } catch (InProgressException) { // can't load this one, its not ready yet worked = false; } return worked; }
/// <summary> Attempt to set a swf as a filter /// for the file list that we create /// </summary> public virtual bool setSwfFilter(String swfName) { // look for a match in our list bool worked = false; if (swfName == null) { m_swfFilter = null; worked = true; } else { SwfInfo[] swfs = Swfs; for (int i = 0; i < swfs.Length; i++) { SwfInfo e = swfs[i]; if (e != null && nameOfSwf(e).ToUpper().Equals(swfName.ToUpper())) { worked = true; m_swfFilter = e; break; } } } // reload if it worked if (worked) reloadCache(); return worked; }
/// <summary> Enable a breakpoint for a particular swf if the sourceFile /// is available in that swf. /// </summary> /// <param name="swf">if null, then set the breakpoint in the given source file /// otherwise try to locate a matching source file in given swf. /// </param> /// <param name="f">Source file. /// </param> /// <param name="line">Line number in file. /// </param> /// <returns> null if the swf does not contain this source file /// </returns> internal virtual Location findAndEnableBreak(SwfInfo swf, SourceFile f, int line) { int fileId = f.Id; if (swf != null) { SourceFile sameFile = m_fileInfo.similarFileInSwf(swf, f); if (sameFile != null) fileId = sameFile.Id; else fileId = - 1; } Location l = (fileId > - 1)?breakEnableRequest(fileId, line):null; return l; }
// locate the name of the swf public static String shortNameOfSwf(SwfInfo e) { String name = nameOfSwf(e); // now strip off any leading path int at = - 1; if ((at = name.LastIndexOf('/')) > - 1) name = name.Substring(at + 1); else if ((at = name.LastIndexOf('\\')) > - 1) name = name.Substring(at + 1); return name; }
public static ActionLocation outputAssembly(DebugCLI cli, SwfInfo info, ActionLocation lStart, ActionLocation lEnd) { // now make sure our actions lists are the same (i.e we haven't spanned past one tag) if (lStart.actions != lEnd.actions) lEnd.at = lStart.actions.size() - 1; Disassembler.disassemble(lStart.actions, lStart.pool, lStart.at, lEnd.at, new StreamWriter(cli.Out.BaseStream, System.Text.Encoding.Default)); return lEnd; }
private void commonUpdateBreakpoints(List <BreakPointInfo> breakpoints, Dictionary <BreakPointInfo, Location> breakpointLocations, IsolateSession i_Session) { Dictionary <string, int> files = new Dictionary <string, int>(); foreach (BreakPointInfo bp in breakpoints) { if (!breakpointLocations.ContainsKey(bp)) { if (!bp.IsDeleted && bp.IsEnabled) { if (!files.ContainsKey(bp.FileFullPath)) { files.Add(bp.FileFullPath, 0); } } } } int nFiles = files.Count; if (nFiles > 0) { // reverse loop to take latest loded swf first, and ignore old swf. SwfInfo[] swfInfo = (i_Session != null) ? i_Session.getSwfs() : m_Session.getSwfs(); for (int swfC = swfInfo.Length - 1; swfC >= 0; swfC--) { SwfInfo swf = swfInfo[swfC]; if (swf == null) { continue; } try { foreach (SourceFile src in swf.getSourceList(m_Session)) { String localPath = PluginMain.debugManager.GetLocalPath(src); if (localPath != null && files.ContainsKey(localPath) && files[localPath] == 0) { files[localPath] = src.getId(); nFiles--; if (nFiles == 0) { break; } } } } catch (InProgressException) { } if (nFiles == 0) { break; } } } foreach (BreakPointInfo bp in breakpoints) { if (!breakpointLocations.ContainsKey(bp)) { if (bp.IsEnabled && !bp.IsDeleted) { if (files.ContainsKey(bp.FileFullPath) && files[bp.FileFullPath] != 0) { Location l = (i_Session != null) ? i_Session.setBreakpoint(files[bp.FileFullPath], bp.Line + 1) : m_Session.setBreakpoint(files[bp.FileFullPath], bp.Line + 1); if (l != null) { breakpointLocations.Add(bp, l); } } } } else { if (bp.IsDeleted || !bp.IsEnabled) { // todo, i_Session does not have a clearBreakpoint method, m_Session clears them all. optimize out extra loops m_Session.clearBreakpoint(breakpointLocations[bp]); breakpointLocations.Remove(bp); } } } }
public void UpdateBreakpoints(List <BreakPointInfo> breakpoints) { Dictionary <string, int> files = new Dictionary <string, int>(); foreach (BreakPointInfo bp in breakpoints) { if (bp.Location == null) { if (!bp.IsDeleted && bp.IsEnabled) { if (!files.ContainsKey(bp.FileFullPath)) { files.Add(bp.FileFullPath, 0); } } } } int nFiles = files.Count; if (nFiles > 0) { // reverse loop to take latest loded swf first, and ignore old swf. SwfInfo[] swfInfo = m_Session.getSwfs(); for (int swfC = swfInfo.Length - 1; swfC >= 0; swfC--) { SwfInfo swf = swfInfo[swfC]; if (swf == null) { continue; } try { foreach (SourceFile src in swf.getSourceList(m_Session)) { String localPath = PluginMain.debugManager.GetLocalPath(src); if (localPath != null && files.ContainsKey(localPath) && files[localPath] == 0) { files[localPath] = src.getId(); nFiles--; if (nFiles == 0) { break; } } } } catch (InProgressException) { } if (nFiles == 0) { break; } } } foreach (BreakPointInfo bp in breakpoints) { if (bp.Location == null) { if (bp.IsEnabled && !bp.IsDeleted) { if (files.ContainsKey(bp.FileFullPath) && files[bp.FileFullPath] != 0) { bp.Location = m_Session.setBreakpoint(files[bp.FileFullPath], bp.Line + 1); } } } else { if (bp.IsDeleted || !bp.IsEnabled) { m_Session.clearBreakpoint(bp.Location); bp.Location = null; } } } }