@@ -38,12 +38,11 @@ fn mono_doorstop_bootstrap(mono_domain: *mono.Domain) void {
3838 }, 0 ) catch @panic ("Out of memory" );
3939 defer alloc .free (config_path );
4040
41- const config_path_n = util .narrow (config_path );
41+ const config_path_n = util .narrow (true , true , config_path );
4242 defer config_path_n .deinit ();
4343
4444 const folder_path = root .util .paths .getFolderName (os_char , app_path );
45- defer alloc .free (folder_path );
46- const folder_path_n = util .narrow (folder_path );
45+ const folder_path_n = util .narrow (false , true , folder_path );
4746 defer folder_path_n .deinit ();
4847
4948 logger .debug ("Setting config paths: base dir: {s}; config path: {s}" , .{ folder_path_n .str , config_path_n .str });
@@ -52,17 +51,19 @@ fn mono_doorstop_bootstrap(mono_domain: *mono.Domain) void {
5251 }
5352
5453 const assembly_dir = std .mem .span (mono .addrs .assembly_getrootdir .? ());
55- const norm_assembly_dir = util .widen (assembly_dir );
56- defer norm_assembly_dir .deinit ();
5754
5855 mono .addrs .config_parse .? (null );
5956
6057 logger .debug ("Assembly dir: {s}" , .{assembly_dir });
61- util .setEnv ("DOORSTOP_MANAGED_FOLDER_DIR" , norm_assembly_dir .str );
58+ {
59+ const norm_assembly_dir = util .widen (assembly_dir );
60+ defer norm_assembly_dir .deinit ();
61+ util .setEnv ("DOORSTOP_MANAGED_FOLDER_DIR" , norm_assembly_dir .str );
62+ }
6263
6364 logger .debug ("Opening assembly: {}" , .{util .fmtString (config .target_assembly .? )});
6465
65- const dll_path = util .narrow (config .target_assembly .? );
66+ const dll_path = util .narrow (true , true , config .target_assembly .? );
6667 defer dll_path .deinit ();
6768 logger .debug ("narrowed dll path" , .{});
6869 const image = blk : {
@@ -127,7 +128,7 @@ pub fn init_mono(root_domain_name: [*:0]const u8, runtime_version: [*:0]const u8
127128 logger .debug ("Overriding mono DLL search path" , .{});
128129
129130 const mono_search_path_alloc = if (config .mono_dll_search_path_override ) | paths | blk : {
130- const mono_dll_search_path_override_n = util .narrow (paths );
131+ const mono_dll_search_path_override_n = util .narrow (true , false , paths );
131132 defer mono_dll_search_path_override_n .deinit ();
132133 break :blk std .mem .concatWithSentinel (
133134 alloc ,
@@ -193,15 +194,9 @@ fn il2cpp_doorstop_bootstrap() void {
193194
194195 var program_path_buf = util.paths.ProgramPathBuf {};
195196 const app_path = program_path_buf .get ();
196- const app_path_n = util .narrow (app_path );
197- defer app_path_n .deinit ();
198197
199198 const target_dir = util .paths .getFolderName (os_char , config .target_assembly .? );
200- defer alloc .free (target_dir );
201199 const target_name = util .paths .getFileName (os_char , config .target_assembly .? , false );
202- defer alloc .free (target_name );
203- const target_name_n = util .narrow (target_name );
204- defer target_name_n .deinit ();
205200
206201 const app_paths_env = std .mem .concatWithSentinel (
207202 alloc ,
@@ -211,7 +206,7 @@ fn il2cpp_doorstop_bootstrap() void {
211206 ) catch @panic ("Out of memory" );
212207 defer alloc .free (app_paths_env );
213208
214- const app_paths_env_n = util .narrow (app_paths_env );
209+ const app_paths_env_n = util .narrow (true , true , app_paths_env );
215210 defer app_paths_env_n .deinit ();
216211
217212 logger .debug ("App path: {}" , .{util .fmtString (app_path )});
@@ -227,13 +222,18 @@ fn il2cpp_doorstop_bootstrap() void {
227222 util .setEnv ("DOORSTOP_PROCESS_PATH" , app_path );
228223 util .setEnv ("DOORSTOP_DLL_SEARCH_DIRS" , app_paths_env );
229224
225+ const app_path_n = util .narrow (true , true , app_path );
226+ defer app_path_n .deinit ();
227+
230228 var host : ? * anyopaque = null ;
231229 var domain_id : u32 = 0 ;
232230 var result = coreclr .addrs .initialize .? (app_path_n .str , "Doorstop Domain" , 1 , &.{props }, &.{app_paths_env_n .str }, & host , & domain_id );
233231 if (result != 0 ) {
234232 std .debug .panic ("Failed to initialize CoreCLR: 0x{x:0>8}" , .{result });
235233 }
236234
235+ const target_name_n = util .narrow (false , true , target_name );
236+ defer target_name_n .deinit ();
237237 var startup : ? * const fn () callconv (.c ) void = null ;
238238 result = coreclr .addrs .create_delegate .? (host .? , domain_id , target_name_n .str , "Doorstop.Entrypoint" , "Start" , @ptrCast (& startup ));
239239 if (result != 0 ) {
@@ -252,7 +252,7 @@ pub fn init_il2cpp(domain_name: [*:0]const u8) callconv(.c) i32 {
252252}
253253
254254pub fn hook_mono_jit_parse_options (argc : c_int , argv : [* ][* :0 ]u8 ) callconv (.c ) void {
255- const debug_options_buf = if (@import ("Config.zig" ).getEnvStrRef ("DNSPY_UNITY_DBG2" )) | s | util .narrow (s ) else null ;
255+ const debug_options_buf = if (@import ("Config.zig" ).getEnvStrRef ("DNSPY_UNITY_DBG2" )) | s | util .narrow (true , true , s ) else null ;
256256 defer if (debug_options_buf ) | buf | buf .deinit ();
257257 var debug_options = if (debug_options_buf ) | buf | buf .str else null ;
258258 defer if (debug_options ) | s | if (debug_options_buf == null ) alloc .free (s );
@@ -269,15 +269,23 @@ pub fn hook_mono_jit_parse_options(argc: c_int, argv: [*][*:0]u8) callconv(.c) v
269269 @memcpy (new_argv [0.. @intCast (argc )], argv );
270270
271271 if (debug_options == null ) {
272- const mono_debug_address_alloc = if (config .mono_debug_address ) | s | util .narrow (s ) else null ;
273- defer if (mono_debug_address_alloc ) | s | s .deinit ();
274- const mono_debug_address : []const u8 = if (mono_debug_address_alloc ) | s | s .str else "127.0.0.1:10000" ;
275-
276- const MONO_DEBUG_NO_SUSPEND = ",suspend=n" ;
277- const MONO_DEBUG_NO_SUSPEND_NET35 = ",suspend=n,defer=y" ;
278- debug_options = std .fmt .allocPrintZ (alloc , "--debugger-agent=transport=dt_socket,server=y,address={s}{s}" , .{
272+ const max_ipv6_addr_len = 5 * 8 - 1 ;
273+ const max_port_len = 5 ;
274+ var mono_debug_address_buf : if (builtin.os.tag == .windows ) [max_ipv6_addr_len + 1 + max_port_len ]u8 else void = undefined ;
275+ const mono_debug_address : []const u8 = if (config .mono_debug_address ) | s | switch (builtin .os .tag ) {
276+ .windows = > blk : {
277+ const n = std .unicode .utf16LeToUtf8 (& mono_debug_address_buf , s ) catch | e | {
278+ std .debug .panic ("Invalid Mono debugger agent address: {}" , .{e });
279+ };
280+ break :blk mono_debug_address_buf [0.. n ];
281+ },
282+ else = > s ,
283+ } else "127.0.0.1:10000" ;
284+
285+ debug_options = std .fmt .allocPrintZ (alloc , "--debugger-agent=transport=dt_socket,server=y,address={s}{s}{s}" , .{
279286 mono_debug_address ,
280- if (config .mono_debug_suspend ) "" else if (mono_is_net35 ) MONO_DEBUG_NO_SUSPEND_NET35 else MONO_DEBUG_NO_SUSPEND ,
287+ if (config .mono_debug_suspend ) "" else ",suspend=n" ,
288+ if (config .mono_debug_suspend or ! mono_is_net35 ) "" else ",defer=y" ,
281289 }) catch @panic ("Out of memory" );
282290 }
283291
@@ -299,7 +307,7 @@ pub fn hook_mono_image_open_from_data_with_name(
299307 name : [* :0 ]const u8 ,
300308) callconv (.c ) ? * mono.Image {
301309 if (config .mono_dll_search_path_override ) | mono_dll_search_path_override | {
302- const name_file = root .util .paths .getFileNameRef (u8 , std .mem .span (name ), true );
310+ const name_file = root .util .paths .getFileName (u8 , std .mem .span (name ), true );
303311
304312 const name_file_len = std .unicode .calcWtf16LeLen (name_file ) catch @panic ("Invalid WTF-8" );
305313 const new_full_path = alloc .allocSentinel (os_char , name_file_len + 1 + mono_dll_search_path_override .len , 0 ) catch @panic ("Out of memory" );
0 commit comments