Advertisement
Guest User

Kernel32

a guest
Jan 1st, 2013
181
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5.37 KB | None | 0 0
  1. package kine;
  2.  
  3. import static java.util.Arrays.asList;
  4.  
  5. import java.util.List;
  6.  
  7. import com.sun.jna.Library;
  8. import com.sun.jna.Structure;
  9. import com.sun.jna.ptr.IntByReference;
  10.  
  11. public interface Kernel32 extends Library {
  12.  
  13.     IntByReference VirtualAllocEx(IntByReference hProcess,
  14.             IntByReference lpAddress, int dwSize, int flAllocationType,
  15.             int flProtect);
  16.  
  17.     boolean CreateProcess(String lpApplicationName, String commandLine,
  18.             int processAttributes, int threadAttributes,
  19.             boolean inheritHandles, int creationFlags,
  20.             IntByReference environment, String currentDirectory,
  21.             STARTUPINFO startupInfo, PROCESS_INFORMATION processInformation);
  22.  
  23.     boolean ReadProcessMemory(IntByReference hProcess,
  24.             IntByReference lpBaseAddress, IntByReference lpBuffer, int dwSize,
  25.             int lpNumberOfBytesRead);
  26.  
  27.     boolean WriteProcessMemory(IntByReference hProcess,
  28.             IntByReference lpBaseAddress, IntByReference lpBuffer, int nSize,
  29.             int lpNumberOfBytesWritten);
  30.  
  31.     boolean GetThreadContext(IntByReference hThread, CONTEXT lpContext);
  32.  
  33.     boolean SetThreadContext(IntByReference hThread, CONTEXT lpContext);
  34.  
  35.     int SuspendThread(IntByReference hThread);
  36.  
  37.     int ResumeThread(IntByReference hThread);
  38.  
  39.     boolean VirtualProtectEx(IntByReference hProcess, IntByReference lpAddress,
  40.             IntByReference dwSize, int flNewProtect, int lpflOldProtect);
  41.  
  42.     int VirtualQueryEx(IntByReference hProcess, IntByReference lpAddress,
  43.             MEMORY_BASIC_INFORMATION lpBuffer, int dwLength);
  44.  
  45.     IntByReference VirtualAlloc(IntByReference address, int numBytes,
  46.             int commitOrReserve, int pageProtectionMode);
  47.  
  48.     public static class PROCINFO extends Structure {
  49.  
  50.         public int baseAddr;
  51.         public int imageSize;
  52.  
  53.         @Override
  54.         protected List<String> getFieldOrder() {
  55.             return asList("baseAddr", "imageSize");
  56.         }
  57.  
  58.     }
  59.  
  60.     public static class PROCESS_INFORMATION extends Structure {
  61.  
  62.         public IntByReference hProcess;
  63.         public IntByReference hThread;
  64.         public int dwProcessId;
  65.         public int dwThreadId;
  66.  
  67.         @Override
  68.         protected List<String> getFieldOrder() {
  69.             return asList("hProcess", "hThread", "dwProcessId", "dwThreadId");
  70.         }
  71.  
  72.     }
  73.  
  74.     public static class STARTUPINFO extends Structure {
  75.  
  76.         public int cb;
  77.         public String lpReserved;
  78.         public String lpDesktop;
  79.         public String lpTitle;
  80.         public byte unused[] = new byte[52];
  81.  
  82.         @Override
  83.         protected List<String> getFieldOrder() {
  84.             return asList("cb", "lpReserved", "lpDesktop", "lpTitle", "unused");
  85.         }
  86.  
  87.     }
  88.  
  89.     public static class CONTEXT extends Structure {
  90.  
  91.         public int ContextFlags;
  92.         public byte[] unused = new byte[160];
  93.         public int Ebx;
  94.         public int Edx;
  95.         public int Ecx;
  96.         public int Eax;
  97.  
  98.         @Override
  99.         protected List<String> getFieldOrder() {
  100.             return asList("ContextFlags", "unused", "Ebx", "Edx", "Ecx", "Eax");
  101.         }
  102.  
  103.     }
  104.  
  105.     public static class MEMORY_BASIC_INFORMATION extends Structure {
  106.  
  107.         public int BaseAddress;
  108.         public int AllocationBase;
  109.         public int AllocationProtect;
  110.         public int RegionSize;
  111.         public int State;
  112.         public int Protect;
  113.         public int lType;
  114.  
  115.         @Override
  116.         protected List<String> getFieldOrder() {
  117.             return asList("BaseAddress", "AllocationBase", "AllocationProtect",
  118.                     "RegionSize", "State", "Protect", "lType");
  119.         }
  120.  
  121.     }
  122.  
  123.     public static class MZHeader extends Structure {
  124.  
  125.         public short signature;
  126.         public byte[] unused = new byte[58];
  127.         public int offsetToPE;
  128.  
  129.         @Override
  130.         protected List<String> getFieldOrder() {
  131.             return asList("signature", "unused", "offsetToPE");
  132.         }
  133.  
  134.     }
  135.  
  136.     public static class PE_Header extends Structure {
  137.  
  138.         public int signature;
  139.         public short machine;
  140.         public short numSections;
  141.         public int timeDateStamp;
  142.         public int pointerToSymbolTable;
  143.         public int numOfSymbols;
  144.         public short sizeOfOptionHeader;
  145.         public short characteristics;
  146.  
  147.         @Override
  148.         protected List<String> getFieldOrder() {
  149.             return asList("signature", "machine", "numSections",
  150.                     "timeDateStamp", "pointerToSymbolTable", "numOfSymbols",
  151.                     "sizeOfOptionHeader", "characteristics");
  152.         }
  153.  
  154.     }
  155.  
  156.     public static class PE_ExtHeader extends Structure {
  157.  
  158.         public short magic;
  159.         public byte majorLinkerVersion;
  160.         public byte minorLinkerVersion;
  161.         public int sizeOfCode;
  162.         public int sizeOfInitializedData;
  163.         public int sizeOfUninitializedData;
  164.         public int addressOfEntryPoint;
  165.         public int baseOfCode;
  166.         public int baseOfData;
  167.         public int imageBase;
  168.         public int sectionAlignment;
  169.         public int fileAlignment;
  170.         public byte[] unused = new byte[16];
  171.         public int sizeOfImage;
  172.         public int sizeOfHeaders;
  173.         public byte[] unused2 = new byte[160];
  174.  
  175.         @Override
  176.         protected List<String> getFieldOrder() {
  177.             return asList("magic", "majorLinkerVersion", "minorLinkerVersion",
  178.                     "sizeOfCode", "sizeOfInitializedData",
  179.                     "sizeOfUninitializedData", "addressOfEntryPoint",
  180.                     "baseOfCode", "baseOfData", "imageBase",
  181.                     "sectionAlignment", "fileAlignment", "unused",
  182.                     "sizeOfImage", "sizeOfHeaders", "unused2");
  183.         }
  184.  
  185.     }
  186.  
  187.     public static class SectionHeader extends Structure {
  188.  
  189.         public long sectionName;
  190.         public int virtualSize;
  191.         public int virtualAddress;
  192.         public int sizeOfRawData;
  193.         public int pointerToRawData;
  194.         public byte[] unused = new byte[16];
  195.  
  196.         @Override
  197.         protected List<String> getFieldOrder() {
  198.             return asList("sectionName", "virtualSize", "virtualAddress",
  199.                     "sizeOfRawData", "pointerToRawData", "unused");
  200.         }
  201.  
  202.     }
  203.  
  204. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement