Embed text in C code


Login or Register to Reply

 
Thread Tools Search this Thread
# 1  
Old 09-13-2018
Embed text in C code

I hope c coding is ok here.

I am fairly new at c coding.

I simply want to embed some text in the executable.

I tried this but can't find the text using Ghex.

Code:
#include <stdio.h>
const char * S = "andrew";

int main()
{
printf("Hello World!\n");
return 0;
}

# 2  
Old 09-13-2018
Code:
#include <stdio.h>

const char *str = "andrew";

int main()
{
  printf("Hello World! %s\n", str);
  return 0;
}

This User Gave Thanks to milhan For This Post:
drew77 (09-13-2018)
# 3  
Old 09-13-2018
Quote:
Originally Posted by drew77
I simply want to embed some text in the executable.

I tried this but can't find the text using Ghex.

Code:
#include <stdio.h>
const char * S = "andrew";

int main()
{
printf("Hello World!\n");
return 0;
}

Text strings won't be embedded in the code, they will reside in the data segment.
# 4  
Old 09-13-2018
Ok.

Can I get it embedded in the code segment where it will be near the top when viewed with a hex editor?
# 5  
Old 09-17-2018
Tricky. Most large-scale architectures separate data and code.

What you might be able to find is the value of the pointer.

Code:
#include <stdio.h>

int main(void)
{
        printf("%p\n", "fixed text");
}

Compile and run that and you'll be given a hexadecimal value. Search for that value in the code segment and you won't find the text itself, but you'll find something which uses it.
# 6  
Old 10-27-2018
Embedding a text file in C code. Therefore it might be easier if you just load the text from a file at runtime, or embed the text directly into the code.

Code:
int main()
{
    const char* text = "
#include "file.txt"
";
    printf("%s", text);
    return 0;

Moderator's Comments:
Mod Comment Added code tags. Please use them per forum rules.
# 7  
Old 10-27-2018
Code:
Embedded_Text.c:3:17: warning: unused variable ‘text’ [-Wunused-variable]
     const char* text = "

Login or Register to Reply

|
Thread Tools Search this Thread
Search this Thread:
Advanced Search

More UNIX and Linux Forum Topics You Might Find Helpful
Embed image to the html script ATWC Shell Programming and Scripting 8 02-06-2018 03:31 PM
How to embed sql query into our shell script? arghadeep adity Shell Programming and Scripting 1 03-05-2014 07:05 AM
Need help on uploading Video files on Mediawiki and embed to page sunnysthakur UNIX and Linux Applications 1 12-04-2013 11:16 AM
Embed tcl in ksh93 script gio001 UNIX for Advanced & Expert Users 3 02-19-2013 12:37 PM
Embed cmd into sed replacement to have dynamic substitution yifangt Shell Programming and Scripting 9 10-03-2012 06:41 PM
How to embed commands in awk search delphys Shell Programming and Scripting 2 12-16-2011 12:57 PM
embed a separator after each word in a text file venu Shell Programming and Scripting 9 11-18-2011 11:41 AM
Embed function in if statement msarro Shell Programming and Scripting 1 07-21-2011 05:05 PM
Embed commands into an expr command? (so I only store result) Bashingaway Shell Programming and Scripting 3 10-17-2010 09:41 AM
Why can't embed commands like fg or bg in a shell script ? qiulang Shell Programming and Scripting 4 04-20-2009 10:28 AM
php youtube style embed code mainegate Web Development 0 11-18-2008 10:44 PM
does any one know free web server to embed in my app umen Programming 4 03-18-2008 10:47 AM
How To Embed Image In output file minut UNIX for Dummies Questions & Answers 0 09-03-2007 04:50 AM
How to embed shell script in a awk code rajbal Shell Programming and Scripting 8 09-28-2006 04:19 PM