Rumah > php教程 > php手册 > php脚本生成google play url的下载链接,下载apk并自动反编译后

php脚本生成google play url的下载链接,下载apk并自动反编译后

WBOY
Lepaskan: 2016-06-06 19:48:08
asal
4636 orang telah melayarinya

需求: get the offer tracking link follow the redirect to get google play url Go to http://apps.evozi.com/apk-downloader/ Enter google play url Download APK file Decompile APK file using https://code.google.com/p/android-apktool/wiki/Apktoo

    需求:

    get the offer tracking link
    follow the redirect to get google play url
    Go to http://apps.evozi.com/apk-downloader/
    Enter google play url
    Download APK file
    Decompile APK file using https://code.google.com/p/android-apktool/wiki/ApktoolOptions#Decompile_Options
    Extract this file
    [app name]/smali/com/kochava/android/tracker/Global.smali
    Extract this line
    .field public static final SDK_VERSION:Ljava/lang/String; = "Android20141023"
    This output the Kochava SDK version numbe

    脚本的目的就是将上面的操作步骤自动化

    运行脚本之前必须在linux里安装apktool和java环境

    操作演示:

    php脚本生成google play url的下载链接,下载apk并自动反编译后

 上面输入的是应用的包名字,你也可以输入对应的google play url:     https://play.google.com/store/apps/details?hl=en&id=com.priceline.android.negotiator

  以下是代码:

 

<span>  1</span> <span>php
</span><span>  2</span>    <span>fwrite</span>(STDOUT, "please enter the google play url or app package name: "<span>);
</span><span>  3</span>    <span>$url</span> = <span>trim</span>(<span>fgets</span><span>(STDIN));
</span><span>  4</span>    <span>$name_reg</span>="/id=([^&]+)/"<span>;
</span><span>  5</span>    <span>preg_match</span>(<span>$name_reg</span>,<span>$url</span>,<span>$name</span><span>);
</span><span>  6</span>    <span>if</span>(<span>empty</span>(<span>$name</span><span>)){
</span><span>  7</span>           <span>$packagename</span>=<span>$url</span><span>;
</span><span>  8</span>    }<span>else</span><span>{
</span><span>  9</span>           <span>$packagename</span>=<span>$name</span>[1<span>];
</span><span> 10</span> <span>   }
</span><span> 11</span>    <span>function</span><span> getParameter(){
</span><span> 12</span>       <span>$url</span>="http://apps.evozi.com/apk-downloader"<span>;
</span><span> 13</span>          <span>$context</span>=<span>file_get_contents</span>(<span>$url</span><span>);
</span><span> 14</span>          <span>preg_match</span>("/var evoziJsData = {(.+)};/",<span>$context</span>,<span>$json</span><span>);
</span><span> 15</span>          <span>$t</span>=<span>explode</span>(",",<span>$json</span>[1<span>]);
</span><span> 16</span>          <span>foreach</span>(<span>$t</span> <span>as</span> <span>$key</span>=><span>$value</span><span>){
</span><span> 17</span>              <span>$value</span>=<span>str_replace</span>(' ','',<span>$value</span><span>);
</span><span> 18</span>              <span>$t</span>[<span>$key</span>]=<span>$value</span><span>;
</span><span> 19</span> <span>         }
</span><span> 20</span>          <span>$token_value</span>=<span>explode</span>(":",<span>$t</span>[1<span>]);
</span><span> 21</span>          <span>$t_value</span>=<span>$token_value</span>[1<span>];
</span><span> 22</span>          <span>$dtrken</span>=<span>explode</span>(":",<span>$t</span>[2<span>]);
</span><span> 23</span>          <span>$patten</span>="/var ".<span>$dtrken</span>[1]." = '(.+)';/"<span>;         
</span><span> 24</span>          <span>preg_match</span>(<span>$patten</span>,<span>$context</span>,<span>$daw</span><span>);
</span><span> 25</span>          <span>$dtrken</span>[1]=<span>$daw</span>[1<span>];
</span><span> 26</span>          <span>return</span> <span>array</span>("t"=><span>$t_value</span>,"dtrken"=><span>$dtrken</span><span>);
</span><span> 27</span> <span>   }
</span><span> 28</span>    <span>function</span> ajaxPost(<span>$packagename</span><span>) {
</span><span> 29</span>          <span>$tk</span>=<span>getParameter();
</span><span> 30</span>          <span>$t</span>=<span>$tk</span>['t'<span>];
</span><span> 31</span>          <span>$dtrken_key</span>=<span>$tk</span>['dtrken'][0<span>];
</span><span> 32</span>          <span>$dtrken_value</span>=<span>$tk</span>['dtrken'][1<span>];
</span><span> 33</span>             <span>$post_url</span>='http://api.evozi.com/apk-downloader/download'<span>;
</span><span> 34</span>           <span>$data</span> = 'packagename='.<span>$packagename</span>.'&t='.<span>$t</span>.'&'.<span>$dtrken_key</span>.'='.<span>$dtrken_value</span>.'&fetch=false'<span>;
</span><span> 35</span>             <span>$ch</span> =<span> curl_init();
</span><span> 36</span>             <span>$headers</span> = <span>array</span>('content-type: application/x-www-form-urlencoded;charset=UTF-8'<span>);
</span><span> 37</span>             curl_setopt(<span>$ch</span>, CURLOPT_URL, <span>$post_url</span><span>);
</span><span> 38</span>             curl_setopt(<span>$ch</span>, CURLOPT_POSTFIELDS, <span>$data</span><span>); 
</span><span> 39</span>             curl_setopt(<span>$ch</span>, CURLOPT_HTTPHEADER, <span>$headers</span><span>);
</span><span> 40</span>             curl_setopt(<span>$ch</span>, CURLOPT_POST, 1<span>);
</span><span> 41</span>             curl_setopt(<span>$ch</span>, CURLOPT_RETURNTRANSFER, 1<span>);
</span><span> 42</span>             <span>$results</span> = curl_exec(<span>$ch</span><span>);
</span><span> 43</span>             curl_close(<span>$ch</span><span>);
</span><span> 44</span>             <span>$results</span> = json_decode(<span>$results</span><span>);
</span><span> 45</span>             <span>return</span> <span>$results</span><span>;
</span><span> 46</span> <span>        }
</span><span> 47</span>         <span>function</span> getVersion(<span>$packagename</span><span>){
</span><span> 48</span>               <span>$version</span>="/Android[0-9]+/"<span>;
</span><span> 49</span>               <span>$path</span>=<span>$packagename</span>."/smali/com/kochava/android/tracker"<span>;
</span><span> 50</span>               <span>$filename1</span>="Global.smali"<span>;
</span><span> 51</span>               <span>$filename2</span>="a.smali"<span>;
</span><span> 52</span>               <span>if</span>(<span>is_dir</span>(<span>$path</span><span>)){
</span><span> 53</span>                     <span>$file</span>=<span>scandir</span>(<span>$path</span><span>);
</span><span> 54</span>                     <span>foreach</span>(<span>$file</span> <span>as</span> <span>$key</span>=><span>$value</span><span>){
</span><span> 55</span>                           <span>$filename</span>=<span>$value</span><span>;
</span><span> 56</span>                           <span>if</span>(<span>isset</span>(<span>$filename</span>)&<span>file_exists</span>(<span>$path</span>."/".<span>$filename</span><span>)){
</span><span> 57</span>                                     <span>$context</span>=<span>file_get_contents</span>(<span>$path</span>."/".<span>$filename</span><span>);
</span><span> 58</span>                                     <span>preg_match</span>(<span>$version</span>,<span>$context</span>,<span>$v</span><span>);
</span><span> 59</span>                                     <span>if</span>(!<span>empty</span>(<span>$v</span><span>)){
</span><span> 60</span>                                        <span>$vs</span>=<span>$v</span>[0<span>];    
</span><span> 61</span>                                        <span>break</span><span>;
</span><span> 62</span> <span>                                    }
</span><span> 63</span> <span>                        }
</span><span> 64</span> <span>                    }
</span><span> 65</span>                     <span>if</span>(<span>isset</span>(<span>$vs</span><span>)){
</span><span> 66</span>                           <span>$info</span>=<span>array</span>("status"=>200,"description"=>"success detection in the file:".<span>$filename</span>,"version"=><span>$vs</span><span>);
</span><span> 67</span>                      }<span>else</span><span>{
</span><span> 68</span>                           <span>$info</span>=<span>array</span>("status"=>203,"description"=>"failure detection in all the .smal file:(".<span>$file</span>."),we can't find the android version number"<span>);
</span><span> 69</span> <span>                     }
</span><span> 70</span>               }<span>else</span><span>{
</span><span> 71</span>                    <span>$info</span>=<span>array</span>("status"=>201,"description"=>"there is no such directory:".<span>$path</span><span>);
</span><span> 72</span> <span>              }
</span><span> 73</span>               <span>$info</span>=json_encode(<span>$info</span><span>);
</span><span> 74</span>               <span>return</span> <span>$info</span><span>;
</span><span> 75</span> <span>        }
</span><span> 76</span>         <span>function</span> getFile(<span>$file_path</span>,<span>$file_name</span><span>){
</span><span> 77</span>             <span>exec</span>("sudo wget -O <span>$file_name</span> <span>$file_path</span>"<span>);
</span><span> 78</span> <span>        }
</span><span> 79</span>         <span>function</span> deCompileApk(<span>$file_name</span><span>){
</span><span> 80</span>                   <span>print_r</span>("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++start decompile apk,this may need a long time,please wait...++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++".<span>PHP_EOL</span><span>);
</span><span> 81</span>                   <span>exec</span>("sudo apktool d <span>$file_name</span>"<span>);
</span><span> 82</span>                   <span>print_r</span>("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++decompile end++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++".<span>PHP_EOL</span><span>);
</span><span> 83</span> <span>        }
</span><span> 84</span>         <span>function</span> delFile(<span>$packagename</span>,<span>$file_name</span><span>){
</span><span> 85</span>                   <span>exec</span>("sudo rm -f <span>$file_name</span>"<span>);
</span><span> 86</span>                   <span>exec</span>("sudo rm -rf <span>$packagename</span>"<span>);
</span><span> 87</span> <span>        }
</span><span> 88</span>         <span>$result</span>=ajaxPost(<span>$packagename</span><span>);
</span><span> 89</span>         <span>if</span>(<span>$result</span>->status=="success"<span>){
</span><span> 90</span>              <span>$file_name</span>=<span>$packagename</span>."."."apk"<span>;
</span><span> 91</span>            <span>$downloadUrl</span>=<span>$result</span>-><span>url;
</span><span> 92</span>            <span>$downloadUrl</span>=<span>preg_replace</span>("/&/i", "\&", <span>$downloadUrl</span><span>);
</span><span> 93</span>        getFile(<span>$downloadUrl</span>,<span>$file_name</span><span>);
</span><span> 94</span>        deCompileApk(<span>$file_name</span><span>);
</span><span> 95</span>        <span>$info</span>=getVersion(<span>$packagename</span><span>);
</span><span> 96</span>        delFile(<span>$packagename</span>,<span>$file_name</span><span>);
</span><span> 97</span>         }<span>else</span><span>{
</span><span> 98</span>              <span>$tinfo</span>=<span>array</span>("status"=>204,"description"=>"we can't generate Download Link from http://apps.evozi.com/apk-downloader/,please check your input of google play url or app package name!"<span>);
</span><span> 99</span>              <span>$info</span>=json_encode(<span>$tinfo</span><span>);
</span><span>100</span> <span>        }
</span><span>101</span>         <span>print_r</span>(<span>$info</span>.<span>PHP_EOL</span><span>);
</span><span>102</span> ?>
Salin selepas log masuk

 

sumber:php.cn
Kenyataan Laman Web ini
Kandungan artikel ini disumbangkan secara sukarela oleh netizen, dan hak cipta adalah milik pengarang asal. Laman web ini tidak memikul tanggungjawab undang-undang yang sepadan. Jika anda menemui sebarang kandungan yang disyaki plagiarisme atau pelanggaran, sila hubungi admin@php.cn
Cadangan popular
Tutorial Popular
Lagi>
Muat turun terkini
Lagi>
kesan web
Kod sumber laman web
Bahan laman web
Templat hujung hadapan