|
Anyone? A possibility is that modern compilers assume the base image address will never change, and forego creating relocations. Can anyone confirm or deny this?
|
|
|
|
|
This program will list all the addresses in "Kernel32.dll" that would need relocating if it didn't load at its preferred base address:
#include "stdafx.h"
#include <iostream>
#include <windows.h>
using namespace std;
int main(int argc, char* argv[])
{
char *pBase = (char*)GetModuleHandle("kernel32.dll");
PIMAGE_DOS_HEADER pDOS = (PIMAGE_DOS_HEADER)pBase;
assert(pDOS->e_magic == IMAGE_DOS_SIGNATURE);
PIMAGE_NT_HEADERS pNT = (PIMAGE_NT_HEADERS)(pBase + pDOS->e_lfanew);
assert(pNT->Signature == IMAGE_NT_SIGNATURE);
PIMAGE_OPTIONAL_HEADER pOpt = &(IMAGE_OPTIONAL_HEADER)(pNT->OptionalHeader);
assert(pOpt->Magic == IMAGE_NT_OPTIONAL_HDR32_MAGIC);
PIMAGE_DATA_DIRECTORY pRelocDD = &(pOpt->DataDirectory[IMAGE_DIRECTORY_ENTRY_BASERELOC]);
DWORD SizeOfRelocs = pRelocDD->Size;
PIMAGE_BASE_RELOCATION pReloc = (PIMAGE_BASE_RELOCATION)(pBase + pRelocDD->VirtualAddress);
for (DWORD ToGo = SizeOfRelocs; ToGo>0; )
{
WORD *pRelocArray = (WORD*)(pReloc + 1);
DWORD NumRelocs = (pReloc->SizeOfBlock - sizeof(IMAGE_BASE_RELOCATION)) / sizeof(WORD);
for (DWORD i=0; i<NumRelocs; ++i)
{
WORD val = pRelocArray[i];
WORD Type = val >> 12;
WORD RVA = val & 0x0FFF;
cout << hex << "Type = " << Type << ", Address = " << (DWORD)(pBase + pReloc->VirtualAddress + RVA) << endl;
}
ToGo -= pReloc->SizeOfBlock;
pReloc = (PIMAGE_BASE_RELOCATION)((char*)pReloc + pReloc->SizeOfBlock);
}
return 0;
}
See here[^] for for information.
Steve
|
|
|
|
|
Hi friends,
I am working on a chat-like application. I was thinking of adding a added utility to it. I want the program to copy itself on another PC of the network & execute there ....
PLz help me in this ....
Thanx !
|
|
|
|
|
Google for RPC.
"Love people and use things, not love things and use people." - Unknown
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
|
or trojan.
OK,. what country just started work for the day ? The ASP.NET forum is flooded with retarded questions. -Christian Graus
Best wishes to Rexx[^]
|
|
|
|
|
|
Hi all,
I need to paint the background of a CStatic control created dynamically this way:
CUnknownCtrl* pUnknown;
pUnknown = new CUnknownCtrl;
pUnknown->Create("Text", SS_CENTER | WS_CHILD | WS_VISIBLE | WS_GROUP, CRect(11,35,360,526), this, 0x31);
Notice that CUnknownCtrl is a CStatic-derived mfc class.
I can't figure out how to set background color of the label created with this code, someone can help me?
Calling OnCtlColor inside CUnknownCtrl won't even be executed and OnPaint fails. Some idea?
Thanks for advance
---
|
|
|
|
|
Hi,
Simply handle the WM_CTLCOLORSTATIC message in your class. The WM_CTLCOLORSTATIC is send to a static control when its background color need to drawn.
thanks.
Nitheesh
|
|
|
|
|
WM_CTLCOLORSTATIC is sent to the parent window of the static control, not the static control itself.
|
|
|
|
|
4288 wrote: and OnPaint fails
What does that mean?
led mike
|
|
|
|
|
I used OnCtlColor handler, but because my label was created with a CStatic-derived class, the code provided into CMyClass::OnCtlColor won't be executed!
OnPaint seemed me a good solution but if I insert the OnPaint handler with Visual Studio, the control won't even show
---
|
|
|
|
|
4288 wrote: but if I insert the OnPaint handler with Visual Studio, the control won't even show
Did you subclass the control?[^]
led mike
|
|
|
|
|
I thought I subclassed it, but my subclassing seems not to work.
Have you got please a link that show how to perform a subclassing with a dynamical control created like mine?
---
|
|
|
|
|
|
Problem solved, thanks!
---
|
|
|
|
|
Very good.
|
|
|
|
|
Hi every body!
From where can I get some information about "Connection Strings" used to connect to MS Access Database. For example I don't know what "MaxBufferSize" means and so on...
Don't laught at me! I know what U R thinking about...
|
|
|
|
|
Usef Marzbani wrote: For example I don't know what "MaxBufferSize" means and so on...
It refers to the amount of RAM Access sets aside for its use as an internal storage space. The larger the storage space, the higher are the odds that the data necessary for a request can be found in RAM and will not require physical disk access.
"Love people and use things, not love things and use people." - Unknown
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
|
So I have this COM object that's packing up an array floats for me.
Here's the loop where the VARIANT* array is getting stuffed:
for (i = 0; i < cElements; i++)
{
VariantInit(&vDataValues[i]);
V_VT(&vDataValues[i]) = VT_R4;
//Works ok UNLESS float_data[i] == 0.0;
V_R4(&vDataValues[i]) = float_data[i];
if (!V_R4(&vDataValues[i]))
{
*pErrorCode = 1;
m_strMessage.Format("V_R4 failed!");
hr = E_FAIL;
goto Error;
}
}
The VT_R4() operation works unless the element in float_data
happens to be 0.0. When that happens, VT_R4 fails.
I know it fails only with 0.0, because I tried this:
if( float_data[i] != 0.0 )
V_R4(&vDataValues[i]) = float_data[i];
else
V_R4(&vDataValues[i]) = float_data[i] + 0.1;
Then, it never fails.
I can't figure out why.
|
|
|
|
|
Well I have no idea what your float_data is or if it has been properly initialized but this works without error
VARIANT DataValues[4];
V_R4( &DataValues[0]) = 0.0;
led mike
|
|
|
|
|
I'm new to using COM, so maybe I'm missing something obvious here.
The data I can verify is OK.
led mike wrote: VARIANT DataValues[4]; V_R4( &DataValues[0]) = 0.0;
Those lines work for me, too.
The examples I'm looking show that you verify it's OK by doing this sort of thing:
if (!V_R4(&vDataValues[i]))
{
//Do some error stuff
}
And !V_R4(&vDataValues[i]) evaluates to false if the data is 0.0.
Why is that?
If I comment out that error check, everything seems to work fine. Is it not needed?
|
|
|
|
|
Eurosid wrote: The examples I'm looking show that you verify it's OK by doing this sort of thing:
I don't think that's correct. Where are you getting these examples?
V_R4 is just a macro that evaluates to the specified VARIANT member during pre-compile. It does not return an status indication value.
led mike
|
|
|
|
|
You are exactly correct. I misunderstood what I was looking at.
The example was for packing up a BSTR, so they did such a check
to make sure the pointer wasn't NULL.
Doing the same thing on a float isn't needed, but will look OK unless the value happens to be 0, which will look like FALSE.
I told you I was a Chump!
Thank you for help!
|
|
|
|