Esempio n. 1
0
        public static int EntryPoint(string pwzArgument)
        {
            Debug.WriteLine("[KeeFarceDLL] Starting");
            //string processName = Process.GetCurrentProcess().ProcessName;
            //MessageBox.Show("The current process is " + processName + " and I am running C# code! Yuss!");

            if (is64Bit)
            {
                Debug.WriteLine("[KeeFarceDLL] Target is 64 bit");
            }

            // Retrieve the DocumentManagerEx object off the heap
            // TODO: KeePass can support multiple password files , so should probably modify this to load
            // ALL of the DocumentManagerEx's into a list and process 'em, as opposed to just breaking
            // after finding the first one.
            IntPtr docManagerPtr = IntPtr.Zero;

            using (DataTarget dataTarget = DataTarget.AttachToProcess(Process.GetCurrentProcess().Id, 5000, AttachFlag.Passive))
            {
                string     dacLocation = dataTarget.ClrVersions[0].TryGetDacLocation();
                ClrRuntime runtime     = CreateRuntimeHack(dataTarget, dacLocation, 4, 5);
                Debug.WriteLine("[KeeFarceDLL] Attached to process.");

                ClrHeap heap = runtime.GetHeap();
                foreach (ulong obj in heap.EnumerateObjects())
                {
                    ClrType type = heap.GetObjectType(obj);

                    ulong size = type.GetSize(obj);
                    if (type.Name == "KeePass.UI.DocumentManagerEx")
                    {
                        Debug.WriteLine("[KeeFarceDLL] Found DocumentManagerEx at: " + obj.ToString("X") + " " + type.Name);
                        docManagerPtr = (IntPtr)obj;
                        break;
                    }
                }

                if (docManagerPtr == IntPtr.Zero)
                {
                    // Didn't find a document manager, time to return.
                    Debug.WriteLine("[KeeFarceDLL] No DocumentManagerEx found");
                    return(1);
                }
            }

            // Get the DocumentManagerEx object
            Converter <object> ptrconv           = new Converter <object>();
            object             documentManagerEx = ptrconv.ConvertFromIntPtr(docManagerPtr);
            var info = new DocumentManagerExInfo(documentManagerEx);
            int r    = doExport(info.ActiveDatabase, info.RootGroup, exportFile);

            return(r);
        }
Esempio n. 2
0
        public static int EntryPoint(string pwzArgument)
        {
            Debug.WriteLine("[KeeFarceDLL] Starting");
            //string processName = Process.GetCurrentProcess().ProcessName;
            //MessageBox.Show("The current process is " + processName + " and I am running C# code! Yuss!");

            if (is64Bit)
            {
                Debug.WriteLine("[KeeFarceDLL] Target is 64 bit");
            }

            // Retrieve the DocumentManagerEx object off the heap
            // TODO: KeePass can support multiple password files , so should probably modify this to load 
            // ALL of the DocumentManagerEx's into a list and process 'em, as opposed to just breaking
            // after finding the first one.
            IntPtr docManagerPtr = IntPtr.Zero;
            using (DataTarget dataTarget = DataTarget.AttachToProcess(Process.GetCurrentProcess().Id, 5000, AttachFlag.Passive))
            {
                string dacLocation = dataTarget.ClrVersions[0].TryGetDacLocation();
                ClrRuntime runtime = CreateRuntimeHack(dataTarget, dacLocation, 4, 5);
                Debug.WriteLine("[KeeFarceDLL] Attached to process.");

                ClrHeap heap = runtime.GetHeap();
                foreach (ulong obj in heap.EnumerateObjects())
                {
                    
                    ClrType type = heap.GetObjectType(obj);
                    
                    ulong size = type.GetSize(obj);
                    if (type.Name == "KeePass.UI.DocumentManagerEx")
                    {
                        Debug.WriteLine("[KeeFarceDLL] Found DocumentManagerEx at: " + obj.ToString("X") + " " + type.Name);
                        docManagerPtr = (IntPtr)obj;
                        break;
                    }
                }
                
                if(docManagerPtr == IntPtr.Zero) {
                    // Didn't find a document manager, time to return.
                    Debug.WriteLine("[KeeFarceDLL] No DocumentManagerEx found");
                    return 1;
                }

            }
 
            // Get the DocumentManagerEx object
            Converter<object> ptrconv = new Converter<object>();
            object documentManagerEx = ptrconv.ConvertFromIntPtr(docManagerPtr);
            var info = new DocumentManagerExInfo(documentManagerEx);
            int r = doExport(info.ActiveDatabase, info.RootGroup, exportFile);

            return r;
        }