Skip to content

Commit 435776c

Browse files
Add header icon edge-case tests + add OTA status edgecase
1 parent 6ebf1c2 commit 435776c

8 files changed

Lines changed: 232 additions & 3 deletions

File tree

extractor/main.c

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,18 @@ void index_file(char *path, char* filename, bool new) {
159159
readScriptHeader(file, &header);
160160
fclose(file);
161161

162-
bool validIcon = header.icon != NULL && strncmp(header.icon, "data:image", strlen("data:image")) == 0;
162+
bool validIcon = false;
163+
if (header.icon != NULL)
164+
{
165+
if (strncmp(header.icon, "data:image", strlen("data:image")) == 0)
166+
{
167+
validIcon = true;
168+
}
169+
if (access(header.icon, R_OK|W_OK) == F_OK)
170+
{
171+
validIcon = true;
172+
}
173+
}
163174
if (validIcon || header.useHooks) {
164175
Log("Valid icon OR uses hooks");
165176
// Create sdr folder

tests/Check OTA status v1.1.sh

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
#!/bin/sh
2+
# Name: Check OTA Status
3+
# Author: neura
4+
# Icon:
5+
# Created: jan-08-2025
6+
# Modified: jan-09-2025
7+
# Version: 1.1
8+
# Description: This scriptlet checks the status of OTA (Over-The-Air) update binaries on Kindle devices and informs the user whether updates are enabled or blocked.
9+
#
10+
# Changelog:
11+
# - jan-09-2025: added dynamic touch device detection in order to increase the compatibility across devices.
12+
# - jan-08-2025: first working version (works on KT4 using event2 device).
13+
14+
# Check the status of OTA binaries
15+
if [ -f /usr/bin/otaupd.bck ] && [ -f /usr/bin/otav3.bck ]; then
16+
MESSAGE1="OTA blocking is enabled."
17+
MESSAGE2="Your Kindle will NOT update."
18+
MESSAGE3="Your jailbreak is safe."
19+
MESSAGE4="Wanna restore OTA? Enable Airplane mode."
20+
21+
elif [ -f /usr/bin/otaupd ] && [ -f /usr/bin/otav3 ]; then
22+
MESSAGE1="OTA blocking is disabled."
23+
MESSAGE2="Your Kindle can be updated."
24+
MESSAGE3="Your jailbreak is in danger."
25+
MESSAGE4="Rename OTA binaries to keep jailbreak."
26+
27+
else
28+
MESSAGE1="OTA binaries are corrupted."
29+
MESSAGE2="Check manually."
30+
MESSAGE3="" # No third message
31+
MESSAGE4="" # No fourth message
32+
fi
33+
34+
# Function to force a full screen refresh
35+
force_refresh() {
36+
eips -c > /dev/null 2>&1 # Clear the screen silently
37+
eips -c > /dev/null 2>&1 # Double clear to ensure full refresh
38+
sleep 1 # Use integer value for sleep
39+
}
40+
41+
# Function to detect the correct touch device
42+
detect_touch_device() {
43+
awk '{
44+
if ($1 == "Section" && $2 == "\"InputDevice\"") { isInput=1 };
45+
if ($2 == "\"Device\"" && isInput) { inputDevice=$3; hasInputDevice=1 };
46+
if ($2 == "\"CorePointer\"" && hasInputDevice && isInput) {
47+
gsub(/\"/, "", inputDevice);
48+
print inputDevice
49+
}
50+
}' /etc/xorg.conf
51+
}
52+
53+
# Set the correct touch device dynamically
54+
TOUCH_DEVICE=$(detect_touch_device)
55+
if [ -z "$TOUCH_DEVICE" ]; then
56+
echo "Error: Could not detect touch device."
57+
exit 1
58+
fi
59+
60+
# Print the detected touch device (uncomment for debugging)
61+
# echo "[ DEBUG ] Detected touch device: $TOUCH_DEVICE"
62+
63+
# Display the messages with forced refresh
64+
force_refresh
65+
eips 0 0 "$MESSAGE1" > /dev/null 2>&1 # Display the first message
66+
eips 0 1 "$MESSAGE2" > /dev/null 2>&1 # Display the second message
67+
if [ -n "$MESSAGE3" ]; then # Check if there's a third message
68+
eips 0 2 "$MESSAGE3" > /dev/null 2>&1
69+
fi
70+
if [ -n "$MESSAGE4" ]; then # Check if there's a fourth message
71+
eips 0 3 "$MESSAGE4" > /dev/null 2>&1
72+
fi
73+
eips 0 5 "Tap the screen to exit." > /dev/null 2>&1 # Display instructions
74+
75+
# Wait for a tap
76+
while :; do
77+
# Refresh the screen periodically to keep messages visible
78+
force_refresh
79+
eips 0 0 "$MESSAGE1" > /dev/null 2>&1
80+
eips 0 1 "$MESSAGE2" > /dev/null 2>&1
81+
if [ -n "$MESSAGE3" ]; then
82+
eips 0 2 "$MESSAGE3" > /dev/null 2>&1
83+
fi
84+
if [ -n "$MESSAGE4" ]; then
85+
eips 0 3 "$MESSAGE4" > /dev/null 2>&1
86+
fi
87+
eips 0 5 "Tap the screen to exit." > /dev/null 2>&1
88+
89+
# Wait for a touch event to occur
90+
dd if="$TOUCH_DEVICE" bs=16 count=1 2>/dev/null | grep -q .
91+
if [ $? -eq 0 ]; then
92+
break
93+
fi
94+
95+
sleep 1 # Reduce CPU usage
96+
done
97+
98+
# Clear the screen and return to home
99+
force_refresh
100+
lipc-set-prop com.lab126.appmgrd start app://com.lab126.booklet.home

tests/extractor_test_edgecases.c

Lines changed: 48 additions & 0 deletions
Large diffs are not rendered by default.

tests/launcher_test_edgecases.c

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#include "launcher.h"
2+
#include <assert.h>
3+
#include <stdio.h>
4+
#include <stdlib.h>
5+
#include <string.h>
6+
7+
int main()
8+
{
9+
char* command = getScriptCommand("./tests/Check OTA status v1.1.sh");
10+
assert(command != NULL);
11+
printf("Check OTA status v1.1.sh - %s\n", command);
12+
assert(strcmp(command, "/mnt/us/libkh/bin/fbink -k; sh -l \"./tests/Check OTA status v1.1.sh\" 2>&1 | /mnt/us/libkh/bin/fbink -y 5 -r") == 0);
13+
free(command);
14+
15+
command = getScriptCommand("./tests/KindleCraft.sh");
16+
assert(command != NULL);
17+
printf("KindleCraft.sh - %s\n", command);
18+
assert(strcmp(command, "sh -l \"./tests/KindleCraft.sh\"") == 0);
19+
free(command);
20+
21+
printf("\n\n");
22+
const char* test = "4:app://com.notmarek.shell_integration.launcher./tests/KindleCraft.sh";
23+
go_callback(NULL, "test1", test, NULL);
24+
printf("\n\n");
25+
26+
test = "4:app://com.notmarek.shell_integration.launcher./tests/Check OTA status v1.1.sh";
27+
go_callback(NULL, "test2", test, NULL);
28+
return 0;
29+
}

tests/launcher_test_go_callback.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
int main()
88
{
9-
char* test = "4:app://com.notmarek.shell_integration.launcherhelp";
9+
char* test = "4:app://com.notmarek.shell_integration.launcher./tests/test.sh";
1010
go_callback(NULL, "test", test, NULL);
1111
return 0;
1212
}

tests/meson.build

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,12 @@ configure_file(
4444
copy: true
4545
)
4646

47+
configure_file(
48+
input: 'Check OTA status v1.1.sh',
49+
output: 'Check OTA status v1.1.sh',
50+
copy: true
51+
)
52+
4753
utils_test = executable('utils_test', ['utils_test.c', '../utils/utils.c'], include_directories: ['../utils', '.'])
4854
test('Test Utils', utils_test, is_parallel : false)
4955

@@ -79,4 +85,7 @@ launcher_test_go_callback = executable('launcher_test_go_callback', ['launcher_t
7985
test('Test Launcher Go Callback', launcher_test_go_callback, is_parallel: false)
8086

8187
launcher_test_unload_callback = executable('launcher_test_unload_callback', ['launcher_test_unload_callback.c', '../launcher/main.c', '../utils/utils.c'], include_directories: ['../utils', '.'], dependencies: [ lipc_dep, scanner_stub_dep ], c_args: ['-DLAUNCHER_TESTING'])
82-
test('Test Launcher Unload Callback', launcher_test_unload_callback, is_parallel: false)
88+
test('Test Launcher Unload Callback', launcher_test_unload_callback, is_parallel: false)
89+
90+
launcher_test_edgecases = executable('launcher_test_edgecases', ['launcher_test_edgecases.c', '../launcher/main.c', '../utils/utils.c'], include_directories: ['../utils', '.'], dependencies: [ lipc_dep, scanner_stub_dep ], c_args: ['-DLAUNCHER_TESTING'])
91+
test('Test Launcher Edge Cases', launcher_test_edgecases, is_parallel: false)

utils/utils.c

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include "utils.h"
2+
#include <ctype.h>
23
#include <stddef.h>
34
#include <stdlib.h>
45
#include <string.h>
@@ -20,6 +21,18 @@ char* urlDecode(char* raw)
2021
return result;
2122
}
2223

24+
void strip(char** string)
25+
{
26+
char* strippedString = *string;
27+
while (isspace(*strippedString)) { (strippedString)++; };
28+
char* back = strippedString + strlen(strippedString);
29+
while(back > strippedString && isspace(*(--back))) { printf("Back: [%c]\n", *back); *back = '\0'; };
30+
31+
char* finalString = strdup(strippedString);
32+
free(*string);
33+
*string = finalString;
34+
}
35+
2336
inline char* buildCommand(const char* command, const char* sub)
2437
{
2538
char* builtCommand = (char*) malloc(strlen(command) + strlen(sub) + 1);
@@ -101,14 +114,32 @@ void readScriptHeader(FILE* file, struct ScriptHeader* header)
101114
if (strncmp(buffer, "# Name: ", strlen("# Name: ")) == 0)
102115
{
103116
header->name = strdup(buffer + strlen("# Name: "));
117+
strip(&header->name);
118+
if (strlen(header->name) == 0)
119+
{
120+
free(header->name);
121+
header->name = NULL;
122+
}
104123
}
105124
else if (strncmp(buffer, "# Author: ", strlen("# Author: ")) == 0)
106125
{
107126
header->author = strdup(buffer + strlen("# Author: "));
127+
strip(&header->author);
128+
if (strlen(header->author) == 0)
129+
{
130+
free(header->author);
131+
header->author = NULL;
132+
}
108133
}
109134
else if (strncmp(buffer, "# Icon: ", strlen("# Icon: ")) == 0)
110135
{
111136
header->icon = strdup(buffer + strlen("# Icon: "));
137+
strip(&header->icon);
138+
if (strlen(header->icon) == 0)
139+
{
140+
free(header->icon);
141+
header->icon = NULL;
142+
}
112143
}
113144
else if (strncmp(buffer, "# UseHooks", strlen("# UseHooks")) == 0)
114145
{

utils/utils.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include <string.h>
99

1010
char* urlDecode(char* raw);
11+
void strip(char** string);
1112

1213
void recursiveDelete(char* path);
1314

0 commit comments

Comments
 (0)