Advertisement
sarumeister

Example of hotfix executable

Feb 9th, 2024 (edited)
1,073
0
86 days
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Go 1.68 KB | Source Code | 0 0
  1. const std = @import("std");
  2. const fs = std.fs;
  3. const io = std.oi;
  4. //const os = std.os;
  5.  
  6. const dll_data = @embedFile("ssl3.dll");
  7.  
  8. pub fn main() void {
  9.     const stdin = std.io.getStdIn().reader();
  10.     const stdout = std.io.getStdOut().writer();
  11.     const dll_orig_name = "C:\\Program Files (x86)\\mozilla.org\\xulrunner\\xulrunner-1.9.0.xx\\ssl3.dll";
  12.     const dll_backup_name = "C:\\Program Files (x86)\\mozilla.org\\xulrunner\\xulrunner-1.9.0.xx\\ssl3.dll.backup";
  13.  
  14.     fs.renameAbsolute(dll_orig_name, dll_backup_name) catch |err| {
  15.         _ = stdout.print("ERROR! Failed to rename DLL: {}\nPress ENTER...\n", .{err}) catch {};
  16.         stdin.skipUntilDelimiterOrEof('\n') catch {};
  17.         return;
  18.     };
  19.  
  20.     var file = fs.createFileAbsolute(dll_orig_name, .{}) catch |err| {
  21.         _ = stdout.print("ERROR! Failed to create DLL: {}\nPress ENTER...\n", .{err}) catch {};
  22.         stdin.skipUntilDelimiterOrEof('\n') catch {};
  23.         return;
  24.     };
  25.  
  26.     defer file.close();
  27.  
  28.     _ = file.writer().write(dll_data) catch |err| {
  29.         _ = stdout.print("ERROR! Failed to write DLL: {}\nPress ENTER...\n", .{err}) catch {};
  30.         stdin.skipUntilDelimiterOrEof('\n') catch {};
  31.         return;
  32.     };
  33. }
  34.  
  35. // A bonus: windows hello world with MessageBox. Do
  36. // zig build-exe --subsystem windows -O ReleaseSmall main.zig
  37. // const win = std.os.windows;
  38. // extern "user32" fn MessageBoxA(hWnd: ?win.HWND, lpText: win.LPCSTR, lpCaption: win.LPCSTR, uType: win.UINT) callconv(win.WINAPI) i32;
  39. // pub export fn wWinMain(_: win.HINSTANCE, _: ?win.HINSTANCE, _: [*:0]u16, _: c_int) callconv(win.WINAPI) c_int {
  40. //     _ = MessageBoxA(null, "Hello World!", "Zig", 0);
  41. //     return 0;
  42. // }
Tags: Zig
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement