Solved kanker ifstream

Hexui Undetected CSGO Cheats Sinkicheat PUBG Cheat

Roman_Ablo

Banned
Feb 27, 2017
355
2,402
1
so i was trying to read an exe file but when I ran it I got fuckig E A R R A P E D with like 100 beeps
I heard its caused by some gay characters but i dont want a way around it, im looking to also read those but idk how

here's my shitty code
C++:
std::string dump(std::string path)
{
	std::ifstream in;
	in.open(path, std::ios::in | std::ios::binary);
	std::string hex((std::istreambuf_iterator<char>(in)), std::istreambuf_iterator<char>());
	if (hex.length() <= 1) return false;
	in.close();
	path.clear();
	return hex;
}
the beeps godamn jumpscared me almost dropped a fried chicken piece on the floor
 

bitm0de

Newbie
Full Member
Feb 28, 2016
19
358
2
W O W, T H A N K S F O R R E V I V I N G T H I S!

I figured it out loooong time ago

also, lol, who gives 2 shits if that code could fail once a christmas when it works perfectly for mein needs? are we on stackoverflow?
This is a comment that I would expect from a noobie who hasn't been working with a programming language long enough to see what kinds of adverse effects writing unsafe code does in which makes too many assumptions. There was an unanswered question from your last post so I answered it since you provided no indication that you actually figured it out. It's not that old given the average last post dates on most of the threads in here too so I figured it was just a fairly inactive section.

It's not really pointless but I agree that the conversion into a UINT_PTR is wrong. UINT_PTR is no pointer type though. It's just an unsigned integral data type with the size of a pointer.
The main problem was that operator new[] takes a size_t where tellg() returns an std::streampos (24 bytes in size) which - just as converting it into an UINT_PTR or size_t - will at least result in warning which is why I prefer to manually convert it into the correct type. If there's a better way to properly convert it tell me.
I didn't mean pointer type literally as in a typedef for a pointer of some type, but an alias for a type that is mainly used for dealing with pointers (in this case as an integer rather than a pointer address).

You don't need to convert it at all. No warnings here:
C++:
#include <fstream>

int main()
{
    std::ifstream ifs("test.txt", std::ifstream::binary);
    ifs.seekg (0, ifs.end);
    int *arr = new int[ifs.tellg()];
    delete [] arr;
}
And streampos is not relevant here, the () operator returns a streamoff which is a typedef for long long. You're not passing the std::streampos into there for the size of the array, you don't fully understand how std::fpos is implemented.







So yes it is fairly pointless.
 
Last edited:

Broihon

edgy 12 y/o
Escobar Tier VIP
Fleep Tier Donator
Dec 22, 2013
1,746
40,528
316
C++:
std::ifstream File(szFile, std::ios::binary | std::ios::ate);
auto FileSize = File.tellg();
BYTE * pData = new BYTE[static_cast<UINT_PTR>(FileSize)];
File.seekg(0, std::ios::beg);
File.read(ReCa<char*>(pData), FileSize);
File.close();
At least that's how I do it.
 

Roman_Ablo

Banned
Feb 27, 2017
355
2,402
1
meet me in the swamp

it only displays the type of the file like itf its an exe is that NZ shit and for png its like PNG shit

kill it
 

Broihon

edgy 12 y/o
Escobar Tier VIP
Fleep Tier Donator
Dec 22, 2013
1,746
40,528
316
Well, if you print the BYTE* buffer to the console it'll treat the values as chars and terminate the string at the first 0 of course.
 

bitm0de

Newbie
Full Member
Feb 28, 2016
19
358
2
C++:
std::ifstream File(szFile, std::ios::binary | std::ios::ate);
auto FileSize = File.tellg();
BYTE * pData = new BYTE[static_cast<UINT_PTR>(FileSize)];
File.seekg(0, std::ios::beg);
File.read(ReCa<char*>(pData), FileSize);
File.close();
At least that's how I do it.
Why are you casting the result to a UINT_PTR? There's no need for that to determine the size of the array, that's pointless. :S You don't need to cast it to use it for the dynamic array allocation size, and you're casting something which has the potential to be -1 on failure, to an unsigned type. I've also never seen someone cast something that is supposed to represent a LENGTH, to a pointer type...

@OP - those beeps if you are writing binary data to the console (not sure why you would though) are the result of special characters that are intended to cause beeps when written to the console from old legacy stuff mainly as an easy way to provide audible indications of something.

C++:
std::cout << "\x07" << std::endl;
You can do the same from a batch script.
 
Last edited:

Roman_Ablo

Banned
Feb 27, 2017
355
2,402
1
W O W, T H A N K S F O R R E V I V I N G T H I S!

I figured it out loooong time ago

also, lol, who gives 2 shits if that code could fail once a christmas when it works perfectly for mein needs? are we on stackoverflow?
 

Broihon

edgy 12 y/o
Escobar Tier VIP
Fleep Tier Donator
Dec 22, 2013
1,746
40,528
316
Why are you casting the result to a UINT_PTR? There's no need for that to determine the size of the array, that's pointless. :S You don't need to cast it to use it for the dynamic array allocation size, and you're casting something which has the potential to be -1 on failure, to an unsigned type. I've also never seen someone cast something that is supposed to represent a LENGTH, to a pointer type...
It's not really pointless but I agree that the conversion into a UINT_PTR is wrong. UINT_PTR is no pointer type though. It's just an unsigned integral data type with the size of a pointer.
The main problem was that operator new[] takes a size_t where tellg() returns an std::streampos (24 bytes in size) which - just as converting it into an UINT_PTR or size_t - will at least result in warning which is why I prefer to manually convert it into the correct type. If there's a better way to properly convert it tell me.
 

Traxin

Escobar Tier VIP
Dank Tier Donator
Aug 3, 2015
1,041
25,378
154
This is a comment that I would expect from a noobie who hasn't been working with a programming language long enough to see what kinds of adverse effects writing unsafe code does in which makes too many assumptions. There was an unanswered question from your last post so I answered it since you provided no indication that you actually figured it out. It's not that old given the average last post dates on most of the threads in here too so I figured it was just a fairly inactive section.
Don't mind him, he's fairly retarded.
 

Broihon

edgy 12 y/o
Escobar Tier VIP
Fleep Tier Donator
Dec 22, 2013
1,746
40,528
316
I didn't mean pointer type literally as in a typedef for a pointer of some type, but an alias for a type that is mainly used for dealing with pointers (in this case as an integer rather than a pointer address).

You don't need to convert it at all. No warnings here:
C++:
#include <fstream>

int main()
{
    std::ifstream ifs("test.txt", std::ifstream::binary);
    ifs.seekg (0, ifs.end);
    int *arr = new int[ifs.tellg()];
    delete [] arr;
}
And streampos is not relevant here, the () operator returns a streamoff which is a typedef for long long. You're not passing the std::streampos into there for the size of the array, you don't fully understand how std::fpos is implemented.







So yes it is fairly pointless.
That's weird, the definitions in my files are completely different and I get warnings for doing exactly that. Otherwise I wouldn't have done the conversion. Anyway thanks for clearing this up.
 
Last edited:
Attention! Before you post:

Read the How to Ask Questions Guide
99% of questions are answered in the Beginner's Guide, do it before asking a question.

No Hack Requests. Post in the correct section.  Search the forum first. Read the rules.

How to make a good post:

  • Fill out the form correctly
  • Tell us the game name & coding language
  • Post everything we need to know to help you
  • Ask specific questions, be descriptive
  • Post errors, line numbers & screenshots
  • Post code snippets using code tags
  • If it's a large project, zip it up and attach it

If you do not comply, your post may be deleted.  We want to help, please make a good post and we will do our best to help you.

Community Mods