macserialrb 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,102 @@
1
+ #include "macserialrb.h"
2
+
3
+ #include <limits.h>
4
+ #include <stdbool.h>
5
+ #include <stdio.h>
6
+ #include <stdlib.h>
7
+ #include <stdint.h>
8
+ #include <string.h>
9
+ #include <time.h>
10
+
11
+ #ifdef __APPLE__
12
+ #include <CoreFoundation/CoreFoundation.h>
13
+ #include <IOKit/IOKitLib.h>
14
+ #endif
15
+
16
+ #include "macserial/macserial.h"
17
+ #include "macserial/modelinfo.h"
18
+ #include "macserial/macserial.c"
19
+ #include "macserial/modelinfo_autogen.h"
20
+
21
+ VALUE rb_mMacserialrb;
22
+
23
+ static VALUE
24
+ models()
25
+ {
26
+ VALUE obj = rb_ary_new_capa(APPLE_MODEL_MAX);
27
+
28
+ for (int32_t idx = 0; idx < APPLE_MODEL_MAX; idx++) {
29
+ rb_ary_push(obj, rb_str_new_cstr(ApplePlatformData[idx].productName));
30
+ }
31
+ return obj;
32
+ }
33
+
34
+ static SERIALINFO
35
+ get_serialinfo(VALUE model)
36
+ {
37
+ SERIALINFO info = {
38
+ .modelIndex = -1,
39
+ .decodedYear = -1,
40
+ .decodedWeek = -1,
41
+ .decodedCopy = -1,
42
+ .decodedLine = -1
43
+ };
44
+
45
+ // model
46
+ for (int32_t idx = 0; idx < APPLE_MODEL_MAX; idx++) {
47
+ if (strcmp(ApplePlatformData[idx].productName, rb_string_value_cstr(&model)) == 0)
48
+ {
49
+ info.modelIndex = idx;
50
+ break;
51
+ }
52
+ }
53
+
54
+ return info;
55
+ }
56
+
57
+ static VALUE
58
+ generate(int argc, VALUE *argv, VALUE self)
59
+ {
60
+ VALUE model = Qnil;
61
+ VALUE obj = rb_hash_new();
62
+
63
+ for (int i = 0; i < argc; ++i)
64
+ {
65
+ model = rb_hash_aref(argv[i], rb_to_symbol( rb_str_new2("model") ));
66
+ }
67
+
68
+ if (NIL_P(model))
69
+ {
70
+ rb_raise(rb_eTypeError, "model is required!");
71
+ exit(0);
72
+ }
73
+
74
+ SERIALINFO info = get_serialinfo(model);
75
+
76
+ if (get_serial(&info)) {
77
+ char mlb[MLB_MAX_SIZE];
78
+ char ssn[MLB_MAX_SIZE];
79
+
80
+ get_mlb(&info, mlb, MLB_MAX_SIZE);
81
+ sprintf(ssn, "%s%s%s%s%s", info.country, info.year, info.week, info.line, info.model);
82
+
83
+ VALUE productName = rb_str_new2(ApplePlatformData[info.modelIndex].productName);
84
+ VALUE SystemSerialNumber = rb_str_new2(ssn);
85
+ VALUE MLB = rb_str_new2(mlb);
86
+
87
+ rb_hash_aset(obj, rb_to_symbol( rb_str_new2("productName") ), productName);
88
+ rb_hash_aset(obj, rb_to_symbol( rb_str_new2("SystemSerialNumber") ), SystemSerialNumber);
89
+ rb_hash_aset(obj, rb_to_symbol( rb_str_new2("MLB") ), MLB);
90
+ }
91
+
92
+ return obj;
93
+ }
94
+
95
+ void
96
+ Init_macserialrb(void)
97
+ {
98
+ rb_mMacserialrb = rb_define_module("Macserialrb");
99
+
100
+ rb_define_module_function(rb_mMacserialrb, "models", models, 0);
101
+ rb_define_module_function(rb_mMacserialrb, "generate", generate, -1);
102
+ }
@@ -0,0 +1,12 @@
1
+ #ifndef MACSERIALRB_H
2
+ #define MACSERIALRB_H 1
3
+
4
+ #include "ruby.h"
5
+ #include "macserial/macserial.h"
6
+ #include "macserial/modelinfo.h"
7
+
8
+ static VALUE models();
9
+ static VALUE generate(int argc, VALUE *argv, VALUE self);
10
+ static SERIALINFO get_serialinfo(const VALUE model);
11
+
12
+ #endif /* MACSERIALRB_H */
@@ -0,0 +1,7 @@
1
+ require "macserialrb/version"
2
+ require "macserialrb/macserialrb"
3
+
4
+ module Macserialrb
5
+ class Error < StandardError; end
6
+ # Your code goes here...
7
+ end
@@ -0,0 +1,3 @@
1
+ module Macserialrb
2
+ VERSION = "0.2.0"
3
+ end
@@ -0,0 +1,30 @@
1
+ require_relative 'lib/macserialrb/version'
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = "macserialrb"
5
+ spec.version = Macserialrb::VERSION
6
+ spec.authors = ["csrutil"]
7
+ spec.email = ["csrutil@protonmail.com"]
8
+
9
+ spec.summary = %q{macserialrb is a tool that obtains and decodes Mac serial number and board identifier to provide more information about the production of your hardware. }
10
+ spec.description = %q{macserialrb is a tool that obtains and decodes Mac serial number and board identifier to provide more information about the production of your hardware. }
11
+ spec.homepage = "https://github.com/csrutil/macserialrb"
12
+ spec.license = "MIT"
13
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
14
+
15
+ # spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
16
+
17
+ spec.metadata["homepage_uri"] = spec.homepage
18
+ spec.metadata["source_code_uri"] = "https://github.com/csrutil/macserialrb"
19
+ spec.metadata["changelog_uri"] = "https://github.com/csrutil/macserialrb/README.md"
20
+
21
+ # Specify which files should be added to the gem when it is released.
22
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
23
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
24
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
25
+ end
26
+ spec.bindir = "exe"
27
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
28
+ spec.require_paths = ["lib"]
29
+ spec.extensions = ["ext/macserialrb/extconf.rb"]
30
+ end
metadata ADDED
@@ -0,0 +1,76 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: macserialrb
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
5
+ platform: ruby
6
+ authors:
7
+ - csrutil
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2020-11-25 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: 'macserialrb is a tool that obtains and decodes Mac serial number and
14
+ board identifier to provide more information about the production of your hardware. '
15
+ email:
16
+ - csrutil@protonmail.com
17
+ executables:
18
+ - macserialrb
19
+ extensions:
20
+ - ext/macserialrb/extconf.rb
21
+ extra_rdoc_files: []
22
+ files:
23
+ - ".gitignore"
24
+ - ".rspec"
25
+ - ".travis.yml"
26
+ - CODE_OF_CONDUCT.md
27
+ - Gemfile
28
+ - Gemfile.lock
29
+ - LICENSE.txt
30
+ - README.md
31
+ - Rakefile
32
+ - bin/console
33
+ - bin/setup
34
+ - exe/macserialrb
35
+ - ext/macserialrb/extconf.rb
36
+ - ext/macserialrb/macserial/FORMAT.md
37
+ - ext/macserialrb/macserial/Makefile
38
+ - ext/macserialrb/macserial/README.md
39
+ - ext/macserialrb/macserial/cccdump.py
40
+ - ext/macserialrb/macserial/macserial.c
41
+ - ext/macserialrb/macserial/macserial.h
42
+ - ext/macserialrb/macserial/modelinfo.h
43
+ - ext/macserialrb/macserial/modelinfo_autogen.h
44
+ - ext/macserialrb/macserialrb.c
45
+ - ext/macserialrb/macserialrb.h
46
+ - lib/macserialrb.rb
47
+ - lib/macserialrb/version.rb
48
+ - macserialrb.gemspec
49
+ homepage: https://github.com/csrutil/macserialrb
50
+ licenses:
51
+ - MIT
52
+ metadata:
53
+ homepage_uri: https://github.com/csrutil/macserialrb
54
+ source_code_uri: https://github.com/csrutil/macserialrb
55
+ changelog_uri: https://github.com/csrutil/macserialrb/README.md
56
+ post_install_message:
57
+ rdoc_options: []
58
+ require_paths:
59
+ - lib
60
+ required_ruby_version: !ruby/object:Gem::Requirement
61
+ requirements:
62
+ - - ">="
63
+ - !ruby/object:Gem::Version
64
+ version: 2.3.0
65
+ required_rubygems_version: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ requirements: []
71
+ rubygems_version: 3.1.4
72
+ signing_key:
73
+ specification_version: 4
74
+ summary: macserialrb is a tool that obtains and decodes Mac serial number and board
75
+ identifier to provide more information about the production of your hardware.
76
+ test_files: []