obfuskit 0.1.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 64dba62899b6d17faac7cb64e3797074bf7d532bda2ed2541b7eaf0a7e831be4
4
+ data.tar.gz: eb181aeb2d05fffc68a2c7bc1229ed9524aa5bceebbf648e4ae80d342d8c3e52
5
+ SHA512:
6
+ metadata.gz: 152431909ff9df68577645f73f68cb267662291b3e4ac8e13c95a34dd204718951a238f2d01c5d16d335a69083e79091e420b4103e0f6a35f151e0be8d09890d
7
+ data.tar.gz: 3167acf2e668dc3fd4b5eb0a6d1b2d31f6f1d0eeaa98316f8375212baae9b56e0254b22a8a610d77d0b0238d2a832323734381dba8352d9df92e117e063f35ae
data/bin/obfuskit ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env ruby
2
+ require 'obfuskit'
data/lib/O.rb ADDED
@@ -0,0 +1,25 @@
1
+ # A class representing an obfuscator.
2
+ class O
3
+ # Initializes the obfuscator with a string.
4
+ # The string is converted to an array of bytes and stored in @c.
5
+ # The size of the array is stored in @l.
6
+ def initialize(s)
7
+ s = s.bytes if s.is_a? String
8
+ @c = s
9
+ @l = @c.size
10
+ end
11
+
12
+ # Obfuscates a string.
13
+ # The string is converted to an array of bytes and each element is XORed with an element from @c.
14
+ # The index of the element from @c is the index of the element from the string modulo @l.
15
+ def o(v)
16
+ v.bytes.map.with_index { |b, i| b ^ @c[i % @l] }
17
+ end
18
+
19
+ # Reverses the obfuscation of an array of bytes.
20
+ # Each element is XORed with an element from @c and the result is converted back to a string.
21
+ # The index of the element from @c is the index of the element from the array modulo @l.
22
+ def r(value)
23
+ value.map.with_index { |b, i| b ^ @c[i % @l] }.pack('C*').force_encoding('utf-8')
24
+ end
25
+ end
data/lib/Omin.kt ADDED
@@ -0,0 +1 @@
1
+ class O{private val a:ByteArray;private val b:Int;constructor(s:String){a=s.toByteArray(Charsets.UTF_8);b=a.size};fun o(v:String):ByteArray{val d=v.toByteArray(Charsets.UTF_8);return ByteArray(d.size){i->(d[i].toInt() xor a[i%b].toInt()).toByte()}};fun r(value:ByteArray):String{return String(ByteArray(value.size){i->(value[i].toInt() xor a[i%b].toInt()).toByte()},Charsets.UTF_8)}}
data/lib/Omin.swift ADDED
@@ -0,0 +1 @@
1
+ struct O { private let c: [UInt8]; private let l: Int; init(_ s: String) { self.init([UInt8](s.utf8)) }; init(_ c: [UInt8]) { self.c = c; l = c.count }; @inline(__always) func o(_ v: String) -> [UInt8] { [UInt8](v.utf8).enumerated().map { $0.element ^ c[$0.offset % l] } }; @inline(__always) func r(_ value: [UInt8]) -> String { String(bytes: value.enumerated().map { $0.element ^ c[$0.offset % l] }, encoding: .utf8) ?? "" } }
data/lib/obfuskit.rb ADDED
@@ -0,0 +1,107 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # Import the necessary modules and files
4
+ require_relative 'O'
5
+ require 'securerandom'
6
+ require 'dotenv'
7
+
8
+ # Define a module for language constants
9
+ module Language
10
+ SWIFT = "Swift"
11
+ KOTLIN = "Kotlin"
12
+ end
13
+
14
+ # Function to generate Swift code
15
+ def generate_swift(args)
16
+ # Get the source code for the obfuscator
17
+ obfuscator_source = obfuscator_source('Omin.swift')
18
+ # Generate a random UUID and remove the hyphens
19
+ obfuscation_salt = SecureRandom.uuid.to_s.gsub("-", "")
20
+ # Create a new instance of the O class with the obfuscation salt
21
+ o = O.new("_" + obfuscation_salt)
22
+
23
+ # Start building the Swift code
24
+ code = "import Foundation\n\n"
25
+ code += "enum ObfusKit {\n"
26
+ # For each argument, if it's in the environment variables, add it to the code
27
+ args.each_with_index do |arg, index|
28
+ if ENV[arg] != nil
29
+ code += "\tstatic let #{arg}: String = _o.r(#{o.o(ENV[arg])})\n"
30
+ end
31
+ end
32
+ code += "\n"
33
+ # Add the obfuscation salt and the obfuscator to the code
34
+ code += <<-STRING
35
+ \tprivate class _#{obfuscation_salt} { }
36
+ \tprivate static let _o = O(String(describing: _#{obfuscation_salt}.self))
37
+ }\n\n
38
+ STRING
39
+
40
+ # Add the obfuscator source code to the code
41
+ code += obfuscator_source
42
+ # Return the generated code
43
+ return code
44
+ end
45
+
46
+ # Function to generate Kotlin code
47
+ def generate_kotlin(args)
48
+ # Get the source code for the obfuscator
49
+ obfuscator_source = obfuscator_source('Omin.kt')
50
+ # Generate a random UUID and remove the hyphens
51
+ obfuscation_salt = SecureRandom.uuid.to_s.gsub("-", "")
52
+ # Create a new instance of the O class with the obfuscation salt
53
+ o = O.new("_" + obfuscation_salt)
54
+
55
+ # Start building the Kotlin code
56
+ code = "object ObfusKit {\n"
57
+ # Add the obfuscation salt and the obfuscator to the code
58
+ code += <<-STRING
59
+ \tprivate val _o = O(_#{obfuscation_salt}::class.java.simpleName)
60
+ \tprivate class _#{obfuscation_salt}\n
61
+ STRING
62
+
63
+ # For each argument, if it's in the environment variables, add it to the code
64
+ args.each_with_index do |arg, index|
65
+ if ENV[arg] != nil
66
+ code += "\tval #{arg}: String = _o.r(byteArrayOf(#{o.o(ENV[arg]).map { |i| i.to_s }.join(', ')}))\n"
67
+ end
68
+ end
69
+ code += "}\n\n"
70
+
71
+ # Add the obfuscator source code to the code
72
+ code += obfuscator_source
73
+ # Return the generated code
74
+ return code
75
+ end
76
+
77
+ # Function to get the source code for the obfuscator
78
+ def obfuscator_source(file_name)
79
+ # Get the full path to the file
80
+ source_file_path = File.expand_path(file_name, __dir__)
81
+ # If the file exists, read and return its contents
82
+ return File.read(source_file_path) if File.exist?(source_file_path)
83
+ end
84
+
85
+ # MAIN
86
+
87
+ language_map = {
88
+ "swift" => Language::SWIFT,
89
+ "kotlin" => Language::KOTLIN,
90
+ "kt" => Language::KOTLIN
91
+ }
92
+
93
+ Dotenv.load
94
+
95
+ args = ARGV
96
+ first_arg = args.shift
97
+
98
+ if first_arg != nil && language_map.key?(first_arg.downcase)
99
+ case language_map[first_arg]
100
+ when Language::SWIFT
101
+ puts generate_swift(args)
102
+ when Language::KOTLIN
103
+ puts generate_kotlin(args)
104
+ end
105
+ else
106
+ puts "First argument is not a valid language. Use `swift` or `kotlin`."
107
+ end
metadata ADDED
@@ -0,0 +1,48 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: obfuskit
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Martin Gratzer
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2024-01-16 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Environment variable obfuscation for Swift and Kotlin
14
+ email: mgratzer@gmail.com
15
+ executables:
16
+ - obfuskit
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - bin/obfuskit
21
+ - lib/O.rb
22
+ - lib/Omin.kt
23
+ - lib/Omin.swift
24
+ - lib/obfuskit.rb
25
+ homepage: https://github.com/mgratzer/obfuskit
26
+ licenses:
27
+ - MIT
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
+ rubygems_version: 3.3.3
45
+ signing_key:
46
+ specification_version: 4
47
+ summary: Environment variable obfuscation for Swift and Kotlin
48
+ test_files: []