Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6539963
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T10:55:16+00:00 2026-05-25T10:55:16+00:00

Good evening, I wrote the code below in C to read and print from

  • 0

Good evening,

I wrote the code below in C to read and print from a binary file a random hexadecimal string with a constant length, knowing a certain offset and the location of the string regarding the offset.

FILE *f = NULL;
unsigned char *buffer = NULL;
unsigned long fileLen;        
unsigned char bytes[] = {0x22, 0x22, 0x22, 0x22};

f = fopen(argv[1], "rb");
if (!f) 
{
    fprintf(stderr, "Unable to open %s\n", argv[1]);
    return -1;
}

fseek(f, 0, SEEK_END);
fileLen=ftell(f);
fseek(f, 0, SEEK_SET);

buffer=malloc(fileLen);
if (!buffer) 
{
    fprintf(stderr, "Memory error!\n");
    fclose(f);
    return -1;
}

fread(buffer, fileLen, 1, f);
fclose(f);

unsigned int *p = memmem(buffer, fileLen, bytes, 4);

if (!p) {

    return -1;
}

unsigned long off_to_string = 4 + 0x12 + ((void *)p) - ((void *)buffer);

for (unsigned long c = off_to_string; c < off_to_string+0x30; c++)
{
    printf("%.2X", (int)buffer[c]);
}

printf("\n");
free(buffer);

I would like to use this code in a Cocoa app, I tried to make something like:

NSMutableString *tehString = [[NSMutableString alloc] init];

for (unsigned long c = off_to_string; c < off_to_string+0x30; c++)
{
    [tehString appendString:...]
}

the problem is I must pass a NSString to appendString: and I don’t even know how to print its hexadecimal representation.

Thanks !

PS: Feel free to improve the code of the “hexadecimal string reader” 🙂

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T10:55:17+00:00Added an answer on May 25, 2026 at 10:55 am

    NSStrings can be created using the same string format specifiers.

    so you could do this:

    [tehString appendString:[NSString stringWithFormat:@"%.2X", (int)buffer[c]]];
    

    caveat: I’ve just typed that in so it might be a little off – but you get the idea.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Good evening everyone, I am using a JavaScript to load/override content from an HTML-File
Good evening, I'm trying to send a XMFLOAT3X3 to a constant buffer (see code
Good evening, i need to know how can i have one .h file that
Good evening :-)! I have this code to use Drag & Drop method for
Good evening, I created a class which inherits from UIViewController and i created a
Good evening, Following is the code I used for reading the files and folders
This is program is input some string from a file, then, push strings into
Good evening. This code works. It sorts an array of cards by both Suit
Good evening I've got a little problem with my DataGridView in a .NET Windows
Good evening, In my app that I'm currently developing, I have a class that

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.