Una alternativa a cualquier función, usando la PEB.
{
Autor: Orlando9427
Metodo: InOrderModuleLoad
}
procedure GetOwnPath(): String;
var PEB: Pointer;
begin
  asm
    push eax
    mov eax, fs: $30
    mov PEB, eax
    pop eax
  
  PEB = Pointer(Pointer(Integer(PEB) + $0C)^);
  PEB = Pointer(Pointer(Integer(PEB) + $0C)^);
  PEB = Pointer(Pointer(Integer(PEB) + $28)^);
  Result = WideCharToString(PEB);
end;
Saludos!
We do what we must, because, we can-> [www.youtube.com/watch?v=Y6ljFaKRTrI]
Pasa a saludar: NeoDark-Labs.BlogSpot.mx
<<<<Proyectos en curso>>>>
[+]Restauración de SSDT
[+]Driver v3 - Ocultar drivers
[+]Anti-rootkit
Gracias por el código muy bueno.


Pudiste hacerlo así.


mov eax, fs:[eax+$30]
mov eax, [eax+$10]
mov eax, [eax+$3C]
mov PEB,eax
Imagen
Lo intente hacer así pero no pude, ASM es muy complejo para mi .
El código quedaría así.
procedure GetOwnPath(): String;
var PEB: Pointer;
begin
  asm
    mov eax, fs:[eax+$30]
    mov eax, [eax+$10]
    mov eax, [eax+$3C]
    mov PEB,eax
  end;
  Result = WideCharToString(PEB);
end;
Saludos!
We do what we must, because, we can-> [www.youtube.com/watch?v=Y6ljFaKRTrI]
Pasa a saludar: NeoDark-Labs.BlogSpot.mx
<<<<Proyectos en curso>>>>
[+]Restauración de SSDT
[+]Driver v3 - Ocultar drivers
[+]Anti-rootkit
orlando9427 escribió::Aplausos: Lo intente hacer así pero no pude, ASM es muy complejo para mi .
El código quedaría así.
procedure GetOwnPath(): String;
var PEB: Pointer;
begin
  asm
    mov eax, fs:[eax+$30]
    mov eax, [eax+$10]
    mov eax, [eax+$3C]
    mov PEB,eax
  end;
  Result = WideCharToString(PEB);
end;
Saludos!
function GetOwnPath(): PWideChar;
begin
  asm
    mov eax, fs:[eax+$30]
    mov eax, [eax+$10]
    mov eax, [eax+$3C]
    mov Result,eax
  end;
end;
Por qué así sí funciona y de tipo string no? pues ni idea, el caso es que se vuelve loco y explota.
Saludos
UDTools.net
GitHub: https://github.com/MetalUDT
Porque para poder usar una string tiene que ser inicializada con un tamaño y si solo devuelves el puntero para llenar una cadena adimensional Delphi se vuelve loco.

Saludos!
We do what we must, because, we can-> [www.youtube.com/watch?v=Y6ljFaKRTrI]
Pasa a saludar: NeoDark-Labs.BlogSpot.mx
<<<<Proyectos en curso>>>>
[+]Restauración de SSDT
[+]Driver v3 - Ocultar drivers
[+]Anti-rootkit
Sí, pero en teoría debería funcionar como la pusiste:

funcion GetOwnPath(): String;
var PEB: Pointer;
begin
asm
mov eax, fs:[eax+$30]
mov eax, [eax+$10]
mov eax, [eax+$3C]
mov PEB,eax
end;
Result = WideCharToString(PEB);
end;

Pero no funciona ni con setlength.

Edito, claro, si devolvemos un pointer pues como que no..
UDTools.net
GitHub: https://github.com/MetalUDT
De hecho no, le faltan los ":" antes del "=" de Result... Que versión de Delphi usas?
En la 7 me va bien
We do what we must, because, we can-> [www.youtube.com/watch?v=Y6ljFaKRTrI]
Pasa a saludar: NeoDark-Labs.BlogSpot.mx
<<<<Proyectos en curso>>>>
[+]Restauración de SSDT
[+]Driver v3 - Ocultar drivers
[+]Anti-rootkit
Fue un copy paste rápido de tu post :P, uso Delphi 7, a mí me funciona la que puse con resultado PWideChar, pero no la citada, y la primera para que me funcione he tenido que retocar varias cosas, el procedure [Function], los ':=' y el 'end;' al finalizar el asm.
function GetOwnPath(): String;
var PEB: Pointer;
begin
  asm
    push eax
    mov eax, fs: $30
    mov PEB, eax
    pop eax
  end;

  PEB:= Pointer(Pointer(Integer(PEB) + $0C)^);
  PEB:= Pointer(Pointer(Integer(PEB) + $0C)^);
  PEB:= Pointer(Pointer(Integer(PEB) + $28)^);
  Result:= WideCharToString(PEB);
end;
Saludos!
UDTools.net
GitHub: https://github.com/MetalUDT
Tienes razón pero no falla en la string falla en la rutina ASM a pesar de que es la misma no funciona cuando se devuelve una string y si cuando devuelve un puntero. Revisaré un poco haber que sucede.

Saludos!
We do what we must, because, we can-> [www.youtube.com/watch?v=Y6ljFaKRTrI]
Pasa a saludar: NeoDark-Labs.BlogSpot.mx
<<<<Proyectos en curso>>>>
[+]Restauración de SSDT
[+]Driver v3 - Ocultar drivers
[+]Anti-rootkit
Supuestamente el uso de WideCharToString debería subsanarlo (hablo de la función que pusiste tras la de Pink), pero por alguna razón no lo hace, por algún sitio creo haber visto una solución un poco 'cerda' que recuerdo no encontrarle sentido pero funcionaba, si lo encuentro lo pongo.

Edito y pongo lo que se me ocurrió xD (funciona):
function GetOwnPath(): String;
var PEB: Pointer; s: string;
begin
asm
mov eax, fs:[eax+$30]
mov eax, [eax+$10]
mov eax, [eax+$3C]
mov PEB,eax
end;
s:= PWideChar(PEB);
Result:= s;
end;
UDTools.net
GitHub: https://github.com/MetalUDT
Por alguna razón así si funciona tambien me funciono sin la variable "s" usando Result. Tal vez tenga que ver algo con el stack de la función. Al parecer se han creado muchas variantes de la función xD
We do what we must, because, we can-> [www.youtube.com/watch?v=Y6ljFaKRTrI]
Pasa a saludar: NeoDark-Labs.BlogSpot.mx
<<<<Proyectos en curso>>>>
[+]Restauración de SSDT
[+]Driver v3 - Ocultar drivers
[+]Anti-rootkit
Hola. Así lo solucione para que no de error en el código asm. solo limpiamos el registro eax.

Function GetOwnPath():String;
var
PEB:Pointer;
begin
  asm
    xor eax,eax  //Problema resuelto :P
    mov eax, fs:[eax+$30]
    mov eax, [eax+$10]
    mov eax, [eax+$3C]
    mov PEB,eax
 end;
 Result:= WideCharToString(PEB);
end;

Saludos compas.
Imagen
Responder

Volver a “Fuentes”