473,394 Members | 1,700 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Including huge strings with line breaks as variables

I have a file with roughly 1000 lines that I cannot allow the user to
read but which I want to use in my project.

I thought I could copy it into one huge string variable but that won't
work because of the line breaks.

Is there a way to enclos ethis data in 1 huge variable that tehn gets
compiled into the exutable?

Oct 6 '06 #1
15 1977
nt

Oct 6 '06 #2
"pkirk25" <pa*****@kirks.netwrote in message
news:11*********************@i3g2000cwc.googlegrou ps.com...
I thought I could copy it into one huge string variable but that won't
work because of the line breaks.
Why won't it work?
Oct 6 '06 #3
c++ error C2001: newline in constant

Examples of the text are:
string crafted_items = "alchemy,Minor Healing
Potion,1,Peacebloom,1,Silverleaf,1,Empty Vial
alchemy,Elixir of Lion's Strength,1,Earthroot,1,Silverleaf,1,Empty Vial
alchemy,Elixir of Minor Defense,2,Silverleaf,1,Empty Vial,,
alchemy,Weak Troll's Blood Potion,1,Peacebloom,2,Earthroot,1,Empty Vial
alchemy,Minor Mana Potion,1,Mageroyal,1,Silverleaf,1,Empty Vial
alchemy,Minor Rejuvenation Potion,2,Mageroyal,1,Peacebloom,1,Empty
Vial";

Its in CSV format.

I like Accelerated C++ btw - on my desk right now and used this morning
while working out medians.

Oct 6 '06 #4
Done by exporting each liem to a text file perceded by

