var fopen
=
new NativeFunction(Module.findExportByName(
"libc.so"
,
"fopen"
),
"pointer"
,[
"pointer"
,
"pointer"
]);
var fread
=
new NativeFunction(Module.findExportByName(
"libc.so"
,
"fread"
),
"int"
,[
"pointer"
,
"int"
,
"int"
,
"pointer"
]);
var fgets
=
new NativeFunction(Module.findExportByName(
"libc.so"
,
"fgets"
),
"pointer"
,[
"pointer"
,
"int"
,
"pointer"
]);
var fclose
=
new NativeFunction(Module.findExportByName(
"libc.so"
,
"fclose"
),
"int"
,[
"pointer"
]);
var fseek
=
new NativeFunction(Module.findExportByName(
"libc.so"
,
"fseek"
),
"int"
,[
"pointer"
,
"int"
,
"int"
]);
var ftell
=
new NativeFunction(Module.findExportByName(
"libc.so"
,
"ftell"
),
"long"
,[
"pointer"
]);
function ReadFile(path){
var fp
=
fopen(Memory.allocUtf8String(path),Memory.allocUtf8String(
"rb"
));
if
(fp !
=
null){
fseek(fp,
0
,
2
);
/
/
SEEK_END
var size
=
ftell(fp);
console.log(
"load size -> "
+
size);
fseek(fp,
0
,
0
);
/
/
SEEK_SET
var
buffer
=
Memory.alloc(size);
fread(
buffer
, size,
1
, fp);
fclose(fp);
}
}