-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implemented a custom executable called, ForstWing Deployed Executable
- Loading branch information
1 parent
e7a6a82
commit 30e6a78
Showing
9 changed files
with
148 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import struct | ||
import os | ||
|
||
def check_endian(file_path): | ||
with open(file_path, 'rb') as file: | ||
data = file.read(4) | ||
|
||
if len(data) == 4: | ||
little_endian_value = int.from_bytes(data, byteorder='little') | ||
big_endian_value = int.from_bytes(data, byteorder='big') | ||
|
||
if little_endian_value == big_endian_value: | ||
print(f"The file '{file_path}' has an indeterminate endian.") | ||
exit(1) | ||
elif little_endian_value < big_endian_value: | ||
print(f"The file '{file_path}' is little-endian.") | ||
return 1 | ||
else: | ||
print(f"The file '{file_path}' is big-endian.") | ||
return 2 | ||
else: | ||
print(f"The file '{file_path}' does not contain enough data to determine its endian.") | ||
exit(1) | ||
|
||
def append_header(file_path, architecture, file_size): | ||
""" | ||
Appends a custom header to a binary file. | ||
Args: | ||
file_path (str): Path to the binary file. | ||
architecture (int): Architecture information (32 or 64 bits). | ||
file_size (int): Size of the file in bytes. | ||
""" | ||
signature = b'FWDE' # stands for Frost Wing Deployed Executable | ||
architecture_byte = struct.pack('B', architecture) # 'B' format code packs an unsigned char (1 byte) | ||
size_byte = struct.pack('B', file_size) # 'B' format code packs an unsigned char (1 byte) | ||
|
||
endian = check_endian(file_path) # 0 = error; 1 = little; 2 = big | ||
|
||
endian_byte = struct.pack('B', endian) # 'B' format code packs an unsigned char (1 byte) | ||
|
||
with open(file_path, 'rb') as file: | ||
existing_content = file.read() | ||
|
||
with open(file_path, 'wb') as file: | ||
file.write(signature + architecture_byte + size_byte + endian_byte) | ||
file.write(existing_content) | ||
|
||
file_path = 'desktop-manager.bin' | ||
architecture = 1 # 1 = 64 bits; 2 = 32 bits; 3 = 16 bits; 4 = 8 bits | ||
file_size = os.path.getsize(file_path) | ||
|
||
append_header(file_path, architecture, file_size) |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/** | ||
* @file fwde.h | ||
* @author Pradosh ([email protected]) | ||
* @brief The executor header for FrostWing Deployed Executable - 64 bits | ||
* @version 0.1 | ||
* @date 2024-01-07 | ||
* | ||
* @copyright Copyright (c) Pradosh 2024 | ||
* | ||
*/ | ||
#include <basics.h> | ||
#include <stdbool.h> | ||
|
||
typedef struct { | ||
char signature[4]; // FWDE | ||
int8 architecture; // 1 = 64 bits; 2 = 32 bits; 3 = 16 bits; 4 = 8 bits | ||
int8 raw_size; // size of just the executable part and not the header | ||
int8 endian; // 0 = error; 1 = little; 2 = big | ||
} fwde_header; | ||
|
||
void execute_fwde(int64* addr); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/** | ||
* @file fwde.c | ||
* @author Pradosh ([email protected]) | ||
* @brief The executor code for FrostWing Deployed Executable - 64 bits | ||
* @version 0.1 | ||
* @date 2024-01-07 | ||
* | ||
* @copyright Copyright (c) Pradosh 2024 | ||
* | ||
*/ | ||
|
||
#include <executables/fwde.h> | ||
|
||
bool verify_signature(char* signature){ | ||
if(signature[0] == 'F' && | ||
signature[1] == 'W' && | ||
signature[2] == 'D' && | ||
signature[3] == 'E'){ | ||
return true; | ||
} | ||
else | ||
return false; | ||
} | ||
|
||
void execute_fwde(int64* addr){ | ||
info("Verifying the FrostWing deployed executable!", __FILE__); | ||
|
||
int8* local = (int8*)addr; | ||
|
||
fwde_header* header = (fwde_header*)local; | ||
|
||
if(verify_signature(header->signature)){ | ||
info("Signature is correct!", __FILE__); | ||
}else{ | ||
error("Wrong signature! Abort.", __FILE__); | ||
return; | ||
} | ||
|
||
if(header->endian != 1 && header->endian != 2){ | ||
error("Undetermined endian executable! Abort.", __FILE__); | ||
return; | ||
} | ||
|
||
if(header->architecture == 1){ // 64 bits | ||
local += sizeof(fwde_header); | ||
if(*(local + header->raw_size) == 0){ | ||
info("Valid executable! and ready for execution!", __FILE__); | ||
} | ||
info("Starting executing the FrostWing deployed executable...", __FILE__); | ||
int (*execute_binary)() = (int (*)())local; | ||
info("Function is ready!", __FILE__); | ||
int status_code = execute_binary(); | ||
if(status_code != 0){ | ||
error("Executable returned an non zero status code! (something went wrong on the executable side)", __FILE__); | ||
printf("Status code : 0x%x (%d)", status_code, status_code); | ||
return; | ||
} | ||
}else{ | ||
error("Unsupported architecture!", __FILE__); | ||
return; | ||
} | ||
|
||
|
||
done("Completed successfully!", __FILE__); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters