Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
daily-scripts
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Recolic
daily-scripts
Commits
da1f0325
There was an error fetching the commit references. Please try again later.
Commit
da1f0325
authored
2 months ago
by
Recolic
Browse files
Options
Downloads
Patches
Plain Diff
.
parent
2f0e1ebe
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
archived/rflog-broken.h
+41
-25
41 additions, 25 deletions
archived/rflog-broken.h
fish-config/functions/totpapi.fish
+7
-0
7 additions, 0 deletions
fish-config/functions/totpapi.fish
rflog.h
+25
-41
25 additions, 41 deletions
rflog.h
with
73 additions
and
66 deletions
rflog.h-backup
→
archived/rflog-broken.h
+
41
−
25
View file @
da1f0325
// GPT-4o generated. NOT thread safe.
// v2502.
1
// v2502.
2
#ifndef SIMPLE_LOGGER_H
#define SIMPLE_LOGGER_H
...
...
@@ -11,15 +11,15 @@
#if defined(_WIN32) && defined(NTDDI_VERSION)
#include
<ntddk.h>
#include
<ntstrsafe.h>
// For RtlStringCbPrintfA
#define RL_SNPRINTF_F
UNC
RtlStringCbPrintfA
#define RL_SNPRINTF_F RtlStringCbPrintfA
#define RL_LOG_FILE_PATH "N/A"
#elif defined(_WIN32)
#include
<windows.h>
#define RL_SNPRINTF_F
UNC
snprintf
#define RL_SNPRINTF_F snprintf
#define RL_LOG_FILE_PATH "C:\\rflog.txt"
#else
#include
<sys/time.h>
#define RL_SNPRINTF_F
UNC
snprintf
#define RL_SNPRINTF_F snprintf
#define RL_LOG_FILE_PATH "/tmp/rflog.txt"
#endif
...
...
@@ -42,6 +42,16 @@ static RL_THREAD_LOC char log_buffer[RL_LOG_BUFFER_SIZE];
static
RL_THREAD_LOC
WCHAR
wideBuffer
[
RL_LOG_BUFFER_SIZE
];
#endif
#if defined(_WIN32) && defined(NTDDI_VERSION)
// Windows kernel-mode only
size_t
NaiveStrlen
(
const
char
*
str
)
{
if
(
!
str
)
return
0
;
size_t
len
=
0
;
while
(
str
[
len
])
len
++
;
return
len
;
}
#endif
RL_UNUSED
static
const
char
*
get_current_datetime
()
{
#if defined(_WIN32) && defined(NTDDI_VERSION)
// Windows kernel-mode implementation
...
...
@@ -53,7 +63,7 @@ RL_UNUSED static const char *get_current_datetime() {
RtlTimeToTimeFields
(
&
local_time
,
&
time_fields
);
// Format the datetime string
RL_SNPRINTF_F
UNC
(datetime_buffer, RL_DATETIME_BUFFER_SIZE,
RL_SNPRINTF_F
(
datetime_buffer
,
RL_DATETIME_BUFFER_SIZE
,
"%04d-%02d-%02d %02d:%02d:%02d.%03d"
,
time_fields
.
Year
,
time_fields
.
Month
,
time_fields
.
Day
,
time_fields
.
Hour
,
time_fields
.
Minute
,
time_fields
.
Second
,
0
);
// No millisecond precision in kernel
...
...
@@ -80,22 +90,28 @@ RL_UNUSED static const char *get_current_datetime() {
RL_UNUSED
static
void
log_to_file
(
const
char
*
message
)
{
#if defined(_WIN32) && defined(NTDDI_VERSION)
// Windows kernel-mode
size_t messageLen = strlen(message);
size_t maxConvertLength = RL_LOG_BUFFER_SIZE - 1; // Leave space for null terminator
if (messageLen > maxConvertLength) {
messageLen = maxConvertLength; // Truncate if message is too long
}
// Manually convert char* to WCHAR* by iterating through the string
for (size_t i = 0; i < messageLen; ++i) {
wideBuffer[i] = (WCHAR)message[i]; // Cast each char to WCHAR
{
// Windows kernel-mode
HANDLE
hPipe
;
UNICODE_STRING
pipeName
;
OBJECT_ATTRIBUTES
objAttr
;
IO_STATUS_BLOCK
ioStatus
;
NTSTATUS
status
;
LARGE_INTEGER
timeout
;
timeout
.
QuadPart
=
-
10
*
1000
*
10
;
// 10 ms timeout
RtlInitUnicodeString
(
&
pipeName
,
L"
\\
??
\\
pipe
\\
rflog_pipe"
);
InitializeObjectAttributes
(
&
objAttr
,
&
pipeName
,
OBJ_CASE_INSENSITIVE
,
NULL
,
NULL
);
status
=
ZwCreateFile
(
&
hPipe
,
GENERIC_WRITE
,
&
objAttr
,
&
ioStatus
,
NULL
,
FILE_ATTRIBUTE_NORMAL
,
0
,
FILE_OPEN
,
0
,
NULL
,
0
);
if
(
!
NT_SUCCESS
(
status
))
{
return
;
// Pipe does not exist or cannot be opened
}
status
=
ZwWriteFile
(
hPipe
,
NULL
,
NULL
,
NULL
,
&
ioStatus
,
(
void
*
)
message
,
(
ULONG
)
NaiveStrlen
(
message
),
NULL
,
NULL
);
ZwClose
(
hPipe
);
return
;
// old solution // TraceDtlsMiscTraceOnPort(NULL, wideBuffer);
}
wideBuffer[messageLen] = L'\0'; // Null-terminate the wide string
// Log the wide string
TraceDtlsMiscTraceOnPort(NULL, wideBuffer);
#else
// User mode
FILE
*
file
=
fopen
(
RL_LOG_FILE_PATH
,
"a"
);
...
...
@@ -110,23 +126,23 @@ RL_UNUSED static void log_to_file(const char *message) {
RL_UNUSED
static
void
rflogs
(
const
char
*
message
)
{
RL_SNPRINTF_F
UNC
(log_buffer, RL_LOG_BUFFER_SIZE, "[%s] %s", get_current_datetime(), message);
RL_SNPRINTF_F
(
log_buffer
,
RL_LOG_BUFFER_SIZE
,
"[%s] %s"
,
get_current_datetime
(),
message
);
log_to_file
(
log_buffer
);
}
RL_UNUSED
static
void
rflogsi
(
const
char
*
message
,
int
value
)
{
RL_SNPRINTF_F
UNC
(log_buffer, RL_LOG_BUFFER_SIZE, "[%s] %s: %d", get_current_datetime(), message, value);
RL_SNPRINTF_F
(
log_buffer
,
RL_LOG_BUFFER_SIZE
,
"[%s] %s: %d"
,
get_current_datetime
(),
message
,
value
);
log_to_file
(
log_buffer
);
}
RL_UNUSED
static
void
rflogsii
(
const
char
*
message
,
int
value
,
int
i2
)
{
RL_SNPRINTF_F
UNC
(log_buffer, RL_LOG_BUFFER_SIZE, "[%s] %s: %d, %d", get_current_datetime(), message, value, i2);
RL_SNPRINTF_F
(
log_buffer
,
RL_LOG_BUFFER_SIZE
,
"[%s] %s: %d, %d"
,
get_current_datetime
(),
message
,
value
,
i2
);
log_to_file
(
log_buffer
);
}
RL_UNUSED
static
void
rflogsiip
(
const
char
*
message
,
int
value
,
int
i2
,
void
*
ptr
)
{
RL_SNPRINTF_F
UNC
(log_buffer, RL_LOG_BUFFER_SIZE, "[%s] %s: %d, %d, %p", get_current_datetime(), message, value, i2, ptr);
RL_SNPRINTF_F
(
log_buffer
,
RL_LOG_BUFFER_SIZE
,
"[%s] %s: %d, %d, %p"
,
get_current_datetime
(),
message
,
value
,
i2
,
ptr
);
log_to_file
(
log_buffer
);
}
RL_UNUSED
static
void
rflogss
(
const
char
*
message1
,
const
char
*
message2
)
{
RL_SNPRINTF_F
UNC
(log_buffer, RL_LOG_BUFFER_SIZE, "[%s] %s: %s", get_current_datetime(), message1, message2);
RL_SNPRINTF_F
(
log_buffer
,
RL_LOG_BUFFER_SIZE
,
"[%s] %s: %s"
,
get_current_datetime
(),
message1
,
message2
);
log_to_file
(
log_buffer
);
}
...
...
This diff is collapsed.
Click to expand it.
fish-config/functions/totpapi.fish
0 → 100644
+
7
−
0
View file @
da1f0325
function totpapi
if test -n "$argv[1]"
curl -X POST https://recolic.net/res/river/rauth/secdump.php --data $argv[1]
else
echo "Usage: totpapi (rsec TOTP_CARD_SEED_*)"
end
end
This diff is collapsed.
Click to expand it.
rflog.h
+
25
−
41
View file @
da1f0325
// GPT-4o generated. NOT thread safe.
// v2502.
2
// v2502.
1
#ifndef SIMPLE_LOGGER_H
#define SIMPLE_LOGGER_H
...
...
@@ -11,15 +11,15 @@
#if defined(_WIN32) && defined(NTDDI_VERSION)
#include
<ntddk.h>
#include
<ntstrsafe.h>
// For RtlStringCbPrintfA
#define RL_SNPRINTF_F RtlStringCbPrintfA
#define RL_SNPRINTF_F
UNC
RtlStringCbPrintfA
#define RL_LOG_FILE_PATH "N/A"
#elif defined(_WIN32)
#include
<windows.h>
#define RL_SNPRINTF_F snprintf
#define RL_SNPRINTF_F
UNC
snprintf
#define RL_LOG_FILE_PATH "C:\\rflog.txt"
#else
#include
<sys/time.h>
#define RL_SNPRINTF_F snprintf
#define RL_SNPRINTF_F
UNC
snprintf
#define RL_LOG_FILE_PATH "/tmp/rflog.txt"
#endif
...
...
@@ -42,16 +42,6 @@ static RL_THREAD_LOC char log_buffer[RL_LOG_BUFFER_SIZE];
static
RL_THREAD_LOC
WCHAR
wideBuffer
[
RL_LOG_BUFFER_SIZE
];
#endif
#if defined(_WIN32) && defined(NTDDI_VERSION)
// Windows kernel-mode only
size_t
NaiveStrlen
(
const
char
*
str
)
{
if
(
!
str
)
return
0
;
size_t
len
=
0
;
while
(
str
[
len
])
len
++
;
return
len
;
}
#endif
RL_UNUSED
static
const
char
*
get_current_datetime
()
{
#if defined(_WIN32) && defined(NTDDI_VERSION)
// Windows kernel-mode implementation
...
...
@@ -63,7 +53,7 @@ RL_UNUSED static const char *get_current_datetime() {
RtlTimeToTimeFields
(
&
local_time
,
&
time_fields
);
// Format the datetime string
RL_SNPRINTF_F
(
datetime_buffer
,
RL_DATETIME_BUFFER_SIZE
,
RL_SNPRINTF_F
UNC
(
datetime_buffer
,
RL_DATETIME_BUFFER_SIZE
,
"%04d-%02d-%02d %02d:%02d:%02d.%03d"
,
time_fields
.
Year
,
time_fields
.
Month
,
time_fields
.
Day
,
time_fields
.
Hour
,
time_fields
.
Minute
,
time_fields
.
Second
,
0
);
// No millisecond precision in kernel
...
...
@@ -90,28 +80,22 @@ RL_UNUSED static const char *get_current_datetime() {
RL_UNUSED
static
void
log_to_file
(
const
char
*
message
)
{
#if defined(_WIN32) && defined(NTDDI_VERSION)
{
// Windows kernel-mode
HANDLE
hPipe
;
UNICODE_STRING
pipeName
;
OBJECT_ATTRIBUTES
objAttr
;
IO_STATUS_BLOCK
ioStatus
;
NTSTATUS
status
;
LARGE_INTEGER
timeout
;
timeout
.
QuadPart
=
-
10
*
1000
*
10
;
// 10 ms timeout
RtlInitUnicodeString
(
&
pipeName
,
L"
\\
??
\\
pipe
\\
rflog_pipe"
);
InitializeObjectAttributes
(
&
objAttr
,
&
pipeName
,
OBJ_CASE_INSENSITIVE
,
NULL
,
NULL
);
status
=
ZwCreateFile
(
&
hPipe
,
GENERIC_WRITE
,
&
objAttr
,
&
ioStatus
,
NULL
,
FILE_ATTRIBUTE_NORMAL
,
0
,
FILE_OPEN
,
0
,
NULL
,
0
);
if
(
!
NT_SUCCESS
(
status
))
{
return
;
// Pipe does not exist or cannot be opened
}
status
=
ZwWriteFile
(
hPipe
,
NULL
,
NULL
,
NULL
,
&
ioStatus
,
(
void
*
)
message
,
(
ULONG
)
NaiveStrlen
(
message
),
NULL
,
NULL
);
ZwClose
(
hPipe
);
return
;
// old solution // TraceDtlsMiscTraceOnPort(NULL, wideBuffer);
// Windows kernel-mode
size_t
messageLen
=
strlen
(
message
);
size_t
maxConvertLength
=
RL_LOG_BUFFER_SIZE
-
1
;
// Leave space for null terminator
if
(
messageLen
>
maxConvertLength
)
{
messageLen
=
maxConvertLength
;
// Truncate if message is too long
}
// Manually convert char* to WCHAR* by iterating through the string
for
(
size_t
i
=
0
;
i
<
messageLen
;
++
i
)
{
wideBuffer
[
i
]
=
(
WCHAR
)
message
[
i
];
// Cast each char to WCHAR
}
wideBuffer
[
messageLen
]
=
L'\0'
;
// Null-terminate the wide string
// Log the wide string
TraceDtlsMiscTraceOnPort
(
NULL
,
wideBuffer
);
#else
// User mode
FILE
*
file
=
fopen
(
RL_LOG_FILE_PATH
,
"a"
);
...
...
@@ -126,23 +110,23 @@ RL_UNUSED static void log_to_file(const char *message) {
RL_UNUSED
static
void
rflogs
(
const
char
*
message
)
{
RL_SNPRINTF_F
(
log_buffer
,
RL_LOG_BUFFER_SIZE
,
"[%s] %s"
,
get_current_datetime
(),
message
);
RL_SNPRINTF_F
UNC
(
log_buffer
,
RL_LOG_BUFFER_SIZE
,
"[%s] %s"
,
get_current_datetime
(),
message
);
log_to_file
(
log_buffer
);
}
RL_UNUSED
static
void
rflogsi
(
const
char
*
message
,
int
value
)
{
RL_SNPRINTF_F
(
log_buffer
,
RL_LOG_BUFFER_SIZE
,
"[%s] %s: %d"
,
get_current_datetime
(),
message
,
value
);
RL_SNPRINTF_F
UNC
(
log_buffer
,
RL_LOG_BUFFER_SIZE
,
"[%s] %s: %d"
,
get_current_datetime
(),
message
,
value
);
log_to_file
(
log_buffer
);
}
RL_UNUSED
static
void
rflogsii
(
const
char
*
message
,
int
value
,
int
i2
)
{
RL_SNPRINTF_F
(
log_buffer
,
RL_LOG_BUFFER_SIZE
,
"[%s] %s: %d, %d"
,
get_current_datetime
(),
message
,
value
,
i2
);
RL_SNPRINTF_F
UNC
(
log_buffer
,
RL_LOG_BUFFER_SIZE
,
"[%s] %s: %d, %d"
,
get_current_datetime
(),
message
,
value
,
i2
);
log_to_file
(
log_buffer
);
}
RL_UNUSED
static
void
rflogsiip
(
const
char
*
message
,
int
value
,
int
i2
,
void
*
ptr
)
{
RL_SNPRINTF_F
(
log_buffer
,
RL_LOG_BUFFER_SIZE
,
"[%s] %s: %d, %d, %p"
,
get_current_datetime
(),
message
,
value
,
i2
,
ptr
);
RL_SNPRINTF_F
UNC
(
log_buffer
,
RL_LOG_BUFFER_SIZE
,
"[%s] %s: %d, %d, %p"
,
get_current_datetime
(),
message
,
value
,
i2
,
ptr
);
log_to_file
(
log_buffer
);
}
RL_UNUSED
static
void
rflogss
(
const
char
*
message1
,
const
char
*
message2
)
{
RL_SNPRINTF_F
(
log_buffer
,
RL_LOG_BUFFER_SIZE
,
"[%s] %s: %s"
,
get_current_datetime
(),
message1
,
message2
);
RL_SNPRINTF_F
UNC
(
log_buffer
,
RL_LOG_BUFFER_SIZE
,
"[%s] %s: %s"
,
get_current_datetime
(),
message1
,
message2
);
log_to_file
(
log_buffer
);
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment