Skip to content

Commit

Permalink
2.36
Browse files Browse the repository at this point in the history
  • Loading branch information
nidud committed Oct 21, 2024
1 parent d032f24 commit 53c0e78
Show file tree
Hide file tree
Showing 16 changed files with 677 additions and 70 deletions.
26 changes: 26 additions & 0 deletions include/pe/_tcsext.asm
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
; _TCSEXT.ASM--
;
; Copyright (c) The Asmc Contributors. All rights reserved.
; Consult your license regarding permissions and restrictions.
;
; char *strext(char *);
; wchar_t *_wstrext(wchar_t *);
;

_tcsext proc uses rbx string:LPTSTR

ldr rcx,string

mov rbx,_tcsfn( rcx )

.if _tcsrchr( rbx, '.' )

.if ( rax == rbx )

xor eax,eax
.endif
.endif
ret

_tcsext endp

55 changes: 55 additions & 0 deletions include/pe/_tcsfcat.asm
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
; _TCSFCAT.ASM--
;
; Copyright (c) The Asmc Contributors. All rights reserved.
; Consult your license regarding permissions and restrictions.
;
; char *strfcat(char *, char *, char *);
; wchar_t *_wstrfcat(wchar_t *, wchar_t *, wchar_t *);
;

_tcsfcat proc uses rsi rdi rbx buffer:LPTSTR, path:LPTSTR, file:LPTSTR

ldr rsi,path
ldr rbx,file
ldr rdx,buffer

xor eax,eax
mov ecx,-1

.if ( rsi )

mov rdi,rsi ; overwrite buffer
repne _tscasb
mov rdi,rdx
not ecx
rep _tmovsb
.else
mov rdi,rdx ; length of buffer
repne _tscasb
.endif
sub rdi,TCHAR

.if ( rdi != rdx ) ; add slash if missing

movzx eax,TCHAR ptr [rdi-TCHAR]
ifdef __UNIX__
.if ( eax != '/' )

