G
Guest
It should be possible to build a verifiable assembly using the managed
extensions for C++. It may be possible if the target is a library, but as far
as I can determine it cannot be done for an application. Hopefully it is
possible, and I just need someone to explain what I'm doing wrong.
1. Using the "New Projects" wizard, create a new Visual C++ .NET Windows
Forms Application.
2. Add NOTHING to the project.
3. Build it, run it. No problem.
4. Confirm that peverify reports that it is unverifiable. This is expected
at this stage.
5. Add the following code to Form1.cpp:
extern "C" {
int _fltused=1;
void _cdecl _check_commonlanguageruntime_version(){}
}
and this code to AssemblyInfo.cpp:
using namespace System::Security:ermissions;
[assembly: SecurityPermissionAttribute(
SecurityAction::RequestMinimum,
SkipVerification=false)];
6. In the project settings, disable optimisations (/Od) and confirm /clr is
set.
7. Build it. Run it. Still no problem.
8. Confirm that peverify still reports it is unverifiable.
9. Use silo (after finding and building the SetILOnly sample project) to
set the "IL only" bit in the assembly (the .exe file).
10. The app should now be verifiable, shouldn't it? But ...
11. Run peverify on it again: observe that it is still unverifiable.
12. Run the app: observe that the runtime now complains: "Application failed
to initialize properly (0xC000007B)"
Note that peverify always reports the same errors:
[IL]: Error: Unverifiable PE Header/native stub.
[IL]: Error: Unverifiable image '' can not be run.
It fails if it is run with or without the "/IL" switch, but it always
succeeds if run with the "/MD" switch.
Steps 5 to 9 above are a fuzzy union of instructions given in:
1. Visual Studio .NET help topic: "Producing Verifiable Components with
Managed Extensions for C++"
2. The usually accurate and informative "Programming with managed extensions
for MS VC++ .NET", by Richard Grimes.
Unfortunately, both of these sources (and all the random advice I've found
elsewhere) are focused to some extent on building verifiable libraries, not
applications, and my suspicion is it only works for dlls.
Can anyone set me straight?
Allan
extensions for C++. It may be possible if the target is a library, but as far
as I can determine it cannot be done for an application. Hopefully it is
possible, and I just need someone to explain what I'm doing wrong.
1. Using the "New Projects" wizard, create a new Visual C++ .NET Windows
Forms Application.
2. Add NOTHING to the project.
3. Build it, run it. No problem.
4. Confirm that peverify reports that it is unverifiable. This is expected
at this stage.
5. Add the following code to Form1.cpp:
extern "C" {
int _fltused=1;
void _cdecl _check_commonlanguageruntime_version(){}
}
and this code to AssemblyInfo.cpp:
using namespace System::Security:ermissions;
[assembly: SecurityPermissionAttribute(
SecurityAction::RequestMinimum,
SkipVerification=false)];
6. In the project settings, disable optimisations (/Od) and confirm /clr is
set.
7. Build it. Run it. Still no problem.
8. Confirm that peverify still reports it is unverifiable.
9. Use silo (after finding and building the SetILOnly sample project) to
set the "IL only" bit in the assembly (the .exe file).
10. The app should now be verifiable, shouldn't it? But ...
11. Run peverify on it again: observe that it is still unverifiable.
12. Run the app: observe that the runtime now complains: "Application failed
to initialize properly (0xC000007B)"
Note that peverify always reports the same errors:
[IL]: Error: Unverifiable PE Header/native stub.
[IL]: Error: Unverifiable image '' can not be run.
It fails if it is run with or without the "/IL" switch, but it always
succeeds if run with the "/MD" switch.
Steps 5 to 9 above are a fuzzy union of instructions given in:
1. Visual Studio .NET help topic: "Producing Verifiable Components with
Managed Extensions for C++"
2. The usually accurate and informative "Programming with managed extensions
for MS VC++ .NET", by Richard Grimes.
Unfortunately, both of these sources (and all the random advice I've found
elsewhere) are focused to some extent on building verifiable libraries, not
applications, and my suspicion is it only works for dlls.
Can anyone set me straight?
Allan