Click here to Skip to main content
15,860,859 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Registry REG_BINARY Problem Pin
CPallini12-Apr-09 9:58
mveCPallini12-Apr-09 9:58 
GeneralRe: Registry REG_BINARY Problem Pin
locoone12-Apr-09 10:46
locoone12-Apr-09 10:46 
GeneralRe: Registry REG_BINARY Problem Pin
CPallini12-Apr-09 11:17
mveCPallini12-Apr-09 11:17 
GeneralRe: Registry REG_BINARY Problem [modified] Pin
locoone12-Apr-09 11:50
locoone12-Apr-09 11:50 
GeneralRe: Registry REG_BINARY Problem Pin
CPallini13-Apr-09 4:46
mveCPallini13-Apr-09 4:46 
GeneralRe: Registry REG_BINARY Problem Pin
locoone13-Apr-09 12:40
locoone13-Apr-09 12:40 
QuestionRemoving the MS-DOS stub from a PE File Pin
iNoble11-Apr-09 8:05
iNoble11-Apr-09 8:05 
AnswerRe: Removing the MS-DOS stub from a PE File Pin
Baltoro11-Apr-09 9:08
Baltoro11-Apr-09 9:08 
There are a number of good explanations of the Portable Executable file format on the Web. Here's one: Structure of the Portable Executable File Format[^]. A more complete description is Matt Pietrek's original article: Peering Inside the PE: A Tour of the Win32 Portable Executable File Format[^].
Are you trying to substitute a new DOS Stub for the existing one, or just eliminate it altogether? And, why? Is this necessary?
In Matt Pietrek's article, he starts out by saying: "The first few hundred bytes of the typical PE file are taken up by the MS-DOS stub. This stub is a tiny program that prints out something to the effect of "This program cannot be run in MS-DOS mode." So if you run a Win32-based program in an environment that doesn't support Win32, you'll get this informative error message."
Actually, the MS DOS Header is located at the beginning of the PE file: The MS-DOS header occupies the first 64 bytes of the PE file. You obviously know that because the structure is listed in your code:
WINNT.H

typedef struct _IMAGE_DOS_HEADER {  // DOS .EXE header
    USHORT e_magic;         // Magic number
    USHORT e_cblp;          // Bytes on last page of file
    USHORT e_cp;            // Pages in file
    USHORT e_crlc;          // Relocations
    USHORT e_cparhdr;       // Size of header in paragraphs
    USHORT e_minalloc;      // Minimum extra paragraphs needed
    USHORT e_maxalloc;      // Maximum extra paragraphs needed
    USHORT e_ss;            // Initial (relative) SS value
    USHORT e_sp;            // Initial SP value
    USHORT e_csum;          // Checksum
    USHORT e_ip;            // Initial IP value
    USHORT e_cs;            // Initial (relative) CS value
    USHORT e_lfarlc;        // File address of relocation table
    USHORT e_ovno;          // Overlay number
    USHORT e_res[4];        // Reserved words
    USHORT e_oemid;         // OEM identifier (for e_oeminfo)
    USHORT e_oeminfo;       // OEM information; e_oemid specific
    USHORT e_res2[10];      // Reserved words
    LONG   e_lfanew;        // File address of new exe header
  } IMAGE_DOS_HEADER, *PIMAGE_DOS_HEADER;


An imporvement on your code would be to read that IMAGE_DOS_HEADER.e_lfanew value, initially, and then attempt to rewrite your file data into the new version. But, your code appears to be correct in that respect, you write the NT Headers at that value without changing it. Your big problem is that you don't move all the rest of the file data forward in the new file, like you did with the initial headers (and change the corresponding header fields to reflect this). Many of these fields are RVAs (Relative Virtual Address, relative to the base loading address), which the Windows loader reads to locate the various PE file sections and their identifying headers.
Also, the CreateFileMapping and MapViewOfFile are executing with a file handle that you just closed. But, you don't seem to be using the address anyway, so it doesn't really matter. When you are initially attempting to get code lke this to work, you should be checking return values (the errors will be obvious).
Just out of curiosity, what happens when the Windows loader attempts to load your new file? Or, are you using a Hex Editor to examine the realigned structure?
GeneralRe: Removing the MS-DOS stub from a PE File [modified] Pin
iNoble11-Apr-09 9:40
iNoble11-Apr-09 9:40 
GeneralRe: Removing the MS-DOS stub from a PE File Pin
Baltoro11-Apr-09 10:21
Baltoro11-Apr-09 10:21 
GeneralRe: Removing the MS-DOS stub from a PE File Pin
iNoble11-Apr-09 13:16
iNoble11-Apr-09 13:16 
AnswerRe: Removing the MS-DOS stub from a PE File Pin
Stephen Hewitt12-Apr-09 6:08
Stephen Hewitt12-Apr-09 6:08 
GeneralRe: Removing the MS-DOS stub from a PE File Pin
iNoble12-Apr-09 11:36
iNoble12-Apr-09 11:36 
GeneralRe: Removing the MS-DOS stub from a PE File Pin
Baltoro13-Apr-09 5:55
Baltoro13-Apr-09 5:55 
Questionneed help.. [modified] Pin
badboyz8911-Apr-09 7:31
badboyz8911-Apr-09 7:31 
AnswerRe: need help.. Pin
CARPETBURNER12-Apr-09 0:06
CARPETBURNER12-Apr-09 0:06 
Questionwho can share the code to intercept iexplore connect send recv closesocket Pin
ernst2002053011-Apr-09 5:19
ernst2002053011-Apr-09 5:19 
AnswerRe: who can share the code to intercept iexplore connect send recv closesocket Pin
Green Fuze11-Apr-09 20:00
Green Fuze11-Apr-09 20:00 
News[ANN] Announcement: NUI C++ multi-platform appllication framework, 3D hardware GUI [modified] Pin
meelooo11-Apr-09 0:17
meelooo11-Apr-09 0:17 
GeneralRe: [ANN] Announcement: NUI C++ multi-platform appllication framework, 3D hardware GUI Pin
Rajesh R Subramanian11-Apr-09 0:20
professionalRajesh R Subramanian11-Apr-09 0:20 
GeneralRe: [ANN] Announcement: NUI C++ multi-platform appllication framework, 3D hardware GUI Pin
meelooo11-Apr-09 0:26
meelooo11-Apr-09 0:26 
GeneralRe: [ANN] Announcement: NUI C++ multi-platform appllication framework, 3D hardware GUI Pin
Rajesh R Subramanian11-Apr-09 0:31
professionalRajesh R Subramanian11-Apr-09 0:31 
QuestionGEt path of msi Pin
p_196010-Apr-09 23:46
p_196010-Apr-09 23:46 
AnswerRe: GEt path of msi Pin
Rajesh R Subramanian10-Apr-09 23:51
professionalRajesh R Subramanian10-Apr-09 23:51 
GeneralRe: GEt path of msi Pin
p_196010-Apr-09 23:53
p_196010-Apr-09 23:53 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.