如何保护/检测Android设备上的数据库还原?

时间:2021-07-26 00:07:49

I have an app for Android, that saves data to sqlite database in a common way. As the user works with the application, the data is changed etc. So far no problem...

我有一个Android应用程序,它以一种常见的方式将数据保存到sqlite数据库。当用户使用应用程序时,数据会发生变化等。到目前为止没问题...

But when the user use some back-up software (like Titanium Backup or others), make a backup of the application, he can restore the data to old state. I need the way to protect application from this or to detect the restoration and handle it.

但是当用户使用某些备份软件(如Titanium Backup或其他软件)时,备份应用程序,他可以将数据恢复到旧状态。我需要保护应用程序的方法或检测恢复并处理它。

The simple workflow:

简单的工作流程:

  1. Install APP
  2. Work with APP
  3. 使用APP

  4. Reach the STATE1 of APP's database
  5. 到达APP数据库的STATE1

  6. Back-up the APP (with any backup/restore application, the device can be rooted)
  7. 备份APP(使用任何备份/恢复应用程序,设备可以植根)

  8. Work with APP
  9. 使用APP

  10. Reach the STATE2 of APP's database
  11. 到达APP数据库的STATE2

  12. Restores the APP (or just data) to STATE1 - this is the point I need to deny or detect on the next execution of the APP.
  13. 将APP(或仅数据)恢复到STATE1 - 这是我在下次执行APP时需要拒绝或检测的点。

So far I played with the Access-time detection and comparsion, but it seems to be really un-reliable through different devices and ROMs.

到目前为止,我使用了访问时检测和比较,但它通过不同的设备和ROM似乎真的不可靠。

Thank you.

1 个解决方案

#1


2  

To do this you need to save some state off the device, or at least outside of the data directory. The easiest way is probably to save the fingerprint of the DB file in some 'hidden' directory on external storage (SD card). Or if your app has Web login, etc. store the fingerprint for each user.

为此,您需要将某些状态保存在设备上,或至少保存在数据目录之外。最简单的方法可能是将DB文件的指纹保存在外部存储(SD卡)的某个“隐藏”目录中。或者,如果您的应用程序具有Web登录等,则为每个用户存储指纹。

In any case, the user has full control over the device so you can't prevent this 100%. Your app needs to gracefully handle any changes in the DB or simply fail if it detects a fatal inconsistency.

在任何情况下,用户都可以完全控制设备,因此您无法阻止此100%。您的应用程序需要优雅地处理数据库中的任何更改,或者只有在检测到致命的不一致时才会失败。

#1


2  

To do this you need to save some state off the device, or at least outside of the data directory. The easiest way is probably to save the fingerprint of the DB file in some 'hidden' directory on external storage (SD card). Or if your app has Web login, etc. store the fingerprint for each user.

为此,您需要将某些状态保存在设备上,或至少保存在数据目录之外。最简单的方法可能是将DB文件的指纹保存在外部存储(SD卡)的某个“隐藏”目录中。或者,如果您的应用程序具有Web登录等,则为每个用户存储指纹。

In any case, the user has full control over the device so you can't prevent this 100%. Your app needs to gracefully handle any changes in the DB or simply fail if it detects a fatal inconsistency.

在任何情况下,用户都可以完全控制设备,因此您无法阻止此100%。您的应用程序需要优雅地处理数据库中的任何更改,或者只有在检测到致命的不一致时才会失败。