473,513 Members | 10,313 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Hiding that string in the compiled code

My program includes a use of strstr(). It looks like this:

if(strstr(*str1, *str2)
...........

After compiling the code, I opened the program with a hex editor
(this is on Windows). Sure enough, I found str2 in the compiled code.

Is there a simple alternative (preferrably still using strstr) to
achieve the same objective without revealing str2 in the compiled
code?
Nov 15 '05 #1
4 7005
On Sat, 02 Jul 2005 02:58:11 GMT, John Smith <js****@company.com>
wrote in comp.lang.c:
My program includes a use of strstr(). It looks like this:

if(strstr(*str1, *str2)
..........

After compiling the code, I opened the program with a hex editor
(this is on Windows). Sure enough, I found str2 in the compiled code.

Is there a simple alternative (preferrably still using strstr) to
achieve the same objective without revealing str2 in the compiled
code?


Sure, select any mechanism you like to encrypt str2. For a simple
example, xor each character treated as an unsigned char with a
constant value, for example 0x55.

Put the result in your program as an array of unsigned char. At run
time, decrypt it before using.

For "hello", in your source do:

#include <stdio.h>

#define CRYPT 0x55

unsigned char str2 [6] = { 'h' ^ CRYPT, 'e' ^ CRYPT,
'l' ^ CRYPT, 'l' ^ CRYPT, 'o' ^ CRYPT };

int main()
{
int count;
char *cp = (char *)str2;
printf("Before decryption: %s\n", cp);
for (count = 0; count < 5; ++count)
{
str2 [count] ^= CRYPT;
}
printf("After decryption: %s\n", cp);
return 0;
}

Output:
Before decryption: =099:
After decryption: hello

Feel free to use methods other than xor with a constant. Remember to
do your encryption and decryption on unsigned chars.

Be careful in general not to depend on C string functions while your
array is in the encrypted state, as one of the real characters in the
plain text might become '\0' when encrypted. In the example xor with
0x55, the ASCII character 'U' will become '\0' when encrypted.

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.contrib.andrew.cmu.edu/~a...FAQ-acllc.html
Nov 15 '05 #2
or just upx your executable.

Nov 15 '05 #3
On 1 Jul 2005 20:53:25 -0700, a.*************@gmail.com wrote in
comp.lang.c:
or just upx your executable.


Can't find any mention of "upx" in the C standard, so it is quite
off-topic here.

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.contrib.andrew.cmu.edu/~a...FAQ-acllc.html
Nov 15 '05 #4


Jack Klein wrote:
On Sat, 02 Jul 2005 02:58:11 GMT, John Smith <js****@company.com>
wrote in comp.lang.c:
My program includes a use of strstr(). It looks like this:

if(strstr(*str1, *str2)
..........

After compiling the code, I opened the program with a hex editor
(this is on Windows). Sure enough, I found str2 in the compiled code.

Is there a simple alternative (preferrably still using strstr) to
achieve the same objective without revealing str2 in the compiled
code?


Sure, select any mechanism you like to encrypt str2. For a simple
example, xor each character treated as an unsigned char with a
constant value, for example 0x55.

Put the result in your program as an array of unsigned char. At run
time, decrypt it before using.

That's basically what I did for the string file for the text-adventure
game I wrote years back. To make it even more secure I used a "rolling
key" approach. There was an initial seed value for the xor crypt key,
which then incremented after each use. At startup, the game would load
all the text from the file, decrypt it, and store the resulting strings
in a table.


Brian

Nov 15 '05 #5

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

Similar topics

7
2679
by: Les Juby | last post by:
I have a customer with an extensive intranet which contains a lot of sensitive company data. The client is concerned that any employee could download source code back to removable storage and...
6
1558
by: Ted Singh | last post by:
(I apologize in advance if this is an obvious question, my experience is more with console or client-only apps) I am trying to build an web-based HTML UI, which will work with a web-server on...
11
4168
by: Lorenzo Villari | last post by:
I premise I don't know C++ well but... I wondered what is this data hiding thing... I mean, if I can look at the header (and i need it beacuse of the class), then what's hidden? Can someone give...
4
2787
by: sam | last post by:
Hi, Is there any way I can prevent people use some binary disambler (eg. strings in unix) to view the const string value in a compiled C++ program? Sam.
4
2044
by: Dave | last post by:
Hi, Is possible that memcpy can be used to hide const string value? D
17
2898
by: Bob Weiner | last post by:
What is the purpose of hiding intead of overriding a method? I have googled the question but haven't found anything that makes any sense of it. In the code below, the only difference is that...
12
1467
by: Wes Spikes | last post by:
Ok, first things first: I'm a VB classic programmer and am considering upgrading now that I've seen VB2005. .NET1 & 1.5 never seemed to appeal to me, but now I'm considering the 2005. Does anyone...
2
4831
by: developer.new | last post by:
Hi I have a question regarding this concept I learned about recently: Name Hiding. Here's what I've come across: There is a base class with two functions with the same name but different...
11
4917
by: JJ297 | last post by:
I want to hide the Pin field below in my repeater. How do I do this? <asp:Repeater ID="Repeater1" runat="server" DataSourceID="SqlDataSource1"> <ItemTemplate> <tr> <td><font...
0
7254
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
7373
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
7519
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...
0
5677
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5079
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3218
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1585
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
796
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
452
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.