Moderator: Moderator
Alexey wrote:Unfortunately, there is not such page now.
Alexey wrote:Anybody can publish a link to the gentee program in this forum.
#exe=1
#optimizer=1
/* ___ _ _ __ __ ___ ___
Author : Suresh Kumar A N ( SKAN ) | __(_) |___| \/ | \| __|
arian.suresh@gmail.com | _|| | / -_) |\/| | |) |__ \
Version : 0.10 Modified: 19.Sep.2011 |_| |_|_\___|_| |_|___/|___/
License : Unlicensed. For information, please refer to <http://unlicense.org/>
This File : http://dl.dropbox.com/u/6428211/Gentee/FileMD5/FileMD5.g
*/
import "kernel32.dll" {
uint GetFileSizeEx( uint, uint ) -> FileGetSize
uint CreateFileA( uint, uint, uint, uint, uint, uint, uint )-> FileOpen
uint ReadFile( uint, uint, uint, uint, uint ) -> FileRead
uint CloseHandle( uint ) -> hClose
uint GetCurrentProcessId() -> ProcID
uint OpenProcess( uint, uint, uint ) -> ProcOpen
uint SetPriorityClass( uint, uint ) -> ProcPriority
uint SetProcessWorkingSetSize( uint, uint, uint ) -> ProcSetWorkingSize
}
import "advapi32.dll" {
uint MD5Init( uint )
uint MD5Update( uint, uint, uint )
uint MD5Final( uint )
}
func main<main> {
str Par, str File = argv( Par,1 ), uint csz = uint( argv( Par,2 ) ), int hFile
if File == "" : print( "usage: FileMD5 <filename>" ) ; return exit( 1 )
hFile = FileOpen( File.ptr(), $GENERIC_READ,$FILE_SHARE_RW, 0,$OPEN_EXISTING, 0,0 )
if hFile < 1 : print( "error: file error / file not found" ) ; return
ulong Filesz ; FileGetSize( hFile, &Filesz )
if Filesz < 1L : print( "error: empty file" ) ; hClose( hFile ) ; return exit( 2 )
csz = ?( argv( Par,2 ) == "" || csz > 8, 32768, 4096 << csz )
uint iterReqd = uint( Filesz / ulong(csz) ) + 1
buf dat[csz], buf ctx[104], uint bytes, uint i, uint hProc
hProc = ProcOpen( 0x1F0FFF, 0, ProcID() )
ProcPriority( hProc, 0x80 /* HIGH_PRIORITY_CLASS */ )
ProcSetWorkingSize( hProc, -1, -1 )
hClose( hProc )
MD5Init( ctx.ptr() )
for i = 1, i <= iterReqd, i++ {
FileRead( hFile, dat.ptr(), csz, &bytes, 0 )
MD5Update( ctx.ptr(), dat.ptr(), bytes )
}
MD5Final( ctx.ptr() ) ; hClose( hFile )
uint n, str md5
for i = 1, i <= 16, i++
: n = ctx[ 87 + i ] ; md5.hexu( n >> 4 ) ; md5.hexu( n & 15 )
print( md5 ) ; return exit( 0 )
}
#exe=1
#optimizer=1
/* _ _ _____ _ _____ _
Author : Suresh Kumar A N ( SKAN ) | | | | __ \| | / ____| | |
arian.suresh@gmail.com | | | | |__) | | | | __ ___| |_
| | | | _ /| | | | |_ |/ _ \ __|
Version : 0.9.0.0 | |__| | | \ \| |___| |__| | __/ |_
Modified : 01.Oct.2011 \____/|_| \_\______\_____|\___|\__|
>> Internet Explorer based Downloader
License : Unlicensed. For information, please refer to <http://unlicense.org/>
This File : http://dl.dropbox.com/u/6428211/Gentee/URLGet/v0.9.0.0/URLGet.g
Compiled : http://dl.dropbox.com/u/6428211/Gentee/URLGet/v0.9.0.0/URLGet.exe
Usage : URLGet <url>
*/
import "kernel32.dll" {
uint CreateFileW( uint, uint, uint, uint, int, int, int ) -> FileCreate
uint CopyFileW( uint, uint, uint ) -> FileCopy
uint DeleteFileW( uint ) -> FileDelete
uint CloseHandle( uint )
uint GetCurrentProcessId() -> ProcessID
uint OpenProcess( uint, uint, uint ) -> ProcessOpen
uint SetPriorityClass( uint, uint ) -> ProcessSetPriority
uint SetProcessWorkingSetSize( uint, uint, uint ) -> ProcessSetWorkingSize
uint GetConsoleWindow()
uint GetCommandLineW()
uint GetCurrentDirectoryW( uint, uint )
uint GetShortPathNameW( uint, uint, uint )
uint lstrlenW( uint ) -> StrLenW
uint lstrcpyW( uint, uint ) -> StrCopyW
}
import "shlwapi.dll" {
uint PathFileExistsW( uint ) -> FileExistW
uint PathFileExistsA( uint ) -> FileExistA
uint StrRChrW( uint, uint, uint )
}
import "user32.dll" {
uint SendMessageW( uint, uint, uint, uint ) -> SendMessage
uint IsWindow( uint ) -> WinExist
uint SetWindowTextW( uint, uint )
uint SetWindowTextA( uint, uint )
}
import "ole32.dll" {
uint CoInitialize( uint )
uint CoUninitialize()
}
import "urlmon.dll" {
uint URLDownloadToCacheFileW( uint, uint, uint, uint, uint, uint )
}
import "msvcrt.dll" <cdeclare> {
uint _wsplitpath( uint, uint, uint, uint, uint )
}
define <export namedef> {
BINDF = 0x10 /* BINDF Enumerated Type - http://goo.gl/k2B8s */
E_ABORT = 0x80004004
MAX_PATH = 260 * 2
NORMAL_PRIORITY_CLASS = 0x00000020
WM_USER = 0x400
UGM_INIT = WM_USER + 1
UGM_SETPRIORITY = WM_USER + 2
UGM_BINDF = WM_USER + 3
UGM_CACHEFILE = WM_USER + 4
UGM_TARGETFILE = WM_USER + 5
UGM_DEINIT = WM_USER + 6
UGM_CANCEL = WM_USER + 16
}
global {
uint ConsoleWnd ; uint CallerWnd ; uint CallerMsg
uint dSz, NoFileCopy, FileCopied
ustr CacFile, CacFileShort, TrgFile, TrgFileShort
arrstr BINDSTATUS = %{ "", /* http://goo.gl/UCl1Q */
"Finding Resource","Connecting","Redirecting","Begin Download","Downloading",
"End Download","Begin Download Components","Install Components",
"End Download Components","Using Cached Copy","Sending Request","ClassID Available",
"MIME Type Available","Cache Filename Available","Begin Sync Operation",
"End Sync Opertion","Begin Upload","Uploading","End Upload","Protocol ClassID",
"Encoding","Verified MIME type Available","Class Install Location","Decoding",
"Loading MIME Handler","Content Disposition Attach","Filter Report MIME Type",
"CLSID can Instantiate","IUnknown Available","Direct Bind","Raw MIME Type",
"Proxy Detecting","Accept Ranges","Cookie Sent","Compact Policy Received",
"Cookie Supressed","Cookie State Unknown","Cookie State Accept",
"Cookie State Reject","Cookie State Prompt","Cookie State Leash",
"Cookie State Downgrade","Policy HREF","P3P Header","Session Cookie Received",
"Persistent Cookie Received","Session Cookies Allowed","Cache Control",
"Content Disposition Filename","MIME Text Plain Mismatch","Publisher Available",
"Display Name Available","SSLUX NAV Blocked","Server MIME type Available",
"Sniffed ClassID Available","","","","","","","","","","","","","" }
}
type VTABLE { uint cb1 ; uint cb2 ; uint cb3 ; uint cb4 ; uint cb5 ; uint cb6
uint cb7 ; uint cb8 ; uint cb9 ; uint cba ; uint cbb
}
// - - - - - - - - - - - - - - - - - - - - - - - - StrGet()
func uint StrGet( uint sPtr, ustr trg ) {
uint sLen = StrLenW( sPtr ) ; buf buff[sLen * 2 + 2]
StrCopyW( buff.ptr(), sPtr ) ; trg.copy( buff.ptr() )
return sLen
}
// - - - - - - - - - - - - - - - - - - - - - - - SplitPath()
func uint SplitPath( ustr filepath fdir fnam fext ) {
uint slen = (*filepath) * 2 + 2
buf fd1[slen] ; buf fd2[slen] ; buf fn[slen] ; buf fe[slen]
uint res = _wsplitpath( filepath.ptr(), fd1.ptr(), fd2.ptr(), fn.ptr(), fe.ptr() )
ustr fdir1, fdir2 ; fdir1.copy( fd1.ptr() ) ; fdir2.copy( fd2.ptr() )
fdir = fdir1 + fdir2 ; fnam.copy( fn.ptr() ) ; fext.copy( fe.ptr() )
return res
}
// - - - - - - - - - - - - - - - - - - - - - - GetCurrentDir()
func uint GetCurrentDir( ustr filename ) {
uint reqsz = GetCurrentDirectoryW( 0, 0 ) * 2
buf fnam[reqsz] ; GetCurrentDirectoryW( reqsz, fnam.ptr() )
filename.copy( fnam.ptr() )
return reqsz
}
// - - - - - - - - - - - - - - - - - - - - - GetShortPathName()
func uint GetShortPathName( ustr filelongpath fileshortpath ) {
uint reqsz = GetShortPathNameW( filelongpath.ptr(), 0, 0 ) * 2 + 2
buf fshp[reqsz] = GetShortPathNameW( filelongpath.ptr(), fshp.ptr(), reqsz )
fileshortpath.copy( fshp.ptr() )
return reqsz
}
// - - - - - - - - - - - - - - - - - - - - - CreateTargetFile()
func uint CreateTargetFile( ustr CacheFile TargetFile ) {
GetShortPathName( CacheFile, CacFileShort )
str CacheFileA = str( CacheFile )
if FileExistA( CacheFileA.ptr() ) : SetWindowTextA( ConsoleWnd, CacheFileA.ptr() )
else : SetWindowTextW( ConsoleWnd, CacFileShort.ptr() )
if WinExist( CallerWnd ) : SendMessage( CallerWnd, CallerMsg, UGM_CACHEFILE, 0 )
if NoFileCopy: return 0
ustr CurrentFolder ; GetCurrentDir( CurrentFolder )
ustr Folder, Filename, Ext
SplitPath( CacheFile, Folder, Filename, Ext )
uint Found5B ; uint FilenameLen = StrLenW( Filename.ptr() )
if Filename[ FilenameLen-1 ] = 0x5D && Found5B = StrRChrW( Filename.ptr(), 0, 0x5B )
: Filename.setlen( ( Found5B - Filename.ptr() ) / 2 )
uint i ; TargetFile = CurrentFolder + "\\" + Filename + Ext
for i=1, FileExistW( TargetFile.ptr() ), i++
: TargetFile = CurrentFolder + "\\" + Filename + "." + str(i) + Ext
CloseHandle( FileCreate( TargetFile.ptr(), 0x40000000, 2, 0, 2, 0, 0 ) )
GetShortPathName( TargetFile, TrgFileShort )
str TargetFileA = str( TargetFile )
if FileExistA( TargetFileA.ptr() ) : SetWindowTextA( ConsoleWnd, TargetFileA.ptr() )
else : SetWindowTextW( ConsoleWnd, TrgFileShort.ptr())
if WinExist( CallerWnd ) : SendMessage( CallerWnd, CallerMsg, UGM_TARGETFILE, 0 )
return FileExistW( TargetFile.ptr() )
}
// - - - - - - - - - - - - - - - - - - - - 11 callback functions
func uint Callback1( uint param1 param2 param3 ) { return 0 }
func uint Callback2( uint param1 ) { return 0 }
func uint Callback3( uint param1 ) { return 0 }
func uint Callback4( uint param1 param2 param3 ) { return 0 }
func uint Callback5( uint param1 param2 ) { return 0 }
func uint Callback6( uint param1 param2 ) { return 0 }
func uint Callback8( uint param1 param2 param3 ) { return 0 }
func uint Callback9( uint param1 param2 param3 ) { return 0 }
func uint CallbackA( uint param1 param2 param3 param4 param5 ) { return 0 }
func uint CallbackB( uint param1 param2 param3 ) { return 0 }
/* Callback7() alias OnProgress() - http://goo.gl/xH7KN */
func uint OnProgress( uint pThis Prog PMax Stat pStatText ) {
uint wParam, lParam, retv, str Capt
switch ( wParam = Stat ) {
case 4 : lParam = dSz = ?( Prog < PMax, PMax, 0 )
case 5,6 : lParam = Prog
case 14 : StrGet( pStatText, CacFile ) ; CreateTargetFile( CacFile, TrgFile )
default : lParam = 0
}
SetWindowTextW( ConsoleWnd, pStatText )
if WinExist( CallerWnd ): retv = SendMessage( CallerWnd, CallerMsg, wParam, lParam )
if dSz>0: Capt = str( Prog*100/dSz ) + "% [" + str( Prog ) + "/" + str( PMax ) + "]"
else : Capt = str( Prog ) + " » " + BINDSTATUS[ Stat ]
SetWindowTextA( ConsoleWnd, Capt.ptr() )
if ( wParam == 6 && NoFileCopy == 0 )
: FileCopied = FileCopy( CacFile.ptr(), TrgFile.ptr(), 0 )
if ( WinExist( CallerWnd ) && retv==E_ABORT )
: SendMessage( CallerWnd, CallerMsg, UGM_CANCEL, 1 )
return retv
}
// - - - - - - - - - - - - - - - - - - - - - - MAIN FUNCTION
func main<main> {
ConsoleWnd = GetConsoleWindow()
ustr CmdLine ; CmdLine.copy( GetCommandLineW() )
arrustr ArgsU ; ArgsU = CmdLine.split( 0x0020, $SPLIT_QUOTE )
uint ArgsCount = *ArgsU, ustr url
if ArgsCount > 1 : url = ArgsU[1]
if ArgsCount > 2 : NoFileCopy = uint( str( ArgsU[2] ) )
if ArgsCount > 3 : CallerWnd = uint( str( ArgsU[3] ) )
if ArgsCount > 4 : CallerMsg = uint( str( ArgsU[4] ) )
if url == "" : print( "usage: UrlGet <url>" ) ; return exit( 1 )
if WinExist( CallerWnd ): SendMessage( CallerWnd, CallerMsg, UGM_INIT, ConsoleWnd )
VTABLE vtable ; vtable.cb1 = callback( &Callback1, 3 )
vtable.cb2 = callback( &Callback2, 1 ) ; vtable.cb3 = callback( &Callback3, 1 )
vtable.cb4 = callback( &Callback4, 3 ) ; vtable.cb5 = callback( &Callback5, 2 )
vtable.cb6 = callback( &Callback6, 2 ) ; vtable.cb7 = callback( &OnProgress,5 )
vtable.cb8 = callback( &Callback8, 3 ) ; vtable.cb9 = callback( &Callback9, 3 )
vtable.cba = callback( &CallbackA, 5 ) ; vtable.cbb = callback( &CallbackB, 3 )
buf vt[44] ; vt.copy( &vtable,44 )
uint PrPr = NORMAL_PRIORITY_CLASS ; uint PID = ProcessID()
if WinExist( CallerWnd ) {
switch PrPr = SendMessage( CallerWnd, CallerMsg, UGM_SETPRIORITY, PID ) {
case 0x80,0x8000,0x20,0x4000,0x40 { }
default { PrPr = NORMAL_PRIORITY_CLASS }
}}
CoInitialize( 0 ) ; buf cac[ MAX_PATH ], str HxEr
uint hProc = ProcessOpen( 0x1F0FFF, 0, PID )
if PrPr != NORMAL_PRIORITY_CLASS
: ProcessSetPriority( hProc, PrPr )
ProcessSetWorkingSize( hProc, -1, -1 ) ; CloseHandle( hProc )
uint UGR = URLDownloadToCacheFileW( 0, url.ptr(), cac.ptr(), MAX_PATH, BINDF, &vt )
CoUninitialize() /* URLDownloadToCacheFile - http://goo.gl/ui6E0 */
if NoFileCopy | FileCopied == 0 : FileDelete( TrgFile.ptr() )
if UGR != 0 { /* URL Moniker Error Codes - http://goo.gl/6SWCT */
if WinExist( CallerWnd ) : SendMessage( CallerWnd, CallerMsg, UGM_DEINIT, UGR )
HxEr.hexu( UGR ) ; print( "error: " + HxEr ) ; return exit( UGR )
}
str FileFullpathA = ?( FileCopied, str(TrgFile), str(CacFile) )
str FileShortpathA = ?( FileCopied, str(TrgFileShort), str(CacFileShort) )
if FileExistA( FileFullpathA.ptr() ) : print( FileFullpathA )
else : print( FileShortpathA )
if WinExist( CallerWnd ) : SendMessage( CallerWnd, CallerMsg, UGM_DEINIT, 0 )
return exit(0)
}#Res=LZ_.res
#exe=1
#optimizer=1
#norun=1
/* -- -- - -- - -- - -- - -- - -- - -- - -- - -- - -- - -- - -- - -- - -- - -- - -- - -- -
_ ______ _ _____ _
Author : Suresh Kumar A N ( SKAN ) | | |__ / \ | |_ _/ |
arian.suresh@gmail.com | | / /| \| | | | | |
| |___ / /_| |\ | | | | |
Version : LZ_.g v1.0.0.0 |_____/____|_| \_| |_| |_|
Created : 27-Sep-2012 NT Native Data Compression
Usage : LZ_ <Filename>
License : PD-self < http://en.wikipedia.org/wiki/Template:PD-self >
This File : http://tinyurl.com/skanbox/Gentee/LZ_/v1-0/LZ_.g
Resource : http://tinyurl.com/skanbox/Gentee/LZ_/v1-0/LZ_.res
Compiled : http://tinyurl.com/skanbox/Gentee/LZ_/v1-0/LZ_.exe
This is utility is written in 'Gentee Programming Language' >> http://gentee.com/
-- -- - -- - -- - -- - -- - -- - -- - -- - -- - -- - -- - -- - -- - -- - -- - -- - -- - */
import "ntdll" {
uint RtlDecompressBuffer( uint, uint, uint, uint, uint, uint )
uint RtlCompressBuffer( uint, uint, uint, uint, uint, uint, uint, uint )
uint RtlGetCompressionWorkSpaceSize( uint, uint, uint )
}
import "shlwapi.dll" {
uint HashData( uint, uint, uint, uint )
uint PathRemoveExtensionA( uint ) -> RemoveExt
}
import "kernel32.dll" {
uint RtlMoveMemory( uint, uint, uint ) -> MemMove
}
// - - - - - - - - - - - - - - - - - - - - - - - - Buf_Compress()
func uint Buf_Compress( buf Buf, uint Mode ) {
uint pBuf = Buf.ptr(), str marker ; marker.load( Buf.ptr(), 3 )
if ( marker == "LZ_" ) { return -1 } else { marker = "LZ_" }
uint CompressBufferWorkSpaceSize, CompressFragmentWorkSpaceSize
RtlGetCompressionWorkSpaceSize( Mode,
&CompressBufferWorkSpaceSize,
&CompressFragmentWorkSpaceSize )
buf CompressBufferWorkSpace[ CompressBufferWorkSpaceSize ]
uint NTSTATUS Final OrgSz, buf TempBuf[ OrgSz = *Buf ]
NTSTATUS = RtlCompressBuffer( Mode,
Buf.ptr(), *Buf,
TempBuf.ptr(), *TempBuf,
CompressFragmentWorkSpaceSize,
&Final,
CompressBufferWorkSpace.ptr() )
if NTSTATUS != 0 : return -2
uint hdrSz = 18
Buf.del( Final + hdrSz, *Buf - (Final + hdrSz) ) // Trim the Buffer to the exact size
MemMove( pBuf + hdrSz, TempBuf.ptr(), Final ) // Move data from Temp Buffer
// Prefix and fill 18 byte header with compressed data, required for Buf_Decompress()
MemMove( pBuf + 0 , marker.ptr(), 4 ) // Header Marker
MemMove( pBuf + 8 , &Mode, 2 ) // Compression mode
MemMove( pBuf + 10, &OrgSz, 4 ) // Uncompressed data size
MemMove( pBuf + 14, &Final, 4 ) // Compressed data size
HashData( pBuf + 8, Final + 10, pBuf + 4, 4 ) // Compute Hash & write @ Offset 4
return Final + hdrSz
}
// - - - - - - - - - - - - - - - - - - - - - - - Buf_Decompress()
func uint Buf_Decompress( buf Buf ) {
str marker ; marker.load( Buf.ptr(), 3 ) ; if ( marker != "LZ_" ) : return -1
uint cHash sHash Mode OrgSz ComSz, pBuf = Buf.ptr()
MemMove( &sHash, pBuf + 4, 4 ) // saved Hash
MemMove( &Mode, pBuf + 8, 2 ) // Compression mode
MemMove( &OrgSz, pBuf + 10, 4 ) // Uncompressed data size
MemMove( &ComSz, pBuf + 14, 4 ) // Compressed data size
HashData( pBuf + 8, ComSz + 10, &cHash, 4 ) // Computing Hash
if cHash != sHash : return -3 // Comparing Hash
uint NTSTATUS Final, hdrSz = 18, buf TempBuf[OrgSz]
NTSTATUS = RtlDecompressBuffer( Mode,
TempBuf.ptr(), OrgSz,
pBuf + hdrSz, ComSz,
&Final )
if NTSTATUS != 0 : return -2
Buf.expand( Final - ComSz - hdrSz ) // Expand the Buffer to the exact size
Buf.copy( TempBuf.ptr(), Final ) // Move data from Temp Buffer
return Final
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - MAIN()
func main<main> {
str ifile ; if ! fileexist( argv(ifile,1) ) : print( "File not found!" ) ; exit(-4)
buf buffer ; uint trgsz, bufsz = buffer.read( ifile )
str marker ; marker.load( buffer.ptr(), 3 ) ; ; str ofile = ifile
if ( marker == "LZ_" ) : trgsz = Buf_Decompress( buffer ) ; RemoveExt( ofile.ptr() )
else : trgsz = Buf_Compress( buffer, 0x102 ) ; ofile += ".lz_"
if trgsz < 1 : print( "Error!" ) ; exit(0)
ofile.setlenptr() ; buffer.write( ofile )
print( "LZNT1:\n\tIn : \( ifile ) -> \( bufsz ) \n\tOut : \( ofile ) -> \( trgsz )\n")
exit(0)
}
03-Oct-2012#Res=LZ_.res
#exe=1
#optimizer=1
#norun=1
/* -- -- - -- - -- - -- - -- - -- - -- - -- - -- - -- - -- - -- - -- - -- - -- - -- - -- -
_ ______ _ _____ _
Author : Suresh Kumar A N ( SKAN ) | | |__ / \ | |_ _/ |
arian.suresh@gmail.com | | / /| \| | | | | |
| |___ / /_| |\ | | | | |
Version : LZ_.g v1.1.0.0 |_____/____|_| \_| |_| |_|
Modified : 03-Oct-2012 ( 27-Sep-2012 ) NT Native Data Compression
Usage : LZ_ <Filename>
License : PD-self < http://en.wikipedia.org/wiki/Template:PD-self >
This File : http://tinyurl.com/skanbox/Gentee/LZ_/v1-1/LZ_.g
Resource : http://tinyurl.com/skanbox/Gentee/LZ_/v1-1/LZ_.res
Compiled : http://tinyurl.com/skanbox/Gentee/LZ_/v1-1/LZ_.exe
This is utility is written in 'Gentee Programming Language' >> http://gentee.com/
-- -- - -- - -- - -- - -- - -- - -- - -- - -- - -- - -- - -- - -- - -- - -- - -- - -- - */
import "ntdll" {
uint RtlDecompressBuffer( uint, uint, uint, uint, uint, uint )
uint RtlCompressBuffer( uint, uint, uint, uint, uint, uint, uint, uint )
uint RtlGetCompressionWorkSpaceSize( uint, uint, uint )
}
import "shlwapi.dll" {
uint HashData( uint, uint, uint, uint )
uint PathRemoveExtensionA( uint ) -> RemoveExt
}
import "kernel32.dll" {
uint RtlMoveMemory( uint, uint, uint ) -> MemCopy
}
// - - - - - - - - - - - - - - - - - - - - - - - - Buf_Compress()
func int Buf_Compress( buf Buf, uint Mode ) {
uint hdrSz = 18, pBuf = Buf.ptr(), str marker = "LZ_"
uint CompressBufferWorkSpaceSize, CompressFragmentWorkSpaceSize
RtlGetCompressionWorkSpaceSize( Mode,
&CompressBufferWorkSpaceSize,
&CompressFragmentWorkSpaceSize )
buf CompressBufferWorkSpace[ CompressBufferWorkSpaceSize ]
uint NTSTATUS Final OrgSz, buf TempBuf[ OrgSz = *Buf ]
NTSTATUS = RtlCompressBuffer( Mode,
Buf.ptr(), *Buf,
TempBuf.ptr(), *TempBuf,
CompressFragmentWorkSpaceSize,
&Final,
CompressBufferWorkSpace.ptr() )
if ( NTSTATUS != 0 || Final + hdrSz > OrgSz ) : return -1
Buf.del( Final + hdrSz, *Buf - (Final + hdrSz) ) // Trim the Buffer to the exact size
MemCopy( pBuf + hdrSz, TempBuf.ptr(), Final ) // Move data from Temp Buffer
// Prefix and fill 18 byte header with compressed data, required for Buf_Decompress()
MemCopy( pBuf + 0 , marker.ptr(), 4 ) // Header Marker
MemCopy( pBuf + 8 , &Mode, 2 ) // Compression mode
MemCopy( pBuf + 10, &OrgSz, 4 ) // Uncompressed data size
MemCopy( pBuf + 14, &Final, 4 ) // Compressed data size
HashData( pBuf + 8, Final + 10, pBuf + 4, 4 ) // Compute Hash & write @ Offset 4
return Final + hdrSz
}
// - - - - - - - - - - - - - - - - - - - - - - - Buf_Decompress()
func int Buf_Decompress( buf Buf ) {
str marker ; marker.load( Buf.ptr(), 3 ) ; if ( marker != "LZ_" ) : return -3
uint cHash sHash Mode OrgSz ComSz, pBuf = Buf.ptr()
MemCopy( &sHash, pBuf + 4, 4 ) // saved Hash
MemCopy( &Mode, pBuf + 8, 2 ) // Compression mode
MemCopy( &OrgSz, pBuf + 10, 4 ) // Uncompressed data size
MemCopy( &ComSz, pBuf + 14, 4 ) // Compressed data size
HashData( pBuf + 8, ComSz + 10, &cHash, 4 ) // Computing Hash
if cHash != sHash : return -2 // Comparing Hash
uint NTSTATUS Final, hdrSz = 18, buf TempBuf[OrgSz]
NTSTATUS = RtlDecompressBuffer( Mode,
TempBuf.ptr(), OrgSz,
pBuf + hdrSz, ComSz,
&Final )
if NTSTATUS != 0 : return -1
Buf.expand( Final - ComSz - hdrSz ) // Expand the Buffer to the exact size
Buf.copy( TempBuf.ptr(), Final ) // Move data from Temp Buffer
marker.load( Buf.ptr(), 3 ) ; if ( marker == "LZ_" ) : return Buf_Decompress( Buf )
return Final
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - MAIN()
func main<main> {
str ifile ; if ! fileexist( argv(ifile,1) ) : print( "File not found!" ) ; exit(-4)
str ofile = ifile ; buf buffer ; uint bufsz = buffer.read( ifile ), int tmpsz trgsz
str marker ; marker.load( buffer.ptr(), 3 )
if ( marker == "LZ_" )
: trgsz = Buf_Decompress( buffer ) ; RemoveExt( ofile.ptr() ) ; ofile.setlenptr()
else
: while ( tmpsz = Buf_Compress( buffer,0x102 ) ) > 0 { trgsz = tmpsz } ; ofile += ".lz_"
if trgsz < 1 { print( "Error!" ) ; exit( trgsz ) } else { buffer.write( ofile ) }
print( "LZNT1:\n\tIn : \( ifile ) -> \( bufsz ) \n\tOut : \( ofile ) -> \( trgsz )\n")
exit(0)
}