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: BlackZeroX▓▓▒▒░░ en 15 Octubre 2010, 04:35 AM
.
Como Dato:
Private Function MTrim(ByVal s As String) As String
Dim i As Long
Dim res As String
For i = 1 To Len(s)
If Mid$(s, i, 1) <> Chr$(0) Then
res = res & Mid$(s, i, 1)
End If
Next
MTrim = res
End Function
Queda mejor asi!¡:
Private Function NullTrim(ByVal vDataIn As String) As String
Dim Lng_Pos As Long
Lng_Pos = InStr(1, vDataIn, Chr(0)) - 1
If Lng_Pos > 0 Then NullTrim = Mid$(vDataIn, 1, Lng_Pos)
End Function
Para quitar los chr(0) de los string (Unicode) solo se me ocurrre hacer esto en un array de bytes.
Dim arrbyte() As Byte
arrbyte() = StrConv("hola", VbStrConv.vbFromUnicode)
MsgBox Chr(arrbyte(0)) & Chr(arrbyte(1)) & Chr(arrbyte(2)) & Chr(arrbyte(3))
Dulces Lunas!¡.
Option Explicit
Public Const DLL_PROCESS_DETACH = 0 ':El proceso descarga la DLL
Public Const DLL_PROCESS_ATTACH = 1 ': Cuando un proceso carga la DLL
Public Const DLL_THREAD_ATTACH = 2 ': El proceso está recargando una DLL
Public Const DLL_THREAD_DETACH = 3 ':El proceso está descargando una Dll recargada
Public Declare Function MessageBox Lib "user32" Alias "MessageBoxA" (ByVal hwnd As Long, ByVal lpText As String, ByVal lpCaption As String, ByVal wType As Long) As Long
Public Function DllMain(hInst As Long, fdwReason As Long, lpvReserved As Long) As Boolean
Select Case fdwReason
Case DLL_PROCESS_DETACH
'No per-process cleanup needed
Case DLL_PROCESS_ATTACH
MsgBox "Project1.dll Injected!"
'MsgBox "End of Search!"
DllMain = True
Case DLL_THREAD_ATTACH
'No per-thread initialization needed
Case DLL_THREAD_DETACH
'No per-thread cleanup needed
End Select
'DllMain = True
End Function
Public Sub Mensaje()
MessageBox 0&, "Test", "Mensaje", 0&
End Sub
Public Function Suma(ByVal N1 As Long, ByVal N2 As Long) As Long
Suma = N1 + N2
'MessageBox 0, Suma, "Resultado", 0
End Function
'Public Function Mensaje2(ByVal Msg As String) As String
'Mensaje2 = Msg
'End Function
Public Function Mensaje2() As String
' Las cadenas de VB6 son Unicode y al usarla desde una DLL
' se hace un follón... así que debemos quitarles los Chr$(0)
' que tenga en medio
'Dim str As String * 4
'str = "Hola"
'Mensaje2 = str
Mensaje2 = "Esto es una prueba."
End Function
Public Function LenString(ByVal Cadena As String) As Integer
LenString = Len(Cadena)
End Function
Private Function MTrim(ByVal s As String) As String
Dim i As Long
Dim res As String
For i = 1 To Len(s)
If Mid$(s, i, 1) <> Chr$(0) Then
res = res & Mid$(s, i, 1)
End If
Next
MTrim = res
End Function
#include <iostream>
#include <windows.h>
#include <string>
using namespace std;
typedef void (WINAPI*MsgFunction) ();
typedef long (WINAPI*SumaFunction) (long,long);
void MyDLL();
void MyDLL2();
void MyDLL3();
void MyDLL4();
string MTrim(char *);
string MTrim(char *, int);
int tStrLen(char *);
bool IsValid(char);
//Declaramos el ProcID de la dll
//HINSTANCE hGetProcIDDLL = LoadLibrary("Project1.dll");
int main()
{
MyDLL4();
/*
MsgFunction MsgBox;
SumaFunction Suma;
HINSTANCE hinstDLL = LoadLibrary("Project1.dll");
if(hinstDLL != 0)
{
printf("DLL LOADED.\n");
MsgBox = (MsgFunction)GetProcAddress(hinstDLL,"Mensaje");
MsgBox();
Suma = (SumaFunction)GetProcAddress(hinstDLL,"Suma");
long x = Suma(6,6);
if(x == 12)
{
cout << "Message Displayed!\n";
}
// Unload DLL file
FreeLibrary(hinstDLL);
}
else
{
printf("DLL NOT LOADED.\n");
}
*/
system("PAUSE");
return 0;
}
void MyDLL()
{
/* get handle to dll */
HINSTANCE hGetProcIDDLL = LoadLibrary("Project1.dll");
/* get pointer to the function in the dll*/
FARPROC lpfnGetProcessID = GetProcAddress((HMODULE)hGetProcIDDLL,"Mensaje");
/*
Define the Function in the DLL for reuse. This is just prototyping
the dll's function. A mock of it. Use "stdcall" for maximum
compatibility.
*/
typedef void (__stdcall * pICFUNC)(HWND);
pICFUNC MyFunction;
if (hGetProcIDDLL==NULL)
{
printf("Can not open the Library\n");
}
else
{
printf("CAN open the Library\n");
}
MyFunction = (pICFUNC)lpfnGetProcessID;
/* The actual call to the function contained in the dll */
MyFunction(NULL);
/* Release the Dll */
FreeLibrary(hGetProcIDDLL);
}
void MyDLL2()
{
/* get handle to dll */
HINSTANCE hGetProcIDDLL = LoadLibrary("Project1.dll");
/* get pointer to the function in the dll*/
FARPROC lpfnGetProcessID = GetProcAddress((HMODULE)hGetProcIDDLL,"Suma");
/*
Define the Function in the DLL for reuse. This is just prototyping
the dll's function. A mock of it. Use "stdcall" for maximum
compatibility.
*/
typedef long (__stdcall * pICFUNC)(long,long);
pICFUNC MyFunction;
if (hGetProcIDDLL==NULL)
{
printf("Can not open the Library\n");
}
else
{
printf("CAN open the Library\n");
}
MyFunction = (pICFUNC)lpfnGetProcessID;
/* The actual call to the function contained in the dll */
long x = MyFunction(5,5);
//printf("Result: %l\n",x);
cout <<"Resultado: ";
cout << x;
cout << '\n';
cout <<"Resultado: " << x <<'\n';
//cout <<"El valor decimal de número es:" << numero << '\n';
//cout <<"El valor octal de número es:" << oct <<numero << '\n';
//cout <<"El valor hexadecimal de número es:" << hex <<numero << '\n';
//Si se hace otro cout de algun numero, lo muestra en hex, xq fue
//el último que usamos
/* Release the Dll */
FreeLibrary(hGetProcIDDLL);
}
void MyDLL3()
{
/* get handle to dll */
HINSTANCE hGetProcIDDLL = LoadLibrary("Project1.dll");
/* get pointer to the function in the dll*/
FARPROC lpfnGetProcessID = GetProcAddress((HMODULE)hGetProcIDDLL,"Mensaje2");
/*
Define the Function in the DLL for reuse. This is just prototyping
the dll's function. A mock of it. Use "stdcall" for maximum
compatibility.
*/
typedef char * (__stdcall * pICFUNC)(); //LPCSTR
//typedef void (CALLBACK* pICFUNC)();
pICFUNC MyFunction;
if (hGetProcIDDLL==NULL)
{
printf("Can not open the Library\n");
}
else
{
printf("CAN open the Library\n");
}
MyFunction = (pICFUNC)lpfnGetProcessID;
/* The actual call to the function contained in the dll */
//MessageBox(NULL, MyFunction(),"CAPTION",MB_OK);
char * ss = MyFunction();
//cout << MTrim(ss) << "\n";
/* Release the Dll */
FreeLibrary(hGetProcIDDLL);
}
void MyDLL4()
{
/* get handle to dll */
HINSTANCE hGetProcIDDLL = LoadLibrary("Project1.dll");
/* get pointer to the function in the dll*/
FARPROC lpfnGetProcessID = GetProcAddress((HMODULE)hGetProcIDDLL,"Mensaje2");
FARPROC lpfnGetProcessID2 = GetProcAddress((HMODULE)hGetProcIDDLL,"LenString");
/*
Define the Function in the DLL for reuse. This is just prototyping
the dll's function. A mock of it. Use "stdcall" for maximum
compatibility.
*/
typedef char * (__stdcall * pICFUNC)(); //LPCSTR
typedef int (__stdcall * pICFUNC2)(char *); //LPCSTR
//typedef void (CALLBACK* pICFUNC)();
pICFUNC MyFunction;
pICFUNC2 MyFunction2;
if (hGetProcIDDLL==NULL)
{
printf("Can not open the Library\n");
}
else
{
printf("CAN open the Library\n");
}
MyFunction = (pICFUNC)lpfnGetProcessID;
MyFunction2 = (pICFUNC2)lpfnGetProcessID2;
/* The actual call to the function contained in the dll */
//MessageBox(NULL, MyFunction(),"CAPTION",MB_OK);
char * ss = MyFunction();
cout << "Longitud: " << MyFunction2(ss) << "\n\n";
cout << "Supuesta cadena: " << ss << "\n\n";
cout << "Forma Frutera: " << MTrim(ss) << "\n\n";
cout << "A la gran Misery: " << MTrim(ss, MyFunction2(ss)) << "\n\n";
/* Release the Dll */
FreeLibrary(hGetProcIDDLL);
}
string MTrim(char * s)
{
long i;
string res="";
char chr = char(0);
//cout << "Longitud: " << tStrLen("Hola") << "\n";
//cout << "Longitud: " << strlen(s) << "\n";
//cout << "Longitud: " << sizeof(s) << "\n";
//cout << "Longitud: " << s.length() << "\n";
for(i=0; i < 16 ;i++) //Testin'
{
if(s[i] != chr)
{
res = res + s[i];
}
}
return res;
}
string MTrim(char * s,int len)
{
long i;
string res="";
char chr = char(0);
int acum=0;
//cout << "Longitud: " << tStrLen("Hola") << "\n";
//cout << "Longitud: " << strlen(s) << "\n";
//cout << "Longitud: " << sizeof(s) << "\n";
//cout << "Longitud: " << s.length() << "\n";
for(i=0; acum < len ;i++) //Testin'
{
if(IsValid(s[i]) == true && s[i] != chr)
{
res = res + s[i];
acum++;
}
}
return res;
}
bool IsValid(char s)
{
char valid[] = "abcdefghijklmnñopqrstuvwxyzABCDEFGHIJKLMÑOPQRSTUVWXYZ0123456789 ,.-!$%&/()=?¿*;_¬[]{}";
for(int i = 0; i < strlen(valid); i++)
{
if(valid[i] == s)
{
return true;
}
}
return false;
}
//Función que devuelve la longitud de una cadena
int tStrLen(char * s)
{
char * s0= s;
while (*s++);
return s - s0 - 1;
}
char * ss = MyFunction();
cout << "Longitud: " << MyFunction2(ss) << "\n\n";
cout << "Supuesta cadena: " << ss << "\n\n";
cout << "Forma Frutera: " << MTrim(ss) << "\n\n";
cout << "A la gran Misery: " << MTrim(ss, MyFunction2(ss)) << "\n\n";
Option Explicit
Public Function Mensaje(ByVal Msg As String) As String
Mensaje = Msg
End Function
#include <iostream>
#include <windows.h>
using namespace std;
typedef void (*MsgFunction) (void);
HINSTANCE hinstDLL;
int main()
{
MsgFunction MsgBox;
hinstDLL = LoadLibrary("Project1.dll");
if(hinstDLL != 0)
{
printf("DLL LOADED.\n");
MsgBox = (MsgFunction)GetProcAddress(hinstDLL,"Mensaje");
if(MsgBox != 0)
{
printf("FUNCTION FOUND.\n");
//Call Function
MsgBox;
}
else
{
printf("FUNCTION NOT FOUND.\n");
}
// Unload DLL file
FreeLibrary(hinstDLL);
}
else
{
printf("DLL NOT LOADED.\n");
}
system("PAUSE");
return 0;
}
Option Explicit
Public Declare Function MessageBox Lib "user32" Alias "MessageBoxA" (ByVal hwnd As Long, ByVal lpText As String, ByVal lpCaption As String, ByVal wType As Long) As Long
Public Sub Mensaje()
MessageBox 0, "Test", "Caption", 0
End Sub
Public Function Suma(ByVal n1 As Long, ByVal N2 As Long) As Long
Suma = n1 + N2
End Function
#include <iostream>
#include <windows.h>
using namespace std;
typedef void (WINAPI*MsgFunction) ();
typedef long (WINAPI*SumaFunction) (long,long);
int main()
{
MsgFunction MsgBox;
SumaFunction Suma;
HINSTANCE hinstDLL = LoadLibrary("Project1.dll");
if(hinstDLL != 0)
{
printf("DLL LOADED.\n");
MsgBox = (MsgFunction)GetProcAddress(hinstDLL,"Mensaje");
MsgBox();
Suma = (SumaFunction)GetProcAddress(hinstDLL,"Suma");
long x = Suma(6,6);
if(x == 12)
{
cout << "Message Displayed!\n";
}
// Unload DLL file
FreeLibrary(hinstDLL);
}
else
{
printf("DLL NOT LOADED.\n");
}
system("PAUSE");
return 0;
}
Public Sub Mensaje()
Msgbox "Mensaje!"
End Sub
// DLL function signature
typedef double (*importFunction)(void);
importFunction MyFunction;
// Load DLL file
HINSTANCE hinstLib = LoadLibrary("Project1.dll");
if (hinstLib == NULL)
{
MessageBox(0,"ERROR: unable to load DLL","Error",0);
}
else
{
// Get function pointer
MyFunction = (importFunction)GetProcAddress(hinstLib, "Mensaje");
if (MyFunction == NULL)
{
MessageBox(0,"ERROR: unable to find DLL function","Error",0);
FreeLibrary(hinstLib);
}
else
{
MyFunction();
// Unload DLL file
FreeLibrary(hinstLib);
}
}
Cita de: BlackZeroX en 9 Octubre 2010, 02:56 AMCita de: Miseryk en 8 Octubre 2010, 08:27 AM
Hola, quería saber si me podrían guiar con este tema:
Yo inyecto una dll en un programa, el programa tiene muchas funciónes y procedimientos, como hago para llamarlos desde la dll inyectada? alguna idea? Desde ya muchas gracias por resolver y aclarar mis dudas en los posts.![]()
![]()
![]()
![]()
Ej: del ejecutable.
Option Explicit
Private Sub Command1_Click()
Dim var As Long
var = VarPtr(Valor(1, 1))
MsgBox var & " (" & Hex(var) & ")"
End Sub
Public Function Valor(ByVal v1 As Long, ByVal v2 As Long) As Long
Valor = v1 + v2
End Function
Esto hice para saber el address de la función.
lo que haces hay no es devolver la dirección del proceso, devuelves la dirrecion de variable de RESULTADO del Proceso
si quieres saber la dirrecion del Proceso, Funcion, u otra cosa similar
En un Modulo (Bas)
Option Explicit
Sub main()
Dim ThisAddress&
ThisAddress& = Adrs&(AddressOf procesoX)
MsgBox ThisAddress& & " - (" & Hex(ThisAddress&) & ")"
End Sub
Public Function Adrs(ByVal Addrs As Long) As Long
Adrs& = Addrs&
End Function
Public Function procesoX(ParamArray ParametrosX() As Variant) As String
End Function
Dulce Infierno Lunar!¡.