Advertisement
Guest User

Untitled

a guest
Feb 25th, 2018
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.32 KB | None | 0 0
  1.  
  2. import java.util.ArrayList;
  3. import java.util.Collections;
  4. import java.util.HashMap;
  5. import java.util.Scanner;
  6. import java.util.regex.Matcher;
  7. import java.util.regex.Pattern;
  8.  
  9. public class linker
  10. {
  11.  
  12. public static void main(String[] args)
  13. {
  14. Scanner input = new Scanner(System.in);
  15. String filename = "^([A-Za-z0-9])+(.o:)$";
  16. String textSection = "^(\\s)*(U )([a-zA-Z0-9_]+)$";
  17. String dataSection = "^([0-9a-f]+) ([0-9a-f]+) ([TtbCdDU]) ([a-zA-Z0-9_]+)$";
  18. ArrayList<String> textArray = new ArrayList<String>();
  19. ArrayList<String[]> dataArray = new ArrayList<String[]>();
  20. HashMap<String, String> dataMap = new HashMap<String, String>();
  21.  
  22. while(input.hasNextLine())
  23. {
  24. String line = input.nextLine();
  25. if (!line.equals(""))
  26. {
  27. if (line.matches(filename))
  28. {
  29.  
  30. }
  31. else if (line.matches(textSection))
  32. {
  33.  
  34. Pattern pattern = Pattern.compile(textSection);
  35. Matcher match = pattern.matcher(line);
  36. if (match.find())
  37. {
  38. textArray.add(match.group(3));
  39. }
  40. }
  41. else if (line.matches(dataSection))
  42. {
  43. Pattern pattern = Pattern.compile(dataSection);
  44. Matcher match = pattern.matcher(line);
  45. if (match.find())
  46. {
  47. String[] dataElement = new String[4];
  48. dataElement[0] = match.group(1);
  49. dataElement[1] = match.group(2);
  50. dataElement[2] = match.group(3);
  51. dataElement[3] = match.group(4);
  52. if (!dataMap.containsKey(dataElement[3]))
  53. {
  54. dataMap.put(dataElement[3], dataElement[2]);
  55. }
  56. else
  57. {
  58. if (dataMap.get(dataElement[3]).equals("C") && dataElement[2].toUpperCase().equals(dataElement[2]))
  59. {
  60. dataMap.put(dataElement[3], dataElement[2]);
  61. }
  62. else if (dataElement[2].equals("C") &&
  63. dataMap.get(dataElement[3]).toUpperCase().equals(dataMap.get(dataElement[3])))
  64. {
  65. continue;
  66. }
  67. else if (!dataMap.get(dataElement[3]).toUpperCase().equals(dataMap.get(dataElement[3])) &&
  68. dataElement[2].toUpperCase().equals(dataElement[2]))
  69. {
  70. dataMap.put(dataElement[3], dataElement[2]);
  71. }
  72. else if (dataMap.get(dataElement[3]).toUpperCase().equals(dataMap.get(dataElement[3])) &&
  73. dataElement[2].toUpperCase().equals(dataElement[2]))
  74. {
  75. System.out.println("Symbol " + dataElement[3] + " multiply defined");
  76. return;
  77. }
  78. }
  79. dataArray.add(dataElement);
  80. }
  81. }
  82. else
  83. {
  84. throw new IllegalArgumentException();
  85. }
  86.  
  87. //System.out.println(line);
  88. }
  89. }
  90. Collections.sort(textArray);
  91. for (int i = 0; i < textArray.size(); i++)
  92. {
  93. if (dataMap.containsKey(textArray.get(i)))
  94. {
  95. textArray.remove(i);
  96. i--;
  97. }
  98. }
  99. for (String item: textArray)
  100. {
  101. System.out.println(" U " + item);
  102. }
  103. int counter = 0x400680;
  104. for(String[] data: dataArray)
  105. {
  106. if (data[2].equalsIgnoreCase("t"))
  107. {
  108. System.out.print(String.format("%016x ", counter));
  109. System.out.print(String.format("%016x ", Integer.parseInt(data[1], 16)));
  110. System.out.print(data[2] + " ");
  111. System.out.println(data[3]);
  112. int i = Integer.parseInt(data[1], 16);
  113. if (((i / 4) * 4) != i)
  114. {
  115. i = ((i / 4) + 1) * 4;
  116. }
  117. counter += i;
  118. }
  119. }
  120. counter = 0x601044;
  121. for(String[] data: dataArray)
  122. {
  123. if (data[2].equalsIgnoreCase("d"))
  124. {
  125. System.out.print(String.format("%016x ", counter));
  126. System.out.print(String.format("%016x ", Integer.parseInt(data[1], 16)));
  127. System.out.print(data[2] + " ");
  128. System.out.println(data[3]);
  129. int i = Integer.parseInt(data[1], 16);
  130. if (((i / 4) * 4) != i)
  131. {
  132. i = ((i / 4) + 1) * 4;
  133. }
  134. counter += i;
  135. }
  136. }
  137. for(String[] data: dataArray)
  138. {
  139. if (data[2].equalsIgnoreCase("b"))
  140. {
  141. System.out.print(String.format("%016x ", counter));
  142. System.out.print(String.format("%016x ", Integer.parseInt(data[1], 16)));
  143. System.out.print(data[2] + " ");
  144. System.out.println(data[3]);
  145. int i = Integer.parseInt(data[1], 16);
  146. if (((i / 4) * 4) != i)
  147. {
  148. i = ((i / 4) + 1) * 4;
  149. }
  150. counter += i;
  151. }
  152. else if (data[2].equalsIgnoreCase("c") && dataMap.get(data[3]).equals("C"))
  153. {
  154. data[2] = "B";
  155. System.out.print(String.format("%016x ", counter));
  156. System.out.print(String.format("%016x ", Integer.parseInt(data[1], 16)));
  157. System.out.print(data[2] + " ");
  158. System.out.println(data[3]);
  159. int i = Integer.parseInt(data[1], 16);
  160. if (((i / 4) * 4) != i)
  161. {
  162. i = ((i / 4) + 1) * 4;
  163. }
  164. counter += i;
  165. }
  166. }
  167. input.close();
  168. }
  169. }
  170.  
  171.  
  172.  
  173.  
  174.  
  175. 2)
  176. 2. /home/ugrads/majors/ski23/Desktop/node-v9.5.0/out/Release/node
  177. 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
  178. 4. Using grep with " T " I found: ssl_cert_add1_chain_cert
  179. 5. I used grep and found that there are 502 strong global readonly symbols
  180. 6. Using size, I found that the size of the data section of the node executable is 101672
  181. 7.
  182. a. /home/ugrads/majors/ski23/Desktop/node-v9.5.0/out/Release/obj.target/openssl/deps/openssl/openssl/ssl/bio_ssl.o
  183. 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
  184.  
  185. 3)
  186. 1. ./pie uses different addresses for text, data, and bss between different iterations while ./no.pie uses the same addresses every time.
  187. 2. This helps prevent against return oriented programming attacks because it randomizes the addresses for the code every time.
  188.  
  189. 4)
  190. 1. Running objdump -d lto2.o yields the following error: objdump: lto2.o: File format not recognized
  191. 2. Running file lto2.o yields: lto2.o: LLVM bitcode
  192. 3. define i64 @fac(i64) local_unnamed_addr #0 {
  193. 4.
  194. 00000000004004c0 <main>:
  195. 4004c0: b8 00 5f 37 00 mov $0x375f00,%eax
  196. 4004c5: c3 retq
  197. 4004c6: 66 2e 0f 1f 84 00 00 nopw %cs:0x0(%rax,%rax,1)
  198. 4004cd: 00 00 00
  199. 5. So cool...
  200. 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