Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
btwise
OpenCorePKG_MOD
提交
ae76a3f6
O
OpenCorePKG_MOD
项目概览
btwise
/
OpenCorePKG_MOD
通知
26
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
O
OpenCorePKG_MOD
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
ae76a3f6
编写于
2月 27, 2021
作者:
M
Marvin Häuser
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
User: Introduce UserPseudoRadom
上级
ced62ddf
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
88 addition
and
64 deletion
+88
-64
User/Include/UserPseudoRandom.h
User/Include/UserPseudoRandom.h
+14
-0
User/Library/UserPseudoRandom.c
User/Library/UserPseudoRandom.c
+71
-0
User/Makefile
User/Makefile
+1
-1
Utilities/macserial/macserial.c
Utilities/macserial/macserial.c
+2
-58
Utilities/macserial/macserial.h
Utilities/macserial/macserial.h
+0
-5
未找到文件。
User/Include/UserPseudoRandom.h
0 → 100644
浏览文件 @
ae76a3f6
/** @file
Copyright (c) 2020, vit9696. All rights reserved.
SPDX-License-Identifier: BSD-3-Clause
**/
#ifndef OC_USER_PSEUDO_RANDOM_H
#define OC_USER_PSEUDO_RANDOM_H
#include <stdint.h>
uint32_t
pseudo_random
(
void
);
uint32_t
pseudo_random_between
(
uint32_t
from
,
uint32_t
to
);
#endif // OC_USER_PSEUDO_RANDOM_H
User/Library/UserPseudoRandom.c
0 → 100644
浏览文件 @
ae76a3f6
/** @file
Copyright (c) 2020, vit9696. All rights reserved.
SPDX-License-Identifier: BSD-3-Clause
**/
#include <stdint.h>
#include <stdio.h>
#include <time.h>
#ifdef __GNUC__
uint32_t
arc4random
(
void
)
__attribute__
((
weak
));
uint32_t
arc4random_uniform
(
uint32_t
upper_bound
)
__attribute__
((
weak
));
#endif
// Taken from https://en.wikipedia.org/wiki/Xorshift#Example_implementation
// I am not positive what is better to use here (especially on Windows).
// Fortunately we only need something only looking random.
uint32_t
pseudo_random
(
void
)
{
#if defined(__GNUC__) && !defined(__EMSCRIPTEN__)
if
(
arc4random
)
return
arc4random
();
#endif
static
uint32_t
state
;
if
(
!
state
)
{
fprintf
(
stderr
,
"Warning: arc4random is not available!
\n
"
);
state
=
(
uint32_t
)
time
(
NULL
);
}
uint32_t
x
=
state
;
x
^=
x
<<
13
;
x
^=
x
>>
17
;
x
^=
x
<<
5
;
state
=
x
;
return
x
;
}
// Taken from https://opensource.apple.com/source/Libc/Libc-1082.50.1/gen/FreeBSD/arc4random.c
// Mac OS X 10.6.8 and earlier do not have arc4random_uniform, so we implement one.
uint32_t
pseudo_random_between
(
uint32_t
from
,
uint32_t
to
)
{
uint32_t
upper_bound
=
to
+
1
-
from
;
#if defined(__GNUC__) && !defined(__EMSCRIPTEN__)
// Prefer native implementation if available.
if
(
arc4random_uniform
)
return
from
+
arc4random_uniform
(
upper_bound
);
#endif
uint32_t
r
,
min
;
if
(
upper_bound
<
2
)
return
from
;
#if (ULONG_MAX > 0xffffffffUL)
min
=
0x100000000UL
%
upper_bound
;
#else
if
(
upper_bound
>
0x80000000
)
min
=
1
+
~
upper_bound
;
else
min
=
((
0xffffffff
-
(
upper_bound
*
2
))
+
1
)
%
upper_bound
;
#endif
for
(;;)
{
r
=
pseudo_random
();
if
(
r
>=
min
)
break
;
}
return
from
+
r
%
upper_bound
;
}
User/Makefile
浏览文件 @
ae76a3f6
...
...
@@ -217,7 +217,7 @@ endif
# Miscellaneous implementations that do not depend on UDK.
#
VPATH
+=
$(OC_USER)
/User/Library:
$
OBJS
+=
UserFile.o
OBJS
+=
UserFile.o
UserPseudoRandom.o
#
# Directory where objects will be produced.
...
...
Utilities/macserial/macserial.c
浏览文件 @
ae76a3f6
...
...
@@ -18,6 +18,8 @@
#include <IOKit/IOKitLib.h>
#endif
#include <UserPseudoRandom.h>
#include "macserial.h"
#include "modelinfo.h"
...
...
@@ -120,64 +122,6 @@ static bool verify_mlb_checksum(const char *mlb, size_t len) {
return
checksum
%
(
sizeof
(
alphabet
)
-
1
)
==
0
;
}
// Taken from https://en.wikipedia.org/wiki/Xorshift#Example_implementation
// I am not positive what is better to use here (especially on Windows).
// Fortunately we only need something only looking random.
static
uint32_t
pseudo_random
(
void
)
{
#if defined(__GNUC__) && !defined(__EMSCRIPTEN__)
if
(
arc4random
)
return
arc4random
();
#endif
static
uint32_t
state
;
if
(
!
state
)
{
fprintf
(
stderr
,
"Warning: arc4random is not available!
\n
"
);
state
=
(
uint32_t
)
time
(
NULL
);
}
uint32_t
x
=
state
;
x
^=
x
<<
13
;
x
^=
x
>>
17
;
x
^=
x
<<
5
;
state
=
x
;
return
x
;
}
// Taken from https://opensource.apple.com/source/Libc/Libc-1082.50.1/gen/FreeBSD/arc4random.c
// Mac OS X 10.6.8 and earlier do not have arc4random_uniform, so we implement one.
static
uint32_t
pseudo_random_between
(
uint32_t
from
,
uint32_t
to
)
{
uint32_t
upper_bound
=
to
+
1
-
from
;
#if defined(__GNUC__) && !defined(__EMSCRIPTEN__)
// Prefer native implementation if available.
if
(
arc4random_uniform
)
return
from
+
arc4random_uniform
(
upper_bound
);
#endif
uint32_t
r
,
min
;
if
(
upper_bound
<
2
)
return
from
;
#if (ULONG_MAX > 0xffffffffUL)
min
=
0x100000000UL
%
upper_bound
;
#else
if
(
upper_bound
>
0x80000000
)
min
=
1
+
~
upper_bound
;
else
min
=
((
0xffffffff
-
(
upper_bound
*
2
))
+
1
)
%
upper_bound
;
#endif
for
(;;)
{
r
=
pseudo_random
();
if
(
r
>=
min
)
break
;
}
return
from
+
r
%
upper_bound
;
}
static
int32_t
get_current_model
(
void
)
{
#ifdef __APPLE__
CFDataRef
model
=
get_ioreg_entry
(
"IODeviceTree:/"
,
CFSTR
(
"model"
),
CFDataGetTypeID
());
...
...
Utilities/macserial/macserial.h
浏览文件 @
ae76a3f6
...
...
@@ -13,11 +13,6 @@
#define PROGRAM_VERSION "2.1.7"
#ifdef __GNUC__
uint32_t
arc4random
(
void
)
__attribute__
((
weak
));
uint32_t
arc4random_uniform
(
uint32_t
upper_bound
)
__attribute__
((
weak
));
#endif
#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
#define SZUUID 16
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录