Fix the windows build by avoiding posix-only apis and translating the r2 flags for msvc

This commit is contained in:
pancake authored and pancake committed 2026-09-08 09:52:56 +02:00
1 parent edd43d6042
commit b2d8a4917a
3 files changed
+40 -6

No files matched your search

+26 -3
View File
@@ -2,17 +2,40 @@ project(
'r2flutter',
'c',
version : '0.3.2',
meson_version : '>=0.55.0',
meson_version : '>=0.56.0',
default_options : ['warning_level=2', 'werror=false']
)
cc = meson.get_compiler('c')
r2 = find_program('r2', required: true)
r2_cflags_res = run_command(r2, '-H', 'R2_CFLAGS', check: true)
r2_ldflags_res = run_command(r2, '-H', 'R2_LDFLAGS', check: true)
r2_libs_res = run_command(r2, '-H', 'R2_LIBS', check: true)
r2_compile_args = r2_cflags_res.stdout().strip().split()
r2_link_args = r2_ldflags_res.stdout().strip().split() + r2_libs_res.stdout().strip().split()
# r2 -H always reports gcc style flags, msvc needs its own spelling for them
if cc.get_argument_syntax() == 'msvc'
msvc_link_args = []
foreach flag : r2_link_args
if flag.startswith('-L')
msvc_link_args += '/LIBPATH:' + flag.substring(2)
elif flag.startswith('-l')
msvc_link_args += flag.substring(2) + '.lib'
else
msvc_link_args += flag
endif
endforeach
r2_link_args = msvc_link_args
# posix names like strdup are available, just noisy without this
r2_compile_args += ['-D_CRT_SECURE_NO_WARNINGS', '-D_CRT_NONSTDC_NO_DEPRECATE']
endif
r_core_dep = declare_dependency(
compile_args: r2_cflags_res.stdout().strip().split(),
link_args: r2_ldflags_res.stdout().strip().split() + r2_libs_res.stdout().strip().split(),
compile_args: r2_compile_args,
link_args: r2_link_args,
)
r2flutter_inc = include_directories('include')
+13 -2
View File
@@ -179,13 +179,24 @@ static FILE *open_payload_temp(char **out_path) {
FILE *out = try_open_temp_path (r_file_temp ("r2flutter-dart-app-snap"), out_path);
if (!out) {
char *name = r_str_newf ("r2flutter-dart-app-snap.%" PFMT64x, (ut64)r_time_now ());
char *path = name? r_file_new (P_tmpdir, name, NULL): NULL;
char *tmpdir = r_file_tmpdir ();
char *path = (name && tmpdir)? r_file_new (tmpdir, name, NULL): NULL;
free (tmpdir);
free (name);
out = try_open_temp_path (path, out_path);
}
return out;
}
// msvc has no fseeko, but it ships an equivalent 64bit seek
static bool payload_seek(FILE *f, ut64 off) {
#if defined(_MSC_VER)
return _fseeki64 (f, (__int64)off, SEEK_SET) == 0;
#else
return fseeko (f, (off_t)off, SEEK_SET) == 0;
#endif
}
char *dart_app_extract_payload(const char *path, const DartAppEmbeddedPayload *payload) {
if (R_STR_ISEMPTY (path) || !payload || !payload->payload_size) {
return NULL;
@@ -202,7 +213,7 @@ char *dart_app_extract_payload(const char *path, const DartAppEmbeddedPayload *p
fclose (in);
return NULL;
}
bool ok = fseeko (in, (off_t)payload->payload_offset, SEEK_SET) == 0;
bool ok = payload_seek (in, payload->payload_offset);
ut64 remaining = payload->payload_size;
ut8 buf[65536];
while (ok && remaining > 0) {
+1 -1
View File
@@ -377,7 +377,7 @@ void collect_data_names_with_r2(DartCtx *ctx, ut64 data_image_base, ut64 data_im
continue;
}
char *line, *saveptr = NULL;
for (line = strtok_r (out, "\n", &saveptr); line; line = strtok_r (NULL, "\n", &saveptr)) {
for (line = r_str_tok_r (out, "\n", &saveptr); line; line = r_str_tok_r (NULL, "\n", &saveptr)) {
if (!r_str_startswith (line, "0x")) {
continue;
}