Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


[C++] 1/2 Working hex editor

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
Chaosis13
Master Cheater
Reputation: 0

Joined: 14 Aug 2007
Posts: 372

PostPosted: Mon Jul 14, 2008 9:43 pm    Post subject: [C++] 1/2 Working hex editor Reply with quote

I made a hex editor awhile ago, and it was shit. A few min ago I almost completely re-wrote it, using none of its old code. I fixed a problem with ASCII, but my the part that displays the hex doesn't work right. Every now and then it displays abunch of F's before a byte like this:
Code:
4D 5A FFFFFF90 00 03 00 00 00 04 00 00 00 FFFFFFFF FFFFFFFF 00 00 FFFFFFB8 00 00

It should look like this:
Code:
4D 5A 90 00 03 00 00 00 04 00 00 00 FF FF 00 00 B8 00 00


Here is a portion of my source code, which should compile (name hex.cpp/hex.exe):
Code:
#include <iostream>
#include <fstream>
#include <windows.h>
using namespace std;
int main() {
    unsigned long int i = 0;
    cout.unsetf(ios::dec);
    cout.setf(ios::uppercase | /*ios::showbase |*/ ios::hex);
    ifstream ino("hex.exe", ios::in | ios::binary);
    int count = 0;
    char c[999999];
    while(!ino.eof()){
                   ino.get(c[i]);
                   if (c[i]==0)cout << hex << "00 ";
                   else if (c[i]==1)cout << "01 ";
                   else if (c[i]==2)cout << "02 ";
                   else if (c[i]==3)cout << "03 ";
                   else if (c[i]==4)cout << "04 ";
                   else if (c[i]==5)cout << "05 ";
                   else if (c[i]==6)cout << "06 ";
                   else if (c[i]==7)cout << "07 ";
                   else if (c[i]==8)cout << "08 ";
                   else if (c[i]==9)cout << "09 ";
                   else if (c[i]==10)cout << "0A ";
                   else if (c[i]==11)cout << "0B ";
                   else if (c[i]==12)cout << "0C ";
                   else if (c[i]==13)cout << "0D ";
                   else if (c[i]==14)cout << "0E ";
                   else if (c[i]==15)cout << "0F ";
                   else cout << (DWORD)c[i] << " ";
                   i++;
                   Sleep(25);
    }   
   
    return 0;
}


And I attached the program and source, which will open itself and output the hex.

PLZ HELP! Very Happy



The Extension 'rar' was deactivated by an board admin, therefore this Attachment is not displayed.

Back to top
View user's profile Send private message
jackyyll
Expert Cheater
Reputation: 0

Joined: 28 Jan 2008
Posts: 143
Location: here

PostPosted: Mon Jul 14, 2008 9:57 pm    Post subject: Reply with quote

Didn't look at the source, but when displaying each byte do this:
Code:

printf("%0.2hX ", ( theByte & 0xFF ) );


EDIT:
Looked at the code you put in your post, :S, please don't do that it hurts my eyes and brain XD No need to match each decimal and then display it as text, using printf (same as above) you can easily display it as hex.
Back to top
View user's profile Send private message AIM Address MSN Messenger
Chaosis13
Master Cheater
Reputation: 0

Joined: 14 Aug 2007
Posts: 372

PostPosted: Mon Jul 14, 2008 9:59 pm    Post subject: Reply with quote

kk, and the source is what I posted. But it also includes the program.

EDIT:
HOLY SHIT! It works!

Maybe I should learn more C.... Very Happy
Back to top
View user's profile Send private message
jackyyll
Expert Cheater
Reputation: 0

Joined: 28 Jan 2008
Posts: 143
Location: here

PostPosted: Mon Jul 14, 2008 10:40 pm    Post subject: Reply with quote

Hehe, now for your next challenge. Make it display 16 bytes in hex and those 16 bytes in ASCII per line.. It's a bit of a brain teaser Razz

i.e
Code:

41 41 41 41 41 41 41 41 41 41 41 41 41 41 41 41    AAAAAAAAAAAAAAAA
42 42 42 42 42 42 42 42 42 42 42 42 42 42 42 42    BBBBBBBBBBBBBBBB
...
Back to top
View user's profile Send private message AIM Address MSN Messenger
Dark Byte
Site Admin
Reputation: 475

