mirror of
https://github.com/osnr/TabFS.git
synced 2024-05-03 14:23:11 +02:00
base64 hack to handle binary files.
add memory fences because why not.
This commit is contained in:
parent
74c794d75c
commit
73f8bc754e
3
.gitmodules
vendored
3
.gitmodules
vendored
|
@ -4,3 +4,6 @@
|
|||
[submodule "fs/mmx"]
|
||||
path = fs/mmx
|
||||
url = https://github.com/vurtun/mmx.git
|
||||
[submodule "fs/base64"]
|
||||
path = fs/base64
|
||||
url = https://github.com/zhicheng/base64.git
|
||||
|
|
|
@ -126,13 +126,18 @@ const router = {
|
|||
for (let resource of frameTree.resources) {
|
||||
const resourceSuffix = sanitize(String(resource.url).slice(0, 200));
|
||||
if (resourceSuffix === suffix) {
|
||||
const {content} = await sendDebuggerCommand(tabId, "Page.getResourceContent", {
|
||||
let {base64Encoded, content} = await sendDebuggerCommand(tabId, "Page.getResourceContent", {
|
||||
frameId: frameTree.frame.id,
|
||||
url: resource.url
|
||||
});
|
||||
if (base64Encoded) {
|
||||
const buf = btoa(atob(content).substr(offset, size));
|
||||
return { buf, base64Encoded: true };
|
||||
}
|
||||
return content.substr(offset, size);
|
||||
}
|
||||
}
|
||||
throw new UnixError(unix.ENOENT);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -226,11 +231,13 @@ async function onmessage(event) {
|
|||
};
|
||||
|
||||
} else if (req.op === 'read') {
|
||||
const buf = await read(req.path, req.fh, req.size, req.offset)
|
||||
const ret = await read(req.path, req.fh, req.size, req.offset)
|
||||
const buf = typeof ret === 'string' ? ret : ret.buf;
|
||||
response = {
|
||||
op: 'read',
|
||||
buf
|
||||
};
|
||||
if (ret.base64Encoded) response.base64Encoded = ret.base64Encoded;
|
||||
|
||||
} else if (req.op === 'release') {
|
||||
await release(req.path, req.fh);
|
||||
|
@ -263,7 +270,6 @@ async function onmessage(event) {
|
|||
}
|
||||
/* console.timeEnd(req.op + ':' + req.path);*/
|
||||
|
||||
response.id = req.id;
|
||||
console.log('resp', response);
|
||||
ws.send(JSON.stringify(response));
|
||||
};
|
||||
|
|
|
@ -14,7 +14,7 @@ CFLAGS_OSXFUSE += -DFUSE_USE_VERSION=26
|
|||
CFLAGS_OSXFUSE += -D_FILE_OFFSET_BITS=64
|
||||
CFLAGS_OSXFUSE += -D_DARWIN_USE_64_BIT_INODE
|
||||
|
||||
CFLAGS_EXTRA = -Wall -g $(CFLAGS)
|
||||
CFLAGS_EXTRA = -Wall -Wno-unused-function -g $(CFLAGS)
|
||||
|
||||
LIBS = -losxfuse
|
||||
|
||||
|
|
1
fs/base64
Submodule
1
fs/base64
Submodule
|
@ -0,0 +1 @@
|
|||
Subproject commit 6148c6944469d629a94a1695eb91989030762ffc
|
16
fs/common.c
16
fs/common.c
|
@ -1,10 +1,7 @@
|
|||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <sys/time.h>
|
||||
#include <stdio.h>
|
||||
#include <signal.h>
|
||||
#include <stdatomic.h>
|
||||
|
||||
#include "common.h"
|
||||
|
||||
|
@ -16,11 +13,13 @@ void common_init() {
|
|||
if (pipe(ws_to_tabfs)) exit(1);
|
||||
}
|
||||
|
||||
// FIXME: we probably need memory fences here?? especially on
|
||||
// non-x86?? idk
|
||||
// see https://stackoverflow.com/questions/35837539/does-the-use-of-an-anonymous-pipe-introduce-a-memory-barrier-for-interthread-com
|
||||
// We probably technically need memory fences here? especially on
|
||||
// non-x86?? Are these right? idk. See
|
||||
// https://stackoverflow.com/questions/35837539/does-the-use-of-an-anonymous-pipe-introduce-a-memory-barrier-for-interthread-com
|
||||
// https://preshing.com/20120913/acquire-and-release-semantics/
|
||||
|
||||
void common_send_tabfs_to_ws(char *request_data) {
|
||||
atomic_thread_fence(memory_order_release);
|
||||
write(tabfs_to_ws[1], &request_data, sizeof(request_data));
|
||||
}
|
||||
|
||||
|
@ -51,16 +50,19 @@ char *common_receive_tabfs_to_ws(fd_set_filler_fn_t filler) {
|
|||
|
||||
char *request_data;
|
||||
read(tabfs_to_ws[0], &request_data, sizeof(request_data));
|
||||
atomic_thread_fence(memory_order_acquire);
|
||||
|
||||
return request_data;
|
||||
}
|
||||
|
||||
void common_send_ws_to_tabfs(char *response_data) {
|
||||
atomic_thread_fence(memory_order_release);
|
||||
write(ws_to_tabfs[1], &response_data, sizeof(response_data));
|
||||
}
|
||||
char *common_receive_ws_to_tabfs() {
|
||||
char *response_data;
|
||||
read(ws_to_tabfs[0], &response_data, sizeof(response_data));
|
||||
atomic_thread_fence(memory_order_acquire);
|
||||
|
||||
return response_data;
|
||||
}
|
||||
|
|
14
fs/tabfs.c
14
fs/tabfs.c
|
@ -8,6 +8,9 @@
|
|||
#include "cJSON/cJSON.h"
|
||||
#include "cJSON/cJSON.c"
|
||||
|
||||
#include "base64/base64.h"
|
||||
#include "base64/base64.c"
|
||||
|
||||
#include "common.h"
|
||||
#include "ws.h"
|
||||
|
||||
|
@ -119,12 +122,15 @@ tabfs_read(const char *path, char *buf, size_t size, off_t offset,
|
|||
|
||||
char *resp_buf = cJSON_GetStringValue(resp_buf_item);
|
||||
if (!resp_buf) return -EIO;
|
||||
|
||||
size_t resp_buf_len = strlen(resp_buf);
|
||||
size = resp_buf_len < size ? resp_buf_len : size;
|
||||
|
||||
memcpy(buf, resp_buf, size);
|
||||
|
||||
cJSON *base64_encoded_item = cJSON_GetObjectItemCaseSensitive(resp, "base64Encoded");
|
||||
if (base64_encoded_item && cJSON_IsTrue(base64_encoded_item)) {
|
||||
size = base64_decode(resp_buf, resp_buf_len, (unsigned char *) buf);
|
||||
} else {
|
||||
size = resp_buf_len < size ? resp_buf_len : size;
|
||||
memcpy(buf, resp_buf, size);
|
||||
}
|
||||
ret = size;
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue