public static void doInit(pipeBehavior ps, string home) { //pipe1 = pipe1In; currentFunction = null; lineVector = new Vector3[10000]; zeroLine(); GameObject memoryObject = GameObject.Find("Memory1"); memoryScript = (memory)memoryObject.GetComponent(typeof(memory)); memoryRegions = new List <memory> (); memoryRegions.Add(memoryScript); //camera = GameObject.Find ("Main Camera"); if (controlLine != null) { VectorLine.Destroy(ref controlLine); } controlLine = new VectorLine("myLines", lineVector, flowColor, null, 0.5f, LineType.Continuous); controlLine.maxDrawIndex = 0; lineElement = 0; pipeScript = ps; if (pipeScript == null) { Debug.Log("pipeScript is null"); } pipe1 = pipeScript.getPipe("pipe"); breakpoints = new List <long> (); StreamReader reader = null; if (System.IO.File.Exists(home + "/breakpoints.txt")) { reader = new StreamReader(home + "/breakpoints.txt"); Debug.Log("Found breakpoints"); } else { Debug.Log("No breakpoint file in " + home); } if (reader != null) { string line; using (reader) { while ((line = reader.ReadLine()) != null) { long value = long.Parse(line, System.Globalization.NumberStyles.HexNumber); Debug.Log("add breakpoint at " + value.ToString("x")); breakpoints.Add(value); } } } clockLabelString = "0"; currentCycleString = "0"; numInstructions = 0; currentClock = 0; startClock = 0; updateClock(0); }
// for a given function, look at all higher level functions and identify those in the current call chain. public bool validateCall(functionDatabase.functionItem fi) { float newY = fi.y; bool retval = true; for (int i = 0; i < functionDatabase.length(); i++) { functionDatabase.functionItem tmpf = functionDatabase.getFunction(functionDatabase.getFunctionAddress(i)); if (tmpf.y >= newY) { //if(tmpf.callStack.Count > 0){ // Debug.Log("validateCall called "+fi.name+" level "+fi.y+" but "+tmpf.name+" has been called at level "+tmpf.level); //retval = false; //} } } return(retval); }
/* * Parse an instruction and perform the associated command */ public static string doInstruct(string line) { var parts = line.Split(); numInstructions++; //Debug.Log ("line: " + line); string command = null; try{ currentClock = long.Parse(parts[0], System.Globalization.NumberStyles.HexNumber); command = parts [2]; eipLabel = "EIP: 0x" + parts [1]; }catch (System.FormatException fe) { if (parts[0] == "break") { command = "break"; } else { Debug.Log("manageControl doInstruct could not parse clock from line " + line); Debug.Break(); return("error"); } } updateClock(currentClock); //Debug.Log ("start doInstruct command is " + command); uint address; uint source; uint destination; int count; Vector3 globalPoint; Vector3 pos; functionDatabase.functionItem newFunction = null; memory sourceRegion; memory destinationRegion; //newFunction = null; // hack to init thisMatrix //Matrix4x4 thisMatrix = transform.localToWorldMatrix; address = 0; if (command != "accept" && command != "break") { try{ address = uint.Parse(parts[4], System.Globalization.NumberStyles.HexNumber); }catch (System.Exception) { Debug.Log("crap at line " + line); } } int block = 0; switch (command) { case startup.GOTO: case "return": case "start": case "call": if (parts.Length < 6) { Debug.Log("manageControl error parsing operation, no block found in " + line); //Debug.Break(); return("error"); } block = int.Parse(parts [5]); if (address == 0) { Debug.Log("no address for line: " + line); //Debug.Break(); } break; } //Debug.Log ("line is "+line); //if(command == GOTO){ // // Debug.Log("newFunction now is "+newFunction.name); //} switch (command) { case "start": startClock = currentClock; newFunction = functionDatabase.getFunction(address); pos = newFunction.go.transform.position; pos.z = funForwardRunning; newFunction.go.transform.position = pos; currentPoint = newFunction.script.getVertexPosition(block); lineVector[lineElement] = currentPoint; controlLine.maxDrawIndex = 0; controlLine.drawEnd = 0; newFunction.didCall(); //Debug.Log ("start at function "+newFunction.name+" currentpoint is "+currentPoint); currentFunction = newFunction; break; case "break": Debug.Log("GOT A BREAK " + parts[1]); startup.doUserPause(); startup.pauseLabelString = parts[1] + " (Breakpoint)"; break; case "call": //if (!validateCall(newFunction)){ // isPlaying = false; //} newFunction = functionDatabase.getFunction(address); if (followFunction) { startup.cameraScript.setObject(newFunction.getPosition()); } if (newFunction.called == 0) { // first invocation in this call chain, bring the function forward pos = newFunction.go.transform.position; pos.z = newFunction.z + funForwardRunning; newFunction.go.transform.position = pos; //newFunction.setShader(startup.shader2); //newFunction.setColor(startup.color2); //Debug.Log ("set newfun to pos "+pos); } globalPoint = newFunction.script.getVertexPosition(block); lineElement++; lineVector[lineElement] = globalPoint; //Debug.Log ("call "+newFunction.name+" from "+currentFunction.name+ " from "+currentPoint+" to "+globalPoint+" #pts "+controlLine.maxDrawIndex); currentPoint = globalPoint; //newFunction.addLine(vl); callStack.Add(currentFunction); //newFunction.called ++; newFunction.didCall(); drawControl(false); //pause(); //newFunction.callStack = new List<functionItem>(callStack); //Debug.Break(); break; case "return": newFunction = functionDatabase.getFunction(address); if (followFunction) { startup.cameraScript.setObject(newFunction.getPosition()); } currentPoint = newFunction.script.getVertexPosition(block); //currentFunction.called --; if (currentFunction.called == 1) { // last return for this funtion in current call stack, put it backwards (but not all the way) pos = currentFunction.go.transform.position; pos.z = currentFunction.z + funForwardCalled; currentFunction.go.transform.position = pos; } lineElement = lineElement - currentFunction.currentPoints(); currentFunction.didReturn(); drawControl(false); callStack.RemoveAt(callStack.Count - 1); break; case startup.GOTO: //Debug.Log("goto current function is "+currentFunction.name); globalPoint = currentFunction.script.getVertexPosition(block); lineElement++; lineVector[lineElement] = globalPoint; currentPoint = globalPoint; currentFunction.didGoto(); //Debug.Log ("goto "+currentFunction.name+ " to "+block+" pts "+controlLine.maxDrawIndex+" currentPoints is "+currentFunction.currentPoints()); drawControl(false); eipLabel = "EIP: 0x" + address.ToString("x"); break; case "read": if (pipeBehavior.sessionNumber == 0) { return("skip"); } //Debug.Log ("is a read"); address = uint.Parse(parts[3], System.Globalization.NumberStyles.HexNumber); count = int.Parse(parts[4]); if (count > 0) { drawControl(true); doRead(address, count, currentPoint); } //Debug.Log ("back from doRead"); break; case "write": if (pipeBehavior.sessionNumber == 0) { return("skip"); } //Debug.Log ("is a write"); address = uint.Parse(parts[3], System.Globalization.NumberStyles.HexNumber); count = int.Parse(parts[4]); if (count > 0) { drawControl(true); doWrite(address, count, currentPoint); } break; case "move_local": if (pipeBehavior.sessionNumber == 0) { return("skip"); } count = int.Parse(parts[4]); // TBD hack to speed things up drawControl(false); if (count > 0) { destination = uint.Parse(parts[3], System.Globalization.NumberStyles.HexNumber); //Debug.Log ("is a move_local to "+destination.ToString("x")); Color color = pipeBehavior.getPipeColor(); destinationRegion = mmap.findMemoryRegion(destination); if (destinationRegion) { destinationRegion.copyBytes(0, destination, destinationRegion, count, currentPoint, color, true); } else { Debug.Log("copy to " + destination.ToString("x") + " assumed write to stack, ignore"); } } break; case "move": if (pipeBehavior.sessionNumber == 0) { return("skip"); } count = int.Parse(parts[5]); // TBD hack to speed things up drawControl(true); if (count > 0) { source = uint.Parse(parts[3], System.Globalization.NumberStyles.HexNumber); destination = uint.Parse(parts[4], System.Globalization.NumberStyles.HexNumber); //Debug.Log ("is a move from "+source.ToString("x")+" to "+destination.ToString("x")); Color color = pipeBehavior.getPipeColor(); sourceRegion = mmap.findMemoryRegion(source); destinationRegion = mmap.findMemoryRegion(destination); //Debug.Log ("current point is "+currentPoint+" function is "+currentFunction.name); if (sourceRegion) { if (destinationRegion) { sourceRegion.copyBytes(source, destination, destinationRegion, count, currentPoint, color, startup.skipToNetwork); } else { Debug.Log("copy to " + destination.ToString("x") + " assumed write to stack, ignore"); } } else { // copy from stack if (destinationRegion) { destinationRegion.copyBytes(0, destination, destinationRegion, count, currentPoint, color, true); } else { Debug.Log("copy to " + destination.ToString("x") + " assumed write to stack, ignore"); } } //startup.pause(true); } else { Debug.Log("skip move"); command = "skip"; } break; case "accept": Debug.Log("ACCEPT ******"); pipeScript.didAccept(); if (pipeBehavior.sessionNumber == 1) { mmap.firstSession(); } //GameObject connection = Instantiate (Resources.Load ("connectSpherePrefab")) as GameObject; //connectSphere script = (connectSphere) connection.GetComponent(typeof(connectSphere)); //script.doConnect(); break; case "mmap": address = uint.Parse(parts[3], System.Globalization.NumberStyles.HexNumber); count = int.Parse(parts[4]); mmap.newRegion(address, count); //Debug.Log ("got an mmap address "+address.ToString("x")+" count "+count); break; case "munmap": //Debug.Log ("found munmap for address "+address.ToString("x")); address = uint.Parse(parts[3], System.Globalization.NumberStyles.HexNumber); count = int.Parse(parts[4]); mmap.removeRegion(address, count); break; } if (newFunction != null) { currentFunction = newFunction; } if (breakpoints.Contains(currentClock)) { startup.doUserPause(); startup.pauseLabelString = "breakpoint"; } //startup.doUserPause (); return(command); }
public static void fromXML(XmlDocument xmlDoc) { XmlNode controlNode = xmlDoc.SelectSingleNode("//bookmark/control"); XmlNode currentClockNode = controlNode.SelectSingleNode("currentClock"); currentClock = long.Parse(currentClockNode.InnerText, System.Globalization.NumberStyles.HexNumber); XmlNode startClockNode = controlNode.SelectSingleNode("startClock"); if (startClockNode != null) { startClock = long.Parse(startClockNode.InnerText, System.Globalization.NumberStyles.HexNumber); } updateClock(currentClock); XmlNode currentFunctionNode = controlNode.SelectSingleNode("currentFunction"); if (currentFunctionNode != null) { uint addr = uint.Parse(currentFunctionNode.InnerText, System.Globalization.NumberStyles.HexNumber); currentFunction = functionDatabase.getFunction(addr); eipLabel = "EIP: 0x" + addr.ToString("x"); Debug.Log("currentFunction is " + currentFunction.name); } XmlNode numInstructNode = controlNode.SelectSingleNode("numberInstructions"); numInstructions = int.Parse(numInstructNode.InnerText, System.Globalization.NumberStyles.HexNumber); startup.resetInstructionTo(numInstructions); zeroLine(); XmlNode lineNode = controlNode.SelectSingleNode("controlLine"); XmlNode elementNode = lineNode.SelectSingleNode("lineElement"); int tmpLineElement = int.Parse(elementNode.InnerText); XmlNodeList pointNodes = lineNode.SelectNodes("linePoint"); for (int i = 0; i <= tmpLineElement; i++) { XmlNode xNode = pointNodes[i].SelectSingleNode("x"); lineVector[i].x = float.Parse(xNode.InnerText); XmlNode yNode = pointNodes[i].SelectSingleNode("y"); lineVector[i].y = float.Parse(yNode.InnerText); XmlNode zNode = pointNodes[i].SelectSingleNode("z"); lineVector[i].z = float.Parse(zNode.InnerText); } currentPoint = lineVector [tmpLineElement]; //Debug.Log ("line elements: " + tmpLineElement + " last " + lineVector [tmpLineElement]); // TBD hack needed to keep line from going to zero if this is the first draw. lineElement = 3; drawControl(true); lineElement = tmpLineElement; drawControl(true); XmlNode callStackNode = controlNode.SelectSingleNode("callStack"); XmlNodeList callNodes = callStackNode.SelectNodes("call"); callStack.Clear(); for (int i = 0; i < callNodes.Count; i++) { uint a = uint.Parse(callNodes[i].InnerText, System.Globalization.NumberStyles.HexNumber); functionDatabase.functionItem fi = functionDatabase.getFunction(a); callStack.Add(fi); } }
// look for keyboard shortcuts and clicking of objects bool checkKeys() { bool retval = true; if (menus.clicked != "") { return(true); } if (Input.GetMouseButtonDown(0) && !Input.GetKey(KeyCode.LeftAlt)) { // User clicked button (but not while naviaging via alt key //Debug.Log("clicked in checkKyes"); Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit hit; if (Physics.Raycast(ray, out hit, 100)) { if (Input.GetKey(KeyCode.LeftShift)) { // user seeks information about an object functionBehaive funScript = (functionBehaive)hit.transform.gameObject.GetComponent(typeof(functionBehaive)); if (funScript != null) { funScript.showSummary(false, false); } else { Debug.Log("perhaps hit data? " + hit.transform.gameObject.name); dataBehaviorNew dataScript = (dataBehaviorNew)hit.transform.gameObject.GetComponent(typeof(dataBehaviorNew)); if (dataScript != null) { dataScript.showSummary(); addressLabel = "address: 0x" + dataScript.address.ToString("x"); } } } else { // if function is clicked, zoom to it. Debug.Log("HIT SOMETHING " + hit.transform.gameObject.name); functionBehaive funScript = (functionBehaive)hit.transform.gameObject.GetComponent(typeof(functionBehaive)); if (funScript != null) { cameraScript.setObject(funScript.function.getPosition()); } } } } else if (Input.GetMouseButtonUp(0)) { addressLabel = ""; } else if (Input.GetKeyDown("space")) { doUserPause(); //print("space key was pressed"); //}else if (Input.GetKeyDown("escape")){ // //print("escape key was pressed"); // helpString = null; // //cameraScript.restore(); // setCamera(); } else if (Input.GetKeyDown("w") && Input.GetKey(KeyCode.LeftShift)) { cameraScript.moveZ(1); } else if (Input.GetKeyDown("s") && Input.GetKey(KeyCode.LeftShift)) { cameraScript.moveZ(-1); } else if (Input.GetKeyDown("w")) { cameraScript.moveY(1); } else if (Input.GetKeyDown("s")) { cameraScript.moveY(-1); } else if (Input.GetKeyDown("a")) { cameraScript.moveX(1); } else if (Input.GetKeyDown("d")) { cameraScript.moveX(-1); // }else if (Input.GetKeyDown("r") && (Input.GetKey (KeyCode.LeftShift) || Input.GetKey (KeyCode.RightShift))){ } else if (Input.GetKeyDown("r") && (Input.GetKey(KeyCode.LeftShift))) { if (!justShowData) { justShowData = true; skipToData = true; pauseLabelString = "skipping"; } else { justShowData = false; } } else if (Input.GetKeyDown("f")) { manageControl.follow(!manageControl.following()); } else if (Input.GetKeyDown("r")) { if (isPlaying) { skipToData = true; pauseLabelString = "skipping"; //Debug.Log("Skip to data at clock "+currentClock); } } else if (Input.GetKeyDown("h")) { setCamera(); } else if (Input.GetKeyDown("i")) { if (!skipToNetwork) { justShowData = true; skipToData = true; pauseLabelString = "skipping"; } else { justShowData = false; skipToData = false; if (!userPause) { pauseLabelString = "play"; } } skipToNetwork = !skipToNetwork; } else if (Input.GetKeyDown("b")) { pause(true); userStackFrame = manageControl.callStack.Count - 1; functionDatabase.functionItem fi = manageControl.currentFunction; cameraScript.setObject(fi.getPosition()); if (functionLabels) { fi.script.showSummary(true, true); } } else if (Input.GetKeyDown("n") && (Input.GetKey(KeyCode.LeftShift))) { if (userStackFrame < manageControl.callStack.Count - 1) { functionDatabase.functionItem fi = manageControl.callStack[userStackFrame]; cameraScript.setObject(fi.getPosition()); userStackFrame++; if (functionLabels) { fi.script.showSummary(true, true); } } } else if (Input.GetKeyDown("n")) { if (userStackFrame >= 0) { functionDatabase.functionItem fi = manageControl.callStack[userStackFrame]; cameraScript.setObject(fi.getPosition()); if (userStackFrame > 0) { userStackFrame--; } if (functionLabels) { fi.script.showSummary(true, true); } } } else if (Input.GetKeyDown("m")) { pause(true); menus.clicked = "create bookmark"; //createBookmark(); } else if (Input.GetKeyDown("l")) { pause(true); menus.clicked = "goto bookmark"; } else { retval = false; } return(retval); }
public void setFunction(functionDatabase.functionItem fi) { this.function = fi; }