57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
|
# File 'ext/macserialrb/macserialrb.c', line 57
static VALUE
generate(int argc, VALUE *argv, VALUE self)
{
VALUE model = Qnil;
VALUE obj = rb_hash_new();
for (int i = 0; i < argc; ++i)
{
model = rb_hash_aref(argv[i], rb_to_symbol( rb_str_new2("model") ));
}
if (NIL_P(model))
{
rb_raise(rb_eTypeError, "model is required!");
exit(0);
}
SERIALINFO info = get_serialinfo(model);
if (get_serial(&info)) {
char mlb[MLB_MAX_SIZE];
char ssn[MLB_MAX_SIZE];
get_mlb(&info, mlb, MLB_MAX_SIZE);
sprintf(ssn, "%s%s%s%s%s", info.country, info.year, info.week, info.line, info.model);
VALUE productName = rb_str_new2(ApplePlatformData[info.modelIndex].productName);
VALUE SystemSerialNumber = rb_str_new2(ssn);
VALUE MLB = rb_str_new2(mlb);
rb_hash_aset(obj, rb_to_symbol( rb_str_new2("productName") ), productName);
rb_hash_aset(obj, rb_to_symbol( rb_str_new2("SystemSerialNumber") ), SystemSerialNumber);
rb_hash_aset(obj, rb_to_symbol( rb_str_new2("MLB") ), MLB);
}
return obj;
}
|