/// <summary>
        /// Try to bind this breakpoint to an actual breakpoint in the VM.
        /// This method is blocking, so make sure to call accordingly.
        /// </summary>
        internal override bool TryBind(DalvikProcess process)
        {
            if (IsBound)
            {
                return(true);
            }

            var loc = TryGetLocation(process);

            if (loc == null)
            {
                return(false); // not yet.
            }
            // Now set breakpoint
            var setTask = process.Debugger.EventRequest.SetAsync(Jdwp.EventKind.BreakPoint, Jdwp.SuspendPolicy.All,
                                                                 new LocationOnlyModifier(loc));
            var requestId = setTask.Await(DalvikProcess.VmTimeout);

            // Store request ID and notify listeners that we're now bound.
            OnBound(requestId, process.BreakpointManager);

            // Process any events that came before we got a chance to record property.
            process.BreakpointManager.ProcessPendingEvents(this);

            return(true);
        }
 public DalvikDisassemblyProvider(DalvikProcess process, string apkPath, MapFileLookup mapFile)
 {
     _process = process;
     _apkPath = apkPath;
     _mapFile = mapFile;
     _dex     = new Lazy <DexLookup>(LoadDex);
 }
 public DalvikDisassemblyProvider(DalvikProcess process, string apkPath, MapFileLookup mapFile)
 {
     _process = process;
     _apkPath = apkPath;
     _mapFile = mapFile;
     _dex = new Lazy<DexLookup>(LoadDex);
 }
