|
Here is a quick question for you. I have a program which I have embedded within a program. I am basicall trying to achieve a sort of security wrapper to the second embedded program. Anyway, I can write the embedded program to disc and execute it there, then delete it when done, but I would prefer to hold it im RAM. Is there any method by which a program can be held in RAM and executed?
Any thoughts and comments would be well received.
Many thanks
|
|
|
|
|
If the second program is embedded in the first as a resource, maybe something like this will help. (NOTE: I don't really know that this is even plausible, just a concept I came up with in my head).
Anyway, how about reading all the bytes of the 2nd executable into a byte array, find out where the address is for the wndproc or initinstance function, make a function pointer member in the first executable, then set the address of the function pointer to that address in the byte array (offset from the first byte, of course), and execute it. Does that make any sense?
My articles
www.stillwaterexpress.com
BlackDice
|
|
|
|
|
Thanks for the post. I have been pondering along a similar line of thought myself. I'll give it a go later and see what occurs. Sounds like a plan though
u6ik
|
|
|
|
|
Don't even waste your time thinking about this. The loader has a huge amount more to do than merely copying bytes into memory and then calling something.
Anyway, how would you know what to call? It's certainly not WndProc or InitInstance!
The opinions expressed in this communication do not necessarily represent those of the author (especially if you find them impolite, discourteous or inflammatory).
|
|
|
|
|
Although not a trivial task, it is indeed possible. It requires knowledge of the PE file format. See here. There is Web site referrred to in one of the C++ threads but I am unable to find it right now.
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
|
|
|
|
|
If the wrapped file is already in a binary/exe format when imported into the VC++ resource hex table, then exporting that file to memory in binary form should load it to memory in the correct format ie a binary exacutable, the PE format is automatically taken care of. As long as the start of that memory location can be referenced as an exe in some way, all should run okay, shouldn't it?
V interesting links, thanks
u6ik
|
|
|
|
|
This is true for the most part. The executable file on disk is very similar to what the module will look like after Windows has loaded it.
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
|
|
|
|
|
Hi... I got a weird problem here : ). I'm made a VC++ 6 DLL (Simple Win32 DLL Project). It's a DLL that installs a system-wide hook for the keyboard. I used keyboard because it's quite easy, my final purpose is to monitor messages with WH_GETMESSAGE. Anyhow, even this doesn't work.
My main Application is a VB6 Application. I will call the DLL from there. As you know, in order for a hook to work, you have to give it an address for a callback function which the hook will call each time it catches a keyboard event or message. The trick in my DLL is that the callback ain't here. I pass to the DLL (from VB) a parameter obtained from VB with the AddressOf operator. The parameter is the address of a VB function. Practically, I`m setting up the hook in VC++, but the callback function is in VB : ). I use "AddressOfCallBackFunction" parameter below to achieve this.
#include "stdafx.h"
#include "winuser.h"
HANDLE hInstance;
HHOOK hhookHooks;
const int WH_KEYBOARD = 2;
BOOL APIENTRY DllMain( HANDLE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
hInstance = hModule;
switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
case DLL_THREAD_ATTACH:
case DLL_THREAD_DETACH:
case DLL_PROCESS_DETACH:
break;
}
return TRUE;
}
int HookSystem(int AddressOfCallBackFunction);
int UnHookSystem(int HookID);
int HookSystem(int AddressOfCallBackFunction)
{
hhookHooks = SetWindowsHookEx(WH_KEYBOARD,
(HOOKPROC) AddressOfCallBackFunction,
(HINSTANCE) hInstance,
0);
return (int)hhookHooks;
}
int UnHookSystem(int HookID)
{
int iResult = 0;
iResult = UnhookWindowsHookEx((HHOOK)HookID);
if (iResult == 0) return 0; else return 1;
}
The VB code is simple and short.
In a module I got this...
Public Declare Function HookSystem Lib "D:\Lucru\Test\ASDClock.dll" (ByVal AddressOfTheCallBackFunction As Long) As Long
Public Declare Function UnHookSystem Lib "D:\Lucru\Test\ASDClock.dll" (ByVal HookID As Long) As Long
Public Function KeyboardCallback(ByVal Code As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
MsgBox Code
End Function
And in the Form I got this.
Dim test As Long
test = HookSystem(AddressOf KeyboardCallback)
Surprise surprise! When VB reaches test = HookSystem(AddressOf KeyboardCallback) guess what? Error : BAD DLL CALLING CONVENTION. However, great must be your amazement when you hear that the hook IS ACTUALLY INSTALLED. The Application crashes, I must stop it, but the hook is succesfully installed.
As I learned, the error I just wrote above occurs when there are data type inconsistencies between VB and the DLL (or wrong number of parameters). Weird, because this is not the case. Long in VB = int in C++. The number of parameters is correct too.... Passing the parameters by ByVal is also correct. So anybody know what could be the problem?? Because I sure don't know. I've been using VB for quite some time...
The .DEF file for the VC++ DLL is :
LIBRARY ASDClock
DESCRIPTION "Testing some hook."
EXPORTS
HookSystem @1
UnHookSystem @2
Hm... I'm in the dark here : ).
-= E C H Y S T T A S =-
The Greater Mind Balance
|
|
|
|
|
Hi !
No, a calling convention error is not because the parameters you pass are wrong. A calling convention describe in fact which part will clean the stack after the function has been called: the program which calls the dll or the dll itselfs. VB and C++ uses different calling conventions: for VB it is the standard calling convention (__stdcall) and for C++ it is the the C calling convention.
So, here your HookSystem and UnHookSystem functions have the C calling convention in the dll but VB calls them with it own calling convention. So, you have to change the calling convention of these functions inside your dll: just add a __stdcall :
<br />
int __stdcall HookSystem(int AddressOfCallBackFunction);<br />
int __stdcall UnHookSystem(int HookID);<br />
<br />
int __stdcall HookSystem(int AddressOfCallBackFunction)<br />
{ <br />
....<br />
}<br />
int __stdcall UnHookSystem(int HookID)<br />
{<br />
....<br />
}
You could also use APIENTRY as it is defined as __stdcall
|
|
|
|
|
Hi Cedric : ). Thanks a lot for your answer. That solved the problem!
-= E C H Y S T T A S =-
The Greater Mind Balance
|
|
|
|
|
Hi everybody,
I'm planning to write a multi platform driver in order to capture
applications on a desktop and send them to FlashComm server.
I know that I may use Camtasia, but I'm planning an open source
project and I would like to implemet my own drivers.
I have to be able to select my screen output if you click on a flash movie and go to properties. There you can select all available cameras from a dropdown menu. My goal is that my screen output can be selected here.
Anyone with solutions
Tom Lismont
|
|
|
|
|
Hey
I'm building this small image processing program using MFC with the Doc/View stuff and i'm annoyed about the 3D border of the frame (or the inlay so to speak) in which the view is placed. I tried to remove that border or whatever it is by adjusting the CREATESTRUCT in the PreCreateWindow function of the child frame which holds my view. That doesn't seem to work. Any ideas/suggestions what it should be or what i did wrong?
thanks and greetings Joris
|
|
|
|
|
try using ModifyStyle().....
cheerz.....
"faith, hope, love remain, these three.....; but the greatest of these is love" -1 Corinthians 13:13
|
|
|
|
|
try using ModifyStyle() or ModifyStyleEx......
u can change/modify the window char/styles dynamically(u have border optionz in that if i am right!!!.....search in msdn for WS_EX_STATICEDGE(for modifystylex) or WS_THICKFRAME(for modifyStyle) .....there r many optionz i dunno what kind of frame ,but u ought to find ur type of frame listed in these parameterz(WS_EX_.....,WS_....).....
hope that helpz!!!!!
cheerz.....
"faith, hope, love remain, these three.....; but the greatest of these is love" -1 Corinthians 13:13
|
|
|
|
|
Hey
Thanks. I solved it. I removed the WS_EX_CLIENTEDGE in the PreCreateWindow function from both the MDI child frame AND the view. I stumbled on that by accident. Seems to work fine, but i have no clue why the client edge has to be removed from both parts of the framework.
greetings Joris
|
|
|
|
|
i am writting an ActiveX control.
i want change mouse cursor at run time.
i written the following code in OnSetCursor.
SetCursor(AfxGetApp()->LoadStandardCursor(IDC_WAIT));
But OnSetCursor is not called.
how call the OnSetCursor. won't framework call it?
|
|
|
|
|
well.....
u have to override the OnSetCursor function!!!!!
just calling it wont help!!!!!
add the WM_SETCURSOR.....
then in that function..... remove the return statement and replace it with return TRUE;
eg:
bool EXAMPLE::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message)
{
....
...
....
return CDialog::OnSetCursor(pWnd, nHitTest, message);
return TRUE;
}
now add the code where u want to add it ......
SetCursor(AfxGetApp()->LoadStandardCursor(IDC_WAIT));
hope that helpz!!!!!
cheerz.....
"faith, hope, love remain, these three.....; but the greatest of these is love" -1 Corinthians 13:13
|
|
|
|
|
I'm creating a property sheet with many property pages but I don't know how to handle the Close button to save my data on the property page . Please help me!
Love
|
|
|
|
|
|
Hello,
I try to compile and get that the sddl.h file is missing.
Is there anyone that have this file and can EMail me that
goran.larsson@neteye.se
|
|
|
|
|
Looks like you may need to install the latest Platform SDK.
/ravi
My new year's resolution: 2048 x 1536
Home | Articles | Freeware | Music
ravib@ravib.com
|
|
|
|
|
Ok,
And where can I get that?
|
|
|
|
|
|
hiho@ll
just wanted to know what to do if i have 2 classes
class example1
class example2
to use the class example1 in example2 i use #include "exmple1.h" in the example2.h
but then i want to program a function in example1 which uses example2
if i add #include "example2.h" in example1.h i get a compiler error in example1.h
syntax error: identifier 'example2'
i understand why this error occurs
but how i make a workaround?
thx
|
|
|
|
|
You just forward-declare example 2:
<br />
<br />
class example2;<br />
<br />
class example1<br />
{<br />
public:<br />
....<br />
example2* pex2;<br />
}<br />
but as you can see, you can only use pointers to the forwarded class, not the class itself.
Cheers
Steen.
"To claim that computer games influence children is ridiculous. If Pacman had influenced children born in the 80'ies we would see a lot of youngsters running around in dark rooms eating pills while listening to monotonous music"
|
|
|
|