npgrt 0.0.1 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c1f8bbb219c98c3cba032b0b24c4b57925d8330c
4
- data.tar.gz: 51fa1b9e7e2255af6f93fa36ec254b2d6453502d
3
+ metadata.gz: 444d0978a8020feaefb2a5e0adcad3e4c161d8d3
4
+ data.tar.gz: c771aeaef308edf04c7005103865d61011fcae85
5
5
  SHA512:
6
- metadata.gz: 1b393f309a918dfa83bf68f8038cc710baf757fd03ac31dd54293c7d285a18e072436854592dc743ffe47c30c523b74528f264923d5770cb63b3e65459a6858d
7
- data.tar.gz: 12542c08f36342ca6bf2ee1ccaae53390badeaea20574846f6cc285a4fbc36d267b024bd61d67c3192ad9055e8642445456db98fbd80606a6453f58dbf1b6461
6
+ metadata.gz: 1145e1cfcfa9a752eab716013492a6df6a711de972f2dc61cecfb1e5eb62a5bc5d50082da70926bd98fa233c33fbd9e318d40f046cbb79e45e97957e96ecb118
7
+ data.tar.gz: 9a1303dd3ef1be63407acf1e16e2a9671eb237b025c739798fe8a3aa8533af764c4414e09840d6767b48094cf4ff78633416d2c521c524a38d4d17401b55e3f3
@@ -0,0 +1,8 @@
1
+ module NPGRT
2
+ module Message
3
+ def message(*a)
4
+ defined?(msgbox) ? msgbox(*a) : print(*a)
5
+ end
6
+ end
7
+ extend Message
8
+ end
@@ -0,0 +1,8 @@
1
+ module NPGRT
2
+ module Message
3
+ def message(*a)
4
+ defined?(:msgbox) ? msgbox(*a) : p(*a)
5
+ end
6
+ end
7
+ extend Message
8
+ end
@@ -0,0 +1,27 @@
1
+ module NPGRT
2
+ module Require
3
+ def require(a)
4
+ path = Gem.find_files(a)
5
+ path.each{|x| yield x}
6
+ super a
7
+ end
8
+
9
+ alias primitive_require require
10
+ private :primitive_require
11
+
12
+ def require(a)
13
+ primitive_require(a) do |x|
14
+ try_build x
15
+ end
16
+ end
17
+
18
+ private
19
+
20
+ def try_build(dir)
21
+ dir = File.dirname dir if FileTest.file?(dir)
22
+ system "cmd /c \"cd /d #{dir} & rake npgrt:build\""
23
+ end
24
+ end
25
+
26
+ extend Require
27
+ end
@@ -0,0 +1,26 @@
1
+ module NPGRT
2
+ module Require
3
+ def require(a)
4
+ path = Gem.find_files(a)
5
+ path.each{|x| yield x}
6
+ super a
7
+ end
8
+
9
+ alias primitive_require require
10
+
11
+ def require(a)
12
+ primitive_require(a) do |x|
13
+ try_build x
14
+ end
15
+ end
16
+
17
+ private
18
+
19
+ def try_build(dir)
20
+ dir = File.dirname dir if FileTest.file?(dir)
21
+ system "cmd /c \"cd /d #{dir} & rake npgrt:build\""
22
+ end
23
+ end
24
+
25
+ extend Require
26
+ end
data/lib/npgrt/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module NPGRT
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -0,0 +1,3 @@
1
+ module NPGRT
2
+ VERSION = "0.0.3"
3
+ end
@@ -0,0 +1,104 @@
1
+ module NPGRT
2
+ require 'Win32API' unless defined? ::Win32API
3
+ module Win32API
4
+ W = ::Win32API
5
+ class API
6
+ def initialize(dll, func, param = nil, ret = "L")
7
+ @dll, @func, @param, @ret = dll, func, param, ret
8
+
9
+ end
10
+
11
+ def call(*args)
12
+ param = @param || guess(args)
13
+ @api ||= W.new(@dll, @func, param, @ret)
14
+ @api.call(*args)
15
+ end
16
+
17
+ def inspect
18
+ "#<API #{@dll}!#{@func} takes #{@param || '<auto>'} returns #{@ret}>"
19
+ end
20
+
21
+ def guess(args)
22
+ args.map{|x| Integer === x ? "L" : "p"}
23
+ end
24
+ end
25
+
26
+ def api(dll, func, params = nil, ret = "L")
27
+ API.new dll, func, params, ret
28
+ end
29
+
30
+ def addressof(dll, func)
31
+ dl = api('kernel32', 'GetModuleHandle').call(dll)
32
+ dl = (dl == 0) ? dl : api('kernel32', 'LoadLibrary').call(dll)
33
+ api('kernel32', 'GetProcAddress').call dl, func
34
+ end
35
+
36
+ def memwrite(addr, buf, len = buf.size)
37
+ api('Kernel32', 'RtlMoveMemory').call addr, buf, len
38
+ end
39
+
40
+ def memread(addr, size)
41
+ buf = "\0"*size
42
+ api('Kernel32','RtlMoveMemory').call buf, addr, size
43
+ buf
44
+ end
45
+
46
+ def grant_all(addr, size)
47
+ api('Kernel32', 'VirtualProtect').call addr, size, 0x40, "RGBARGBARGBARGBA"
48
+ addr
49
+ end
50
+
51
+ def memread!(addr, size)
52
+ memread(grant_all(addr, size), size)
53
+ end
54
+
55
+ def memwrite!(addr, buf, len = buf.size)
56
+ memread(grant_all(addr, len), buf, len)
57
+ end
58
+
59
+ CP_UTF8 = {cp: 65001, suffix:"\0", encoding: "utf-8"}
60
+ CP_ANSI = {cp: 0, suffix:"\0", encoding: "ascii-8bit"}
61
+ CP_OEM = CP_ANSI
62
+ CP_GBK = {cp: 65001, suffix: "\0", encoding: "gbk"}
63
+
64
+ def to_unicode(string, codepage = CP_UTF8)
65
+ len = api('Kernel32', 'MultiByteToWideChar').call codepage[:cp], 0, string, -1, 0, 0
66
+ buf = "\0\0"*len
67
+ api('Kernel32', 'MultiByteToWideChar').call codepage[:cp], 0, string, -1, buf, len
68
+ buf[0..-3]
69
+ end
70
+
71
+ def to_codepage(string, codepage = CP_UTF8)
72
+ len = api('Kernel32', 'WideCharToMultiByte').call codepage[:cp], 0, string, -1, 0, 0, 0, 0
73
+ buf = "\0"*len
74
+ api('Kernel32', 'WideCharToMultiByte').call codepage[:cp], 0, string, -1, buf, len, 0, 0
75
+ b = buf[0..-1].sub(/\0+$/){}
76
+ if b.respond_to?(:force_encoding)
77
+ b.force_encoding(defined?($RGSS_SCRIPTS) ?
78
+ 'utf-8' :
79
+ codepage[:encoding])
80
+ else
81
+ b
82
+ end
83
+ end
84
+
85
+ def strread(addr)
86
+ len = api('Kernel32', 'lstrlenA').call(addr)
87
+ to_codepage(to_unicode(memread(addr, len+1), CP_ANSI), CP_UTF8)
88
+ end
89
+
90
+ def wstrread(addr)
91
+ len = api('Kernel32', 'lstrlenW').call(addr)
92
+ to_codepage(memread(addr, len*2+2))
93
+ end
94
+
95
+
96
+
97
+
98
+
99
+
100
+
101
+ end
102
+
103
+ extend Win32API
104
+ end
@@ -0,0 +1,104 @@
1
+ module NPGRT
2
+ require 'Win32API' unless defined? ::Win32API
3
+ module Win32API
4
+ W = ::Win32API
5
+ class API
6
+ def initialize(dll, func, param = nil, ret = "L")
7
+ @dll, @func, @param, @ret = dll, func, param, ret
8
+
9
+ end
10
+
11
+ def call(*args)
12
+ param = @param || guess(args)
13
+ @api ||= W.new(@dll, @func, param, @ret)
14
+ @api.call(*args)
15
+ end
16
+
17
+ def inspect
18
+ "#<API #{@dll}!#{@func} takes #{@param || '<auto>'} returns #{@ret}>"
19
+ end
20
+
21
+ def guess(args)
22
+ args.map{|x| Integer === x ? "L" : "p"}
23
+ end
24
+ end
25
+
26
+ def api(dll, func, params = nil, ret = "L")
27
+ API.new dll, func, params, ret
28
+ end
29
+
30
+ def addressof(dll, func)
31
+ dl = api('kernel32', 'GetModuleHandle').call(dll)
32
+ dl = (dl == 0) ? dl : api('kernel32', 'LoadLibrary').call(dll)
33
+ api('kernel32', 'GetProcAddress').call dl, func
34
+ end
35
+
36
+ def memwrite(addr, buf, len = buf.size)
37
+ api('Kernel32', 'RtlMoveMemory').call addr, buf, len
38
+ end
39
+
40
+ def memread(addr, size)
41
+ buf = "\0"*size
42
+ api('Kernel32','RtlMoveMemory').call buf, addr, size
43
+ buf
44
+ end
45
+
46
+ def grant_all(addr, size)
47
+ api('Kernel32', 'VirtualProtect').call addr, size, 0x40, "RGBARGBARGBARGBA"
48
+ addr
49
+ end
50
+
51
+ def memread!(addr, size)
52
+ memread(grant_all(addr, size), size)
53
+ end
54
+
55
+ def memwrite!(addr, buf, len = buf.size)
56
+ memread(grant_all(addr, len), buf, len)
57
+ end
58
+
59
+ CP_UTF8 = {cp: 65001, suffix:"\0", encoding: "utf-8"}
60
+ CP_ANSI = {cp: 0, suffix:"\0", encoding: "ascii-8bit"}
61
+ CP_OEM = CP_ANSI
62
+ CP_GBK = {cp: 65001, suffix: "\0", encoding: "gbk"}
63
+
64
+ def to_unicode(string, codepage = CP_UTF8)
65
+ len = api('Kernel32', 'MultiByteToWideChar').call codepage[:cp], 0, string, -1, 0, 0
66
+ buf = "\0\0"*len
67
+ api('Kernel32', 'MultiByteToWideChar').call codepage[:cp], 0, string, -1, buf, len
68
+ buf[0..-3]
69
+ end
70
+
71
+ def to_codepage(string, codepage = CP_UTF8)
72
+ len = api('Kernel32', 'WideCharToMultiByte').call codepage[:cp], 0, string, -1, 0, 0, 0, 0
73
+ buf = "\0"*len
74
+ api('Kernel32', 'WideCharToMultiByte').call codepage[:cp], 0, string, -1, buf, len, 0, 0
75
+ b = buf[0..-1].sub(/\0+$/){}
76
+ if b.respond_to?(:force_encoding)
77
+ b.force_encoding(defined?($RGSS_SCRIPTS) ?
78
+ 'utf-8' :
79
+ codepage[:encoding])
80
+ else
81
+ b
82
+ end
83
+ end
84
+
85
+ def strread(addr)
86
+ len = api('Kernel32', 'lstrlenA').call(addr)
87
+ to_codepage(to_unicode(memread(addr, len+1), CP_ANSI), CP_UTF8)
88
+ end
89
+
90
+ def wstrread(addr)
91
+ len = api('Kernel32', 'lstrlenW').call(addr)
92
+ to_codepage(memread(addr, len*2+2))
93
+ end
94
+
95
+
96
+
97
+
98
+
99
+
100
+
101
+ end
102
+
103
+ extend Win32API
104
+ end
data/lib/npgrt.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  require "npgrt/version"
2
+ require 'npgrt/win32api'
3
+ require 'npgrt/message'
4
+ require 'npgrt/require'
2
5
 
3
- module NPGRT
4
-
5
- end
data/lib/npgrt.rb~ ADDED
@@ -0,0 +1,4 @@
1
+ require "npgrt/version"
2
+ require 'npgrt/message'
3
+ require 'npgrt/require'
4
+
data/message.rb ADDED
@@ -0,0 +1 @@
1
+
data/npgrt.gemspec~ ADDED
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'npgrt/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "npgrt"
8
+ spec.version = NPGRT::VERSION
9
+ spec.authors = ["TODO: Write your name"]
10
+ spec.email = ["TODO: Write your email address"]
11
+ spec.summary = %q{TODO: Write a short summary. Required.}
12
+ spec.description = %q{TODO: Write a longer description. Optional.}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.7"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: npgrt
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Seiran
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-08-26 00:00:00.000000000 Z
11
+ date: 2014-08-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -51,8 +51,18 @@ files:
51
51
  - README.md
52
52
  - Rakefile
53
53
  - lib/npgrt.rb
54
+ - lib/npgrt.rb~
55
+ - lib/npgrt/message.rb
56
+ - lib/npgrt/message.rb~
57
+ - lib/npgrt/require.rb
58
+ - lib/npgrt/require.rb~
54
59
  - lib/npgrt/version.rb
60
+ - lib/npgrt/version.rb~
61
+ - lib/npgrt/win32api.rb
62
+ - lib/npgrt/win32api.rb~
63
+ - message.rb
55
64
  - npgrt.gemspec
65
+ - npgrt.gemspec~
56
66
  homepage: ''
57
67
  licenses:
58
68
  - MIT