Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. wrong output ,error in my program

wrong output ,error in my program

Scheduled Pinned Locked Moved C / C++ / MFC
questionhelp
8 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • 0 Offline
    0 Offline
    0x8085
    wrote on last edited by
    #1

    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

    M M E 3 Replies Last reply
    0
    • 0 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

      M Offline
      M Offline
      mk14882
      wrote on last edited by
      #2

      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?

      0 1 Reply Last reply
      0
      • 0 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

        M Offline
        M Offline
        Maximilien
        wrote on last edited by
        #3

        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.

        0 1 Reply Last reply
        0
        • M mk14882

          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?

          0 Offline
          0 Offline
          0x8085
          wrote on last edited by
          #4

          Hi mk14882, thanks for replying. yes that was the mistake i think .. but i dint know how to fix it..still i am going googling for it. Regards 0x8085

          1 Reply Last reply
          0
          • 0 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

            E Offline
            E Offline
            elchupathingy
            wrote on last edited by
            #5

            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.

            1 Reply Last reply
            0
            • M Maximilien

              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.

              0 Offline
              0 Offline
              0x8085
              wrote on last edited by
              #6

              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

              M 1 Reply Last reply
              0
              • 0 0x8085

                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

                M Offline
                M Offline
                mk14882
                wrote on last edited by
                #7

                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.

                0 1 Reply Last reply
                0
                • M mk14882

                  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.

                  0 Offline
                  0 Offline
                  0x8085
                  wrote on last edited by
                  #8

                  hi mk14882, Thanks a lot.. I think this would help me.. thank you once again.. I will check it and let you know. Regards 0x8085

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups