2016-06-10 186 views
0

我試圖對第三方項目使用的base64編碼的應用程序進行逆向工程,所以我可以創建一個自定義用戶界面。我的方法在一個例子中取得了成功,但在其他例子中似乎並未達到標準(少數字符不太正確)。數據庫中base64解碼/編碼不一致

AQAAAAAAGQBec2lwOigwMjAxMjM0NTZbMC05XSspQC4qFwBzaXA6MDIwMTIyMTEzQDEyNy4wLjAuMQAA 

^^實際base64編碼

AQAAAAAAEABec2lwOigwMjAxMjM0NTZbMC05XSspQC4qEwBzaXA6MDIwMTIyMTEzQDEyNy4wLjAuMQoA 

,以配合PHP方法

由於控制字符^^最好的嘗​​試,我實現了一些JSON編碼,以使其更容易識別正在用於變量的字符串。該字符串與本例匹配,但base64編碼結果與預期的實際不同。

$actualfour = 'AQAAAAAAGQBec2lwOigwMjAxMjM0NTZbMC05XSspQC4qFwBzaXA6MDIwMTIyMTEzQDEyNy4wLjAuMQAA'; 
echo "".$actualfour; 
echo "<br />"; 

    $four = chr(01); 
    $four .= chr(00); 
    $four .= chr(00); 
    $four .= chr(00); 
    $four .= chr(00); 
    $four .= chr(00); 
    $four .= chr(16); 
    $four .= chr(00); 
    $four .= '^sip:(02[0-9]+)@.*'; 
    $four .= chr(19); 
    $four .= chr(00); 
    $four .= 'sip:[email protected] 
'.chr(00); 

$jsonfour = json_encode($four); 
echo "unencoded: ".$jsonfour; 
echo "<br />"; 
$encodefour = base64_encode($four); 
echo "".$encodefour; 
echo "<br />"; 
$jsonencodefour = json_encode(base64_decode($encodefour)); 
echo "encoded: ".$jsonencodefour; 
echo "<br />"; 

if ($encodefour != $actualfour) { echo "FAIL"; } else { echo "PASS"; } 

^^代碼方法

AQAAAAAAGQBec2lwOigwMjAxMjM0NTZbMC05XSspQC4qFwBzaXA6MDIwMTIyMTEzQDEyNy4wLjAuMQAA 
unencoded: "\u0001\u0000\u0000\u0000\u0000\u0000\u0010\u0000^sip:(02[0-9]+)@.*\u0013\u0000sip:[email protected]\n\u0000" 
AQAAAAAAEABec2lwOigwMjAxMjM0NTZbMC05XSspQC4qEwBzaXA6MDIwMTIyMTEzQDEyNy4wLjAuMQoA 
encoded: "\u0001\u0000\u0000\u0000\u0000\u0000\u0010\u0000^sip:(02[0-9]+)@.*\u0013\u0000sip:[email protected]\n\u0000" 
FAIL 

^^輸出

回答

1

您在$four有幾個錯誤。

  • chr(16)chr(0x19)chr(25)
  • chr(13)chr(0x17)chr(23)
  • 127.0.0.1之後的換行符應該是chr(00)

這裏是正確的$four

$four = chr(01); 
$four .= chr(00); 
$four .= chr(00); 
$four .= chr(00); 
$four .= chr(00); 
$four .= chr(00); 
$four .= chr(0x19); 
$four .= chr(00); 
$four .= '^sip:(02[0-9]+)@.*'; 
$four .= chr(0x17); 
$four .= chr(00); 
$four .= 'sip:[email protected]'.chr(00).chr(00); 

您可以通過比較json_encode(base64_decode($actualfour))json_encode($four)找到所有這些差異。請記住,當它顯示的控制字符爲\u####時,數字爲十六進制,而不是十進制。