Joined: 09 May 2003
Posts: 25982
Location: The netherlands

PostPosted: Tue Jul 15, 2008 1:16 am    Post subject: Reply with quote

Hint, do a check if the value is bigger or equal to 32
Lower contain 'control' characters, like line break, delete, cursorpos left/right/up/down, backspace, etc...
You really do NOT want to display them. I recommend just writing a . or a empty space in those cases

_________________
Tools give you results. Knowledge gives you control.

Like my help? Join me on Patreon so i can keep helping
Back to top
View user's profile Send private message MSN Messenger
jackyyll
Expert Cheater
Reputation: 0

Joined: 28 Jan 2008
Posts: 143
Location: here

PostPosted: Tue Jul 15, 2008 1:39 am    Post subject: Reply with quote

x0r wrote:
Dark Byte wrote:
Hint, do a check if the value is bigger or equal to 32
Lower contain 'control' characters, like line break, delete, cursorpos left/right/up/down, backspace, etc...
You really do NOT want to display them. I recommend just writing a . or a empty space in those cases

IsCharAlpha Smile


if ( theByte >= 0x20 )
{
...
}

works fine too Smile

But i suppose, to each his own.
Back to top
View user's profile Send private message AIM Address MSN Messenger
Symbol
I'm a spammer
Reputation: 0

Joined: 18 Apr 2007
Posts: 5094
Location: Israel.

PostPosted: Tue Jul 15, 2008 3:33 am    Post subject: Reply with quote

Use IsCharAlphaNumeric to check if the character is either numerical or alphabetical.
Back to top
View user's profile Send private message
Jani
Grandmaster Cheater
Reputation: 2

Joined: 29 Dec 2006
Posts: 804

PostPosted: Tue Jul 15, 2008 4:43 am    Post subject: Reply with quote

Back to the original problem :p If you're going to do it the C++ way (or something):
Code:
std::cout.flags( std::ios_base::hex | std::ios_base::uppercase );
int i = file.get();

while( !file.eof() ) {
   std::cout << std::setw(2) << std::setfill('0') << i << " ";
   i = file.get();
}
Back to top
View user's profile Send private message
samuri25404
Grandmaster Cheater
Reputation: 7

Joined: 04 May 2007
Posts: 955
Location: Why do you care?

PostPosted: Tue Jul 15, 2008 7:07 am    Post subject: Reply with quote

Code:

BYTE b;

//...

cout << hex << b << endl;


Came across the "hex" modifier recently, figured you might like it.

_________________
Wiccaan wrote:

Oh jeez, watchout I'm a bias person! Locked.


Auto Assembly Tuts:
In Depth Tutorial on AA
Extended
Back to top
View user's profile Send private message
jackyyll
Expert Cheater
Reputation: 0

Joined: 28 Jan 2008
Posts: 143
Location: here

PostPosted: Tue Jul 15, 2008 10:21 am    Post subject: Reply with quote

x0r wrote:
jackyyll wrote:
if ( theByte >= 0x20 )
{
...
}

works fine too Smile

But i suppose, to each his own.

That isn't UNICODE compliant.


Hmm, suppose you are right there Very Happy
Back to top
View user's profile Send private message AIM Address MSN Messenger
Chaosis13
Master Cheater
Reputation: 0

Joined: 14 Aug 2007
Posts: 372

PostPosted: Tue Jul 15, 2008 11:15 am    Post subject: Reply with quote

Ik how to do IO and stuff, but I was just getting some wierd results. Ty for all your help.
Back to top
View user's profile Send private message
Jani
Grandmaster Cheater
Reputation: 2

Joined: 29 Dec 2006
Posts: 804

PostPosted: Tue Jul 15, 2008 12:39 pm    Post subject: Reply with quote

samuri25404 wrote:
Came across the "hex" modifier recently, figured you might like it.
Going offtopic again.. :p Anyway, if you liked that, you might like other manipulators too: http://www.cplusplus.com/reference/iostream/manipulators/
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites