佳木斯湛栽影视文化发展公司

主頁 > 知識(shí)庫 > php微信小程序解包過程實(shí)例詳解

php微信小程序解包過程實(shí)例詳解

熱門標(biāo)簽:團(tuán)購網(wǎng)站 科大訊飛語音識(shí)別系統(tǒng) 銀行業(yè)務(wù) Mysql連接數(shù)設(shè)置 服務(wù)器配置 阿里云 電子圍欄 Linux服務(wù)器

這個(gè)解包只能看個(gè)大概

1.找到小程序壓縮包

1.1、手機(jī)root或安裝模擬器(我用的是夜神)

1.2、在模擬器上安裝微信(用android5系統(tǒng)的模擬器,低版本小程序容易打不開)

1.3、打開登陸微信后,打開小程序

1.4、打開模擬器自帶的文件管理器來到目錄:/data/data/com.tencent.mm/MicroMsg/{{一串32位的16進(jìn)制字符串文件夾}}/appbrand/pkg/

1.5、里面有很多wxapkg文件,找到最新修改日期的文件比如 -357038350_91.wxapkg,前面打勾選中

1.6、文件管理器回到/mnt/shared/Other目錄,粘貼即可,打開安卓模擬器上我的電腦 =〉打開電腦文件夾找到粘貼的文件-357038350_91.wxapkg 夜神教程鏈接:跳轉(zhuǎn)查看

2.對(duì)壓縮包解包

詳細(xì)參考:https://codechina.csdn.net/mirrors/leo9960/wechat-app-unpack?utm_source=csdn_github_accelerator

我用的php類:

使用方法:cmd =>cd php文件目錄 =〉php wx_unpak.php 357038350_91.wxapkg

我主要是想用其中的一些圖片,很多圖片都被base64了放到j(luò)s(app-service.js)和樣式(app-wxss.js)文件中了;需要我們匹配組裝一下

?php
$str = file_get_contents('_-357038350_97.wxapkg.unpacked/app-service.js');
$preg = '/(data:image.*?)\"/';
$len = strlen('data:image/png;base64,');
if(preg_match_all($preg, $str, $arr)){
  foreach($arr[1] as $k => $img){
    file_put_contents('./images/'.$k.'.png',base64_decode(substr($img,$len)));
    //echo substr($img,$len);exit;
  }
} else {
  echo 'no';
}

$str = file_get_contents('_-357038350_97.wxapkg.unpacked/app-wxss.js');
$preg = '/\((data:image.*?)\)/';
$len = strlen('data:image/png;base64,');
if(preg_match_all($preg, $str, $arr)){
  foreach($arr[1] as $k => $img){
    file_put_contents('./images/a2_'.$k.'.png',base64_decode(substr($img,$len)));
    //echo substr($img,$len);exit;
  }
} else {
  echo 'no';
}

wx_unpak.php

?php
/**
源文件目錄
  /data/data/com.tencent.mm/MicroMsg/{{一串32位的16進(jìn)制字符串文件夾}}/appbrand/pkg/
  /data/data/com.eg.android.AlipayGphone, 在files/nebulaInstallApps/目錄下存儲(chǔ)了所有加載過的小程序
 * [php] /path/to/unpack-wxapkg.php xxx.wxapkg>
 * php unpak.php _1123949441_351.wxapkg
 */

function unpack_wxapkg($file, $targetDir)
{
  if (!is_dir($targetDir)){
    mkdir($targetDir);
  }

  echo "Reading file.\n";
  $file = file_get_contents($file);
  $ptr = 18;

  $headerStruct = new StructDef([
    'mask1' => 'ushort',
    'info1' => 'ulong',
    'indexInfoLength' => 'ulong',
    'bodyInfoLength' => 'ushort',
    'mask2' => 'ushort',
    'fileCount' => 'ulong',
  ]);

  echo "Parsing file header...\n";

  $header = $headerStruct->unpack($file);
//  print_r(['header' => $header]);

  $unpackULong = function () use ($file, $ptr) {
    $ret = unpack_ulong(substr($file, $ptr, 4));
    $ptr += 4;
    return $ret;
  };

  $unpackUShort = function () use ($file, $ptr) {
    $ret = unpack_ushort(substr($file, $ptr, 2));
    $ptr += 2;
    return $ret;
  };


  $unpackStr = function ($len) use ($file, $ptr) {
    $ret = substr($file, $ptr, $len);
    $ptr += $len;
    return $ret;
  };


  $fileCount = $header['fileCount'];

  echo "Got $fileCount files.\n";

  $unpackedFiles = [];

  for ($i = 0; $i  $fileCount; $i++) {
    $nameLength = $unpackULong();
    $f = [
      'nameLength' => $nameLength,
      'name' => $unpackStr($nameLength),
      'offset' => $unpackULong(),
      'size' => $unpackULong(),
    ];

    echo "Unpacking file {$f['name']} ({$f['size']}bytes)...\n";

    $f['content'] = substr($file, $f['offset'], $f['size']);
    $unpackedFiles[] = $f;

    $destFile = $targetDir . $f['name'];
    $destDir = dirname($destFile);
    if (!is_dir($destDir)){
      mkdir($destDir, 0777, true);
    }

    file_put_contents($targetDir . $f['name'], $f['content']);
  }


//  print_r(['unpackedFiles' => $unpackedFiles]);



  echo "All done.\n";
}

function unpack_ulong($str)
{
  $x = unpack('N', $str);
  return $x[1];
}

function unpack_ushort($str)
{
  $x = unpack('n', $str);
  return $x[1];
}

class StructDef
{
  protected $def;
  protected $unpackFormat;

  public function __construct($def)
  {
    $this->def = $def;
    $this->unpackFormat = self::convertStructDefToUnpackFormat($def);
  }

  public function unpack($data)
  {
    return unpack($this->unpackFormat, $data);
  }

  protected static function convertStructDefToUnpackFormat($def)
  {
    $defTypeToUnpackType = [
      'byte' => 'C',
      'uchar' => 'C',
      'u8' => 'C',
      'ushort' => 'n',
      'u16' => 'n',
      'ulong' => 'N',
      'u32' => 'N',
    ];

    $ret = [];
    foreach ($def as $key => $type) {
      $ret[] = $defTypeToUnpackType[$type] . $key;
    }

    return implode('/', $ret);
  }
}

$packageFile = $argv[1];

//支持目錄下文件批量解壓
 if (is_dir($packageFile)){
  $handle = opendir($packageFile);
  if($handle){
    while(($fl = readdir($handle)) !== false){
      $temp = $packageFile.DIRECTORY_SEPARATOR.$fl;
      //如果不加 $fl!='.'  $fl != '..' 則會(huì)造成把$dir的父級(jí)目錄也讀取出來
      if(is_file($temp)){
        if($fl!='.'  $fl != '..'){
          $targetDir = $temp . '.unpacked';
          unpack_wxapkg($temp, $targetDir);
        }
      }
    }
  } 
}else if (is_file($packageFile)){
  $targetDir = $packageFile . '.unpacked';
  unpack_wxapkg($packageFile, $targetDir);
}else{
  echo HELP
Usage:
  [php] {$argv[0]} xxx.wxapkg>
  - Unpack the `xxx.wxapkg` to `xxx.wxapkg.unpacked` directory.
HELP;

  exit(1);
}

exit(0);

到此這篇關(guān)于php微信小程序解包的文章就介紹到這了,更多相關(guān)php微信小程序解包內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

您可能感興趣的文章:
  • PHP與以太坊交互詳解
  • php實(shí)現(xiàn)單筆轉(zhuǎn)賬到支付寶功能
  • php實(shí)現(xiàn)微信企業(yè)轉(zhuǎn)賬功能
  • 微信企業(yè)轉(zhuǎn)賬之入口類分裝php代碼
  • php實(shí)現(xiàn)微信公眾號(hào)企業(yè)轉(zhuǎn)賬功能
  • php7中停止php-fpm服務(wù)的方法詳解
  • PHP 對(duì)接美團(tuán)大眾點(diǎn)評(píng)團(tuán)購券(門票)的開發(fā)步驟
  • PHP小程序后臺(tái)部署運(yùn)行 LNMP+WNMP的方法
  • 為PHP模塊添加SQL SERVER2012數(shù)據(jù)庫的步驟詳解
  • 利用ajax+php實(shí)現(xiàn)商品價(jià)格計(jì)算
  • PHP實(shí)現(xiàn)創(chuàng)建以太坊錢包轉(zhuǎn)賬等功能

標(biāo)簽:江蘇 萍鄉(xiāng) 棗莊 衡水 廣元 衢州 大理 蚌埠

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《php微信小程序解包過程實(shí)例詳解》,本文關(guān)鍵詞  ;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請(qǐng)?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無關(guān)。
  • 相關(guān)文章
  • 收縮
    • 微信客服
    • 微信二維碼
    • 電話咨詢

    • 400-1100-266
    永寿县| 饶阳县| 宝兴县| 青神县| 沈丘县| 婺源县| 新沂市| 高台县| 防城港市| 平阳县| 凤山县| 洪洞县| 蒙阴县| 江川县| 香港| 兴安盟| 德保县| 眉山市| 五峰| 容城县| 沂水县| 宁武县| 德保县| 崇礼县| 枣强县| 南华县| 大英县| 长泰县| 河间市| 广宁县| 长丰县| 金塔县| 项城市| 北票市| 华坪县| 珲春市| 怀来县| 偃师市| 金乡县| 井陉县| 阜平县|