Example #4
0
        /// <summary>
        /// Try to bind this breakpoint to an actual breakpoint in the VM.
        /// This method is blocking, so make sure to call accordingly.
        /// </summary>
        internal override void TryBind(DalvikProcess process)
        {
            if (IsBound)
            {
                return;
            }

            // Lookup classid & methodid
            var pos                  = documentPosition;
            var signature            = typeEntry.DexSignature;
            var referenceTypeManager = process.ReferenceTypeManager;

            // Register a callback for when the class is prepared.
            if (classPrepareCookie == null)
            {
                classPrepareCookie = referenceTypeManager.RegisterClassPrepareHandler(signature, evt => TryBind(process));
            }

            // Now try to find the type
            var refType = referenceTypeManager.FindBySignature(signature);

            if (refType == null)
            {
                // Not possible yet
                return;
            }

            // We've found the type, we're no longer interested in class prepare events
            if (classPrepareCookie != null)
            {
                referenceTypeManager.Remove(classPrepareCookie);
            }

            var refTypeMethods = refType.GetMethodsAsync().Await(DalvikProcess.VmTimeout);
            var dmethod        = refTypeMethods.FirstOrDefault(x => x.IsMatch(methodEntry));

            if (dmethod == null)
            {
                throw new ArgumentException(string.Format("Cannot find method {0}", methodEntry.Name));
            }

            // Now set breakpoint
            var location = new Location(refType.Id, dmethod.Id, (ulong)pos.MethodOffset);
            var setTask  = process.Debugger.EventRequest.SetAsync(Jdwp.EventKind.BreakPoint, Jdwp.SuspendPolicy.All,
                                                                  new LocationOnlyModifier(location));
            var requestId = setTask.Await(DalvikProcess.VmTimeout);

            // Store request ID and notify listeners that we're now bound.
            OnBound(requestId, process.BreakpointManager);

            // Process any events that came before we got a chance to record property.
            process.BreakpointManager.ProcessPendingEvents(this);
        }
        /// <summary>
        /// Try to bind this breakpoint to an actual breakpoint in the VM.
        /// This method is blocking, so make sure to call accordingly.
        /// </summary>
        internal override void TryBind(DalvikProcess process)
        {
            if (IsBound)
                return;

            // Lookup classid & methodid
            var pos = documentPosition;
            var signature = typeEntry.DexSignature;
            var referenceTypeManager = process.ReferenceTypeManager;

            // Register a callback for when the class is prepared.
            if (classPrepareCookie == null)
            {
                classPrepareCookie = referenceTypeManager.RegisterClassPrepareHandler(signature, evt => TryBind(process));
            }

            // Now try to find the type
            var refType = referenceTypeManager.FindBySignature(signature);
            if (refType == null)
            {
                // Not possible yet
                return;
            }

            // We've found the type, we're no longer interested in class prepare events
            if (classPrepareCookie != null)
            {
                referenceTypeManager.Remove(classPrepareCookie);
            }

            var refTypeMethods = refType.GetMethodsAsync().Await(DalvikProcess.VmTimeout);
            var dmethod = refTypeMethods.FirstOrDefault(x => x.IsMatch(methodEntry));
            if (dmethod == null)
            {
                throw new ArgumentException(string.Format("Cannot find method {0}", methodEntry.Name));
            }

            // Now set breakpoint
            var location = new Location(refType.Id, dmethod.Id, (ulong) pos.MethodOffset);
            var setTask = process.Debugger.EventRequest.SetAsync(Jdwp.EventKind.BreakPoint, Jdwp.SuspendPolicy.All,
                                                            new LocationOnlyModifier(location));
            var requestId = setTask.Await(DalvikProcess.VmTimeout);

            // Store request ID and notify listeners that we're now bound.
            OnBound(requestId, process.BreakpointManager);

            // Process any events that came before we got a chance to record property.
            process.BreakpointManager.ProcessPendingEvents(this);
        }
        private Location TryGetLocation(DalvikProcess process)
        {
            if (location != null)
            {
                return(location);
            }

            // Lookup classid & methodid
            var signature            = typeEntry.DexSignature;
            var referenceTypeManager = process.ReferenceTypeManager;

            // Register a callback for when the class is prepared.
            if (classPrepareCookie == null)
            {
                classPrepareCookie = referenceTypeManager.RegisterClassPrepareHandler(signature, evt => TryBind(process));
            }

            // Now try to find the type
            var refType = referenceTypeManager.FindBySignature(signature);

            if (refType == null)
            {
                // Not possible yet
                return(null);
            }

            // We've found the type, we're no longer interested in class prepare events
            if (classPrepareCookie != null)
            {
                referenceTypeManager.Remove(classPrepareCookie);
            }

            var refTypeMethods = refType.GetMethodsAsync().Await(DalvikProcess.VmTimeout);
            var dmethod        = refTypeMethods.FirstOrDefault(x => x.IsMatch(methodEntry));

            if (dmethod == null)
            {
                throw new ArgumentException(string.Format("Cannot find method {0}", methodEntry.Name));
            }

            // return location.
            var pos = SourceCodePosition;

            location         = new Location(refType.Id, dmethod.Id, (ulong)pos.Position.MethodOffset);
            documentLocation = new DocumentLocation(location, pos, refType, dmethod, typeEntry, methodEntry);

            return(location);
        }
Example #7
0
 /// <summary>
 /// Status notification
 /// </summary>
 private void OnDebuggerConnectedChanged(object sender, System.EventArgs e)
 {
     if (InvokeRequired)
     {
         Invoke(new EventHandler(OnDebuggerConnectedChanged), sender, e);
     }
     else
     {
         if (debugger.Connected && (lastProcess != debugger.Process))
         {
             lastProcess = debugger.Process;
             var ui = TaskScheduler.FromCurrentSynchronizationContext();
             debugger.Process.IsSuspendedChanged += (s, x) => Task.Factory.StartNew(RefreshThreads, CancellationToken.None, TaskCreationOptions.None, ui);
             
         }
         treeView.Nodes.Clear();                
         UpdateStatus();
     }
 }
        /// <summary>
        /// Try to bind this breakpoint to an actual breakpoint in the VM.
        /// This method is blocking, so make sure to call accordingly.
        /// </summary>
        internal override bool TryBind(DalvikProcess process)
        {
            if (IsBound)
                return true;

            var loc = TryGetLocation(process);
            if (loc == null)
                return false; // not yet.

            // Now set breakpoint
            var setTask = process.Debugger.EventRequest.SetAsync(Jdwp.EventKind.BreakPoint, Jdwp.SuspendPolicy.All,
                                                                 new LocationOnlyModifier(loc));
            var requestId = setTask.Await(DalvikProcess.VmTimeout);

            // Store request ID and notify listeners that we're now bound.
            OnBound(requestId, process.BreakpointManager);

            // Process any events that came before we got a chance to record property.
            process.BreakpointManager.ProcessPendingEvents(this);

            return true;
        }
Example #9
0
        /// <summary>
        /// Connect to the VM in the given process id on the given device.
        /// </summary>
        public void Connect(IDevice device, int pid, MapFile mapFile)
        {
            // Disconnect any pending connections
            Disconnect();

            // Cleanup
            process = null;
            this.mapFile = mapFile;
            this.pid = pid;

            // Setup forward
            var port = GetFreePort();
            var adb = new Adb();
            adb.ForwardJdwp(device, port, pid);

            // Establish connection
            connection = new JdwpConnection(new IPEndPoint(IPAddress.Parse("127.0.0.1"), port), ChunkHandler, pid, PacketHandler);
            connection.Disconnect += OnConnectionDisconnect;

            // Notify
            ConnectedChanged.Fire(this);
        }
Example #10
0
 /// <summary>
 /// Default ctor
 /// </summary
 public DalvikObjectReference(ObjectId id, DalvikProcess process)
 {
     Id           = id;
     this.process = process;
 }
 /// <summary>
 /// Default ctor
 /// </summary>
 protected internal DalvikExceptionManager(DalvikProcess process)
     : base(process)
 {
 }
Example #12
0
 /// <summary>
 /// Default ctor
 /// </summary>
 protected internal DalvikThreadManager(DalvikProcess process)
     : base(process)
 {
 }
 /// <summary>
 /// Default ctor
 /// </summary>
 protected internal DalvikReferenceTypeManager(DalvikProcess process)
     : base(process)
 {
 }
 /// <summary>
 /// Default ctor
 /// </summary>
 protected internal DalvikExceptionManager(DalvikProcess process)
     : base(process)
 {
 }
Example #15
0
 /// <summary>
 /// Default ctor
 /// </summary>
 protected internal DalvikThreadManager(DalvikProcess process)
     : base(process)
 {
 }
Example #16
0
 /// <summary>
 /// Default ctor
 /// </summary>
 protected internal DalvikBreakpointManager(DalvikProcess process)
 {
     this.process = process;
 }
        private Location TryGetLocation(DalvikProcess process)
        {
            if (location != null)
                return location;

            // Lookup classid & methodid
            var signature = typeEntry.DexSignature;
            var referenceTypeManager = process.ReferenceTypeManager;

            // Register a callback for when the class is prepared.
            if (classPrepareCookie == null)
            {
                classPrepareCookie = referenceTypeManager.RegisterClassPrepareHandler(signature, evt => TryBind(process));
            }

            // Now try to find the type
            var refType = referenceTypeManager.FindBySignature(signature);
            if (refType == null)
            {
                // Not possible yet
                return null;
            }

            // We've found the type, we're no longer interested in class prepare events
            if (classPrepareCookie != null)
            {
                referenceTypeManager.Remove(classPrepareCookie);
            }

            var refTypeMethods = refType.GetMethodsAsync().Await(DalvikProcess.VmTimeout);
            var dmethod = refTypeMethods.FirstOrDefault(x => x.IsMatch(methodEntry));
            if (dmethod == null)
            {
                throw new ArgumentException(string.Format("Cannot find method {0}", methodEntry.Name));
            }

            // return location.
            var pos = SourceCodePosition;

            location = new Location(refType.Id, dmethod.Id, (ulong) pos.Position.MethodOffset);
            documentLocation = new DocumentLocation(location, pos, refType, dmethod, typeEntry, methodEntry);

            return location;
        }
 /// <summary>
 /// Default ctor
 /// </summary>
 protected internal DalvikReferenceTypeManager(DalvikProcess process)
     : base(process)
 {
 }
Example #19
0
 /// <summary>
 /// Default ctor
 /// </summary
 public DalvikObjectReference(ObjectId id, DalvikProcess process)
 {
     Id = id;
     this.process = process;
 }