Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7655883
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T12:37:42+00:00 2026-05-31T12:37:42+00:00

I compiled the following four lines of code into a file called foo.exe, hoping

  • 0

I compiled the following four lines of code into a file called foo.exe, hoping that the value of the global variable ‘i’ (i.e, 9) would go into the data section of foo.exe

int i = 9;    
int main()
{
}

Then I used the following code to find out if it really was in the .data section of foo.exe, but didn’t find anything.. Can someone please explain me what went wrong..??

#include<iostream>
#include<Windows.h>
#include<stdio.h>
#include<WinNT.h>


int main()
{

HANDLE hFile;
HANDLE hFileMapping;
LPVOID lpFileBase;
PIMAGE_DOS_HEADER dosHeader;

hFile = CreateFile(TEXT("foo.exe"), GENERIC_READ, FILE_SHARE_READ, NULL,
                    OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);

if ( hFile == INVALID_HANDLE_VALUE )
{
    printf("Couldn't open file with CreateFile()\n");
    return 0;
}

hFileMapping = CreateFileMapping(hFile, NULL, PAGE_READONLY, 0, 0, NULL);
if ( hFileMapping == 0 )
{
    CloseHandle(hFile);
    printf("Couldn't open file mapping with CreateFileMapping()\n");
    return 0;
}

lpFileBase = MapViewOfFile(hFileMapping, FILE_MAP_READ, 0, 0, 0);
if ( lpFileBase == 0 )
{
    CloseHandle(hFileMapping);
    CloseHandle(hFile);
    printf("Couldn't map view of file with MapViewOfFile()\n");
    return 0;
}


PIMAGE_DOS_HEADER pimdh;
pimdh = (PIMAGE_DOS_HEADER)lpFileBase;

PIMAGE_NT_HEADERS pimnth;
pimnth = (PIMAGE_NT_HEADERS)((char *)lpFileBase + pimdh->e_lfanew);

PIMAGE_SECTION_HEADER pimsh;
pimsh = (PIMAGE_SECTION_HEADER)(pimnth + 1);

PIMAGE_IMPORT_DESCRIPTOR pimid;
long delta;

for(int i = 0; i<pimnth->FileHeader.NumberOfSections;i++)
{
    if(!strcmp((char *)pimsh->Name,".data"))
    {
        DWORD base = (DWORD)lpFileBase;
        for(DWORD start = pimsh ->PointerToRawData; start <= (pimsh->PointerToRawData + pimsh->SizeOfRawData); start++)
        {
            if(*((int *)(start + base)) == 9)
            {
                printf("found");
                break;
            }
        }
    }
    pimsh++;
}

}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T12:37:44+00:00Added an answer on May 31, 2026 at 12:37 pm

    The compiler (linker) did not put your variable in the image file because the variable is not even used in the code!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I come into a strange problem in pthread programming I've compiled the following code
When I compiled the following code, it shows that y and the beginning of
The following code compiled with MSVC9.0 runs and outputs Destructor four times, which is
I compiled the following code as a shared library using g++ -shared ... :
I have the following code compiled by gcc: #include <iostream> using namespace std; class
the following piece of C++ code compiled two years ago in a suse 10.1
The following code is generating warning C6284 when compiled with /analyze on MSVC 2008
Following code, when compiled and run with g++, prints '1' twice, whereas I expect
In Python compiled regex patterns have a findall method that does the following: Return
I have the following compiled query that I want to return a list of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.