### Download and Execute Setup Script Source: https://github.com/byu-cpe/ecen224/blob/main/_labs/01_getting-started.md Downloads the installation script from a provided URL, makes it executable, and then runs it to install required tools on the Pi Z2W. You will need to enter the Pi's password when prompted. ```bash wget https://byu-cpe.github.io/ecen224/assets/scripts/install.sh ``` ```bash chmod +x install.sh ``` ```bash ./install.sh ``` -------------------------------- ### Download, Make Executable, and Run SD Card Imaging Script Source: https://github.com/byu-cpe/ecen224/blob/main/_labs/01_getting-started.md This script downloads the necessary imaging utility, makes it executable, and then runs it to prepare the SD card for the Raspberry Pi Zero 2 W. This process is crucial for installing the operating system and is a prerequisite for subsequent lab steps. Ensure you have the necessary permissions and sufficient time for the script to complete. ```bash wget https://byu-cpe.github.io/ecen224/assets/scripts/imager.sh chmod +x imager.sh ./imager.sh ``` -------------------------------- ### Check GCC and Make Installation Source: https://github.com/byu-cpe/ecen224/blob/main/recitation/make-walkthrough.md Verifies if the GCC C compiler and Gnu Make utility are installed on the system. If not installed, provides commands to install them using apt. ```bash gcc --version make --version ``` ```bash sudo apt install gcc sudo apt install make ``` -------------------------------- ### Configure Git Username and Email Source: https://github.com/byu-cpe/ecen224/blob/main/_labs/01_getting-started.md These commands set your Git username and email address, which are essential for committing changes and identifying your contributions on GitHub. This configuration is typically done during the initial GitHub setup on a new machine or environment. ```bash git config --global user.name "Your Name" git config --global user.email "your.email@example.com" ``` -------------------------------- ### Clone GitHub Repository Source: https://github.com/byu-cpe/ecen224/blob/main/_labs/01_getting-started.md This command clones a specified GitHub repository to your local file system. Replace 'repository_url' with the actual URL of the repository you wish to clone, typically provided by GitHub Classroom. ```bash git clone repository_url ``` -------------------------------- ### Initialize Three.js Scene and Load 3D Model (JavaScript) Source: https://github.com/byu-cpe/ecen224/blob/main/_labs/01_getting-started.md Sets up the Three.js renderer, scene, and camera. It configures orbit controls, adds ambient and point lights, and uses a LoadingManager to handle the loading of a 3MF model. The model is centered and added to the scene upon successful loading. ```javascript import * as THREE from 'three'; import { OrbitControls } from '../../assets/OrbitControls.js'; import { ThreeMFLoader } from '../../assets/3MFLoader.js'; let camera, scene, renderer, object, loader, controls; var container = document.getElementById('camera-body'); init(); function init() { renderer = new THREE.WebGLRenderer( { antialias: true, alpha: true } ); renderer.setPixelRatio( window.devicePixelRatio ); renderer.setSize( 500, 300 ); renderer.setClearColor( 0x000000, 0 ); // the default container.appendChild( renderer.domElement ); renderer.domElement.style.cursor = "grab"; scene = new THREE.Scene(); scene.add( new THREE.AmbientLight( 0xffffff, 0.2 ) ); camera = new THREE.PerspectiveCamera( 15, window.innerWidth / window.innerHeight, 1, 500 ); // Z is up for objects intended to be 3D printed. camera.up.set( 0, 0, 1 ); camera.position.set( - 100, - 250, 100 ); scene.add( camera ); controls = new OrbitControls( camera, renderer.domElement ); controls.addEventListener( 'change', render ); controls.minDistance = 50; controls.maxDistance = 400; controls.enablePan = false; controls.update(); const pointLight = new THREE.PointLight( 0xffffff, 0.8 ); camera.add( pointLight ); const manager = new THREE.LoadingManager(); manager.onLoad = function () { const aabb = new THREE.Box3().setFromObject( object ); const center = aabb.getCenter( new THREE.Vector3() ); object.position.x += ( object.position.x - center.x ); object.position.y += ( object.position.y - center.y ); object.position.z += ( object.position.z - center.z ); controls.reset(); scene.add( object ); render(); }; loader = new ThreeMFLoader( manager ); loadAsset( '../../assets/cam-case-sss.3mf' ); // window.addEventListener( 'resize', onWindowResize ); } function loadAsset( asset ) { loader.load( asset, function ( group ) { if ( object ) { object.traverse( function ( child ) { if ( child.material ) child.material.dispose(); if ( child.material && child.material.map ) child.material.map.dispose(); if ( child.geometry ) child.geometry.dispose(); } ); scene.remove( object ); } object = group; } ); } function onWindowResize() { camera.aspect = window.innerWidth / window.innerHeight; camera.updateProjectionMatrix(); renderer.setSize( window.innerWidth, window.innerHeight ); render(); } function render() { renderer.render( scene, camera ); } ``` -------------------------------- ### C Source Code Example (main.c) Source: https://github.com/byu-cpe/ecen224/blob/main/recitation/make-walkthrough.md A simple C program that calculates and prints the ounces of dry pasta needed for a given number of servings. It includes a header file 'servings.h' and uses a function 'servings2ounces' defined elsewhere. ```c #include #include "servings.h" int main() { int servings = 5; int ounces = servings2ounces(servings); printf("We need %d ounces of dry pasta to make %d servings.\n", ounces, servings); } ``` -------------------------------- ### Install Development Tools (Linux) Source: https://github.com/byu-cpe/ecen224/blob/main/recitation/gdb-walkthrough.md Installs essential development tools including gcc, build-essential, gcc-multilib, and gdb on a Linux system. These tools are necessary for compiling, linking, and debugging code. ```bash sudo apt update sudo apt install gcc build-essential sudo apt install gcc-multilib sudo apt install gdb ``` -------------------------------- ### Debugging with gdb Source: https://github.com/byu-cpe/ecen224/blob/main/recitation/attackLab-gettingStarted.md Utilize the gdb debugger to inspect the 'ctarget' executable. Commands like 'disassemble' help in finding buffer sizes and function addresses. ```bash gdb ctarget disassemble getbuf disassemble touch1 ``` -------------------------------- ### Visualize 3D Printed Enclosure with Three.js Source: https://github.com/byu-cpe/ecen224/blob/main/_labs/01_getting-started.md JavaScript code using the Three.js library to load and display a 3D model of the Pi Z2W kit's enclosure. It sets up the scene, camera, lighting, and controls for interactive viewing. Requires Three.js and OrbitControls modules. ```javascript import * as THREE from 'three'; import { OrbitControls } from '../../assets/OrbitControls.js'; import { ThreeMFLoader } from '../../assets/3MFLoader.js'; let camera, scene, renderer, object, loader, controls; var container = document.getElementById('camera-lid'); init(); function init() { renderer = new THREE.WebGLRenderer( { antialias: true, alpha: true } ); renderer.setPixelRatio( window.devicePixelRatio ); renderer.setSize( 750, 750 ); renderer.setClearColor( 0x000000, 0 ); // the default container.appendChild( renderer.domElement ); renderer.domElement.style.cursor = "grab"; scene = new THREE.Scene(); scene.add( new THREE.AmbientLight( 0xffffff, 0.2 ) ); camera = new THREE.PerspectiveCamera( 30, window.innerWidth / window.innerHeight, 1, 500 ); // Z is up for objects intended to be 3D printed. camera.up.set( 0, 0, 1 ); camera.position.set( - 100, - 250, 100 ); scene.add( camera ); controls = new OrbitControls( camera, renderer.domElement ); controls.addEventListener( 'change', render ); controls.minDistance = 100; controls.maxDistance = 1000; controls.enablePan = false; controls.update(); const pointLight = new THREE.PointLight( 0xffffff, 0.8 ); ``` -------------------------------- ### Jumping to Addresses with pushq and retq Source: https://github.com/byu-cpe/ecen224/blob/main/recitation/attackLab-gettingStarted.md A technique to jump to a specific address by pushing the target address onto the stack and then returning. This is useful for controlling execution flow in exploit development. ```assembly pushq $0xabcdefgh retq ``` -------------------------------- ### Connecting to CAEDM Server with SSH Source: https://github.com/byu-cpe/ecen224/blob/main/recitation/attackLab-gettingStarted.md Establish an SSH connection to the CAEDM server to access the lab environment. Replace 'username' with your actual CAEDM username. ```bash ssh username@ssh.et.byu.edu ``` -------------------------------- ### C Hello World Program Source: https://github.com/byu-cpe/ecen224/blob/main/_labs/03_c-programming.md A basic 'Hello, World!' program in C. It demonstrates single-line and multi-line comments, includes the standard input/output library, and uses the printf function to display text to the console. This is a foundational example for new C programmers. ```c // This is a single line comment. /* This is a multi-line comment. Any text that is between the slash-star and the star-slash will be ignored. */ #include int main() { printf("Hello, World!\n"); return 0; } ``` -------------------------------- ### Examine Memory with GDB 'x' Command Source: https://github.com/byu-cpe/ecen224/blob/main/recitation/gdb-walkthrough.md The 'x' command in GDB allows you to examine memory contents. This example shows how to display 16 bytes in hexadecimal format starting from the 'add' function. Use 'help x' for detailed options on formatting, word size, and amount to print. ```gdb x/16xb add ``` -------------------------------- ### Control systemd Daemon Operations (Bash) Source: https://github.com/byu-cpe/ecen224/blob/main/_labs/11_doorbell.md These commands demonstrate how to start or stop a systemd daemon. While the example uses 'sshd', these principles apply to any managed service. Use with caution as stopping essential services can disrupt system functionality. ```bash sudo systemctl start sshd # Starts the sshd daemon sudo systemctl stop sshd # Stops the sshd daemon ``` -------------------------------- ### systemd Service Configuration for Doorbell Source: https://context7.com/byu-cpe/ecen224/llms.txt Details the creation and management of a systemd service for the doorbell program to ensure it starts automatically on boot. This includes creating the service file, defining its properties, and using systemctl commands for service management. ```bash # Create service file sudo nano /etc/systemd/system/doorbell.service ``` ```ini # /etc/systemd/system/doorbell.service [Unit] Description=Smart Doorbell Service [Service] WorkingDirectory=/home/username/doorbell-project ExecStart=/home/username/doorbell-project/main [Install] WantedBy=multi-user.target ``` ```bash # Service management commands sudo systemctl start doorbell.service # Start the service sudo systemctl stop doorbell.service # Stop the service sudo systemctl status doorbell.service # Check status and logs sudo systemctl enable doorbell.service # Enable start on boot sudo systemctl disable doorbell.service # Disable start on boot # After making changes, reload daemon sudo systemctl daemon-reload ``` -------------------------------- ### C For Loop Example Source: https://github.com/byu-cpe/ecen224/blob/main/recitation/cta-walkthrough.md A C function that initializes an array with multiples of 5 using a for loop. This snippet is used to demonstrate how for loops are represented in assembly language. ```c void loop() { int a[10]; for (int i=0; i<10; ++i) { a[i] = i*5; } } ``` -------------------------------- ### Check Git Version Source: https://github.com/byu-cpe/ecen224/blob/main/recitation/git-walkthrough.md Verifies if Git is installed and displays its version number. This is a fundamental check before proceeding with any Git operations. ```bash git -v ``` -------------------------------- ### Start GDB Debugger Source: https://github.com/byu-cpe/ecen224/blob/main/recitation/gdb-walkthrough.md Launches the GNU Debugger (GDB) with the compiled program 'a.out' as the target for debugging. This command assumes the program has been successfully compiled in the previous step. ```bash gdb a.out ``` -------------------------------- ### Enable and Disable systemd Services (Bash) Source: https://github.com/byu-cpe/ecen224/blob/main/_labs/11_doorbell.md These commands manage whether a systemd service automatically starts when the system boots. 'enable' ensures the service runs on startup, while 'disable' prevents it. This is crucial for applications like the doorbell that need to be persistent. ```bash sudo systemctl enable my-service.service # Enables the my-service service sudo systemctl disable my-service.service # Disables the my-service service ``` -------------------------------- ### Multi-step Compilation and Linking with GCC Source: https://github.com/byu-cpe/ecen224/blob/main/recitation/make-walkthrough.md Demonstrates the separate steps for compiling C source files into object files and then linking these object files to create an executable. This approach is useful for managing larger projects. ```bash gcc -c pasta.c gcc -c servings.c gcc pasta.o servings.o -o pasta ``` -------------------------------- ### SSH into Raspberry Pi Z2W Source: https://github.com/byu-cpe/ecen224/blob/main/_labs/01_getting-started.md Establishes an SSH connection to the Pi Z2W. You will be prompted for the password set during initial setup. Trust the remote machine by typing 'yes' when prompted. ```bash ssh NETID@doorbell-NETID.local ``` -------------------------------- ### Create C Program Files Source: https://github.com/byu-cpe/ecen224/blob/main/recitation/make-walkthrough.md Defines the content for three source files: 'pasta.c', 'servings.h', and 'servings.c', which together form a simple C program to calculate pasta ounces based on servings. ```c #include #include "servings.h" int main() { int servings = 5; int ounces = servings2ounces(servings); printf("You need %d ounces of dry pasta to make %d servings.\n", ounces, servings); } ``` ```c #include "servings.h" int servings2ounces(int servings) { return servings * 3; } ``` ```c int servings2ounces(int servings); ``` -------------------------------- ### Initialize and Draw on LCD HAT using C Source: https://context7.com/byu-cpe/ecen224/llms.txt Demonstrates initializing the display, drawing various shapes (rectangles, circles, lines), and rendering text with different fonts. It also includes a main loop for handling button presses and updating the display. Requires the display, buttons, colors, fonts, and device libraries. ```c #include "display.h" #include "buttons.h" #include "colors.h" #include "fonts.h" #include "device.h" int main() { // Initialize display and buttons (order matters!) display_init(); buttons_init(); // Clear screen to white display_clear(WHITE); // Draw shapes display_draw_rectangle(0, 5, 128, 15, BYU_ORANGE, true, 1); display_draw_circle(64, 64, 30, BLUE, false, 2); display_draw_line(0, 0, 128, 128, RED, 1); // Draw text with different fonts display_draw_string(10, 10, "Hello, World!", &Font8, WHITE, BLACK); display_draw_string(10, 30, "ECEn 224", &Font12, BLACK, WHITE); display_draw_char(60, 60, 'A', &Font16, RED, WHITE); // Main loop with button handling while (1) { if (button_up() == 0) { display_draw_string(10, 50, "UP pressed!", &Font8, GREEN, BLACK); while (button_up() == 0) { delay_ms(1); // Wait for release } } if (button_center() == 0) { display_clear(BLUE); while (button_center() == 0) { delay_ms(1); } } delay_ms(10); // Prevent CPU overload } return 0; } ``` -------------------------------- ### Disassembling Target with objdump Source: https://github.com/byu-cpe/ecen224/blob/main/recitation/attackLab-gettingStarted.md Use objdump to disassemble the 'ctarget' executable and save the output to a text file. This is used to find buffer sizes and function addresses. ```bash objdump -d ctarget > ctarget.txt ``` -------------------------------- ### C Compilation Process with GCC Source: https://context7.com/byu-cpe/ecen224/llms.txt Demonstrates the four stages of C compilation using GCC: preprocessing, compiling, assembling, and linking. This process transforms C source code into an executable program. The example shows a 'Hello, World!' program and the commands to generate intermediate files and the final executable. ```c // simple.c - Hello World program #include int main() { printf("Hello, World!\n"); return 0; } ``` ```bash # Step 1: Preprocessing - expands #include directives and macros gcc -E simple.c > simple_preprocessed.txt # Step 2: Compiling - converts C to assembly language gcc -S simple.c # Creates simple.s with ARM assembly instructions # Step 3: Assembling - converts assembly to machine code gcc -c simple.c # Creates simple.o object file # Step 4: Linking - combines object files and libraries gcc simple.c -o simple # Creates executable binary # Run the program ./simple # Output: Hello, World! # Check return value echo $? # Output: 0 (success) ``` -------------------------------- ### Unpacking Target Archive Source: https://github.com/byu-cpe/ecen224/blob/main/recitation/attackLab-gettingStarted.md Extract the contents of the target .tar file on the CAEDM server. This command will create a directory containing the lab executables and source files. ```bash tar -xvf targetK.tar ``` -------------------------------- ### Build C Program with GCC Source: https://github.com/byu-cpe/ecen224/blob/main/recitation/make-walkthrough.md Compiles and links the C source files ('pasta.c' and 'servings.c') into an executable file named 'pasta'. This is a single-step build command. ```bash gcc pasta.c servings.c -o pasta ``` -------------------------------- ### Transferring Files with scp Source: https://github.com/byu-cpe/ecen224/blob/main/recitation/attackLab-gettingStarted.md Use the scp command to securely copy files between your local machine and the CAEDM server. This is essential for transferring the target program and other necessary files. ```bash scp targetK.tar username@ssh.et.byu.edu:~ ``` -------------------------------- ### Initialize a New Git Repository Source: https://github.com/byu-cpe/ecen224/blob/main/recitation/git-walkthrough.md Creates a new Git repository in the current directory. This command initializes Git tracking for all files within the directory. ```bash git init ``` -------------------------------- ### Reboot Raspberry Pi Z2W Source: https://github.com/byu-cpe/ecen224/blob/main/_labs/01_getting-started.md Reboots the Raspberry Pi Z2W using the `sudo reboot` command. This action will disconnect the current SSH session. ```bash sudo reboot ``` -------------------------------- ### Switch to a Git Branch Source: https://github.com/byu-cpe/ecen224/blob/main/_pages/lab_setup.md This command switches your active branch to the specified branch. Use this after creating a new branch to start working on it. Replace `` with the name of the branch you want to switch to. ```bash git checkout ``` -------------------------------- ### Create and Modify a File Source: https://github.com/byu-cpe/ecen224/blob/main/recitation/git-walkthrough.md Demonstrates creating a file with initial text and then appending more text to it. This is a common precursor to staging and committing changes in Git. ```bash echo Some Text >README.md echo Some more text >>README.md ``` -------------------------------- ### Using Nano Text Editor Source: https://github.com/byu-cpe/ecen224/blob/main/_labs/02_command-line.md Provides essential keybindings for the `nano` text editor, a command-line interface for creating and editing files. Keybindings include saving (`Ctrl+O`), exiting (`Ctrl+X`), cutting (`Ctrl+K`), pasting (`Ctrl+U`), and searching (`Ctrl+W`). `nano` is suitable for SSH sessions as it doesn't require a GUI. ```bash nano your_file_name.txt ``` -------------------------------- ### Shutdown Raspberry Pi Zero 2 W Source: https://github.com/byu-cpe/ecen224/blob/main/_labs/01_getting-started.md Command to safely shut down the Raspberry Pi Zero 2 W. This ensures all processes are stopped before unplugging power. ```bash sudo shutdown now ``` -------------------------------- ### SSH and Network Commands for Raspberry Pi Source: https://context7.com/byu-cpe/ecen224/llms.txt This snippet includes essential bash commands for connecting to a Raspberry Pi via SSH, testing network connectivity with ping, downloading and executing setup scripts, and safely shutting down or rebooting the device. It assumes the Raspberry Pi is accessible on the local network. ```bash # Connect to Pi over local network ssh NETID@doorbell-NETID.local # Test network connectivity ping doorbell-NETID.local # Download and run setup scripts wget https://byu-cpe.github.io/ecen224/assets/scripts/install.sh chmod +x install.sh ./install.sh # Shutdown Pi safely sudo shutdown now # Reboot Pi sudo reboot ``` -------------------------------- ### Ping Raspberry Pi Z2W Source: https://github.com/byu-cpe/ecen224/blob/main/_labs/01_getting-started.md Verifies network connectivity to the Pi Z2W by sending ICMP echo requests. Replace 'NETID' with your actual NetID. If the ping fails, check the Ethernet connection and wait before retrying. ```bash # replace NETID with your NetID ping doorbell-NETID.local ``` -------------------------------- ### Verify SSH Connection to GitHub Source: https://github.com/byu-cpe/ecen224/blob/main/_labs/01_getting-started.md This command tests the SSH connection to GitHub using the configured SSH key. A successful connection confirms that your SSH key has been correctly added to your GitHub account and is properly set up for authentication. ```bash ssh -T git@github.com ``` -------------------------------- ### C Main Application Logic with Startup Delay Source: https://context7.com/byu-cpe/ecen224/llms.txt The main C file for the smart doorbell application. It includes an initial delay to prevent display conflicts during startup, initializes display and buttons, shows a welcome message, and enters a main loop to detect button presses for taking pictures and uploading. ```c // main.c - Add startup delay to avoid display conflicts #include int main() { // Wait for IP address display to finish sleep(15); display_init(); buttons_init(); // Show welcome message display_clear(WHITE); display_draw_string(20, 50, "Smart Doorbell", &Font12, BLACK, WHITE); display_draw_string(30, 70, "Ready!", &Font8, BLUE, WHITE); // Main doorbell loop while (1) { if (button_center() == 0) { // Take picture and upload in thread // Display "Ding Dong!" message delay_ms(2000); } delay_ms(10); } return 0; } ``` -------------------------------- ### Generate SSH Key for GitHub Source: https://github.com/byu-cpe/ecen224/blob/main/_labs/01_getting-started.md This command generates a new SSH key pair (public and private) for your GitHub account. The public key will be added to your GitHub profile, and the private key will be used to authenticate your connection securely. ```bash ssh-keygen -t ed25519 -C "your.email@example.com" ``` -------------------------------- ### Run Compiled C Program Source: https://github.com/byu-cpe/ecen224/blob/main/recitation/make-walkthrough.md Executes the compiled C program named 'pasta'. The program calculates and prints the required ounces of dry pasta for a given number of servings. ```bash ./pasta ``` -------------------------------- ### Compile and Run C Display Code Source: https://context7.com/byu-cpe/ecen224/llms.txt Instructions for compiling and running the C code that utilizes the display library. Compilation is handled by a Makefile, and execution requires sudo privileges for GPIO access. ```bash # Compile with Makefile (handles bcm2835 library linking) make test # Run with sudo for GPIO access sudo ./test ``` -------------------------------- ### Bash Command to Build with Make Source: https://github.com/byu-cpe/ecen224/blob/main/recitation/make-walkthrough.md The standard command to execute Make. Make automatically searches for a file named 'Makefile' in the current directory and runs the default target (usually the first one defined). ```bash make ``` -------------------------------- ### Compilation using Make Source: https://github.com/byu-cpe/ecen224/blob/main/_labs/06_display.md This command utilizes the Make build tool to compile a project. Make reads a Makefile to determine dependencies and execute compilation rules, significantly speeding up the build process by only recompiling necessary files. ```bash make test ``` -------------------------------- ### C Data Types and printf Formatting Source: https://context7.com/byu-cpe/ecen224/llms.txt Illustrates C's native and fixed-width data types, along with their typical sizes. It also demonstrates the use of `printf` with various format specifiers for displaying different data types, including integers, floats, and strings. Type casting is also shown. ```c #include #include int main() { // Native C data types with sizes char c = 'A'; // 1 byte - stores integer/character short s = 1000; // 2 bytes int i = 100000; // 4 bytes long l = 1000000000L; // 8 bytes float f = 3.14f; // 4 bytes - decimal number double d = 3.14159265; // 8 bytes - higher precision decimal // Fixed-width types from stdint.h (guaranteed size) uint8_t u8 = 255; // Unsigned 8-bit (0 to 255) int16_t i16 = -32768; // Signed 16-bit uint32_t u32 = 3735928559; // Unsigned 32-bit // Printf format specifiers printf("Character: %c\n", c); // Output: A printf("Decimal: %d\n", i); // Output: 100000 printf("Unsigned: %u\n", u32); // Output: 3735928559 printf("Hexadecimal: %x\n", u32); // Output: deadbeef printf("Float: %f\n", f); // Output: 3.140000 printf("String: %s\n", "Hello"); // Output: Hello // Multiple format specifiers printf("Values: %d, %x, %c\n", 42, 255, 'Z'); // Output: Values: 42, ff, Z // Casting between types int num = 7; float num_f = (float)num; // Explicit cast printf("Cast result: %f\n", num_f); // Output: 7.000000 return 0; } ``` -------------------------------- ### C Switch Statement Example Source: https://github.com/byu-cpe/ecen224/blob/main/recitation/cta-walkthrough.md A C function that uses a switch statement to return different integer values based on the input integer. This example helps in understanding how switch statements are compiled into assembly, often involving conditional jumps. ```c int switchit(int a) { switch(a) { case 1: return 12; case 2: return 9; case 3: return 42; default: return 0; } } ``` -------------------------------- ### C Function Example for ROP Gadget Identification Source: https://github.com/byu-cpe/ecen224/blob/main/_programming-assignments/attack-lab.md This C function, `setval_210`, is presented as an example to illustrate how useful ROP gadgets can be found within compiled code. Although the function's original purpose is seemingly irrelevant for attacks, its disassembled machine code contains a valuable gadget. ```c void setval_210(unsigned *p) { *p = 3347663060U; } ``` -------------------------------- ### Capture and Process Camera Image using C Source: https://context7.com/byu-cpe/ecen224/llms.txt Illustrates capturing an image from the Raspberry Pi camera, saving it as a BMP file, and then processing it for display. Includes memory allocation, image capture, saving, and applying image filters like color channel removal and grayscale conversion. Requires camera, image, and display libraries. ```c #include #include #include "camera.h" #include "image.h" #define IMG_SIZE 49206 // Size of 128x128 BMP image with header // Camera capture workflow void capture_and_display_image() { // Allocate buffer for image data uint8_t *img_buffer = malloc(IMG_SIZE); if (img_buffer == NULL) { printf("Error: Memory allocation failed\n"); return; } // Capture image from camera (includes BMP header) camera_capture_data(img_buffer, IMG_SIZE); // Save to file camera_save_to_file(img_buffer, IMG_SIZE, "viewer/doorbell.bmp"); // Convert to Bitmap struct for display/manipulation Bitmap bmp; if (create_bmp(&bmp, img_buffer) == LOAD_SUCCESS) { // Display raw pixel data on LCD display_draw_image_data(bmp.pxl_data, bmp.img_width, bmp.img_height); // Apply filters remove_color_channel(RED_CHANNEL, &bmp); display_draw_image_data(bmp.pxl_data, bmp.img_width, bmp.img_height); // Reset to original and apply different filter reset_pixel_data(&bmp); grayscale(&bmp); display_draw_image_data(bmp.pxl_data, bmp.img_width, bmp.img_height); // Clean up Bitmap struct destroy_bmp(&bmp); } // Free the capture buffer free(img_buffer); } ``` -------------------------------- ### C: Read string into buffer using getbuf Source: https://github.com/byu-cpe/ecen224/blob/main/_programming-assignments/attack-lab.md The `getbuf` function reads a string from standard input into a fixed-size buffer. It utilizes the `Gets` function, which is similar to the standard `gets` function, and does not perform bounds checking, making it vulnerable to buffer overflows. The function returns 1 upon successful execution. ```c unsigned getbuf() { char buf[BUFFER_SIZE]; Gets(buf); return 1; } ``` -------------------------------- ### Executing a Compiled Program Source: https://github.com/byu-cpe/ecen224/blob/main/_labs/06_display.md This command shows how to execute a compiled program. The 'sudo' prefix is required for programs that need elevated privileges to access hardware, such as the HAT hardware mentioned in the context. ```bash sudo ./main ``` -------------------------------- ### Manual Compilation with GCC Source: https://github.com/byu-cpe/ecen224/blob/main/_labs/06_display.md This command demonstrates the manual compilation of multiple C source files into a single executable using gcc. It is prone to errors and recompiles all files even for minor changes, making it inefficient for large projects. ```bash gcc -o test -l bcm2835 main.c buttons.c device.c display.c lcd.c log.c font8.c font12.c font16.c font20.c font24.c ``` -------------------------------- ### List All Git Branches Source: https://github.com/byu-cpe/ecen224/blob/main/_pages/lab_setup.md This command displays a list of all branches in your current Git repository. The currently active branch will be indicated, usually with an asterisk. ```bash git branch ``` -------------------------------- ### Make, Commit, and Push Changes to GitHub Source: https://github.com/byu-cpe/ecen224/blob/main/recitation/git-walkthrough.md This sequence of commands demonstrates how to make a change to a file (in this case, appending text to README.md), stage all changes, commit them with a message, and then push these committed changes to the remote GitHub repository. This is a fundamental workflow for updating your remote repository. ```bash echo One more change >>README.md git add * git commit -m "One more change." git push ```