将程序转换成本地代码防止反编译

将程序转换成本地代码也是一种防止反编译的有效方法。

因为本地代码往往难以被反编译。

开发人员可以选择将整个应用程序转换成本地代码,也可以选择关键模块转换。

如果仅仅转换关键部分模块,Java程序在使用这些模块时,需要使用JNI技术进行调用。

当然,在使用这种技术保护Java程序的同时,也牺牲了Java的跨平台特性。

对于不同的平台,我们需要维护不同版本的本地代码,这将加重软件支持和维护的工作。

不过对于一些关键的模块,有时这种方案往往是必要的。

为了保证这些本地代码不被修改和替代,通常需要对这些代码进行数字签名。

在使用这些本地代码之前,往往需要对这些本地代码进行认证,确保这些代码没有被黑客更改。

如果签名检查通过,则调用相关JNI方法。

 1 package Com.TableTest;
 2 
 3 
 4 class SimpleDotCom {
 5 
 6     int[] locationCells;
 7 
 8     int numOfHits = 0;
 9 
10 
11     public void setLocationCells(int[] locs){
12 
13         locationCells = locs;
14 }
15 
16     public String checkYourself(String StringGuess) {
17 
18         int guess = Integer.parseInt(StringGuess);
19 
20         String result = "miss";
21 
22         for (int cell:locationCells){
23 
24             if (guess == cell){
25 
26                 result = "hit";
27 
28                 numOfHits++;
29 
30                 break;
31 
32             }
33 
34         }
35 
36         if(numOfHits == locationCells.length){
37 
38             result = "kill";
39 
40         }
41 
42         System.out.println(result);
43 
44         return result;
45 
46     }
47 }
48 
49 
50 public class TableText_14 {
51  
52     public static void main(String[] args){
53 
54         //初始化一个SimpleDotCom对象
55 
56         SimpleDotCom dot = new SimpleDotCom();
57 
58         //创建带有dot com位置的数组
59 
60         int[] locations = {2,3,4};
61 
62         //调用dot com 的setter
63 
64         dot.setLocationCells(locations);
65 
66         //假的猜测
67 
68         String userGuess = "2";
69 
70         //调用被测方法并传入假的数据
71 
72         dot.checkYourself(userGuess);  
73  
74     }
75 
76 }

猜你喜欢

转载自www.cnblogs.com/borter/p/9388506.html
今日推荐