Initial commit

This commit is contained in:
2025-08-03 20:55:12 +02:00
commit f7d91d55b0
18 changed files with 918 additions and 0 deletions
+3
View File
@@ -0,0 +1,3 @@
*.dll
*.exe
*.cfg
+20
View File
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://www.purebasic.com/namespace" version="1.0" creator="PureBasic 6.20 (Windows - x64)">
<section name="config">
<options closefiles="1" openmode="0" name="PB-DllWrapperMaker"/>
</section>
<section name="data">
<explorer view="C:\ProgramData\PureBasic\Examples\" pattern="0"/>
<log show="1"/>
<lastopen date="2025-08-03 16:40" user="Herwin" host="DESKTOP-FND9TQS"/>
</section>
<section name="files"/>
<section name="targets">
<target name="Default Target" enabled="1" default="1">
<inputfile value=""/>
<outputfile value=""/>
<options xpskin="1" dpiaware="1" debug="1" optimizer="0"/>
</target>
</section>
</project>
+174
View File
@@ -0,0 +1,174 @@
;{- Code Header
; ==- Basic Info -================================
; Name: ImageNtHeaderHelper.pbi
; Version: 0.0.1
; Author: Herwin Bozet (NibblePoker)
;
; ==- Compatibility -=============================
; Compiler version:
; * PureBasic 6.0 LTS
; * PureBasic 6.0 LTS - C Backend
;
; ==- Links & License -===========================
; License: Unlicense
; GitHub: ???
;}
;- Module declaration
DeclareModule ImageNtHeaderHelper
Enumeration INHH_ErrorCodes
#INHH_ERROR_None = 0
#INHH_ERROR_IdAlreadyUsed
#INHH_ERROR_IdNotfound
#INHH_ERROR_CannotOpenFile
#INHH_ERROR_CannotCreateFileMapping
#INHH_ERROR_CannotMapViewOfFile
#INHH_ERROR_CannotRetrieveHeaders
EndEnumeration
; Loads the given file into memory, maps a view of it into memory and attempts to retrieve the IMAGE_NT_HEADERS32 structure.
Declare.i GetImageNtHeader32(ImageNtHeaderId.i, FilePath$)
;
Declare.i FreeImageNtHeader32(ImageNtHeaderId.i)
;
Declare.i GetLastError()
Declare ClearLastError()
EndDeclareModule
;- Module definition
Module ImageNtHeaderHelper
EnableExplicit
CompilerIf Not Defined(SEC_IMAGE_NO_EXECUTE, #PB_Constant)
#SEC_IMAGE_NO_EXECUTE = $11000000
CompilerEndIf
Structure OpenImageNtHeader
FileId.i
*ViewAddress
*RetrievedNtHeaders
EndStructure
Global LastErrorCode.i = 0
Global NewMap OpenImageNtHeaders.OpenImageNtHeader()
Procedure.i GetImageNtHeader32(ImageNtHeaderId.i, FilePath$)
; Handling the ID and the map
Define ImageNtHeaderId$
If ImageNtHeaderId = #PB_Any
Repeat
RandomData(@ImageNtHeaderId, SizeOf(ImageNtHeaderId))
ImageNtHeaderId$ = Str(ImageNtHeaderId)
Until FindMapElement(OpenImageNtHeaders(), ImageNtHeaderId$) = #Null
Else
ImageNtHeaderId$ = Str(ImageNtHeaderId)
If FindMapElement(OpenImageNtHeaders(), ImageNtHeaderId$) <> #Null
Debug "The value used for 'ImageNtHeaderId' was already in use ! (" + ImageNtHeaderId$ + ")"
LastErrorCode = #INHH_ERROR_IdAlreadyUsed
ProcedureReturn #Null
EndIf
EndIf
AddMapElement(OpenImageNtHeaders(), ImageNtHeaderId$)
; Opening the file
Define InputFileHandle = ReadFile(#PB_Any, FilePath$)
If InputFileHandle = 0
Debug "Unable to open input file !"
LastErrorCode = #INHH_ERROR_CannotOpenFile
Goto INHH_GetImageNtHeader32_BadEnding
EndIf
OpenImageNtHeaders()\FileId = InputFileHandle
; Mapping the file into memory
Define InputFileMappingHandle = CreateFileMapping_(FileID(InputFileHandle), #Null, #PAGE_READONLY | #SEC_IMAGE_NO_EXECUTE, 0, 0, #Null)
If InputFileMappingHandle = #ERROR_ALREADY_EXISTS Or InputFileMappingHandle = 0
Debug "Unable to create a file mapping !"
LastErrorCode = #INHH_ERROR_CannotCreateFileMapping
Goto INHH_GetImageNtHeader32_CloseInputFileHandle
EndIf
Define InputFileViewPtr.i = MapViewOfFile_(InputFileMappingHandle, #FILE_MAP_READ, 0, 0, 0)
If InputFileViewPtr = #Null
Debug "Unable to map the input file into memory !"
LastErrorCode = #INHH_ERROR_CannotMapViewOfFile
Goto INHH_GetImageNtHeader32_CloseInputFileHandle
EndIf
OpenImageNtHeaders()\ViewAddress = InputFileViewPtr
; Retrieving the NT headers
Define *RetrievedNtHeaders.IMAGE_NT_HEADERS32 = ImageNtHeader_(InputFileViewPtr)
If *RetrievedNtHeaders = #Null
Debug "Unable to retrieve the NT headers !"
LastErrorCode = #INHH_ERROR_CannotRetrieveHeaders
Goto INHH_GetImageNtHeader32_UnmapFileView
EndIf
OpenImageNtHeaders()\RetrievedNtHeaders = *RetrievedNtHeaders
ProcedureReturn *RetrievedNtHeaders
; Error cases
INHH_GetImageNtHeader32_UnmapFileView:
UnmapViewOfFile_(InputFileViewPtr)
INHH_GetImageNtHeader32_CloseInputFileHandle:
CloseFile(InputFileHandle)
INHH_GetImageNtHeader32_BadEnding:
DeleteMapElement(OpenImageNtHeaders(), ImageNtHeaderId$)
ProcedureReturn #Null
EndProcedure
Procedure.i FreeImageNtHeader32(ImageNtHeaderId.i)
Define ImageNtHeaderId$ = Str(ImageNtHeaderId)
Define *HeaderInternalData.OpenImageNtHeader = FindMapElement(OpenImageNtHeaders(), ImageNtHeaderId$)
If *HeaderInternalData = #Null
ProcedureReturn #INHH_ERROR_IdNotfound
EndIf
UnmapViewOfFile_(*HeaderInternalData\ViewAddress)
CloseFile(*HeaderInternalData\FileId)
ProcedureReturn #Null
EndProcedure
Procedure.i GetLastError()
ProcedureReturn LastErrorCode
EndProcedure
Procedure ClearLastError()
LastErrorCode = 0
EndProcedure
EndModule
;- Tests
CompilerIf #PB_Compiler_IsMainFile
CompilerEndIf
; IDE Options = PureBasic 6.21 (Windows - x64)
; CursorPosition = 120
; FirstLine = 102
; Folding = --
; EnableXP
; DPIAware
+35
View File
@@ -0,0 +1,35 @@
;{- Code Header
; ==- Basic Info -================================
; Name: WinApi_GetConsoleProcessList.pbi
; Version: 0.0.1
; Author: Herwin Bozet (NibblePoker)
;
; ==- Compatibility -=============================
; Compiler version:
; * PureBasic 6.0 LTS
; * PureBasic 6.0 LTS - C Backend
;
; ==- Links & License -===========================
; License: Unlicense
; GitHub: ???
;}
EnableExplicit
CompilerIf #PB_Compiler_Processor = #PB_Processor_x86
#WinApi_GetConsoleProcessList_LibPath$ = "../Libs/X86/kernel32.lib"
CompilerElseIf #PB_Compiler_Processor = #PB_Processor_x64
#WinApi_GetConsoleProcessList_LibPath$ = "../Libs/X64/kernel32.lib"
CompilerElse
CompilerError "Please use x64 or x86 compilers for this include !"
CompilerEndIf
Import #WinApi_GetConsoleProcessList_LibPath$
GetConsoleProcessList_.l(*lpdwProcessList, dwProcessCount.l) As "GetConsoleProcessList"
EndImport
; IDE Options = PureBasic 6.21 (Windows - x64)
; CursorPosition = 27
; Folding = -
; EnableXP
; DPIAware
+24
View File
@@ -0,0 +1,24 @@
This is free and unencumbered software released into the public domain.
Anyone is free to copy, modify, publish, use, compile, sell, or
distribute this software, either in source code form or as a compiled
binary, for any purpose, commercial or non-commercial, and by any
means.
In jurisdictions that recognize copyright laws, the author or authors
of this software dedicate any and all copyright interest in the
software to the public domain. We make this dedication for the benefit
of the public at large and to the detriment of our heirs and
successors. We intend this dedication to be an overt act of
relinquishment in perpetuity of all present and future rights to this
software under copyright law.
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 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.
For more information, please refer to <http://unlicense.org/>
+7
View File
@@ -0,0 +1,7 @@
@echo off
:: These variables should point to '.exe' files.
set MSVC_DUMPBIN="C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.43.34808\bin\Hostx64\x64\dumpbin.exe"
set MSVC_LIB="C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.43.34808\bin\Hostx64\x64\lib.exe"
exit /b
+43
View File
@@ -0,0 +1,43 @@
@echo off
setlocal
pushd %CD%
cd /D "%~dp0"
call "%~dp0\0_config.cmd"
echo Checking the PATH
IF NOT EXIST %MSVC_LIB% (
echo ^> Unable to find 'lib.exe' as indicated in '%%MSVC_DUMPBIN%%' !
echo ^> Please check the '0_config.cmd' script !
goto end
)
echo ^> Found 'lib.exe' at the given location !
echo Removing old '.lib' files
del /S /Q .\*.lib 2> nul
echo Iterating over all '.def' files in 'libs/' for 'x64', 'x86' and 'arm64'...
for /R ".\" %%i in (*.def) do call :sub-make-lib X64 %%i
for /R ".\" %%i in (*.def) do call :sub-make-lib X86 %%i
for /R ".\" %%i in (*.def) do call :sub-make-lib ARM64 %%i
echo Done !
:end
popd
endlocal
pause
exit /b
:sub-make-lib
echo ^> %2
pushd %~dp2
::set _RAW_DEF_NAME=%~nx2
::set _RAW_DEF_NAME=%_RAW_DEF_NAME:.raw.def=%
::echo lib.exe /nologo /def:%_RAW_DEF_NAME%.raw.def /out:%_RAW_DEF_NAME%.lib /machine:%1
::%MSVC_LIB% /nologo /def:%_RAW_DEF_NAME%.raw.def /out:%_RAW_DEF_NAME%.lib /machine:%1
mkdir .\%1
%MSVC_LIB% /nologo /def:%~nx2 /out:.\%1\%~n2.lib /machine:%1
popd
exit /b
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
+4
View File
@@ -0,0 +1,4 @@
LIBRARY msvcrt.dll
EXPORTS
GetConsoleProcessList
+385
View File
@@ -0,0 +1,385 @@
;{- Code Header
; ==- Basic Info -================================
; Name: Main_PEArch.pb
; Version: 0.0.1
; Author: Herwin Bozet (NibblePoker)
;
; ==- Compatibility -=============================
; Compiler version:
; * PureBasic 6.0 LTS
; * PureBasic 6.0 LTS - C Backend
;
; ==- Links & License -===========================
; License: Unlicense
; GitHub: ???
;}
;- Compiler directive
EnableExplicit
XIncludeFile "./Includes/ImageNtHeaderHelper.pbi"
XIncludeFile "./Includes/WinApi_GetConsoleProcessList.pbi"
;- Constants
#IMAGE_FILE_MACHINE_UNKNOWN = $0
#IMAGE_FILE_MACHINE_ALPHA = $184
#IMAGE_FILE_MACHINE_ALPHA64 = $284
#IMAGE_FILE_MACHINE_AM33 = $1d3
#IMAGE_FILE_MACHINE_AMD64 = $8664
#IMAGE_FILE_MACHINE_ARM = $1c0
#IMAGE_FILE_MACHINE_ARM64 = $aa64
#IMAGE_FILE_MACHINE_ARM64EC = $A641
#IMAGE_FILE_MACHINE_ARM64X = $A64E
#IMAGE_FILE_MACHINE_ARMNT = $1c4
#IMAGE_FILE_MACHINE_AXP64 = $284
#IMAGE_FILE_MACHINE_EBC = $ebc
#IMAGE_FILE_MACHINE_I386 = $14c
#IMAGE_FILE_MACHINE_IA64 = $200
#IMAGE_FILE_MACHINE_LOONGARCH32 = $6232
#IMAGE_FILE_MACHINE_LOONGARCH64 = $6264
#IMAGE_FILE_MACHINE_M32R = $9041
#IMAGE_FILE_MACHINE_MIPS16 = $266
#IMAGE_FILE_MACHINE_MIPSFPU = $366
#IMAGE_FILE_MACHINE_MIPSFPU16 = $466
#IMAGE_FILE_MACHINE_POWERPC = $1f0
#IMAGE_FILE_MACHINE_POWERPCFP = $1f1
#IMAGE_FILE_MACHINE_R3000BE = $160
#IMAGE_FILE_MACHINE_R3000 = $162
#IMAGE_FILE_MACHINE_R4000 = $166
#IMAGE_FILE_MACHINE_R10000 = $168
#IMAGE_FILE_MACHINE_RISCV32 = $5032
#IMAGE_FILE_MACHINE_RISCV64 = $5064
#IMAGE_FILE_MACHINE_RISCV128 = $5128
#IMAGE_FILE_MACHINE_SH3 = $1a2
#IMAGE_FILE_MACHINE_SH3DSP = $1a3
#IMAGE_FILE_MACHINE_SH4 = $1a6
#IMAGE_FILE_MACHINE_SH5 = $1a8
#IMAGE_FILE_MACHINE_THUMB = $1c2
#IMAGE_FILE_MACHINE_WCEMIPSV2 = $169
;- Enumerations
Enumeration PEARCH_ErrorCodes
#PEARCH_ERROR_None = 0
#PEARCH_ERROR_ConsoleError = 1
#PEARCH_ERROR_UnknownError = 2
;#PEARCH_ERROR_INHH_ERROR_IdAlreadyUsed = 10
;#PEARCH_ERROR_INHH_ERROR_IdNotfound = 11
#PEARCH_ERROR_INHH_ERROR_CannotOpenFile = 12
#PEARCH_ERROR_INHH_ERROR_CannotCreateFileMapping = 13
#PEARCH_ERROR_INHH_ERROR_CannotMapViewOfFile = 14
#PEARCH_ERROR_INHH_ERROR_CannotRetrieveHeaders = 15
#PEARCH_ERROR_UnknownArgument = 20
#PEARCH_ERROR_MissingFileArgument = 21
#PEARCH_ERROR_TooManyFileArguments = 22
#PEARCH_ERROR_UnknownAchitecture = 30
EndEnumeration
;- Globals
Global ExitCode.i = #PEARCH_ERROR_None
Global OptionAsHex.b = #False
Global OptionAsError.b = #False
Global OptionFullText.b = #False
Global InputFile$ = #Null$
;- Macros
Macro HandlePeArch(ShortText, FullText, Code)
If OptionAsHex
PrintN(Hex(Code, #PB_Word))
Else
If OptionFullText
PrintN(FullText)
Else
PrintN(ShortText)
EndIf
EndIf
If OptionAsError
ExitCode = Code
EndIf
EndMacro
;- Procedures
Procedure PrintUsageText(PrintFull.b = #False)
Define UsageText$
Restore UsageText
Read.s UsageText$
PrintN(UsageText$)
If PrintFull
Read.s UsageText$
PrintN(UsageText$)
EndIf
EndProcedure
; Checks if the current process was started via another process (CMD), or not.
Procedure.b IsProgramRunDirectly()
; Will act as a DWORD[2]
Define ProcessListBuffer.q
ProcedureReturn Bool(GetConsoleProcessList_(@ProcessListBuffer, 2) <= 1)
EndProcedure
;- App's code
If Not OpenConsole("PEArch")
ExitCode = #PEARCH_ERROR_ConsoleError
Goto PEArch_End
EndIf
Define IParam.i
For IParam = 0 To CountProgramParameters()
Define CurrentParam$ = ProgramParameter(IParam)
If Len(CurrentParam$) > 0
If Left(CurrentParam$, 1) <> "/"
If InputFile$ = #Null$
InputFile$ = CurrentParam$
Else
ConsoleError("More than one input file was given !")
ExitCode = #PEARCH_ERROR_TooManyFileArguments
PrintUsageText()
Goto PEArch_End
EndIf
Else
CurrentParam$ = UCase(CurrentParam$)
If CurrentParam$ = "/ASHEX" Or CurrentParam$ = "/H"
OptionAsHex = #True
ElseIf CurrentParam$ = "/?"
PrintUsageText(#True)
Goto PEArch_End
ElseIf CurrentParam$ = "/ASERROR" Or CurrentParam$ = "/E"
OptionAsError = #True
ElseIf CurrentParam$ = "/FULLTEXT" Or CurrentParam$ = "/F"
OptionFullText = #True
Else
ConsoleError("Unknown argument: '" + CurrentParam$ + "'")
ExitCode = #PEARCH_ERROR_UnknownArgument
PrintUsageText()
Goto PEArch_End
EndIf
EndIf
EndIf
Next
If InputFile$ = #Null$
ConsoleError("No input file given !")
ExitCode = #PEARCH_ERROR_MissingFileArgument
PrintUsageText()
Goto PEArch_End
EndIf
Define *Headers.IMAGE_NT_HEADERS32 = ImageNtHeaderHelper::GetImageNtHeader32(0, InputFile$)
If *Headers = #Null
Define HelperErrorCode.i = ImageNtHeaderHelper::GetLastError()
Select HelperErrorCode
Case ImageNtHeaderHelper::#INHH_ERROR_CannotOpenFile
ConsoleError("Cannot open file !")
ExitCode = #PEARCH_ERROR_INHH_ERROR_CannotOpenFile
Case ImageNtHeaderHelper::#INHH_ERROR_CannotCreateFileMapping
ConsoleError("Cannot create file mapping !")
ExitCode = #PEARCH_ERROR_INHH_ERROR_CannotCreateFileMapping
Case ImageNtHeaderHelper::#INHH_ERROR_CannotMapViewOfFile
ConsoleError("Cannot map view of file into memory !")
ExitCode = #PEARCH_ERROR_INHH_ERROR_CannotMapViewOfFile
Case ImageNtHeaderHelper::#INHH_ERROR_CannotRetrieveHeaders
ConsoleError("Cannot retrieve PE headers !")
ExitCode = #PEARCH_ERROR_INHH_ERROR_CannotRetrieveHeaders
Default
ConsoleError("Unknown 'ImageNtHeaderHelper' error ! ("+Str(HelperErrorCode)+")")
ExitCode = #PEARCH_ERROR_UnknownError
EndSelect
If OptionAsError
ExitCode = 0
EndIf
Goto PEArch_End
EndIf
Define PeArchId.u = *Headers\FileHeader\Machine
Select PeArchId
Case #IMAGE_FILE_MACHINE_UNKNOWN
HandlePeArch("UNKNOWN", "The content of this field is assumed To be applicable To any machine type", PeArchId)
Case #IMAGE_FILE_MACHINE_ALPHA
HandlePeArch("ALPHA", "Alpha AXP, 32-bit address space", PeArchId)
Case #IMAGE_FILE_MACHINE_ALPHA64
HandlePeArch("ALPHA64", "Alpha 64, 64-bit address space", PeArchId)
Case #IMAGE_FILE_MACHINE_AM33
HandlePeArch("AM33", "Matsushita AM33", PeArchId)
Case #IMAGE_FILE_MACHINE_AMD64
HandlePeArch("AMD64", "x64", PeArchId)
Case #IMAGE_FILE_MACHINE_ARM
HandlePeArch("ARM", "ARM little endian", PeArchId)
Case #IMAGE_FILE_MACHINE_ARM64
HandlePeArch("ARM64", "ARM64 little endian", PeArchId)
Case #IMAGE_FILE_MACHINE_ARM64EC
HandlePeArch("ARM64EC", "ABI that enables interoperability between native ARM64 And emulated x64 code.", PeArchId)
Case #IMAGE_FILE_MACHINE_ARM64X
HandlePeArch("ARM64X", "Binary format that allows both native ARM64 And ARM64EC code To coexist in the same file.", PeArchId)
Case #IMAGE_FILE_MACHINE_ARMNT
HandlePeArch("ARMNT", "ARM Thumb-2 little endian", PeArchId)
Case #IMAGE_FILE_MACHINE_AXP64
HandlePeArch("AXP64", "AXP 64 (Same As Alpha 64)", PeArchId)
Case #IMAGE_FILE_MACHINE_EBC
HandlePeArch("EBC", "EFI byte code", PeArchId)
Case #IMAGE_FILE_MACHINE_I386
HandlePeArch("I386", "Intel 386 Or later processors And compatible processors", PeArchId)
Case #IMAGE_FILE_MACHINE_IA64
HandlePeArch("IA64", "Intel Itanium processor family", PeArchId)
Case #IMAGE_FILE_MACHINE_LOONGARCH32
HandlePeArch("LOONGARCH32", "LoongArch 32-bit processor family", PeArchId)
Case #IMAGE_FILE_MACHINE_LOONGARCH64
HandlePeArch("LOONGARCH64", "LoongArch 64-bit processor family", PeArchId)
Case #IMAGE_FILE_MACHINE_M32R
HandlePeArch("M32R", "Mitsubishi M32R little endian", PeArchId)
Case #IMAGE_FILE_MACHINE_MIPS16
HandlePeArch("MIPS16", "MIPS16", PeArchId)
Case #IMAGE_FILE_MACHINE_MIPSFPU
HandlePeArch("MIPSFPU", "MIPS With FPU", PeArchId)
Case #IMAGE_FILE_MACHINE_MIPSFPU16
HandlePeArch("MIPSFPU16", "MIPS16 With FPU", PeArchId)
Case #IMAGE_FILE_MACHINE_POWERPC
HandlePeArch("POWERPC", "Power PC little endian", PeArchId)
Case #IMAGE_FILE_MACHINE_POWERPCFP
HandlePeArch("POWERPCFP", "Power PC With floating point support", PeArchId)
Case #IMAGE_FILE_MACHINE_R3000BE
HandlePeArch("R3000BE", "MIPS I compatible 32-bit big endian", PeArchId)
Case #IMAGE_FILE_MACHINE_R3000
HandlePeArch("R3000", "MIPS I compatible 32-bit little endian", PeArchId)
Case #IMAGE_FILE_MACHINE_R4000
HandlePeArch("R4000", "MIPS III compatible 64-bit little endian", PeArchId)
Case #IMAGE_FILE_MACHINE_R10000
HandlePeArch("R10000", "MIPS IV compatible 64-bit little endian", PeArchId)
Case #IMAGE_FILE_MACHINE_RISCV32
HandlePeArch("RISCV32", "RISC-V 32-bit address space", PeArchId)
Case #IMAGE_FILE_MACHINE_RISCV64
HandlePeArch("RISCV64", "RISC-V 64-bit address space", PeArchId)
Case #IMAGE_FILE_MACHINE_RISCV128
HandlePeArch("RISCV128", "RISC-V 128-bit address space", PeArchId)
Case #IMAGE_FILE_MACHINE_SH3
HandlePeArch("SH3", "Hitachi SH3", PeArchId)
Case #IMAGE_FILE_MACHINE_SH3DSP
HandlePeArch("SH3DSP", "Hitachi SH3 DSP", PeArchId)
Case #IMAGE_FILE_MACHINE_SH4
HandlePeArch("SH4", "Hitachi SH4", PeArchId)
Case #IMAGE_FILE_MACHINE_SH5
HandlePeArch("SH5", "Hitachi SH5", PeArchId)
Case #IMAGE_FILE_MACHINE_THUMB
HandlePeArch("THUMB", "Thumb", PeArchId)
Case #IMAGE_FILE_MACHINE_WCEMIPSV2
HandlePeArch("WCEMIPSV2", "MIPS little-endian WCE v2", PeArchId)
Default
If OptionAsHex
HandlePeArch("WCEMIPSV2", "MIPS little-endian WCE v2", PeArchId)
Else
If OptionAsError
ExitCode = 0
Else
ExitCode = #PEARCH_ERROR_UnknownAchitecture
EndIf
EndIf
EndSelect
ImageNtHeaderHelper::FreeImageNtHeader32(0)
PEArch_End:
If IsProgramRunDirectly()
PrintN("Press enter to exit...")
Input()
EndIf
End ExitCode
;- Data section
DataSection
UsageText:
Data.s "PEArch.exe [/?] [/E|/AsError] [/H|/AsHex] [/F|/FullText] <File>" + #CRLF$ +
"" + #CRLF$ +
"Options:" + #CRLF$ +
" /? Prints this help text." + #CRLF$ +
" /E, /AsError Gives out the result as an error code." + #CRLF$ +
" /H, /AsHex Prints the architecture as a hex number." + #CRLF$ +
" /F, /FullText Prints a longer description of the architecture." + #CRLF$
Data.s "Errors:" + #CRLF$ +
" 0 - No error" + #CRLF$ +
" 1 - Console error" + #CRLF$ +
" 1 - Unknown error" + #CRLF$ +
" 12 - Unable to open the file" + #CRLF$ +
" 13 - Cannot create a file mapping" + #CRLF$ +
" 14 - Cannot map the file into memory" + #CRLF$ +
" 15 - Unable to retrieve the NT headers" + #CRLF$ +
" 20 - Unknown argument" + #CRLF$ +
" 21 - Missing file argument" + #CRLF$ +
" 22 - Too many file arguments" + #CRLF$ +
" 30 - The architecture is unknown, '/AsHex' will bypass it" + #CRLF$ +
#CRLF$ +
"Architectures:" + #CRLF$ +
" 0x0 - UNKNOWN - The content of this field is assumed To be applicable To any machine type" + #CRLF$ +
" 0x184 - ALPHA - Alpha AXP, 32-bit address space" + #CRLF$ +
" 0x284 - ALPHA64 - Alpha 64, 64-bit address space" + #CRLF$ +
" 0x1d3 - AM33 - Matsushita AM33" + #CRLF$ +
" 0x8664 - AMD64 - x64" + #CRLF$ +
" 0x1c0 - ARM - ARM little endian" + #CRLF$ +
" 0xaa64 - ARM64 - ARM64 little endian" + #CRLF$ +
" 0xA641 - ARM64EC - ABI that enables interoperability between native ARM64 And emulated x64 code." + #CRLF$ +
" 0xA64E - ARM64X - Binary format that allows both native ARM64 And ARM64EC code To coexist in the same file." + #CRLF$ +
" 0x1c4 - ARMNT - ARM Thumb-2 little endian" + #CRLF$ +
" 0x284 - AXP64 - AXP 64 (Same As Alpha 64)" + #CRLF$ +
" 0xebc - EBC - EFI byte code" + #CRLF$ +
" 0x14c - I386 - Intel 386 Or later processors And compatible processors" + #CRLF$ +
" 0x200 - IA64 - Intel Itanium processor family" + #CRLF$ +
" 0x6232 - LOONGARCH32 - LoongArch 32-bit processor family" + #CRLF$ +
" 0x6264 - LOONGARCH64 - LoongArch 64-bit processor family" + #CRLF$ +
" 0x9041 - M32R - Mitsubishi M32R little endian" + #CRLF$ +
" 0x266 - MIPS16 - MIPS16" + #CRLF$ +
" 0x366 - MIPSFPU - MIPS With FPU" + #CRLF$ +
" 0x466 - MIPSFPU16 - MIPS16 With FPU" + #CRLF$ +
" 0x1f0 - POWERPC - Power PC little endian" + #CRLF$ +
" 0x1f1 - POWERPCFP - Power PC With floating point support" + #CRLF$ +
" 0x160 - R3000BE - MIPS I compatible 32-bit big endian" + #CRLF$ +
" 0x162 - R3000 - MIPS I compatible 32-bit little endian" + #CRLF$ +
" 0x166 - R4000 - MIPS III compatible 64-bit little endian" + #CRLF$ +
" 0x168 - R10000 - MIPS IV compatible 64-bit little endian" + #CRLF$ +
" 0x5032 - RISCV32 - RISC-V 32-bit address space" + #CRLF$ +
" 0x5064 - RISCV64 - RISC-V 64-bit address space" + #CRLF$ +
" 0x5128 - RISCV128 - RISC-V 128-bit address space" + #CRLF$ +
" 0x1a2 - SH3 - Hitachi SH3" + #CRLF$ +
" 0x1a3 - SH3DSP - Hitachi SH3 DSP" + #CRLF$ +
" 0x1a6 - SH4 - Hitachi SH4" + #CRLF$ +
" 0x1a8 - SH5 - Hitachi SH5" + #CRLF$ +
" 0x1c2 - THUMB - Thumb" + #CRLF$ +
" 0x169 - WCEMIPSV2 - MIPS little-endian WCE v2" + #CRLF$
EndDataSection
; IDE Options = PureBasic 6.21 (Windows - x64)
; CursorPosition = 220
; FirstLine = 212
; Folding = -
; EnableXP
; DPIAware
+105
View File
@@ -0,0 +1,105 @@
;{- Code Header
; ==- Basic Info -================================
; Name: PB-CTypes.pbi
; Version: 0.0.1
; Author: Herwin Bozet
;
; ==- Compatibility -=============================
; Compiler version:
; * PureBasic 6.0 LTS
; * PureBasic 6.0 LTS - C Backend
;
; ==- Links & License -===========================
; License: Unlicense
; GitHub: https://github.com/aziascreations/PB-CTypes
; Private Repo: https://git.nibblepoker.lu/aziascreations/PB-CTypes
;}
;- Compiler Directives
EnableExplicit
;- Constants
; SEC_IMAGE_NO_EXECUTE
; 0x11000000
CompilerIf Not Defined(SEC_IMAGE_NO_EXECUTE, #PB_Constant)
#SEC_IMAGE_NO_EXECUTE = $11000000
CompilerEndIf
If Not OpenConsole("DllWrapperMaker")
End 1
EndIf
; If CountProgramParameters() <> 2
; PrintN("DllWrap <DLL> <Output>")
; EndIf
;
; Define DllPath$ = ProgramParameter()
; Define OutputPath$ = ProgramParameter()
Define DllPath1$ = "C:\Program Files\7-Zip\7-zip32.dll"
Define DllPath2$ = "C:\Program Files\7-Zip\7-zip.dll"
; Debug DllPath$
; Debug OutputPath$
Procedure GetImageCpuArch(ImagePath$)
; Mapping the file into memory
Define InputFileHandle = ReadFile(#PB_Any, ImagePath$)
If InputFileHandle = 0
PrintN("Unable to open input file !")
ProcedureReturn
EndIf
Define InputFileMappingHandle = CreateFileMapping_(FileID(InputFileHandle), #Null, #PAGE_READONLY | #SEC_IMAGE_NO_EXECUTE, 0, 0, #Null)
If InputFileMappingHandle = #ERROR_ALREADY_EXISTS Or InputFileMappingHandle = 0
PrintN("Unable to create a file mapping !")
Goto GetImageCpuArch_CloseInputFileHandle
EndIf
Define InputFileViewPtr.i = MapViewOfFile_(InputFileMappingHandle, #FILE_MAP_READ, 0, 0, 0)
If InputFileViewPtr = #Null
PrintN("Unable to map the input file into memory !")
Goto GetImageCpuArch_CloseInputFileHandle
EndIf
; Retrieving the NT headers
Define *RetrievedNtHeaders.IMAGE_NT_HEADERS32 = ImageNtHeader_(InputFileViewPtr)
If *RetrievedNtHeaders = #Null
PrintN("Unable to retrieve the NT headers !")
Goto GetImageCpuArch_UnmapFileView
EndIf
Debug *RetrievedNtHeaders\FileHeader\ Machine
; Do not do this !
;FreeMemory(*RetrievedNtHeaders)
; Cleaning up
GetImageCpuArch_UnmapFileView:
UnmapViewOfFile_(InputFileViewPtr)
GetImageCpuArch_CloseInputFileHandle:
CloseFile(InputFileHandle)
EndProcedure
GetImageCpuArch(DllPath1$)
GetImageCpuArch(DllPath2$)
Input()
; IDE Options = PureBasic 6.21 (Windows - x64)
; CursorPosition = 78
; FirstLine = 44
; Folding = -
; EnableXP
; DPIAware
; CommandLine = "C:\Program Files (x86)\PureBasic\Compilers\Engine3D.dll" "./test.pb"
; CompileSourceDirectory
; EnableCompileCount = 21
; EnableBuildCount = 0
+109
View File
@@ -0,0 +1,109 @@
;{- Code Header
; ==- Basic Info -================================
; Name: PB-CTypes.pbi
; Version: 0.0.1
; Author: Herwin Bozet
;
; ==- Compatibility -=============================
; Compiler version:
; * PureBasic 6.0 LTS
; * PureBasic 6.0 LTS - C Backend
;
; ==- Links & License -===========================
; License: Unlicense
; GitHub: https://github.com/aziascreations/PB-CTypes
; Private Repo: https://git.nibblepoker.lu/aziascreations/PB-CTypes
;}
;- Compiler Directives
EnableExplicit
;- Constants
; SEC_IMAGE_NO_EXECUTE
; 0x11000000
CompilerIf Not Defined(SEC_IMAGE_NO_EXECUTE, #PB_Constant)
#SEC_IMAGE_NO_EXECUTE = $11000000
CompilerEndIf
If Not OpenConsole("DllWrapperMaker")
End 1
EndIf
If CountProgramParameters() <> 2
PrintN("DllWrap <DLL> <Output>")
EndIf
Define DllPath$ = ProgramParameter()
Define OutputPath$ = ProgramParameter()
DllPath$ = "C:\Program Files\7-Zip\7-zip32.dll"
DllPath$ = "C:\Program Files\7-Zip\7-zip.dll"
; Debug DllPath$
; Debug OutputPath$
Procedure GetImageCpuArch(ImagePath$)
; Mapping the file into memory
Define InputFileHandle = ReadFile(#PB_Any, ImagePath$)
If InputFileHandle = 0
PrintN("Unable to open input file !")
ProcedureReturn
EndIf
Define InputFileMappingHandle = CreateFileMapping_(FileID(InputFileHandle), #Null, #PAGE_READONLY | #SEC_IMAGE_NO_EXECUTE, 0, 0, #Null)
If InputFileMappingHandle = #ERROR_ALREADY_EXISTS Or InputFileMappingHandle = 0
PrintN("Unable to create a file mapping !")
Goto GetImageCpuArch_CloseInputFileHandle
EndIf
Define InputFileViewPtr.i = MapViewOfFile_(InputFileMappingHandle, #FILE_MAP_READ, 0, 0, 0)
If InputFileViewPtr = #Null
PrintN("Unable to map the input file into memory !")
Goto GetImageCpuArch_CloseInputFileHandle
EndIf
; Retrieving the NT headers
Define *RetrievedNtHeaders.IMAGE_NT_HEADERS32 = ImageNtHeader_(InputFileViewPtr)
If *RetrievedNtHeaders = #Null
PrintN("Unable to retrieve the NT headers !")
Goto GetImageCpuArch_UnmapFileView
EndIf
Debug *RetrievedNtHeaders\FileHeader\ Machine
;FreeMemory(*RetrievedNtHeaders)
; Cleaning up
GetImageCpuArch_UnmapFileView:
UnmapViewOfFile_(InputFileViewPtr)
GetImageCpuArch_CloseInputFileHandle:
CloseFile(InputFileHandle)
EndProcedure
GetImageCpuArch(DllPath$)
GetImageCpuArch(DllPath$)
GetImageCpuArch(DllPath$)
GetImageCpuArch(DllPath$)
Input()
; IDE Options = PureBasic 6.21 (Windows - x64)
; CursorPosition = 8
; Folding = -
; EnableXP
; DPIAware
; CommandLine = "C:\Program Files (x86)\PureBasic\Compilers\Engine3D.dll" "./test.pb"
; CompileSourceDirectory
; EnableCompileCount = 20
; EnableBuildCount = 0
+9
View File
@@ -0,0 +1,9 @@
# PB-PEArch
A small tool that tells you which [CPU architecture](https://learn.microsoft.com/en-us/windows/win32/debug/pe-format#machine-types)
a given [Windows PE](https://learn.microsoft.com/en-us/windows/win32/debug/pe-format) is made for.
## Usage
TODO
## License
All the code in this repo is released in the [Public Domain](LICENSE).