fgets linux

This is a discussion on fgets linux within the C Programming forums, part of the General Programming Boards category; Dear all, I'm trying to use fgets to read in Hex value for eg: 34120A I enter this as an ...

  1. #1
    Registered User
    Join Date
    Mar 2008
    Posts
    7

    fgets linux

    Dear all,

    I'm trying to use fgets to read in Hex value for eg: 34120A

    I enter this as an input, "\x34\x12\x0a"

    However I keep getting 5C 78 33 34 in the memory which are the char of \x34
    What should I do to force it to display 34 in the memory?

    I have to use fgets

    Thank you in advance

  2. #2
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    your string array doesn't know stink about hex values. if you want it to have 34120A, then don't iinput \x char's.

    Just enter 34, and deal with them from there.

  3. #3
    Registered User
    Join Date
    Mar 2008
    Posts
    7
    I need the memory value to appear as 0x08048760

    however if I just type 08048760, the memory will show 30 38 30 34 ..... (0 8 0 4 8 ....) instead

  4. #4
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Right. That's what I'm saying. Char strings know zip about hex values.

    STOP trying to get them hex smart.

    You know we have functions in C to change a string into an int, or a long, or a float, right?

    You need a function that will change a string into a hex number. Isn't that your assignment here, to write that function to change a string into a hex number?

  5. #5
    Registered User
    Join Date
    Mar 2008
    Posts
    7
    char shellcode[]=
    "\xeb\x17\x5e\x89\x76\x08\x31\xc0\x88\x46\x07\x89\ x46\x0c\xb0\x0b\x89\xf3\x8d"
    "\x4e\x08\x31\xd2\xcd\x80\xe8\xe4\xff\xff\xff\x2f\ x62\x69\x6e\x2f\x73\x68\x58";

    how come the above code can work? Why doesn't \x prefix working with fgets since it is saved in the char buffer too?

  6. #6
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Because they're sending that string's contents into a program or function, that understands how to work with hex values.

    What you're doing is looking at the memory of the string, and saying "it's a char's value!"

    Well, what else could it be? When you look at an elephant, it looks like - an elephant, right?

  7. #7
    Captain Crash brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,274
    Let's allow the "hacker" to remain confused, eh?
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

  8. #8
    a_capitalist_story
    Join Date
    Dec 2007
    Posts
    2,657
    Thanks for the dose of sanity, brewbuck!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Linux
    By cerin in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 02-10-2005, 09:41 PM
  2. installing linux for the first time
    By Micko in forum Tech Board
    Replies: 9
    Last Post: 12-06-2004, 05:15 AM
  3. Linux for Windows!
    By Strut in forum Linux Programming
    Replies: 2
    Last Post: 12-25-2002, 11:36 AM
  4. Linux? Windows Xp?
    By VooDoo in forum Linux Programming
    Replies: 15
    Last Post: 07-31-2002, 09:18 AM
  5. linux vs linux?
    By Dreamerv3 in forum Linux Programming
    Replies: 5
    Last Post: 01-22-2002, 09:39 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21