Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.ArrayList;
- import java.util.Collections;
- import java.util.HashMap;
- import java.util.Scanner;
- import java.util.regex.Matcher;
- import java.util.regex.Pattern;
- public class linker
- {
- public static void main(String[] args)
- {
- Scanner input = new Scanner(System.in);
- String filename = "^([A-Za-z0-9])+(.o:)$";
- String textSection = "^(\\s)*(U )([a-zA-Z0-9_]+)$";
- String dataSection = "^([0-9a-f]+) ([0-9a-f]+) ([TtbCdDU]) ([a-zA-Z0-9_]+)$";
- ArrayList<String> textArray = new ArrayList<String>();
- ArrayList<String[]> dataArray = new ArrayList<String[]>();
- HashMap<String, String> dataMap = new HashMap<String, String>();
- while(input.hasNextLine())
- {
- String line = input.nextLine();
- if (!line.equals(""))
- {
- if (line.matches(filename))
- {
- }
- else if (line.matches(textSection))
- {
- Pattern pattern = Pattern.compile(textSection);
- Matcher match = pattern.matcher(line);
- if (match.find())
- {
- textArray.add(match.group(3));
- }
- }
- else if (line.matches(dataSection))
- {
- Pattern pattern = Pattern.compile(dataSection);
- Matcher match = pattern.matcher(line);
- if (match.find())
- {
- String[] dataElement = new String[4];
- dataElement[0] = match.group(1);
- dataElement[1] = match.group(2);
- dataElement[2] = match.group(3);
- dataElement[3] = match.group(4);
- if (!dataMap.containsKey(dataElement[3]))
- {
- dataMap.put(dataElement[3], dataElement[2]);
- }
- else
- {
- if (dataMap.get(dataElement[3]).equals("C") && dataElement[2].toUpperCase().equals(dataElement[2]))
- {
- dataMap.put(dataElement[3], dataElement[2]);
- }
- else if (dataElement[2].equals("C") &&
- dataMap.get(dataElement[3]).toUpperCase().equals(dataMap.get(dataElement[3])))
- {
- continue;
- }
- else if (!dataMap.get(dataElement[3]).toUpperCase().equals(dataMap.get(dataElement[3])) &&
- dataElement[2].toUpperCase().equals(dataElement[2]))
- {
- dataMap.put(dataElement[3], dataElement[2]);
- }
- else if (dataMap.get(dataElement[3]).toUpperCase().equals(dataMap.get(dataElement[3])) &&
- dataElement[2].toUpperCase().equals(dataElement[2]))
- {
- System.out.println("Symbol " + dataElement[3] + " multiply defined");
- return;
- }
- }
- dataArray.add(dataElement);
- }
- }
- else
- {
- throw new IllegalArgumentException();
- }
- //System.out.println(line);
- }
- }
- Collections.sort(textArray);
- for (int i = 0; i < textArray.size(); i++)
- {
- if (dataMap.containsKey(textArray.get(i)))
- {
- textArray.remove(i);
- i--;
- }
- }
- for (String item: textArray)
- {
- System.out.println(" U " + item);
- }
- int counter = 0x400680;
- for(String[] data: dataArray)
- {
- if (data[2].equalsIgnoreCase("t"))
- {
- System.out.print(String.format("%016x ", counter));
- System.out.print(String.format("%016x ", Integer.parseInt(data[1], 16)));
- System.out.print(data[2] + " ");
- System.out.println(data[3]);
- int i = Integer.parseInt(data[1], 16);
- if (((i / 4) * 4) != i)
- {
- i = ((i / 4) + 1) * 4;
- }
- counter += i;
- }
- }
- counter = 0x601044;
- for(String[] data: dataArray)
- {
- if (data[2].equalsIgnoreCase("d"))
- {
- System.out.print(String.format("%016x ", counter));
- System.out.print(String.format("%016x ", Integer.parseInt(data[1], 16)));
- System.out.print(data[2] + " ");
- System.out.println(data[3]);
- int i = Integer.parseInt(data[1], 16);
- if (((i / 4) * 4) != i)
- {
- i = ((i / 4) + 1) * 4;
- }
- counter += i;
- }
- }
- for(String[] data: dataArray)
- {
- if (data[2].equalsIgnoreCase("b"))
- {
- System.out.print(String.format("%016x ", counter));
- System.out.print(String.format("%016x ", Integer.parseInt(data[1], 16)));
- System.out.print(data[2] + " ");
- System.out.println(data[3]);
- int i = Integer.parseInt(data[1], 16);
- if (((i / 4) * 4) != i)
- {
- i = ((i / 4) + 1) * 4;
- }
- counter += i;
- }
- else if (data[2].equalsIgnoreCase("c") && dataMap.get(data[3]).equals("C"))
- {
- data[2] = "B";
- System.out.print(String.format("%016x ", counter));
- System.out.print(String.format("%016x ", Integer.parseInt(data[1], 16)));
- System.out.print(data[2] + " ");
- System.out.println(data[3]);
- int i = Integer.parseInt(data[1], 16);
- if (((i / 4) * 4) != i)
- {
- i = ((i / 4) + 1) * 4;
- }
- counter += i;
- }
- }
- input.close();
- }
- }
- 2)
- 2. /home/ugrads/majors/ski23/Desktop/node-v9.5.0/out/Release/node
- 3. The -z flag takes a keyword that changes the way the linker treats the object. noexecstack is a keyword that tells the linker that it doesnt need an executable stack. src-> info ld
- 4. Using grep with " T " I found: ssl_cert_add1_chain_cert
- 5. I used grep and found that there are 502 strong global readonly symbols
- 6. Using size, I found that the size of the data section of the node executable is 101672
- 7.
- a. /home/ugrads/majors/ski23/Desktop/node-v9.5.0/out/Release/obj.target/openssl/deps/openssl/openssl/ssl/bio_ssl.o
- b. /home/ugrads/majors/ski23/Desktop/node-v9.5.0/out/Release/obj.target/nghttp2/deps/nghttp2/lib/nghttp2_session.o Is the module that contained an external reference to nghttp2_outbound_item.o. It referred to the symbol nghttp2_outbound_item_init
- 3)
- 1. ./pie uses different addresses for text, data, and bss between different iterations while ./no.pie uses the same addresses every time.
- 2. This helps prevent against return oriented programming attacks because it randomizes the addresses for the code every time.
- 4)
- 1. Running objdump -d lto2.o yields the following error: objdump: lto2.o: File format not recognized
- 2. Running file lto2.o yields: lto2.o: LLVM bitcode
- 3. define i64 @fac(i64) local_unnamed_addr #0 {
- 4.
- 00000000004004c0 <main>:
- 4004c0: b8 00 5f 37 00 mov $0x375f00,%eax
- 4004c5: c3 retq
- 4004c6: 66 2e 0f 1f 84 00 00 nopw %cs:0x0(%rax,%rax,1)
- 4004cd: 00 00 00
- 5. So cool...
- Instead of actually calling the function fac, the compiler/linker just uses the value $0x375f00 and eliminates the function entirely
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement