Home | History | Annotate | Download | only in droiddreamclean
      1 #include <stdio.h>
      2 #include <stdlib.h>
      3 #include <sys/mount.h>
      4 #include <unistd.h>
      5 #include <errno.h>
      6 #include <string.h>
      7 #include <ctype.h>
      8 
      9 /* from mwomack's product_data.csv */
     10 const char *packages[] = { "Super.mobi.eraser",
     11   "advanced.piano",
     12   "com.Funny.Face",
     13   "com.advanced.SoundManager",
     14   "com.advanced.scientific.calculator",
     15   "com.app.aun",
     16   "com.apps.tosd",
     17   "com.beauty.leg",
     18   "com.bubble",
     19   "com.dice.power",
     20   "com.dice.power.advanced",
     21   "com.dodge.game.fallingball",
     22   "com.droiddream.advancedtaskkiller1",
     23   "com.droiddream.android.afdvancedfm",
     24   "com.droiddream.barcodescanner",
     25   "com.droiddream.basketball",
     26   "com.droiddream.blueftp",
     27   "com.droiddream.bowlingtime",
     28   "com.droiddream.comparator",
     29   "com.droiddream.compasslevel",
     30   "com.droiddream.daltonismo",
     31   "com.droiddream.fallingball",
     32   "com.droiddream.game.omok",
     33   "com.droiddream.glowhockey",
     34   "com.droiddream.howtotie",
     35   "com.droiddream.lovePositions",
     36   "com.droiddream.musicbox",
     37   "com.droiddream.passwordsafe",
     38   "com.droiddream.pewpew",
     39   "com.droiddream.sexringtones",
     40   "com.droiddream.stopwatch",
     41   "com.droiddream.system.app.remover",
     42   "com.editor.photoenhance",
     43   "com.fall.down",
     44   "com.fall.soft.down",
     45   "com.free.chess",
     46   "com.free.game.finger",
     47   "com.hg.panzerpanic1",
     48   "com.hz.game.mrrunner1",
     49   "com.magic.spiral",
     50   "com.power.SuperSolo",
     51   "com.power.basketball",
     52   "com.power.demo.note",
     53   "com.power.magic.StrobeLight",
     54   "com.quick.Delete",
     55   "com.sex.japaneese.girls",
     56   "com.sexsound.hilton",
     57   "com.sexy.hotgirls",
     58   "com.sexy.legs",
     59   "com.spider.man",
     60   "com.super.mp3ringtone",
     61   "hot.goddchen.sexyvideos",
     62   "org.droiddream.yellow4",
     63   "power.nick.ypaint",
     64   "power.power.rate",
     65   "powerstudio.spiderman",
     66   "proscio.app.nick.ypaint",
     67   "super.sancron.ringtones.sexysb",
     68   "org.super.yellow4",
     69   "com.droid.publick.hotgirls",
     70   "com.super.free.sexringtones",
     71   "hot.goddchen.power.sexyvideos",
     72   "\0"};
     73 
     74 #define MAX_PACKAGES 512
     75 #define MAX_PACKAGE_NAME_LENGTH 512
     76 
     77 char installed_packages[MAX_PACKAGES][MAX_PACKAGE_NAME_LENGTH];
     78 int num_packages;
     79 
     80 void llog(char * msg, int result) {
     81   printf("%s:%s", msg, (result==0)?"Success":"Failure"); // Success is 0.
     82   if (result != 0 && errno != 0) {
     83     printf(" errorno=%s", strerror(errno));
     84   }
     85   printf("\n");
     86 }
     87 
     88 char *strstrip(char *s) {
     89   size_t size;
     90   char *end;
     91 
     92   size = strlen(s);
     93 
     94   if (!size)
     95     return s;
     96 
     97   end = s + size - 1;
     98   while (end >= s && isspace(*end))
     99     end--;
    100   *(end + 1) = '\0';
    101 
    102   while (*s && isspace(*s))
    103     s++;
    104 
    105   return s;
    106 }
    107 
    108 void populate_installed_packages() {
    109   FILE *fp;
    110   char pkg[MAX_PACKAGE_NAME_LENGTH];
    111   int len;
    112   num_packages = 0;
    113 
    114   fp = popen("/system/bin/pm list packages", "r");
    115 
    116   if (fp == NULL) {
    117     printf("failed to run /system/bin/pm list packages. not removing apps.\n");
    118     return;
    119   }
    120 
    121   while ((fgets(pkg, sizeof(pkg)-1,fp) != NULL)
    122          && num_packages < MAX_PACKAGES) {
    123 
    124     //printf("package before = %s\n", pkg);
    125     len = (strlen(pkg)-8 < MAX_PACKAGE_NAME_LENGTH)?(strlen(pkg)-8):MAX_PACKAGE_NAME_LENGTH;
    126     strncpy(installed_packages[num_packages], (pkg+8), len);
    127     // pkg+8 removes the initial "package:""
    128     strstrip(installed_packages[num_packages]);
    129     //printf("package after = %s\n", installed_packages[num_packages]);
    130     num_packages++;
    131   }
    132 
    133   pclose(fp);
    134 }
    135 
    136 int package_installed(const char *package_name) {
    137 
    138   int i;
    139 
    140   for (i=0; i<num_packages; i++) {
    141     if (strcmp(package_name, installed_packages[i]) == 0) {
    142       return i;
    143     }
    144   }
    145 
    146   return -1;
    147 }
    148 
    149 void remove_package(const char *package_name, int idx) {
    150   char command[1024];
    151   int retval;
    152 
    153   printf("%d:",idx);
    154   fflush(stdout);
    155 
    156   snprintf(command, 1024, "pm uninstall %s", package_name);
    157   retval = system(command);
    158 }
    159 
    160 
    161 void getSystemMountPoint(char * dev) {
    162   FILE *f = fopen("/proc/mounts", "r");
    163   if (f == NULL) {
    164     printf("unable to read /proc/mounts: \n");
    165     exit(1);
    166   }
    167 
    168   char mountPoint[1024];
    169   char type[1024];
    170   char opts[1024];
    171   int freq;
    172   int passno;
    173 
    174   while(1) {
    175     int retval = fscanf(f, "%s %s %s %s %d %d", dev,
    176                         mountPoint, type, opts, &freq, &passno);
    177     if (retval != 6) {
    178       llog("getsysmntpnt wrong num args", retval);
    179       exit(1);
    180     }
    181     if (strcmp(mountPoint, "/system")) {
    182       return;
    183     }
    184   }
    185 }
    186 
    187 int file_exists(const char *filename) {
    188   FILE *f;
    189 
    190   if (f = fopen(filename, "r")) {
    191     fclose(f);
    192     return 1;
    193   }
    194   return 0;
    195 }
    196 
    197 int main() {
    198   int retval;
    199   char dev[1024];
    200   int i=0;
    201 
    202   printf("elh\n");
    203 
    204   if (getuid() != 0) {
    205     printf("not running as root\n");
    206     exit(1);
    207   }
    208 
    209   populate_installed_packages();
    210 
    211   while (packages[i][0] != '\0') {
    212     if (package_installed(packages[i]) != -1) {
    213       remove_package(packages[i], i);
    214     }
    215     i++;
    216   }
    217 
    218   getSystemMountPoint(dev);
    219 
    220   errno = 0;
    221   retval = mount(dev, "/system", "ignored", MS_REMOUNT, NULL);
    222   llog("mnt rw", retval);
    223 
    224   if (retval != 0) {
    225     // no use continuing if we can't remount read-write
    226     exit(1);
    227   }
    228 
    229   if (file_exists("/system/app/DownloadProvidersManager.apk")) {
    230     errno = 0;
    231     retval = unlink("/system/app/DownloadProvidersManager.apk");
    232     llog("rm DownloadProvidersManager", retval);
    233 
    234     errno = 0;
    235     printf("pm uninst downloadsmanager:");
    236     fflush(stdout);
    237     system("/system/bin/pm uninstall com.android.providers.downloadsmanager");
    238   }
    239 
    240   if (file_exists("/system/app/com.android.providers.ammanage.apk")) {
    241     errno = 0;
    242     retval = unlink("/system/app/com.android.providers.ammanage.apk");
    243     llog("rm ammanager", retval);
    244 
    245     errno = 0;
    246     printf("pm uninst ammanager:");
    247     fflush(stdout);
    248     system("/system/bin/pm uninstall com.android.providers.ammanage");
    249   }
    250 
    251   if (file_exists("/system/bin/profile")) {
    252     errno = 0;
    253     retval = unlink("/system/bin/profile");
    254     llog("rm profile", retval);
    255   }
    256 
    257   if (file_exists("/system/bin/share")) {
    258     errno = 0;
    259     retval = unlink("/system/bin/share");
    260     llog("rm share", retval);
    261   }
    262 
    263   /*
    264    * technically it's ok if the next line fails, as the
    265    * filesystem will be mounted read-only on the next boot
    266    */
    267   errno = 0;
    268   retval = mount(dev, "/system", "ignored", MS_REMOUNT | MS_RDONLY, NULL);
    269   llog("mnt ro", retval);
    270 
    271   return 0;
    272 }
    273