Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F4502103
printf.js
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
770 B
Referenced Files
None
Subscribers
None
printf.js
View Options
import
{
dlopen
,
FFIType
}
from
'ant:ffi'
;
let
libcName
;
if
(
process
.
platform
===
'darwin'
)
{
libcName
=
'libSystem.dylib'
;
}
else
if
(
process
.
platform
===
'linux'
)
{
libcName
=
'libc.so.6'
;
}
else
if
(
process
.
platform
===
'win32'
)
{
libcName
=
'msvcrt.dll'
;
}
else
{
throw
new
Error
(
`Unsupported platform:
${
process
.
platform
}
`
);
}
const
libc
=
dlopen
(
libcName
);
libc
.
define
(
'putchar'
,
{
args
:
[
FFIType
.
int
],
returns
:
FFIType
.
int
});
libc
.
define
(
'printf'
,
{
args
:
[
FFIType
.
string
,
FFIType
.
spread
],
returns
:
FFIType
.
int
});
console
.
log
(
'calling putchar(65):'
);
libc
.
call
(
'putchar'
,
65
);
// 'A'
console
.
log
(
'\ncalling printf:'
);
libc
.
call
(
'printf'
,
'Hello FFI! I see %d\n'
,
42
);
console
.
log
(
'calling putchar(66):'
);
libc
.
call
(
'putchar'
,
66
);
// 'B'
File Metadata
Details
Attached
Mime Type
application/javascript
Expires
Sun, May 3, 8:58 AM (3 h, 53 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
543668
Default Alt Text
printf.js (770 B)
Attached To
Mode
rANT Ant
Attached
Detach File
Event Timeline
Log In to Comment