Created
February 26, 2014 23:42
-
-
Save yajd/9241197 to your computer and use it in GitHub Desktop.
fgets alicjab version - ctypes works but its weird. copy paste this to scratchpad with environment set to browser
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Cu.import("resource://gre/modules/ctypes.jsm"); | |
var libc = ctypes.open("msvcrt.dll"); | |
var FILE = new ctypes.StructType("FILE").ptr; //made var otherwise in scratchpad cant run multiple times, this can be CONST its no issue | |
var fopen = libc.declare("fopen", // symbol name | |
ctypes.default_abi, // cdecl calling convention | |
FILE, // return type (FILE*) | |
ctypes.char.ptr, // first arg (const char*) | |
ctypes.char.ptr); // second arg (const char*) | |
var fgets = libc.declare("fgets", | |
ctypes.default_abi, | |
ctypes.char.ptr, | |
ctypes.char.ptr, | |
ctypes.int32_t, | |
FILE); | |
var myfile = fopen("C:\\Users\\3K2KYC1\\Desktop\\FirefoxPortable\\newfile.in", "r"); | |
var SIZE = 100; | |
var line = new ctypes.char(SIZE); | |
var ret = fgets(line.address(), SIZE, myfile); | |
//newfile.in already exists and its contents is "ABC" no quotes | |
//line - after running code line is set to "ctypes.char(65)" and 65 is character code of A but how do you read line? | |
//ret - after running code ret is set to "ctypes.char.ptr(ctypes.UInt64("0x1e70e808"))" this also makes no sense to me how do you get a string out of this? | |
Services.wm.getMostRecentWindow(null).alert(line); | |
Services.wm.getMostRecentWindow(null).alert(ret); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment