| 1 |
# -*- coding: utf-8 -*- |
| 2 |
# |
| 3 |
# yaya.rb - a (Real) YAYA loader for ninix |
| 4 |
# Copyright (C) 2004 by linjian |
| 5 |
# Copyright (C) 2004-2019 by Shyouzou Sugitani <[email protected]> |
| 6 |
# Copyright (C) 2011 by henryhu |
| 7 |
# Copyright (C) 2024 by Tatakinov |
| 8 |
# |
| 9 |
# This program is free software; you can redistribute it and/or modify it |
| 10 |
# under the terms of the GNU General Public License (version 2) as |
| 11 |
# published by the Free Software Foundation. It is distributed in the |
| 12 |
# hope that it will be useful, but WITHOUT ANY WARRANTY; without even the |
| 13 |
# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
| 14 |
# PURPOSE. See the GNU General Public License for more details. |
| 15 |
# |
| 16 |
|
| 17 |
require "fiddle/import" |
| 18 |
|
| 19 |
require_relative "../logging" |
| 20 |
|
| 21 |
$_yaya = nil |
| 22 |
|
| 23 |
module Yaya |
| 24 |
extend Fiddle::Importer |
| 25 |
begin |
| 26 |
dlload "libaya5.#{RbConfig::CONFIG['SOEXT']}" |
| 27 |
extern "long multi_load(char *, long)" |
| 28 |
extern "int multi_unload(long)" |
| 29 |
extern "char *multi_request(long, char *, long *)" |
| 30 |
|
| 31 |
$_yaya = self |
| 32 |
rescue |
| 33 |
$_yaya = nil |
| 34 |
end |
| 35 |
|
| 36 |
class Shiori |
| 37 |
|
| 38 |
def initialize(dll_name) |
| 39 |
@dll_name = dll_name |
| 40 |
@pathdic = [] |
| 41 |
@reqdic = [] |
| 42 |
@id = nil |
| 43 |
end |
| 44 |
|
| 45 |
def find(topdir, dll_name) |
| 46 |
result = 0 |
| 47 |
unless $_yaya.nil? |
| 48 |
if File.file?(File.join(topdir, 'yaya.txt')) |
| 49 |
result = 205 |
| 50 |
elsif not dll_name.nil? and \ |
| 51 |
File.file?(File.join(topdir, [dll_name[0..-3], 'txt'].join(''))) |
| 52 |
result = 105 |
| 53 |
end |
| 54 |
end |
| 55 |
result |
| 56 |
end |
| 57 |
|
| 58 |
def show_description |
| 59 |
Logging::Logging.info( |
| 60 |
"Shiori: a (Real) YAYA loader for ninix\n" \ |
| 61 |
" Copyright (C) 2004 by linjian\n" \ |
| 62 |
" Copyright (C) 2004-2019 by Shyouzou Sugitani\n" \ |
| 63 |
" Copyright (C) 2011 by henryhu") |
| 64 |
end |
| 65 |
|
| 66 |
def load(dir: nil) |
| 67 |
@dir = dir |
| 68 |
return 0 if $_yaya.nil? |
| 69 |
if @dir.end_with?(File::SEPARATOR) |
| 70 |
#topdir = @dir |
| 71 |
else |
| 72 |
#topdir = [@dir, File::SEPARATOR].join() |
| 73 |
@dir = [@dir, File::SEPARATOR].join() |
| 74 |
end |
| 75 |
path = Fiddle::Pointer.malloc( |
| 76 |
@dir.bytesize + 1, |
| 77 |
freefunc=nil # Yaya will free this pointer |
| 78 |
) |
| 79 |
path[0, @dir.bytesize] = @dir |
| 80 |
@id = $_yaya.multi_load(path, @dir.bytesize) |
| 81 |
1 |
| 82 |
end |
| 83 |
|
| 84 |
def unload |
| 85 |
$_yaya.multi_unload(@id) unless $_yaya.nil? |
| 86 |
@id = nil |
| 87 |
end |
| 88 |
|
| 89 |
def request(req_string) |
| 90 |
return '' if $_yaya.nil? # FIXME |
| 91 |
request = Fiddle::Pointer.malloc( |
| 92 |
req_string.bytesize + 1, |
| 93 |
freefunc=nil # Yaya will free this pointer |
| 94 |
) |
| 95 |
request[0, req_string.bytesize] = req_string |
| 96 |
rlen =[req_string.bytesize].pack("l!") |
| 97 |
result = $_yaya.multi_request(@id, request, rlen) |
| 98 |
rlen, = rlen.unpack("l!") |
| 99 |
unless result.null? |
| 100 |
ret = result[0, rlen].to_s |
| 101 |
Fiddle.free(result) |
| 102 |
ret |
| 103 |
else |
| 104 |
'' |
| 105 |
end |
| 106 |
end |
| 107 |
end |
| 108 |
end |