item_list.push_back("

and followed by ");

Is this the best way to hide data?

Oct 6 '06 #5

pkirk25 wrote:
c++ error C2001: newline in constant

Examples of the text are:
string crafted_items = "alchemy,Minor Healing
Potion,1,Peacebloom,1,Silverleaf,1,Empty Vial
alchemy,Elixir of Lion's Strength,1,Earthroot,1,Silverleaf,1,Empty Vial
alchemy,Elixir of Minor Defense,2,Silverleaf,1,Empty Vial,,
alchemy,Weak Troll's Blood Potion,1,Peacebloom,2,Earthroot,1,Empty Vial
alchemy,Minor Mana Potion,1,Mageroyal,1,Silverleaf,1,Empty Vial
alchemy,Minor Rejuvenation Potion,2,Mageroyal,1,Peacebloom,1,Empty
Vial";

Its in CSV format.

I like Accelerated C++ btw - on my desk right now and used this morning
while working out medians.

you will have to terminate the end-of line with a backslash:

const char ad[] = "line1\n\
line2\n\
line3\n\
line4";

If you don't want to change this string there is no need to copy it
into a std::string but you can leave it in a const char array like
above.

Oct 6 '06 #6
c++ error C2001: newline in constant
>
Examples of the text are:
string crafted_items = "alchemy,Minor Healing
Potion,1,Peacebloom,1,Silverleaf,1,Empty Vial
alchemy,Elixir of Lion's Strength,1,Earthroot,1,Silverleaf,1,Empty Vial
alchemy,Elixir of Minor Defense,2,Silverleaf,1,Empty Vial,,
alchemy,Weak Troll's Blood Potion,1,Peacebloom,2,Earthroot,1,Empty Vial
alchemy,Minor Mana Potion,1,Mageroyal,1,Silverleaf,1,Empty Vial
alchemy,Minor Rejuvenation Potion,2,Mageroyal,1,Peacebloom,1,Empty
Vial";
Just put quotes around each line and add newlines:
string crafted_items = "alchemy,Minor Healing\n"
"Potion,1,Peacebloom,1,Silverleaf,1,Empty Vial\n"
"alchemy,Elixir of Lion's Strength,1,Earthroot,1,Silverleaf,1,Empty
Vial\n"
etc.

The compiler concatenates adjacent string literals into one.

I've been doing this a lot in some code I wrote recently, and it's just
a couple of commands in VI to change the original text to the final.
Or you could write a little C++ program. Or a script of some sort.

Michael

Oct 6 '06 #7
Peter wrote:
>>
you will have to terminate the end-of line with a backslash:

const char ad[] = "line1\n\
line2\n\
line3\n\
line4";
Why bother with the backslashes? Just rely on literal concatenation.
The compiler will concatenate adjacent string literals.
e.g.:

const char ad[] = "line1\n"
"line2\n"
"line3\n"
"line4";
Oct 6 '06 #8
pkirk25 wrote:
I have a file with roughly 1000 lines that I cannot allow the user to
read but which I want to use in my project.

I thought I could copy it into one huge string variable but that won't
work because of the line breaks.

Is there a way to enclos ethis data in 1 huge variable that tehn gets
compiled into the exutable?
Sure, there is:

#include <iostream>

char const multi_line_const [] =
"the first line,\n"
"the second line,\n"
"and the third line\n";

int main ( void ) {
std::cout << multi_line_const;
}

But that won't stop any but the most lazy attacker: the compiler will just
embed the string within the executable. Thus, anybody can still read it
using a text or a hex editor.

Also, any cracker will run 'strings' (or whatever equivalent is available on
the target platform) on the executable and get the whole text without
effort:

news_groupstrings a.out
/lib/ld-linux.so.2
libstdc++.so.6
_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES 5_PKc
__gxx_personality_v0
_ZNSt8ios_base4InitC1Ev
_ZNSt8ios_base4InitD1Ev
_ZSt4cout
_Jv_RegisterClasses
__gmon_start__
libm.so.6
libgcc_s.so.1
libc.so.6
_IO_stdin_used
__libc_start_main
/added/pkg/gcc-4.1.1/usr/lib
GLIBC_2.0
CXXABI_1.3
GLIBCXX_3.4
PTRhq
[^_]
the first line,
the second line,
and the third line
This route of obfuscation is essentially useless.
Best

Kai-Uwe Bux
Oct 6 '06 #9
"pkirk25" <pa*****@kirks.netwrote in message
news:11*********************@i3g2000cwc.googlegrou ps.com...
>I have a file with roughly 1000 lines that I cannot allow the user to
read but which I want to use in my project.

I thought I could copy it into one huge string variable but that won't
work because of the line breaks.

Is there a way to enclos ethis data in 1 huge variable that tehn gets
compiled into the exutable?
Read the above replies to your exact question, but I don't think you want to
go this way anyway as it's very easy to look at an executable program and
read the strings in them.

A better way would be to go ahead and put it in a file, but encrypt it
somehow. You should be able to google for a fairly simple encryption you
could use (doesn't need to be military grade) and then all you have to keep
in your source .exe is the key for the encryption, which would look like
garbage anyway. And if you got creative you could build the key from a few
parts of different strings so it would look like even more garbage.
Oct 6 '06 #10

Jim Langston wrote:
[...]
A better way would be to go ahead and put it in a file, but encrypt it
somehow. You should be able to google for a fairly simple encryption you
could use (doesn't need to be military grade) and then all you have to keep
in your source .exe is the key for the encryption, which would look like
garbage anyway. And if you got creative you could build the key from a few
parts of different strings so it would look like even more garbage.
Interesting. I do need to do something because a freeware that helps
gamers but costs me legal fees would be a bad idea. Not something the
missus would understand...

Oct 6 '06 #11

pkirk25 wrote in message
<11**********************@m73g2000cwd.googlegroups .com>...
>
Jim Langston wrote:
[...]
>A better way would be to go ahead and put it in a file, but encrypt it
somehow. You should be able to google for a fairly simple encryption you
could use (doesn't need to be military grade) and then all you have to
keep
>in your source .exe is the key for the encryption, which would look like
garbage anyway. And if you got creative you could build the key from a
few
>parts of different strings so it would look like even more garbage.

Interesting. I do need to do something because a freeware that helps
gamers but costs me legal fees would be a bad idea. Not something the
missus would understand...
You could just store the string as numerical:

std::string HideThis(" don't want just "
"anybody to see this "
"hidden message! ");
// std::reverse( HideThis.begin(), HideThis.end() ); // reverse it

std::ofstream Fout("XFiles.txt");
if( not Fout ){ /* handle error */ }
for(size_t i(0); i < HideThis.size(); ++i){
Fout << int( HideThis.at( i ) ) << " ";
} // for(i)
Fout<<std::endl;
Fout.close();

// -- output --
32 100 111 110 39 116 32 119 97 110 116 32 106 117 115 116 32 97 110 121 98
111 100 121 32 116 111 32 115 101 101 32 116 104 105 115 32 104 105 100 100
101 110 32 109 101 115 115 97 103 101 33 32
Then reverse the procedure to read it into a std::string in your program
(using a '.push_back( char( number ) );' or?).

--
Bob R
POVrookie
Oct 8 '06 #12
BobR wrote:
>
pkirk25 wrote in message
<11**********************@m73g2000cwd.googlegroups .com>...
>>
Jim Langston wrote:
[...]
>>A better way would be to go ahead and put it in a file, but encrypt it
somehow. You should be able to google for a fairly simple encryption
you could use (doesn't need to be military grade) and then all you have
to
keep
>>in your source .exe is the key for the encryption, which would look like
garbage anyway. And if you got creative you could build the key from a
few
>>parts of different strings so it would look like even more garbage.

Interesting. I do need to do something because a freeware that helps
gamers but costs me legal fees would be a bad idea. Not something the
missus would understand...
To the OP: That sounds like the cryptographic attacker would not be the
gamer but a company. In that case, the attacker may safely be assumed to be
highly motivated and resourcefull. Then you are facing a difficult problem,
namely that you have to deliver. That means you have to give away the
information within the file somehow. You may embed an encrypted version of
the file, but you also have to embed the key, and you have to embed the
decryption routine. In these three parts, you give away all the attacker
needs to reconstruct the file.

Also, if you are up against a company you should consider the non-technical
attacks they have: the way you mention legal fees can indicate that you
expect being sued. Then, their lawers will just ask the court to order you
to fork over all iterations of the source code and related data during
discovery (caveat: IANAL). When that happens, all encryption was in vain
anyway.

You could just store the string as numerical:

std::string HideThis(" don't want just "
"anybody to see this "
"hidden message! ");
// std::reverse( HideThis.begin(), HideThis.end() ); // reverse it

std::ofstream Fout("XFiles.txt");
if( not Fout ){ /* handle error */ }
for(size_t i(0); i < HideThis.size(); ++i){
Fout << int( HideThis.at( i ) ) << " ";
} // for(i)
Fout<<std::endl;
Fout.close();

// -- output --
32 100 111 110 39 116 32 119 97 110 116 32 106 117 115 116 32 97 110 121
98 111 100 121 32 116 111 32 115 101 101 32 116 104 105 115 32 104 105 100
100 101 110 32 109 101 115 115 97 103 101 33 32
Then reverse the procedure to read it into a std::string in your program
(using a '.push_back( char( number ) );' or?).
This little obfuscation scheme is a good example. If someone runs your
program in a debugger, the encryption scheme will show. This is obfuscation
at best and will not work against any attacker who is reasonably determined
and resourcefull. If you just need to deter the casual cheater, it might
suffice; however, it will notsuffice agains a seasoned cracker or against a
company suspecting your program of containing their IP and sending their
lawers after you.
Best

Kai-Uwe Bux
Oct 8 '06 #13

Kai-Uwe Bux wrote in message ...
BobR wrote:
>>
Interesting. I do need to do something because a freeware that helps
gamers but costs me legal fees would be a bad idea. Not something the
missus would understand...
You could just store the string as numerical:

std::string HideThis(" don't want just "
"anybody to see this "
"hidden message! ");
// std::reverse( HideThis.begin(), HideThis.end() ); // reverse it
std::ofstream Fout("XFiles.txt");
if( not Fout ){ /* handle error */ }
for(size_t i(0); i < HideThis.size(); ++i){
Fout << int( HideThis.at( i ) ) << " ";
} // for(i)
Fout<<std::endl;
Fout.close();
// -- output --
32 100 111 110 39 116 32 119 97 110 116 32 106 117 115 116 32 97 110 121
98 111 100 121 32 116 111 32 115 101 101 32 116 104 105 115 32 104 105 100
100 101 110 32 109 101 115 115 97 103 101 33 32

Then reverse the procedure to read it into a std::string in your program
(using a '.push_back( char( number ) );' or?).
/* "
This little obfuscation scheme is a good example. If someone runs your
program in a debugger, the encryption scheme will show. This is obfuscation
at best and will not work against any attacker who is reasonably determined
and resourcefull. If you just need to deter the casual cheater, it might
suffice; however, it will notsuffice agains a seasoned cracker or against a
company suspecting your program of containing their IP and sending their
lawers after you.
Best
Kai-Uwe Bux
" */

I figured the OP just wanted to hide the data from casual users. Our part is
NOT to help someone rip-off some company! <G[ there are other NGs for
that! ]

Yeah, I remember using debug to cheat games on my Apple][+. Back in those
days, I would crack the protection and hand out copies to anyone who would
take them, but, if it was not protected, my answer was "BUY your own copy!!"
[1]. I cracked everything but "Choplifter" 1/4 track non-standard write
scheme on the 5.25 floppy (I came close, but the ones that did crack it used
a network (which I didn't have)). Ahhh, the memories!!

[1] - the "protection wars" in the early '80s.
--
Bob R
POVrookie
Oct 8 '06 #14
I AM NOT A THIEF

My question was how to prevent data teing passed on for free. I have
no interest in stealing from anyone. But if I buy data and use it in
my app, I need to be able to hide it. Not from the publisher, but from
the casual user who would love to have it all in Excel.

As such, something that would take more than an hour with a Hex editor
will be more than enough for me.

The bigger picture is that I am learning C++ and ask questions in the
hope of learning more. Its unlikely I'll make something thats fit to
sell as shareware but having a goal helps.

Oct 8 '06 #15

pkirk25 wrote in message
<11**********************@e3g2000cwe.googlegroups. com>...
>I AM NOT A THIEF
If i thought you were, I would *never* have offered help!
[ my comment was directed to Mr. Box. ]
>
My question was how to prevent data teing passed on for free. I have
no interest in stealing from anyone. But if I buy data and use it in
my app, I need to be able to hide it. Not from the publisher, but from
the casual user who would love to have it all in Excel.

As such, something that would take more than an hour with a Hex editor
will be more than enough for me.
Notice in the code I offered, I commented-out a line that will 'reverse' the
string. That will slow down anybody trying to figure it out.
Another thing you could do is add one to the number before writing it to
file, and then subtract one from the number before putting it back in a
string in your main program.
There are millions of ways to encrypt data.
>
The bigger picture is that I am learning C++ and ask questions in the
hope of learning more. Its unlikely I'll make something thats fit to
sell as shareware but having a goal helps.
'goals' are GOOD! Just set reasonable goals. [Attempting to write the next
major network app your first year in (C++) programming in not reasonable.].
As you achieve goals, raise the bar a little, and go to it.

A person who posts a homework assignment and wants someone to code it for
them, well...you've seen those answers. A hobbyist (or student) who posts his
code attempt will get more than enough help from the experts ( and others,
like me (if I think I can help)) here.

If you want/need more help, just post it.
--
Bob R
POVrookie
Oct 9 '06 #16

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Logical | last post by:
I wanted to do: include('page.htm?id=12&foo=bar'); But since I can't (and don't want to make another seperate HTTP request with include('http://...')); I was wondering if there's a function...
7
by: news.hku.hk | last post by:
is there any way to make a loop to store strings?? e.g. abc.txt contains 3 lines i.e. this is line 1. this is line 2. this is line 3. i want to create a loop that can make the three strings...
4
by: Rick | last post by:
I am fairly new to XML, I have an XML document that holds configurations for an ASP.NET application, within the configuration XML File I have a line of text that will feed into a lable on a web...
8
by: Sven | last post by:
Dear all, I'm trying to extract data from HTML using XPath in Java. Unfortunately the text contents of nodes may contain <br/tags which are not correctly interpreted, at least not for me ;) A...
26
by: machineghost | last post by:
First off, let me just say that as someone with no DBA training whatsoever, any help I can get with this issue will be very, very much appreciated. My company recently migrated our database from...
9
by: NvrBst | last post by:
Whats the best way to count the lines? I'm using the following code at the moment: public long GetNumberOfLines(string fileName) { int buffSize = 65536; int streamSize = 65536; long...
21
by: FutureShock | last post by:
I have just recently started to use OOP for my web applications and am running into some head scratching issues. I wanted to have a separate file for all my configuration variables. Some of them...
2
by: Jean-Paul Calderone | last post by:
On Fri, 5 Sep 2008 14:24:16 -0500, Robert Dailey <rcdailey@gmail.comwrote: mystring = ( "This is a very long string that " "spans multiple lines and does " "not include line breaks or tabs "...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.