10 Replies - 981 Views - Last Post: 21 October 2015 - 06:42 PM Rate Topic: -----

#1 marchingt9   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 20
  • Joined: 19-October 15

Help making program to read .exe file and output ASCII

Posted 19 October 2015 - 09:25 AM

I need to create a program that can open its own .exe file, read it, and display the ASCII code in the file. Any help would be appreciated.
Is This A Good Question/Topic? 0
  • +

Replies To: Help making program to read .exe file and output ASCII

#2 CTphpnwb   User is offline

  • D.I.C Lover
  • member icon

Reputation: 3802
  • View blog
  • Posts: 13,798
  • Joined: 08-August 08

Re: Help making program to read .exe file and output ASCII

Posted 19 October 2015 - 09:26 AM

ASCII != binary, and exe files are binary.
Was This Post Helpful? 0
  • +
  • -

#3 modi123_1   User is online

  • Suitor #2
  • member icon



Reputation: 14410
  • View blog
  • Posts: 57,781
  • Joined: 12-June 08

Re: Help making program to read .exe file and output ASCII

Posted 19 October 2015 - 09:28 AM

Why?

Typically 'compiled code' is not readable after compiling.
Was This Post Helpful? 0
  • +
  • -

#4 CTphpnwb   User is offline

  • D.I.C Lover
  • member icon

Reputation: 3802
  • View blog
  • Posts: 13,798
  • Joined: 08-August 08

Re: Help making program to read .exe file and output ASCII

Posted 19 October 2015 - 09:29 AM

Maybe there is some ASCII text in the executable that you're looking for? If that's the case, why?
Was This Post Helpful? 0
  • +
  • -

#5 marchingt9   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 20
  • Joined: 19-October 15

Re: Help making program to read .exe file and output ASCII

Posted 19 October 2015 - 10:12 AM

This is a project for class. This is the project
Write a program that reads its own ".cpp" file and counts the number of "{"s in the file.

Then write a program that reads its own ".exe" file and write out ONLY the ASCII codes contained therein.

I'm not looking to copy and paste, I just need help in knowing if I'm on the right track, and what the next step is.
I did not think the executable would be readable either.

I have done part 1 with the cpp file and the {'s

#include "stdafx.h"
#include <iostream>
#include <fstream>
#include <string>
using namespace std;

int _tmain(int argc, _TCHAR* argv[])
{
	string filename;
	string line;
	filename = "C:\\Users\\march_000\\Documents\\Visual Studio 2015\\Projects\\lab 5 part 2\\Debug";
	ifstream in(filename);
	while (!in.eof()) {
		getline(in, line);
		cout << line << "\n";
	}
	in.close();
	return 0;
}

This is what I have so far for part 2

This post has been edited by snoopy11: 19 October 2015 - 10:28 AM
Reason for edit:: added code tags please learn to use them !

Was This Post Helpful? 0
  • +
  • -

#6 CTphpnwb   User is offline

  • D.I.C Lover
  • member icon

Reputation: 3802
  • View blog
  • Posts: 13,798
  • Joined: 08-August 08

Re: Help making program to read .exe file and output ASCII

Posted 19 October 2015 - 10:25 AM

Here's a screenshot of the executable generated by the Hello World template that comes with Xcode. Lot's of ASCII mixed in with the code, but parsing it from the code? Maybe you could assume it's ASCII if the high bit isn't set, but I doubt it's that simple.

Attached image(s)

  • Attached Image

Was This Post Helpful? 0
  • +
  • -

#7 Salem_c   User is online

  • void main'ers are DOOMED
  • member icon

Reputation: 2219
  • View blog
  • Posts: 4,300
  • Joined: 30-May 10

Re: Help making program to read .exe file and output ASCII

Posted 19 October 2015 - 11:14 AM

Just read the file one byte at a time, and use 'isprint' in #include <cctype>

See also http://linux.die.net/man/1/strings

Oh, and it's something like
while ( getline(in, line) ) {
  // do something.
}


Your use of .eof() is incorrect.
Was This Post Helpful? 0
  • +
  • -

#8 marchingt9   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 20
  • Joined: 19-October 15

Re: Help making program to read .exe file and output ASCII

Posted 19 October 2015 - 11:43 AM

Thank I made that correction to the while and used #include <cctype>. How would I use isprint in this occasion?
Was This Post Helpful? 0
  • +
  • -

#9 Salem_c   User is online

  • void main'ers are DOOMED
  • member icon

Reputation: 2219
  • View blog
  • Posts: 4,300
  • Joined: 30-May 10

Re: Help making program to read .exe file and output ASCII

Posted 19 October 2015 - 11:56 AM

Go and read the manual page for isprint() would be a good start.
Was This Post Helpful? 0
  • +
  • -

#10 CTphpnwb   User is offline

  • D.I.C Lover
  • member icon

Reputation: 3802
  • View blog
  • Posts: 13,798
  • Joined: 08-August 08

Re: Help making program to read .exe file and output ASCII

Posted 19 October 2015 - 12:23 PM

Are you sure that no byte that is printable is not part of the executable code? Just because it looks like ASCII doesn't make it ASCII.
Was This Post Helpful? 0
  • +
  • -

#11 jjl   User is offline

  • Engineer
  • member icon

Reputation: 1270
  • View blog
  • Posts: 4,998
  • Joined: 09-June 09

Re: Help making program to read .exe file and output ASCII

Posted 21 October 2015 - 06:42 PM

First off, ASCII is binary...everything is binary. It's just based on how you interpret it that makes it ASCII. You need to clarify some things with your processor:

1) Am I supposed to located the string table (section where string constants are stored) in the executable and print that ASCII

OR

2) Am I simply supposed to print every byte that falls between the ASCII range (0-127)

If it is (2), then your task is quite simple

This post has been edited by jjl: 21 October 2015 - 06:44 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1