⑴ Node.js浣跨敤ffi-napi,ref-napi,ref-array-napi,ref-struct-napi璋冪敤鍔ㄦ佸簱
浣跨敤electron寮榪涜屾岄潰紼嬪簭鐨勫紑鍙戱紝浼間箮鎴愪簡WEB鍓嶇寮鍙戜漢鍛樿漿妗岄潰紼嬪簭寮鍙戠殑棣栭夈傝繎鏈熸湁涓浜涗嬌鐢ㄥ湪electron涓浣跨敤鍔犲瘑閿佺殑闇奼傦紝瀛︿範浜嗕竴涓嬪湪Node.js涓閫氳繃ffi-napi妯″潡璋冪敤鍔ㄦ侀摼鎺ュ簱錛屾妸鍑犳懼姞瀵嗛攣浜у搧鐨勫姩鎬佸簱浣跨敤javascript灝佽呬簡涓涓嬶紝瀹炵幇浜唀lectron涓浣跨敤鍔犲瘑閿佸姛鑳姐
寮鍙戣繃紼嬩腑閬囧埌浜嗕竴浜涢棶棰橈紝韙╀簡涓浜涘潙錛岃繖閲屾葷粨璁板綍涓涓嬨傝繖閲屼嬌鐢ㄦ帴鍙e嚱鏁板弬鏁扮被鍨嬫瘮杈冨嶆潅鐨凴OCKEY-ARM鐨勫姩鎬侀摼鎺ュ簱鏉ヨ繘琛屽紑鍙戙
NOTE: javascript灝佽呯殑ROCKEY-ARM鎺ュ彛妯″潡婧愮爜錛屾垜宸茬粡鍒嗕韓鍑烘潵錛屽傛灉鍙鏄闇瑕乪lectron鎴栬匩ode.js宸ョ▼涓浣跨敤ROCKEY-ARM鐨勭綉鍙嬶紝鍙浠ョ洿鎺ヤ嬌鐢ㄣ
棣栧厛闇瑕佸湪node.js欏圭洰涓瀹夎呰皟鐢ㄥ姩鎬侀摼鎺ュ簱鏃墮渶瑕佷緷璧栫殑妯″潡 ffi-napi,ref-napi,ref-array-napi,ref-struct-napi 銆
涓嬮潰澶ф備粙緇嶄竴涓嬭繖鍑犱釜妯″潡鐨勭敤閫旓細
鍚 椋炲ぉ璇氫俊 璐涔癛OCKEY-ARM鍔犲瘑閿佷駭鍝侊紝鍙浠ヨ幏寰桼OCKEY-ARM鐨凷DK錛屽彲浠ヨ幏寰梂indows鍜孡inux鐨勫姩鎬侀摼鎺ュ簱錛屾枃浠跺悕涓鑸涓篋ongle_d.鍜宭ibRockeyARM.so.0.3銆
ffi-napi鏀鎸乄indows錛孡inux緋葷粺錛屾墍浠.dll鍜.so閮藉彲浠ユ敮鎸侊紝鍦ㄤ笉鍚岀殑鎿嶄綔緋葷粺涓嬪幓鍔犺澆涓嶅悓鐨勫姩鎬佸簱鏂囦歡灝卞彲浠ヤ簡銆傚姞杞藉姩鎬佸簱鐨勬柟娉曞備笅:
Library()絎涓涓鍙傛暟鏄.dll鐨勮礬寰勶紝linux緋葷粺鏄.so鐨勮礬寰勩傜浜屼釜鍙傛暟rockeyInterface鏄鍔ㄦ佸簱瀵煎嚭鍑芥暟鐨勫0鏄庯紝ROCKEY-ARM鐨勫煎嚭鍑芥暟姣旇緝澶氾紝鎴戝崟鐙鎷垮嚭鏉ュ畾涔夈傚叿浣撲笅闈浼氳插埌銆
棣栧厛浠嶳OCKEY-ARM涓鎵懼嚑涓鍙傛暟綆鍗曠殑鍑芥暟鏉ュ0鏄庝竴涓嬨
棣栧厛鐪嬩竴涓嬩笂闈㈠嚑涓鎺ュ彛鐢ㄥ埌鐨勬暟鎹綾誨瀷鏈:DONGLE_HANDLE,DWORD,DONGLE_HANDLE ,int,BYTE 榪欏嚑縐嶃
鍐嶇湅涓媐fi-napi鏀鎸佺殑ref-napi鏀鎸佺殑鏁版嵁綾誨瀷鏈変互涓嬬被鍨嬶細
鍙傛暟榪欓噷搴旇ョ敤闀垮害涓鑷寸殑鏁版嵁綾誨瀷錛屽彲浠ユ湁浠ヤ笅鍖歸厤銆
澹版槑鐨勫啓娉曞備笅錛
涓涓猨son錛宬ey鏄鍔ㄦ佸簱瀵煎嚭鍑芥暟鍚嶏紝姣斿'Dongle_Open'錛寁alue鏄涓鍒楄〃錛岀涓涓鍏冪礌鏄榪斿洖鍊礆紝絎浜屼釜鍏冪礌鏄鍙傛暟銆傚叾涓鍙傛暟榪樻槸涓鍒楄〃銆傝繖涓猺ef-napi涓鏈夐傚悎綾誨瀷鐨勶紝鐩存帴鍐欑О鍏蜂綋綾誨瀷鍗沖彲錛屾瘮濡傝繑鍥炲糄WORD鍜屼紶鍏ョ殑闀垮害int錛屾垜榪欓噷閮界敤'int'銆傚叾浠栫殑鍙傛暟鎴戦濆栧畾涔変簡鍙ユ焺ryHandle銆佸彞鏌勭殑鎸囬拡ptrHandle銆佸瓧鑺傜殑鎸囬拡ptrByte銆傚叾涓璻yHandle錛宲trryHandle錛宲trByte鐨勫畾涔夊備笅錛
DONGLE_HANDLE鏈璐ㄦ槸void *綾誨瀷, void* 綾誨瀷鏈寮濮嬬殑鏃跺欏勫浘瀹氫箟涓涓獀oid鐨勬暟緇勶紝鐒跺悗鐢╲oid鏁扮粍鏉ヨ〃紺簐oid 錛岀劧鍚庡彂鐜版姤鏂璦閿欒錛屾暟緇勪笉鏀鎸乿oid綾誨瀷銆傛墍浠ュ氨鐩存帴鐢ㄦ棤絎﹀彿鏁版潵琛ㄧずvoid鎸囬拡錛屽湪64浣嶇郴緇熸槸8瀛楄妭錛32浣嶇郴緇熸槸4瀛楄妭錛屼嬌鐢╱int綾誨瀷灝卞彲浠ヤ簡銆侱ONGLE_HANDLE 銆
鍦≧OCKEY-ARM鐨勫嚱鏁頒腑涔熸湁寰堝氬甫鍙傛暟鐨勬帴鍙o紝姣斿傦細
鎷誇互涓婁袱涓鍑芥暟鎺ュ彛涓句緥錛孌ongle_Enum涓鐨勭涓涓鍙傛暟鏄涓涓鎸囧悜DONGLE_INFO緇撴瀯浣撶殑鎸囬拡錛岃繍琛屽悗榪斿洖璁懼囦俊鎮鐨勫垪琛錛屼嬌鐢≧OCKEY-ARM鐨勬椂鍊欓渶瑕侀氳繃鏋氫婦鍑芥暟鑾峰緱璁懼囦俊鎮鍒楄〃錛岀劧鍚庢瘮杈冧駭鍝両D鎴栬呯‖浠禝D鍐沖畾鎵撳紑鍝涓涓璁懼囥備負浜嗘柟渚誇粠鏋氫婦鍑芥暟榪斿洖鐨勮懼囦俊鎮涓鏂逛究鐨勮В鏋愬嚭浜у搧ID鎴栬呯‖浠禝D絳変俊鎮錛岄渶瑕佹妸DONGLE_INFO* pDongleInfo榪欎釜鍙傛暟澹版槑鎴愪竴涓緇撴瀯浣撴暟緇勩侱ongle_RsaGenPubPriKey()鍑芥暟涓鏈塕SA_PUBLIC_KEY ,RSA_PRIVATE_KEIY 涓や釜緇撴瀯浣撴寚閽堝弬鏁幫紝鍥犱負鍦ㄨ繖閲屼竴鑸鐢ㄦ埛騫朵笉闇瑕佽В鏋怰SA瀵嗛掗涓鐨刵,d,e絳夊垎閲忥紝鍙浠ョ洿鎺ュ仛浣滀負涓涓瀛楄妭鏁扮粍錛岀洿鎺ュ0鏄庢垚涓婇潰鐨刾trByte綾誨瀷鍗沖彲銆傛墍浠ュ湪澹版槑濡備笅錛
璋冪敤ffi-napi澹版槑鐨勫嚱鏁幫紝涓昏佹槸緇欒嚜宸卞畾涔夌殑鏁版嵁綾誨瀷璧嬪垵鍊間互鍙婅幏寰楄嚜瀹氫箟鍙傛暟鐨勮繑鍥炲箋備笅闈㈠垎鍒璇存槑銆
榪欓噷鐨剗nt*錛屾槸璁╁嚱鏁拌繑鍥炶懼囩殑鏁伴噺錛屾垨鑰呬紶鍏ヨ緭鍏ユ暟鎹鐨勯暱搴︽垨鑰呬紶鍑鴻緭鍑烘暟鎹鐨勯暱搴︼紝鎵浠ュ彧瑕佸畾涔変竴涓闀垮害涓1鐨剗nt鏁扮粍鍗沖彲錛屽備笅錛
緇欎紶鍏ョ殑鏁版嵁璧嬪礆紝鍙瑕佺粰涓嬫爣涓0鐨勫厓緔犺祴鍊煎嵆鍙銆
榪欎釜鍙傛暟鏄鏋氫婦鍑芥暟浼犲嚭鏋氫婦鍒拌懼囦俊鎮鐨勫垪琛錛屾灇涓懼埌澶氬皯璁懼囷紝灝變紶鍑哄氬皯涓狣ONGLE_INFO錛屾墍浠ラ渶瑕佷紶鍏ヨ凍澶熸暟閲忕殑鐨凞ONGLE_INFO錛屽備笅錛
榪欎釜鍙傛暟涓鑸鏄浣滀負浼犲叆浼犲嚭鏁版嵁鐨勭紦鍐插尯鐨勶紝鎵浠ュ壋寤烘暟緇勭殑鏃跺欙紝闇瑕佸壋寤鴻凍澶熼暱鐨勭┖闂達紝濡備笅錛
寮鍙戠殑榪囩▼涓錛岃俯鍒頒竴浜涘潙鑰借浜嗕笉灝戞椂闂達紝榪欓噷鎬葷粨涓涓嬨
ROCKEY-ARM鐨勭粨鏋勪綋鏄鎸夊瓧鑺傚歸綈鐨勶紝ref-struct-napi娌℃湁鎵懼埌璁劇疆瀛楄妭瀵歸綈鐨勬柟娉曘傚綋鏃跺0鏄庣殑緇撴瀯浣撳備笅錛
嫻嬭瘯鐨勬椂鍊欎細鍙戠幇瀹氫箟鐨勭粨鏋勪綋鍜孯OCKEY-ARM瀹氫箟鐨勭粨鏋勪綋瀵歸綈鏂瑰紡涓嶄竴鏍鳳紝浜庢槸鎶妋_Birthday鍜宮_HID涓や釜鎴愬憳浠巖ef.types.uint64錛屾媶鍒嗘垚宸﹀彸涓や釜uint32錛岃繖鏍峰氨鍙浠ヨ╃粨鏋勪綋瀵歸綈鏂瑰紡鍜孯OCKEY-ARM鐨勪竴鑷淬備嬌鐢╩_Birthday鍜宮_HID鐨勬椂鍊欙紝闇瑕佽插乏鍙充袱涓猽int32鎷兼帴涓浜涳紝紼嶅井楹葷儲涓鐐癸紝浣嗘槸鍦ㄦ病鎵懼埌閰嶇疆StructType瀵歸綈鏂圭殑鎯呭喌錛屼繚璇佺粨鏋滄g『錛岃繕鏄鍙浠ユ帴鍙楃殑銆
⑵ DelphiforLinux涓搴旂敤鍏變韓瀵硅薄搴
1. Delphi for Linux鏄疊orland鍏鍙告帹鍑虹殑鍩轟簬Linux騫沖彴鐨勯潰鍚戝硅薄鐨勫彲瑙嗗寲寮鍙戝伐鍏鳳紝鏄鐩鍓峀inux騫沖彴涓婂緢濂界殑搴旂敤寮鍙戝伐鍏楓侱elphi for Linux涔熺ОKylix錛屽紑鍙戣呯敤Kylix寮鍙慙inux搴旂敤紼嬪簭鏃訛紝鍙鑳戒細浣跨敤鍒癓inux鎿嶄綔緋葷粺鏈韜甯︾殑澶ч噺SO鏂囦歡銆
2. SO鏄涓縐嶇壒孌婄殑榪愯屾枃浠訛紝鍖呭惈鑻ュ共鏂規硶銆佸硅薄鍜岃祫婧愩傚畠涓嶈兘鐩存帴榪愯岋紝浣嗗彲浠ヨ獽ylix搴旂敤紼嬪簭鎴栧叾浠栧彲鎵ц屾枃浠跺姩鎬佽皟鐢ㄣ係O鏂囦歡鎵╁睍鍚嶄負so銆傜紪璇戝墠婧愭枃浠舵墿灞曞悕涓篸pr銆傛湰鏂囨墍涓句緥瀛愬潎鍦≧ed Hat Linux鍙奒ylix鐜澧冧笅璋冭瘯緙栬瘧閫氳繃錛屽苟鍙姝e父榪愯屻
3. SO搴撴枃浠剁殑緇勬垚鍜孠ylix鏍囧噯鍗曞厓鏂囦歡鐨勫唴閮ㄧ粨鏋勫熀鏈鐩稿悓錛屼篃鏈夊0鏄庛佸疄鐜板強鍒濆嬪寲閮ㄥ垎銆傚尯鍒涔嬩竴鍦ㄤ簬SO搴撳彧鏄鍏朵粬紼嬪簭鍙浠ヨ皟鐢ㄧ殑鏂規硶錛堝寘鎷鍑芥暟鍙婅繃紼嬶級闆嗗悎銆傚尯鍒涔嬩簩錛屽簱紼嬪簭浠library鍏抽敭瀛楄岄潪project寮澶村惎鍔ㄥ叾欏圭洰鏂囦歡銆傚簱紼嬪簭鍖呭惈鏈塭xports璇鍙ワ紝鍏跺垪鍑鴻佸悜澶栭儴鎻愪緵鐨勫煎嚭鍑芥暟鍙婅繃紼嬨
4. 鍏變韓瀵硅薄搴撶殑鍒涘緩錛孲O搴撴枃浠剁殑鏋勬垚錛屽嚱鏁伴噸杞斤紝鐗規畩緙栬瘧鎸囦護錛岄噰鐢―elphi for Linux鍒涘緩SO鐨勭紪紼嬭勫垯錛屼嬌鐢ㄥ墠鐨凩inux緋葷粺璁劇疆錛屼互鍙婂湪Delphi for Linux涓鐢ㄩ殣寮忔垨鏄懼紡閾炬帴鏂規硶瑁呭叆鍜屼嬌鐢⊿O鍑芥暟鐨勫熀鏈鏂規硶錛岀粡楠屽強鎶宸э紝騫跺瑰簲鐢⊿O鍙鑳藉嚭鐜扮殑闂棰樿繘琛屼簡鎺㈣ㄥ拰鍒嗘瀽銆
5. 鍏變韓瀵硅薄搴撳熀鏈姒傚康錛氬氫釜Kylix紼嬪簭鎴栧畠鐨勫氫釜鍗曞厓鏂囦歡鍙閫氳繃鎺ュ彛鍏辯敤涓涓猄O搴撴枃浠訛紱鏌愪竴涓狵ylix紼嬪簭鍙閫氳繃澶氫釜鎺ュ彛浣跨敤澶氫釜SO搴撴枃浠訛紝榪欐牱SO鍙樻垚涓縐嶅彲鍏辯敤鐨勮祫婧愶紝瀹炵幇鐪熸g殑璧勬簮鍏變韓錛屽ぇ澶х緝灝忎簡Kylix搴旂敤紼嬪簭鐨勬墽琛屼唬鐮侊紝澧炲己浜嗚蔣浠剁殑鍙閲嶇敤鎬с
6. 灝哠O鏂囦歡浣滀負Kylix搴旂敤紼嬪簭鐨勫叕鍏辮皟鐢ㄦā鍧楄捐℃椂錛岀敱浜庡叾鐙絝嬩簬搴旂敤紼嬪簭錛岃蔣浠跺崌綰ф椂鍙闇淇鏀筍O搴撴枃浠跺強緙栬瘧SO錛屾棤闇鏇存敼鍙婇噸緙栬瘧Kylix搴旂敤涓葷▼搴忋
7. 涓嶄粎鍙浣跨敤Kylix緙栧啓SO搴擄紝榪樺彲浣跨敤C鎴朇++絳夊父鐢ㄨ璦鏉ョ紪鍐欙紝鍙瑕侀伒寰鐗瑰畾鐨勬帴鍙h勮寖銆
8. 鍏變韓瀵硅薄搴撶殑浣跨敤錛孠ylix搴旂敤紼嬪簭浣跨敤SO搴撴椂鍙浠ラ噰鐢ㄤ袱縐嶆柟寮忥紝涓縐嶆槸闅愬紡閾炬帴錛圛mplicit linking錛夛紝涔熺О闈欐佽呭叆錛涘彟涓縐嶆槸鏄懼紡閾炬帴錛圗xplicit Linking錛夛紝涔熺О鍔ㄦ佽呭叆銆
9. 浣跨敤鍓嶇殑緋葷粺璁劇疆錛岃嚜瀹氫箟SO搴撳緩濂藉悗錛孠ylix搴旂敤紼嬪簭璋冪敤鏃朵細鎶ラ敊錛岃繖鏄鍥犱負Kylix鎵句笉鍒版柊寤哄簱銆傚繀欏誨圭郴緇熻繘琛岀浉鍏寵劇疆錛岃繖涓庡湪Delphi for Windows涓浣跨敤DLL搴撲笉鍚屻侱LL搴撳緩濂藉悗鍙闇灝嗙紪璇戝悗鐨凞LL鏂囦歡鏀懼埌Delphi涓葷▼搴忕洰褰曚笅鍗沖彲浣跨敤銆
10. 闅愬紡閾炬帴錛屽疄鐜伴殣寮忛摼鎺ュ苟涓嶉毦錛屽彧闇鍦ㄥ簲鐢ㄧ▼搴忎腑鍔犲叆搴撳嚱鏁扮殑澹版槑璇鍙ュ強搴撶殑external瀹氫箟浠庡彞錛屽垯搴撳嚱鏁板彲浠ュ拰涓鑸灞閮ㄥ嚱鏁頒竴鏍蜂嬌鐢ㄣ
11. 鏄懼紡閾炬帴錛屾樉寮忛摼鎺ユ槸搴旂敤紼嬪簭鍦ㄦ墽琛岃繃紼嬩腑鍙鏍規嵁瀹為檯闇瑕侀殢鏃跺姞杞絊O搴撴枃浠訛紝涔熷彲浠ラ殢鏃跺嵏杞絊O搴撴枃浠訛紝榪樺彲鍦ㄨ繍琛屾椂榪涜孲O搴撶殑鍒囨崲錛岃岃繖浜涙槸闅愬紡閾炬帴鏃犳硶鍋氬埌鐨勩備笌闅愬紡閾炬帴鐩告瘮錛屾樉寮忛摼鎺ュ叿鏈夋洿澶х殑鐏墊椿鎬с
12. 鍦↘ylix涓錛岃佸姩鎬佽呭叆搴撳拰璋冪敤瀵煎嚭鍑芥暟鍙浠ョ敤Delphi浠跨湡浠g爜鎴栬嚜鐒禠inux鏂規硶錛屼笅闈㈠垎鍒浠嬬粛榪欎袱縐嶆柟娉曘
13. SO搴撲腑紿椾綋瀵硅薄鐨勪嬌鐢錛岄櫎浜嗗寘鍚鍑芥暟鍜岃繃紼嬬殑搴撲箣澶栵紝榪樺彲浠ュ皢Kylix寤虹珛鐨勭獥浣撴斁鍦ㄥ叡浜瀵硅薄涓錛岃繖鍙浠ユ槸瀵硅瘽妗嗘垨鍏朵粬紿椾綋銆
⑶ GCC濡備綍鍙瀵煎嚭鎸囧畾鐨勭殑鍑芥暟
涓嶇敤鐗瑰畾鐨勬墿灞曞悕錛屼笖涓嶆槸鍦 gcc 涓鎸囧畾鍙傛暟錛岃屾槸鍦 ld 涓銆傚啓涓涓瀵煎嚭絎﹀彿鏂囦歡錛屽 symbol 鎸囧畾浣犲彧瀵煎嚭鐨勫嚱鏁幫紝濡 func1銆備嬌鐢 ld 鐨--retain-symbols-file 鍙傛暟鍙浠ュ湪 static section 閲屽彇娑 func1 浠ュ栫殑鎵鏈夊嚱鏁般傝繖鏃朵綘鐢 readelf 鐪嬬紪璇戝ソ鍚庣殑 銆俿o 鏂囦歡 static section 閲屾病鏈変簡錛屼嬌鐢 nm 鐪嬨俿o鏂囦歡瀹冩棤娉曟煡鍑哄煎嚭鍑芥暟銆備絾榪欏苟涓嶅畬鍏ㄣ傚洜涓哄湪 dynamic section 閲岃繕鏄浼氱湅鍒版墍鏈夌﹀彿琚瀵煎嚭銆傚傛灉鎯沖湪 銆俤ynsym 榪欎釜 section 閲屼篃涓嶈╀粬瀵煎嚭鐨勮瘽錛岄渶瑕佸啀緙栧啓涓涓 script 鏂囦歡銆 鎸囧畾 global 涓 local 鍦 global 涓鎸囧畾浣犺佸煎嚭鐨勫嚱鏁幫紝綆鍗曠殑鏍煎紡濡備笅錛歿global: 瀵煎嚭鍑芥暟鍚;local: *;};鍐嶅湪ld 鏃剁敤 --version-script 閫夐」鏉 load 浣 鏂囦歡銆傞兘瀹屼簨鍚庡啀浣跨敤 readelf 瑙傚療static 涓 dynamic section 鍙戠幇鍙瀵煎嚭浜嗕綘鎸囧畾鐨勫嚱鏁板悕鍗崇﹀彿銆 渚嬶細ld -shared --retain-symbols-file 絎﹀彿鏂囦歡 --version-script 鑴氭湰鏂囦歡 -o 鍔ㄦ佸簱鏂囦歡銆俿o filename銆俹
⑷ linux 怎麼調用內核導出的函數
Linux內核沒有導出的函數不能調用,即使包含了頭文件,也會出現符號未定義的警告,並在載入模塊時失敗。
以下是我的測試例子:
#include <linux/mole.h>
#include <linux/syscalls.h>
MODULE_LICENSE("GPL");
MODULE_AUTHOR("Linmiaohe");
MODULE_DESCRIPTION("try to evole sys_umount");
extern asmlinkage long sys_umount(char __user *name, int flags);
static int __init sys_umount_init(void)
{
sys_umount("./proc",0);
return 0;
}
static void __exit sys_umount_exit(void)
{
printk(KERN_INFO "***********sys_umount mole has been unregistered*************\n");
}
mole_init(sys_umount_init);
mole_exit(sys_umount_exit);