mov eax,'/'
else
.if ( !( eax == '\' || eax == '/' ) )

mov eax,'\'
endif
_tstosb
.endif
.endif

mov rsi,rbx ; add file name
.repeat
_tlodsb
_tstosb
.until !eax
.return(rdx)

_tcsfcat endp
34 changes: 34 additions & 0 deletions include/pe/_tcsfn.asm
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
; _TCSFN.ASM--
;
; Copyright (c) The Asmc Contributors. All rights reserved.
; Consult your license regarding permissions and restrictions.
;
; char *strfn(char *path);
; wchar_t *_wstrfn(wchar_t *path);
;
; return file part of path if /\ is found, else path
;

_tcsfn proc path:LPTSTR

ldr rcx,path
movzx edx,TCHAR ptr [rcx]

.for ( rax = rcx : edx : )
ifdef __UNIX__
.if ( edx == '/' )
else
.if ( edx == '\' || edx == '/' )
endif
.if ( TCHAR ptr [rcx+TCHAR] )

lea rax,[rcx+TCHAR]
.endif
.endif
add rcx,TCHAR
movzx edx,TCHAR ptr [rcx]
.endf
ret

_tcsfn endp

19 changes: 19 additions & 0 deletions include/pe/_tcsfxcat.asm
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
; _TCSFXCAT.ASM--
;
; Copyright (c) The Asmc Contributors. All rights reserved.
; Consult your license regarding permissions and restrictions.
;
; char *strfxcat(char *, char *);
; wchar_t *_wstrfxcat(wchar_t *, wchar_t *);
;

_tcsfxcat proc path:LPTSTR, ext:LPTSTR

.if _tcsext(path)

mov TCHAR ptr [rax],0
.endif
_tcscat(path, ext)
ret

_tcsfxcat endp
28 changes: 28 additions & 0 deletions include/pe/_tcstrim.asm
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
; _TCSTRIM.ASM--
;
; Copyright (c) The Asmc Contributors. All rights reserved.
; Consult your license regarding permissions and restrictions.
;
; int strtrim(char *);
; int _wstrtrim(wchar_t *);
;
; Return EAX char count, RCX string, and edx last char
;

_tcstrim proc uses rdi rbx string:LPTSTR

ldr rbx,string

.for ( rdi = &[rbx+_tcslen(rbx)*TCHAR-TCHAR], rcx = _pctype : eax : eax--, rdi-=TCHAR )

movzx edx,TCHAR ptr [rdi]
ifdef _UNICODE
.break .if ( edx > ' ' )
endif
.break .if !( byte ptr [rcx+rdx*2] & _SPACE )
mov TCHAR ptr [rdi],0
.endf
mov rcx,rbx
ret

_tcstrim endp
6 changes: 3 additions & 3 deletions include/sys/syscall.inc
Original file line number Diff line number Diff line change
Expand Up @@ -983,7 +983,7 @@ sys_rename proto :string_t, :string_t {
mov eax,SYS_RENAME
syscall
}
sys_mkdir proto :string_t {
sys_mkdir proto :string_t, :int_t {
mov eax,SYS_MKDIR
syscall
}
Expand Down Expand Up @@ -2321,8 +2321,8 @@ sys_kill proto fastcall :int_t, :int_t {
sys_rename proto fastcall :string_t, :string_t {
sys_call(SYS_RENAME, _1, _2)
}
sys_mkdir proto fastcall :string_t {
sys_call(SYS_MKDIR, _1)
sys_mkdir proto fastcall :string_t, :int_t {
sys_call(SYS_MKDIR, _1, _2)
}
sys_rmdir proto fastcall :string_t {
sys_call(SYS_RMDIR, _1)
Expand Down
3 changes: 2 additions & 1 deletion source/libc/direct/_tmkdir.asm
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ include io.inc
include errno.inc
include direct.inc
ifdef __UNIX__
include sys/stat.inc
include sys/syscall.inc
else
include winbase.inc
Expand All @@ -23,7 +24,7 @@ ifdef __UNIX__
ifdef _UNICODE
_set_errno( ENOSYS )
else
.ifsd ( sys_mkdir(rcx) < 0 )
.ifsd ( sys_mkdir(rcx, S_IRWXU or S_IRWXG or S_IROTH or S_IXOTH) < 0 )

neg eax
_set_errno(eax)
Expand Down
99 changes: 99 additions & 0 deletions source/tools/file/file.asm
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
; FILE.ASM--
;
; Copyright (c) The Asmc Contributors. All rights reserved.
; Consult your license regarding permissions and restrictions.
;

include io.inc
include fcntl.inc
include stdio.inc
include winbase.inc
include tchar.inc

.code

_tmain proc argc:int_t, argv:array_t

.new fname[ 256]:TCHAR
.new finfo[1024]:TCHAR

.if ( ecx != 2 ) ; argc

_tprintf( "Usage: FILE <name>[.exe]\n\n" )
.return( 1 )
.endif

mov rdi,[rdx+size_t] ; argv[1]
.ifd ( SearchPath( ".", rdi, ".exe", 256, &fname, NULL ) == 0 )

SearchPath( NULL, rdi, ".exe", 256, &fname, NULL )
.endif

.if ( eax == 0 )

_tprintf( "File not found: %s\n", rdi )
.return( 1 )
.endif

lea rdi,fname
.ifd ( _topen( rdi, O_RDONLY or O_BINARY, 0 ) == -1 )

_tperror(rdi)
.return( 1 )
.endif

mov ebx,eax
lea rsi,finfo

_read( ebx, rsi, 1024 )
_close( ebx )
_tprintf( "\n%s:\n Machine:", rdi )

mov eax,[rsi].IMAGE_DOS_HEADER.e_lfanew
add rsi,rax

.if ( [rsi].IMAGE_NT_HEADERS.FileHeader.Machine == IMAGE_FILE_MACHINE_I386 )

_tprintf( "\tI386\n ImageBase:\t%08X\n", [rsi].IMAGE_NT_HEADERS32.OptionalHeader.ImageBase )
.return( 0 )
.endif

_tprintf( "\t\tAMD64\n ImageBase:\t\t%016llX\n", [rsi].IMAGE_NT_HEADERS64.OptionalHeader.ImageBase )

lea rdi,@CStr( "No" )
lea rbx,@CStr( "Yes" )
mov rax,rdi
.if ( [rsi].IMAGE_NT_HEADERS64.FileHeader.Characteristics & IMAGE_FILE_LARGE_ADDRESS_AWARE )
mov rax,rbx
.endif
_tprintf( " Large address aware:\t%s\n", rax )

movzx esi,[rsi].IMAGE_NT_HEADERS64.OptionalHeader.DllCharacteristics
mov rax,rdi
.if ( esi & IMAGE_DLLCHARACTERISTICS_DYNAMIC_BASE )
mov rax,rbx
.endif
_tprintf( " ASLR:\t\t\t%s\t/DYNAMICBASE\n", rax )

mov rax,rdi
.if ( esi & IMAGE_DLLCHARACTERISTICS_HIGH_ENTROPY_VA )
mov rax,rbx
.endif
_tprintf( " ASLR^2:\t\t%s\t/HIGHENTROPYVA\n", rax )

mov rax,rdi
.if ( esi & IMAGE_DLLCHARACTERISTICS_NX_COMPAT )
mov rax,rbx
.endif
_tprintf( " DEP:\t\t\t%s\t/NXCOMPAT\n", rax )

mov rax,rdi
.if ( esi & IMAGE_DLLCHARACTERISTICS_TERMINAL_SERVER_AWARE )
mov rax,rbx
.endif
_tprintf( " TS Aware:\t\t%s\t/GS\n\n", rax )
.return( 0 )

_tmain endp

end _tstart
75 changes: 75 additions & 0 deletions source/tools/file/file.vcxproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|X64">
<Configuration>Debug</Configuration>
<Platform>X64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|win32">
<Configuration>Debug</Configuration>
<Platform>win32</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<AsmcDir>$(AsmcDir)</AsmcDir>
<RootNamespace>file</RootNamespace>
<VCProjectVersion>16.0</VCProjectVersion>
<Keyword>Win32Proj</Keyword>
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)Microsoft.Cpp.Default.props" />
<PropertyGroup Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
</PropertyGroup>
<Import Project="$(VCTargetsPath)Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
<Import Project="$(AsmcDir)\bin\asmc.props" />
</ImportGroup>
<ImportGroup Label="Shared">
</ImportGroup>
<ImportGroup Label="PropertySheets">
<Import Project="$(UserRootDir)Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup>
<LinkIncremental>true</LinkIncremental>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|X64'">
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<GenerateMapFile>true</GenerateMapFile>
<TargetMachine>MachineX64</TargetMachine>
<AdditionalLibraryDirectories>$(AsmcDir)\lib\X64</AdditionalLibraryDirectories>
<AdditionalOptions>/merge:.CRT=.rdata %(AdditionalOptions)</AdditionalOptions>
</Link>
<ASMC>
<UnicodeCharacterSet>false</UnicodeCharacterSet>
<GenerateUnwindInformation>true</GenerateUnwindInformation>
<GenerateCStackFrame>true</GenerateCStackFrame>
</ASMC>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|win32'">
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<GenerateMapFile>true</GenerateMapFile>
<AdditionalLibraryDirectories>$(AsmcDir)\lib\x86</AdditionalLibraryDirectories>
<AdditionalOptions>/merge:.CRT=.rdata %(AdditionalOptions)</AdditionalOptions>
</Link>
<ASMC>
<UnicodeCharacterSet>false</UnicodeCharacterSet>
<GenerateCStackFrame>true</GenerateCStackFrame>
<ObjectFileTypeCOFF>true</ObjectFileTypeCOFF>
</ASMC>
</ItemDefinitionGroup>
<ItemGroup>
<ASMC Include="file.asm" />
</ItemGroup>
<Import Project="$(VCTargetsPath)Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
<Import Project="$(AsmcDir)\bin\asmc.targets" />
</ImportGroup>
</Project>
12 changes: 12 additions & 0 deletions source/tools/file/makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Makefile for file
# Mon Oct 21 19:18:15 2024

flags = -q -pe

file:
asmc64 $(flags) $@.asm
$@
@pause

clean:
del file.exe
Loading

0 comments on commit 53c0e78

Please sign in to comment.