基于gh0st的远程控制器

实现了终端管理、进程管理、窗口管理、桌面管理、文件管理、语音管理、视频管理、服务管理、注册表管理等功能。
This commit is contained in:
yuanyuanxiang
2019-01-05 20:21:43 +08:00
parent 3a66916242
commit 27fcb6284e
136 changed files with 33399 additions and 0 deletions

View File

@@ -0,0 +1,190 @@
#include "StdAfx.h"
#include "Buffer.h"
#include <math.h>
#define U_PAGE_ALIGNMENT 3
#define F_PAGE_ALIGNMENT 3.0
CBuffer::CBuffer(void)
{
m_ulMaxLength = 0;
m_Ptr = m_Base = NULL;
InitializeCriticalSection(&m_cs);
}
CBuffer::~CBuffer(void)
{
if (m_Base)
{
VirtualFree(m_Base, 0, MEM_RELEASE);
m_Base = NULL;
}
DeleteCriticalSection(&m_cs);
m_Base = m_Ptr = NULL;
m_ulMaxLength = 0;
}
ULONG CBuffer::RemoveComletedBuffer(ULONG ulLength)
{
if (ulLength >GetBufferMaxLength()) //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ij<EFBFBD><C4B3>ȱ<EFBFBD><C8B1>ڴ<EFBFBD><DAB4>ij<EFBFBD><C4B3>Ȼ<EFBFBD><C8BB><EFBFBD>
{
return 0;
}
if (ulLength >GetBufferLength()) //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ij<EFBFBD><C4B3><EFBFBD> <20><><EFBFBD><EFBFBD>Ч<EFBFBD><D0A7><EFBFBD><EFBFBD><EFBFBD>ݳ<EFBFBD><DDB3>Ȼ<EFBFBD><C8BB><EFBFBD>
{
ulLength = GetBufferLength();
}
if (ulLength)
{
MoveMemory(m_Base,m_Base+ulLength,GetBufferMaxLength() - ulLength); //<2F><><EFBFBD><EFBFBD>ǰ<EFBFBD><C7B0> [Shinexxxx??]
m_Ptr -= ulLength;
}
DeAllocateBuffer(GetBufferLength());
return ulLength;
}
ULONG CBuffer::ReadBuffer(PBYTE Buffer, ULONG ulLength)
{
EnterCriticalSection(&m_cs);
if (ulLength > GetBufferMaxLength())
{
LeaveCriticalSection(&m_cs);
return 0;
}
if (ulLength > GetBufferLength())
{
ulLength = GetBufferLength();
}
if (ulLength)
{
CopyMemory(Buffer,m_Base,ulLength);
MoveMemory(m_Base,m_Base+ulLength,GetBufferMaxLength() - ulLength);
m_Ptr -= ulLength;
}
DeAllocateBuffer(GetBufferLength());
LeaveCriticalSection(&m_cs);
return ulLength;
}
ULONG CBuffer::DeAllocateBuffer(ULONG ulLength)
{
if (ulLength < GetBufferLength())
return 0;
ULONG ulNewMaxLength = (ULONG)ceil(ulLength / F_PAGE_ALIGNMENT) * U_PAGE_ALIGNMENT;
if (GetBufferMaxLength() <= ulNewMaxLength)
{
return 0;
}
PBYTE NewBase = (PBYTE) VirtualAlloc(NULL,ulNewMaxLength,MEM_COMMIT,PAGE_READWRITE);
ULONG ulv1 = GetBufferLength(); //<2F><>ԭ<EFBFBD><D4AD><EFBFBD>ڴ<EFBFBD><DAB4><EFBFBD><EFBFBD><EFBFBD>Ч<EFBFBD><D0A7><EFBFBD><EFBFBD>
CopyMemory(NewBase,m_Base,ulv1);
VirtualFree(m_Base,0,MEM_RELEASE);
m_Base = NewBase;
m_Ptr = m_Base + ulv1;
m_ulMaxLength = ulNewMaxLength;
return m_ulMaxLength;
}
BOOL CBuffer::WriteBuffer(PBYTE Buffer, ULONG ulLength)
{
EnterCriticalSection(&m_cs);
if (ReAllocateBuffer(ulLength + GetBufferLength()) == -1)//10 +1 1024
{
LeaveCriticalSection(&m_cs);
return false;
}
CopyMemory(m_Ptr,Buffer,ulLength);//Hello 5
m_Ptr+=ulLength;
LeaveCriticalSection(&m_cs);
return TRUE;
}
ULONG CBuffer::ReAllocateBuffer(ULONG ulLength)
{
if (ulLength < GetBufferMaxLength())
return 0;
ULONG ulNewMaxLength = (ULONG)ceil(ulLength / F_PAGE_ALIGNMENT) * U_PAGE_ALIGNMENT;
PBYTE NewBase = (PBYTE) VirtualAlloc(NULL,ulNewMaxLength,MEM_COMMIT,PAGE_READWRITE);
if (NewBase == NULL)
{
return -1;
}
ULONG ulv1 = GetBufferLength(); //ԭ<>ȵ<EFBFBD><C8B5><EFBFBD>Ч<EFBFBD><D0A7><EFBFBD>ݳ<EFBFBD><DDB3><EFBFBD>
CopyMemory(NewBase,m_Base,ulv1);
if (m_Base)
{
VirtualFree(m_Base,0,MEM_RELEASE);
}
m_Base = NewBase;
m_Ptr = m_Base + ulv1; //1024
m_ulMaxLength = ulNewMaxLength; //2048
return m_ulMaxLength;
}
VOID CBuffer::ClearBuffer()
{
EnterCriticalSection(&m_cs);
m_Ptr = m_Base;
DeAllocateBuffer(1024);
LeaveCriticalSection(&m_cs);
}
ULONG CBuffer::GetBufferLength() //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ч<EFBFBD><D0A7><EFBFBD>ݳ<EFBFBD><DDB3><EFBFBD>
{
if (m_Base == NULL)
return 0;
return (ULONG)m_Ptr - (ULONG)m_Base;
}
ULONG CBuffer::GetBufferMaxLength()
{
return m_ulMaxLength;
}
PBYTE CBuffer::GetBuffer(ULONG ulPos)
{
if (m_Base==NULL)
{
return NULL;
}
if (ulPos>=GetBufferLength())
{
return NULL;
}
return m_Base+ulPos;
}