2015-10-18 152 views
3

我正在開發使用LibGDX框架的遊戲。我想知道如何讓遊戲更安全。例如,擁有紮根android設備的用戶可以更改保存的.xml文件,以便遊戲被黑客入侵,或者他/她可以使用GameKiller或類似的程序並更改遊戲運行時值(金錢,exp等)。那我該如何防止這些?LibGDX:Android遊戲安全

和桌面版本一樣,保存文件不隱藏,玩家也可以在PC上找到該文件。並且可以使用CheatEngine或其他程序進行黑客攻擊並再次更改運行時值。

+0

我想運行你的遊戲在服務器上,只有堅持數據沒有一個選項?否則,你只能讓它「更難」作弊,但你永遠無法完全防止它。如果您需要在用戶擁有的設備上操作。 –

+0

如何讓它變得更難? –

+0

混淆你的代碼/保存文件。一個選項是「加密」保存文件並在代碼中模糊密鑰。加密可能是一個簡單的XOR或轉換。但是你不應該付出太多的努力,因爲如果你的遊戲變得流行起來,那麼它就會被破解,破解者很可能會發布他們的作品,等等......代碼混淆可以通過程序來完成,但這是最重要的可能是基於意見的問題。 –

回答

0

如果沒有存儲專用/重要數據,但只希望使其難以破解您的遊戲(例如,通過與你的遊戲水平變化的XML),你可以在GWT Crypto library

的方式將實現加密倍欣在初始化加密是:

//this will be used for encrypting and decrypting strings 
    private TripleDesCipher encryptor; 

    ... 

    //creating key for encryptor 
    TripleDesKeyGenerator generator = new TripleDesKeyGenerator(); 
    byte[] key = generator.decodeKey("04578a8f0be3a7109d9e5e86839e3bc41654927034df92ec"); //you can pass your own string here 

    //initializing encryptor with generated key 
    encryptor = new TripleDesCipher(); 
    encryptor.setKey(key); 

    ... 

,並用它的方式:

private String encryptString(String string) 
    { 
     try 
     { 
      string = encryptor.encrypt(string); 
     } 
     catch (DataLengthException e1) 
     { 
      e1.printStackTrace(); 
     } 
     catch (IllegalStateException e1) 
     { 
      e1.printStackTrace(); 
     } 
     catch (InvalidCipherTextException e1) 
     { 
      e1.printStackTrace(); 
     } 

     return string; 
    } 

    private String decryptString(String string) 
    { 
     try 
     { 
      string = encryptor.decrypt(string); 
     } 
     catch (DataLengthException e) 
     { 
      e.printStackTrace(); 
     } catch (IllegalStateException e) 
     { 
      e.printStackTrace(); 
     } catch (InvalidCipherTextException e) 
     { 
      e.printStackTrace(); 
     } 

     return string; 
    } 

我也建議你不要用個XML但JSONs - 中y更方便,重量更輕。 Read how to handle it here


請記住,通常客戶端加密是不是很不錯的主意,總是能以某種方式被黑 - 但我敢肯定,如果它不是錢的問題沒有人會認爲它的價值。

如果您對保存數據更高級的方式感興趣,最好的辦法是通過SSL發送所有數據並將其保存在一些保安服務器中 - 儘管我不確定Libgdx是否具有良好的SSL機制,並不知道我可以推薦的第三方庫。

保存文件的服務示例可以是Shephertz(我正在使用他們的AppWarp,並在我的應用程序中實現這個)。

+1

請注意,此加密在此上下文中提供與使用一個字節異或的相同安全性。爲什麼? Java很容易反編譯。所以我只是反編譯jar/apk(甚至有在線工具),複製代碼並解密/加密保存文件。人們至少應該試着隱藏/模糊密鑰,以便找到它更「難」。 –

0

可以使用那些用於運行時

  1. 雙牀變量

雙牀用於cheatengine和gamekiller

int health=15; 
int twinhealth=15; 
if(HPtaken()) 
{ 
    health+=10;//those twins will always change together 
    twinhealth+=10; 
} 
if(health!=twinhealth)//if they are different this means there is hack attempt 
{ 
//punishment for hacker 
} 
  • 加密後變量
  • 事實上,它不是一個隱藏的變量,所以黑客不能通過gamekiller或cheatengine改變easly。

    int health=15*7; 
    int twinhealth=15*7; 
    
    if(HPtaken()) 
    { 
        health+=10*7;//those twins will always change together 
        twinhealth+=10*7; 
    } 
    drawhealth(health/7);// So hacker going to see and search wrong value on cheatengine  
    
  • 加密後的雙變量:d
  • 哈克禁止冷凍,並用相同的值同時改變雙。所以至少有一個雙胞胎會被加密。

    int health=15; 
    int twinhealth=15*5;  
    if(HPtaken()) 
    { 
        health+=10;//those twins will always change together 
        twinhealth+=10*5; 
    } 
    if(health!=twinhealth*5)//if they are different this means there is hack attempt 
    { 
    //punishment for hacker 
    } 
    

    當然黑客可以反編譯apk和破解你的遊戲,但它使得更難以破解遊戲。順便說一下,您可以使用隨機變量來編輯變量。

    你可以申請到XML或偏好那些,但你可以使用一點點複雜的地穴,因爲速度不是問題,因爲你只導入/導出幾次。