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:
Isitshixo | Ixabiso lomzekelo | Intsingiselo |
anno | 3 | Imowudi yezichaso |
umxhasi | te_lib | Ulwazi lwabathengi (luyahluka, ixabiso "yi-webapp" ngokudlula kuGoogle Guqula ujongano lwewebhu; inefuthe kwifomathi yokubuyisa kunye nomda wokunciphisa) |
ifomathi | html | Ifomathi yomtya (ibalulekile ekuguqulweni kweethegi ze-HTML) |
v | 1.0 | Inombolo yoguqulelo lukaGoogle |
isitshixo | AIzaSyBOti4mM-6x9WDnZIjIeyEU21OpBXqWBgw | Isitshixo se-API (jonga ngezantsi) |
logld | vTE_20200210_00 | Uhlobo lweProtocol |
Isl | de | Ulwimi olusisiseko |
tl | xh | Ulwimi ekujoliswe kulo |
sp | nmt | Imodeli yeML |
TC | 1 | ayaziwa |
sr | 1 | ayaziwa |
tk | 709408.812158 | Ithokheni (jonga ngezantsi) |
Ifashoni | 1 | ayaziwa |
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 eguqulelweyo. Ke ngoko akufuneki sixelise yonke indlela yokuziphatha yokwahlulahlula, kodwa sikhuphe kuphela umtya wokugqibela, oguqulelweyo kwimpendulo. Ukwenza oku, sakha i-HTML encinci ye-tag ye-tag elahla i-tags yangaphandle <i> iquka umxholo wabo kwaye isuse i-tags <b> yangaphandle. Ngolu lwazi singakwazi ngoku (emva kokufaka izixhomekeki kunye nomqambi zifuna i-fzaninotto / faker vielhuber / stringhelper ) ukwakha i-server-side version ye-API yokuguqulela:
b7739bf50b2edcf636c43a8f8910def9
Oku kulandelayo ziziphumo zovavanyo lokuqala olwenziwe kwiinkqubo ezintlanu ezahlukeneyo ngeebhendithwidth ezahlukeneyo kunye needilesi ze-IP:
Uphawu | Abalinganiswa ngesicelo ngasinye | Ubude bexesha | Ireyithi yempazamo | Iindleko nge-API esemthethweni |
13.064.662 | ~250 | 03: 36: 17h | 0% | 237,78€ |
24.530.510 | ~250 | 11: 09: 13h | 0% | 446,46€ |
49.060.211 | ~250 | 20: 39: 10h | 0% | 892,90€ |
99.074.487 | ~1000 | 61: 24: 37h | 0% | 1803,16€ |
99.072.896 | ~1000 | 62: 22: 20h | 0% | 1803,13€ |
Umnxeba: 284.802.766 | ~ ~ ~ 5050 | 159: 11: 37h | 0% | 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 .