uac 0.3.0
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 +7 -0
- data/bin/uac +11 -0
- data/bin/uacs +11 -0
- data/lib/uac.rb +106 -0
- data/lib/uac_sh.rb +89 -0
- metadata +49 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 37528e1860f9e3fda920e2edbb5132b706455a6b
|
4
|
+
data.tar.gz: d81a019f32dacc8228d85b73da5419f1912a3498
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 3943141310485d72528db7d4621a82b88cee357f64be29ff555e8059c4863d73c0a6160636e90b30d687d936de8e8af8650682b88febf3fe0fa80d73ad431bd9
|
7
|
+
data.tar.gz: 4a044333ff2315d10b94eefa82fe3e8d110680af89e635a9fa0f87472db608c236ff3b2661b04936faadb992912dbf8613d2399d4bc126cb2a63b6b4013db3c0
|
data/bin/uac
ADDED
data/bin/uacs
ADDED
data/lib/uac.rb
ADDED
@@ -0,0 +1,106 @@
|
|
1
|
+
require 'ffi'
|
2
|
+
require 'optparse'
|
3
|
+
|
4
|
+
module Uac
|
5
|
+
class UacPrivate
|
6
|
+
def encode_arg arg
|
7
|
+
s = arg.gsub /(\\+)"/, "#{$1}#{$1}\""
|
8
|
+
s = s.gsub /(\\+)$"/, "#{$1}#{$1}"
|
9
|
+
if s.match /\s/
|
10
|
+
s = "\"" + s + "\""
|
11
|
+
end
|
12
|
+
return s
|
13
|
+
end
|
14
|
+
|
15
|
+
def get_long_arg args
|
16
|
+
return args.map do |arg|
|
17
|
+
encode_arg arg
|
18
|
+
end.join " "
|
19
|
+
end
|
20
|
+
|
21
|
+
def join_long_args args, separator = " "
|
22
|
+
result = []
|
23
|
+
for arg in args
|
24
|
+
m = arg.match /^"(.+?)"$/
|
25
|
+
if m
|
26
|
+
core = m.captures[0]
|
27
|
+
else
|
28
|
+
core = arg
|
29
|
+
end
|
30
|
+
result << core
|
31
|
+
end
|
32
|
+
return result.join separator
|
33
|
+
end
|
34
|
+
|
35
|
+
def join_args options, args
|
36
|
+
if options[:terminal]
|
37
|
+
file = "cmd"
|
38
|
+
rest_args = args
|
39
|
+
else
|
40
|
+
file = args[0]
|
41
|
+
rest_args = args[1..-1]
|
42
|
+
end
|
43
|
+
|
44
|
+
rest = get_long_arg rest_args
|
45
|
+
|
46
|
+
if options[:cd]
|
47
|
+
pre = get_long_arg [ 'cd', '/d', Dir.pwd, '&' ]
|
48
|
+
rest = join_long_args [ pre, rest ]
|
49
|
+
end
|
50
|
+
|
51
|
+
if options[:pause]
|
52
|
+
post = get_long_arg([ '&', 'pause' ])
|
53
|
+
rest = join_long_args [ rest, post ]
|
54
|
+
end
|
55
|
+
|
56
|
+
if options[:terminal]
|
57
|
+
rest = "/c \"#{rest}\""
|
58
|
+
end
|
59
|
+
|
60
|
+
if options[:debug]
|
61
|
+
puts "file: #{file}"
|
62
|
+
puts "rest: #{rest}"
|
63
|
+
end
|
64
|
+
|
65
|
+
return [file, rest]
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
module Shell32
|
70
|
+
extend FFI::Library
|
71
|
+
|
72
|
+
ffi_lib 'shell32'
|
73
|
+
ffi_convention :stdcall
|
74
|
+
|
75
|
+
# HINSTANCE ShellExecute(HWND hwnd, LPCTSTR lpOperation, LPCTSTR lpFile, LPCTSTR lpParameters, LPCTSTR lpDirectory, INT nShowCmd)
|
76
|
+
attach_function :ShellExecuteA, [ :pointer, :pointer, :pointer, :pointer, :pointer, :int ], :pointer
|
77
|
+
|
78
|
+
SW_HIDE = 0
|
79
|
+
SW_SHOWNORMAL = 1
|
80
|
+
SW_SHOWMINIMIZED = 2
|
81
|
+
SW_SHOWMAXIMIZED = 3
|
82
|
+
SW_SHOWNOACTIVATE = 4
|
83
|
+
SW_SHOW = 5
|
84
|
+
SW_MINIMIZE = 6
|
85
|
+
SW_SHOWMINNOACTIVE = 7
|
86
|
+
SW_SHOWNA = 8
|
87
|
+
SW_RESTORE = 9
|
88
|
+
SW_SHOWDEFAULT = 10
|
89
|
+
end
|
90
|
+
|
91
|
+
def self.shell_execute options, args
|
92
|
+
uac_private = UacPrivate.new
|
93
|
+
|
94
|
+
(file, rest) = uac_private.join_args options, args
|
95
|
+
|
96
|
+
verb = options[:verb] || "runas"
|
97
|
+
|
98
|
+
Shell32.ShellExecuteA(
|
99
|
+
nil,
|
100
|
+
FFI::MemoryPointer.from_string(verb),
|
101
|
+
FFI::MemoryPointer.from_string(file),
|
102
|
+
FFI::MemoryPointer.from_string(rest),
|
103
|
+
FFI::MemoryPointer.from_string(Dir.pwd),
|
104
|
+
Shell32::SW_SHOWNORMAL)
|
105
|
+
end
|
106
|
+
end
|
data/lib/uac_sh.rb
ADDED
@@ -0,0 +1,89 @@
|
|
1
|
+
require_relative 'uac'
|
2
|
+
|
3
|
+
module UacSh
|
4
|
+
def self.split_args args
|
5
|
+
i = args.index '--'
|
6
|
+
if i
|
7
|
+
return [ args[0...i], args[(i+1)..-1] ]
|
8
|
+
else
|
9
|
+
return [ [], args ]
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.parse_meta_args options, args
|
14
|
+
option_parser = OptionParser.new do |opt|
|
15
|
+
opt.banner = <<-EOF
|
16
|
+
Usage: uac <OPTIONS> <COMMAND>
|
17
|
+
|
18
|
+
For examples please see https://github.com/winteryoung/uac
|
19
|
+
EOF
|
20
|
+
|
21
|
+
opt.separator ""
|
22
|
+
opt.separator "Options:"
|
23
|
+
|
24
|
+
terminal_help = 'The given command will be executed in a terminal window, so cmd /c is added implictly. This is enabled by default.'
|
25
|
+
opt.on('-t', '--[no-]terminal', terminal_help) do |o|
|
26
|
+
options[:terminal] = o
|
27
|
+
if not o
|
28
|
+
options[:pause] = o
|
29
|
+
options[:cd] = o
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
pause_help = 'Pause after execution. This implies executing command line, so cmd.exe is the program to be executed. This option implies --terminal. This is enabled by default.'
|
34
|
+
opt.on('-p', '--[no-]pause', pause_help) do |o|
|
35
|
+
options[:pause] = o
|
36
|
+
if o
|
37
|
+
options[:terminal] = o
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
opt.on('--debug') do |o|
|
42
|
+
options[:debug] = o
|
43
|
+
end
|
44
|
+
|
45
|
+
opt.on('--cd', '-c', 'Change to current directory. Default is true. This option implies --terminal.') do |o|
|
46
|
+
options[:cd] = o
|
47
|
+
if o
|
48
|
+
options[:terminal] = o
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
opt.on_tail('-h', '--help', 'Print this help.') do |o|
|
53
|
+
puts opt
|
54
|
+
exit
|
55
|
+
end
|
56
|
+
end.parse! args
|
57
|
+
end
|
58
|
+
|
59
|
+
def self.run options, args
|
60
|
+
(meta_args, args) = split_args args
|
61
|
+
|
62
|
+
all_options = args.all? do |arg|
|
63
|
+
arg.start_with? "-"
|
64
|
+
end
|
65
|
+
if all_options
|
66
|
+
meta_args = args
|
67
|
+
args = []
|
68
|
+
end
|
69
|
+
|
70
|
+
options = {
|
71
|
+
:pause => true,
|
72
|
+
:terminal => true,
|
73
|
+
:cd => true
|
74
|
+
}.merge options
|
75
|
+
|
76
|
+
parse_meta_args options, meta_args
|
77
|
+
|
78
|
+
if options[:debug]
|
79
|
+
puts "options: #{options}"
|
80
|
+
puts "args: #{args}"
|
81
|
+
end
|
82
|
+
|
83
|
+
if not args or args.empty?
|
84
|
+
exit
|
85
|
+
end
|
86
|
+
|
87
|
+
Uac.shell_execute options, args
|
88
|
+
end
|
89
|
+
end
|
metadata
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: uac
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.3.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Winter Young
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-03-19 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: Executes commands with elevated privilege in Windows
|
14
|
+
email: 513805252@qq.com
|
15
|
+
executables:
|
16
|
+
- uac
|
17
|
+
- uacs
|
18
|
+
extensions: []
|
19
|
+
extra_rdoc_files: []
|
20
|
+
files:
|
21
|
+
- bin/uac
|
22
|
+
- bin/uacs
|
23
|
+
- lib/uac.rb
|
24
|
+
- lib/uac_sh.rb
|
25
|
+
homepage: https://github.com/winteryoung/uac
|
26
|
+
licenses:
|
27
|
+
- Apache-2.0
|
28
|
+
metadata: {}
|
29
|
+
post_install_message:
|
30
|
+
rdoc_options: []
|
31
|
+
require_paths:
|
32
|
+
- lib
|
33
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
34
|
+
requirements:
|
35
|
+
- - ">="
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
39
|
+
requirements:
|
40
|
+
- - ">="
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: '0'
|
43
|
+
requirements: []
|
44
|
+
rubyforge_project:
|
45
|
+
rubygems_version: 2.6.1
|
46
|
+
signing_key:
|
47
|
+
specification_version: 4
|
48
|
+
summary: Windows UAC elevator
|
49
|
+
test_files: []
|