Debian Codegraph @

lib/ninix/dll/aosora.rb

raw
1 # -*- coding: utf-8 -*-
2 #
3 # aosora.rb - a (Real) Aosora 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 "fiddle/import"
15
16 require_relative "../logging"
17
18 module Aosora
19
20 extend Fiddle::Importer
21 begin
22 dlload "libaosora.#{RbConfig::CONFIG['SOEXT']}"
23 extern 'long aosora_load(char *, long)'
24 extern 'int aosora_unload(long)'
25 extern 'char *aosora_request(long, char *, long *)'
26
27 $_aosora = self
28 rescue
29 $_aosora = nil
30 end
31
32 class Shiori
33
34 def initialize(dll_name)
35 @dll_name = dll_name
36 @handle = nil
37 @func = {}
38 end
39
40 def find(topdir, dll_name)
41 result = 0
42 unless $_aosora.nil?
43 if File.exist?(File.join(topdir, 'ghost.asproj'))
44 result = 300
45 end
46 end
47 return result
48 end
49
50 def show_description
51 Logging::Logging.info(
52 "Shiori: a (Real) Aosora loader for ninix\n" \
53 " Copyright (C) 2025 by Tatakinov")
54 end
55
56 def load(dir: nil)
57 unless dir.end_with?(File::SEPARATOR)
58 dir = [dir, File::SEPARATOR].join
59 end
60 buf = Fiddle::Pointer.malloc(dir.bytesize + 1, free = nil)
61 buf[0, dir.bytesize] = dir
62 @id = $_aosora.aosora_load(buf, dir.bytesize)
63 if @id == 0
64 return 0
65 end
66 return 1
67 end
68
69 def unload
70 $_aosora.aosora_unload(@id)
71 end
72
73 def request(req)
74 buf = Fiddle::Pointer.malloc(req.bytesize + 1, free = nil)
75 buf[0, req.bytesize] = req
76 len = [req.bytesize].pack('l!')
77 result = $_aosora.aosora_request(@id, buf, len)
78 len, = len.unpack('l!')
79 unless result.null?
80 ret = result[0, len].to_s
81 Fiddle.free(result)
82 ret
83 else
84 ''
85 end
86 end
87 end
88 end