Uguqulelo lukaGoogle kwi-API

Njengengxenye yelifu lakhe likaGoogle, uGoogle unikezela ngeGoogle API yoGuqulelo ngesiseko sendleko esisekwe kusetyenziso. Kukho i- API engenamaphepha enokusetyenziswa ngaphandle kwesitshixo , kodwa esalayo ukusebenza emva kwezicelo ezimbalwa. Xa usebenzisa umsebenzi wokuguqulela iwebhusayithi kwiGoogle Chrome, kuyabonakala ukuba amaphepha anokuguqulelwa kumgangatho olunge kakhulu ngaphandle komda obonakalayo.


Ngokucacileyo imodeli ye-nmt eseleyo sele isetyenziswa apha. Kodwa yeyiphi i-API esebenzisa iGoogle Chrome ngaphakathi ukuguqulela umxholo kwaye ngaba le API inokuqwalaselwa ngokuthe ngqo- nokuba kwicala leseva? Ukuhlalutya ukugcwala kwenethiwekhi, izixhobo ezinje ngeWireshark okanye iTelerik Fiddler , enokuthi ihlalutye ukugcwala kwabantu ngokufihlakeleyo, kuyacetyiswa. Kodwa i-Chrome ide ihambise izicelo ezithunyelwa kuguqulo lwephepha ngaphandle kwentlawulo : Banokujongwa ngokulula besebenzisa i- Chrome DevTools:

Ukuba uqhuba uguqulo, bamba isicelo esibalulekileyo sePOST ku https://translate.googleapis.com nge "Copy> Copy as cURL (bash)" kwaye uyenze ngesixhobo esifana nePostman , umzekelo, ungasithumela isicelo kwakhona ngaphandle kwengxaki:

Intsingiselo yeeparamitha ze-URL nayo icacile:

IsitshixoIxabiso lomzekeloIntsingiselo
anno3Imowudi yezichaso
umxhasite_libUlwazi lwabathengi (luyahluka, ixabiso "yi-webapp" ngokudlula kuGoogle Guqula ujongano lwewebhu; inefuthe kwifomathi yokubuyisa kunye nomda wokunciphisa)
ifomathihtmlIfomathi yomtya (ibalulekile ekuguqulweni kweethegi ze-HTML)
v1.0Inombolo yoguqulelo lukaGoogle
isitshixoAIzaSyBOti4mM-6x9WDnZIjIeyEU21OpBXqWBgwIsitshixo se-API (jonga ngezantsi)
logldvTE_20200210_00Uhlobo lweProtocol
IsldeUlwimi olusisiseko
tlxhUlwimi ekujoliswe kulo
spnmtImodeli yeML
TC1ayaziwa
sr1ayaziwa
tk709408.812158Ithokheni (jonga ngezantsi)
Ifashoni1ayaziwa

Ezinye izihloko zezicelo nazo zisetiwe- kodwa ezi zinokungahoywa. Emva kokungazikhethi ngesandla zonke ii-headers, kubandakanya nezo zivela kwiarhente yomsebenzisi , ingxaki yekhowudi ifunyenwe xa kufakwa abalinganiswa abakhethekileyo (apha xa kuguqulelwa " Molo weHlabathi "):

Ukuba uyaphinda uyisebenzise iarhente yomsebenzisi (engasebenziyo ngokubanzi), i-API ihambisa i-UTF-8 ebhalwe ngoonobumba:

Ngaba sele sikhona kwaye sinalo lonke ulwazi lokusebenzisa le API ngaphandle kweGoogle Chrome? Ukuba utshintsha umtya ukuba uguqulelwe (indawo yedatha q yesicelo se -POST) ukusuka, umzekelo, "Molo mhlaba" uye ku "Molo wehlabathi ! ", Sifumana umyalezo wemposiso:

Siguqulela le ilungisiweyo kwakhona kwiGoogle Chrome sisebenzisa umsebenzi wokuguqulela iwebhusayithi kwaye sifumanisa ukuba, ukongeza kwiparameter q , ipharamitha tk nayo itshintshile (zonke ezinye iiparameter zihlala zinjalo):

