How could I hide the visible string?

Hi,

Is there a way to modify the string such as char a or char b? Could I use the way like “Replace an instruction with another Value” in Programm Manual? In fact, what I am interested in is string with visible expression, not all string, and I am trying to hide the orignal string by using simple way like XOR…

Is there a way to reorder the basic blocks?

Thanks.

Qiuyu

C Source code:

#include <stdio.h>
#include <stdlib.h>

char a[20]=“global string test\n”;

int main( int argc , char *argv){

char b[20]= “Internal string test”;

printf(“Global %s \n”,a);
printf(“Internal %s\n”,b);

}

IR code :

target endian = little
target pointersize = 32
%struct…TorRec = type { int, void ()* }
%struct.TorRec = type { int, void ()* }
%a = internal global [20 x sbyte] c"global string test\0A\00" ; <[20 x sbyte]> [#uses=1]
%.ctor_1 = internal global [20 x sbyte] c"Internal string test" ; <[20 x sbyte]
> [#uses=1]
%.str_1 = internal constant [12 x sbyte] c"Global %s \0A\00" ; <[12 x sbyte]> [#uses=1]
%.str_2 = internal constant [13 x sbyte] c"Internal %s\0A\00" ; <[13 x sbyte]
> [#uses=1]
%Initialized.0__ = internal global bool false ; <bool*> [#uses=2]

implementation ; Functions:

declare int %printf(sbyte*, …)

int %main(int %argc, sbyte** %argv) {
entry:
%b = alloca [20 x sbyte] ; <[20 x sbyte]> [#uses=1]
%tmp.1.i = load bool
%Initialized.0__ ; [#uses=1]
br bool %tmp.1.i, label %__main.entry, label %endif.0.i

endif.0.i: ; preds = %entry
store bool true, bool* %Initialized.0__
br label %__main.entry

__main.entry: ; preds = %entry, %endif.0.i
%tmp.0 = getelementptr [20 x sbyte]* %b, uint 0, uint 0 ; <sbyte*> [#uses=2]
call void %llvm.memcpy( sbyte* %tmp.0, sbyte* getelementptr ([20 x sbyte]* %.ctor_1, long 0, long 0), uint 20, uint 1 )
%tmp.3 = call int (sbyte*, …)* %printf( sbyte* getelementptr ([12 x sbyte]* %.str_1, long 0, long 0), sbyte* getelementptr ([20 x sbyte]* %a, long 0, long 0) ) ; [#uses=0]
%tmp.6 = call int (sbyte*, …)* %printf( sbyte* getelementptr ([13 x sbyte]* %.str_2, long 0, long 0), sbyte* %tmp.0 ) ; [#uses=0]
ret int 0
}

declare void %llvm.memcpy(sbyte*, sbyte*, uint, uint)

Is there a way to modify the string such as char a or char b? Could I
use the way like "Replace an instruction with another Value" in Programm
Manual? In fact, what I am interested in is string with visible
expression, not all string, and I am trying to hide the orignal string
by using simple way like XOR..

Yes, there is. At the C level, what transformation do you want to do?
The LLVM code is a pretty straight-forward translation from the C code in
this case.

Is there a way to reorder the basic blocks?

Yes, for an example pass that does this, take a look at
lib/Transforms/Scalar/BasicBlockPlacement.cpp

-Chris

C Source code:

#include <stdio.h>
#include <stdlib.h>

char a[20]="global string test\n";

int main( int argc , char *argv){

  char b[20]= "Internal string test";

  printf("Global %s \n",a);
  printf("Internal %s\n",b);

}

IR code :

target endian = little
target pointersize = 32
%struct..TorRec = type { int, void ()* }
%struct.TorRec = type { int, void ()* }
%a = internal global [20 x sbyte] c"global string test\0A\00" ; <[20 x sbyte]*> [#uses=1]
%.ctor_1 = internal global [20 x sbyte] c"Internal string test" ; <[20 x sbyte]*> [#uses=1]
%.str_1 = internal constant [12 x sbyte] c"Global %s \0A\00" ; <[12 x sbyte]*> [#uses=1]
%.str_2 = internal constant [13 x sbyte] c"Internal %s\0A\00" ; <[13 x sbyte]*> [#uses=1]
%Initialized.0__ = internal global bool false ; <bool*> [#uses=2]

implementation ; Functions:

declare int %printf(sbyte*, ...)

int %main(int %argc, sbyte** %argv) {
entry:
%b = alloca [20 x sbyte] ; <[20 x sbyte]*> [#uses=1]
%tmp.1.i = load bool* %Initialized.0__ ; <bool> [#uses=1]
br bool %tmp.1.i, label %__main.entry, label %endif.0.i

endif.0.i: ; preds = %entry
store bool true, bool* %Initialized.0__
br label %__main.entry

__main.entry: ; preds = %entry, %endif.0.i
%tmp.0 = getelementptr [20 x sbyte]* %b, uint 0, uint 0 ; <sbyte*> [#uses=2]
call void %llvm.memcpy( sbyte* %tmp.0, sbyte* getelementptr ([20 x sbyte]* %.ctor_1, long 0, long 0), uint 20, uint 1 )
%tmp.3 = call int (sbyte*, ...)* %printf( sbyte* getelementptr ([12 x sbyte]* %.str_1, long 0, long 0), sbyte* getelementptr ([20 x sbyte]* %a, long 0, long 0) ) ; <int> [#uses=0]
%tmp.6 = call int (sbyte*, ...)* %printf( sbyte* getelementptr ([13 x sbyte]* %.str_2, long 0, long 0), sbyte* %tmp.0 ) ; <int> [#uses=0]
ret int 0
}

declare void %llvm.memcpy(sbyte*, sbyte*, uint, uint)

-Chris