Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
10dccf56bd | ||
|
|
cbf85a8a6d | ||
|
|
50677dfcc9 | ||
|
|
cd17b4be86 | ||
|
|
4dacc96660 |
3
ACPI/SSDTTime-master/.gitattributes
vendored
Normal file
3
ACPI/SSDTTime-master/.gitattributes
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
# Ensure all .bat scripts use CRLF line endings
|
||||
# This can prevent a number of odd batch issues
|
||||
*.bat text eol=crlf
|
||||
110
ACPI/SSDTTime-master/.gitignore
vendored
Normal file
110
ACPI/SSDTTime-master/.gitignore
vendored
Normal file
@@ -0,0 +1,110 @@
|
||||
# Byte-compiled / optimized / DLL files
|
||||
__pycache__/
|
||||
*.py[cod]
|
||||
*$py.class
|
||||
|
||||
# C extensions
|
||||
*.so
|
||||
|
||||
# Distribution / packaging
|
||||
.Python
|
||||
build/
|
||||
develop-eggs/
|
||||
dist/
|
||||
downloads/
|
||||
eggs/
|
||||
.eggs/
|
||||
lib/
|
||||
lib64/
|
||||
parts/
|
||||
sdist/
|
||||
var/
|
||||
wheels/
|
||||
*.egg-info/
|
||||
.installed.cfg
|
||||
*.egg
|
||||
MANIFEST
|
||||
|
||||
# PyInstaller
|
||||
# Usually these files are written by a python script from a template
|
||||
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
||||
*.manifest
|
||||
*.spec
|
||||
|
||||
# Installer logs
|
||||
pip-log.txt
|
||||
pip-delete-this-directory.txt
|
||||
|
||||
# Unit test / coverage reports
|
||||
htmlcov/
|
||||
.tox/
|
||||
.coverage
|
||||
.coverage.*
|
||||
.cache
|
||||
nosetests.xml
|
||||
coverage.xml
|
||||
*.cover
|
||||
.hypothesis/
|
||||
.pytest_cache/
|
||||
|
||||
# Translations
|
||||
*.mo
|
||||
*.pot
|
||||
|
||||
# Django stuff:
|
||||
*.log
|
||||
local_settings.py
|
||||
db.sqlite3
|
||||
|
||||
# Flask stuff:
|
||||
instance/
|
||||
.webassets-cache
|
||||
|
||||
# Scrapy stuff:
|
||||
.scrapy
|
||||
|
||||
# Sphinx documentation
|
||||
docs/_build/
|
||||
|
||||
# PyBuilder
|
||||
target/
|
||||
|
||||
# Jupyter Notebook
|
||||
.ipynb_checkpoints
|
||||
|
||||
# pyenv
|
||||
.python-version
|
||||
|
||||
# celery beat schedule file
|
||||
celerybeat-schedule
|
||||
|
||||
# SageMath parsed files
|
||||
*.sage.py
|
||||
|
||||
# Environments
|
||||
.env
|
||||
.venv
|
||||
env/
|
||||
venv/
|
||||
ENV/
|
||||
env.bak/
|
||||
venv.bak/
|
||||
|
||||
# Spyder project settings
|
||||
.spyderproject
|
||||
.spyproject
|
||||
|
||||
# Rope project settings
|
||||
.ropeproject
|
||||
|
||||
# mkdocs documentation
|
||||
/site
|
||||
|
||||
# mypy
|
||||
.mypy_cache/
|
||||
|
||||
Results/*
|
||||
iasl*
|
||||
acpidump*
|
||||
|
||||
.vs
|
||||
21
ACPI/SSDTTime-master/LICENSE
Normal file
21
ACPI/SSDTTime-master/LICENSE
Normal file
@@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2019 CorpNewt
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
426
ACPI/SSDTTime-master/PatchMerge.bat
Normal file
426
ACPI/SSDTTime-master/PatchMerge.bat
Normal file
@@ -0,0 +1,426 @@
|
||||
@echo off
|
||||
REM Get our local path and args before delayed expansion - allows % and !
|
||||
set "thisDir=%~dp0"
|
||||
set "args=%*"
|
||||
|
||||
setlocal enableDelayedExpansion
|
||||
REM Setup initial vars
|
||||
set "script_name="
|
||||
set /a tried=0
|
||||
set "toask=yes"
|
||||
set "pause_on_error=yes"
|
||||
set "py2v="
|
||||
set "py2path="
|
||||
set "py3v="
|
||||
set "py3path="
|
||||
set "pypath="
|
||||
set "targetpy=3"
|
||||
|
||||
REM use_py3:
|
||||
REM TRUE = Use if found, use py2 otherwise
|
||||
REM FALSE = Use py2
|
||||
REM FORCE = Use py3
|
||||
set "use_py3=TRUE"
|
||||
|
||||
REM We'll parse if the first argument passed is
|
||||
REM --install-python and if so, we'll just install
|
||||
REM Can optionally take a version number as the
|
||||
REM second arg - i.e. --install-python 3.13.1
|
||||
set "just_installing=FALSE"
|
||||
set "user_provided="
|
||||
|
||||
REM Get the system32 (or equivalent) path
|
||||
call :getsyspath "syspath"
|
||||
|
||||
REM Make sure the syspath exists
|
||||
if "!syspath!" == "" (
|
||||
if exist "%SYSTEMROOT%\system32\cmd.exe" (
|
||||
if exist "%SYSTEMROOT%\system32\reg.exe" (
|
||||
if exist "%SYSTEMROOT%\system32\where.exe" (
|
||||
REM Fall back on the default path if it exists
|
||||
set "ComSpec=%SYSTEMROOT%\system32\cmd.exe"
|
||||
set "syspath=%SYSTEMROOT%\system32\"
|
||||
)
|
||||
)
|
||||
)
|
||||
if "!syspath!" == "" (
|
||||
cls
|
||||
echo ### ###
|
||||
echo # Missing Required Files #
|
||||
echo ### ###
|
||||
echo.
|
||||
echo Could not locate cmd.exe, reg.exe, or where.exe
|
||||
echo.
|
||||
echo Please ensure your ComSpec environment variable is properly configured and
|
||||
echo points directly to cmd.exe, then try again.
|
||||
echo.
|
||||
echo Current CompSpec Value: "%ComSpec%"
|
||||
echo.
|
||||
echo Press [enter] to quit.
|
||||
pause > nul
|
||||
exit /b 1
|
||||
)
|
||||
)
|
||||
|
||||
if "%~1" == "--install-python" (
|
||||
set "just_installing=TRUE"
|
||||
set "user_provided=%~2"
|
||||
goto installpy
|
||||
)
|
||||
|
||||
goto checkscript
|
||||
|
||||
:checkscript
|
||||
REM Check for our script first
|
||||
set "looking_for=!script_name!"
|
||||
if "!script_name!" == "" (
|
||||
set "looking_for=%~n0.py or %~n0.command"
|
||||
set "script_name=%~n0.py"
|
||||
if not exist "!thisDir!\!script_name!" (
|
||||
set "script_name=%~n0.command"
|
||||
)
|
||||
)
|
||||
if not exist "!thisDir!\!script_name!" (
|
||||
cls
|
||||
echo ### ###
|
||||
echo # Target Not Found #
|
||||
echo ### ###
|
||||
echo.
|
||||
echo Could not find !looking_for!.
|
||||
echo Please make sure to run this script from the same directory
|
||||
echo as !looking_for!.
|
||||
echo.
|
||||
echo Press [enter] to quit.
|
||||
pause > nul
|
||||
exit /b 1
|
||||
)
|
||||
goto checkpy
|
||||
|
||||
:checkpy
|
||||
call :updatepath
|
||||
for /f "USEBACKQ tokens=*" %%x in (`!syspath!where.exe python 2^> nul`) do ( call :checkpyversion "%%x" "py2v" "py2path" "py3v" "py3path" )
|
||||
for /f "USEBACKQ tokens=*" %%x in (`!syspath!where.exe python3 2^> nul`) do ( call :checkpyversion "%%x" "py2v" "py2path" "py3v" "py3path" )
|
||||
for /f "USEBACKQ tokens=*" %%x in (`!syspath!where.exe py 2^> nul`) do ( call :checkpylauncher "%%x" "py2v" "py2path" "py3v" "py3path" )
|
||||
REM Walk our returns to see if we need to install
|
||||
if /i "!use_py3!" == "FALSE" (
|
||||
set "targetpy=2"
|
||||
set "pypath=!py2path!"
|
||||
) else if /i "!use_py3!" == "FORCE" (
|
||||
set "pypath=!py3path!"
|
||||
) else if /i "!use_py3!" == "TRUE" (
|
||||
set "pypath=!py3path!"
|
||||
if "!pypath!" == "" set "pypath=!py2path!"
|
||||
)
|
||||
if not "!pypath!" == "" (
|
||||
goto runscript
|
||||
)
|
||||
if !tried! lss 1 (
|
||||
if /i "!toask!"=="yes" (
|
||||
REM Better ask permission first
|
||||
goto askinstall
|
||||
) else (
|
||||
goto installpy
|
||||
)
|
||||
) else (
|
||||
cls
|
||||
echo ### ###
|
||||
echo # Python Not Found #
|
||||
echo ### ###
|
||||
echo.
|
||||
REM Couldn't install for whatever reason - give the error message
|
||||
echo Python is not installed or not found in your PATH var.
|
||||
echo Please go to https://www.python.org/downloads/windows/ to
|
||||
echo download and install the latest version, then try again.
|
||||
echo.
|
||||
echo Make sure you check the box labeled:
|
||||
echo.
|
||||
echo "Add Python X.X to PATH"
|
||||
echo.
|
||||
echo Where X.X is the py version you're installing.
|
||||
echo.
|
||||
echo Press [enter] to quit.
|
||||
pause > nul
|
||||
exit /b 1
|
||||
)
|
||||
goto runscript
|
||||
|
||||
:checkpylauncher <path> <py2v> <py2path> <py3v> <py3path>
|
||||
REM Attempt to check the latest python 2 and 3 versions via the py launcher
|
||||
for /f "USEBACKQ tokens=*" %%x in (`%~1 -2 -c "import sys; print(sys.executable)" 2^> nul`) do ( call :checkpyversion "%%x" "%~2" "%~3" "%~4" "%~5" )
|
||||
for /f "USEBACKQ tokens=*" %%x in (`%~1 -3 -c "import sys; print(sys.executable)" 2^> nul`) do ( call :checkpyversion "%%x" "%~2" "%~3" "%~4" "%~5" )
|
||||
goto :EOF
|
||||
|
||||
:checkpyversion <path> <py2v> <py2path> <py3v> <py3path>
|
||||
set "version="&for /f "tokens=2* USEBACKQ delims= " %%a in (`"%~1" -V 2^>^&1`) do (
|
||||
REM Ensure we have a version number
|
||||
call :isnumber "%%a"
|
||||
if not "!errorlevel!" == "0" goto :EOF
|
||||
set "version=%%a"
|
||||
)
|
||||
if not defined version goto :EOF
|
||||
if "!version:~0,1!" == "2" (
|
||||
REM Python 2
|
||||
call :comparepyversion "!version!" "!%~2!"
|
||||
if "!errorlevel!" == "1" (
|
||||
set "%~2=!version!"
|
||||
set "%~3=%~1"
|
||||
)
|
||||
) else (
|
||||
REM Python 3
|
||||
call :comparepyversion "!version!" "!%~4!"
|
||||
if "!errorlevel!" == "1" (
|
||||
set "%~4=!version!"
|
||||
set "%~5=%~1"
|
||||
)
|
||||
)
|
||||
goto :EOF
|
||||
|
||||
:isnumber <check_value>
|
||||
set "var="&for /f "delims=0123456789." %%i in ("%~1") do set var=%%i
|
||||
if defined var (exit /b 1)
|
||||
exit /b 0
|
||||
|
||||
:comparepyversion <version1> <version2> <return>
|
||||
REM Exits with status 0 if equal, 1 if v1 gtr v2, 2 if v1 lss v2
|
||||
for /f "tokens=1,2,3 delims=." %%a in ("%~1") do (
|
||||
set a1=%%a
|
||||
set a2=%%b
|
||||
set a3=%%c
|
||||
)
|
||||
for /f "tokens=1,2,3 delims=." %%a in ("%~2") do (
|
||||
set b1=%%a
|
||||
set b2=%%b
|
||||
set b3=%%c
|
||||
)
|
||||
if not defined a1 set a1=0
|
||||
if not defined a2 set a2=0
|
||||
if not defined a3 set a3=0
|
||||
if not defined b1 set b1=0
|
||||
if not defined b2 set b2=0
|
||||
if not defined b3 set b3=0
|
||||
if %a1% gtr %b1% exit /b 1
|
||||
if %a1% lss %b1% exit /b 2
|
||||
if %a2% gtr %b2% exit /b 1
|
||||
if %a2% lss %b2% exit /b 2
|
||||
if %a3% gtr %b3% exit /b 1
|
||||
if %a3% lss %b3% exit /b 2
|
||||
exit /b 0
|
||||
|
||||
:askinstall
|
||||
cls
|
||||
echo ### ###
|
||||
echo # Python Not Found #
|
||||
echo ### ###
|
||||
echo.
|
||||
echo Python !targetpy! was not found on the system or in the PATH var.
|
||||
echo.
|
||||
set /p "menu=Would you like to install it now? [y/n]: "
|
||||
if /i "!menu!"=="y" (
|
||||
REM We got the OK - install it
|
||||
goto installpy
|
||||
) else if "!menu!"=="n" (
|
||||
REM No OK here...
|
||||
set /a tried=!tried!+1
|
||||
goto checkpy
|
||||
)
|
||||
REM Incorrect answer - go back
|
||||
goto askinstall
|
||||
|
||||
:installpy
|
||||
REM This will attempt to download and install python
|
||||
set /a tried=!tried!+1
|
||||
cls
|
||||
echo ### ###
|
||||
echo # Downloading Python #
|
||||
echo ### ###
|
||||
echo.
|
||||
set "release=!user_provided!"
|
||||
if "!release!" == "" (
|
||||
REM No explicit release set - get the latest from python.org
|
||||
echo Gathering latest version...
|
||||
powershell -command "[Net.ServicePointManager]::SecurityProtocol=[Net.SecurityProtocolType]::Tls12;(new-object System.Net.WebClient).DownloadFile('https://www.python.org/downloads/windows/','%TEMP%\pyurl.txt')"
|
||||
REM Extract it if it's gzip compressed
|
||||
powershell -command "$infile='%TEMP%\pyurl.txt';$outfile='%TEMP%\pyurl.temp';try{$input=New-Object System.IO.FileStream $infile,([IO.FileMode]::Open),([IO.FileAccess]::Read),([IO.FileShare]::Read);$output=New-Object System.IO.FileStream $outfile,([IO.FileMode]::Create),([IO.FileAccess]::Write),([IO.FileShare]::None);$gzipStream=New-Object System.IO.Compression.GzipStream $input,([IO.Compression.CompressionMode]::Decompress);$buffer=New-Object byte[](1024);while($true){$read=$gzipstream.Read($buffer,0,1024);if($read -le 0){break};$output.Write($buffer,0,$read)};$gzipStream.Close();$output.Close();$input.Close();Move-Item -Path $outfile -Destination $infile -Force}catch{}"
|
||||
if not exist "%TEMP%\pyurl.txt" (
|
||||
if /i "!just_installing!" == "TRUE" (
|
||||
echo - Failed to get info
|
||||
exit /b 1
|
||||
) else (
|
||||
goto checkpy
|
||||
)
|
||||
)
|
||||
pushd "%TEMP%"
|
||||
:: Version detection code slimmed by LussacZheng (https://github.com/corpnewt/gibMacOS/issues/20)
|
||||
for /f "tokens=9 delims=< " %%x in ('findstr /i /c:"Latest Python !targetpy! Release" pyurl.txt') do ( set "release=%%x" )
|
||||
popd
|
||||
REM Let's delete our txt file now - we no longer need it
|
||||
del "%TEMP%\pyurl.txt"
|
||||
if "!release!" == "" (
|
||||
if /i "!just_installing!" == "TRUE" (
|
||||
echo - Failed to get python version
|
||||
exit /b 1
|
||||
) else (
|
||||
goto checkpy
|
||||
)
|
||||
)
|
||||
echo Located Version: !release!
|
||||
) else (
|
||||
echo User-Provided Version: !release!
|
||||
REM Update our targetpy to reflect the first number of
|
||||
REM our release
|
||||
for /f "tokens=1 delims=." %%a in ("!release!") do (
|
||||
call :isnumber "%%a"
|
||||
if "!errorlevel!" == "0" (
|
||||
set "targetpy=%%a"
|
||||
)
|
||||
)
|
||||
)
|
||||
echo Building download url...
|
||||
REM At this point - we should have the version number.
|
||||
REM We can build the url like so: "https://www.python.org/ftp/python/[version]/python-[version]-amd64.exe"
|
||||
set "url=https://www.python.org/ftp/python/!release!/python-!release!-amd64.exe"
|
||||
set "pytype=exe"
|
||||
if "!targetpy!" == "2" (
|
||||
set "url=https://www.python.org/ftp/python/!release!/python-!release!.amd64.msi"
|
||||
set "pytype=msi"
|
||||
)
|
||||
echo - !url!
|
||||
echo Downloading...
|
||||
REM Now we download it with our slick powershell command
|
||||
powershell -command "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; (new-object System.Net.WebClient).DownloadFile('!url!','%TEMP%\pyinstall.!pytype!')"
|
||||
REM If it doesn't exist - we bail
|
||||
if not exist "%TEMP%\pyinstall.!pytype!" (
|
||||
if /i "!just_installing!" == "TRUE" (
|
||||
echo - Failed to download python installer
|
||||
exit /b 1
|
||||
) else (
|
||||
goto checkpy
|
||||
)
|
||||
)
|
||||
REM It should exist at this point - let's run it to install silently
|
||||
echo Running python !pytype! installer...
|
||||
pushd "%TEMP%"
|
||||
if /i "!pytype!" == "exe" (
|
||||
echo - pyinstall.exe /quiet PrependPath=1 Include_test=0 Shortcuts=0 Include_launcher=0
|
||||
pyinstall.exe /quiet PrependPath=1 Include_test=0 Shortcuts=0 Include_launcher=0
|
||||
) else (
|
||||
set "foldername=!release:.=!"
|
||||
echo - msiexec /i pyinstall.msi /qb ADDLOCAL=ALL TARGETDIR="%LocalAppData%\Programs\Python\Python!foldername:~0,2!"
|
||||
msiexec /i pyinstall.msi /qb ADDLOCAL=ALL TARGETDIR="%LocalAppData%\Programs\Python\Python!foldername:~0,2!"
|
||||
)
|
||||
popd
|
||||
set "py_error=!errorlevel!"
|
||||
echo Installer finished with status: !py_error!
|
||||
echo Cleaning up...
|
||||
REM Now we should be able to delete the installer and check for py again
|
||||
del "%TEMP%\pyinstall.!pytype!"
|
||||
REM If it worked, then we should have python in our PATH
|
||||
REM this does not get updated right away though - let's try
|
||||
REM manually updating the local PATH var
|
||||
call :updatepath
|
||||
if /i "!just_installing!" == "TRUE" (
|
||||
echo.
|
||||
echo Done.
|
||||
) else (
|
||||
goto checkpy
|
||||
)
|
||||
exit /b
|
||||
|
||||
:runscript
|
||||
REM Python found
|
||||
cls
|
||||
REM Checks the args gathered at the beginning of the script.
|
||||
REM Make sure we're not just forwarding empty quotes.
|
||||
set "arg_test=!args:"=!"
|
||||
if "!arg_test!"=="" (
|
||||
"!pypath!" "!thisDir!!script_name!"
|
||||
) else (
|
||||
"!pypath!" "!thisDir!!script_name!" !args!
|
||||
)
|
||||
if /i "!pause_on_error!" == "yes" (
|
||||
if not "%ERRORLEVEL%" == "0" (
|
||||
echo.
|
||||
echo Script exited with error code: %ERRORLEVEL%
|
||||
echo.
|
||||
echo Press [enter] to exit...
|
||||
pause > nul
|
||||
)
|
||||
)
|
||||
goto :EOF
|
||||
|
||||
:undouble <string_name> <string_value> <character>
|
||||
REM Helper function to strip doubles of a single character out of a string recursively
|
||||
set "string_value=%~2"
|
||||
:undouble_continue
|
||||
set "check=!string_value:%~3%~3=%~3!"
|
||||
if not "!check!" == "!string_value!" (
|
||||
set "string_value=!check!"
|
||||
goto :undouble_continue
|
||||
)
|
||||
set "%~1=!check!"
|
||||
goto :EOF
|
||||
|
||||
:updatepath
|
||||
set "spath="
|
||||
set "upath="
|
||||
for /f "USEBACKQ tokens=2* delims= " %%i in (`!syspath!reg.exe query "HKCU\Environment" /v "Path" 2^> nul`) do ( if not "%%j" == "" set "upath=%%j" )
|
||||
for /f "USEBACKQ tokens=2* delims= " %%i in (`!syspath!reg.exe query "HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment" /v "Path" 2^> nul`) do ( if not "%%j" == "" set "spath=%%j" )
|
||||
if not "%spath%" == "" (
|
||||
REM We got something in the system path
|
||||
set "PATH=%spath%"
|
||||
if not "%upath%" == "" (
|
||||
REM We also have something in the user path
|
||||
set "PATH=%PATH%;%upath%"
|
||||
)
|
||||
) else if not "%upath%" == "" (
|
||||
set "PATH=%upath%"
|
||||
)
|
||||
REM Remove double semicolons from the adjusted PATH
|
||||
call :undouble "PATH" "%PATH%" ";"
|
||||
goto :EOF
|
||||
|
||||
:getsyspath <variable_name>
|
||||
REM Helper method to return a valid path to cmd.exe, reg.exe, and where.exe by
|
||||
REM walking the ComSpec var - will also repair it in memory if need be
|
||||
REM Strip double semi-colons
|
||||
call :undouble "temppath" "%ComSpec%" ";"
|
||||
|
||||
REM Dirty hack to leverage the "line feed" approach - there are some odd side
|
||||
REM effects with this. Do not use this variable name in comments near this
|
||||
REM line - as it seems to behave erradically.
|
||||
(set LF=^
|
||||
%=this line is empty=%
|
||||
)
|
||||
REM Replace instances of semi-colons with a line feed and wrap
|
||||
REM in parenthesis to work around some strange batch behavior
|
||||
set "testpath=%temppath:;=!LF!%"
|
||||
|
||||
REM Let's walk each path and test if cmd.exe, reg.exe, and where.exe exist there
|
||||
set /a found=0
|
||||
for /f "tokens=* delims=" %%i in ("!testpath!") do (
|
||||
REM Only continue if we haven't found it yet
|
||||
if not "%%i" == "" (
|
||||
if !found! lss 1 (
|
||||
set "checkpath=%%i"
|
||||
REM Remove "cmd.exe" from the end if it exists
|
||||
if /i "!checkpath:~-7!" == "cmd.exe" (
|
||||
set "checkpath=!checkpath:~0,-7!"
|
||||
)
|
||||
REM Pad the end with a backslash if needed
|
||||
if not "!checkpath:~-1!" == "\" (
|
||||
set "checkpath=!checkpath!\"
|
||||
)
|
||||
REM Let's see if cmd, reg, and where exist there - and set it if so
|
||||
if EXIST "!checkpath!cmd.exe" (
|
||||
if EXIST "!checkpath!reg.exe" (
|
||||
if EXIST "!checkpath!where.exe" (
|
||||
set /a found=1
|
||||
set "ComSpec=!checkpath!cmd.exe"
|
||||
set "%~1=!checkpath!"
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
goto :EOF
|
||||
339
ACPI/SSDTTime-master/PatchMerge.command
Normal file
339
ACPI/SSDTTime-master/PatchMerge.command
Normal file
@@ -0,0 +1,339 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# Get the curent directory, the script name
|
||||
# and the script name with "py" substituted for the extension.
|
||||
args=( "$@" )
|
||||
dir="$(cd -- "$(dirname "$0")" >/dev/null 2>&1; pwd -P)"
|
||||
script="${0##*/}"
|
||||
target="${script%.*}.py"
|
||||
|
||||
# use_py3:
|
||||
# TRUE = Use if found, use py2 otherwise
|
||||
# FALSE = Use py2
|
||||
# FORCE = Use py3
|
||||
use_py3="TRUE"
|
||||
|
||||
# We'll parse if the first argument passed is
|
||||
# --install-python and if so, we'll just install
|
||||
# Can optionally take a version number as the
|
||||
# second arg - i.e. --install-python 3.13.1
|
||||
just_installing="FALSE"
|
||||
|
||||
tempdir=""
|
||||
|
||||
compare_to_version () {
|
||||
# Compares our OS version to the passed OS version, and
|
||||
# return a 1 if we match the passed compare type, or a 0 if we don't.
|
||||
# $1 = 0 (equal), 1 (greater), 2 (less), 3 (gequal), 4 (lequal)
|
||||
# $2 = OS version to compare ours to
|
||||
if [ -z "$1" ] || [ -z "$2" ]; then
|
||||
# Missing info - bail.
|
||||
return
|
||||
fi
|
||||
local current_os= comp=
|
||||
current_os="$(sw_vers -productVersion 2>/dev/null)"
|
||||
comp="$(vercomp "$current_os" "$2")"
|
||||
# Check gequal and lequal first
|
||||
if [[ "$1" == "3" && ("$comp" == "1" || "$comp" == "0") ]] || [[ "$1" == "4" && ("$comp" == "2" || "$comp" == "0") ]] || [[ "$comp" == "$1" ]]; then
|
||||
# Matched
|
||||
echo "1"
|
||||
else
|
||||
# No match
|
||||
echo "0"
|
||||
fi
|
||||
}
|
||||
|
||||
set_use_py3_if () {
|
||||
# Auto sets the "use_py3" variable based on
|
||||
# conditions passed
|
||||
# $1 = 0 (equal), 1 (greater), 2 (less), 3 (gequal), 4 (lequal)
|
||||
# $2 = OS version to compare
|
||||
# $3 = TRUE/FALSE/FORCE in case of match
|
||||
if [ -z "$1" ] || [ -z "$2" ] || [ -z "$3" ]; then
|
||||
# Missing vars - bail with no changes.
|
||||
return
|
||||
fi
|
||||
if [ "$(compare_to_version "$1" "$2")" == "1" ]; then
|
||||
use_py3="$3"
|
||||
fi
|
||||
}
|
||||
|
||||
get_remote_py_version () {
|
||||
local pyurl= py_html= py_vers= py_num="3"
|
||||
pyurl="https://www.python.org/downloads/macos/"
|
||||
py_html="$(curl -L $pyurl --compressed 2>&1)"
|
||||
if [ -z "$use_py3" ]; then
|
||||
use_py3="TRUE"
|
||||
fi
|
||||
if [ "$use_py3" == "FALSE" ]; then
|
||||
py_num="2"
|
||||
fi
|
||||
py_vers="$(echo "$py_html" | grep -i "Latest Python $py_num Release" | awk '{print $8}' | cut -d'<' -f1)"
|
||||
echo "$py_vers"
|
||||
}
|
||||
|
||||
download_py () {
|
||||
local vers="$1" url=
|
||||
clear
|
||||
echo " ### ###"
|
||||
echo " # Downloading Python #"
|
||||
echo "### ###"
|
||||
echo
|
||||
if [ -z "$vers" ]; then
|
||||
echo "Gathering latest version..."
|
||||
vers="$(get_remote_py_version)"
|
||||
if [ -z "$vers" ]; then
|
||||
if [ "$just_installing" == "TRUE" ]; then
|
||||
echo " - Failed to get info!"
|
||||
exit 1
|
||||
else
|
||||
# Didn't get it still - bail
|
||||
print_error
|
||||
fi
|
||||
fi
|
||||
echo "Located Version: $vers"
|
||||
else
|
||||
# Got a version passed
|
||||
echo "User-Provided Version: $vers"
|
||||
fi
|
||||
echo "Building download url..."
|
||||
url="$(curl -L https://www.python.org/downloads/release/python-${vers//./}/ --compressed 2>&1 | grep -iE "python-$vers-macos.*.pkg\"" | awk -F'"' '{ print $2 }' | head -n 1)"
|
||||
if [ -z "$url" ]; then
|
||||
if [ "$just_installing" == "TRUE" ]; then
|
||||
echo " - Failed to build download url!"
|
||||
exit 1
|
||||
else
|
||||
# Couldn't get the URL - bail
|
||||
print_error
|
||||
fi
|
||||
fi
|
||||
echo " - $url"
|
||||
echo "Downloading..."
|
||||
# Create a temp dir and download to it
|
||||
tempdir="$(mktemp -d 2>/dev/null || mktemp -d -t 'tempdir')"
|
||||
curl "$url" -o "$tempdir/python.pkg"
|
||||
if [ "$?" != "0" ]; then
|
||||
echo " - Failed to download python installer!"
|
||||
exit $?
|
||||
fi
|
||||
echo
|
||||
echo "Running python install package..."
|
||||
echo
|
||||
sudo installer -pkg "$tempdir/python.pkg" -target /
|
||||
echo
|
||||
if [ "$?" != "0" ]; then
|
||||
echo " - Failed to install python!"
|
||||
exit $?
|
||||
fi
|
||||
# Now we expand the package and look for a shell update script
|
||||
pkgutil --expand "$tempdir/python.pkg" "$tempdir/python"
|
||||
if [ -e "$tempdir/python/Python_Shell_Profile_Updater.pkg/Scripts/postinstall" ]; then
|
||||
# Run the script
|
||||
echo "Updating PATH..."
|
||||
echo
|
||||
"$tempdir/python/Python_Shell_Profile_Updater.pkg/Scripts/postinstall"
|
||||
echo
|
||||
fi
|
||||
vers_folder="Python $(echo "$vers" | cut -d'.' -f1 -f2)"
|
||||
if [ -f "/Applications/$vers_folder/Install Certificates.command" ]; then
|
||||
# Certs script exists - let's execute that to make sure our certificates are updated
|
||||
echo "Updating Certificates..."
|
||||
echo
|
||||
"/Applications/$vers_folder/Install Certificates.command"
|
||||
echo
|
||||
fi
|
||||
echo "Cleaning up..."
|
||||
cleanup
|
||||
if [ "$just_installing" == "TRUE" ]; then
|
||||
echo
|
||||
echo "Done."
|
||||
else
|
||||
# Now we check for py again
|
||||
downloaded="TRUE"
|
||||
clear
|
||||
main
|
||||
fi
|
||||
}
|
||||
|
||||
cleanup () {
|
||||
if [ -d "$tempdir" ]; then
|
||||
rm -Rf "$tempdir"
|
||||
fi
|
||||
}
|
||||
|
||||
print_error() {
|
||||
clear
|
||||
cleanup
|
||||
echo " ### ###"
|
||||
echo " # Python Not Found #"
|
||||
echo "### ###"
|
||||
echo
|
||||
echo "Python is not installed or not found in your PATH var."
|
||||
echo
|
||||
if [ "$kernel" == "Darwin" ]; then
|
||||
echo "Please go to https://www.python.org/downloads/macos/ to"
|
||||
echo "download and install the latest version, then try again."
|
||||
else
|
||||
echo "Please install python through your package manager and"
|
||||
echo "try again."
|
||||
fi
|
||||
echo
|
||||
exit 1
|
||||
}
|
||||
|
||||
print_target_missing() {
|
||||
clear
|
||||
cleanup
|
||||
echo " ### ###"
|
||||
echo " # Target Not Found #"
|
||||
echo "### ###"
|
||||
echo
|
||||
echo "Could not locate $target!"
|
||||
echo
|
||||
exit 1
|
||||
}
|
||||
|
||||
format_version () {
|
||||
local vers="$1"
|
||||
echo "$(echo "$1" | awk -F. '{ printf("%d%03d%03d%03d\n", $1,$2,$3,$4); }')"
|
||||
}
|
||||
|
||||
vercomp () {
|
||||
# Modified from: https://apple.stackexchange.com/a/123408/11374
|
||||
local ver1="$(format_version "$1")" ver2="$(format_version "$2")"
|
||||
if [ $ver1 -gt $ver2 ]; then
|
||||
echo "1"
|
||||
elif [ $ver1 -lt $ver2 ]; then
|
||||
echo "2"
|
||||
else
|
||||
echo "0"
|
||||
fi
|
||||
}
|
||||
|
||||
get_local_python_version() {
|
||||
# $1 = Python bin name (defaults to python3)
|
||||
# Echoes the path to the highest version of the passed python bin if any
|
||||
local py_name="$1" max_version= python= python_version= python_path=
|
||||
if [ -z "$py_name" ]; then
|
||||
py_name="python3"
|
||||
fi
|
||||
py_list="$(which -a "$py_name" 2>/dev/null)"
|
||||
# Walk that newline separated list
|
||||
while read python; do
|
||||
if [ -z "$python" ]; then
|
||||
# Got a blank line - skip
|
||||
continue
|
||||
fi
|
||||
if [ "$check_py3_stub" == "1" ] && [ "$python" == "/usr/bin/python3" ]; then
|
||||
# See if we have a valid developer path
|
||||
xcode-select -p > /dev/null 2>&1
|
||||
if [ "$?" != "0" ]; then
|
||||
# /usr/bin/python3 path - but no valid developer dir
|
||||
continue
|
||||
fi
|
||||
fi
|
||||
python_version="$(get_python_version $python)"
|
||||
if [ -z "$python_version" ]; then
|
||||
# Didn't find a py version - skip
|
||||
continue
|
||||
fi
|
||||
# Got the py version - compare to our max
|
||||
if [ -z "$max_version" ] || [ "$(vercomp "$python_version" "$max_version")" == "1" ]; then
|
||||
# Max not set, or less than the current - update it
|
||||
max_version="$python_version"
|
||||
python_path="$python"
|
||||
fi
|
||||
done <<< "$py_list"
|
||||
echo "$python_path"
|
||||
}
|
||||
|
||||
get_python_version() {
|
||||
local py_path="$1" py_version=
|
||||
# Get the python version by piping stderr into stdout (for py2), then grepping the output for
|
||||
# the word "python", getting the second element, and grepping for an alphanumeric version number
|
||||
py_version="$($py_path -V 2>&1 | grep -i python | cut -d' ' -f2 | grep -E "[A-Za-z\d\.]+")"
|
||||
if [ ! -z "$py_version" ]; then
|
||||
echo "$py_version"
|
||||
fi
|
||||
}
|
||||
|
||||
prompt_and_download() {
|
||||
if [ "$downloaded" != "FALSE" ] || [ "$kernel" != "Darwin" ]; then
|
||||
# We already tried to download, or we're not on macOS - just bail
|
||||
print_error
|
||||
fi
|
||||
clear
|
||||
echo " ### ###"
|
||||
echo " # Python Not Found #"
|
||||
echo "### ###"
|
||||
echo
|
||||
target_py="Python 3"
|
||||
printed_py="Python 2 or 3"
|
||||
if [ "$use_py3" == "FORCE" ]; then
|
||||
printed_py="Python 3"
|
||||
elif [ "$use_py3" == "FALSE" ]; then
|
||||
target_py="Python 2"
|
||||
printed_py="Python 2"
|
||||
fi
|
||||
echo "Could not locate $printed_py!"
|
||||
echo
|
||||
echo "This script requires $printed_py to run."
|
||||
echo
|
||||
while true; do
|
||||
read -p "Would you like to install the latest $target_py now? (y/n): " yn
|
||||
case $yn in
|
||||
[Yy]* ) download_py;break;;
|
||||
[Nn]* ) print_error;;
|
||||
esac
|
||||
done
|
||||
}
|
||||
|
||||
main() {
|
||||
local python= version=
|
||||
# Verify our target exists
|
||||
if [ ! -f "$dir/$target" ]; then
|
||||
# Doesn't exist
|
||||
print_target_missing
|
||||
fi
|
||||
if [ -z "$use_py3" ]; then
|
||||
use_py3="TRUE"
|
||||
fi
|
||||
if [ "$use_py3" != "FALSE" ]; then
|
||||
# Check for py3 first
|
||||
python="$(get_local_python_version python3)"
|
||||
fi
|
||||
if [ "$use_py3" != "FORCE" ] && [ -z "$python" ]; then
|
||||
# We aren't using py3 explicitly, and we don't already have a path
|
||||
python="$(get_local_python_version python2)"
|
||||
if [ -z "$python" ]; then
|
||||
# Try just looking for "python"
|
||||
python="$(get_local_python_version python)"
|
||||
fi
|
||||
fi
|
||||
if [ -z "$python" ]; then
|
||||
# Didn't ever find it - prompt
|
||||
prompt_and_download
|
||||
return 1
|
||||
fi
|
||||
# Found it - start our script and pass all args
|
||||
"$python" "$dir/$target" "${args[@]}"
|
||||
}
|
||||
|
||||
# Keep track of whether or not we're on macOS to determine if
|
||||
# we can download and install python for the user as needed.
|
||||
kernel="$(uname -s)"
|
||||
# Check to see if we need to force based on
|
||||
# macOS version. 10.15 has a dummy python3 version
|
||||
# that can trip up some py3 detection in other scripts.
|
||||
# set_use_py3_if "3" "10.15" "FORCE"
|
||||
downloaded="FALSE"
|
||||
# Check for the aforementioned /usr/bin/python3 stub if
|
||||
# our OS version is 10.15 or greater.
|
||||
check_py3_stub="$(compare_to_version "3" "10.15")"
|
||||
trap cleanup EXIT
|
||||
if [ "$1" == "--install-python" ] && [ "$kernel" == "Darwin" ]; then
|
||||
just_installing="TRUE"
|
||||
download_py "$2"
|
||||
else
|
||||
main
|
||||
fi
|
||||
586
ACPI/SSDTTime-master/PatchMerge.py
Normal file
586
ACPI/SSDTTime-master/PatchMerge.py
Normal file
@@ -0,0 +1,586 @@
|
||||
from Scripts import utils, plist
|
||||
import argparse, os
|
||||
|
||||
class PatchMerge:
|
||||
def __init__(self, config=None, results=None, overwrite=False, interactive=True):
|
||||
self.u = utils.Utils("Patch Merge")
|
||||
self.w = 80
|
||||
self.h = 24
|
||||
self.red = "\u001b[41;1m"
|
||||
self.yel = "\u001b[43;1m"
|
||||
self.grn = "\u001b[42;1m"
|
||||
self.blu = "\u001b[46;1m"
|
||||
self.rst = "\u001b[0m"
|
||||
self.copy_as_path = self.u.check_admin() if os.name=="nt" else False
|
||||
if 2/3==0:
|
||||
# ANSI escapes don't seem to work properly with python 2.x
|
||||
self.red = self.yel = self.grn = self.blu = self.rst = ""
|
||||
if os.name == "nt":
|
||||
if 2/3!=0:
|
||||
os.system("color") # Allow ANSI color escapes.
|
||||
self.w = 120
|
||||
self.h = 30
|
||||
self.interactive = interactive
|
||||
self.overwrite = overwrite
|
||||
self.target_patches = (
|
||||
("OpenCore","patches_OC.plist"),
|
||||
("Clover","patches_Clover.plist")
|
||||
)
|
||||
self.config_path = config
|
||||
self.config_type = None
|
||||
self.output = results or self.get_default_results_folder()
|
||||
# Expand paths as needed
|
||||
if self.config_path:
|
||||
self.config_path = os.path.realpath(self.config_path)
|
||||
self.config_type,_,_ = self.get_plist_info(self.config_path)
|
||||
if self.output:
|
||||
self.output = os.path.realpath(self.output)
|
||||
|
||||
def _get_patches_plists(self, path):
|
||||
# Append patches_OC/Clover.plist to the path, and return a list
|
||||
# with the format:
|
||||
# ((oc_path,exists,plist_name),(clover_path,exists,plist_name))
|
||||
path_checks = []
|
||||
for p_type,name in self.target_patches:
|
||||
if path:
|
||||
p = os.path.join(path,name)
|
||||
isfile = os.path.isfile(p)
|
||||
else:
|
||||
p = None
|
||||
isfile = False
|
||||
path_checks.append((
|
||||
p,
|
||||
isfile,
|
||||
name
|
||||
))
|
||||
return path_checks
|
||||
|
||||
def get_default_results_folder(self, prompt=False):
|
||||
# Let's attempt to locate a Results folder either in the same
|
||||
# directory as this script, or in the parent directory.
|
||||
# If none is found - we'll have to prompt the user as needed.
|
||||
#
|
||||
# Try our directory first
|
||||
local_path = os.path.dirname(os.path.realpath(__file__))
|
||||
local_results = os.path.join(local_path,"Results")
|
||||
parent_results = os.path.realpath(os.path.join(local_path,"..","Results"))
|
||||
potentials = []
|
||||
for path in (local_results,parent_results):
|
||||
if os.path.isdir(path):
|
||||
# Check if we have the files we need
|
||||
o,c = self._get_patches_plists(path)
|
||||
if o[1] or c[1]:
|
||||
potentials.append(path)
|
||||
if potentials:
|
||||
return potentials[0]
|
||||
# If we got here - we didn't find anything - check if we need
|
||||
# to prompt
|
||||
if not prompt:
|
||||
# Nope - bail
|
||||
return None
|
||||
# We're prompting
|
||||
return self.select_results_folder()
|
||||
|
||||
def select_results_folder(self):
|
||||
while True:
|
||||
self.u.head("Select Results Folder")
|
||||
print("")
|
||||
if self.copy_as_path:
|
||||
print("NOTE: Currently running as admin on Windows - drag and drop may not work.")
|
||||
print(" Shift + right-click in Explorer and select 'Copy as path' then paste here instead.")
|
||||
print("")
|
||||
print("M. Main Menu")
|
||||
print("Q. Quit")
|
||||
print("")
|
||||
print("NOTE: This is the folder containing the patches_OC.plist and")
|
||||
print(" patches_Clover.plist you are trying to merge. It will also be where")
|
||||
print(" the patched config.plist is saved.")
|
||||
print("")
|
||||
path = self.u.grab("Please drag and drop the Results folder here: ")
|
||||
if not path:
|
||||
continue
|
||||
if path.lower() == "m":
|
||||
return self.output
|
||||
elif path.lower() == "q":
|
||||
self.u.custom_quit()
|
||||
test_path = self.u.check_path(path)
|
||||
if os.path.isfile(test_path):
|
||||
# Got a file - get the containing folder
|
||||
test_path = os.path.dirname(test_path)
|
||||
if not test_path:
|
||||
self.u.head("Invalid Path")
|
||||
print("")
|
||||
print("That path either does not exist, or is not a folder.")
|
||||
print("")
|
||||
self.u.grab("Press [enter] to return...")
|
||||
continue
|
||||
# Got a folder - check for patches_OC/Clover.plist
|
||||
o,c = self._get_patches_plists(test_path)
|
||||
if not (o[1] or c[1]):
|
||||
# No patches plists in there
|
||||
self.u.head("Missing Files")
|
||||
print("")
|
||||
print("Neither patches_OC.plist nor patches_Clover.plist were found at that path.")
|
||||
print("")
|
||||
self.u.grab("Press [enter] to return...")
|
||||
continue
|
||||
# We got what we need - set and return the path
|
||||
self.output = test_path
|
||||
return self.output
|
||||
|
||||
def get_ascii_print(self, data):
|
||||
# Helper to sanitize unprintable characters by replacing them with
|
||||
# ? where needed
|
||||
unprintables = False
|
||||
all_zeroes = True
|
||||
ascii_string = ""
|
||||
for b in data:
|
||||
if not isinstance(b,int):
|
||||
try: b = ord(b)
|
||||
except: pass
|
||||
if b != 0:
|
||||
# Not wildcard matching
|
||||
all_zeroes = False
|
||||
if ord(" ") <= b < ord("~"):
|
||||
ascii_string += chr(b)
|
||||
else:
|
||||
ascii_string += "?"
|
||||
unprintables = True
|
||||
return (False if all_zeroes else unprintables,ascii_string)
|
||||
|
||||
def check_normalize(self, patch_or_drop, normalize_headers, check_type="Patch"):
|
||||
sig = ("OemTableId","TableSignature")
|
||||
if normalize_headers:
|
||||
# OpenCore - and NormalizeHeaders is enabled. Check if we have
|
||||
# any unprintable ASCII chars in our OemTableId or TableSignature
|
||||
# and warn.
|
||||
if any(self.get_ascii_print(plist.extract_data(patch_or_drop.get(x,b"\x00")))[0] for x in sig):
|
||||
print("\n{}!! WARNING !!{} NormalizeHeaders is {}ENABLED{}, and table ids contain unprintable".format(
|
||||
self.yel,
|
||||
self.rst,
|
||||
self.grn,
|
||||
self.rst
|
||||
))
|
||||
print(" characters! {} may not match or apply!\n".format(check_type))
|
||||
return True
|
||||
else:
|
||||
# Not enabled - check for question marks as that may imply characters
|
||||
# were sanitized when creating the patches/dropping tables.
|
||||
if any(b"\x3F" in plist.extract_data(patch_or_drop.get(x,b"\x00")) for x in sig):
|
||||
print("\n{}!! WARNING !!{} NormalizeHeaders is {}DISABLED{}, and table ids contain '?'!".format(
|
||||
self.yel,
|
||||
self.rst,
|
||||
self.red,
|
||||
self.rst
|
||||
))
|
||||
print(" {} may not match or apply!\n".format(check_type))
|
||||
return True
|
||||
return False
|
||||
|
||||
def ensure_path(self, plist_data, path_list, final_type = list):
|
||||
if not path_list:
|
||||
return plist_data
|
||||
if not isinstance(plist_data,dict):
|
||||
plist_data = {} # Override it with a dict
|
||||
# Set our initial reference, then iterate the
|
||||
# path list
|
||||
last = plist_data
|
||||
for i,path in enumerate(path_list,start=1):
|
||||
# Check if our next path var is in last
|
||||
if not path in last:
|
||||
last[path] = {} if i < len(path_list) else final_type()
|
||||
# Make sure it's the correct type if we're at the
|
||||
# end of the entries
|
||||
if i >= len(path_list) and not isinstance(last[path],final_type):
|
||||
# Override it
|
||||
last[path] = final_type()
|
||||
# Update our reference
|
||||
last = last[path]
|
||||
return plist_data
|
||||
|
||||
def get_unique_name(self,name,target_folder,name_append=""):
|
||||
# Get a new file name in the target folder so we don't override the original
|
||||
name = os.path.basename(name)
|
||||
ext = "" if not "." in name else name.split(".")[-1]
|
||||
if ext: name = name[:-len(ext)-1]
|
||||
if name_append: name = name+str(name_append)
|
||||
check_name = ".".join((name,ext)) if ext else name
|
||||
if not os.path.exists(os.path.join(target_folder,check_name)):
|
||||
return check_name
|
||||
# We need a unique name
|
||||
num = 1
|
||||
while True:
|
||||
check_name = "{}-{}".format(name,num)
|
||||
if ext: check_name += "."+ext
|
||||
if not os.path.exists(os.path.join(target_folder,check_name)):
|
||||
return check_name
|
||||
num += 1 # Increment our counter
|
||||
|
||||
def pause_interactive(self, return_value=None):
|
||||
if self.interactive:
|
||||
print("")
|
||||
self.u.grab("Press [enter] to return...")
|
||||
return return_value
|
||||
|
||||
def patch_plist(self):
|
||||
# Retain the config name
|
||||
if self.interactive:
|
||||
self.u.head("Patching Plist")
|
||||
print("")
|
||||
# Make sure we have a config_path
|
||||
if not self.config_path:
|
||||
print("No target plist path specified!")
|
||||
return self.pause_interactive()
|
||||
# Make sure that config_path exists
|
||||
if not os.path.isfile(self.config_path):
|
||||
print("Could not locate target plist at:")
|
||||
print(" - {}".format(self.config_path))
|
||||
return self.pause_interactive()
|
||||
# Make sure our output var has a value
|
||||
if not self.output:
|
||||
print("No Results folder path specified!")
|
||||
return self.pause_interactive()
|
||||
config_name = os.path.basename(self.config_path)
|
||||
print("Loading {}...".format(config_name))
|
||||
self.config_type,config_data,e = self.get_plist_info(self.config_path)
|
||||
if e:
|
||||
print(" - Failed to load! {}".format(e))
|
||||
return self.pause_interactive()
|
||||
# Recheck the config.plist type
|
||||
if not self.config_type:
|
||||
print("Could not determine plist type!")
|
||||
return self.pause_interactive()
|
||||
# Ensure our patches plists exist, and break out info
|
||||
# into the target_path and target_name as needed
|
||||
target_path,_,target_name = self.get_patch_plist_for_type(
|
||||
self.output,
|
||||
self.config_type
|
||||
)
|
||||
# This should only show up if output is None/False/empty
|
||||
if not target_path:
|
||||
print("Could not locate {} in:".format(target_name or "the required patches plist"))
|
||||
print(" - {}".format(self.output))
|
||||
return self.pause_interactive()
|
||||
# Make sure the path actually exists - and is a file
|
||||
if not os.path.isfile(target_path):
|
||||
print("Could not locate required patches at:")
|
||||
print(" - {}".format(target_path))
|
||||
return self.pause_interactive()
|
||||
# Set up some preliminary variables for reporting later
|
||||
errors_found = normalize_headers = False # Default to off
|
||||
target_name = os.path.basename(target_path)
|
||||
print("Loading {}...".format(target_name))
|
||||
# Load the target plist
|
||||
_,target_data,e = self.get_plist_info(target_path)
|
||||
if e:
|
||||
print(" - Failed to load! {}".format(e))
|
||||
return self.pause_interactive()
|
||||
print("Ensuring paths in {} and {}...".format(config_name,target_name))
|
||||
# Make sure all the needed values are there
|
||||
if self.config_type == "OpenCore":
|
||||
for p in (("ACPI","Add"),("ACPI","Delete"),("ACPI","Patch")):
|
||||
print(" - {}...".format(" -> ".join(p)))
|
||||
config_data = self.ensure_path(config_data,p)
|
||||
target_data = self.ensure_path(target_data,p)
|
||||
print(" - ACPI -> Quirks...")
|
||||
config_data = self.ensure_path(config_data,("ACPI","Quirks"),final_type=dict)
|
||||
normalize_headers = config_data["ACPI"]["Quirks"].get("NormalizeHeaders",False)
|
||||
if not isinstance(normalize_headers,(bool)):
|
||||
errors_found = True
|
||||
print("\n{}!! WARNING !!{} ACPI -> Quirks -> NormalizeHeaders is malformed - assuming False".format(
|
||||
self.yel,
|
||||
self.rst
|
||||
))
|
||||
normalize_headers = False
|
||||
# Set up our patch sources
|
||||
ssdts = target_data["ACPI"]["Add"]
|
||||
patch = target_data["ACPI"]["Patch"]
|
||||
drops = target_data["ACPI"]["Delete"]
|
||||
# Set up our original values
|
||||
s_orig = config_data["ACPI"]["Add"]
|
||||
p_orig = config_data["ACPI"]["Patch"]
|
||||
d_orig = config_data["ACPI"]["Delete"]
|
||||
else:
|
||||
for p in (("ACPI","DropTables"),("ACPI","SortedOrder"),("ACPI","DSDT","Patches")):
|
||||
print(" - {}...".format(" -> ".join(p)))
|
||||
config_data = self.ensure_path(config_data,p)
|
||||
target_data = self.ensure_path(target_data,p)
|
||||
# Set up our patch sources
|
||||
ssdts = target_data["ACPI"]["SortedOrder"]
|
||||
patch = target_data["ACPI"]["DSDT"]["Patches"]
|
||||
drops = target_data["ACPI"]["DropTables"]
|
||||
# Set up our original values
|
||||
s_orig = config_data["ACPI"]["SortedOrder"]
|
||||
p_orig = config_data["ACPI"]["DSDT"]["Patches"]
|
||||
d_orig = config_data["ACPI"]["DropTables"]
|
||||
print("")
|
||||
if not ssdts:
|
||||
print("--- No SSDTs to add - skipping...")
|
||||
else:
|
||||
print("--- Walking target SSDTs ({:,} total)...".format(len(ssdts)))
|
||||
s_rem = []
|
||||
# Gather any entries broken from user error
|
||||
s_broken = [x for x in s_orig if not isinstance(x,dict)] if self.config_type == "OpenCore" else []
|
||||
for s in ssdts:
|
||||
if self.config_type == "OpenCore":
|
||||
print(" - Checking {}...".format(s["Path"]))
|
||||
existing = [x for x in s_orig if isinstance(x,dict) and x["Path"] == s["Path"]]
|
||||
else:
|
||||
print(" - Checking {}...".format(s))
|
||||
existing = [x for x in s_orig if x == s]
|
||||
if existing:
|
||||
print(" --> Located {:,} existing to replace...".format(len(existing)))
|
||||
s_rem.extend(existing)
|
||||
if s_rem:
|
||||
print(" - Removing {:,} existing duplicate{}...".format(len(s_rem),"" if len(s_rem)==1 else "s"))
|
||||
for r in s_rem:
|
||||
if r in s_orig: s_orig.remove(r)
|
||||
else:
|
||||
print(" - No duplicates to remove...")
|
||||
print(" - Adding {:,} SSDT{}...".format(len(ssdts),"" if len(ssdts)==1 else "s"))
|
||||
s_orig.extend(ssdts)
|
||||
if s_broken:
|
||||
errors_found = True
|
||||
print("\n{}!! WARNING !!{} {:,} Malformed entr{} found - please fix your {}!".format(
|
||||
self.yel,
|
||||
self.rst,
|
||||
len(s_broken),
|
||||
"y" if len(d_broken)==1 else "ies",
|
||||
config_name
|
||||
))
|
||||
print("")
|
||||
if not patch:
|
||||
print("--- No patches to add - skipping...")
|
||||
else:
|
||||
print("--- Walking target patches ({:,} total)...".format(len(patch)))
|
||||
p_rem = []
|
||||
# Gather any entries broken from user error
|
||||
p_broken = [x for x in p_orig if not isinstance(x,dict)]
|
||||
for p in patch:
|
||||
print(" - Checking {}...".format(p["Comment"]))
|
||||
if self.config_type == "OpenCore" and self.check_normalize(p,normalize_headers):
|
||||
errors_found = True
|
||||
existing = [x for x in p_orig if isinstance(x,dict) and x["Find"] == p["Find"] and x["Replace"] == p["Replace"]]
|
||||
if existing:
|
||||
print(" --> Located {:,} existing to replace...".format(len(existing)))
|
||||
p_rem.extend(existing)
|
||||
# Remove any dupes
|
||||
if p_rem:
|
||||
print(" - Removing {:,} existing duplicate{}...".format(len(p_rem),"" if len(p_rem)==1 else "s"))
|
||||
for r in p_rem:
|
||||
if r in p_orig: p_orig.remove(r)
|
||||
else:
|
||||
print(" - No duplicates to remove...")
|
||||
print(" - Adding {:,} patch{}...".format(len(patch),"" if len(patch)==1 else "es"))
|
||||
p_orig.extend(patch)
|
||||
if p_broken:
|
||||
errors_found = True
|
||||
print("\n{}!! WARNING !!{} {:,} Malformed entr{} found - please fix your {}!".format(
|
||||
self.yel,
|
||||
self.rst,
|
||||
len(p_broken),
|
||||
"y" if len(d_broken)==1 else "ies",
|
||||
config_name
|
||||
))
|
||||
print("")
|
||||
if not drops:
|
||||
print("--- No tables to drop - skipping...")
|
||||
else:
|
||||
print("--- Walking target tables to drop ({:,} total)...".format(len(drops)))
|
||||
d_rem = []
|
||||
# Gather any entries broken from user error
|
||||
d_broken = [x for x in d_orig if not isinstance(x,dict)]
|
||||
for d in drops:
|
||||
if self.config_type == "OpenCore":
|
||||
print(" - Checking {}...".format(d["Comment"]))
|
||||
if self.check_normalize(d,normalize_headers,check_type="Dropped table"):
|
||||
errors_found = True
|
||||
existing = [x for x in d_orig if isinstance(x,dict) and x["TableSignature"] == d["TableSignature"] and x["OemTableId"] == d["OemTableId"]]
|
||||
else:
|
||||
name = " - ".join([x for x in (d.get("Signature",""),d.get("TableId","")) if x]) or "Unknown Dropped Table"
|
||||
print(" - Checking {}...".format(name))
|
||||
existing = [x for x in d_orig if isinstance(x,dict) and x.get("Signature") == d.get("Signature") and x.get("TableId") == d.get("TableId")]
|
||||
if existing:
|
||||
print(" --> Located {:,} existing to replace...".format(len(existing)))
|
||||
d_rem.extend(existing)
|
||||
if d_rem:
|
||||
print(" - Removing {:,} existing duplicate{}...".format(len(d_rem),"" if len(d_rem)==1 else "s"))
|
||||
for r in d_rem:
|
||||
if r in d_orig: d_orig.remove(r)
|
||||
else:
|
||||
print(" - No duplicates to remove...")
|
||||
print(" - Dropping {:,} table{}...".format(len(drops),"" if len(drops)==1 else "s"))
|
||||
d_orig.extend(drops)
|
||||
if d_broken:
|
||||
errors_found = True
|
||||
print("\n{}!! WARNING !!{} {:,} Malformed entr{} found - please fix your {}!".format(
|
||||
self.yel,
|
||||
self.rst,
|
||||
len(d_broken),
|
||||
"y" if len(d_broken)==1 else "ies",
|
||||
config_name
|
||||
))
|
||||
print("")
|
||||
if self.overwrite:
|
||||
output_path = self.config_path
|
||||
else:
|
||||
config_name = self.get_unique_name(config_name,self.output)
|
||||
output_path = os.path.join(self.output,config_name)
|
||||
print("Saving to {}...".format(output_path))
|
||||
try:
|
||||
plist.dump(config_data,open(output_path,"wb"))
|
||||
except Exception as e:
|
||||
print(" - Failed to save! {}".format(e))
|
||||
return self.pause_interactive()
|
||||
print(" - Saved.")
|
||||
print("")
|
||||
if errors_found:
|
||||
print("{}!! WARNING !!{} Potential errors were found when merging - please address them!".format(
|
||||
self.yel,
|
||||
self.rst
|
||||
))
|
||||
print("")
|
||||
if not self.overwrite:
|
||||
print("{}!! WARNING !!{} Make sure you review the saved {} before replacing!".format(
|
||||
self.red,
|
||||
self.rst,
|
||||
config_name
|
||||
))
|
||||
print("")
|
||||
print("Done.")
|
||||
return self.pause_interactive()
|
||||
|
||||
def get_plist_info(self, config_path):
|
||||
# Attempts to load the passed config and return a tuple
|
||||
# of (type_string,config_data,error)
|
||||
type_string = config_data = e = None
|
||||
try:
|
||||
config_data = plist.load(open(config_path,"rb"))
|
||||
except Exception as e:
|
||||
return (None,None,e)
|
||||
if not isinstance(config_data,dict):
|
||||
e = "Invalid root node type: {}".format(type(config_data))
|
||||
else:
|
||||
type_string = "OpenCore" if "PlatformInfo" in config_data else "Clover" if "SMBIOS" in config_data else None
|
||||
return (type_string,config_data,None)
|
||||
|
||||
def get_patch_plist_for_type(self, path, config_type):
|
||||
o,c = self._get_patches_plists(path)
|
||||
return {
|
||||
"OpenCore":o,
|
||||
"Clover":c
|
||||
}.get(config_type,(None,False,None))
|
||||
|
||||
def select_plist(self):
|
||||
while True:
|
||||
self.u.head("Select Plist")
|
||||
print("")
|
||||
if self.copy_as_path:
|
||||
print("NOTE: Currently running as admin on Windows - drag and drop may not work.")
|
||||
print(" Shift + right-click in Explorer and select 'Copy as path' then paste here instead.")
|
||||
print("")
|
||||
print("M. Main Menu")
|
||||
print("Q. Quit")
|
||||
print("")
|
||||
path = self.u.grab("Please drag and drop the config.plist here: ")
|
||||
if not path: continue
|
||||
if path.lower() == "m": return
|
||||
elif path.lower() == "q": self.u.custom_quit()
|
||||
test_path = self.u.check_path(path)
|
||||
if not test_path or not os.path.isfile(test_path):
|
||||
self.u.head("Invalid Path")
|
||||
print("")
|
||||
print("That path either does not exist, or is not a file.")
|
||||
print("")
|
||||
self.u.grab("Press [enter] to return...")
|
||||
continue
|
||||
# Got a file - try to load it
|
||||
t,_,e = self.get_plist_info(test_path)
|
||||
if e:
|
||||
self.u.head("Invalid File")
|
||||
print("")
|
||||
print("That file failed to load:\n\n{}".format(e))
|
||||
print("")
|
||||
self.u.grab("Press [enter] to return...")
|
||||
continue
|
||||
# Got a valid file
|
||||
self.config_path = test_path
|
||||
self.config_type = t
|
||||
return
|
||||
|
||||
def main(self):
|
||||
# Gather some preliminary info for display
|
||||
target_path,target_exists,target_name = self.get_patch_plist_for_type(
|
||||
self.output,
|
||||
self.config_type
|
||||
)
|
||||
self.u.resize(self.w,self.h)
|
||||
self.u.head()
|
||||
print("")
|
||||
print("Current config.plist: {}".format(self.config_path))
|
||||
print("Type of config.plist: {}".format(self.config_type or "Unknown"))
|
||||
print("Results Folder: {}".format(self.output))
|
||||
print("Patches Plist: {}{}".format(
|
||||
target_name or "Unknown",
|
||||
"" if (not target_name or target_exists) else " - {}!! MISSING !!{}".format(self.red,self.rst)
|
||||
))
|
||||
print("Overwrite Original: {}{}{}{}".format(
|
||||
self.red if self.overwrite else self.grn,
|
||||
"!! True !!" if self.overwrite else "False",
|
||||
self.rst,
|
||||
" - Make Sure You Have A Backup!" if self.overwrite else ""
|
||||
))
|
||||
print("")
|
||||
print("C. Select config.plist")
|
||||
print("O. Toggle Overwrite Original")
|
||||
print("R. Select Results Folder")
|
||||
if self.config_path and target_exists:
|
||||
print("P. Patch with {}".format(target_name))
|
||||
print("")
|
||||
print("Q. Quit")
|
||||
print("")
|
||||
menu = self.u.grab("Please make a selection: ")
|
||||
if not len(menu):
|
||||
return
|
||||
if menu.lower() == "q":
|
||||
self.u.custom_quit()
|
||||
elif menu.lower() == "c":
|
||||
self.select_plist()
|
||||
elif menu.lower() == "o":
|
||||
self.overwrite ^= True
|
||||
elif menu.lower() == "r":
|
||||
self.select_results_folder()
|
||||
elif menu.lower() == "p" and self.config_path and target_exists:
|
||||
self.patch_plist()
|
||||
|
||||
if __name__ == '__main__':
|
||||
# Setup the cli args
|
||||
parser = argparse.ArgumentParser(prog="PatchMerge.py", description="PatchMerge - py script to merge patches_[OC/Clover].plist with a config.plist.")
|
||||
parser.add_argument("-c", "--config", help="path to target config.plist - required if running in non-interactive mode")
|
||||
parser.add_argument("-r", "--results", help="path to Results folder containing patches_[OC/Clover].plist - required if running in non-interactive mode")
|
||||
parser.add_argument("-o", "--overwrite", help="overwrite the original config.plist", action="store_true")
|
||||
parser.add_argument("-i", "--no-interaction", help="run in non-interactive mode - requires -c and -r", action="store_true")
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
p = PatchMerge(
|
||||
config=args.config,
|
||||
results=args.results,
|
||||
overwrite=args.overwrite,
|
||||
interactive=not args.no_interaction
|
||||
)
|
||||
|
||||
if args.no_interaction:
|
||||
# We're in non-interactive mode here
|
||||
p.patch_plist()
|
||||
else:
|
||||
# Interactive mode
|
||||
if 2/3 == 0:
|
||||
input = raw_input
|
||||
while True:
|
||||
try:
|
||||
p.main()
|
||||
except Exception as e:
|
||||
print("An error occurred: {}".format(e))
|
||||
print("")
|
||||
input("Press [enter] to continue...")
|
||||
47
ACPI/SSDTTime-master/README.md
Normal file
47
ACPI/SSDTTime-master/README.md
Normal file
@@ -0,0 +1,47 @@
|
||||
SSDTTime
|
||||
==========
|
||||
A simple tool designed to make creating SSDTs simple.
|
||||
Supports macOS, Linux and Windows
|
||||
|
||||
## Supported SSDTs:
|
||||
- SSDT-HPET
|
||||
- Patches out IRQ conflicts
|
||||
- SSDT-EC
|
||||
- OS-aware fake EC (laptop and desktop variants)
|
||||
- SSDT-USBX
|
||||
- Provides generic USB power properties
|
||||
- SSDT-PLUG
|
||||
- Sets plugin-type = 1 on CPU0/PR00
|
||||
- SSDT-PMC
|
||||
- Adds missing PMCR device for native 300-series NVRAM
|
||||
- SSDT-AWAC
|
||||
- Disables AWAC clock, and enables (or fakes) RTC as needed
|
||||
- SSDT-USB-Reset
|
||||
- Returns a zero status for detected root hubs to allow hardware querying
|
||||
- SSDT-Bridge
|
||||
- Create missing PCI bridges for passed device path
|
||||
- SSDT-PNLF
|
||||
- Sets up a PNLF device for laptop backlight control
|
||||
- SSDT-XOSI
|
||||
- _OSI rename and patch to return true for a range of Windows versions - also checks for OSID
|
||||
- DMAR
|
||||
- Remove Reserved Memory Regions from the DMAR table
|
||||
- SSDT-SBUS-MCHC
|
||||
- Defines an MCHC and BUS0 device for SMBus compatibility
|
||||
- IMEI Bridge
|
||||
- Defines IMEI - only needed on SNB + 7-series or IVB + 6-series
|
||||
|
||||
Additionally on Linux and Windows the tool can be used to dump the system DSDT.
|
||||
|
||||
## Instructions:
|
||||
### Linux:
|
||||
* Launch SSDTTime.py with any somewhat recent version of Python from either a terminal window or by running the file normally.
|
||||
### macOS:
|
||||
* Launch SSDTTime.command from either a terminal window or by double clicking the file.
|
||||
### Windows:
|
||||
* Launch SSDTTime.bat from either a terminal window or by double clicking the file.
|
||||
|
||||
## Credits:
|
||||
- [CorpNewt](https://github.com/CorpNewt) - Writing the script and libraries used
|
||||
- [NoOne](https://github.com/IOIIIO) - Some small improvements to the script
|
||||
- Rehabman/Intel - iasl
|
||||
426
ACPI/SSDTTime-master/SSDTTime.bat
Normal file
426
ACPI/SSDTTime-master/SSDTTime.bat
Normal file
@@ -0,0 +1,426 @@
|
||||
@echo off
|
||||
REM Get our local path and args before delayed expansion - allows % and !
|
||||
set "thisDir=%~dp0"
|
||||
set "args=%*"
|
||||
|
||||
setlocal enableDelayedExpansion
|
||||
REM Setup initial vars
|
||||
set "script_name="
|
||||
set /a tried=0
|
||||
set "toask=yes"
|
||||
set "pause_on_error=yes"
|
||||
set "py2v="
|
||||
set "py2path="
|
||||
set "py3v="
|
||||
set "py3path="
|
||||
set "pypath="
|
||||
set "targetpy=3"
|
||||
|
||||
REM use_py3:
|
||||
REM TRUE = Use if found, use py2 otherwise
|
||||
REM FALSE = Use py2
|
||||
REM FORCE = Use py3
|
||||
set "use_py3=TRUE"
|
||||
|
||||
REM We'll parse if the first argument passed is
|
||||
REM --install-python and if so, we'll just install
|
||||
REM Can optionally take a version number as the
|
||||
REM second arg - i.e. --install-python 3.13.1
|
||||
set "just_installing=FALSE"
|
||||
set "user_provided="
|
||||
|
||||
REM Get the system32 (or equivalent) path
|
||||
call :getsyspath "syspath"
|
||||
|
||||
REM Make sure the syspath exists
|
||||
if "!syspath!" == "" (
|
||||
if exist "%SYSTEMROOT%\system32\cmd.exe" (
|
||||
if exist "%SYSTEMROOT%\system32\reg.exe" (
|
||||
if exist "%SYSTEMROOT%\system32\where.exe" (
|
||||
REM Fall back on the default path if it exists
|
||||
set "ComSpec=%SYSTEMROOT%\system32\cmd.exe"
|
||||
set "syspath=%SYSTEMROOT%\system32\"
|
||||
)
|
||||
)
|
||||
)
|
||||
if "!syspath!" == "" (
|
||||
cls
|
||||
echo ### ###
|
||||
echo # Missing Required Files #
|
||||
echo ### ###
|
||||
echo.
|
||||
echo Could not locate cmd.exe, reg.exe, or where.exe
|
||||
echo.
|
||||
echo Please ensure your ComSpec environment variable is properly configured and
|
||||
echo points directly to cmd.exe, then try again.
|
||||
echo.
|
||||
echo Current CompSpec Value: "%ComSpec%"
|
||||
echo.
|
||||
echo Press [enter] to quit.
|
||||
pause > nul
|
||||
exit /b 1
|
||||
)
|
||||
)
|
||||
|
||||
if "%~1" == "--install-python" (
|
||||
set "just_installing=TRUE"
|
||||
set "user_provided=%~2"
|
||||
goto installpy
|
||||
)
|
||||
|
||||
goto checkscript
|
||||
|
||||
:checkscript
|
||||
REM Check for our script first
|
||||
set "looking_for=!script_name!"
|
||||
if "!script_name!" == "" (
|
||||
set "looking_for=%~n0.py or %~n0.command"
|
||||
set "script_name=%~n0.py"
|
||||
if not exist "!thisDir!\!script_name!" (
|
||||
set "script_name=%~n0.command"
|
||||
)
|
||||
)
|
||||
if not exist "!thisDir!\!script_name!" (
|
||||
cls
|
||||
echo ### ###
|
||||
echo # Target Not Found #
|
||||
echo ### ###
|
||||
echo.
|
||||
echo Could not find !looking_for!.
|
||||
echo Please make sure to run this script from the same directory
|
||||
echo as !looking_for!.
|
||||
echo.
|
||||
echo Press [enter] to quit.
|
||||
pause > nul
|
||||
exit /b 1
|
||||
)
|
||||
goto checkpy
|
||||
|
||||
:checkpy
|
||||
call :updatepath
|
||||
for /f "USEBACKQ tokens=*" %%x in (`!syspath!where.exe python 2^> nul`) do ( call :checkpyversion "%%x" "py2v" "py2path" "py3v" "py3path" )
|
||||
for /f "USEBACKQ tokens=*" %%x in (`!syspath!where.exe python3 2^> nul`) do ( call :checkpyversion "%%x" "py2v" "py2path" "py3v" "py3path" )
|
||||
for /f "USEBACKQ tokens=*" %%x in (`!syspath!where.exe py 2^> nul`) do ( call :checkpylauncher "%%x" "py2v" "py2path" "py3v" "py3path" )
|
||||
REM Walk our returns to see if we need to install
|
||||
if /i "!use_py3!" == "FALSE" (
|
||||
set "targetpy=2"
|
||||
set "pypath=!py2path!"
|
||||
) else if /i "!use_py3!" == "FORCE" (
|
||||
set "pypath=!py3path!"
|
||||
) else if /i "!use_py3!" == "TRUE" (
|
||||
set "pypath=!py3path!"
|
||||
if "!pypath!" == "" set "pypath=!py2path!"
|
||||
)
|
||||
if not "!pypath!" == "" (
|
||||
goto runscript
|
||||
)
|
||||
if !tried! lss 1 (
|
||||
if /i "!toask!"=="yes" (
|
||||
REM Better ask permission first
|
||||
goto askinstall
|
||||
) else (
|
||||
goto installpy
|
||||
)
|
||||
) else (
|
||||
cls
|
||||
echo ### ###
|
||||
echo # Python Not Found #
|
||||
echo ### ###
|
||||
echo.
|
||||
REM Couldn't install for whatever reason - give the error message
|
||||
echo Python is not installed or not found in your PATH var.
|
||||
echo Please go to https://www.python.org/downloads/windows/ to
|
||||
echo download and install the latest version, then try again.
|
||||
echo.
|
||||
echo Make sure you check the box labeled:
|
||||
echo.
|
||||
echo "Add Python X.X to PATH"
|
||||
echo.
|
||||
echo Where X.X is the py version you're installing.
|
||||
echo.
|
||||
echo Press [enter] to quit.
|
||||
pause > nul
|
||||
exit /b 1
|
||||
)
|
||||
goto runscript
|
||||
|
||||
:checkpylauncher <path> <py2v> <py2path> <py3v> <py3path>
|
||||
REM Attempt to check the latest python 2 and 3 versions via the py launcher
|
||||
for /f "USEBACKQ tokens=*" %%x in (`%~1 -2 -c "import sys; print(sys.executable)" 2^> nul`) do ( call :checkpyversion "%%x" "%~2" "%~3" "%~4" "%~5" )
|
||||
for /f "USEBACKQ tokens=*" %%x in (`%~1 -3 -c "import sys; print(sys.executable)" 2^> nul`) do ( call :checkpyversion "%%x" "%~2" "%~3" "%~4" "%~5" )
|
||||
goto :EOF
|
||||
|
||||
:checkpyversion <path> <py2v> <py2path> <py3v> <py3path>
|
||||
set "version="&for /f "tokens=2* USEBACKQ delims= " %%a in (`"%~1" -V 2^>^&1`) do (
|
||||
REM Ensure we have a version number
|
||||
call :isnumber "%%a"
|
||||
if not "!errorlevel!" == "0" goto :EOF
|
||||
set "version=%%a"
|
||||
)
|
||||
if not defined version goto :EOF
|
||||
if "!version:~0,1!" == "2" (
|
||||
REM Python 2
|
||||
call :comparepyversion "!version!" "!%~2!"
|
||||
if "!errorlevel!" == "1" (
|
||||
set "%~2=!version!"
|
||||
set "%~3=%~1"
|
||||
)
|
||||
) else (
|
||||
REM Python 3
|
||||
call :comparepyversion "!version!" "!%~4!"
|
||||
if "!errorlevel!" == "1" (
|
||||
set "%~4=!version!"
|
||||
set "%~5=%~1"
|
||||
)
|
||||
)
|
||||
goto :EOF
|
||||
|
||||
:isnumber <check_value>
|
||||
set "var="&for /f "delims=0123456789." %%i in ("%~1") do set var=%%i
|
||||
if defined var (exit /b 1)
|
||||
exit /b 0
|
||||
|
||||
:comparepyversion <version1> <version2> <return>
|
||||
REM Exits with status 0 if equal, 1 if v1 gtr v2, 2 if v1 lss v2
|
||||
for /f "tokens=1,2,3 delims=." %%a in ("%~1") do (
|
||||
set a1=%%a
|
||||
set a2=%%b
|
||||
set a3=%%c
|
||||
)
|
||||
for /f "tokens=1,2,3 delims=." %%a in ("%~2") do (
|
||||
set b1=%%a
|
||||
set b2=%%b
|
||||
set b3=%%c
|
||||
)
|
||||
if not defined a1 set a1=0
|
||||
if not defined a2 set a2=0
|
||||
if not defined a3 set a3=0
|
||||
if not defined b1 set b1=0
|
||||
if not defined b2 set b2=0
|
||||
if not defined b3 set b3=0
|
||||
if %a1% gtr %b1% exit /b 1
|
||||
if %a1% lss %b1% exit /b 2
|
||||
if %a2% gtr %b2% exit /b 1
|
||||
if %a2% lss %b2% exit /b 2
|
||||
if %a3% gtr %b3% exit /b 1
|
||||
if %a3% lss %b3% exit /b 2
|
||||
exit /b 0
|
||||
|
||||
:askinstall
|
||||
cls
|
||||
echo ### ###
|
||||
echo # Python Not Found #
|
||||
echo ### ###
|
||||
echo.
|
||||
echo Python !targetpy! was not found on the system or in the PATH var.
|
||||
echo.
|
||||
set /p "menu=Would you like to install it now? [y/n]: "
|
||||
if /i "!menu!"=="y" (
|
||||
REM We got the OK - install it
|
||||
goto installpy
|
||||
) else if "!menu!"=="n" (
|
||||
REM No OK here...
|
||||
set /a tried=!tried!+1
|
||||
goto checkpy
|
||||
)
|
||||
REM Incorrect answer - go back
|
||||
goto askinstall
|
||||
|
||||
:installpy
|
||||
REM This will attempt to download and install python
|
||||
set /a tried=!tried!+1
|
||||
cls
|
||||
echo ### ###
|
||||
echo # Downloading Python #
|
||||
echo ### ###
|
||||
echo.
|
||||
set "release=!user_provided!"
|
||||
if "!release!" == "" (
|
||||
REM No explicit release set - get the latest from python.org
|
||||
echo Gathering latest version...
|
||||
powershell -command "[Net.ServicePointManager]::SecurityProtocol=[Net.SecurityProtocolType]::Tls12;(new-object System.Net.WebClient).DownloadFile('https://www.python.org/downloads/windows/','%TEMP%\pyurl.txt')"
|
||||
REM Extract it if it's gzip compressed
|
||||
powershell -command "$infile='%TEMP%\pyurl.txt';$outfile='%TEMP%\pyurl.temp';try{$input=New-Object System.IO.FileStream $infile,([IO.FileMode]::Open),([IO.FileAccess]::Read),([IO.FileShare]::Read);$output=New-Object System.IO.FileStream $outfile,([IO.FileMode]::Create),([IO.FileAccess]::Write),([IO.FileShare]::None);$gzipStream=New-Object System.IO.Compression.GzipStream $input,([IO.Compression.CompressionMode]::Decompress);$buffer=New-Object byte[](1024);while($true){$read=$gzipstream.Read($buffer,0,1024);if($read -le 0){break};$output.Write($buffer,0,$read)};$gzipStream.Close();$output.Close();$input.Close();Move-Item -Path $outfile -Destination $infile -Force}catch{}"
|
||||
if not exist "%TEMP%\pyurl.txt" (
|
||||
if /i "!just_installing!" == "TRUE" (
|
||||
echo - Failed to get info
|
||||
exit /b 1
|
||||
) else (
|
||||
goto checkpy
|
||||
)
|
||||
)
|
||||
pushd "%TEMP%"
|
||||
:: Version detection code slimmed by LussacZheng (https://github.com/corpnewt/gibMacOS/issues/20)
|
||||
for /f "tokens=9 delims=< " %%x in ('findstr /i /c:"Latest Python !targetpy! Release" pyurl.txt') do ( set "release=%%x" )
|
||||
popd
|
||||
REM Let's delete our txt file now - we no longer need it
|
||||
del "%TEMP%\pyurl.txt"
|
||||
if "!release!" == "" (
|
||||
if /i "!just_installing!" == "TRUE" (
|
||||
echo - Failed to get python version
|
||||
exit /b 1
|
||||
) else (
|
||||
goto checkpy
|
||||
)
|
||||
)
|
||||
echo Located Version: !release!
|
||||
) else (
|
||||
echo User-Provided Version: !release!
|
||||
REM Update our targetpy to reflect the first number of
|
||||
REM our release
|
||||
for /f "tokens=1 delims=." %%a in ("!release!") do (
|
||||
call :isnumber "%%a"
|
||||
if "!errorlevel!" == "0" (
|
||||
set "targetpy=%%a"
|
||||
)
|
||||
)
|
||||
)
|
||||
echo Building download url...
|
||||
REM At this point - we should have the version number.
|
||||
REM We can build the url like so: "https://www.python.org/ftp/python/[version]/python-[version]-amd64.exe"
|
||||
set "url=https://www.python.org/ftp/python/!release!/python-!release!-amd64.exe"
|
||||
set "pytype=exe"
|
||||
if "!targetpy!" == "2" (
|
||||
set "url=https://www.python.org/ftp/python/!release!/python-!release!.amd64.msi"
|
||||
set "pytype=msi"
|
||||
)
|
||||
echo - !url!
|
||||
echo Downloading...
|
||||
REM Now we download it with our slick powershell command
|
||||
powershell -command "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; (new-object System.Net.WebClient).DownloadFile('!url!','%TEMP%\pyinstall.!pytype!')"
|
||||
REM If it doesn't exist - we bail
|
||||
if not exist "%TEMP%\pyinstall.!pytype!" (
|
||||
if /i "!just_installing!" == "TRUE" (
|
||||
echo - Failed to download python installer
|
||||
exit /b 1
|
||||
) else (
|
||||
goto checkpy
|
||||
)
|
||||
)
|
||||
REM It should exist at this point - let's run it to install silently
|
||||
echo Running python !pytype! installer...
|
||||
pushd "%TEMP%"
|
||||
if /i "!pytype!" == "exe" (
|
||||
echo - pyinstall.exe /quiet PrependPath=1 Include_test=0 Shortcuts=0 Include_launcher=0
|
||||
pyinstall.exe /quiet PrependPath=1 Include_test=0 Shortcuts=0 Include_launcher=0
|
||||
) else (
|
||||
set "foldername=!release:.=!"
|
||||
echo - msiexec /i pyinstall.msi /qb ADDLOCAL=ALL TARGETDIR="%LocalAppData%\Programs\Python\Python!foldername:~0,2!"
|
||||
msiexec /i pyinstall.msi /qb ADDLOCAL=ALL TARGETDIR="%LocalAppData%\Programs\Python\Python!foldername:~0,2!"
|
||||
)
|
||||
popd
|
||||
set "py_error=!errorlevel!"
|
||||
echo Installer finished with status: !py_error!
|
||||
echo Cleaning up...
|
||||
REM Now we should be able to delete the installer and check for py again
|
||||
del "%TEMP%\pyinstall.!pytype!"
|
||||
REM If it worked, then we should have python in our PATH
|
||||
REM this does not get updated right away though - let's try
|
||||
REM manually updating the local PATH var
|
||||
call :updatepath
|
||||
if /i "!just_installing!" == "TRUE" (
|
||||
echo.
|
||||
echo Done.
|
||||
) else (
|
||||
goto checkpy
|
||||
)
|
||||
exit /b
|
||||
|
||||
:runscript
|
||||
REM Python found
|
||||
cls
|
||||
REM Checks the args gathered at the beginning of the script.
|
||||
REM Make sure we're not just forwarding empty quotes.
|
||||
set "arg_test=!args:"=!"
|
||||
if "!arg_test!"=="" (
|
||||
"!pypath!" "!thisDir!!script_name!"
|
||||
) else (
|
||||
"!pypath!" "!thisDir!!script_name!" !args!
|
||||
)
|
||||
if /i "!pause_on_error!" == "yes" (
|
||||
if not "%ERRORLEVEL%" == "0" (
|
||||
echo.
|
||||
echo Script exited with error code: %ERRORLEVEL%
|
||||
echo.
|
||||
echo Press [enter] to exit...
|
||||
pause > nul
|
||||
)
|
||||
)
|
||||
goto :EOF
|
||||
|
||||
:undouble <string_name> <string_value> <character>
|
||||
REM Helper function to strip doubles of a single character out of a string recursively
|
||||
set "string_value=%~2"
|
||||
:undouble_continue
|
||||
set "check=!string_value:%~3%~3=%~3!"
|
||||
if not "!check!" == "!string_value!" (
|
||||
set "string_value=!check!"
|
||||
goto :undouble_continue
|
||||
)
|
||||
set "%~1=!check!"
|
||||
goto :EOF
|
||||
|
||||
:updatepath
|
||||
set "spath="
|
||||
set "upath="
|
||||
for /f "USEBACKQ tokens=2* delims= " %%i in (`!syspath!reg.exe query "HKCU\Environment" /v "Path" 2^> nul`) do ( if not "%%j" == "" set "upath=%%j" )
|
||||
for /f "USEBACKQ tokens=2* delims= " %%i in (`!syspath!reg.exe query "HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment" /v "Path" 2^> nul`) do ( if not "%%j" == "" set "spath=%%j" )
|
||||
if not "%spath%" == "" (
|
||||
REM We got something in the system path
|
||||
set "PATH=%spath%"
|
||||
if not "%upath%" == "" (
|
||||
REM We also have something in the user path
|
||||
set "PATH=%PATH%;%upath%"
|
||||
)
|
||||
) else if not "%upath%" == "" (
|
||||
set "PATH=%upath%"
|
||||
)
|
||||
REM Remove double semicolons from the adjusted PATH
|
||||
call :undouble "PATH" "%PATH%" ";"
|
||||
goto :EOF
|
||||
|
||||
:getsyspath <variable_name>
|
||||
REM Helper method to return a valid path to cmd.exe, reg.exe, and where.exe by
|
||||
REM walking the ComSpec var - will also repair it in memory if need be
|
||||
REM Strip double semi-colons
|
||||
call :undouble "temppath" "%ComSpec%" ";"
|
||||
|
||||
REM Dirty hack to leverage the "line feed" approach - there are some odd side
|
||||
REM effects with this. Do not use this variable name in comments near this
|
||||
REM line - as it seems to behave erradically.
|
||||
(set LF=^
|
||||
%=this line is empty=%
|
||||
)
|
||||
REM Replace instances of semi-colons with a line feed and wrap
|
||||
REM in parenthesis to work around some strange batch behavior
|
||||
set "testpath=%temppath:;=!LF!%"
|
||||
|
||||
REM Let's walk each path and test if cmd.exe, reg.exe, and where.exe exist there
|
||||
set /a found=0
|
||||
for /f "tokens=* delims=" %%i in ("!testpath!") do (
|
||||
REM Only continue if we haven't found it yet
|
||||
if not "%%i" == "" (
|
||||
if !found! lss 1 (
|
||||
set "checkpath=%%i"
|
||||
REM Remove "cmd.exe" from the end if it exists
|
||||
if /i "!checkpath:~-7!" == "cmd.exe" (
|
||||
set "checkpath=!checkpath:~0,-7!"
|
||||
)
|
||||
REM Pad the end with a backslash if needed
|
||||
if not "!checkpath:~-1!" == "\" (
|
||||
set "checkpath=!checkpath!\"
|
||||
)
|
||||
REM Let's see if cmd, reg, and where exist there - and set it if so
|
||||
if EXIST "!checkpath!cmd.exe" (
|
||||
if EXIST "!checkpath!reg.exe" (
|
||||
if EXIST "!checkpath!where.exe" (
|
||||
set /a found=1
|
||||
set "ComSpec=!checkpath!cmd.exe"
|
||||
set "%~1=!checkpath!"
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
goto :EOF
|
||||
339
ACPI/SSDTTime-master/SSDTTime.command
Normal file
339
ACPI/SSDTTime-master/SSDTTime.command
Normal file
@@ -0,0 +1,339 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# Get the curent directory, the script name
|
||||
# and the script name with "py" substituted for the extension.
|
||||
args=( "$@" )
|
||||
dir="$(cd -- "$(dirname "$0")" >/dev/null 2>&1; pwd -P)"
|
||||
script="${0##*/}"
|
||||
target="${script%.*}.py"
|
||||
|
||||
# use_py3:
|
||||
# TRUE = Use if found, use py2 otherwise
|
||||
# FALSE = Use py2
|
||||
# FORCE = Use py3
|
||||
use_py3="TRUE"
|
||||
|
||||
# We'll parse if the first argument passed is
|
||||
# --install-python and if so, we'll just install
|
||||
# Can optionally take a version number as the
|
||||
# second arg - i.e. --install-python 3.13.1
|
||||
just_installing="FALSE"
|
||||
|
||||
tempdir=""
|
||||
|
||||
compare_to_version () {
|
||||
# Compares our OS version to the passed OS version, and
|
||||
# return a 1 if we match the passed compare type, or a 0 if we don't.
|
||||
# $1 = 0 (equal), 1 (greater), 2 (less), 3 (gequal), 4 (lequal)
|
||||
# $2 = OS version to compare ours to
|
||||
if [ -z "$1" ] || [ -z "$2" ]; then
|
||||
# Missing info - bail.
|
||||
return
|
||||
fi
|
||||
local current_os= comp=
|
||||
current_os="$(sw_vers -productVersion 2>/dev/null)"
|
||||
comp="$(vercomp "$current_os" "$2")"
|
||||
# Check gequal and lequal first
|
||||
if [[ "$1" == "3" && ("$comp" == "1" || "$comp" == "0") ]] || [[ "$1" == "4" && ("$comp" == "2" || "$comp" == "0") ]] || [[ "$comp" == "$1" ]]; then
|
||||
# Matched
|
||||
echo "1"
|
||||
else
|
||||
# No match
|
||||
echo "0"
|
||||
fi
|
||||
}
|
||||
|
||||
set_use_py3_if () {
|
||||
# Auto sets the "use_py3" variable based on
|
||||
# conditions passed
|
||||
# $1 = 0 (equal), 1 (greater), 2 (less), 3 (gequal), 4 (lequal)
|
||||
# $2 = OS version to compare
|
||||
# $3 = TRUE/FALSE/FORCE in case of match
|
||||
if [ -z "$1" ] || [ -z "$2" ] || [ -z "$3" ]; then
|
||||
# Missing vars - bail with no changes.
|
||||
return
|
||||
fi
|
||||
if [ "$(compare_to_version "$1" "$2")" == "1" ]; then
|
||||
use_py3="$3"
|
||||
fi
|
||||
}
|
||||
|
||||
get_remote_py_version () {
|
||||
local pyurl= py_html= py_vers= py_num="3"
|
||||
pyurl="https://www.python.org/downloads/macos/"
|
||||
py_html="$(curl -L $pyurl --compressed 2>&1)"
|
||||
if [ -z "$use_py3" ]; then
|
||||
use_py3="TRUE"
|
||||
fi
|
||||
if [ "$use_py3" == "FALSE" ]; then
|
||||
py_num="2"
|
||||
fi
|
||||
py_vers="$(echo "$py_html" | grep -i "Latest Python $py_num Release" | awk '{print $8}' | cut -d'<' -f1)"
|
||||
echo "$py_vers"
|
||||
}
|
||||
|
||||
download_py () {
|
||||
local vers="$1" url=
|
||||
clear
|
||||
echo " ### ###"
|
||||
echo " # Downloading Python #"
|
||||
echo "### ###"
|
||||
echo
|
||||
if [ -z "$vers" ]; then
|
||||
echo "Gathering latest version..."
|
||||
vers="$(get_remote_py_version)"
|
||||
if [ -z "$vers" ]; then
|
||||
if [ "$just_installing" == "TRUE" ]; then
|
||||
echo " - Failed to get info!"
|
||||
exit 1
|
||||
else
|
||||
# Didn't get it still - bail
|
||||
print_error
|
||||
fi
|
||||
fi
|
||||
echo "Located Version: $vers"
|
||||
else
|
||||
# Got a version passed
|
||||
echo "User-Provided Version: $vers"
|
||||
fi
|
||||
echo "Building download url..."
|
||||
url="$(curl -L https://www.python.org/downloads/release/python-${vers//./}/ --compressed 2>&1 | grep -iE "python-$vers-macos.*.pkg\"" | awk -F'"' '{ print $2 }' | head -n 1)"
|
||||
if [ -z "$url" ]; then
|
||||
if [ "$just_installing" == "TRUE" ]; then
|
||||
echo " - Failed to build download url!"
|
||||
exit 1
|
||||
else
|
||||
# Couldn't get the URL - bail
|
||||
print_error
|
||||
fi
|
||||
fi
|
||||
echo " - $url"
|
||||
echo "Downloading..."
|
||||
# Create a temp dir and download to it
|
||||
tempdir="$(mktemp -d 2>/dev/null || mktemp -d -t 'tempdir')"
|
||||
curl "$url" -o "$tempdir/python.pkg"
|
||||
if [ "$?" != "0" ]; then
|
||||
echo " - Failed to download python installer!"
|
||||
exit $?
|
||||
fi
|
||||
echo
|
||||
echo "Running python install package..."
|
||||
echo
|
||||
sudo installer -pkg "$tempdir/python.pkg" -target /
|
||||
echo
|
||||
if [ "$?" != "0" ]; then
|
||||
echo " - Failed to install python!"
|
||||
exit $?
|
||||
fi
|
||||
# Now we expand the package and look for a shell update script
|
||||
pkgutil --expand "$tempdir/python.pkg" "$tempdir/python"
|
||||
if [ -e "$tempdir/python/Python_Shell_Profile_Updater.pkg/Scripts/postinstall" ]; then
|
||||
# Run the script
|
||||
echo "Updating PATH..."
|
||||
echo
|
||||
"$tempdir/python/Python_Shell_Profile_Updater.pkg/Scripts/postinstall"
|
||||
echo
|
||||
fi
|
||||
vers_folder="Python $(echo "$vers" | cut -d'.' -f1 -f2)"
|
||||
if [ -f "/Applications/$vers_folder/Install Certificates.command" ]; then
|
||||
# Certs script exists - let's execute that to make sure our certificates are updated
|
||||
echo "Updating Certificates..."
|
||||
echo
|
||||
"/Applications/$vers_folder/Install Certificates.command"
|
||||
echo
|
||||
fi
|
||||
echo "Cleaning up..."
|
||||
cleanup
|
||||
if [ "$just_installing" == "TRUE" ]; then
|
||||
echo
|
||||
echo "Done."
|
||||
else
|
||||
# Now we check for py again
|
||||
downloaded="TRUE"
|
||||
clear
|
||||
main
|
||||
fi
|
||||
}
|
||||
|
||||
cleanup () {
|
||||
if [ -d "$tempdir" ]; then
|
||||
rm -Rf "$tempdir"
|
||||
fi
|
||||
}
|
||||
|
||||
print_error() {
|
||||
clear
|
||||
cleanup
|
||||
echo " ### ###"
|
||||
echo " # Python Not Found #"
|
||||
echo "### ###"
|
||||
echo
|
||||
echo "Python is not installed or not found in your PATH var."
|
||||
echo
|
||||
if [ "$kernel" == "Darwin" ]; then
|
||||
echo "Please go to https://www.python.org/downloads/macos/ to"
|
||||
echo "download and install the latest version, then try again."
|
||||
else
|
||||
echo "Please install python through your package manager and"
|
||||
echo "try again."
|
||||
fi
|
||||
echo
|
||||
exit 1
|
||||
}
|
||||
|
||||
print_target_missing() {
|
||||
clear
|
||||
cleanup
|
||||
echo " ### ###"
|
||||
echo " # Target Not Found #"
|
||||
echo "### ###"
|
||||
echo
|
||||
echo "Could not locate $target!"
|
||||
echo
|
||||
exit 1
|
||||
}
|
||||
|
||||
format_version () {
|
||||
local vers="$1"
|
||||
echo "$(echo "$1" | awk -F. '{ printf("%d%03d%03d%03d\n", $1,$2,$3,$4); }')"
|
||||
}
|
||||
|
||||
vercomp () {
|
||||
# Modified from: https://apple.stackexchange.com/a/123408/11374
|
||||
local ver1="$(format_version "$1")" ver2="$(format_version "$2")"
|
||||
if [ $ver1 -gt $ver2 ]; then
|
||||
echo "1"
|
||||
elif [ $ver1 -lt $ver2 ]; then
|
||||
echo "2"
|
||||
else
|
||||
echo "0"
|
||||
fi
|
||||
}
|
||||
|
||||
get_local_python_version() {
|
||||
# $1 = Python bin name (defaults to python3)
|
||||
# Echoes the path to the highest version of the passed python bin if any
|
||||
local py_name="$1" max_version= python= python_version= python_path=
|
||||
if [ -z "$py_name" ]; then
|
||||
py_name="python3"
|
||||
fi
|
||||
py_list="$(which -a "$py_name" 2>/dev/null)"
|
||||
# Walk that newline separated list
|
||||
while read python; do
|
||||
if [ -z "$python" ]; then
|
||||
# Got a blank line - skip
|
||||
continue
|
||||
fi
|
||||
if [ "$check_py3_stub" == "1" ] && [ "$python" == "/usr/bin/python3" ]; then
|
||||
# See if we have a valid developer path
|
||||
xcode-select -p > /dev/null 2>&1
|
||||
if [ "$?" != "0" ]; then
|
||||
# /usr/bin/python3 path - but no valid developer dir
|
||||
continue
|
||||
fi
|
||||
fi
|
||||
python_version="$(get_python_version $python)"
|
||||
if [ -z "$python_version" ]; then
|
||||
# Didn't find a py version - skip
|
||||
continue
|
||||
fi
|
||||
# Got the py version - compare to our max
|
||||
if [ -z "$max_version" ] || [ "$(vercomp "$python_version" "$max_version")" == "1" ]; then
|
||||
# Max not set, or less than the current - update it
|
||||
max_version="$python_version"
|
||||
python_path="$python"
|
||||
fi
|
||||
done <<< "$py_list"
|
||||
echo "$python_path"
|
||||
}
|
||||
|
||||
get_python_version() {
|
||||
local py_path="$1" py_version=
|
||||
# Get the python version by piping stderr into stdout (for py2), then grepping the output for
|
||||
# the word "python", getting the second element, and grepping for an alphanumeric version number
|
||||
py_version="$($py_path -V 2>&1 | grep -i python | cut -d' ' -f2 | grep -E "[A-Za-z\d\.]+")"
|
||||
if [ ! -z "$py_version" ]; then
|
||||
echo "$py_version"
|
||||
fi
|
||||
}
|
||||
|
||||
prompt_and_download() {
|
||||
if [ "$downloaded" != "FALSE" ] || [ "$kernel" != "Darwin" ]; then
|
||||
# We already tried to download, or we're not on macOS - just bail
|
||||
print_error
|
||||
fi
|
||||
clear
|
||||
echo " ### ###"
|
||||
echo " # Python Not Found #"
|
||||
echo "### ###"
|
||||
echo
|
||||
target_py="Python 3"
|
||||
printed_py="Python 2 or 3"
|
||||
if [ "$use_py3" == "FORCE" ]; then
|
||||
printed_py="Python 3"
|
||||
elif [ "$use_py3" == "FALSE" ]; then
|
||||
target_py="Python 2"
|
||||
printed_py="Python 2"
|
||||
fi
|
||||
echo "Could not locate $printed_py!"
|
||||
echo
|
||||
echo "This script requires $printed_py to run."
|
||||
echo
|
||||
while true; do
|
||||
read -p "Would you like to install the latest $target_py now? (y/n): " yn
|
||||
case $yn in
|
||||
[Yy]* ) download_py;break;;
|
||||
[Nn]* ) print_error;;
|
||||
esac
|
||||
done
|
||||
}
|
||||
|
||||
main() {
|
||||
local python= version=
|
||||
# Verify our target exists
|
||||
if [ ! -f "$dir/$target" ]; then
|
||||
# Doesn't exist
|
||||
print_target_missing
|
||||
fi
|
||||
if [ -z "$use_py3" ]; then
|
||||
use_py3="TRUE"
|
||||
fi
|
||||
if [ "$use_py3" != "FALSE" ]; then
|
||||
# Check for py3 first
|
||||
python="$(get_local_python_version python3)"
|
||||
fi
|
||||
if [ "$use_py3" != "FORCE" ] && [ -z "$python" ]; then
|
||||
# We aren't using py3 explicitly, and we don't already have a path
|
||||
python="$(get_local_python_version python2)"
|
||||
if [ -z "$python" ]; then
|
||||
# Try just looking for "python"
|
||||
python="$(get_local_python_version python)"
|
||||
fi
|
||||
fi
|
||||
if [ -z "$python" ]; then
|
||||
# Didn't ever find it - prompt
|
||||
prompt_and_download
|
||||
return 1
|
||||
fi
|
||||
# Found it - start our script and pass all args
|
||||
"$python" "$dir/$target" "${args[@]}"
|
||||
}
|
||||
|
||||
# Keep track of whether or not we're on macOS to determine if
|
||||
# we can download and install python for the user as needed.
|
||||
kernel="$(uname -s)"
|
||||
# Check to see if we need to force based on
|
||||
# macOS version. 10.15 has a dummy python3 version
|
||||
# that can trip up some py3 detection in other scripts.
|
||||
# set_use_py3_if "3" "10.15" "FORCE"
|
||||
downloaded="FALSE"
|
||||
# Check for the aforementioned /usr/bin/python3 stub if
|
||||
# our OS version is 10.15 or greater.
|
||||
check_py3_stub="$(compare_to_version "3" "10.15")"
|
||||
trap cleanup EXIT
|
||||
if [ "$1" == "--install-python" ] && [ "$kernel" == "Darwin" ]; then
|
||||
just_installing="TRUE"
|
||||
download_py "$2"
|
||||
else
|
||||
main
|
||||
fi
|
||||
4138
ACPI/SSDTTime-master/SSDTTime.py
Normal file
4138
ACPI/SSDTTime-master/SSDTTime.py
Normal file
File diff suppressed because it is too large
Load Diff
4
ACPI/SSDTTime-master/Scripts/__init__.py
Normal file
4
ACPI/SSDTTime-master/Scripts/__init__.py
Normal file
@@ -0,0 +1,4 @@
|
||||
from os.path import dirname, basename, isfile
|
||||
import glob
|
||||
modules = glob.glob(dirname(__file__)+"/*.py")
|
||||
__all__ = [ basename(f)[:-3] for f in modules if isfile(f) and not f.endswith('__init__.py')]
|
||||
330
ACPI/SSDTTime-master/Scripts/downloader.py
Normal file
330
ACPI/SSDTTime-master/Scripts/downloader.py
Normal file
@@ -0,0 +1,330 @@
|
||||
import sys, os, time, ssl, gzip, multiprocessing
|
||||
from io import BytesIO
|
||||
# Python-aware urllib stuff
|
||||
try:
|
||||
from urllib.request import urlopen, Request
|
||||
import queue as q
|
||||
except ImportError:
|
||||
# Import urllib2 to catch errors
|
||||
import urllib2
|
||||
from urllib2 import urlopen, Request
|
||||
import Queue as q
|
||||
|
||||
TERMINAL_WIDTH = 120 if os.name=="nt" else 80
|
||||
|
||||
def get_size(size, suffix=None, use_1024=False, round_to=2, strip_zeroes=False):
|
||||
# size is the number of bytes
|
||||
# suffix is the target suffix to locate (B, KB, MB, etc) - if found
|
||||
# use_2014 denotes whether or not we display in MiB vs MB
|
||||
# round_to is the number of dedimal points to round our result to (0-15)
|
||||
# strip_zeroes denotes whether we strip out zeroes
|
||||
|
||||
# Failsafe in case our size is unknown
|
||||
if size == -1:
|
||||
return "Unknown"
|
||||
# Get our suffixes based on use_1024
|
||||
ext = ["B","KiB","MiB","GiB","TiB","PiB"] if use_1024 else ["B","KB","MB","GB","TB","PB"]
|
||||
div = 1024 if use_1024 else 1000
|
||||
s = float(size)
|
||||
s_dict = {} # Initialize our dict
|
||||
# Iterate the ext list, and divide by 1000 or 1024 each time to setup the dict {ext:val}
|
||||
for e in ext:
|
||||
s_dict[e] = s
|
||||
s /= div
|
||||
# Get our suffix if provided - will be set to None if not found, or if started as None
|
||||
suffix = next((x for x in ext if x.lower() == suffix.lower()),None) if suffix else suffix
|
||||
# Get the largest value that's still over 1
|
||||
biggest = suffix if suffix else next((x for x in ext[::-1] if s_dict[x] >= 1), "B")
|
||||
# Determine our rounding approach - first make sure it's an int; default to 2 on error
|
||||
try:round_to=int(round_to)
|
||||
except:round_to=2
|
||||
round_to = 0 if round_to < 0 else 15 if round_to > 15 else round_to # Ensure it's between 0 and 15
|
||||
bval = round(s_dict[biggest], round_to)
|
||||
# Split our number based on decimal points
|
||||
a,b = str(bval).split(".")
|
||||
# Check if we need to strip or pad zeroes
|
||||
b = b.rstrip("0") if strip_zeroes else b.ljust(round_to,"0") if round_to > 0 else ""
|
||||
return "{:,}{} {}".format(int(a),"" if not b else "."+b,biggest)
|
||||
|
||||
def _process_hook(queue, total_size, bytes_so_far=0, update_interval=1.0, max_packets=0):
|
||||
packets = []
|
||||
speed = remaining = ""
|
||||
last_update = time.time()
|
||||
while True:
|
||||
# Write our info first so we have *some* status while
|
||||
# waiting for packets
|
||||
if total_size > 0:
|
||||
percent = float(bytes_so_far) / total_size
|
||||
percent = round(percent*100, 2)
|
||||
t_s = get_size(total_size)
|
||||
try:
|
||||
b_s = get_size(bytes_so_far, t_s.split(" ")[1])
|
||||
except:
|
||||
b_s = get_size(bytes_so_far)
|
||||
perc_str = " {:.2f}%".format(percent)
|
||||
bar_width = (TERMINAL_WIDTH // 3)-len(perc_str)
|
||||
progress = "=" * int(bar_width * (percent/100))
|
||||
sys.stdout.write("\r\033[K{}/{} | {}{}{}{}{}".format(
|
||||
b_s,
|
||||
t_s,
|
||||
progress,
|
||||
" " * (bar_width-len(progress)),
|
||||
perc_str,
|
||||
speed,
|
||||
remaining
|
||||
))
|
||||
else:
|
||||
b_s = get_size(bytes_so_far)
|
||||
sys.stdout.write("\r\033[K{}{}".format(b_s, speed))
|
||||
sys.stdout.flush()
|
||||
# Now we gather the next packet
|
||||
try:
|
||||
packet = queue.get(timeout=update_interval)
|
||||
# Packets should be formatted as a tuple of
|
||||
# (timestamp, len(bytes_downloaded))
|
||||
# If "DONE" is passed, we assume the download
|
||||
# finished - and bail
|
||||
if packet == "DONE":
|
||||
print("") # Jump to the next line
|
||||
return
|
||||
# Append our packet to the list and ensure we're not
|
||||
# beyond our max.
|
||||
# Only check max if it's > 0
|
||||
packets.append(packet)
|
||||
if max_packets > 0:
|
||||
packets = packets[-max_packets:]
|
||||
# Increment our bytes so far as well
|
||||
bytes_so_far += packet[1]
|
||||
except q.Empty:
|
||||
# Didn't get anything - reset the speed
|
||||
# and packets
|
||||
packets = []
|
||||
speed = " | 0 B/s"
|
||||
remaining = " | ?? left" if total_size > 0 else ""
|
||||
except KeyboardInterrupt:
|
||||
print("") # Jump to the next line
|
||||
return
|
||||
# If we have packets and it's time for an update, process
|
||||
# the info.
|
||||
update_check = time.time()
|
||||
if packets and update_check - last_update >= update_interval:
|
||||
last_update = update_check # Refresh our update timestamp
|
||||
speed = " | ?? B/s"
|
||||
if len(packets) > 1:
|
||||
# Let's calculate the amount downloaded over how long
|
||||
try:
|
||||
first,last = packets[0][0],packets[-1][0]
|
||||
chunks = sum([float(x[1]) for x in packets])
|
||||
t = last-first
|
||||
assert t >= 0
|
||||
bytes_speed = 1. / t * chunks
|
||||
speed = " | {}/s".format(get_size(bytes_speed,round_to=1))
|
||||
# Get our remaining time
|
||||
if total_size > 0:
|
||||
seconds_left = (total_size-bytes_so_far) / bytes_speed
|
||||
days = seconds_left // 86400
|
||||
hours = (seconds_left - (days*86400)) // 3600
|
||||
mins = (seconds_left - (days*86400) - (hours*3600)) // 60
|
||||
secs = seconds_left - (days*86400) - (hours*3600) - (mins*60)
|
||||
if days > 99 or bytes_speed == 0:
|
||||
remaining = " | ?? left"
|
||||
else:
|
||||
remaining = " | {}{:02d}:{:02d}:{:02d} left".format(
|
||||
"{}:".format(int(days)) if days else "",
|
||||
int(hours),
|
||||
int(mins),
|
||||
int(round(secs))
|
||||
)
|
||||
except:
|
||||
pass
|
||||
# Clear the packets so we don't reuse the same ones
|
||||
packets = []
|
||||
|
||||
class Downloader:
|
||||
|
||||
def __init__(self,**kwargs):
|
||||
self.ua = kwargs.get("useragent",{"User-Agent":"Mozilla"})
|
||||
self.chunk = 1048576 # 1024 x 1024 i.e. 1MiB
|
||||
if os.name=="nt": os.system("color") # Initialize cmd for ANSI escapes
|
||||
# Provide reasonable default logic to workaround macOS CA file handling
|
||||
cafile = ssl.get_default_verify_paths().openssl_cafile
|
||||
try:
|
||||
# If default OpenSSL CA file does not exist, use that from certifi
|
||||
if not os.path.exists(cafile):
|
||||
import certifi
|
||||
cafile = certifi.where()
|
||||
self.ssl_context = ssl.create_default_context(cafile=cafile)
|
||||
except:
|
||||
# None of the above worked, disable certificate verification for now
|
||||
self.ssl_context = ssl._create_unverified_context()
|
||||
return
|
||||
|
||||
def _decode(self, value, encoding="utf-8", errors="ignore"):
|
||||
# Helper method to only decode if bytes type
|
||||
if sys.version_info >= (3,0) and isinstance(value, bytes):
|
||||
return value.decode(encoding,errors)
|
||||
return value
|
||||
|
||||
def _update_main_name(self):
|
||||
# Windows running python 2 seems to have issues with multiprocessing
|
||||
# if the case of the main script's name is incorrect:
|
||||
# e.g. Downloader.py vs downloader.py
|
||||
#
|
||||
# To work around this, we try to scrape for the correct case if
|
||||
# possible.
|
||||
try:
|
||||
path = os.path.abspath(sys.modules["__main__"].__file__)
|
||||
except AttributeError as e:
|
||||
# This likely means we're running from the interpreter
|
||||
# directly
|
||||
return None
|
||||
if not os.path.isfile(path):
|
||||
return None
|
||||
# Get the file name and folder path
|
||||
name = os.path.basename(path).lower()
|
||||
fldr = os.path.dirname(path)
|
||||
# Walk the files in the folder until we find our
|
||||
# name - then steal its case and update that path
|
||||
for f in os.listdir(fldr):
|
||||
if f.lower() == name:
|
||||
# Got it
|
||||
new_path = os.path.join(fldr,f)
|
||||
sys.modules["__main__"].__file__ = new_path
|
||||
return new_path
|
||||
# If we got here, it wasn't found
|
||||
return None
|
||||
|
||||
def _get_headers(self, headers = None):
|
||||
# Fall back on the default ua if none provided
|
||||
target = headers if isinstance(headers,dict) else self.ua
|
||||
new_headers = {}
|
||||
# Shallow copy to prevent changes to the headers
|
||||
# overriding the original
|
||||
for k in target:
|
||||
new_headers[k] = target[k]
|
||||
return new_headers
|
||||
|
||||
def open_url(self, url, headers = None):
|
||||
headers = self._get_headers(headers)
|
||||
# Wrap up the try/except block so we don't have to do this for each function
|
||||
try:
|
||||
response = urlopen(Request(url, headers=headers), context=self.ssl_context)
|
||||
except Exception as e:
|
||||
# No fixing this - bail
|
||||
return None
|
||||
return response
|
||||
|
||||
def get_size(self, *args, **kwargs):
|
||||
return get_size(*args,**kwargs)
|
||||
|
||||
def get_string(self, url, progress = True, headers = None, expand_gzip = True):
|
||||
response = self.get_bytes(url,progress,headers,expand_gzip)
|
||||
if response is None: return None
|
||||
return self._decode(response)
|
||||
|
||||
def get_bytes(self, url, progress = True, headers = None, expand_gzip = True):
|
||||
response = self.open_url(url, headers)
|
||||
if response is None: return None
|
||||
try: total_size = int(response.headers['Content-Length'])
|
||||
except: total_size = -1
|
||||
chunk_so_far = b""
|
||||
packets = queue = process = None
|
||||
if progress:
|
||||
# Make sure our vars are initialized
|
||||
packets = [] if progress else None
|
||||
queue = multiprocessing.Queue()
|
||||
# Create the multiprocess and start it
|
||||
process = multiprocessing.Process(
|
||||
target=_process_hook,
|
||||
args=(queue,total_size)
|
||||
)
|
||||
process.daemon = True
|
||||
# Filthy hack for earlier python versions on Windows
|
||||
if os.name == "nt" and hasattr(multiprocessing,"forking"):
|
||||
self._update_main_name()
|
||||
process.start()
|
||||
try:
|
||||
while True:
|
||||
chunk = response.read(self.chunk)
|
||||
if progress:
|
||||
# Add our items to the queue
|
||||
queue.put((time.time(),len(chunk)))
|
||||
if not chunk: break
|
||||
chunk_so_far += chunk
|
||||
finally:
|
||||
# Close the response whenever we're done
|
||||
response.close()
|
||||
if expand_gzip and response.headers.get("Content-Encoding","unknown").lower() == "gzip":
|
||||
fileobj = BytesIO(chunk_so_far)
|
||||
gfile = gzip.GzipFile(fileobj=fileobj)
|
||||
return gfile.read()
|
||||
if progress:
|
||||
# Finalize the queue and wait
|
||||
queue.put("DONE")
|
||||
process.join()
|
||||
return chunk_so_far
|
||||
|
||||
def stream_to_file(self, url, file_path, progress = True, headers = None, ensure_size_if_present = True, allow_resume = False):
|
||||
response = self.open_url(url, headers)
|
||||
if response is None: return None
|
||||
bytes_so_far = 0
|
||||
try: total_size = int(response.headers['Content-Length'])
|
||||
except: total_size = -1
|
||||
packets = queue = process = None
|
||||
mode = "wb"
|
||||
if allow_resume and os.path.isfile(file_path) and total_size != -1:
|
||||
# File exists, we're resuming and have a target size. Check the
|
||||
# local file size.
|
||||
current_size = os.stat(file_path).st_size
|
||||
if current_size == total_size:
|
||||
# File is already complete - return the path
|
||||
return file_path
|
||||
elif current_size < total_size:
|
||||
response.close()
|
||||
# File is not complete - seek to our current size
|
||||
bytes_so_far = current_size
|
||||
mode = "ab" # Append
|
||||
# We also need to try creating a new request
|
||||
# in order to pass our range header
|
||||
new_headers = self._get_headers(headers)
|
||||
# Get the start byte, 0-indexed
|
||||
byte_string = "bytes={}-".format(current_size)
|
||||
new_headers["Range"] = byte_string
|
||||
response = self.open_url(url, new_headers)
|
||||
if response is None: return None
|
||||
if progress:
|
||||
# Make sure our vars are initialized
|
||||
packets = [] if progress else None
|
||||
queue = multiprocessing.Queue()
|
||||
# Create the multiprocess and start it
|
||||
process = multiprocessing.Process(
|
||||
target=_process_hook,
|
||||
args=(queue,total_size,bytes_so_far)
|
||||
)
|
||||
process.daemon = True
|
||||
# Filthy hack for earlier python versions on Windows
|
||||
if os.name == "nt" and hasattr(multiprocessing,"forking"):
|
||||
self._update_main_name()
|
||||
process.start()
|
||||
with open(file_path,mode) as f:
|
||||
try:
|
||||
while True:
|
||||
chunk = response.read(self.chunk)
|
||||
bytes_so_far += len(chunk)
|
||||
if progress:
|
||||
# Add our items to the queue
|
||||
queue.put((time.time(),len(chunk)))
|
||||
if not chunk: break
|
||||
f.write(chunk)
|
||||
finally:
|
||||
# Close the response whenever we're done
|
||||
response.close()
|
||||
if progress:
|
||||
# Finalize the queue and wait
|
||||
queue.put("DONE")
|
||||
process.join()
|
||||
if ensure_size_if_present and total_size != -1:
|
||||
# We're verifying size - make sure we got what we asked for
|
||||
if bytes_so_far != total_size:
|
||||
return None # We didn't - imply it failed
|
||||
return file_path if os.path.exists(file_path) else None
|
||||
907
ACPI/SSDTTime-master/Scripts/dsdt.py
Normal file
907
ACPI/SSDTTime-master/Scripts/dsdt.py
Normal file
@@ -0,0 +1,907 @@
|
||||
import os, errno, tempfile, shutil, plistlib, sys, binascii, zipfile, getpass, re
|
||||
from . import run, downloader, utils
|
||||
|
||||
try:
|
||||
FileNotFoundError
|
||||
except NameError:
|
||||
FileNotFoundError = IOError
|
||||
|
||||
class DSDT:
|
||||
def __init__(self, **kwargs):
|
||||
self.dl = downloader.Downloader()
|
||||
self.r = run.Run()
|
||||
self.u = utils.Utils("SSDT Time")
|
||||
self.iasl_url_macOS = "https://raw.githubusercontent.com/acidanthera/MaciASL/master/Dist/iasl-stable"
|
||||
self.iasl_url_macOS_legacy = "https://raw.githubusercontent.com/acidanthera/MaciASL/master/Dist/iasl-legacy"
|
||||
self.iasl_url_linux = "https://raw.githubusercontent.com/corpnewt/linux_iasl/main/iasl.zip"
|
||||
self.iasl_url_linux_legacy = "https://raw.githubusercontent.com/corpnewt/iasl-legacy/main/iasl-legacy-linux.zip"
|
||||
self.acpi_github_windows = "https://github.com/acpica/acpica/releases/latest"
|
||||
self.acpi_binary_tools = "https://www.intel.com/content/www/us/en/developer/topic-technology/open/acpica/download.html"
|
||||
self.iasl_url_windows_legacy = "https://raw.githubusercontent.com/corpnewt/iasl-legacy/main/iasl-legacy-windows.zip"
|
||||
self.h = {} # {"User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36"}
|
||||
self.iasl = self.check_iasl()
|
||||
self.iasl_legacy = self.check_iasl(legacy=True)
|
||||
if not self.iasl:
|
||||
url = (self.acpi_github_windows,self.acpi_binary_tools) if os.name=="nt" else \
|
||||
self.iasl_url_macOS if sys.platform=="darwin" else \
|
||||
self.iasl_url_linux if sys.platform.startswith("linux") else None
|
||||
exception = "Could not locate or download iasl!"
|
||||
if url:
|
||||
exception += "\n\nPlease manually download {} from:\n - {}\n\nAnd place in:\n - {}\n".format(
|
||||
"and extract iasl.exe and acpidump.exe" if os.name=="nt" else "iasl",
|
||||
"\n - ".join(url) if isinstance(url,(list,tuple)) else url,
|
||||
os.path.dirname(os.path.realpath(__file__))
|
||||
)
|
||||
raise Exception(exception)
|
||||
self.allowed_signatures = (b"APIC",b"DMAR",b"DSDT",b"SSDT")
|
||||
self.mixed_listing = (b"DSDT",b"SSDT")
|
||||
self.acpi_tables = {}
|
||||
# Setup regex matches
|
||||
self.hex_match = re.compile(r"^\s*[0-9A-F]{4,}:(\s[0-9A-F]{2})+(\s+\/\/.*)?$")
|
||||
self.type_match = re.compile(r".*(?P<type>Processor|Scope|Device|Method|Name) \((?P<name>[^,\)]+).*")
|
||||
|
||||
def _table_signature(self, table_path, table_name = None, data = None):
|
||||
path = os.path.join(table_path,table_name) if table_name else table_path
|
||||
if not os.path.isfile(path):
|
||||
return None
|
||||
if data:
|
||||
# Got data - make sure there's enough for a signature
|
||||
if len(data) >= 4:
|
||||
return data[:4]
|
||||
else:
|
||||
return None
|
||||
# Try to load it and read the first 4 bytes to verify the
|
||||
# signature
|
||||
with open(path,"rb") as f:
|
||||
try:
|
||||
return f.read(4)
|
||||
except:
|
||||
pass
|
||||
return None
|
||||
|
||||
def non_ascii_count(self, data):
|
||||
# Helper to emulate the ACPI_IS_ASCII macro from ACPICA's code
|
||||
# It just appears to check if the passed byte is < 0x80
|
||||
# We'll check all available data though - and return the number
|
||||
# of non-ascii bytes
|
||||
non_ascii = 0
|
||||
for b in data:
|
||||
if not isinstance(b,int):
|
||||
try: b = ord(b)
|
||||
except: b = -1
|
||||
if not b < 0x80:
|
||||
non_ascii += 1
|
||||
return non_ascii
|
||||
|
||||
def table_is_valid(self, table_path, table_name = None, ensure_binary = True, check_signature = True):
|
||||
# Ensure we have a valid file
|
||||
path = os.path.join(table_path,table_name) if table_name else table_path
|
||||
if not os.path.isfile(path):
|
||||
return False
|
||||
# Set up a data placeholder
|
||||
data = None
|
||||
if ensure_binary is not None:
|
||||
# Make sure the table is the right type - load it
|
||||
# and read the data
|
||||
with open(path,"rb") as f:
|
||||
data = f.read()
|
||||
# Make sure we actually got some data
|
||||
if not data:
|
||||
return False
|
||||
# Gather the non-ASCII char count
|
||||
non_ascii_count = self.non_ascii_count(data)
|
||||
if ensure_binary and not non_ascii_count:
|
||||
# We want a binary, but it's all ascii
|
||||
return False
|
||||
elif not ensure_binary and non_ascii_count:
|
||||
# We want ascii, and got a binary
|
||||
return False
|
||||
if check_signature:
|
||||
if not self._table_signature(path,data=data) in self.allowed_signatures:
|
||||
# Check with the function - we didn't load the table
|
||||
# already
|
||||
return False
|
||||
# If we got here - the table passed our checks
|
||||
return True
|
||||
|
||||
def get_ascii_print(self, data):
|
||||
# Helper to sanitize unprintable characters by replacing them with
|
||||
# ? where needed
|
||||
unprintables = False
|
||||
ascii_string = ""
|
||||
for b in data:
|
||||
if not isinstance(b,int):
|
||||
try: b = ord(b)
|
||||
except: b = -1
|
||||
if ord(" ") <= b < ord("~"):
|
||||
ascii_string += chr(b)
|
||||
else:
|
||||
ascii_string += "?"
|
||||
unprintables = True
|
||||
return (unprintables,ascii_string)
|
||||
|
||||
def load(self, table_path):
|
||||
# Attempt to load the passed file - or if a directory
|
||||
# was passed, load all .aml and .dat files within
|
||||
cwd = os.getcwd()
|
||||
temp = None
|
||||
target_files = {}
|
||||
failed = []
|
||||
try:
|
||||
if os.path.isdir(table_path):
|
||||
# Got a directory - gather all valid
|
||||
# files in the directory
|
||||
valid_files = [
|
||||
x for x in os.listdir(table_path) if self.table_is_valid(table_path,x)
|
||||
]
|
||||
elif os.path.isfile(table_path):
|
||||
# Just loading the one table - don't check
|
||||
# the signature - but make sure it's binary
|
||||
if self.table_is_valid(table_path,check_signature=False):
|
||||
valid_files = [table_path]
|
||||
else:
|
||||
# Not valid - raise an error
|
||||
raise FileNotFoundError(
|
||||
errno.ENOENT,
|
||||
os.strerror(errno.ENOENT),
|
||||
"{} is not a valid .aml/.dat file.".format(table_path)
|
||||
)
|
||||
else:
|
||||
# Not a valid path
|
||||
raise FileNotFoundError(
|
||||
errno.ENOENT,
|
||||
os.strerror(errno.ENOENT),
|
||||
table_path
|
||||
)
|
||||
if not valid_files:
|
||||
# No valid files were found
|
||||
raise FileNotFoundError(
|
||||
errno.ENOENT,
|
||||
os.strerror(errno.ENOENT),
|
||||
"No valid .aml/.dat files found at {}".format(table_path)
|
||||
)
|
||||
# Create a temp dir and copy all files there
|
||||
temp = tempfile.mkdtemp()
|
||||
for file in valid_files:
|
||||
shutil.copy(
|
||||
os.path.join(table_path,file),
|
||||
temp
|
||||
)
|
||||
# Build a list of all target files in the temp folder - and save
|
||||
# the disassembled_name for each to verify after
|
||||
list_dir = os.listdir(temp)
|
||||
for x in list_dir:
|
||||
if len(list_dir) > 1 and not self.table_is_valid(temp,x):
|
||||
continue # Skip invalid files when multiple are passed
|
||||
name_ext = [y for y in os.path.basename(x).split(".") if y]
|
||||
if name_ext and name_ext[-1].lower() in ("asl","dsl"):
|
||||
continue # Skip any already disassembled files
|
||||
target_files[x] = {
|
||||
"assembled_name": os.path.basename(x),
|
||||
"disassembled_name": ".".join(x.split(".")[:-1]) + ".dsl",
|
||||
}
|
||||
if not target_files:
|
||||
# Somehow we ended up with none?
|
||||
raise FileNotFoundError(
|
||||
errno.ENOENT,
|
||||
os.strerror(errno.ENOENT),
|
||||
"No valid .aml/.dat files found at {}".format(table_path)
|
||||
)
|
||||
os.chdir(temp)
|
||||
# Generate and run a command
|
||||
dsdt_or_ssdt = [x for x in list(target_files) if self._table_signature(temp,x) in self.mixed_listing]
|
||||
other_tables = [x for x in list(target_files) if not x in dsdt_or_ssdt]
|
||||
out_d = ("","",0)
|
||||
out_t = ("","",0)
|
||||
|
||||
def exists(folder_path,file_name):
|
||||
# Helper to make sure the file exists and has a non-Zero size
|
||||
check_path = os.path.join(folder_path,file_name)
|
||||
if os.path.isfile(check_path) and os.stat(check_path).st_size > 0:
|
||||
return True
|
||||
return False
|
||||
|
||||
# Check our DSDT and SSDTs first
|
||||
if dsdt_or_ssdt:
|
||||
args = [self.iasl,"-da","-dl","-l"]+list(dsdt_or_ssdt)
|
||||
out_d = self.r.run({"args":args})
|
||||
if out_d[2] != 0:
|
||||
# Attempt to run without `-da` if the above failed
|
||||
args = [self.iasl,"-dl","-l"]+list(dsdt_or_ssdt)
|
||||
out_d = self.r.run({"args":args})
|
||||
# Get a list of disassembled names that failed
|
||||
fail_temp = []
|
||||
for x in dsdt_or_ssdt:
|
||||
if not exists(temp,target_files[x]["disassembled_name"]):
|
||||
fail_temp.append(x)
|
||||
# Let's try to disassemble any that failed individually
|
||||
for x in fail_temp:
|
||||
args = [self.iasl,"-dl","-l",x]
|
||||
self.r.run({"args":args})
|
||||
if not exists(temp,target_files[x]["disassembled_name"]):
|
||||
failed.append(x)
|
||||
# Check for other tables (DMAR, APIC, etc)
|
||||
if other_tables:
|
||||
args = [self.iasl]+list(other_tables)
|
||||
out_t = self.r.run({"args":args})
|
||||
# Get a list of disassembled names that failed
|
||||
for x in other_tables:
|
||||
if not exists(temp,target_files[x]["disassembled_name"]):
|
||||
failed.append(x)
|
||||
if len(failed) == len(target_files):
|
||||
raise Exception("Failed to disassemble - {}".format(", ".join(failed)))
|
||||
# Actually process the tables now
|
||||
to_remove = []
|
||||
for file in target_files:
|
||||
# We need to load the .aml and .dsl into memory
|
||||
# and get the paths and scopes
|
||||
if not exists(temp,target_files[file]["disassembled_name"]):
|
||||
to_remove.append(file)
|
||||
continue
|
||||
with open(os.path.join(temp,target_files[file]["disassembled_name"]),"r") as f:
|
||||
target_files[file]["table"] = f.read()
|
||||
# Remove the compiler info at the start
|
||||
if target_files[file]["table"].startswith("/*"):
|
||||
target_files[file]["table"] = "*/".join(target_files[file]["table"].split("*/")[1:]).strip()
|
||||
# Check for "Table Header:" or "Raw Table Data: Length" and strip everything
|
||||
# after the last occurrence
|
||||
for h in ("\nTable Header:","\nRaw Table Data: Length"):
|
||||
if h in target_files[file]["table"]:
|
||||
target_files[file]["table"] = h.join(target_files[file]["table"].split(h)[:-1]).rstrip()
|
||||
break # Bail on the first match
|
||||
target_files[file]["lines"] = target_files[file]["table"].split("\n")
|
||||
target_files[file]["scopes"] = self.get_scopes(table=target_files[file])
|
||||
target_files[file]["paths"] = self.get_paths(table=target_files[file])
|
||||
with open(os.path.join(temp,file),"rb") as f:
|
||||
table_bytes = f.read()
|
||||
target_files[file]["raw"] = table_bytes
|
||||
# Let's read the table header and get the info we need
|
||||
#
|
||||
# [0:4] = Table Signature
|
||||
# [4:8] = Length (little endian)
|
||||
# [8] = Compliance Revision
|
||||
# [9] = Checksum
|
||||
# [10:16] = OEM ID (6 chars, padded to the right with \x00)
|
||||
# [16:24] = Table ID (8 chars, padded to the right with \x00)
|
||||
# [24:28] = OEM Revision (little endian)
|
||||
#
|
||||
target_files[file]["signature"] = table_bytes[0:4]
|
||||
target_files[file]["revision"] = table_bytes[8]
|
||||
target_files[file]["oem"] = table_bytes[10:16]
|
||||
target_files[file]["id"] = table_bytes[16:24]
|
||||
target_files[file]["oem_revision"] = int(binascii.hexlify(table_bytes[24:28][::-1]),16)
|
||||
target_files[file]["length"] = len(table_bytes)
|
||||
# Get the printable versions of the sig, oem, and id as needed
|
||||
for key in ("signature","oem","id"):
|
||||
unprintable,ascii_string = self.get_ascii_print(target_files[file][key])
|
||||
if unprintable:
|
||||
target_files[file][key+"_ascii"] = ascii_string
|
||||
# Cast as int on py2, and try to decode bytes to strings on py3
|
||||
if 2/3==0:
|
||||
target_files[file]["revision"] = int(binascii.hexlify(target_files[file]["revision"]),16)
|
||||
if target_files[file]["signature"] in self.mixed_listing:
|
||||
# The disassembler omits the last line of hex data in a mixed listing
|
||||
# file... convenient. However - we should be able to reconstruct this
|
||||
# manually.
|
||||
last_hex = next((l for l in target_files[file]["lines"][::-1] if self.is_hex(l)),None)
|
||||
if last_hex:
|
||||
# Get the address left of the colon
|
||||
addr = int(last_hex.split(":")[0].strip(),16)
|
||||
# Get the hex bytes right of the colon
|
||||
hexs = last_hex.split(":")[1].split("//")[0].strip()
|
||||
# Increment the address by the number of hex bytes
|
||||
next_addr = addr+len(hexs.split())
|
||||
# Now we need to get the bytes at the end
|
||||
hexb = self.get_hex_bytes(hexs.replace(" ",""))
|
||||
# Get the last occurrence after the split
|
||||
remaining = target_files[file]["raw"].split(hexb)[-1]
|
||||
else:
|
||||
# If we didn't get a last hex val - then we likely don't have any
|
||||
# This can happen if the file passed is small enough, or has all
|
||||
# the data in a single block.
|
||||
next_addr = 0
|
||||
remaining = target_files[file]["raw"]
|
||||
# Iterate in chunks of 16
|
||||
for chunk in [remaining[i:i+16] for i in range(0,len(remaining),16)]:
|
||||
# Build a new byte string
|
||||
hex_string = binascii.hexlify(chunk)
|
||||
# Decode the bytes if we're on python 3
|
||||
if 2/3!=0: hex_string = hex_string.decode()
|
||||
# Ensure the bytes are all upper case
|
||||
hex_string = hex_string.upper()
|
||||
l = " {}: {}".format(
|
||||
hex(next_addr)[2:].upper().rjust(4,"0"),
|
||||
" ".join([hex_string[i:i+2] for i in range(0,len(hex_string),2)])
|
||||
)
|
||||
# Increment our address
|
||||
next_addr += len(chunk)
|
||||
# Append our line
|
||||
target_files[file]["lines"].append(l)
|
||||
target_files[file]["table"] += "\n"+l
|
||||
# Remove any that didn't disassemble
|
||||
for file in to_remove:
|
||||
target_files.pop(file,None)
|
||||
except Exception as e:
|
||||
print(e)
|
||||
return ({},failed)
|
||||
finally:
|
||||
os.chdir(cwd)
|
||||
if temp: shutil.rmtree(temp,ignore_errors=True)
|
||||
# Add/update any tables we loaded
|
||||
for table in target_files:
|
||||
self.acpi_tables[table] = target_files[table]
|
||||
# Only return the newly loaded results
|
||||
return (target_files, failed,)
|
||||
|
||||
def get_latest_iasl(self):
|
||||
# First try getting from github - if that fails, fall back to intel.com
|
||||
try:
|
||||
source = self.dl.get_string(self.acpi_github_windows, progress=False, headers=self.h)
|
||||
assets_url = None
|
||||
# Check for attachments first
|
||||
for line in source.split("\n"):
|
||||
if '<a href="https://github.com/user-attachments/files/' in line \
|
||||
and "/iasl-win-" in line and '.zip"' in line:
|
||||
# We found it - return the URL
|
||||
return line.split('<a href="')[1].split('"')[0]
|
||||
if 'src="' in line and "expanded_assets" in line:
|
||||
# Save the URL for later in case we need it
|
||||
assets_url = line.split('src="')[1].split('"')[0]
|
||||
# If we got here - we didn't find the link in the attachments,
|
||||
# check in the expanded assets
|
||||
if assets_url:
|
||||
source = self.dl.get_string(assets_url, progress=False, headers=self.h)
|
||||
iasl = acpidump = None # Placeholders
|
||||
for line in source.split("\n"):
|
||||
# Check for any required assets
|
||||
if '<a href="/acpica/acpica/releases/download/' in line:
|
||||
# Check if we got iasl.exe or acpidump.exe
|
||||
if '/iasl.exe"' in line:
|
||||
iasl = "https://github.com{}".format(line.split('"')[1].split('"')[0])
|
||||
if '/acpidump.exe"' in line:
|
||||
acpidump = "https://github.com{}".format(line.split('"')[1].split('"')[0])
|
||||
if iasl and acpidump:
|
||||
# Got the needed files, return them
|
||||
return (iasl,acpidump)
|
||||
# If we got here - move on to intel.com
|
||||
except: pass
|
||||
# Helper to scrape https://www.intel.com/content/www/us/en/developer/topic-technology/open/acpica/download.html for the latest
|
||||
# download binaries link - then scrape the contents of that page for the actual download as needed
|
||||
try:
|
||||
source = self.dl.get_string(self.acpi_binary_tools, progress=False, headers=self.h)
|
||||
for line in source.split("\n"):
|
||||
if '<a href="' in line and ">iasl compiler and windows acpi tools" in line.lower():
|
||||
# Check if we have a direct download link - i.e. ends with .zip - or if we're
|
||||
# redirected to a different download page - i.e. ends with .html
|
||||
dl_link = line.split('<a href="')[1].split('"')[0]
|
||||
if dl_link.lower().endswith(".zip"):
|
||||
# Direct download - return as-is
|
||||
return dl_link
|
||||
elif dl_link.lower().endswith((".html",".htm")):
|
||||
# Redirect - try to scrape for a download link
|
||||
try:
|
||||
if dl_link.lower().startswith(("http:","https:")):
|
||||
# The existing link is likely complete - use it as-is
|
||||
dl_page_url = dl_link
|
||||
else:
|
||||
# <a href="/content/www/us/en/download/774881/acpi-component-architecture-downloads-windows-binary-tools.html">iASL Compiler and Windows ACPI Tools
|
||||
# Only a suffix - prepend to it
|
||||
dl_page_url = "https://www.intel.com" + line.split('<a href="')[1].split('"')[0]
|
||||
dl_page_source = self.dl.get_string(dl_page_url, progress=False, headers=self.h)
|
||||
for line in dl_page_source.split("\n"):
|
||||
if 'data-href="' in line and '"download-button"' in line:
|
||||
# Should have the right line
|
||||
return line.split('data-href="')[1].split('"')[0]
|
||||
except: pass
|
||||
except: pass
|
||||
return None
|
||||
|
||||
def check_iasl(self, legacy=False, try_downloading=True):
|
||||
if sys.platform == "win32":
|
||||
targets = (os.path.join(os.path.dirname(os.path.realpath(__file__)), "iasl-legacy.exe" if legacy else "iasl.exe"),)
|
||||
else:
|
||||
if legacy:
|
||||
targets = (os.path.join(os.path.dirname(os.path.realpath(__file__)), "iasl-legacy"),)
|
||||
else:
|
||||
targets = (
|
||||
os.path.join(os.path.dirname(os.path.realpath(__file__)), "iasl-dev"),
|
||||
os.path.join(os.path.dirname(os.path.realpath(__file__)), "iasl-stable"),
|
||||
os.path.join(os.path.dirname(os.path.realpath(__file__)), "iasl")
|
||||
)
|
||||
target = next((t for t in targets if os.path.exists(t)),None)
|
||||
if target or not try_downloading:
|
||||
# Either found it - or we didn't, and have already tried downloading
|
||||
return target
|
||||
# Need to download
|
||||
temp = tempfile.mkdtemp()
|
||||
try:
|
||||
if sys.platform == "darwin":
|
||||
self._download_and_extract(temp,self.iasl_url_macOS_legacy if legacy else self.iasl_url_macOS)
|
||||
elif sys.platform.startswith("linux"):
|
||||
self._download_and_extract(temp,self.iasl_url_linux_legacy if legacy else self.iasl_url_linux)
|
||||
elif sys.platform == "win32":
|
||||
iasl_url_windows = self.iasl_url_windows_legacy if legacy else self.get_latest_iasl()
|
||||
if not iasl_url_windows: raise Exception("Could not get latest iasl for Windows")
|
||||
self._download_and_extract(temp,iasl_url_windows)
|
||||
else:
|
||||
raise Exception("Unknown OS")
|
||||
except Exception as e:
|
||||
print("An error occurred :(\n - {}".format(e))
|
||||
shutil.rmtree(temp, ignore_errors=True)
|
||||
# Check again after downloading
|
||||
return self.check_iasl(legacy=legacy,try_downloading=False)
|
||||
|
||||
def _download_and_extract(self, temp, url):
|
||||
script_dir = os.path.join(os.path.dirname(os.path.realpath(__file__)))
|
||||
if not isinstance(url,(tuple,list)):
|
||||
url = (url,) # Wrap in a tuple
|
||||
for u in url:
|
||||
ztemp = tempfile.mkdtemp(dir=temp)
|
||||
zfile = os.path.basename(u)
|
||||
print("Downloading {}".format(zfile))
|
||||
self.dl.stream_to_file(u, os.path.join(ztemp,zfile), progress=False, headers=self.h)
|
||||
search_dir = ztemp
|
||||
if zfile.lower().endswith(".zip"):
|
||||
print(" - Extracting")
|
||||
search_dir = tempfile.mkdtemp(dir=temp)
|
||||
# Extract with built-in tools \o/
|
||||
with zipfile.ZipFile(os.path.join(ztemp,zfile)) as z:
|
||||
z.extractall(search_dir)
|
||||
for x in os.listdir(search_dir):
|
||||
if x.lower().startswith(("iasl","acpidump")):
|
||||
# Found one
|
||||
print(" - Found {}".format(x))
|
||||
if sys.platform != "win32":
|
||||
print(" - Chmod +x")
|
||||
self.r.run({"args":["chmod","+x",os.path.join(search_dir,x)]})
|
||||
print(" - Copying to {} directory".format(os.path.basename(script_dir)))
|
||||
shutil.copy(os.path.join(search_dir,x), os.path.join(script_dir,x))
|
||||
|
||||
def dump_tables(self, output, disassemble=False):
|
||||
# Helper to dump all ACPI tables to the specified
|
||||
# output path
|
||||
def check_command_output(out):
|
||||
if out[2] == 0: return False
|
||||
print(" - {}".format(out[1]))
|
||||
return True
|
||||
self.u.head("Dumping ACPI Tables")
|
||||
print("")
|
||||
res = self.check_output(output)
|
||||
if os.name == "nt":
|
||||
target = os.path.join(os.path.dirname(os.path.realpath(__file__)),"acpidump.exe")
|
||||
if os.path.exists(target):
|
||||
# Dump to the target folder
|
||||
print("Dumping tables to {}...".format(res))
|
||||
cwd = os.getcwd()
|
||||
os.chdir(res)
|
||||
out = self.r.run({"args":[target,"-b"]})
|
||||
os.chdir(cwd)
|
||||
if check_command_output(out):
|
||||
return
|
||||
# Make sure we have a DSDT
|
||||
if not next((x for x in os.listdir(res) if x.lower().startswith("dsdt.")),None):
|
||||
# We need to try and dump the DSDT individually - this sometimes
|
||||
# happens on older Windows installs or odd OEM machines
|
||||
print(" - DSDT not found - dumping by signature...")
|
||||
os.chdir(res)
|
||||
out = self.r.run({"args":[target,"-b","-n","DSDT"]})
|
||||
os.chdir(cwd)
|
||||
if check_command_output(out):
|
||||
return
|
||||
# Iterate the dumped files and ensure the names are uppercase, and the
|
||||
# extension used is .aml, not the default .dat
|
||||
print("Updating names...")
|
||||
for f in os.listdir(res):
|
||||
new_name = f.upper()
|
||||
if new_name.endswith(".DAT"):
|
||||
new_name = new_name[:-4]+".aml"
|
||||
if new_name != f:
|
||||
# Something changed - print it and rename it
|
||||
try:
|
||||
os.rename(os.path.join(res,f),os.path.join(res,new_name))
|
||||
except Exception as e:
|
||||
print(" - {} -> {} failed: {}".format(f,new_name,e))
|
||||
print("Dump successful!")
|
||||
if disassemble:
|
||||
return self.load(res)
|
||||
return res
|
||||
else:
|
||||
print("Failed to locate acpidump.exe")
|
||||
return
|
||||
elif sys.platform.startswith("linux"):
|
||||
table_dir = "/sys/firmware/acpi/tables"
|
||||
if not os.path.isdir(table_dir):
|
||||
print("Could not locate {}!".format(table_dir))
|
||||
return
|
||||
print("Copying tables to {}...".format(res))
|
||||
copied_files = []
|
||||
for table in os.listdir(table_dir):
|
||||
if not os.path.isfile(os.path.join(table_dir,table)):
|
||||
continue # We only want files
|
||||
target_path = os.path.join(res,table.upper()+".aml")
|
||||
comms = (
|
||||
# Copy the file
|
||||
["sudo","cp",os.path.join(table_dir,table),target_path],
|
||||
# Ensure it's owned by the user account
|
||||
["sudo","chown",getpass.getuser(),target_path],
|
||||
# Enable read and write permissions
|
||||
["sudo","chmod","a+rw",target_path]
|
||||
)
|
||||
# Iterate our commands and bail if any error
|
||||
for comm in comms:
|
||||
out = self.r.run({"args":comm})
|
||||
if check_command_output(out):
|
||||
return
|
||||
print("Dump successful!")
|
||||
if disassemble:
|
||||
return self.load(res)
|
||||
return res
|
||||
|
||||
def check_output(self, output):
|
||||
t_folder = os.path.join(os.path.dirname(os.path.dirname(os.path.realpath(__file__))), output)
|
||||
if not os.path.isdir(t_folder):
|
||||
os.makedirs(t_folder)
|
||||
return t_folder
|
||||
|
||||
def get_hex_from_int(self, total, pad_to = 4):
|
||||
hex_str = hex(total)[2:].upper().rjust(pad_to,"0")
|
||||
return "".join([hex_str[i:i + 2] for i in range(0, len(hex_str), 2)][::-1])
|
||||
|
||||
def get_hex(self, line):
|
||||
# strip the header and commented end
|
||||
return line.split(":")[1].split("//")[0].replace(" ","")
|
||||
|
||||
def get_line(self, line):
|
||||
# Strip the header and commented end - no space replacing though
|
||||
line = line.split("//")[0]
|
||||
if ":" in line:
|
||||
return line.split(":")[1]
|
||||
return line
|
||||
|
||||
def get_hex_bytes(self, line):
|
||||
return binascii.unhexlify(line)
|
||||
|
||||
def get_str_bytes(self, value):
|
||||
if 2/3!=0 and isinstance(value,str):
|
||||
value = value.encode()
|
||||
return value
|
||||
|
||||
def get_table_with_id(self, table_id):
|
||||
table_id = self.get_str_bytes(table_id)
|
||||
return next((v for k,v in self.acpi_tables.items() if table_id == v.get("id")),None)
|
||||
|
||||
def get_table_with_signature(self, table_sig):
|
||||
table_sig = self.get_str_bytes(table_sig)
|
||||
return next((v for k,v in self.acpi_tables.items() if table_sig == v.get("signature")),None)
|
||||
|
||||
def get_table(self, table_id_or_sig):
|
||||
table_id_or_sig = self.get_str_bytes(table_id_or_sig)
|
||||
return next((v for k,v in self.acpi_tables.items() if table_id_or_sig in (v.get("signature"),v.get("id"))),None)
|
||||
|
||||
def get_dsdt(self):
|
||||
return self.get_table_with_signature("DSDT")
|
||||
|
||||
def get_dsdt_or_only(self):
|
||||
dsdt = self.get_dsdt()
|
||||
if dsdt: return dsdt
|
||||
# Make sure we have only one table
|
||||
if len(self.acpi_tables) != 1:
|
||||
return None
|
||||
return list(self.acpi_tables.values())[0]
|
||||
|
||||
def find_previous_hex(self, index=0, table=None):
|
||||
if not table: table = self.get_dsdt_or_only()
|
||||
if not table: return ("",-1,-1)
|
||||
# Returns the index of the previous set of hex digits before the passed index
|
||||
start_index = -1
|
||||
end_index = -1
|
||||
old_hex = True
|
||||
for i,line in enumerate(table.get("lines","")[index::-1]):
|
||||
if old_hex:
|
||||
if not self.is_hex(line):
|
||||
# Broke out of the old hex
|
||||
old_hex = False
|
||||
continue
|
||||
# Not old_hex territory - check if we got new hex
|
||||
if self.is_hex(line): # Checks for a :, but not in comments
|
||||
end_index = index-i
|
||||
hex_text,start_index = self.get_hex_ending_at(end_index,table=table)
|
||||
return (hex_text, start_index, end_index)
|
||||
return ("",start_index,end_index)
|
||||
|
||||
def find_next_hex(self, index=0, table=None):
|
||||
if not table: table = self.get_dsdt_or_only()
|
||||
if not table: return ("",-1,-1)
|
||||
# Returns the index of the next set of hex digits after the passed index
|
||||
start_index = -1
|
||||
end_index = -1
|
||||
old_hex = True
|
||||
for i,line in enumerate(table.get("lines","")[index:]):
|
||||
if old_hex:
|
||||
if not self.is_hex(line):
|
||||
# Broke out of the old hex
|
||||
old_hex = False
|
||||
continue
|
||||
# Not old_hex territory - check if we got new hex
|
||||
if self.is_hex(line): # Checks for a :, but not in comments
|
||||
start_index = i+index
|
||||
hex_text,end_index = self.get_hex_starting_at(start_index,table=table)
|
||||
return (hex_text, start_index, end_index)
|
||||
return ("",start_index,end_index)
|
||||
|
||||
def is_hex(self, line):
|
||||
return self.hex_match.match(line) is not None
|
||||
|
||||
def get_hex_starting_at(self, start_index, table=None):
|
||||
if not table: table = self.get_dsdt_or_only()
|
||||
if not table: return ("",-1)
|
||||
# Returns a tuple of the hex, and the ending index
|
||||
hex_text = ""
|
||||
index = -1
|
||||
for i,x in enumerate(table.get("lines","")[start_index:]):
|
||||
if not self.is_hex(x):
|
||||
break
|
||||
hex_text += self.get_hex(x)
|
||||
index = i+start_index
|
||||
return (hex_text, index)
|
||||
|
||||
def get_hex_ending_at(self, start_index, table=None):
|
||||
if not table: table = self.get_dsdt_or_only()
|
||||
if not table: return ("",-1)
|
||||
# Returns a tuple of the hex, and the ending index
|
||||
hex_text = ""
|
||||
index = -1
|
||||
for i,x in enumerate(table.get("lines","")[start_index::-1]):
|
||||
if not self.is_hex(x):
|
||||
break
|
||||
hex_text = self.get_hex(x)+hex_text
|
||||
index = start_index-i
|
||||
return (hex_text, index)
|
||||
|
||||
def get_shortest_unique_pad(self, current_hex, index, instance=0, table=None):
|
||||
if not table: table = self.get_dsdt_or_only()
|
||||
if not table: return None
|
||||
try: left_pad = self.get_unique_pad(current_hex, index, False, instance, table=table)
|
||||
except: left_pad = None
|
||||
try: right_pad = self.get_unique_pad(current_hex, index, True, instance, table=table)
|
||||
except: right_pad = None
|
||||
try: mid_pad = self.get_unique_pad(current_hex, index, None, instance, table=table)
|
||||
except: mid_pad = None
|
||||
if left_pad == right_pad == mid_pad is None: raise Exception("No unique pad found!")
|
||||
# We got at least one unique pad
|
||||
min_pad = None
|
||||
for x in (left_pad,right_pad,mid_pad):
|
||||
if x is None: continue # Skip
|
||||
if min_pad is None or len(x[0]+x[1]) < len(min_pad[0]+min_pad[1]):
|
||||
min_pad = x
|
||||
return min_pad
|
||||
|
||||
def get_unique_pad(self, current_hex, index, direction=None, instance=0, table=None):
|
||||
if not table: table = self.get_dsdt_or_only()
|
||||
if not table: raise Exception("No valid table passed!")
|
||||
# Returns any pad needed to make the passed patch unique
|
||||
# direction can be True = forward, False = backward, None = both
|
||||
start_index = index
|
||||
line,last_index = self.get_hex_starting_at(index,table=table)
|
||||
if last_index == -1:
|
||||
raise Exception("Could not find hex starting at index {}!".format(index))
|
||||
first_line = line
|
||||
# Assume at least 1 byte of our current_hex exists at index, so we need to at
|
||||
# least load in len(current_hex)-2 worth of data if we haven't found it.
|
||||
while True:
|
||||
if current_hex in line or len(line) >= len(first_line)+len(current_hex):
|
||||
break # Assume we've hit our cap
|
||||
new_line,_index,last_index = self.find_next_hex(last_index, table=table)
|
||||
if last_index == -1:
|
||||
raise Exception("Hit end of file before passed hex was located!")
|
||||
# Append the new info
|
||||
line += new_line
|
||||
if not current_hex in line:
|
||||
raise Exception("{} not found in table at index {}-{}!".format(current_hex,start_index,last_index))
|
||||
padl = padr = ""
|
||||
parts = line.split(current_hex)
|
||||
if instance >= len(parts)-1:
|
||||
raise Exception("Instance out of range!")
|
||||
linel = current_hex.join(parts[0:instance+1])
|
||||
liner = current_hex.join(parts[instance+1:])
|
||||
last_check = True # Default to forward
|
||||
while True:
|
||||
# Check if our hex string is unique
|
||||
check_bytes = self.get_hex_bytes(padl+current_hex+padr)
|
||||
if table["raw"].count(check_bytes) == 1: # Got it!
|
||||
break
|
||||
if direction == True or (direction is None and len(padr)<=len(padl)):
|
||||
# Let's check a forward byte
|
||||
if not len(liner):
|
||||
# Need to grab more
|
||||
liner, _index, last_index = self.find_next_hex(last_index, table=table)
|
||||
if last_index == -1: raise Exception("Hit end of file before unique hex was found!")
|
||||
padr = padr+liner[0:2]
|
||||
liner = liner[2:]
|
||||
continue
|
||||
if direction == False or (direction is None and len(padl)<=len(padr)):
|
||||
# Let's check a backward byte
|
||||
if not len(linel):
|
||||
# Need to grab more
|
||||
linel, start_index, _index = self.find_previous_hex(start_index, table=table)
|
||||
if _index == -1: raise Exception("Hit end of file before unique hex was found!")
|
||||
padl = linel[-2:]+padl
|
||||
linel = linel[:-2]
|
||||
continue
|
||||
break
|
||||
return (padl,padr)
|
||||
|
||||
def get_devices(self,search=None,types=("Device (","Scope ("),strip_comments=False,table=None):
|
||||
if not table: table = self.get_dsdt_or_only()
|
||||
if not table: return []
|
||||
# Returns a list of tuples organized as (Device/Scope,d_s_index,matched_index)
|
||||
if search is None:
|
||||
return []
|
||||
last_device = None
|
||||
device_index = 0
|
||||
devices = []
|
||||
for index,line in enumerate(table.get("lines","")):
|
||||
if self.is_hex(line):
|
||||
continue
|
||||
line = self.get_line(line) if strip_comments else line
|
||||
if any ((x for x in types if x in line)):
|
||||
# Got a last_device match
|
||||
last_device = line
|
||||
device_index = index
|
||||
if search in line:
|
||||
# Got a search hit - add it
|
||||
devices.append((last_device,device_index,index))
|
||||
return devices
|
||||
|
||||
def get_scope(self,starting_index=0,add_hex=False,strip_comments=False,table=None):
|
||||
if not table: table = self.get_dsdt_or_only()
|
||||
if not table: return []
|
||||
# Walks the scope starting at starting_index, and returns when
|
||||
# we've exited
|
||||
brackets = None
|
||||
scope = []
|
||||
for line in table.get("lines","")[starting_index:]:
|
||||
if self.is_hex(line):
|
||||
if add_hex:
|
||||
scope.append(line)
|
||||
continue
|
||||
line = self.get_line(line) if strip_comments else line
|
||||
scope.append(line)
|
||||
if brackets is None:
|
||||
if line.count("{"):
|
||||
brackets = line.count("{")
|
||||
continue
|
||||
brackets = brackets + line.count("{") - line.count("}")
|
||||
if brackets <= 0:
|
||||
# We've exited the scope
|
||||
return scope
|
||||
return scope
|
||||
|
||||
def get_scopes(self, table=None):
|
||||
if not table: table = self.get_dsdt_or_only()
|
||||
if not table: return []
|
||||
scopes = []
|
||||
for index,line in enumerate(table.get("lines","")):
|
||||
if self.is_hex(line): continue
|
||||
if any(x in line for x in ("Processor (","Scope (","Device (","Method (","Name (")):
|
||||
scopes.append((line,index))
|
||||
return scopes
|
||||
|
||||
def get_paths(self, table=None):
|
||||
if not table: table = self.get_dsdt_or_only()
|
||||
if not table: return []
|
||||
# Set up lists for complete paths, as well
|
||||
# as our current path reference
|
||||
path_list = []
|
||||
_path = []
|
||||
brackets = 0
|
||||
for i,line in enumerate(table.get("lines",[])):
|
||||
if self.is_hex(line):
|
||||
# Skip hex
|
||||
continue
|
||||
line = self.get_line(line)
|
||||
brackets += line.count("{")-line.count("}")
|
||||
while len(_path):
|
||||
# Remove any path entries that are nested
|
||||
# equal to or further than our current set
|
||||
if _path[-1][-1] >= brackets:
|
||||
del _path[-1]
|
||||
else:
|
||||
break
|
||||
type_match = self.type_match.match(line)
|
||||
if type_match:
|
||||
# Add our path entry and save the full path
|
||||
# to the path list as needed
|
||||
_path.append((type_match.group("name"),brackets))
|
||||
if type_match.group("type") == "Scope":
|
||||
continue
|
||||
# Ensure that we only consider non-Scope paths that aren't
|
||||
# already fully qualified with a \ prefix
|
||||
path = []
|
||||
for p in _path[::-1]:
|
||||
path.append(p[0])
|
||||
p_check = p[0].split(".")[0].rstrip("_")
|
||||
if p_check.startswith("\\") or p_check in ("_SB","_PR"):
|
||||
# Fully qualified - bail here
|
||||
break
|
||||
path = ".".join(path[::-1]).split(".")
|
||||
# Properly qualify the path
|
||||
if len(path) and path[0] == "\\": path.pop(0)
|
||||
if any("^" in x for x in path): # Accommodate caret notation
|
||||
new_path = []
|
||||
for x in path:
|
||||
if x.count("^"):
|
||||
# Remove the last Y paths to account for going up a level
|
||||
del new_path[-1*x.count("^"):]
|
||||
new_path.append(x.replace("^","")) # Add the original, removing any ^ chars
|
||||
path = new_path
|
||||
if not path:
|
||||
continue
|
||||
# Ensure we strip trailing underscores for consistency
|
||||
padded_path = [("\\" if j==0 else"")+x.lstrip("\\").rstrip("_") for j,x in enumerate(path)]
|
||||
path_str = ".".join(padded_path)
|
||||
path_list.append((path_str,i,type_match.group("type")))
|
||||
return sorted(path_list)
|
||||
|
||||
def get_path_of_type(self, obj_type="Device", obj="HPET", table=None):
|
||||
if not table: table = self.get_dsdt_or_only()
|
||||
if not table: return []
|
||||
paths = []
|
||||
# Remove trailing underscores and normalize case for all path
|
||||
# elements passed
|
||||
obj = ".".join([x.rstrip("_").upper() for x in obj.split(".")])
|
||||
obj_type = obj_type.lower() if obj_type else obj_type
|
||||
for path in table.get("paths",[]):
|
||||
path_check = ".".join([x.rstrip("_").upper() for x in path[0].split(".")])
|
||||
if (obj_type and obj_type != path[2].lower()) or not path_check.endswith(obj):
|
||||
# Type or object mismatch - skip
|
||||
continue
|
||||
paths.append(path)
|
||||
return sorted(paths)
|
||||
|
||||
def get_device_paths(self, obj="HPET",table=None):
|
||||
return self.get_path_of_type(obj_type="Device",obj=obj,table=table)
|
||||
|
||||
def get_method_paths(self, obj="_STA",table=None):
|
||||
return self.get_path_of_type(obj_type="Method",obj=obj,table=table)
|
||||
|
||||
def get_name_paths(self, obj="CPU0",table=None):
|
||||
return self.get_path_of_type(obj_type="Name",obj=obj,table=table)
|
||||
|
||||
def get_processor_paths(self, obj_type="Processor",table=None):
|
||||
return self.get_path_of_type(obj_type=obj_type,obj="",table=table)
|
||||
|
||||
def get_device_paths_with_id(self,_id="PNP0A03",id_types=("_HID","_CID"),table=None):
|
||||
if not table: table = self.get_dsdt_or_only()
|
||||
if not table: return []
|
||||
if not isinstance(id_types,(list,tuple)): return []
|
||||
# Strip non-strings from the list
|
||||
id_types = [x.upper() for x in id_types if isinstance(x,str)]
|
||||
if not id_types: return []
|
||||
_id = _id.upper() # Ensure case
|
||||
devs = []
|
||||
for p in table.get("paths",[]):
|
||||
try:
|
||||
for type_check in id_types:
|
||||
if p[0].endswith(type_check) and _id in table.get("lines")[p[1]]:
|
||||
# Save the path, strip the suffix and trailing periods
|
||||
devs.append(p[0][:-len(type_check)].rstrip("."))
|
||||
# Leave this loop to avoid adding the same device
|
||||
# multiple times
|
||||
break
|
||||
except Exception as e:
|
||||
print(e)
|
||||
continue
|
||||
devices = []
|
||||
# Walk the paths again - and save any devices
|
||||
# that match our prior list
|
||||
for p in table.get("paths",[]):
|
||||
if p[0] in devs and p[-1] == "Device":
|
||||
devices.append(p)
|
||||
return devices
|
||||
|
||||
def get_device_paths_with_cid(self,cid="PNP0A03",table=None):
|
||||
return self.get_device_paths_with_id(_id=cid,id_types=("_CID",),table=table)
|
||||
|
||||
def get_device_paths_with_hid(self,hid="ACPI000E",table=None):
|
||||
return self.get_device_paths_with_id(_id=hid,id_types=("_HID",),table=table)
|
||||
688
ACPI/SSDTTime-master/Scripts/plist.py
Normal file
688
ACPI/SSDTTime-master/Scripts/plist.py
Normal file
@@ -0,0 +1,688 @@
|
||||
### ###
|
||||
# Imports #
|
||||
### ###
|
||||
|
||||
import datetime, os, plistlib, struct, sys, itertools, binascii
|
||||
from io import BytesIO
|
||||
|
||||
if sys.version_info < (3,0):
|
||||
# Force use of StringIO instead of cStringIO as the latter
|
||||
# has issues with Unicode strings
|
||||
from StringIO import StringIO
|
||||
else:
|
||||
from io import StringIO
|
||||
|
||||
try:
|
||||
basestring # Python 2
|
||||
unicode
|
||||
except NameError:
|
||||
basestring = str # Python 3
|
||||
unicode = str
|
||||
|
||||
try:
|
||||
FMT_XML = plistlib.FMT_XML
|
||||
FMT_BINARY = plistlib.FMT_BINARY
|
||||
except AttributeError:
|
||||
FMT_XML = "FMT_XML"
|
||||
FMT_BINARY = "FMT_BINARY"
|
||||
|
||||
### ###
|
||||
# Helper Methods #
|
||||
### ###
|
||||
|
||||
def wrap_data(value):
|
||||
if not _check_py3(): return plistlib.Data(value)
|
||||
return value
|
||||
|
||||
def extract_data(value):
|
||||
if not _check_py3() and isinstance(value,plistlib.Data): return value.data
|
||||
return value
|
||||
|
||||
def _check_py3():
|
||||
return sys.version_info >= (3, 0)
|
||||
|
||||
def _is_binary(fp):
|
||||
if isinstance(fp, basestring):
|
||||
return fp.startswith(b"bplist00")
|
||||
header = fp.read(32)
|
||||
fp.seek(0)
|
||||
return header[:8] == b'bplist00'
|
||||
|
||||
def _seek_past_whitespace(fp):
|
||||
offset = 0
|
||||
while True:
|
||||
byte = fp.read(1)
|
||||
if not byte:
|
||||
# End of file, reset offset and bail
|
||||
offset = 0
|
||||
break
|
||||
if not byte.isspace():
|
||||
# Found our first non-whitespace character
|
||||
break
|
||||
offset += 1
|
||||
# Seek to the first non-whitespace char
|
||||
fp.seek(offset)
|
||||
return offset
|
||||
|
||||
### ###
|
||||
# Deprecated Functions - Remapped #
|
||||
### ###
|
||||
|
||||
def readPlist(pathOrFile):
|
||||
if not isinstance(pathOrFile, basestring):
|
||||
return load(pathOrFile)
|
||||
with open(pathOrFile, "rb") as f:
|
||||
return load(f)
|
||||
|
||||
def writePlist(value, pathOrFile):
|
||||
if not isinstance(pathOrFile, basestring):
|
||||
return dump(value, pathOrFile, fmt=FMT_XML, sort_keys=True, skipkeys=False)
|
||||
with open(pathOrFile, "wb") as f:
|
||||
return dump(value, f, fmt=FMT_XML, sort_keys=True, skipkeys=False)
|
||||
|
||||
### ###
|
||||
# Remapped Functions #
|
||||
### ###
|
||||
|
||||
def load(fp, fmt=None, use_builtin_types=None, dict_type=dict):
|
||||
if _is_binary(fp):
|
||||
use_builtin_types = False if use_builtin_types is None else use_builtin_types
|
||||
try:
|
||||
p = _BinaryPlistParser(use_builtin_types=use_builtin_types, dict_type=dict_type)
|
||||
except:
|
||||
# Python 3.9 removed use_builtin_types
|
||||
p = _BinaryPlistParser(dict_type=dict_type)
|
||||
return p.parse(fp)
|
||||
elif _check_py3():
|
||||
offset = _seek_past_whitespace(fp)
|
||||
use_builtin_types = True if use_builtin_types is None else use_builtin_types
|
||||
# We need to monkey patch this to allow for hex integers - code taken/modified from
|
||||
# https://github.com/python/cpython/blob/3.8/Lib/plistlib.py
|
||||
if fmt is None:
|
||||
header = fp.read(32)
|
||||
fp.seek(offset)
|
||||
for info in plistlib._FORMATS.values():
|
||||
if info['detect'](header):
|
||||
P = info['parser']
|
||||
break
|
||||
else:
|
||||
raise plistlib.InvalidFileException()
|
||||
else:
|
||||
P = plistlib._FORMATS[fmt]['parser']
|
||||
try:
|
||||
p = P(use_builtin_types=use_builtin_types, dict_type=dict_type)
|
||||
except:
|
||||
# Python 3.9 removed use_builtin_types
|
||||
p = P(dict_type=dict_type)
|
||||
if isinstance(p,plistlib._PlistParser):
|
||||
# Monkey patch!
|
||||
def end_integer():
|
||||
d = p.get_data()
|
||||
value = int(d,16) if d.lower().startswith("0x") else int(d)
|
||||
if -1 << 63 <= value < 1 << 64:
|
||||
p.add_object(value)
|
||||
else:
|
||||
raise OverflowError("Integer overflow at line {}".format(p.parser.CurrentLineNumber))
|
||||
def end_data():
|
||||
try:
|
||||
p.add_object(plistlib._decode_base64(p.get_data()))
|
||||
except Exception as e:
|
||||
raise Exception("Data error at line {}: {}".format(p.parser.CurrentLineNumber,e))
|
||||
p.end_integer = end_integer
|
||||
p.end_data = end_data
|
||||
return p.parse(fp)
|
||||
else:
|
||||
offset = _seek_past_whitespace(fp)
|
||||
# Is not binary - assume a string - and try to load
|
||||
# We avoid using readPlistFromString() as that uses
|
||||
# cStringIO and fails when Unicode strings are detected
|
||||
# Don't subclass - keep the parser local
|
||||
from xml.parsers.expat import ParserCreate
|
||||
# Create a new PlistParser object - then we need to set up
|
||||
# the values and parse.
|
||||
p = plistlib.PlistParser()
|
||||
parser = ParserCreate()
|
||||
parser.StartElementHandler = p.handleBeginElement
|
||||
parser.EndElementHandler = p.handleEndElement
|
||||
parser.CharacterDataHandler = p.handleData
|
||||
# We also need to monkey patch this to allow for other dict_types, hex int support
|
||||
# proper line output for data errors, and for unicode string decoding
|
||||
def begin_dict(attrs):
|
||||
d = dict_type()
|
||||
p.addObject(d)
|
||||
p.stack.append(d)
|
||||
def end_integer():
|
||||
d = p.getData()
|
||||
value = int(d,16) if d.lower().startswith("0x") else int(d)
|
||||
if -1 << 63 <= value < 1 << 64:
|
||||
p.addObject(value)
|
||||
else:
|
||||
raise OverflowError("Integer overflow at line {}".format(parser.CurrentLineNumber))
|
||||
def end_data():
|
||||
try:
|
||||
p.addObject(plistlib.Data.fromBase64(p.getData()))
|
||||
except Exception as e:
|
||||
raise Exception("Data error at line {}: {}".format(parser.CurrentLineNumber,e))
|
||||
def end_string():
|
||||
d = p.getData()
|
||||
if isinstance(d,unicode):
|
||||
d = d.encode("utf-8")
|
||||
p.addObject(d)
|
||||
p.begin_dict = begin_dict
|
||||
p.end_integer = end_integer
|
||||
p.end_data = end_data
|
||||
p.end_string = end_string
|
||||
if isinstance(fp, unicode):
|
||||
# Encode unicode -> string; use utf-8 for safety
|
||||
fp = fp.encode("utf-8")
|
||||
if isinstance(fp, basestring):
|
||||
# It's a string - let's wrap it up
|
||||
fp = StringIO(fp)
|
||||
# Parse it
|
||||
parser.ParseFile(fp)
|
||||
return p.root
|
||||
|
||||
def loads(value, fmt=None, use_builtin_types=None, dict_type=dict):
|
||||
if _check_py3() and isinstance(value, basestring):
|
||||
# If it's a string - encode it
|
||||
value = value.encode()
|
||||
try:
|
||||
return load(BytesIO(value),fmt=fmt,use_builtin_types=use_builtin_types,dict_type=dict_type)
|
||||
except:
|
||||
# Python 3.9 removed use_builtin_types
|
||||
return load(BytesIO(value),fmt=fmt,dict_type=dict_type)
|
||||
|
||||
def dump(value, fp, fmt=FMT_XML, sort_keys=True, skipkeys=False):
|
||||
if fmt == FMT_BINARY:
|
||||
# Assume binary at this point
|
||||
writer = _BinaryPlistWriter(fp, sort_keys=sort_keys, skipkeys=skipkeys)
|
||||
writer.write(value)
|
||||
elif fmt == FMT_XML:
|
||||
if _check_py3():
|
||||
plistlib.dump(value, fp, fmt=fmt, sort_keys=sort_keys, skipkeys=skipkeys)
|
||||
else:
|
||||
# We need to monkey patch a bunch here too in order to avoid auto-sorting
|
||||
# of keys
|
||||
writer = plistlib.PlistWriter(fp)
|
||||
def writeDict(d):
|
||||
if d:
|
||||
writer.beginElement("dict")
|
||||
items = sorted(d.items()) if sort_keys else d.items()
|
||||
for key, value in items:
|
||||
if not isinstance(key, basestring):
|
||||
if skipkeys:
|
||||
continue
|
||||
raise TypeError("keys must be strings")
|
||||
writer.simpleElement("key", key)
|
||||
writer.writeValue(value)
|
||||
writer.endElement("dict")
|
||||
else:
|
||||
writer.simpleElement("dict")
|
||||
writer.writeDict = writeDict
|
||||
writer.writeln("<plist version=\"1.0\">")
|
||||
writer.writeValue(value)
|
||||
writer.writeln("</plist>")
|
||||
else:
|
||||
# Not a proper format
|
||||
raise ValueError("Unsupported format: {}".format(fmt))
|
||||
|
||||
def dumps(value, fmt=FMT_XML, skipkeys=False, sort_keys=True):
|
||||
# We avoid using writePlistToString() as that uses
|
||||
# cStringIO and fails when Unicode strings are detected
|
||||
f = BytesIO() if _check_py3() else StringIO()
|
||||
dump(value, f, fmt=fmt, skipkeys=skipkeys, sort_keys=sort_keys)
|
||||
value = f.getvalue()
|
||||
if _check_py3():
|
||||
value = value.decode("utf-8")
|
||||
return value
|
||||
|
||||
### ###
|
||||
# Binary Plist Stuff For Py2 #
|
||||
### ###
|
||||
|
||||
# From the python 3 plistlib.py source: https://github.com/python/cpython/blob/3.11/Lib/plistlib.py
|
||||
# Tweaked to function on both Python 2 and 3
|
||||
|
||||
class UID:
|
||||
def __init__(self, data):
|
||||
if not isinstance(data, int):
|
||||
raise TypeError("data must be an int")
|
||||
# It seems Apple only uses 32-bit unsigned ints for UIDs. Although the comment in
|
||||
# CoreFoundation's CFBinaryPList.c detailing the binary plist format theoretically
|
||||
# allows for 64-bit UIDs, most functions in the same file use 32-bit unsigned ints,
|
||||
# with the sole function hinting at 64-bits appearing to be a leftover from copying
|
||||
# and pasting integer handling code internally, and this code has not changed since
|
||||
# it was added. (In addition, code in CFPropertyList.c to handle CF$UID also uses a
|
||||
# 32-bit unsigned int.)
|
||||
#
|
||||
# if data >= 1 << 64:
|
||||
# raise ValueError("UIDs cannot be >= 2**64")
|
||||
if data >= 1 << 32:
|
||||
raise ValueError("UIDs cannot be >= 2**32 (4294967296)")
|
||||
if data < 0:
|
||||
raise ValueError("UIDs must be positive")
|
||||
self.data = data
|
||||
|
||||
def __index__(self):
|
||||
return self.data
|
||||
|
||||
def __repr__(self):
|
||||
return "%s(%s)" % (self.__class__.__name__, repr(self.data))
|
||||
|
||||
def __reduce__(self):
|
||||
return self.__class__, (self.data,)
|
||||
|
||||
def __eq__(self, other):
|
||||
if not isinstance(other, UID):
|
||||
return NotImplemented
|
||||
return self.data == other.data
|
||||
|
||||
def __hash__(self):
|
||||
return hash(self.data)
|
||||
|
||||
class InvalidFileException (ValueError):
|
||||
def __init__(self, message="Invalid file"):
|
||||
ValueError.__init__(self, message)
|
||||
|
||||
_BINARY_FORMAT = {1: 'B', 2: 'H', 4: 'L', 8: 'Q'}
|
||||
|
||||
_undefined = object()
|
||||
|
||||
class _BinaryPlistParser:
|
||||
"""
|
||||
Read or write a binary plist file, following the description of the binary
|
||||
format. Raise InvalidFileException in case of error, otherwise return the
|
||||
root object.
|
||||
see also: http://opensource.apple.com/source/CF/CF-744.18/CFBinaryPList.c
|
||||
"""
|
||||
def __init__(self, use_builtin_types, dict_type):
|
||||
self._use_builtin_types = use_builtin_types
|
||||
self._dict_type = dict_type
|
||||
|
||||
def parse(self, fp):
|
||||
try:
|
||||
# The basic file format:
|
||||
# HEADER
|
||||
# object...
|
||||
# refid->offset...
|
||||
# TRAILER
|
||||
self._fp = fp
|
||||
self._fp.seek(-32, os.SEEK_END)
|
||||
trailer = self._fp.read(32)
|
||||
if len(trailer) != 32:
|
||||
raise InvalidFileException()
|
||||
(
|
||||
offset_size, self._ref_size, num_objects, top_object,
|
||||
offset_table_offset
|
||||
) = struct.unpack('>6xBBQQQ', trailer)
|
||||
self._fp.seek(offset_table_offset)
|
||||
self._object_offsets = self._read_ints(num_objects, offset_size)
|
||||
self._objects = [_undefined] * num_objects
|
||||
return self._read_object(top_object)
|
||||
|
||||
except (OSError, IndexError, struct.error, OverflowError,
|
||||
UnicodeDecodeError):
|
||||
raise InvalidFileException()
|
||||
|
||||
def _get_size(self, tokenL):
|
||||
""" return the size of the next object."""
|
||||
if tokenL == 0xF:
|
||||
m = self._fp.read(1)[0]
|
||||
if not _check_py3():
|
||||
m = ord(m)
|
||||
m = m & 0x3
|
||||
s = 1 << m
|
||||
f = '>' + _BINARY_FORMAT[s]
|
||||
return struct.unpack(f, self._fp.read(s))[0]
|
||||
|
||||
return tokenL
|
||||
|
||||
def _read_ints(self, n, size):
|
||||
data = self._fp.read(size * n)
|
||||
if size in _BINARY_FORMAT:
|
||||
return struct.unpack('>' + _BINARY_FORMAT[size] * n, data)
|
||||
else:
|
||||
if not size or len(data) != size * n:
|
||||
raise InvalidFileException()
|
||||
return tuple(int(binascii.hexlify(data[i: i + size]),16)
|
||||
for i in range(0, size * n, size))
|
||||
'''return tuple(int.from_bytes(data[i: i + size], 'big')
|
||||
for i in range(0, size * n, size))'''
|
||||
|
||||
def _read_refs(self, n):
|
||||
return self._read_ints(n, self._ref_size)
|
||||
|
||||
def _read_object(self, ref):
|
||||
"""
|
||||
read the object by reference.
|
||||
May recursively read sub-objects (content of an array/dict/set)
|
||||
"""
|
||||
result = self._objects[ref]
|
||||
if result is not _undefined:
|
||||
return result
|
||||
|
||||
offset = self._object_offsets[ref]
|
||||
self._fp.seek(offset)
|
||||
token = self._fp.read(1)[0]
|
||||
if not _check_py3():
|
||||
token = ord(token)
|
||||
tokenH, tokenL = token & 0xF0, token & 0x0F
|
||||
|
||||
if token == 0x00: # \x00 or 0x00
|
||||
result = None
|
||||
|
||||
elif token == 0x08: # \x08 or 0x08
|
||||
result = False
|
||||
|
||||
elif token == 0x09: # \x09 or 0x09
|
||||
result = True
|
||||
|
||||
# The referenced source code also mentions URL (0x0c, 0x0d) and
|
||||
# UUID (0x0e), but neither can be generated using the Cocoa libraries.
|
||||
|
||||
elif token == 0x0f: # \x0f or 0x0f
|
||||
result = b''
|
||||
|
||||
elif tokenH == 0x10: # int
|
||||
result = int(binascii.hexlify(self._fp.read(1 << tokenL)),16)
|
||||
if tokenL >= 3: # Signed - adjust
|
||||
result = result-((result & 0x8000000000000000) << 1)
|
||||
|
||||
elif token == 0x22: # real
|
||||
result = struct.unpack('>f', self._fp.read(4))[0]
|
||||
|
||||
elif token == 0x23: # real
|
||||
result = struct.unpack('>d', self._fp.read(8))[0]
|
||||
|
||||
elif token == 0x33: # date
|
||||
f = struct.unpack('>d', self._fp.read(8))[0]
|
||||
# timestamp 0 of binary plists corresponds to 1/1/2001
|
||||
# (year of Mac OS X 10.0), instead of 1/1/1970.
|
||||
result = (datetime.datetime(2001, 1, 1) +
|
||||
datetime.timedelta(seconds=f))
|
||||
|
||||
elif tokenH == 0x40: # data
|
||||
s = self._get_size(tokenL)
|
||||
if self._use_builtin_types or not hasattr(plistlib, "Data"):
|
||||
result = self._fp.read(s)
|
||||
else:
|
||||
result = plistlib.Data(self._fp.read(s))
|
||||
|
||||
elif tokenH == 0x50: # ascii string
|
||||
s = self._get_size(tokenL)
|
||||
result = self._fp.read(s).decode('ascii')
|
||||
result = result
|
||||
|
||||
elif tokenH == 0x60: # unicode string
|
||||
s = self._get_size(tokenL)
|
||||
result = self._fp.read(s * 2).decode('utf-16be')
|
||||
|
||||
elif tokenH == 0x80: # UID
|
||||
# used by Key-Archiver plist files
|
||||
result = UID(int(binascii.hexlify(self._fp.read(1 + tokenL)),16))
|
||||
|
||||
elif tokenH == 0xA0: # array
|
||||
s = self._get_size(tokenL)
|
||||
obj_refs = self._read_refs(s)
|
||||
result = []
|
||||
self._objects[ref] = result
|
||||
result.extend(self._read_object(x) for x in obj_refs)
|
||||
|
||||
# tokenH == 0xB0 is documented as 'ordset', but is not actually
|
||||
# implemented in the Apple reference code.
|
||||
|
||||
# tokenH == 0xC0 is documented as 'set', but sets cannot be used in
|
||||
# plists.
|
||||
|
||||
elif tokenH == 0xD0: # dict
|
||||
s = self._get_size(tokenL)
|
||||
key_refs = self._read_refs(s)
|
||||
obj_refs = self._read_refs(s)
|
||||
result = self._dict_type()
|
||||
self._objects[ref] = result
|
||||
for k, o in zip(key_refs, obj_refs):
|
||||
key = self._read_object(k)
|
||||
if hasattr(plistlib, "Data") and isinstance(key, plistlib.Data):
|
||||
key = key.data
|
||||
result[key] = self._read_object(o)
|
||||
|
||||
else:
|
||||
raise InvalidFileException()
|
||||
|
||||
self._objects[ref] = result
|
||||
return result
|
||||
|
||||
def _count_to_size(count):
|
||||
if count < 1 << 8:
|
||||
return 1
|
||||
|
||||
elif count < 1 << 16:
|
||||
return 2
|
||||
|
||||
elif count < 1 << 32:
|
||||
return 4
|
||||
|
||||
else:
|
||||
return 8
|
||||
|
||||
_scalars = (str, int, float, datetime.datetime, bytes)
|
||||
|
||||
class _BinaryPlistWriter (object):
|
||||
def __init__(self, fp, sort_keys, skipkeys):
|
||||
self._fp = fp
|
||||
self._sort_keys = sort_keys
|
||||
self._skipkeys = skipkeys
|
||||
|
||||
def write(self, value):
|
||||
|
||||
# Flattened object list:
|
||||
self._objlist = []
|
||||
|
||||
# Mappings from object->objectid
|
||||
# First dict has (type(object), object) as the key,
|
||||
# second dict is used when object is not hashable and
|
||||
# has id(object) as the key.
|
||||
self._objtable = {}
|
||||
self._objidtable = {}
|
||||
|
||||
# Create list of all objects in the plist
|
||||
self._flatten(value)
|
||||
|
||||
# Size of object references in serialized containers
|
||||
# depends on the number of objects in the plist.
|
||||
num_objects = len(self._objlist)
|
||||
self._object_offsets = [0]*num_objects
|
||||
self._ref_size = _count_to_size(num_objects)
|
||||
|
||||
self._ref_format = _BINARY_FORMAT[self._ref_size]
|
||||
|
||||
# Write file header
|
||||
self._fp.write(b'bplist00')
|
||||
|
||||
# Write object list
|
||||
for obj in self._objlist:
|
||||
self._write_object(obj)
|
||||
|
||||
# Write refnum->object offset table
|
||||
top_object = self._getrefnum(value)
|
||||
offset_table_offset = self._fp.tell()
|
||||
offset_size = _count_to_size(offset_table_offset)
|
||||
offset_format = '>' + _BINARY_FORMAT[offset_size] * num_objects
|
||||
self._fp.write(struct.pack(offset_format, *self._object_offsets))
|
||||
|
||||
# Write trailer
|
||||
sort_version = 0
|
||||
trailer = (
|
||||
sort_version, offset_size, self._ref_size, num_objects,
|
||||
top_object, offset_table_offset
|
||||
)
|
||||
self._fp.write(struct.pack('>5xBBBQQQ', *trailer))
|
||||
|
||||
def _flatten(self, value):
|
||||
# First check if the object is in the object table, not used for
|
||||
# containers to ensure that two subcontainers with the same contents
|
||||
# will be serialized as distinct values.
|
||||
if isinstance(value, _scalars):
|
||||
if (type(value), value) in self._objtable:
|
||||
return
|
||||
|
||||
elif hasattr(plistlib, "Data") and isinstance(value, plistlib.Data):
|
||||
if (type(value.data), value.data) in self._objtable:
|
||||
return
|
||||
|
||||
elif id(value) in self._objidtable:
|
||||
return
|
||||
|
||||
# Add to objectreference map
|
||||
refnum = len(self._objlist)
|
||||
self._objlist.append(value)
|
||||
if isinstance(value, _scalars):
|
||||
self._objtable[(type(value), value)] = refnum
|
||||
elif hasattr(plistlib, "Data") and isinstance(value, plistlib.Data):
|
||||
self._objtable[(type(value.data), value.data)] = refnum
|
||||
else:
|
||||
self._objidtable[id(value)] = refnum
|
||||
|
||||
# And finally recurse into containers
|
||||
if isinstance(value, dict):
|
||||
keys = []
|
||||
values = []
|
||||
items = value.items()
|
||||
if self._sort_keys:
|
||||
items = sorted(items)
|
||||
|
||||
for k, v in items:
|
||||
if not isinstance(k, basestring):
|
||||
if self._skipkeys:
|
||||
continue
|
||||
raise TypeError("keys must be strings")
|
||||
keys.append(k)
|
||||
values.append(v)
|
||||
|
||||
for o in itertools.chain(keys, values):
|
||||
self._flatten(o)
|
||||
|
||||
elif isinstance(value, (list, tuple)):
|
||||
for o in value:
|
||||
self._flatten(o)
|
||||
|
||||
def _getrefnum(self, value):
|
||||
if isinstance(value, _scalars):
|
||||
return self._objtable[(type(value), value)]
|
||||
elif hasattr(plistlib, "Data") and isinstance(value, plistlib.Data):
|
||||
return self._objtable[(type(value.data), value.data)]
|
||||
else:
|
||||
return self._objidtable[id(value)]
|
||||
|
||||
def _write_size(self, token, size):
|
||||
if size < 15:
|
||||
self._fp.write(struct.pack('>B', token | size))
|
||||
|
||||
elif size < 1 << 8:
|
||||
self._fp.write(struct.pack('>BBB', token | 0xF, 0x10, size))
|
||||
|
||||
elif size < 1 << 16:
|
||||
self._fp.write(struct.pack('>BBH', token | 0xF, 0x11, size))
|
||||
|
||||
elif size < 1 << 32:
|
||||
self._fp.write(struct.pack('>BBL', token | 0xF, 0x12, size))
|
||||
|
||||
else:
|
||||
self._fp.write(struct.pack('>BBQ', token | 0xF, 0x13, size))
|
||||
|
||||
def _write_object(self, value):
|
||||
ref = self._getrefnum(value)
|
||||
self._object_offsets[ref] = self._fp.tell()
|
||||
if value is None:
|
||||
self._fp.write(b'\x00')
|
||||
|
||||
elif value is False:
|
||||
self._fp.write(b'\x08')
|
||||
|
||||
elif value is True:
|
||||
self._fp.write(b'\x09')
|
||||
|
||||
elif isinstance(value, int):
|
||||
if value < 0:
|
||||
try:
|
||||
self._fp.write(struct.pack('>Bq', 0x13, value))
|
||||
except struct.error:
|
||||
raise OverflowError(value) # from None
|
||||
elif value < 1 << 8:
|
||||
self._fp.write(struct.pack('>BB', 0x10, value))
|
||||
elif value < 1 << 16:
|
||||
self._fp.write(struct.pack('>BH', 0x11, value))
|
||||
elif value < 1 << 32:
|
||||
self._fp.write(struct.pack('>BL', 0x12, value))
|
||||
elif value < 1 << 63:
|
||||
self._fp.write(struct.pack('>BQ', 0x13, value))
|
||||
elif value < 1 << 64:
|
||||
self._fp.write(b'\x14' + value.to_bytes(16, 'big', signed=True))
|
||||
else:
|
||||
raise OverflowError(value)
|
||||
|
||||
elif isinstance(value, float):
|
||||
self._fp.write(struct.pack('>Bd', 0x23, value))
|
||||
|
||||
elif isinstance(value, datetime.datetime):
|
||||
f = (value - datetime.datetime(2001, 1, 1)).total_seconds()
|
||||
self._fp.write(struct.pack('>Bd', 0x33, f))
|
||||
|
||||
elif (_check_py3() and isinstance(value, (bytes, bytearray))) or (hasattr(plistlib, "Data") and isinstance(value, plistlib.Data)):
|
||||
if not isinstance(value, (bytes, bytearray)):
|
||||
value = value.data # Unpack it
|
||||
self._write_size(0x40, len(value))
|
||||
self._fp.write(value)
|
||||
|
||||
elif isinstance(value, basestring):
|
||||
try:
|
||||
t = value.encode('ascii')
|
||||
self._write_size(0x50, len(value))
|
||||
except UnicodeEncodeError:
|
||||
t = value.encode('utf-16be')
|
||||
self._write_size(0x60, len(t) // 2)
|
||||
self._fp.write(t)
|
||||
|
||||
elif isinstance(value, UID) or (hasattr(plistlib,"UID") and isinstance(value, plistlib.UID)):
|
||||
if value.data < 0:
|
||||
raise ValueError("UIDs must be positive")
|
||||
elif value.data < 1 << 8:
|
||||
self._fp.write(struct.pack('>BB', 0x80, value))
|
||||
elif value.data < 1 << 16:
|
||||
self._fp.write(struct.pack('>BH', 0x81, value))
|
||||
elif value.data < 1 << 32:
|
||||
self._fp.write(struct.pack('>BL', 0x83, value))
|
||||
# elif value.data < 1 << 64:
|
||||
# self._fp.write(struct.pack('>BQ', 0x87, value))
|
||||
else:
|
||||
raise OverflowError(value)
|
||||
|
||||
elif isinstance(value, (list, tuple)):
|
||||
refs = [self._getrefnum(o) for o in value]
|
||||
s = len(refs)
|
||||
self._write_size(0xA0, s)
|
||||
self._fp.write(struct.pack('>' + self._ref_format * s, *refs))
|
||||
|
||||
elif isinstance(value, dict):
|
||||
keyRefs, valRefs = [], []
|
||||
|
||||
if self._sort_keys:
|
||||
rootItems = sorted(value.items())
|
||||
else:
|
||||
rootItems = value.items()
|
||||
|
||||
for k, v in rootItems:
|
||||
if not isinstance(k, basestring):
|
||||
if self._skipkeys:
|
||||
continue
|
||||
raise TypeError("keys must be strings")
|
||||
keyRefs.append(self._getrefnum(k))
|
||||
valRefs.append(self._getrefnum(v))
|
||||
|
||||
s = len(keyRefs)
|
||||
self._write_size(0xD0, s)
|
||||
self._fp.write(struct.pack('>' + self._ref_format * s, *keyRefs))
|
||||
self._fp.write(struct.pack('>' + self._ref_format * s, *valRefs))
|
||||
|
||||
else:
|
||||
raise TypeError(value)
|
||||
69
ACPI/SSDTTime-master/Scripts/reveal.py
Normal file
69
ACPI/SSDTTime-master/Scripts/reveal.py
Normal file
@@ -0,0 +1,69 @@
|
||||
import sys, os
|
||||
from . import run
|
||||
|
||||
class Reveal:
|
||||
|
||||
def __init__(self):
|
||||
self.r = run.Run()
|
||||
return
|
||||
|
||||
def get_parent(self, path):
|
||||
return os.path.normpath(os.path.join(path, os.pardir))
|
||||
|
||||
def reveal(self, path, new_window = False):
|
||||
# Reveals the passed path in Finder - only works on macOS
|
||||
if not sys.platform == "darwin":
|
||||
return ("", "macOS Only", 1)
|
||||
if not path:
|
||||
# No path sent - nothing to reveal
|
||||
return ("", "No path specified", 1)
|
||||
# Build our script - then convert it to a single line task
|
||||
if not os.path.exists(path):
|
||||
# Not real - bail
|
||||
return ("", "{} - doesn't exist".format(path), 1)
|
||||
# Get the absolute path
|
||||
path = os.path.abspath(path)
|
||||
command = ["osascript"]
|
||||
if new_window:
|
||||
command.extend([
|
||||
"-e", "set p to \"{}\"".format(path.replace("\"", "\\\"")),
|
||||
"-e", "tell application \"Finder\"",
|
||||
"-e", "reveal POSIX file p as text",
|
||||
"-e", "activate",
|
||||
"-e", "end tell"
|
||||
])
|
||||
else:
|
||||
if path == self.get_parent(path):
|
||||
command.extend([
|
||||
"-e", "set p to \"{}\"".format(path.replace("\"", "\\\"")),
|
||||
"-e", "tell application \"Finder\"",
|
||||
"-e", "reopen",
|
||||
"-e", "activate",
|
||||
"-e", "set target of window 1 to (POSIX file p as text)",
|
||||
"-e", "end tell"
|
||||
])
|
||||
else:
|
||||
command.extend([
|
||||
"-e", "set o to \"{}\"".format(self.get_parent(path).replace("\"", "\\\"")),
|
||||
"-e", "set p to \"{}\"".format(path.replace("\"", "\\\"")),
|
||||
"-e", "tell application \"Finder\"",
|
||||
"-e", "reopen",
|
||||
"-e", "activate",
|
||||
"-e", "set target of window 1 to (POSIX file o as text)",
|
||||
"-e", "select (POSIX file p as text)",
|
||||
"-e", "end tell"
|
||||
])
|
||||
return self.r.run({"args" : command})
|
||||
|
||||
def notify(self, title = None, subtitle = None, sound = None):
|
||||
# Sends a notification
|
||||
if not title:
|
||||
return ("", "Malformed dict", 1)
|
||||
# Build our notification
|
||||
n_text = "display notification with title \"{}\"".format(title.replace("\"", "\\\""))
|
||||
if subtitle:
|
||||
n_text += " subtitle \"{}\"".format(subtitle.replace("\"", "\\\""))
|
||||
if sound:
|
||||
n_text += " sound name \"{}\"".format(sound.replace("\"", "\\\""))
|
||||
command = ["osascript", "-e", n_text]
|
||||
return self.r.run({"args" : command})
|
||||
151
ACPI/SSDTTime-master/Scripts/run.py
Normal file
151
ACPI/SSDTTime-master/Scripts/run.py
Normal file
@@ -0,0 +1,151 @@
|
||||
import sys, subprocess, time, threading, shlex
|
||||
try:
|
||||
from Queue import Queue, Empty
|
||||
except:
|
||||
from queue import Queue, Empty
|
||||
|
||||
ON_POSIX = 'posix' in sys.builtin_module_names
|
||||
|
||||
class Run:
|
||||
|
||||
def __init__(self):
|
||||
return
|
||||
|
||||
def _read_output(self, pipe, q):
|
||||
try:
|
||||
for line in iter(lambda: pipe.read(1), b''):
|
||||
q.put(line)
|
||||
except ValueError:
|
||||
pass
|
||||
pipe.close()
|
||||
|
||||
def _create_thread(self, output):
|
||||
# Creates a new queue and thread object to watch based on the output pipe sent
|
||||
q = Queue()
|
||||
t = threading.Thread(target=self._read_output, args=(output, q))
|
||||
t.daemon = True
|
||||
return (q,t)
|
||||
|
||||
def _stream_output(self, comm, shell = False):
|
||||
output = error = ""
|
||||
p = None
|
||||
try:
|
||||
if shell and type(comm) is list:
|
||||
comm = " ".join(shlex.quote(x) for x in comm)
|
||||
if not shell and type(comm) is str:
|
||||
comm = shlex.split(comm)
|
||||
p = subprocess.Popen(comm, shell=shell, stdout=subprocess.PIPE, stderr=subprocess.PIPE, bufsize=0, universal_newlines=True, close_fds=ON_POSIX)
|
||||
# Setup the stdout thread/queue
|
||||
q,t = self._create_thread(p.stdout)
|
||||
qe,te = self._create_thread(p.stderr)
|
||||
# Start both threads
|
||||
t.start()
|
||||
te.start()
|
||||
|
||||
while True:
|
||||
c = z = ""
|
||||
try: c = q.get_nowait()
|
||||
except Empty: pass
|
||||
else:
|
||||
sys.stdout.write(c)
|
||||
output += c
|
||||
sys.stdout.flush()
|
||||
try: z = qe.get_nowait()
|
||||
except Empty: pass
|
||||
else:
|
||||
sys.stderr.write(z)
|
||||
error += z
|
||||
sys.stderr.flush()
|
||||
if not c==z=="": continue # Keep going until empty
|
||||
# No output - see if still running
|
||||
p.poll()
|
||||
if p.returncode != None:
|
||||
# Subprocess ended
|
||||
break
|
||||
# No output, but subprocess still running - stall for 20ms
|
||||
time.sleep(0.02)
|
||||
|
||||
o, e = p.communicate()
|
||||
return (output+o, error+e, p.returncode)
|
||||
except:
|
||||
if p:
|
||||
try: o, e = p.communicate()
|
||||
except: o = e = ""
|
||||
return (output+o, error+e, p.returncode)
|
||||
return ("", "Command not found!", 1)
|
||||
|
||||
def _decode(self, value, encoding="utf-8", errors="ignore"):
|
||||
# Helper method to only decode if bytes type
|
||||
if sys.version_info >= (3,0) and isinstance(value, bytes):
|
||||
return value.decode(encoding,errors)
|
||||
return value
|
||||
|
||||
def _run_command(self, comm, shell = False):
|
||||
c = None
|
||||
try:
|
||||
if shell and type(comm) is list:
|
||||
comm = " ".join(shlex.quote(x) for x in comm)
|
||||
if not shell and type(comm) is str:
|
||||
comm = shlex.split(comm)
|
||||
p = subprocess.Popen(comm, shell=shell, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
||||
c = p.communicate()
|
||||
except:
|
||||
if c == None:
|
||||
return ("", "Command not found!", 1)
|
||||
return (self._decode(c[0]), self._decode(c[1]), p.returncode)
|
||||
|
||||
def run(self, command_list, leave_on_fail = False):
|
||||
# Command list should be an array of dicts
|
||||
if type(command_list) is dict:
|
||||
# We only have one command
|
||||
command_list = [command_list]
|
||||
output_list = []
|
||||
for comm in command_list:
|
||||
args = comm.get("args", [])
|
||||
shell = comm.get("shell", False)
|
||||
stream = comm.get("stream", False)
|
||||
sudo = comm.get("sudo", False)
|
||||
stdout = comm.get("stdout", False)
|
||||
stderr = comm.get("stderr", False)
|
||||
mess = comm.get("message", None)
|
||||
show = comm.get("show", False)
|
||||
|
||||
if not mess == None:
|
||||
print(mess)
|
||||
|
||||
if not len(args):
|
||||
# nothing to process
|
||||
continue
|
||||
if sudo:
|
||||
# Check if we have sudo
|
||||
out = self._run_command(["which", "sudo"])
|
||||
if "sudo" in out[0]:
|
||||
# Can sudo
|
||||
if type(args) is list:
|
||||
args.insert(0, out[0].replace("\n", "")) # add to start of list
|
||||
elif type(args) is str:
|
||||
args = out[0].replace("\n", "") + " " + args # add to start of string
|
||||
|
||||
if show:
|
||||
print(" ".join(args))
|
||||
|
||||
if stream:
|
||||
# Stream it!
|
||||
out = self._stream_output(args, shell)
|
||||
else:
|
||||
# Just run and gather output
|
||||
out = self._run_command(args, shell)
|
||||
if stdout and len(out[0]):
|
||||
print(out[0])
|
||||
if stderr and len(out[1]):
|
||||
print(out[1])
|
||||
# Append output
|
||||
output_list.append(out)
|
||||
# Check for errors
|
||||
if leave_on_fail and out[2] != 0:
|
||||
# Got an error - leave
|
||||
break
|
||||
if len(output_list) == 1:
|
||||
# We only ran one command - just return that output
|
||||
return output_list[0]
|
||||
return output_list
|
||||
263
ACPI/SSDTTime-master/Scripts/utils.py
Normal file
263
ACPI/SSDTTime-master/Scripts/utils.py
Normal file
@@ -0,0 +1,263 @@
|
||||
import sys, os, time, re, json, datetime, ctypes, subprocess
|
||||
|
||||
if os.name == "nt":
|
||||
# Windows
|
||||
import msvcrt
|
||||
else:
|
||||
# Not Windows \o/
|
||||
import select
|
||||
|
||||
class Utils:
|
||||
|
||||
def __init__(self, name = "Python Script"):
|
||||
self.name = name
|
||||
# Init our colors before we need to print anything
|
||||
cwd = os.getcwd()
|
||||
os.chdir(os.path.dirname(os.path.realpath(__file__)))
|
||||
if os.path.exists("colors.json"):
|
||||
self.colors_dict = json.load(open("colors.json"))
|
||||
else:
|
||||
self.colors_dict = {}
|
||||
os.chdir(cwd)
|
||||
|
||||
def check_admin(self):
|
||||
# Returns whether or not we're admin
|
||||
try:
|
||||
is_admin = os.getuid() == 0
|
||||
except AttributeError:
|
||||
is_admin = ctypes.windll.shell32.IsUserAnAdmin() != 0
|
||||
return is_admin
|
||||
|
||||
def elevate(self, file):
|
||||
# Runs the passed file as admin
|
||||
if self.check_admin():
|
||||
return
|
||||
if os.name == "nt":
|
||||
ctypes.windll.shell32.ShellExecuteW(None, "runas", '"{}"'.format(sys.executable), '"{}"'.format(file), None, 1)
|
||||
else:
|
||||
try:
|
||||
p = subprocess.Popen(["which", "sudo"], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
||||
c = p.communicate()[0].decode("utf-8", "ignore").replace("\n", "")
|
||||
os.execv(c, [ sys.executable, 'python'] + sys.argv)
|
||||
except:
|
||||
exit(1)
|
||||
|
||||
def compare_versions(self, vers1, vers2, **kwargs):
|
||||
# Helper method to compare ##.## strings
|
||||
#
|
||||
# vers1 < vers2 = True
|
||||
# vers1 = vers2 = None
|
||||
# vers1 > vers2 = False
|
||||
|
||||
# Sanitize the pads
|
||||
pad = str(kwargs.get("pad", ""))
|
||||
sep = str(kwargs.get("separator", "."))
|
||||
|
||||
ignore_case = kwargs.get("ignore_case", True)
|
||||
|
||||
# Cast as strings
|
||||
vers1 = str(vers1)
|
||||
vers2 = str(vers2)
|
||||
|
||||
if ignore_case:
|
||||
vers1 = vers1.lower()
|
||||
vers2 = vers2.lower()
|
||||
|
||||
# Split and pad lists
|
||||
v1_parts, v2_parts = self.pad_length(vers1.split(sep), vers2.split(sep))
|
||||
|
||||
# Iterate and compare
|
||||
for i in range(len(v1_parts)):
|
||||
# Remove non-numeric
|
||||
v1 = ''.join(c.lower() for c in v1_parts[i] if c.isalnum())
|
||||
v2 = ''.join(c.lower() for c in v2_parts[i] if c.isalnum())
|
||||
# Equalize the lengths
|
||||
v1, v2 = self.pad_length(v1, v2)
|
||||
# Compare
|
||||
if str(v1) < str(v2):
|
||||
return True
|
||||
elif str(v1) > str(v2):
|
||||
return False
|
||||
# Never differed - return None, must be equal
|
||||
return None
|
||||
|
||||
def pad_length(self, var1, var2, pad = "0"):
|
||||
# Pads the vars on the left side to make them equal length
|
||||
pad = "0" if len(str(pad)) < 1 else str(pad)[0]
|
||||
if not type(var1) == type(var2):
|
||||
# Type mismatch! Just return what we got
|
||||
return (var1, var2)
|
||||
if len(var1) < len(var2):
|
||||
if type(var1) is list:
|
||||
var1.extend([str(pad) for x in range(len(var2) - len(var1))])
|
||||
else:
|
||||
var1 = "{}{}".format((pad*(len(var2)-len(var1))), var1)
|
||||
elif len(var2) < len(var1):
|
||||
if type(var2) is list:
|
||||
var2.extend([str(pad) for x in range(len(var1) - len(var2))])
|
||||
else:
|
||||
var2 = "{}{}".format((pad*(len(var1)-len(var2))), var2)
|
||||
return (var1, var2)
|
||||
|
||||
def check_path(self, path):
|
||||
# Let's loop until we either get a working path, or no changes
|
||||
test_path = path
|
||||
last_path = None
|
||||
while True:
|
||||
# Bail if we've looped at least once and the path didn't change
|
||||
if last_path != None and last_path == test_path: return None
|
||||
last_path = test_path
|
||||
# Check if we stripped everything out
|
||||
if not len(test_path): return None
|
||||
# Check if we have a valid path
|
||||
if os.path.exists(test_path):
|
||||
return os.path.abspath(test_path)
|
||||
# Check for quotes
|
||||
if test_path[0] == test_path[-1] and test_path[0] in ('"',"'"):
|
||||
test_path = test_path[1:-1]
|
||||
continue
|
||||
# Check for a tilde and expand if needed
|
||||
if test_path[0] == "~":
|
||||
tilde_expanded = os.path.expanduser(test_path)
|
||||
if tilde_expanded != test_path:
|
||||
# Got a change
|
||||
test_path = tilde_expanded
|
||||
continue
|
||||
# Let's check for spaces - strip from the left first, then the right
|
||||
if test_path[0] in (" ","\t"):
|
||||
test_path = test_path[1:]
|
||||
continue
|
||||
if test_path[-1] in (" ","\t"):
|
||||
test_path = test_path[:-1]
|
||||
continue
|
||||
# Maybe we have escapes to handle?
|
||||
test_path = "\\".join([x.replace("\\", "") for x in test_path.split("\\\\")])
|
||||
|
||||
def grab(self, prompt, **kwargs):
|
||||
# Takes a prompt, a default, and a timeout and shows it with that timeout
|
||||
# returning the result
|
||||
timeout = kwargs.get("timeout",0)
|
||||
default = kwargs.get("default","")
|
||||
# If we don't have a timeout - then skip the timed sections
|
||||
if timeout <= 0:
|
||||
try:
|
||||
if sys.version_info >= (3, 0):
|
||||
return input(prompt)
|
||||
else:
|
||||
return str(raw_input(prompt))
|
||||
except EOFError:
|
||||
return default
|
||||
# Write our prompt
|
||||
sys.stdout.write(prompt)
|
||||
sys.stdout.flush()
|
||||
if os.name == "nt":
|
||||
start_time = time.time()
|
||||
i = ''
|
||||
while True:
|
||||
if msvcrt.kbhit():
|
||||
c = msvcrt.getche()
|
||||
if ord(c) == 13: # enter_key
|
||||
break
|
||||
elif ord(c) >= 32: # space_char
|
||||
i += c.decode() if sys.version_info >= (3,0) and isinstance(c,bytes) else c
|
||||
else:
|
||||
time.sleep(0.02) # Delay for 20ms to prevent CPU workload
|
||||
if len(i) == 0 and (time.time() - start_time) > timeout:
|
||||
break
|
||||
else:
|
||||
i, o, e = select.select( [sys.stdin], [], [], timeout )
|
||||
if i:
|
||||
i = sys.stdin.readline().strip()
|
||||
print('') # needed to move to next line
|
||||
if len(i) > 0:
|
||||
return i
|
||||
else:
|
||||
return default
|
||||
|
||||
def cls(self):
|
||||
if os.name == "nt":
|
||||
os.system("cls")
|
||||
elif os.environ.get("TERM"):
|
||||
os.system("clear")
|
||||
|
||||
def cprint(self, message, **kwargs):
|
||||
strip_colors = kwargs.get("strip_colors", False)
|
||||
if os.name == "nt":
|
||||
strip_colors = True
|
||||
reset = u"\u001b[0m"
|
||||
# Requires sys import
|
||||
for c in self.colors:
|
||||
if strip_colors:
|
||||
message = message.replace(c["find"], "")
|
||||
else:
|
||||
message = message.replace(c["find"], c["replace"])
|
||||
if strip_colors:
|
||||
return message
|
||||
sys.stdout.write(message)
|
||||
print(reset)
|
||||
|
||||
# Needs work to resize the string if color chars exist
|
||||
'''# Header drawing method
|
||||
def head(self, text = None, width = 55):
|
||||
if text == None:
|
||||
text = self.name
|
||||
self.cls()
|
||||
print(" {}".format("#"*width))
|
||||
len_text = self.cprint(text, strip_colors=True)
|
||||
mid_len = int(round(width/2-len(len_text)/2)-2)
|
||||
middle = " #{}{}{}#".format(" "*mid_len, len_text, " "*((width - mid_len - len(len_text))-2))
|
||||
if len(middle) > width+1:
|
||||
# Get the difference
|
||||
di = len(middle) - width
|
||||
# Add the padding for the ...#
|
||||
di += 3
|
||||
# Trim the string
|
||||
middle = middle[:-di]
|
||||
newlen = len(middle)
|
||||
middle += "...#"
|
||||
find_list = [ c["find"] for c in self.colors ]
|
||||
|
||||
# Translate colored string to len
|
||||
middle = middle.replace(len_text, text + self.rt_color) # always reset just in case
|
||||
self.cprint(middle)
|
||||
print("#"*width)'''
|
||||
|
||||
# Header drawing method
|
||||
def head(self, text = None, width = 55):
|
||||
if text == None:
|
||||
text = self.name
|
||||
self.cls()
|
||||
print(" {}".format("#"*width))
|
||||
mid_len = int(round(width/2-len(text)/2)-2)
|
||||
middle = " #{}{}{}#".format(" "*mid_len, text, " "*((width - mid_len - len(text))-2))
|
||||
if len(middle) > width+1:
|
||||
# Get the difference
|
||||
di = len(middle) - width
|
||||
# Add the padding for the ...#
|
||||
di += 3
|
||||
# Trim the string
|
||||
middle = middle[:-di] + "...#"
|
||||
print(middle)
|
||||
print("#"*width)
|
||||
|
||||
def resize(self, width, height):
|
||||
print('\033[8;{};{}t'.format(height, width))
|
||||
|
||||
def custom_quit(self):
|
||||
self.head()
|
||||
print("by CorpNewt\n")
|
||||
print("Thanks for testing it out, for bugs/comments/complaints")
|
||||
print("send me a message on Reddit, or check out my GitHub:\n")
|
||||
print("www.reddit.com/u/corpnewt")
|
||||
print("www.github.com/corpnewt\n")
|
||||
# Get the time and wish them a good morning, afternoon, evening, and night
|
||||
hr = datetime.datetime.now().time().hour
|
||||
if hr > 3 and hr < 12:
|
||||
print("Have a nice morning!\n\n")
|
||||
elif hr >= 12 and hr < 17:
|
||||
print("Have a nice afternoon!\n\n")
|
||||
elif hr >= 17 and hr < 21:
|
||||
print("Have a nice evening!\n\n")
|
||||
else:
|
||||
print("Have a nice night!\n\n")
|
||||
exit(0)
|
||||
1
EFI/BOOT/.contentFlavour
Normal file
1
EFI/BOOT/.contentFlavour
Normal file
@@ -0,0 +1 @@
|
||||
OpenCore
|
||||
1
EFI/BOOT/.contentVisibility
Normal file
1
EFI/BOOT/.contentVisibility
Normal file
@@ -0,0 +1 @@
|
||||
Disabled
|
||||
BIN
EFI/BOOT/BOOTx64.efi
Normal file
BIN
EFI/BOOT/BOOTx64.efi
Normal file
Binary file not shown.
1
EFI/OC/.contentFlavour
Normal file
1
EFI/OC/.contentFlavour
Normal file
@@ -0,0 +1 @@
|
||||
OpenCore
|
||||
1
EFI/OC/.contentVisibility
Normal file
1
EFI/OC/.contentVisibility
Normal file
@@ -0,0 +1 @@
|
||||
Disabled
|
||||
BIN
EFI/OC/ACPI/SSDT-BAT.aml
Normal file
BIN
EFI/OC/ACPI/SSDT-BAT.aml
Normal file
Binary file not shown.
BIN
EFI/OC/ACPI/SSDT-BATC.aml
Normal file
BIN
EFI/OC/ACPI/SSDT-BATC.aml
Normal file
Binary file not shown.
BIN
EFI/OC/ACPI/SSDT-BKey.aml
Normal file
BIN
EFI/OC/ACPI/SSDT-BKey.aml
Normal file
Binary file not shown.
BIN
EFI/OC/ACPI/SSDT-DDGPU.aml
Normal file
BIN
EFI/OC/ACPI/SSDT-DDGPU.aml
Normal file
Binary file not shown.
BIN
EFI/OC/ACPI/SSDT-EHC1.aml
Normal file
BIN
EFI/OC/ACPI/SSDT-EHC1.aml
Normal file
Binary file not shown.
BIN
EFI/OC/ACPI/SSDT-EXT3-LedReset.aml
Normal file
BIN
EFI/OC/ACPI/SSDT-EXT3-LedReset.aml
Normal file
Binary file not shown.
BIN
EFI/OC/ACPI/SSDT-EXT4-WakeScreen.aml
Normal file
BIN
EFI/OC/ACPI/SSDT-EXT4-WakeScreen.aml
Normal file
Binary file not shown.
BIN
EFI/OC/ACPI/SSDT-HPET_RTC_TIMR-Fix.aml
Normal file
BIN
EFI/OC/ACPI/SSDT-HPET_RTC_TIMR-Fix.aml
Normal file
Binary file not shown.
BIN
EFI/OC/ACPI/SSDT-IPIC.aml
Normal file
BIN
EFI/OC/ACPI/SSDT-IPIC.aml
Normal file
Binary file not shown.
BIN
EFI/OC/ACPI/SSDT-MCHC.aml
Normal file
BIN
EFI/OC/ACPI/SSDT-MCHC.aml
Normal file
Binary file not shown.
BIN
EFI/OC/ACPI/SSDT-PCI0.EXP1-Disbale.aml
Normal file
BIN
EFI/OC/ACPI/SSDT-PCI0.EXP1-Disbale.aml
Normal file
Binary file not shown.
BIN
EFI/OC/ACPI/SSDT-PLUG.aml
Normal file
BIN
EFI/OC/ACPI/SSDT-PLUG.aml
Normal file
Binary file not shown.
BIN
EFI/OC/ACPI/SSDT-PNLF.aml
Normal file
BIN
EFI/OC/ACPI/SSDT-PNLF.aml
Normal file
Binary file not shown.
BIN
EFI/OC/ACPI/SSDT-PTSWAK.aml
Normal file
BIN
EFI/OC/ACPI/SSDT-PTSWAK.aml
Normal file
Binary file not shown.
BIN
EFI/OC/ACPI/SSDT-PWRB.aml
Normal file
BIN
EFI/OC/ACPI/SSDT-PWRB.aml
Normal file
Binary file not shown.
BIN
EFI/OC/ACPI/SSDT-TEMPToFans.aml
Normal file
BIN
EFI/OC/ACPI/SSDT-TEMPToFans.aml
Normal file
Binary file not shown.
BIN
EFI/OC/ACPI/SSDT-XHCI.aml
Normal file
BIN
EFI/OC/ACPI/SSDT-XHCI.aml
Normal file
Binary file not shown.
BIN
EFI/OC/Drivers/HfsPlus.efi
Normal file
BIN
EFI/OC/Drivers/HfsPlus.efi
Normal file
Binary file not shown.
BIN
EFI/OC/Drivers/OpenRuntime.efi
Normal file
BIN
EFI/OC/Drivers/OpenRuntime.efi
Normal file
Binary file not shown.
16818
EFI/OC/Kexts/AppleALC.kext/Contents/Info.plist
Normal file
16818
EFI/OC/Kexts/AppleALC.kext/Contents/Info.plist
Normal file
File diff suppressed because it is too large
Load Diff
BIN
EFI/OC/Kexts/AppleALC.kext/Contents/MacOS/AppleALC
Normal file
BIN
EFI/OC/Kexts/AppleALC.kext/Contents/MacOS/AppleALC
Normal file
Binary file not shown.
81
EFI/OC/Kexts/BrightnessKeys.kext/Contents/Info.plist
Normal file
81
EFI/OC/Kexts/BrightnessKeys.kext/Contents/Info.plist
Normal file
@@ -0,0 +1,81 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>BuildMachineOSBuild</key>
|
||||
<string>21G419</string>
|
||||
<key>CFBundleDevelopmentRegion</key>
|
||||
<string>en</string>
|
||||
<key>CFBundleExecutable</key>
|
||||
<string>BrightnessKeys</string>
|
||||
<key>CFBundleIdentifier</key>
|
||||
<string>as.acidanthera.BrightnessKeys</string>
|
||||
<key>CFBundleInfoDictionaryVersion</key>
|
||||
<string>6.0</string>
|
||||
<key>CFBundleName</key>
|
||||
<string>BrightnessKeys</string>
|
||||
<key>CFBundlePackageType</key>
|
||||
<string>KEXT</string>
|
||||
<key>CFBundleSupportedPlatforms</key>
|
||||
<array>
|
||||
<string>MacOSX</string>
|
||||
</array>
|
||||
<key>CFBundleVersion</key>
|
||||
<string>1.0.3</string>
|
||||
<key>DTCompiler</key>
|
||||
<string>com.apple.compilers.llvm.clang.1_0</string>
|
||||
<key>DTPlatformBuild</key>
|
||||
<string>13F100</string>
|
||||
<key>DTPlatformName</key>
|
||||
<string>macosx</string>
|
||||
<key>DTPlatformVersion</key>
|
||||
<string>12.3</string>
|
||||
<key>DTSDKBuild</key>
|
||||
<string>21E226</string>
|
||||
<key>DTSDKName</key>
|
||||
<string>macosx12.3</string>
|
||||
<key>DTXcode</key>
|
||||
<string>1341</string>
|
||||
<key>DTXcodeBuild</key>
|
||||
<string>13F100</string>
|
||||
<key>IOKitPersonalities</key>
|
||||
<dict>
|
||||
<key>BrightnessKeys</key>
|
||||
<dict>
|
||||
<key>CFBundleIdentifier</key>
|
||||
<string>as.acidanthera.BrightnessKeys</string>
|
||||
<key>IOClass</key>
|
||||
<string>BrightnessKeys</string>
|
||||
<key>IOMatchCategory</key>
|
||||
<string>BrightnessKeys</string>
|
||||
<key>IOProviderClass</key>
|
||||
<string>IOResources</string>
|
||||
<key>IOResourceMatch</key>
|
||||
<string>IOKit</string>
|
||||
</dict>
|
||||
</dict>
|
||||
<key>LSMinimumSystemVersion</key>
|
||||
<string>10.11</string>
|
||||
<key>OSBundleLibraries</key>
|
||||
<dict>
|
||||
<key>as.vit9696.Lilu</key>
|
||||
<string>1.2.0</string>
|
||||
<key>com.apple.iokit.IOACPIFamily</key>
|
||||
<string>1.0.0d1</string>
|
||||
<key>com.apple.iokit.IOHIDFamily</key>
|
||||
<string>1.0.0b1</string>
|
||||
<key>com.apple.kpi.bsd</key>
|
||||
<string>8.0.0</string>
|
||||
<key>com.apple.kpi.iokit</key>
|
||||
<string>8.0.0</string>
|
||||
<key>com.apple.kpi.libkern</key>
|
||||
<string>8.0.0</string>
|
||||
<key>com.apple.kpi.mach</key>
|
||||
<string>8.0.0</string>
|
||||
<key>com.apple.kpi.unsupported</key>
|
||||
<string>8.0.0</string>
|
||||
</dict>
|
||||
<key>OSBundleRequired</key>
|
||||
<string>Console</string>
|
||||
</dict>
|
||||
</plist>
|
||||
BIN
EFI/OC/Kexts/BrightnessKeys.kext/Contents/MacOS/BrightnessKeys
Normal file
BIN
EFI/OC/Kexts/BrightnessKeys.kext/Contents/MacOS/BrightnessKeys
Normal file
Binary file not shown.
87
EFI/OC/Kexts/HibernationFixup.kext/Contents/Info.plist
Normal file
87
EFI/OC/Kexts/HibernationFixup.kext/Contents/Info.plist
Normal file
@@ -0,0 +1,87 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>BuildMachineOSBuild</key>
|
||||
<string>23H626</string>
|
||||
<key>CFBundleDevelopmentRegion</key>
|
||||
<string>en</string>
|
||||
<key>CFBundleExecutable</key>
|
||||
<string>HibernationFixup</string>
|
||||
<key>CFBundleIdentifier</key>
|
||||
<string>as.lvs1974.HibernationFixup</string>
|
||||
<key>CFBundleInfoDictionaryVersion</key>
|
||||
<string>6.0</string>
|
||||
<key>CFBundleName</key>
|
||||
<string>HibernationFixup</string>
|
||||
<key>CFBundlePackageType</key>
|
||||
<string>KEXT</string>
|
||||
<key>CFBundleShortVersionString</key>
|
||||
<string>1.5.4</string>
|
||||
<key>CFBundleSignature</key>
|
||||
<string>????</string>
|
||||
<key>CFBundleSupportedPlatforms</key>
|
||||
<array>
|
||||
<string>MacOSX</string>
|
||||
</array>
|
||||
<key>CFBundleVersion</key>
|
||||
<string>1.5.4</string>
|
||||
<key>DTCompiler</key>
|
||||
<string>com.apple.compilers.llvm.clang.1_0</string>
|
||||
<key>DTPlatformBuild</key>
|
||||
<string></string>
|
||||
<key>DTPlatformName</key>
|
||||
<string>macosx</string>
|
||||
<key>DTPlatformVersion</key>
|
||||
<string>14.2</string>
|
||||
<key>DTSDKBuild</key>
|
||||
<string>23C53</string>
|
||||
<key>DTSDKName</key>
|
||||
<string>macosx14.2</string>
|
||||
<key>DTXcode</key>
|
||||
<string>1520</string>
|
||||
<key>DTXcodeBuild</key>
|
||||
<string>15C500b</string>
|
||||
<key>IOKitPersonalities</key>
|
||||
<dict>
|
||||
<key>as.lvs1974.HibernationFixup</key>
|
||||
<dict>
|
||||
<key>CFBundleIdentifier</key>
|
||||
<string>as.lvs1974.HibernationFixup</string>
|
||||
<key>IOClass</key>
|
||||
<string>HibernationFixup</string>
|
||||
<key>IOMatchCategory</key>
|
||||
<string>HibernationFixup</string>
|
||||
<key>IOProviderClass</key>
|
||||
<string>IOResources</string>
|
||||
<key>IOResourceMatch</key>
|
||||
<string>IOKit</string>
|
||||
</dict>
|
||||
</dict>
|
||||
<key>LSMinimumSystemVersion</key>
|
||||
<string>10.8</string>
|
||||
<key>NSHumanReadableCopyright</key>
|
||||
<string>Copyright © 2017 lvs1974. All rights reserved.</string>
|
||||
<key>OSBundleCompatibleVersion</key>
|
||||
<string>1.0</string>
|
||||
<key>OSBundleLibraries</key>
|
||||
<dict>
|
||||
<key>as.vit9696.Lilu</key>
|
||||
<string>1.2.4</string>
|
||||
<key>com.apple.kpi.bsd</key>
|
||||
<string>12.0.0</string>
|
||||
<key>com.apple.kpi.dsep</key>
|
||||
<string>12.0.0</string>
|
||||
<key>com.apple.kpi.iokit</key>
|
||||
<string>12.0.0</string>
|
||||
<key>com.apple.kpi.libkern</key>
|
||||
<string>12.0.0</string>
|
||||
<key>com.apple.kpi.mach</key>
|
||||
<string>12.0.0</string>
|
||||
<key>com.apple.kpi.unsupported</key>
|
||||
<string>12.0.0</string>
|
||||
</dict>
|
||||
<key>OSBundleRequired</key>
|
||||
<string>Root</string>
|
||||
</dict>
|
||||
</plist>
|
||||
Binary file not shown.
110
EFI/OC/Kexts/IntelMausi.kext/Contents/Info.plist
Normal file
110
EFI/OC/Kexts/IntelMausi.kext/Contents/Info.plist
Normal file
@@ -0,0 +1,110 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>BuildMachineOSBuild</key>
|
||||
<string>23H222</string>
|
||||
<key>CFBundleDevelopmentRegion</key>
|
||||
<string>English</string>
|
||||
<key>CFBundleExecutable</key>
|
||||
<string>IntelMausi</string>
|
||||
<key>CFBundleIdentifier</key>
|
||||
<string>as.acidanthera.mieze.IntelMausi</string>
|
||||
<key>CFBundleInfoDictionaryVersion</key>
|
||||
<string>6.0</string>
|
||||
<key>CFBundleName</key>
|
||||
<string>IntelMausi</string>
|
||||
<key>CFBundlePackageType</key>
|
||||
<string>KEXT</string>
|
||||
<key>CFBundleShortVersionString</key>
|
||||
<string>1.0.8</string>
|
||||
<key>CFBundleSignature</key>
|
||||
<string>????</string>
|
||||
<key>CFBundleSupportedPlatforms</key>
|
||||
<array>
|
||||
<string>MacOSX</string>
|
||||
</array>
|
||||
<key>CFBundleVersion</key>
|
||||
<string>1.0.8</string>
|
||||
<key>DTCompiler</key>
|
||||
<string>com.apple.compilers.llvm.clang.1_0</string>
|
||||
<key>DTPlatformBuild</key>
|
||||
<string></string>
|
||||
<key>DTPlatformName</key>
|
||||
<string>macosx</string>
|
||||
<key>DTPlatformVersion</key>
|
||||
<string>14.2</string>
|
||||
<key>DTSDKBuild</key>
|
||||
<string>23C53</string>
|
||||
<key>DTSDKName</key>
|
||||
<string>macosx14.2</string>
|
||||
<key>DTXcode</key>
|
||||
<string>1520</string>
|
||||
<key>DTXcodeBuild</key>
|
||||
<string>15C500b</string>
|
||||
<key>IOKitPersonalities</key>
|
||||
<dict>
|
||||
<key>IntelMausi</key>
|
||||
<dict>
|
||||
<key>CFBundleIdentifier</key>
|
||||
<string>as.acidanthera.mieze.IntelMausi</string>
|
||||
<key>Driver Parameters</key>
|
||||
<dict>
|
||||
<key>enableCSO6</key>
|
||||
<true/>
|
||||
<key>enableWakeOnAddrMatch</key>
|
||||
<false/>
|
||||
<key>maxIntrRate10</key>
|
||||
<integer>3000</integer>
|
||||
<key>maxIntrRate100</key>
|
||||
<integer>5000</integer>
|
||||
<key>maxIntrRate1000</key>
|
||||
<integer>8000</integer>
|
||||
<key>rxAbsTime10</key>
|
||||
<integer>0</integer>
|
||||
<key>rxAbsTime100</key>
|
||||
<integer>0</integer>
|
||||
<key>rxAbsTime1000</key>
|
||||
<integer>10</integer>
|
||||
<key>rxDelayTime10</key>
|
||||
<integer>0</integer>
|
||||
<key>rxDelayTime100</key>
|
||||
<integer>0</integer>
|
||||
<key>rxDelayTime1000</key>
|
||||
<integer>0</integer>
|
||||
</dict>
|
||||
<key>Driver_Version</key>
|
||||
<string>1.0.8</string>
|
||||
<key>IOClass</key>
|
||||
<string>IntelMausi</string>
|
||||
<key>IOPCIMatch</key>
|
||||
<string>0x10EA8086 0x10EB8086 0x10EF8086 0x10F08086 0x15028086 0x15038086 0x153A8086 0x153B8086 0x155A8086 0x15598086 0x15A08086 0x15A18086 0x15A28086 0x15A38086 0x156F8086 0x15708086 0x15B78086 0x15B88086 0x15D78086 0x15D88086 0x15E38086 0x15D68086 0x15BD8086 0x15BE8086 0x15BB8086 0x15BC8086 0x15DF8086 0x15E08086 0x15E18086 0x15E28086 0x15B98086 0x0D4E8086 0x0D4F8086 0x0D4C8086 0x0D4D8086 0x0D538086 0x0D558086 0x15FB8086 0x15FC8086 0x15F98086 0x15FA8086 0x15F48086 0x15F58086 0x1A1E8086 0x1A1F8086 0x1A1C8086 0x1A1D8086 0x550A8086 0x550B8086 0x550C8086 0x550D8086</string>
|
||||
<key>IOProbeScore</key>
|
||||
<integer>1000</integer>
|
||||
<key>IOProviderClass</key>
|
||||
<string>IOPCIDevice</string>
|
||||
</dict>
|
||||
</dict>
|
||||
<key>LSMinimumSystemVersion</key>
|
||||
<string>10.9</string>
|
||||
<key>NSHumanReadableCopyright</key>
|
||||
<string>Copyright © 2014 Laura Müller. All rights reserved.</string>
|
||||
<key>OSBundleLibraries</key>
|
||||
<dict>
|
||||
<key>com.apple.iokit.IONetworkingFamily</key>
|
||||
<string>1.5.0</string>
|
||||
<key>com.apple.iokit.IOPCIFamily</key>
|
||||
<string>1.7</string>
|
||||
<key>com.apple.kpi.bsd</key>
|
||||
<string>8.10.0</string>
|
||||
<key>com.apple.kpi.iokit</key>
|
||||
<string>8.10.0</string>
|
||||
<key>com.apple.kpi.libkern</key>
|
||||
<string>8.10.0</string>
|
||||
<key>com.apple.kpi.mach</key>
|
||||
<string>8.10.0</string>
|
||||
</dict>
|
||||
<key>OSBundleRequired</key>
|
||||
<string>Network-Root</string>
|
||||
</dict>
|
||||
</plist>
|
||||
BIN
EFI/OC/Kexts/IntelMausi.kext/Contents/MacOS/IntelMausi
Normal file
BIN
EFI/OC/Kexts/IntelMausi.kext/Contents/MacOS/IntelMausi
Normal file
Binary file not shown.
100
EFI/OC/Kexts/Lilu.kext/Contents/Info.plist
Normal file
100
EFI/OC/Kexts/Lilu.kext/Contents/Info.plist
Normal file
@@ -0,0 +1,100 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>BuildMachineOSBuild</key>
|
||||
<string>23H626</string>
|
||||
<key>CFBundleDevelopmentRegion</key>
|
||||
<string>en</string>
|
||||
<key>CFBundleExecutable</key>
|
||||
<string>Lilu</string>
|
||||
<key>CFBundleIdentifier</key>
|
||||
<string>as.vit9696.Lilu</string>
|
||||
<key>CFBundleInfoDictionaryVersion</key>
|
||||
<string>6.0</string>
|
||||
<key>CFBundleName</key>
|
||||
<string>Lilu</string>
|
||||
<key>CFBundlePackageType</key>
|
||||
<string>KEXT</string>
|
||||
<key>CFBundleShortVersionString</key>
|
||||
<string>1.7.1</string>
|
||||
<key>CFBundleSignature</key>
|
||||
<string>????</string>
|
||||
<key>CFBundleSupportedPlatforms</key>
|
||||
<array>
|
||||
<string>MacOSX</string>
|
||||
</array>
|
||||
<key>CFBundleVersion</key>
|
||||
<string>1.7.1</string>
|
||||
<key>DTCompiler</key>
|
||||
<string>com.apple.compilers.llvm.clang.1_0</string>
|
||||
<key>DTPlatformBuild</key>
|
||||
<string></string>
|
||||
<key>DTPlatformName</key>
|
||||
<string>macosx</string>
|
||||
<key>DTPlatformVersion</key>
|
||||
<string>14.2</string>
|
||||
<key>DTSDKBuild</key>
|
||||
<string>23C53</string>
|
||||
<key>DTSDKName</key>
|
||||
<string>macosx14.2</string>
|
||||
<key>DTXcode</key>
|
||||
<string>1520</string>
|
||||
<key>DTXcodeBuild</key>
|
||||
<string>15C500b</string>
|
||||
<key>IOKitPersonalities</key>
|
||||
<dict>
|
||||
<key>as.vit9696.Lilu</key>
|
||||
<dict>
|
||||
<key>CFBundleIdentifier</key>
|
||||
<string>as.vit9696.Lilu</string>
|
||||
<key>IOClass</key>
|
||||
<string>Lilu</string>
|
||||
<key>IOMatchCategory</key>
|
||||
<string>Lilu</string>
|
||||
<key>IOProviderClass</key>
|
||||
<string>IOResources</string>
|
||||
<key>IOResourceMatch</key>
|
||||
<string>IOBSD</string>
|
||||
</dict>
|
||||
</dict>
|
||||
<key>LSMinimumSystemVersion</key>
|
||||
<string>10.6</string>
|
||||
<key>NSHumanReadableCopyright</key>
|
||||
<string>Copyright © 2016-2020 vit9696. All rights reserved.</string>
|
||||
<key>OSBundleCompatibleVersion</key>
|
||||
<string>1.2.0</string>
|
||||
<key>OSBundleLibraries</key>
|
||||
<dict>
|
||||
<key>com.apple.kernel.6.0</key>
|
||||
<string>7.9.9</string>
|
||||
<key>com.apple.kpi.bsd</key>
|
||||
<string>8.0.0</string>
|
||||
<key>com.apple.kpi.iokit</key>
|
||||
<string>8.0.0</string>
|
||||
<key>com.apple.kpi.libkern</key>
|
||||
<string>8.0.0</string>
|
||||
<key>com.apple.kpi.mach</key>
|
||||
<string>8.0.0</string>
|
||||
<key>com.apple.kpi.unsupported</key>
|
||||
<string>8.0.0</string>
|
||||
</dict>
|
||||
<key>OSBundleLibraries_x86_64</key>
|
||||
<dict>
|
||||
<key>com.apple.kpi.bsd</key>
|
||||
<string>10.0.0</string>
|
||||
<key>com.apple.kpi.dsep</key>
|
||||
<string>10.0.0</string>
|
||||
<key>com.apple.kpi.iokit</key>
|
||||
<string>10.0.0</string>
|
||||
<key>com.apple.kpi.libkern</key>
|
||||
<string>10.0.0</string>
|
||||
<key>com.apple.kpi.mach</key>
|
||||
<string>10.0.0</string>
|
||||
<key>com.apple.kpi.unsupported</key>
|
||||
<string>10.0.0</string>
|
||||
</dict>
|
||||
<key>OSBundleRequired</key>
|
||||
<string>Root</string>
|
||||
</dict>
|
||||
</plist>
|
||||
BIN
EFI/OC/Kexts/Lilu.kext/Contents/MacOS/Lilu
Normal file
BIN
EFI/OC/Kexts/Lilu.kext/Contents/MacOS/Lilu
Normal file
Binary file not shown.
883
EFI/OC/Kexts/Lilu.kext/Contents/Resources/Headers/capstone/arm.h
Normal file
883
EFI/OC/Kexts/Lilu.kext/Contents/Resources/Headers/capstone/arm.h
Normal file
@@ -0,0 +1,883 @@
|
||||
#ifndef CAPSTONE_ARM_H
|
||||
#define CAPSTONE_ARM_H
|
||||
|
||||
/* Capstone Disassembly Engine */
|
||||
/* By Nguyen Anh Quynh <aquynh@gmail.com>, 2013-2014 */
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#if !defined(_MSC_VER) || !defined(_KERNEL_MODE)
|
||||
#include <stdint.h>
|
||||
#endif
|
||||
|
||||
#include "platform.h"
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#pragma warning(disable:4201)
|
||||
#endif
|
||||
|
||||
//> ARM shift type
|
||||
typedef enum arm_shifter {
|
||||
ARM_SFT_INVALID = 0,
|
||||
ARM_SFT_ASR, // shift with immediate const
|
||||
ARM_SFT_LSL, // shift with immediate const
|
||||
ARM_SFT_LSR, // shift with immediate const
|
||||
ARM_SFT_ROR, // shift with immediate const
|
||||
ARM_SFT_RRX, // shift with immediate const
|
||||
ARM_SFT_ASR_REG, // shift with register
|
||||
ARM_SFT_LSL_REG, // shift with register
|
||||
ARM_SFT_LSR_REG, // shift with register
|
||||
ARM_SFT_ROR_REG, // shift with register
|
||||
ARM_SFT_RRX_REG, // shift with register
|
||||
} arm_shifter;
|
||||
|
||||
//> ARM condition code
|
||||
typedef enum arm_cc {
|
||||
ARM_CC_INVALID = 0,
|
||||
ARM_CC_EQ, // Equal Equal
|
||||
ARM_CC_NE, // Not equal Not equal, or unordered
|
||||
ARM_CC_HS, // Carry set >, ==, or unordered
|
||||
ARM_CC_LO, // Carry clear Less than
|
||||
ARM_CC_MI, // Minus, negative Less than
|
||||
ARM_CC_PL, // Plus, positive or zero >, ==, or unordered
|
||||
ARM_CC_VS, // Overflow Unordered
|
||||
ARM_CC_VC, // No overflow Not unordered
|
||||
ARM_CC_HI, // Unsigned higher Greater than, or unordered
|
||||
ARM_CC_LS, // Unsigned lower or same Less than or equal
|
||||
ARM_CC_GE, // Greater than or equal Greater than or equal
|
||||
ARM_CC_LT, // Less than Less than, or unordered
|
||||
ARM_CC_GT, // Greater than Greater than
|
||||
ARM_CC_LE, // Less than or equal <, ==, or unordered
|
||||
ARM_CC_AL // Always (unconditional) Always (unconditional)
|
||||
} arm_cc;
|
||||
|
||||
typedef enum arm_sysreg {
|
||||
//> Special registers for MSR
|
||||
ARM_SYSREG_INVALID = 0,
|
||||
|
||||
// SPSR* registers can be OR combined
|
||||
ARM_SYSREG_SPSR_C = 1,
|
||||
ARM_SYSREG_SPSR_X = 2,
|
||||
ARM_SYSREG_SPSR_S = 4,
|
||||
ARM_SYSREG_SPSR_F = 8,
|
||||
|
||||
// CPSR* registers can be OR combined
|
||||
ARM_SYSREG_CPSR_C = 16,
|
||||
ARM_SYSREG_CPSR_X = 32,
|
||||
ARM_SYSREG_CPSR_S = 64,
|
||||
ARM_SYSREG_CPSR_F = 128,
|
||||
|
||||
// independent registers
|
||||
ARM_SYSREG_APSR = 256,
|
||||
ARM_SYSREG_APSR_G,
|
||||
ARM_SYSREG_APSR_NZCVQ,
|
||||
ARM_SYSREG_APSR_NZCVQG,
|
||||
|
||||
ARM_SYSREG_IAPSR,
|
||||
ARM_SYSREG_IAPSR_G,
|
||||
ARM_SYSREG_IAPSR_NZCVQG,
|
||||
|
||||
ARM_SYSREG_EAPSR,
|
||||
ARM_SYSREG_EAPSR_G,
|
||||
ARM_SYSREG_EAPSR_NZCVQG,
|
||||
|
||||
ARM_SYSREG_XPSR,
|
||||
ARM_SYSREG_XPSR_G,
|
||||
ARM_SYSREG_XPSR_NZCVQG,
|
||||
|
||||
ARM_SYSREG_IPSR,
|
||||
ARM_SYSREG_EPSR,
|
||||
ARM_SYSREG_IEPSR,
|
||||
|
||||
ARM_SYSREG_MSP,
|
||||
ARM_SYSREG_PSP,
|
||||
ARM_SYSREG_PRIMASK,
|
||||
ARM_SYSREG_BASEPRI,
|
||||
ARM_SYSREG_BASEPRI_MAX,
|
||||
ARM_SYSREG_FAULTMASK,
|
||||
ARM_SYSREG_CONTROL,
|
||||
} arm_sysreg;
|
||||
|
||||
//> The memory barrier constants map directly to the 4-bit encoding of
|
||||
//> the option field for Memory Barrier operations.
|
||||
typedef enum arm_mem_barrier {
|
||||
ARM_MB_INVALID = 0,
|
||||
ARM_MB_RESERVED_0,
|
||||
ARM_MB_OSHLD,
|
||||
ARM_MB_OSHST,
|
||||
ARM_MB_OSH,
|
||||
ARM_MB_RESERVED_4,
|
||||
ARM_MB_NSHLD,
|
||||
ARM_MB_NSHST,
|
||||
ARM_MB_NSH,
|
||||
ARM_MB_RESERVED_8,
|
||||
ARM_MB_ISHLD,
|
||||
ARM_MB_ISHST,
|
||||
ARM_MB_ISH,
|
||||
ARM_MB_RESERVED_12,
|
||||
ARM_MB_LD,
|
||||
ARM_MB_ST,
|
||||
ARM_MB_SY,
|
||||
} arm_mem_barrier;
|
||||
|
||||
//> Operand type for instruction's operands
|
||||
typedef enum arm_op_type {
|
||||
ARM_OP_INVALID = 0, // = CS_OP_INVALID (Uninitialized).
|
||||
ARM_OP_REG, // = CS_OP_REG (Register operand).
|
||||
ARM_OP_IMM, // = CS_OP_IMM (Immediate operand).
|
||||
ARM_OP_MEM, // = CS_OP_MEM (Memory operand).
|
||||
ARM_OP_FP, // = CS_OP_FP (Floating-Point operand).
|
||||
ARM_OP_CIMM = 64, // C-Immediate (coprocessor registers)
|
||||
ARM_OP_PIMM, // P-Immediate (coprocessor registers)
|
||||
ARM_OP_SETEND, // operand for SETEND instruction
|
||||
ARM_OP_SYSREG, // MSR/MRS special register operand
|
||||
} arm_op_type;
|
||||
|
||||
//> Operand type for SETEND instruction
|
||||
typedef enum arm_setend_type {
|
||||
ARM_SETEND_INVALID = 0, // Uninitialized.
|
||||
ARM_SETEND_BE, // BE operand.
|
||||
ARM_SETEND_LE, // LE operand
|
||||
} arm_setend_type;
|
||||
|
||||
typedef enum arm_cpsmode_type {
|
||||
ARM_CPSMODE_INVALID = 0,
|
||||
ARM_CPSMODE_IE = 2,
|
||||
ARM_CPSMODE_ID = 3
|
||||
} arm_cpsmode_type;
|
||||
|
||||
//> Operand type for SETEND instruction
|
||||
typedef enum arm_cpsflag_type {
|
||||
ARM_CPSFLAG_INVALID = 0,
|
||||
ARM_CPSFLAG_F = 1,
|
||||
ARM_CPSFLAG_I = 2,
|
||||
ARM_CPSFLAG_A = 4,
|
||||
ARM_CPSFLAG_NONE = 16, // no flag
|
||||
} arm_cpsflag_type;
|
||||
|
||||
//> Data type for elements of vector instructions.
|
||||
typedef enum arm_vectordata_type {
|
||||
ARM_VECTORDATA_INVALID = 0,
|
||||
|
||||
// Integer type
|
||||
ARM_VECTORDATA_I8,
|
||||
ARM_VECTORDATA_I16,
|
||||
ARM_VECTORDATA_I32,
|
||||
ARM_VECTORDATA_I64,
|
||||
|
||||
// Signed integer type
|
||||
ARM_VECTORDATA_S8,
|
||||
ARM_VECTORDATA_S16,
|
||||
ARM_VECTORDATA_S32,
|
||||
ARM_VECTORDATA_S64,
|
||||
|
||||
// Unsigned integer type
|
||||
ARM_VECTORDATA_U8,
|
||||
ARM_VECTORDATA_U16,
|
||||
ARM_VECTORDATA_U32,
|
||||
ARM_VECTORDATA_U64,
|
||||
|
||||
// Data type for VMUL/VMULL
|
||||
ARM_VECTORDATA_P8,
|
||||
|
||||
// Floating type
|
||||
ARM_VECTORDATA_F32,
|
||||
ARM_VECTORDATA_F64,
|
||||
|
||||
// Convert float <-> float
|
||||
ARM_VECTORDATA_F16F64, // f16.f64
|
||||
ARM_VECTORDATA_F64F16, // f64.f16
|
||||
ARM_VECTORDATA_F32F16, // f32.f16
|
||||
ARM_VECTORDATA_F16F32, // f32.f16
|
||||
ARM_VECTORDATA_F64F32, // f64.f32
|
||||
ARM_VECTORDATA_F32F64, // f32.f64
|
||||
|
||||
// Convert integer <-> float
|
||||
ARM_VECTORDATA_S32F32, // s32.f32
|
||||
ARM_VECTORDATA_U32F32, // u32.f32
|
||||
ARM_VECTORDATA_F32S32, // f32.s32
|
||||
ARM_VECTORDATA_F32U32, // f32.u32
|
||||
ARM_VECTORDATA_F64S16, // f64.s16
|
||||
ARM_VECTORDATA_F32S16, // f32.s16
|
||||
ARM_VECTORDATA_F64S32, // f64.s32
|
||||
ARM_VECTORDATA_S16F64, // s16.f64
|
||||
ARM_VECTORDATA_S16F32, // s16.f64
|
||||
ARM_VECTORDATA_S32F64, // s32.f64
|
||||
ARM_VECTORDATA_U16F64, // u16.f64
|
||||
ARM_VECTORDATA_U16F32, // u16.f32
|
||||
ARM_VECTORDATA_U32F64, // u32.f64
|
||||
ARM_VECTORDATA_F64U16, // f64.u16
|
||||
ARM_VECTORDATA_F32U16, // f32.u16
|
||||
ARM_VECTORDATA_F64U32, // f64.u32
|
||||
} arm_vectordata_type;
|
||||
|
||||
// Instruction's operand referring to memory
|
||||
// This is associated with ARM_OP_MEM operand type above
|
||||
typedef struct arm_op_mem {
|
||||
unsigned int base; // base register
|
||||
unsigned int index; // index register
|
||||
int scale; // scale for index register (can be 1, or -1)
|
||||
int disp; // displacement/offset value
|
||||
} arm_op_mem;
|
||||
|
||||
// Instruction operand
|
||||
typedef struct cs_arm_op {
|
||||
int vector_index; // Vector Index for some vector operands (or -1 if irrelevant)
|
||||
struct {
|
||||
arm_shifter type;
|
||||
unsigned int value;
|
||||
} shift;
|
||||
arm_op_type type; // operand type
|
||||
union {
|
||||
unsigned int reg; // register value for REG/SYSREG operand
|
||||
int32_t imm; // immediate value for C-IMM, P-IMM or IMM operand
|
||||
double fp; // floating point value for FP operand
|
||||
arm_op_mem mem; // base/index/scale/disp value for MEM operand
|
||||
arm_setend_type setend; // SETEND instruction's operand type
|
||||
};
|
||||
// in some instructions, an operand can be subtracted or added to
|
||||
// the base register,
|
||||
bool subtracted; // if TRUE, this operand is subtracted. otherwise, it is added.
|
||||
} cs_arm_op;
|
||||
|
||||
// Instruction structure
|
||||
typedef struct cs_arm {
|
||||
bool usermode; // User-mode registers to be loaded (for LDM/STM instructions)
|
||||
int vector_size; // Scalar size for vector instructions
|
||||
arm_vectordata_type vector_data; // Data type for elements of vector instructions
|
||||
arm_cpsmode_type cps_mode; // CPS mode for CPS instruction
|
||||
arm_cpsflag_type cps_flag; // CPS mode for CPS instruction
|
||||
arm_cc cc; // conditional code for this insn
|
||||
bool update_flags; // does this insn update flags?
|
||||
bool writeback; // does this insn write-back?
|
||||
arm_mem_barrier mem_barrier; // Option for some memory barrier instructions
|
||||
|
||||
// Number of operands of this instruction,
|
||||
// or 0 when instruction has no operand.
|
||||
uint8_t op_count;
|
||||
|
||||
cs_arm_op operands[36]; // operands for this instruction.
|
||||
} cs_arm;
|
||||
|
||||
//> ARM registers
|
||||
typedef enum arm_reg {
|
||||
ARM_REG_INVALID = 0,
|
||||
ARM_REG_APSR,
|
||||
ARM_REG_APSR_NZCV,
|
||||
ARM_REG_CPSR,
|
||||
ARM_REG_FPEXC,
|
||||
ARM_REG_FPINST,
|
||||
ARM_REG_FPSCR,
|
||||
ARM_REG_FPSCR_NZCV,
|
||||
ARM_REG_FPSID,
|
||||
ARM_REG_ITSTATE,
|
||||
ARM_REG_LR,
|
||||
ARM_REG_PC,
|
||||
ARM_REG_SP,
|
||||
ARM_REG_SPSR,
|
||||
ARM_REG_D0,
|
||||
ARM_REG_D1,
|
||||
ARM_REG_D2,
|
||||
ARM_REG_D3,
|
||||
ARM_REG_D4,
|
||||
ARM_REG_D5,
|
||||
ARM_REG_D6,
|
||||
ARM_REG_D7,
|
||||
ARM_REG_D8,
|
||||
ARM_REG_D9,
|
||||
ARM_REG_D10,
|
||||
ARM_REG_D11,
|
||||
ARM_REG_D12,
|
||||
ARM_REG_D13,
|
||||
ARM_REG_D14,
|
||||
ARM_REG_D15,
|
||||
ARM_REG_D16,
|
||||
ARM_REG_D17,
|
||||
ARM_REG_D18,
|
||||
ARM_REG_D19,
|
||||
ARM_REG_D20,
|
||||
ARM_REG_D21,
|
||||
ARM_REG_D22,
|
||||
ARM_REG_D23,
|
||||
ARM_REG_D24,
|
||||
ARM_REG_D25,
|
||||
ARM_REG_D26,
|
||||
ARM_REG_D27,
|
||||
ARM_REG_D28,
|
||||
ARM_REG_D29,
|
||||
ARM_REG_D30,
|
||||
ARM_REG_D31,
|
||||
ARM_REG_FPINST2,
|
||||
ARM_REG_MVFR0,
|
||||
ARM_REG_MVFR1,
|
||||
ARM_REG_MVFR2,
|
||||
ARM_REG_Q0,
|
||||
ARM_REG_Q1,
|
||||
ARM_REG_Q2,
|
||||
ARM_REG_Q3,
|
||||
ARM_REG_Q4,
|
||||
ARM_REG_Q5,
|
||||
ARM_REG_Q6,
|
||||
ARM_REG_Q7,
|
||||
ARM_REG_Q8,
|
||||
ARM_REG_Q9,
|
||||
ARM_REG_Q10,
|
||||
ARM_REG_Q11,
|
||||
ARM_REG_Q12,
|
||||
ARM_REG_Q13,
|
||||
ARM_REG_Q14,
|
||||
ARM_REG_Q15,
|
||||
ARM_REG_R0,
|
||||
ARM_REG_R1,
|
||||
ARM_REG_R2,
|
||||
ARM_REG_R3,
|
||||
ARM_REG_R4,
|
||||
ARM_REG_R5,
|
||||
ARM_REG_R6,
|
||||
ARM_REG_R7,
|
||||
ARM_REG_R8,
|
||||
ARM_REG_R9,
|
||||
ARM_REG_R10,
|
||||
ARM_REG_R11,
|
||||
ARM_REG_R12,
|
||||
ARM_REG_S0,
|
||||
ARM_REG_S1,
|
||||
ARM_REG_S2,
|
||||
ARM_REG_S3,
|
||||
ARM_REG_S4,
|
||||
ARM_REG_S5,
|
||||
ARM_REG_S6,
|
||||
ARM_REG_S7,
|
||||
ARM_REG_S8,
|
||||
ARM_REG_S9,
|
||||
ARM_REG_S10,
|
||||
ARM_REG_S11,
|
||||
ARM_REG_S12,
|
||||
ARM_REG_S13,
|
||||
ARM_REG_S14,
|
||||
ARM_REG_S15,
|
||||
ARM_REG_S16,
|
||||
ARM_REG_S17,
|
||||
ARM_REG_S18,
|
||||
ARM_REG_S19,
|
||||
ARM_REG_S20,
|
||||
ARM_REG_S21,
|
||||
ARM_REG_S22,
|
||||
ARM_REG_S23,
|
||||
ARM_REG_S24,
|
||||
ARM_REG_S25,
|
||||
ARM_REG_S26,
|
||||
ARM_REG_S27,
|
||||
ARM_REG_S28,
|
||||
ARM_REG_S29,
|
||||
ARM_REG_S30,
|
||||
ARM_REG_S31,
|
||||
|
||||
ARM_REG_ENDING, // <-- mark the end of the list or registers
|
||||
|
||||
//> alias registers
|
||||
ARM_REG_R13 = ARM_REG_SP,
|
||||
ARM_REG_R14 = ARM_REG_LR,
|
||||
ARM_REG_R15 = ARM_REG_PC,
|
||||
|
||||
ARM_REG_SB = ARM_REG_R9,
|
||||
ARM_REG_SL = ARM_REG_R10,
|
||||
ARM_REG_FP = ARM_REG_R11,
|
||||
ARM_REG_IP = ARM_REG_R12,
|
||||
} arm_reg;
|
||||
|
||||
//> ARM instruction
|
||||
typedef enum arm_insn {
|
||||
ARM_INS_INVALID = 0,
|
||||
|
||||
ARM_INS_ADC,
|
||||
ARM_INS_ADD,
|
||||
ARM_INS_ADR,
|
||||
ARM_INS_AESD,
|
||||
ARM_INS_AESE,
|
||||
ARM_INS_AESIMC,
|
||||
ARM_INS_AESMC,
|
||||
ARM_INS_AND,
|
||||
ARM_INS_BFC,
|
||||
ARM_INS_BFI,
|
||||
ARM_INS_BIC,
|
||||
ARM_INS_BKPT,
|
||||
ARM_INS_BL,
|
||||
ARM_INS_BLX,
|
||||
ARM_INS_BX,
|
||||
ARM_INS_BXJ,
|
||||
ARM_INS_B,
|
||||
ARM_INS_CDP,
|
||||
ARM_INS_CDP2,
|
||||
ARM_INS_CLREX,
|
||||
ARM_INS_CLZ,
|
||||
ARM_INS_CMN,
|
||||
ARM_INS_CMP,
|
||||
ARM_INS_CPS,
|
||||
ARM_INS_CRC32B,
|
||||
ARM_INS_CRC32CB,
|
||||
ARM_INS_CRC32CH,
|
||||
ARM_INS_CRC32CW,
|
||||
ARM_INS_CRC32H,
|
||||
ARM_INS_CRC32W,
|
||||
ARM_INS_DBG,
|
||||
ARM_INS_DMB,
|
||||
ARM_INS_DSB,
|
||||
ARM_INS_EOR,
|
||||
ARM_INS_VMOV,
|
||||
ARM_INS_FLDMDBX,
|
||||
ARM_INS_FLDMIAX,
|
||||
ARM_INS_VMRS,
|
||||
ARM_INS_FSTMDBX,
|
||||
ARM_INS_FSTMIAX,
|
||||
ARM_INS_HINT,
|
||||
ARM_INS_HLT,
|
||||
ARM_INS_ISB,
|
||||
ARM_INS_LDA,
|
||||
ARM_INS_LDAB,
|
||||
ARM_INS_LDAEX,
|
||||
ARM_INS_LDAEXB,
|
||||
ARM_INS_LDAEXD,
|
||||
ARM_INS_LDAEXH,
|
||||
ARM_INS_LDAH,
|
||||
ARM_INS_LDC2L,
|
||||
ARM_INS_LDC2,
|
||||
ARM_INS_LDCL,
|
||||
ARM_INS_LDC,
|
||||
ARM_INS_LDMDA,
|
||||
ARM_INS_LDMDB,
|
||||
ARM_INS_LDM,
|
||||
ARM_INS_LDMIB,
|
||||
ARM_INS_LDRBT,
|
||||
ARM_INS_LDRB,
|
||||
ARM_INS_LDRD,
|
||||
ARM_INS_LDREX,
|
||||
ARM_INS_LDREXB,
|
||||
ARM_INS_LDREXD,
|
||||
ARM_INS_LDREXH,
|
||||
ARM_INS_LDRH,
|
||||
ARM_INS_LDRHT,
|
||||
ARM_INS_LDRSB,
|
||||
ARM_INS_LDRSBT,
|
||||
ARM_INS_LDRSH,
|
||||
ARM_INS_LDRSHT,
|
||||
ARM_INS_LDRT,
|
||||
ARM_INS_LDR,
|
||||
ARM_INS_MCR,
|
||||
ARM_INS_MCR2,
|
||||
ARM_INS_MCRR,
|
||||
ARM_INS_MCRR2,
|
||||
ARM_INS_MLA,
|
||||
ARM_INS_MLS,
|
||||
ARM_INS_MOV,
|
||||
ARM_INS_MOVT,
|
||||
ARM_INS_MOVW,
|
||||
ARM_INS_MRC,
|
||||
ARM_INS_MRC2,
|
||||
ARM_INS_MRRC,
|
||||
ARM_INS_MRRC2,
|
||||
ARM_INS_MRS,
|
||||
ARM_INS_MSR,
|
||||
ARM_INS_MUL,
|
||||
ARM_INS_MVN,
|
||||
ARM_INS_ORR,
|
||||
ARM_INS_PKHBT,
|
||||
ARM_INS_PKHTB,
|
||||
ARM_INS_PLDW,
|
||||
ARM_INS_PLD,
|
||||
ARM_INS_PLI,
|
||||
ARM_INS_QADD,
|
||||
ARM_INS_QADD16,
|
||||
ARM_INS_QADD8,
|
||||
ARM_INS_QASX,
|
||||
ARM_INS_QDADD,
|
||||
ARM_INS_QDSUB,
|
||||
ARM_INS_QSAX,
|
||||
ARM_INS_QSUB,
|
||||
ARM_INS_QSUB16,
|
||||
ARM_INS_QSUB8,
|
||||
ARM_INS_RBIT,
|
||||
ARM_INS_REV,
|
||||
ARM_INS_REV16,
|
||||
ARM_INS_REVSH,
|
||||
ARM_INS_RFEDA,
|
||||
ARM_INS_RFEDB,
|
||||
ARM_INS_RFEIA,
|
||||
ARM_INS_RFEIB,
|
||||
ARM_INS_RSB,
|
||||
ARM_INS_RSC,
|
||||
ARM_INS_SADD16,
|
||||
ARM_INS_SADD8,
|
||||
ARM_INS_SASX,
|
||||
ARM_INS_SBC,
|
||||
ARM_INS_SBFX,
|
||||
ARM_INS_SDIV,
|
||||
ARM_INS_SEL,
|
||||
ARM_INS_SETEND,
|
||||
ARM_INS_SHA1C,
|
||||
ARM_INS_SHA1H,
|
||||
ARM_INS_SHA1M,
|
||||
ARM_INS_SHA1P,
|
||||
ARM_INS_SHA1SU0,
|
||||
ARM_INS_SHA1SU1,
|
||||
ARM_INS_SHA256H,
|
||||
ARM_INS_SHA256H2,
|
||||
ARM_INS_SHA256SU0,
|
||||
ARM_INS_SHA256SU1,
|
||||
ARM_INS_SHADD16,
|
||||
ARM_INS_SHADD8,
|
||||
ARM_INS_SHASX,
|
||||
ARM_INS_SHSAX,
|
||||
ARM_INS_SHSUB16,
|
||||
ARM_INS_SHSUB8,
|
||||
ARM_INS_SMC,
|
||||
ARM_INS_SMLABB,
|
||||
ARM_INS_SMLABT,
|
||||
ARM_INS_SMLAD,
|
||||
ARM_INS_SMLADX,
|
||||
ARM_INS_SMLAL,
|
||||
ARM_INS_SMLALBB,
|
||||
ARM_INS_SMLALBT,
|
||||
ARM_INS_SMLALD,
|
||||
ARM_INS_SMLALDX,
|
||||
ARM_INS_SMLALTB,
|
||||
ARM_INS_SMLALTT,
|
||||
ARM_INS_SMLATB,
|
||||
ARM_INS_SMLATT,
|
||||
ARM_INS_SMLAWB,
|
||||
ARM_INS_SMLAWT,
|
||||
ARM_INS_SMLSD,
|
||||
ARM_INS_SMLSDX,
|
||||
ARM_INS_SMLSLD,
|
||||
ARM_INS_SMLSLDX,
|
||||
ARM_INS_SMMLA,
|
||||
ARM_INS_SMMLAR,
|
||||
ARM_INS_SMMLS,
|
||||
ARM_INS_SMMLSR,
|
||||
ARM_INS_SMMUL,
|
||||
ARM_INS_SMMULR,
|
||||
ARM_INS_SMUAD,
|
||||
ARM_INS_SMUADX,
|
||||
ARM_INS_SMULBB,
|
||||
ARM_INS_SMULBT,
|
||||
ARM_INS_SMULL,
|
||||
ARM_INS_SMULTB,
|
||||
ARM_INS_SMULTT,
|
||||
ARM_INS_SMULWB,
|
||||
ARM_INS_SMULWT,
|
||||
ARM_INS_SMUSD,
|
||||
ARM_INS_SMUSDX,
|
||||
ARM_INS_SRSDA,
|
||||
ARM_INS_SRSDB,
|
||||
ARM_INS_SRSIA,
|
||||
ARM_INS_SRSIB,
|
||||
ARM_INS_SSAT,
|
||||
ARM_INS_SSAT16,
|
||||
ARM_INS_SSAX,
|
||||
ARM_INS_SSUB16,
|
||||
ARM_INS_SSUB8,
|
||||
ARM_INS_STC2L,
|
||||
ARM_INS_STC2,
|
||||
ARM_INS_STCL,
|
||||
ARM_INS_STC,
|
||||
ARM_INS_STL,
|
||||
ARM_INS_STLB,
|
||||
ARM_INS_STLEX,
|
||||
ARM_INS_STLEXB,
|
||||
ARM_INS_STLEXD,
|
||||
ARM_INS_STLEXH,
|
||||
ARM_INS_STLH,
|
||||
ARM_INS_STMDA,
|
||||
ARM_INS_STMDB,
|
||||
ARM_INS_STM,
|
||||
ARM_INS_STMIB,
|
||||
ARM_INS_STRBT,
|
||||
ARM_INS_STRB,
|
||||
ARM_INS_STRD,
|
||||
ARM_INS_STREX,
|
||||
ARM_INS_STREXB,
|
||||
ARM_INS_STREXD,
|
||||
ARM_INS_STREXH,
|
||||
ARM_INS_STRH,
|
||||
ARM_INS_STRHT,
|
||||
ARM_INS_STRT,
|
||||
ARM_INS_STR,
|
||||
ARM_INS_SUB,
|
||||
ARM_INS_SVC,
|
||||
ARM_INS_SWP,
|
||||
ARM_INS_SWPB,
|
||||
ARM_INS_SXTAB,
|
||||
ARM_INS_SXTAB16,
|
||||
ARM_INS_SXTAH,
|
||||
ARM_INS_SXTB,
|
||||
ARM_INS_SXTB16,
|
||||
ARM_INS_SXTH,
|
||||
ARM_INS_TEQ,
|
||||
ARM_INS_TRAP,
|
||||
ARM_INS_TST,
|
||||
ARM_INS_UADD16,
|
||||
ARM_INS_UADD8,
|
||||
ARM_INS_UASX,
|
||||
ARM_INS_UBFX,
|
||||
ARM_INS_UDF,
|
||||
ARM_INS_UDIV,
|
||||
ARM_INS_UHADD16,
|
||||
ARM_INS_UHADD8,
|
||||
ARM_INS_UHASX,
|
||||
ARM_INS_UHSAX,
|
||||
ARM_INS_UHSUB16,
|
||||
ARM_INS_UHSUB8,
|
||||
ARM_INS_UMAAL,
|
||||
ARM_INS_UMLAL,
|
||||
ARM_INS_UMULL,
|
||||
ARM_INS_UQADD16,
|
||||
ARM_INS_UQADD8,
|
||||
ARM_INS_UQASX,
|
||||
ARM_INS_UQSAX,
|
||||
ARM_INS_UQSUB16,
|
||||
ARM_INS_UQSUB8,
|
||||
ARM_INS_USAD8,
|
||||
ARM_INS_USADA8,
|
||||
ARM_INS_USAT,
|
||||
ARM_INS_USAT16,
|
||||
ARM_INS_USAX,
|
||||
ARM_INS_USUB16,
|
||||
ARM_INS_USUB8,
|
||||
ARM_INS_UXTAB,
|
||||
ARM_INS_UXTAB16,
|
||||
ARM_INS_UXTAH,
|
||||
ARM_INS_UXTB,
|
||||
ARM_INS_UXTB16,
|
||||
ARM_INS_UXTH,
|
||||
ARM_INS_VABAL,
|
||||
ARM_INS_VABA,
|
||||
ARM_INS_VABDL,
|
||||
ARM_INS_VABD,
|
||||
ARM_INS_VABS,
|
||||
ARM_INS_VACGE,
|
||||
ARM_INS_VACGT,
|
||||
ARM_INS_VADD,
|
||||
ARM_INS_VADDHN,
|
||||
ARM_INS_VADDL,
|
||||
ARM_INS_VADDW,
|
||||
ARM_INS_VAND,
|
||||
ARM_INS_VBIC,
|
||||
ARM_INS_VBIF,
|
||||
ARM_INS_VBIT,
|
||||
ARM_INS_VBSL,
|
||||
ARM_INS_VCEQ,
|
||||
ARM_INS_VCGE,
|
||||
ARM_INS_VCGT,
|
||||
ARM_INS_VCLE,
|
||||
ARM_INS_VCLS,
|
||||
ARM_INS_VCLT,
|
||||
ARM_INS_VCLZ,
|
||||
ARM_INS_VCMP,
|
||||
ARM_INS_VCMPE,
|
||||
ARM_INS_VCNT,
|
||||
ARM_INS_VCVTA,
|
||||
ARM_INS_VCVTB,
|
||||
ARM_INS_VCVT,
|
||||
ARM_INS_VCVTM,
|
||||
ARM_INS_VCVTN,
|
||||
ARM_INS_VCVTP,
|
||||
ARM_INS_VCVTT,
|
||||
ARM_INS_VDIV,
|
||||
ARM_INS_VDUP,
|
||||
ARM_INS_VEOR,
|
||||
ARM_INS_VEXT,
|
||||
ARM_INS_VFMA,
|
||||
ARM_INS_VFMS,
|
||||
ARM_INS_VFNMA,
|
||||
ARM_INS_VFNMS,
|
||||
ARM_INS_VHADD,
|
||||
ARM_INS_VHSUB,
|
||||
ARM_INS_VLD1,
|
||||
ARM_INS_VLD2,
|
||||
ARM_INS_VLD3,
|
||||
ARM_INS_VLD4,
|
||||
ARM_INS_VLDMDB,
|
||||
ARM_INS_VLDMIA,
|
||||
ARM_INS_VLDR,
|
||||
ARM_INS_VMAXNM,
|
||||
ARM_INS_VMAX,
|
||||
ARM_INS_VMINNM,
|
||||
ARM_INS_VMIN,
|
||||
ARM_INS_VMLA,
|
||||
ARM_INS_VMLAL,
|
||||
ARM_INS_VMLS,
|
||||
ARM_INS_VMLSL,
|
||||
ARM_INS_VMOVL,
|
||||
ARM_INS_VMOVN,
|
||||
ARM_INS_VMSR,
|
||||
ARM_INS_VMUL,
|
||||
ARM_INS_VMULL,
|
||||
ARM_INS_VMVN,
|
||||
ARM_INS_VNEG,
|
||||
ARM_INS_VNMLA,
|
||||
ARM_INS_VNMLS,
|
||||
ARM_INS_VNMUL,
|
||||
ARM_INS_VORN,
|
||||
ARM_INS_VORR,
|
||||
ARM_INS_VPADAL,
|
||||
ARM_INS_VPADDL,
|
||||
ARM_INS_VPADD,
|
||||
ARM_INS_VPMAX,
|
||||
ARM_INS_VPMIN,
|
||||
ARM_INS_VQABS,
|
||||
ARM_INS_VQADD,
|
||||
ARM_INS_VQDMLAL,
|
||||
ARM_INS_VQDMLSL,
|
||||
ARM_INS_VQDMULH,
|
||||
ARM_INS_VQDMULL,
|
||||
ARM_INS_VQMOVUN,
|
||||
ARM_INS_VQMOVN,
|
||||
ARM_INS_VQNEG,
|
||||
ARM_INS_VQRDMULH,
|
||||
ARM_INS_VQRSHL,
|
||||
ARM_INS_VQRSHRN,
|
||||
ARM_INS_VQRSHRUN,
|
||||
ARM_INS_VQSHL,
|
||||
ARM_INS_VQSHLU,
|
||||
ARM_INS_VQSHRN,
|
||||
ARM_INS_VQSHRUN,
|
||||
ARM_INS_VQSUB,
|
||||
ARM_INS_VRADDHN,
|
||||
ARM_INS_VRECPE,
|
||||
ARM_INS_VRECPS,
|
||||
ARM_INS_VREV16,
|
||||
ARM_INS_VREV32,
|
||||
ARM_INS_VREV64,
|
||||
ARM_INS_VRHADD,
|
||||
ARM_INS_VRINTA,
|
||||
ARM_INS_VRINTM,
|
||||
ARM_INS_VRINTN,
|
||||
ARM_INS_VRINTP,
|
||||
ARM_INS_VRINTR,
|
||||
ARM_INS_VRINTX,
|
||||
ARM_INS_VRINTZ,
|
||||
ARM_INS_VRSHL,
|
||||
ARM_INS_VRSHRN,
|
||||
ARM_INS_VRSHR,
|
||||
ARM_INS_VRSQRTE,
|
||||
ARM_INS_VRSQRTS,
|
||||
ARM_INS_VRSRA,
|
||||
ARM_INS_VRSUBHN,
|
||||
ARM_INS_VSELEQ,
|
||||
ARM_INS_VSELGE,
|
||||
ARM_INS_VSELGT,
|
||||
ARM_INS_VSELVS,
|
||||
ARM_INS_VSHLL,
|
||||
ARM_INS_VSHL,
|
||||
ARM_INS_VSHRN,
|
||||
ARM_INS_VSHR,
|
||||
ARM_INS_VSLI,
|
||||
ARM_INS_VSQRT,
|
||||
ARM_INS_VSRA,
|
||||
ARM_INS_VSRI,
|
||||
ARM_INS_VST1,
|
||||
ARM_INS_VST2,
|
||||
ARM_INS_VST3,
|
||||
ARM_INS_VST4,
|
||||
ARM_INS_VSTMDB,
|
||||
ARM_INS_VSTMIA,
|
||||
ARM_INS_VSTR,
|
||||
ARM_INS_VSUB,
|
||||
ARM_INS_VSUBHN,
|
||||
ARM_INS_VSUBL,
|
||||
ARM_INS_VSUBW,
|
||||
ARM_INS_VSWP,
|
||||
ARM_INS_VTBL,
|
||||
ARM_INS_VTBX,
|
||||
ARM_INS_VCVTR,
|
||||
ARM_INS_VTRN,
|
||||
ARM_INS_VTST,
|
||||
ARM_INS_VUZP,
|
||||
ARM_INS_VZIP,
|
||||
ARM_INS_ADDW,
|
||||
ARM_INS_ASR,
|
||||
ARM_INS_DCPS1,
|
||||
ARM_INS_DCPS2,
|
||||
ARM_INS_DCPS3,
|
||||
ARM_INS_IT,
|
||||
ARM_INS_LSL,
|
||||
ARM_INS_LSR,
|
||||
ARM_INS_ASRS,
|
||||
ARM_INS_LSRS,
|
||||
ARM_INS_ORN,
|
||||
ARM_INS_ROR,
|
||||
ARM_INS_RRX,
|
||||
ARM_INS_SUBS,
|
||||
ARM_INS_SUBW,
|
||||
ARM_INS_TBB,
|
||||
ARM_INS_TBH,
|
||||
ARM_INS_CBNZ,
|
||||
ARM_INS_CBZ,
|
||||
ARM_INS_MOVS,
|
||||
ARM_INS_POP,
|
||||
ARM_INS_PUSH,
|
||||
|
||||
// special instructions
|
||||
ARM_INS_NOP,
|
||||
ARM_INS_YIELD,
|
||||
ARM_INS_WFE,
|
||||
ARM_INS_WFI,
|
||||
ARM_INS_SEV,
|
||||
ARM_INS_SEVL,
|
||||
ARM_INS_VPUSH,
|
||||
ARM_INS_VPOP,
|
||||
|
||||
ARM_INS_ENDING, // <-- mark the end of the list of instructions
|
||||
} arm_insn;
|
||||
|
||||
//> Group of ARM instructions
|
||||
typedef enum arm_insn_group {
|
||||
ARM_GRP_INVALID = 0, // = CS_GRP_INVALID
|
||||
|
||||
//> Generic groups
|
||||
// all jump instructions (conditional+direct+indirect jumps)
|
||||
ARM_GRP_JUMP, // = CS_GRP_JUMP
|
||||
|
||||
//> Architecture-specific groups
|
||||
ARM_GRP_CRYPTO = 128,
|
||||
ARM_GRP_DATABARRIER,
|
||||
ARM_GRP_DIVIDE,
|
||||
ARM_GRP_FPARMV8,
|
||||
ARM_GRP_MULTPRO,
|
||||
ARM_GRP_NEON,
|
||||
ARM_GRP_T2EXTRACTPACK,
|
||||
ARM_GRP_THUMB2DSP,
|
||||
ARM_GRP_TRUSTZONE,
|
||||
ARM_GRP_V4T,
|
||||
ARM_GRP_V5T,
|
||||
ARM_GRP_V5TE,
|
||||
ARM_GRP_V6,
|
||||
ARM_GRP_V6T2,
|
||||
ARM_GRP_V7,
|
||||
ARM_GRP_V8,
|
||||
ARM_GRP_VFP2,
|
||||
ARM_GRP_VFP3,
|
||||
ARM_GRP_VFP4,
|
||||
ARM_GRP_ARM,
|
||||
ARM_GRP_MCLASS,
|
||||
ARM_GRP_NOTMCLASS,
|
||||
ARM_GRP_THUMB,
|
||||
ARM_GRP_THUMB1ONLY,
|
||||
ARM_GRP_THUMB2,
|
||||
ARM_GRP_PREV8,
|
||||
ARM_GRP_FPVMLX,
|
||||
ARM_GRP_MULOPS,
|
||||
ARM_GRP_CRC,
|
||||
ARM_GRP_DPVFP,
|
||||
ARM_GRP_V6M,
|
||||
|
||||
ARM_GRP_ENDING,
|
||||
} arm_insn_group;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
1154
EFI/OC/Kexts/Lilu.kext/Contents/Resources/Headers/capstone/arm64.h
Normal file
1154
EFI/OC/Kexts/Lilu.kext/Contents/Resources/Headers/capstone/arm64.h
Normal file
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,675 @@
|
||||
#ifndef CAPSTONE_ENGINE_H
|
||||
#define CAPSTONE_ENGINE_H
|
||||
|
||||
/* Capstone Disassembly Engine */
|
||||
/* By Nguyen Anh Quynh <aquynh@gmail.com>, 2013-2016 */
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#if !defined(_MSC_VER) || !defined(_KERNEL_MODE)
|
||||
#include <stdint.h>
|
||||
#endif
|
||||
|
||||
#include <stdarg.h>
|
||||
|
||||
#if defined(CAPSTONE_HAS_OSXKERNEL)
|
||||
#include <libkern/libkern.h>
|
||||
#else
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#endif
|
||||
|
||||
#include "platform.h"
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#pragma warning(disable:4201)
|
||||
#pragma warning(disable:4100)
|
||||
#define CAPSTONE_API __cdecl
|
||||
#ifdef CAPSTONE_SHARED
|
||||
#define CAPSTONE_EXPORT __declspec(dllexport)
|
||||
#else // defined(CAPSTONE_STATIC)
|
||||
#define CAPSTONE_EXPORT
|
||||
#endif
|
||||
#else
|
||||
#define CAPSTONE_API
|
||||
#if defined(__GNUC__) && !defined(CAPSTONE_STATIC)
|
||||
#define CAPSTONE_EXPORT __attribute__((visibility("default")))
|
||||
#else // defined(CAPSTONE_STATIC)
|
||||
#define CAPSTONE_EXPORT
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef __GNUC__
|
||||
#define CAPSTONE_DEPRECATED __attribute__((deprecated))
|
||||
#elif defined(_MSC_VER)
|
||||
#define CAPSTONE_DEPRECATED __declspec(deprecated)
|
||||
#else
|
||||
#pragma message("WARNING: You need to implement CAPSTONE_DEPRECATED for this compiler")
|
||||
#define CAPSTONE_DEPRECATED
|
||||
#endif
|
||||
|
||||
// Capstone API version
|
||||
#define CS_API_MAJOR 3
|
||||
#define CS_API_MINOR 0
|
||||
|
||||
// Capstone package version
|
||||
#define CS_VERSION_MAJOR CS_API_MAJOR
|
||||
#define CS_VERSION_MINOR CS_API_MINOR
|
||||
#define CS_VERSION_EXTRA 5
|
||||
|
||||
// Macro to create combined version which can be compared to
|
||||
// result of cs_version() API.
|
||||
#define CS_MAKE_VERSION(major, minor) ((major << 8) + minor)
|
||||
|
||||
// Handle using with all API
|
||||
typedef size_t csh;
|
||||
|
||||
// Architecture type
|
||||
typedef enum cs_arch {
|
||||
CS_ARCH_ARM = 0, // ARM architecture (including Thumb, Thumb-2)
|
||||
CS_ARCH_ARM64, // ARM-64, also called AArch64
|
||||
CS_ARCH_MIPS, // Mips architecture
|
||||
CS_ARCH_X86, // X86 architecture (including x86 & x86-64)
|
||||
CS_ARCH_PPC, // PowerPC architecture
|
||||
CS_ARCH_SPARC, // Sparc architecture
|
||||
CS_ARCH_SYSZ, // SystemZ architecture
|
||||
CS_ARCH_XCORE, // XCore architecture
|
||||
CS_ARCH_MAX,
|
||||
CS_ARCH_ALL = 0xFFFF, // All architectures - for cs_support()
|
||||
} cs_arch;
|
||||
|
||||
// Support value to verify diet mode of the engine.
|
||||
// If cs_support(CS_SUPPORT_DIET) return True, the engine was compiled
|
||||
// in diet mode.
|
||||
#define CS_SUPPORT_DIET (CS_ARCH_ALL + 1)
|
||||
|
||||
// Support value to verify X86 reduce mode of the engine.
|
||||
// If cs_support(CS_SUPPORT_X86_REDUCE) return True, the engine was compiled
|
||||
// in X86 reduce mode.
|
||||
#define CS_SUPPORT_X86_REDUCE (CS_ARCH_ALL + 2)
|
||||
|
||||
// Mode type
|
||||
typedef enum cs_mode {
|
||||
CS_MODE_LITTLE_ENDIAN = 0, // little-endian mode (default mode)
|
||||
CS_MODE_ARM = 0, // 32-bit ARM
|
||||
CS_MODE_16 = 1 << 1, // 16-bit mode (X86)
|
||||
CS_MODE_32 = 1 << 2, // 32-bit mode (X86)
|
||||
CS_MODE_64 = 1 << 3, // 64-bit mode (X86, PPC)
|
||||
CS_MODE_THUMB = 1 << 4, // ARM's Thumb mode, including Thumb-2
|
||||
CS_MODE_MCLASS = 1 << 5, // ARM's Cortex-M series
|
||||
CS_MODE_V8 = 1 << 6, // ARMv8 A32 encodings for ARM
|
||||
CS_MODE_MICRO = 1 << 4, // MicroMips mode (MIPS)
|
||||
CS_MODE_MIPS3 = 1 << 5, // Mips III ISA
|
||||
CS_MODE_MIPS32R6 = 1 << 6, // Mips32r6 ISA
|
||||
CS_MODE_MIPSGP64 = 1 << 7, // General Purpose Registers are 64-bit wide (MIPS)
|
||||
CS_MODE_V9 = 1 << 4, // SparcV9 mode (Sparc)
|
||||
CS_MODE_BIG_ENDIAN = 1 << 31, // big-endian mode
|
||||
CS_MODE_MIPS32 = CS_MODE_32, // Mips32 ISA (Mips)
|
||||
CS_MODE_MIPS64 = CS_MODE_64, // Mips64 ISA (Mips)
|
||||
} cs_mode;
|
||||
|
||||
typedef void* (CAPSTONE_API *cs_malloc_t)(size_t size);
|
||||
typedef void* (CAPSTONE_API *cs_calloc_t)(size_t nmemb, size_t size);
|
||||
typedef void* (CAPSTONE_API *cs_realloc_t)(void *ptr, size_t size);
|
||||
typedef void (CAPSTONE_API *cs_free_t)(void *ptr);
|
||||
typedef int (CAPSTONE_API *cs_vsnprintf_t)(char *str, size_t size, const char *format, va_list ap);
|
||||
|
||||
|
||||
// User-defined dynamic memory related functions: malloc/calloc/realloc/free/vsnprintf()
|
||||
// By default, Capstone uses system's malloc(), calloc(), realloc(), free() & vsnprintf().
|
||||
typedef struct cs_opt_mem {
|
||||
cs_malloc_t malloc;
|
||||
cs_calloc_t calloc;
|
||||
cs_realloc_t realloc;
|
||||
cs_free_t free;
|
||||
cs_vsnprintf_t vsnprintf;
|
||||
} cs_opt_mem;
|
||||
|
||||
// Runtime option for the disassembled engine
|
||||
typedef enum cs_opt_type {
|
||||
CS_OPT_INVALID = 0, // No option specified
|
||||
CS_OPT_SYNTAX, // Assembly output syntax
|
||||
CS_OPT_DETAIL, // Break down instruction structure into details
|
||||
CS_OPT_MODE, // Change engine's mode at run-time
|
||||
CS_OPT_MEM, // User-defined dynamic memory related functions
|
||||
CS_OPT_SKIPDATA, // Skip data when disassembling. Then engine is in SKIPDATA mode.
|
||||
CS_OPT_SKIPDATA_SETUP, // Setup user-defined function for SKIPDATA option
|
||||
} cs_opt_type;
|
||||
|
||||
// Runtime option value (associated with option type above)
|
||||
typedef enum cs_opt_value {
|
||||
CS_OPT_OFF = 0, // Turn OFF an option - default option of CS_OPT_DETAIL, CS_OPT_SKIPDATA.
|
||||
CS_OPT_ON = 3, // Turn ON an option (CS_OPT_DETAIL, CS_OPT_SKIPDATA).
|
||||
CS_OPT_SYNTAX_DEFAULT = 0, // Default asm syntax (CS_OPT_SYNTAX).
|
||||
CS_OPT_SYNTAX_INTEL, // X86 Intel asm syntax - default on X86 (CS_OPT_SYNTAX).
|
||||
CS_OPT_SYNTAX_ATT, // X86 ATT asm syntax (CS_OPT_SYNTAX).
|
||||
CS_OPT_SYNTAX_NOREGNAME, // Prints register name with only number (CS_OPT_SYNTAX)
|
||||
} cs_opt_value;
|
||||
|
||||
//> Common instruction operand types - to be consistent across all architectures.
|
||||
typedef enum cs_op_type {
|
||||
CS_OP_INVALID = 0, // uninitialized/invalid operand.
|
||||
CS_OP_REG, // Register operand.
|
||||
CS_OP_IMM, // Immediate operand.
|
||||
CS_OP_MEM, // Memory operand.
|
||||
CS_OP_FP, // Floating-Point operand.
|
||||
} cs_op_type;
|
||||
|
||||
//> Common instruction groups - to be consistent across all architectures.
|
||||
typedef enum cs_group_type {
|
||||
CS_GRP_INVALID = 0, // uninitialized/invalid group.
|
||||
CS_GRP_JUMP, // all jump instructions (conditional+direct+indirect jumps)
|
||||
CS_GRP_CALL, // all call instructions
|
||||
CS_GRP_RET, // all return instructions
|
||||
CS_GRP_INT, // all interrupt instructions (int+syscall)
|
||||
CS_GRP_IRET, // all interrupt return instructions
|
||||
} cs_group_type;
|
||||
|
||||
/*
|
||||
User-defined callback function for SKIPDATA option.
|
||||
See tests/test_skipdata.c for sample code demonstrating this API.
|
||||
|
||||
@code: the input buffer containing code to be disassembled.
|
||||
This is the same buffer passed to cs_disasm().
|
||||
@code_size: size (in bytes) of the above @code buffer.
|
||||
@offset: the position of the currently-examining byte in the input
|
||||
buffer @code mentioned above.
|
||||
@user_data: user-data passed to cs_option() via @user_data field in
|
||||
cs_opt_skipdata struct below.
|
||||
|
||||
@return: return number of bytes to skip, or 0 to immediately stop disassembling.
|
||||
*/
|
||||
typedef size_t (CAPSTONE_API *cs_skipdata_cb_t)(const uint8_t *code, size_t code_size, size_t offset, void *user_data);
|
||||
|
||||
// User-customized setup for SKIPDATA option
|
||||
typedef struct cs_opt_skipdata {
|
||||
// Capstone considers data to skip as special "instructions".
|
||||
// User can specify the string for this instruction's "mnemonic" here.
|
||||
// By default (if @mnemonic is NULL), Capstone use ".byte".
|
||||
const char *mnemonic;
|
||||
|
||||
// User-defined callback function to be called when Capstone hits data.
|
||||
// If the returned value from this callback is positive (>0), Capstone
|
||||
// will skip exactly that number of bytes & continue. Otherwise, if
|
||||
// the callback returns 0, Capstone stops disassembling and returns
|
||||
// immediately from cs_disasm()
|
||||
// NOTE: if this callback pointer is NULL, Capstone would skip a number
|
||||
// of bytes depending on architectures, as following:
|
||||
// Arm: 2 bytes (Thumb mode) or 4 bytes.
|
||||
// Arm64: 4 bytes.
|
||||
// Mips: 4 bytes.
|
||||
// PowerPC: 4 bytes.
|
||||
// Sparc: 4 bytes.
|
||||
// SystemZ: 2 bytes.
|
||||
// X86: 1 bytes.
|
||||
// XCore: 2 bytes.
|
||||
cs_skipdata_cb_t callback; // default value is NULL
|
||||
|
||||
// User-defined data to be passed to @callback function pointer.
|
||||
void *user_data;
|
||||
} cs_opt_skipdata;
|
||||
|
||||
|
||||
#include "arm.h"
|
||||
#include "arm64.h"
|
||||
#include "mips.h"
|
||||
#include "ppc.h"
|
||||
#include "sparc.h"
|
||||
#include "systemz.h"
|
||||
#include "x86.h"
|
||||
#include "xcore.h"
|
||||
|
||||
// NOTE: All information in cs_detail is only available when CS_OPT_DETAIL = CS_OPT_ON
|
||||
typedef struct cs_detail {
|
||||
uint8_t regs_read[12]; // list of implicit registers read by this insn
|
||||
uint8_t regs_read_count; // number of implicit registers read by this insn
|
||||
|
||||
uint8_t regs_write[20]; // list of implicit registers modified by this insn
|
||||
uint8_t regs_write_count; // number of implicit registers modified by this insn
|
||||
|
||||
uint8_t groups[8]; // list of group this instruction belong to
|
||||
uint8_t groups_count; // number of groups this insn belongs to
|
||||
|
||||
// Architecture-specific instruction info
|
||||
union {
|
||||
cs_x86 x86; // X86 architecture, including 16-bit, 32-bit & 64-bit mode
|
||||
cs_arm64 arm64; // ARM64 architecture (aka AArch64)
|
||||
cs_arm arm; // ARM architecture (including Thumb/Thumb2)
|
||||
cs_mips mips; // MIPS architecture
|
||||
cs_ppc ppc; // PowerPC architecture
|
||||
cs_sparc sparc; // Sparc architecture
|
||||
cs_sysz sysz; // SystemZ architecture
|
||||
cs_xcore xcore; // XCore architecture
|
||||
};
|
||||
} cs_detail;
|
||||
|
||||
// Detail information of disassembled instruction
|
||||
typedef struct cs_insn {
|
||||
// Instruction ID (basically a numeric ID for the instruction mnemonic)
|
||||
// Find the instruction id in the '[ARCH]_insn' enum in the header file
|
||||
// of corresponding architecture, such as 'arm_insn' in arm.h for ARM,
|
||||
// 'x86_insn' in x86.h for X86, etc...
|
||||
// This information is available even when CS_OPT_DETAIL = CS_OPT_OFF
|
||||
// NOTE: in Skipdata mode, "data" instruction has 0 for this id field.
|
||||
unsigned int id;
|
||||
|
||||
// Address (EIP) of this instruction
|
||||
// This information is available even when CS_OPT_DETAIL = CS_OPT_OFF
|
||||
uint64_t address;
|
||||
|
||||
// Size of this instruction
|
||||
// This information is available even when CS_OPT_DETAIL = CS_OPT_OFF
|
||||
uint16_t size;
|
||||
// Machine bytes of this instruction, with number of bytes indicated by @size above
|
||||
// This information is available even when CS_OPT_DETAIL = CS_OPT_OFF
|
||||
uint8_t bytes[16];
|
||||
|
||||
// Ascii text of instruction mnemonic
|
||||
// This information is available even when CS_OPT_DETAIL = CS_OPT_OFF
|
||||
char mnemonic[32];
|
||||
|
||||
// Ascii text of instruction operands
|
||||
// This information is available even when CS_OPT_DETAIL = CS_OPT_OFF
|
||||
char op_str[160];
|
||||
|
||||
// Pointer to cs_detail.
|
||||
// NOTE: detail pointer is only valid when both requirements below are met:
|
||||
// (1) CS_OP_DETAIL = CS_OPT_ON
|
||||
// (2) Engine is not in Skipdata mode (CS_OP_SKIPDATA option set to CS_OPT_ON)
|
||||
//
|
||||
// NOTE 2: when in Skipdata mode, or when detail mode is OFF, even if this pointer
|
||||
// is not NULL, its content is still irrelevant.
|
||||
cs_detail *detail;
|
||||
} cs_insn;
|
||||
|
||||
|
||||
// Calculate the offset of a disassembled instruction in its buffer, given its position
|
||||
// in its array of disassembled insn
|
||||
// NOTE: this macro works with position (>=1), not index
|
||||
#define CS_INSN_OFFSET(insns, post) (insns[post - 1].address - insns[0].address)
|
||||
|
||||
|
||||
// All type of errors encountered by Capstone API.
|
||||
// These are values returned by cs_errno()
|
||||
typedef enum cs_err {
|
||||
CS_ERR_OK = 0, // No error: everything was fine
|
||||
CS_ERR_MEM, // Out-Of-Memory error: cs_open(), cs_disasm(), cs_disasm_iter()
|
||||
CS_ERR_ARCH, // Unsupported architecture: cs_open()
|
||||
CS_ERR_HANDLE, // Invalid handle: cs_op_count(), cs_op_index()
|
||||
CS_ERR_CSH, // Invalid csh argument: cs_close(), cs_errno(), cs_option()
|
||||
CS_ERR_MODE, // Invalid/unsupported mode: cs_open()
|
||||
CS_ERR_OPTION, // Invalid/unsupported option: cs_option()
|
||||
CS_ERR_DETAIL, // Information is unavailable because detail option is OFF
|
||||
CS_ERR_MEMSETUP, // Dynamic memory management uninitialized (see CS_OPT_MEM)
|
||||
CS_ERR_VERSION, // Unsupported version (bindings)
|
||||
CS_ERR_DIET, // Access irrelevant data in "diet" engine
|
||||
CS_ERR_SKIPDATA, // Access irrelevant data for "data" instruction in SKIPDATA mode
|
||||
CS_ERR_X86_ATT, // X86 AT&T syntax is unsupported (opt-out at compile time)
|
||||
CS_ERR_X86_INTEL, // X86 Intel syntax is unsupported (opt-out at compile time)
|
||||
} cs_err;
|
||||
|
||||
/*
|
||||
Return combined API version & major and minor version numbers.
|
||||
|
||||
@major: major number of API version
|
||||
@minor: minor number of API version
|
||||
|
||||
@return hexical number as (major << 8 | minor), which encodes both
|
||||
major & minor versions.
|
||||
NOTE: This returned value can be compared with version number made
|
||||
with macro CS_MAKE_VERSION
|
||||
|
||||
For example, second API version would return 1 in @major, and 1 in @minor
|
||||
The return value would be 0x0101
|
||||
|
||||
NOTE: if you only care about returned value, but not major and minor values,
|
||||
set both @major & @minor arguments to NULL.
|
||||
*/
|
||||
CAPSTONE_EXPORT
|
||||
unsigned int CAPSTONE_API cs_version(int *major, int *minor);
|
||||
|
||||
|
||||
/*
|
||||
This API can be used to either ask for archs supported by this library,
|
||||
or check to see if the library was compile with 'diet' option (or called
|
||||
in 'diet' mode).
|
||||
|
||||
To check if a particular arch is supported by this library, set @query to
|
||||
arch mode (CS_ARCH_* value).
|
||||
To verify if this library supports all the archs, use CS_ARCH_ALL.
|
||||
|
||||
To check if this library is in 'diet' mode, set @query to CS_SUPPORT_DIET.
|
||||
|
||||
@return True if this library supports the given arch, or in 'diet' mode.
|
||||
*/
|
||||
CAPSTONE_EXPORT
|
||||
bool CAPSTONE_API cs_support(int query);
|
||||
|
||||
/*
|
||||
Initialize CS handle: this must be done before any usage of CS.
|
||||
|
||||
@arch: architecture type (CS_ARCH_*)
|
||||
@mode: hardware mode. This is combined of CS_MODE_*
|
||||
@handle: pointer to handle, which will be updated at return time
|
||||
|
||||
@return CS_ERR_OK on success, or other value on failure (refer to cs_err enum
|
||||
for detailed error).
|
||||
*/
|
||||
CAPSTONE_EXPORT
|
||||
cs_err CAPSTONE_API cs_open(cs_arch arch, cs_mode mode, csh *handle);
|
||||
|
||||
/*
|
||||
Close CS handle: MUST do to release the handle when it is not used anymore.
|
||||
NOTE: this must be only called when there is no longer usage of Capstone,
|
||||
not even access to cs_insn array. The reason is the this API releases some
|
||||
cached memory, thus access to any Capstone API after cs_close() might crash
|
||||
your application.
|
||||
|
||||
In fact,this API invalidate @handle by ZERO out its value (i.e *handle = 0).
|
||||
|
||||
@handle: pointer to a handle returned by cs_open()
|
||||
|
||||
@return CS_ERR_OK on success, or other value on failure (refer to cs_err enum
|
||||
for detailed error).
|
||||
*/
|
||||
CAPSTONE_EXPORT
|
||||
cs_err CAPSTONE_API cs_close(csh *handle);
|
||||
|
||||
/*
|
||||
Set option for disassembling engine at runtime
|
||||
|
||||
@handle: handle returned by cs_open()
|
||||
@type: type of option to be set
|
||||
@value: option value corresponding with @type
|
||||
|
||||
@return: CS_ERR_OK on success, or other value on failure.
|
||||
Refer to cs_err enum for detailed error.
|
||||
|
||||
NOTE: in the case of CS_OPT_MEM, handle's value can be anything,
|
||||
so that cs_option(handle, CS_OPT_MEM, value) can (i.e must) be called
|
||||
even before cs_open()
|
||||
*/
|
||||
CAPSTONE_EXPORT
|
||||
cs_err CAPSTONE_API cs_option(csh handle, cs_opt_type type, size_t value);
|
||||
|
||||
/*
|
||||
Report the last error number when some API function fail.
|
||||
Like glibc's errno, cs_errno might not retain its old value once accessed.
|
||||
|
||||
@handle: handle returned by cs_open()
|
||||
|
||||
@return: error code of cs_err enum type (CS_ERR_*, see above)
|
||||
*/
|
||||
CAPSTONE_EXPORT
|
||||
cs_err CAPSTONE_API cs_errno(csh handle);
|
||||
|
||||
|
||||
/*
|
||||
Return a string describing given error code.
|
||||
|
||||
@code: error code (see CS_ERR_* above)
|
||||
|
||||
@return: returns a pointer to a string that describes the error code
|
||||
passed in the argument @code
|
||||
*/
|
||||
CAPSTONE_EXPORT
|
||||
const char * CAPSTONE_API cs_strerror(cs_err code);
|
||||
|
||||
/*
|
||||
Disassemble binary code, given the code buffer, size, address and number
|
||||
of instructions to be decoded.
|
||||
This API dynamically allocate memory to contain disassembled instruction.
|
||||
Resulted instructions will be put into @*insn
|
||||
|
||||
NOTE 1: this API will automatically determine memory needed to contain
|
||||
output disassembled instructions in @insn.
|
||||
|
||||
NOTE 2: caller must free the allocated memory itself to avoid memory leaking.
|
||||
|
||||
NOTE 3: for system with scarce memory to be dynamically allocated such as
|
||||
OS kernel or firmware, the API cs_disasm_iter() might be a better choice than
|
||||
cs_disasm(). The reason is that with cs_disasm(), based on limited available
|
||||
memory, we have to calculate in advance how many instructions to be disassembled,
|
||||
which complicates things. This is especially troublesome for the case @count=0,
|
||||
when cs_disasm() runs uncontrollably (until either end of input buffer, or
|
||||
when it encounters an invalid instruction).
|
||||
|
||||
@handle: handle returned by cs_open()
|
||||
@code: buffer containing raw binary code to be disassembled.
|
||||
@code_size: size of the above code buffer.
|
||||
@address: address of the first instruction in given raw code buffer.
|
||||
@insn: array of instructions filled in by this API.
|
||||
NOTE: @insn will be allocated by this function, and should be freed
|
||||
with cs_free() API.
|
||||
@count: number of instructions to be disassembled, or 0 to get all of them
|
||||
|
||||
@return: the number of successfully disassembled instructions,
|
||||
or 0 if this function failed to disassemble the given code
|
||||
|
||||
On failure, call cs_errno() for error code.
|
||||
*/
|
||||
CAPSTONE_EXPORT
|
||||
size_t CAPSTONE_API cs_disasm(csh handle,
|
||||
const uint8_t *code, size_t code_size,
|
||||
uint64_t address,
|
||||
size_t count,
|
||||
cs_insn **insn);
|
||||
|
||||
/*
|
||||
Deprecated function - to be retired in the next version!
|
||||
Use cs_disasm() instead of cs_disasm_ex()
|
||||
*/
|
||||
CAPSTONE_EXPORT
|
||||
CAPSTONE_DEPRECATED
|
||||
size_t CAPSTONE_API cs_disasm_ex(csh handle,
|
||||
const uint8_t *code, size_t code_size,
|
||||
uint64_t address,
|
||||
size_t count,
|
||||
cs_insn **insn);
|
||||
|
||||
/*
|
||||
Free memory allocated by cs_malloc() or cs_disasm() (argument @insn)
|
||||
|
||||
@insn: pointer returned by @insn argument in cs_disasm() or cs_malloc()
|
||||
@count: number of cs_insn structures returned by cs_disasm(), or 1
|
||||
to free memory allocated by cs_malloc().
|
||||
*/
|
||||
CAPSTONE_EXPORT
|
||||
void CAPSTONE_API cs_free(cs_insn *insn, size_t count);
|
||||
|
||||
|
||||
/*
|
||||
Allocate memory for 1 instruction to be used by cs_disasm_iter().
|
||||
|
||||
@handle: handle returned by cs_open()
|
||||
|
||||
NOTE: when no longer in use, you can reclaim the memory allocated for
|
||||
this instruction with cs_free(insn, 1)
|
||||
*/
|
||||
CAPSTONE_EXPORT
|
||||
cs_insn * CAPSTONE_API cs_malloc(csh handle);
|
||||
|
||||
/*
|
||||
Fast API to disassemble binary code, given the code buffer, size, address
|
||||
and number of instructions to be decoded.
|
||||
This API put the resulted instruction into a given cache in @insn.
|
||||
See tests/test_iter.c for sample code demonstrating this API.
|
||||
|
||||
NOTE 1: this API will update @code, @size & @address to point to the next
|
||||
instruction in the input buffer. Therefore, it is convenient to use
|
||||
cs_disasm_iter() inside a loop to quickly iterate all the instructions.
|
||||
While decoding one instruction at a time can also be achieved with
|
||||
cs_disasm(count=1), some benchmarks shown that cs_disasm_iter() can be 30%
|
||||
faster on random input.
|
||||
|
||||
NOTE 2: the cache in @insn can be created with cs_malloc() API.
|
||||
|
||||
NOTE 3: for system with scarce memory to be dynamically allocated such as
|
||||
OS kernel or firmware, this API is recommended over cs_disasm(), which
|
||||
allocates memory based on the number of instructions to be disassembled.
|
||||
The reason is that with cs_disasm(), based on limited available memory,
|
||||
we have to calculate in advance how many instructions to be disassembled,
|
||||
which complicates things. This is especially troublesome for the case
|
||||
@count=0, when cs_disasm() runs uncontrollably (until either end of input
|
||||
buffer, or when it encounters an invalid instruction).
|
||||
|
||||
@handle: handle returned by cs_open()
|
||||
@code: buffer containing raw binary code to be disassembled
|
||||
@size: size of above code
|
||||
@address: address of the first insn in given raw code buffer
|
||||
@insn: pointer to instruction to be filled in by this API.
|
||||
|
||||
@return: true if this API successfully decode 1 instruction,
|
||||
or false otherwise.
|
||||
|
||||
On failure, call cs_errno() for error code.
|
||||
*/
|
||||
CAPSTONE_EXPORT
|
||||
bool CAPSTONE_API cs_disasm_iter(csh handle,
|
||||
const uint8_t **code, size_t *size,
|
||||
uint64_t *address, cs_insn *insn);
|
||||
|
||||
/*
|
||||
Return friendly name of register in a string.
|
||||
Find the instruction id from header file of corresponding architecture (arm.h for ARM,
|
||||
x86.h for X86, ...)
|
||||
|
||||
WARN: when in 'diet' mode, this API is irrelevant because engine does not
|
||||
store register name.
|
||||
|
||||
@handle: handle returned by cs_open()
|
||||
@reg_id: register id
|
||||
|
||||
@return: string name of the register, or NULL if @reg_id is invalid.
|
||||
*/
|
||||
CAPSTONE_EXPORT
|
||||
const char * CAPSTONE_API cs_reg_name(csh handle, unsigned int reg_id);
|
||||
|
||||
/*
|
||||
Return friendly name of an instruction in a string.
|
||||
Find the instruction id from header file of corresponding architecture (arm.h for ARM, x86.h for X86, ...)
|
||||
|
||||
WARN: when in 'diet' mode, this API is irrelevant because the engine does not
|
||||
store instruction name.
|
||||
|
||||
@handle: handle returned by cs_open()
|
||||
@insn_id: instruction id
|
||||
|
||||
@return: string name of the instruction, or NULL if @insn_id is invalid.
|
||||
*/
|
||||
CAPSTONE_EXPORT
|
||||
const char * CAPSTONE_API cs_insn_name(csh handle, unsigned int insn_id);
|
||||
|
||||
/*
|
||||
Return friendly name of a group id (that an instruction can belong to)
|
||||
Find the group id from header file of corresponding architecture (arm.h for ARM, x86.h for X86, ...)
|
||||
|
||||
WARN: when in 'diet' mode, this API is irrelevant because the engine does not
|
||||
store group name.
|
||||
|
||||
@handle: handle returned by cs_open()
|
||||
@group_id: group id
|
||||
|
||||
@return: string name of the group, or NULL if @group_id is invalid.
|
||||
*/
|
||||
CAPSTONE_EXPORT
|
||||
const char * CAPSTONE_API cs_group_name(csh handle, unsigned int group_id);
|
||||
|
||||
/*
|
||||
Check if a disassembled instruction belong to a particular group.
|
||||
Find the group id from header file of corresponding architecture (arm.h for ARM, x86.h for X86, ...)
|
||||
Internally, this simply verifies if @group_id matches any member of insn->groups array.
|
||||
|
||||
NOTE: this API is only valid when detail option is ON (which is OFF by default).
|
||||
|
||||
WARN: when in 'diet' mode, this API is irrelevant because the engine does not
|
||||
update @groups array.
|
||||
|
||||
@handle: handle returned by cs_open()
|
||||
@insn: disassembled instruction structure received from cs_disasm() or cs_disasm_iter()
|
||||
@group_id: group that you want to check if this instruction belong to.
|
||||
|
||||
@return: true if this instruction indeed belongs to aboved group, or false otherwise.
|
||||
*/
|
||||
CAPSTONE_EXPORT
|
||||
bool CAPSTONE_API cs_insn_group(csh handle, const cs_insn *insn, unsigned int group_id);
|
||||
|
||||
/*
|
||||
Check if a disassembled instruction IMPLICITLY used a particular register.
|
||||
Find the register id from header file of corresponding architecture (arm.h for ARM, x86.h for X86, ...)
|
||||
Internally, this simply verifies if @reg_id matches any member of insn->regs_read array.
|
||||
|
||||
NOTE: this API is only valid when detail option is ON (which is OFF by default)
|
||||
|
||||
WARN: when in 'diet' mode, this API is irrelevant because the engine does not
|
||||
update @regs_read array.
|
||||
|
||||
@insn: disassembled instruction structure received from cs_disasm() or cs_disasm_iter()
|
||||
@reg_id: register that you want to check if this instruction used it.
|
||||
|
||||
@return: true if this instruction indeed implicitly used aboved register, or false otherwise.
|
||||
*/
|
||||
CAPSTONE_EXPORT
|
||||
bool CAPSTONE_API cs_reg_read(csh handle, const cs_insn *insn, unsigned int reg_id);
|
||||
|
||||
/*
|
||||
Check if a disassembled instruction IMPLICITLY modified a particular register.
|
||||
Find the register id from header file of corresponding architecture (arm.h for ARM, x86.h for X86, ...)
|
||||
Internally, this simply verifies if @reg_id matches any member of insn->regs_write array.
|
||||
|
||||
NOTE: this API is only valid when detail option is ON (which is OFF by default)
|
||||
|
||||
WARN: when in 'diet' mode, this API is irrelevant because the engine does not
|
||||
update @regs_write array.
|
||||
|
||||
@insn: disassembled instruction structure received from cs_disasm() or cs_disasm_iter()
|
||||
@reg_id: register that you want to check if this instruction modified it.
|
||||
|
||||
@return: true if this instruction indeed implicitly modified aboved register, or false otherwise.
|
||||
*/
|
||||
CAPSTONE_EXPORT
|
||||
bool CAPSTONE_API cs_reg_write(csh handle, const cs_insn *insn, unsigned int reg_id);
|
||||
|
||||
/*
|
||||
Count the number of operands of a given type.
|
||||
Find the operand type in header file of corresponding architecture (arm.h for ARM, x86.h for X86, ...)
|
||||
|
||||
NOTE: this API is only valid when detail option is ON (which is OFF by default)
|
||||
|
||||
@handle: handle returned by cs_open()
|
||||
@insn: disassembled instruction structure received from cs_disasm() or cs_disasm_iter()
|
||||
@op_type: Operand type to be found.
|
||||
|
||||
@return: number of operands of given type @op_type in instruction @insn,
|
||||
or -1 on failure.
|
||||
*/
|
||||
CAPSTONE_EXPORT
|
||||
int CAPSTONE_API cs_op_count(csh handle, const cs_insn *insn, unsigned int op_type);
|
||||
|
||||
/*
|
||||
Retrieve the position of operand of given type in <arch>.operands[] array.
|
||||
Later, the operand can be accessed using the returned position.
|
||||
Find the operand type in header file of corresponding architecture (arm.h for ARM, x86.h for X86, ...)
|
||||
|
||||
NOTE: this API is only valid when detail option is ON (which is OFF by default)
|
||||
|
||||
@handle: handle returned by cs_open()
|
||||
@insn: disassembled instruction structure received from cs_disasm() or cs_disasm_iter()
|
||||
@op_type: Operand type to be found.
|
||||
@position: position of the operand to be found. This must be in the range
|
||||
[1, cs_op_count(handle, insn, op_type)]
|
||||
|
||||
@return: index of operand of given type @op_type in <arch>.operands[] array
|
||||
in instruction @insn, or -1 on failure.
|
||||
*/
|
||||
CAPSTONE_EXPORT
|
||||
int CAPSTONE_API cs_op_index(csh handle, const cs_insn *insn, unsigned int op_type,
|
||||
unsigned int position);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,906 @@
|
||||
#ifndef CAPSTONE_MIPS_H
|
||||
#define CAPSTONE_MIPS_H
|
||||
|
||||
/* Capstone Disassembly Engine */
|
||||
/* By Nguyen Anh Quynh <aquynh@gmail.com>, 2013-2014 */
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#if !defined(_MSC_VER) || !defined(_KERNEL_MODE)
|
||||
#include <stdint.h>
|
||||
#endif
|
||||
|
||||
#include "platform.h"
|
||||
|
||||
// GCC MIPS toolchain has a default macro called "mips" which breaks
|
||||
// compilation
|
||||
#undef mips
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#pragma warning(disable:4201)
|
||||
#endif
|
||||
|
||||
//> Operand type for instruction's operands
|
||||
typedef enum mips_op_type {
|
||||
MIPS_OP_INVALID = 0, // = CS_OP_INVALID (Uninitialized).
|
||||
MIPS_OP_REG, // = CS_OP_REG (Register operand).
|
||||
MIPS_OP_IMM, // = CS_OP_IMM (Immediate operand).
|
||||
MIPS_OP_MEM, // = CS_OP_MEM (Memory operand).
|
||||
} mips_op_type;
|
||||
|
||||
// Instruction's operand referring to memory
|
||||
// This is associated with MIPS_OP_MEM operand type above
|
||||
typedef struct mips_op_mem {
|
||||
unsigned int base; // base register
|
||||
int64_t disp; // displacement/offset value
|
||||
} mips_op_mem;
|
||||
|
||||
// Instruction operand
|
||||
typedef struct cs_mips_op {
|
||||
mips_op_type type; // operand type
|
||||
union {
|
||||
unsigned int reg; // register value for REG operand
|
||||
int64_t imm; // immediate value for IMM operand
|
||||
mips_op_mem mem; // base/index/scale/disp value for MEM operand
|
||||
};
|
||||
} cs_mips_op;
|
||||
|
||||
// Instruction structure
|
||||
typedef struct cs_mips {
|
||||
// Number of operands of this instruction,
|
||||
// or 0 when instruction has no operand.
|
||||
uint8_t op_count;
|
||||
cs_mips_op operands[8]; // operands for this instruction.
|
||||
} cs_mips;
|
||||
|
||||
//> MIPS registers
|
||||
typedef enum mips_reg {
|
||||
MIPS_REG_INVALID = 0,
|
||||
//> General purpose registers
|
||||
MIPS_REG_0,
|
||||
MIPS_REG_1,
|
||||
MIPS_REG_2,
|
||||
MIPS_REG_3,
|
||||
MIPS_REG_4,
|
||||
MIPS_REG_5,
|
||||
MIPS_REG_6,
|
||||
MIPS_REG_7,
|
||||
MIPS_REG_8,
|
||||
MIPS_REG_9,
|
||||
MIPS_REG_10,
|
||||
MIPS_REG_11,
|
||||
MIPS_REG_12,
|
||||
MIPS_REG_13,
|
||||
MIPS_REG_14,
|
||||
MIPS_REG_15,
|
||||
MIPS_REG_16,
|
||||
MIPS_REG_17,
|
||||
MIPS_REG_18,
|
||||
MIPS_REG_19,
|
||||
MIPS_REG_20,
|
||||
MIPS_REG_21,
|
||||
MIPS_REG_22,
|
||||
MIPS_REG_23,
|
||||
MIPS_REG_24,
|
||||
MIPS_REG_25,
|
||||
MIPS_REG_26,
|
||||
MIPS_REG_27,
|
||||
MIPS_REG_28,
|
||||
MIPS_REG_29,
|
||||
MIPS_REG_30,
|
||||
MIPS_REG_31,
|
||||
|
||||
//> DSP registers
|
||||
MIPS_REG_DSPCCOND,
|
||||
MIPS_REG_DSPCARRY,
|
||||
MIPS_REG_DSPEFI,
|
||||
MIPS_REG_DSPOUTFLAG,
|
||||
MIPS_REG_DSPOUTFLAG16_19,
|
||||
MIPS_REG_DSPOUTFLAG20,
|
||||
MIPS_REG_DSPOUTFLAG21,
|
||||
MIPS_REG_DSPOUTFLAG22,
|
||||
MIPS_REG_DSPOUTFLAG23,
|
||||
MIPS_REG_DSPPOS,
|
||||
MIPS_REG_DSPSCOUNT,
|
||||
|
||||
//> ACC registers
|
||||
MIPS_REG_AC0,
|
||||
MIPS_REG_AC1,
|
||||
MIPS_REG_AC2,
|
||||
MIPS_REG_AC3,
|
||||
|
||||
//> COP registers
|
||||
MIPS_REG_CC0,
|
||||
MIPS_REG_CC1,
|
||||
MIPS_REG_CC2,
|
||||
MIPS_REG_CC3,
|
||||
MIPS_REG_CC4,
|
||||
MIPS_REG_CC5,
|
||||
MIPS_REG_CC6,
|
||||
MIPS_REG_CC7,
|
||||
|
||||
//> FPU registers
|
||||
MIPS_REG_F0,
|
||||
MIPS_REG_F1,
|
||||
MIPS_REG_F2,
|
||||
MIPS_REG_F3,
|
||||
MIPS_REG_F4,
|
||||
MIPS_REG_F5,
|
||||
MIPS_REG_F6,
|
||||
MIPS_REG_F7,
|
||||
MIPS_REG_F8,
|
||||
MIPS_REG_F9,
|
||||
MIPS_REG_F10,
|
||||
MIPS_REG_F11,
|
||||
MIPS_REG_F12,
|
||||
MIPS_REG_F13,
|
||||
MIPS_REG_F14,
|
||||
MIPS_REG_F15,
|
||||
MIPS_REG_F16,
|
||||
MIPS_REG_F17,
|
||||
MIPS_REG_F18,
|
||||
MIPS_REG_F19,
|
||||
MIPS_REG_F20,
|
||||
MIPS_REG_F21,
|
||||
MIPS_REG_F22,
|
||||
MIPS_REG_F23,
|
||||
MIPS_REG_F24,
|
||||
MIPS_REG_F25,
|
||||
MIPS_REG_F26,
|
||||
MIPS_REG_F27,
|
||||
MIPS_REG_F28,
|
||||
MIPS_REG_F29,
|
||||
MIPS_REG_F30,
|
||||
MIPS_REG_F31,
|
||||
|
||||
MIPS_REG_FCC0,
|
||||
MIPS_REG_FCC1,
|
||||
MIPS_REG_FCC2,
|
||||
MIPS_REG_FCC3,
|
||||
MIPS_REG_FCC4,
|
||||
MIPS_REG_FCC5,
|
||||
MIPS_REG_FCC6,
|
||||
MIPS_REG_FCC7,
|
||||
|
||||
//> AFPR128
|
||||
MIPS_REG_W0,
|
||||
MIPS_REG_W1,
|
||||
MIPS_REG_W2,
|
||||
MIPS_REG_W3,
|
||||
MIPS_REG_W4,
|
||||
MIPS_REG_W5,
|
||||
MIPS_REG_W6,
|
||||
MIPS_REG_W7,
|
||||
MIPS_REG_W8,
|
||||
MIPS_REG_W9,
|
||||
MIPS_REG_W10,
|
||||
MIPS_REG_W11,
|
||||
MIPS_REG_W12,
|
||||
MIPS_REG_W13,
|
||||
MIPS_REG_W14,
|
||||
MIPS_REG_W15,
|
||||
MIPS_REG_W16,
|
||||
MIPS_REG_W17,
|
||||
MIPS_REG_W18,
|
||||
MIPS_REG_W19,
|
||||
MIPS_REG_W20,
|
||||
MIPS_REG_W21,
|
||||
MIPS_REG_W22,
|
||||
MIPS_REG_W23,
|
||||
MIPS_REG_W24,
|
||||
MIPS_REG_W25,
|
||||
MIPS_REG_W26,
|
||||
MIPS_REG_W27,
|
||||
MIPS_REG_W28,
|
||||
MIPS_REG_W29,
|
||||
MIPS_REG_W30,
|
||||
MIPS_REG_W31,
|
||||
|
||||
MIPS_REG_HI,
|
||||
MIPS_REG_LO,
|
||||
|
||||
MIPS_REG_P0,
|
||||
MIPS_REG_P1,
|
||||
MIPS_REG_P2,
|
||||
|
||||
MIPS_REG_MPL0,
|
||||
MIPS_REG_MPL1,
|
||||
MIPS_REG_MPL2,
|
||||
|
||||
MIPS_REG_ENDING, // <-- mark the end of the list or registers
|
||||
|
||||
// alias registers
|
||||
MIPS_REG_ZERO = MIPS_REG_0,
|
||||
MIPS_REG_AT = MIPS_REG_1,
|
||||
MIPS_REG_V0 = MIPS_REG_2,
|
||||
MIPS_REG_V1 = MIPS_REG_3,
|
||||
MIPS_REG_A0 = MIPS_REG_4,
|
||||
MIPS_REG_A1 = MIPS_REG_5,
|
||||
MIPS_REG_A2 = MIPS_REG_6,
|
||||
MIPS_REG_A3 = MIPS_REG_7,
|
||||
MIPS_REG_T0 = MIPS_REG_8,
|
||||
MIPS_REG_T1 = MIPS_REG_9,
|
||||
MIPS_REG_T2 = MIPS_REG_10,
|
||||
MIPS_REG_T3 = MIPS_REG_11,
|
||||
MIPS_REG_T4 = MIPS_REG_12,
|
||||
MIPS_REG_T5 = MIPS_REG_13,
|
||||
MIPS_REG_T6 = MIPS_REG_14,
|
||||
MIPS_REG_T7 = MIPS_REG_15,
|
||||
MIPS_REG_S0 = MIPS_REG_16,
|
||||
MIPS_REG_S1 = MIPS_REG_17,
|
||||
MIPS_REG_S2 = MIPS_REG_18,
|
||||
MIPS_REG_S3 = MIPS_REG_19,
|
||||
MIPS_REG_S4 = MIPS_REG_20,
|
||||
MIPS_REG_S5 = MIPS_REG_21,
|
||||
MIPS_REG_S6 = MIPS_REG_22,
|
||||
MIPS_REG_S7 = MIPS_REG_23,
|
||||
MIPS_REG_T8 = MIPS_REG_24,
|
||||
MIPS_REG_T9 = MIPS_REG_25,
|
||||
MIPS_REG_K0 = MIPS_REG_26,
|
||||
MIPS_REG_K1 = MIPS_REG_27,
|
||||
MIPS_REG_GP = MIPS_REG_28,
|
||||
MIPS_REG_SP = MIPS_REG_29,
|
||||
MIPS_REG_FP = MIPS_REG_30, MIPS_REG_S8 = MIPS_REG_30,
|
||||
MIPS_REG_RA = MIPS_REG_31,
|
||||
|
||||
MIPS_REG_HI0 = MIPS_REG_AC0,
|
||||
MIPS_REG_HI1 = MIPS_REG_AC1,
|
||||
MIPS_REG_HI2 = MIPS_REG_AC2,
|
||||
MIPS_REG_HI3 = MIPS_REG_AC3,
|
||||
|
||||
MIPS_REG_LO0 = MIPS_REG_HI0,
|
||||
MIPS_REG_LO1 = MIPS_REG_HI1,
|
||||
MIPS_REG_LO2 = MIPS_REG_HI2,
|
||||
MIPS_REG_LO3 = MIPS_REG_HI3,
|
||||
} mips_reg;
|
||||
|
||||
//> MIPS instruction
|
||||
typedef enum mips_insn {
|
||||
MIPS_INS_INVALID = 0,
|
||||
|
||||
MIPS_INS_ABSQ_S,
|
||||
MIPS_INS_ADD,
|
||||
MIPS_INS_ADDIUPC,
|
||||
MIPS_INS_ADDQH,
|
||||
MIPS_INS_ADDQH_R,
|
||||
MIPS_INS_ADDQ,
|
||||
MIPS_INS_ADDQ_S,
|
||||
MIPS_INS_ADDSC,
|
||||
MIPS_INS_ADDS_A,
|
||||
MIPS_INS_ADDS_S,
|
||||
MIPS_INS_ADDS_U,
|
||||
MIPS_INS_ADDUH,
|
||||
MIPS_INS_ADDUH_R,
|
||||
MIPS_INS_ADDU,
|
||||
MIPS_INS_ADDU_S,
|
||||
MIPS_INS_ADDVI,
|
||||
MIPS_INS_ADDV,
|
||||
MIPS_INS_ADDWC,
|
||||
MIPS_INS_ADD_A,
|
||||
MIPS_INS_ADDI,
|
||||
MIPS_INS_ADDIU,
|
||||
MIPS_INS_ALIGN,
|
||||
MIPS_INS_ALUIPC,
|
||||
MIPS_INS_AND,
|
||||
MIPS_INS_ANDI,
|
||||
MIPS_INS_APPEND,
|
||||
MIPS_INS_ASUB_S,
|
||||
MIPS_INS_ASUB_U,
|
||||
MIPS_INS_AUI,
|
||||
MIPS_INS_AUIPC,
|
||||
MIPS_INS_AVER_S,
|
||||
MIPS_INS_AVER_U,
|
||||
MIPS_INS_AVE_S,
|
||||
MIPS_INS_AVE_U,
|
||||
MIPS_INS_BADDU,
|
||||
MIPS_INS_BAL,
|
||||
MIPS_INS_BALC,
|
||||
MIPS_INS_BALIGN,
|
||||
MIPS_INS_BC,
|
||||
MIPS_INS_BC0F,
|
||||
MIPS_INS_BC0FL,
|
||||
MIPS_INS_BC0T,
|
||||
MIPS_INS_BC0TL,
|
||||
MIPS_INS_BC1EQZ,
|
||||
MIPS_INS_BC1F,
|
||||
MIPS_INS_BC1FL,
|
||||
MIPS_INS_BC1NEZ,
|
||||
MIPS_INS_BC1T,
|
||||
MIPS_INS_BC1TL,
|
||||
MIPS_INS_BC2EQZ,
|
||||
MIPS_INS_BC2F,
|
||||
MIPS_INS_BC2FL,
|
||||
MIPS_INS_BC2NEZ,
|
||||
MIPS_INS_BC2T,
|
||||
MIPS_INS_BC2TL,
|
||||
MIPS_INS_BC3F,
|
||||
MIPS_INS_BC3FL,
|
||||
MIPS_INS_BC3T,
|
||||
MIPS_INS_BC3TL,
|
||||
MIPS_INS_BCLRI,
|
||||
MIPS_INS_BCLR,
|
||||
MIPS_INS_BEQ,
|
||||
MIPS_INS_BEQC,
|
||||
MIPS_INS_BEQL,
|
||||
MIPS_INS_BEQZALC,
|
||||
MIPS_INS_BEQZC,
|
||||
MIPS_INS_BGEC,
|
||||
MIPS_INS_BGEUC,
|
||||
MIPS_INS_BGEZ,
|
||||
MIPS_INS_BGEZAL,
|
||||
MIPS_INS_BGEZALC,
|
||||
MIPS_INS_BGEZALL,
|
||||
MIPS_INS_BGEZALS,
|
||||
MIPS_INS_BGEZC,
|
||||
MIPS_INS_BGEZL,
|
||||
MIPS_INS_BGTZ,
|
||||
MIPS_INS_BGTZALC,
|
||||
MIPS_INS_BGTZC,
|
||||
MIPS_INS_BGTZL,
|
||||
MIPS_INS_BINSLI,
|
||||
MIPS_INS_BINSL,
|
||||
MIPS_INS_BINSRI,
|
||||
MIPS_INS_BINSR,
|
||||
MIPS_INS_BITREV,
|
||||
MIPS_INS_BITSWAP,
|
||||
MIPS_INS_BLEZ,
|
||||
MIPS_INS_BLEZALC,
|
||||
MIPS_INS_BLEZC,
|
||||
MIPS_INS_BLEZL,
|
||||
MIPS_INS_BLTC,
|
||||
MIPS_INS_BLTUC,
|
||||
MIPS_INS_BLTZ,
|
||||
MIPS_INS_BLTZAL,
|
||||
MIPS_INS_BLTZALC,
|
||||
MIPS_INS_BLTZALL,
|
||||
MIPS_INS_BLTZALS,
|
||||
MIPS_INS_BLTZC,
|
||||
MIPS_INS_BLTZL,
|
||||
MIPS_INS_BMNZI,
|
||||
MIPS_INS_BMNZ,
|
||||
MIPS_INS_BMZI,
|
||||
MIPS_INS_BMZ,
|
||||
MIPS_INS_BNE,
|
||||
MIPS_INS_BNEC,
|
||||
MIPS_INS_BNEGI,
|
||||
MIPS_INS_BNEG,
|
||||
MIPS_INS_BNEL,
|
||||
MIPS_INS_BNEZALC,
|
||||
MIPS_INS_BNEZC,
|
||||
MIPS_INS_BNVC,
|
||||
MIPS_INS_BNZ,
|
||||
MIPS_INS_BOVC,
|
||||
MIPS_INS_BPOSGE32,
|
||||
MIPS_INS_BREAK,
|
||||
MIPS_INS_BSELI,
|
||||
MIPS_INS_BSEL,
|
||||
MIPS_INS_BSETI,
|
||||
MIPS_INS_BSET,
|
||||
MIPS_INS_BZ,
|
||||
MIPS_INS_BEQZ,
|
||||
MIPS_INS_B,
|
||||
MIPS_INS_BNEZ,
|
||||
MIPS_INS_BTEQZ,
|
||||
MIPS_INS_BTNEZ,
|
||||
MIPS_INS_CACHE,
|
||||
MIPS_INS_CEIL,
|
||||
MIPS_INS_CEQI,
|
||||
MIPS_INS_CEQ,
|
||||
MIPS_INS_CFC1,
|
||||
MIPS_INS_CFCMSA,
|
||||
MIPS_INS_CINS,
|
||||
MIPS_INS_CINS32,
|
||||
MIPS_INS_CLASS,
|
||||
MIPS_INS_CLEI_S,
|
||||
MIPS_INS_CLEI_U,
|
||||
MIPS_INS_CLE_S,
|
||||
MIPS_INS_CLE_U,
|
||||
MIPS_INS_CLO,
|
||||
MIPS_INS_CLTI_S,
|
||||
MIPS_INS_CLTI_U,
|
||||
MIPS_INS_CLT_S,
|
||||
MIPS_INS_CLT_U,
|
||||
MIPS_INS_CLZ,
|
||||
MIPS_INS_CMPGDU,
|
||||
MIPS_INS_CMPGU,
|
||||
MIPS_INS_CMPU,
|
||||
MIPS_INS_CMP,
|
||||
MIPS_INS_COPY_S,
|
||||
MIPS_INS_COPY_U,
|
||||
MIPS_INS_CTC1,
|
||||
MIPS_INS_CTCMSA,
|
||||
MIPS_INS_CVT,
|
||||
MIPS_INS_C,
|
||||
MIPS_INS_CMPI,
|
||||
MIPS_INS_DADD,
|
||||
MIPS_INS_DADDI,
|
||||
MIPS_INS_DADDIU,
|
||||
MIPS_INS_DADDU,
|
||||
MIPS_INS_DAHI,
|
||||
MIPS_INS_DALIGN,
|
||||
MIPS_INS_DATI,
|
||||
MIPS_INS_DAUI,
|
||||
MIPS_INS_DBITSWAP,
|
||||
MIPS_INS_DCLO,
|
||||
MIPS_INS_DCLZ,
|
||||
MIPS_INS_DDIV,
|
||||
MIPS_INS_DDIVU,
|
||||
MIPS_INS_DERET,
|
||||
MIPS_INS_DEXT,
|
||||
MIPS_INS_DEXTM,
|
||||
MIPS_INS_DEXTU,
|
||||
MIPS_INS_DI,
|
||||
MIPS_INS_DINS,
|
||||
MIPS_INS_DINSM,
|
||||
MIPS_INS_DINSU,
|
||||
MIPS_INS_DIV,
|
||||
MIPS_INS_DIVU,
|
||||
MIPS_INS_DIV_S,
|
||||
MIPS_INS_DIV_U,
|
||||
MIPS_INS_DLSA,
|
||||
MIPS_INS_DMFC0,
|
||||
MIPS_INS_DMFC1,
|
||||
MIPS_INS_DMFC2,
|
||||
MIPS_INS_DMOD,
|
||||
MIPS_INS_DMODU,
|
||||
MIPS_INS_DMTC0,
|
||||
MIPS_INS_DMTC1,
|
||||
MIPS_INS_DMTC2,
|
||||
MIPS_INS_DMUH,
|
||||
MIPS_INS_DMUHU,
|
||||
MIPS_INS_DMUL,
|
||||
MIPS_INS_DMULT,
|
||||
MIPS_INS_DMULTU,
|
||||
MIPS_INS_DMULU,
|
||||
MIPS_INS_DOTP_S,
|
||||
MIPS_INS_DOTP_U,
|
||||
MIPS_INS_DPADD_S,
|
||||
MIPS_INS_DPADD_U,
|
||||
MIPS_INS_DPAQX_SA,
|
||||
MIPS_INS_DPAQX_S,
|
||||
MIPS_INS_DPAQ_SA,
|
||||
MIPS_INS_DPAQ_S,
|
||||
MIPS_INS_DPAU,
|
||||
MIPS_INS_DPAX,
|
||||
MIPS_INS_DPA,
|
||||
MIPS_INS_DPOP,
|
||||
MIPS_INS_DPSQX_SA,
|
||||
MIPS_INS_DPSQX_S,
|
||||
MIPS_INS_DPSQ_SA,
|
||||
MIPS_INS_DPSQ_S,
|
||||
MIPS_INS_DPSUB_S,
|
||||
MIPS_INS_DPSUB_U,
|
||||
MIPS_INS_DPSU,
|
||||
MIPS_INS_DPSX,
|
||||
MIPS_INS_DPS,
|
||||
MIPS_INS_DROTR,
|
||||
MIPS_INS_DROTR32,
|
||||
MIPS_INS_DROTRV,
|
||||
MIPS_INS_DSBH,
|
||||
MIPS_INS_DSHD,
|
||||
MIPS_INS_DSLL,
|
||||
MIPS_INS_DSLL32,
|
||||
MIPS_INS_DSLLV,
|
||||
MIPS_INS_DSRA,
|
||||
MIPS_INS_DSRA32,
|
||||
MIPS_INS_DSRAV,
|
||||
MIPS_INS_DSRL,
|
||||
MIPS_INS_DSRL32,
|
||||
MIPS_INS_DSRLV,
|
||||
MIPS_INS_DSUB,
|
||||
MIPS_INS_DSUBU,
|
||||
MIPS_INS_EHB,
|
||||
MIPS_INS_EI,
|
||||
MIPS_INS_ERET,
|
||||
MIPS_INS_EXT,
|
||||
MIPS_INS_EXTP,
|
||||
MIPS_INS_EXTPDP,
|
||||
MIPS_INS_EXTPDPV,
|
||||
MIPS_INS_EXTPV,
|
||||
MIPS_INS_EXTRV_RS,
|
||||
MIPS_INS_EXTRV_R,
|
||||
MIPS_INS_EXTRV_S,
|
||||
MIPS_INS_EXTRV,
|
||||
MIPS_INS_EXTR_RS,
|
||||
MIPS_INS_EXTR_R,
|
||||
MIPS_INS_EXTR_S,
|
||||
MIPS_INS_EXTR,
|
||||
MIPS_INS_EXTS,
|
||||
MIPS_INS_EXTS32,
|
||||
MIPS_INS_ABS,
|
||||
MIPS_INS_FADD,
|
||||
MIPS_INS_FCAF,
|
||||
MIPS_INS_FCEQ,
|
||||
MIPS_INS_FCLASS,
|
||||
MIPS_INS_FCLE,
|
||||
MIPS_INS_FCLT,
|
||||
MIPS_INS_FCNE,
|
||||
MIPS_INS_FCOR,
|
||||
MIPS_INS_FCUEQ,
|
||||
MIPS_INS_FCULE,
|
||||
MIPS_INS_FCULT,
|
||||
MIPS_INS_FCUNE,
|
||||
MIPS_INS_FCUN,
|
||||
MIPS_INS_FDIV,
|
||||
MIPS_INS_FEXDO,
|
||||
MIPS_INS_FEXP2,
|
||||
MIPS_INS_FEXUPL,
|
||||
MIPS_INS_FEXUPR,
|
||||
MIPS_INS_FFINT_S,
|
||||
MIPS_INS_FFINT_U,
|
||||
MIPS_INS_FFQL,
|
||||
MIPS_INS_FFQR,
|
||||
MIPS_INS_FILL,
|
||||
MIPS_INS_FLOG2,
|
||||
MIPS_INS_FLOOR,
|
||||
MIPS_INS_FMADD,
|
||||
MIPS_INS_FMAX_A,
|
||||
MIPS_INS_FMAX,
|
||||
MIPS_INS_FMIN_A,
|
||||
MIPS_INS_FMIN,
|
||||
MIPS_INS_MOV,
|
||||
MIPS_INS_FMSUB,
|
||||
MIPS_INS_FMUL,
|
||||
MIPS_INS_MUL,
|
||||
MIPS_INS_NEG,
|
||||
MIPS_INS_FRCP,
|
||||
MIPS_INS_FRINT,
|
||||
MIPS_INS_FRSQRT,
|
||||
MIPS_INS_FSAF,
|
||||
MIPS_INS_FSEQ,
|
||||
MIPS_INS_FSLE,
|
||||
MIPS_INS_FSLT,
|
||||
MIPS_INS_FSNE,
|
||||
MIPS_INS_FSOR,
|
||||
MIPS_INS_FSQRT,
|
||||
MIPS_INS_SQRT,
|
||||
MIPS_INS_FSUB,
|
||||
MIPS_INS_SUB,
|
||||
MIPS_INS_FSUEQ,
|
||||
MIPS_INS_FSULE,
|
||||
MIPS_INS_FSULT,
|
||||
MIPS_INS_FSUNE,
|
||||
MIPS_INS_FSUN,
|
||||
MIPS_INS_FTINT_S,
|
||||
MIPS_INS_FTINT_U,
|
||||
MIPS_INS_FTQ,
|
||||
MIPS_INS_FTRUNC_S,
|
||||
MIPS_INS_FTRUNC_U,
|
||||
MIPS_INS_HADD_S,
|
||||
MIPS_INS_HADD_U,
|
||||
MIPS_INS_HSUB_S,
|
||||
MIPS_INS_HSUB_U,
|
||||
MIPS_INS_ILVEV,
|
||||
MIPS_INS_ILVL,
|
||||
MIPS_INS_ILVOD,
|
||||
MIPS_INS_ILVR,
|
||||
MIPS_INS_INS,
|
||||
MIPS_INS_INSERT,
|
||||
MIPS_INS_INSV,
|
||||
MIPS_INS_INSVE,
|
||||
MIPS_INS_J,
|
||||
MIPS_INS_JAL,
|
||||
MIPS_INS_JALR,
|
||||
MIPS_INS_JALRS,
|
||||
MIPS_INS_JALS,
|
||||
MIPS_INS_JALX,
|
||||
MIPS_INS_JIALC,
|
||||
MIPS_INS_JIC,
|
||||
MIPS_INS_JR,
|
||||
MIPS_INS_JRADDIUSP,
|
||||
MIPS_INS_JRC,
|
||||
MIPS_INS_JALRC,
|
||||
MIPS_INS_LB,
|
||||
MIPS_INS_LBUX,
|
||||
MIPS_INS_LBU,
|
||||
MIPS_INS_LD,
|
||||
MIPS_INS_LDC1,
|
||||
MIPS_INS_LDC2,
|
||||
MIPS_INS_LDC3,
|
||||
MIPS_INS_LDI,
|
||||
MIPS_INS_LDL,
|
||||
MIPS_INS_LDPC,
|
||||
MIPS_INS_LDR,
|
||||
MIPS_INS_LDXC1,
|
||||
MIPS_INS_LH,
|
||||
MIPS_INS_LHX,
|
||||
MIPS_INS_LHU,
|
||||
MIPS_INS_LL,
|
||||
MIPS_INS_LLD,
|
||||
MIPS_INS_LSA,
|
||||
MIPS_INS_LUXC1,
|
||||
MIPS_INS_LUI,
|
||||
MIPS_INS_LW,
|
||||
MIPS_INS_LWC1,
|
||||
MIPS_INS_LWC2,
|
||||
MIPS_INS_LWC3,
|
||||
MIPS_INS_LWL,
|
||||
MIPS_INS_LWPC,
|
||||
MIPS_INS_LWR,
|
||||
MIPS_INS_LWUPC,
|
||||
MIPS_INS_LWU,
|
||||
MIPS_INS_LWX,
|
||||
MIPS_INS_LWXC1,
|
||||
MIPS_INS_LI,
|
||||
MIPS_INS_MADD,
|
||||
MIPS_INS_MADDF,
|
||||
MIPS_INS_MADDR_Q,
|
||||
MIPS_INS_MADDU,
|
||||
MIPS_INS_MADDV,
|
||||
MIPS_INS_MADD_Q,
|
||||
MIPS_INS_MAQ_SA,
|
||||
MIPS_INS_MAQ_S,
|
||||
MIPS_INS_MAXA,
|
||||
MIPS_INS_MAXI_S,
|
||||
MIPS_INS_MAXI_U,
|
||||
MIPS_INS_MAX_A,
|
||||
MIPS_INS_MAX,
|
||||
MIPS_INS_MAX_S,
|
||||
MIPS_INS_MAX_U,
|
||||
MIPS_INS_MFC0,
|
||||
MIPS_INS_MFC1,
|
||||
MIPS_INS_MFC2,
|
||||
MIPS_INS_MFHC1,
|
||||
MIPS_INS_MFHI,
|
||||
MIPS_INS_MFLO,
|
||||
MIPS_INS_MINA,
|
||||
MIPS_INS_MINI_S,
|
||||
MIPS_INS_MINI_U,
|
||||
MIPS_INS_MIN_A,
|
||||
MIPS_INS_MIN,
|
||||
MIPS_INS_MIN_S,
|
||||
MIPS_INS_MIN_U,
|
||||
MIPS_INS_MOD,
|
||||
MIPS_INS_MODSUB,
|
||||
MIPS_INS_MODU,
|
||||
MIPS_INS_MOD_S,
|
||||
MIPS_INS_MOD_U,
|
||||
MIPS_INS_MOVE,
|
||||
MIPS_INS_MOVF,
|
||||
MIPS_INS_MOVN,
|
||||
MIPS_INS_MOVT,
|
||||
MIPS_INS_MOVZ,
|
||||
MIPS_INS_MSUB,
|
||||
MIPS_INS_MSUBF,
|
||||
MIPS_INS_MSUBR_Q,
|
||||
MIPS_INS_MSUBU,
|
||||
MIPS_INS_MSUBV,
|
||||
MIPS_INS_MSUB_Q,
|
||||
MIPS_INS_MTC0,
|
||||
MIPS_INS_MTC1,
|
||||
MIPS_INS_MTC2,
|
||||
MIPS_INS_MTHC1,
|
||||
MIPS_INS_MTHI,
|
||||
MIPS_INS_MTHLIP,
|
||||
MIPS_INS_MTLO,
|
||||
MIPS_INS_MTM0,
|
||||
MIPS_INS_MTM1,
|
||||
MIPS_INS_MTM2,
|
||||
MIPS_INS_MTP0,
|
||||
MIPS_INS_MTP1,
|
||||
MIPS_INS_MTP2,
|
||||
MIPS_INS_MUH,
|
||||
MIPS_INS_MUHU,
|
||||
MIPS_INS_MULEQ_S,
|
||||
MIPS_INS_MULEU_S,
|
||||
MIPS_INS_MULQ_RS,
|
||||
MIPS_INS_MULQ_S,
|
||||
MIPS_INS_MULR_Q,
|
||||
MIPS_INS_MULSAQ_S,
|
||||
MIPS_INS_MULSA,
|
||||
MIPS_INS_MULT,
|
||||
MIPS_INS_MULTU,
|
||||
MIPS_INS_MULU,
|
||||
MIPS_INS_MULV,
|
||||
MIPS_INS_MUL_Q,
|
||||
MIPS_INS_MUL_S,
|
||||
MIPS_INS_NLOC,
|
||||
MIPS_INS_NLZC,
|
||||
MIPS_INS_NMADD,
|
||||
MIPS_INS_NMSUB,
|
||||
MIPS_INS_NOR,
|
||||
MIPS_INS_NORI,
|
||||
MIPS_INS_NOT,
|
||||
MIPS_INS_OR,
|
||||
MIPS_INS_ORI,
|
||||
MIPS_INS_PACKRL,
|
||||
MIPS_INS_PAUSE,
|
||||
MIPS_INS_PCKEV,
|
||||
MIPS_INS_PCKOD,
|
||||
MIPS_INS_PCNT,
|
||||
MIPS_INS_PICK,
|
||||
MIPS_INS_POP,
|
||||
MIPS_INS_PRECEQU,
|
||||
MIPS_INS_PRECEQ,
|
||||
MIPS_INS_PRECEU,
|
||||
MIPS_INS_PRECRQU_S,
|
||||
MIPS_INS_PRECRQ,
|
||||
MIPS_INS_PRECRQ_RS,
|
||||
MIPS_INS_PRECR,
|
||||
MIPS_INS_PRECR_SRA,
|
||||
MIPS_INS_PRECR_SRA_R,
|
||||
MIPS_INS_PREF,
|
||||
MIPS_INS_PREPEND,
|
||||
MIPS_INS_RADDU,
|
||||
MIPS_INS_RDDSP,
|
||||
MIPS_INS_RDHWR,
|
||||
MIPS_INS_REPLV,
|
||||
MIPS_INS_REPL,
|
||||
MIPS_INS_RINT,
|
||||
MIPS_INS_ROTR,
|
||||
MIPS_INS_ROTRV,
|
||||
MIPS_INS_ROUND,
|
||||
MIPS_INS_SAT_S,
|
||||
MIPS_INS_SAT_U,
|
||||
MIPS_INS_SB,
|
||||
MIPS_INS_SC,
|
||||
MIPS_INS_SCD,
|
||||
MIPS_INS_SD,
|
||||
MIPS_INS_SDBBP,
|
||||
MIPS_INS_SDC1,
|
||||
MIPS_INS_SDC2,
|
||||
MIPS_INS_SDC3,
|
||||
MIPS_INS_SDL,
|
||||
MIPS_INS_SDR,
|
||||
MIPS_INS_SDXC1,
|
||||
MIPS_INS_SEB,
|
||||
MIPS_INS_SEH,
|
||||
MIPS_INS_SELEQZ,
|
||||
MIPS_INS_SELNEZ,
|
||||
MIPS_INS_SEL,
|
||||
MIPS_INS_SEQ,
|
||||
MIPS_INS_SEQI,
|
||||
MIPS_INS_SH,
|
||||
MIPS_INS_SHF,
|
||||
MIPS_INS_SHILO,
|
||||
MIPS_INS_SHILOV,
|
||||
MIPS_INS_SHLLV,
|
||||
MIPS_INS_SHLLV_S,
|
||||
MIPS_INS_SHLL,
|
||||
MIPS_INS_SHLL_S,
|
||||
MIPS_INS_SHRAV,
|
||||
MIPS_INS_SHRAV_R,
|
||||
MIPS_INS_SHRA,
|
||||
MIPS_INS_SHRA_R,
|
||||
MIPS_INS_SHRLV,
|
||||
MIPS_INS_SHRL,
|
||||
MIPS_INS_SLDI,
|
||||
MIPS_INS_SLD,
|
||||
MIPS_INS_SLL,
|
||||
MIPS_INS_SLLI,
|
||||
MIPS_INS_SLLV,
|
||||
MIPS_INS_SLT,
|
||||
MIPS_INS_SLTI,
|
||||
MIPS_INS_SLTIU,
|
||||
MIPS_INS_SLTU,
|
||||
MIPS_INS_SNE,
|
||||
MIPS_INS_SNEI,
|
||||
MIPS_INS_SPLATI,
|
||||
MIPS_INS_SPLAT,
|
||||
MIPS_INS_SRA,
|
||||
MIPS_INS_SRAI,
|
||||
MIPS_INS_SRARI,
|
||||
MIPS_INS_SRAR,
|
||||
MIPS_INS_SRAV,
|
||||
MIPS_INS_SRL,
|
||||
MIPS_INS_SRLI,
|
||||
MIPS_INS_SRLRI,
|
||||
MIPS_INS_SRLR,
|
||||
MIPS_INS_SRLV,
|
||||
MIPS_INS_SSNOP,
|
||||
MIPS_INS_ST,
|
||||
MIPS_INS_SUBQH,
|
||||
MIPS_INS_SUBQH_R,
|
||||
MIPS_INS_SUBQ,
|
||||
MIPS_INS_SUBQ_S,
|
||||
MIPS_INS_SUBSUS_U,
|
||||
MIPS_INS_SUBSUU_S,
|
||||
MIPS_INS_SUBS_S,
|
||||
MIPS_INS_SUBS_U,
|
||||
MIPS_INS_SUBUH,
|
||||
MIPS_INS_SUBUH_R,
|
||||
MIPS_INS_SUBU,
|
||||
MIPS_INS_SUBU_S,
|
||||
MIPS_INS_SUBVI,
|
||||
MIPS_INS_SUBV,
|
||||
MIPS_INS_SUXC1,
|
||||
MIPS_INS_SW,
|
||||
MIPS_INS_SWC1,
|
||||
MIPS_INS_SWC2,
|
||||
MIPS_INS_SWC3,
|
||||
MIPS_INS_SWL,
|
||||
MIPS_INS_SWR,
|
||||
MIPS_INS_SWXC1,
|
||||
MIPS_INS_SYNC,
|
||||
MIPS_INS_SYSCALL,
|
||||
MIPS_INS_TEQ,
|
||||
MIPS_INS_TEQI,
|
||||
MIPS_INS_TGE,
|
||||
MIPS_INS_TGEI,
|
||||
MIPS_INS_TGEIU,
|
||||
MIPS_INS_TGEU,
|
||||
MIPS_INS_TLBP,
|
||||
MIPS_INS_TLBR,
|
||||
MIPS_INS_TLBWI,
|
||||
MIPS_INS_TLBWR,
|
||||
MIPS_INS_TLT,
|
||||
MIPS_INS_TLTI,
|
||||
MIPS_INS_TLTIU,
|
||||
MIPS_INS_TLTU,
|
||||
MIPS_INS_TNE,
|
||||
MIPS_INS_TNEI,
|
||||
MIPS_INS_TRUNC,
|
||||
MIPS_INS_V3MULU,
|
||||
MIPS_INS_VMM0,
|
||||
MIPS_INS_VMULU,
|
||||
MIPS_INS_VSHF,
|
||||
MIPS_INS_WAIT,
|
||||
MIPS_INS_WRDSP,
|
||||
MIPS_INS_WSBH,
|
||||
MIPS_INS_XOR,
|
||||
MIPS_INS_XORI,
|
||||
|
||||
//> some alias instructions
|
||||
MIPS_INS_NOP,
|
||||
MIPS_INS_NEGU,
|
||||
|
||||
//> special instructions
|
||||
MIPS_INS_JALR_HB, // jump and link with Hazard Barrier
|
||||
MIPS_INS_JR_HB, // jump register with Hazard Barrier
|
||||
|
||||
MIPS_INS_ENDING,
|
||||
} mips_insn;
|
||||
|
||||
//> Group of MIPS instructions
|
||||
typedef enum mips_insn_group {
|
||||
MIPS_GRP_INVALID = 0, // = CS_GRP_INVALID
|
||||
|
||||
//> Generic groups
|
||||
// all jump instructions (conditional+direct+indirect jumps)
|
||||
MIPS_GRP_JUMP, // = CS_GRP_JUMP
|
||||
|
||||
//> Architecture-specific groups
|
||||
MIPS_GRP_BITCOUNT = 128,
|
||||
MIPS_GRP_DSP,
|
||||
MIPS_GRP_DSPR2,
|
||||
MIPS_GRP_FPIDX,
|
||||
MIPS_GRP_MSA,
|
||||
MIPS_GRP_MIPS32R2,
|
||||
MIPS_GRP_MIPS64,
|
||||
MIPS_GRP_MIPS64R2,
|
||||
MIPS_GRP_SEINREG,
|
||||
MIPS_GRP_STDENC,
|
||||
MIPS_GRP_SWAP,
|
||||
MIPS_GRP_MICROMIPS,
|
||||
MIPS_GRP_MIPS16MODE,
|
||||
MIPS_GRP_FP64BIT,
|
||||
MIPS_GRP_NONANSFPMATH,
|
||||
MIPS_GRP_NOTFP64BIT,
|
||||
MIPS_GRP_NOTINMICROMIPS,
|
||||
MIPS_GRP_NOTNACL,
|
||||
MIPS_GRP_NOTMIPS32R6,
|
||||
MIPS_GRP_NOTMIPS64R6,
|
||||
MIPS_GRP_CNMIPS,
|
||||
MIPS_GRP_MIPS32,
|
||||
MIPS_GRP_MIPS32R6,
|
||||
MIPS_GRP_MIPS64R6,
|
||||
MIPS_GRP_MIPS2,
|
||||
MIPS_GRP_MIPS3,
|
||||
MIPS_GRP_MIPS3_32,
|
||||
MIPS_GRP_MIPS3_32R2,
|
||||
MIPS_GRP_MIPS4_32,
|
||||
MIPS_GRP_MIPS4_32R2,
|
||||
MIPS_GRP_MIPS5_32R2,
|
||||
MIPS_GRP_GP32BIT,
|
||||
MIPS_GRP_GP64BIT,
|
||||
|
||||
MIPS_GRP_ENDING,
|
||||
} mips_insn_group;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,110 @@
|
||||
/* Capstone Disassembly Engine */
|
||||
/* By Axel Souchet & Nguyen Anh Quynh, 2014 */
|
||||
|
||||
#ifndef CAPSTONE_PLATFORM_H
|
||||
#define CAPSTONE_PLATFORM_H
|
||||
|
||||
// handle C99 issue (for pre-2013 VisualStudio)
|
||||
#if !defined(__CYGWIN__) && !defined(__MINGW32__) && !defined(__MINGW64__) && (defined (WIN32) || defined (WIN64) || defined (_WIN32) || defined (_WIN64))
|
||||
// MSVC
|
||||
|
||||
// stdbool.h
|
||||
#if (_MSC_VER < 1800) || defined(_KERNEL_MODE)
|
||||
// this system does not have stdbool.h
|
||||
#ifndef __cplusplus
|
||||
typedef unsigned char bool;
|
||||
#define false 0
|
||||
#define true 1
|
||||
#endif
|
||||
|
||||
#else
|
||||
// VisualStudio 2013+ -> C99 is supported
|
||||
#include <stdbool.h>
|
||||
#endif
|
||||
|
||||
#else
|
||||
// not MSVC -> C99 is supported
|
||||
#include <stdbool.h>
|
||||
#endif
|
||||
|
||||
|
||||
// handle C99 issue (for pre-2013 VisualStudio)
|
||||
#if defined(CAPSTONE_HAS_OSXKERNEL) || (defined(_MSC_VER) && (_MSC_VER <= 1700 || defined(_KERNEL_MODE)))
|
||||
// this system does not have inttypes.h
|
||||
|
||||
#if defined(_MSC_VER) && (_MSC_VER < 1600 || defined(_KERNEL_MODE))
|
||||
// this system does not have stdint.h
|
||||
typedef signed char int8_t;
|
||||
typedef signed short int16_t;
|
||||
typedef signed int int32_t;
|
||||
typedef unsigned char uint8_t;
|
||||
typedef unsigned short uint16_t;
|
||||
typedef unsigned int uint32_t;
|
||||
typedef signed long long int64_t;
|
||||
typedef unsigned long long uint64_t;
|
||||
|
||||
#define INT8_MIN (-127i8 - 1)
|
||||
#define INT16_MIN (-32767i16 - 1)
|
||||
#define INT32_MIN (-2147483647i32 - 1)
|
||||
#define INT64_MIN (-9223372036854775807i64 - 1)
|
||||
#define INT8_MAX 127i8
|
||||
#define INT16_MAX 32767i16
|
||||
#define INT32_MAX 2147483647i32
|
||||
#define INT64_MAX 9223372036854775807i64
|
||||
#define UINT8_MAX 0xffui8
|
||||
#define UINT16_MAX 0xffffui16
|
||||
#define UINT32_MAX 0xffffffffui32
|
||||
#define UINT64_MAX 0xffffffffffffffffui64
|
||||
#endif
|
||||
|
||||
#define __PRI_8_LENGTH_MODIFIER__ "hh"
|
||||
#define __PRI_64_LENGTH_MODIFIER__ "ll"
|
||||
|
||||
#define PRId8 __PRI_8_LENGTH_MODIFIER__ "d"
|
||||
#define PRIi8 __PRI_8_LENGTH_MODIFIER__ "i"
|
||||
#define PRIo8 __PRI_8_LENGTH_MODIFIER__ "o"
|
||||
#define PRIu8 __PRI_8_LENGTH_MODIFIER__ "u"
|
||||
#define PRIx8 __PRI_8_LENGTH_MODIFIER__ "x"
|
||||
#define PRIX8 __PRI_8_LENGTH_MODIFIER__ "X"
|
||||
|
||||
#define PRId16 "hd"
|
||||
#define PRIi16 "hi"
|
||||
#define PRIo16 "ho"
|
||||
#define PRIu16 "hu"
|
||||
#define PRIx16 "hx"
|
||||
#define PRIX16 "hX"
|
||||
|
||||
#if defined(_MSC_VER) && _MSC_VER <= 1700
|
||||
#define PRId32 "ld"
|
||||
#define PRIi32 "li"
|
||||
#define PRIo32 "lo"
|
||||
#define PRIu32 "lu"
|
||||
#define PRIx32 "lx"
|
||||
#define PRIX32 "lX"
|
||||
#else // OSX
|
||||
#define PRId32 "d"
|
||||
#define PRIi32 "i"
|
||||
#define PRIo32 "o"
|
||||
#define PRIu32 "u"
|
||||
#define PRIx32 "x"
|
||||
#define PRIX32 "X"
|
||||
#endif
|
||||
|
||||
#if defined(_MSC_VER) && _MSC_VER <= 1700
|
||||
// redefine functions from inttypes.h used in cstool
|
||||
#define strtoull _strtoui64
|
||||
#endif
|
||||
|
||||
#define PRId64 __PRI_64_LENGTH_MODIFIER__ "d"
|
||||
#define PRIi64 __PRI_64_LENGTH_MODIFIER__ "i"
|
||||
#define PRIo64 __PRI_64_LENGTH_MODIFIER__ "o"
|
||||
#define PRIu64 __PRI_64_LENGTH_MODIFIER__ "u"
|
||||
#define PRIx64 __PRI_64_LENGTH_MODIFIER__ "x"
|
||||
#define PRIX64 __PRI_64_LENGTH_MODIFIER__ "X"
|
||||
|
||||
#else
|
||||
// this system has inttypes.h by default
|
||||
#include <inttypes.h>
|
||||
#endif
|
||||
|
||||
#endif
|
||||
1254
EFI/OC/Kexts/Lilu.kext/Contents/Resources/Headers/capstone/ppc.h
Normal file
1254
EFI/OC/Kexts/Lilu.kext/Contents/Resources/Headers/capstone/ppc.h
Normal file
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,522 @@
|
||||
#ifndef CAPSTONE_SPARC_H
|
||||
#define CAPSTONE_SPARC_H
|
||||
|
||||
/* Capstone Disassembly Engine */
|
||||
/* By Nguyen Anh Quynh <aquynh@gmail.com>, 2014 */
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#if !defined(_MSC_VER) || !defined(_KERNEL_MODE)
|
||||
#include <stdint.h>
|
||||
#endif
|
||||
|
||||
#include "platform.h"
|
||||
|
||||
// GCC SPARC toolchain has a default macro called "sparc" which breaks
|
||||
// compilation
|
||||
#undef sparc
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#pragma warning(disable:4201)
|
||||
#endif
|
||||
|
||||
//> Enums corresponding to Sparc condition codes, both icc's and fcc's.
|
||||
typedef enum sparc_cc {
|
||||
SPARC_CC_INVALID = 0, // invalid CC (default)
|
||||
//> Integer condition codes
|
||||
SPARC_CC_ICC_A = 8+256, // Always
|
||||
SPARC_CC_ICC_N = 0+256, // Never
|
||||
SPARC_CC_ICC_NE = 9+256, // Not Equal
|
||||
SPARC_CC_ICC_E = 1+256, // Equal
|
||||
SPARC_CC_ICC_G = 10+256, // Greater
|
||||
SPARC_CC_ICC_LE = 2+256, // Less or Equal
|
||||
SPARC_CC_ICC_GE = 11+256, // Greater or Equal
|
||||
SPARC_CC_ICC_L = 3+256, // Less
|
||||
SPARC_CC_ICC_GU = 12+256, // Greater Unsigned
|
||||
SPARC_CC_ICC_LEU = 4+256, // Less or Equal Unsigned
|
||||
SPARC_CC_ICC_CC = 13+256, // Carry Clear/Great or Equal Unsigned
|
||||
SPARC_CC_ICC_CS = 5+256, // Carry Set/Less Unsigned
|
||||
SPARC_CC_ICC_POS = 14+256, // Positive
|
||||
SPARC_CC_ICC_NEG = 6+256, // Negative
|
||||
SPARC_CC_ICC_VC = 15+256, // Overflow Clear
|
||||
SPARC_CC_ICC_VS = 7+256, // Overflow Set
|
||||
|
||||
//> Floating condition codes
|
||||
SPARC_CC_FCC_A = 8+16+256, // Always
|
||||
SPARC_CC_FCC_N = 0+16+256, // Never
|
||||
SPARC_CC_FCC_U = 7+16+256, // Unordered
|
||||
SPARC_CC_FCC_G = 6+16+256, // Greater
|
||||
SPARC_CC_FCC_UG = 5+16+256, // Unordered or Greater
|
||||
SPARC_CC_FCC_L = 4+16+256, // Less
|
||||
SPARC_CC_FCC_UL = 3+16+256, // Unordered or Less
|
||||
SPARC_CC_FCC_LG = 2+16+256, // Less or Greater
|
||||
SPARC_CC_FCC_NE = 1+16+256, // Not Equal
|
||||
SPARC_CC_FCC_E = 9+16+256, // Equal
|
||||
SPARC_CC_FCC_UE = 10+16+256, // Unordered or Equal
|
||||
SPARC_CC_FCC_GE = 11+16+256, // Greater or Equal
|
||||
SPARC_CC_FCC_UGE = 12+16+256, // Unordered or Greater or Equal
|
||||
SPARC_CC_FCC_LE = 13+16+256, // Less or Equal
|
||||
SPARC_CC_FCC_ULE = 14+16+256, // Unordered or Less or Equal
|
||||
SPARC_CC_FCC_O = 15+16+256, // Ordered
|
||||
} sparc_cc;
|
||||
|
||||
//> Branch hint
|
||||
typedef enum sparc_hint {
|
||||
SPARC_HINT_INVALID = 0, // no hint
|
||||
SPARC_HINT_A = 1 << 0, // annul delay slot instruction
|
||||
SPARC_HINT_PT = 1 << 1, // branch taken
|
||||
SPARC_HINT_PN = 1 << 2, // branch NOT taken
|
||||
} sparc_hint;
|
||||
|
||||
//> Operand type for instruction's operands
|
||||
typedef enum sparc_op_type {
|
||||
SPARC_OP_INVALID = 0, // = CS_OP_INVALID (Uninitialized).
|
||||
SPARC_OP_REG, // = CS_OP_REG (Register operand).
|
||||
SPARC_OP_IMM, // = CS_OP_IMM (Immediate operand).
|
||||
SPARC_OP_MEM, // = CS_OP_MEM (Memory operand).
|
||||
} sparc_op_type;
|
||||
|
||||
// Instruction's operand referring to memory
|
||||
// This is associated with SPARC_OP_MEM operand type above
|
||||
typedef struct sparc_op_mem {
|
||||
uint8_t base; // base register
|
||||
uint8_t index; // index register
|
||||
int32_t disp; // displacement/offset value
|
||||
} sparc_op_mem;
|
||||
|
||||
// Instruction operand
|
||||
typedef struct cs_sparc_op {
|
||||
sparc_op_type type; // operand type
|
||||
union {
|
||||
unsigned int reg; // register value for REG operand
|
||||
int32_t imm; // immediate value for IMM operand
|
||||
sparc_op_mem mem; // base/disp value for MEM operand
|
||||
};
|
||||
} cs_sparc_op;
|
||||
|
||||
// Instruction structure
|
||||
typedef struct cs_sparc {
|
||||
sparc_cc cc; // code condition for this insn
|
||||
sparc_hint hint; // branch hint: encoding as bitwise OR of sparc_hint.
|
||||
// Number of operands of this instruction,
|
||||
// or 0 when instruction has no operand.
|
||||
uint8_t op_count;
|
||||
cs_sparc_op operands[4]; // operands for this instruction.
|
||||
} cs_sparc;
|
||||
|
||||
//> SPARC registers
|
||||
typedef enum sparc_reg {
|
||||
SPARC_REG_INVALID = 0,
|
||||
|
||||
SPARC_REG_F0,
|
||||
SPARC_REG_F1,
|
||||
SPARC_REG_F2,
|
||||
SPARC_REG_F3,
|
||||
SPARC_REG_F4,
|
||||
SPARC_REG_F5,
|
||||
SPARC_REG_F6,
|
||||
SPARC_REG_F7,
|
||||
SPARC_REG_F8,
|
||||
SPARC_REG_F9,
|
||||
SPARC_REG_F10,
|
||||
SPARC_REG_F11,
|
||||
SPARC_REG_F12,
|
||||
SPARC_REG_F13,
|
||||
SPARC_REG_F14,
|
||||
SPARC_REG_F15,
|
||||
SPARC_REG_F16,
|
||||
SPARC_REG_F17,
|
||||
SPARC_REG_F18,
|
||||
SPARC_REG_F19,
|
||||
SPARC_REG_F20,
|
||||
SPARC_REG_F21,
|
||||
SPARC_REG_F22,
|
||||
SPARC_REG_F23,
|
||||
SPARC_REG_F24,
|
||||
SPARC_REG_F25,
|
||||
SPARC_REG_F26,
|
||||
SPARC_REG_F27,
|
||||
SPARC_REG_F28,
|
||||
SPARC_REG_F29,
|
||||
SPARC_REG_F30,
|
||||
SPARC_REG_F31,
|
||||
SPARC_REG_F32,
|
||||
SPARC_REG_F34,
|
||||
SPARC_REG_F36,
|
||||
SPARC_REG_F38,
|
||||
SPARC_REG_F40,
|
||||
SPARC_REG_F42,
|
||||
SPARC_REG_F44,
|
||||
SPARC_REG_F46,
|
||||
SPARC_REG_F48,
|
||||
SPARC_REG_F50,
|
||||
SPARC_REG_F52,
|
||||
SPARC_REG_F54,
|
||||
SPARC_REG_F56,
|
||||
SPARC_REG_F58,
|
||||
SPARC_REG_F60,
|
||||
SPARC_REG_F62,
|
||||
SPARC_REG_FCC0, // Floating condition codes
|
||||
SPARC_REG_FCC1,
|
||||
SPARC_REG_FCC2,
|
||||
SPARC_REG_FCC3,
|
||||
SPARC_REG_FP,
|
||||
SPARC_REG_G0,
|
||||
SPARC_REG_G1,
|
||||
SPARC_REG_G2,
|
||||
SPARC_REG_G3,
|
||||
SPARC_REG_G4,
|
||||
SPARC_REG_G5,
|
||||
SPARC_REG_G6,
|
||||
SPARC_REG_G7,
|
||||
SPARC_REG_I0,
|
||||
SPARC_REG_I1,
|
||||
SPARC_REG_I2,
|
||||
SPARC_REG_I3,
|
||||
SPARC_REG_I4,
|
||||
SPARC_REG_I5,
|
||||
SPARC_REG_I7,
|
||||
SPARC_REG_ICC, // Integer condition codes
|
||||
SPARC_REG_L0,
|
||||
SPARC_REG_L1,
|
||||
SPARC_REG_L2,
|
||||
SPARC_REG_L3,
|
||||
SPARC_REG_L4,
|
||||
SPARC_REG_L5,
|
||||
SPARC_REG_L6,
|
||||
SPARC_REG_L7,
|
||||
SPARC_REG_O0,
|
||||
SPARC_REG_O1,
|
||||
SPARC_REG_O2,
|
||||
SPARC_REG_O3,
|
||||
SPARC_REG_O4,
|
||||
SPARC_REG_O5,
|
||||
SPARC_REG_O7,
|
||||
SPARC_REG_SP,
|
||||
SPARC_REG_Y,
|
||||
|
||||
// special register
|
||||
SPARC_REG_XCC,
|
||||
|
||||
SPARC_REG_ENDING, // <-- mark the end of the list of registers
|
||||
|
||||
// extras
|
||||
SPARC_REG_O6 = SPARC_REG_SP,
|
||||
SPARC_REG_I6 = SPARC_REG_FP,
|
||||
} sparc_reg;
|
||||
|
||||
//> SPARC instruction
|
||||
typedef enum sparc_insn {
|
||||
SPARC_INS_INVALID = 0,
|
||||
|
||||
SPARC_INS_ADDCC,
|
||||
SPARC_INS_ADDX,
|
||||
SPARC_INS_ADDXCC,
|
||||
SPARC_INS_ADDXC,
|
||||
SPARC_INS_ADDXCCC,
|
||||
SPARC_INS_ADD,
|
||||
SPARC_INS_ALIGNADDR,
|
||||
SPARC_INS_ALIGNADDRL,
|
||||
SPARC_INS_ANDCC,
|
||||
SPARC_INS_ANDNCC,
|
||||
SPARC_INS_ANDN,
|
||||
SPARC_INS_AND,
|
||||
SPARC_INS_ARRAY16,
|
||||
SPARC_INS_ARRAY32,
|
||||
SPARC_INS_ARRAY8,
|
||||
SPARC_INS_B,
|
||||
SPARC_INS_JMP,
|
||||
SPARC_INS_BMASK,
|
||||
SPARC_INS_FB,
|
||||
SPARC_INS_BRGEZ,
|
||||
SPARC_INS_BRGZ,
|
||||
SPARC_INS_BRLEZ,
|
||||
SPARC_INS_BRLZ,
|
||||
SPARC_INS_BRNZ,
|
||||
SPARC_INS_BRZ,
|
||||
SPARC_INS_BSHUFFLE,
|
||||
SPARC_INS_CALL,
|
||||
SPARC_INS_CASX,
|
||||
SPARC_INS_CAS,
|
||||
SPARC_INS_CMASK16,
|
||||
SPARC_INS_CMASK32,
|
||||
SPARC_INS_CMASK8,
|
||||
SPARC_INS_CMP,
|
||||
SPARC_INS_EDGE16,
|
||||
SPARC_INS_EDGE16L,
|
||||
SPARC_INS_EDGE16LN,
|
||||
SPARC_INS_EDGE16N,
|
||||
SPARC_INS_EDGE32,
|
||||
SPARC_INS_EDGE32L,
|
||||
SPARC_INS_EDGE32LN,
|
||||
SPARC_INS_EDGE32N,
|
||||
SPARC_INS_EDGE8,
|
||||
SPARC_INS_EDGE8L,
|
||||
SPARC_INS_EDGE8LN,
|
||||
SPARC_INS_EDGE8N,
|
||||
SPARC_INS_FABSD,
|
||||
SPARC_INS_FABSQ,
|
||||
SPARC_INS_FABSS,
|
||||
SPARC_INS_FADDD,
|
||||
SPARC_INS_FADDQ,
|
||||
SPARC_INS_FADDS,
|
||||
SPARC_INS_FALIGNDATA,
|
||||
SPARC_INS_FAND,
|
||||
SPARC_INS_FANDNOT1,
|
||||
SPARC_INS_FANDNOT1S,
|
||||
SPARC_INS_FANDNOT2,
|
||||
SPARC_INS_FANDNOT2S,
|
||||
SPARC_INS_FANDS,
|
||||
SPARC_INS_FCHKSM16,
|
||||
SPARC_INS_FCMPD,
|
||||
SPARC_INS_FCMPEQ16,
|
||||
SPARC_INS_FCMPEQ32,
|
||||
SPARC_INS_FCMPGT16,
|
||||
SPARC_INS_FCMPGT32,
|
||||
SPARC_INS_FCMPLE16,
|
||||
SPARC_INS_FCMPLE32,
|
||||
SPARC_INS_FCMPNE16,
|
||||
SPARC_INS_FCMPNE32,
|
||||
SPARC_INS_FCMPQ,
|
||||
SPARC_INS_FCMPS,
|
||||
SPARC_INS_FDIVD,
|
||||
SPARC_INS_FDIVQ,
|
||||
SPARC_INS_FDIVS,
|
||||
SPARC_INS_FDMULQ,
|
||||
SPARC_INS_FDTOI,
|
||||
SPARC_INS_FDTOQ,
|
||||
SPARC_INS_FDTOS,
|
||||
SPARC_INS_FDTOX,
|
||||
SPARC_INS_FEXPAND,
|
||||
SPARC_INS_FHADDD,
|
||||
SPARC_INS_FHADDS,
|
||||
SPARC_INS_FHSUBD,
|
||||
SPARC_INS_FHSUBS,
|
||||
SPARC_INS_FITOD,
|
||||
SPARC_INS_FITOQ,
|
||||
SPARC_INS_FITOS,
|
||||
SPARC_INS_FLCMPD,
|
||||
SPARC_INS_FLCMPS,
|
||||
SPARC_INS_FLUSHW,
|
||||
SPARC_INS_FMEAN16,
|
||||
SPARC_INS_FMOVD,
|
||||
SPARC_INS_FMOVQ,
|
||||
SPARC_INS_FMOVRDGEZ,
|
||||
SPARC_INS_FMOVRQGEZ,
|
||||
SPARC_INS_FMOVRSGEZ,
|
||||
SPARC_INS_FMOVRDGZ,
|
||||
SPARC_INS_FMOVRQGZ,
|
||||
SPARC_INS_FMOVRSGZ,
|
||||
SPARC_INS_FMOVRDLEZ,
|
||||
SPARC_INS_FMOVRQLEZ,
|
||||
SPARC_INS_FMOVRSLEZ,
|
||||
SPARC_INS_FMOVRDLZ,
|
||||
SPARC_INS_FMOVRQLZ,
|
||||
SPARC_INS_FMOVRSLZ,
|
||||
SPARC_INS_FMOVRDNZ,
|
||||
SPARC_INS_FMOVRQNZ,
|
||||
SPARC_INS_FMOVRSNZ,
|
||||
SPARC_INS_FMOVRDZ,
|
||||
SPARC_INS_FMOVRQZ,
|
||||
SPARC_INS_FMOVRSZ,
|
||||
SPARC_INS_FMOVS,
|
||||
SPARC_INS_FMUL8SUX16,
|
||||
SPARC_INS_FMUL8ULX16,
|
||||
SPARC_INS_FMUL8X16,
|
||||
SPARC_INS_FMUL8X16AL,
|
||||
SPARC_INS_FMUL8X16AU,
|
||||
SPARC_INS_FMULD,
|
||||
SPARC_INS_FMULD8SUX16,
|
||||
SPARC_INS_FMULD8ULX16,
|
||||
SPARC_INS_FMULQ,
|
||||
SPARC_INS_FMULS,
|
||||
SPARC_INS_FNADDD,
|
||||
SPARC_INS_FNADDS,
|
||||
SPARC_INS_FNAND,
|
||||
SPARC_INS_FNANDS,
|
||||
SPARC_INS_FNEGD,
|
||||
SPARC_INS_FNEGQ,
|
||||
SPARC_INS_FNEGS,
|
||||
SPARC_INS_FNHADDD,
|
||||
SPARC_INS_FNHADDS,
|
||||
SPARC_INS_FNOR,
|
||||
SPARC_INS_FNORS,
|
||||
SPARC_INS_FNOT1,
|
||||
SPARC_INS_FNOT1S,
|
||||
SPARC_INS_FNOT2,
|
||||
SPARC_INS_FNOT2S,
|
||||
SPARC_INS_FONE,
|
||||
SPARC_INS_FONES,
|
||||
SPARC_INS_FOR,
|
||||
SPARC_INS_FORNOT1,
|
||||
SPARC_INS_FORNOT1S,
|
||||
SPARC_INS_FORNOT2,
|
||||
SPARC_INS_FORNOT2S,
|
||||
SPARC_INS_FORS,
|
||||
SPARC_INS_FPACK16,
|
||||
SPARC_INS_FPACK32,
|
||||
SPARC_INS_FPACKFIX,
|
||||
SPARC_INS_FPADD16,
|
||||
SPARC_INS_FPADD16S,
|
||||
SPARC_INS_FPADD32,
|
||||
SPARC_INS_FPADD32S,
|
||||
SPARC_INS_FPADD64,
|
||||
SPARC_INS_FPMERGE,
|
||||
SPARC_INS_FPSUB16,
|
||||
SPARC_INS_FPSUB16S,
|
||||
SPARC_INS_FPSUB32,
|
||||
SPARC_INS_FPSUB32S,
|
||||
SPARC_INS_FQTOD,
|
||||
SPARC_INS_FQTOI,
|
||||
SPARC_INS_FQTOS,
|
||||
SPARC_INS_FQTOX,
|
||||
SPARC_INS_FSLAS16,
|
||||
SPARC_INS_FSLAS32,
|
||||
SPARC_INS_FSLL16,
|
||||
SPARC_INS_FSLL32,
|
||||
SPARC_INS_FSMULD,
|
||||
SPARC_INS_FSQRTD,
|
||||
SPARC_INS_FSQRTQ,
|
||||
SPARC_INS_FSQRTS,
|
||||
SPARC_INS_FSRA16,
|
||||
SPARC_INS_FSRA32,
|
||||
SPARC_INS_FSRC1,
|
||||
SPARC_INS_FSRC1S,
|
||||
SPARC_INS_FSRC2,
|
||||
SPARC_INS_FSRC2S,
|
||||
SPARC_INS_FSRL16,
|
||||
SPARC_INS_FSRL32,
|
||||
SPARC_INS_FSTOD,
|
||||
SPARC_INS_FSTOI,
|
||||
SPARC_INS_FSTOQ,
|
||||
SPARC_INS_FSTOX,
|
||||
SPARC_INS_FSUBD,
|
||||
SPARC_INS_FSUBQ,
|
||||
SPARC_INS_FSUBS,
|
||||
SPARC_INS_FXNOR,
|
||||
SPARC_INS_FXNORS,
|
||||
SPARC_INS_FXOR,
|
||||
SPARC_INS_FXORS,
|
||||
SPARC_INS_FXTOD,
|
||||
SPARC_INS_FXTOQ,
|
||||
SPARC_INS_FXTOS,
|
||||
SPARC_INS_FZERO,
|
||||
SPARC_INS_FZEROS,
|
||||
SPARC_INS_JMPL,
|
||||
SPARC_INS_LDD,
|
||||
SPARC_INS_LD,
|
||||
SPARC_INS_LDQ,
|
||||
SPARC_INS_LDSB,
|
||||
SPARC_INS_LDSH,
|
||||
SPARC_INS_LDSW,
|
||||
SPARC_INS_LDUB,
|
||||
SPARC_INS_LDUH,
|
||||
SPARC_INS_LDX,
|
||||
SPARC_INS_LZCNT,
|
||||
SPARC_INS_MEMBAR,
|
||||
SPARC_INS_MOVDTOX,
|
||||
SPARC_INS_MOV,
|
||||
SPARC_INS_MOVRGEZ,
|
||||
SPARC_INS_MOVRGZ,
|
||||
SPARC_INS_MOVRLEZ,
|
||||
SPARC_INS_MOVRLZ,
|
||||
SPARC_INS_MOVRNZ,
|
||||
SPARC_INS_MOVRZ,
|
||||
SPARC_INS_MOVSTOSW,
|
||||
SPARC_INS_MOVSTOUW,
|
||||
SPARC_INS_MULX,
|
||||
SPARC_INS_NOP,
|
||||
SPARC_INS_ORCC,
|
||||
SPARC_INS_ORNCC,
|
||||
SPARC_INS_ORN,
|
||||
SPARC_INS_OR,
|
||||
SPARC_INS_PDIST,
|
||||
SPARC_INS_PDISTN,
|
||||
SPARC_INS_POPC,
|
||||
SPARC_INS_RD,
|
||||
SPARC_INS_RESTORE,
|
||||
SPARC_INS_RETT,
|
||||
SPARC_INS_SAVE,
|
||||
SPARC_INS_SDIVCC,
|
||||
SPARC_INS_SDIVX,
|
||||
SPARC_INS_SDIV,
|
||||
SPARC_INS_SETHI,
|
||||
SPARC_INS_SHUTDOWN,
|
||||
SPARC_INS_SIAM,
|
||||
SPARC_INS_SLLX,
|
||||
SPARC_INS_SLL,
|
||||
SPARC_INS_SMULCC,
|
||||
SPARC_INS_SMUL,
|
||||
SPARC_INS_SRAX,
|
||||
SPARC_INS_SRA,
|
||||
SPARC_INS_SRLX,
|
||||
SPARC_INS_SRL,
|
||||
SPARC_INS_STBAR,
|
||||
SPARC_INS_STB,
|
||||
SPARC_INS_STD,
|
||||
SPARC_INS_ST,
|
||||
SPARC_INS_STH,
|
||||
SPARC_INS_STQ,
|
||||
SPARC_INS_STX,
|
||||
SPARC_INS_SUBCC,
|
||||
SPARC_INS_SUBX,
|
||||
SPARC_INS_SUBXCC,
|
||||
SPARC_INS_SUB,
|
||||
SPARC_INS_SWAP,
|
||||
SPARC_INS_TADDCCTV,
|
||||
SPARC_INS_TADDCC,
|
||||
SPARC_INS_T,
|
||||
SPARC_INS_TSUBCCTV,
|
||||
SPARC_INS_TSUBCC,
|
||||
SPARC_INS_UDIVCC,
|
||||
SPARC_INS_UDIVX,
|
||||
SPARC_INS_UDIV,
|
||||
SPARC_INS_UMULCC,
|
||||
SPARC_INS_UMULXHI,
|
||||
SPARC_INS_UMUL,
|
||||
SPARC_INS_UNIMP,
|
||||
SPARC_INS_FCMPED,
|
||||
SPARC_INS_FCMPEQ,
|
||||
SPARC_INS_FCMPES,
|
||||
SPARC_INS_WR,
|
||||
SPARC_INS_XMULX,
|
||||
SPARC_INS_XMULXHI,
|
||||
SPARC_INS_XNORCC,
|
||||
SPARC_INS_XNOR,
|
||||
SPARC_INS_XORCC,
|
||||
SPARC_INS_XOR,
|
||||
|
||||
// alias instructions
|
||||
SPARC_INS_RET,
|
||||
SPARC_INS_RETL,
|
||||
|
||||
SPARC_INS_ENDING, // <-- mark the end of the list of instructions
|
||||
} sparc_insn;
|
||||
|
||||
//> Group of SPARC instructions
|
||||
typedef enum sparc_insn_group {
|
||||
SPARC_GRP_INVALID = 0, // = CS_GRP_INVALID
|
||||
|
||||
//> Generic groups
|
||||
// all jump instructions (conditional+direct+indirect jumps)
|
||||
SPARC_GRP_JUMP, // = CS_GRP_JUMP
|
||||
|
||||
//> Architecture-specific groups
|
||||
SPARC_GRP_HARDQUAD = 128,
|
||||
SPARC_GRP_V9,
|
||||
SPARC_GRP_VIS,
|
||||
SPARC_GRP_VIS2,
|
||||
SPARC_GRP_VIS3,
|
||||
SPARC_GRP_32BIT,
|
||||
SPARC_GRP_64BIT,
|
||||
|
||||
SPARC_GRP_ENDING, // <-- mark the end of the list of groups
|
||||
} sparc_insn_group;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,832 @@
|
||||
#ifndef CAPSTONE_SYSTEMZ_H
|
||||
#define CAPSTONE_SYSTEMZ_H
|
||||
|
||||
/* Capstone Disassembly Engine */
|
||||
/* By Nguyen Anh Quynh <aquynh@gmail.com>, 2014 */
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#if !defined(_MSC_VER) || !defined(_KERNEL_MODE)
|
||||
#include <stdint.h>
|
||||
#endif
|
||||
|
||||
#include "platform.h"
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#pragma warning(disable:4201)
|
||||
#endif
|
||||
|
||||
//> Enums corresponding to SystemZ condition codes
|
||||
typedef enum sysz_cc {
|
||||
SYSZ_CC_INVALID = 0, // invalid CC (default)
|
||||
|
||||
SYSZ_CC_O,
|
||||
SYSZ_CC_H,
|
||||
SYSZ_CC_NLE,
|
||||
SYSZ_CC_L,
|
||||
SYSZ_CC_NHE,
|
||||
SYSZ_CC_LH,
|
||||
SYSZ_CC_NE,
|
||||
SYSZ_CC_E,
|
||||
SYSZ_CC_NLH,
|
||||
SYSZ_CC_HE,
|
||||
SYSZ_CC_NL,
|
||||
SYSZ_CC_LE,
|
||||
SYSZ_CC_NH,
|
||||
SYSZ_CC_NO,
|
||||
} sysz_cc;
|
||||
|
||||
//> Operand type for instruction's operands
|
||||
typedef enum sysz_op_type {
|
||||
SYSZ_OP_INVALID = 0, // = CS_OP_INVALID (Uninitialized).
|
||||
SYSZ_OP_REG, // = CS_OP_REG (Register operand).
|
||||
SYSZ_OP_IMM, // = CS_OP_IMM (Immediate operand).
|
||||
SYSZ_OP_MEM, // = CS_OP_MEM (Memory operand).
|
||||
SYSZ_OP_ACREG = 64, // Access register operand.
|
||||
} sysz_op_type;
|
||||
|
||||
// Instruction's operand referring to memory
|
||||
// This is associated with SYSZ_OP_MEM operand type above
|
||||
typedef struct sysz_op_mem {
|
||||
uint8_t base; // base register
|
||||
uint8_t index; // index register
|
||||
uint64_t length; // BDLAddr operand
|
||||
int64_t disp; // displacement/offset value
|
||||
} sysz_op_mem;
|
||||
|
||||
// Instruction operand
|
||||
typedef struct cs_sysz_op {
|
||||
sysz_op_type type; // operand type
|
||||
union {
|
||||
unsigned int reg; // register value for REG operand
|
||||
int64_t imm; // immediate value for IMM operand
|
||||
sysz_op_mem mem; // base/disp value for MEM operand
|
||||
};
|
||||
} cs_sysz_op;
|
||||
|
||||
// Instruction structure
|
||||
typedef struct cs_sysz {
|
||||
sysz_cc cc; // Code condition
|
||||
// Number of operands of this instruction,
|
||||
// or 0 when instruction has no operand.
|
||||
uint8_t op_count;
|
||||
cs_sysz_op operands[6]; // operands for this instruction.
|
||||
} cs_sysz;
|
||||
|
||||
//> SystemZ registers
|
||||
typedef enum sysz_reg {
|
||||
SYSZ_REG_INVALID = 0,
|
||||
|
||||
SYSZ_REG_0,
|
||||
SYSZ_REG_1,
|
||||
SYSZ_REG_2,
|
||||
SYSZ_REG_3,
|
||||
SYSZ_REG_4,
|
||||
SYSZ_REG_5,
|
||||
SYSZ_REG_6,
|
||||
SYSZ_REG_7,
|
||||
SYSZ_REG_8,
|
||||
SYSZ_REG_9,
|
||||
SYSZ_REG_10,
|
||||
SYSZ_REG_11,
|
||||
SYSZ_REG_12,
|
||||
SYSZ_REG_13,
|
||||
SYSZ_REG_14,
|
||||
SYSZ_REG_15,
|
||||
SYSZ_REG_CC,
|
||||
SYSZ_REG_F0,
|
||||
SYSZ_REG_F1,
|
||||
SYSZ_REG_F2,
|
||||
SYSZ_REG_F3,
|
||||
SYSZ_REG_F4,
|
||||
SYSZ_REG_F5,
|
||||
SYSZ_REG_F6,
|
||||
SYSZ_REG_F7,
|
||||
SYSZ_REG_F8,
|
||||
SYSZ_REG_F9,
|
||||
SYSZ_REG_F10,
|
||||
SYSZ_REG_F11,
|
||||
SYSZ_REG_F12,
|
||||
SYSZ_REG_F13,
|
||||
SYSZ_REG_F14,
|
||||
SYSZ_REG_F15,
|
||||
|
||||
SYSZ_REG_R0L,
|
||||
|
||||
SYSZ_REG_ENDING,
|
||||
} sysz_reg;
|
||||
|
||||
//> SystemZ instruction
|
||||
typedef enum sysz_insn {
|
||||
SYSZ_INS_INVALID = 0,
|
||||
|
||||
SYSZ_INS_A,
|
||||
SYSZ_INS_ADB,
|
||||
SYSZ_INS_ADBR,
|
||||
SYSZ_INS_AEB,
|
||||
SYSZ_INS_AEBR,
|
||||
SYSZ_INS_AFI,
|
||||
SYSZ_INS_AG,
|
||||
SYSZ_INS_AGF,
|
||||
SYSZ_INS_AGFI,
|
||||
SYSZ_INS_AGFR,
|
||||
SYSZ_INS_AGHI,
|
||||
SYSZ_INS_AGHIK,
|
||||
SYSZ_INS_AGR,
|
||||
SYSZ_INS_AGRK,
|
||||
SYSZ_INS_AGSI,
|
||||
SYSZ_INS_AH,
|
||||
SYSZ_INS_AHI,
|
||||
SYSZ_INS_AHIK,
|
||||
SYSZ_INS_AHY,
|
||||
SYSZ_INS_AIH,
|
||||
SYSZ_INS_AL,
|
||||
SYSZ_INS_ALC,
|
||||
SYSZ_INS_ALCG,
|
||||
SYSZ_INS_ALCGR,
|
||||
SYSZ_INS_ALCR,
|
||||
SYSZ_INS_ALFI,
|
||||
SYSZ_INS_ALG,
|
||||
SYSZ_INS_ALGF,
|
||||
SYSZ_INS_ALGFI,
|
||||
SYSZ_INS_ALGFR,
|
||||
SYSZ_INS_ALGHSIK,
|
||||
SYSZ_INS_ALGR,
|
||||
SYSZ_INS_ALGRK,
|
||||
SYSZ_INS_ALHSIK,
|
||||
SYSZ_INS_ALR,
|
||||
SYSZ_INS_ALRK,
|
||||
SYSZ_INS_ALY,
|
||||
SYSZ_INS_AR,
|
||||
SYSZ_INS_ARK,
|
||||
SYSZ_INS_ASI,
|
||||
SYSZ_INS_AXBR,
|
||||
SYSZ_INS_AY,
|
||||
SYSZ_INS_BCR,
|
||||
SYSZ_INS_BRC,
|
||||
SYSZ_INS_BRCL,
|
||||
SYSZ_INS_CGIJ,
|
||||
SYSZ_INS_CGRJ,
|
||||
SYSZ_INS_CIJ,
|
||||
SYSZ_INS_CLGIJ,
|
||||
SYSZ_INS_CLGRJ,
|
||||
SYSZ_INS_CLIJ,
|
||||
SYSZ_INS_CLRJ,
|
||||
SYSZ_INS_CRJ,
|
||||
SYSZ_INS_BER,
|
||||
SYSZ_INS_JE,
|
||||
SYSZ_INS_JGE,
|
||||
SYSZ_INS_LOCE,
|
||||
SYSZ_INS_LOCGE,
|
||||
SYSZ_INS_LOCGRE,
|
||||
SYSZ_INS_LOCRE,
|
||||
SYSZ_INS_STOCE,
|
||||
SYSZ_INS_STOCGE,
|
||||
SYSZ_INS_BHR,
|
||||
SYSZ_INS_BHER,
|
||||
SYSZ_INS_JHE,
|
||||
SYSZ_INS_JGHE,
|
||||
SYSZ_INS_LOCHE,
|
||||
SYSZ_INS_LOCGHE,
|
||||
SYSZ_INS_LOCGRHE,
|
||||
SYSZ_INS_LOCRHE,
|
||||
SYSZ_INS_STOCHE,
|
||||
SYSZ_INS_STOCGHE,
|
||||
SYSZ_INS_JH,
|
||||
SYSZ_INS_JGH,
|
||||
SYSZ_INS_LOCH,
|
||||
SYSZ_INS_LOCGH,
|
||||
SYSZ_INS_LOCGRH,
|
||||
SYSZ_INS_LOCRH,
|
||||
SYSZ_INS_STOCH,
|
||||
SYSZ_INS_STOCGH,
|
||||
SYSZ_INS_CGIJNLH,
|
||||
SYSZ_INS_CGRJNLH,
|
||||
SYSZ_INS_CIJNLH,
|
||||
SYSZ_INS_CLGIJNLH,
|
||||
SYSZ_INS_CLGRJNLH,
|
||||
SYSZ_INS_CLIJNLH,
|
||||
SYSZ_INS_CLRJNLH,
|
||||
SYSZ_INS_CRJNLH,
|
||||
SYSZ_INS_CGIJE,
|
||||
SYSZ_INS_CGRJE,
|
||||
SYSZ_INS_CIJE,
|
||||
SYSZ_INS_CLGIJE,
|
||||
SYSZ_INS_CLGRJE,
|
||||
SYSZ_INS_CLIJE,
|
||||
SYSZ_INS_CLRJE,
|
||||
SYSZ_INS_CRJE,
|
||||
SYSZ_INS_CGIJNLE,
|
||||
SYSZ_INS_CGRJNLE,
|
||||
SYSZ_INS_CIJNLE,
|
||||
SYSZ_INS_CLGIJNLE,
|
||||
SYSZ_INS_CLGRJNLE,
|
||||
SYSZ_INS_CLIJNLE,
|
||||
SYSZ_INS_CLRJNLE,
|
||||
SYSZ_INS_CRJNLE,
|
||||
SYSZ_INS_CGIJH,
|
||||
SYSZ_INS_CGRJH,
|
||||
SYSZ_INS_CIJH,
|
||||
SYSZ_INS_CLGIJH,
|
||||
SYSZ_INS_CLGRJH,
|
||||
SYSZ_INS_CLIJH,
|
||||
SYSZ_INS_CLRJH,
|
||||
SYSZ_INS_CRJH,
|
||||
SYSZ_INS_CGIJNL,
|
||||
SYSZ_INS_CGRJNL,
|
||||
SYSZ_INS_CIJNL,
|
||||
SYSZ_INS_CLGIJNL,
|
||||
SYSZ_INS_CLGRJNL,
|
||||
SYSZ_INS_CLIJNL,
|
||||
SYSZ_INS_CLRJNL,
|
||||
SYSZ_INS_CRJNL,
|
||||
SYSZ_INS_CGIJHE,
|
||||
SYSZ_INS_CGRJHE,
|
||||
SYSZ_INS_CIJHE,
|
||||
SYSZ_INS_CLGIJHE,
|
||||
SYSZ_INS_CLGRJHE,
|
||||
SYSZ_INS_CLIJHE,
|
||||
SYSZ_INS_CLRJHE,
|
||||
SYSZ_INS_CRJHE,
|
||||
SYSZ_INS_CGIJNHE,
|
||||
SYSZ_INS_CGRJNHE,
|
||||
SYSZ_INS_CIJNHE,
|
||||
SYSZ_INS_CLGIJNHE,
|
||||
SYSZ_INS_CLGRJNHE,
|
||||
SYSZ_INS_CLIJNHE,
|
||||
SYSZ_INS_CLRJNHE,
|
||||
SYSZ_INS_CRJNHE,
|
||||
SYSZ_INS_CGIJL,
|
||||
SYSZ_INS_CGRJL,
|
||||
SYSZ_INS_CIJL,
|
||||
SYSZ_INS_CLGIJL,
|
||||
SYSZ_INS_CLGRJL,
|
||||
SYSZ_INS_CLIJL,
|
||||
SYSZ_INS_CLRJL,
|
||||
SYSZ_INS_CRJL,
|
||||
SYSZ_INS_CGIJNH,
|
||||
SYSZ_INS_CGRJNH,
|
||||
SYSZ_INS_CIJNH,
|
||||
SYSZ_INS_CLGIJNH,
|
||||
SYSZ_INS_CLGRJNH,
|
||||
SYSZ_INS_CLIJNH,
|
||||
SYSZ_INS_CLRJNH,
|
||||
SYSZ_INS_CRJNH,
|
||||
SYSZ_INS_CGIJLE,
|
||||
SYSZ_INS_CGRJLE,
|
||||
SYSZ_INS_CIJLE,
|
||||
SYSZ_INS_CLGIJLE,
|
||||
SYSZ_INS_CLGRJLE,
|
||||
SYSZ_INS_CLIJLE,
|
||||
SYSZ_INS_CLRJLE,
|
||||
SYSZ_INS_CRJLE,
|
||||
SYSZ_INS_CGIJNE,
|
||||
SYSZ_INS_CGRJNE,
|
||||
SYSZ_INS_CIJNE,
|
||||
SYSZ_INS_CLGIJNE,
|
||||
SYSZ_INS_CLGRJNE,
|
||||
SYSZ_INS_CLIJNE,
|
||||
SYSZ_INS_CLRJNE,
|
||||
SYSZ_INS_CRJNE,
|
||||
SYSZ_INS_CGIJLH,
|
||||
SYSZ_INS_CGRJLH,
|
||||
SYSZ_INS_CIJLH,
|
||||
SYSZ_INS_CLGIJLH,
|
||||
SYSZ_INS_CLGRJLH,
|
||||
SYSZ_INS_CLIJLH,
|
||||
SYSZ_INS_CLRJLH,
|
||||
SYSZ_INS_CRJLH,
|
||||
SYSZ_INS_BLR,
|
||||
SYSZ_INS_BLER,
|
||||
SYSZ_INS_JLE,
|
||||
SYSZ_INS_JGLE,
|
||||
SYSZ_INS_LOCLE,
|
||||
SYSZ_INS_LOCGLE,
|
||||
SYSZ_INS_LOCGRLE,
|
||||
SYSZ_INS_LOCRLE,
|
||||
SYSZ_INS_STOCLE,
|
||||
SYSZ_INS_STOCGLE,
|
||||
SYSZ_INS_BLHR,
|
||||
SYSZ_INS_JLH,
|
||||
SYSZ_INS_JGLH,
|
||||
SYSZ_INS_LOCLH,
|
||||
SYSZ_INS_LOCGLH,
|
||||
SYSZ_INS_LOCGRLH,
|
||||
SYSZ_INS_LOCRLH,
|
||||
SYSZ_INS_STOCLH,
|
||||
SYSZ_INS_STOCGLH,
|
||||
SYSZ_INS_JL,
|
||||
SYSZ_INS_JGL,
|
||||
SYSZ_INS_LOCL,
|
||||
SYSZ_INS_LOCGL,
|
||||
SYSZ_INS_LOCGRL,
|
||||
SYSZ_INS_LOCRL,
|
||||
SYSZ_INS_LOC,
|
||||
SYSZ_INS_LOCG,
|
||||
SYSZ_INS_LOCGR,
|
||||
SYSZ_INS_LOCR,
|
||||
SYSZ_INS_STOCL,
|
||||
SYSZ_INS_STOCGL,
|
||||
SYSZ_INS_BNER,
|
||||
SYSZ_INS_JNE,
|
||||
SYSZ_INS_JGNE,
|
||||
SYSZ_INS_LOCNE,
|
||||
SYSZ_INS_LOCGNE,
|
||||
SYSZ_INS_LOCGRNE,
|
||||
SYSZ_INS_LOCRNE,
|
||||
SYSZ_INS_STOCNE,
|
||||
SYSZ_INS_STOCGNE,
|
||||
SYSZ_INS_BNHR,
|
||||
SYSZ_INS_BNHER,
|
||||
SYSZ_INS_JNHE,
|
||||
SYSZ_INS_JGNHE,
|
||||
SYSZ_INS_LOCNHE,
|
||||
SYSZ_INS_LOCGNHE,
|
||||
SYSZ_INS_LOCGRNHE,
|
||||
SYSZ_INS_LOCRNHE,
|
||||
SYSZ_INS_STOCNHE,
|
||||
SYSZ_INS_STOCGNHE,
|
||||
SYSZ_INS_JNH,
|
||||
SYSZ_INS_JGNH,
|
||||
SYSZ_INS_LOCNH,
|
||||
SYSZ_INS_LOCGNH,
|
||||
SYSZ_INS_LOCGRNH,
|
||||
SYSZ_INS_LOCRNH,
|
||||
SYSZ_INS_STOCNH,
|
||||
SYSZ_INS_STOCGNH,
|
||||
SYSZ_INS_BNLR,
|
||||
SYSZ_INS_BNLER,
|
||||
SYSZ_INS_JNLE,
|
||||
SYSZ_INS_JGNLE,
|
||||
SYSZ_INS_LOCNLE,
|
||||
SYSZ_INS_LOCGNLE,
|
||||
SYSZ_INS_LOCGRNLE,
|
||||
SYSZ_INS_LOCRNLE,
|
||||
SYSZ_INS_STOCNLE,
|
||||
SYSZ_INS_STOCGNLE,
|
||||
SYSZ_INS_BNLHR,
|
||||
SYSZ_INS_JNLH,
|
||||
SYSZ_INS_JGNLH,
|
||||
SYSZ_INS_LOCNLH,
|
||||
SYSZ_INS_LOCGNLH,
|
||||
SYSZ_INS_LOCGRNLH,
|
||||
SYSZ_INS_LOCRNLH,
|
||||
SYSZ_INS_STOCNLH,
|
||||
SYSZ_INS_STOCGNLH,
|
||||
SYSZ_INS_JNL,
|
||||
SYSZ_INS_JGNL,
|
||||
SYSZ_INS_LOCNL,
|
||||
SYSZ_INS_LOCGNL,
|
||||
SYSZ_INS_LOCGRNL,
|
||||
SYSZ_INS_LOCRNL,
|
||||
SYSZ_INS_STOCNL,
|
||||
SYSZ_INS_STOCGNL,
|
||||
SYSZ_INS_BNOR,
|
||||
SYSZ_INS_JNO,
|
||||
SYSZ_INS_JGNO,
|
||||
SYSZ_INS_LOCNO,
|
||||
SYSZ_INS_LOCGNO,
|
||||
SYSZ_INS_LOCGRNO,
|
||||
SYSZ_INS_LOCRNO,
|
||||
SYSZ_INS_STOCNO,
|
||||
SYSZ_INS_STOCGNO,
|
||||
SYSZ_INS_BOR,
|
||||
SYSZ_INS_JO,
|
||||
SYSZ_INS_JGO,
|
||||
SYSZ_INS_LOCO,
|
||||
SYSZ_INS_LOCGO,
|
||||
SYSZ_INS_LOCGRO,
|
||||
SYSZ_INS_LOCRO,
|
||||
SYSZ_INS_STOCO,
|
||||
SYSZ_INS_STOCGO,
|
||||
SYSZ_INS_STOC,
|
||||
SYSZ_INS_STOCG,
|
||||
SYSZ_INS_BASR,
|
||||
SYSZ_INS_BR,
|
||||
SYSZ_INS_BRAS,
|
||||
SYSZ_INS_BRASL,
|
||||
SYSZ_INS_J,
|
||||
SYSZ_INS_JG,
|
||||
SYSZ_INS_BRCT,
|
||||
SYSZ_INS_BRCTG,
|
||||
SYSZ_INS_C,
|
||||
SYSZ_INS_CDB,
|
||||
SYSZ_INS_CDBR,
|
||||
SYSZ_INS_CDFBR,
|
||||
SYSZ_INS_CDGBR,
|
||||
SYSZ_INS_CDLFBR,
|
||||
SYSZ_INS_CDLGBR,
|
||||
SYSZ_INS_CEB,
|
||||
SYSZ_INS_CEBR,
|
||||
SYSZ_INS_CEFBR,
|
||||
SYSZ_INS_CEGBR,
|
||||
SYSZ_INS_CELFBR,
|
||||
SYSZ_INS_CELGBR,
|
||||
SYSZ_INS_CFDBR,
|
||||
SYSZ_INS_CFEBR,
|
||||
SYSZ_INS_CFI,
|
||||
SYSZ_INS_CFXBR,
|
||||
SYSZ_INS_CG,
|
||||
SYSZ_INS_CGDBR,
|
||||
SYSZ_INS_CGEBR,
|
||||
SYSZ_INS_CGF,
|
||||
SYSZ_INS_CGFI,
|
||||
SYSZ_INS_CGFR,
|
||||
SYSZ_INS_CGFRL,
|
||||
SYSZ_INS_CGH,
|
||||
SYSZ_INS_CGHI,
|
||||
SYSZ_INS_CGHRL,
|
||||
SYSZ_INS_CGHSI,
|
||||
SYSZ_INS_CGR,
|
||||
SYSZ_INS_CGRL,
|
||||
SYSZ_INS_CGXBR,
|
||||
SYSZ_INS_CH,
|
||||
SYSZ_INS_CHF,
|
||||
SYSZ_INS_CHHSI,
|
||||
SYSZ_INS_CHI,
|
||||
SYSZ_INS_CHRL,
|
||||
SYSZ_INS_CHSI,
|
||||
SYSZ_INS_CHY,
|
||||
SYSZ_INS_CIH,
|
||||
SYSZ_INS_CL,
|
||||
SYSZ_INS_CLC,
|
||||
SYSZ_INS_CLFDBR,
|
||||
SYSZ_INS_CLFEBR,
|
||||
SYSZ_INS_CLFHSI,
|
||||
SYSZ_INS_CLFI,
|
||||
SYSZ_INS_CLFXBR,
|
||||
SYSZ_INS_CLG,
|
||||
SYSZ_INS_CLGDBR,
|
||||
SYSZ_INS_CLGEBR,
|
||||
SYSZ_INS_CLGF,
|
||||
SYSZ_INS_CLGFI,
|
||||
SYSZ_INS_CLGFR,
|
||||
SYSZ_INS_CLGFRL,
|
||||
SYSZ_INS_CLGHRL,
|
||||
SYSZ_INS_CLGHSI,
|
||||
SYSZ_INS_CLGR,
|
||||
SYSZ_INS_CLGRL,
|
||||
SYSZ_INS_CLGXBR,
|
||||
SYSZ_INS_CLHF,
|
||||
SYSZ_INS_CLHHSI,
|
||||
SYSZ_INS_CLHRL,
|
||||
SYSZ_INS_CLI,
|
||||
SYSZ_INS_CLIH,
|
||||
SYSZ_INS_CLIY,
|
||||
SYSZ_INS_CLR,
|
||||
SYSZ_INS_CLRL,
|
||||
SYSZ_INS_CLST,
|
||||
SYSZ_INS_CLY,
|
||||
SYSZ_INS_CPSDR,
|
||||
SYSZ_INS_CR,
|
||||
SYSZ_INS_CRL,
|
||||
SYSZ_INS_CS,
|
||||
SYSZ_INS_CSG,
|
||||
SYSZ_INS_CSY,
|
||||
SYSZ_INS_CXBR,
|
||||
SYSZ_INS_CXFBR,
|
||||
SYSZ_INS_CXGBR,
|
||||
SYSZ_INS_CXLFBR,
|
||||
SYSZ_INS_CXLGBR,
|
||||
SYSZ_INS_CY,
|
||||
SYSZ_INS_DDB,
|
||||
SYSZ_INS_DDBR,
|
||||
SYSZ_INS_DEB,
|
||||
SYSZ_INS_DEBR,
|
||||
SYSZ_INS_DL,
|
||||
SYSZ_INS_DLG,
|
||||
SYSZ_INS_DLGR,
|
||||
SYSZ_INS_DLR,
|
||||
SYSZ_INS_DSG,
|
||||
SYSZ_INS_DSGF,
|
||||
SYSZ_INS_DSGFR,
|
||||
SYSZ_INS_DSGR,
|
||||
SYSZ_INS_DXBR,
|
||||
SYSZ_INS_EAR,
|
||||
SYSZ_INS_FIDBR,
|
||||
SYSZ_INS_FIDBRA,
|
||||
SYSZ_INS_FIEBR,
|
||||
SYSZ_INS_FIEBRA,
|
||||
SYSZ_INS_FIXBR,
|
||||
SYSZ_INS_FIXBRA,
|
||||
SYSZ_INS_FLOGR,
|
||||
SYSZ_INS_IC,
|
||||
SYSZ_INS_ICY,
|
||||
SYSZ_INS_IIHF,
|
||||
SYSZ_INS_IIHH,
|
||||
SYSZ_INS_IIHL,
|
||||
SYSZ_INS_IILF,
|
||||
SYSZ_INS_IILH,
|
||||
SYSZ_INS_IILL,
|
||||
SYSZ_INS_IPM,
|
||||
SYSZ_INS_L,
|
||||
SYSZ_INS_LA,
|
||||
SYSZ_INS_LAA,
|
||||
SYSZ_INS_LAAG,
|
||||
SYSZ_INS_LAAL,
|
||||
SYSZ_INS_LAALG,
|
||||
SYSZ_INS_LAN,
|
||||
SYSZ_INS_LANG,
|
||||
SYSZ_INS_LAO,
|
||||
SYSZ_INS_LAOG,
|
||||
SYSZ_INS_LARL,
|
||||
SYSZ_INS_LAX,
|
||||
SYSZ_INS_LAXG,
|
||||
SYSZ_INS_LAY,
|
||||
SYSZ_INS_LB,
|
||||
SYSZ_INS_LBH,
|
||||
SYSZ_INS_LBR,
|
||||
SYSZ_INS_LCDBR,
|
||||
SYSZ_INS_LCEBR,
|
||||
SYSZ_INS_LCGFR,
|
||||
SYSZ_INS_LCGR,
|
||||
SYSZ_INS_LCR,
|
||||
SYSZ_INS_LCXBR,
|
||||
SYSZ_INS_LD,
|
||||
SYSZ_INS_LDEB,
|
||||
SYSZ_INS_LDEBR,
|
||||
SYSZ_INS_LDGR,
|
||||
SYSZ_INS_LDR,
|
||||
SYSZ_INS_LDXBR,
|
||||
SYSZ_INS_LDXBRA,
|
||||
SYSZ_INS_LDY,
|
||||
SYSZ_INS_LE,
|
||||
SYSZ_INS_LEDBR,
|
||||
SYSZ_INS_LEDBRA,
|
||||
SYSZ_INS_LER,
|
||||
SYSZ_INS_LEXBR,
|
||||
SYSZ_INS_LEXBRA,
|
||||
SYSZ_INS_LEY,
|
||||
SYSZ_INS_LFH,
|
||||
SYSZ_INS_LG,
|
||||
SYSZ_INS_LGB,
|
||||
SYSZ_INS_LGBR,
|
||||
SYSZ_INS_LGDR,
|
||||
SYSZ_INS_LGF,
|
||||
SYSZ_INS_LGFI,
|
||||
SYSZ_INS_LGFR,
|
||||
SYSZ_INS_LGFRL,
|
||||
SYSZ_INS_LGH,
|
||||
SYSZ_INS_LGHI,
|
||||
SYSZ_INS_LGHR,
|
||||
SYSZ_INS_LGHRL,
|
||||
SYSZ_INS_LGR,
|
||||
SYSZ_INS_LGRL,
|
||||
SYSZ_INS_LH,
|
||||
SYSZ_INS_LHH,
|
||||
SYSZ_INS_LHI,
|
||||
SYSZ_INS_LHR,
|
||||
SYSZ_INS_LHRL,
|
||||
SYSZ_INS_LHY,
|
||||
SYSZ_INS_LLC,
|
||||
SYSZ_INS_LLCH,
|
||||
SYSZ_INS_LLCR,
|
||||
SYSZ_INS_LLGC,
|
||||
SYSZ_INS_LLGCR,
|
||||
SYSZ_INS_LLGF,
|
||||
SYSZ_INS_LLGFR,
|
||||
SYSZ_INS_LLGFRL,
|
||||
SYSZ_INS_LLGH,
|
||||
SYSZ_INS_LLGHR,
|
||||
SYSZ_INS_LLGHRL,
|
||||
SYSZ_INS_LLH,
|
||||
SYSZ_INS_LLHH,
|
||||
SYSZ_INS_LLHR,
|
||||
SYSZ_INS_LLHRL,
|
||||
SYSZ_INS_LLIHF,
|
||||
SYSZ_INS_LLIHH,
|
||||
SYSZ_INS_LLIHL,
|
||||
SYSZ_INS_LLILF,
|
||||
SYSZ_INS_LLILH,
|
||||
SYSZ_INS_LLILL,
|
||||
SYSZ_INS_LMG,
|
||||
SYSZ_INS_LNDBR,
|
||||
SYSZ_INS_LNEBR,
|
||||
SYSZ_INS_LNGFR,
|
||||
SYSZ_INS_LNGR,
|
||||
SYSZ_INS_LNR,
|
||||
SYSZ_INS_LNXBR,
|
||||
SYSZ_INS_LPDBR,
|
||||
SYSZ_INS_LPEBR,
|
||||
SYSZ_INS_LPGFR,
|
||||
SYSZ_INS_LPGR,
|
||||
SYSZ_INS_LPR,
|
||||
SYSZ_INS_LPXBR,
|
||||
SYSZ_INS_LR,
|
||||
SYSZ_INS_LRL,
|
||||
SYSZ_INS_LRV,
|
||||
SYSZ_INS_LRVG,
|
||||
SYSZ_INS_LRVGR,
|
||||
SYSZ_INS_LRVR,
|
||||
SYSZ_INS_LT,
|
||||
SYSZ_INS_LTDBR,
|
||||
SYSZ_INS_LTEBR,
|
||||
SYSZ_INS_LTG,
|
||||
SYSZ_INS_LTGF,
|
||||
SYSZ_INS_LTGFR,
|
||||
SYSZ_INS_LTGR,
|
||||
SYSZ_INS_LTR,
|
||||
SYSZ_INS_LTXBR,
|
||||
SYSZ_INS_LXDB,
|
||||
SYSZ_INS_LXDBR,
|
||||
SYSZ_INS_LXEB,
|
||||
SYSZ_INS_LXEBR,
|
||||
SYSZ_INS_LXR,
|
||||
SYSZ_INS_LY,
|
||||
SYSZ_INS_LZDR,
|
||||
SYSZ_INS_LZER,
|
||||
SYSZ_INS_LZXR,
|
||||
SYSZ_INS_MADB,
|
||||
SYSZ_INS_MADBR,
|
||||
SYSZ_INS_MAEB,
|
||||
SYSZ_INS_MAEBR,
|
||||
SYSZ_INS_MDB,
|
||||
SYSZ_INS_MDBR,
|
||||
SYSZ_INS_MDEB,
|
||||
SYSZ_INS_MDEBR,
|
||||
SYSZ_INS_MEEB,
|
||||
SYSZ_INS_MEEBR,
|
||||
SYSZ_INS_MGHI,
|
||||
SYSZ_INS_MH,
|
||||
SYSZ_INS_MHI,
|
||||
SYSZ_INS_MHY,
|
||||
SYSZ_INS_MLG,
|
||||
SYSZ_INS_MLGR,
|
||||
SYSZ_INS_MS,
|
||||
SYSZ_INS_MSDB,
|
||||
SYSZ_INS_MSDBR,
|
||||
SYSZ_INS_MSEB,
|
||||
SYSZ_INS_MSEBR,
|
||||
SYSZ_INS_MSFI,
|
||||
SYSZ_INS_MSG,
|
||||
SYSZ_INS_MSGF,
|
||||
SYSZ_INS_MSGFI,
|
||||
SYSZ_INS_MSGFR,
|
||||
SYSZ_INS_MSGR,
|
||||
SYSZ_INS_MSR,
|
||||
SYSZ_INS_MSY,
|
||||
SYSZ_INS_MVC,
|
||||
SYSZ_INS_MVGHI,
|
||||
SYSZ_INS_MVHHI,
|
||||
SYSZ_INS_MVHI,
|
||||
SYSZ_INS_MVI,
|
||||
SYSZ_INS_MVIY,
|
||||
SYSZ_INS_MVST,
|
||||
SYSZ_INS_MXBR,
|
||||
SYSZ_INS_MXDB,
|
||||
SYSZ_INS_MXDBR,
|
||||
SYSZ_INS_N,
|
||||
SYSZ_INS_NC,
|
||||
SYSZ_INS_NG,
|
||||
SYSZ_INS_NGR,
|
||||
SYSZ_INS_NGRK,
|
||||
SYSZ_INS_NI,
|
||||
SYSZ_INS_NIHF,
|
||||
SYSZ_INS_NIHH,
|
||||
SYSZ_INS_NIHL,
|
||||
SYSZ_INS_NILF,
|
||||
SYSZ_INS_NILH,
|
||||
SYSZ_INS_NILL,
|
||||
SYSZ_INS_NIY,
|
||||
SYSZ_INS_NR,
|
||||
SYSZ_INS_NRK,
|
||||
SYSZ_INS_NY,
|
||||
SYSZ_INS_O,
|
||||
SYSZ_INS_OC,
|
||||
SYSZ_INS_OG,
|
||||
SYSZ_INS_OGR,
|
||||
SYSZ_INS_OGRK,
|
||||
SYSZ_INS_OI,
|
||||
SYSZ_INS_OIHF,
|
||||
SYSZ_INS_OIHH,
|
||||
SYSZ_INS_OIHL,
|
||||
SYSZ_INS_OILF,
|
||||
SYSZ_INS_OILH,
|
||||
SYSZ_INS_OILL,
|
||||
SYSZ_INS_OIY,
|
||||
SYSZ_INS_OR,
|
||||
SYSZ_INS_ORK,
|
||||
SYSZ_INS_OY,
|
||||
SYSZ_INS_PFD,
|
||||
SYSZ_INS_PFDRL,
|
||||
SYSZ_INS_RISBG,
|
||||
SYSZ_INS_RISBHG,
|
||||
SYSZ_INS_RISBLG,
|
||||
SYSZ_INS_RLL,
|
||||
SYSZ_INS_RLLG,
|
||||
SYSZ_INS_RNSBG,
|
||||
SYSZ_INS_ROSBG,
|
||||
SYSZ_INS_RXSBG,
|
||||
SYSZ_INS_S,
|
||||
SYSZ_INS_SDB,
|
||||
SYSZ_INS_SDBR,
|
||||
SYSZ_INS_SEB,
|
||||
SYSZ_INS_SEBR,
|
||||
SYSZ_INS_SG,
|
||||
SYSZ_INS_SGF,
|
||||
SYSZ_INS_SGFR,
|
||||
SYSZ_INS_SGR,
|
||||
SYSZ_INS_SGRK,
|
||||
SYSZ_INS_SH,
|
||||
SYSZ_INS_SHY,
|
||||
SYSZ_INS_SL,
|
||||
SYSZ_INS_SLB,
|
||||
SYSZ_INS_SLBG,
|
||||
SYSZ_INS_SLBR,
|
||||
SYSZ_INS_SLFI,
|
||||
SYSZ_INS_SLG,
|
||||
SYSZ_INS_SLBGR,
|
||||
SYSZ_INS_SLGF,
|
||||
SYSZ_INS_SLGFI,
|
||||
SYSZ_INS_SLGFR,
|
||||
SYSZ_INS_SLGR,
|
||||
SYSZ_INS_SLGRK,
|
||||
SYSZ_INS_SLL,
|
||||
SYSZ_INS_SLLG,
|
||||
SYSZ_INS_SLLK,
|
||||
SYSZ_INS_SLR,
|
||||
SYSZ_INS_SLRK,
|
||||
SYSZ_INS_SLY,
|
||||
SYSZ_INS_SQDB,
|
||||
SYSZ_INS_SQDBR,
|
||||
SYSZ_INS_SQEB,
|
||||
SYSZ_INS_SQEBR,
|
||||
SYSZ_INS_SQXBR,
|
||||
SYSZ_INS_SR,
|
||||
SYSZ_INS_SRA,
|
||||
SYSZ_INS_SRAG,
|
||||
SYSZ_INS_SRAK,
|
||||
SYSZ_INS_SRK,
|
||||
SYSZ_INS_SRL,
|
||||
SYSZ_INS_SRLG,
|
||||
SYSZ_INS_SRLK,
|
||||
SYSZ_INS_SRST,
|
||||
SYSZ_INS_ST,
|
||||
SYSZ_INS_STC,
|
||||
SYSZ_INS_STCH,
|
||||
SYSZ_INS_STCY,
|
||||
SYSZ_INS_STD,
|
||||
SYSZ_INS_STDY,
|
||||
SYSZ_INS_STE,
|
||||
SYSZ_INS_STEY,
|
||||
SYSZ_INS_STFH,
|
||||
SYSZ_INS_STG,
|
||||
SYSZ_INS_STGRL,
|
||||
SYSZ_INS_STH,
|
||||
SYSZ_INS_STHH,
|
||||
SYSZ_INS_STHRL,
|
||||
SYSZ_INS_STHY,
|
||||
SYSZ_INS_STMG,
|
||||
SYSZ_INS_STRL,
|
||||
SYSZ_INS_STRV,
|
||||
SYSZ_INS_STRVG,
|
||||
SYSZ_INS_STY,
|
||||
SYSZ_INS_SXBR,
|
||||
SYSZ_INS_SY,
|
||||
SYSZ_INS_TM,
|
||||
SYSZ_INS_TMHH,
|
||||
SYSZ_INS_TMHL,
|
||||
SYSZ_INS_TMLH,
|
||||
SYSZ_INS_TMLL,
|
||||
SYSZ_INS_TMY,
|
||||
SYSZ_INS_X,
|
||||
SYSZ_INS_XC,
|
||||
SYSZ_INS_XG,
|
||||
SYSZ_INS_XGR,
|
||||
SYSZ_INS_XGRK,
|
||||
SYSZ_INS_XI,
|
||||
SYSZ_INS_XIHF,
|
||||
SYSZ_INS_XILF,
|
||||
SYSZ_INS_XIY,
|
||||
SYSZ_INS_XR,
|
||||
SYSZ_INS_XRK,
|
||||
SYSZ_INS_XY,
|
||||
|
||||
SYSZ_INS_ENDING, // <-- mark the end of the list of instructions
|
||||
} sysz_insn;
|
||||
|
||||
//> Group of SystemZ instructions
|
||||
typedef enum sysz_insn_group {
|
||||
SYSZ_GRP_INVALID = 0, // = CS_GRP_INVALID
|
||||
|
||||
//> Generic groups
|
||||
// all jump instructions (conditional+direct+indirect jumps)
|
||||
SYSZ_GRP_JUMP, // = CS_GRP_JUMP
|
||||
|
||||
//> Architecture-specific groups
|
||||
SYSZ_GRP_DISTINCTOPS = 128,
|
||||
SYSZ_GRP_FPEXTENSION,
|
||||
SYSZ_GRP_HIGHWORD,
|
||||
SYSZ_GRP_INTERLOCKEDACCESS1,
|
||||
SYSZ_GRP_LOADSTOREONCOND,
|
||||
|
||||
SYSZ_GRP_ENDING, // <-- mark the end of the list of groups
|
||||
} sysz_insn_group;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
1632
EFI/OC/Kexts/Lilu.kext/Contents/Resources/Headers/capstone/x86.h
Normal file
1632
EFI/OC/Kexts/Lilu.kext/Contents/Resources/Headers/capstone/x86.h
Normal file
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,237 @@
|
||||
#ifndef CAPSTONE_XCORE_H
|
||||
#define CAPSTONE_XCORE_H
|
||||
|
||||
/* Capstone Disassembly Engine */
|
||||
/* By Nguyen Anh Quynh <aquynh@gmail.com>, 2014 */
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#if !defined(_MSC_VER) || !defined(_KERNEL_MODE)
|
||||
#include <stdint.h>
|
||||
#endif
|
||||
|
||||
#include "platform.h"
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#pragma warning(disable:4201)
|
||||
#endif
|
||||
|
||||
//> Operand type for instruction's operands
|
||||
typedef enum xcore_op_type {
|
||||
XCORE_OP_INVALID = 0, // = CS_OP_INVALID (Uninitialized).
|
||||
XCORE_OP_REG, // = CS_OP_REG (Register operand).
|
||||
XCORE_OP_IMM, // = CS_OP_IMM (Immediate operand).
|
||||
XCORE_OP_MEM, // = CS_OP_MEM (Memory operand).
|
||||
} xcore_op_type;
|
||||
|
||||
// Instruction's operand referring to memory
|
||||
// This is associated with XCORE_OP_MEM operand type above
|
||||
typedef struct xcore_op_mem {
|
||||
uint8_t base; // base register
|
||||
uint8_t index; // index register
|
||||
int32_t disp; // displacement/offset value
|
||||
int direct; // +1: forward, -1: backward
|
||||
} xcore_op_mem;
|
||||
|
||||
// Instruction operand
|
||||
typedef struct cs_xcore_op {
|
||||
xcore_op_type type; // operand type
|
||||
union {
|
||||
unsigned int reg; // register value for REG operand
|
||||
int32_t imm; // immediate value for IMM operand
|
||||
xcore_op_mem mem; // base/disp value for MEM operand
|
||||
};
|
||||
} cs_xcore_op;
|
||||
|
||||
// Instruction structure
|
||||
typedef struct cs_xcore {
|
||||
// Number of operands of this instruction,
|
||||
// or 0 when instruction has no operand.
|
||||
uint8_t op_count;
|
||||
cs_xcore_op operands[8]; // operands for this instruction.
|
||||
} cs_xcore;
|
||||
|
||||
//> XCore registers
|
||||
typedef enum xcore_reg {
|
||||
XCORE_REG_INVALID = 0,
|
||||
|
||||
XCORE_REG_CP,
|
||||
XCORE_REG_DP,
|
||||
XCORE_REG_LR,
|
||||
XCORE_REG_SP,
|
||||
XCORE_REG_R0,
|
||||
XCORE_REG_R1,
|
||||
XCORE_REG_R2,
|
||||
XCORE_REG_R3,
|
||||
XCORE_REG_R4,
|
||||
XCORE_REG_R5,
|
||||
XCORE_REG_R6,
|
||||
XCORE_REG_R7,
|
||||
XCORE_REG_R8,
|
||||
XCORE_REG_R9,
|
||||
XCORE_REG_R10,
|
||||
XCORE_REG_R11,
|
||||
|
||||
//> pseudo registers
|
||||
XCORE_REG_PC, // pc
|
||||
|
||||
// internal thread registers
|
||||
// see The-XMOS-XS1-Architecture(X7879A).pdf
|
||||
XCORE_REG_SCP, // save pc
|
||||
XCORE_REG_SSR, // save status
|
||||
XCORE_REG_ET, // exception type
|
||||
XCORE_REG_ED, // exception data
|
||||
XCORE_REG_SED, // save exception data
|
||||
XCORE_REG_KEP, // kernel entry pointer
|
||||
XCORE_REG_KSP, // kernel stack pointer
|
||||
XCORE_REG_ID, // thread ID
|
||||
|
||||
XCORE_REG_ENDING, // <-- mark the end of the list of registers
|
||||
} xcore_reg;
|
||||
|
||||
//> XCore instruction
|
||||
typedef enum xcore_insn {
|
||||
XCORE_INS_INVALID = 0,
|
||||
|
||||
XCORE_INS_ADD,
|
||||
XCORE_INS_ANDNOT,
|
||||
XCORE_INS_AND,
|
||||
XCORE_INS_ASHR,
|
||||
XCORE_INS_BAU,
|
||||
XCORE_INS_BITREV,
|
||||
XCORE_INS_BLA,
|
||||
XCORE_INS_BLAT,
|
||||
XCORE_INS_BL,
|
||||
XCORE_INS_BF,
|
||||
XCORE_INS_BT,
|
||||
XCORE_INS_BU,
|
||||
XCORE_INS_BRU,
|
||||
XCORE_INS_BYTEREV,
|
||||
XCORE_INS_CHKCT,
|
||||
XCORE_INS_CLRE,
|
||||
XCORE_INS_CLRPT,
|
||||
XCORE_INS_CLRSR,
|
||||
XCORE_INS_CLZ,
|
||||
XCORE_INS_CRC8,
|
||||
XCORE_INS_CRC32,
|
||||
XCORE_INS_DCALL,
|
||||
XCORE_INS_DENTSP,
|
||||
XCORE_INS_DGETREG,
|
||||
XCORE_INS_DIVS,
|
||||
XCORE_INS_DIVU,
|
||||
XCORE_INS_DRESTSP,
|
||||
XCORE_INS_DRET,
|
||||
XCORE_INS_ECALLF,
|
||||
XCORE_INS_ECALLT,
|
||||
XCORE_INS_EDU,
|
||||
XCORE_INS_EEF,
|
||||
XCORE_INS_EET,
|
||||
XCORE_INS_EEU,
|
||||
XCORE_INS_ENDIN,
|
||||
XCORE_INS_ENTSP,
|
||||
XCORE_INS_EQ,
|
||||
XCORE_INS_EXTDP,
|
||||
XCORE_INS_EXTSP,
|
||||
XCORE_INS_FREER,
|
||||
XCORE_INS_FREET,
|
||||
XCORE_INS_GETD,
|
||||
XCORE_INS_GET,
|
||||
XCORE_INS_GETN,
|
||||
XCORE_INS_GETR,
|
||||
XCORE_INS_GETSR,
|
||||
XCORE_INS_GETST,
|
||||
XCORE_INS_GETTS,
|
||||
XCORE_INS_INCT,
|
||||
XCORE_INS_INIT,
|
||||
XCORE_INS_INPW,
|
||||
XCORE_INS_INSHR,
|
||||
XCORE_INS_INT,
|
||||
XCORE_INS_IN,
|
||||
XCORE_INS_KCALL,
|
||||
XCORE_INS_KENTSP,
|
||||
XCORE_INS_KRESTSP,
|
||||
XCORE_INS_KRET,
|
||||
XCORE_INS_LADD,
|
||||
XCORE_INS_LD16S,
|
||||
XCORE_INS_LD8U,
|
||||
XCORE_INS_LDA16,
|
||||
XCORE_INS_LDAP,
|
||||
XCORE_INS_LDAW,
|
||||
XCORE_INS_LDC,
|
||||
XCORE_INS_LDW,
|
||||
XCORE_INS_LDIVU,
|
||||
XCORE_INS_LMUL,
|
||||
XCORE_INS_LSS,
|
||||
XCORE_INS_LSUB,
|
||||
XCORE_INS_LSU,
|
||||
XCORE_INS_MACCS,
|
||||
XCORE_INS_MACCU,
|
||||
XCORE_INS_MJOIN,
|
||||
XCORE_INS_MKMSK,
|
||||
XCORE_INS_MSYNC,
|
||||
XCORE_INS_MUL,
|
||||
XCORE_INS_NEG,
|
||||
XCORE_INS_NOT,
|
||||
XCORE_INS_OR,
|
||||
XCORE_INS_OUTCT,
|
||||
XCORE_INS_OUTPW,
|
||||
XCORE_INS_OUTSHR,
|
||||
XCORE_INS_OUTT,
|
||||
XCORE_INS_OUT,
|
||||
XCORE_INS_PEEK,
|
||||
XCORE_INS_REMS,
|
||||
XCORE_INS_REMU,
|
||||
XCORE_INS_RETSP,
|
||||
XCORE_INS_SETCLK,
|
||||
XCORE_INS_SET,
|
||||
XCORE_INS_SETC,
|
||||
XCORE_INS_SETD,
|
||||
XCORE_INS_SETEV,
|
||||
XCORE_INS_SETN,
|
||||
XCORE_INS_SETPSC,
|
||||
XCORE_INS_SETPT,
|
||||
XCORE_INS_SETRDY,
|
||||
XCORE_INS_SETSR,
|
||||
XCORE_INS_SETTW,
|
||||
XCORE_INS_SETV,
|
||||
XCORE_INS_SEXT,
|
||||
XCORE_INS_SHL,
|
||||
XCORE_INS_SHR,
|
||||
XCORE_INS_SSYNC,
|
||||
XCORE_INS_ST16,
|
||||
XCORE_INS_ST8,
|
||||
XCORE_INS_STW,
|
||||
XCORE_INS_SUB,
|
||||
XCORE_INS_SYNCR,
|
||||
XCORE_INS_TESTCT,
|
||||
XCORE_INS_TESTLCL,
|
||||
XCORE_INS_TESTWCT,
|
||||
XCORE_INS_TSETMR,
|
||||
XCORE_INS_START,
|
||||
XCORE_INS_WAITEF,
|
||||
XCORE_INS_WAITET,
|
||||
XCORE_INS_WAITEU,
|
||||
XCORE_INS_XOR,
|
||||
XCORE_INS_ZEXT,
|
||||
|
||||
XCORE_INS_ENDING, // <-- mark the end of the list of instructions
|
||||
} xcore_insn;
|
||||
|
||||
//> Group of XCore instructions
|
||||
typedef enum xcore_insn_group {
|
||||
XCORE_GRP_INVALID = 0, // = CS_GRP_INVALID
|
||||
|
||||
//> Generic groups
|
||||
// all jump instructions (conditional+direct+indirect jumps)
|
||||
XCORE_GRP_JUMP, // = CS_GRP_JUMP
|
||||
|
||||
XCORE_GRP_ENDING, // <-- mark the end of the list of groups
|
||||
} xcore_insn_group;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
96
EFI/OC/Kexts/Lilu.kext/Contents/Resources/Headers/hde32.h
Normal file
96
EFI/OC/Kexts/Lilu.kext/Contents/Resources/Headers/hde32.h
Normal file
@@ -0,0 +1,96 @@
|
||||
/*
|
||||
* Hacker Disassembler Engine 32
|
||||
* Copyright (c) 2006-2009, Vyacheslav Patkov.
|
||||
* All rights reserved.
|
||||
*
|
||||
* hde32.h: C/C++ header file
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef _HDE32_H_
|
||||
#define _HDE32_H_
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#define F_MODRM 0x00000001
|
||||
#define F_SIB 0x00000002
|
||||
#define F_IMM8 0x00000004
|
||||
#define F_IMM16 0x00000008
|
||||
#define F_IMM32 0x00000010
|
||||
#define F_DISP8 0x00000020
|
||||
#define F_DISP16 0x00000040
|
||||
#define F_DISP32 0x00000080
|
||||
#define F_RELATIVE 0x00000100
|
||||
#define F_2IMM16 0x00000800
|
||||
#define F_ERROR 0x00001000
|
||||
#define F_ERROR_OPCODE 0x00002000
|
||||
#define F_ERROR_LENGTH 0x00004000
|
||||
#define F_ERROR_LOCK 0x00008000
|
||||
#define F_ERROR_OPERAND 0x00010000
|
||||
#define F_PREFIX_REPNZ 0x01000000
|
||||
#define F_PREFIX_REPX 0x02000000
|
||||
#define F_PREFIX_REP 0x03000000
|
||||
#define F_PREFIX_66 0x04000000
|
||||
#define F_PREFIX_67 0x08000000
|
||||
#define F_PREFIX_LOCK 0x10000000
|
||||
#define F_PREFIX_SEG 0x20000000
|
||||
#define F_PREFIX_ANY 0x3f000000
|
||||
|
||||
#define PREFIX_SEGMENT_CS 0x2e
|
||||
#define PREFIX_SEGMENT_SS 0x36
|
||||
#define PREFIX_SEGMENT_DS 0x3e
|
||||
#define PREFIX_SEGMENT_ES 0x26
|
||||
#define PREFIX_SEGMENT_FS 0x64
|
||||
#define PREFIX_SEGMENT_GS 0x65
|
||||
#define PREFIX_LOCK 0xf0
|
||||
#define PREFIX_REPNZ 0xf2
|
||||
#define PREFIX_REPX 0xf3
|
||||
#define PREFIX_OPERAND_SIZE 0x66
|
||||
#define PREFIX_ADDRESS_SIZE 0x67
|
||||
|
||||
#pragma pack(push,1)
|
||||
|
||||
typedef struct {
|
||||
uint8_t len;
|
||||
uint8_t p_rep;
|
||||
uint8_t p_lock;
|
||||
uint8_t p_seg;
|
||||
uint8_t p_66;
|
||||
uint8_t p_67;
|
||||
uint8_t opcode;
|
||||
uint8_t opcode2;
|
||||
uint8_t modrm;
|
||||
uint8_t modrm_mod;
|
||||
uint8_t modrm_reg;
|
||||
uint8_t modrm_rm;
|
||||
uint8_t sib;
|
||||
uint8_t sib_scale;
|
||||
uint8_t sib_index;
|
||||
uint8_t sib_base;
|
||||
union {
|
||||
uint8_t imm8;
|
||||
uint16_t imm16;
|
||||
uint32_t imm32;
|
||||
} imm;
|
||||
union {
|
||||
uint8_t disp8;
|
||||
uint16_t disp16;
|
||||
uint32_t disp32;
|
||||
} disp;
|
||||
uint32_t flags;
|
||||
} hde32s;
|
||||
|
||||
#pragma pack(pop)
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* __cdecl */
|
||||
unsigned int hde32_disasm(const void *code, hde32s *hs);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _HDE32_H_ */
|
||||
103
EFI/OC/Kexts/Lilu.kext/Contents/Resources/Headers/hde64.h
Normal file
103
EFI/OC/Kexts/Lilu.kext/Contents/Resources/Headers/hde64.h
Normal file
@@ -0,0 +1,103 @@
|
||||
/*
|
||||
* Hacker Disassembler Engine 64
|
||||
* Copyright (c) 2008-2009, Vyacheslav Patkov.
|
||||
* All rights reserved.
|
||||
*
|
||||
* hde64.h: C/C++ header file
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef _HDE64_H_
|
||||
#define _HDE64_H_
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#define F_MODRM 0x00000001
|
||||
#define F_SIB 0x00000002
|
||||
#define F_IMM8 0x00000004
|
||||
#define F_IMM16 0x00000008
|
||||
#define F_IMM32 0x00000010
|
||||
#define F_IMM64 0x00000020
|
||||
#define F_DISP8 0x00000040
|
||||
#define F_DISP16 0x00000080
|
||||
#define F_DISP32 0x00000100
|
||||
#define F_RELATIVE 0x00000200
|
||||
#define F_ERROR 0x00001000
|
||||
#define F_ERROR_OPCODE 0x00002000
|
||||
#define F_ERROR_LENGTH 0x00004000
|
||||
#define F_ERROR_LOCK 0x00008000
|
||||
#define F_ERROR_OPERAND 0x00010000
|
||||
#define F_PREFIX_REPNZ 0x01000000
|
||||
#define F_PREFIX_REPX 0x02000000
|
||||
#define F_PREFIX_REP 0x03000000
|
||||
#define F_PREFIX_66 0x04000000
|
||||
#define F_PREFIX_67 0x08000000
|
||||
#define F_PREFIX_LOCK 0x10000000
|
||||
#define F_PREFIX_SEG 0x20000000
|
||||
#define F_PREFIX_REX 0x40000000
|
||||
#define F_PREFIX_ANY 0x7f000000
|
||||
|
||||
#define PREFIX_SEGMENT_CS 0x2e
|
||||
#define PREFIX_SEGMENT_SS 0x36
|
||||
#define PREFIX_SEGMENT_DS 0x3e
|
||||
#define PREFIX_SEGMENT_ES 0x26
|
||||
#define PREFIX_SEGMENT_FS 0x64
|
||||
#define PREFIX_SEGMENT_GS 0x65
|
||||
#define PREFIX_LOCK 0xf0
|
||||
#define PREFIX_REPNZ 0xf2
|
||||
#define PREFIX_REPX 0xf3
|
||||
#define PREFIX_OPERAND_SIZE 0x66
|
||||
#define PREFIX_ADDRESS_SIZE 0x67
|
||||
|
||||
#pragma pack(push,1)
|
||||
|
||||
typedef struct {
|
||||
uint8_t len;
|
||||
uint8_t p_rep;
|
||||
uint8_t p_lock;
|
||||
uint8_t p_seg;
|
||||
uint8_t p_66;
|
||||
uint8_t p_67;
|
||||
uint8_t rex;
|
||||
uint8_t rex_w;
|
||||
uint8_t rex_r;
|
||||
uint8_t rex_x;
|
||||
uint8_t rex_b;
|
||||
uint8_t opcode;
|
||||
uint8_t opcode2;
|
||||
uint8_t modrm;
|
||||
uint8_t modrm_mod;
|
||||
uint8_t modrm_reg;
|
||||
uint8_t modrm_rm;
|
||||
uint8_t sib;
|
||||
uint8_t sib_scale;
|
||||
uint8_t sib_index;
|
||||
uint8_t sib_base;
|
||||
union {
|
||||
uint8_t imm8;
|
||||
uint16_t imm16;
|
||||
uint32_t imm32;
|
||||
uint64_t imm64;
|
||||
} imm;
|
||||
union {
|
||||
uint8_t disp8;
|
||||
uint16_t disp16;
|
||||
uint32_t disp32;
|
||||
} disp;
|
||||
uint32_t flags;
|
||||
} hde64s;
|
||||
|
||||
#pragma pack(pop)
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Note, code should point to at least 32 valid bytes. */
|
||||
unsigned int hde64_disasm(const void *code, hde64s *hs);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _HDE64_H_ */
|
||||
382
EFI/OC/Kexts/Lilu.kext/Contents/Resources/Headers/kern_api.hpp
Normal file
382
EFI/OC/Kexts/Lilu.kext/Contents/Resources/Headers/kern_api.hpp
Normal file
@@ -0,0 +1,382 @@
|
||||
//
|
||||
// kern_api.hpp
|
||||
// Lilu
|
||||
//
|
||||
// Copyright © 2016-2017 vit9696. All rights reserved.
|
||||
//
|
||||
|
||||
#ifndef kern_api_h
|
||||
#define kern_api_h
|
||||
|
||||
#include <Headers/kern_config.hpp>
|
||||
#include <Headers/kern_patcher.hpp>
|
||||
#include <Headers/kern_user.hpp>
|
||||
#include <Headers/kern_util.hpp>
|
||||
|
||||
#include <stdint.h>
|
||||
#include <sys/types.h>
|
||||
#include <libkern/OSAtomic.h>
|
||||
#include <Availability.h>
|
||||
|
||||
#ifndef __ACIDANTHERA_MAC_SDK
|
||||
#error "This kext SDK is unsupported. Download from https://github.com/acidanthera/MacKernelSDK"
|
||||
#endif
|
||||
|
||||
class LiluAPI {
|
||||
public:
|
||||
/**
|
||||
* Initialise lilu api
|
||||
*/
|
||||
void init();
|
||||
|
||||
/**
|
||||
* Deinitialise lilu api
|
||||
*/
|
||||
void deinit();
|
||||
|
||||
/**
|
||||
* Errors returned by functions
|
||||
*/
|
||||
enum class Error {
|
||||
NoError,
|
||||
LockError,
|
||||
MemoryError,
|
||||
UnsupportedFeature,
|
||||
IncompatibleOS,
|
||||
Disabled,
|
||||
TooLate,
|
||||
Offline
|
||||
};
|
||||
|
||||
/**
|
||||
* Minimal API version that guarantees forward ABI compatibility
|
||||
* Present due to lack of OSBundleCompatibleVersion at kext injection
|
||||
*/
|
||||
static constexpr size_t CompatibilityVersion {parseModuleVersion("1.2.0")};
|
||||
|
||||
/**
|
||||
* Obtains api access by holding a lock, which is required when accessing out of the main context
|
||||
*
|
||||
* @param version api compatibility version
|
||||
* @param check do not wait on the lock but return Error::LockError on failure
|
||||
*
|
||||
* @return Error::NoError on success
|
||||
*/
|
||||
EXPORT Error requestAccess(size_t version=CompatibilityVersion, bool check=false);
|
||||
|
||||
/**
|
||||
* Releases api lock
|
||||
*
|
||||
* @return Error::NoError on success
|
||||
*/
|
||||
EXPORT Error releaseAccess();
|
||||
|
||||
/**
|
||||
* You are supposed declare that your plugins work in at least one of these modes
|
||||
* It is assumed that single user mode is equal to normal, because it is generally
|
||||
* used to continue the load of a complete OS, and by default Lilu itself ignores it.
|
||||
*/
|
||||
enum RunningMode : uint32_t {
|
||||
RunningNormal = 1,
|
||||
AllowNormal = RunningNormal,
|
||||
RunningInstallerRecovery = 2,
|
||||
AllowInstallerRecovery = RunningInstallerRecovery,
|
||||
RunningSafeMode = 4,
|
||||
AllowSafeMode = RunningSafeMode
|
||||
};
|
||||
|
||||
/**
|
||||
* Obtain current run mode similarly to requirements
|
||||
*
|
||||
* @return run mode mask (RunningMode)
|
||||
*/
|
||||
inline uint32_t getRunMode() {
|
||||
return currentRunMode;
|
||||
}
|
||||
|
||||
/**
|
||||
* Decides whether you are eligible to continue
|
||||
*
|
||||
* @param product product name
|
||||
* @param version product version
|
||||
* @param runmode bitmask of allowed enviornments
|
||||
* @param disableArg pointer to disabling boot arguments array
|
||||
* @param disableArgNum number of disabling boot arguments
|
||||
* @param debugArg pointer to debug boot arguments array
|
||||
* @param debugArgNum number of debug boot arguments
|
||||
* @param betaArg pointer to beta boot arguments array
|
||||
* @param betaArgNum number of beta boot arguments
|
||||
* @param min minimal required kernel version
|
||||
* @param max maximum supported kernel version
|
||||
* @param printDebug returns debug printing status (based on debugArg)
|
||||
*
|
||||
* @return Error::NoError on success
|
||||
*/
|
||||
EXPORT Error shouldLoad(const char *product, size_t version, uint32_t runmode, const char **disableArg, size_t disableArgNum, const char **debugArg, size_t debugArgNum, const char **betaArg, size_t betaArgNum, KernelVersion min, KernelVersion max, bool &printDebug);
|
||||
|
||||
/**
|
||||
* Kernel patcher loaded callback
|
||||
*
|
||||
* @param user user provided pointer at registering
|
||||
* @param patcher kernel patcher instance
|
||||
*/
|
||||
using t_patcherLoaded = void (*)(void *user, KernelPatcher &patcher);
|
||||
|
||||
/**
|
||||
* Registers custom provided callbacks for later invocation on kernel patcher initialisation
|
||||
*
|
||||
* @param callback your callback function
|
||||
* @param user your pointer that will be passed to the callback function
|
||||
*
|
||||
* @return Error::NoError on success
|
||||
*/
|
||||
EXPORT Error onPatcherLoad(t_patcherLoaded callback, void *user=nullptr);
|
||||
|
||||
/**
|
||||
* Registers custom provided callbacks for later invocation on kernel patcher initialisation
|
||||
* Enforced version, which panics on registration failure (assuming your code cannot continue otherwise)
|
||||
*
|
||||
* @param callback your callback function
|
||||
* @param user your pointer that will be passed to the callback function
|
||||
*/
|
||||
inline void onPatcherLoadForce(t_patcherLoaded callback, void *user=nullptr) {
|
||||
auto err = onPatcherLoad(callback, user);
|
||||
if (err != Error::NoError)
|
||||
PANIC("api", "onPatcherLoad failed with code %d", err);
|
||||
}
|
||||
|
||||
/**
|
||||
* Kext loaded callback
|
||||
* Note that you will get notified of all the requested kexts for speed reasons
|
||||
*
|
||||
* @param user user provided pointer at registering
|
||||
* @param patcher kernel patcher instance
|
||||
* @param id loaded kinfo id
|
||||
* @param slide loaded slide
|
||||
* @param size loaded memory size
|
||||
*/
|
||||
using t_kextLoaded = void (*)(void *user, KernelPatcher &patcher, size_t id, mach_vm_address_t slide, size_t size);
|
||||
|
||||
/**
|
||||
* Registers custom provided callbacks for later invocation on kext load
|
||||
*
|
||||
* @param infos your kext list (make sure to point to const memory)
|
||||
* @param num number of provided kext entries
|
||||
* @param callback your callback function (optional)
|
||||
* @param user your pointer that will be passed to the callback function (optional)
|
||||
*
|
||||
* @return Error::NoError on success
|
||||
*/
|
||||
EXPORT Error onKextLoad(KernelPatcher::KextInfo *infos, size_t num=1, t_kextLoaded callback=nullptr, void *user=nullptr);
|
||||
|
||||
/**
|
||||
* Registers custom provided callbacks for later invocation on kext load
|
||||
* Enforced version, which panics on registration failure (assuming your code cannot continue otherwise)
|
||||
*
|
||||
* @param infos your kext list (make sure to point to const memory)
|
||||
* @param num number of provided kext entries
|
||||
* @param callback your callback function (optional)
|
||||
* @param user your pointer that will be passed to the callback function (optional)
|
||||
*/
|
||||
inline void onKextLoadForce(KernelPatcher::KextInfo *infos, size_t num=1, t_kextLoaded callback=nullptr, void *user=nullptr) {
|
||||
auto err = onKextLoad(infos, num, callback, user);
|
||||
if (err != Error::NoError)
|
||||
PANIC("api", "onKextLoad failed with code %d", err);
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers custom provided callbacks for later invocation on binary load
|
||||
*
|
||||
* @param infos your binary list (make sure to point to const memory)
|
||||
* @param num number of provided binary entries
|
||||
* @param callback your callback function (could be null)
|
||||
* @param user your pointer that will be passed to the callback function
|
||||
* @param mods optional mod list (make sure to point to const memory)
|
||||
* @param modnum number of provided mod entries
|
||||
*
|
||||
* @return Error::NoError on success
|
||||
*/
|
||||
EXPORT Error onProcLoad(UserPatcher::ProcInfo *infos, size_t num=1, UserPatcher::t_BinaryLoaded callback=nullptr, void *user=nullptr, UserPatcher::BinaryModInfo *mods=nullptr, size_t modnum=0);
|
||||
|
||||
/**
|
||||
* Registers custom provided callbacks for later invocation on binary load
|
||||
* Enforced version, which panics on registration failure (assuming your code cannot continue otherwise)
|
||||
*
|
||||
* @param infos your binary list (make sure to point to const memory)
|
||||
* @param num number of provided binary entries
|
||||
* @param callback your callback function (could be null)
|
||||
* @param user your pointer that will be passed to the callback function
|
||||
* @param mods optional mod list (make sure to point to const memory)
|
||||
* @param modnum number of provided mod entries
|
||||
*/
|
||||
inline void onProcLoadForce(UserPatcher::ProcInfo *infos, size_t num=1, UserPatcher::t_BinaryLoaded callback=nullptr, void *user=nullptr, UserPatcher::BinaryModInfo *mods=nullptr, size_t modnum=0) {
|
||||
auto err = onProcLoad(infos, num, callback, user, mods, modnum);
|
||||
if (err != Error::NoError)
|
||||
PANIC("api", "onProcLoad failed with code %d", err);
|
||||
}
|
||||
|
||||
/**
|
||||
* Kext loaded callback
|
||||
* Note that you will get notified of all the requested kexts for speed reasons
|
||||
*
|
||||
* @param user user provided pointer at registering
|
||||
* @param task task
|
||||
* @param entitlement loaded kinfo id
|
||||
* @param original original entitlement value
|
||||
*/
|
||||
using t_entitlementRequested = void (*)(void *user, task_t task, const char *entitlement, OSObject *&original);
|
||||
|
||||
/**
|
||||
* Registers custom provided callbacks for later invocation on entitlement registration
|
||||
*
|
||||
* @param callback your callback function
|
||||
* @param user your pointer that will be passed to the callback function
|
||||
*
|
||||
* @return Error::NoError on success
|
||||
*/
|
||||
EXPORT Error onEntitlementRequest(t_entitlementRequested callback, void *user=nullptr);
|
||||
|
||||
/**
|
||||
* Registers custom provided callbacks for later invocation on entitlement registration
|
||||
* Enforced version, which panics on registration failure (assuming your code cannot continue otherwise)
|
||||
*
|
||||
* @param callback your callback function
|
||||
* @param user your pointer that will be passed to the callback function
|
||||
*/
|
||||
inline void onEntitlementRequestForce(t_entitlementRequested callback, void *user=nullptr) {
|
||||
auto err = onEntitlementRequest(callback, user);
|
||||
if (err != Error::NoError)
|
||||
PANIC("api", "onEntitlementRequest failed with code %d", err);
|
||||
}
|
||||
|
||||
/**
|
||||
* Complete plugin registration and perform regulatory actions
|
||||
*/
|
||||
void finaliseRequests();
|
||||
|
||||
/**
|
||||
* Processes all the registered patcher load callbacks
|
||||
*
|
||||
* @param patcher kernel patcher instance
|
||||
*/
|
||||
void processPatcherLoadCallbacks(KernelPatcher &patcher);
|
||||
|
||||
/**
|
||||
* Processes all the registered kext load callbacks
|
||||
*
|
||||
* @param patcher kernel patcher instance
|
||||
* @param id loaded kinfo id
|
||||
* @param slide loaded slide
|
||||
* @param size loaded memory size
|
||||
* @param reloadable kinfo could be unloaded
|
||||
*/
|
||||
void processKextLoadCallbacks(KernelPatcher &patcher, size_t id, mach_vm_address_t slide, size_t size, bool reloadable);
|
||||
|
||||
/**
|
||||
* Processes all the registered user patcher load callbacks
|
||||
*
|
||||
* @param patcher user patcher instance
|
||||
*/
|
||||
void processUserLoadCallbacks(UserPatcher &patcher);
|
||||
|
||||
/**
|
||||
* Processes all the registered binary load callbacks
|
||||
*
|
||||
* @param patcher kernel patcher instance
|
||||
* @param map process image vm_map
|
||||
* @param path path to the binary absolute or relative
|
||||
* @param len path length excluding null terminator
|
||||
*/
|
||||
void processBinaryLoadCallbacks(UserPatcher &patcher, vm_map_t map, const char *path, size_t len);
|
||||
|
||||
/**
|
||||
* Activates patchers
|
||||
*
|
||||
* @param kpatcher kernel patcher instance
|
||||
* @param upatcher user patcher instance
|
||||
*/
|
||||
void activate(KernelPatcher &kpatcher, UserPatcher &upatcher);
|
||||
|
||||
private:
|
||||
|
||||
/**
|
||||
* Api lock
|
||||
*/
|
||||
IOLock *access {nullptr};
|
||||
|
||||
/**
|
||||
* Defines current running modes
|
||||
*/
|
||||
uint32_t currentRunMode {};
|
||||
|
||||
/**
|
||||
* No longer accept any requests
|
||||
*/
|
||||
bool apiRequestsOver {false};
|
||||
|
||||
/**
|
||||
* Stores call function and user pointer
|
||||
*/
|
||||
template <typename T, typename Y=void *>
|
||||
using stored_pair = ppair<T, Y>;
|
||||
|
||||
/**
|
||||
* Stores multiple callbacks
|
||||
*/
|
||||
template <typename T, typename Y=void *>
|
||||
using stored_vector = evector<stored_pair<T, Y> *, stored_pair<T, Y>::deleter>;
|
||||
|
||||
/**
|
||||
* List of patcher callbacks
|
||||
*/
|
||||
stored_vector<t_patcherLoaded> patcherLoadedCallbacks;
|
||||
|
||||
/**
|
||||
* List of kext callbacks
|
||||
*/
|
||||
stored_vector<t_kextLoaded> kextLoadedCallbacks;
|
||||
|
||||
/**
|
||||
* List of binary callbacks
|
||||
*/
|
||||
stored_vector<UserPatcher::t_BinaryLoaded> binaryLoadedCallbacks;
|
||||
|
||||
/**
|
||||
* List of entitlement callbacks
|
||||
*/
|
||||
stored_vector<t_entitlementRequested> entitlementRequestedCallbacks;
|
||||
|
||||
/**
|
||||
* List of processed kexts
|
||||
*/
|
||||
stored_vector<KernelPatcher::KextInfo *, size_t> storedKexts;
|
||||
|
||||
/**
|
||||
* List of processed procs
|
||||
*/
|
||||
evector<UserPatcher::ProcInfo *> storedProcs;
|
||||
|
||||
/**
|
||||
* List of processed binary mods
|
||||
*/
|
||||
evector<UserPatcher::BinaryModInfo *> storedBinaryMods;
|
||||
|
||||
/**
|
||||
* Copy client entitlement type (see IOUserClient)
|
||||
*/
|
||||
using t_copyClientEntitlement = OSObject *(*)(task_t, const char *);
|
||||
|
||||
/**
|
||||
* Hooked entitlement copying method
|
||||
*/
|
||||
static OSObject *copyClientEntitlement(task_t task, const char *entitlement);
|
||||
|
||||
/**
|
||||
* Trampoline for original entitlement copying method
|
||||
*/
|
||||
t_copyClientEntitlement orgCopyClientEntitlement {nullptr};
|
||||
};
|
||||
|
||||
EXPORT extern LiluAPI lilu;
|
||||
|
||||
#endif /* kern_api_h */
|
||||
@@ -0,0 +1,42 @@
|
||||
//
|
||||
// kern_compat.hpp
|
||||
// Lilu
|
||||
//
|
||||
// Copyright © 2016-2017 vit9696. All rights reserved.
|
||||
//
|
||||
|
||||
#ifndef kern_compat_hpp
|
||||
#define kern_compat_hpp
|
||||
|
||||
#include <Headers/kern_config.hpp>
|
||||
#include <stdint.h>
|
||||
|
||||
// Legacy compatibility layer created to avoid 10.13 SDK macros
|
||||
// unsupported in older systems and improperly guarded due to
|
||||
// Availability.h header not being. Currently these macros
|
||||
// are left to avoid compilation errors.
|
||||
#define lilu_os_memcpy memcpy
|
||||
#define lilu_os_memmove memmove
|
||||
#define lilu_os_strncpy strncpy
|
||||
#define lilu_os_strncat strncat
|
||||
#define lilu_os_strlcat strlcat
|
||||
#define lilu_os_strlcpy strlcpy
|
||||
#define lilu_os_strcat strcat
|
||||
#define lilu_os_bcopy bcopy
|
||||
|
||||
// This may not be nice but will protect users from changes in KernInfo strcture.
|
||||
#ifndef LILU_DISABLE_BRACE_WARNINGS
|
||||
#pragma clang diagnostic error "-Wmissing-braces"
|
||||
#endif
|
||||
|
||||
#if defined(__i386__)
|
||||
#define lilu_strtou strtoul
|
||||
|
||||
#elif defined(__x86_64__)
|
||||
#define lilu_strtou strtouq
|
||||
|
||||
#else
|
||||
#error Unsupported arch.
|
||||
#endif
|
||||
|
||||
#endif /* kern_compat_hpp */
|
||||
@@ -0,0 +1,84 @@
|
||||
//
|
||||
// kern_compression.hpp
|
||||
// Lilu
|
||||
//
|
||||
// Copyright © 2016-2017 vit9696. All rights reserved.
|
||||
//
|
||||
|
||||
#ifndef kern_compression_hpp
|
||||
#define kern_compression_hpp
|
||||
|
||||
#include <Headers/kern_config.hpp>
|
||||
|
||||
#ifdef LILU_COMPRESSION_SUPPORT
|
||||
|
||||
#include <Headers/kern_util.hpp>
|
||||
#include <stdint.h>
|
||||
|
||||
namespace Compression {
|
||||
|
||||
/**
|
||||
* Compression constants and modes
|
||||
*/
|
||||
static constexpr uint32_t Magic {0x706D6F63}; //comp
|
||||
static constexpr uint32_t ModeLZVN {0x6E767A6C}; //lzvn
|
||||
static constexpr uint32_t ModeLZSS {0x73737A6C}; //lzss
|
||||
static constexpr uint32_t ModeZLIB {0x9C787A6C}; //zlib
|
||||
|
||||
/**
|
||||
* Compressed header structure
|
||||
*/
|
||||
struct Header {
|
||||
uint32_t magic;
|
||||
uint32_t compression;
|
||||
uint32_t hash; // adler32
|
||||
uint32_t decompressed;
|
||||
uint32_t compressed;
|
||||
uint32_t version;
|
||||
uint32_t padding[90];
|
||||
};
|
||||
|
||||
/**
|
||||
* Typed decompressing function (currently for lzvn, lzss, and zlib)
|
||||
*
|
||||
* @param compression compression type
|
||||
* @param dstlen decompression buffer size
|
||||
* @param src compressed data
|
||||
* @param srclen compressed data size
|
||||
* @param buffer preallocated buffer to use
|
||||
*
|
||||
* @return decompressed buffer (must be freeded by Buffer::deleter if not preallocated)
|
||||
*/
|
||||
EXPORT uint8_t *decompress(uint32_t compression, uint32_t dstlen, const uint8_t *src, uint32_t srclen, uint8_t *buffer=nullptr);
|
||||
|
||||
/**
|
||||
* Typed decompressing function (currently for lzvn, lzss, and zlib)
|
||||
*
|
||||
* @param compression compression type
|
||||
* @param dstlen decompression buffer size, actual decompressed size on success
|
||||
* @param src compressed data
|
||||
* @param srclen compressed data size
|
||||
* @param buffer preallocated buffer to use
|
||||
*
|
||||
* @return decompressed buffer (must be freeded by Buffer::deleter if not preallocated)
|
||||
*/
|
||||
EXPORT uint8_t *decompress(uint32_t compression, uint32_t *dstlen, const uint8_t *src, uint32_t srclen, uint8_t *buffer=nullptr);
|
||||
|
||||
/**
|
||||
* Typed compressing function (currently for lzss)
|
||||
*
|
||||
* @param compression compression type
|
||||
* @param dstlen maximum compression buffer size
|
||||
* @param src uncompressed data
|
||||
* @param srclen uncompressed data size
|
||||
* @param buffer preallocated buffer to use
|
||||
*
|
||||
* @return compressed buffer with its actual size in dstlen (must be freeded by Buffer::deleter if not preallocated)
|
||||
*/
|
||||
EXPORT uint8_t *compress(uint32_t compression, uint32_t &dstlen, const uint8_t *src, uint32_t srclen, uint8_t *buffer=nullptr);
|
||||
|
||||
}
|
||||
|
||||
#endif /* LILU_COMPRESSION_SUPPORT */
|
||||
|
||||
#endif /* kern_compression_hpp */
|
||||
@@ -0,0 +1,33 @@
|
||||
//
|
||||
// kern_config.hpp
|
||||
// Lilu
|
||||
//
|
||||
// Copyright © 2016-2017 vit9696. All rights reserved.
|
||||
//
|
||||
|
||||
#ifndef kern_config_hpp
|
||||
#define kern_config_hpp
|
||||
|
||||
/**
|
||||
* Enable kext patching support
|
||||
*/
|
||||
#define LILU_KEXTPATCH_SUPPORT 1
|
||||
|
||||
/**
|
||||
* Enable compression and decompression support
|
||||
*/
|
||||
#define LILU_COMPRESSION_SUPPORT 1
|
||||
|
||||
/**
|
||||
* Enable advanced disassembly API based on capstone
|
||||
*/
|
||||
// #define LILU_ADVANCED_DISASSEMBLY 1
|
||||
|
||||
/**
|
||||
* Specify custom initialisation code
|
||||
* Use these in plugins in Xcode Project Preprocessor Macros section.
|
||||
*/
|
||||
// #define LILU_CUSTOM_IOKIT_INIT 1
|
||||
// #define LILU_CUSTOM_KMOD_INIT 1
|
||||
|
||||
#endif /* kern_config_hpp */
|
||||
426
EFI/OC/Kexts/Lilu.kext/Contents/Resources/Headers/kern_cpu.hpp
Normal file
426
EFI/OC/Kexts/Lilu.kext/Contents/Resources/Headers/kern_cpu.hpp
Normal file
@@ -0,0 +1,426 @@
|
||||
//
|
||||
// kern_cpu.hpp
|
||||
// Lilu
|
||||
//
|
||||
// Copyright © 2018 vit9696. All rights reserved.
|
||||
//
|
||||
|
||||
#ifndef kern_cpu_h
|
||||
#define kern_cpu_h
|
||||
|
||||
#include <Headers/kern_config.hpp>
|
||||
#include <Headers/kern_iokit.hpp>
|
||||
#include <Headers/kern_util.hpp>
|
||||
|
||||
#include <IOKit/IOService.h>
|
||||
|
||||
/**
|
||||
* XNU CPU-related exports missing from headers
|
||||
*/
|
||||
extern "C" {
|
||||
int cpu_number(void);
|
||||
void mp_rendezvous_no_intrs(void (*action_func)(void *), void *arg);
|
||||
};
|
||||
|
||||
namespace CPUInfo {
|
||||
/**
|
||||
* Keep this in sync to XNU MAX_CPUS from osfmk/i386/mp.h
|
||||
*/
|
||||
static constexpr size_t MaxCpus {64};
|
||||
|
||||
/**
|
||||
* Contents of CPUID(1) eax register contents describing model version
|
||||
*/
|
||||
struct CpuVersion {
|
||||
uint32_t stepping : 4;
|
||||
uint32_t model : 4;
|
||||
uint32_t family : 4;
|
||||
uint32_t type : 2;
|
||||
uint32_t reserved1 : 2;
|
||||
uint32_t extendedModel : 4;
|
||||
uint32_t extendedFamily : 8;
|
||||
uint32_t reserved2 : 4;
|
||||
};
|
||||
|
||||
static_assert(sizeof(CpuVersion) == sizeof(uint32_t), "CpuVersion size mismatch!");
|
||||
|
||||
/**
|
||||
* Intel CPU models as returned by CPUID
|
||||
* The list is synchronised and updated with XNU source code (osfmk/i386/cpuid.h).
|
||||
* Names are altered to avoid conflicts just in case.
|
||||
* Last update: xnu-4903.221.2
|
||||
* Some details could be found on http://instlatx64.atw.hu and https://en.wikichip.org/wiki/64-bit_architecture#x86
|
||||
* Also: https://www.intel.com/content/dam/www/public/us/en/documents/sa00115-microcode-update-guidance.pdf
|
||||
*/
|
||||
enum CpuModel {
|
||||
CPU_MODEL_UNKNOWN = 0x00,
|
||||
CPU_MODEL_PENRYN = 0x17,
|
||||
CPU_MODEL_NEHALEM = 0x1A,
|
||||
CPU_MODEL_FIELDS = 0x1E, /* Lynnfield, Clarksfield */
|
||||
CPU_MODEL_DALES = 0x1F, /* Havendale, Auburndale */
|
||||
CPU_MODEL_NEHALEM_EX = 0x2E,
|
||||
CPU_MODEL_DALES_32NM = 0x25, /* Clarkdale, Arrandale */
|
||||
CPU_MODEL_WESTMERE = 0x2C, /* Gulftown, Westmere-EP/-WS */
|
||||
CPU_MODEL_WESTMERE_EX = 0x2F,
|
||||
CPU_MODEL_SANDYBRIDGE = 0x2A,
|
||||
CPU_MODEL_JAKETOWN = 0x2D,
|
||||
CPU_MODEL_IVYBRIDGE = 0x3A,
|
||||
CPU_MODEL_IVYBRIDGE_EP = 0x3E,
|
||||
CPU_MODEL_CRYSTALWELL = 0x46,
|
||||
CPU_MODEL_HASWELL = 0x3C,
|
||||
CPU_MODEL_HASWELL_EP = 0x3F,
|
||||
CPU_MODEL_HASWELL_ULT = 0x45,
|
||||
CPU_MODEL_BROADWELL = 0x3D,
|
||||
CPU_MODEL_BROADWELL_ULX = 0x3D,
|
||||
CPU_MODEL_BROADWELL_ULT = 0x3D,
|
||||
CPU_MODEL_BRYSTALWELL = 0x47,
|
||||
CPU_MODEL_SKYLAKE = 0x4E,
|
||||
CPU_MODEL_SKYLAKE_ULT = 0x4E,
|
||||
CPU_MODEL_SKYLAKE_ULX = 0x4E,
|
||||
CPU_MODEL_BROADWELL_EP = 0x4F,
|
||||
CPU_MODEL_SKYLAKE_DT = 0x5E,
|
||||
CPU_MODEL_SKYLAKE_W = 0x55,
|
||||
CPU_MODEL_KABYLAKE = 0x8E,
|
||||
CPU_MODEL_KABYLAKE_ULT = 0x8E,
|
||||
CPU_MODEL_KABYLAKE_ULX = 0x8E,
|
||||
CPU_MODEL_KABYLAKE_DT = 0x9E,
|
||||
CPU_MODEL_CANNONLAKE = 0x66,
|
||||
CPU_MODEL_ICELAKE_Y = 0x7D,
|
||||
CPU_MODEL_ICELAKE_U = 0x7E,
|
||||
CPU_MODEL_ICELAKE_SP = 0x9F, /* Some variation of Ice Lake */
|
||||
CPU_MODEL_COMETLAKE_S = 0xA5, /* desktop CometLake */
|
||||
CPU_MODEL_COMETLAKE_Y = 0xA5, /* aka 10th generation Amber Lake Y */
|
||||
CPU_MODEL_COMETLAKE_U = 0xA6,
|
||||
CPU_MODEL_ROCKETLAKE_S = 0xA7, /* desktop RocketLake */
|
||||
CPU_MODEL_TIGERLAKE_U = 0x8C,
|
||||
CPU_MODEL_ALDERLAKE_S = 0x97,
|
||||
CPU_MODEL_RAPTORLAKE_S = 0xB7, /* Raptor Lake B0 stepping */
|
||||
CPU_MODEL_RAPTORLAKE_HX = 0xBF, /* Raptor Lake C0 stepping */
|
||||
CPU_MODEL_ARROWLAKE_HX = 0xC5,
|
||||
CPU_MODEL_ARROWLAKE_S = 0xC6, /* desktop ArrowLake */
|
||||
CPU_MODEL_ARROWLAKE_U = 0xB5,
|
||||
};
|
||||
|
||||
/**
|
||||
* Known CPU vendors
|
||||
*/
|
||||
enum class CpuVendor {
|
||||
Unknown,
|
||||
AMD,
|
||||
Intel
|
||||
/* Add more processors here if needed */
|
||||
};
|
||||
|
||||
/**
|
||||
* Intel CPU generations (starting from 0)
|
||||
*/
|
||||
enum class CpuGeneration {
|
||||
Unknown,
|
||||
Penryn,
|
||||
Nehalem,
|
||||
Westmere,
|
||||
SandyBridge,
|
||||
IvyBridge,
|
||||
Haswell,
|
||||
Broadwell,
|
||||
Skylake,
|
||||
KabyLake,
|
||||
CoffeeLake,
|
||||
CannonLake,
|
||||
IceLake,
|
||||
CometLake,
|
||||
RocketLake,
|
||||
TigerLake,
|
||||
AlderLake,
|
||||
RaptorLake,
|
||||
ArrowLake,
|
||||
MaxGeneration
|
||||
};
|
||||
|
||||
/* Responses identification request with %eax 0 */
|
||||
/* AMD: "AuthenticAMD" */
|
||||
static constexpr uint32_t signature_AMD_ebx = 0x68747541;
|
||||
static constexpr uint32_t signature_AMD_edx = 0x69746e65;
|
||||
static constexpr uint32_t signature_AMD_ecx = 0x444d4163;
|
||||
/* CENTAUR: "CentaurHauls" */
|
||||
static constexpr uint32_t signature_CENTAUR_ebx = 0x746e6543;
|
||||
static constexpr uint32_t signature_CENTAUR_edx = 0x48727561;
|
||||
static constexpr uint32_t signature_CENTAUR_ecx = 0x736c7561;
|
||||
/* CYRIX: "CyrixInstead" */
|
||||
static constexpr uint32_t signature_CYRIX_ebx = 0x69727943;
|
||||
static constexpr uint32_t signature_CYRIX_edx = 0x736e4978;
|
||||
static constexpr uint32_t signature_CYRIX_ecx = 0x64616574;
|
||||
/* INTEL: "GenuineIntel" */
|
||||
static constexpr uint32_t signature_INTEL_ebx = 0x756e6547;
|
||||
static constexpr uint32_t signature_INTEL_edx = 0x49656e69;
|
||||
static constexpr uint32_t signature_INTEL_ecx = 0x6c65746e;
|
||||
/* TM1: "TransmetaCPU" */
|
||||
static constexpr uint32_t signature_TM1_ebx = 0x6e617254;
|
||||
static constexpr uint32_t signature_TM1_edx = 0x74656d73;
|
||||
static constexpr uint32_t signature_TM1_ecx = 0x55504361;
|
||||
/* TM2: "GenuineTMx86" */
|
||||
static constexpr uint32_t signature_TM2_ebx = 0x756e6547;
|
||||
static constexpr uint32_t signature_TM2_edx = 0x54656e69;
|
||||
static constexpr uint32_t signature_TM2_ecx = 0x3638784d;
|
||||
/* NSC: "Geode by NSC" */
|
||||
static constexpr uint32_t signature_NSC_ebx = 0x646f6547;
|
||||
static constexpr uint32_t signature_NSC_edx = 0x43534e20;
|
||||
static constexpr uint32_t signature_NSC_ecx = 0x79622065;
|
||||
/* NEXGEN: "NexGenDriven" */
|
||||
static constexpr uint32_t signature_NEXGEN_ebx = 0x4778654e;
|
||||
static constexpr uint32_t signature_NEXGEN_edx = 0x72446e65;
|
||||
static constexpr uint32_t signature_NEXGEN_ecx = 0x6e657669;
|
||||
/* RISE: "RiseRiseRise" */
|
||||
static constexpr uint32_t signature_RISE_ebx = 0x65736952;
|
||||
static constexpr uint32_t signature_RISE_edx = 0x65736952;
|
||||
static constexpr uint32_t signature_RISE_ecx = 0x65736952;
|
||||
/* SIS: "SiS SiS SiS " */
|
||||
static constexpr uint32_t signature_SIS_ebx = 0x20536953;
|
||||
static constexpr uint32_t signature_SIS_edx = 0x20536953;
|
||||
static constexpr uint32_t signature_SIS_ecx = 0x20536953;
|
||||
/* UMC: "UMC UMC UMC " */
|
||||
static constexpr uint32_t signature_UMC_ebx = 0x20434d55;
|
||||
static constexpr uint32_t signature_UMC_edx = 0x20434d55;
|
||||
static constexpr uint32_t signature_UMC_ecx = 0x20434d55;
|
||||
/* VIA: "VIA VIA VIA " */
|
||||
static constexpr uint32_t signature_VIA_ebx = 0x20414956;
|
||||
static constexpr uint32_t signature_VIA_edx = 0x20414956;
|
||||
static constexpr uint32_t signature_VIA_ecx = 0x20414956;
|
||||
/* VORTEX: "Vortex86 SoC" */
|
||||
static constexpr uint32_t signature_VORTEX_ebx = 0x74726f56;
|
||||
static constexpr uint32_t signature_VORTEX_edx = 0x36387865;
|
||||
static constexpr uint32_t signature_VORTEX_ecx = 0x436f5320;
|
||||
|
||||
/* Features in %ecx for leaf 1 */
|
||||
static constexpr uint32_t bit_SSE3 = 0x00000001;
|
||||
static constexpr uint32_t bit_PCLMULQDQ = 0x00000002;
|
||||
static constexpr uint32_t bit_DTES64 = 0x00000004;
|
||||
static constexpr uint32_t bit_MONITOR = 0x00000008;
|
||||
static constexpr uint32_t bit_DSCPL = 0x00000010;
|
||||
static constexpr uint32_t bit_VMX = 0x00000020;
|
||||
static constexpr uint32_t bit_SMX = 0x00000040;
|
||||
static constexpr uint32_t bit_EIST = 0x00000080;
|
||||
static constexpr uint32_t bit_TM2 = 0x00000100;
|
||||
static constexpr uint32_t bit_SSSE3 = 0x00000200;
|
||||
static constexpr uint32_t bit_CNXTID = 0x00000400;
|
||||
static constexpr uint32_t bit_FMA = 0x00001000;
|
||||
static constexpr uint32_t bit_CMPXCHG16B = 0x00002000;
|
||||
static constexpr uint32_t bit_xTPR = 0x00004000;
|
||||
static constexpr uint32_t bit_PDCM = 0x00008000;
|
||||
static constexpr uint32_t bit_PCID = 0x00020000;
|
||||
static constexpr uint32_t bit_DCA = 0x00040000;
|
||||
static constexpr uint32_t bit_SSE41 = 0x00080000;
|
||||
static constexpr uint32_t bit_SSE42 = 0x00100000;
|
||||
static constexpr uint32_t bit_x2APIC = 0x00200000;
|
||||
static constexpr uint32_t bit_MOVBE = 0x00400000;
|
||||
static constexpr uint32_t bit_POPCNT = 0x00800000;
|
||||
static constexpr uint32_t bit_TSCDeadline = 0x01000000;
|
||||
static constexpr uint32_t bit_AESNI = 0x02000000;
|
||||
static constexpr uint32_t bit_XSAVE = 0x04000000;
|
||||
static constexpr uint32_t bit_OSXSAVE = 0x08000000;
|
||||
static constexpr uint32_t bit_AVX = 0x10000000;
|
||||
static constexpr uint32_t bit_F16C = 0x20000000;
|
||||
static constexpr uint32_t bit_RDRND = 0x40000000;
|
||||
|
||||
/* Features in %edx for leaf 1 */
|
||||
static constexpr uint32_t bit_FPU = 0x00000001;
|
||||
static constexpr uint32_t bit_VME = 0x00000002;
|
||||
static constexpr uint32_t bit_DE = 0x00000004;
|
||||
static constexpr uint32_t bit_PSE = 0x00000008;
|
||||
static constexpr uint32_t bit_TSC = 0x00000010;
|
||||
static constexpr uint32_t bit_MSR = 0x00000020;
|
||||
static constexpr uint32_t bit_PAE = 0x00000040;
|
||||
static constexpr uint32_t bit_MCE = 0x00000080;
|
||||
static constexpr uint32_t bit_CX8 = 0x00000100;
|
||||
static constexpr uint32_t bit_APIC = 0x00000200;
|
||||
static constexpr uint32_t bit_SEP = 0x00000800;
|
||||
static constexpr uint32_t bit_MTRR = 0x00001000;
|
||||
static constexpr uint32_t bit_PGE = 0x00002000;
|
||||
static constexpr uint32_t bit_MCA = 0x00004000;
|
||||
static constexpr uint32_t bit_CMOV = 0x00008000;
|
||||
static constexpr uint32_t bit_PAT = 0x00010000;
|
||||
static constexpr uint32_t bit_PSE36 = 0x00020000;
|
||||
static constexpr uint32_t bit_PSN = 0x00040000;
|
||||
static constexpr uint32_t bit_CLFSH = 0x00080000;
|
||||
static constexpr uint32_t bit_DS = 0x00200000;
|
||||
static constexpr uint32_t bit_ACPI = 0x00400000;
|
||||
static constexpr uint32_t bit_MMX = 0x00800000;
|
||||
static constexpr uint32_t bit_FXSR = 0x01000000;
|
||||
static constexpr uint32_t bit_SSE = 0x02000000;
|
||||
static constexpr uint32_t bit_SSE2 = 0x04000000;
|
||||
static constexpr uint32_t bit_SS = 0x08000000;
|
||||
static constexpr uint32_t bit_HTT = 0x10000000;
|
||||
static constexpr uint32_t bit_TM = 0x20000000;
|
||||
static constexpr uint32_t bit_PBE = 0x80000000;
|
||||
|
||||
/* Features in %ebx for leaf 7 sub-leaf 0 */
|
||||
static constexpr uint32_t bit_FSGSBASE = 0x00000001;
|
||||
static constexpr uint32_t bit_SGX = 0x00000004;
|
||||
static constexpr uint32_t bit_BMI = 0x00000008;
|
||||
static constexpr uint32_t bit_HLE = 0x00000010;
|
||||
static constexpr uint32_t bit_AVX2 = 0x00000020;
|
||||
static constexpr uint32_t bit_SMEP = 0x00000080;
|
||||
static constexpr uint32_t bit_BMI2 = 0x00000100;
|
||||
static constexpr uint32_t bit_ENH_MOVSB = 0x00000200;
|
||||
static constexpr uint32_t bit_RTM = 0x00000800;
|
||||
static constexpr uint32_t bit_MPX = 0x00004000;
|
||||
static constexpr uint32_t bit_AVX512F = 0x00010000;
|
||||
static constexpr uint32_t bit_AVX512DQ = 0x00020000;
|
||||
static constexpr uint32_t bit_RDSEED = 0x00040000;
|
||||
static constexpr uint32_t bit_ADX = 0x00080000;
|
||||
static constexpr uint32_t bit_AVX512IFMA = 0x00200000;
|
||||
static constexpr uint32_t bit_CLFLUSHOPT = 0x00800000;
|
||||
static constexpr uint32_t bit_CLWB = 0x01000000;
|
||||
static constexpr uint32_t bit_AVX512PF = 0x04000000;
|
||||
static constexpr uint32_t bit_AVX51SER = 0x08000000;
|
||||
static constexpr uint32_t bit_AVX512CD = 0x10000000;
|
||||
static constexpr uint32_t bit_SHA = 0x20000000;
|
||||
static constexpr uint32_t bit_AVX512BW = 0x40000000;
|
||||
static constexpr uint32_t bit_AVX512VL = 0x80000000;
|
||||
|
||||
/* Features in %ecx for leaf 7 sub-leaf 0 */
|
||||
static constexpr uint32_t bit_PREFTCHWT1 = 0x00000001;
|
||||
static constexpr uint32_t bit_AVX512VBMI = 0x00000002;
|
||||
static constexpr uint32_t bit_PKU = 0x00000004;
|
||||
static constexpr uint32_t bit_OSPKE = 0x00000010;
|
||||
static constexpr uint32_t bit_AVX512VPOPCNTDQ = 0x00004000;
|
||||
static constexpr uint32_t bit_RDPID = 0x00400000;
|
||||
|
||||
/* Features in %edx for leaf 7 sub-leaf 0 */
|
||||
static constexpr uint32_t bit_AVX5124VNNIW = 0x00000004;
|
||||
static constexpr uint32_t bit_AVX5124FMAPS = 0x00000008;
|
||||
|
||||
/* Features in %eax for leaf 13 sub-leaf 1 */
|
||||
static constexpr uint32_t bit_XSAVEOPT = 0x00000001;
|
||||
static constexpr uint32_t bit_XSAVEC = 0x00000002;
|
||||
static constexpr uint32_t bit_XSAVES = 0x00000008;
|
||||
|
||||
/* Features in %ecx for leaf = 0x80000001 */;
|
||||
static constexpr uint32_t bit_LAHF_LM = 0x00000001;
|
||||
static constexpr uint32_t bit_ABM = 0x00000020;
|
||||
static constexpr uint32_t bit_SSE4a = 0x00000040;
|
||||
static constexpr uint32_t bit_PRFCHW = 0x00000100;
|
||||
static constexpr uint32_t bit_XOP = 0x00000800;
|
||||
static constexpr uint32_t bit_LWP = 0x00008000;
|
||||
static constexpr uint32_t bit_FMA4 = 0x00010000;
|
||||
static constexpr uint32_t bit_TBM = 0x00200000;
|
||||
static constexpr uint32_t bit_MWAITX = 0x20000000;
|
||||
|
||||
/* Features in %edx for leaf = 0x80000001 */;
|
||||
static constexpr uint32_t bit_MMXEXT = 0x00400000;
|
||||
static constexpr uint32_t bit_LM = 0x20000000;
|
||||
static constexpr uint32_t bit_3DNOWP = 0x40000000;
|
||||
static constexpr uint32_t bit_3DNOW = 0x80000000;
|
||||
|
||||
/* Features in %ebx for leaf = 0x80000001 */;
|
||||
static constexpr uint32_t bit_CLZERO = 0x00000001;
|
||||
|
||||
/**
|
||||
* Reads CPU information and other data.
|
||||
*/
|
||||
void init();
|
||||
|
||||
/**
|
||||
* Installed CPU information mapping
|
||||
*/
|
||||
struct CpuTopology {
|
||||
/**
|
||||
* Number of physical processors installed
|
||||
*/
|
||||
uint8_t packageCount {0};
|
||||
|
||||
/**
|
||||
* Number of physical cores per package
|
||||
*/
|
||||
uint8_t physicalCount[MaxCpus] {};
|
||||
|
||||
/**
|
||||
* Number of logical cores per package
|
||||
*/
|
||||
uint8_t logicalCount[MaxCpus] {};
|
||||
|
||||
/**
|
||||
* Total number of physical cores
|
||||
*/
|
||||
inline uint8_t totalPhysical() {
|
||||
uint8_t count = physicalCount[0];
|
||||
for (uint8_t i = 1; i < packageCount; i++)
|
||||
count += physicalCount[i];
|
||||
return count;
|
||||
}
|
||||
|
||||
/**
|
||||
* Total number of logical cores
|
||||
*/
|
||||
inline uint8_t totalLogical() {
|
||||
uint8_t count = logicalCount[0];
|
||||
for (uint8_t i = 1; i < packageCount; i++)
|
||||
count += logicalCount[i];
|
||||
return count;
|
||||
}
|
||||
|
||||
/**
|
||||
* Mapping of cpu_number() to CPU package from 0 to packageCount
|
||||
*/
|
||||
uint8_t numberToPackage[MaxCpus] {};
|
||||
|
||||
/**
|
||||
* Mapping of cpu_number() to physical core from 0 to physicalCount in package
|
||||
*/
|
||||
uint8_t numberToPhysical[MaxCpus] {};
|
||||
|
||||
/**
|
||||
* Mapping of cpu_number() to physical cores from 0 to totalPhysical.
|
||||
*/
|
||||
inline uint8_t numberToPhysicalUnique(uint8_t i) {
|
||||
uint8_t num = 0;
|
||||
uint8_t package = numberToPackage[i];
|
||||
for (uint8_t i = 0; i < package; i++)
|
||||
num += physicalCount[i];
|
||||
return num + numberToPhysical[i];
|
||||
}
|
||||
|
||||
/**
|
||||
* Mapping of cpu_number() to logical thread from 0 to logicalCount in package
|
||||
* Note, that the list is sorted, and the first physicalCount logical threads
|
||||
* correspond to their corresponding physical cores.
|
||||
*/
|
||||
uint8_t numberToLogical[MaxCpus] {};
|
||||
};
|
||||
|
||||
/**
|
||||
* Get running CPU generation.
|
||||
*
|
||||
* @param ofamily a pointer to store CPU family in
|
||||
* @param omodel a pointer to store CPU model in
|
||||
* @param ostepping a pointer to store CPU stepping in
|
||||
*
|
||||
* @return detected Intel CPU generation
|
||||
*/
|
||||
EXPORT CpuGeneration getGeneration(uint32_t *ofamily=nullptr, uint32_t *omodel=nullptr, uint32_t *ostepping=nullptr) DEPRECATE("Use BaseDeviceInfo");;
|
||||
|
||||
/**
|
||||
* Obtain CPU topology.
|
||||
*
|
||||
* @param topology parsed cpu topology, must be passed zeroed.
|
||||
*
|
||||
* @return true on success
|
||||
*/
|
||||
EXPORT bool getCpuTopology(CpuTopology &topology);
|
||||
|
||||
/**
|
||||
* Obtain cpuid registers
|
||||
*
|
||||
* @param no cpuid number
|
||||
* @param count cpuid count
|
||||
* @param a eax output pointer (optional)
|
||||
* @param b ebx output pointer (optional)
|
||||
* @param c ecx output pointer (optional)
|
||||
* @param d edx output pointer (optional)
|
||||
*
|
||||
* @return true if supported
|
||||
*/
|
||||
EXPORT bool getCpuid(uint32_t no, uint32_t count, uint32_t *a, uint32_t *b=nullptr, uint32_t *c=nullptr, uint32_t *d=nullptr);
|
||||
}
|
||||
|
||||
#endif /* kern_cpu_h */
|
||||
@@ -0,0 +1,95 @@
|
||||
//
|
||||
// kern_crypto.hpp
|
||||
// Lilu
|
||||
//
|
||||
// Copyright © 2017 vit9696. All rights reserved.
|
||||
//
|
||||
|
||||
#ifndef kern_crypto_h
|
||||
#define kern_crypto_h
|
||||
|
||||
#include <Headers/kern_config.hpp>
|
||||
#include <Headers/kern_util.hpp>
|
||||
#include <stdint.h>
|
||||
|
||||
namespace Crypto {
|
||||
/**
|
||||
* Currently this is equal to both key size and block size
|
||||
*/
|
||||
static constexpr uint32_t BlockSize = 16;
|
||||
|
||||
/**
|
||||
* Currently this is guaranteed hash size
|
||||
*/
|
||||
static constexpr uint32_t MinDigestSize = 32;
|
||||
|
||||
/**
|
||||
* Encrypted data format
|
||||
*/
|
||||
struct PACKED Encrypted {
|
||||
uint8_t iv[BlockSize]; // Initialisation vector
|
||||
struct PACKED Data {
|
||||
uint32_t size; // Actual encrypted buffer size
|
||||
uint8_t buf[BlockSize - sizeof(uint32_t)]; // Encrypted buffer >= BlockSize
|
||||
};
|
||||
|
||||
union {
|
||||
Data enc;
|
||||
uint8_t buf[BlockSize];
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
* Securely erase memory buffer
|
||||
* Based off cc_clear from corecrypto (src/cc_clear.c)
|
||||
*
|
||||
* @param len buffer length
|
||||
* @param dst buffer pointer
|
||||
*/
|
||||
inline void zeroMemory(size_t len, void *dst) {
|
||||
auto vptr = reinterpret_cast<volatile char *>(dst);
|
||||
while (len--)
|
||||
*vptr++ = '\0';
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates cryptographically secure encryption key (from /dev/random)
|
||||
*
|
||||
* @return generated key of at least BlockSize bits long (must be freeded by Buffer::deleter) or nullptr
|
||||
*/
|
||||
EXPORT uint8_t *genUniqueKey(uint32_t size=BlockSize);
|
||||
|
||||
/**
|
||||
* Encrypts data of specified size and stores in Encrypted format
|
||||
*
|
||||
* @param key encryption key returned by genUniqueKey
|
||||
* @param src source data
|
||||
* @param size data size, encrypted size is returned on success
|
||||
*
|
||||
* @return encrypted data in Encrypted format (must be freed by Buffer::deleter) or nullptr
|
||||
*/
|
||||
EXPORT uint8_t *encrypt(const uint8_t *key, const uint8_t *src, uint32_t &size);
|
||||
|
||||
/**
|
||||
* Decrypts data of specified size stored in Encrypted format
|
||||
*
|
||||
* @param key encryption key returned by genUniqueKey
|
||||
* @param src source data
|
||||
* @param size data size, decrypted size is returned on success
|
||||
*
|
||||
* @return decrypted data (must be freed by Buffer::deleter) or nullptr
|
||||
*/
|
||||
EXPORT uint8_t *decrypt(const uint8_t *key, const uint8_t *src, uint32_t &size);
|
||||
|
||||
/**
|
||||
* Calculate digest of given size
|
||||
*
|
||||
* @param src source data
|
||||
* @param size data size
|
||||
*
|
||||
* @return digest hash of at least MinDigestSize bytes (must be freeded by Buffer::deleter) or nullptr
|
||||
*/
|
||||
EXPORT uint8_t *hash(const uint8_t *src, uint32_t size);
|
||||
}
|
||||
|
||||
#endif /* kern_crypto_h */
|
||||
@@ -0,0 +1,485 @@
|
||||
//
|
||||
// kern_devinfo.hpp
|
||||
// Lilu
|
||||
//
|
||||
// Copyright © 2018-2020 vit9696. All rights reserved.
|
||||
//
|
||||
|
||||
#ifndef kern_devinfo_h
|
||||
#define kern_devinfo_h
|
||||
|
||||
#include <Headers/kern_config.hpp>
|
||||
#include <Headers/kern_cpu.hpp>
|
||||
#include <Headers/kern_iokit.hpp>
|
||||
#include <Headers/kern_util.hpp>
|
||||
#include <IOKit/IOService.h>
|
||||
|
||||
/**
|
||||
* Obtain installed devices split into categories.
|
||||
* Should be used from onPatcherLoad and onwards.
|
||||
*/
|
||||
class DeviceInfo {
|
||||
/**
|
||||
* Updates reportedLayoutId
|
||||
*/
|
||||
void updateLayoutId();
|
||||
|
||||
/**
|
||||
* Updates reportedFramebufferId
|
||||
*/
|
||||
void updateFramebufferId();
|
||||
|
||||
/**
|
||||
* Obtains devices from PCI root
|
||||
*
|
||||
* @param pciRoot PCI root instance (commonly PCI0@0 device)
|
||||
*/
|
||||
void grabDevicesFromPciRoot(IORegistryEntry *pciRoot);
|
||||
|
||||
/**
|
||||
* Await for PCI device publishing in IODeviceTree plane
|
||||
*
|
||||
* @param obj wait for (PCI) object publishing
|
||||
*/
|
||||
void awaitPublishing(IORegistryEntry *obj);
|
||||
|
||||
/**
|
||||
* Checks if an ATIAMD object is an AMD iGPU
|
||||
*
|
||||
* @param obj Object to run the check on.
|
||||
*/
|
||||
bool checkForAndSetAMDiGPU(IORegistryEntry *obj);
|
||||
|
||||
public:
|
||||
/**
|
||||
* Obtains autodetected legacy framebuffer if applicable
|
||||
*
|
||||
* @return framebuffer or 0xFFFFFFFF
|
||||
*/
|
||||
static uint32_t getLegacyFramebufferId();
|
||||
|
||||
/**
|
||||
* Checks whether the framebuffer has connectors or not.
|
||||
*
|
||||
* @return true if the framebuffer has no connectors
|
||||
*/
|
||||
static bool isConnectorLessPlatformId(uint32_t id);
|
||||
|
||||
/**
|
||||
* Common external GPU parameter list
|
||||
*/
|
||||
struct ExternalVideo {
|
||||
/**
|
||||
* Aka GFX0 device
|
||||
*/
|
||||
IORegistryEntry *video {nullptr};
|
||||
|
||||
/**
|
||||
* Aka HDAU device
|
||||
*/
|
||||
IORegistryEntry *audio {nullptr};
|
||||
|
||||
/**
|
||||
* External GPU vendor
|
||||
*/
|
||||
uint32_t vendor {0};
|
||||
};
|
||||
|
||||
/**
|
||||
* Aka HDEF device
|
||||
*/
|
||||
IORegistryEntry *audioBuiltinAnalog {nullptr};
|
||||
|
||||
/**
|
||||
* Aka HDAU device for builtin GPU
|
||||
*/
|
||||
IORegistryEntry *audioBuiltinDigital {nullptr};
|
||||
|
||||
/**
|
||||
* Aka IGPU device
|
||||
*/
|
||||
IORegistryEntry *videoBuiltin {nullptr};
|
||||
|
||||
/**
|
||||
* Aka IMEI device
|
||||
*/
|
||||
IORegistryEntry *managementEngine {nullptr};
|
||||
|
||||
/**
|
||||
* Aka GFX0 devices (kept in sync with audioExternal)
|
||||
*/
|
||||
evector<ExternalVideo&> videoExternal;
|
||||
|
||||
private:
|
||||
/**
|
||||
* This is the default reported layout-id passed to reportedLayoutId.
|
||||
* The reason for choosing 7 is its presence in 10.14 and the fact
|
||||
* Apple frameworks still communicate to the files present on disk.
|
||||
* For information purposes only! Use reportedLayoutId!
|
||||
*/
|
||||
static constexpr uint32_t DefaultReportedLayoutId = 7;
|
||||
|
||||
/**
|
||||
* The boot-arg to override the reported layout-id to AppleHDA.
|
||||
* For user configuration only! Use reportedLayoutId!
|
||||
*/
|
||||
static constexpr const char *ReportedLayoutIdArg = "alcapplid";
|
||||
|
||||
/**
|
||||
* The property to override the reported layout-id to AppleHDA.
|
||||
* For user configuration only! Use reportedLayoutId!
|
||||
*/
|
||||
static constexpr const char *ReportedLayoutIdName = "apple-layout-id";
|
||||
|
||||
public:
|
||||
/**
|
||||
* Layout id to be reported by all audio devices (you must update it yourself).
|
||||
* This follows the standard convention initially found in AppleALC:
|
||||
* alcapplid=X boot-arg has highest priority and overrides any other value.
|
||||
* apple-layout-id HDEF prop has normal priority, you may use it if you need.
|
||||
* DefaultReportedLayoutId will be used if both of the above are not set.
|
||||
*/
|
||||
uint32_t reportedLayoutId {0};
|
||||
|
||||
private:
|
||||
/**
|
||||
* The boot-arg to override the reported AAPL,ig-platform-id to Intel drivers.
|
||||
* For user configuration only! Use reportedFramebufferId!
|
||||
*/
|
||||
static constexpr const char *ReportedFrameIdArg = "igfxframe";
|
||||
|
||||
/**
|
||||
* The boot-arg to override the reported AAPL,ig-platform-id to Intel drivers.
|
||||
* Sets VESA framebuffer id (0xFFFFFFFF).
|
||||
* For user configuration only! Use reportedFramebufferId!
|
||||
*/
|
||||
static constexpr const char *ReportedVesaIdArg = "-igfxvesa";
|
||||
|
||||
/**
|
||||
* The boot-arg to force-disable any external GPU if found.
|
||||
* For user configuration only! Use requestedExternalSwitchOff!
|
||||
*/
|
||||
static constexpr const char *RequestedExternalSwitchOffArg {"-wegnoegpu"};
|
||||
|
||||
/**
|
||||
* The boot-arg to force-disable any internal GPU if found.
|
||||
* For user configuration only! Use requestedInternalSwitchOff!
|
||||
*/
|
||||
static constexpr const char *RequestedInternalSwitchOffArg {"-wegnoigpu"};
|
||||
|
||||
/**
|
||||
* The boot-arg to force-disable any internal GPU if external GPU found.
|
||||
* For user configuration only! Use requestedGpuSwitch!!
|
||||
*/
|
||||
static constexpr const char *RequestedGpuSwitchArg {"-wegswitchgpu"};
|
||||
|
||||
/**
|
||||
* The property to set your platform id for Intel drivers (Ivy and newer).
|
||||
* For user configuration only! Use reportedFramebufferName!
|
||||
*/
|
||||
static constexpr const char *ReportedFrameIdName = "AAPL,ig-platform-id";
|
||||
|
||||
/**
|
||||
* The property to set your platform id for Intel drivers (Sandy).
|
||||
* For user configuration only! Use reportedFramebufferName!
|
||||
*/
|
||||
static constexpr const char *ReportedFrameIdLegacyName = "AAPL,snb-platform-id";
|
||||
|
||||
/**
|
||||
* The IGPU property to force-disable any external GPU if found.
|
||||
* For user configuration only! Use processSwitchOff()!
|
||||
*/
|
||||
static constexpr const char *RequestedExternalSwitchOffName {"disable-external-gpu"};
|
||||
|
||||
/**
|
||||
* The IGPU property to force-disable the IGPU if any external GPU is found.
|
||||
* For user configuration only! Use processSwitchOff()!
|
||||
*/
|
||||
static constexpr const char *RequestedGpuSwitchName {"switch-to-external-gpu"};
|
||||
|
||||
/**
|
||||
* The GPU property to force-disable any external or internal GPU.
|
||||
* For user configuration only! Use processSwitchOff()!
|
||||
*/
|
||||
static constexpr const char *RequestedGpuSwitchOffName {"disable-gpu"};
|
||||
|
||||
/**
|
||||
* The GPU property to force-disable any this external GPU with minimum kernel version (inclusive).
|
||||
* For user configuration only! Use processSwitchOff()!
|
||||
*/
|
||||
static constexpr const char *RequestedGpuSwitchOffMinKernelName {"disable-gpu-min"};
|
||||
|
||||
/**
|
||||
* The GPU property to force-disable any this external GPU with maximum kernel version (inclusive).
|
||||
* For user configuration only! Use processSwitchOff()!
|
||||
*/
|
||||
static constexpr const char *RequestedGpuSwitchOffMaxKernelName {"disable-gpu-max"};
|
||||
|
||||
|
||||
/**
|
||||
* Known platform ids used by Intel GPU kexts
|
||||
* For user configuration only!
|
||||
*/
|
||||
static constexpr uint32_t DefaultAppleSkylakePlatformId {0x19120000};
|
||||
static constexpr uint32_t DefaultAppleKabyLakePlatformId {0x59160000};
|
||||
static constexpr uint32_t DefaultAppleCoffeeLakePlatformId {0x3EA50000};
|
||||
static constexpr uint32_t DefaultAppleCannonLakePlatformId {0x5A520000};
|
||||
static constexpr uint32_t DefaultAppleIceLakeRealPlatformId {0x8A520000};
|
||||
static constexpr uint32_t DefaultAppleIceLakeSimulatorPlatformId {0xFF050000};
|
||||
|
||||
/**
|
||||
* Framebuffers without any ports used for hardware acceleration only
|
||||
* Note 1: Broadwell framebuffers all have connectors added.
|
||||
* Note 2: Coffee Lake framebuffers without connectors are only present in 10.14.
|
||||
* Note 3: prerelease Cannon Lake and Ice Lake framebuffers are without connectors.
|
||||
* For user configuration only!
|
||||
*/
|
||||
static constexpr uint32_t ConnectorLessSandyBridgePlatformId1 {0x00030030};
|
||||
static constexpr uint32_t ConnectorLessSandyBridgePlatformId2 {0x00050000};
|
||||
static constexpr uint32_t ConnectorLessIvyBridgePlatformId1 {0x01620006};
|
||||
static constexpr uint32_t ConnectorLessIvyBridgePlatformId2 {0x01620007};
|
||||
static constexpr uint32_t ConnectorLessHaswellPlatformId1 {0x04120004};
|
||||
static constexpr uint32_t ConnectorLessHaswellPlatformId2 {0x0412000B};
|
||||
static constexpr uint32_t ConnectorLessSkylakePlatformId1 {0x19020001};
|
||||
static constexpr uint32_t ConnectorLessSkylakePlatformId2 {0x19170001};
|
||||
static constexpr uint32_t ConnectorLessSkylakePlatformId3 {0x19120001};
|
||||
static constexpr uint32_t ConnectorLessSkylakePlatformId4 {0x19320001};
|
||||
static constexpr uint32_t ConnectorLessKabyLakePlatformId1 {0x59180002};
|
||||
static constexpr uint32_t ConnectorLessKabyLakePlatformId2 {0x59120003};
|
||||
static constexpr uint32_t ConnectorLessCoffeeLakePlatformId1 {0x3E920003};
|
||||
static constexpr uint32_t ConnectorLessCoffeeLakePlatformId2 {0x3E910003};
|
||||
static constexpr uint32_t ConnectorLessCoffeeLakePlatformId3 {0x3E980003};
|
||||
static constexpr uint32_t ConnectorLessCoffeeLakePlatformId4 {0x9BC80003};
|
||||
static constexpr uint32_t ConnectorLessCoffeeLakePlatformId5 {0x9BC50003};
|
||||
static constexpr uint32_t ConnectorLessCoffeeLakePlatformId6 {0x9BC40003};
|
||||
|
||||
/**
|
||||
* Kaveri, and also catches the new Granite Ridge rDNA 2 iGPU.
|
||||
*/
|
||||
static constexpr uint32_t GenericAMDKvGr = 0x1300;
|
||||
|
||||
/**
|
||||
* Kabini, Mullins, Carrizo, Stoney Ridge, Wrestler.
|
||||
*/
|
||||
static constexpr uint32_t GenericAMDKbMlCzStnWr = 0x9800;
|
||||
|
||||
/**
|
||||
* Van Gogh's other Device ID, specifically: 0x1435 rev 0xAE.
|
||||
*/
|
||||
static constexpr uint32_t GenericAMDVanGogh2 = 0x1400;
|
||||
|
||||
/**
|
||||
* Raven/Raven2, Picasso, Barcelo, Phoenix, Phoenix 2 (possibly Hawk Point) & Strix (0x150E)
|
||||
*/
|
||||
static constexpr uint32_t GenericAMDRvPcBcPhn = 0x1500;
|
||||
|
||||
/**
|
||||
* Renoir, Cezanne, Lucienne, Van Gogh, Rembrandt, Raphael.
|
||||
*/
|
||||
static constexpr uint32_t GenericAMDRnCznLcVghRmbRph = 0x1600;
|
||||
|
||||
/**
|
||||
* Trinity
|
||||
*/
|
||||
static constexpr uint32_t GenericAMDTrinity = 0x9900;
|
||||
|
||||
/**
|
||||
* Sumo & Sumo2?
|
||||
*/
|
||||
static constexpr uint32_t GenericAMDSumo = 0x9600;
|
||||
|
||||
/**
|
||||
* Phoenix.
|
||||
*/
|
||||
static constexpr uint32_t GenericAMDPhoenix2 = 0x1900;
|
||||
|
||||
public:
|
||||
/**
|
||||
* Vesa framebuffer identifier
|
||||
*/
|
||||
static constexpr uint32_t DefaultVesaPlatformId {0xFFFFFFFF};
|
||||
|
||||
/**
|
||||
* Framebuffer id to be reported to IGPU.
|
||||
* This follows the standard convention initially found in IntelGraphicsFixup:
|
||||
* igfxframe=X boot-arg has highest priority and overrides any other value.
|
||||
* -igfxvesa forces 0xFFFFFFFF frame to get into VESA mode.
|
||||
* Manually specified AAPL,ig-platform-id or AAPL,snb-platform-id go next.
|
||||
* On Sandy Bridge processors a default AAPL,snb-platform-id will be tried afterwards.
|
||||
* On Skylake and Kaby Lake processors some default id will be tried afterwards.
|
||||
*/
|
||||
uint32_t reportedFramebufferId {0};
|
||||
|
||||
/**
|
||||
* Compatible platform id property name for this IGPU
|
||||
*/
|
||||
const char *reportedFramebufferName {nullptr};
|
||||
|
||||
/**
|
||||
* Set to true if the framebuffer has no connectors
|
||||
*/
|
||||
bool reportedFramebufferIsConnectorLess {false};
|
||||
|
||||
/**
|
||||
* Known variants of firmware vendors
|
||||
* Please note, that it may not be possible to always detect the right vendor
|
||||
*/
|
||||
enum class FirmwareVendor {
|
||||
Unknown,
|
||||
Apple,
|
||||
VMware,
|
||||
EDKII,
|
||||
Parallels,
|
||||
AMI,
|
||||
Insyde,
|
||||
Phoenix,
|
||||
HP
|
||||
};
|
||||
|
||||
/**
|
||||
* Firmware vendor manufacturer
|
||||
*/
|
||||
FirmwareVendor firmwareVendor {FirmwareVendor::Unknown};
|
||||
|
||||
/**
|
||||
* Requested external GPU switchoff
|
||||
*/
|
||||
bool requestedExternalSwitchOff {false};
|
||||
|
||||
/**
|
||||
* Requested internal GPU switchoff
|
||||
*/
|
||||
bool requestedInternalSwitchOff {false};
|
||||
|
||||
/**
|
||||
* Requested GPU switch
|
||||
*/
|
||||
bool requestedGpuSwitch {false};
|
||||
/**
|
||||
* Allocate and initialise cached device list.
|
||||
*
|
||||
* @return device list or nullptr
|
||||
*/
|
||||
static DeviceInfo *createCached();
|
||||
|
||||
/**
|
||||
* Allocate and initialise the device list.
|
||||
*
|
||||
* @return device list or nullptr
|
||||
*/
|
||||
EXPORT static DeviceInfo *create();
|
||||
|
||||
/**
|
||||
* Release initialised device list.
|
||||
*
|
||||
* @param d device list
|
||||
*/
|
||||
EXPORT static void deleter(DeviceInfo *d NONNULL);
|
||||
|
||||
/**
|
||||
* Perform device switch-off as prescribed by the properties injected.
|
||||
*/
|
||||
EXPORT void processSwitchOff();
|
||||
};
|
||||
|
||||
/**
|
||||
* Simple device information available at early stage.
|
||||
*/
|
||||
class BaseDeviceInfo {
|
||||
/**
|
||||
* Updates firmwareVendor
|
||||
*/
|
||||
void updateFirmwareVendor();
|
||||
|
||||
/**
|
||||
* Updates model information
|
||||
*/
|
||||
void updateModelInfo();
|
||||
public:
|
||||
/**
|
||||
* Board identifier board-id (VMware has "440BX Desktop Reference Platform", eek)
|
||||
*/
|
||||
char boardIdentifier[48] {};
|
||||
|
||||
/**
|
||||
* Model identifier
|
||||
*/
|
||||
char modelIdentifier[48] {};
|
||||
|
||||
/**
|
||||
* Computer model type.
|
||||
*/
|
||||
int modelType {WIOKit::ComputerModel::ComputerAny};
|
||||
|
||||
/**
|
||||
* Firmware vendor manufacturer
|
||||
*/
|
||||
DeviceInfo::FirmwareVendor firmwareVendor {DeviceInfo::FirmwareVendor::Unknown};
|
||||
|
||||
/**
|
||||
* Known variants of bootloader vendors
|
||||
* Please note, that it may not be possible to always detect the right vendor
|
||||
*/
|
||||
enum class BootloaderVendor {
|
||||
Unknown,
|
||||
Acidanthera,
|
||||
Clover
|
||||
};
|
||||
|
||||
/**
|
||||
* Bootloader vendor
|
||||
*/
|
||||
BootloaderVendor bootloaderVendor {BootloaderVendor::Unknown};
|
||||
|
||||
/**
|
||||
* CPU vendor
|
||||
*/
|
||||
CPUInfo::CpuVendor cpuVendor {CPUInfo::CpuVendor::Unknown};
|
||||
|
||||
/**
|
||||
* CPU generation
|
||||
*/
|
||||
CPUInfo::CpuGeneration cpuGeneration {CPUInfo::CpuGeneration::Unknown};
|
||||
|
||||
/**
|
||||
* CPU family
|
||||
*/
|
||||
uint32_t cpuFamily {};
|
||||
|
||||
/**
|
||||
* CPU model
|
||||
*/
|
||||
uint32_t cpuModel {};
|
||||
|
||||
/**
|
||||
* CPU stepping
|
||||
*/
|
||||
uint32_t cpuStepping {};
|
||||
|
||||
/**
|
||||
* CPU max level
|
||||
*/
|
||||
uint32_t cpuMaxLevel {};
|
||||
|
||||
/**
|
||||
* CPU max level (ext)
|
||||
*/
|
||||
uint32_t cpuMaxLevelExt {0x80000000};
|
||||
|
||||
/**
|
||||
* AVX 2.0 support
|
||||
*/
|
||||
bool cpuHasAvx2 {false};
|
||||
|
||||
/**
|
||||
* Obtain base device info.
|
||||
*/
|
||||
EXPORT static const BaseDeviceInfo &get();
|
||||
|
||||
/**
|
||||
* Initialize global base device info.
|
||||
*/
|
||||
static void init();
|
||||
};
|
||||
|
||||
#endif /* kern_devinfo_h */
|
||||
@@ -0,0 +1,183 @@
|
||||
//
|
||||
// kern_disasm.hpp
|
||||
// Lilu
|
||||
//
|
||||
// Copyright © 2016-2017 vit9696. All rights reserved.
|
||||
//
|
||||
|
||||
#ifndef kern_disasm_hpp
|
||||
#define kern_disasm_hpp
|
||||
|
||||
#include <Headers/kern_config.hpp>
|
||||
#include <Headers/kern_util.hpp>
|
||||
|
||||
#if defined(__i386__)
|
||||
#include <Headers/hde32.h>
|
||||
#elif defined(__x86_64__)
|
||||
#include <Headers/hde64.h>
|
||||
#else
|
||||
#error Unsupported arch.
|
||||
#endif
|
||||
|
||||
#ifdef LILU_ADVANCED_DISASSEMBLY
|
||||
#ifndef CAPSTONE_HAS_OSXKERNEL
|
||||
#define CAPSTONE_HAS_OSXKERNEL 1
|
||||
#endif
|
||||
#include <Headers/capstone/capstone.h>
|
||||
#endif /* LILU_ADVANCED_DISASSEMBLY */
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <mach/vm_types.h>
|
||||
|
||||
class Disassembler {
|
||||
#ifdef LILU_ADVANCED_DISASSEMBLY
|
||||
/**
|
||||
* Because captsone handle can be 0
|
||||
*/
|
||||
bool initialised {false};
|
||||
|
||||
/**
|
||||
* Internal capstone handle
|
||||
*/
|
||||
size_t handle {};
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Max instruction size
|
||||
*/
|
||||
static constexpr size_t MaxInstruction {15};
|
||||
public:
|
||||
|
||||
#if defined(__i386__)
|
||||
using hde_t = hde32s;
|
||||
static constexpr auto hde_disasm = hde32_disasm;
|
||||
#elif defined(__x86_64__)
|
||||
using hde_t = hde64s;
|
||||
static constexpr auto hde_disasm = hde64_disasm;
|
||||
#else
|
||||
#error Unsupported arch.
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Return the real instruction size contained within min bytes
|
||||
* Unlike instructionSize this uses HDE engine and at the cost of reduced compatibility it is much faster
|
||||
* Note: instruction pointer should point to at least min + 32 valid bytes.
|
||||
*
|
||||
* @param ptr instruction pointer
|
||||
* @param min minimal possible size
|
||||
*
|
||||
* @return instruction size >= min on success or 0
|
||||
*/
|
||||
EXPORT static size_t quickInstructionSize(mach_vm_address_t ptr, size_t min);
|
||||
|
||||
/* Note, code should point to at least 32 valid bytes. */
|
||||
EXPORT static size_t hdeDisasm(mach_vm_address_t code, hde_t *hs);
|
||||
|
||||
#ifdef LILU_ADVANCED_DISASSEMBLY
|
||||
|
||||
/**
|
||||
* Initialise advanced dissassembling framework
|
||||
*
|
||||
* @param detailed debugging output necessity
|
||||
*
|
||||
* @return true on success
|
||||
*/
|
||||
EXPORT bool init(bool detailed=false);
|
||||
|
||||
/**
|
||||
* Deinitialise advanced dissassembling framework, must be called regardless of the init error
|
||||
*/
|
||||
EXPORT void deinit();
|
||||
|
||||
/**
|
||||
* Reads size bytes from addr and disassembles them.
|
||||
*
|
||||
* @param addr Address to read from
|
||||
* @param size Size of buffer to read
|
||||
* @param result Disassembled instructions array. You must free it
|
||||
*
|
||||
* @return size of result
|
||||
*/
|
||||
EXPORT size_t disasmBuf(mach_vm_address_t addr, size_t size, cs_insn **result);
|
||||
|
||||
/**
|
||||
* Return the real instruction size contained within min bytes
|
||||
*
|
||||
* @param ptr instruction pointer
|
||||
* @param min minimal possible size
|
||||
*
|
||||
* @return instruction size >= min on success or 0
|
||||
*/
|
||||
EXPORT size_t instructionSize(mach_vm_address_t ptr, size_t min);
|
||||
|
||||
/**
|
||||
* Reads lookup_size bytes from addr and disassembles them.
|
||||
* After disassembling, tries to find num-th entry with call instruction, which argument is an immediate value (some address).
|
||||
*
|
||||
* @param addr Address to read from
|
||||
* @param num Number of call instruction to search for
|
||||
* @param lookup_size Number of bytes to read
|
||||
*
|
||||
* @note It is assumed that the operand contains a positive relative address.
|
||||
*
|
||||
* @return direct address of num-th call instruction on success, else 0
|
||||
*/
|
||||
EXPORT mach_vm_address_t disasmNthSub(mach_vm_address_t addr, size_t num, size_t lookup_size);
|
||||
|
||||
/**
|
||||
* @brief Reads lookup_size bytes from addr and disassembles them.
|
||||
*
|
||||
* After disassembling, tries to find num-th entry with jmp instruction, which argument is an immediate value (some address).
|
||||
*
|
||||
* @param addr Address to read from
|
||||
* @param num Number of jmp instruction to search for
|
||||
* @param lookup_size Number of bytes to read
|
||||
*
|
||||
* @note It is assumed that the operand contains a positive relative address.
|
||||
*
|
||||
* @return direct address of num-th jmp instruction on success, else 0
|
||||
*/
|
||||
EXPORT mach_vm_address_t disasmNthJmp(mach_vm_address_t addr, size_t num, size_t lookup_size);
|
||||
|
||||
/**
|
||||
* Reads lookup_size bytes from addr and disassembles them.
|
||||
* After disassembling, tries to find num-th entry of inst instruction.
|
||||
*
|
||||
* @param addr Addres to read from
|
||||
* @param ins Instruction code
|
||||
* @param num Number of ins instruction to search for
|
||||
* @param lookup_size Number of bytes to read
|
||||
*
|
||||
* @return address of found instruction on success, else 0
|
||||
*/
|
||||
EXPORT mach_vm_address_t disasmNthIns(mach_vm_address_t addr, x86_insn ins, size_t num, size_t lookup_size);
|
||||
|
||||
/**
|
||||
* Disassembly matching structure
|
||||
*/
|
||||
struct DisasmSig {
|
||||
x86_insn ins; // instruction
|
||||
bool sub; // relevant only for X86_INS_CALL, if its arg is X86_OP_IMM
|
||||
bool addr; // if you want to return the address of exact inst in sig
|
||||
|
||||
static DisasmSig *create() { return new DisasmSig; }
|
||||
static void deleter(DisasmSig *sig NONNULL) { delete sig; }
|
||||
};
|
||||
|
||||
/**
|
||||
* Reads lookup_size bytes from addr and disassembles them.
|
||||
* After disassembling, tries to find num-th entry of sig instruction pattern.
|
||||
*
|
||||
* @param addr Address to read from
|
||||
* @param sig Instruction pattern
|
||||
* @param num Order of pattern to search for
|
||||
* @param lookup_size Number of bytes to read
|
||||
*
|
||||
* @return direct address of pattern start on success, else 0
|
||||
*/
|
||||
EXPORT mach_vm_address_t disasmSig(mach_vm_address_t addr, evector<DisasmSig *, DisasmSig::deleter> &sig, size_t num, size_t lookup_size);
|
||||
|
||||
#endif /* LILU_ADVANCED_DISASSEMBLY */
|
||||
};
|
||||
|
||||
#endif /* kern_disasm_hpp */
|
||||
@@ -0,0 +1,95 @@
|
||||
//
|
||||
// kern_efi.hpp
|
||||
// Lilu
|
||||
//
|
||||
// Copyright © 2018 vit9696. All rights reserved.
|
||||
//
|
||||
|
||||
#ifndef kern_efi_h
|
||||
#define kern_efi_h
|
||||
|
||||
#include <Headers/kern_util.hpp>
|
||||
|
||||
#include <pexpert/i386/efi.h>
|
||||
|
||||
/**
|
||||
* Convert 32-bit EFI errors provided by Apple to 64-bit EFI errors
|
||||
*/
|
||||
#define EFI_ERROR64(x) (((x) & ~(1ULL << 31)) | (1ULL << 63))
|
||||
static_assert(EFI_LOAD_ERROR == 0x80000001 && EFI_ERROR64(EFI_LOAD_ERROR) == 0x8000000000000001,
|
||||
"Apple has finally upgraded EFI headers!");
|
||||
|
||||
class EfiRuntimeServices {
|
||||
IOLock *accessLock {nullptr};
|
||||
static EfiRuntimeServices *instance;
|
||||
private:
|
||||
bool is32BitEFI {false};
|
||||
void *efiRuntimeServices {nullptr};
|
||||
|
||||
/**
|
||||
* Set EFI runtime services table pointer
|
||||
*/
|
||||
void setRuntimeServices();
|
||||
|
||||
public:
|
||||
/**
|
||||
* Activates EFI Runtime Services
|
||||
*/
|
||||
static void activate();
|
||||
|
||||
/**
|
||||
* Lilu custom GUIDs exports, see OcSupportPkg/Include/Guid/OcVariables.h
|
||||
*/
|
||||
EXPORT static const EFI_GUID LiluVendorGuid;
|
||||
EXPORT static const EFI_GUID LiluReadOnlyGuid;
|
||||
EXPORT static const EFI_GUID LiluWriteOnlyGuid;
|
||||
|
||||
/**
|
||||
* Get EFI Runtime Services wrapper if supported
|
||||
*
|
||||
* @param lock lock instance during the run, must be put back
|
||||
*
|
||||
* @return wrapper instance
|
||||
*/
|
||||
EXPORT static EfiRuntimeServices *get(bool lock=false);
|
||||
|
||||
/**
|
||||
* Put EFI Runtime Services wrapper to unlock
|
||||
*/
|
||||
EXPORT void put();
|
||||
|
||||
/**
|
||||
* Perform system reset (does not return on success)
|
||||
*
|
||||
* @param type reset type
|
||||
*/
|
||||
EXPORT void resetSystem(EFI_RESET_TYPE type);
|
||||
|
||||
/**
|
||||
* Obtain EFI variable, invokes EFI_RUNTIME_SERVICES::GetVariable.
|
||||
*
|
||||
* @param name variable name
|
||||
* @param guid vendor guid
|
||||
* @param attr variable attributes
|
||||
* @param size data buffer size updated on read
|
||||
* @param data read data
|
||||
*
|
||||
* @return EFI_STATUS code
|
||||
*/
|
||||
EXPORT uint64_t getVariable(const char16_t *name, const EFI_GUID *guid, uint32_t *attr, uint64_t *size, void *data);
|
||||
|
||||
/**
|
||||
* Set EFI variable, invokes EFI_RUNTIME_SERVICES::SetVariable.
|
||||
*
|
||||
* @param name variable name
|
||||
* @param guid vendor guid
|
||||
* @param attr variable attributes
|
||||
* @param size data buffer size
|
||||
* @param data data to write
|
||||
*
|
||||
* @return EFI_STATUS code
|
||||
*/
|
||||
EXPORT uint64_t setVariable(const char16_t *name, const EFI_GUID *guid, uint32_t attr, uint64_t size, void *data);
|
||||
};
|
||||
|
||||
#endif /* kern_efi_h */
|
||||
@@ -0,0 +1,92 @@
|
||||
//
|
||||
// kern_file.hpp
|
||||
// Lilu
|
||||
//
|
||||
// Copyright © 2016-2017 vit9696. All rights reserved.
|
||||
//
|
||||
|
||||
#ifndef kern_file_hpp
|
||||
#define kern_file_hpp
|
||||
|
||||
#include <Headers/kern_config.hpp>
|
||||
#include <Headers/kern_util.hpp>
|
||||
|
||||
#include <sys/kernel_types.h>
|
||||
#include <sys/fcntl.h>
|
||||
|
||||
namespace FileIO {
|
||||
/**
|
||||
* Reads file data at path
|
||||
*
|
||||
* @param path full file path
|
||||
* @param size bytes read
|
||||
*
|
||||
* @return allocated buffer on success or nullptr on error
|
||||
*/
|
||||
EXPORT uint8_t *readFileToBuffer(const char *path, size_t &size);
|
||||
|
||||
/**
|
||||
* Read file data from a vnode
|
||||
*
|
||||
* @param buffer output buffer
|
||||
* @param off file offset
|
||||
* @param sz bytes to read
|
||||
* @param vnode file node
|
||||
* @param ctxt filesystem context
|
||||
*
|
||||
* @return 0 on success
|
||||
*/
|
||||
EXPORT int readFileData(void *buffer, off_t off, size_t sz, vnode_t vnode, vfs_context_t ctxt);
|
||||
|
||||
/**
|
||||
* Read file size from a vnode
|
||||
*
|
||||
* @param vnode file node
|
||||
* @param ctxt filesystem context
|
||||
*
|
||||
* @return file size or 0
|
||||
*/
|
||||
EXPORT size_t readFileSize(vnode_t vnode, vfs_context_t ctxt);
|
||||
|
||||
/**
|
||||
* Writes buffer to a file at path
|
||||
*
|
||||
* @param path full file path
|
||||
* @param buffer input buffer
|
||||
* @param size bytes write
|
||||
* @param fmode file opening mode
|
||||
* @param cmode file permissions
|
||||
*
|
||||
* @return 0 on success
|
||||
*/
|
||||
EXPORT int writeBufferToFile(const char *path, void *buffer, size_t size, int fmode=O_TRUNC | O_CREAT | FWRITE | O_NOFOLLOW, int cmode=S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH);
|
||||
|
||||
/**
|
||||
* Write file data to a vnode
|
||||
*
|
||||
* @param buffer input buffer
|
||||
* @param off file offset
|
||||
* @param size bytes to write
|
||||
* @param vnode file node
|
||||
* @param ctxt filesystem context
|
||||
*
|
||||
* @return 0 on success
|
||||
*/
|
||||
EXPORT int writeFileData(void *buffer, off_t off, size_t size, vnode_t vnode, vfs_context_t ctxt);
|
||||
|
||||
/**
|
||||
* Perform file i/o through a vnode
|
||||
*
|
||||
* @param buffer input buffer
|
||||
* @param off file offset
|
||||
* @param size bytes to write
|
||||
* @param vnode file node
|
||||
* @param ctxt filesystem context
|
||||
* @param write write to buffer otherwise read
|
||||
*
|
||||
* @return 0 on success
|
||||
*/
|
||||
int performFileIO(void *buffer, off_t off, size_t size, vnode_t vnode, vfs_context_t ctxt, bool write);
|
||||
}
|
||||
|
||||
#endif /* kern_file_hpp */
|
||||
331
EFI/OC/Kexts/Lilu.kext/Contents/Resources/Headers/kern_iokit.hpp
Normal file
331
EFI/OC/Kexts/Lilu.kext/Contents/Resources/Headers/kern_iokit.hpp
Normal file
@@ -0,0 +1,331 @@
|
||||
//
|
||||
// kern_iokit.hpp
|
||||
// Lilu
|
||||
//
|
||||
// Copyright © 2016-2017 vit9696. All rights reserved.
|
||||
//
|
||||
|
||||
#ifndef kern_iokit_hpp
|
||||
#define kern_iokit_hpp
|
||||
|
||||
#include <Headers/kern_config.hpp>
|
||||
#include <Headers/kern_util.hpp>
|
||||
#include <Headers/kern_patcher.hpp>
|
||||
|
||||
#include <libkern/c++/OSSerialize.h>
|
||||
#include <IOKit/IORegistryEntry.h>
|
||||
|
||||
namespace WIOKit {
|
||||
|
||||
/**
|
||||
* AppleHDAEngine::getLocation teaches us to use loop infinitely when talking to IOReg
|
||||
* This feels mad and insane, since it may prevent the system from booting.
|
||||
* Although this had never happened, we will use a far bigger fail-safe stop value.
|
||||
*/
|
||||
static constexpr size_t bruteMax {40000000};
|
||||
|
||||
/**
|
||||
* Read typed OSData
|
||||
*
|
||||
* @param obj read object
|
||||
* @param value read value
|
||||
* @param name propert name
|
||||
*
|
||||
* @return true on success
|
||||
*/
|
||||
template <typename T>
|
||||
inline bool getOSDataValue(const OSObject *obj, const char *name, T &value) {
|
||||
if (obj) {
|
||||
auto data = OSDynamicCast(OSData, obj);
|
||||
if (data && data->getLength() == sizeof(T)) {
|
||||
value = *static_cast<const T *>(data->getBytesNoCopy());
|
||||
DBGLOG("iokit", "getOSData %s has %llX value", name, static_cast<uint64_t>(value));
|
||||
return true;
|
||||
} else {
|
||||
SYSLOG("iokit", "getOSData %s has unexpected format", name);
|
||||
}
|
||||
} else {
|
||||
DBGLOG("iokit", "getOSData %s was not found", name);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Read typed OSData through a temp type
|
||||
*
|
||||
* @param obj read object
|
||||
* @param value read value
|
||||
* @param name propert name
|
||||
*
|
||||
* @return true on success
|
||||
*/
|
||||
template <typename AS, typename T>
|
||||
inline bool getOSDataValue(const OSObject *obj, const char *name, T &value) {
|
||||
AS tmp;
|
||||
if (getOSDataValue(obj, name, tmp)) {
|
||||
value = static_cast<T>(tmp);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Read typed OSData from IORegistryEntry
|
||||
*
|
||||
* @see getOSDataValue
|
||||
*/
|
||||
template <typename T>
|
||||
inline bool getOSDataValue(const IORegistryEntry *sect, const char *name, T &value) {
|
||||
return getOSDataValue(sect->getProperty(name), name, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Read typed OSData from IORegistryEntry
|
||||
*
|
||||
* @see getOSDataValue
|
||||
*/
|
||||
template <typename AS, typename T>
|
||||
inline bool getOSDataValue(const IORegistryEntry *sect, const char *name, T &value) {
|
||||
return getOSDataValue<AS>(sect->getProperty(name), name, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Read typed OSData from IORegistryEntry
|
||||
*
|
||||
* @see getOSDataValue
|
||||
*/
|
||||
template <typename T>
|
||||
inline bool getOSDataValue(const OSDictionary *dict, const char *name, T &value) {
|
||||
return getOSDataValue(dict->getObject(name), name, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Read typed OSData from IORegistryEntry
|
||||
*
|
||||
* @see getOSDataValue
|
||||
*/
|
||||
template <typename AS, typename T>
|
||||
inline bool getOSDataValue(const OSDictionary *dict, const char *name, T &value) {
|
||||
return getOSDataValue<AS>(dict->getObject(name), name, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve property object
|
||||
*
|
||||
* @param entry IORegistry entry
|
||||
* @param property property name
|
||||
*
|
||||
* @return property object (must be released) or nullptr
|
||||
*/
|
||||
EXPORT LIBKERN_RETURNS_RETAINED OSSerialize *getProperty(IORegistryEntry *entry, const char *property);
|
||||
|
||||
/**
|
||||
* Model variants
|
||||
*/
|
||||
struct ComputerModel {
|
||||
enum {
|
||||
ComputerInvalid = 0x0,
|
||||
ComputerLaptop = 0x1,
|
||||
ComputerDesktop = 0x2,
|
||||
ComputerAny = ComputerLaptop | ComputerDesktop
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
* PCI GPU Vendor identifiers
|
||||
*/
|
||||
struct VendorID {
|
||||
enum : uint16_t {
|
||||
ATIAMD = 0x1002,
|
||||
AMDZEN = 0x1022,
|
||||
NVIDIA = 0x10DE,
|
||||
Intel = 0x8086,
|
||||
VMware = 0x15AD,
|
||||
QEMU = 0x1B36,
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
* PCI class codes
|
||||
*/
|
||||
struct ClassCode {
|
||||
enum : uint32_t {
|
||||
VGAController = 0x030000,
|
||||
// I have never seen this one, but laptops are evil.
|
||||
XGAController = 0x030100,
|
||||
// Some laptops use this for Optimus GPUs.
|
||||
Ex3DController = 0x030200,
|
||||
DisplayController = 0x038000,
|
||||
PCIBridge = 0x060400,
|
||||
// HDA device on some laptops like Acer Aspire VN7-592G (INSYDE).
|
||||
HDAMmDevice = 0x040100,
|
||||
// Watch out for PCISubclassMask, 0x040380 is common on laptops.
|
||||
HDADevice = 0x040300,
|
||||
// This does not seem to be documented. It works on Haswell at least.
|
||||
IMEI = 0x078000,
|
||||
// To ignore device subclasses.
|
||||
PCISubclassMask = 0xFFFF00,
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
* Definitions of PCI Config Registers
|
||||
*/
|
||||
enum PCIRegister : uint8_t {
|
||||
kIOPCIConfigVendorID = 0x00,
|
||||
kIOPCIConfigDeviceID = 0x02,
|
||||
kIOPCIConfigCommand = 0x04,
|
||||
kIOPCIConfigStatus = 0x06,
|
||||
kIOPCIConfigRevisionID = 0x08,
|
||||
kIOPCIConfigClassCode = 0x09,
|
||||
kIOPCIConfigCacheLineSize = 0x0C,
|
||||
kIOPCIConfigLatencyTimer = 0x0D,
|
||||
kIOPCIConfigHeaderType = 0x0E,
|
||||
kIOPCIConfigBIST = 0x0F,
|
||||
kIOPCIConfigBaseAddress0 = 0x10,
|
||||
kIOPCIConfigBaseAddress1 = 0x14,
|
||||
kIOPCIConfigBaseAddress2 = 0x18,
|
||||
kIOPCIConfigBaseAddress3 = 0x1C,
|
||||
kIOPCIConfigBaseAddress4 = 0x20,
|
||||
kIOPCIConfigBaseAddress5 = 0x24,
|
||||
kIOPCIConfigCardBusCISPtr = 0x28,
|
||||
kIOPCIConfigSubSystemVendorID = 0x2C,
|
||||
kIOPCIConfigSubSystemID = 0x2E,
|
||||
kIOPCIConfigExpansionROMBase = 0x30,
|
||||
kIOPCIConfigCapabilitiesPtr = 0x34,
|
||||
kIOPCIConfigInterruptLine = 0x3C,
|
||||
kIOPCIConfigInterruptPin = 0x3D,
|
||||
kIOPCIConfigMinimumGrant = 0x3E,
|
||||
kIOPCIConfigMaximumLatency = 0x3F,
|
||||
kIOPCIConfigGraphicsControl = 0x50
|
||||
};
|
||||
|
||||
/**
|
||||
* Fixed offsets for PCI Config I/O virtual methods
|
||||
*/
|
||||
struct PCIConfigOffset {
|
||||
enum : size_t {
|
||||
ConfigRead32 = 0x10A,
|
||||
ConfigWrite32 = 0x10B,
|
||||
ConfigRead16 = 0x10C,
|
||||
ConfigWrite16 = 0x10D,
|
||||
ConfigRead8 = 0x10E,
|
||||
ConfigWrite8 = 0x10F,
|
||||
GetBusNumber = 0x11D,
|
||||
GetDeviceNumber = 0x11E,
|
||||
GetFunctionNumber = 0x11F
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
* PCI Config I/O method prototypes
|
||||
*/
|
||||
using t_PCIConfigRead32 = uint32_t (*)(IORegistryEntry *service, uint32_t space, uint8_t offset);
|
||||
using t_PCIConfigRead16 = uint16_t (*)(IORegistryEntry *service, uint32_t space, uint8_t offset);
|
||||
using t_PCIConfigRead8 = uint8_t (*)(IORegistryEntry *service, uint32_t space, uint8_t offset);
|
||||
using t_PCIConfigWrite32 = void (*)(IORegistryEntry *service, uint32_t space, uint8_t offset, uint32_t data);
|
||||
using t_PCIConfigWrite16 = void (*)(IORegistryEntry *service, uint32_t space, uint8_t offset, uint16_t data);
|
||||
using t_PCIConfigWrite8 = void (*)(IORegistryEntry *service, uint32_t space, uint8_t offset, uint8_t data);
|
||||
using t_PCIGetBusNumber = uint8_t (*)(IORegistryEntry *service);
|
||||
using t_PCIGetDeviceNumber = uint8_t (*)(IORegistryEntry *service);
|
||||
using t_PCIGetFunctionNumber = uint8_t (*)(IORegistryEntry *service);
|
||||
|
||||
/**
|
||||
* Await for device publishing in IOService plane
|
||||
*
|
||||
* @param obj wait for (PCI) object publishing
|
||||
*
|
||||
* @retval true on success
|
||||
*/
|
||||
EXPORT bool awaitPublishing(IORegistryEntry *obj);
|
||||
|
||||
/**
|
||||
* Read PCI Config register
|
||||
*
|
||||
* @param service IOPCIDevice-compatible service.
|
||||
* @param reg PCI config register
|
||||
* @param space adress space
|
||||
* @param size read size for reading custom registers
|
||||
*
|
||||
* @return value read
|
||||
*/
|
||||
EXPORT uint32_t readPCIConfigValue(IORegistryEntry *service, uint32_t reg, uint32_t space = 0, uint32_t size = 0);
|
||||
|
||||
/**
|
||||
* Retrieve PCI device address
|
||||
*
|
||||
* @param service IOPCIDevice-compatible service.
|
||||
* @param bus bus address
|
||||
* @param device device address
|
||||
* @param function function address
|
||||
*/
|
||||
EXPORT void getDeviceAddress(IORegistryEntry *service, uint8_t &bus, uint8_t &device, uint8_t &function);
|
||||
|
||||
/**
|
||||
* Retrieve the computer type
|
||||
*
|
||||
* @return valid computer type or ComputerAny
|
||||
*/
|
||||
EXPORT int getComputerModel() DEPRECATE("Use BaseDeviceInfo");
|
||||
|
||||
/**
|
||||
* Retrieve computer model and/or board-id properties
|
||||
*
|
||||
* @param model model name output buffer or null
|
||||
* @param modelsz model name output buffer size
|
||||
* @param board board identifier output buffer or null
|
||||
* @param boardsz board identifier output buffer size
|
||||
*
|
||||
* @return true if relevant properties already are available, otherwise buffers are unchanged
|
||||
*/
|
||||
EXPORT bool getComputerInfo(char *model, size_t modelsz, char *board, size_t boardsz) DEPRECATE("Use BaseDeviceInfo");
|
||||
|
||||
/**
|
||||
* Retrieve an ioreg entry by path/prefix
|
||||
*
|
||||
* @param path an exact lookup path
|
||||
* @param prefix entry prefix at path
|
||||
* @param plane plane to lookup in
|
||||
* @param proc process every found entry with the method
|
||||
* @param brute kick ioreg until a value is found
|
||||
* @param user pass some value to the callback function
|
||||
*
|
||||
* @return entry pointer (must NOT be released) or nullptr (on failure or in proc mode)
|
||||
*/
|
||||
EXPORT LIBKERN_RETURNS_NOT_RETAINED IORegistryEntry *findEntryByPrefix(const char *path, const char *prefix, const IORegistryPlane *plane, bool (*proc)(void *, IORegistryEntry *)=nullptr, bool brute=false, void *user=nullptr);
|
||||
|
||||
/**
|
||||
* Retrieve an ioreg entry by path/prefix
|
||||
*
|
||||
* @param entry an ioreg entry to look in
|
||||
* @param prefix entry prefix at path
|
||||
* @param plane plane to lookup in
|
||||
* @param proc process every found entry with the method
|
||||
* @param brute kick ioreg until a value is found
|
||||
* @param user pass some value to the callback function
|
||||
*
|
||||
* @return entry pointer (must NOT be released) or nullptr (on failure or in proc mode)
|
||||
*/
|
||||
EXPORT LIBKERN_RETURNS_NOT_RETAINED IORegistryEntry *findEntryByPrefix(IORegistryEntry *entry, const char *prefix, const IORegistryPlane *plane, bool (*proc)(void *, IORegistryEntry *)=nullptr, bool brute=false, void *user=nullptr);
|
||||
|
||||
/**
|
||||
* Check if we are using prelinked kernel/kexts or not
|
||||
*
|
||||
* @return true when confirmed that we definitely are
|
||||
*/
|
||||
EXPORT bool usingPrelinkedCache();
|
||||
|
||||
/**
|
||||
* Properly rename the device
|
||||
*
|
||||
* @param entry device to rename
|
||||
* @param name new name
|
||||
* @param compat correct compatible
|
||||
*
|
||||
* @return true on success
|
||||
*/
|
||||
EXPORT bool renameDevice(IORegistryEntry *entry, const char *name, bool compat=true);
|
||||
}
|
||||
|
||||
#endif /* kern_iokit_hpp */
|
||||
349
EFI/OC/Kexts/Lilu.kext/Contents/Resources/Headers/kern_mach.hpp
Normal file
349
EFI/OC/Kexts/Lilu.kext/Contents/Resources/Headers/kern_mach.hpp
Normal file
@@ -0,0 +1,349 @@
|
||||
//
|
||||
// kern_mach.hpp
|
||||
// Lilu
|
||||
//
|
||||
// Certain parts of code are the subject of
|
||||
// copyright © 2011, 2012, 2013, 2014 fG!, reverser@put.as - http://reverse.put.as
|
||||
// Copyright © 2016-2017 vit9696. All rights reserved.
|
||||
//
|
||||
|
||||
#ifndef kern_mach_hpp
|
||||
#define kern_mach_hpp
|
||||
|
||||
#include <Headers/kern_config.hpp>
|
||||
#include <Headers/kern_util.hpp>
|
||||
|
||||
#include <sys/time.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/vnode.h>
|
||||
#include <mach-o/loader.h>
|
||||
#include <mach/vm_param.h>
|
||||
#include <libkern/c++/OSDictionary.h>
|
||||
|
||||
class MachInfo {
|
||||
#if defined(__i386__)
|
||||
using mach_header_native = mach_header;
|
||||
using segment_command_native = segment_command;
|
||||
using nlist_native = struct nlist;
|
||||
|
||||
static constexpr uint8_t SegmentTypeNative {LC_SEGMENT};
|
||||
static constexpr uint32_t MachMagicNative {MH_MAGIC};
|
||||
static constexpr uint32_t MachCpuTypeNative {CPU_TYPE_I386};
|
||||
|
||||
#elif defined(__x86_64__)
|
||||
using mach_header_native = mach_header_64;
|
||||
using segment_command_native = segment_command_64;
|
||||
using nlist_native = struct nlist_64;
|
||||
|
||||
static constexpr uint8_t SegmentTypeNative {LC_SEGMENT_64};
|
||||
static constexpr uint32_t MachMagicNative {MH_MAGIC_64};
|
||||
static constexpr uint32_t MachCpuTypeNative {CPU_TYPE_X86_64};
|
||||
|
||||
#else
|
||||
#error Unsupported arch.
|
||||
#endif
|
||||
|
||||
mach_vm_address_t running_text_addr {0}; // the address of running __TEXT segment
|
||||
mach_vm_address_t disk_text_addr {0}; // the same address at from a file
|
||||
mach_vm_address_t kaslr_slide {0}; // the kernel aslr slide, computed as the difference between above's addresses
|
||||
uint8_t *file_buf {nullptr}; // read file data
|
||||
OSDictionary *prelink_dict {nullptr}; // read prealinked kext dictionary
|
||||
uint8_t *prelink_addr {nullptr}; // prelink text base address
|
||||
mach_vm_address_t prelink_vmaddr {0}; // prelink text base vm address (for kexts this is their actual slide)
|
||||
uint32_t file_buf_size {0}; // read file data size
|
||||
uint8_t *sym_buf {nullptr}; // pointer to buffer (normally __LINKEDIT) containing symbols to solve
|
||||
bool sym_buf_ro {false}; // sym_buf is read-only (not copy).
|
||||
uint64_t sym_fileoff {0}; // file offset of symbols (normally __LINKEDIT) so we can read
|
||||
size_t sym_size {0};
|
||||
uint32_t symboltable_fileoff {0}; // file offset to symbol table - used to position inside the __LINKEDIT buffer
|
||||
uint32_t symboltable_nr_symbols {0};
|
||||
uint32_t stringtable_fileoff {0}; // file offset to string table
|
||||
uint32_t stringtable_size {0};
|
||||
mach_header_native *running_mh {nullptr}; // pointer to mach-o header of running kernel item
|
||||
mach_vm_address_t address_slots {0}; // pointer after mach-o header to store pointers
|
||||
mach_vm_address_t address_slots_end {0}; // pointer after mach-o header to store pointers
|
||||
off_t fat_offset {0}; // additional fat offset
|
||||
size_t memory_size {HeaderSize}; // memory size
|
||||
bool kaslr_slide_set {false}; // kaslr can be null, used for disambiguation
|
||||
bool allow_decompress {true}; // allows mach decompression
|
||||
bool prelink_slid {false}; // assume kaslr-slid kext addresses
|
||||
bool kernel_collection {false}; // kernel collection (11.0+)
|
||||
uint64_t self_uuid[2] {}; // saved uuid of the loaded kext or kernel
|
||||
|
||||
/**
|
||||
* Kernel slide is aligned by 20 bits
|
||||
*/
|
||||
static constexpr size_t KASLRAlignment {0x100000};
|
||||
|
||||
/**
|
||||
* Retrieve LC_UUID command value from a mach header
|
||||
*
|
||||
* @param header mach header pointer
|
||||
*
|
||||
* @return UUID or nullptr
|
||||
*/
|
||||
uint64_t *getUUID(void *header);
|
||||
|
||||
/**
|
||||
* Retrieve and preserve LC_UUID command value from a mach header
|
||||
*
|
||||
* @param header mach header pointer
|
||||
*
|
||||
* @return true on success
|
||||
*/
|
||||
bool loadUUID(void *header);
|
||||
|
||||
/**
|
||||
* Enable/disable the Write Protection bit in CR0 register
|
||||
*
|
||||
* @param enable the desired value
|
||||
*
|
||||
* @return KERN_SUCCESS if succeeded
|
||||
*/
|
||||
static kern_return_t setWPBit(bool enable);
|
||||
|
||||
/**
|
||||
* Retrieve the first pages of a binary at disk into a buffer
|
||||
* Version that uses KPI VFS functions and a ripped uio_createwithbuffer() from XNU
|
||||
*
|
||||
* @param buffer allocated buffer sized no less than HeaderSize
|
||||
* @param vnode file node
|
||||
* @param ctxt filesystem context
|
||||
* @param decompress enable decompression
|
||||
* @param off fat offset or 0
|
||||
*
|
||||
* @return KERN_SUCCESS if the read data contains 64-bit mach header
|
||||
*/
|
||||
kern_return_t readMachHeader(uint8_t *buffer, vnode_t vnode, vfs_context_t ctxt, off_t off=0);
|
||||
|
||||
/**
|
||||
* Retrieve the whole symbol table (typically contained within the linkedit segment) into target buffer from kernel binary at disk
|
||||
*
|
||||
* @param vnode file node
|
||||
* @param ctxt filesystem context
|
||||
*
|
||||
* @return KERN_SUCCESS on success
|
||||
*/
|
||||
kern_return_t readSymbols(vnode_t vnode, vfs_context_t ctxt);
|
||||
|
||||
/**
|
||||
* Retrieve necessary mach-o header information from the mach header
|
||||
*
|
||||
* @param header read header sized no less than HeaderSize
|
||||
*/
|
||||
void processMachHeader(void *header);
|
||||
|
||||
/**
|
||||
* Load kext info dictionary and addresses if they were not loaded previously
|
||||
*/
|
||||
void updatePrelinkInfo();
|
||||
|
||||
/**
|
||||
* Lookup mach image in prelinked image
|
||||
*
|
||||
* @param identifier identifier
|
||||
* @param imageSize size of the returned buffer
|
||||
* @param slide actual slide for symbols (normally kaslr or 0)
|
||||
* @param missing set to true on successful prelink parsing when image is not needed
|
||||
*
|
||||
* @return pointer to const buffer on success or nullptr
|
||||
*/
|
||||
uint8_t *findImage(const char *identifier, uint32_t &imageSize, mach_vm_address_t &slide, bool &missing);
|
||||
|
||||
MachInfo(bool asKernel, const char *id) : isKernel(asKernel), objectId(id) {
|
||||
DBGLOG("mach", "MachInfo asKernel %d object constructed", asKernel);
|
||||
}
|
||||
MachInfo(const MachInfo &) = delete;
|
||||
MachInfo &operator =(const MachInfo &) = delete;
|
||||
|
||||
/**
|
||||
* Resolve mach data in the kernel via prelinked cache
|
||||
*
|
||||
* @param prelink prelink information source (i.e. Kernel MachInfo)
|
||||
*
|
||||
* @return KERN_SUCCESS if loaded
|
||||
*/
|
||||
kern_return_t initFromPrelinked(MachInfo *prelink);
|
||||
|
||||
/**
|
||||
* Resolve mach data in the kernel via filesystem access
|
||||
*
|
||||
* @param paths filesystem paths for lookup
|
||||
* @param num the number of paths passed
|
||||
*
|
||||
* @return KERN_SUCCESS if loaded
|
||||
*/
|
||||
kern_return_t initFromFileSystem(const char * const paths[], size_t num);
|
||||
|
||||
/**
|
||||
* Resolve mach data in the kernel via memory access
|
||||
*
|
||||
* @return KERN_SUCCESS if loaded
|
||||
*/
|
||||
kern_return_t initFromMemory();
|
||||
|
||||
public:
|
||||
|
||||
/**
|
||||
* Each header is assumed to fit two pages
|
||||
*/
|
||||
static constexpr size_t HeaderSize {PAGE_SIZE_64*2};
|
||||
|
||||
/**
|
||||
* Representation mode (kernel/kext)
|
||||
*/
|
||||
EXPORT const bool isKernel;
|
||||
|
||||
/**
|
||||
* Specified file identifier
|
||||
*/
|
||||
EXPORT const char *objectId {nullptr};
|
||||
|
||||
/**
|
||||
* MachInfo object generator
|
||||
*
|
||||
* @param asKernel this MachInfo represents a kernel
|
||||
* @param id kinfo identifier (e.g. CFBundleIdentifier)
|
||||
*
|
||||
* @return MachInfo object or nullptr
|
||||
*/
|
||||
static MachInfo *create(bool asKernel=false, const char *id=nullptr) { return new MachInfo(asKernel, id); }
|
||||
static void deleter(MachInfo *i NONNULL) { delete i; }
|
||||
|
||||
/**
|
||||
* Resolve mach data in the kernel
|
||||
*
|
||||
* @param paths filesystem paths for lookup
|
||||
* @param num the number of paths passed
|
||||
* @param prelink prelink information source (i.e. Kernel MachInfo)
|
||||
* @param fsfallback fallback to reading from filesystem if prelink failed
|
||||
*
|
||||
* @return KERN_SUCCESS if loaded
|
||||
*/
|
||||
EXPORT kern_return_t init(const char * const paths[], size_t num = 1, MachInfo *prelink=nullptr, bool fsfallback=false);
|
||||
|
||||
/**
|
||||
* Release the allocated memory, must be called regardless of the init error
|
||||
*/
|
||||
EXPORT void deinit();
|
||||
|
||||
/**
|
||||
* Retrieve the mach header and __TEXT addresses for KC mode
|
||||
*
|
||||
* @param slide load slide if calculating for kexts
|
||||
*
|
||||
* @return KERN_SUCCESS on success
|
||||
*/
|
||||
kern_return_t kcGetRunningAddresses(mach_vm_address_t slide);
|
||||
|
||||
/**
|
||||
* Get address slot if present
|
||||
*
|
||||
* @return address slot on success
|
||||
* @return NULL on success
|
||||
*/
|
||||
mach_vm_address_t getAddressSlot();
|
||||
|
||||
/**
|
||||
* Retrieve the mach header and __TEXT addresses
|
||||
*
|
||||
* @param slide load slide if calculating for kexts
|
||||
* @param size memory size
|
||||
* @param force force address recalculation
|
||||
*
|
||||
* @return KERN_SUCCESS on success
|
||||
*/
|
||||
EXPORT kern_return_t getRunningAddresses(mach_vm_address_t slide=0, size_t size=0, bool force=false);
|
||||
|
||||
/**
|
||||
* Set the mach header address
|
||||
*
|
||||
* @param slide load address
|
||||
* @param size memory size
|
||||
*
|
||||
* @return KERN_SUCCESS on success
|
||||
*/
|
||||
EXPORT kern_return_t setRunningAddresses(mach_vm_address_t slide=0, size_t size=0);
|
||||
|
||||
/**
|
||||
* Retrieve running mach positions
|
||||
*
|
||||
* @param header pointer to header
|
||||
* @param size file size
|
||||
*/
|
||||
EXPORT void getRunningPosition(uint8_t * &header, size_t &size);
|
||||
|
||||
/**
|
||||
* Solve a mach symbol (running addresses must be calculated)
|
||||
*
|
||||
* @param symbol symbol to solve
|
||||
*
|
||||
* @return running symbol address or 0
|
||||
*/
|
||||
EXPORT mach_vm_address_t solveSymbol(const char *symbol);
|
||||
|
||||
/**
|
||||
* Find the kernel base address (mach-o header)
|
||||
*
|
||||
* @return kernel base address or 0
|
||||
*/
|
||||
EXPORT mach_vm_address_t findKernelBase();
|
||||
|
||||
/**
|
||||
* Compare the loaded kernel with the current UUID (see loadUUID)
|
||||
*
|
||||
* @param base image base, pass 0 to use kernel base
|
||||
*
|
||||
* @return true if image uuids match
|
||||
*/
|
||||
EXPORT bool isCurrentBinary(mach_vm_address_t base=0);
|
||||
|
||||
/**
|
||||
* Enable/disable interrupt handling
|
||||
* this is similar to ml_set_interrupts_enabled except the return value
|
||||
*
|
||||
* @param enable the desired value
|
||||
*
|
||||
* @return true if changed the value and false if it is unchanged
|
||||
*/
|
||||
EXPORT static bool setInterrupts(bool enable);
|
||||
|
||||
/**
|
||||
* Enable/disable kernel memory write protection
|
||||
*
|
||||
* @param enable the desired value
|
||||
* @param lock use spinlock to disable cpu preemption (see KernelPatcher::kernelWriteLock)
|
||||
*
|
||||
* @return KERN_SUCCESS if succeeded
|
||||
*/
|
||||
EXPORT static kern_return_t setKernelWriting(bool enable, IOSimpleLock *lock);
|
||||
|
||||
/**
|
||||
* Find section bounds in a passed binary for provided cpu
|
||||
*
|
||||
* @param ptr pointer to a complete mach-o binary
|
||||
* @param sourceSize size of the mach-o binary
|
||||
* @param vmsegment returned vm segment pointer
|
||||
* @param vmsection returned vm section pointer
|
||||
* @param sectionptr returned section pointer
|
||||
* @param sectionSize returned section size or 0 on failure
|
||||
* @param segmentName segment name
|
||||
* @param sectionName section name
|
||||
* @param cpu cpu to look for in case of fat binaries
|
||||
*/
|
||||
EXPORT static void findSectionBounds(void *ptr, size_t sourceSize, vm_address_t &vmsegment, vm_address_t &vmsection, void *§ionptr, size_t §ionSize, const char *segmentName="__TEXT", const char *sectionName="__text", cpu_type_t cpu=CPU_TYPE_X86_64);
|
||||
|
||||
/**
|
||||
* Request to free file buffer resources (not including linkedit symtable)
|
||||
*/
|
||||
void freeFileBufferResources();
|
||||
|
||||
/**
|
||||
* Get fat offset of the initialised image
|
||||
*/
|
||||
off_t getFatOffset() {
|
||||
return fat_offset;
|
||||
}
|
||||
};
|
||||
|
||||
#endif /* kern_mach_hpp */
|
||||
198
EFI/OC/Kexts/Lilu.kext/Contents/Resources/Headers/kern_nvram.hpp
Normal file
198
EFI/OC/Kexts/Lilu.kext/Contents/Resources/Headers/kern_nvram.hpp
Normal file
@@ -0,0 +1,198 @@
|
||||
//
|
||||
// kern_nvram.hpp
|
||||
// Lilu
|
||||
//
|
||||
// Copyright © 2017 vit9696. All rights reserved.
|
||||
//
|
||||
|
||||
#ifndef kern_nvram_hpp
|
||||
#define kern_nvram_hpp
|
||||
|
||||
#include <Headers/kern_util.hpp>
|
||||
#include <IOKit/IOService.h>
|
||||
#include <libkern/c++/OSSymbol.h>
|
||||
#include <libkern/libkern.h>
|
||||
#include <stdint.h>
|
||||
|
||||
/**
|
||||
* Some of the most common GUIDs used for variable storage on macOS
|
||||
*/
|
||||
#define NVRAM_GLOBAL_GUID "8BE4DF61-93CA-11D2-AA0D-00E098032B8C"
|
||||
#define NVRAM_APPLE_BOOT_GUID "7C436110-AB2A-4BBB-A880-FE41995C9F82"
|
||||
#define NVRAM_APPLE_VENDOR_GUID "4D1EDE05-38C7-4A6A-9CC6-4BCCA8B38C14"
|
||||
#define NVRAM_APPLE_FILEVAULT_GUID "8D63D4FE-BD3C-4AAD-881D-86FD974BC1DF"
|
||||
#define NVRAM_APPLE_PASSWORD_UI_GUID "9EBA2D25-BBE3-4AC2-A2C6-C87F44A1278C"
|
||||
|
||||
/**
|
||||
* Custom GUIDs used for Lilu preferences
|
||||
* Must be kept in sync to OcSupportPkg/Include/Guid/OcVariables.h
|
||||
*/
|
||||
#define LILU_VENDOR_GUID "4D1FDA02-38C7-4A6A-9CC6-4BCCA8B30102"
|
||||
#define LILU_READ_ONLY_GUID "E09B9297-7928-4440-9AAB-D1F8536FBF0A"
|
||||
#define LILU_WRITE_ONLY_GUID "F0B9AF8F-2222-4840-8A37-ECF7CC8C12E1"
|
||||
|
||||
/**
|
||||
* Prefix variable name with a GUID
|
||||
*/
|
||||
#define NVRAM_PREFIX(x, y) x ":" y
|
||||
|
||||
class NVStorage {
|
||||
/**
|
||||
* Local nvram controller reference
|
||||
*/
|
||||
IORegistryEntry *dtEntry {nullptr};
|
||||
|
||||
public:
|
||||
/**
|
||||
* Compress data with a default compression algorithm
|
||||
*
|
||||
* @param src source data
|
||||
* @param size data size (updated with new size)
|
||||
* @param sensitive contains sensitive data
|
||||
*
|
||||
* @return compressed data (must be freed with Buffer::deleter) or nullptr
|
||||
*/
|
||||
EXPORT uint8_t *compress(const uint8_t *src, uint32_t &size, bool sensitive=false);
|
||||
|
||||
/**
|
||||
* Decompress data compressed with compress
|
||||
*
|
||||
* @param src compressed data
|
||||
* @param size data size (updated with new size)
|
||||
* @param sensitive contains sensitive data
|
||||
*
|
||||
* @return decompressed data (must be freed with Buffer::deleter) or nullptr
|
||||
*/
|
||||
EXPORT uint8_t *decompress(const uint8_t *src, uint32_t &size, bool sensitive=false);
|
||||
|
||||
/**
|
||||
* Value storage options
|
||||
*/
|
||||
enum Options {
|
||||
OptAuto = 0, // Default options
|
||||
OptRaw = 1, // i/o as raw buffer
|
||||
OptCompressed = 2, // Apply compression (see kern_compression.hpp)
|
||||
OptEncrypted = 4, // Apply encryption with device-unique key (see kern_crypto.hpp)
|
||||
OptChecksum = 8, // Append CRC32 checksum to the end
|
||||
OptSensitive = 16 // Value contains sensitive data
|
||||
};
|
||||
|
||||
/**
|
||||
* Prepended value header unless OptRaw is used
|
||||
* After the header the following fields should go:
|
||||
* uint8_t iv[16]; aes initialisation vector (if OptEncrypted is set)
|
||||
* uint32_t size; decryption size (if OptEncrypted is set, encrypted)
|
||||
* uint32_t size; decompression size (if OptCompressed is set, encrypted if OptEncrypted)
|
||||
* uint8_t data[]; content data (encrypted if OptEncrypted)
|
||||
* uint32_t crc32; CRC32 cheksum (if OptChecksum is set)
|
||||
*/
|
||||
struct PACKED Header {
|
||||
static constexpr uint16_t Magic = 0xC717;
|
||||
static constexpr uint8_t MaxVer = 1;
|
||||
using Checksum = uint32_t;
|
||||
|
||||
uint16_t magic {Magic};
|
||||
uint8_t version {MaxVer};
|
||||
uint8_t opts {OptAuto};
|
||||
};
|
||||
|
||||
/**
|
||||
* Attempt to connect to active nvram, may fail at early stages
|
||||
*
|
||||
* @return true on success
|
||||
*/
|
||||
EXPORT bool init();
|
||||
|
||||
/**
|
||||
* Relinquish resources used, must be called regardless of the init error
|
||||
*/
|
||||
EXPORT void deinit();
|
||||
|
||||
/**
|
||||
* Read data from nvram
|
||||
*
|
||||
* @param key key name
|
||||
* @param size amount of data read
|
||||
* @param opts bitmask of Options, may set option requirements
|
||||
* @param enckey encryption key (platform-defined if OptEncrypted is set)
|
||||
*
|
||||
* @return pointer to data (must be freed via Buffer::deleter), nullptr on failure
|
||||
*/
|
||||
EXPORT uint8_t *read(const char *key, uint32_t &size, uint8_t opts=OptAuto, const uint8_t *enckey=nullptr);
|
||||
|
||||
/**
|
||||
* Read data from nvram
|
||||
*
|
||||
* @param key key name
|
||||
* @param opts bitmask of Options, may set option requirements
|
||||
* @param enckey encryption key (platform-defined if OptEncrypted is set)
|
||||
*
|
||||
* @return pointer to data (must be freed via OSData::release), nullptr on failure
|
||||
*/
|
||||
EXPORT OSData *read(const char *key, uint8_t opts=OptAuto, const uint8_t *enckey=nullptr);
|
||||
|
||||
/**
|
||||
* Write data to nvram
|
||||
*
|
||||
* @param key key name
|
||||
* @param src source buffer
|
||||
* @param size buffer size
|
||||
* @param opts bitmask of Options
|
||||
* @param enckey encryption key (platform-defined if OptEncrypted is set)
|
||||
*
|
||||
* @return true on success
|
||||
*/
|
||||
EXPORT bool write(const char *key, const uint8_t *src, uint32_t sz, uint8_t opts=OptAuto, const uint8_t *enckey=nullptr);
|
||||
|
||||
/**
|
||||
* Write data to nvram
|
||||
*
|
||||
* @param key key name
|
||||
* @param data data object to write
|
||||
* @param opts bitmask of Options
|
||||
* @param enckey encryption key (platform-defined if OptEncrypted is set)
|
||||
*
|
||||
* @return true on success
|
||||
*/
|
||||
EXPORT bool write(const char *key, const OSData *data, uint8_t opts=OptAuto, const uint8_t *enckey=nullptr);
|
||||
|
||||
/**
|
||||
* Delete key from nvram
|
||||
*
|
||||
* @param key key name
|
||||
* @param sensitive sensitive data
|
||||
*
|
||||
* @return true on successful deletion or if key is missing
|
||||
*/
|
||||
EXPORT bool remove(const char *key, bool sensitive=false);
|
||||
|
||||
/**
|
||||
* Synchronize with nvram controller
|
||||
* This method might fail if synchronisation was done recently.
|
||||
*
|
||||
* @return true if synchronised
|
||||
*/
|
||||
EXPORT bool sync();
|
||||
|
||||
/**
|
||||
* Exports nvram to a plist file
|
||||
*
|
||||
* @param filename file path
|
||||
* @oaram max max output size
|
||||
* @param sensitive contains sensitive data
|
||||
*
|
||||
* @return true if saved
|
||||
*/
|
||||
EXPORT bool save(const char *filename, uint32_t max=0x20000, bool sensitive=false);
|
||||
|
||||
/**
|
||||
* Check whether key exists
|
||||
*
|
||||
* @param key key name
|
||||
*
|
||||
* @return true if key exists
|
||||
*/
|
||||
EXPORT bool exists(const char *key);
|
||||
};
|
||||
|
||||
#endif /* kern_nvram_hpp */
|
||||
@@ -0,0 +1,879 @@
|
||||
//
|
||||
// kern_patcher.hpp
|
||||
// Lilu
|
||||
//
|
||||
// Copyright © 2016-2017 vit9696. All rights reserved.
|
||||
//
|
||||
|
||||
#ifndef kern_patcher_hpp
|
||||
#define kern_patcher_hpp
|
||||
|
||||
#include <Headers/kern_config.hpp>
|
||||
#include <Headers/kern_compat.hpp>
|
||||
#include <Headers/kern_util.hpp>
|
||||
#include <Headers/kern_mach.hpp>
|
||||
#include <Headers/kern_disasm.hpp>
|
||||
|
||||
#include <mach/mach_types.h>
|
||||
|
||||
namespace Patch { union All; void deleter(All * NONNULL); }
|
||||
#ifdef LILU_KEXTPATCH_SUPPORT
|
||||
union OSKextLoadedKextSummaryHeaderAny;
|
||||
#endif /* LILU_KEXTPATCH_SUPPORT */
|
||||
|
||||
class KernelPatcher {
|
||||
public:
|
||||
|
||||
/**
|
||||
* Errors set by functions
|
||||
*/
|
||||
enum class Error {
|
||||
NoError,
|
||||
NoKinfoFound,
|
||||
NoSymbolFound,
|
||||
KernInitFailure,
|
||||
KernRunningInitFailure,
|
||||
KextListeningFailure,
|
||||
DisasmFailure,
|
||||
MemoryIssue,
|
||||
MemoryProtection,
|
||||
PointerRange,
|
||||
AlreadyDone,
|
||||
LockError,
|
||||
Unsupported,
|
||||
InvalidSymbolFound
|
||||
};
|
||||
|
||||
/**
|
||||
* Get last error
|
||||
*
|
||||
* @return error code
|
||||
*/
|
||||
EXPORT Error getError();
|
||||
|
||||
/**
|
||||
* Reset all the previous errors
|
||||
*/
|
||||
EXPORT void clearError();
|
||||
|
||||
/**
|
||||
* Initialise KernelPatcher, prepare for modifications
|
||||
*/
|
||||
void init();
|
||||
|
||||
/**
|
||||
* Deinitialise KernelPatcher, must be called regardless of the init error
|
||||
*/
|
||||
void deinit();
|
||||
|
||||
/**
|
||||
* Kernel write lock used for performing kernel & kext writes to disable cpu preemption
|
||||
* See MachInfo::setKernelWriting
|
||||
*/
|
||||
EXPORT static IOSimpleLock *kernelWriteLock;
|
||||
|
||||
/**
|
||||
* Kext information
|
||||
*/
|
||||
struct KextInfo;
|
||||
|
||||
#ifdef LILU_KEXTPATCH_SUPPORT
|
||||
struct KextInfo {
|
||||
static constexpr size_t Unloaded {0};
|
||||
enum SysFlags : uint64_t {
|
||||
Loaded, // invoke for kext if it is already loaded
|
||||
Reloadable, // allow the kext to unload and get patched again
|
||||
Disabled, // do not load this kext (formerly achieved pathNum = 0, this no longer works)
|
||||
FSOnly, // do not use prelinkedkernel (kextcache) as a symbol source
|
||||
FSFallback, // perform fs fallback if kextcache failed
|
||||
Reserved,
|
||||
SysFlagNum,
|
||||
};
|
||||
static constexpr uint64_t UserFlagNum {sizeof(uint64_t)-SysFlagNum};
|
||||
static_assert(UserFlagNum > 0, "There should be at least one user flag");
|
||||
const char *id {nullptr};
|
||||
const char **paths {nullptr};
|
||||
size_t pathNum {0};
|
||||
bool sys[SysFlagNum] {};
|
||||
bool user[UserFlagNum] {};
|
||||
size_t loadIndex {Unloaded}; // Updated after loading
|
||||
|
||||
/**
|
||||
* Disable this info from being used
|
||||
* May be called from onPatcherLoad callbacks to disable certain kexts
|
||||
*/
|
||||
void switchOff() {
|
||||
sys[KernelPatcher::KextInfo::Disabled] = true;
|
||||
}
|
||||
};
|
||||
|
||||
static_assert(sizeof(KextInfo) == 4 * sizeof(size_t) + sizeof(uint64_t), "KextInfo is no longer ABI compatible");
|
||||
#endif /* LILU_KEXTPATCH_SUPPORT */
|
||||
|
||||
/**
|
||||
* Loads and stores kinfo information locally
|
||||
*
|
||||
* @param id kernel item identifier
|
||||
* @param paths item filesystem path array
|
||||
* @param num number of path entries
|
||||
* @param isKernel kinfo is kernel info
|
||||
* @param fsonly avoid using prelinkedkernel for kexts
|
||||
* @param fsfallback fallback to reading from filesystem if prelink failed
|
||||
*
|
||||
* @return loaded kinfo id
|
||||
*/
|
||||
EXPORT size_t loadKinfo(const char *id, const char * const paths[], size_t num=1, bool isKernel=false, bool fsonly=false, bool fsfallback=false);
|
||||
|
||||
#ifdef LILU_KEXTPATCH_SUPPORT
|
||||
/**
|
||||
* Loads and stores kinfo information locally
|
||||
*
|
||||
* @param info kext to load, updated on success
|
||||
*
|
||||
* @return loaded kinfo id
|
||||
*/
|
||||
EXPORT size_t loadKinfo(KextInfo *info);
|
||||
#endif /* LILU_KEXTPATCH_SUPPORT */
|
||||
|
||||
/**
|
||||
* Kernel kinfo id
|
||||
*/
|
||||
static constexpr size_t KernelID {0};
|
||||
|
||||
/**
|
||||
* Update running information
|
||||
*
|
||||
* @param id loaded kinfo id
|
||||
* @param slide loaded slide
|
||||
* @param size loaded memory size
|
||||
* @param force force recalculatiob
|
||||
*
|
||||
* @return new size
|
||||
*/
|
||||
EXPORT size_t updateRunningInfo(size_t id, mach_vm_address_t slide=0, size_t size=0, bool force=false);
|
||||
|
||||
/**
|
||||
* Any kernel
|
||||
*/
|
||||
static constexpr uint32_t KernelAny {0};
|
||||
|
||||
/**
|
||||
* Check kernel compatibility
|
||||
*
|
||||
* @param min minimal requested version or KernelAny
|
||||
* @param max maximum supported version or KernelAny
|
||||
*
|
||||
* @return true on success
|
||||
*/
|
||||
EXPORT static bool compatibleKernel(uint32_t min, uint32_t max);
|
||||
|
||||
/**
|
||||
* Erase coverage instruction prefix (like inc qword ptr[]), that causes function routing to fail
|
||||
*
|
||||
* @param addr address to valid instruction code
|
||||
* @param count amount of instructions to inspect
|
||||
*/
|
||||
EXPORT void eraseCoverageInstPrefix(mach_vm_address_t addr, size_t count=5);
|
||||
|
||||
/**
|
||||
* Erase coverage instruction prefix (like inc qword ptr[]), that causes function routing to fail
|
||||
*
|
||||
* @param addr address to valid instruction code
|
||||
* @param count amount of instructions to inspect
|
||||
* @param limit amount of bytes to inspect
|
||||
*/
|
||||
EXPORT void eraseCoverageInstPrefix(mach_vm_address_t addr, size_t count, off_t limit);
|
||||
|
||||
/**
|
||||
* Solve a kinfo symbol
|
||||
*
|
||||
* @param id loaded kinfo id
|
||||
* @param symbol symbol to solve
|
||||
*
|
||||
* @return running symbol address or 0
|
||||
*/
|
||||
EXPORT mach_vm_address_t solveSymbol(size_t id, const char *symbol);
|
||||
|
||||
/**
|
||||
* Solve a kinfo symbol in range with designated type
|
||||
*
|
||||
* @param id loaded kinfo id
|
||||
* @param symbol symbol to solve
|
||||
* @param start start address range
|
||||
* @param size address range size
|
||||
* @param crash kernel panic on invalid non-zero address
|
||||
*
|
||||
* @return running symbol address or 0 casted to type T (mach_vm_address_t)
|
||||
*/
|
||||
template <typename T = mach_vm_address_t>
|
||||
inline T solveSymbol(size_t id, const char *symbol, mach_vm_address_t start, size_t size, bool crash=false) {
|
||||
auto addr = solveSymbol(id, symbol);
|
||||
if (addr) {
|
||||
if (addr >= start && addr < start + size)
|
||||
return (T)addr;
|
||||
|
||||
code = Error::InvalidSymbolFound;
|
||||
SYSTRACE("patcher", "address " PRIKADDR " is out of range " PRIKADDR " with size %lX",
|
||||
CASTKADDR(addr), CASTKADDR(start), size);
|
||||
|
||||
PANIC_COND(crash, "patcher", "address " PRIKADDR " is out of range " PRIKADDR " with size %lX",
|
||||
CASTKADDR(addr), CASTKADDR(start), size);
|
||||
}
|
||||
|
||||
return (T)nullptr;
|
||||
}
|
||||
|
||||
/**
|
||||
* Solve request to resolve multiple symbols in one shot and simplify error handling
|
||||
*
|
||||
* @seealso solveMultiple().
|
||||
*/
|
||||
struct SolveRequest {
|
||||
/**
|
||||
* The symbol to solve
|
||||
*/
|
||||
const char *symbol {nullptr};
|
||||
|
||||
/**
|
||||
* The symbol address on success, otherwise NULL.
|
||||
*/
|
||||
mach_vm_address_t *address {nullptr};
|
||||
|
||||
/**
|
||||
* Construct a solve request conveniently
|
||||
*/
|
||||
template <typename T>
|
||||
SolveRequest(const char *s, T &addr) :
|
||||
symbol(s), address(reinterpret_cast<mach_vm_address_t*>(&addr)) { }
|
||||
};
|
||||
|
||||
/**
|
||||
* Solve multiple functions with basic error handling
|
||||
*
|
||||
* @param id loaded kinfo id
|
||||
* @param requests an array of requests to solve
|
||||
* @param num requests array size
|
||||
* @param start start address range
|
||||
* @param size address range size
|
||||
* @param crash kernel panic on invalid non-zero address
|
||||
* @param force continue on first error
|
||||
*
|
||||
* @return false if at least one symbol cannot be solved.
|
||||
*/
|
||||
inline bool solveMultiple(size_t id, SolveRequest *requests, size_t num, mach_vm_address_t start, size_t size, bool crash=false, bool force=false) {
|
||||
for (size_t index = 0; index < num; index++) {
|
||||
auto result = solveSymbol(id, requests[index].symbol, start, size, crash);
|
||||
if (result) {
|
||||
*requests[index].address = result;
|
||||
} else {
|
||||
clearError();
|
||||
if (!force) return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Solve multiple functions with basic error handling
|
||||
*
|
||||
* @param id loaded kinfo id
|
||||
* @param requests an array of requests to solve
|
||||
* @param start start address range
|
||||
* @param size address range size
|
||||
* @param crash kernel panic on invalid non-zero address
|
||||
* @param force continue on first error
|
||||
*
|
||||
* @return false if at least one symbol cannot be solved.
|
||||
*/
|
||||
template <size_t N>
|
||||
inline bool solveMultiple(size_t id, SolveRequest (&requests)[N], mach_vm_address_t start, size_t size, bool crash=false, bool force=false) {
|
||||
return solveMultiple(id, requests, N, start, size, crash, force);
|
||||
}
|
||||
|
||||
/**
|
||||
* Hook kext loading and unloading to access kexts at early stage
|
||||
*/
|
||||
EXPORT void setupKextListening();
|
||||
|
||||
/**
|
||||
* Free file buffer resources and effectively make prelinked kext loading impossible
|
||||
*/
|
||||
void freeFileBufferResources();
|
||||
|
||||
/**
|
||||
* Activates monitoring functions if necessary
|
||||
*/
|
||||
void activate();
|
||||
|
||||
/**
|
||||
* Load handling structure
|
||||
*/
|
||||
class KextHandler {
|
||||
using t_handler = void (*)(KextHandler *);
|
||||
KextHandler(const char * const i, size_t idx, t_handler h, bool l, bool r) :
|
||||
id(i), index(idx), handler(h), loaded(l), reloadable(r) {}
|
||||
public:
|
||||
static KextHandler *create(const char * const i, size_t idx, t_handler h, bool l=false, bool r=false) {
|
||||
return new KextHandler(i, idx, h, l, r);
|
||||
}
|
||||
static void deleter(KextHandler *i NONNULL) {
|
||||
delete i;
|
||||
}
|
||||
|
||||
void *self {nullptr};
|
||||
const char * const id {nullptr};
|
||||
size_t index {0};
|
||||
mach_vm_address_t address {0};
|
||||
size_t size {0};
|
||||
t_handler handler {nullptr};
|
||||
bool loaded {false};
|
||||
bool reloadable {false};
|
||||
};
|
||||
|
||||
#ifdef LILU_KEXTPATCH_SUPPORT
|
||||
/**
|
||||
* Enqueue handler processing at kext loading
|
||||
*
|
||||
* @param handler handler to process
|
||||
*/
|
||||
EXPORT void waitOnKext(KextHandler *handler);
|
||||
|
||||
/**
|
||||
* Update kext handler features
|
||||
*
|
||||
* @param info loaded kext info with features
|
||||
*/
|
||||
void updateKextHandlerFeatures(KextInfo *info);
|
||||
|
||||
/**
|
||||
* Arbitrary kext find/replace patch
|
||||
*/
|
||||
struct LookupPatch {
|
||||
KextInfo *kext;
|
||||
const uint8_t *find;
|
||||
const uint8_t *replace;
|
||||
size_t size;
|
||||
size_t count;
|
||||
};
|
||||
|
||||
/**
|
||||
* Apply a find/replace patch
|
||||
*
|
||||
* @param patch patch to apply
|
||||
*/
|
||||
EXPORT void applyLookupPatch(const LookupPatch *patch);
|
||||
|
||||
/**
|
||||
* Apply a find/replace patch with additional constraints
|
||||
*
|
||||
* @param patch patch to apply
|
||||
* @param startingAddress start with this address (or kext/kernel lowest address)
|
||||
* @param maxSize maximum size to lookup (or kext/kernel max size)
|
||||
*/
|
||||
EXPORT void applyLookupPatch(const LookupPatch *patch, uint8_t *startingAddress, size_t maxSize);
|
||||
#endif /* LILU_KEXTPATCH_SUPPORT */
|
||||
|
||||
/**
|
||||
* Route function to function
|
||||
*
|
||||
* @param from function to route
|
||||
* @param to routed function
|
||||
* @param buildWrapper create entrance wrapper
|
||||
* @param kernelRoute kernel change requiring memory protection changes and patch reverting at unload
|
||||
* @param revertible patches could be reverted
|
||||
*
|
||||
* @return wrapper pointer or 0 on success
|
||||
*/
|
||||
EXPORT mach_vm_address_t routeFunction(mach_vm_address_t from, mach_vm_address_t to, bool buildWrapper=false, bool kernelRoute=true, bool revertible=true) DEPRECATE("Use routeMultiple where possible");
|
||||
|
||||
/**
|
||||
* Route function to function with long jump
|
||||
*
|
||||
* @param from function to route
|
||||
* @param to routed function
|
||||
* @param buildWrapper create entrance wrapper
|
||||
* @param kernelRoute kernel change requiring memory protection changes and patch reverting at unload
|
||||
* @param revertible patches could be reverted
|
||||
*
|
||||
* @return wrapper pointer or 0 on success
|
||||
*/
|
||||
EXPORT mach_vm_address_t routeFunctionLong(mach_vm_address_t from, mach_vm_address_t to, bool buildWrapper=false, bool kernelRoute=true, bool revertible=true) DEPRECATE("Use routeMultiple where possible");
|
||||
|
||||
/**
|
||||
* Route function to function with short jump
|
||||
*
|
||||
* @param from function to route
|
||||
* @param to routed function
|
||||
* @param buildWrapper create entrance wrapper
|
||||
* @param kernelRoute kernel change requiring memory protection changes and patch reverting at unload
|
||||
* @param revertible patches could be reverted
|
||||
*
|
||||
* @return wrapper pointer or 0 on success
|
||||
*/
|
||||
EXPORT mach_vm_address_t routeFunctionShort(mach_vm_address_t from, mach_vm_address_t to, bool buildWrapper=false, bool kernelRoute=true, bool revertible=true) DEPRECATE("Use routeMultiple where possible");
|
||||
|
||||
/**
|
||||
* Route block at assembly level
|
||||
*
|
||||
* @param from address to route
|
||||
* @param opcodes opcodes to insert
|
||||
* @param opnum number of opcodes
|
||||
* @param buildWrapper create entrance wrapper
|
||||
* @param kernelRoute kernel change requiring memory protection changes and patch reverting at unload
|
||||
*
|
||||
* @return wrapper pointer or 0 on success
|
||||
*/
|
||||
EXPORT mach_vm_address_t routeBlock(mach_vm_address_t from, const uint8_t *opcodes, size_t opnum, bool buildWrapper=false, bool kernelRoute=true);
|
||||
|
||||
/**
|
||||
* Route virtual function to function
|
||||
*
|
||||
* @param obj OSObject-compatible instance
|
||||
* @param off function offset in a virtual table (arch-neutral, i.e. divided by sizeof(uintptr_t)
|
||||
* @param func function to replace with
|
||||
* @param orgFunc pointer to store the original function
|
||||
*
|
||||
* @return true on success
|
||||
*/
|
||||
template <typename T>
|
||||
static inline bool routeVirtual(void *obj, size_t off, T func, T *orgFunc=nullptr) {
|
||||
// First OSObject (and similar) field is its virtual table.
|
||||
auto vt = obj ? reinterpret_cast<T **>(obj)[0] : nullptr;
|
||||
if (vt) {
|
||||
// Do not try to replace twice!
|
||||
if (vt[off] == func)
|
||||
return false;
|
||||
if (orgFunc) *orgFunc = vt[off];
|
||||
vt[off] = func;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Route request to simplify casting and error handling
|
||||
* See routeMultiple.
|
||||
*
|
||||
* symbol symbol to lookup
|
||||
* from solved symbol (assigned by routeMultiple)
|
||||
* to destination address
|
||||
* org trampoline storage to the original symbol
|
||||
*/
|
||||
struct RouteRequest {
|
||||
const char *symbol {nullptr};
|
||||
mach_vm_address_t from {0};
|
||||
const mach_vm_address_t to {0};
|
||||
mach_vm_address_t *org {nullptr};
|
||||
|
||||
/**
|
||||
* Construct RouteRequest for wrapping a function
|
||||
* @param s symbol to lookup
|
||||
* @param t destination address
|
||||
* @param o trampoline storage to the original symbol
|
||||
*/
|
||||
template <typename T>
|
||||
RouteRequest(const char *s, T t, mach_vm_address_t &o) :
|
||||
symbol(s), to(reinterpret_cast<mach_vm_address_t>(t)), org(&o) { }
|
||||
|
||||
/**
|
||||
* Construct RouteRequest for wrapping a function
|
||||
* @param s symbol to lookup
|
||||
* @param t destination address
|
||||
* @param o trampoline storage to the original symbol
|
||||
*/
|
||||
template <typename T, typename O>
|
||||
RouteRequest(const char *s, T t, O &o) :
|
||||
RouteRequest(s, t, reinterpret_cast<mach_vm_address_t&>(o)) { }
|
||||
|
||||
/**
|
||||
* Construct RouteRequest for routing a function
|
||||
* @param s symbol to lookup
|
||||
* @param t destination address
|
||||
*/
|
||||
template <typename T>
|
||||
RouteRequest(const char *s, T t) :
|
||||
symbol(s), to(reinterpret_cast<mach_vm_address_t>(t)) { }
|
||||
};
|
||||
|
||||
/**
|
||||
* Simple route multiple functions with basic error handling
|
||||
*
|
||||
* @param id kernel item identifier
|
||||
* @param requests an array of requests to replace
|
||||
* @param num requests array size
|
||||
* @param start start address range
|
||||
* @param size address range size
|
||||
* @param kernelRoute kernel change requiring memory protection changes and patch reverting at unload
|
||||
* @param force continue on first error
|
||||
*
|
||||
* @return false if it at least one error happened
|
||||
*/
|
||||
EXPORT bool routeMultiple(size_t id, RouteRequest *requests, size_t num, mach_vm_address_t start=0, size_t size=0, bool kernelRoute=true, bool force=false);
|
||||
|
||||
/**
|
||||
* Simple route multiple functions with basic error handling with long routes
|
||||
*
|
||||
* @param id kernel item identifier
|
||||
* @param requests an array of requests to replace
|
||||
* @param num requests array size
|
||||
* @param start start address range
|
||||
* @param size address range size
|
||||
* @param kernelRoute kernel change requiring memory protection changes and patch reverting at unload
|
||||
* @param force continue on first error
|
||||
*
|
||||
* @return false if it at least one error happened
|
||||
*/
|
||||
EXPORT bool routeMultipleLong(size_t id, RouteRequest *requests, size_t num, mach_vm_address_t start=0, size_t size=0, bool kernelRoute=true, bool force=false);
|
||||
|
||||
/**
|
||||
* Simple route multiple functions with basic error handling with short routes
|
||||
*
|
||||
* @param id kernel item identifier
|
||||
* @param requests an array of requests to replace
|
||||
* @param num requests array size
|
||||
* @param start start address range
|
||||
* @param size address range size
|
||||
* @param kernelRoute kernel change requiring memory protection changes and patch reverting at unload
|
||||
* @param force continue on first error
|
||||
*
|
||||
* @return false if it at least one error happened
|
||||
*/
|
||||
EXPORT bool routeMultipleShort(size_t id, RouteRequest *requests, size_t num, mach_vm_address_t start=0, size_t size=0, bool kernelRoute=true, bool force=false);
|
||||
|
||||
/**
|
||||
* Simple route multiple functions with basic error handling
|
||||
*
|
||||
* @param id kernel item identifier
|
||||
* @param requests an array of requests to replace
|
||||
* @param start start address range
|
||||
* @param size address range size
|
||||
* @param kernelRoute kernel change requiring memory protection changes and patch reverting at unload
|
||||
* @param force continue on first error
|
||||
*
|
||||
* @return false if it at least one error happened
|
||||
*/
|
||||
template <size_t N>
|
||||
inline bool routeMultiple(size_t id, RouteRequest (&requests)[N], mach_vm_address_t start=0, size_t size=0, bool kernelRoute=true, bool force=false) {
|
||||
return routeMultiple(id, requests, N, start, size, kernelRoute, force);
|
||||
}
|
||||
|
||||
/**
|
||||
* Simple route multiple functions with basic error handling with long routes
|
||||
*
|
||||
* @param id kernel item identifier
|
||||
* @param requests an array of requests to replace
|
||||
* @param start start address range
|
||||
* @param size address range size
|
||||
* @param kernelRoute kernel change requiring memory protection changes and patch reverting at unload
|
||||
* @param force continue on first error
|
||||
*
|
||||
* @return false if it at least one error happened
|
||||
*/
|
||||
template <size_t N>
|
||||
inline bool routeMultipleLong(size_t id, RouteRequest (&requests)[N], mach_vm_address_t start=0, size_t size=0, bool kernelRoute=true, bool force=false) {
|
||||
return routeMultipleLong(id, requests, N, start, size, kernelRoute, force);
|
||||
}
|
||||
|
||||
/**
|
||||
* Simple route multiple functions with basic error handling with long routes
|
||||
*
|
||||
* @param id kernel item identifier
|
||||
* @param requests an array of requests to replace
|
||||
* @param start start address range
|
||||
* @param size address range size
|
||||
* @param kernelRoute kernel change requiring memory protection changes and patch reverting at unload
|
||||
* @param force continue on first error
|
||||
*
|
||||
* @return false if it at least one error happened
|
||||
*/
|
||||
template <size_t N>
|
||||
inline bool routeMultipleShort(size_t id, RouteRequest (&requests)[N], mach_vm_address_t start=0, size_t size=0, bool kernelRoute=true, bool force=false) {
|
||||
return routeMultipleShort(id, requests, N, start, size, kernelRoute, force);
|
||||
}
|
||||
|
||||
/**
|
||||
* Find one pattern with optional masking within a block of memory
|
||||
*
|
||||
* @param pattern pattern to search
|
||||
* @param patternMask pattern mask
|
||||
* @param patternSize size of pattern
|
||||
* @param data a block of memory
|
||||
* @param dataSize size of memory
|
||||
* @param dataOffset data offset, to be set by this function
|
||||
*
|
||||
* @return true if pattern is found in data
|
||||
*/
|
||||
EXPORT static bool findPattern(const void *pattern, const void *patternMask, size_t patternSize, const void *data, size_t dataSize, size_t *dataOffset);
|
||||
|
||||
/**
|
||||
* Simple find and replace with masking in kernel memory.
|
||||
*/
|
||||
EXPORT static bool findAndReplaceWithMask(void *data, size_t dataSize, const void *find, size_t findSize, const void *findMask, size_t findMaskSize, const void *replace, size_t replaceSize, const void *replaceMask, size_t replaceMaskSize, size_t count=0, size_t skip=0);
|
||||
|
||||
/**
|
||||
* Simple find and replace in kernel memory.
|
||||
*/
|
||||
static inline bool findAndReplace(void *data, size_t dataSize, const void *find, size_t findSize, const void *replace, size_t replaceSize) {
|
||||
return findAndReplaceWithMask(data, dataSize, find, findSize, nullptr, 0, replace, replaceSize, nullptr, 0, 0, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Simple find and replace in kernel memory but require both `find` and `replace` buffers to have the same length
|
||||
*/
|
||||
template <size_t N>
|
||||
static inline bool findAndReplace(void *data, size_t dataSize, const uint8_t (&find)[N], const uint8_t (&replace)[N]) {
|
||||
return findAndReplace(data, dataSize, find, N, replace, N);
|
||||
}
|
||||
|
||||
/**
|
||||
* Simple find and replace with masking in kernel memory but require both `find` and `replace` buffers and masking buffers to have the same length
|
||||
*/
|
||||
template <size_t N>
|
||||
static inline bool findAndReplaceWithMask(void *data, size_t dataSize, const uint8_t (&find)[N], const uint8_t (&findMask)[N], const uint8_t (&replace)[N], const uint8_t (&replaceMask)[N], size_t count, size_t skip) {
|
||||
return findAndReplaceWithMask(data, dataSize, find, N, findMask, N, replace, N, replaceMask, N, count, skip);
|
||||
}
|
||||
|
||||
private:
|
||||
/**
|
||||
* Jump type for routing
|
||||
*/
|
||||
enum class JumpType {
|
||||
Auto,
|
||||
Long,
|
||||
Short,
|
||||
Medium
|
||||
};
|
||||
|
||||
/**
|
||||
* The minimal reasonable memory requirement
|
||||
*/
|
||||
static constexpr size_t TempExecutableMemorySize {4096};
|
||||
|
||||
/**
|
||||
* As of 10.12 we seem to be not allowed to call vm_ functions from several places including onKextSummariesUpdated.
|
||||
*/
|
||||
static uint8_t tempExecutableMemory[TempExecutableMemorySize];
|
||||
|
||||
/**
|
||||
* Offset to tempExecutableMemory that is safe to use
|
||||
*/
|
||||
size_t tempExecutableMemoryOff {0};
|
||||
|
||||
/**
|
||||
* Patcher status
|
||||
*/
|
||||
_Atomic(bool) activated = false;
|
||||
|
||||
/**
|
||||
* Read previous jump destination from function
|
||||
*
|
||||
* @param from formerly routed function
|
||||
* @param jumpType previous jump type
|
||||
*
|
||||
* @return wrapper pointer on success or 0
|
||||
*/
|
||||
mach_vm_address_t readChain(mach_vm_address_t from, JumpType &jumpType);
|
||||
|
||||
/**
|
||||
* Created routed trampoline page
|
||||
*
|
||||
* @param func original area
|
||||
* @param min minimal amount of bytes that will be overwritten
|
||||
* @param opcodes opcodes to insert before function
|
||||
* @param opnum number of opcodes
|
||||
*
|
||||
* @return trampoline pointer or 0
|
||||
*/
|
||||
mach_vm_address_t createTrampoline(mach_vm_address_t func, size_t min, const uint8_t *opcodes=nullptr, size_t opnum=0);
|
||||
|
||||
/**
|
||||
* Route function to function
|
||||
*
|
||||
* @param from function to route
|
||||
* @param to routed function
|
||||
* @param buildWrapper create entrance wrapper
|
||||
* @param kernelRoute kernel change requiring memory protection changes and patch reverting at unload
|
||||
* @param revertible patches could be reverted
|
||||
* @param jumpType jump type to use, relative short or absolute long
|
||||
* @param info info to access address slots to use for shorter routing
|
||||
* @param org write pointer to this variable
|
||||
*
|
||||
* @return wrapper pointer or 0 on success
|
||||
*/
|
||||
mach_vm_address_t routeFunctionInternal(mach_vm_address_t from, mach_vm_address_t to, bool buildWrapper=false, bool kernelRoute=true, bool revertible=true, JumpType jumpType=JumpType::Auto, MachInfo *info=nullptr, mach_vm_address_t *org=nullptr);
|
||||
|
||||
/**
|
||||
* Simple route multiple functions with basic error handling with long routes
|
||||
*
|
||||
* @param id kernel item identifier
|
||||
* @param requests an array of requests to replace
|
||||
* @param num requests array size
|
||||
* @param start start address range
|
||||
* @param size address range size
|
||||
* @param kernelRoute kernel change requiring memory protection changes and patch reverting at unload
|
||||
* @param force continue on first error
|
||||
* @param jumpType jump type to use, relative short or absolute long
|
||||
*
|
||||
* @return false if it at least one error happened
|
||||
*/
|
||||
bool routeMultipleInternal(size_t id, RouteRequest *requests, size_t num, mach_vm_address_t start=0, size_t size=0, bool kernelRoute=true, bool force=false, JumpType jumpType=JumpType::Auto);
|
||||
|
||||
#ifdef LILU_KEXTPATCH_SUPPORT
|
||||
/**
|
||||
* Process loaded kext
|
||||
*/
|
||||
void processKext(kmod_info_t *kmod, bool loaded);
|
||||
|
||||
/**
|
||||
* Process already loaded kexts once at the start
|
||||
*
|
||||
*/
|
||||
void processAlreadyLoadedKexts();
|
||||
|
||||
/**
|
||||
* Pointer to loaded kmods for kexts
|
||||
*/
|
||||
kmod_info_t **kextKmods {nullptr};
|
||||
|
||||
/**
|
||||
* Called at kext unloading if kext listening is enabled on macOS 10.6 and newer
|
||||
*/
|
||||
static OSReturn onOSKextUnload(void *thisKext);
|
||||
|
||||
/**
|
||||
* A pointer to OSKext::unload()
|
||||
*/
|
||||
mach_vm_address_t orgOSKextUnload {};
|
||||
|
||||
/**
|
||||
* Called at kext loading and unloading if kext listening is enabled on macOS 10.6 and newer
|
||||
*/
|
||||
static void onOSKextSaveLoadedKextPanicList();
|
||||
|
||||
/**
|
||||
* A pointer to OSKext::saveLoadedKextPanicList()
|
||||
*/
|
||||
mach_vm_address_t orgOSKextSaveLoadedKextPanicList {};
|
||||
|
||||
#if defined(__i386__)
|
||||
/**
|
||||
* Called at kext loading if kext listening is enabled on macOS 10.4 and 10.5
|
||||
*/
|
||||
static kern_return_t onKmodCreateInternal(kmod_info_t *kmod, kmod_t *id);
|
||||
|
||||
/**
|
||||
* A pointer to kmod_create_internal()
|
||||
*/
|
||||
mach_vm_address_t orgKmodCreateInternal {};
|
||||
#endif
|
||||
|
||||
#endif /* LILU_KEXTPATCH_SUPPORT */
|
||||
|
||||
/**
|
||||
* Kernel prelink image in case prelink is used
|
||||
*/
|
||||
MachInfo *prelinkInfo {nullptr};
|
||||
|
||||
/**
|
||||
* Loaded kernel items
|
||||
*/
|
||||
evector<MachInfo *, MachInfo::deleter> kinfos;
|
||||
|
||||
/**
|
||||
* Applied patches
|
||||
*/
|
||||
evector<Patch::All *, Patch::deleter> kpatches;
|
||||
|
||||
#ifdef LILU_KEXTPATCH_SUPPORT
|
||||
/**
|
||||
* Awaiting kext notificators
|
||||
*/
|
||||
evector<KextHandler *, KextHandler::deleter> khandlers;
|
||||
|
||||
/**
|
||||
* Awaiting already loaded kext list
|
||||
*/
|
||||
bool waitingForAlreadyLoadedKexts {false};
|
||||
|
||||
/**
|
||||
* Flag to prevent kext processing during an unload
|
||||
*/
|
||||
bool isKextUnloading {false};
|
||||
|
||||
#endif /* LILU_KEXTPATCH_SUPPORT */
|
||||
|
||||
/**
|
||||
* Current error code
|
||||
*/
|
||||
Error code {Error::NoError};
|
||||
static constexpr size_t INVALID {0};
|
||||
|
||||
/**
|
||||
* Jump instruction sizes
|
||||
*/
|
||||
static constexpr size_t SmallJump {1 + sizeof(int32_t)};
|
||||
static constexpr size_t LongJump {6 + sizeof(uintptr_t)};
|
||||
static constexpr size_t MediumJump {6};
|
||||
static constexpr uint8_t SmallJumpPrefix {0xE9};
|
||||
static constexpr uint16_t LongJumpPrefix {0x25FF};
|
||||
|
||||
/**
|
||||
* Atomic trampoline generator, wraps jumper into 64-bit or 128-bit storage
|
||||
*/
|
||||
union FunctionPatch {
|
||||
struct PACKED LongPatch {
|
||||
uint16_t opcode;
|
||||
uint32_t argument;
|
||||
uintptr_t disp;
|
||||
uint8_t org[sizeof(uint64_t) - sizeof(uintptr_t) + sizeof(uint16_t)];
|
||||
} l;
|
||||
static_assert(sizeof(l) == (sizeof(uint64_t) * 2), "Invalid long patch rounding");
|
||||
struct PACKED MediumPatch {
|
||||
uint16_t opcode;
|
||||
uint32_t argument;
|
||||
uint8_t org[2];
|
||||
} m;
|
||||
static_assert(sizeof(m) == sizeof(uint64_t), "Invalid medium patch rounding");
|
||||
struct PACKED SmallPatch {
|
||||
uint8_t opcode;
|
||||
uint32_t argument;
|
||||
uint8_t org[3];
|
||||
} s;
|
||||
static_assert(sizeof(s) == sizeof(uint64_t), "Invalid small patch rounding");
|
||||
template <typename T>
|
||||
inline void sourceIt(mach_vm_address_t source) {
|
||||
// Note, this one violates strict aliasing, but we play with the memory anyway.
|
||||
for (size_t i = 0; i < sizeof(T::org); ++i)
|
||||
reinterpret_cast<volatile T *>(this)->org[i] = *reinterpret_cast<uint8_t *>(source + offsetof(T, org) + i);
|
||||
}
|
||||
uint64_t value64;
|
||||
#if defined(__x86_64__)
|
||||
unsigned __int128 value128;
|
||||
#endif
|
||||
} patch;
|
||||
|
||||
/**
|
||||
* Possible kernel paths
|
||||
*/
|
||||
#ifdef LILU_COMPRESSION_SUPPORT
|
||||
const char *prelinkKernelPaths[7] {
|
||||
// This is the usual kernel cache place, which often the best thing to use
|
||||
"/System/Library/Caches/com.apple.kext.caches/Startup/kernelcache",
|
||||
// Otherwise fallback to one of the prelinked kernels
|
||||
// Since we always verify the LC_UUID value, trying the kernels could be done in any order.
|
||||
"/System/Library/PrelinkedKernels/prelinkedkernel", // normal
|
||||
"/macOS Install Data/Locked Files/Boot Files/prelinkedkernel", // 10.13 installer
|
||||
"/com.apple.boot.R/prelinkedkernel", // 10.12+ fusion drive installer
|
||||
"/com.apple.boot.S/System/Library/PrelinkedKernels/prelinkedkernel", // 10.11 fusion drive installer
|
||||
"/com.apple.recovery.boot/prelinkedkernel", // recovery
|
||||
"/kernelcache" // 10.7 installer
|
||||
};
|
||||
#endif
|
||||
|
||||
const char *kernelPaths[2] {
|
||||
"/System/Library/Kernels/kernel", //since 10.10
|
||||
"/mach_kernel"
|
||||
};
|
||||
};
|
||||
|
||||
#endif /* kern_patcher_hpp */
|
||||
@@ -0,0 +1,67 @@
|
||||
//
|
||||
// kern_policy.hpp
|
||||
// Lilu
|
||||
//
|
||||
// Copyright © 2016-2017 vit9696. All rights reserved.
|
||||
//
|
||||
|
||||
#ifndef kern_policy_hpp
|
||||
#define kern_policy_hpp
|
||||
|
||||
#include <Headers/kern_config.hpp>
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/proc.h>
|
||||
|
||||
#include <security/mac_framework.h>
|
||||
#include <security/mac_policy.h>
|
||||
#include <Headers/kern_util.hpp>
|
||||
|
||||
#if defined(__x86_64__)
|
||||
class Policy {
|
||||
/**
|
||||
* TrustedBSD Policy handle
|
||||
*/
|
||||
mac_policy_handle_t policyHandle {0};
|
||||
|
||||
/**
|
||||
* TrustedBSD policy configuration
|
||||
*/
|
||||
mac_policy_conf policyConf;
|
||||
public:
|
||||
/**
|
||||
* Compile-time policy constructor
|
||||
*
|
||||
* @param name policy name literal
|
||||
* @param descr policy description literal
|
||||
* @param ops policy functions
|
||||
*/
|
||||
constexpr Policy(const char *name, const char *descr, struct mac_policy_ops *ops) : policyConf{
|
||||
.mpc_name = name,
|
||||
.mpc_fullname = descr,
|
||||
.mpc_labelnames = nullptr,
|
||||
.mpc_labelname_count = 0,
|
||||
.mpc_ops = ops,
|
||||
// Our policies are loaded very early and are static. We cannot unload them.
|
||||
.mpc_loadtime_flags = 0 /*MPC_LOADTIME_FLAG_UNLOADOK*/,
|
||||
.mpc_field_off = nullptr,
|
||||
.mpc_runtime_flags = 0
|
||||
} { }
|
||||
|
||||
/**
|
||||
* Registers TrustedBSD policy
|
||||
*
|
||||
* @return true on success
|
||||
*/
|
||||
EXPORT bool registerPolicy();
|
||||
|
||||
/**
|
||||
* Unregisters TrustedBSD policy if allowed
|
||||
*
|
||||
* @return true on success
|
||||
*/
|
||||
EXPORT bool unregisterPolicy();
|
||||
};
|
||||
#endif
|
||||
|
||||
#endif /* kern_policy_hpp */
|
||||
250
EFI/OC/Kexts/Lilu.kext/Contents/Resources/Headers/kern_rtc.hpp
Normal file
250
EFI/OC/Kexts/Lilu.kext/Contents/Resources/Headers/kern_rtc.hpp
Normal file
@@ -0,0 +1,250 @@
|
||||
//
|
||||
// kern_rtc.hpp
|
||||
// Lilu
|
||||
//
|
||||
// Copyright © 2018 vit9696. All rights reserved.
|
||||
//
|
||||
|
||||
#ifndef kern_rtc_h
|
||||
#define kern_rtc_h
|
||||
|
||||
#include <Headers/kern_util.hpp>
|
||||
#include <IOKit/IOService.h>
|
||||
#include <IOKit/acpi/IOACPIPlatformDevice.h>
|
||||
#include <IOKit/IOUserClient.h>
|
||||
|
||||
class RTCStorage {
|
||||
/**
|
||||
* Apple-specific RTC checksum addresses
|
||||
*/
|
||||
static constexpr uint8_t APPLERTC_HASHED_ADDR = 0x0E;
|
||||
static constexpr uint8_t APPLERTC_CHECKSUM_ADDR1 = 0x58;
|
||||
static constexpr uint8_t APPLERTC_CHECKSUM_ADDR2 = 0x59;
|
||||
|
||||
/**
|
||||
* AppleRTC service handle
|
||||
*/
|
||||
IOService *rtcSrv {nullptr};
|
||||
|
||||
/**
|
||||
* Low-level RTC read (does not check memory availability).
|
||||
*
|
||||
* @param dev RTC ACPI device
|
||||
* @param offset offset
|
||||
*
|
||||
* @result read value
|
||||
*/
|
||||
static uint8_t readByte(IOACPIPlatformDevice *dev, uint8_t offset);
|
||||
|
||||
/**
|
||||
* Low-level RTC write (does not check memory availability).
|
||||
*
|
||||
* @param dev RTC ACPI device
|
||||
* @param offset offset
|
||||
* @param value value
|
||||
*/
|
||||
static void writeByte(IOACPIPlatformDevice *dev, uint8_t offset, uint8_t value);
|
||||
public:
|
||||
/**
|
||||
* General access RTC ports on x86 systems.
|
||||
*/
|
||||
static constexpr uint8_t R_PCH_RTC_INDEX = 0x70;
|
||||
static constexpr uint8_t R_PCH_RTC_TARGET = 0x71;
|
||||
static constexpr uint8_t R_PCH_RTC_EXT_INDEX = 0x72;
|
||||
static constexpr uint8_t R_PCH_RTC_EXT_TARGET = 0x73;
|
||||
|
||||
/**
|
||||
* RTC has N banks (we support up to 2) of memory.
|
||||
*/
|
||||
static constexpr uint8_t RTC_BANK_SIZE = 0x80;
|
||||
|
||||
/**
|
||||
* Non-ext RTC index register uses higher bit for nmi.
|
||||
*/
|
||||
static constexpr uint8_t RTC_DATA_MASK = 0x7F;
|
||||
static constexpr uint8_t RTC_NMI_MASK = 0x80;
|
||||
|
||||
/**
|
||||
* Time offsets.
|
||||
*/
|
||||
static constexpr uint8_t RTC_SEC = 0x00;
|
||||
static constexpr uint8_t RTC_MIN = 0x02;
|
||||
static constexpr uint8_t RTC_HOUR = 0x04;
|
||||
|
||||
static constexpr uint8_t RTC_DAY = 0x07;
|
||||
static constexpr uint8_t RTC_MON = 0x08;
|
||||
static constexpr uint8_t RTC_YEAR = 0x09;
|
||||
|
||||
#if __MAC_OS_X_VERSION_MIN_REQUIRED < __MAC_10_5
|
||||
using t_UserClientExternalMethod = IOReturn (*)(IORegistryEntry *service, uint32_t selector, IOExternalMethodArguments * arguments,
|
||||
IOExternalMethodDispatch * dispatch, OSObject * target, void * reference);
|
||||
static constexpr size_t UserClientExternalMethodIndex = 0x129;
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Attempt to connect to active RTC service
|
||||
*
|
||||
* @param wait wait for service availability
|
||||
*
|
||||
* @return true on success
|
||||
*/
|
||||
EXPORT bool init(bool wait=true);
|
||||
|
||||
/**
|
||||
* Release obtained RTC service
|
||||
*/
|
||||
EXPORT void deinit();
|
||||
|
||||
/**
|
||||
* Check whether extended (higher 128 bytes) is available
|
||||
*
|
||||
* @return true on success
|
||||
*/
|
||||
EXPORT bool checkExtendedMemory();
|
||||
|
||||
/**
|
||||
* Read memory from RTC
|
||||
*
|
||||
* @param off offset to read data from
|
||||
* @param size data size
|
||||
* @param buffer data buffer to read to
|
||||
*
|
||||
* @return true on success
|
||||
*/
|
||||
EXPORT bool read(uint64_t off, uint32_t size, uint8_t *buffer);
|
||||
|
||||
/**
|
||||
* Write memory to RTC
|
||||
*
|
||||
* @param off offset to write data to
|
||||
* @param size data size
|
||||
* @param buffer data buffer to write from
|
||||
*
|
||||
* @return true on success
|
||||
*/
|
||||
EXPORT bool write(uint64_t off, uint32_t size, uint8_t *buffer);
|
||||
|
||||
/**
|
||||
* Obtain RTC device for direct writing.
|
||||
* Written as inline to avoid IOACPIPlatformDevice dependency.
|
||||
*
|
||||
* @param name device name
|
||||
*
|
||||
* @return RTC ACPI device for I/O access, must be released
|
||||
*/
|
||||
static inline IOACPIPlatformDevice *getRTCDevice(const char *name = "PNP0B00") {
|
||||
IOService *rtcDev = nullptr;
|
||||
auto matching = IOService::nameMatching(name);
|
||||
if (matching) {
|
||||
#if __MAC_OS_X_VERSION_MIN_REQUIRED < __MAC_10_6
|
||||
rtcDev = IOService::waitForService(matching);
|
||||
if (rtcDev)
|
||||
rtcDev->retain();
|
||||
#else
|
||||
rtcDev = IOService::waitForMatchingService(matching);
|
||||
matching->release();
|
||||
#endif
|
||||
|
||||
} else {
|
||||
SYSLOG("rtc", "failed to allocate rtc device matching");
|
||||
}
|
||||
|
||||
if (rtcDev) {
|
||||
DBGLOG("rtc", "got rtc device");
|
||||
auto acpiDev = OSDynamicCast(IOACPIPlatformDevice, rtcDev);
|
||||
if (acpiDev) {
|
||||
DBGLOG("rtc", "got rtc acpi device");
|
||||
return acpiDev;
|
||||
} else {
|
||||
SYSLOG("rtc", "failed to obtain rtc acpi device");
|
||||
rtcDev->release();
|
||||
}
|
||||
}
|
||||
|
||||
SYSLOG("rtc", "failed to get rtc device");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
/**
|
||||
* Directly read RTC memory (UNSAFE, usage with caution!)
|
||||
*
|
||||
* @param dev RTC device
|
||||
* @param off offset to read data from
|
||||
* @param size data size
|
||||
* @param buffer data buffer to read to
|
||||
* @param introff turn interrupts off
|
||||
*
|
||||
* @return true on success
|
||||
*/
|
||||
EXPORT static void readDirect(IOACPIPlatformDevice *dev, uint8_t off, uint16_t size, uint8_t *buffer, bool introff);
|
||||
|
||||
/**
|
||||
* Directly write RTC memory (UNSAFE, usage with caution!)
|
||||
*
|
||||
* @param dev RTC device
|
||||
* @param off offset to read data from
|
||||
* @param size data size
|
||||
* @param buffer data buffer to read to
|
||||
* @param updatecrc recalculate crc on write
|
||||
* @param introff turn interrupts off
|
||||
*
|
||||
* @return true on success
|
||||
*/
|
||||
EXPORT static void writeDirect(IOACPIPlatformDevice *dev, uint8_t off, uint16_t size, uint8_t *buffer, bool updatecrc, bool introff);
|
||||
|
||||
|
||||
/**
|
||||
* Directly read RTC memory (UNSAFE, usage with caution!), this is just a compatibility function.
|
||||
*
|
||||
* @param off offset to read data from
|
||||
* @param size data size
|
||||
* @param buffer data buffer to read to
|
||||
* @param introff turn interrupts off
|
||||
*
|
||||
* @return true on success
|
||||
*/
|
||||
static inline bool readDirect(uint8_t off, uint16_t size, uint8_t *buffer, bool introff) {
|
||||
if (size > RTC_BANK_SIZE*2 - off) {
|
||||
SYSLOG("rtc", "reading unsupported size");
|
||||
return false;
|
||||
}
|
||||
|
||||
auto rtc = getRTCDevice();
|
||||
if (rtc) {
|
||||
readDirect(rtc, off, size, buffer, introff);
|
||||
rtc->release();
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Directly write RTC memory (UNSAFE, usage with caution!), this is just a compatibility function.
|
||||
*
|
||||
* @param off offset to read data from
|
||||
* @param size data size
|
||||
* @param buffer data buffer to read to
|
||||
* @param updatecrc recalculate crc on write
|
||||
* @param introff turn interrupts off
|
||||
*
|
||||
* @return true on success
|
||||
*/
|
||||
static inline bool writeDirect(uint8_t off, uint16_t size, uint8_t *buffer, bool updatecrc, bool introff) {
|
||||
if (size > RTC_BANK_SIZE*2 - off) {
|
||||
SYSLOG("rtc", "writing unsupported size");
|
||||
return false;
|
||||
}
|
||||
|
||||
auto rtc = getRTCDevice();
|
||||
if (rtc) {
|
||||
writeDirect(rtc, off, size, buffer, updatecrc, introff);
|
||||
rtc->release();
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
#endif /* kern_rtc_h */
|
||||
135
EFI/OC/Kexts/Lilu.kext/Contents/Resources/Headers/kern_time.hpp
Normal file
135
EFI/OC/Kexts/Lilu.kext/Contents/Resources/Headers/kern_time.hpp
Normal file
@@ -0,0 +1,135 @@
|
||||
//
|
||||
// kern_time.hpp
|
||||
// Lilu
|
||||
//
|
||||
// Copyright © 2018 vit9696. All rights reserved.
|
||||
//
|
||||
|
||||
#ifndef kern_time_hpp
|
||||
#define kern_time_hpp
|
||||
|
||||
#include <kern/clock.h>
|
||||
|
||||
/**
|
||||
* Obtain current system time in nanoseconds
|
||||
*
|
||||
* @return current time
|
||||
*/
|
||||
inline uint64_t getCurrentTimeNs() {
|
||||
uint64_t currt = 0;
|
||||
absolutetime_to_nanoseconds(mach_absolute_time(), &currt);
|
||||
return currt;
|
||||
}
|
||||
|
||||
/**
|
||||
* Obtain current calendar system time in nanoseconds
|
||||
*
|
||||
* @return current time
|
||||
*/
|
||||
inline uint64_t getCalendarTimeNs() {
|
||||
clock_sec_t sc;
|
||||
clock_nsec_t ns;
|
||||
clock_get_calendar_nanotime(&sc, &ns);
|
||||
return static_cast<uint64_t>(sc) * NSEC_PER_SEC + ns;
|
||||
}
|
||||
|
||||
/**
|
||||
* Obtain time passed since some timestamp in nanoseconds
|
||||
*
|
||||
* @param start starting timestamp
|
||||
* @param current timestamp to check against (pass 0 for current time)
|
||||
*
|
||||
* @return delta or 0 (if current time equals or precedeces the start)
|
||||
*/
|
||||
inline uint64_t getTimeSinceNs(uint64_t start, uint64_t current = 0) {
|
||||
if (current == 0)
|
||||
current = getCurrentTimeNs();
|
||||
if (current > start)
|
||||
return current - start;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Obtain time left till a timestamp in the future in nanoseconds
|
||||
*
|
||||
* @param start starting timestamp
|
||||
* @param timeout timeout for the event
|
||||
* @param current timestamp to check against (pass 0 for current time)
|
||||
*
|
||||
* @return delta or 0 (if the timeout is over)
|
||||
*/
|
||||
inline uint64_t getTimeLeftNs(uint64_t start, uint64_t timeout, uint64_t current = 0) {
|
||||
if (current == 0)
|
||||
current = getCurrentTimeNs();
|
||||
if (start + timeout > current)
|
||||
return start + timeout - current;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert from nanoseconds to milliseconds
|
||||
*
|
||||
* @param t timestamp in ns
|
||||
*
|
||||
* @return timestamp in ms
|
||||
*/
|
||||
constexpr uint64_t convertNsToMs(uint64_t t) {
|
||||
return t / 1000000;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert from nanoseconds to seconds
|
||||
*
|
||||
* @param t timestamp in ns
|
||||
*
|
||||
* @return timestamp in s
|
||||
*/
|
||||
constexpr uint64_t convertNsToSc(uint64_t t) {
|
||||
return t / 1000000000;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert from milliseconds to seconds
|
||||
*
|
||||
* @param t timestamp in ms
|
||||
*
|
||||
* @return timestamp in s
|
||||
*/
|
||||
constexpr uint64_t convertMsToSc(uint64_t t) {
|
||||
return t / 1000;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert from milliseconds to nanoseconds
|
||||
*
|
||||
* @param t timestamp in ms
|
||||
*
|
||||
* @return timestamp in ns
|
||||
*/
|
||||
constexpr uint64_t convertMsToNs(uint64_t t) {
|
||||
return t * 1000000;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert from seconds to nanoseconds
|
||||
*
|
||||
* @param t timestamp in s
|
||||
*
|
||||
* @return timestamp in ns
|
||||
*/
|
||||
constexpr uint64_t convertScToNs(uint64_t t) {
|
||||
return t * 1000000000;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert from seconds to milliseconds
|
||||
*
|
||||
* @param t timestamp in s
|
||||
*
|
||||
* @return timestamp in ms
|
||||
*/
|
||||
constexpr uint64_t convertScToMs(uint64_t t) {
|
||||
return t * 1000;
|
||||
}
|
||||
|
||||
#endif /* kern_time_hpp */
|
||||
635
EFI/OC/Kexts/Lilu.kext/Contents/Resources/Headers/kern_user.hpp
Normal file
635
EFI/OC/Kexts/Lilu.kext/Contents/Resources/Headers/kern_user.hpp
Normal file
@@ -0,0 +1,635 @@
|
||||
//
|
||||
// kern_user.hpp
|
||||
// Lilu
|
||||
//
|
||||
// Copyright © 2016-2017 vit9696. All rights reserved.
|
||||
//
|
||||
|
||||
#ifndef kern_user_hpp
|
||||
#define kern_user_hpp
|
||||
|
||||
#include <Headers/kern_config.hpp>
|
||||
#include <Headers/kern_patcher.hpp>
|
||||
|
||||
#include <mach/shared_region.h>
|
||||
#include <sys/kauth.h>
|
||||
|
||||
class UserPatcher {
|
||||
public:
|
||||
/**
|
||||
* Initialise UserPatcher, prepare for modifications
|
||||
*
|
||||
* @param patcher kernel patcher instance
|
||||
* @param preferSlowMode policy boot type
|
||||
*
|
||||
* @return true on success
|
||||
*/
|
||||
bool init(KernelPatcher &patcher, bool preferSlowMode);
|
||||
|
||||
/**
|
||||
* Deinitialise UserPatcher, must be called regardless of the init error
|
||||
*/
|
||||
void deinit();
|
||||
|
||||
/**
|
||||
* Obtain page protection
|
||||
*
|
||||
* @param map vm map
|
||||
* @param addr map offset
|
||||
*
|
||||
* @return protection
|
||||
*/
|
||||
EXPORT vm_prot_t getPageProtection(vm_map_t map, vm_map_address_t addr);
|
||||
|
||||
/**
|
||||
* Mach segment/section references for patch locations
|
||||
*/
|
||||
enum FileSegment : uint32_t {
|
||||
SegmentsTextStart,
|
||||
SegmentTextText = SegmentsTextStart,
|
||||
SegmentTextStubs,
|
||||
SegmentTextConst,
|
||||
SegmentTextCstring,
|
||||
SegmentTextUstring,
|
||||
SegmentsTextEnd = SegmentTextUstring,
|
||||
SegmentsDataStart,
|
||||
SegmentDataConst = SegmentsDataStart,
|
||||
SegmentDataCfstring,
|
||||
SegmentDataCommon,
|
||||
SegmentsDataEnd = SegmentDataCommon,
|
||||
SegmentTotal
|
||||
};
|
||||
|
||||
/**
|
||||
* Mach segment names kept in sync with FileSegment
|
||||
*/
|
||||
const char *fileSegments[SegmentTotal] {
|
||||
"__TEXT",
|
||||
"__TEXT",
|
||||
"__TEXT",
|
||||
"__TEXT",
|
||||
"__TEXT",
|
||||
"__DATA",
|
||||
"__DATA",
|
||||
"__DATA"
|
||||
};
|
||||
|
||||
/**
|
||||
* Mach section names kept in sync with FileSegment
|
||||
*/
|
||||
const char *fileSections[SegmentTotal] {
|
||||
"__text",
|
||||
"__stubs",
|
||||
"__const",
|
||||
"__cstring",
|
||||
"__ustring",
|
||||
"__const",
|
||||
"__cfstring",
|
||||
"__common"
|
||||
};
|
||||
|
||||
/**
|
||||
* Binary modification patches flags
|
||||
*/
|
||||
enum BinaryModPatchFlags {
|
||||
/*
|
||||
* Only applies to one process, not globally.
|
||||
*/
|
||||
LocalOnly = 1
|
||||
};
|
||||
|
||||
/**
|
||||
* Structure holding lookup-style binary patches
|
||||
*/
|
||||
struct BinaryModPatch {
|
||||
cpu_type_t cpu;
|
||||
uint32_t flags;
|
||||
const uint8_t *find;
|
||||
const uint8_t *replace;
|
||||
size_t size;
|
||||
size_t skip;
|
||||
size_t count;
|
||||
FileSegment segment;
|
||||
uint32_t section;
|
||||
};
|
||||
|
||||
#if defined(__i386__)
|
||||
static_assert(sizeof(BinaryModPatch) == 36, "BinaryModPatch 32-bit ABI compatibility failure");
|
||||
#elif defined(__x86_64__)
|
||||
static_assert(sizeof(BinaryModPatch) == 56, "BinaryModPatch 64-bit ABI compatibility failure");
|
||||
#else
|
||||
#error Unsupported arch.
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Structure describing the modifications for the binary
|
||||
*/
|
||||
struct BinaryModInfo {
|
||||
const char *path;
|
||||
BinaryModPatch *patches;
|
||||
size_t count;
|
||||
vm_address_t startTEXT;
|
||||
vm_address_t endTEXT;
|
||||
vm_address_t startDATA;
|
||||
vm_address_t endDATA;
|
||||
};
|
||||
|
||||
/**
|
||||
* Structure describing relevant processes run
|
||||
*/
|
||||
struct ProcInfo {
|
||||
/**
|
||||
* Process matching flags
|
||||
*/
|
||||
enum ProcFlags {
|
||||
MatchExact = 0,
|
||||
MatchAny = 1,
|
||||
MatchPrefix = 2,
|
||||
MatchSuffix = 4,
|
||||
MatchMask = MatchExact | MatchAny | MatchPrefix | MatchSuffix
|
||||
};
|
||||
|
||||
/**
|
||||
* Unused (aka disabled) proc info section
|
||||
*/
|
||||
static constexpr uint32_t SectionDisabled {0};
|
||||
|
||||
const char *path {nullptr};
|
||||
uint32_t len {0};
|
||||
uint32_t section {SectionDisabled};
|
||||
uint32_t flags {MatchExact};
|
||||
};
|
||||
|
||||
/**
|
||||
* External callback type for on process invocation
|
||||
*
|
||||
* @param user user provided pointer at registering
|
||||
* @param patcher user patcher instance
|
||||
* @param map process image vm_map
|
||||
* @param path path to the binary absolute or relative
|
||||
* @param len path length excluding null terminator
|
||||
*/
|
||||
using t_BinaryLoaded = void (*)(void *user, UserPatcher &patcher, vm_map_t map, const char *path, size_t len);
|
||||
|
||||
/**
|
||||
* Instructs user patcher to do further actions
|
||||
*
|
||||
* @param procs process list
|
||||
* @param procNum process list size
|
||||
* @param mods modification list
|
||||
* @param modNum modification list size
|
||||
* @param callback callback function
|
||||
* @param user pointer that will be passed to the callback function
|
||||
*/
|
||||
bool registerPatches(ProcInfo **procs, size_t procNum, BinaryModInfo **mods, size_t modNum, t_BinaryLoaded callback, void *user);
|
||||
|
||||
/**
|
||||
* Reads current process header
|
||||
*
|
||||
* @param map vm map
|
||||
* @param header Mach-O header
|
||||
*
|
||||
* @return false on failure
|
||||
*/
|
||||
EXPORT bool getTaskHeader(vm_map_t map, mach_header_64 &header);
|
||||
|
||||
/**
|
||||
* Disables dyld_shared_cache for the current process
|
||||
*
|
||||
* @param map vm map
|
||||
*
|
||||
* @return false on mach image failure
|
||||
*/
|
||||
EXPORT bool injectRestrict(vm_map_t map);
|
||||
|
||||
/**
|
||||
* Injects payload into the process right after the header with EP replacement.
|
||||
*
|
||||
* @param map vm map
|
||||
* @param payload code
|
||||
* @param size code size (up to PAGE_SIZE)
|
||||
* @param ep original entrypoint (may be written to code before copying)
|
||||
*
|
||||
* @return false on mach image failure
|
||||
*/
|
||||
EXPORT bool injectPayload(vm_map_t map, uint8_t *payload, size_t size, void *ep=nullptr);
|
||||
|
||||
/**
|
||||
* Allocates a new segment in the process.
|
||||
*
|
||||
* @param map vm map
|
||||
* @param addr allocation address (e.g. a little below SHARED_REGION_BASE_X86_64)
|
||||
* @param payload code
|
||||
* @param size code size (must be PAGE_SIZE-aligned)
|
||||
* @param prot segment protection
|
||||
*
|
||||
* @return allocated address or 0 on failure
|
||||
*/
|
||||
EXPORT vm_address_t injectSegment(vm_map_t taskPort, vm_address_t addr, uint8_t *payload, size_t size, vm_prot_t prot);
|
||||
|
||||
/**
|
||||
* Activates monitoring functions if necessary
|
||||
*/
|
||||
void activate();
|
||||
|
||||
/**
|
||||
* Get active dyld shared cache path.
|
||||
*
|
||||
* @return shared cache path constant
|
||||
*/
|
||||
EXPORT static const char *getSharedCachePath() DEPRECATE("Use matchSharedCachePath, macOS 12 has multiple caches");
|
||||
|
||||
/**
|
||||
* Check if the supplied path matches dyld shared cache path.
|
||||
*
|
||||
* @param path image path
|
||||
*
|
||||
* @return shared cache path constant
|
||||
*/
|
||||
EXPORT static bool matchSharedCachePath(const char *path);
|
||||
|
||||
private:
|
||||
|
||||
/**
|
||||
* Kernel function prototypes
|
||||
*/
|
||||
using vm_shared_region_t = void *;
|
||||
using shared_file_mapping_np = void *;
|
||||
using t_currentMap = vm_map_t (*)(void);
|
||||
using t_getTaskMap = vm_map_t (*)(task_t);
|
||||
using t_getMapMin = vm_map_offset_t (*)(vm_map_t);
|
||||
using t_vmMapSwitchProtect = void (*)(vm_map_t, boolean_t);
|
||||
using t_vmMapCheckProtection = boolean_t (*)(vm_map_t, vm_map_offset_t, vm_map_offset_t, vm_prot_t);
|
||||
using t_vmMapReadUser = kern_return_t (*)(vm_map_t, vm_map_address_t, const void *, vm_size_t);
|
||||
using t_vmMapWriteUser = kern_return_t (*)(vm_map_t, const void *, vm_map_address_t, vm_size_t);
|
||||
|
||||
/**
|
||||
* Original kernel function trampolines
|
||||
*/
|
||||
mach_vm_address_t orgCodeSignValidatePageWrapper {};
|
||||
mach_vm_address_t orgCodeSignValidateRangeWrapper {};
|
||||
mach_vm_address_t orgVmSharedRegionMapFile {};
|
||||
mach_vm_address_t orgVmSharedRegionSlide {};
|
||||
mach_vm_address_t orgVmSharedRegionSlideMojave {};
|
||||
t_currentMap orgCurrentMap {nullptr};
|
||||
t_getMapMin orgGetMapMin {nullptr};
|
||||
t_getTaskMap orgGetTaskMap {nullptr};
|
||||
t_vmMapSwitchProtect orgVmMapSwitchProtect {nullptr};
|
||||
t_vmMapCheckProtection orgVmMapCheckProtection {nullptr};
|
||||
t_vmMapReadUser orgVmMapReadUser {nullptr};
|
||||
t_vmMapWriteUser orgVmMapWriteUser {nullptr};
|
||||
mach_vm_address_t orgTaskSetMainThreadQos {};
|
||||
|
||||
/**
|
||||
* Kernel function wrappers
|
||||
*/
|
||||
static boolean_t codeSignValidatePageWrapper(void *blobs, memory_object_t pager, memory_object_offset_t page_offset, const void *data, unsigned *tainted);
|
||||
static boolean_t codeSignValidateRangeWrapper(void *blobs, memory_object_t pager, memory_object_offset_t range_offset, const void *data, memory_object_size_t data_size, unsigned *tainted);
|
||||
static vm_map_t swapTaskMap(task_t task, thread_t thread, vm_map_t map, boolean_t doswitch);
|
||||
static vm_map_t vmMapSwitch(vm_map_t map);
|
||||
static kern_return_t vmSharedRegionMapFile(vm_shared_region_t shared_region, unsigned int mappings_count, shared_file_mapping_np *mappings, memory_object_control_t file_control, memory_object_size_t file_size, void *root_dir, uint32_t slide, user_addr_t slide_start, user_addr_t slide_size);
|
||||
static void execsigs(proc_t p, thread_t thread);
|
||||
static int vmSharedRegionSlide(uint32_t slide, mach_vm_offset_t entry_start_address, mach_vm_size_t entry_size, mach_vm_offset_t slide_start, mach_vm_size_t slide_size, memory_object_control_t sr_file_control);
|
||||
static int vmSharedRegionSlideMojave(uint32_t slide, mach_vm_offset_t entry_start_address, mach_vm_size_t entry_size, mach_vm_offset_t slide_start, mach_vm_size_t slide_size, mach_vm_offset_t slid_mapping, memory_object_control_t sr_file_control);
|
||||
static void taskSetMainThreadQos(task_t task, thread_t main_thread);
|
||||
|
||||
/**
|
||||
* Applies page patches to the memory range
|
||||
*
|
||||
* @param data_ptr pages in kernel memory
|
||||
* @param data_size data size divisible by PAGE_SIZE
|
||||
*/
|
||||
void performPagePatch(const void *data_ptr, size_t data_size);
|
||||
|
||||
/**
|
||||
* dyld shared cache map entry structure
|
||||
*/
|
||||
struct MapEntry {
|
||||
const char *filename;
|
||||
size_t length;
|
||||
vm_address_t startTEXT;
|
||||
vm_address_t endTEXT;
|
||||
vm_address_t startDATA;
|
||||
vm_address_t endDATA;
|
||||
};
|
||||
|
||||
/**
|
||||
* Obtains __TEXT addresses from .map files
|
||||
*
|
||||
* @param mapBuf read .map file
|
||||
* @param mapSz .map file size
|
||||
* @param mapEntries entries to look for
|
||||
* @param nentries number of entries
|
||||
*
|
||||
* @return number of entries found
|
||||
*/
|
||||
size_t mapAddresses(const char *mapBuf, MapEntry *mapEntries, size_t nentries);
|
||||
|
||||
/**
|
||||
* Stored ASLR slide of dyld shared cache
|
||||
*/
|
||||
uint32_t storedSharedCacheSlide {0};
|
||||
|
||||
/**
|
||||
* Set once shared cache slide is defined
|
||||
*/
|
||||
bool sharedCacheSlideStored {false};
|
||||
|
||||
/**
|
||||
* Set on init to decide on whether to use __RESTRICT or patch dyld shared cache
|
||||
*/
|
||||
bool patchDyldSharedCache {false};
|
||||
|
||||
/**
|
||||
* Kernel patcher instance
|
||||
*/
|
||||
KernelPatcher *patcher {nullptr};
|
||||
|
||||
/**
|
||||
* Pending callback entry
|
||||
*/
|
||||
struct PendingUser {
|
||||
/**
|
||||
* Patch requested for path
|
||||
*/
|
||||
char path[MAXPATHLEN] {};
|
||||
|
||||
/**
|
||||
* Patch requested for path
|
||||
*/
|
||||
uint32_t pathLen {0};
|
||||
};
|
||||
|
||||
/**
|
||||
* Stored pending callback
|
||||
*/
|
||||
ThreadLocal<PendingUser *, 32> pending;
|
||||
|
||||
/**
|
||||
* Current minimal proc name length
|
||||
*/
|
||||
uint32_t currentMinProcLength {0};
|
||||
|
||||
/**
|
||||
* Provided binary modification list
|
||||
*/
|
||||
BinaryModInfo **binaryMod {nullptr};
|
||||
|
||||
/**
|
||||
* Amount of provided binary modifications
|
||||
*/
|
||||
size_t binaryModSize {0};
|
||||
|
||||
/**
|
||||
* Provided process list
|
||||
*/
|
||||
ProcInfo **procInfo {nullptr};
|
||||
|
||||
/**
|
||||
* Amount of provided processes
|
||||
*/
|
||||
size_t procInfoSize {0};
|
||||
|
||||
/**
|
||||
* Provided global callback for on proc invocation
|
||||
*/
|
||||
ppair<t_BinaryLoaded, void *> userCallback {};
|
||||
|
||||
/**
|
||||
* Applies dyld shared cache patches
|
||||
*
|
||||
* @param map current process map
|
||||
* @param slide ASLR offset
|
||||
* @param cpu cache cpu type
|
||||
* @param restore true to rollback the changes
|
||||
*/
|
||||
void patchSharedCache(vm_map_t map, uint32_t slide, cpu_type_t cpu, bool applyChanges=true);
|
||||
|
||||
/**
|
||||
* Structure holding userspace lookup patches
|
||||
*/
|
||||
struct LookupStorage {
|
||||
struct PatchRef {
|
||||
size_t i {0};
|
||||
evector<off_t> pageOffs;
|
||||
evector<off_t> segOffs;
|
||||
static PatchRef *create() {
|
||||
return new PatchRef;
|
||||
}
|
||||
static void deleter(PatchRef *r NONNULL) {
|
||||
r->pageOffs.deinit();
|
||||
r->segOffs.deinit();
|
||||
delete r;
|
||||
}
|
||||
};
|
||||
|
||||
const BinaryModInfo *mod {nullptr};
|
||||
evector<PatchRef *, PatchRef::deleter> refs;
|
||||
Page *page {nullptr};
|
||||
vm_address_t pageOff {0};
|
||||
|
||||
static LookupStorage *create() {
|
||||
auto p = new LookupStorage;
|
||||
if (p) {
|
||||
p->page = Page::create();
|
||||
if (!p->page) {
|
||||
deleter(p);
|
||||
p = nullptr;
|
||||
}
|
||||
}
|
||||
return p;
|
||||
}
|
||||
|
||||
static void deleter(LookupStorage *p NONNULL) {
|
||||
if (p->page) {
|
||||
Page::deleter(p->page);
|
||||
p->page = nullptr;
|
||||
}
|
||||
p->refs.deinit();
|
||||
delete p;
|
||||
}
|
||||
};
|
||||
|
||||
struct Lookup {
|
||||
uint32_t offs[4] {};
|
||||
static constexpr size_t matchNum {4};
|
||||
evector<uint64_t> c[matchNum];
|
||||
};
|
||||
|
||||
evector<LookupStorage *, LookupStorage::deleter> lookupStorage;
|
||||
Lookup lookup;
|
||||
|
||||
/**
|
||||
* Restrict 64-bit entry overlapping DYLD_SHARED_CACHE to enforce manual library loading
|
||||
*/
|
||||
segment_command_64 restrictSegment64 {
|
||||
LC_SEGMENT_64,
|
||||
sizeof(segment_command_64),
|
||||
"__RESTRICT",
|
||||
SHARED_REGION_BASE_X86_64,
|
||||
1, 0, 0, 0, 0, 0, 0
|
||||
};
|
||||
|
||||
/**
|
||||
* Restrict 32-bit entry overlapping DYLD_SHARED_CACHE to enforce manual library loading
|
||||
*/
|
||||
segment_command restrictSegment32 {
|
||||
LC_SEGMENT,
|
||||
sizeof(segment_command),
|
||||
"__RESTRICT",
|
||||
SHARED_REGION_BASE_I386,
|
||||
1, 0, 0, 0, 0, 0, 0
|
||||
};
|
||||
|
||||
/**
|
||||
* Temporary buffer for reading image data
|
||||
*/
|
||||
uint8_t tmpBufferData[PAGE_SIZE*3] {};
|
||||
|
||||
/**
|
||||
* Kernel auth listener handle
|
||||
*/
|
||||
kauth_listener_t listener {nullptr};
|
||||
|
||||
/**
|
||||
* Patcher status
|
||||
*/
|
||||
_Atomic(bool) activated = false;
|
||||
|
||||
/**
|
||||
* Validation cookie
|
||||
*/
|
||||
void *cookie {nullptr};
|
||||
|
||||
/**
|
||||
* Flags for codesign (PL) offset in struct proc. (uint32_t p_csflags)
|
||||
*/
|
||||
size_t csFlagsOffset {0};
|
||||
|
||||
/**
|
||||
* Exec callback
|
||||
*
|
||||
* @param credential kauth credential
|
||||
* @param idata cookie
|
||||
* @param action passed action, we only need KAUTH_FILEOP_EXEC
|
||||
* @param arg0 pointer to vnode (vnode *) for executable
|
||||
* @param arg1 pointer to path (char *) to executable
|
||||
*
|
||||
* @return 0 to allow further execution
|
||||
*/
|
||||
static int execListener(kauth_cred_t /* credential */, void *idata, kauth_action_t action, uintptr_t /* arg0 */, uintptr_t arg1, uintptr_t, uintptr_t);
|
||||
|
||||
/**
|
||||
* Unrestricted vm_protect, that takes care of Mojave codesign limitations for everyone's good.
|
||||
* See vm_protect description.
|
||||
*/
|
||||
kern_return_t vmProtect(vm_map_t map, vm_offset_t start, vm_size_t size, boolean_t set_maximum, vm_prot_t new_protection);
|
||||
|
||||
/**
|
||||
* Callback invoked at process loading
|
||||
*
|
||||
* @param path binary path
|
||||
* @param len path length
|
||||
*/
|
||||
void onPath(const char *path, uint32_t len);
|
||||
|
||||
/**
|
||||
* Reads files from BinaryModInfos and prepares lookupStorage
|
||||
*
|
||||
* @return true on success
|
||||
*/
|
||||
bool loadFilesForPatching();
|
||||
|
||||
/**
|
||||
* Reads dyld shared cache and obtains segment offsets
|
||||
*
|
||||
* @return true on success
|
||||
*/
|
||||
bool loadDyldSharedCacheMapping();
|
||||
|
||||
/**
|
||||
* Prepares quick page lookup based on lookupStorage values
|
||||
*
|
||||
* @return true on success
|
||||
*/
|
||||
bool loadLookups();
|
||||
|
||||
/**
|
||||
* Hooks memory access to get ready for patching
|
||||
*
|
||||
* @return true on success
|
||||
*/
|
||||
bool hookMemoryAccess();
|
||||
|
||||
/**
|
||||
* Peforms the actual binary patching
|
||||
*
|
||||
* @param map vm map
|
||||
* @param path binary path
|
||||
* @param len path length
|
||||
*/
|
||||
void patchBinary(vm_map_t map, const char *path, uint32_t len);
|
||||
|
||||
/**
|
||||
* DYLD shared cache map path for 10.10+ on Haswell
|
||||
*/
|
||||
static constexpr const char *SharedCacheMapHaswell {"/private/var/db/dyld/dyld_shared_cache_x86_64h.map"};
|
||||
|
||||
/**
|
||||
* DYLD shared cache map path for all other systems and older CPUs
|
||||
*/
|
||||
static constexpr const char *SharedCacheMapLegacy {"/private/var/db/dyld/dyld_shared_cache_x86_64.map"};
|
||||
|
||||
/**
|
||||
* DYLD shared cache path on Haswell+ before Big Sur
|
||||
*/
|
||||
static constexpr const char *sharedCacheHaswell {"/private/var/db/dyld/dyld_shared_cache_x86_64h"};
|
||||
|
||||
/**
|
||||
* DYLD shared cache path on older systems before Big Sur
|
||||
*/
|
||||
static constexpr const char *sharedCacheLegacy {"/private/var/db/dyld/dyld_shared_cache_x86_64"};
|
||||
|
||||
/**
|
||||
* DYLD shared cache map path on Haswell+ on Big Sur
|
||||
*/
|
||||
static constexpr const char *bigSurSharedCacheMapHaswell {"/System/Library/dyld/dyld_shared_cache_x86_64h.map"};
|
||||
|
||||
/**
|
||||
* DYLD shared cache map path on older systems on Big Sur
|
||||
*/
|
||||
static constexpr const char *bigSurSharedCacheMapLegacy {"/System/Library/dyld/dyld_shared_cache_x86_64.map"};
|
||||
|
||||
/**
|
||||
* DYLD shared cache path on Haswell+ on Big Sur
|
||||
*/
|
||||
static constexpr const char *bigSurSharedCacheHaswell {"/System/Library/dyld/dyld_shared_cache_x86_64h"};
|
||||
|
||||
/**
|
||||
* DYLD shared cache path on older systems on Big Sur
|
||||
*/
|
||||
static constexpr const char *bigSurSharedCacheLegacy {"/System/Library/dyld/dyld_shared_cache_x86_64"};
|
||||
|
||||
/**
|
||||
* DYLD shared cache map path on Haswell+ on Ventura
|
||||
*/
|
||||
static constexpr const char *venturaSharedCacheMapHaswell {"/System/Volumes/Preboot/Cryptexes/OS/System/Library/dyld/dyld_shared_cache_x86_64h.map"};
|
||||
|
||||
/**
|
||||
* DYLD shared cache map path on older systems on Ventura
|
||||
*/
|
||||
static constexpr const char *venturaSharedCacheMapLegacy {"/System/Volumes/Preboot/Cryptexes/OS/System/Library/dyld/dyld_shared_cache_x86_64.map"};
|
||||
|
||||
/**
|
||||
* DYLD shared cache path on Haswell+ on Ventura
|
||||
*/
|
||||
static constexpr const char *venturaSharedCacheHaswell {"/System/Volumes/Preboot/Cryptexes/OS/System/Library/dyld/dyld_shared_cache_x86_64h"};
|
||||
|
||||
/**
|
||||
* DYLD shared cache path on older systems on Ventura
|
||||
*/
|
||||
static constexpr const char *venturaSharedCacheLegacy {"/System/Volumes/Preboot/Cryptexes/OS/System/Library/dyld/dyld_shared_cache_x86_64"};
|
||||
|
||||
};
|
||||
|
||||
#endif /* kern_user_hpp */
|
||||
1224
EFI/OC/Kexts/Lilu.kext/Contents/Resources/Headers/kern_util.hpp
Normal file
1224
EFI/OC/Kexts/Lilu.kext/Contents/Resources/Headers/kern_util.hpp
Normal file
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,85 @@
|
||||
//
|
||||
// kern_version.hpp
|
||||
// Lilu
|
||||
//
|
||||
// Copyright © 2016-2020 vit9696. All rights reserved.
|
||||
//
|
||||
|
||||
#ifndef kern_version_hpp
|
||||
#define kern_version_hpp
|
||||
|
||||
#include <Headers/kern_util.hpp>
|
||||
|
||||
#include <stdint.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
/**
|
||||
* Slightly non-standard helpers to get the date in a YYYY-MM-DD format.
|
||||
*/
|
||||
template <size_t i>
|
||||
inline constexpr char getBuildYear() {
|
||||
static_assert(i < 4, "Year consists of four digits");
|
||||
return __DATE__[7+i];
|
||||
}
|
||||
|
||||
template <size_t i>
|
||||
inline constexpr char getBuildMonth() {
|
||||
static_assert(i < 2, "Month consists of two digits");
|
||||
auto mon = static_cast<uint32_t>(__DATE__[0])
|
||||
| (static_cast<uint32_t>(__DATE__[1]) << 8U)
|
||||
| (static_cast<uint32_t>(__DATE__[2]) << 16U)
|
||||
| (static_cast<uint32_t>(__DATE__[3]) << 24U);
|
||||
switch (mon) {
|
||||
case ' naJ':
|
||||
return "01"[i];
|
||||
case ' beF':
|
||||
return "02"[i];
|
||||
case ' raM':
|
||||
return "03"[i];
|
||||
case ' rpA':
|
||||
return "04"[i];
|
||||
case ' yaM':
|
||||
return "05"[i];
|
||||
case ' nuJ':
|
||||
return "06"[i];
|
||||
case ' luJ':
|
||||
return "07"[i];
|
||||
case ' guA':
|
||||
return "08"[i];
|
||||
case ' peS':
|
||||
return "09"[i];
|
||||
case ' tcO':
|
||||
return "10"[i];
|
||||
case ' voN':
|
||||
return "11"[i];
|
||||
case ' ceD':
|
||||
return "12"[i];
|
||||
default:
|
||||
return '0';
|
||||
}
|
||||
}
|
||||
|
||||
template <size_t i>
|
||||
inline constexpr char getBuildDay() {
|
||||
static_assert(i < 2, "Day consists of two digits");
|
||||
if (i == 0 && __DATE__[4+i] == ' ')
|
||||
return '0';
|
||||
return __DATE__[4+i];
|
||||
}
|
||||
|
||||
#if !defined(LILU_CUSTOM_KMOD_INIT) || !defined(LILU_CUSTOM_IOKIT_INIT) || defined(LILU_USE_KEXT_VERSION)
|
||||
|
||||
static const char kextVersion[] {
|
||||
#ifdef DEBUG
|
||||
'D', 'B', 'G', '-',
|
||||
#else
|
||||
'R', 'E', 'L', '-',
|
||||
#endif
|
||||
xStringify(MODULE_VERSION)[0], xStringify(MODULE_VERSION)[2], xStringify(MODULE_VERSION)[4], '-',
|
||||
getBuildYear<0>(), getBuildYear<1>(), getBuildYear<2>(), getBuildYear<3>(), '-',
|
||||
getBuildMonth<0>(), getBuildMonth<1>(), '-', getBuildDay<0>(), getBuildDay<1>(), '\0'
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
#endif /* kern_version_hpp */
|
||||
@@ -0,0 +1,53 @@
|
||||
//
|
||||
// kern_start.hpp
|
||||
// AppleALC
|
||||
//
|
||||
// Copyright © 2016 vit9696. All rights reserved.
|
||||
//
|
||||
|
||||
#ifndef kern_start_hpp
|
||||
#define kern_start_hpp
|
||||
|
||||
#include <Headers/kern_util.hpp>
|
||||
|
||||
#include <IOKit/IOService.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
struct PluginConfiguration {
|
||||
const char *product; // Product name (e.g. xStringify(PRODUCT_NAME))
|
||||
size_t version; // Product version (e.g. parseModuleVersion(xStringify(MODULE_VERSION)))
|
||||
uint32_t runmode; // Product supported environments (e.g. LiluAPI::AllowNormal)
|
||||
const char **disableArg; // Pointer to disabling boot arguments array
|
||||
size_t disableArgNum; // Number of disabling boot arguments
|
||||
const char **debugArg; // Pointer to debug boot arguments array
|
||||
size_t debugArgNum; // Number of debug boot arguments
|
||||
const char **betaArg; // Pointer to beta boot arguments array
|
||||
size_t betaArgNum; // Number of beta boot arguments
|
||||
KernelVersion minKernel; // Minimal required kernel version
|
||||
KernelVersion maxKernel; // Maximum supported kernel version
|
||||
void (*pluginStart)(); // Main function
|
||||
};
|
||||
|
||||
#ifndef LILU_CUSTOM_KMOD_INIT
|
||||
|
||||
extern PluginConfiguration ADDPR(config);
|
||||
|
||||
extern bool ADDPR(startSuccess);
|
||||
|
||||
#endif /* LILU_CUSTOM_KMOD_INIT */
|
||||
|
||||
#ifndef LILU_CUSTOM_IOKIT_INIT
|
||||
|
||||
class EXPORT PRODUCT_NAME : public IOService {
|
||||
OSDeclareDefaultStructors(PRODUCT_NAME)
|
||||
public:
|
||||
IOService *probe(IOService *provider, SInt32 *score) override;
|
||||
bool start(IOService *provider) override;
|
||||
void stop(IOService *provider) override;
|
||||
};
|
||||
|
||||
extern PRODUCT_NAME *ADDPR(selfInstance);
|
||||
|
||||
#endif /* LILU_CUSTOM_IOKIT_INIT */
|
||||
|
||||
#endif /* kern_start_hpp */
|
||||
@@ -0,0 +1,99 @@
|
||||
//
|
||||
// plugin_start.cpp
|
||||
// Lilu
|
||||
//
|
||||
// Copyright © 2016-2017 vit9696. All rights reserved.
|
||||
//
|
||||
|
||||
#include <Headers/plugin_start.hpp>
|
||||
#include <Headers/kern_api.hpp>
|
||||
#include <Headers/kern_util.hpp>
|
||||
#include <Headers/kern_version.hpp>
|
||||
|
||||
#ifndef LILU_CUSTOM_KMOD_INIT
|
||||
bool ADDPR(startSuccess) = false;
|
||||
#else
|
||||
// Workaround custom kmod code and enable by default
|
||||
bool ADDPR(startSuccess) = true;
|
||||
#endif /* LILU_CUSTOM_KMOD_INIT */
|
||||
|
||||
bool ADDPR(debugEnabled) = false;
|
||||
uint32_t ADDPR(debugPrintDelay) = 0;
|
||||
|
||||
#ifndef LILU_CUSTOM_IOKIT_INIT
|
||||
|
||||
OSDefineMetaClassAndStructors(PRODUCT_NAME, IOService)
|
||||
|
||||
PRODUCT_NAME *ADDPR(selfInstance) = nullptr;
|
||||
|
||||
IOService *PRODUCT_NAME::probe(IOService *provider, SInt32 *score) {
|
||||
ADDPR(selfInstance) = this;
|
||||
setProperty("VersionInfo", kextVersion);
|
||||
auto service = IOService::probe(provider, score);
|
||||
return ADDPR(startSuccess) ? service : nullptr;
|
||||
}
|
||||
|
||||
bool PRODUCT_NAME::start(IOService *provider) {
|
||||
ADDPR(selfInstance) = this;
|
||||
if (!IOService::start(provider)) {
|
||||
SYSLOG("init", "failed to start the parent");
|
||||
return false;
|
||||
}
|
||||
|
||||
return ADDPR(startSuccess);
|
||||
}
|
||||
|
||||
void PRODUCT_NAME::stop(IOService *provider) {
|
||||
ADDPR(selfInstance) = nullptr;
|
||||
IOService::stop(provider);
|
||||
}
|
||||
|
||||
#endif /* LILU_CUSTOM_IOKIT_INIT */
|
||||
|
||||
#ifndef LILU_CUSTOM_KMOD_INIT
|
||||
|
||||
EXPORT extern "C" kern_return_t ADDPR(kern_start)(kmod_info_t *, void *) {
|
||||
// This is an ugly hack necessary on some systems where buffering kills most of debug output.
|
||||
lilu_get_boot_args("liludelay", &ADDPR(debugPrintDelay), sizeof(ADDPR(debugPrintDelay)));
|
||||
|
||||
auto error = lilu.requestAccess();
|
||||
if (error == LiluAPI::Error::NoError) {
|
||||
error = lilu.shouldLoad(ADDPR(config).product, ADDPR(config).version, ADDPR(config).runmode, ADDPR(config).disableArg, ADDPR(config).disableArgNum,
|
||||
ADDPR(config).debugArg, ADDPR(config).debugArgNum, ADDPR(config).betaArg, ADDPR(config).betaArgNum, ADDPR(config).minKernel,
|
||||
ADDPR(config).maxKernel, ADDPR(debugEnabled));
|
||||
|
||||
if (error == LiluAPI::Error::NoError) {
|
||||
DBGLOG("init", "%s bootstrap %s", xStringify(PRODUCT_NAME), kextVersion);
|
||||
(void)kextVersion;
|
||||
ADDPR(startSuccess) = true;
|
||||
ADDPR(config).pluginStart();
|
||||
} else {
|
||||
SYSLOG("init", "parent said we should not continue %d", error);
|
||||
}
|
||||
|
||||
lilu.releaseAccess();
|
||||
} else {
|
||||
SYSLOG("init", "failed to call parent %d", error);
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < ADDPR(config).debugArgNum; i++) {
|
||||
if (checkKernelArgument(ADDPR(config).debugArg[i])) {
|
||||
ADDPR(debugEnabled) = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (checkKernelArgument("-liludbgall"))
|
||||
ADDPR(debugEnabled) = true;
|
||||
|
||||
// Report success but actually do not start and let I/O Kit unload us.
|
||||
// This works better and increases boot speed in some cases.
|
||||
return KERN_SUCCESS;
|
||||
}
|
||||
|
||||
EXPORT extern "C" kern_return_t ADDPR(kern_stop)(kmod_info_t *, void *) {
|
||||
// It is not safe to unload Lilu plugins unless they were disabled!
|
||||
return ADDPR(startSuccess) ? KERN_FAILURE : KERN_SUCCESS;
|
||||
}
|
||||
|
||||
#endif /* LILU_CUSTOM_KMOD_INIT */
|
||||
@@ -0,0 +1,57 @@
|
||||
#!/bin/bash
|
||||
#
|
||||
# build.tool
|
||||
# Lilu
|
||||
#
|
||||
# Copyright © 2018 vit9696. All rights reserved.
|
||||
#
|
||||
|
||||
cd $(dirname "$0") || exit 1
|
||||
|
||||
rm -f *.o *.bin wrappers.inc entry32 entry64
|
||||
|
||||
clang -m32 -c entry32.S || exit 1
|
||||
clang -m64 -c entry64.S || exit 1
|
||||
|
||||
clang -m32 entry32.o -o entry32 || exit 1
|
||||
clang -m64 entry64.o -o entry64 || exit 1
|
||||
|
||||
if [ "$(nm entry32.o | grep '00000000 T _main')" == "" ] || [ "$(nm entry64.o | grep '0000000000000000 T _main')" == "" ]; then
|
||||
echo "Invalid main address"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
otool -t entry32 | grep -E '^0000' | sed 's#^[0-9a-f]*##' | xxd -r -p > entry32.bin
|
||||
otool -t entry64 | grep -E '^0000' | sed 's#^[0-9a-f]*##' | xxd -r -p > entry64.bin
|
||||
|
||||
sz32=$(stat -f '%z' entry32.bin)
|
||||
sz64=$(stat -f '%z' entry64.bin)
|
||||
|
||||
btr32=$(nm entry32.o | grep -E 't booter$' | cut -f1 -d' ')
|
||||
btr64=$(nm entry64.o | grep -E 't booter$' | cut -f1 -d' ')
|
||||
|
||||
ep32=$(nm entry32.o | grep -E 't entrypoint$' | cut -f1 -d' ')
|
||||
ep64=$(nm entry64.o | grep -E 't entrypoint$' | cut -f1 -d' ')
|
||||
|
||||
echo '//' > wrappers.inc
|
||||
echo '// wrappers.inc' >> wrappers.inc
|
||||
echo '// Lilu' >> wrappers.inc
|
||||
echo '//' >> wrappers.inc
|
||||
echo '// Copyright © 2018 vit9696. All rights reserved.' >> wrappers.inc
|
||||
echo '//' >> wrappers.inc
|
||||
echo '' >> wrappers.inc
|
||||
echo '// This is an autogenerated file, do not edit!' >> wrappers.inc
|
||||
echo 'static uint8_t entryWrapper32[] = {' >> wrappers.inc
|
||||
cat entry32.bin | xxd -i >> wrappers.inc
|
||||
echo '};' >> wrappers.inc
|
||||
echo 'static uint8_t entryWrapper64[] = {' >> wrappers.inc
|
||||
cat entry64.bin | xxd -i >> wrappers.inc
|
||||
echo '};' >> wrappers.inc
|
||||
echo "static_assert(sizeof(entryWrapper32) == ${sz32}, \"Invalid entryWrapper32 size\");" >> wrappers.inc
|
||||
echo "static_assert(sizeof(entryWrapper64) == ${sz64}, \"Invalid entryWrapper64 size\");" >> wrappers.inc
|
||||
echo "static constexpr size_t EntryWrapper32Booter {0x${btr32}};" >> wrappers.inc
|
||||
echo "static constexpr size_t EntryWrapper64Booter {0x${btr64}};" >> wrappers.inc
|
||||
echo "static constexpr size_t EntryWrapper32Entry {0x${ep32}};" >> wrappers.inc
|
||||
echo "static constexpr size_t EntryWrapper64Entry {0x${ep64}};" >> wrappers.inc
|
||||
|
||||
rm -f *.o *.bin entry32 entry64
|
||||
@@ -0,0 +1,41 @@
|
||||
#
|
||||
# entry32.S
|
||||
# Lilu
|
||||
#
|
||||
# Copyright © 2018 vit9696. All rights reserved.
|
||||
#
|
||||
|
||||
.text
|
||||
.global _main
|
||||
_main:
|
||||
push %ebp
|
||||
mov %esp, %ebp
|
||||
# ensure 16-byte alignment
|
||||
and $0xfffffff0, %esp
|
||||
# int main(int argc, const char* argv[], const char* envp[], const char* apple[]);
|
||||
push 20(%ebp)
|
||||
push 16(%ebp)
|
||||
push 12(%ebp)
|
||||
push 8(%ebp)
|
||||
call get_booter
|
||||
# entrypoint-compatible wrapper
|
||||
booter:
|
||||
.word 0xFFFF
|
||||
.word 0xFFFF
|
||||
get_booter:
|
||||
pop %edx
|
||||
mov (%edx), %edx
|
||||
call *%edx
|
||||
xor %eax, %eax
|
||||
mov %ebp, %esp
|
||||
pop %ebp
|
||||
call get_entrypoint
|
||||
# original entrypoint (main)
|
||||
entrypoint:
|
||||
.word 0xFFFF
|
||||
.word 0xFFFF
|
||||
get_entrypoint:
|
||||
pop %edx
|
||||
mov (%edx), %edx
|
||||
jmp *%edx
|
||||
_end:
|
||||
@@ -0,0 +1,41 @@
|
||||
#
|
||||
# entry64.S
|
||||
# Lilu
|
||||
#
|
||||
# Copyright © 2018 vit9696. All rights reserved.
|
||||
#
|
||||
|
||||
.text
|
||||
.global _main
|
||||
_main:
|
||||
push %rbp
|
||||
mov %rsp, %rbp
|
||||
# ensure 16-byte alignment
|
||||
and $0xfffffffffffffff0, %rsp
|
||||
# int main(int argc, const char* argv[], const char* envp[], const char* apple[]);
|
||||
push %rdi
|
||||
push %rsi
|
||||
push %rdx
|
||||
push %rcx
|
||||
call *booter(%rip)
|
||||
xor %eax, %eax
|
||||
pop %rcx
|
||||
pop %rdx
|
||||
pop %rsi
|
||||
pop %rdi
|
||||
mov %rbp, %rsp
|
||||
pop %rbp
|
||||
jmp *entrypoint(%rip)
|
||||
# original entrypoint (main)
|
||||
entrypoint:
|
||||
.word 0xFFFF
|
||||
.word 0xFFFF
|
||||
.word 0xFFFF
|
||||
.word 0xFFFF
|
||||
# entrypoint-compatible wrapper
|
||||
booter:
|
||||
.word 0xFFFF
|
||||
.word 0xFFFF
|
||||
.word 0xFFFF
|
||||
.word 0xFFFF
|
||||
_end:
|
||||
@@ -0,0 +1,28 @@
|
||||
//
|
||||
// wrappers.inc
|
||||
// Lilu
|
||||
//
|
||||
// Copyright © 2018 vit9696. All rights reserved.
|
||||
//
|
||||
|
||||
// This is an autogenerated file, do not edit!
|
||||
static uint8_t entryWrapper32[] = {
|
||||
0x55, 0x89, 0xe5, 0x83, 0xe4, 0xf0, 0xff, 0x75, 0x14, 0xff, 0x75, 0x10,
|
||||
0xff, 0x75, 0x0c, 0xff, 0x75, 0x08, 0xe8, 0x04, 0x00, 0x00, 0x00, 0xff,
|
||||
0xff, 0xff, 0xff, 0x5a, 0x8b, 0x12, 0xff, 0xd2, 0x31, 0xc0, 0x89, 0xec,
|
||||
0x5d, 0xe8, 0x04, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x5a, 0x8b,
|
||||
0x12, 0xff, 0xe2
|
||||
};
|
||||
static uint8_t entryWrapper64[] = {
|
||||
0x55, 0x48, 0x89, 0xe5, 0x48, 0x83, 0xe4, 0xf0, 0x57, 0x56, 0x52, 0x51,
|
||||
0xff, 0x15, 0x18, 0x00, 0x00, 0x00, 0x31, 0xc0, 0x59, 0x5a, 0x5e, 0x5f,
|
||||
0x48, 0x89, 0xec, 0x5d, 0xff, 0x25, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff,
|
||||
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
|
||||
0xff, 0xff
|
||||
};
|
||||
static_assert(sizeof(entryWrapper32) == 51, "Invalid entryWrapper32 size");
|
||||
static_assert(sizeof(entryWrapper64) == 50, "Invalid entryWrapper64 size");
|
||||
static constexpr size_t EntryWrapper32Booter {0x00000017};
|
||||
static constexpr size_t EntryWrapper64Booter {0x000000000000002a};
|
||||
static constexpr size_t EntryWrapper32Entry {0x0000002a};
|
||||
static constexpr size_t EntryWrapper64Entry {0x0000000000000022};
|
||||
83
EFI/OC/Kexts/RTCMemoryFixup.kext/Contents/Info.plist
Normal file
83
EFI/OC/Kexts/RTCMemoryFixup.kext/Contents/Info.plist
Normal file
@@ -0,0 +1,83 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>BuildMachineOSBuild</key>
|
||||
<string>19F101</string>
|
||||
<key>CFBundleDevelopmentRegion</key>
|
||||
<string>en</string>
|
||||
<key>CFBundleExecutable</key>
|
||||
<string>RTCMemoryFixup</string>
|
||||
<key>CFBundleIdentifier</key>
|
||||
<string>as.lvs1974.RTCMemoryFixup</string>
|
||||
<key>CFBundleInfoDictionaryVersion</key>
|
||||
<string>6.0</string>
|
||||
<key>CFBundleName</key>
|
||||
<string>RTCMemoryFixup</string>
|
||||
<key>CFBundlePackageType</key>
|
||||
<string>KEXT</string>
|
||||
<key>CFBundleShortVersionString</key>
|
||||
<string>1.0.7</string>
|
||||
<key>CFBundleSupportedPlatforms</key>
|
||||
<array>
|
||||
<string>MacOSX</string>
|
||||
</array>
|
||||
<key>CFBundleVersion</key>
|
||||
<string>1.0.7</string>
|
||||
<key>DTCompiler</key>
|
||||
<string>com.apple.compilers.llvm.clang.1_0</string>
|
||||
<key>DTPlatformBuild</key>
|
||||
<string>11E708</string>
|
||||
<key>DTPlatformVersion</key>
|
||||
<string>GM</string>
|
||||
<key>DTSDKBuild</key>
|
||||
<string>19G68</string>
|
||||
<key>DTSDKName</key>
|
||||
<string>macosx10.15</string>
|
||||
<key>DTXcode</key>
|
||||
<string>1160</string>
|
||||
<key>DTXcodeBuild</key>
|
||||
<string>11E708</string>
|
||||
<key>IOKitPersonalities</key>
|
||||
<dict>
|
||||
<key>as.lvs1974.RTCMemoryFixup</key>
|
||||
<dict>
|
||||
<key>CFBundleIdentifier</key>
|
||||
<string>as.lvs1974.RTCMemoryFixup</string>
|
||||
<key>IOClass</key>
|
||||
<string>RTCMemoryFixup</string>
|
||||
<key>IONameMatch</key>
|
||||
<string>PNP0B00</string>
|
||||
<key>IOProbeScore</key>
|
||||
<integer>100</integer>
|
||||
<key>IOProviderClass</key>
|
||||
<string>IOACPIPlatformDevice</string>
|
||||
</dict>
|
||||
</dict>
|
||||
<key>LSMinimumSystemVersion</key>
|
||||
<string>10.8</string>
|
||||
<key>NSHumanReadableCopyright</key>
|
||||
<string>Copyright © 2018 lvs1974. All rights reserved.</string>
|
||||
<key>OSBundleCompatibleVersion</key>
|
||||
<string>1.0</string>
|
||||
<key>OSBundleLibraries</key>
|
||||
<dict>
|
||||
<key>as.vit9696.Lilu</key>
|
||||
<string>1.2.0</string>
|
||||
<key>com.apple.kpi.bsd</key>
|
||||
<string>12.0.0</string>
|
||||
<key>com.apple.kpi.dsep</key>
|
||||
<string>12.0.0</string>
|
||||
<key>com.apple.kpi.iokit</key>
|
||||
<string>12.0.0</string>
|
||||
<key>com.apple.kpi.libkern</key>
|
||||
<string>12.0.0</string>
|
||||
<key>com.apple.kpi.mach</key>
|
||||
<string>12.0.0</string>
|
||||
<key>com.apple.kpi.unsupported</key>
|
||||
<string>12.0.0</string>
|
||||
</dict>
|
||||
<key>OSBundleRequired</key>
|
||||
<string>Root</string>
|
||||
</dict>
|
||||
</plist>
|
||||
BIN
EFI/OC/Kexts/RTCMemoryFixup.kext/Contents/MacOS/RTCMemoryFixup
Normal file
BIN
EFI/OC/Kexts/RTCMemoryFixup.kext/Contents/MacOS/RTCMemoryFixup
Normal file
Binary file not shown.
102
EFI/OC/Kexts/SMCBatteryManager.kext/Contents/Info.plist
Normal file
102
EFI/OC/Kexts/SMCBatteryManager.kext/Contents/Info.plist
Normal file
@@ -0,0 +1,102 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>BuildMachineOSBuild</key>
|
||||
<string>23H626</string>
|
||||
<key>CFBundleDevelopmentRegion</key>
|
||||
<string>en</string>
|
||||
<key>CFBundleExecutable</key>
|
||||
<string>SMCBatteryManager</string>
|
||||
<key>CFBundleIdentifier</key>
|
||||
<string>ru.usrsse2.SMCBatteryManager</string>
|
||||
<key>CFBundleInfoDictionaryVersion</key>
|
||||
<string>6.0</string>
|
||||
<key>CFBundleName</key>
|
||||
<string>SMCBatteryManager</string>
|
||||
<key>CFBundlePackageType</key>
|
||||
<string>KEXT</string>
|
||||
<key>CFBundleShortVersionString</key>
|
||||
<string>1.3.7</string>
|
||||
<key>CFBundleSupportedPlatforms</key>
|
||||
<array>
|
||||
<string>MacOSX</string>
|
||||
</array>
|
||||
<key>CFBundleVersion</key>
|
||||
<string>1.3.7</string>
|
||||
<key>DTCompiler</key>
|
||||
<string>com.apple.compilers.llvm.clang.1_0</string>
|
||||
<key>DTPlatformBuild</key>
|
||||
<string></string>
|
||||
<key>DTPlatformName</key>
|
||||
<string>macosx</string>
|
||||
<key>DTPlatformVersion</key>
|
||||
<string>14.2</string>
|
||||
<key>DTSDKBuild</key>
|
||||
<string>23C53</string>
|
||||
<key>DTSDKName</key>
|
||||
<string>macosx14.2</string>
|
||||
<key>DTXcode</key>
|
||||
<string>1520</string>
|
||||
<key>DTXcodeBuild</key>
|
||||
<string>15C500b</string>
|
||||
<key>IOKitPersonalities</key>
|
||||
<dict>
|
||||
<key>IOSMBusController</key>
|
||||
<dict>
|
||||
<key>CFBundleIdentifier</key>
|
||||
<string>ru.usrsse2.SMCBatteryManager</string>
|
||||
<key>IOClass</key>
|
||||
<string>SMCSMBusController</string>
|
||||
<key>IOMatchCategory</key>
|
||||
<string>SMCSMBusController</string>
|
||||
<key>IOProviderClass</key>
|
||||
<string>IOResources</string>
|
||||
<key>IOResourceMatch</key>
|
||||
<string>IOKit</string>
|
||||
</dict>
|
||||
<key>SMCBatteryManager</key>
|
||||
<dict>
|
||||
<key>CFBundleIdentifier</key>
|
||||
<string>ru.usrsse2.SMCBatteryManager</string>
|
||||
<key>IOClass</key>
|
||||
<string>SMCBatteryManager</string>
|
||||
<key>IOMatchCategory</key>
|
||||
<string>SMCBatteryManager</string>
|
||||
<key>IOProviderClass</key>
|
||||
<string>IOResources</string>
|
||||
<key>IOResourceMatch</key>
|
||||
<string>IOKit</string>
|
||||
</dict>
|
||||
</dict>
|
||||
<key>LSMinimumSystemVersion</key>
|
||||
<string>10.6</string>
|
||||
<key>NSHumanReadableCopyright</key>
|
||||
<string>Copyright © 2018 usrsse2. All rights reserved.</string>
|
||||
<key>OSBundleCompatibleVersion</key>
|
||||
<string>1.0.0</string>
|
||||
<key>OSBundleLibraries</key>
|
||||
<dict>
|
||||
<key>as.vit9696.Lilu</key>
|
||||
<string>1.2.0</string>
|
||||
<key>as.vit9696.VirtualSMC</key>
|
||||
<string>1.0.0</string>
|
||||
<key>com.apple.iokit.IOACPIFamily</key>
|
||||
<string>1.0.0d1</string>
|
||||
<key>com.apple.iokit.IOSMBusFamily</key>
|
||||
<string>1.0.0</string>
|
||||
<key>com.apple.kpi.bsd</key>
|
||||
<string>8.0.0</string>
|
||||
<key>com.apple.kpi.iokit</key>
|
||||
<string>8.0.0</string>
|
||||
<key>com.apple.kpi.libkern</key>
|
||||
<string>8.0.0</string>
|
||||
<key>com.apple.kpi.mach</key>
|
||||
<string>8.0.0</string>
|
||||
<key>com.apple.kpi.unsupported</key>
|
||||
<string>8.0.0</string>
|
||||
</dict>
|
||||
<key>OSBundleRequired</key>
|
||||
<string>Root</string>
|
||||
</dict>
|
||||
</plist>
|
||||
Binary file not shown.
@@ -0,0 +1,400 @@
|
||||
// SSDT-BATC.dsl
|
||||
//
|
||||
// Based on https://github.com/RehabMan/OS-X-ACPI-Battery-Driver/blob/master/SSDT-BATC.dsl
|
||||
//
|
||||
// An SSDT to combine two batteries into one
|
||||
// initial work/testing by ag6952563 (with assistance by RehabMan)
|
||||
// finalize into generic SSDT by RehabMan
|
||||
// some code cleanup/optimization/and bug fixing by RehabMan
|
||||
// modifications to work VirtualSMC SMCBatteryManager by armenio
|
||||
// add _BIX (easy, following the original code from RehabMan) by armenio
|
||||
//
|
||||
// OS X support for multiple batteries is a bit buggy.
|
||||
// This SSDT can be used to combine two batteries into one,
|
||||
// avoiding the bugs.
|
||||
//
|
||||
// It may need modification depending on the ACPI path of your
|
||||
// existing battery objects.
|
||||
//
|
||||
|
||||
// IMPORTANT:
|
||||
//
|
||||
// To use this SSDT, you must also patch any Notify for either BAT0 or BAT1
|
||||
// objects.
|
||||
//
|
||||
// The Notify is used to tell the system when a battery is removed or added.
|
||||
//
|
||||
// Any code:
|
||||
// Notify (...BAT0, ...)
|
||||
// -or
|
||||
// Notify (...BAT1, ...)
|
||||
//
|
||||
// Must be changed to:
|
||||
// Notify (...BATC, ...)
|
||||
//
|
||||
// Refer to Dual Battery Support.md for patching details
|
||||
//
|
||||
|
||||
DefinitionBlock ("", "SSDT", 2, "ACDT", "BATC", 0x00000000)
|
||||
{
|
||||
External (_SB_.PCI0.LPCB.EC, DeviceObj)
|
||||
External (_SB_.PCI0.LPCB.EC.BAT0, DeviceObj)
|
||||
External (_SB_.PCI0.LPCB.EC.BAT0._BIF, MethodObj)
|
||||
External (_SB_.PCI0.LPCB.EC.BAT0._BIX, MethodObj)
|
||||
External (_SB_.PCI0.LPCB.EC.BAT0._BST, MethodObj)
|
||||
External (_SB_.PCI0.LPCB.EC.BAT0._HID, IntObj)
|
||||
External (_SB_.PCI0.LPCB.EC.BAT0._STA, MethodObj)
|
||||
External (_SB_.PCI0.LPCB.EC.BAT1, DeviceObj)
|
||||
External (_SB_.PCI0.LPCB.EC.BAT1._BIF, MethodObj)
|
||||
External (_SB_.PCI0.LPCB.EC.BAT1._BIX, MethodObj)
|
||||
External (_SB_.PCI0.LPCB.EC.BAT1._BST, MethodObj)
|
||||
External (_SB_.PCI0.LPCB.EC.BAT1._HID, IntObj)
|
||||
External (_SB_.PCI0.LPCB.EC.BAT1._STA, MethodObj)
|
||||
|
||||
Scope (\_SB.PCI0.LPCB.EC)
|
||||
{
|
||||
Device (BATC)
|
||||
{
|
||||
Name (_HID, EisaId ("PNP0C0A"))
|
||||
Name (_UID, 0x02)
|
||||
|
||||
Method (_INI)
|
||||
{
|
||||
If (_OSI ("Darwin"))
|
||||
{
|
||||
// disable original battery objects by setting invalid _HID
|
||||
^^BAT0._HID = 0
|
||||
^^BAT1._HID = 0
|
||||
}
|
||||
}
|
||||
|
||||
Method (_STA)
|
||||
{
|
||||
If (_OSI ("Darwin"))
|
||||
{
|
||||
// call original _STA for BAT0 and BAT1
|
||||
// result is bitwise OR between them
|
||||
Return (^^BAT0._STA () | ^^BAT1._STA ())
|
||||
}
|
||||
Else
|
||||
{
|
||||
Return (Zero)
|
||||
}
|
||||
}
|
||||
|
||||
Method (_BIF)
|
||||
{
|
||||
// Local0 BAT0._BIF
|
||||
// Local1 BAT1._BIF
|
||||
// Local2 BAT0._STA
|
||||
// Local3 BAT1._STA
|
||||
// Local4/Local5 scratch
|
||||
|
||||
// gather and validate data from BAT0
|
||||
Local0 = ^^BAT0._BIF ()
|
||||
Local2 = ^^BAT0._STA ()
|
||||
If (0x1f == Local2)
|
||||
{
|
||||
// check for invalid design capacity
|
||||
Local4 = DerefOf (Local0 [1])
|
||||
If (!Local4 || Ones == Local4) { Local2 = 0; }
|
||||
// check for invalid last full charge capacity
|
||||
Local4 = DerefOf (Local0 [2])
|
||||
If (!Local4 || Ones == Local4) { Local2 = 0; }
|
||||
// check for invalid design voltage
|
||||
Local4 = DerefOf (Local0 [4])
|
||||
If (!Local4 || Ones == Local4) { Local2 = 0; }
|
||||
}
|
||||
// gather and validate data from BAT1
|
||||
Local1 = ^^BAT1._BIF ()
|
||||
Local3 = ^^BAT1._STA ()
|
||||
If (0x1f == Local3)
|
||||
{
|
||||
// check for invalid design capacity
|
||||
Local4 = DerefOf (Local1 [1])
|
||||
If (!Local4 || Ones == Local4) { Local3 = 0; }
|
||||
// check for invalid last full charge capacity
|
||||
Local4 = DerefOf (Local1 [2])
|
||||
If (!Local4 || Ones == Local4) { Local3 = 0; }
|
||||
// check for invalid design voltage
|
||||
Local4 = DerefOf (Local1 [4])
|
||||
If (!Local4 || Ones == Local4) { Local3 = 0; }
|
||||
}
|
||||
// find primary and secondary battery
|
||||
If (0x1f != Local2 && 0x1f == Local3)
|
||||
{
|
||||
// make primary use BAT1 data
|
||||
Local0 = Local1 // BAT1._BIF result
|
||||
Local2 = Local3 // BAT1._STA result
|
||||
Local3 = 0 // no secondary battery
|
||||
}
|
||||
// combine batteries into Local0 result if possible
|
||||
If (0x1f == Local2 && 0x1f == Local3)
|
||||
{
|
||||
// _BIF 0 Power Unit - leave BAT0 value
|
||||
// _BIF 1 Design Capacity - add BAT0 and BAT1 values
|
||||
Local4 = DerefOf (Local0 [1])
|
||||
Local5 = DerefOf (Local1 [1])
|
||||
If (0xffffffff != Local4 && 0xffffffff != Local5)
|
||||
{
|
||||
Local0 [1] = Local4 + Local5
|
||||
}
|
||||
// _BIF 2 Last Full Charge Capacity - add BAT0 and BAT1 values
|
||||
Local4 = DerefOf (Local0 [2])
|
||||
Local5 = DerefOf (Local1 [2])
|
||||
If (0xffffffff != Local4 && 0xffffffff != Local5)
|
||||
{
|
||||
Local0 [2] = Local4 + Local5
|
||||
}
|
||||
// _BIF 3 Battery Technology - leave BAT0 value
|
||||
// _BIF 4 Design Voltage - average between BAT0 and BAT1 values
|
||||
Local4 = DerefOf (Local0 [4])
|
||||
Local5 = DerefOf (Local1 [4])
|
||||
If (0xffffffff != Local4 && 0xffffffff != Local5)
|
||||
{
|
||||
Local0 [4] = (Local4 + Local5) / 2
|
||||
}
|
||||
// _BIF 5 Design Capacity of Warning - add BAT0 and BAT1 values
|
||||
Local0 [5] = DerefOf (Local0 [5]) + DerefOf (Local1 [5])
|
||||
// _BIF 6 Design Capacity of Low - add BAT0 and BAT1 values
|
||||
Local0 [6] = DerefOf (Local0 [6]) + DerefOf (Local1 [6])
|
||||
// _BIF 7 Battery Capacity Granularity 1 - add BAT0 and BAT1 values
|
||||
Local4 = DerefOf (Local0 [7])
|
||||
Local5 = DerefOf (Local1 [7])
|
||||
If (0xffffffff != Local4 && 0xffffffff != Local5)
|
||||
{
|
||||
Local0 [7] = Local4 + Local5
|
||||
}
|
||||
// _BIF 8 Battery Capacity Granularity 2 - add BAT0 and BAT1 values
|
||||
Local4 = DerefOf (Local0 [8])
|
||||
Local5 = DerefOf (Local1 [8])
|
||||
If (0xffffffff != Local4 && 0xffffffff != Local5)
|
||||
{
|
||||
Local0 [8] = Local4 + Local5
|
||||
}
|
||||
// _BIF 9 Model Number - concatenate BAT0 and BAT1 values
|
||||
Local0 [0x09] = Concatenate (Concatenate (DerefOf (Local0 [0x09]), " / "), DerefOf (Local1 [0x09]))
|
||||
// _BIF a Serial Number - concatenate BAT0 and BAT1 values
|
||||
Local0 [0x0a] = Concatenate (Concatenate (DerefOf (Local0 [0x0a]), " / "), DerefOf (Local1 [0x0a]))
|
||||
// _BIF b Battery Type - concatenate BAT0 and BAT1 values
|
||||
Local0 [0x0b] = Concatenate (Concatenate (DerefOf (Local0 [0x0b]), " / "), DerefOf (Local1 [0x0b]))
|
||||
// _BIF c OEM Information - concatenate BAT0 and BAT1 values
|
||||
Local0 [0x0c] = Concatenate (Concatenate (DerefOf (Local0 [0x0c]), " / "), DerefOf (Local1 [0x0c]))
|
||||
}
|
||||
|
||||
Return (Local0)
|
||||
} // _BIF
|
||||
|
||||
Method (_BIX)
|
||||
{
|
||||
// Local0 BAT0._BIX
|
||||
// Local1 BAT1._BIX
|
||||
// Local2 BAT0._STA
|
||||
// Local3 BAT1._STA
|
||||
// Local4/Local5 scratch
|
||||
|
||||
// gather and validate data from BAT0
|
||||
Local0 = ^^BAT0._BIX ()
|
||||
Local2 = ^^BAT0._STA ()
|
||||
If (0x1f == Local2)
|
||||
{
|
||||
// check for invalid design capacity
|
||||
Local4 = DerefOf (Local0 [2])
|
||||
If (!Local4 || Ones == Local4) { Local2 = 0; }
|
||||
// check for invalid last full charge capacity
|
||||
Local4 = DerefOf (Local0 [3])
|
||||
If (!Local4 || Ones == Local4) { Local2 = 0; }
|
||||
// check for invalid design voltage
|
||||
Local4 = DerefOf (Local0 [5])
|
||||
If (!Local4 || Ones == Local4) { Local2 = 0; }
|
||||
}
|
||||
// gather and validate data from BAT1
|
||||
Local1 = ^^BAT1._BIX ()
|
||||
Local3 = ^^BAT1._STA ()
|
||||
If (0x1f == Local3)
|
||||
{
|
||||
// check for invalid design capacity
|
||||
Local4 = DerefOf (Local1 [2])
|
||||
If (!Local4 || Ones == Local4) { Local3 = 0; }
|
||||
// check for invalid last full charge capacity
|
||||
Local4 = DerefOf (Local1 [3])
|
||||
If (!Local4 || Ones == Local4) { Local3 = 0; }
|
||||
// check for invalid design voltage
|
||||
Local4 = DerefOf (Local1 [5])
|
||||
If (!Local4 || Ones == Local4) { Local3 = 0; }
|
||||
}
|
||||
// find primary and secondary battery
|
||||
If (0x1f != Local2 && 0x1f == Local3)
|
||||
{
|
||||
// make primary use BAT1 data
|
||||
Local0 = Local1 // BAT1._BIX result
|
||||
Local2 = Local3 // BAT1._STA result
|
||||
Local3 = 0 // no secondary battery
|
||||
}
|
||||
// combine batteries into Local0 result if possible
|
||||
If (0x1f == Local2 && 0x1f == Local3)
|
||||
{
|
||||
// _BIX 0 Revision - leave BAT0 value
|
||||
// _BIX 1 Power Unit - leave BAT0 value
|
||||
// _BIX 2 Design Capacity - add BAT0 and BAT1 values
|
||||
Local4 = DerefOf (Local0 [2])
|
||||
Local5 = DerefOf (Local1 [2])
|
||||
If (0xffffffff != Local4 && 0xffffffff != Local5)
|
||||
{
|
||||
Local0 [2] = Local4 + Local5
|
||||
}
|
||||
// _BIX 3 Last Full Charge Capacity - add BAT0 and BAT1 values
|
||||
Local4 = DerefOf (Local0 [3])
|
||||
Local5 = DerefOf (Local1 [3])
|
||||
If (0xffffffff != Local4 && 0xffffffff != Local5)
|
||||
{
|
||||
Local0 [3] = Local4 + Local5
|
||||
}
|
||||
// _BIX 4 Battery Technology - leave BAT0 value
|
||||
// _BIX 5 Design Voltage - average between BAT0 and BAT1 values
|
||||
Local4 = DerefOf (Local0 [5])
|
||||
Local5 = DerefOf (Local1 [5])
|
||||
If (0xffffffff != Local4 && 0xffffffff != Local5)
|
||||
{
|
||||
Local0 [5] = (Local4 + Local5) / 2
|
||||
}
|
||||
// _BIX 6 Design Capacity of Warning - add BAT0 and BAT1 values
|
||||
Local0 [6] = DerefOf (Local0 [6]) + DerefOf (Local1 [6])
|
||||
// _BIX 7 Design Capacity of Low - add BAT0 and BAT1 values
|
||||
Local0 [7] = DerefOf (Local0 [7]) + DerefOf (Local1 [7])
|
||||
// _BIX 8 Cycle Count - average between BAT0 and BAT1 values
|
||||
Local4 = DerefOf (Local0 [8])
|
||||
Local5 = DerefOf (Local1 [8])
|
||||
If (0xffffffff != Local4 && 0xffffffff != Local5)
|
||||
{
|
||||
Local0 [8] = (Local4 + Local5) / 2
|
||||
}
|
||||
// _BIX 9 Measurement Accuracy - average between BAT0 and BAT1 values
|
||||
Local0 [9] = (DerefOf (Local0 [9]) + DerefOf (Local1 [9])) / 2
|
||||
// _BIX 0xa Max Sampling Time - average between BAT0 and BAT1 values
|
||||
Local4 = DerefOf (Local0 [0xa])
|
||||
Local5 = DerefOf (Local1 [0xa])
|
||||
If (0xffffffff != Local4 && 0xffffffff != Local5)
|
||||
{
|
||||
Local0 [0xa] = (Local4 + Local5) / 2
|
||||
}
|
||||
// _BIX 0xb Min Sampling Time - average between BAT0 and BAT1 values
|
||||
Local4 = DerefOf (Local0 [0xb])
|
||||
Local5 = DerefOf (Local1 [0xb])
|
||||
If (0xffffffff != Local4 && 0xffffffff != Local5)
|
||||
{
|
||||
Local0 [0xb] = (Local4 + Local5) / 2
|
||||
}
|
||||
// _BIX 0xc Max Averaging Interval - average between BAT0 and BAT1 values
|
||||
Local0 [0xc] = (DerefOf (Local0 [0xc]) + DerefOf (Local1 [0xc])) / 2
|
||||
// _BIX 0xd Min Averaging Interval - average between BAT0 and BAT1 values
|
||||
Local0 [0xd] = (DerefOf (Local0 [0xd]) + DerefOf (Local1 [0xd])) / 2
|
||||
// _BIX 0xe Battery Capacity Granularity 1 - add BAT0 and BAT1 values
|
||||
Local4 = DerefOf (Local0 [0xe])
|
||||
Local5 = DerefOf (Local1 [0xe])
|
||||
If (0xffffffff != Local4 && 0xffffffff != Local5)
|
||||
{
|
||||
Local0 [0xe] = Local4 + Local5
|
||||
}
|
||||
// _BIX 0xf Battery Capacity Granularity 2 - add BAT0 and BAT1 values
|
||||
Local4 = DerefOf (Local0 [0xf])
|
||||
Local5 = DerefOf (Local1 [0xf])
|
||||
If (0xffffffff != Local4 && 0xffffffff != Local5)
|
||||
{
|
||||
Local0 [0xf] = Local4 + Local5
|
||||
}
|
||||
// _BIX 10 Model Number - concatenate BAT0 and BAT1 values
|
||||
Local0 [0x10] = Concatenate (Concatenate (DerefOf (Local0 [0x10]), " / "), DerefOf (Local1 [0x10]))
|
||||
// _BIX 11 Serial Number - concatenate BAT0 and BAT1 values
|
||||
Local0 [0x11] = Concatenate (Concatenate (DerefOf (Local0 [0x11]), " / "), DerefOf (Local1 [0x11]))
|
||||
// _BIX 12 Battery Type - concatenate BAT0 and BAT1 values
|
||||
Local0 [0x12] = Concatenate (Concatenate (DerefOf (Local0 [0x12]), " / "), DerefOf (Local1 [0x12]))
|
||||
// _BIX 13 OEM Information - concatenate BAT0 and BAT1 values
|
||||
Local0 [0x13] = Concatenate (Concatenate (DerefOf (Local0 [0x13]), " / "), DerefOf (Local1 [0x13]))
|
||||
// _BIX 14 Battery Swapping Capability - leave BAT0 value for now
|
||||
}
|
||||
Return (Local0)
|
||||
} // _BIX
|
||||
|
||||
Method (_BST)
|
||||
{
|
||||
// Local0 BAT0._BST
|
||||
// Local1 BAT1._BST
|
||||
// Local2 BAT0._STA
|
||||
// Local3 BAT1._STA
|
||||
// Local4/Local5 scratch
|
||||
|
||||
// gather battery data from BAT0
|
||||
Local0 = ^^BAT0._BST ()
|
||||
Local2 = ^^BAT0._STA ()
|
||||
If (0x1f == Local2)
|
||||
{
|
||||
// check for invalid remaining capacity
|
||||
Local4 = DerefOf (Local0 [2])
|
||||
If (!Local4 || Ones == Local4) { Local2 = 0; }
|
||||
}
|
||||
// gather battery data from BAT1
|
||||
Local1 = ^^BAT1._BST ()
|
||||
Local3 = ^^BAT1._STA ()
|
||||
If (0x1f == Local3)
|
||||
{
|
||||
// check for invalid remaining capacity
|
||||
Local4 = DerefOf (Local1 [2])
|
||||
If (!Local4 || Ones == Local4) { Local3 = 0; }
|
||||
}
|
||||
// find primary and secondary battery
|
||||
If (0x1f != Local2 && 0x1f == Local3)
|
||||
{
|
||||
// make primary use BAT1 data
|
||||
Local0 = Local1 // BAT1._BST result
|
||||
Local2 = Local3 // BAT1._STA result
|
||||
Local3 = 0 // no secondary battery
|
||||
}
|
||||
// combine batteries into Local0 result if possible
|
||||
If (0x1f == Local2 && 0x1f == Local3)
|
||||
{
|
||||
// _BST 0 - Battery State - if one battery is charging, then charging, else discharging
|
||||
Local4 = DerefOf (Local0 [0])
|
||||
Local5 = DerefOf (Local1 [0])
|
||||
If (Local4 != Local5)
|
||||
{
|
||||
If (Local4 == 2 || Local5 == 2)
|
||||
{
|
||||
// 2 = charging
|
||||
Local0 [0] = 2
|
||||
}
|
||||
ElseIf (Local4 == 1 || Local5 == 1)
|
||||
{
|
||||
// 1 = discharging
|
||||
Local0 [0] = 1
|
||||
}
|
||||
ElseIf (Local4 == 3 || Local5 == 3)
|
||||
{
|
||||
Local0 [0] = 3
|
||||
}
|
||||
ElseIf (Local4 == 4 || Local5 == 4)
|
||||
{
|
||||
// critical
|
||||
Local0 [0] = 4
|
||||
}
|
||||
ElseIf (Local4 == 5 || Local5 == 5)
|
||||
{
|
||||
// critical and discharging
|
||||
Local0 [0] = 5
|
||||
}
|
||||
// if none of the above, just leave as BAT0 is
|
||||
}
|
||||
|
||||
// _BST 1 - Battery Present Rate - add BAT0 and BAT1 values
|
||||
Local0 [1] = DerefOf (Local0 [1]) + DerefOf (Local1 [1])
|
||||
// _BST 2 - Battery Remaining Capacity - add BAT0 and BAT1 values
|
||||
Local0 [2] = DerefOf (Local0 [2]) + DerefOf (Local1 [2])
|
||||
// _BST 3 - Battery Present Voltage - average between BAT0 and BAT1 values
|
||||
Local0 [3] = (DerefOf (Local0 [3]) + DerefOf (Local1 [3])) / 2
|
||||
}
|
||||
Return (Local0)
|
||||
} // _BST
|
||||
} // BATC
|
||||
} // Scope (...)
|
||||
}
|
||||
//EOF
|
||||
98
EFI/OC/Kexts/SMCProcessor.kext/Contents/Info.plist
Normal file
98
EFI/OC/Kexts/SMCProcessor.kext/Contents/Info.plist
Normal file
@@ -0,0 +1,98 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>BuildMachineOSBuild</key>
|
||||
<string>23H626</string>
|
||||
<key>CFBundleDevelopmentRegion</key>
|
||||
<string>en</string>
|
||||
<key>CFBundleExecutable</key>
|
||||
<string>SMCProcessor</string>
|
||||
<key>CFBundleIdentifier</key>
|
||||
<string>as.vit9696.SMCProcessor</string>
|
||||
<key>CFBundleInfoDictionaryVersion</key>
|
||||
<string>6.0</string>
|
||||
<key>CFBundleName</key>
|
||||
<string>SMCProcessor</string>
|
||||
<key>CFBundlePackageType</key>
|
||||
<string>KEXT</string>
|
||||
<key>CFBundleShortVersionString</key>
|
||||
<string>1.3.7</string>
|
||||
<key>CFBundleSignature</key>
|
||||
<string>????</string>
|
||||
<key>CFBundleSupportedPlatforms</key>
|
||||
<array>
|
||||
<string>MacOSX</string>
|
||||
</array>
|
||||
<key>CFBundleVersion</key>
|
||||
<string>1.3.7</string>
|
||||
<key>DTCompiler</key>
|
||||
<string>com.apple.compilers.llvm.clang.1_0</string>
|
||||
<key>DTPlatformBuild</key>
|
||||
<string></string>
|
||||
<key>DTPlatformName</key>
|
||||
<string>macosx</string>
|
||||
<key>DTPlatformVersion</key>
|
||||
<string>14.2</string>
|
||||
<key>DTSDKBuild</key>
|
||||
<string>23C53</string>
|
||||
<key>DTSDKName</key>
|
||||
<string>macosx14.2</string>
|
||||
<key>DTXcode</key>
|
||||
<string>1520</string>
|
||||
<key>DTXcodeBuild</key>
|
||||
<string>15C500b</string>
|
||||
<key>IOKitPersonalities</key>
|
||||
<dict>
|
||||
<key>as.vit9696.SMCProcessor</key>
|
||||
<dict>
|
||||
<key>CFBundleIdentifier</key>
|
||||
<string>as.vit9696.SMCProcessor</string>
|
||||
<key>IOClass</key>
|
||||
<string>SMCProcessor</string>
|
||||
<key>IOMatchCategory</key>
|
||||
<string>SMCProcessor</string>
|
||||
<key>IONameMatch</key>
|
||||
<string>processor</string>
|
||||
<key>IOPropertyMatch</key>
|
||||
<dict>
|
||||
<key>processor-index</key>
|
||||
<integer>0</integer>
|
||||
</dict>
|
||||
<key>IOProviderClass</key>
|
||||
<string>IOACPIPlatformDevice</string>
|
||||
<key>IOResourceMatch</key>
|
||||
<string>ACPI</string>
|
||||
</dict>
|
||||
</dict>
|
||||
<key>LSMinimumSystemVersion</key>
|
||||
<string>10.7</string>
|
||||
<key>NSHumanReadableCopyright</key>
|
||||
<string>Copyright © 2018 vit9696. All rights reserved.</string>
|
||||
<key>OSBundleCompatibleVersion</key>
|
||||
<string>1.0</string>
|
||||
<key>OSBundleLibraries</key>
|
||||
<dict>
|
||||
<key>as.vit9696.Lilu</key>
|
||||
<string>1.2.0</string>
|
||||
<key>as.vit9696.VirtualSMC</key>
|
||||
<string>1.0.0</string>
|
||||
<key>com.apple.iokit.IOACPIFamily</key>
|
||||
<string>1.0.0d1</string>
|
||||
<key>com.apple.kpi.bsd</key>
|
||||
<string>11.0.0</string>
|
||||
<key>com.apple.kpi.dsep</key>
|
||||
<string>11.0.0</string>
|
||||
<key>com.apple.kpi.iokit</key>
|
||||
<string>11.0.0</string>
|
||||
<key>com.apple.kpi.libkern</key>
|
||||
<string>11.0.0</string>
|
||||
<key>com.apple.kpi.mach</key>
|
||||
<string>11.0.0</string>
|
||||
<key>com.apple.kpi.unsupported</key>
|
||||
<string>11.0.0</string>
|
||||
</dict>
|
||||
<key>OSBundleRequired</key>
|
||||
<string>Root</string>
|
||||
</dict>
|
||||
</plist>
|
||||
BIN
EFI/OC/Kexts/SMCProcessor.kext/Contents/MacOS/SMCProcessor
Normal file
BIN
EFI/OC/Kexts/SMCProcessor.kext/Contents/MacOS/SMCProcessor
Normal file
Binary file not shown.
93
EFI/OC/Kexts/SMCSuperIO.kext/Contents/Info.plist
Normal file
93
EFI/OC/Kexts/SMCSuperIO.kext/Contents/Info.plist
Normal file
@@ -0,0 +1,93 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>BuildMachineOSBuild</key>
|
||||
<string>23H626</string>
|
||||
<key>CFBundleDevelopmentRegion</key>
|
||||
<string>en</string>
|
||||
<key>CFBundleExecutable</key>
|
||||
<string>SMCSuperIO</string>
|
||||
<key>CFBundleIdentifier</key>
|
||||
<string>ru.joedm.SMCSuperIO</string>
|
||||
<key>CFBundleInfoDictionaryVersion</key>
|
||||
<string>6.0</string>
|
||||
<key>CFBundleName</key>
|
||||
<string>SMCSuperIO</string>
|
||||
<key>CFBundlePackageType</key>
|
||||
<string>KEXT</string>
|
||||
<key>CFBundleShortVersionString</key>
|
||||
<string>1.3.7</string>
|
||||
<key>CFBundleSignature</key>
|
||||
<string>????</string>
|
||||
<key>CFBundleSupportedPlatforms</key>
|
||||
<array>
|
||||
<string>MacOSX</string>
|
||||
</array>
|
||||
<key>CFBundleVersion</key>
|
||||
<string>1.3.7</string>
|
||||
<key>DTCompiler</key>
|
||||
<string>com.apple.compilers.llvm.clang.1_0</string>
|
||||
<key>DTPlatformBuild</key>
|
||||
<string></string>
|
||||
<key>DTPlatformName</key>
|
||||
<string>macosx</string>
|
||||
<key>DTPlatformVersion</key>
|
||||
<string>14.2</string>
|
||||
<key>DTSDKBuild</key>
|
||||
<string>23C53</string>
|
||||
<key>DTSDKName</key>
|
||||
<string>macosx14.2</string>
|
||||
<key>DTXcode</key>
|
||||
<string>1520</string>
|
||||
<key>DTXcodeBuild</key>
|
||||
<string>15C500b</string>
|
||||
<key>IOKitPersonalities</key>
|
||||
<dict>
|
||||
<key>ru.joedm.SMCSuperIO</key>
|
||||
<dict>
|
||||
<key>CFBundleIdentifier</key>
|
||||
<string>ru.joedm.SMCSuperIO</string>
|
||||
<key>IOClass</key>
|
||||
<string>SMCSuperIO</string>
|
||||
<key>IOMatchCategory</key>
|
||||
<string>SMCSuperIO</string>
|
||||
<key>IOPCIClassMatch</key>
|
||||
<string>0x06010000&0xffff0000</string>
|
||||
<key>IOProviderClass</key>
|
||||
<string>IOPCIDevice</string>
|
||||
<key>IOResourceMatch</key>
|
||||
<string>ACPI</string>
|
||||
</dict>
|
||||
</dict>
|
||||
<key>LSMinimumSystemVersion</key>
|
||||
<string>10.6</string>
|
||||
<key>NSHumanReadableCopyright</key>
|
||||
<string>Copyright © 2018 joedm. All rights reserved.</string>
|
||||
<key>OSBundleCompatibleVersion</key>
|
||||
<string>1.0</string>
|
||||
<key>OSBundleLibraries</key>
|
||||
<dict>
|
||||
<key>as.vit9696.Lilu</key>
|
||||
<string>1.2.0</string>
|
||||
<key>as.vit9696.VirtualSMC</key>
|
||||
<string>1.0.0</string>
|
||||
<key>com.apple.iokit.IOACPIFamily</key>
|
||||
<string>1.0.0d1</string>
|
||||
<key>com.apple.kpi.bsd</key>
|
||||
<string>10.0.0</string>
|
||||
<key>com.apple.kpi.dsep</key>
|
||||
<string>10.0.0</string>
|
||||
<key>com.apple.kpi.iokit</key>
|
||||
<string>10.0.0</string>
|
||||
<key>com.apple.kpi.libkern</key>
|
||||
<string>10.0.0</string>
|
||||
<key>com.apple.kpi.mach</key>
|
||||
<string>10.0.0</string>
|
||||
<key>com.apple.kpi.unsupported</key>
|
||||
<string>10.0.0</string>
|
||||
</dict>
|
||||
<key>OSBundleRequired</key>
|
||||
<string>Root</string>
|
||||
</dict>
|
||||
</plist>
|
||||
BIN
EFI/OC/Kexts/SMCSuperIO.kext/Contents/MacOS/SMCSuperIO
Normal file
BIN
EFI/OC/Kexts/SMCSuperIO.kext/Contents/MacOS/SMCSuperIO
Normal file
Binary file not shown.
63
EFI/OC/Kexts/USBToolBox.kext/Contents/Info.plist
Normal file
63
EFI/OC/Kexts/USBToolBox.kext/Contents/Info.plist
Normal file
@@ -0,0 +1,63 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>BuildMachineOSBuild</key>
|
||||
<string>23H626</string>
|
||||
<key>CFBundleDevelopmentRegion</key>
|
||||
<string>en</string>
|
||||
<key>CFBundleExecutable</key>
|
||||
<string>USBToolBox</string>
|
||||
<key>CFBundleIdentifier</key>
|
||||
<string>com.dhinakg.USBToolBox.kext</string>
|
||||
<key>CFBundleInfoDictionaryVersion</key>
|
||||
<string>6.0</string>
|
||||
<key>CFBundleName</key>
|
||||
<string>USBToolBox</string>
|
||||
<key>CFBundlePackageType</key>
|
||||
<string>KEXT</string>
|
||||
<key>CFBundleSupportedPlatforms</key>
|
||||
<array>
|
||||
<string>MacOSX</string>
|
||||
</array>
|
||||
<key>CFBundleVersion</key>
|
||||
<string>1.2.0</string>
|
||||
<key>DTCompiler</key>
|
||||
<string>com.apple.compilers.llvm.clang.1_0</string>
|
||||
<key>DTPlatformBuild</key>
|
||||
<string></string>
|
||||
<key>DTPlatformName</key>
|
||||
<string>macosx</string>
|
||||
<key>DTPlatformVersion</key>
|
||||
<string>14.2</string>
|
||||
<key>DTSDKBuild</key>
|
||||
<string>23C53</string>
|
||||
<key>DTSDKName</key>
|
||||
<string>macosx14.2</string>
|
||||
<key>DTXcode</key>
|
||||
<string>1520</string>
|
||||
<key>DTXcodeBuild</key>
|
||||
<string>15C500b</string>
|
||||
<key>IOKitPersonalities</key>
|
||||
<dict/>
|
||||
<key>LSMinimumSystemVersion</key>
|
||||
<string>10.11</string>
|
||||
<key>NSHumanReadableCopyright</key>
|
||||
<string>Copyright © 2020-2021 Dhinak G. All rights reserved.</string>
|
||||
<key>OSBundleCompatibleVersion</key>
|
||||
<string>1.0.0</string>
|
||||
<key>OSBundleLibraries</key>
|
||||
<dict>
|
||||
<key>com.apple.driver.AppleUSBHostMergeProperties</key>
|
||||
<string>1.0</string>
|
||||
<key>com.apple.iokit.IOPCIFamily</key>
|
||||
<string>2.9</string>
|
||||
<key>com.apple.kpi.iokit</key>
|
||||
<string>15.0.0</string>
|
||||
<key>com.apple.kpi.libkern</key>
|
||||
<string>15.0.0</string>
|
||||
</dict>
|
||||
<key>OSBundleRequired</key>
|
||||
<string>Root</string>
|
||||
</dict>
|
||||
</plist>
|
||||
BIN
EFI/OC/Kexts/USBToolBox.kext/Contents/MacOS/USBToolBox
Normal file
BIN
EFI/OC/Kexts/USBToolBox.kext/Contents/MacOS/USBToolBox
Normal file
Binary file not shown.
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user