wrong output ,error in my program
-
hi to everyone here is my code below and i am newbie to programming
#include"stdafx.h"
#include"windows.h"
#include"winnt.h"int APIENTRY WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int ncmdShow)
{
HANDLE hImage;
DWORD dwExitCode = 0;
IMAGE_DOS_HEADER imgdosh={0};
hImage = CreateFileA("E:\\kill.exe",GENERIC_READ,FILE_SHARE_READ,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL);if (INVALID\_HANDLE\_VALUE == hImage) { MessageBoxA(NULL,"invalid file","err",MB\_OK); } HANDLE hfilemaping = CreateFileMapping(hImage,NULL,PAGE\_READONLY,0,0,0); { if(!hfilemaping) { MessageBoxA(NULL,"Mapping Fails","err",MB\_OK); }
HANDLE ndmapview = MapViewOfFile(hfilemaping,FILE_MAP_READ,0,0,0);
if(!ndmapview)
{
MessageBoxA(NULL,"Mapping Fails","err",MB_OK);
}if (IMAGE_DOS_SIGNATURE != imgdosh.e_magic)
{
MessageBoxA(NULL,"not a dos file","Suuc",MB_OK);
}
if (IMAGE_DOS_SIGNATURE == imgdosh.e_magic)
{
MessageBoxA(NULL,"dos file","Suuc",MB_OK);
}return 0;
}}
Question - Test.exe is a PE file but my program returns me a msgbox that "it is not a dos file".? what is the mistake i have done please can anyone help me to figure out.? Regards 0x8085
-
hi to everyone here is my code below and i am newbie to programming
#include"stdafx.h"
#include"windows.h"
#include"winnt.h"int APIENTRY WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int ncmdShow)
{
HANDLE hImage;
DWORD dwExitCode = 0;
IMAGE_DOS_HEADER imgdosh={0};
hImage = CreateFileA("E:\\kill.exe",GENERIC_READ,FILE_SHARE_READ,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL);if (INVALID\_HANDLE\_VALUE == hImage) { MessageBoxA(NULL,"invalid file","err",MB\_OK); } HANDLE hfilemaping = CreateFileMapping(hImage,NULL,PAGE\_READONLY,0,0,0); { if(!hfilemaping) { MessageBoxA(NULL,"Mapping Fails","err",MB\_OK); }
HANDLE ndmapview = MapViewOfFile(hfilemaping,FILE_MAP_READ,0,0,0);
if(!ndmapview)
{
MessageBoxA(NULL,"Mapping Fails","err",MB_OK);
}if (IMAGE_DOS_SIGNATURE != imgdosh.e_magic)
{
MessageBoxA(NULL,"not a dos file","Suuc",MB_OK);
}
if (IMAGE_DOS_SIGNATURE == imgdosh.e_magic)
{
MessageBoxA(NULL,"dos file","Suuc",MB_OK);
}return 0;
}}
Question - Test.exe is a PE file but my program returns me a msgbox that "it is not a dos file".? what is the mistake i have done please can anyone help me to figure out.? Regards 0x8085
I have no idea on PE file reading. Wow, you are newbie and started coding with PE. :confused: where is your imgdosh correctly initialized? Did you miss any code for that? You initialized to 0 in the beginning, there is no code to set the values to it and you are checking for if(IMAGE_DOS_SIGNATURE != imgdosh.e_magic). Is this correct or am I missing something?
-
hi to everyone here is my code below and i am newbie to programming
#include"stdafx.h"
#include"windows.h"
#include"winnt.h"int APIENTRY WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int ncmdShow)
{
HANDLE hImage;
DWORD dwExitCode = 0;
IMAGE_DOS_HEADER imgdosh={0};
hImage = CreateFileA("E:\\kill.exe",GENERIC_READ,FILE_SHARE_READ,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL);if (INVALID\_HANDLE\_VALUE == hImage) { MessageBoxA(NULL,"invalid file","err",MB\_OK); } HANDLE hfilemaping = CreateFileMapping(hImage,NULL,PAGE\_READONLY,0,0,0); { if(!hfilemaping) { MessageBoxA(NULL,"Mapping Fails","err",MB\_OK); }
HANDLE ndmapview = MapViewOfFile(hfilemaping,FILE_MAP_READ,0,0,0);
if(!ndmapview)
{
MessageBoxA(NULL,"Mapping Fails","err",MB_OK);
}if (IMAGE_DOS_SIGNATURE != imgdosh.e_magic)
{
MessageBoxA(NULL,"not a dos file","Suuc",MB_OK);
}
if (IMAGE_DOS_SIGNATURE == imgdosh.e_magic)
{
MessageBoxA(NULL,"dos file","Suuc",MB_OK);
}return 0;
}}
Question - Test.exe is a PE file but my program returns me a msgbox that "it is not a dos file".? what is the mistake i have done please can anyone help me to figure out.? Regards 0x8085
0x8085 wrote:
Test.exe
what is that file ? is it the same as "kill.exe" that is written in the example ? What makes you think that creating an file makes it a PE (Portable Executable) file ? anyway, you do nothing with
imgdosh
...Watched code never compiles.
-
I have no idea on PE file reading. Wow, you are newbie and started coding with PE. :confused: where is your imgdosh correctly initialized? Did you miss any code for that? You initialized to 0 in the beginning, there is no code to set the values to it and you are checking for if(IMAGE_DOS_SIGNATURE != imgdosh.e_magic). Is this correct or am I missing something?
-
0x8085 wrote:
Test.exe
what is that file ? is it the same as "kill.exe" that is written in the example ? What makes you think that creating an file makes it a PE (Portable Executable) file ? anyway, you do nothing with
imgdosh
...Watched code never compiles.
hi, Kill.exe is a small PE file with a function to display message box hello world. i want to create a file to an application to check whether the file is a pe file or not. for that i started with a first step of verifying the dos signature. you change the path "e:\\kill.exe" to any pe file it will compile. regards 0x8085
-
hi to everyone here is my code below and i am newbie to programming
#include"stdafx.h"
#include"windows.h"
#include"winnt.h"int APIENTRY WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int ncmdShow)
{
HANDLE hImage;
DWORD dwExitCode = 0;
IMAGE_DOS_HEADER imgdosh={0};
hImage = CreateFileA("E:\\kill.exe",GENERIC_READ,FILE_SHARE_READ,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL);if (INVALID\_HANDLE\_VALUE == hImage) { MessageBoxA(NULL,"invalid file","err",MB\_OK); } HANDLE hfilemaping = CreateFileMapping(hImage,NULL,PAGE\_READONLY,0,0,0); { if(!hfilemaping) { MessageBoxA(NULL,"Mapping Fails","err",MB\_OK); }
HANDLE ndmapview = MapViewOfFile(hfilemaping,FILE_MAP_READ,0,0,0);
if(!ndmapview)
{
MessageBoxA(NULL,"Mapping Fails","err",MB_OK);
}if (IMAGE_DOS_SIGNATURE != imgdosh.e_magic)
{
MessageBoxA(NULL,"not a dos file","Suuc",MB_OK);
}
if (IMAGE_DOS_SIGNATURE == imgdosh.e_magic)
{
MessageBoxA(NULL,"dos file","Suuc",MB_OK);
}return 0;
}}
Question - Test.exe is a PE file but my program returns me a msgbox that "it is not a dos file".? what is the mistake i have done please can anyone help me to figure out.? Regards 0x8085
Looks like you are taking code from other places and kinda skipping a few important details about some of the functions you are using from the winsdk such as:
Return Value
If the function succeeds, the return value is the starting address of the mapped view.
If the function fails, the return value is NULL. To get extended error information, call GetLastError.
From the msdn, this will solve your problem.
-
hi, Kill.exe is a small PE file with a function to display message box hello world. i want to create a file to an application to check whether the file is a pe file or not. for that i started with a first step of verifying the dos signature. you change the path "e:\\kill.exe" to any pe file it will compile. regards 0x8085
Some time back I read Vijay mukhi's website on PE files. I thought it was not my world and left it. Here is the link if it can help you: http://www.vijaymukhi.com/security/windows/pefile.htm[^] The return type of MapViewOfFile() is LPVOID. Check it out if it can cause any issue.
-
Some time back I read Vijay mukhi's website on PE files. I thought it was not my world and left it. Here is the link if it can help you: http://www.vijaymukhi.com/security/windows/pefile.htm[^] The return type of MapViewOfFile() is LPVOID. Check it out if it can cause any issue.