全部产品
存储与CDN 数据库 安全 应用服务 数加·人工智能 数加·大数据基础服务 互联网中间件 视频服务 阿里云办公 培训与认证 物联网

应用加固示例代码

更新时间:2017-06-07 13:26:11

应用加固

  1. public class DiyShieldTest {
  2. IAcsClient client = null;
  3. @BeforeMethod
  4. public void init() throws ClientException {
  5. // 替换成调用方的 accessKey 和 accessKeySecret
  6. IClientProfile profile = DefaultProfile.getProfile("cn-hangzhou", "your key", "your secret");
  7. // 初始化一个IAcsClient对象
  8. client = new DefaultAcsClient(profile);
  9. }
  10. @Test
  11. public void testDiyShield() {
  12. // 请求对象
  13. DiyShieldRequest request = new DiyShieldRequest();
  14. // 设置入参
  15. request.setAppInfo(getAppInfo());
  16. request.setChannel(getChannel());
  17. request.setEnhance(getEnhance());
  18. try {
  19. // 得到请求结果
  20. DiyShieldResponse response = client.getAcsResponse(request);
  21. System.out.println("error code : " + response.getErrorCode());
  22. System.out.println("error msg : " + response.getErrorMsg());
  23. Data data = response.getData();
  24. //todo
  25. } catch (ServerException e) {
  26. e.printStackTrace();
  27. } catch (ClientException e) {
  28. e.printStackTrace();
  29. }
  30. }
  31. private String getChannel() {
  32. JSONObject channel = new JSONObject();
  33. channel.put("metaName", "channel");
  34. List<String> values = new ArrayList<>();
  35. values.add("91");
  36. values.add("360");
  37. channel.put("values", values);
  38. return channel.toJSONString();
  39. }
  40. private String getAppInfo() {
  41. JSONObject appInfo = new JSONObject();
  42. appInfo.put("dataType", 1);
  43. appInfo.put("data",
  44. "https://g01.alibaba-inc.com/tfscom/LB1PaMeKXXXXXX8XFXXXXXXXXXX.tfsprivate1446115983140-375");
  45. appInfo.put("md5", "ce86f08da845d0af6d9df2a958de17b0");
  46. appInfo.put("size", 1713656);
  47. appInfo.put("callbackUrl", "https://aaa.com/callback");
  48. appInfo.put("appOsType", 1);
  49. return appInfo.toJSONString();
  50. }
  51. private String getEnhance() {
  52. return "{'enhanceType': -1, 'javaAntiDex2jar': {'percent': 20},'javaConstEncrypt': {'percent': 20},'soEnhance': {'enhanceType': 1,'soFileList': ['lib/armeabi/libbitmaps.so','lib/armeabi/libgifimage.so']}}";
  53. }
  54. }

查询应用加固结果

  1. public class GetShieldResultTest {
  2. IAcsClient client = null;
  3. @BeforeMethod
  4. public void init() throws ClientException {
  5. // 替换成调用方的 accessKey 和 accessKeySecret
  6. IClientProfile profile = DefaultProfile.getProfile("cn-hangzhou", "your key", "your secret");
  7. // 初始化一个IAcsClient对象
  8. client = new DefaultAcsClient(profile);
  9. }
  10. @Test
  11. public void testGetShieldResult() {
  12. GetShieldResultRequest request = new GetShieldResultRequest();
  13. request.setItemId("366ce1a0-8b71-4409-bfcc-961811805077");
  14. try {
  15. GetShieldResultResponse response = client.getAcsResponse(request);
  16. System.out.println("error code : " + response.getErrorCode());
  17. System.out.println("error msg : " + response.getErrorMsg());
  18. Data data = response.getData();
  19. //todo
  20. } catch (ServerException e) {
  21. e.printStackTrace();
  22. } catch (ClientException e) {
  23. e.printStackTrace();
  24. }
  25. }
  26. }
本文导读目录