# embeded sansi

# clone sample project

Clone the sample project on the github to your PC as follows:

git clone https://github.com/UedaTakeyuki/sansi_examples.git
1

Move to c sample code as follows:

cd sansi_examples/c
1

You can see following files:

  • README.md: readme file
  • compile.sh: shell script for compileation
  • main.c: a sample file to show how to use sansi
  • main.simple.c: a sample application file of 10 second countdown
  • sansi.h: header file to use sansi library.

For a while, I will explain how to embed sansi and set copy protection using main.simple.c, which is a simple 10-second countdown app, as an example.

The contents of main.simple.c are as follows:








 







 


















/*
* 10 second countdown, copy guarded by sansi
* 
* @author Dr. Takeyuki UEDA
* @copyright Copyright© Atelier UEDA 2020 - All rights reserved.
*/

#include "sansi.h"  // for sansi libraries

#include <stdio.h>  // for printf
#include <unistd.h> // for seep
void tenseccount();

int main(){

  if (ok_confirmed == confirm(NULL, NULL, NULL)){
    printf("OK\n");
    tenseccount();
  } else {
    printf("NG\n");
  }
  return 0;
}

void tenseccount(){
  int i;
  printf("start 10 second countdown\n");
  for (i=10; i>0; i--){
    printf("%d\n",i);
    sleep(1);
  }
  printf("0!\n");
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33

Point is as follows:

  • include sansi.h at line 8.
  • check the result of calling confirm() function at line 16, call tenseccount() for count down if result is ok_confirmed which is defined at sansi.h, or exit if result is other.

# copy downloaded sansi library to here

Copy downloaded sansi library to here.

The library file name can be as follows: ** libsansi_[12 character bind id for your library]_[target name]_v1.1.o

The folder might be as follows, depend on your bind id and the target archtecture of your application:

# 1. for MAC

README.md				main.c
compile.sh				main.simple.c
libsansi_XMdvaoLeqDKn_mac_v1.1.o	sansi.h
1
2
3

# 2. for ARM Linux (Raspberry Pi, C1 server on the Scaleway, etc. )

README.md				main.c
compile.sh				main.simple.c
libsansi_XMdvaoLeqDKn_arm_v1.1.o	sansi.h
1
2
3

# 3. for x86 Linux

README.md				main.c
compile.sh				main.simple.c
libsansi_XMdvaoLeqDKn_x86_v1.1.o	sansi.h
1
2
3

# compile.

You can use compile.sh, the usage is as follows:

./compile.sh -h
Usage: ./compile.sh [-h][-c][-g][-m][-o obj] [source] [libsansi]
  [source]:   compiling source file, default is 'main.sample.c' 
  [libsansi]: path for linking 'libsansi….o', default is found it in cwd automatically 
  [-h]: show this usage and exit
  [-c]: compile for linux by clang
  [-g]: compile for linux by gcc, this is default
  [-m]: compile for mac by clang
  [-o obj] set compiled object file name, default is a.out
1
2
3
4
5
6
7
8
9

The compile.sh script compiles main.simple.c if no source file is specified. Also, if libsansi is not specified, it will search the directory and use the appropriate library file.

Therefore, the compile command will be as follows depending on whether the target is linux or mac, or if it is linux, the compiler to use.

# for Linux with gcc

./compile or ./compile -g as follow:

pi@raspberrypi:~/sansi_examples/c $ ./compile.sh -g
source   = main.simple.c
libsansi = libsansi_BQWpZrXOqAMX_arm_v1.1.o
compiler = gcc
obj      = a.out
compiling…
1
2
3
4
5
6

The generated object file is a.out

# for Linux with clang

./compile -c as follow:

source   = main.simple.c
libsansi = libsansi_BQWpZrXOqAMX_arm_v1.1.o
compiler = clang
obj      = a.out
compiling…
1
2
3
4
5

The generated object file is a.out

# for MAC

./compile -m as follows:

MacBook-Air:c takeyuki$ ./compile.sh -m
source   = main.simple.c
libsansi = libsansi_XMdvaoLeqDKn_mac_v1.1.o
1
2
3

The generated object file is a.out

# dependency

The sansi library depend on the openssl library. In general, it is usually had installed on your Linux, it may not be had installed on Mac.

If you get an error when compiling that libssl or libcrypto cannot be found, please install openssl.

Last Updated: 11/8/2020, 2:57:19 PM