Skip to content

Instantly share code, notes, and snippets.

@Noitidart
Forked from yajd/ctypes notes.md
Last active August 29, 2015 14:06
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Noitidart/cb48dca021a4402ec1fc to your computer and use it in GitHub Desktop.
Save Noitidart/cb48dca021a4402ec1fc to your computer and use it in GitHub Desktop.

var runtime = Components.classes["@mozilla.org/xre/app-info;1"] .getService(Components.interfaces.nsIXULRuntime); var abi = runtime.OS + "_" + runtime.XPCOMABI; var lib_name; this.data_loc = ""; //================================================================== // Detect shared library name to load //================================================================== if (abi == "Linux_x86-gcc3" || abi == "Linux_x86_64-gcc3") { lib_name = "libvoikko.so.1"; } else if (abi == "WINNT_x86-msvc" || abi == "WINNT_x86_64-msvc") { lib_name = "libvoikko-1.dll"; this.call_abi = ctypes.winapi_abi; } else if (abi == "Darwin_x86_64-gcc3" || abi == "Darwin_x86-gcc3" || abi == "Darwin_ppc-gcc3") { lib_name = "libvoikko.1.dylib"; } else { throw "Unsupported ABI " + abi; }


* https://github.com/stephenfox/iceweasel-dev/blob/c1ebf8be93add288837377e4fdd87f9c9f1082cc/l10n-gu-IN/services/crypto/modules/WeaveCrypto.js#L112

let os = Services.appinfo.OS; switch (os) { case "WINNT": case "WINMO": case "WINCE": nssfile.append("nss3.dll"); break; case "Darwin": nssfile.append("libnss3.dylib"); break; case "Linux": case "SunOS": case "WebOS": // Palm Pre nssfile.append("libnss3.so"); break; case "Android": // Android uses a $GREDIR/lib/ subdir. nssfile.append("lib"); nssfile.append("libnss3.so"); break; default: throw this.makeException("unsupported platform: " + os, Cr.NS_ERROR_UNEXPECTED); }


* https://github.com/mozilla/deuxdrop/blob/2404f3fccaf762dfb935ee1563f68ca2c61d32b4/clients/addon/lib/nacl.js#L68

let runtime = Cc["@mozilla.org/xre/app-info;1"] .getService(Ci.nsIXULRuntime); let platLibName; switch (runtime.OS) { case 'WINNT': if (numbits !== 32) throw new Error('64-bit windows not supported right now.'); platLibName = 'nacl-i686.dll'; break; case 'Linux': platLibName = 'libnacl-' + platCode + '.so'; break; case 'Darwin': if (numbits !== 64) throw new Error('32-bit OS X not supported right now.'); platLibName = 'libnacl-x86_64.dylib'; break; case 'Android': platLibName = 'libnacl-arm.so'; break; default: throw new Error('No native library for platform: ' + runtime.OS); }



* https://github.com/ochameau/adbhelper/blob/fd3073a0f5f51e1707a5b4cbace82b13fb5a1fe5/subprocess.js#L311

function getPlatformValue(valueType) { if (! gXulRuntime) gXulRuntime = Cc["@mozilla.org/xre/app-info;1"].getService(Ci.nsIXULRuntime); const platformDefaults = { // Windows API: 'winnt': [ 'kernel32.dll' ], // Unix API: // library name O_NONBLOCK RLIM_T RLIMIT_NOFILE 'darwin': [ 'libc.dylib', 0x04 , ctypes.uint64_t , 8 ], 'linux': [ 'libc.so.6', 2024 , ctypes.unsigned_long, 7 ], 'freebsd': [ 'libc.so.7', 0x04 , ctypes.int64_t , 8 ], 'openbsd': [ 'libc.so.61.0', 0x04 , ctypes.int64_t , 8 ], 'sunos': [ 'libc.so', 0x80 , ctypes.unsigned_long, 5 ] } return platformDefaults[gXulRuntime.OS.toLowerCase()][valueType]; }


* a method to get platform name:

var hh = Cc["@mozilla.org/network/protocol;1?name=http"].getService(Ci.nsIHttpProtocolHandler); var plat = hh["platform"];

on win8.1 this returns "Windows"

* interesting way to defined NULL https://github.com/mozilla/libadb.js/blob/d90624bef3830b357ab907b7b26f1f5f954efbcd/addon/adb-types.js#L17

* more lib names from irc

let libc = new SharedAll.Library("libc", "libc.so", "libSystem.B.dylib", "a.out");


* null on windows?

const NULL = ctypes.cast(ctypes.uint64_t(0x0), ctypes.void_t.ptr);

@Noitidart
Copy link
Author

in winapi only ANSI things are limited to MAX_PATH: https://msdn.microsoft.com/en-us/library/windows/desktop/aa363858%28v=vs.85%29.aspx see description under first arg

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment