| 1 |
# -*- coding: utf-8 -*- |
| 2 |
# |
| 3 |
# x86.rb - a Real x86 SHIORI loader for ninix |
| 4 |
# Copyright (C) 2025 by Tatakinov |
| 5 |
# |
| 6 |
# This program is free software; you can redistribute it and/or modify it |
| 7 |
# under the terms of the GNU General Public License (version 2) as |
| 8 |
# published by the Free Software Foundation. It is distributed in the |
| 9 |
# hope that it will be useful, but WITHOUT ANY WARRANTY; without even the |
| 10 |
# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
| 11 |
# PURPOSE. See the GNU General Public License for more details. |
| 12 |
# |
| 13 |
|
| 14 |
require 'open3' |
| 15 |
|
| 16 |
require_relative '../logging' |
| 17 |
|
| 18 |
module X86 |
| 19 |
|
| 20 |
PROGRAM = (ENV.include?('X86_PROXY') and File.join(ENV['X86_PROXY'], 'ninix-proxy.exe') or 'ninix-proxy.exe') |
| 21 |
|
| 22 |
class Shiori |
| 23 |
|
| 24 |
def initialize(dll_name) |
| 25 |
@dll_name = dll_name |
| 26 |
end |
| 27 |
|
| 28 |
def find(topdir, dll_name) |
| 29 |
result = 0 |
| 30 |
begin |
| 31 |
dll_path = File.join(topdir, dll_name) |
| 32 |
Open3.popen3(PROGRAM, dll_path) do |_write, read, _err, _th| |
| 33 |
result = 800 if read.read == 'true' |
| 34 |
end |
| 35 |
rescue |
| 36 |
# nop |
| 37 |
end |
| 38 |
return result |
| 39 |
end |
| 40 |
|
| 41 |
def show_description |
| 42 |
Logging::Logging.info( |
| 43 |
"Shiori: a Real SHIORI loader for ninix\n" \ |
| 44 |
" Copyright (C) 2025 by Tatakinov") |
| 45 |
end |
| 46 |
|
| 47 |
def load(dir: nil) |
| 48 |
unless dir.end_with?(File::SEPARATOR) |
| 49 |
dir = [dir, File::SEPARATOR].join |
| 50 |
end |
| 51 |
dll_path = File.join(dir, @dll_name) |
| 52 |
dll_dir = File.dirname(dll_path) |
| 53 |
@write, @read, @err, @thread = Open3.popen3(PROGRAM, dll_path, dll_dir) |
| 54 |
return 1 |
| 55 |
end |
| 56 |
|
| 57 |
def unload |
| 58 |
begin |
| 59 |
@write.write([0].pack('L')) |
| 60 |
@write.close |
| 61 |
@thread.join |
| 62 |
rescue |
| 63 |
# TODO error |
| 64 |
end |
| 65 |
end |
| 66 |
|
| 67 |
def request(req) |
| 68 |
req = [[req.bytesize].pack('L'), req.force_encoding(Encoding::BINARY)].join |
| 69 |
begin |
| 70 |
@write.write(req) |
| 71 |
len = @read.read(4)&.unpack('L').first |
| 72 |
if len.nil? |
| 73 |
# TODO error |
| 74 |
return |
| 75 |
end |
| 76 |
if len.zero? |
| 77 |
return '' |
| 78 |
end |
| 79 |
res = @read.read(len) |
| 80 |
return res |
| 81 |
rescue => e |
| 82 |
# TODO error |
| 83 |
return '' |
| 84 |
end |
| 85 |
end |
| 86 |
end |
| 87 |
end |