Ngokucacileyo, luphawu oluxhomekeke kumtya, olwakhiwo olungelula ukuwabona. Xa uqala uguqulelo lwewebhusayithi, ezi fayile zilandelayo zilayishiwe:

  • 1 ifayile yeCSS: translateelement.css
  • Imizobo emi-4: translate_24dp.png (2x), gen204 (2x)
  • 2 iifayile zeJS: main_de.js , element_main.js

Iifayile ezimbini zeJavaScript zenziwe zaze zalungiswa. Izixhobo ezinje ngeJS Nice kunye nee- de4js ngoku ziyasinceda ukwenza ezi fayile zifundeke ngakumbi. Ukuze uzilungise ngokusisigxina, sincoma i-Chrome Extension Isicelo, esilungisa iifayile ezikude kwindawo ekubhabhayo:

Ngoku sinokulungisa ikhowudi (ii- CORS kufuneka ziqale zisebenze kwiserver yasekhaya). Icandelo lekhowudi elifanelekileyo lokuvelisa ithokheni libonakala lifihliwe kweli candelo kwifayile ye- element_main.js:

b7739bf50b2edcf636c43a8f8910def9

Apha isicatshulwa sikhawuleze ngoncedo lotshintsho oluncinci . Kodwa ngelishwa sisaphoswa sisiqwengana sephazili: Ukongeza kwingxoxo a (engumbhalo oza kuguqulelwa), enye impikiswano b idluliselwe kumsebenzi Bp () -uhlobo lwembewu olubonakala luguquka amaxesha ngamaxesha kwaye lukwabandakanya Ukungena kwi-hashing. Kodwa uvela phi? Ukuba sitsibela kumnxeba wokusebenza weBp () , sifumana eli candelo lekhowudi lilandelayo:

b7739bf50b2edcf636c43a8f8910def9

Umsebenzi Hq ubhengezwe kwangaphambili ngolu hlobo lulandelayo:

b7739bf50b2edcf636c43a8f8910def9

Apha iDeobfuscater yashiya inkunkuma; Emva kokuba sithathe indawo yeString.fromCharCode ('...') ngentambo yomlinganiswa, susa iphelelwe li () kunye nokudibanisa iifowuni zomsebenzi [c (), c ()] , isiphumo:

b7739bf50b2edcf636c43a8f8910def9

Okanye kube lula:

b7739bf50b2edcf636c43a8f8910def9

Umsebenzi yq wachazwa ngaphambili njenge:

b7739bf50b2edcf636c43a8f8910def9

Imbewu ibonakala ikwisimo sehlabathi google.translate._const._ctkk , efumaneka ngexesha lokubaleka. Kodwa ibekwa phi? Kwenye, ifayile yeJS eyayilayishwe ngaphambili main_de.js, ubuncinci ikwafumaneka ekuqaleni. Songeza oku kulandelayo ekuqaleni:

b7739bf50b2edcf636c43a8f8910def9

Kwikhonsoli siyifumana ngokwenene imbewu yangoku:

Oku kushiya iGoogle Chrome uqobo, ekubonakala ukuba ibonelela ngembewu, njengokhetho lokugqibela. Ngethamsanqa, ikhowudi yemithombo yayo (iChromium, kubandakanya icandelo leToliki) ngumthombo ovulekileyo kwaye ke uyafumaneka esidlangalaleni. Sitsala indawo yogcino lwasekhaya kwaye sifumana umnxeba weTranscript :: GetTranslateScriptURL umsebenzi kwifayile translate_script.cc kumacandelo / translate / core / browser:

b7739bf50b2edcf636c43a8f8910def9

Umahluko kunye ne-URL uchazwe nzima kwifayile efanayo:

b7739bf50b2edcf636c43a8f8910def9

Ukuba ngoku ifayile element.js ngokusondeleyo kakhulu (emva kwakhona defocusing oko), sifumana i c._ctkk entry nzima-set - into google.translate Ikwabekelwe ngokufanelekileyo kwaye ekulayisheni yazo zonke ii-asethi ezifanelekileyo (oko sele safumanisa ngaphambili) kubangelwa:

b7739bf50b2edcf636c43a8f8910def9

Ngoku isitshixo sepharameter sihlala siqwalaselwe (ngexabiso AIzaSyBOti4mM-6x9WDnZIjIeyEU21OpBXqWBgw). Oku kubonakala ngathi sisitshixo esiqhelekileyo se-API yesitshixo (enokufumaneka nakwezinye iziphumo zikaGoogle ). Kokuba imisiwe kwi chromium kwifayile translate_url_util.cc kwi amacandelo / ukuguqulela / core / browser eneenkcukacha:

b7739bf50b2edcf636c43a8f8910def9

Isitshixo senziwe kugoogle_apis / google_api_keys.cc kwixabiso ledummy:

b7739bf50b2edcf636c43a8f8910def9

Nangona kunjalo, uvavanyo lubonisa ukuba i-API yeminxeba isebenza ngokufanayo ngaphandle kwale parameter iphambili. Ukuba uzama i-API, uya kuyifumana ikhowudi yenqanaba lama- 200 ubuyile ukuba uyaphumelela. Ukuba ubaleka uye kumda, ufumana ikhowudi yenqanaba 411 ngasemva nomyalezo " POST izicelo zifuna umxholo-ubude bentloko ". Kuyacetyiswa ke ngoko ukuba ubandakanye le ntloko ( esetwa ngokuzenzekelayo njenge- header yethutyana kwiPostman).

Ifomathi yokubuyisa yemitya eguqulweyo ayiqhelekanga xa kukho izivakalisi ezininzi kwisicelo esinye. Izivakalisi ezizodwa zifakwe kwii-i-b-HTML tags:

Kwakhona, uGoogle Chrome akathumeli i-HTML epheleleyo kwi-API, kodwa ugcina amaxabiso njenge- href kwisicelo (kwaye endaweni yoko usete ii-indices ukuze iithegi zinokwabelwa kamva kwicala lomxhasi):

Ukuba utshintsha ixabiso lomxhasi ophambili wePOST kwi te_lib (Google Chrome) kwiwebhu ( iwebhusayithi yokuTolika kuGoogle ), ufumana umtya wokugqibela oguqulweyo:

Ingxaki kukuba unamathuba amaninzi okubaleka kumda wokunciphisa kunokuba usebenzisa i- te_lib (ngokuthelekisa: nge- webapp oku kufikelelwe emva kwama-40,000 chars, nge te_lib akukho mda umiselweyo). Ke kufuneka sijongisise ukuba iChannel isicacisa njani isiphumo. Siza kuyifumana apha kwi- element_main.js:

b7739bf50b2edcf636c43a8f8910def9

Ukuba uthumela yonke ikhowudi ye-HTML kwi-API, ishiya iimpawu kwimpendulo eguqulweyo. Akunyanzelekanga ukuba sixelise yonke indlela yokuziphatha, kodwa sikhuphe umtya wokugqibela oguqulweyo kwimpendulo. Ukwenza oku, sakha isicatshulwa esincinci se-HTML esilahla iithegi ezingaphandle ze- <i> kubandakanya umxholo wazo kwaye sisuse ii-tag zangaphandle. Ngale nto engqondweni, ngoku sinokwakha uguqulelo lwecala le-API:

b7739bf50b2edcf636c43a8f8910def9

Oku kulandelayo ziziphumo zovavanyo lokuqala olwenziwe kwiinkqubo ezintlanu ezahlukeneyo ngeebhendithwidth ezahlukeneyo kunye needilesi ze-IP:

UphawuAbalinganiswa ngesicelo ngasinyeUbude bexeshaIreyithi yempazamoIindleko nge-API esemthethweni
13.064.662~25003: 36: 17h0%237,78€
24.530.510~25011: 09: 13h0%446,46€
49.060.211~25020: 39: 10h0%892,90€
99.074.487~100061: 24: 37h0%1803,16€
99.072.896~100062: 22: 20h0%1803,13€
Umnxeba: 284.802.766~ ~ ~ 5050159: 11: 37h0%Ixabiso le- € 5183.41

Qaphela: Le posti yebhlog kubandakanya zonke iincwadi zeempendulo zazibhalelwe uvavanyo kuphela. Musa ukusebenzisa amaphepha ukusetyenziswa elinemveliso, asebenze endaweni negosa API Google Translation .

Emva