View previous topic :: View next topic |
Author |
Message |
lsimaster
Joined: 19 Mar 2009 Posts: 25
|
.encrypt || (#EXPORT & #IMPORT)? |
Posted: Wed Feb 24, 2010 9:52 am |
|
|
I am using v4.099. I have a program that requires certain parts to be hidden due to proprietary concerns. I need to distribute the logic to my customer but want to hide the device drivers as I have no control over what they will do with the code. I have been playing with various ways to make this happen with no success. Hopefully someone has solved this.
I tried making a .encrypt file and then use #INCLUDE (which is supposed to recognize and decode this file) but I get an error. The program compiles and is completely functional if I compile the same without encrypting. The only difference being a .c vs. a .encrypt file extension.
I then tried #EXPORT (relocatable) and #IMPORT (xxxx.o). The #export file compiles to a xxxx.o file with no apparent problem. When I compile the master file (w/#INCLUDE (xxxx.o)) I get errors on every instance of putc and puts until it hits 100. These are the standard built in functions that have nothing to do with my code. I also get an error regarding a "prior instance" of a function even though the documentation says that duplicate instances will be treated as the same instance. I have shifted all shared variables and functions into a separate #INCLUDE file as described in the CCS "documentation". (editorial comment: I quote the word because we all know that certain parts are sketchy or just wrong and getting an answer is time consuming if you ever get one.)
At this point I am stumped. I searched the forum and I found no instances where someone had this approach working. I thought I would try again. If anyone has been able to make either approach work please let the ROW know. |
|
|
tinley
Joined: 09 May 2006 Posts: 67
|
|
Posted: Thu Sep 16, 2010 7:31 am |
|
|
I am finding the same thing with compiler version 4.112
I tried both the #export #import and the encrypt method you tried before searching this forum.
It would appear that these functions have been broken sometime in the past, but no one uses them enough to complain.
I'll report it now and hope they fix it before my customers deadline... after all, they will sell another complier to my customer if they do! |
|
|
lsimaster
Joined: 19 Mar 2009 Posts: 25
|
file encryption |
Posted: Thu Sep 16, 2010 8:36 am |
|
|
CCS fixed this but not the way implied in their documentation.
Use the form #INCLUDE filename.c.encrypted
I am using this and I think it is successful. The frequent problem these days is customers try to get the code cloned by some off shore source so they can get it for free. This is a potential block on that although someone has probably cracked this by now. At least we can make them do a little work to get there. In my case I am encrypting some critical drivers that took a lot to develop. They still have access to the basic logic which is called out in a specification anyway. |
|
|
FvM
Joined: 27 Aug 2008 Posts: 2337 Location: Germany
|
|
Posted: Thu Sep 16, 2010 8:52 am |
|
|
I found, that #include file.ext.encrypted works both with PCD and PCD 4.112. You shouldn't overestimate the level of protection achieved by a method that should be rather considered as obfuscation than as encryption.
P.S.: I agree, that the documentation isn't very clear, but it was sufficient for me to use the method at first attempt. |
|
|
tinley
Joined: 09 May 2006 Posts: 67
|
|
Posted: Thu Sep 16, 2010 8:58 am |
|
|
Thanks for the reply.
My test program was:
Code: |
#include "C:\PICC\test\test.h"
#include "C:\PICC\test\hide.h.encrypted"
void main()
{
setup_adc_ports(NO_ANALOGS|VSS_VDD);
setup_adc(ADC_CLOCK_DIV_2|ADC_TAD_MUL_0);
setup_spi(SPI_SS_DISABLED);
setup_wdt(WDT_OFF);
setup_timer_0(RTCC_INTERNAL);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
setup_comparator(NC_NC_NC_NC);
setup_vref(FALSE);
printf("Hello %u",crypt());
while(1);
}
|
and the following in a file encrypted as "hide.h.encrypted"
Code: |
int crypt(){
int i=25;
return i;
} |
This gives:
*** Error 117 "test.c" Line 7(4,5): Improper use of a function identifier
1 Errors, 0 Warnings. |
|
|
FvM
Joined: 27 Aug 2008 Posts: 2337 Location: Germany
|
|
Posted: Thu Sep 16, 2010 10:13 am |
|
|
Yes, I can confirm the reported error. I didn't occur in a more complex example, don't know why.
P.S.: Just place a carriage return after the last code line.
Last edited by FvM on Thu Sep 16, 2010 10:43 am; edited 1 time in total |
|
|
lsimaster
Joined: 19 Mar 2009 Posts: 25
|
encryption |
Posted: Thu Sep 16, 2010 10:15 am |
|
|
I'm sorry but I left out a critical step. You have to encrypt the file that will be included. Go to the File tab and click on the Encrypt option. Once you have the properly encrypted file then you can include it. |
|
|
tinley
Joined: 09 May 2006 Posts: 67
|
|
Posted: Thu Sep 16, 2010 10:24 am |
|
|
Thanks, but I had encrypted the file! |
|
|
lsimaster
Joined: 19 Mar 2009 Posts: 25
|
encryption |
Posted: Thu Sep 16, 2010 11:54 am |
|
|
I did it with an earlier version. 4.099 I think.
I note that your file is a .h Try making that a .c and see if that works as mine was a .c.
Otherwise you will have to fight this out with the support group like I did since I am out of ideas. This is one of those areas where the documentation is severely lacking. |
|
|
FvM
Joined: 27 Aug 2008 Posts: 2337 Location: Germany
|
|
Posted: Thu Sep 16, 2010 3:25 pm |
|
|
Quote: | Otherwise you will have to fight this out with the support group like I did since I am out of ideas. | The problem has been already solved. Read my above post. |
|
|
lsimaster
Joined: 19 Mar 2009 Posts: 25
|
encryption |
Posted: Thu Sep 16, 2010 3:38 pm |
|
|
Thanks, I got out of sync with the posts. I agree this is only a road block to someone who is sufficiently determined. |
|
|
tinley
Joined: 09 May 2006 Posts: 67
|
|
Posted: Fri Sep 17, 2010 2:08 am |
|
|
Thank you FvM... I now read that you confirm the compiler has an error and you give a workaround. I did not notice this until just now. It works, so thank you for your help... again!
How did you stumble on that workaround? |
|
|
FvM
Joined: 27 Aug 2008 Posts: 2337 Location: Germany
|
|
Posted: Fri Sep 17, 2010 2:23 am |
|
|
Quote: | How did you stumble on that workaround? |
I noticed, that the error location was after the #include position, which usually happens with a real (or apparent) syntax error in the included file.
CCS C is actually training your sixth sense in predicting possible bug locations...
I guess that one character is lost or the "encryption" routine expects a carriage return for lines to be valid. |
|
|
tinley
Joined: 09 May 2006 Posts: 67
|
#IMPORT #EXPORT |
Posted: Fri Sep 17, 2010 3:24 am |
|
|
I have found why #IMPORT was not working for me, and since the manual does not explain it well and others have clearly had problems, here is a working example. You need to either have an #ORG statement to relocate the imported object away from the reset vector, or you put the #IMPORT after main();
test.c:
Code: |
#include "C:\PICC\test\test.h"
void main()
{
setup_adc_ports(NO_ANALOGS|VSS_VDD);
setup_adc(ADC_CLOCK_DIV_2|ADC_TAD_MUL_0);
setup_spi(SPI_SS_DISABLED);
setup_wdt(WDT_OFF);
setup_timer_0(RTCC_INTERNAL);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
setup_comparator(NC_NC_NC_NC);
setup_vref(FALSE);
printf("Hello %u",crypt());
while(1);
}
#import(file=hide.o)
|
hide.c compiles to produce hide.o:
Code: |
#DEVICE PIC18F2620
#export(RELOCATABLE,file=hide.o)
int crypt(){
int i=25;
return i;
}
|
|
|
|
|