Page 2 of 2 FirstFirst 12
Results 21 to 37 of 37

Thread: Can somebody show how to read bytes?

  1. #21
    Join Date
    Oct 2010
    Location
    Berlin, Germany
    Posts
    358
    Thanks
    18
    Thanked 68 Times in 66 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Can somebody show how to read bytes?

    Quote Originally Posted by "BumbleBee" View Post
    .btw,your code makes an infinite loop....
    where is that infinite loop? I don't see any...

  2. #22
    Join Date
    Jan 2011
    Posts
    128
    Thanks
    2

    Default Re: Can somebody show how to read bytes?

    Qt Code:
    1. #include "StdAfx.h"
    2. #include <iostream>
    3. #include <string.h>
    4. using namespace std;
    5.  
    6. void encrypt_data();
    7.  
    8. int main()
    9. {
    10. FILE * f;
    11. unsigned char buffer[100];
    12. int n;
    13.  
    14. f = fopen("C:\\Program Files (x86)\\TeamViewer\\Version6\\TeamViewer.exe", "rb");
    15. if (f)
    16. {
    17. n = fread(buffer, 100, 1, f);
    18. for (int c = 0; c <= 100 ; c++)
    19. {
    20. printf("%.2X ", (int)buffer[c]); //outputs hex!!!!!!
    21. // put an extra space between every 4 bytes
    22. if (c % 4 == 3)
    23. {
    24. printf(" ");
    25. }
    26.  
    27. // Display 16 bytes per line
    28. if (c % 16 == 15)
    29. {
    30. printf("\n");
    31. }
    32. }
    33. // Add an extra line feed for good measure
    34. printf("\n\n\n");
    35. }
    36. else
    37. {
    38. cout << "error";
    39. }
    40.  
    41. char a;
    42. cin >> a;
    43. return 0;
    44. }
    To copy to clipboard, switch view to plain text mode 

    I want to make that in Qt^^^

    And FelixB the loop doesn't stop for me.

  3. #23
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Can somebody show how to read bytes?

    Quote Originally Posted by "BumbleBee" View Post
    btw,your code makes an infinite loop....
    There is no infinite loop in my code.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  4. #24
    Join Date
    Oct 2010
    Location
    Berlin, Germany
    Posts
    358
    Thanks
    18
    Thanked 68 Times in 66 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Can somebody show how to read bytes?

    Quote Originally Posted by "BumbleBee" View Post
    And FelixB the loop doesn't stop for me.
    which loop do you mean?

  5. #25
    Join Date
    Jan 2011
    Posts
    128
    Thanks
    2

    Default Re: Can somebody show how to read bytes?

    it keeps outputting bytes....never stops.

  6. #26
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Can somebody show how to read bytes?

    Quote Originally Posted by "BumbleBee" View Post
    it keeps outputting bytes....never stops.
    Maybe try pointing the program to a smaller file?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  7. #27
    Join Date
    Jan 2011
    Posts
    128
    Thanks
    2

    Default Re: Can somebody show how to read bytes?

    Accually yes.It works with a smaller one.
    Thank you for this,could you comment a bit the lines?
    Thanks.

  8. #28
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Can somebody show how to read bytes?

    Quote Originally Posted by "BumbleBee" View Post
    Thank you for this,could you comment a bit the lines?
    No, I couldn't. It's so trivial there is nothing to comment. If you have specific questions then ask and I'm sure somebody will provide an explanation.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  9. #29
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Can somebody show how to read bytes?

    Quote Originally Posted by "BumbleBee" View Post
    I need to take the hex,in order to encrypt it and save it as a new exe...btw,your code makes an infinite loop....
    Why do you want to encrypt the hex (text) version of a binary file? Why not just encrypt the binary version? Converting to text first makes no sense...

  10. #30
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Can somebody show how to read bytes?

    Maybe he wants to encrypt twice as much as he needs to? It's always fun to make a 10MB file out of a 5MB file...
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  11. #31
    Join Date
    Jan 2011
    Posts
    128
    Thanks
    2

    Default Re: Can somebody show how to read bytes?

    Quote Originally Posted by squidge View Post
    Why do you want to encrypt the hex (text) version of a binary file? Why not just encrypt the binary version? Converting to text first makes no sense...
    You mean like this?
    Qt Code:
    1. QByteArray byte = file.read(16);
    To copy to clipboard, switch view to plain text mode 

  12. #32
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Can somebody show how to read bytes?

    Quote Originally Posted by "BumbleBee" View Post
    You mean like this?
    Qt Code:
    1. QByteArray byte = file.read(16);
    To copy to clipboard, switch view to plain text mode 
    Yes, exactlly.

  13. #33
    Join Date
    Jan 2011
    Posts
    128
    Thanks
    2

    Default Re: Can somebody show how to read bytes?

    This outputs some strange symbols(I suppose bin. code),but it also beeps and crashes after some secs...

  14. #34
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Can somebody show how to read bytes?

    Do you want to encrypt it or print it? I doubt encrypting it outputs any strange symbols or makes any sounds. This is binary data that is not suitable for printing to a text terminal.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  15. #35
    Join Date
    Jan 2011
    Posts
    128
    Thanks
    2

    Default Re: Can somebody show how to read bytes?

    Well,crypt it of course,but I want to out put it,to make sure,everything works...and that I will encrypt the data I need.!

  16. #36
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Can somebody show how to read bytes?

    So encrypt the binary data but output it to a terminal as hex for the before and after.

  17. #37
    Join Date
    Jan 2011
    Posts
    128
    Thanks
    2

    Default Re: Can somebody show how to read bytes?

    Yup.
    Thanks guys for the support,help and sorry for the dump question...

Similar Threads

  1. Replies: 2
    Last Post: 9th June 2010, 17:08
  2. How to read only a certain amount of bytes
    By Morea in forum Qt Programming
    Replies: 1
    Last Post: 28th January 2009, 08:38
  3. socket read/write bytes
    By nowire75 in forum Newbie
    Replies: 3
    Last Post: 5th July 2007, 00:12
  4. How to read more bytes using QTcpSocket?
    By vishesh in forum Qt Programming
    Replies: 1
    Last Post: 3rd July 2007, 21:23
  5. How to write bytes read from serial port to a QFile
    By shamik in forum Qt Programming
    Replies: 19
    Last Post: 25th June 2007, 15:12

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.