Exemplo n.º 1
0
    internal IntPtr AllocateBuffer(int bufferSize)
    {
        var buffer = _processContext.CallRoutine <IntPtr>(_processContext.GetFunctionAddress("kernel32.dll", "HeapAlloc"), _heapAddress, HeapAllocationType.ZeroMemory, bufferSize);

        if (buffer == IntPtr.Zero)
        {
            throw new ApplicationException("Failed to allocate a buffer in the process heap");
        }

        _bufferCache.Add(buffer);

        return(buffer);
    }
Exemplo n.º 2
0
        private void CallInitialisationRoutines(DllReason reason)
        {
            // Call the entry point of any TLS callbacks

            foreach (var callbackAddress in _peImage.TlsDirectory.GetTlsCallbacks().Select(callBack => DllBaseAddress + callBack.RelativeAddress))
            {
                _processContext.CallRoutine(callbackAddress, DllBaseAddress, reason, 0);
            }

            if (_peImage.Headers.PEHeader !.AddressOfEntryPoint == 0)
            {
                return;
            }

            // Call the entry point of the DLL

            var entryPointAddress = DllBaseAddress + _peImage.Headers.PEHeader !.AddressOfEntryPoint;

            if (!_processContext.CallRoutine <bool>(entryPointAddress, DllBaseAddress, reason, 0))
            {
                throw new ApplicationException($"Failed to call the entry point of the DLL with {reason:G}");
            }
        }
Exemplo n.º 3
0
 internal SafePebLock(ProcessContext processContext)
 {
     _processContext = processContext;
     processContext.CallRoutine(processContext.GetFunctionAddress("ntdll.dll", "RtlAcquirePebLock"));
 }
Exemplo n.º 4
0
 public void Dispose()
 {
     Executor.IgnoreExceptions(() => _processContext.CallRoutine(_processContext.GetFunctionAddress("ntdll.dll", "RtlReleasePebLock")));
 }
Exemplo n.º 5
0
 public void Dispose()
 {
     _processContext.CallRoutine(_processContext.GetFunctionAddress("ntdll.dll", "RtlReleasePebLock"));
 }